<?php
	include "db_connection/db_connection.php";
	include "config/config.php";	
	
    $estimate_id	=	base64_decode(base64_decode(base64_decode(base64_decode($_GET['estimate_id']))));
	$SLCT_cost = "SELECT * FROM cost_estimate WHERE cost_estimate_id = '$estimate_id'";
	$QURY_cost = mysqli_query($connect,$SLCT_cost);
	if(mysqli_num_rows($QURY_cost)>0)
	{
		$FTCH_cost 		= mysqli_fetch_object($QURY_cost);
		
		$SLCT_comp1 = "SELECT * FROM `supplier_enquiry` WHERE statu_s='1' AND order_enquiry_id='$FTCH_cost->order_enquiry_id' GROUP BY order_enquiry_det_id ASC";
		$QURY_comp1 = mysqli_query($connect,$SLCT_comp1);	
		$FTCH_comp1	= mysqli_fetch_object($QURY_comp1);	
		
		$slct_det_mat	=	"SELECT * FROM supplier_enquiry_det WHERE supplier_enquiry_id='$FTCH_comp1->supplier_enquiry_id' AND order_enquiry_det_id='$FTCH_comp1->order_enquiry_det_id' AND enquiry_status='final'";
		$qury_det_mat	=	mysqli_query($connect,$slct_det_mat);
		$fetch_det_mat	=	mysqli_fetch_object($qury_det_mat);
		
		$SLCT_ord1 = "SELECT * FROM order_enquiry WHERE order_enquiry_id = '$FTCH_cost->order_enquiry_id'";
		$QURY_ord1 = mysqli_query($connect,$SLCT_ord1);
		$FTCH_ord1		= mysqli_fetch_object($QURY_ord1);
		if($FTCH_ord1->type=='component')
		{				
			$descp = $FTCH_comp1->component_name;
		}
		else if($FTCH_ord1->type=='product')
		{
			$descp = $FTCH_ord1->assembly_name;
		}
				
		$SLCT_cust = "SELECT * FROM  `mas_customer_det` WHERE `mas_customer_det_id`='$FTCH_cost->mas_customer_det_id'";
		$QURY_cust = mysqli_query($connect,$SLCT_cust);
		$FTCH_cust = mysqli_fetch_object($QURY_cust);
	
		$enq_no			= $FTCH_cost->enquiry_no;
		$enq_id			= $FTCH_cost->order_enquiry_id;
		$comp_name		= $FTCH_cost->cmp_name;
		$enq_date		= $FTCH_cost->date;
		$cust_nm		= $FTCH_cost->customer_name;
		$exp_qty		= $FTCH_cost->expected_qty;
		$tot_cost_mate	= $FTCH_cost->tot_cost_mate;
		$mate_cost		= $FTCH_cost->material_cost;
		$scrp_val		= $FTCH_cost->scrap_value;
		$tool_req		= $FTCH_cost->tools_req;
		$jigs			= $FTCH_cost->jigs_fix;
		$ins_gauge		= $FTCH_cost->instr_gauge;
		$consume		= $FTCH_cost->consumable;
		$pck_chrg		= $FTCH_cost->pack_charge;
		$hndl_chrg		= $FTCH_cost->handle_charge;
		/*$mrgn			= $FTCH_cost->margin;
		$trans_name		= $FTCH_cost->transport_name;
		$trans_chrg		= $FTCH_cost->trans_charge;
		//$tot_cst_exp	= $FTCH_cost->tot_cost_exp;
		$tot_cst_exp	= $FTCH_cost->tot_cost_mate;*/
		$kind_attention	= $FTCH_cost->kind_attention;
	}
	else
	{
		$enq_no			= "";
		$comp_name		= "";
		$enq_date		= "";
		$cust_nm		= "";
		$exp_qty   		= "";
		$tot_cost_mate	= "";
		$mate_cost		= "";
		$scrp_val		= "";
		$tool_req		= "";
		$jigs			= "";
		$ins_gauge		= "";
		$consume		= "";
		$pck_chrg		= "";
		$hndl_chrg		= "";
		$mrgn			= "";
		$trans_name		= "";
		$trans_chrg		= "";
		$tot_cst_exp	= "";
		$kind_attention	= "";			
	}
	
	ob_start();
   /* include(dirname(__FILE__).'/res/exemple07a.php');
    include(dirname(__FILE__).'/res/exemple07b.php');*/
    $content = "
	<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>
	<html xmlns='https://www.w3.org/1999/xhtml'>
	<head>
	<meta http-equiv='Content-Type' content='text/html; charset=utf-8' />
	<title>Untitled Document</title>
	</head>
	<body style='font-family:Times, serif'>
		<table style='width:100%' border='0'>
			<tr>
				<td style='width:10%; display:table-cell; vertical-align:middle; text-align:center; border:0px solid red'><img src='img/logo_kgc.png'/></td>
				<td style='width:70%; display:table-cell; vertical-align:middle; text-align:center;'>
					<span style='text-align:center; font-size:20; font-weight:bold; padding:10px'>Kay Ge Corporation</span><br><br>
					<span style='text-align:center; font-size:14;'>House of Precision CNC Turned and Machined Parts</span><br><br>
					<span style='text-align:center; font-size:14;'>An ISO 9001 Certified Company</span>
				</td>
				<td style='width:15%; display:table-cell; vertical-align:middle; text-align:center;'><img src='img/ISO-NAB.jpg' /></td>
			</tr>
			<tr><td colspan='3'>&nbsp;</td></tr>   
            <tr>
				<td style='width:10%; display:table-cell; vertical-align:middle; text-align:left; font-size:16; padding-left:10px;'>KGC/AN/102/07/14-15</td>
				<td style='width:70%; display:table-cell; vertical-align:middle; text-align:center;'>&nbsp;</td>
				<td style='width:15%; display:table-cell; vertical-align:middle; text-align:center; font-size:16;'>".date('d-m-Y',strtotime($cur_date))."</td>
			</tr> 
			<tr><td colspan='3'>&nbsp;</td></tr>   
            <tr>
				<td style='width:10%; display:table-cell; vertical-align:middle; text-align:left; font-size:16; padding-left:10px;'>To</td>
				<td style='width:70%; display:table-cell; vertical-align:middle; text-align:center;'>&nbsp;</td>
				<td style='width:15%; display:table-cell; vertical-align:middle; text-align:center; font-size:16;'>&nbsp;</td>
			</tr> 
			<tr>
				<td colspan='2' style='display:table-cell; vertical-align:middle; text-align:left; font-size:16; height:60px; padding-left:75px;'>".$FTCH_cust->cour_addr."</td>
				<td style='width:15%; display:table-cell; vertical-align:middle; text-align:center; font-size:16; height:60px;'></td>
			</tr> 
			<tr><td colspan='3'>&nbsp;</td></tr>   
            <tr>
				<td colspan='3' style='display:table-cell; vertical-align:middle; text-align:left; font-size:16; padding-left:10px;'>Kind Attn : ".$kind_attention."</td>
			</tr> 
			<tr><td colspan='3'>&nbsp;</td></tr>   
            <tr>
				<td colspan='3' style='display:table-cell; vertical-align:middle; text-align:left; font-size:16; padding-left:10px;'>Sub : Quotation for ".$descp." - Reg</td>
			</tr> 
			<tr><td colspan='3'>&nbsp;</td></tr>   
            <tr>
				<td style='width:10%; display:table-cell; vertical-align:middle; text-align:left; font-size:16; padding-left:10px;'>Dear Sir,</td>
				<td colspan='2' style='display:table-cell; vertical-align:middle; text-align:center; font-size:16;'>&nbsp;</td>
			</tr>
			<tr>
				<td colspan='3' style='display:table-cell; vertical-align:middle; text-align:left; font-size:16; padding-left:10px;'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;With reference to your enquery ".$enq_date.", we are submitting our Lowest offer along with our terms and condition</td>
			</tr>  
			<tr><td colspan='3'>&nbsp;</td></tr> 
			<tr>
				<td colspan='3' style='display:table-cell; vertical-align:middle; text-align:left; font-size:16; padding-left:10px;'>
                	<table style='width:100%' border='1' cellpadding='0' cellspacing='0'>
                    	<tr>
                        	<td style='width:8%; display:table-cell; vertical-align:middle; text-align:center; padding:5px 3px; font-size:14; font-weight:bold;'>Sl. No</td>
                            <td style='width:28%; display:table-cell; vertical-align:middle; text-align:center; padding:5px 3px; font-size:14; font-weight:bold;'>Description</td>
                            <td style='width:13%; display:table-cell; vertical-align:middle; text-align:center; padding:5px 3px; font-size:14; font-weight:bold;'>Material</td>
                            <td style='width:12%; display:table-cell; vertical-align:middle; text-align:center; padding:5px 3px; font-size:14; font-weight:bold;'>Qty In Nos</td>
                            <td style='width:13%; display:table-cell; vertical-align:middle; text-align:center; padding:5px 3px; font-size:14; font-weight:bold;'>Mode</td>
                            <td style='width:13%; display:table-cell; vertical-align:middle; text-align:center; padding:5px 3px; font-size:14; font-weight:bold;'>Unit Price</td> 
                            <td style='width:13%; display:table-cell; vertical-align:middle; text-align:center; padding:5px 3px; font-size:14; font-weight:bold;'>Total Price</td> 
                        </tr>";						
						$SLCT_cost1 = "SELECT * FROM cost_estimate WHERE cost_estimate_id = '$estimate_id'";
						$QURY_cost1 = mysqli_query($connect,$SLCT_cost1);
						$i=1;
						$pric_nm='';
						$pric_vl='';
						$pric_to='';
						if(mysqli_num_rows($QURY_cost1)>0)
						{		
							$FTCH_cost1		= mysqli_fetch_object($QURY_cost1);
							
							$SLCT_ord1 = "SELECT * FROM order_enquiry WHERE order_enquiry_id = '$FTCH_cost1->order_enquiry_id'";
							$QURY_ord1 = mysqli_query($connect,$SLCT_ord1);
							$FTCH_ord1		= mysqli_fetch_object($QURY_ord1);
							if($FTCH_ord1->type=='component')
							{
								$SLCT_comp1 = "SELECT * FROM `supplier_enquiry` WHERE statu_s='1' AND order_enquiry_id='$FTCH_cost1->order_enquiry_id' GROUP BY order_enquiry_det_id ASC";
								//echo $SLCT_comp1;
								$QURY_comp1 = mysqli_query($connect,$SLCT_comp1);	
								$FTCH_comp1	= mysqli_fetch_object($QURY_comp1);		
								$descp = $FTCH_comp1->component_name;
							}
							else if($FTCH_ord1->type=='product')
							{
								$descp = $FTCH_ord1->assembly_name;
							}
							
							
							$SLCT_cost2 = "SELECT * FROM cost_estimate_det WHERE cost_estimate_id = '$estimate_id'";
							$QURY_cost2 = mysqli_query($connect,$SLCT_cost2);
							while($FTCH_cost2	= mysqli_fetch_object($QURY_cost2))
							{
								$pric_nm .= $FTCH_cost2->transport_name."###";
								$pric_vl .= "$ ".$FTCH_cost2->usd_per_piece."###";
								$pric_to .= "$ ".$FTCH_cost2->total_usd."###";
								/*if($FTCH_cost2->master_transport_id==4)
								{
									$sea_pric = "$ ".$FTCH_cost2->tot_cost_mate / $FTCH_cost2->expected_qty;
									$cur_pric = '--';
									$tot_sea_pric = "$ ".$FTCH_cost2->tot_cost_mate;
									$tot_cur_pric = '--';
								}
								else
								{
									$sea_pric = '--';
									$cur_pric = "$ ".$FTCH_cost2->tot_cost_mate / $FTCH_cost2->expected_qty;
									$tot_sea_pric = '--';
									$tot_cur_pric = "$ ".$FTCH_cost2->tot_cost_mate;
								}*/   
							}
							$content .= "<tr>
								<td style='display:table-cell; vertical-align:middle; text-align:center; padding:5px 3px; font-size:14;'>".$i."</td>
								<td style='display:table-cell; vertical-align:middle; text-align:center; padding:5px 3px; font-size:14;'>".$descp."</td>
								<td style='display:table-cell; vertical-align:middle; text-align:center; padding:5px 3px; font-size:14;'></td>
								<td style='display:table-cell; vertical-align:middle; text-align:center; padding:5px 3px; font-size:14;'>".$FTCH_cost1->expected_qty."</td>
								<td style='display:table-cell; vertical-align:middle; text-align:right; padding:5px 3px; font-size:14;'>
									<table style='width:100%' cellpadding='0' cellspacing='0'>";
								$explode = explode("###",$pric_nm);	
								for($ivl=0;$ivl<sizeof($explode);$ivl++)
								{									
										$content .= "<tr>
											<td style='display:table-cell; vertical-align:middle; text-align:left; padding:5px 3px; font-size:14; '>".$explode[$ivl]."</td>
											</tr>"; 
								}
								$content .= "</table></td>
								<td style='display:table-cell; vertical-align:middle; text-align:left; padding:5px 3px; font-size:14;'>
								<table style='width:100%' cellpadding='0' cellspacing='0'>";
								$explode2 = explode("###",$pric_vl);	
								for($iv2=0;$iv2<sizeof($explode2);$iv2++)
								{									
										$content .= "<tr>
											<td style='display:table-cell; vertical-align:middle; text-align:left; padding:5px 3px; font-size:14; '>".$explode2[$iv2]."</td>
											</tr>"; 
								}
								$content .= "</table>
								</td> 
								<td style='display:table-cell; vertical-align:middle; text-align:left; padding:5px 3px; font-size:14;'>
								<table style='width:100%' cellpadding='0' cellspacing='0'>";
								$explode3 = explode("###",$pric_to);	
								for($iv3=0;$iv3<sizeof($explode3);$iv3++)
								{									
										$content .= "<tr>
											<td style='display:table-cell; vertical-align:middle; text-align:left; padding:5px 3px; font-size:14;'>".$explode3[$iv3]."</td>
											</tr>"; 
								}
								$content .= "</table>
								</td> 
							</tr>";
						}
                    $content .= "</table>
                </td>
			</tr>
			<tr><td colspan='3'>&nbsp;</td></tr>
			<tr>
				<td style='width:10%; display:table-cell; vertical-align:middle; text-align:left; font-size:14; padding-left:10px;'><strong><u>Terms and condition</u></strong></td>
				<td style='width:70%; display:table-cell; vertical-align:middle; text-align:center;'>&nbsp;</td>
				<td style='width:15%; display:table-cell; vertical-align:middle; text-align:center; font-size:14;'>&nbsp;</td>
			</tr>  
			<tr><td colspan='3'>&nbsp;</td></tr>";						
			$SLCT_cost1 = "SELECT * FROM cost_estimate_terms WHERE cost_estimate_id = '$estimate_id' AND revised_sts!=1";
			$QURY_cost1 = mysqli_query($connect,$SLCT_cost1);
			if(mysqli_num_rows($QURY_cost1)>0)
			{		
				while($FTCH_cost1		= mysqli_fetch_object($QURY_cost1))
				{
					$content .= "
					<tr>
						<td style='width:10%; display:table-cell; vertical-align:middle; text-align:left; font-size:16; padding-left:10px;'>".$FTCH_cost1->terms_title." </td>
						<td colspan='2' style='display:table-cell; vertical-align:middle; text-align:left; font-size:16;'>: ".$FTCH_cost1->terms_description."</td>
					</tr>";
				}
			}
			else
			{		
				$SLCT_cost2 = "SELECT * FROM cost_estimate_terms WHERE cost_estimate_id = '0'";
				$QURY_cost2 = mysqli_query($connect,$SLCT_cost2);
				while($FTCH_cost2		= mysqli_fetch_object($QURY_cost2))
				{
					$content .= "
					<tr>
						<td style='width:10%; display:table-cell; vertical-align:middle; text-align:left; font-size:16; padding-left:10px;'>".$FTCH_cost2->terms_title."</td>
						<td colspan='2' style='display:table-cell; vertical-align:middle; text-align:left; font-size:16;'>: ".$FTCH_cost2->terms_description."</td>
					</tr>";
				}
			}
		$content .= "			  
		</table>
		<page_footer>
			<table cellpadding='5' style='width: 100%; border: solid 1px black; font-family:Times, serif'>
				<tr>
					<td colspan='3' style='display:table-cell; vertical-align:middle; text-align:center; font-size:16; width: 100%'>S.F. No 428/1, Eran Thottam, Sathy Road, Gananpathy, Coimbatore-641006. INDIA</td>
				</tr>
				<tr><td colspan='3'>&nbsp;</td></tr>
				<tr>
					<td colspan='3' style='display:table-cell; vertical-align:middle; text-align:center; font-size:16; width: 100%'>Phone: 0422-2531606, Relefax: 0422-2531806, Email: farookg@rediffmail.com</td>
				</tr>
				<tr><td colspan='3'><hr></td></tr>
				<tr>
					<td style='display:table-cell; vertical-align:middle; text-align:center; font-size:16; width: 25%'>TIN : 33602203262</td>
					<td style='display:table-cell; vertical-align:middle; text-align:center; font-size:16; width: 50%'>CST : 855453 DT 01.07.2014 </td>
					<td style='display:table-cell; vertical-align:middle; text-align:center; font-size:16; width: 25%'>Area Code : <span style='border:0px solid red'>1 1 5</span></td>
				</tr>
			</table>
		</page_footer>
	</body>
	</html>";
// convert to PDF
    require_once(dirname(__FILE__).'\html2pdf\html2pdf.class.php');
    try
    {
        $html2pdf = new HTML2PDF('P', 'A4', 'fr');
        $html2pdf->pdf->SetDisplayMode('fullpage');
//      $html2pdf->pdf->SetProtection(array('print'), 'spipu');
        $html2pdf->writeHTML($content, isset($_GET['vuehtml']));
        $html2pdf->Output('exemple07.pdf');
    }
    catch(HTML2PDF_exception $e) {
        echo $e;
        exit;
    }
?>


