 <?php extract($_POST);
$PageSecurity = 1;
$Prefix_code = "PO";
$Prefix_date = date("y");
	$Prefix_date++;
 	$CurrentFinancialYear = date("y").$Prefix_date; 
 
global $db;?>
 
<?php 
if(isset($_REQUEST['CPID']) && $_REQUEST['CPID']!='') 
$title='Process For Purchase Order';
else
$title='Vendor Quotation';
?>
<br/><?php 

if($_REQUEST['Order'])
{
 
	  	 $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'] ;
		$data['vendor_id']=$rowdata['vendor_id'] ;
		$data['supplierno']=$rowdata['vendor_name'] ;	
		$data['sitecode']=$rowdata['sitecode'] ;		
		$data['delivery_place1']=$_REQUEST['delivery_place1'] ;
		//$data['delivery_place2']=$_REQUEST['delivery_place2'] ;
		$data['mode_of_transport']=$_REQUEST['mode_of_transport'] ;
		$data['freight_details']=$_REQUEST['freight_details'] ;
		$data['transit_insurance']=$_REQUEST['transit_insurance'] ;
		$data['delivery_date']=FormatDateForSQL($_REQUEST['delivery_date']);
		$data['delivery_time']=$_REQUEST['delivery_time'] ;
		$data['contact_person']=$_REQUEST['contact_person'] ;
		$data['valid_till']=FormatDateForSQL($_REQUEST['valid_till']) ;
		$data['vat_cst_per']=$_POST['vat_cst_per'] ;
		$data['vat_cst_amount']=$_POST['vat_cst_amount'] ;
		$data['basic_amt']=$_POST['total_item_amount'];
		$data['sur_oct_amt']=$_POST['sur_oct_amt'];
		$data['fright']=$_POST['TotalCharge'] ;
		$data['pkg_charges']=$_POST['pkg_charges'] ;
		$data['additional_charges']=$_POST['add_charges'] ;
		$data['sur_oct_perc']=$_POST['sur_oct_per'] ;	
		$data['grand_total']=$_POST['GrandTotal'];	
		$data['remarks']=$_POST['remarks'];	
		$type=$rowdata['vendor_name'];
		
		/************************************************************/
	
		 
		$siteCode = $rowdata['sitecode'];
		$siteCode123=substr($siteCode,0,3);
      $sql="select * from purchorders where sitecode = '".$siteCode."'";      
	  $result = DB_query($sql,$db);
	  $numrows = DB_num_rows($result);
	 if($numrows>0)
	 {
			 $i=0;
			 $strmax = "";
			 $myrow=DB_Fetch_array($result);
			 
		 //if($siteCode!='')
				//$val1= substr($myrow['purchorders'],0,18);
				//$strChar1 = substr($myrow['purchorders'],0,7);
				//$strChar = $strChar1."/".$siteCode."/".$CurrentFinancialYear."/";  
			
			if($numrows>0)
			{ 
				$maxval = $numrows;
			}
			else
			{
				$maxval=0;
			}
		{
			$strChar = $siteCode123."/".$Prefix_code."/".$CurrentFinancialYear."/";
		}
	  }
	  else
	  {
	  	$strChar = $siteCode123."/".$Prefix_code."/".$CurrentFinancialYear."/";
	  }
	  
	 $strFinal = $maxval+1;
	 $strBothFinal = $strChar.str_pad($strFinal,6,"0",STR_PAD_LEFT); 
	 $data['PO_Orderno']=$strBothFinal;
	 $data['Po_recive_status']= 'Pending';
	 $data['pkg_per']=$_REQUEST['pkg_per'];
	 $data['orddate']=date('Y-m-d');
	 $insert=$s->RecordInsert('purchorders', $data);
	 $last_id=DB_Last_Insert_ID($db,'purchorders','id');
	 $itemno1=$rowdata['mst_product_list']; 
		
			$sub_cats=explode(",",$itemno1);
			$itemno=implode("','",$sub_cats);
			for($i=1;$i<=count($_REQUEST['mst_productid']);$i++)
				{	
			        $purchorderdetails_sql="insert into purchorderdetails set
											id='',											
											orderno='".$last_id."',
											mst_reqino ='".$rowdata['RequisitionNo']."',
											mst_itemid='".$_REQUEST['mst_productid'][$i]."',
											prod_id='".htmlspecialchars($_REQUEST['ProductID'][$i],ENT_QUOTES)."',
 											prod_dec='".htmlspecialchars($_REQUEST['ProductDes'][$i],ENT_QUOTES)."',
											quatity='".$_REQUEST['quantity'][$i]."',
											rate='".$_REQUEST['Rate'][$i]."',
											discount_type='".$_POST['discount_type'][$i]."',
											discount='".$_POST['Discount'][$i]."',
											discount_amount='".$_POST['discount_amount'][$i]."',
											Sub_total='".$_POST['NetRate'][$i]."',
											specialdiscount_amount='".$_POST['specialdiscount_amount'][$i]."',											
											basic_amt='".$_POST['basic'][$i]."',
											tax_type='".$_POST['hid_billing_type'][$i]."',
											Excise_Duty='".$_POST['exciseDuty'][$i]."',
											ExcisePercentage='".$_POST['ExcisePercentage'][$i]."',
											Excise_Duty_value='".$_POST['exciseValue'][$i]."',
											Edu_Cess_perc='".$_POST['ECessPercentage'][$i]."',
											Edu_Cess='".$_POST['ECessValue'][$i]."',
											SHE_Cess_perc='".$_POST['SAHCessPercentage'][$i]."',
											SHE_Cess='".$_POST['SAHCessValue'][$i]."',
											taxabel_amt='".$_POST['taxable_amt'][$i]."',											
											item_no='".$_POST['item_no'][$i]."',
											Make='".$_POST['make'][$i]."',
											Color='".$_POST['color'][$i]."',
											Grade='".$_POST['grade'][$i]."',
											UOM='".$_POST['unit'][$i]."',	
											specialdis_type='".$_REQUEST['specialdis_type'][$i]."',
						                    specialdiscount='".$_REQUEST['special_discount'][$i]."',										
											totalamount='".$_POST['TotalSpecial'][$i]."'";											
			
					$details_res=DB_query($purchorderdetails_sql,$db); 
/********************************************************************************************************/				
		
			$ssl=DB_query("select * from requisitionorderdetails  where requsitionno='".$rowdata['RequisitionNo']."' and mst_itemid='".$_REQUEST['mst_productid'][$i]."' ",$db);		
		     $ssldata=DB_fetch_array($ssl);
				if($ssldata['App_quantity1']==0)
			    {	
				$updatedata=DB_query("update requisitionorderdetails set item_status=1 where requsitionno='".$rowdata['RequisitionNo']."' and product_id='".$_REQUEST['ProductID'][$i]."'",$db);		
		        }				
				}		
				
		$countcheckstatus=0;
		$datareq=DB_query("select * from requisitionorderdetails where requsitionno='".$rowdata['RequisitionNo']."'",$db);
		while($datareqdata=DB_fetch_array($datareq))
		{
		if($datareqdata['item_status']==1)
		{
		$countcheckstatus=1;	
		}			
		}
		if($countcheckstatus==1)
		{
		$dataCompList['status_active']=1;	
		}
       else
        {
	    $dataCompList['status_active']=0;
        }				
		$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&CPID=".$_REQUEST['CPID'].'&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'); 
  $vendor_quotation_type=$s->GetFieldValue('comprative_detail',"comprative_id='".$_REQUEST['CPID']."'" ,'Quotations_type'); 
  ?>

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

 ?>
 <link rel="stylesheet" href="css/new_mxerp.css">
<div class="body_contain">
<div class="tab_div">
<h1><?php echo $title; ?></h1>
 <form action="" method="post">
<table width="100%" cellpadding="3" cellspacing="0">
<tr class="row1">
	<td class="tabledata1">
		<h3>Item Details</h3>
	</td>
</tr>
<tr class="row1">
	<td class="tabledata1">
	<div style="overflow:auto; width:947px; height:auto; background:#FFFFFF"> 
  <table width="100%" border="1" cellpadding="3" cellspacing="0">
   <tr class="row1">
      <td class="tabledata"><strong>Item Code</strong></td>
      <td class="tabledata"><strong>Item Name</strong></td>
      <td class="tabledata"><strong>Item No</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>
	   <th ><strong>BASIC AMOUNT</strong></td>
	   <th ><strong>Excise flag</strong></td>
	   <td class="tabledata"><strong>Excise</strong></td>
	   <td class="tabledata"><strong>E-Cess</strong></td>					
		<td class="tabledata"><strong>SAH-E Cess</strong></td>					
		<td class="tabledata"><strong>Taxable Amount </strong></td>
		<!--<td class="tabledata"><strong>VAT/CST</strong></td>
		<td class="tabledata"><strong>VAT/CST Amount</strong></td>	-->				
		<td class="tabledata"><strong>TOTAL AMOUNT</strong></td>	
</tr>
	 
	 	<?php 
	$sqldata=DB_query("select id from vendor_quotes_ammendment where old_quotetion_no='".$Vendor_Quot_No."' order by revision_no DESC limit 1 ",$db);
	$vend=DB_fetch_array($sqldata);
	 $Vendor_Quot_No1=$vend['id'];				
  $vend_sql="SELECT * FROM vendor_quotes_ammendment WHERE id='".$Vendor_Quot_No1."'";
  $result_vend=DB_query($vend_sql,$db);
  $myrowvender=DB_fetch_array($result_vend);
     $grand_total=$myrowvender['grand_total'];
       $totalcharge =$myrowvender['freight'];
	$totalamount =$myrowvender['total_amt'];
	$taxnameid   =$myrowvender['taxnameid'];
	$billingType =$myrowvender['billingType'];
  	$sur_oct_amt =$myrowvender['sur_oct_amt'];
	//$totalcharge =$myrowvender['totalcharge'];
	$pkg_charges =$myrowvender['pkg_charges'];
	$pkg_per=$myrowvender['pkg_per'];
	 $add_charges =$myrowvender['additional_charges'];
	$vat_cst_amount=$myrowvender['vat_cst_amount'];
	$vat_cst_per=$myrowvender['vat_cst_per'];
 	$sur_oct_perc  =$myrowvender['sur_oct_per'];
	
  // $Vendor_Quot_No=$s->GetFieldValue('comprative_detail',"comprative_id='".$_REQUEST['CPID']."'",'Vendor_Quot_No');
if(isset($_REQUEST['CPID'])&& $_REQUEST['CPID']!=''){
$totalamount=0;	
$sql="SELECT * FROM vendor_quotes_ammendment_details WHERE vendor_quotes_ammendment_id='".$Vendor_Quot_No1."' and   FIND_IN_SET( item_id,'$ITEMLIST' );";
}else{
$sql="SELECT * FROM vendor_quotes_ammendment_details WHERE quotation_no='".$Vendor_Quot_No."'  ";

}
//echo $sql;
$result=DB_query($sql,$db);
$i=1;$j=0;
//echo $sql;
while($myrow=DB_fetch_array($result))
{
if($j==0)
{				   	
$check=DB_query("select assign_qty from comprative_detail where  quotation_id in(".$myrow['id'].")",$db);
$checkdata=DB_fetch_array($check);			   	
$quantity2=explode(",",$checkdata['assign_qty']);	
}

if($quantity2[$j]=='0.00'|| empty($quantity2[$j]))
{
$quantity=$myrow['quantity'];	
}
else {
$quantity=$quantity2[$j];
}
// echo $quantity; 	
if($myrow['discount']=='Amount')
{
$subtotalamount1=$myrow['discount_amount'];
$subtotalamount2=($quantity*$myrow['rate'])-$myrow['discount_amount'];
$subtotalamount=$subtotalamount2;	
	
}
else {
$subtotalamount1=(($quantity*$myrow['rate'])*$myrow['discount_per'])/100;
$subtotalamount=($quantity*$myrow['rate'])-$subtotalamount1;
}
if($myrow['specialdis_type']=='Amount')
{
$basicamount1=$myrow['special_discount_amount'];	
$basicamount=$subtotalamount-$basicamount1;	
}
else
{
$basicamount1=($subtotalamount*$myrow['special_discount'])/100;	
$basicamount=$subtotalamount-$basicamount1;	
}


if($myrow['tax_type']=='IncludeTax')
{
$taxvalue=0;
$taxvalue1=0;
$taxvalue2=0;	
$taxableamount=0;
//$vatamount=0;
$totalamount1=$basicamount;	
}
else if($myrow['tax_type']=='Excisable')
{
//$vatper=$s->getField('service_tax_master','id',$myrow['taxname'],'taxrate');	
$taxvalue=($basicamount*$myrow['excise_percentage'])/100;
$taxvalue1=($taxvalue*$myrow['ecess_per'])/100;	
$taxvalue2=($taxvalue*$myrow['sah_ecess_per'])/100;
$taxableamount=$taxvalue+$taxvalue1+$taxvalue2;
//$vatamount=($taxableamount*$vatper)/100;
//$totalamount1=$taxableamount+$vatamount;	
$totalamount1=$taxableamount+$basicamount;
}
else
{
$taxvalue=0;
$taxvalue1=0;
$taxvalue2=0;	
$taxableamount=0;
//$vatper=$s->getField('service_tax_master','id',$myrow['taxname'],'taxrate');
//$vatamount=($basicamount*$vatper)/100;
//$totalamount1=$basicamount+$vatamount;	
$totalamount1=$basicamount;	
}

$totalamount=$totalamount1+$totalamount;

 $grand_total=$totalamount+$sur_oct_amt+$totalcharge+$pkg_charges+$add_charges+$vat_cst_amount;




//echo "<pre>";
//print_r($myrow);
if($i%2==0)
{$bg="#CCCCCC";}
else
$bg="#C8BECB";
?>
    <tr class="row1">
       <td><?php echo $myrow['item_code'];?>
       	<input type="hidden" name="mst_productid[<?php echo $i;?>]"  value="<?php echo $myrow['item_id'];	 ?>"   />
        <input type="hidden" name="ProductID[<?php echo $i;?>]2" size="10" value="<?php echo $myrow['item_code'];?>" readonly />
    </td>
    <td><?php echo $myrow['item_name'];?>
        <input type="hidden" name="ProductDes[<?php echo $i;?>]2" size="45" value="<?php echo $myrow['item_name'];?>" readonly /></td>
    <td><?php 
	//echo "id=-=".$myrow['item_id'];
	
	echo $s->getField('item_master','id',$myrow['mst_productid'] ,'item_no');  ?></td>
    <td><?php 
	  $makename=$s->getField('product_manufacture','id',$myrow['make'],'manufacturer');
	  echo $makename;?>
        <input type="hidden" name="make[<?php echo $i;?>]2" 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;?>]2" 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;?>]2" size="45" value="<?php echo $myrow['grade'];?>" readonly /></td>
      <td><?php 
	  $unitname=$s->getField('unitsofmeasure','unitid',$myrow['uom'],'unitname');
	  echo $unitname;?>
        <input type="hidden" name="unit[<?php echo $i;?>]2" 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;?>]2" size="5" value="<?php echo $quantity;?>" id="quantity[<?php echo $i;?>]" readonly />
        <?php echo $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'];?>
        <input type="hidden" name="discount_type[<?php echo $i;?>]2" id="discount_type[<?php echo $i;?>]" value="<?php echo $myrow['discount'];?>" readonly/>
    </td>
    <td><?php 	   
if($myrow['discount']=="PercentAmt")
{?>
        <?php echo $myrow['discount_per'];?>%
      <input type="hidden" name="Discount[<?php echo $i;?>]2" 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_per'];?>
        <input type="hidden" name="item_no[]" value="<?php echo $myrow['item_no']; ?>" />
        <input type="hidden" name="Discount[<?php echo $i;?>]2" 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 $subtotalamount1;?>
        <input type="hidden" id="discount_amount[<?php echo $i;?>]" name="discount_amount[<?php echo $i;?>]2" value="<?php echo $subtotalamount1;?>" readonly/></td>
         <td><?php echo $subtotalamount;?>
         <input type="hidden" id="NetRate[<?php echo $i;?>]" name="NetRate[<?php echo $i;?>]" style="width:100%;"  value="<?php echo $subtotalamount; ?>"/>
     	      	
         </td> 
    <td><?php echo $basicamount1; ?>
       <input type="hidden" name="specialdis_type[<?php echo $i;?>]"  value="<?php echo  $myrow['specialdis_type']; ?>"/>
        <input type="hidden" name="special_discount[<?php echo $i;?>]" value="<?php echo $myrow['specialdiscount'];?>" id="special_discount_<?php echo $i;?>"  />
        <input type="hidden" id="specialdiscount_amount[<?php echo $i;?>]" name="specialdiscount_amount[<?php echo $i;?>]2" value="<?php echo $basicamount1;?>" size="8" readonly/></td>
    <td><?php echo round($basicamount,2); ?>
     	<input type="hidden" id="basic[<?php echo $i;?>]" name="basic[<?php echo $i;?>]" style="width:100%;"  value="<?php echo $basicamount; ?>"/>
     	
     	
     </td>
     <td><?php echo $myrow['tax_type']; ?>
     <input type="hidden" name="hid_billing_type[<?php echo $i; ?>]" value="<?php echo $myrow['tax_type']; ?>"/>
    	
     	
     </td>
     <td><?php echo round($taxvalue,2); ?>
     	<input name="Excise_Duty[<?php echo $i;?>]" id="Excise_Duty<?php echo $i;?>" type="hidden" value="<?php echo $myrow['Excise_Duty'];?>"  style="width:100%;" readonly /> 
     
     	<input name="ExcisePercentage[<?php echo $i;?>]" id="ExcisePercentage_<?php echo $i;?>" type="hidden" value="<?php echo $myrow['ExcisePercentage'];?>"  style="width:100%;" readonly /> 
     <input type="hidden" name="exciseValue[<?php echo $i; ?>]" value="<?php echo $taxvalue; ?>"/>
     	
     	
     </td>
     <td><?php echo round($taxvalue1,2); ?>
     	<input name="ECessPercentage[<?php echo $i;?>]" id="ECessPercentage<?php echo $i;?>" type="hidden" value="<?php echo $myrow['Edu_Cess_perc'];?>"  style="width:100%;" readonly /> 
  
     <input type="hidden" name="ECessValue[<?php echo $i; ?>]" value="<?php echo round($taxvalue1,2); ?>"/>
    	
     </td>
     <td><?php echo round($taxvalue2,2); ?>
     	<input name="SAHCessPercentage[<?php echo $i;?>]" id="SAHCessPercentage<?php echo $i;?>" type="hidden" value="<?php echo $myrow['SHE_Cess_perc'];?>"  style="width:100%;" readonly /> 
  
     	<input type="hidden" name="SAHCessValue[<?php echo $i; ?>]" value="<?php echo round($taxvalue2,2); ?>"/>
     
     </td>
     <td><?php echo round($taxableamount,2); ?>
     <input type="hidden" name="taxable_amt[<?php echo $i; ?>]" value="<?php echo round($taxableamount,2); ?>">    </td>
     <!--<td><?php echo $s->getField('service_tax_master','id',$myrow['taxname'],'tax_code'); ?>
     <input type="hidden" name="taxname[<?php echo $i; ?>]" value="<?php echo  $myrow['taxname']; ?>"/>
   	
     	
     </td>
      <td><?php echo round($vatamount,2); ?>
      <input type="hidden" name="taxvalue[<?php echo $i; ?>]" value="<?php echo round($vatamount,2); ?>"/>
   	
      </td>-->
    
    
    <td><?php echo round($totalamount1,2); ?>
     <input type="hidden" id="TotalSpecial_<?php echo $i;?>" name="TotalSpecial[<?php echo $i;?>]" size="8" style="width:100%;" readonly  value="<?php echo round($totalamount1,2); ?>"/>
    	
     </td>
     
     	
     	
     
     

      <?php 	  
	   
$i++;$j++;
}?>
      <input type="hidden" name="PO_count" value="<?php echo $i;?>" />
    </tr>
  </table>
  
  </div>
	</td>
</tr>
  
<tr class="row1">
	<td class="tabledata1">
	<div align="right">	
</br>
<?php if(isset($_REQUEST['POID']))
{
	
	$POSQL=DB_query("Select * from purchorders where orderno='".$_REQUEST['POID']."'",$db);
	$PORESULT=DB_fetch_array($POSQL);
	
	$delivery_place1=$PORESULT['delivery_place1'];
	//$delivery_place2=$PORESULT['delivery_place2'];
	$mode_of_transport=$PORESULT['mode_of_transport'];
	$freight_details=$PORESULT['freight_details'];
	$transit_insurance=$PORESULT['transit_insurance'];
	$delivery_date=$PORESULT['delivery_date'];
	$delivery_time=$PORESULT['delivery_time'];
	$contact_person=$PORESULT['contact_person'];
	$valid_till=$PORESULT['valid_till'];
}
else
{
	
	$POSQL=DB_query("Select * from purchorders where mst_vendor_quotesid='".$Vendor_Quot_No."'",$db);
	$PORESULT=DB_fetch_array($POSQL);
	
	$delivery_place1=$PORESULT['delivery_place1'];
	//$delivery_place2=$PORESULT['delivery_place2'];
	$mode_of_transport=$PORESULT['mode_of_transport'];
	$freight_details=$PORESULT['freight_details'];
	$transit_insurance=$PORESULT['transit_insurance'];
	$delivery_date=$PORESULT['delivery_date'];
	$delivery_time=$PORESULT['delivery_time'];
	$contact_person=$PORESULT['contact_person'];
	$valid_till=$PORESULT['valid_till'];
}
?>
<?php if($CHECK_POSTATUS!=0 && $_REQUEST['CPID']!='')
{?>
<table border="0" width="100%" cellpadding="3" cellspacing="0">
<tr class="row1">
<td width="40%"  align="left">
<table width="100%" border="0" align="left" cellpadding="3" cellspacing="0">
<tr class="row1">
<td class="tabledata1" rowspan="2"  width="168">Delivery Place</td>
<td><?php echo $delivery_place1;?></td>
</tr>
<tr class="row1">
<td width="198"><?php echo $delivery_place2;?></td>
</tr>
<tr class="row1">
<th width="168">Mode Of Transport</td>
<td><?php echo $mode_of_transport;?></td>
</tr>
<tr class="row1">
<td class="tabledata1" width="168">Freight</td>
<td><?php echo $freight_details;?></td>
</tr>
<tr class="row1">
<td class="tabledata1" width="168">Transit Insurance</td>
<td><?php echo $transit_insurance;?></td>
</tr>
<tr class="row1">
<td class="tabledata1" width="168">Delivery Date</td>
<td><?php echo $delivery_date;?></td>
</tr>
<tr class="row1">
<td class="tabledata1" width="168">Delivery Time</td>
<td><?php echo $delivery_time;?></td>
</tr>
<tr class="row1">
<td class="tabledata1" width="168">Contact Person</td>
<td><?php echo $contact_person;?></td>
</tr>
<tr class="row1">
<td class="tabledata1" width="168">Valid Till</td>
<td><?php echo $valid_till;?></td>
</tr>
</table>
</td>
<td width="60%">
<table width="50%" border="0" cellpadding="3" cellspacing="0" align="right">
               <?php
    			
             $grand_total=$totalamount+$sur_oct_amt+$totalcharge+$pkg_charges+$add_charges;
               ?>
               
                <tr class="row1">
                 <td class="tabledata1"><strong>TOTAL AMOUNT</strong> </td>
                  <td ><input type="text" name="total_item_amount" id="total_item_amount" value="<?php echo $totalamount;?>" style="width:100%;" onfocus="cal_totalamount()" readonly="readonly" /></td>
                </tr>
            
                <tr class="row1">
                  <td class="tabledata1"><strong>Surcharge Amount</strong> </td>
                  <td><input name="sur_oct_amt" type="text" id="sur_oct_amt" value="<?php echo $sur_oct_amt; ?>" style="width:100%;" readonly="readonly"/></td>
                </tr>
               <tr class="row1">
                  <td class="tabledata1"><strong>Freight</strong> </td>
                  <td><input type="text" name="TotalCharge" id="TotalCharge" value="<?php echo $totalcharge; ?>" style="width:100%;" readonly="readonly"/></td>
                </tr>
                <tr class="row1">
                  <td class="tabledata1"><strong>Pkg Charges</strong> </td>
                  <td><input name="pkg_charges" id="packagingCharges" type="text" value="<?php echo $pkg_charges; ?>" size="25" style="width:100%;" readonly="readonly"/></td>
                </tr>
                <tr class="row1">
                  <td class="tabledata1"><strong>Additional Charges</strong> </td>
                  <td><input name="add_charges" id="additionalCharges" type="text" value="<?php echo $add_charges; ?>" size="25" style="width:100%;" readonly="readonly"/></td>
                </tr>
				
				
               <tr class="row1">
                  <td><input type="button" name="grandbutton" value="Grand Total" onclick="cal_grandamount()"/></td>
                  <td><input type="text" name="GrandTotal" id="GrandTotal" value="<?php  echo $grand_total; ?>" style="width:100%;" readonly="readonly" /></td>
                </tr>
              </table>

</td>

</tr></table>
<?php }
else {
 ?>

<table border="0" cellpadding="3" cellspacing="0" width="100%">
<tr class="row1">
<td width="40%" valign="top">
<table border="0" cellpadding="3" cellspacing="0" width="100%">
<tr class="row1">
<td class="tabledata1" rowspan="2">Delivery Place</td>
<td>

<!--<select name="de_place2" id="de_place2"	style="width:100%" onchange="showdata(this.value);"  >
<option value="">Select Delivery Place</option>
<?php 

//$branch=DB_query("select * from locations",$db);
     // while($branch_data=DB_fetch_array($branch))
	 // {
	 
	   $branch=DB_query("select * from locations where loccode='".$_REQUEST['site']."'",$db);	
		$branch_data=DB_fetch_array($branch); 
		
?>	
<option value="<?php //echo $branch_data['loccode']; ?>"><?php //echo $branch_data['locationname']; ?></option>
<?php //} ?>	
</select>	-->
<input type="text" name="delivery_place1" id="delivery_place1" value="<?php echo $branch_data['deladd1'];?>" style="width:100%" />
	<!--<input type="text" name="delivery_place1" id="delivery_place1" value="<?php echo $delivery_place1;?>" style="width:100%" />--></td></tr>
	
<tr class="row1">
<td id="divdata" style="display: none;">
<!--<input type="text"   name="delivery_place1" id="delivery_place1" value="<?php echo $delivery_place2;?>" style="width:100%" readonly/>--></td>
</tr>
<tr class="row1">
<td class="tabledata1">Mode Of Transport</td>
<td>
<select name="mode_of_transport" id="mode_of_transport" style="width:100%">
<option value="By Road" <?php if($mode_of_transport=='By Road') echo "selected";?>>By Road</option>
<option value="By Air" <?php if($mode_of_transport=='By Air') echo "selected";?>>By Air</option>
<option value="By Sea" <?php if($mode_of_transport=='By Sea') echo "selected";?>>By Sea</option>
</select></td></tr>

<tr class="row1">
<td class="tabledata1">Freight</td>
<td><input type="text" name="freight_details" id="freight_details" value="<?php echo $freight_details;?>" style="width:100%"/></td></tr>
<tr class="row1">
<td class="tabledata1">Transit Insurance</td>
<td><input type="text" name="transit_insurance" id="transit_insurance" value="<?php echo $transit_insurance;?>" style="width:100%"/></td></tr>

<tr class="row1">
<td class="tabledata1">Delivery Date</td>
<td><input type="text" name="delivery_date" id="delivery_date" value="<?php echo ConvertSQLDate($delivery_date);?>" style="width:100%" class="datepicker"  onchange="checkvalidate()"   /></td>
</tr>
<tr class="row1">
<td class="tabledata1">Delivery Time</td>
<td>
<select name="delivery_time" id="delivery_time" style="width:100%">
<option value="">Select Delivery Time</option>	
<option value="9 am to 9 pm">9 am to 9 pm</option>
<option value="9 pm to 9am">9 pm to 9am</option>
<option value="Any time">Any time</option>
	
</select>	
	<!--<input type="text" name="delivery_time" id="delivery_time" value="<?php echo $delivery_time;?>" style="width:100%"/>--></td></tr>
<tr class="row1">
<td class="tabledata1">Contact Person</td>
<td><input type="text" name="contact_person" id="contact_person" value="<?php echo $contact_person;?>" style="width:100%"/></td></tr>
<tr class="row1">
<td class="tabledata1">Valid Till</td>
<td><input type="text"  class="datepicker" name="valid_till" id="valid_till" value="<?php echo ConvertSQLDate($valid_till);?>" style="width:100%"  onchange="checktilldate()"   /></td>
</tr>
</table>
</td>

<td width="60%">
<table width="50%" border="0" cellspacing="0" cellpadding="3" align="right">
    <tr class="row1">
      <td class="tabledata1"><strong>TOTAL AMOUNT </strong> </td>
                  <td ><input type="text" name="total_item_amount" id="total_item_amount" value="<?php echo round($totalamount,2);?>" style="width:100%;" onfocus="cal_totalamount()" readonly="readonly" /></td>
   </tr>
   <tr class="row1">
                	<?php
                $pkg_charges=($totalamount*$pkg_per)/100;
                
                
                ?>	
       <td class="tabledata1"><strong>Pkg Charges</strong> </td>
                  <td><input type="hidden" name="pkg_per"  value="<?php echo $pkg_per; ?>"/>
                  	
                  	<input name="pkg_charges" id="packagingCharges" type="text" value="<?php echo round($pkg_charges,2); ?>" size="25" style="width:100%;" readonly="readonly"/></td>
                </tr>
      <tr class="row1">
		      <td class="tabledata1"><strong>Vat(description)<strong></td>		
		<td><?php $val1=$s->getField('service_tax_master','id',$vat_cst_per,'tax_code');
		$val2= $s->getField('service_tax_master','id',$vat_cst_per,'taxrate');
		$dataval= $val1 ."---".$val2."%"; ?>	
		<input type="text" name="vatcst_code" value="<?php echo $dataval; ?>" style="width:100%;"/>
		<input type="hidden" name="vat_cst_per" value="<?php echo $vat_cst_per; ?>"/>
			
		</td>
		</tr>
	 <tr class="row1">
			<?php
		$vat_cst_amount=(($totalamount+$pkg_charges)*$val2)/100;
		 
		?>
		<td class="tabledata1"><strong>Vat/Cst Amount</strong></td>
		<td><input type="text" name="vat_cst_amount" value="<?php echo $vat_cst_amount; ?>" style="width:100%;"> </td>	
			</tr>	
            
        <tr class="row1">
            <td class="tabledata1"><strong>Surcharge Amount</strong> </td>
                  <td><input type="hidden" name="sur_oct_per" value="<?php echo $sur_oct_per; ?>" />
                  	<?php
                  	echo $sur_oct_per;
	            $sur_oct_amt=($vat_cst_amount*$sur_oct_perc)/100;
		 
		?>
                  	<input name="sur_oct_amt" type="text" id="sur_oct_amt" value="<?php echo round($sur_oct_amt,2); ?>" style="width:100%;" readonly="readonly"/></td>
                </tr>
      <tr class="row1">
               <td class="tabledata1"><strong>Freight</strong> </td>
                  <td><input type="text" name="TotalCharge" id="TotalCharge" value="<?php echo round($totalcharge,2); ?>" style="width:100%;" readonly="readonly"/></td>
                </tr>
     <tr class="row1">
          <td class="tabledata1"><strong>Additional Charges</strong> </td>
                  <td><input name="add_charges" id="additionalCharges" type="text" value="<?php echo round($add_charges,2); ?>" size="25" style="width:100%;" readonly="readonly"/></td>
                </tr>	
               <?php  $grand_total=$totalamount+$sur_oct_amt+$totalcharge+$pkg_charges+$add_charges+$vat_cst_amount;
               ?> 			
       <tr class="row1">
                 <td class="tabledata1"><strong>GrandTotal</strong></td>
                  <td><input type="text" name="GrandTotal" id="GrandTotal" value="<?php  echo round($grand_total,2); ?>" style="width:100%;" readonly="readonly" /></td>
                </tr>
</table>
</td>
</tr>



</table>
<table width="100%" border="0" cellspacing="0" cellpadding="3" align="right">
 <tr class="row1">
                  <td class="tabledata1"><strong>Remarks</strong> </td>
                  <td ><textarea  name="remarks" id="remarks" style="width:100%;" ></textarea></td>
                </tr>	</table>
	 <?php } ?>		
			

  </td></tr></table>

 </div>
	</td>
</tr>
</table>
 <br />
<?php 
if($CHECK_POSTATUS==0 && $_REQUEST['CPID']!='')
 
{
?>
 <p align="center"><input name="Order" type="submit" value="Process Order"  onclick="return validate();"/></p>
<?php } elseif(  $_REQUEST['CPID']!='')
{
   echo "<h2 align='center'>Purchase Order Already Generated</h2>";
}?>
 </form>
 
<script language="JavaScript">
	
function checkvalidate()
{
	
var curr_date2='';	
var curr_month2='';
var d = new Date();
//alert(d.format("m/dd/yy"));
var curr_date = d.getDate();
var curr_month1 = d.getMonth();
var curr_year = d.getFullYear();
var curr_month=curr_month1+1;
var t=curr_month;
var d=curr_date;
if(t!=10 || t!=11 ||t!=12 )
{
 curr_month2="0" + curr_month;	
}
else
{
 curr_month2=curr_month;	
}
if(d==1 || d==2 || d==3 || d==4 || d==5 || d==6 || d==7 || d==8 || d==9 )
{
 curr_date2="0" + curr_date;		
}
else
{
 curr_date2=curr_date;		
}


var datedat=(curr_date2 + "/" + curr_month2 
+ "/" + curr_year);
var del=document.getElementById("delivery_date").value;	
if(del<datedat)
{
alert("Delivery  Date Not less then current  Date");
//document.getElementById("delivery_date").value='';
document.getElementById("delivery_date").focus;	
return false;	
}


}
function checktilldate()
{
var curr_date2='';	
var curr_month2='';
var d = new Date();
//alert(d.format("m/dd/yy"));
var curr_date = d.getDate();
var curr_month1 = d.getMonth();
var curr_year = d.getFullYear();
var curr_month=curr_month1+1;
var t=curr_month;
var d=curr_date;
if(t!=10 || t!=11 ||t!=12 )
{
 curr_month2="0" + curr_month;	
}
else
{
 curr_month2=curr_month;	
}
if(d==1 || d==2 || d==3 || d==4 || d==5 || d==6 || d==7 || d==8 || d==9 )
{
 curr_date2="0" + curr_date;		
}
else
{
 curr_date2=curr_date;		
}	
var datedat=(curr_date2 + "/" + curr_month2 
+ "/" + curr_year);
var del1=document.getElementById("valid_till").value;	
if(del1<datedat)
{
alert("Valid Till Date Not less then current  Date");
//document.getElementById("valid_till").value='';
document.getElementById("valid_till").focus;	
return false;	
}	
	
	
}	
	
	
	
	
function validate()
{
var curr_date2='';	
var curr_month2='';
var d = new Date();
//alert(d.format("m/dd/yy"));
var curr_date = d.getDate();
var curr_month1 = d.getMonth();
var curr_year = d.getFullYear();
var curr_month=curr_month1+1;
var t=curr_month;
var d=curr_date;
if(t!=10 || t!=11 ||t!=12 )
{
 curr_month2="0" + curr_month;	
}
else
{
 curr_month2=curr_month;	
}
if(d==1 || d==2 || d==3 || d==4 || d==5 || d==6 || d==7 || d==8 || d==9 )
{
 curr_date2="0" + curr_date;		
}
else
{
 curr_date2=curr_date;		
}


var datedat=(curr_date2 + "/" + curr_month2 
+ "/" + curr_year);

if(document.getElementById("delivery_place1").value=='')
{
alert("Must Enter Delivery Place");
document.getElementById("delivery_place1").focus();
return false;	
}
if(document.getElementById("delivery_date").value=='')
{
alert("Must Enter Delivery Date");
document.getElementById("delivery_date").focus();
return false;	
}
if(document.getElementById("delivery_date").value!='')
{

var del=document.getElementById("delivery_date").value;	
}
if(del<datedat)
{
alert("Delivery  Date Not less then current  Date");
document.getElementById("delivery_date").focus();	
return false;	
}
if(document.getElementById("delivery_time").value=='')
{
alert("Must Enter Delivery Time");
document.getElementById("delivery_time").focus();
return false;	
}
if(document.getElementById("contact_person").value=='')
{
alert("Must Enter Contact Person Name");
document.getElementById("contact_person").focus();
return false;	
}
var del1=document.getElementById("valid_till").value;	
if(del1<datedat)
{
alert("Valid Till Date Not less then current  Date");
//document.getElementById("valid_till").value='';
document.getElementById("valid_till").focus;	
return false;	
}	
return true;		
}	
	
function showdata(str)
{
if (str=='')
  {
  document.getElementById("divdata").innerHTML="";
 
  return;
  }
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    	document.getElementById("divdata").style.display='block';
    document.getElementById("divdata").innerHTML=xmlhttp.responseText;
      }
  }
 
xmlhttp.open("GET","geteditdatapo.php?site="+str,true);
xmlhttp.send();
}	
</script>