<style type="text/css">
	td, th {
		font-size: 11px!important;
		line-height:10px;
		padding:6px!important;
		border:1px solid #000!important;
		text-align:center!important;
	}
	table {
	    border-collapse: collapse!important;
	    width:100%1important;
	}
	.pettycash td {
	    	padding:14px!important;
	}
	.text-center {
	    text-align:center!important;
	}
</style>
<?php   
foreach($bill_range as $ra)
$branch = $ra->branch; 
$cur_date = date("d-m-Y");
     
?>
<table>
    <?php foreach($bill_range as $range)  { ?>
        <tr>
            <td class="text-center" colspan='7'><?php echo $branch ?> - <?php echo $cur_date ?> ( Starting Bill :  <?php echo $range->min_id ?> and End Bill : <?php echo $range->max_id ?> )  ---  Time : <?php echo date('H:i:s'); ?>  </td>
        </tr>
    <?php } ?>
    <tr>
        <td class="text-center" colspan='5'><strong> SALES  ESTIMATION  </strong></td>
        <td class="text-center" colspan='2'><strong> SALES  COMPARISION </strong></td>
    </tr>
    <tr>
        <td>PAYMENT TYPE</td>
        <td>AMOUNT</td>
        <td>ADVANCE</td>
        <td>CREDIT(SETTELED)</td>
        <td>SOFTWARE</td>
        <td>ENTERED</td>
        <td>DIFF</td>
    </tr>
    	
<?php $tot_amt = 0;
      $tot_adv = 0;
      $tot_cre = 0;
     
 foreach($all_mode_payment as $pay) {
    $tot_amt = $tot_amt + $pay->total_amount;
?>

<tr>                             
	<td class="text-center"><?php echo $pay->payment_types;?></td>
	<td  class="text-center"><?php echo round($pay->total_amount);?></td>
	<?php 
	    $current_date = date("Y-m-d");
	    $role_id = $this->session->userdata("role");
		$query=$this->db2->query("SELECT branch_slno,branch FROM outlet_deatils WHERE status='Active' and  branch='$branch'");
		$total_branch = $query->result_array();
		//$count =1;
		foreach ($total_branch as $brans) {
			$branch_code = $brans['branch_slno'];
			$branches = $brans['branch'];
			if ($branch == $branches){
			    	$table = 'product_billdetail'.$branch_code;
				    $table1 = 'payments_details'.$branch_code;
				    $query1 = $this->db2->query("SELECT sum(D.multi_payment) as advance FROM $table P inner join $table1 D on P.bill_id=D.bill_id WHERE P.bno !='0'  and P.status ='pending' and D.payment_types='$pay->payment_types' and  D.payment_date = '$current_date'");
			}
		}
		$row1 = $query1->row_array();
		$advance = $row1['advance'];
		$tot_adv =  $tot_adv + $advance;
		if($advance !='') {  
	?>
	<td><?php echo (round($advance)) ?></td>
	<?php } else { ?>
	<td>0</td>
	<?php } ?>
	<?php 
	    $current_date = date("Y-m-d");
	    $role_id = $this->session->userdata("role");
		$query=$this->db2->query("SELECT branch_slno,branch FROM outlet_deatils WHERE status='Active' and  branch='$branch'");
		$total_branch = $query->result_array();
		//$count =1;
		foreach ($total_branch as $brans) {
			$branch_code = $brans['branch_slno'];
			$branches = $brans['branch'];
			if ($branch == $branches){
			    	$table = 'product_billdetail'.$branch_code;
				    $table1 = 'payments_details'.$branch_code;
				    $query1 = $this->db2->query("SELECT sum(D.cr_settle_amt) as credit FROM $table P inner join $table1 D on P.bill_id=D.bill_id WHERE P.bno !='0' and P.mop='CREDIT' and P.status='closed' and D.payment_types='$pay->payment_types' and  D.cr_settle_date = '$current_date'");
			}
		}
		$row1 = $query1->row_array();
		$credit = $row1['credit'];
		$tot_cre =  $tot_cre + $credit;
		if($credit !='') {  
	?>
	<td><?php echo round($credit) ?></td>
	<?php } else { ?>
	<td>0</td>
	<?php } ?>
	<td><?php 
	$sotware_sales = $pay->total_amount + $advance + $credit;
	echo round($sotware_sales) ?></td>
<?php 
	    $current_date = date("Y-m-d");
        $query1 = $this->db2->query("SELECT sum(payment_amount) as amt FROM day_close_details WHERE payment_mode ='$pay->payment_types' and day_close_date ='$current_date' and branch ='$branch'");
		$row1 = $query1->row_array();
		$mode_pay = $row1['amt'];
		if($mode_pay !='') {  
	?>
	<td><?php echo round($mode_pay) ?></td>
	<?php } else { ?>
	<td>0</td>
	<?php } ?>
	<td><?php echo round($sotware_sales - $mode_pay) ?></td>
</tr>

<?php } ?>

<?php 
$total_social_sales=0;
     
 foreach($urbanpiper_data as $online) {
    $total_social_sales = $total_social_sales + $online->total_amount;
?>
<tr>                             
	<td class="text-center"><?php echo $online->payment_types;?></td>
	<td  class="text-center"><?php echo round($online->total_amount);?></td>
	<td  class="text-center">0</td>
	<td  class="text-center">0</td>
	<td  class="text-center"><?php echo round($online->total_amount);?></td>
	<td  class="text-center">0</td>
	<td  class="text-center">0</td>
</tr>	

<?php } ?>
 <tr>
     <td colspan="3"></td>
     <!--<td></td>-->
     <!--<td></td>-->
     <td>Total</td>
     <td><?php echo round($tot_amt + $tot_adv + $tot_cre + $total_social_sales) ?> </td>
     <td colspan="2"></td>
     <!--<td></td>-->
 </tr>
 
 <?php 
        $total_nc = 0;
        foreach($nc_details as $nc) {
        if($nc->payment_types != "" && $nc->payment_types == "NC") {
             $total_nc = $total_nc + $nc->total_amount;
        ?>
        <tr>
            <td colspan="3"></td>
             <!--<td></td>-->
             <!--<td></td>-->
            <td><?php echo $nc->payment_types; ?></td>
            <td><?php echo $nc->total_amount; ?> </td>
            <td colspan="2"></td>
            <!--<td></td>-->
        </tr>
        <?php }  else { ?>
        <tr>
            <td colspan="3"></td>
             <!--<td></td>-->
             <!--<td></td>-->
            <td>NC</td>
            <td>0 </td>
            <td colspan="2"></td>
            <!--<td></td>-->
        </tr>
 <?php } } ?>
 
 <?php 
        $total_credit = 0;
        foreach($credit_details as $credit) {
        if($credit->payment_types != "" && $credit->payment_types == "CREDIT") {
             $total_credit = $total_credit + $credit->total_amount;
        ?>
        <tr>
            <td colspan="3"></td>
             <!--<td></td>-->
             <!--<td></td>-->
            <td><?php echo $credit->payment_types; ?></td>
            <td><?php echo $credit->total_amount; ?> </td>
            <td colspan="2"></td>
            <!--<td></td>-->
        </tr>
        <?php }  else { ?>
        <tr>
            <td colspan="3"></td>
             <!--<td></td>-->
             <!--<td></td>-->
            <td>CREDIT</td>
            <td>0 </td>
            <td colspan="2"></td>
            <!--<td></td>-->
        </tr>
 <?php } } ?>
 
  <?php 
        $total_vocher = 0;
        foreach($vocher_entry as $voch) {
        if($voch->vocher_amt != "") {
             $total_vocher = $total_vocher + $voch->vocher_amt;
        ?>
        <tr>
            <td colspan="3"></td>
             <!--<td></td>-->
             <!--<td></td>-->
            <td>VOCHER</td>
            <td><?php echo $voch->vocher_amt; ?> </td>
            <td colspan="2"></td>
            <!--<td></td>-->
        </tr>
        <?php }  else { ?>
        <tr>
             <td colspan="3"></td>
             <!--<td></td>-->
             <!--<td></td>-->
            <td>VOCHER</td>
            <td>0 </td>
            <td colspan="2"></td>
            <!--<td></td>-->
        </tr>
 <?php } } ?>
 <tr>
     <td colspan="3"></td>
     <!--<td></td>-->
     <!--<td></td>-->
    <td>Grand Total</td>
    <td><?php echo round($tot_amt + $tot_adv + $total_nc + $total_credit + $total_vocher + $total_social_sales) ?> </td>
    <td colspan="2"></td>
    <!--<td></td>-->
 </tr>

 
 
 
 
</table>

 <br/>
 <br/>
 <table>
    <tr>
        <td colspan='5'> <strong>CUSTOMER DATA COLLECTION</strong></td>
    </tr>
    <tr>
        <td>SL.NO</td>
        <td>DATE</td>
        <td>TOTAL NO OF BILLS</td>
        <td>DATA COLLECTED</td>
        <td>DATA NOT COLLECTED</td>
    </tr>
    <?php
    $count = 1;
     foreach($customer_data as $cust) { 
          //$date_of_edit__bill = date('d-m-Y',strtotime($edit->edit_date));
     ?>
    <tr>
        <td><?php echo $count ?></td>
        <td><?php echo $cur_date ?></td>
        <td><?php echo $cust->total_collected ?></td>
        <td><?php echo $cust->collected ?></td>
        <td><?php echo $cust->not_collected ?></td>
        
    </tr>
    
    <?php $count++; } ?>
</table>
<br/>
<br/>
<table>
    <tr>
        <td colspan='5'> <strong>ORDER EDIT / MODIFY DETAILS </strong></td>
    </tr>
    <tr>
        <td>EDITED DATE</td>
        <td>ORDER TYPE</td>
        <td>BILL NO</td>
        <td>INVOICE NO</td>
        <td>STATUS</td>
    </tr>
    <?php
     foreach($all_edit_bills as $edit) { 
          $date_of_edit__bill = date('d-m-Y',strtotime($edit->edit_date));
     ?>
    <tr>
        <td><?php echo $date_of_edit__bill ?></td>
        <?php if($edit->bno !='0' &&  $edit->mop !='CREDIT') { ?>
        <td>ADVANCE</td>
        <?php } else if($edit->bno !='0' &&  $edit->mop !='CREDIT') { ?>
        <td>CREDIT</td>
        <?php } else { ?>
            <td>COUNTER</td>
        <?php } ?>
        <td><?php echo $edit->bill_no ?></td>
        <td><?php echo $edit->invoice_no ?></td>
        <td><?php echo $edit->status ?></td>
    </tr>
    <?php } ?>
</table>
<br/>
<br/>
<table>
    <tr>
        <td colspan="6"><strong>CREDIT ORDERS DETAILS</strong></td>
    </tr>
    <tr>
        <td>ORDER DATE</td>
        <td>ORDER TYPE</td>
        <td>CUSTOMER NAME</td>
        <td>CUSTOMER GST</td>
        <td>SETTELEMT DATE</td>
        <td>STATUS</td>
    </tr>
    <?php
     foreach($credit_bills as $credit) { 
         $current_date = date("Y-m-d");
        $date_of_bill = date('d-m-Y',strtotime($credit->bill_date));
        $date_of_bill_setteled = date('d-m-Y',strtotime($credit->stlmnt_date));
        if($credit->stlmnt_status =='pending' || $credit->stlmnt_status =='0') {
     ?>
    <tr>
        <td><?php echo $date_of_bill ?></td>
        <?php if($credit->bill_date =='$current_date') { ?>
        <td>new order taken</td>
        <?php } else { ?>
         <td>Existing order</td>
         <?php } ?>
        <td><?php echo $credit->cust_name ?></td>
        <td><?php echo $credit->cust_gst ?></td>
        <td><?php echo $date_of_bill_setteled ?></td>
        <td><?php echo $credit->stlmnt_status ?></td>
    </tr>
    <?php } } ?>
</table>

<br/>
<br/>

<table>
    <tr>
        <td colspan="5"> <strong>CANCELLED BILL DETAILS</strong></td>
    </tr>
    <tr>
        <td>BILL DATE</td>
        <td>CANCELLED DATE</td>
        <td>INVOICE NO</td>
        <td>BILL AMOUNT</td>
        <td>REMARKS</td>
    </tr>
    <?php
     foreach($cancelled_bills as $cancel) { 
         $current_date = date("Y-m-d");
        $date_of_bill = date('d-m-Y',strtotime($cancel->invoice_date));
        $date_of_bill_cancelled = date('d-m-Y',strtotime($current_date));
     ?>
    <tr>
        <td><?php echo $date_of_bill ?></td>
        <td><?php echo $date_of_bill_cancelled ?></td>
        <td><?php echo $cancel->invoice_no ?></td>
        <td><?php echo round($cancel->total_paid_amount) ?></td>
        <td><?php echo $cancel->msg ?></td>
    </tr>
    <?php }  ?>
</table>

<br/>
<br/>

<table>
    <tr>
        <td colspan="6"> <strong>NC BILL DETAILS</strong></td>
    </tr>
    <tr>
        <td>BILL DATE</td>
        <td>INVOICE NO</td>
        <td>BILL AMOUNT</td>
        <td>CUSTOMER NAME</td>
        <td>PHONE NO</td>
        <td>APPROVED BY</td>
    </tr>
    <?php
     foreach($nc_bills as $nobill) { 
         $current_date = date("Y-m-d");
        $date_of_bill = date('d-m-Y',strtotime($nobill->invoice_date));
     ?>
    <tr>
        <td><?php echo $date_of_bill ?></td>
        <td><?php echo $nobill->invoice_no ?></td>
        <td><?php echo round($nobill->total_paid_amount) ?></td>
        <td><?php echo $nobill->nc_cust_name ?></td>
        <td><?php echo $nobill->nc_cust_phone ?></td>
        <td><?php echo $nobill->nc_approved_by ?></td>
    </tr>
    <?php }  ?>
</table>

<br/>
<br/>

<table>
    <tr>
        <td colspan="6"> DISCOUNT BILL DETAILS</td>
    </tr>
    <tr>
        <td>BILL DATE</td
        <td>INVOICE NO</td>
        <td>BILL AMOUNT</td>
        <td>DISCOUNT AMOUNT</td>
        <td>GIVEN BY</td>
        <td>GIVEN TO</td>
    </tr>
    <?php
     foreach($discount_bills as $discount) { 
         $current_date = date("Y-m-d");
        $date_of_bill = date('d-m-Y',strtotime($discount->invoice_date));
        //$date_of_bill_cancelled = date('d-m-Y',strtotime($current_date));
     ?>
    <tr>
        <td><?php echo $date_of_bill ?></td>
        <td><?php echo $discount->invoice_no ?></td>
        <td><?php echo round($discount->total_paid_amount) ?></td>
        <td><?php echo $discount->disc_total_amt ?></td>
        <td><?php echo $discount->disc_given_by ?></td>
        <td><?php echo $discount->disc_given_to ?></td>
        
    </tr>
    <?php }  ?>
</table>

