<style>
@media print
{
.separate {page-break-before:always}
}
</style>
<?php
	include("my_functions.php");

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

 
$actual_link = 'https://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
$parts = explode('pastjobs/' , $actual_link);
 
$barcode = 0;
$thedate ='2023-07';
 

$sql = 'SELECT created_by as personel, c.phone as cphone, job.id, c.phone, s.order_status_name as status , parent_bar_code,  receipt_number, amount, value_date, shop, customer_name, pickon,  jobdata, bill, os.order_status_name , rpt_name, owner FROM job_receipt as job JOIN order_status as os on os.status_id = job.order_status JOIN  repair_jobtypes as jt on jt.rptid = job.job_type JOIN repair_owner_category as ow on ow.owid = owner_cat  join order_status s on s.status_id = order_status JOIN customers c on c.id = customer_id   WHERE job.value_date LIKE "'.$thedate.'%" ';
$jobdatax =  DB::query($sql); 
//print_r($jobdata);

//exit();
$html = '';//
$htmlPages = array();
foreach($jobdatax as $jobdata){
     $barcode = $jobdata['parent_bar_code'];
     $html = '';
     
     
 
 $personel = 1;
 $customer = $captured = $pickup= $shop = $status = $cusphone ='';
 $kx =$kxm = 0;
 if(!empty($jobdata)){
     $row = $jobdata;
    
        $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 .=   '

  
							
<p align="center"> <img   id="itemphoto" src="https://kampanisbc.com/pos/images/shoplogos/3.jpg"  height="200px"   /> </p> 
 
<p align="center" style="font-size:10px">   Address: '. $address_line_2.', '. $address_line_3.'    </p> 
 
<p align="center" style="font-size:14px"> Customer: '. ucwords(strtolower($customer)).' <br /> Phone: '.$cusphone.'</p> 
 

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

 
 
  <p align="center" style="font-size:10px">#'.$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>					 
                     
 
                  
                  ';
				  
				   

                  $html .= '</table>';
                }
$html .= '<p align="center">  
                           Ready on <b style="font-size:16px" >'. 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:14px">     '.$barcode.'   </p>

<table     width="100%" style="font-size:10px">

    <tr>   <td> 
    	PAYMENT OPTIONS<br />   
    AIRTEL MONEY : *185*9#, MERCHANT ID: 43 53 132  <br />  
    MTN MOMO PAY     : *165*3# MERCHANT ID: 15 19 95<br /><br />
	THANK YOU FOR SUPPORTING KAMPANI SHOES & BAGS CLINIC <br /> <br />  
    PLEASE NOTE:  </td> 
	
	</tr>
	
 

	<tr> </td> <hr /></td> </tr>
	
	 <tr>   <td> 
	 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>
	</table>
 

 
<p align="center" style="font-size:10px">   Served by:   '.$personel .'   </p> 
<p align="center" style="font-size:10px">   I\'ll heel you ,I\'ll save your sole , I\'ll even dye for you </p>
<p class="separate"> </p>
 

              
				 ';
				 
				 array_push($htmlPages , $html);
				 //$html = '';
				 
				 
 
 
}


 //echo $html;

 //exit();


 
 
	$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); 
	
	
	for($x =0; $x<sizeof($htmlPages); $x++){
	$mpdf->AddPage();
    $mpdf->WriteHTML($htmlPages[$x]);
	$header = array(
    'L' => array(
    ),
    'C' => array(
    ),
    'R' => array(
    'content' => 'page {PAGENO} of '.sizeof($htmlPages),
    'font-family' => 'sans',
    'font-style' => '',
    'font-size' => '9', /* gives default */
    ),
    'line' => 1,
    );
    $footer = '
     
     
    ';  
    $mpdf->SetHTMLFooter($footer, $header,'O' );
 
}
/*



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