
<?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);


 $personel = 1;
 $customer = $captured = $pickup= $shop = $status = $cusphone ='';
 $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'];
		$personel = $row['personel'];
		$cusphone =  $row['cphone'];
    }

 }

 $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'];

    }
 }
 
 $personel = ucwords(strtolower(Personel_name( $personel )));
$html = '';

 

$html .=   '

  
							
<p align="center"> <img   id="itemphoto" src="images/shoplogos/5.jpg"  height="200px"   /> </p> 
 
<p align="center" style="font-size:11px;padding:0px">   Address: '. $address_line_2.', '. $address_line_3.'    </p> 
 
<p align="center" style="font-size:13px;padding:0px"> Customer: '. ucwords(strtolower($customer)).' , Phone: '.$cusphone.' <br /> JOB CARD </p> 

 
 
  <p align="center" style="font-size:11px">#'.$barcode.' Date: '.date('d-M-Y',strtotime($captured)).' </p>
  



';
  

$total = 0;

 

$categorydata = barcode_jobs_for_receipt($barcode);


//print_r($categorydata);

//exit();
if(!empty($categorydata)){
    $html  .= ' <table     width="100%" style="font-size:12px">

    <tr>   <td> <b>Task </b></td> <td>  <b>Price</b></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" ><hr />  </td> 
					 

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

					</tr>
					<tr>
                        
						 <td colspan="2" ><hr />  </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 colspan="2" ><hr />  </td> 
					 

					</tr>
				 <tr>
                        
						 <td  >  Total   </td>
                         <td>   <b >'.number_format( $total).'  </b></td> 
					 </tr>
 <tr>
                        
						 <td colspan="2" ><hr />  </td> 
					 

					</tr>					 
                     

                  <tr>
                     <td >    Balance  </td>
                      <td>  <b >'.number_format(  $bal ).'    </td> 
                  </tr>
                  
                  ';
				  
				   

                  $html .= '</table>';
                }
$html .= '<p align="center">  
                           Ready on <b style="font-size:15px" >'. strtoupper(date('D', strtotime($pickup))).' </b>of  '.date('d-M-Y', strtotime($pickup)).'  @ <b style="font-size:15px" >5:00PM</b></p>
                  
<barcode code="'.$barcode.'"  type="I25"    text="1"  size="1.5"/> 

<p align="center" style="font-size:13px">     '.$barcode.'   </p>

<table     width="100%"  >

    <tr>   <td> <p style="font-size:12px" >
    	PAYMENT OPTIONS<br />   
    AIRTEL : *185*9#, MERCHANT ID: <b>43 53 132 </b>  <br />  
    MTN       : *165*3# MERCHANT ID: <b> 15 19 95</b> </p> 
	<p style="font-size:10px" > <br />
	THANK YOU FOR SUPPORTING KAMPANI SHOES & BAGS CLINIC </p> 
    </td> 
	
	</tr>
 
	

	</table>
 
<p align="center" style="font-size:11px"> <b> Terms and Conditions!   Scan below or  

<a href="https://kampanisbc.com/thesite/rterms/">click here </a></b>  <img   style =" padding: 0px;" id="itemphoto" src="qr-code300.png"  height="120px"   /> </p> ';
/*
	 <tr>   <td>  PLEASE NOTE:  
	 Work will commence upon partial / full payment of items received. <br />

 
The company will not be liable for any items not picked after 30 days of pickup date quoted.
	  </td> 
	
	</tr> */
	$html .= '
 
<p align="center" style="font-size:12px">   Served by:   '.$personel .'    <br /> I\'ll heel you ,I\'ll save your sole , I\'ll even dye for you </p> 




              
				 ';
 
 
 
 
	$mpdf = new \Mpdf\Mpdf(['mode' => 'utf-8','format' =>  array(80, 279), 'margin_left' => 1, 'margin_top' => 0, 'margin_right' => 0,  'margin_bottom' => 0,  'margin_header' => 0  ]);
    $stylesheet = file_get_contents('table.css'); 
    $mpdf->WriteHTML($stylesheet,\Mpdf\HTMLParserMode::HEADER_CSS); 
    $mpdf->SetWatermarkImage(
        'images/shoplogos/water.jpg',
        0.05,
        '',
        array(10,10)
    ); 
    $mpdf->showWatermarkImage = false; 
	
    $mpdf->WriteHTML($html );

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