
<?php
	include("my_functions.php");

require_once __DIR__ . '/vendor/autoload.php';

$actual_link = 'https://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
$parts = explode('customreceipt/' , $actual_link);

 
$barcode = 0;
if(!empty($parts)){
    
    $barcode = $parts[1];
     

}else exit();
 
$jobdata = getjob_by_barcode($barcode);

 
 
 $customer = $captured = $pickup= $shop = $status ='';
 $kx =$kxm = 0;
 if(!empty($jobdata)){
    foreach($jobdata as $row){
        $customer =$row['customer_name'];
        $pickup  = $row['pickon'];
        $status  = $row['status'];
        $captured = $row['value_date'];
        $barcode  = $row['parent_bar_code'];
        $shop  = $row['shop'];
        $kx = $row['bill'];
        $kxm = $row['amount'];
    }

 }

 $shopdata = brachdetails($shop);

 $full_name =  $logo = $address_line_1 =  $address_line_2 =  $address_line_3 =  $phone =  $city = '';
 
 if(!empty($shopdata)){
    foreach($shopdata as $row){
        $full_name = $row['full_name'];
        $logo = $row['logo_file'];
        $address_line_1 = $row['address_line_1'];
        $address_line_2 = $row['address_line_2'];
        $address_line_3 = $row['address_line_3'];
        $phone = $row['phone'];
        $city = $row['city'];

    }
 }
 

$html = '';

 

$html .=   '

<table class="table table-bordered"  cellspacing="0" cellspadding="0" width="100%">
<thead>
<tr> 
 

<th scope="col"   >  
							
<h1 align="center"> <img class="img-thumbnail" id="itemphoto" src="images/shoplogos/'.$logo.'"     > </h1> 
 
<h5 align="center">   Address: '. $address_line_2.', '. $address_line_3.' , '. $address_line_2.'  <br />Phone Number: '.$phone.'</h5> 
 
<h5 align="center"> Customer: '.$customer.' </h5> 
 

<h3 align="center"> JOB CARD </h3> 

 
 
  Date: '.$captured.'
 

</tr>
</thead>

 
</table>



';
  

$total = 0;

 

$categorydata = barcode_jobs_for_receipt($barcode);


//print_r($categorydata);

//exit();
if(!empty($categorydata)){
    $html  .= ' <table class="table table-bordered table-sm"  cellspacing="0" cellspadding="0" width="100%">

    <tr>   <td> Item</td> <td>  Total</span></td>  </tr>
    ';

 $bill = 0;

foreach ($categorydata as $row)
				 {
                    $recept_number =  $row['receipt_number']; 
                    $receipt_items = receipt_item_by_barcodes2($recept_number); 
                    $rowspan = sizeof($receipt_items) +1;
					$change =   $row['bill']- $row['amount'] ;
                    $bill =$row['bill'];
					if($change  >  0){
						$change = 0;

					}

                     
					
					 
					

                   $htmly = ' ';
				   $html .= '<tr>   
					
                    
					 
					
					
					<td colspan="2" >'.strtoupper($row['jobdata']).' , '.$row['rpt_name'].' <p align="left">  # '.$row['receipt_number'].'    </p></td>     
					
                    
					  
					

					</tr>';
                    $sub_total = 0;

                    foreach($receipt_items as $items){
                        $sub_total  += $items['sell_price'];
                       

                        $html .= '<tr>
                        
						 <td >'.$items['job_name'].' </td>
                         <td  >'.number_format(intval($items['sell_price'])).' </td> 
					
					  
					 
					  
					

					</tr>';
                    }
					 
					
					
					$html .=$htmly; 

                    //$html .= '';
                    $total += $sub_total;




					
					
					
					 
				   
			 
				 }
                 $bal = $kxm -$total;
				 $htmlx ='';

                 if(($bal) > 0){ $bal = 0;  }
                 $html .= '<tr>
                        
						 <td  >  Total   </td>
                         <td>   <b >'.number_format( $total).'  </b></td> 
					 </tr> 
                     

                  <tr>
                     <td >  <p align="right">  Balance </p> </td>
                      <td> <p align="right"> <b >'.number_format(  $bal ).'   </p></td> 
                  </tr>
                  
                  ';
				  
				   

                  $html .= '</table>';
                }
$html .= '<p align="center">
                           Ready on <b style="font-size:30px" >'. strtoupper(date('D', strtotime($pickup))).' </b>of  '.$pickup.'  @ <b style="font-size:20px" >5:00PM</b></p>
                  
<barcode code="'.$barcode.'"  type="I25"    text="1"  size="4"/><br />
<p align="center" style="font-size:16px"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;   &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; '.$barcode.' <br />  </p>                
				 ';
 
 
 
 
	$mpdf = new \Mpdf\Mpdf(['mode' => 'utf-8','format' => 'A4' ]);
    $stylesheet = file_get_contents('mpdfcss.css'); 
    $mpdf->WriteHTML($stylesheet,\Mpdf\HTMLParserMode::HEADER_CSS); 
    $mpdf->SetWatermarkImage(
        'images/shoplogos/water.jpg',
        0.05,
        '',
        array(10,10)
    ); 
    $mpdf->showWatermarkImage = true; 
    $mpdf->WriteHTML($html );

    
  // $mpdf->Output( 'devnote.pdf', 'F' ); 
	 $mpdf->Output();
	exit;
?>