 <?php extract($_POST);
$PageSecurity = 1;
 
global $db;?>
<h3 align="center">
 
<?php 
if(isset($_REQUEST['CPID'])&& $_REQUEST['CPID']!='') 
$title='ORDER SUMMARY';
else
$title='Vendor Quotation';

if($_REQUEST['Order'])
{
	$prefixcode=$s->GetFieldValue('prefix_tbl',"prefix_name='Purchase Order'" ,'prefix_code');
	 $sql = "select * from comprative_detail  where  comprative_id='".$_REQUEST['CPID']."'";
	
	$PurchOrdersResult = DB_query($sql,$db); 
	$rowdata=DB_fetch_array($PurchOrdersResult);
	$data['mst_reqino'] =$rowdata['RequisitionNo'];
	$data['mst_vendor_quotesid']=$rowdata['Vendor_Quot_No'];
	$data['mst_vendor_pid']=$rowdata['mst_product_list'] ;
	$data['mst_comperitive']=$_REQUEST['CPID'] ;
		
		
		  $sitecode=$s->GetFieldValue('materialrequisitions',"requisitionno='".$rowdata['RequisitionNo']."'" ,'sitecode');
		  $getlast_poid=$s->GetFieldValue('purchorders',"1=1 order by orderno  desc limit 1" ,'orderno');	
		
		
		$data['PO_Orderno']=$prefixcode.'/'.$sitecode.'/'.($getlast_poid+1) ;
		$data['Po_recive_status']    = 'Pending';
		$data['orddate']=date('Y-m-d');	
		 $insert=$s->RecordInsert('purchorders', $data);
		 
					$dataCompList['status_active']=1;
					$dataCompList['mst_modify_date']=date('Y-m-d');
 					 $cond="comprative_id='".$_REQUEST['CPID']."'  ";
					   $s->RecordEdit('comprative_detail', $dataCompList, $cond);
					   
		 $s->pageLocation("index.php?route=POModule/Comp-order-list&CGROUP=".$rowdata['comprative_no'].'&daction=1'.$rurl);

	 	
}
if($_REQUEST['daction'])
{
   echo "<div class='success'>PO Order Genrated Successfully</div>";
}
?>


<?php 
if(isset($_REQUEST['CPID'])&& $_REQUEST['CPID']!=''){
$Vendor_Quot_No=    $s->GetFieldValue('comprative_detail',"comprative_id='".$_REQUEST['CPID']."'" ,'Vendor_Quot_No'); 
  $ITEMLIST=$s->GetFieldValue('comprative_detail',"comprative_id='".$_REQUEST['CPID']."'" ,'mst_product_list'); 
   $CHECK_POSTATUS=    $s->GetFieldValue('purchorders',"mst_comperitive='".$_REQUEST['CPID']."'" ,'orderno'); 

}
else{
$Vendor_Quot_No=$_REQUEST['VQuotesId'];
}

 ?>
 <form action="" method="post">
<?php 
if($_GET['POID'])
  $sql_po = "Select * from purchorders where orderno='".$_GET['POID']."'";
  else
    $sql_po = "Select * from venderquotations where id='".$_GET['VQuotesId']."'";
	
	//echo  $sql_po;
	$result=DB_query($sql_po,$db);
	$myrow=DB_fetch_array($result);
	if($_GET['POID']){
	
	$orddate=$myrow['orddate'];
	$PO_Orderno=$myrow['orderno'];
	$version1=$myrow['version1'];
	$revised=$myrow['revised'];
	$deliveryby=$myrow['deliveryby'];
	$deliverydate=$myrow['deliverydate'];
	$initiator=$myrow['initiator'];
	$requisitionno=  $s->GetFieldValue('materialrequisitions',"requisitionno ='".$myrow['mst_reqino']."'" ,'Reqno');
	$mst_supplierno=  $s->GetFieldValue('venderquotations',"id ='".$myrow['mst_vendor_quotesid']."'" ,'mst_supplierno');
 	$vernder_quotation =$s->GetFieldValue('venderquotations',"id ='".$myrow['mst_vendor_quotesid']."'" ,'vernder_quotation');
	$sitecode=  $s->GetFieldValue('venderquotations',"id ='".$myrow['mst_vendor_quotesid']."'" ,'sitecode');
	}else{
	$sitecode= $myrow['sitecode'];
	$mst_supplierno =$myrow['mst_supplierno'];
	$sitename= $myrow['site'];
	$vernder_quotation=$myrow['vernder_quotation'];
	$event=$myrow['event'];
	$billingType=$myrow['billingType'];
	$payment_term=$myrow['payment_term'];
	$quotationcategory=$myrow['quotationcategory'];
	$basis=$myrow['basis'];
	$warramtydetails=$myrow['warramtydetails'];
	$deliveryterms=$myrow['deliveryterms'];
	$payment_mode=$myrow['payment_mode'];
	$validtill=$myrow['validtill'];
	$remarks=$myrow['remarks'];
	$warramtydetails =$myrow['warramtydetails '];	
		
 	}
		
	
	  $site_sql="Select * from locations where loccode='".$sitecode."'";
	$site_res=DB_query($site_sql,$db);
	$site_row=DB_fetch_array($site_res);
	 
 
 	$vendor_detail = "Select * from suppliers where id='".$mst_supplierno."'";
	$result_vendor=DB_query($vendor_detail,$db);
	$myrow_vendor=DB_fetch_array($result_vendor);
	$vendor_code=$myrow_vendor['vendor_code'];
	$vendor_name=$myrow_vendor['vendor_name'];
	$phone1=$myrow_vendor['phone1'];  
	$phone2=$myrow_vendor['phone2'];  
	$mobile=$myrow_vendor['mobile'];  
	$fax=$myrow_vendor['fax'];
    $email=$myrow_vendor['email'];
	 
	                           
	$vendor_quotation_no=$myrow['vendor_quotation_no'];
	$dateprinted=$myrow['dateprinted'];
	$stat_comment=$myrow['stat_comment'];
	
 
  
 
 if($_REQUEST['comprative_no']){
  $sql1 = "select  Vendor_Quot_No from comprative_detail  where comprative_no  ='".$_REQUEST['comprative_no']."'   order by Comprative_date desc";
  $_SESSION['compare']=$sql1;
	  $vendor_list=array();
			$result_vend=DB_query($sql1,$db);
			while($r=DB_fetch_array($result_vend)){
			$vendor_list[]=$r['Vendor_Quot_No'];
			}
			if(count($vendor_list)>0)
			{
			   $list=implode(',',$vendor_list);
			   //echo $list;
			}
for($k=0;$k<count($vendor_list);$k++)
{
  $vend_sql="SELECT * FROM venderquotations WHERE id ='".$vendor_list[$k]."'";
$result_vend=DB_query($vend_sql,$db);
while($myrowvender=DB_fetch_array($result_vend))
{
	 $quotation_no=$myrowvender['id'];

	$sitecode= $myrowvender['sitecode'];
	$mst_supplierno =$myrowvender['mst_supplierno'];
	$sitename= $myrowvender['site'];
	$vernder_quotation=$myrowvender['vernder_quotation'];
	$event=$myrowvender['event'];
	$billingType=$myrowvender['billingType'];
	$payment_term=$myrowvender['payment_term'];
	$quotationcategory=$myrowvender['quotationcategory'];
	$basis=$myrowvender['basis'];
	$warramtydetails=$myrowvender['warramtydetails'];
	$deliveryterms=$myrowvender['deliveryterms'];
	$payment_mode=$myrowvender['payment_mode'];
	$validtill=$myrowvender['validtill'];
	$remarks=$myrowvender['remarks'];
	$warramtydetails =$myrowvender['warramtydetails '];
	 
	 
	 
	 	  $site_sql="Select * from locations where loccode='".$sitecode."'";
	$site_res=DB_query($site_sql,$db);
	$site_row=DB_fetch_array($site_res);
	 
 
 	$vendor_detail = "Select * from suppliers where id='".$mst_supplierno."'";
	$result_vendor=DB_query($vendor_detail,$db);
	$myrow_vendor=DB_fetch_array($result_vendor);
	$vendor_code=$myrow_vendor['vendor_code'];
	$vendor_name=$myrow_vendor['vendor_name'];
	$phone1=$myrow_vendor['phone1'];  
	$phone2=$myrow_vendor['phone2'];  
	$mobile=$myrow_vendor['mobile'];  
	$fax=$myrow_vendor['fax'];
    $email=$myrow_vendor['email'];
	 
	                           
	$vendor_quotation_no=$myrow['vendor_quotation_no'];
	$dateprinted=$myrow['dateprinted'];
	$stat_comment=$myrow['stat_comment'];
	
			//print_r($vendor_list) ;
 ?>
<link rel="stylesheet" href="css/new_mxerp.css">
<div class="body_contain">
<div class="tab_div">
<h1><?php echo $title; ?></h1>
 <p align="right"><a href="comparitive_exp.php">Export</a><a href="comparitive_print.php?comprative_no=<?php echo $_REQUEST['comprative_no']; ?>">Print</a></p>
<table width="100%" border="0" cellpadding="3" cellspacing="0">
 <tr class="row1">
	 <td class="tabledata1"><strong>Site Code </strong></td>
	 <td class="tabledata1"><strong>Site Name </strong></td>
	 <td class="tabledata1"><strong>Vendor Code </strong></td>
	 <td class="tabledata1"><strong>Vendor Name </strong></td>
 </tr>
<tr class="row1">
	<td width="10%"><?php echo $sitecode;?>&nbsp;</td>
	<td width="10%"><?php echo $sitename?>&nbsp;</td>
	<td><?php echo $vendor_code?>&nbsp;</td>
	<td><?php echo $vendor_name?>&nbsp;</td>
</tr>
<tr class="row1">
	<td class="tabledata1" colspan="4">
<div style="overflow:auto; width:947px;"> 
  <table width="100%" border="1" cellpadding="3" cellspacing="0">
    <tr>
     <td class="tabledata"><strong>Item Code</strong></td>
     <td class="tabledata"><strong>Item Name</strong></td>
     <td class="tabledata"><strong>Make</strong></td>
     <td class="tabledata"><strong>Color</strong></td>
     <td class="tabledata"><strong>Grade</strong></td>
     <td class="tabledata"><strong>Unit</strong></td>
	 <td class="tabledata"><strong>Length</strong></td>
 	 <td class="tabledata"><strong>Width </strong></td>
	 <td class="tabledata"><strong>Origanal/Local</strong></td>
	 <td class="tabledata"><strong>Quality </strong></td>
     <td class="tabledata"><strong>Quantity</strong></td>
     <td class="tabledata"><strong>Rate</strong></td>
     <td class="tabledata"><strong>Discount Type</strong></td>
     <td class="tabledata"><strong>Discount</strong></td>
     <td class="tabledata"><strong>Discount Amount</strong></td>
      <td class="tabledata"><strong>SubTotal</strong></td>
	  <td class="tabledata"><strong>Special <br />Discount<br />Amount</strong></td>     
      <td class="tabledata"><strong>BASIC AMOUNT</strong></td>
       <td class="tabledata"><strong>Taxable Amount </strong></td>
        <td class="tabledata"><strong>TOTAL AMOUNT</strong></td>
      
    </tr>
      <?php   

  
  $totalcharges = $myrowvender['totalcharge'];
$grandtotal   = $myrowvender['grand_total']; 
$totalamount  = $myrowvender['total_amt'];
$taxnameid    = $myrowvender['taxnameid'];
$billingType= $myrowvender['billingType'];
  // $Vendor_Quot_No=$s->GetFieldValue('comprative_detail',"comprative_id='".$_REQUEST['CPID']."'",'Vendor_Quot_No');
 
   $sql="SELECT * FROM vendorquotationdetails WHERE quotation_no='".$quotation_no."'  ";

 $result=DB_query($sql,$db);
$i=1;
while($myrow=DB_fetch_array($result))
{
//echo "<pre>";
//print_r($myrow);

?>
    <tr class="row1">
      <td><?php echo $myrow['prod_id'];?>
          <input type="hidden" name="ProductID[<?php echo $i;?>]" size="10" value="<?php echo $myrow['prod_id'];?>" readonly />
      </td>
      <td><?php echo $myrow['prod_dec'];?>
          <input type="hidden" name="ProductDes[<?php echo $i;?>]" size="45" value="<?php echo $myrow['prod_dec'];?>" readonly /></td>
      <td><?php 
	  $makename=$s->getField('product_manufacture','id',$myrow['make'],'manufacturer');
	  echo ($makename==''?$myrow['make']:$makename);?>
          <input type="hidden" name="make[<?php echo $i;?>]" size="45" value="<?php echo $myrow['make'];?>" readonly /></td>
      <td><?php 
	  $colorname=$s->getField('product_color','id',$myrow['color'],'color');
	  echo $colorname;?>
          <input type="hidden" name="color[<?php echo $i;?>]" size="45" value="<?php echo $myrow['color'];?>" readonly /></td>
      <td><?php 
	  $gradename=$s->getField('product_grade','id',$myrow['grade'],'grade');
	  echo $gradename;?>
          <input type="hidden" name="grade[<?php echo $i;?>]" size="45" value="<?php echo $myrow['grade'];?>" readonly /></td>
      <?php 
/*$unit_sql = "select units from stockmaster where stockid ='".$myrow['prod_id']."'";
$unit_result = DB_query($unit_sql, $db);
$unit_row = DB_fetch_array($unit_result);*/
?>
      <td><?php 
	  $unitname=$s->getField('unitsofmeasure','unitid',$myrow['uom'],'unitname');
	  echo $unitname;?>
          <input type="hidden" name="unit[<?php echo $i;?>]" size="45" value="<?php echo $myrow['uom'];?>" readonly /></td>
	
		  <?php
		 
		   
		  $query_item=DB_query("select * from item_master where StockID='".$myrow['prod_id']."'", $db);
		  	$item_row=DB_fetch_array($query_item);
		   ?>
	 <td><?php echo $item_row['length'];?> </td>
	 <td><?php echo $item_row['width'];?> </td>
  	 <td><?php echo $item_row['orig_local'];?> </td>
	  <td><?php echo $item_row['quality'];?> </td>

 

      <td><input type="hidden" name="quantity[<?php echo $i;?>]" size="5" value="<?php echo $myrow['quantity'];?>" id="Quantity_<?php echo $i;?>" readonly />
          <?php echo $myrow['quantity'];?></td>
      <td><?php echo $myrow['rate'];?>
          <input type="hidden" name="Rate[<?php echo $i;?>]" id="Rate_<?php echo $i;?>" value="<?php echo $myrow['rate'];?>" size="4" readonly/>
      </td>
      <td><?php 
	  if($myrow['discount']=='0')
	  echo "N/A";
	  else
	  echo $myrow['discount_type'];?>
          <input type="hidden" name="discount_type[<?php echo $i;?>]" id="discount_type_<?php echo $i;?>" value="<?php echo $myrow['discount_type'];?>" readonly/>
      </td>
      <td><?php 	   
if($myrow['discount_type']=="PercentAmt")
{?>
      <?php echo $myrow['discount'];?>%
          <input type="hidden" name="Discount[<?php echo $i;?>]" id="Discount_<?php echo $i;?>" value="<?php echo $myrow['discount'];?>" onblur="DiscountAmount(this.value,<?php echo $i;?>)" size="8" readonly />
      <?php 	 }
else 
{?>
      <?php echo $myrow['discount'];?>
          <input type="hidden" name="Discount[<?php echo $i;?>]" id="Discount_<?php echo $i;?>" value="<?php echo $myrow['discount'];?>" onblur="DiscountAmount(this.value,<?php echo $i;?>)" size="8" readonly />
      <?php } ?></td>
      <td><?php echo $myrow['discount_amount'];?>
          <input type="hidden" id="discount_amount_<?php echo $i;?>" name="discount_amount[<?php echo $i;?>]" value="<?php echo $myrow['discount_amount'];?>" readonly/></td>
		 <td><?php echo $myrow['sub_total'];?>
          <input type="hidden" id="NetRate_<?php echo $i;?>" name="NetRate[<?php echo $i;?>]" value="<?php echo $myrow['sub_total'];?>" size="8" readonly/></td>
      
		  <td><?php echo $myrow['specialdiscount_amount']; ?>
<input type="hidden" id="specialdiscount_amount_<?php echo $i;?>" name="specialdiscount_amount[<?php echo $i;?>]" value="<?php echo $myrow['specialdiscount_amount'];?>" size="8" readonly/></td>
      <td> <?php echo $myrow['basic_amt']; ?><?php echo '<input type="hidden" id="basic_'.$i.'" name="basic['.$i.']" size="8" style="width:100%;"  value="'.$myrow['basic_amt'].' " readonly/>';?></td>
	 <td><?php echo $myrow['taxable_amt']; ?><input type="hidden" name="taxable_amt[<?php echo $i;?>]" id="taxable_amt_<?php echo $i;?>" value="<?php echo $myrow['taxable_amt']; ?>" style="width:100%;" onfocus="calculateTaxable(<?php echo $i; ?>)" readonly/></td>
<td><?php echo $myrow['total_amount']; ?><?php echo '<input type="hidden" id="TotalSpecial_'.$i.'" name="TotalSpecial['.$i.']" size="8" style="width:100%;" readonly  onfocus="cal_grandtotal('.$i.');" value="'.$myrow['total_amount'].' "/>';?></td>
      <?php 
	  
	    //$TotBasic[]=$myrow['sub_total']; 
$i++;
}?>

      <input type="hidden" name="PO_count" value="<?php echo $i;?>" />
    </tr>
  </table>
  </div>
	</td>
</tr>
</table>
  
<?php  //}?>

<?php  } 

}
?>


  

<?php  }
 ?>
 </form>