<?php

require_once('constants.php');

class General

{

	public function __construct()

	{

		

		?>

         

        <script language="javascript" src="js/index_sub.js?t=<?=time();?>" type="text/javascript">       

        </script>

        

        <?php

	}

	

	 

	public function showGeneralList()

	{

		            

		            

		            

		             $sql_nn2 = " SELECT * FROM  draw where m_code>0 order by code desc limit 0,1 ";		 

					$rc_nn2 = mysql_query($sql_nn2);

					$draw = mysql_fetch_assoc($rc_nn2);

			    	//echo  date("Y-m-d",strtotime($draw['draw_date'])).'<'.date("Y-m-t",strtotime("-1 Months")).'<BR/>';

					if(date("Y-m-d",strtotime($draw['draw_date']))<date("Y-m-t",strtotime("-1 Months")))

					{

					  

						//$draw['detail']=='NO Draw' and 

						//echo 'Seems One month old';

						

						

						$sql  = " INSERT INTO draw SET m_code=1,month='".($draw['month']+1)."',prize=1,detail='NO Draw',draw_date='".date("Y-m-t",strtotime("-1 Months"))."'";		 

						

						 mysql_query($sql);

						 $code = mysql_insert_id();

						 

						 

						  $sql_nn2 = " SELECT * FROM  draw where code='".$code."' ";		 

						$rc_nn2 = mysql_query($sql_nn2);

						$draw = mysql_fetch_assoc($rc_nn2);

						

						

						$draw['month']='9999'.$code;

						

						

						$sql_nn2 = " SELECT * FROM  customer_booking  ";		

						//echo '<BR/>'.$sql_nn2; 

						$rc_nn2 = mysql_query($sql_nn2);

						while($cust_d2 = mysql_fetch_assoc($rc_nn2))

						{ 

						  

						  

						  $sql_k1 = " SELECT * FROM  consolidate_policy where policy_code='".$cust_d2['code']."' and used_for='".$draw['month']."'  ";		 

						  //echo '<BR/>'.$sql_k1; 

						  $rc_k1 = mysql_query($sql_k1);

						  $cust_k1 = mysql_fetch_assoc($rc_k1);

						  

						  if($cust_k1['code']<=0)

						  {

						  

							  $sql_k2 = " SELECT * FROM  consolidate_policy where policy_code='".$cust_d2['code']."'  and paid=1 and   (used_for='0') order by ins limit 0,1 ";		 

							 //  echo '<BR/>'.$sql_k2; 

							  $rc_k2 = mysql_query($sql_k2);

							  $cust_k2 = mysql_fetch_assoc($rc_k2);

								if($cust_k2['code']>0)

								{

								

									$su = " UPDATE consolidate_policy SET used_for='".$draw['month']."', used_for_remarks='Draw Skipped for this Month' where policy_code = '".$cust_d2['code']."' and code = '".$cust_k2['code']."'  and paid=1 and  used_for='0'  ";

									

								//	 echo '<HR/>'.$su.'<HR/>'; 

									mysql_query($su);

								}

						  

						  

						  }

						}

						

					}        

		

		//if(count($_SESSION['cat'])<=0)

			 

				/*echo '<PRE/>';

				print_r($_SESSION['cat']);

				echo '<PRE/>';*/

			require_once("../../common_pages/enc.php");

			$converter = new Encryption($_SESSION['unique_enc_id']);

	?>

        <div class="am-mainpanel">

 		<div class="am-pagebody">

        <div class="row row-sm">

          <div class="col-lg-4">

            <div  >

              <div   ></div>

               <?php

			    

				$s  = "select * from dashboard_data  order by code desc limit 0,1";

				$r = mysql_query($s);

				$ro2 = mysql_fetch_assoc($r);

				//

				if($ro2['c_date']<=date("Y-m-d H:i:s",strtotime("-1 hours")))

				{

					// echo $ro2['c_date'].'<='.date("Y-m-d H:i:s",strtotime("-1 hours"));

					 

					

				

						 $s  = "select code,is_closed from customer_booking where payment_status=2 ";

						$r = mysql_query($s);

						while($ro = mysql_fetch_assoc($r))

						{

							customer_payment_status_update($ro['code']);

							if($ro['is_closed']==1)

							{

								$sq = "delete from consolidate_policy where policy_code='".$ro['code']."' and paid='0' ";

								// echo '<BR/>'.$sq;

								mysql_query($sq);

							}

						} 

						$ro2['c_date'] = date("d-M-Y H:i:s"); 

                }  

				echo 'Last Updated : '.date("d-M-Y h:ia",strtotime($ro2['c_date']));
				
				$sql_x1 = "select * from sms_gateway order by code desc limit 0,1";
				$r_x1 = mysql_query($sql_x1);
				$sms_gateway = mysql_fetch_assoc($r_x1);
				
				
				echo '<br /><span style=" color:#F00">SMS GATEWAY Enabled : <B>'.ucwords($sms_gateway['gateway']).'</B></span>';
				

			   ?><br />

<br />



            </div><!-- card -->

          </div><!-- col-4 -->

           <!-- col-4 -->

           <!-- col-4 -->

        </div><!-- row -->

		<div class="row row-sm">

          <div class="col-lg-4">

            <div class="card">

              <div id="rs1" class="wd-100p ht-200"></div>

              <div class="overlay-body pd-x-20 pd-t-20">

                <div class="d-flex justify-content-between">

                  <div>

                    <h6 class="tx-12 tx-uppercase tx-inverse tx-bold mg-b-5">Total Pending</h6>

                    <p class="tx-12">Till today</p>

                  </div>

                  <a href="" class="tx-gray-600 hover-info"><i class="icon ion-more tx-16 lh-0"></i></a>

                </div><!-- d-flex -->

                <h2 class="mg-b-5 tx-inverse tx-lato text-danger"><?php

                

				 if($_SESSION['access_type']<2)	

				$where.= " and (sale_emp_code='".$_SESSION['admin_code']."' or c_admin_id='".$_SESSION['admin_code']."')";



				

				$sql = "select policy_code,sum(amt) as amt from customer_booking b,consolidate_policy c where c.date<='".date("Y-m-d")."' ".$where." and paid = 0  and payment_status=2 and b.code=policy_code group by policy_code  ";

				$r = mysql_query($sql);

				$i = 0;

				while($ro = mysql_fetch_assoc($r))

				{

					$i++;

					$amt+=abs($ro['amt']);

				

				} 

				echo CURRENCY_SYMBOL.number_format($amt,2);

				?></h2>

                <p class="tx-12 mg-b-0">from <?=$i;?> Polices</p>

              </div>

            </div><!-- card -->

          </div><!-- col-4 -->

          <div class="col-lg-4 mg-t-15 mg-sm-t-20 mg-lg-t-0">

            <div class="card">

              <div id="rs2" class="wd-100p ht-200"></div>

              <div class="overlay-body pd-x-20 pd-t-20">

                <div class="d-flex justify-content-between">

                  <div>

                    <h6 class="tx-12 tx-uppercase tx-inverse tx-bold mg-b-5">Total Received </h6>

                    <p class="tx-12">Till today<?php //date("F 01 - d, Y");?></p>

                  </div>

                  <a href="" class="tx-gray-600 hover-info"><i class="icon ion-more tx-16 lh-0"></i></a>

                </div><!-- d-flex -->

                <h2 class="mg-b-5 tx-inverse tx-lato"><h2 class="mg-b-5 tx-inverse tx-lato"><?php

                $sql = "select policy_code,sum(amt) as amt from customer_booking b,consolidate_policy c where   paid =1 ".$where."  and b.code=policy_code group by policy_code  ";

				$r = mysql_query($sql);

				$i = 0;

				$amt= 0;

				while($ro = mysql_fetch_assoc($r))

				{

					$i++;

					$amt+=abs($ro['amt']);

				

				} 

				echo CURRENCY_SYMBOL.number_format($amt,2);

				?></h2>

                <p class="tx-12 mg-b-0">from <?=$i;?> Polices</p></h2> 

              </div>

            </div><!-- card -->

          </div><!-- col-4 -->

          <div class="col-lg-4 mg-t-15 mg-sm-t-20 mg-lg-t-0">

            <div class="card">

              <div id="rs3" class="wd-100p ht-200"></div>

              <div class="overlay-body pd-x-20 pd-t-20">

                <div class="d-flex justify-content-between">

                  <div>

                    <h6 class="tx-12 tx-uppercase tx-inverse tx-bold mg-b-5">Total Polices</h6>

                    <p class="tx-12">Till today</p>

                  </div>

                  <a href="" class="tx-gray-600 hover-info"><i class="icon ion-more tx-16 lh-0"></i></a>

                </div><!-- d-flex -->

                <h2 class="mg-b-5 tx-inverse tx-lato">

                <h2 class="mg-b-5 tx-inverse tx-lato"><h2 class="mg-b-5 tx-inverse tx-lato"><?php

                $sql = "select customer_code,count(*) as c from customer_booking where 1 group by customer_code";

				$r = mysql_query($sql);

				$i = 0;

				$amt = 0;

				while($ro = mysql_fetch_assoc($r))

				{

					$i++;

					$amt+=abs($ro['c']);

				

				} 

				echo number_format($amt,0);

				?></h2>

                <p class="tx-12 mg-b-0">from <?=$i;?> Customers</p></h2> 

                </h2>

                <p class="tx-12 mg-b-0"></p>

              </div>

            </div><!-- card -->

          </div><!-- col-4 -->

        </div>

        <div class="row row-sm mg-t-15 mg-sm-t-20">

           <div class="col-xl-6 mg-t-25 mg-xl-t-0">

            <div class="card pd-20 pd-sm-40">

              <h6 class="card-body-title">Policy Status</h6>

              <!--<p class="mg-b-20 mg-sm-b-30">Labels can be hidden if the slice is less than a given percentage of the pie.</p>-->

              <div id="flotPie2" class="ht-200 ht-sm-250"></div>

              

              <?php 

		

		

				$colours = array();

				$k=1;

				$colours[$k] = '#3498DB'; $k++;

				$colours[$k] = '#2980B9'; $k++;

				$colours[$k] = '#8E44AD'; $k++;

				$colours[$k] = '#FFC300'; $k++;

				$colours[$k] = '#FF5733'; $k++;

				$colours[$k] = '#17A2B8'; $k++;

				$colours[$k] = '#17A2B8'; $k++;

				$colours[$k] = '#17A2B8'; $k++;

				$colours[$k] = '#17A2B8'; $k++;

				$colours[$k] = '#17A2B8'; $k++;

				$colours[$k] = '#17A2B8'; $k++;

				$colours[$k] = '#17A2B8'; $k++;

				

				 

				

				$status_name = array();

				$s2 = "select * from booking_status ";

				$r2 = mysql_query($s2);

				while($r4 = mysql_fetch_assoc($r2))

				{

					$status_name[$r4['code']] = $r4['name'];

				}

			

			

				$status = array();

				$s  = "select 	* from customer_booking where payment_status=2 ".$where." order by code ";

				$r = mysql_query($s);

				while($ro = mysql_fetch_assoc($r))

				{

					$status[$ro['booking_status_code']]['c'] = ($status[$ro['booking_status_code']]['c']+1);

					$status[$ro['booking_status_code']]['payment'][$ro['total_amount']] = ($status[$ro['booking_status_code']]['payment'][$ro['total_amount']]+1);

					$status[$ro['booking_status_code']]['total_amount']+=	$ro['total_amount'];

				}

				?>

               

                <?php

                $ddd = array(); 

				$i = 1;

				$ddd_x = '';

				foreach($status_name as $k=>$v)

				{

					$kk = 1; 

                   	if($k==6)

						$kk = 2;

					if($k==7)

						$kk = 3;

							

					$link_start = "<a href='../policy_list/index.php?task=".$converter->encode('general')."&ref_id2=".$v."&s_booking_status=".$kk."&s_booking_status_m=".$k."'   target='_blank' >";

					

					$ddd_x.= '<div class="line_one" style="background-color:'.$colours[$i].'" >'.$link_start.$v.' = '.$status[$k]['c'].'  '.CURRENCY_SYMBOL.number_format($status[$k]['total_amount'],2).$link_end.'</div>';

					$am_d = array();

					if(count($status[$k]['payment'])>0)

						foreach($status[$k]['payment'] as $k1=>$v1)

							$am_d[] = $k1.' X '.$v1.' = '.($k1*$v1);

							

//$ddd_x.=implode(" ,",$am_d);

                      $link_end = '</a>';

                     

					$ddd[] = '{ label: "'.$link_start.$v.' ('.$status[$k]['c'].')'.$link_end.'", data: [[1,'.$status[$k]['c'].']], color: "'.$colours[$i].'"}';

					$i++;

				

				}

				 

				

				?>

               

               <style>

			   .line_one{

			   

			   			 width:auto;

						color:#FFFFFF;

						display:inline-table;  

						padding:4px 7px;  

						border-radius:3px; 

						 

						margin:2px;

			   	}

				.line_one a{ color:#FFFFFF;}

			   </style>

                

            </div><!-- card -->

          </div>

           <div class="col-xl-6 mg-t-25 mg-xl-t-0">

            <div class="card pd-20 pd-sm-40">

              <h6 class="card-body-title">Policy Status Details</h6>

              <!--<p class="mg-b-20 mg-sm-b-30">Labels can be hidden if the slice is less than a given percentage of the pie.</p>-->

               <?=$ddd_x;?>

            </div><!-- card -->

          </div>

        </div>

        

				

        <script>

		 $( document ).ready(function() {

		var piedata = [

			

			

			<?=implode($ddd,',');?>

			

			];

			

			 $.plot('#flotPie2', piedata, {

				series: {

				  pie: {

					show: true,

					radius: 1,

					innerRadius: 0.3,

					label: {

					  show: true,

					  radius: 2/3,

					  formatter: labelFormatter,

					  threshold: 0.1

					}

				  }

				},

				grid: {

				  hoverable: true,

				  clickable: true

				}

			  });

			

			});

		</script>

        

        <div class="row row-sm mg-t-15 mg-sm-t-20">

          <div class="col-xl-6">

            <!--<div class="card pd-20 pd-sm-40">

              <h6 class="card-body-title">Bar Chart</h6>

              <p class="mg-b-20 mg-sm-b-30">A bar chart or bar graph is a chart with rectangular bars with lengths proportional to the values that they represent.</p>

              <canvas id="chartBar1" height="300"></canvas>

            </div>--><!-- card -->

          </div><!-- col-6 -->

          <div class="col-xl-6 mg-t-25 mg-xl-t-0">

            <!--<div class="card pd-20 pd-sm-40">

              <h6 class="card-body-title">Multiple Color Bar Chart</h6>

              <p class="mg-b-20 mg-sm-b-30">A bar chart or bar graph is a chart with rectangular bars with lengths proportional to the values that they represent.</p>

              <canvas id="chartBar2" height="300"></canvas>

            </div>--><!-- card -->

          </div><!-- col-6 -->

        </div>

        <div class="row row-sm mg-t-15 mg-sm-t-20">

           <!-- col-6 -->

          

          

          

          

          

          

         

          <div class="col-xl-6">

            <div class="card pd-20 pd-sm-40">

              <h6 class="card-body-title">Payment by users</h6>

              <p class="mg-b-20 mg-sm-b-30">it will display payment collection by users today.</p>

              <div id="flotPie1" class="ht-200 ht-sm-250"></div>

            </div><!-- card -->

          </div><!-- col-6 -->

           

        </div>

        

        <!-- col-6 -->

        </div><!-- row -->

		<?php 

		  $c = array();

		  $i = 0;

		  

		  $r = array();

		   

		  $i = 1;

		  $colour[$i] = '#CAB1D2'; $i++;

		  $colour[$i] = '#677489'; $i++;

		  $colour[$i] = '#F89D44'; $i++;

		  $colour[$i] = '#85C441'; $i++;

		  $colour[$i] = '#36B3E3'; $i++;

		  $colour[$i] = '#F00'; $i++;

		  $colour[$i] = '#0F0'; $i++;

		  

		  

		  $s = array();

		  $sql = "select c.admin_id,sum(amt) as c,name from consolidate c,admin_users a where date='".date("Y-m-d")."' and amt>0 and c.admin_id = a.admin_id group by c.admin_id";

		  $r2 = mysql_query($sql);

		  $dd =array();

		  $i = 1;

		  while($ro = mysql_fetch_assoc($r2))

		  {

		  		//$s[$ro['admin_id']] =  $ro['c'] ;

				

		  		$dd[] =  "{ label: '".$ro['name'].' ('.$ro['c'].')'."', data: [[1,".$ro['c']."]], color: '".$colour[$i]."'}";

				$i++;

		  }

		   

		  

		  ?>

          

          <script language="javascript"  type="application/javascript">

		  function labelFormatter(label, series) {

			return "<div style='font-size:8pt; text-align:center; padding:2px; color:white;'>" + label + "<br/>" + Math.round(series.percent) + "%</div>";

			}

		  $( document ).ready(function() {

     

		 	   var piedata = [

					<?=implode(",",$dd);?> 

					];

					

					$.plot('#flotPie1', piedata, {

					series: {

					  pie: {

						show: true,

						radius: 1,

						label: {

						  show: true,

						  radius: 2/3,

						  formatter: labelFormatter,

						  threshold: 0.1

						}

					  }

					},

					grid: {

					  hoverable: true,

					  clickable: true

					}

					});

		  

		  

		  });

          </script>

         <!-- row -->

			

            

            

            

        </div><!-- row -->

      

       

	

           

                     

    <?php

	}

	

	//Add 

		public function add_edit($data='',$extra='')

		{

			

			//echo $_SESSION['role_level'];

			

			

			 

			$data['id'] = $data['code'] = $data['code'];

			

			/*if($data['dob'])

				$data['dob'] = $data['dob'];

			else

				$data['dob'] = date("Y-m-d");

				*/

		?> 



            <div id="add_edit"  >

                <form   name="add_edit_form" id="add_edit_form" method="post" enctype="multipart/form-data" action='../ajaximage/ajaximage.php' data-parsley-validate >

               <div class="header_box"><?=($data['id']>0)?'Edit - ':'Add - ';?><?=TITLE_PAGE;?></div>

               <div class="body_box"> <?php if($data['id']>0) { 

				

				?>

                	<input type="hidden" name="task2" id="task2" value="update"  />

                    <input type="hidden" name="id" id="id" value="<?=$data['id'];?>"  />

                   

				   

                   

				   <?php }else{ 

				   

				   //$data['under'] = $extra['under'];

				  // $data['designation'] = $extra['designation'];

				   ?>

                   <input type="hidden"  name="task2" id="task2" value="Add"  />

                   <input type="hidden" name="id" id="id" value=""  />

                   <?php } ?>

                   

                 

              	

                

                    <div class="wd-300">

                      <div class="d-md-flex mg-b-30">

                        <div class="form-group mg-b-0">

                          <label>Customer Name: <span class="tx-danger">*</span></label>

                          <input type="text" name="name" class="form-control wd-200 wd-sm-250" placeholder="Enter Name" required>

                        </div><!-- form-group -->

                        <div class="form-group mg-b-0 mg-md-l-20 mg-t-20 mg-md-t-0">

                          <label>Mobile Number: <span class="tx-danger">*</span></label>

                          <input type="text" name="mobile" class="form-control wd-200 wd-sm-250" placeholder="Enter Mobile Number" required>

                        </div><!-- form-group -->

                      </div><!-- d-flex -->

                      <div class="d-md-flex mg-b-30">

                        <div class="form-group mg-b-0">

                          <label>Address Line 1: <span class="tx-danger">*</span></label>

                          <input type="text" name="address_line_1" class="form-control wd-200 wd-sm-250" placeholder="Enter Address Line 1" required>

                        </div><!-- form-group -->

                        <div class="form-group mg-b-0 mg-md-l-20 mg-t-20 mg-md-t-0">

                          <label>Address Line 2: <span class="tx-danger"></span></label>

                          <input type="text" name="address_line_2" class="form-control wd-200 wd-sm-250" placeholder="Enter Address Line 2(Optional)"  >

                        </div><!-- form-group -->

                      </div>

                      

                      <div class="d-md-flex mg-b-30">

                         <div  id="res"></div>

                      </div>

                       <div class="d-md-flex mg-b-30">

                        <button type="submit"  id="submit_66"  class="dt-button btn btn-primary btn-success btn-sm">Submit</button> 

                        

                        <button type="button" class="dt-button btn btn-default btn-success btn-sm" onclick="GeneralDetails(<?=$_SESSION['page'];?>)">Go Back</button>

                        </div>

                    </div>

           <!--

           		<button type="button" id="btnInsertPro" name="btnInsertPro" onclick="addNew_Key(this.form)">Save</button>

                <button type="button" id="as" name="as" onclick="GeneralDetails(<?=$_SESSION['page'];?>)" >Go Back</button>-->

            

            	</form>

            </div>

                

		 

        <?php

	}

	

}



?>

</div>

