<?php
error_reporting(0);
// Include the main TCPDF library (search for installation path).
$this->mypdf_class->tcpdf();
 
global $sales_trans_pdf ;
global $sales_data_pdf ;

$sales_data_pdf = $sales_data[0];
$sales_trans_pdf = $sales_trans;

class MYPDF extends TCPDF 
{
    //Page header
    public function Header() 
    {
    	global $sales_data_pdf ;
    	global $sales_trans_pdf ;

    	$sale_no = isset($sales_data_pdf['sale_entry_no']) ? strtoupper($sales_data_pdf['sale_entry_no']) : "";

		$sale_date = (!empty($sales_data_pdf['sale_entry_date']) && $sales_data_pdf['sale_entry_date'] != '1970-01-01') ? date('d-m-Y', strtotime($sales_data_pdf['sale_entry_date'])) : "";

		$sale_bill_date = (!empty($sales_data_pdf['sale_bill_date']) && $sales_data_pdf['sale_bill_date'] != '1970-01-01') ? date('d-m-Y', strtotime($sales_data_pdf['sale_bill_date'])) : "";

		$sale_buyer_order_date = (!empty($sales_data_pdf['sale_buyer_order_date']) && $sales_data_pdf['sale_buyer_order_date'] != '1970-01-01') ? date('d-m-Y', strtotime($sales_data_pdf['sale_buyer_order_date'])) : "";

		$sale_buyer_order_no = isset($sales_data_pdf['sale_buyer_order_no']) && $sales_data_pdf['sale_buyer_order_no'] > 0 ? $sales_data_pdf['sale_buyer_order_no'] : "";

		$sale_delivery_note = isset($sales_data_pdf['sale_delivery_note']) ? strtoupper($sales_data_pdf['sale_delivery_note']) : "";

		$sale_dispatch_doc_no = isset($sales_data_pdf['sale_dispatch_doc_no']) ? strtoupper($sales_data_pdf['sale_dispatch_doc_no']) : "";

		$sale_dispatched_through = isset($sales_data_pdf['sale_dispatched_through']) ? strtoupper($sales_data_pdf['sale_dispatched_through']) : "";

		$sale_destination = isset($sales_data_pdf['sale_destination']) ? strtoupper($sales_data_pdf['sale_destination']) : "";

		$sale_terms_of_delivery = isset($sales_data_pdf['sale_terms_of_delivery']) ? strtoupper($sales_data_pdf['sale_terms_of_delivery']) : "";

		$sale_delivery_note_date = (!empty($sales_data_pdf['sale_delivery_note_date']) && $sales_data_pdf['sale_delivery_note_date'] != '1970-01-01') ? date('d-m-Y', strtotime($sales_data_pdf['sale_delivery_note_date'])) : "";

		$fin_year = isset($sales_data_pdf['sale_fin_year']) ? strtoupper($sales_data_pdf['sale_fin_year']) : "";
		
		$address = isset($sales_data_pdf['acc_billing_address']) ? strtoupper($sales_data_pdf['acc_billing_address']) : "";

		$pan_no = isset($sales_data_pdf['acc_pan']) ? $sales_data_pdf['acc_pan'] : "";

		$gst_no = isset($sales_data_pdf['acc_gst']) ? $sales_data_pdf['acc_gst'] : "";

		$state_name = isset($sales_data_pdf['state_name']) ? $sales_data_pdf['state_name'] : "";

		$state_code = isset($sales_data_pdf['state_code']) ? $sales_data_pdf['state_code'] : "";

		$city_name = isset($sales_data_pdf['city_name']) ? $sales_data_pdf['city_name'] : "";

		$acc_name = isset($sales_data_pdf['acc_name']) ? $sales_data_pdf['acc_name'] : "";

		$acc_days = isset($sales_data_pdf['acc_days']) ? $sales_data_pdf['acc_days'] : "";

		$acc_discount = isset($sales_data_pdf['acc_discount']) ? $sales_data_pdf['acc_discount'] : "";

		$shipping_name = isset($sales_data_pdf['shipping_name']) ? $sales_data_pdf['shipping_name'] : "-";
		$shipping_mobile = isset($sales_data_pdf['shipping_mobile']) ? $sales_data_pdf['shipping_mobile'] : "-";
		$shipping_address = isset($sales_data_pdf['shipping_address']) ? $sales_data_pdf['shipping_address'] : "-";
		$shipping_gst = isset($sales_data_pdf['shipping_gst']) ? $sales_data_pdf['shipping_gst'] : "-";
		$shipping_pan = isset($sales_data_pdf['shipping_pan']) ? $sales_data_pdf['shipping_pan'] : "-";
		$shipping_state = isset($sales_data_pdf['shipping_state']) ? $sales_data_pdf['shipping_state'] : "-";
		$shipping_city = isset($sales_data_pdf['shipping_city']) ? $sales_data_pdf['shipping_city'] : "-";

		$acc_mobile = isset($sales_data_pdf['acc_mobile']) ? $sales_data_pdf['acc_mobile'] : "";
		$acc_address = isset($sales_data_pdf['acc_address']) ? $sales_data_pdf['acc_address'] : "";
		$acc_gst = isset($sales_data_pdf['acc_gst']) ? $sales_data_pdf['acc_gst'] : "";
		$acc_pan = isset($sales_data_pdf['acc_pan']) ? $sales_data_pdf['acc_pan'] : "";
		$acc_state = isset($sales_data_pdf['acc_state']) ? $sales_data_pdf['acc_state'] : "";
		$acc_city = isset($sales_data_pdf['acc_city']) ? $sales_data_pdf['acc_city'] : "";
		
		$this->SetFont('Helvetica', 'c', 8);
		
		$tbl_header = "";
	
		$tbl_header .= <<<EOD

<table border="0" cellpadding="3" style="font-size:10px;">
	<tr>
		<td style="font-size:18px; text-align:center;"><b>Tax Invoice</b></td>
	</tr>
</table>	

<table border="1" cellpadding="3" style="font-size:10px;">
    <tr>
        <!-- LEFT SIDE (ROWSPAN = 4) -->
        <td width="50%" rowspan="4" height="90px">
            <table>
				<tr>
                    <td style="font-size:12px;"><b>EXPORTER</b></td>
                </tr>
                <tr>
                    <td style="font-size:12px;"><b>M/S: Ruchita Gems</b></td>
                </tr>
                <tr>
                    <td> D/8/3 Bhadran Nagar, 
						<br> Behind N L College, S V Road, 
						<br> Malad West, Mumbai 400064 
						<br>

						<table width="100%">
							<tr>
								<td align="left" width="58%">
									 E-Mail: ruchitagems0705@gmail.com
								</td>
								<td align="left">
									PAN: <b>AQDPS0123M</b>
								</td>
							</tr>
						</table>
						<br>
						<table width="100%">
							<tr>
								<td align="left" width="58%">
								 Tel No: 9869768852
								</td>
								<td align="left">
									GST NO.: <b>27AQDPS0123M1ZS</b>
								</td>
							</tr>
						</table>

						<br> State Code: 27, Dis code: 483
                    </td>
                </tr>
            </table>
        </td>

        <!-- MIDDLE -->
        <td width="25%">
			INVOICE NO AND DATE<br>
			<table width="100%">
				<tr>
					<td align="left">
						<b>EXP-$sale_no/$fin_year</b>
					</td>
					<td align="right">
						<b>DT-$sale_date</b>
					</td>
				</tr>
			</table>
		</td>

		<td width="25%">EXPORTER'S REFERENCE<br><b>$sale_date</b><br>UNDER CHAPTER $</td>
    </tr>

    <tr>
        <td width="25%">BUYER’S ORDER NO & DATE<br><b>$sale_buyer_order_no, $sale_buyer_order_date</b><br>
		<b>GST NO.</b>
		</td>
        <td width="25%">LUT NO. <br><b>AD2703240006488</b>
		</td>
    </tr>

	<tr>
        <td width="25%">OTHER REFERENCE(S)<br><b></b>
		</td>
        <td width="25%">IEC.CODE <br><b>AQDPS0123M</b>
		</td>
    </tr>
</table>





<table border="0" cellpadding="3" style="font-size:10px;">
	<tr>
        <!-- LEFT SIDE (ROWSPAN = 4) -->
        <td width="50%" style="border-left:1px solid black; border-right:1px solid black; border-bottom:1px solid black;">
            <table>
				<tr>
                    <td>CONSIGNEE</td>
                </tr>
                <tr>
                    <td style="font-size:12px;"><b>$shipping_name</b></td>
                </tr>
                <tr>
                    <td> Mobile: $shipping_mobile 
						<br> $shipping_address 
						<br>
						<br>
						<br>
                    </td>
                </tr>
            </table>

			<table>
				<tr>
                    <td>DIECT PARCEL</td>
                </tr>
                <tr>
                    <td style="font-size:12px;"><b>$acc_name</b></td>
                </tr>
                <tr>
                    <td> Mobile: $acc_mobile 
						<br> $acc_address
						<br>
                    </td>
                </tr>
            </table>
        </td>

        <!-- MIDDLE -->
        <td width="50%" style="border-left:1px solid black; border-right:1px solid black; border-bottom:1px solid black;">
		<table>
				<tr>
                    <td>BUYER (IF OTHER THAN CONSIGNEE)</td>
                </tr>
                <tr>
                    <td style="font-size:12px;"><b>Tanaya Jewel Co. Ltd</b></td>
                </tr>
                <tr>
                    <td> <br><br>  318-10, Kosemachi Kofu, 
						<br><br>  Yamanashi, japan 400-0836
						<br><br>  Tel: 055-288-0691 
						<br><br>  PAN/IT No.: 055-288-0692
						<br><br>  Mobile: +81 8095660705
                    </td>
                </tr>
            </table>
			</td>
    </tr>


	<tr>
        <td width="25%" style="border-left:1px solid black; border-right:1px solid black; border-bottom:1px solid black;">PRE-CARRIER BY<br><br><b style="display:block; text-align:center;">BVC BRINKS</b></td>

		<td width="25%" style="border-left:1px solid black; border-right:1px solid black; border-bottom:1px solid black;">PLACE OF RECEIPT BY PRE-CARRIER<br><b style="display:block; text-align:center;">N.A.</b></td>

        <td width="25%" style="border-left:1px solid black; border-right:1px solid black; border-bottom:1px solid black;">COUNTRY OF ORIGIN OF GOODS<br><b>INDIA</b></td>

		<td width="25%" style="border-left:1px solid black; border-right:1px solid black; border-bottom:1px solid black;">COUNTRY OF FINAL DESTINATION<br><b>JAPAN</b></td>
    </tr>

    <tr>
		<td width="25%" style="border-left:1px solid black; border-right:1px solid black; border-bottom:1px solid black;">VESSEL/FLIGHT BVC BRINKS<br><br><b style="display:block; text-align:center;">AIR FREIGHT</b></td>

		<td width="25%" style="border-left:1px solid black; border-right:1px solid black; border-bottom:1px solid black;">PORT OF LOADING<br><br><b style="display:block; text-align:center;">MUMBAI</b></td>

        <td width="50%" style="border-right:1px solid black;">Terms of Delivery  & PAYMENT<br>
			<table width="100%">
				<tr>
					<td width="33%" align="center">
						<b>BANK:</b>
					</td>
					<td width="34%" align="center">
						<b>$sale_terms_of_delivery</b>
					</td>
					<td width="33%">
					</td>
				</tr>
			</table>
		</td>
    </tr>

	<tr>
		<td width="25%" style="border-left:1px solid black; border-right:1px solid black; border-bottom:1px solid black;">PORT OF DESTINATION<br><br><b style="display:block; text-align:center;">TOKYO</b></td>

		<td width="25%" style="border-left:1px solid black; border-right:1px solid black; border-bottom:1px solid black;">FINAL DESTINATION<br><br><b style="display:block; text-align:center;">JAPAN</b></td>

        <td width="50%" style="border-right:1px solid black;">&nbsp;</td>
    </tr>

	
	
    <!-- <tr>
        <td width="25%"></td>
        <td width="25%" style="border-right:1px solid black;">&nbsp;</td>
    </tr>
	<tr>
        <td width="25%"></td>
        <td width="25%" style="border-right:1px solid black;">&nbsp;</td>
    </tr>
	<tr>
        <td width="25%"></td>
        <td width="25%" style="border-right:1px solid black;">&nbsp;</td>
    </tr> -->

</table>
EOD;


			$sr_width 			= '7%';		
			$item_width 		= '30%';
			$hsn_width	 		= '15%';
			$qty_width	 		= '15%';
			$rate_width 		= '15%';
			$amt_width	 		= '18%';					

		$tbl_header .= <<<EOD
		<table cellpadding="6" border="1" style="font-size:9;">
			<tr>
				<td width="$sr_width" align="center"><b>Sr No.</b></td>
				<td width="$item_width" align="center"><b>Description</b></td>
				<td width="$hsn_width" align="center"><b>HSN/SAC</b></td>
				<td width="$qty_width" align="center"><b>Qty</b></td>	
				<td width="$rate_width" align="center"><b>Rate</b></td>
				<td width="$amt_width" align="center"><b>AMOUNT</b></td>
			</tr>
		</table>
EOD;

		// Start header at top-left
		$this->SetXY(5, 5);

		// Let TCPDF calculate real header height
		$this->writeHTML($tbl_header, true, false, false, false, '');

		// 📍 Capture Y position EXACTLY after header
		$table_top_y = $this->GetY() - 8;   // small gap under header
		$table_bottom_y = 235;              // footer start (fixed)

		// Draw vertical column lines for full fixed height
		// Left outer border
		$this->line(5, $table_top_y, 5, $table_bottom_y);

		// Column dividers
		$this->line(19, $table_top_y, 19, $table_bottom_y);   // Sr
		$this->line(79, $table_top_y, 79, $table_bottom_y);   // Description
		$this->line(109,  $table_top_y, 109,  $table_bottom_y);   // HSN
		$this->line(139,$table_top_y,139,$table_bottom_y);    // Qty
		$this->line(169,$table_top_y,169,$table_bottom_y);    // Rate
		$this->line(205,  $table_top_y,205,  $table_bottom_y);    // Amount / right border

		$this->SetY($table_top_y + 2);      // Start item rows here
		$this->SetTopMargin($table_top_y + 2);
		$this->setPageMark();

    }

    // Page footer
    public function Footer()
	{
		// show footer ONLY on last page
		if ($this->getPage() != $this->getNumPages()) {
			return; // skip footer on all other pages
		}
		
    	$this->SetFont('Helvetica', 'c', 8);
    	global $sales_trans_pdf;
    	global $sales_data_pdf;
    	global $cnt2 ;
    	$footer_margin_bottom = '220';
    	$page_of_page_margin_bottom = '247';    	
		   
		$sale_addon = isset($sales_data_pdf['sale_addon']) ? $sales_data_pdf['sale_addon'] : "";
		$total_qty=isset($sales_data_pdf['sale_total_qty']) ? $sales_data_pdf['sale_total_qty'] : "";
		$subtotal_amt = isset($sales_data_pdf['sale_sub_total_amt']) ? number_format(round($sales_data_pdf['sale_sub_total_amt'])) : "";
		$total_sgst = isset($sales_data_pdf['sale_total_sgst']) ? round($sales_data_pdf['sale_total_sgst']) : "";
		$total_cgst = isset($sales_data_pdf['sale_total_cgst']) ? round($sales_data_pdf['sale_total_cgst']) : "";
		$total_igst = isset($sales_data_pdf['sale_total_igst']) ? round($sales_data_pdf['sale_total_igst']) : "";
		
		$subtotal_amt1 = isset($sales_data_pdf['sale_sub_total_amt']) ? round($sales_data_pdf['sale_sub_total_amt']) : "";
		$total_final = $total_sgst + $total_cgst + $total_igst + $subtotal_amt1;
		
        $total_final = number_format($total_final);
        
        $sale_date = isset($sales_data_pdf['sale_entry_date']) ? date('d-m-Y',strtotime($sales_data_pdf['sale_entry_date'])) : "";
        $today = strtotime('2022-07-18');
        $gst_date = strtotime($sale_date);
        
        if ($gst_date > $today)
        {
            $cgst = '0.75%'; 
            $sgst = '0.75%'; 
            $igst = '1.50%'; 
        }else
        {
            $cgst =  '0.125%'; 
            $sgst =  '0.125%'; 
            $igst = '0.25%'; 
        }
        $total_final1 = $total_sgst + $total_cgst + $total_igst + $subtotal_amt1;
		$word = strtoupper(number_to_word($total_final1));
		
		$rate_cgst = 0; $rate_sgst = 0;$rate_igst = 0;
		if(!empty($sales_trans_pdf)):
			foreach ($sales_trans_pdf as $key => $value):
				$rate_cgst = $rate_cgst + $value['st_per_cgst'];
				$rate_sgst = $rate_sgst + $value['st_per_sgst'];
				$rate_igst = $rate_igst + $value['st_per_igst'];
			endforeach;
		endif;

    	$tbl_footer = "";    	
    	$tbl_footer .= <<<EOD
    	<table  border="1" cellpadding="" style="font-size:11px;">
		  	<tr>
		  		<td colspan="2" width="100%">
					<table  border="1" cellpadding="3" style="font-size:11px;">			
				  	<tr>
				  		<td width="37%" style="text-align:right"><b>Total</b></td>
				  		<td width="15%"></td>
						<td width="15%" style="text-align:center"><b>$total_qty</b></td>
						<td width="15%"></td>
						<td width="18%" style="text-align:center"><b>$subtotal_amt&nbsp;&nbsp;&nbsp;</b></td>
				  	</tr>
				  	</table>
				</td>
			</tr>
			<tr>
				<td colspan="2" width="100%">
					<table  cellpadding="0" style="font-size:11px;">			
				  	<tr>
				    	<td width="60%">
						    <table cellpadding="1">
						    	<tr>
									<td style="font-size:11px;">Amount Chargeable (in words) <br><b>$word</b>
									
									<br>
									<span style="font-size:6px;">THE ABOVE GOODS ARE ON OUTRIGHT SALE BASIS.												
								PAYMENT INSTRUCTIONS ;- PLEASE CREDIT THE PROCEEDS TO ACCOUNT NUMBER. 0011407376 OF AXIS BANK LTD, MUMBAI SWIFT : AXISINBB												
								(FORMERLY KNOWN AS UTI BANK LIMITED) HELD WITH JP MORGAN CHASE BANK N.A. NEW YORK, U.S.A SWIFT: CHASUS33XX FOR FURTHER												
								CREDIT TO – AXIS BANK LTD,BDB BANDRA MUMBAI,INDIA SWIFT : AXISINBBA10 FOR CREDIT TO OUR A/C. NO :  920020070330978												
								FOR ONWARD CREDIT TO BENEFICIARY RUCHITA GEMS	
								</span>		
									</td>
								</tr>					

							</table>
				    	</td>				    	
						<td width="40%">
							<table border="0" cellpadding="2" style="font-size:10px;">
								<tr>
									<td width="55%" style="text-align:right"><b>SGST $sgst</b></td>
									<td width="45%" style="border-left:1.5px solid #000;text-align:center;"><b>$total_sgst &nbsp;&nbsp;&nbsp;</b></td>
								</tr>
								<tr>
									<td width="55%" style="text-align:right"><b>CGST $cgst</b></td>
									<td width="45%" style="border-left:1.5px solid #000;text-align:center;"><b>$total_cgst&nbsp;&nbsp;&nbsp;</b></td>
								</tr>
								<tr>
									<td width="55%" style="text-align:right"><b>IGST $igst</b></td>
									<td width="45%" style="border-left:1.5px solid #000;text-align:center;"><b>$total_igst&nbsp;&nbsp;&nbsp;</b></td>
								</tr>
								
								<tr>
									<td width="55%" style="text-align:right;font-size:11px;"><b>TOTAL BILL AMOUNT</b></td>
									<td width="45%" style="border:1.5px solid #000;text-align:center"><b>$total_final&nbsp;&nbsp;&nbsp;</b></td>
								</tr>
							</table>
						</td>
				  	</tr>			
				</table>
				</td>
			</tr>

			<tr>
				<td colspan="2" width="100%">
					<table  cellpadding="0" style="font-size:11px;">			
				  	<tr>
				    	<td width="100%">
						    <table cellpadding="1">
						    	<tr>
									<td style="font-size:11px;"><b><u>Declaration</u></b></td>
								</tr>
								<tr>
									<td style="font-size:10px;">We declare that this invoice shows the actual price of the goods <br>described and that all particulars are true and correct.</td>
								</tr><br/><br/>
							</table>
				    	</td>	
				  	</tr>			
				</table>
				</td>
			</tr>




			<tr>
				<td colspan="2" width="100%">
					<table  cellpadding="0" style="font-size:11px;">			
				  	<tr>
				    	<td width="100%">
						    <table cellpadding="1">
						    	<tr>
									<td style="font-size:7px;"><b>WE SHALL  FILE ANY CLAIM AGAINST THIS INVOICE UNDER RoDTEP SCHEME AND SHIPPING BILL FOR THIS INVOICE IS FILED WITH CUSTOM ICEGATE INFO CODE AS RODTEPY</b></td>
								</tr>
							</table>
				    	</td>		
				  	</tr>			
				</table>
				</td>
			</tr>



			<tr>
				<td colspan="2" width="100%">
					<table  cellpadding="0" style="font-size:11px;">			
				  	<tr>
				    	<td width="50%" style="border-right:1px solid black;">
						    <table cellpadding="1">
						    	<tr>
									<td style="font-size:9px;">We hereby certify that our registration certificate under the GST Act, 2017 is in					
									force on the date on which the sale of the goods specified in this tax invoice is					
									made by us and that the transaction of sale covered by this tax invoice has been					
									effected by us and it shall be accounted for in the turnover of sales while filing of					
									return and the due tax, if any, payable on the sale has been paid or shall be paid.					

									</td>
								</tr>
							</table>
				    	</td>				    	
						<td width="50%">
							 <table cellpadding="1">
						    	<tr>
									<td style="font-size:11px; text-align:right;"> 
									<b>SIGNATURE AND DATE</b> 
									<b>FOR M/S RUCHITA GEMS</b>
									<br/><br/><br/>

									(Pankaj Babulal Shah)<br/>
									PROPRIETOR
									</td>
								</tr>
							</table>
						</td>
				  	</tr>			
				</table>
				</td>
			</tr>



			

			
		</table>
    	
		
EOD;

		// $this->writeHTML($tbl_footer, true, false, false, false, '');
		$this->writeHTMLCell(200, 200, 5, 235, $tbl_footer, 0, 0, 0, true, 'P', true);
        //  $this->writeHTML($tbl_footer, true, false, false, false, '');
  
        // Set font
        // $this->SetFont('helvetica', 'c', 8);
        // Page number
        // $this->Cell(0, $page_of_page_margin_bottom, 'Page '.$this->getAliasNumPage().'/'.$this->getAliasNbPages(), 0, false, 'C', 0, '', 0, false, 'T', 'M');
    }
}

// create new PDF document
// $pdf = new TCPDF('P', PDF_UNIT, array('160','200'), true, 'UTF-8', false);
// $pdf = new MYPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, array('210','148'), true, 'UTF-8', false); 
$pdf = new MYPDF('P', PDF_UNIT, 'A4', true, 'UTF-8', false);

// set document information
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor('Imran Khan');
$pdf->SetTitle('sales invoice Pdf');
$pdf->SetSubject('sales invoice Pdf');
// $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->SetMargins(8, 10, 5);
$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
$pdf->SetFooterMargin(84);

$pdf->SetAutoPageBreak(TRUE , 67);


// 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);
}

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

	$sr_width 			= '6%';				
	$item_width 		= '29%';
	$hsn_width	 		= '15%';
	$qty_width	 		= '15%';
	$rate_width 		= '15%';
	$amt_width	 		= '18%';


$pdf->SetFont('Helvetica', 'c', 8);
$row_cnt = count($sales_trans_pdf);

$tbl = "";
$pdf->AddPage();
	$tbl .= <<<EOD

			<table cellpadding="4" style="font-size:10px; line-height:12px;">
EOD;

			// echo "<pre>"; print_r($sales_trans_pdf); exit;

					for($i=0; $i<$row_cnt; $i++)
					{
						$sr_no = $i +1;
						$product_name = $sales_trans_pdf[$i]['st_dm_code'];
						$qty = $sales_trans_pdf[$i]['st_carat'];
						$rate = number_format($sales_trans_pdf[$i]['st_pc_amt']);
						$sub_amt = number_format(round($sales_trans_pdf[$i]['st_sub_total_amt']));
						$total_amt = $sales_trans_pdf[$i]['st_total_amt'];
						$hsn_code = $sales_trans_pdf[$i]['hsn_code'];
						$hsn_description = $sales_trans_pdf[$i]['hsn_description'];

						$tbl .= <<<EOD
							<tr>
								<td width="$sr_width" align="left">$sr_no</td>
								<td width="$item_width" align="center"><b>$hsn_description</b></td>
								<td width="$hsn_width" align="center">$hsn_code</td>
								<td width="$qty_width" align="center">$qty</td>	
								<td width="$rate_width" align="center">$rate</td>
								<td width="$amt_width" align="center">$sub_amt</td>
							</tr>
EOD;
					}

			$tbl .= <<<EOD
					</table>
				
EOD;
// set auto page breaks
// $pdf->SetAutoPageBreak(TRUE, $set_auto_page_break);
$pdf->writeHTML($tbl, true, false, false, false, '');
// $pdf->IncludeJS("print();");
// ---------------------------------------------------------

//Close and output PDF document
ob_end_clean();
$pdf->Output('sales Invoice.pdf', 'I');
//============================================================+
// END OF FILE
//============================================================+