<?php
//*****************************INCLUDE ROOT FILES************START HERE******************************************************/
$PageSecurity = 3;
include('includes/Class_Client.php');
include ('includes/session.inc');
include ('includes/function_lib.php');
include('includes/fun-php.php');
include('includes/fun-HRClass.php');
//include("Class_Party.php");
global $db;
//*****************************INCLUDE ROOT FILES************END HERE******************************************************/


//*****************FETCH DATA FOR COMPANY NAME***************START HERE******************************************************/

$CompanyDetails=DB_query("select * from companies where CompanyId='".$_SESSION['ACGCompanyId']."'",$db);
$CompanyRow=DB_fetch_array($CompanyDetails);
//echo "<pre>";print_r($CompanyRow);
//*****************FETCH DATA FOR COMPANY NAME***************END HERE******************************************************/



//*****************FETCH DATA FOR QUTATION NAME***************START HERE******************************************************/
$GetQuots=DB_query("select * from quotation where id='".$_REQUEST['id']."'",$db);
$GetQuotsRow=DB_fetch_array($GetQuots);
//$client=$s->GetFieldValue('accountledger',"AccountsID='".$GetQuotsRow['party']."'",'vender_client');

$GetSQL=DB_query("select * from clientmaster where id='".$GetQuotsRow['party']."'",$db);
$GetClient=DB_fetch_array($GetSQL);

//$GetContact=$s->GetFieldValue('contact_information_master',"id='".$GetQuotsRow['partyContact']."'",'person');


$BranchSQL=DB_query("select * from locations where loccode='".$GetQuotsRow['site']."'",$db);
$GetBranch=DB_fetch_array($BranchSQL);

//*****************FETCH DATA FOR QUTATION NAME***************END HERE******************************************************/

//*****************FETCH DATA FOR QUTATION TERMS ANDCONDITIONS ****************************************************/

  global $db;
  echo '<link href="'.$rootpath. '/css/'. $_SESSION['Theme'] .'/default.css" rel="stylesheet" type="text/css" />';
?>
<script type="text/javascript" language="javascript">
  function toggle_visibility(id) {
	
	 
       var e = document.getElementById(id);
	       e.style.display = 'none';
		       //alert(e.style.display);
			   window.print();
    }

</script>
<style type="text/css">
body{font-family:Arial;}

</style>

<link rel="stylesheet" href="css/new_mxerp.css">
<div class="body_contain">
<div class="tab_div" style="padding:70px 10px 10px 10px; width:97%">
		 <h1 style="margin-top:-60px; text-align:center; font-family:Arial;">QUOTATION</h1>
<!-- table 1 start here --><div>
<table width="100%" border="0" cellspacing="0" cellpadding="0" style="border:#000000 solid 1px;">
  <tr>
  <td style="padding:20px 0 10 5px; width:10%;"><img src="Setup/CompanyLogo/<?php echo $CompanyRow['CompanyLogo'];?>" /></td>
    <td style="width:1%;border-right:#000000 solid 3px;">&nbsp;</td>
    
    <td style="font-size:15px; padding:20px 40px 0 5px; text-align:right;"><span style="color:#0033FF; font-size:24px;"><strong><? echo $CompanyRow['CompanyName']; ?></strong></span><br />
	<? echo $CompanyRow['Address1'].", ".$CompanyRow['Address2'].", ".$CompanyRow['Address3']."<br>".$CompanyRow['City'].",".$CompanyRow['State'].",".$CompanyRow['Country']."-".$CompanyRow['Zipcode']; ?><br />
	Tel.: <? echo $CompanyRow['Phone'];?> Email: <? echo $CompanyRow['email'];?>	</td>
  </tr>
</table>
<br />
<table width="100%" border="0" cellspacing="0" cellpadding="0" style="border:#000000 solid 1px; font-size:16px; font-weight:bold;">
  <tr>
	  <td width="30%" style="padding:5px; font-size:11px; font-family:Arial;"><?php echo strtoupper($GetClient['c_name']);?><br />
SITE:&nbsp;<?php $consignee=DB_fetch_assoc(DB_query("SELECT * FROM `clientmaster_consignee_address` WHERE id='".$GetQuotsRow['quotationSite']."'",$db)); echo strtoupper($consignee['consignee_name'])."<br>Site Address : ". $consignee['consignee_Address'] ; ?></td>
    
    
    <td align="right" valign="middle" style="font-size:15px; text-align:right; padding-right:5PX;"><?php //if($GetQuotsRow['quotationDate'] != ''){echo date('d/m/Y',strtotime($GetQuotsRow['quotationDate']));}?></td>
  </tr>
</table>
</div><!-- table 1 Close here -->
<div style="height:5px;"></div>
<!-- table 2 start here --><div>
<table width="100%" border="0" cellspacing="0" cellpadding="0" style="font-size:16px; font-weight:bold;border:#000000 solid 1px;">
  <tr>
    <td style="width:40%; padding:5px; font-family:Arial;">Kind Attn&nbsp;:&nbsp;&nbsp;<? $contact=DB_fetch_assoc(DB_query("SELECT * FROM `contact_information_master` WHERE id='".$GetQuotsRow['contactPerson']."'",$db)); echo $contact['person']."<br>" ;?>Mobile No : <?php echo $contact['phone']; ?></td>
	</tr>
</table>
</div>

<div style="margin-top:10px;">
<table width="100%" border="0" cellspacing="0" cellpadding="0" style="font-size:16px; font-weight:bold;border:#000000 solid 1px;">
  <tr>
    <td style="width:40%;font-family:Arial; font-size:11px; padding:5px;">Subject&nbsp;:&nbsp;&nbsp; <?php echo $GetQuotsRow['quotationSubject'];?></td>
	</tr>
</table>
</div><!-- table 2 Close here -->
<!-- table 3 start here --><div>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td class="tabledata1" style="padding-left:5px;font-size:14px;">Dear Sir,</td>
  </tr>	
    <tr>
    <td colspan="2" valign="top"  style="font-size:14px;">This has reference to your mail dated. <?php echo ($GetQuotsRow['quotationMailDate'] != '')?$newDate = date("d/m/Y", strtotime($GetQuotsRow['quotationMailDate'])):"N/A";?> regarding above mentioned subject matter. We are Please to submit our offer for the same as here below :</td>
  </tr>
</table>
<br />

<div style="font-size:14px; font-family:Arial, Helvetica, sans-serifS; font-weight:bold"><strong><u>PRODUCT OFFERED</u></strong></div>
<br />
<table width="100%" border="1" cellspacing="0" cellpadding="3" style="border:#000000 solid 1px; font-size:16px;">
  <tr>
    <th width="6%"  style="font-size:12px;font-family:Arial;">S. No.</th>
    <th width="30%" style="font-size:12px;font-family:Arial;">Item Name</th>
<!--    <th width="18%" style="font-size:16px; width:25%;"><strong>Shade and Code</strong></td>
-->    <th width="20%" style="font-size:12px;font-family:Arial;  text-align:center;" >Size</th>
<th width="10%" style="font-size:12px ;font-family:Arial;  text-align:center;">Quantity</th>
    <th width="5%" style="font-size:12px;font-family:Arial;  text-align:center; ">Unit</th>
    <th width="13%" style="font-size:12px;font-family:Arial;  text-align:center;">Rate Per Unit (INR)</th>
    
  </tr>
  <?php 
  $ItemList=DB_query("SELECT QD.itemCode,QD.est_unit_prm_sec,QD.est_qty_prm_sec, QD.price, S.size FROM 
quotation_details QD INNER JOIN size_master S ON S.id=QD.sizeid 
WHERE QD.parentId='".$GetQuotsRow['id']."'",$db); 
  
  $i=1;

while($ItemListRow=DB_fetch_array($ItemList)) {
 
 $item_query = "SELECT IM.item_name, IM.StockID, U.unitname FROM item_master IM LEFT JOIN unitsofmeasure U ON U.unitid=IM.mst_unitid WHERE id='".$ItemListRow['itemCode']."'";

$item_result = DB_query($item_query,$db);

$itemRow = DB_fetch_array($item_result);

$unit_name=DB_fetch_array(DB_query("SELECT * FROM unitsofmeasure WHERE unitid='".$ItemListRow['est_unit_prm_sec']."'",$db));
?>
  <tr>
    <td style="font-size:12px;text-align:center;"><? echo $i++; ?></td>
    <td style="font-size:12px;"><? echo $itemRow['item_name']; ?></td>
<?php /*?>    <td style="font-size:16px;"><strong><? echo $itemRow['item_name'].'('.$itemRow['StockID'].')'; ?></strong></td>
<?php */?>    <td style="font-size:12px; text-align:center;"><? echo $ItemListRow['size'];?></td>
 <td style="font-size:12px; text-align:center;"><? echo $ItemListRow['est_qty_prm_sec']; ?></td>
    <td style="font-size:12px; text-align:center;"><? echo $unit_name['unitname']; ?></td>
    <td style="font-size:12px; text-align:center;"><strong><? echo $ItemListRow['price']; ?></strong></td>
   
  </tr>
<?php } ?>
</table>
</div><!-- table 3 Close here -->
<br />

<div style="font-size:14px; font-family:Arial, Helvetica, sans-serifS; font-weight:bold"><strong><u>Assembly Details</u></strong></div>
<br />
<table width="100%" border="1" cellspacing="0" cellpadding="3" style="border:#000000 solid 1px; font-size:16px;">
  <tr>
    <th width="6%" style="font-size:12px;font-family:Arial;">Sr.No.</th>
    <th width="30%" style="font-size:12px;font-family:Arial;">Item Name</th>
	<th width="20%" style="font-size:12px;text-align:center;font-family:Arial;">Part Code</th>
    <th width="10%" style="font-size:12px;text-align:center;font-family:Arial;">Quantity</th>
	<th width="5%" style="font-size:12px;text-align:center;font-family:Arial;">Unit</th>
	<th width="13%" style="font-size:12px;text-align:center;font-family:Arial;">Rate Per Unit (INR)</th>
  </tr>
  <?php 
  
 	$hw_query = "SELECT QH.isChecked, QH.quantity,I.mst_unitid,QH.price,I.item_name, I.StockId
  			   FROM quotation_hardware_items QH 
			   INNER JOIN item_master I ON I.id=QH.itemCode
			   where QH.parant_id='".$GetQuotsRow['id']."'";
  $hw_result=DB_query($hw_query,$db);  
  $inclusive = array();
  $exclusive = array();
  while($hardwareRow = DB_fetch_array($hw_result)) 
  {
	if($hardwareRow['isChecked'] == '1')
		$exclusive[] = $hardwareRow;
	else
		$inclusive[] = $hardwareRow;
  }
 ?>
  <tr height="30">
	<td style="font-size:13px" colspan="6"><strong>Inclusive Items </strong></td>
  </tr>
  <?php 
  	$i = 1;
	if(!(empty($inclusive))){
  	foreach($inclusive as $INC){
  ?>
  <tr>
    <td style="font-size:12px;"><?  echo $i++; ?></td>
    <td style="font-size:12px;"><? echo $INC['item_name']; ?></td>
	<td style="font-size:12px;"><? echo $INC['StockId']; ?></td>
    <td style="font-size:12px;text-align:center;"><? echo $INC['quantity']; ?></td>
	<td style="font-size:12px;text-align:center;"><? $unitname=DB_fetch_array(DB_query("SELECT * FROM unitsofmeasure WHERE unitid='".$INC['mst_unitid']."'",$db)); echo $unitname['unitname']; ?></td>
	<td  style="font-size:12px;text-align:center;"><strong>N/A</strong></td>
  </tr>
<?php } }
	else {
?>
<tr>
<td colspan="6" style="font-size:12px;">NO INCLUSIVE ITEMS.</td>
</tr>
<?php } ?>
 <tr height="30">
	<td style="font-size:13px" colspan="6"><strong>Exclusive Items</strong></td>
  </tr>
  <?php 
  	$i = 1;
	if(!(empty($exclusive))){
  	foreach($exclusive as $EXC){
  ?>
  <tr>
    <td style="font-size:12px;text-align:center;"><? echo $i++; ?></td>
    <td style="font-size:12px;"><? echo $EXC['item_name']; ?></td>
	 <td style="font-size:12px;"><? echo $EXC['StockId']; ?></td>
    <td style="font-size:12px;text-align:center;"><? echo $EXC['quantity']; ?></td>
	<td style="font-size:12px;text-align:center;"><? $unitname=DB_fetch_array(DB_query("SELECT * FROM unitsofmeasure WHERE unitid='".$EXC['mst_unitid']."'",$db)); echo $unitname['unitname']; ?></td>
	 <td style="font-size:12px;text-align:center;"><strong><? echo $EXC['price']; ?></strong></td>
  </tr>
<?php } }
else {
 ?>
 <tr>
<td colspan="6" style="font-size:12px;">NO EXCLUSIVE ITEMS.</td>
</tr>
<?php }?>
</table>
</div><!-- table 3 Close here -->

<!-- table 4 start here --><div>

<? $exicise=$s->GetFieldValue('excise_tax',"id='".$GetQuotsRow['VatCst']."'",'caption');
   $GetVat=$s->GetFieldValue('sales_tax_master',"salestax_id='".$GetQuotsRow['VatCst']."'",'tax_code');
?>
</div><!-- table 4 Close here -->
<!-- table 5 start here -->
<br />
<div style="font-size:14px; font-family:Arial, Helvetica, sans-serifS;"><strong>&nbsp;&nbsp;<u>Commercial Terms & Conditions</u></strong></div>
<br />
<div style="font-size:16px">

<?php
$frmid = $_REQUEST['frmid'];

$terms_sql = "SELECT T.terms_conditions as TERMS, C.terms_conditions as COND 
			  from quotation_terms_cond QT 
			  INNER JOIN terms_condition T ON T.id=QT.termsid 
			  INNER JOIN terms_condition C ON C.id=QT.condid
			  where QT.frm_id='".$frmid."' and QT.parant_id='".$_REQUEST['id']."'";

$terms_result = DB_query($terms_sql,$db);
while($termsrow = DB_fetch_array($terms_result)){?>
<div style=" padding:2px;width:100%">
	<div style="font-size:12px; font-weight:bold; font-family:Arial, Helvetica, sans-serif; float:left; padding-right:2px;">
		&nbsp;&nbsp;<?php echo $termsrow['TERMS'];?></div> &nbsp;	
	<div style="float:left; font-size:12px; font-family:Arial, Helvetica, sans-serif; padding-left:2px;"> <strong>: </strong>
</div>
	<div style="float:left; font-size:12px; font-family:Arial, Helvetica, sans-serif; padding-left:2px;">
		&nbsp;&nbsp;<?php echo $termsrow['COND'];?> 
	</div>
</div>
<?php } ?>
<br />
<br />
<div style="padding-left:10px; font-family:Arial;">Thank you,<br />
For <? echo $CompanyRow['CompanyName']; ?><br />
<!--Rajesh Khanna<br />
Asst. Manager Sales)-->
</div>
</div>
<!-- table 5 Close here -->
</div>
<div id="foo"><p align="center">
  <a href="#" onClick="javascript:toggle_visibility('foo');" ><span style="font-size:13px; font-weight:bold;font-family:Arial;">Print</span></a></p>
</div> 
</div>
</div>

