<?php

class Report_all_collection

{

	public function __construct()

	{

		

		?>

        <script language="javascript" src="js/index_3.js" type="text/javascript"></script>

        <style>

		.lb{ border-left:1px solid #666!important;}

		.rb{ border-right:1px solid #666!important;}

	</style>

        <?php

	}

	

	function common_select($table,$fields,$matchField,$code,$class,$sel,$function,$id,$displayName,$value)

	{

		if($matchField=="")

		 	$qry = "SELECT ".$fields." FROM $table";

		else 

			$qry = "SELECT ".$fields." FROM ".$table." WHERE ".$matchField."='".$code."'";

			

		//echo $qry;

		$res=mysql_query($qry);

		

		$out = '<select id="'.$id.'" name="'.$id.'" class="'.$class.'" '.$function.'  multiple="multiple"  style="height:50px;">';

		$out .='<option value="" >--Select--</option>';

		

		while($result=mysql_fetch_array($res))

		{	

			if(strtolower($result[$value])==strtolower($sel))

				$out .='<option value="'.$result[$value].'" selected="selected">'.$result[$displayName].'</option>';

			else

				$out .='<option value="'.$result[$value].'" >'.$result[$displayName].'</option>';

		}

		$out .= '</select>';

		return $out;	

	}

			

	/*-------------------------------------------------------------------------------------KMS list----*/

	

	public function showReport_all_collectionList()
	{	?>
    <script type="text/javascript" language="javascript">
		$(function() { $("#date_1").datepicker({dateFormat: 'dd-mm-yy'}); });
		$(function() { $("#date_2").datepicker({dateFormat: 'dd-mm-yy'}); });		
		$(function() { $("#date").datepicker({dateFormat: 'dd-mm-yy'}); });		
	</script>
    <div style="clear:both;"></div>
            <div class="atstextfield-wrapper">	
                <div class="textfieldtab"><h92>
                Payment Report (Between Dates)</div>

                <div class="textfieldtab">

                </div> 

                <div class="textfieldtab">

                 

	               From:<input type="text" class="date_feild" id="s_date_from" name="s_date_from" value="<? echo date("d-m-Y",strtotime("-1 days"));?>"/>

				   To:<input type="text"  class="date_feild" id="s_date_to" name="s_date_to" value="<? echo date("d-m-Y");?>"/>			

				</div>

                <div class="textfieldtab" >  Sale Employee : <?php 

							$table = "sale_employee";	//$table = name of table

							$fields = "*";//Fields = Fields of tables

							$matchField = "";		//$matchField = matching fields

							$code = "";				//$code = where $code

							$class = "";			//$class = css classs 

							$sel = $data['sale_employee_code'];				//$sel = selected fields

							$function ="";			//$function = javascript function

							$id = "s_sale_employee_code";		//$id = id of select

							$displayName = "name";		//displayName = display name

							$value ="code";  			// $value = value of Select

							

							

							echo $this->common_select($table,$fields,$matchField,$code,$class,$sel,$function,$id,$displayName,$value); ?></div>

                 <div class="textfieldtab right_float">

                    <input name="" type="image" src="../../main_images/search_btt1.png" onclick="Report_all_collectionDetails()" />

                </div>

             </div>

            <div style="clear:both;"></div>

            <div id="main_result_div">

            <script language="javascript" type="text/javascript">Report_all_collectionDetails();</script>

            </div>

    

    

    <?php

	}

	

	 

	

	public function add_edit($data)

	{

			

			 //print_r($data);

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

			//$stu = fetch_details('plot_sale','code',$data['policy_code']);

			//$cust = fetch_details('customers','code',$stu['customer_code']);

			//$course = fetch_details('master_courses','code',$data['s_code']);

			$where.=  $_REQUEST['where']; 

			  

			 

		?>

            <div id="add_edit">
                <form action="" name="add_edit_form" id="add_edit_form" >
                <table id="" cellspacing="0" style="border-top:10px solid #777;" width="100%">
    		    <?php if($_REQUEST['ins']>0){ ?>
                <tr>
                   	<th >Installment <strong><?=$_REQUEST['ins'];?></strong></th>
                </tr>
                 <?php 
				 $where.=  " and c.ins='".$_REQUEST['ins']."' "; 
				 } 
				 	$q = "SELECT s.*,c.*,c.code,c.date,c.receipt_number,cp.received_by_name,cp.bank_name,cp.remarks,sch.scheme_name,au.name as received_user,se.name as sale_employee,cp.remarks_admin FROM consolidate_policy c INNER JOIN 

			

			

			customer_booking s ON 

			s.payment_status='2' and c.type='INS' and c.rec_date>='".date("Y-m-d",strtotime($_REQUEST['s_date_from']))."' and c.rec_date<='".date("Y-m-d",strtotime($_REQUEST['s_date_to']))."' and s.code>0 and c.amt>0  and 

			c.policy_code=s.code
			INNER JOIN   customer v ON v.code = s.customer_code $where

			LEFT JOIN   sale_employee se ON se.code = v.sale_employee_code 
			LEFT JOIN   consolidate_payment cp ON NOT c.receipt_number ='' and cp.receipt_number=c.receipt_number  

			LEFT JOIN   schemes sch ON sch.code = s.scheme  

			LEFT JOIN   admin_users au ON au.admin_id = cp.admin_id  

			

			     order by cp.rec_date";

				 

				 

				 

				 

				/* $q = "Select   p.*,c.*,s.scheme_name,se.name as sale_employee from consolidate_policy c  , customer_booking p , view_customer_policy v , schemes s,sale_employee se    

				 

				 

				 

				 where paid>0 and  rec_date >='".date("Y-m-d",strtotime($_REQUEST['s_date_from']))."' and  rec_date<='".date("Y-m-d",strtotime($_REQUEST['s_date_to']))."'     and p.code=policy_code and  pcode=policy_code  and  s.code=p.scheme  and  se.code = v.sale_employee_code  ".$where.' order by rec_date';*/

			//  echo $q .= "";	

			 

		 	 //echo 'Query ===> '.$q;

			 

			//end of Pageing

			

			$qr = mysql_query($q) or die('Error: '.mysql_error());
			?>
			<tr>
				<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<button type="button" id="as" name="as" onClick="Report_all_collectionDetails();">Go Back</button></td>
			</tr> 			<table id="datatable1" class="table display responsive nowrap" width="100%" cellspacing="0" style="border-top:10px solid #777;">				<thead>		  
				<tr>
				 <tr>
				  <th >&nbsp;</th>
				  <th >Recieved Date</th> 	 
				  <th >Name</th>
				  <th >Mobile</th>
				  <th >Booking No</th>
				  <th>WB No</th>
				  <th>Scheme</th>
				  <th >Ins.</th>
				  <th style="text-align:right;">Amount</th>
				  <th>MOP</th> 
				  <th>Receipt No.</th>
				  <th>Admin Remarks</th>
				  <th >Recieved By</th>
				 </tr>
				</tr>				</thead>				<tbody>
            <?php					  

        	$i=1;

            

			while ($rows=mysql_fetch_array($qr))

            {             	

			?>

            <tr <?php	if(($i%2)==0) echo 'class="alt_new"';?>>

              <td><?=$i;?></td>

             

              <td><?php if($rows['paid']>0){ echo date("d-M-Y",strtotime($rows['rec_date'])); } ?><?php //date("d-M-Y",strtotime($rows['date']));?></td>

              	 

                <td><?=$rows['bookfor_name']; ?></td>

                <td><?=$rows['bookfor_mobile']; ?></td>

                <td><?=$rows['order_no']; ?></td>

                <td><?=$rows['wc_no']; ?></td> 

                <td><?=$rows['scheme_name']; ?></td> 

                <td><?=$rows['ins']; ?></td> 

                <td style="text-align:right;"><?php $total += $rows['amt']; echo number_format($rows['amt'],2); ?></td>

                

                

                <td><?php if($rows['paid']>0){ ?><?php

                	if($rows['received_by_name']=='eWallet' or $rows['received_by_name']=='ew')

						echo 'E-wallet';

					elseif($rows['received_by_name']=='Online')

						echo 'Online';	

					elseif($rows['received_by_name']=='Bank')

						echo 'Bank'.'('.$rows['bank_name'].')';	

					elseif($rows['received_by_name']=='Paytm')

						echo 'Paytm';	

					else if($rows['remarks']=='Paying using PayU Money')

						echo 'PayU Money';	

					else

						echo 'Cash';	

						

						 } ?></td>

                

                

                 <td><?=($rows['paid']>0)?$rows['receipt_number']:''; ?></td>

                

                 <td><?=$rows['remarks_admin']; ?></td>

                   

                   

                  <?php /*if($rows['reference']>0 and $rows['paid']>0) {

					  $sq = "Select * from multipul_payments where code='".$rows['reference']."'";

					  $r = mysql_query($sq);

					  $rt = mysql_fetch_assoc($r);

					 

					  echo 'By : <B>'.$rt['deposited_by'].'</B>';

					  echo '<BR/>'.$rt['payment_type'].' : <B>'.display_feild('admin_users','name','admin_id',$rt['payment_received_by']).'</B>';

					  echo '<BR/>Payment : <B>'.$rt['amount'].'</B>';

					  echo '<BR/>Date : <B>'.date("d-M-Y",strtotime($rt['payment_date'])).'</B>';

					  

				  }*/

					  ?>                  

                 

                 <td><?=$rows['received_user']; ?></td>

                  

                  

                

            </tr>

            <?php

			$i++;

			}

       ?>
			<tr class="total_rows">
			  <td style="text-align:right;" colspan="8">Total :</td>              
			  <td style="text-align:right;"><?=number_format($total,2); ?></td>
			  <td style="text-align:right;" colspan="6"></td>         
			</tr>		</tbody>
        </table>
		<tr>
			<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<button type="button" id="as" name="as" onClick="Report_all_collectionDetails();">Go Back</button></td>
		</tr> 
		</table>
             <?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{ ?>

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

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

                   <?php } ?>

                   

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

		</form>

        </div>

        

        </div>

        <?php

	}

	

	public function add_edit2($data)

	{

			

			 //print_r($data);

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

			//$stu = fetch_details('plot_sale','code',$data['policy_code']);

			//$cust = fetch_details('customers','code',$stu['customer_code']);

			//$course = fetch_details('master_courses','code',$data['s_code']);

		?>

            <div id="add_edit">

                <form action="" name="add_edit_form" id="add_edit_form" >

               

                

              

                <table id="" cellspacing="0" style="border-top:10px solid #777;" width="100%">

    		    <tr>

                   	<th >Commission Paid By <strong><?=$data['name'];?></strong></th>

                </tr>

                 

               <?php 

			   $q = "SELECT c.*,e.* FROM consolidate c INNER JOIN plot_sale e ON e.code=emp_code WHERE paid_by='".$data['admin_id']."' and paid>0 and c.paid_date >='".date("Y-m-d",strtotime($_REQUEST['s_date_from']))."' and c.paid_date<='".date("Y-m-d",strtotime($_REQUEST['s_date_to']))."' ";

			// echo $q .= "";	

			

			

					

			//Paging New Script //

			//if($_REQUEST['s_all_records']==1)

				$p = paging_prepare($q,$_REQUEST['page'],999999999);

			//else

			//	$p = paging_prepare($q,$_REQUEST['page']);

			

			$p['task'] = 'Employee_payDetails';

			$p['div'] = 'main_result_div';

			$p['response_file'] = 'response_employee_pay';

			$i =0;

			$key = array_keys($_REQUEST);	

			$n = count($_REQUEST);					

			while($i<=($n))

			{

				

				if($key[$i]<>"page" && $key[$i]<>"task" && $key[$i]<>"task2" )

					$p['ext_q'] .= "&".$key[$i]."=".$_REQUEST[$key[$i]]."";

				

				$i++;

			}	

			

			$q .= " LIMIT ".$p['Page_Start'].",".$p['Per_Page']." ";

			//end of Pageing

			

			$qr = mysql_query($q) or die('Error: '.mysql_error());

			

			?>



         <tr>

                   	<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<button type="button" id="as" name="as" onClick="Report_all_collectionDetails();">Go Back</button></td>

                </tr> 

        



        

          <table  width="100%" cellspacing="0" style="border-top:10px solid #777;">

            

            <tr>

              <th width="10%">B.Number</th> 	 	 	 	 	 	 	

              <th width="25%">Name</th>

              <th width="9%">Mobile</th>

			   

              <th width="15%">Recieved by</th>

              <th width="10%">Recieved Date</th>

              <th width="31%">Admin_Remarks</th>

			  <th width="13%" style="text-align:right;">Amount</th>

               

            </tr>

            <?php					  

        	$i=1;

            

			while ($rows=mysql_fetch_array($qr))

            {   

			$rows['amt'] = abs($rows['amt']);

			?>

            <tr <?php if(($i%2)==0) echo 'class="alt_new"';?>>

             

              <td><?=$rows['booklet_number_full'];?></td>

              <td><?=$rows['name']; ?></td>

              <td><?=$rows['mobile']; ?></td>

			  

              	 

                <td><?=($rows['paid']>0)?$rows['paid_by_name']:''; ?></td>

                <td><?php if($rows['paid']>0){ echo date("d-M-Y",strtotime($rows['paid_date'])); } ?></td>

                <td><?=$rows['remarks']; ?></td>

              

               <td style="text-align:right; font-size:12px; font-weight:bold;"><?php $t+=$rows['amt']; echo number_format($rows['amt'],0); ?>/-</td>

                   

               

            </tr>

            <?php

			$i++;

			}

       ?>

       <tr style="background-color:#FF0;" >

             

                <td colspan="6" style="text-align:right;">Total : </td>

              

               <td style="text-align:right; font-size:12px; font-weight:bold;"><?php echo number_format($t,2); ?>/-</td>

                   

               

            </tr>

          </table>

                 

                

                 

                 

                

                  

                <tr>

                   	<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<button type="button" id="as" name="as" onClick="Report_all_collectionDetails();">Go Back</button></td>

                </tr> 

                 

            </table>

             <?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{ ?>

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

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

                   <?php } ?>

                   

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

		</form>

        </div>

        

        </div>

        <?php

	}

	

	public function add_edit3($data)

	{

			

			 //print_r($data);

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

			//$stu = fetch_details('plot_sale','code',$data['policy_code']);

			//$cust = fetch_details('customers','code',$stu['customer_code']);

			//$course = fetch_details('master_courses','code',$data['s_code']);

		?>

            <div id="add_edit">

                <form action="" name="add_edit_form" id="add_edit_form" >

               

                

              

                <table id="" cellspacing="0" style="border-top:10px solid #777;" width="100%">

    		    <tr>

                   	<th >Cash Submitted @ Office By <strong><?=$data['name'];?></strong></th>

                </tr>

                 

               <?php 

			   $q = "SELECT * FROM consolidate_cash,admin_users where is_deleted=0 and admin_id=emp_code and emp_code='".$data['admin_id']."' and amt>0 and  date >='".date("Y-m-d",strtotime($_REQUEST['s_date_from']))."' and  date<='".date("Y-m-d",strtotime($_REQUEST['s_date_to']))."' and is_deleted=0 ";

			// echo $q .= "";	

			

			

					

			//Paging New Script //

			//if($_REQUEST['s_all_records']==1)

				$p = paging_prepare($q,$_REQUEST['page'],999999999);

			//else

			//	$p = paging_prepare($q,$_REQUEST['page']);

			

			$p['task'] = 'Employee_payDetails';

			$p['div'] = 'main_result_div';

			$p['response_file'] = 'response_employee_pay';

			$i =0;

			$key = array_keys($_REQUEST);	

			$n = count($_REQUEST);					

			while($i<=($n))

			{

				

				if($key[$i]<>"page" && $key[$i]<>"task" && $key[$i]<>"task2" )

					$p['ext_q'] .= "&".$key[$i]."=".$_REQUEST[$key[$i]]."";

				

				$i++;

			}	

			

			$q .= " LIMIT ".$p['Page_Start'].",".$p['Per_Page']." ";

			//end of Pageing

			

			$qr = mysql_query($q) or die('Error: '.mysql_error());

			

			?>



         <tr>

                   	<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<button type="button" id="as" name="as" onClick="Report_all_collectionDetails();">Go Back</button></td>

                </tr> 

        



        

          <table  width="100%" cellspacing="0" style="border-top:10px solid #777;">

            

            <tr>

              <th width="10%">Date</th> 	 	 	 	 	 	 	

              <th width="25%">Name</th>

              

			   

              

              <th width="31%">Remarks</th>

              

              <th width="15%">Details</th>

              

			  <th width="13%" style="text-align:right;">Amount</th>

               

            </tr>

            <?php					  

        	$i=1;

            

			while ($rows=mysql_fetch_array($qr))

            {   

			$rows['amt'] = abs($rows['amt']);

			?>

            <tr <?php if(($i%2)==0) echo 'class="alt_new"';?>>

             

              <td><?=date("d-M-Y",strtotime($rows['date']));?></td>

              <td><?=$rows['name']; ?></td>

               

			  <td><?=$rows['remarks']; ?></td>

              	 

                <td><?php if($rows['paid']>0)

			  		echo $rows['paid_by_name']; 

			  	?></td>

                 

              

               <td style="text-align:right; font-size:12px; font-weight:bold;"><?php $t+=$rows['amt']; echo number_format($rows['amt'],0); ?>/-</td>

                   

               

            </tr>

            <?php

			$i++;

			}

       ?>

       <tr style="background-color:#FF0;" >

             

                <td colspan="4" style="text-align:right;">Total : </td>

              

               <td style="text-align:right; font-size:12px; font-weight:bold;"><?php echo number_format($t,2); ?>/-</td>

                   

               

            </tr>

          </table>

                 

                

                 

                 

                

                  

                <tr>

                   	<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<button type="button" id="as" name="as" onClick="Report_all_collectionDetails();">Go Back</button></td>

                </tr> 

                 

            </table>

             <?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{ ?>

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

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

                   <?php } ?>

                   

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

		</form>

        </div>

        

        </div>

        <?php

	}

	

		public function add_edit4($data)

	{

			

			 //print_r($data);

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

			//$stu = fetch_details('plot_sale','code',$data['policy_code']);

			//$cust = fetch_details('customers','code',$stu['customer_code']);

			//$course = fetch_details('master_courses','code',$data['s_code']);

		?>

            <div id="add_edit">

                <form action="" name="add_edit_form" id="add_edit_form" >

               

                

              

                <table id="" cellspacing="0" style="border-top:10px solid #777;" width="100%">

    		    <tr>

                   	<th >Cash Taken from Office By <strong><?=$data['name'];?></strong></th>

                </tr>

                 

               <?php 

			   $q = "SELECT * FROM consolidate_cash,admin_users where is_deleted=0 and admin_id=emp_code and emp_code='".$data['admin_id']."' and amt<0 and  date >='".date("Y-m-d",strtotime($_REQUEST['s_date_from']))."' and  date<='".date("Y-m-d",strtotime($_REQUEST['s_date_to']))."' and is_deleted=0 ";

			// echo $q .= "";	

			

			

					

			//Paging New Script //

			//if($_REQUEST['s_all_records']==1)

				$p = paging_prepare($q,$_REQUEST['page'],999999999);

			//else

			//	$p = paging_prepare($q,$_REQUEST['page']);

			

			$p['task'] = 'Employee_payDetails';

			$p['div'] = 'main_result_div';

			$p['response_file'] = 'response_employee_pay';

			$i =0;

			$key = array_keys($_REQUEST);	

			$n = count($_REQUEST);					

			while($i<=($n))

			{

				

				if($key[$i]<>"page" && $key[$i]<>"task" && $key[$i]<>"task2" )

					$p['ext_q'] .= "&".$key[$i]."=".$_REQUEST[$key[$i]]."";

				

				$i++;

			}	

			

			$q .= " LIMIT ".$p['Page_Start'].",".$p['Per_Page']." ";

			//end of Pageing

			

			$qr = mysql_query($q) or die('Error: '.mysql_error());

			

			?>



         <tr>

                   	<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<button type="button" id="as" name="as" onClick="Report_all_collectionDetails();">Go Back</button></td>

                </tr> 

        



        

          <table  width="100%" cellspacing="0" style="border-top:10px solid #777;">

            

            <tr>

              <th width="10%">Date</th> 	 	 	 	 	 	 	

              <th width="25%">Name</th>

              

			   

              

              <th width="31%">Remarks</th>

              

              <th width="15%">Details</th>

              

			  <th width="13%" style="text-align:right;">Amount</th>

               

            </tr>

            <?php					  

        	$i=1;

            

			while ($rows=mysql_fetch_array($qr))

            {   

			$rows['amt'] = abs($rows['amt']);

			?>

            <tr <?php if(($i%2)==0) echo 'class="alt_new"';?>>

             

              <td><?=date("d-M-Y",strtotime($rows['date']));?></td>

              <td><?=$rows['name']; ?></td>

               

			  <td><?=$rows['remarks']; ?></td>

              	 

                <td><?php if($rows['paid']>0)

			  		echo $rows['paid_by_name']; 

			  	?></td>

                 

              

               <td style="text-align:right; font-size:12px; font-weight:bold;"><?php $t+=$rows['amt']; echo number_format($rows['amt'],0); ?>/-</td>

                   

               

            </tr>

            <?php

			$i++;

			}

       ?>

       <tr style="background-color:#FF0;" >

             

                <td colspan="4" style="text-align:right;">Total : </td>

              

               <td style="text-align:right; font-size:12px; font-weight:bold;"><?php echo number_format($t,2); ?>/-</td>

                   

               

            </tr>

          </table>

                 

                

                 

                 

                

                  

                <tr>

                   	<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<button type="button" id="as" name="as" onClick="Report_all_collectionDetails();">Go Back</button></td>

                </tr> 

                 

            </table>

             <?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{ ?>

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

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

                   <?php } ?>

                   

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

		</form>

        </div>

        

        </div>

        <?php

	}

}



?>

</div>

