<?php

//Include the main TCPDF library (search for installation path).
$this->mypdf_class->tcpdf();

global $tbm_client_data1;
global $tbm_trans_data1;
global $yy;

$tbm_client_data1 = $tbm_client_data;
$tbm_trans_data1 = $tbm_trans_data;

// Extend the TCPDF class to create custom Header and Footer
class MYPDF extends TCPDF 
{
    //Page header
    public function Header() 
    {
    	global $tbm_client_data1;

  		$inv_no = $tbm_client_data1[0]['tbm_bill_no'];
		$b_date = ($tbm_client_data1[0]['tbm_bill_date']=="1970-01-01")?"":date('d-m-Y',strtotime($tbm_client_data1[0]['tbm_bill_date']));
		$t_date = ($tbm_client_data1[0]['tbm_trail_date']=="1970-01-01")?"":date('d-m-Y',strtotime($tbm_client_data1[0]['tbm_trail_date']));
		$d_date = ($tbm_client_data1[0]['tbm_del_date']=="1970-01-01")?"":date('d-m-Y',strtotime($tbm_client_data1[0]['tbm_del_date']));

		$client_acc_no = $tbm_client_data1[0]['client_accno'];
		$client_name = $tbm_client_data1[0]['client_name'];
		$client_mob = $tbm_client_data1[0]['client_mobile1'];

		$tbl_header = "";
		$tbl_header .= <<<EOD

		
		<table border="0" style="border-top:13px solid #000;border-left:13px solid #000;border-right:13px solid #000;" cellpadding="1">
		<table border="0" style="text-align:center; width: 100%;" cellpadding="1">
		<br><br><tr>
			<td width="30%" style="padding-top:5px; margin-top:10px; text-align:left">&nbsp;&nbsp;&nbsp;<u><b>TAX INVOICE</b></u></td>			
			<td width="40%" rowspan="2"><img src="public/assets/images/RAJASAB.png" width="600%" height="80px" /></td>
			<td width="30%" style="font-size:8px;">Tel. : 9819133272</td>
		</tr>
		<tr>
			<td width="30%" style="padding-top:5px; margin-top:10px; text-align:left"></td>			
			
			<td width="30%" style="font-size:8px;"></td>
		</tr>
		<tr>
			<td width="30%" style="padding-top:5px; margin-top:10px; text-align:left"></td>			
			<td width="40%" style="font-size:9px;">SHOP 47B, Atria Mall, Worli,<br>
					 Mumbai 400018.</td>
			<td width="30%" style="font-size:8px;"></td>
		</tr>
		<tr>
			<td width="30%" style="padding-top:5px; margin-top:10px; text-align:left"></td>			
			<td width="40%"></td>
			<td width="30%" style="font-size:8px;"></td>
		</tr>		
		</table>	
		
		<table border="0" style="text-align:center; font-size:10px;">
			<tr>
				<td style="width:13%">Name : </td>
				<td style="width:31%; text-align:left">$client_name</td>
				<td style="width:12%; text-align:left">Inv. No. : </td>
				<td style="width:16%; text-align:left">$inv_no</td>
				<td style="width:12%; text-align:left">Date : </td>
				<td style="width:16%; text-align:left">$b_date</td>
			</tr>
			<tr><td colspan="6"></td></tr>
			<tr>			
				<td style="">&nbsp;Mobile :</td>
				<td style="text-align:left">$client_mob</td>
				<td style="text-align:left">TR DT : </td>
				<td style="text-align:left">$t_date</td>
				<td style="text-align:left">DEL DT :</td>
				<td style="text-align:left">$d_date</td>
			</tr>
			<tr><td colspan="6"></td></tr>
		</table>

		<table  border="0" cellpadding="3" style="margin-top:0px;">
			<tr style="font-size:10px; color:#fff; background-color:#000">
				<th style="width:7%; text-align:right;">No.</th>
				<th style="width:75%; text-align:left;" colspan="5">Description</th>
				<th style="width:18%;">Amount</th>
			</tr>
		</table>	

		</table>		

EOD;
		
		$this->SetFont('comic', 'B', 12);
		$this->writeHTML($tbl_header, true, false, false, false, '');
		$yy = $this->GetY();
		$yy = $yy - 10;
		
		$style = array('width' => 3.8);
		$style1 = array('width' => 0.2);

		


		//$pdf->Line(5, 10, 80, 30, $style);
		
		$this->line(5,$yy,5,161, $style);
        $this->line(15.5,$yy,15.5,161, $style1);
        //$this->line(50,$yy,50,150, $style1);
        //$this->line(83,$yy,83,150, $style1);
        //$this->line(105.5,$yy,105.5,150, $style1);
        $this->line(128,$yy,128,161, $style1);
        $this->line(155,$yy,155,161, $style);        

        $this->SetTopMargin($yy + 4);
    }

    // Page footer
    public function Footer() 
    {
    	global $tbm_client_data1;

  	// 		$fb_st_total = 0;			
			// foreach($tbm_trans_data1 as $key => $value) 
			// {
				
			// 		$fb_st_total = $fb_st_total + $value['tbt_final_amt'];
			// }

     	$tbm_final_total = $tbm_client_data1[0]['tbm_final_total'];
     	$tbm_subtotal = $tbm_client_data1[0]['tbm_subtotal'];
     	$tbm_discount = $tbm_client_data1[0]['tbm_discount'];
		$tbm_advance = $tbm_client_data1[0]['tbm_advance'];
		$tbm_balance = $tbm_client_data1[0]['tbm_balance'];

        $tbl_footer = "";
		$tbl_footer .= <<<EOD

		<table border="0" style="border:13px solid #000;" cellpadding="0">
		
		<table  border="0" cellpadding="3" style="margin-top:0px;">
			<tr style="font-size:9px;font-weight:normal;">
				<td style="width:7%;text-align:right; border-right:1px solid #000; border-top:1px solid #000; border-bottom:1px solid #000"><br><br></td>
				
				<td colspan="5" style="width:75%;text-align:right; border-right:1px solid #000; border-top:1px solid #000;color:red; border-bottom:1px solid #000"><br><br><b>Sub Total</b></td>
				<td style="width:18%;color:red;border-top:1px solid #000;border-bottom:1px solid #000; text-align:right"><br><br><b>$tbm_subtotal</b>&nbsp;&nbsp;&nbsp;&nbsp;</td>
			</tr>
			<tr style="font-size:9px;font-weight:normal;">
				<td style="width:7%;text-align:right; border-right:1px solid #000; border-top:1px solid #000; border-bottom:1px solid #000"></td>
				
				<td colspan="5" style="width:75%;text-align:right; border-right:1px solid #000; border-top:1px solid #000;color:red; border-bottom:1px solid #000"><b>Discount</b></td>
				<td style="width:18%;color:red;border-top:1px solid #000;border-bottom:1px solid #000; text-align:right"><b>$tbm_discount</b>&nbsp;&nbsp;&nbsp;&nbsp;</td>
			</tr>
			<tr style="font-size:9px;font-weight:normal;">
				<td style="width:7%;text-align:right; border-right:1px solid #000; border-top:1px solid #000; border-bottom:1px solid #000"></td>
				
				<td colspan="5" style="width:75%;text-align:right; border-right:1px solid #000; border-top:1px solid #000;color:red; border-bottom:1px solid #000"><b>Advance</b></td>
				<td style="width:18%;color:red;border-top:1px solid #000;border-bottom:1px solid #000; text-align:right"><b>$tbm_advance</b>&nbsp;&nbsp;&nbsp;&nbsp;</td>
			</tr>
			<tr style="font-size:9px;font-weight:normal;">
				<td style="width:7%;text-align:right; border-right:1px solid #000; border-top:1px solid #000; border-bottom:1px solid #000"></td>
				
				<td colspan="5" style="width:75%;text-align:right; border-right:1px solid #000; border-top:1px solid #000;color:red; border-bottom:1px solid #000"><b>Balance</b></td>
				<td style="width:18%;color:red;border-top:1px solid #000;border-bottom:1px solid #000; text-align:right"><b>$tbm_balance</b>&nbsp;&nbsp;&nbsp;&nbsp;</td>
			</tr>
			
		</table>


		<table>
			<tr>
			<td style="font-size:9px;font-weight:normal; text-indent:10px;">GSTIN : 27AIOA9210G1ZE</td>
			<td style="font-size:9px; text-align:center"></td>
			<td style="font-size:10px; text-align:right">For Rajasab&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
			</tr>
			
			<tr><td colspan="3"></td></tr>
			<tr><td colspan="3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Terms & Conditions</td></tr>
			<tr style="font-size:9px;font-weight:normal;">
				<td colspan="3" style="text-align:left;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1) No refund.</td>
			</tr>
		</table>
		<table border="0">
			<tr style="font-size:8px;font-weight:normal;">
				<td width="72%" colspan="2" style="text-align:left;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;2)  We hold no responsibility for clothes not taken delivery within 2 months.</td>
				<td width="27%" style="font-size:10px; text-align:left;">&nbsp;&nbsp;&nbsp;</td>
			</tr>
			<tr><td colspan="3"></td></tr>
		</table>
		</table>


EOD;

		$this->SetFont('comic', 'B', 12);
		//$this->SetY(-15);
		
		//$this->Cell(0, 0, $tbl_footer, 0, false, 'C', 0, '', 0, false, 'T', 'M');

		//$this->Cell(0, 0, 'Page '.$this->getAliasNumPage().'/'.$this->getAliasNbPages(), 0, false, 'C', 0, '', 0, false, 'T', 'M');
		//$this->writeHTML($tbl_footer, true, false, false, false, '');
		//$this->writeHTML($tbl_footer, true, true, true, true);
		
		$this->writeHTMLCell(150, 100, 5, 146, $tbl_footer, 0, 0, 0, true, 'P', true);

		//$yy = $yy - 10;
               
    }
}

// create new PDF document
//$pdf = new MYPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
$pdf = new MYPDF('P', PDF_UNIT, array('160','200'), true, 'UTF-8', false);
// set document information
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor('Imran Khan');
$pdf->SetTitle('TAILORING BILL');
$pdf->SetSubject('TAILORING BILL');
// $pdf->SetKeywords('TCPDF, PDF, example, test, guide');

// set default header data
$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE, PDF_HEADER_STRING);

// set header and footer fonts
$pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));

// set default monospaced font
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);

// set margins
$pdf->SetMargins(5, PDF_MARGIN_TOP, 5);
$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
$pdf->SetFooterMargin(10);

// set auto page breaks
$pdf->SetAutoPageBreak(TRUE, 65);

// set image scale factor
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);

// set some language-dependent strings (optional)
if (@file_exists(dirname(__FILE__).'/lang/eng.php')) {
    require_once(dirname(__FILE__).'/lang/eng.php');
    $pdf->setLanguageArray($l);
}

// ---------------------------------------------------------

// set font
// $pdf->SetFont('times', 'BI', 12);

$pdf->SetFont('Helvetica', '', 8);


$tbl = "";
$pdf->AddPage();

$pdf->SetFont('comic', 'B', 12);

$tbl .= <<<EOD

	<table border="0" style="border-left:13px solid #000;border-right:13px solid #000;" cellpadding="1">
			
EOD;

$tbl .= <<<EOD
	
				<table  border="1" cellpadding="3" style="margin-top:0px;">
					
EOD;


			$cnt = count($tbm_trans_data);
			foreach($tbm_trans_data as $key => $value) 
			{
				
				$no = $key+1;
				$app_name = $value['app_name'];
				$desc = $value['tbt_desc'];	
				$hsn = $value['app_hsn_code'];
				$qty = number_format($value['tbt_qty'],2);
				$rate = number_format($value['tbt_rate'],2);
			
				$final_amt = number_format($value['tbt_final_amt'],2);			

				$tbl .= <<<EOD
						<tr align="center" style="font-size:8px;font-weight:normal;">
							<td width="7%" style="text-align:right; ">$no</td>
							<td width="75%" colspan="5" align="left" >$app_name </td>
							<td width="18%" align="right">$final_amt&nbsp;&nbsp;&nbsp;&nbsp;</td>
						</tr>
EOD;
			}


$tbl .= <<<EOD

						



	</table>
		
	</table>
EOD;

$pdf->writeHTMLCell(152, 10, 4, 67, $tbl, 0, 0, 0, true, 'P', true);	
//$pdf->writeHTML($tbl, true, false, false, false, '');

//$height = $pdf->getY();
	//echo $height;
	//$obj_pdf->writeHTML($height, true, false, false, false, '');

//$pdf->Output($file_name, 'I');	
		

//$pdf->writeHTML($tbl, true, false, false, false, '');

// ---------------------------------------------------------

//Close and output PDF document
//ob_end_clean();
$pdf->Output('TAILORING_BILL_PRINT.pdf', 'I');

//============================================================+
// END OF FILE
//============================================================+
