<?php
ob_start();
session_name('CAKEPHP'); session_start();
require_once('config/lang/eng.php');
require_once('tcpdf.php');
include('function.php');



$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);

$add_query = "select * from companies where 1=1";
$result = mysqli_query($con, $add_query);
$num_rows = mysqli_num_rows($result);

if ($num_rows > 0) {
	$row = mysqli_fetch_array($result);
	$org_name = $row["CompanyName"];
	$org_logoname = 'compaint.jpg';
	$org_address = $row["Address1"];
	$org_address1 = $row["Address2"];
	$org_address3 = $row["Address3"];
	$org_city = $row["City"];
	$org_country  = $row["Country"];
	$org_Zipcode  = $row["Zipcode"];
	$org_State  = $row["State"];
	//$logo_name = 'company-1.png';
}
$pdf->SetHeaderData($logo_name, 10, $org_name, $org_address . "\n" . $org_address1 . " " . "\n" . $org_city . " " . $org_Zipcode);

$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(PDF_MARGIN_LEFT, 25, PDF_MARGIN_RIGHT);
$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);

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

//set image scale factor
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
//set some language-dependent strings
$pdf->setLanguageArray($l);
$pdf->AddPage();

$sql = "Select * from salesorder where branch='" . $_REQUEST['loccode'] . "'";
$result = mysqli_query($con, $sql);
$datarow = mysqli_fetch_array($result);

$sql1 = mysqli_query($con, "select * from salesorder_details where masterId='" . $datarow['id'] . "'");
//print "select * from salesorder_details where masterId='".$datarow['id']."'";
$data = '';
$i = 1;
$c_name =  GetFieldValue('clientmaster', "id='" . $datarow['client'] . "'", 'c_name');
?>

<?php
$data .= "<table width='100%' border='0'><tr  style='background-color:#B7B7B7' >
              <td>SNo.</td>
              <td>Code</td>
              <td>Item Name </td>
              <td>Item Description</td>
              <td>Qty</td>
              <td>Remark</td></tr></table>";
$data .= "<table width='100%' border='0'>
		
		  <tr>
			<td>SOP No: " . $datarow['orderNo'] . "</td>
			<td>" . $c_name . "</td>
			<td >Delivery Date:" . $datarow['DeliveryDate'] . "</td>
		  </tr></table><br>
		  ";
$data .= "<table width='100%' border='0'>
  <tr>
    <td>SNo.</td>
    <td >Code</td>
    <td >Item/Shade Name </td>
    <td>Item Desc</td>
    <td >Qty</td>
    <td >Remark</td>
  </tr>
  ";

while ($sql1Row = mysqli_fetch_array($sql1)) {

	//echo $purchrow['ItemCode'];
	$data .= "<tr> <td>" . $i++ . "</td>";
	$StockID = GetFieldValue('item_master', "id='" . $sql1Row['ItemCode'] . "'", 'StockID');
	$data .= "<td>" . $StockID . "</td>";
	$item_name = GetFieldValue('item_master', "id='" . $sql1Row['ItemCode'] . "'", 'item_name');
	$data .= "<td>" . $item_name . "</td>";
	$item_desc = GetFieldValue('item_master', "id='" . $sql1Row['ItemCode'] . "'", 'item_desc');	//echo $row['ItemCode'];
	$data .= "<td>" . $item_desc . "</td>";
	$data .= "<td>" . $sql1Row['Quantity'] . "</td>";
	$data .= "<td>" . $sql1Row['SalesCategory'] . "</td></tr>";
}	//$data.="<td>".$z."</td></tr></table>";
echo "</table>";
?>

 
  
<?php
$pdf->writeHTML($data, true, false, true, false, '');
$pdf->lastPage();
ob_end_clean();
$pdf->Output('ADDMRNEXPORTVIEW.pdf', 'I');
?>