 <?php extract($_POST);
$PageSecurity = 1;
 
global $db;?>
<?php 
if(isset($_REQUEST['CPID']) && $_REQUEST['CPID']!='') 
$title='Purchase Order';
else
$title='Vendor Quotation';


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'); 
  ?>

<?php }


 ?>
 
<?php 
if($_REQUEST['idfy_quotes']=='QUOT')
{

}
if($_REQUEST['AMDPOID']!=''){$sql_po = "Select * from purchorders_ammd where orderno='".$_GET['AMDPOID']."'";}
else{
  $sql_po = "Select * from purchorders where orderno='".$_GET['POID']."'"; }
 //echo $sql_po ;
	$result=DB_query($sql_po,$db);
	$myrow=DB_fetch_array($result);
	//echo "<pre>";
	//print_r($myrow);
	
	
	$orddate=$myrow['orddate'];
	$PO_Orderno=$myrow['PO_Orderno'];
	$ammndmnt_no=$myrow['ammndmnt_no'];
	$date1=$myrow['date1'];
	$date2=$myrow['date2'];
	$version1=$myrow['version1'];
	$revised=$myrow['revised'];
	$deliveryby=$myrow['deliveryby'];
	$deliverydate=$myrow['delivery_date'];
	$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');
	
	
	
	
	
	$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'];  
	$adrress1=$myrow_vendor['adrress1'];
	$adrress2=$myrow_vendor['adrress2'];
	$address3=$myrow_vendor['address3'];
	$phone2=$myrow_vendor['phone2'];  
	$mobile=$myrow_vendor['mobile'];
	$tin_no=$myrow_vendor['tin_no'];  
	$fax=$myrow_vendor['fax'];
    $email=$myrow_vendor['email'];	                           
	$vendor_quotation_no=$myrow['vendor_quotation_no'];
	$dateprinted=$myrow['dateprinted'];
	$stat_comment=$myrow['stat_comment'];
	$vendor_payment_terms=$myrow_vendor['payterms'];

 ?>
 

 	  	  
<link rel="stylesheet" href="css/new_mxerp.css">
<div class="body_contain">
<div class="tab_div">
<h1><?php echo $page_title;?></h1>
<table width="100%" border="0" cellpadding="3" cellspacing="0">
<tr class="row1">
	<td class="tabledata1"><strong>PO Date </strong></td>
    <td><input type="text" value="<?php echo ConvertSQLDate($orddate);?>" style="width:150px;" readonly="true"/></td>
    <td class="tabledata1"><strong>PO Number </strong></td>
    <td><input name="text" type="text" value="<?php if($_REQUEST['AMDPOID']!=''){echo $ammndmnt_no;}else{echo $PO_Orderno;}?>" style="width:150px;" readonly="true"/>          </td>
</tr>
<tr class="row1">
	<td class="tabledata1"><strong>Delivery Date </strong></td>
    <td><input name="text2" type="text" value="<?php echo ConvertSQLDate($deliverydate);?>" style="width:150px;" readonly="true"/></td>
	 <td class="tabledata1"><strong>Initiated By </strong></td>
     <td><input name="text3" type="text" value="<?php echo $initiator;?>" style="width:150px;" readonly="true"/>          </td>
</tr>
<tr class="row1">
	<td class="tabledata1" nowrap="nowrap"><strong>Requisition Number </strong></td>
	<td><input name="text4" type="text" value="<?php echo $requisitionno;?>" style="width:150px;" readonly="true" /></td>
	    <td class="tabledata1"><strong>Requisition Date </strong></td>
	<?php $req_sql=DB_query("Select prdate from materialrequisitions where Reqno='".$requisitionno."'",$db);
		$req_row=DB_fetch_array($req_sql);?>
    <td><input name="text4" type="text" value="<?php echo ConvertSQLDate($req_row['prdate']);?>" style="width:150px;" readonly="true" /></td>
</tr>
<tr class="row1">
     <td class="tabledata1" nowrap="nowrap"><strong>Vendor Quotation Number </strong></td>
     <td><input name="text5" type="text" value="<?php echo  $vernder_quotation;?>" style="width:150px;" readonly="true"/>          </td>
	 <td class="tabledata1"><strong>Status</strong></td>
   <td><input type="text" name="Input28" value="<?php echo $myrow['status1']; ?>" style="width:150px;" id="Input28" readonly="true"></td>
</tr>
<?php 
$site_sql="Select * from locations where loccode='".$sitecode."'";
$site_res=DB_query($site_sql,$db);
$site_row=DB_fetch_array($site_res);
?>
<tr class="row1">
<td class="tabledata1"><strong>Site Code</strong></td>
	<td><input name="text6" type="text" value="<?php echo $sitecode;?>" style="width:150px;"  readonly="true"/></td>
	<td class="tabledata1" scope="row"><strong>Status Comments </strong></td>
	<td><input type="text" name="Input29" value="<?php echo $stat_comment1;?>" style="width:150px;" id="Input29" readonly="true"></td>
</tr>
<tr class="row1">
	<td class="tabledata1" rowspan="3"><strong>Address</strong></td>
	<td><input name="text8" type="text" value="<?php echo $site_row['deladd1'];?>" style="width:150px;" readonly="true"/></td>
	<td class="tabledata1"><strong>Site Name </strong></td>
	<td><input name="text7" type="text" value="<?php echo $site_row['locationname'];?>" style="width:150px;" readonly="true"/></td>
</tr>
<tr class="row1">
	<td><input name="text9" type="text" value="<?php echo $site_row['deladd2'];?>" style="width:150px;" readonly="true"/></td>
	<td class="tabledata1"><strong>Phone</strong></td>
    <td><input name="text11" type="text" value="<?php echo $site_row['phone1'];?>" style="width:150px;" readonly="true"/></td>
</tr>
<tr class="row1">
	<td><input name="text10" type="text" value="<?php echo $site_row['deladd3'];?>" style="width:150px;" readonly="true"/> </td>
	<td class="tabledata1"><strong>Mobile</strong></td>
	<td><input name="text12" type="text" value="<?php echo $site_row['mobile'];?>" style="width:150px;" readonly="true"/></td>
</tr>
<tr class="row1">
	<td class="tabledata1" nowrap="nowrap"><strong>Vendor Code </strong></td>
    <td><input name="vendor_code" type="text" value="<?php echo $vendor_code;?>" style="width:150px;" readonly="true"/></td>
	<td class="tabledata1" nowrap="nowrap"><strong>Vendor Name </strong></td>
	<td><input name="vendor_name" type="text" value="<?php echo $vendor_name;?>" style="width:150px;" readonly="true"/></td>
</tr>
<tr class="row1">
	<td class="tabledata1" rowspan="3"><strong>Adddress</strong></td>
	<td><input name="adrress1" type="text" value="<?php echo $adrress1;?>" style="width:150px;" readonly="true"/></td>
	 <td class="tabledata1"><strong>Delivery By </strong></td>
    <td><input name="deliveryby" type="text" value="<?php echo $deliveryby;?>" style="width:150px;" readonly="true"/></td>
</tr>
<tr class="row1">
	<td><input name="address3" type="text" value="<?php echo $address3;?>" style="width:150px;" readonly="true"/></td>
	<td class="tabledata1"><strong>Phone</strong></td>
	<td><input name="phone1" type="text" value="<?php echo $phone1;?>" style="width:150px;" readonly="true"/></td>
</tr>
<tr class="row1">
	<td><input name="adrress2" type="text" value="<?php echo $adrress2;?>" style="width:150px;" readonly="true"/></td>
	<td class="tabledata1"><strong>Mobile</strong></td>
   		 <td><input name="mobile" type="text" value="<?php echo $mobile;?>" style="width:150px;" readonly="true"/></td>
	
</tr>
<?php 
$pay_sql="Select terms from paymentterms where termsindicator='".$vendor_payment_terms."'";
$pay_res=DB_query($pay_sql,$db);
$pay_row=DB_fetch_array($pay_res);
?>
<tr class="row1">
        <td class="tabledata1" scope="row" nowrap="nowrap"><strong>Payment Terms </strong></td>
        <td><input name="text24" type="text" value="<?php echo $pay_row['terms'];?>" style="width:150px;" readonly="true"/></td>
		<td class="tabledata1" scope="row"><strong>Tin No. </strong></td>
    <td><input name="tin_no" type="text" value="<?php echo $tin_no;?>" style="width:150px;" readonly="true"/></td>
		 
</tr>
<tr class="row1">
	<td colspan="4">
	<h3><strong>Item Details</strong></h3>
	</td>
</tr>
<tr class="row1">
	<td colspan="4">
	<div style="overflow:auto; width:858px;"> 
<table width="100%" border="0" 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>
	<td class="tabledata"><strong>BASIC AMOUNT</strong></td>
	<td class="tabledata"><strong>Tax Type</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>
	<!--<th><strong>VAT/CST</strong></td>
	<th><strong>VAT/CST Amount</strong></td>-->
	<td class="tabledata"><strong>TOTAL AMOUNT</strong></td>
</tr>
	 
	 	<?php 
	if($_REQUEST['AMDPOID']!=''){$vend_sql="SELECT * FROM purchorders_ammd WHERE mst_comperitive='".$_REQUEST['CPID']."' ";}else{				
  $vend_sql="SELECT * FROM purchorders WHERE mst_comperitive='".$_REQUEST['CPID']."' ";}
$result_vend=DB_query($vend_sql,$db);
$myrowvender=DB_fetch_array($result_vend);
    
    $delivery_place1=$myrowvender['delivery_place1'];
	$delivery_place2=$myrowvender['delivery_place2'];
	$mode_of_transport=$myrowvender['mode_of_transport'];
	$freight_details=$myrowvender['freight_details'];
	$transit_insurance=$myrowvender['transit_insurance'];
	$delivery_date=$myrowvender['delivery_date'];
	$delivery_time=$myrowvender['delivery_time'];
	$contact_person=$myrowvender['contact_person'];
	$valid_till=$myrowvender['valid_till'];
	$totalamount=$myrowvender['basic_amt'];
	$sur_oct_amt=$myrowvender['sur_oct_amt'];
	$totalcharge=$myrowvender['fright'];
	$pkg_charges=$myrowvender['pkg_charges'];
	$add_charges=$myrowvender['additional_charges'];
	$grand_total=$myrowvender['grand_total'];
	$vat_cst_amount=$myrowvender['vat_cst_amount'];
	$vat_cst_per=$myrowvender['vat_cst_per'];
	$remarks=$myrowvender['remarks'];
 
if($_REQUEST['AMDPOID']!=''){$sql="SELECT * FROM purchorderdetails_ammd WHERE orderno='".$myrowvender['orderno']."' and mst_reqino='".$myrow['mst_reqino']."' and rate!='0.00'";}else{
$sql="SELECT * FROM purchorderdetails WHERE orderno='".$myrowvender['orderno']."' and mst_reqino='".$myrow['mst_reqino']."' and rate!='0.00'"; }
//echo $sql;
$result=DB_query($sql,$db);
$i=1;
while($myrow=DB_fetch_array($result))
{
//echo "<pre>";
//print_r($myrow);
if($i%2==0)
{$bg="#CCCCCC";}
else
$bg="#C8BECB";
?>
<tr class="row1">
	<td><?php echo $myrow['prod_id'];?> </td>
	<td><?php echo $myrow['prod_dec'];?> </td>
	<td><?php echo $myrow['item_no']; ?></td>
	<td><?php 
	$makename=$s->getField('product_manufacture','id',$myrow['Make'],'manufacturer');
	echo $makename;?>
	</td>
	<td><?php 
	$colorname=$s->getField('product_color','id',$myrow['Color'],'color');
	echo $colorname;?>
	</td>
	<td><?php 
	$gradename=$s->getField('product_grade','id',$myrow['Grade'],'grade');
	echo $gradename;?>
	</td>
	<td><?php
	$itemid=$s->getField('item_master','id',$myrow['mst_itemid'],'unit'); 
	$unitname=$s->getField('unitsofmeasure','unitid',$itemid,'unitname');
	echo $unitname;?>
	</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>
	<?php echo $myrow['quatity'];?></td>
	<td><?php echo $myrow['rate'];?>
	</td>
	<td><?php 
	if($myrow['discount']=='0')
	echo "N/A";
	else
	echo $myrow['discount_type'];?>
	</td>
	<td><?php 	   
	if($myrow['discount_type']=="PercentAmt")
	{?>
	<?php echo $myrow['discount'];?>%
	<?php 	 }
	else 
	{?>
	<?php echo $myrow['discount'];?>
	<?php } ?></td>
	<td><?php echo $myrow['discount_amount'];?></td>
	<td><?php echo $myrow['Sub_total'];?></td> 
	<td><?php echo $myrow['specialdiscount_amount']; ?></td>
	<td><?php echo $myrow['basic_amt']; ?></td>
	<td><?php echo $myrow['tax_type']; ?></td>
	<td><?php echo $myrow['Excise_Duty_value']; ?></td>
	<td><?php echo $myrow['Edu_Cess']; ?></td>
	<td><?php echo $myrow['SHE_Cess']; ?></td>
	<td><?php echo $myrow['taxabel_amt']; ?></td>
	<!-- <td><?php echo $s->getField('service_tax_master','id',$myrow['taxname'],'tax_code'); ?></td>
	<td><?php echo $myrow['taxvalue']; ?></td>-->
	
	
	<td><?php echo $myrow['totalamount']; ?></td>
	</tr>
	<?php 
	
	$TotBasic[]=$myrow['sub_total']; 
	$i++;
	}?>
	<input type="hidden" name="PO_count" value="<?php echo $i;?>" />

  </table>
</div>
	</td>
</tr>
<tr class="row1">
	<td colspan="4">
		<table width="100%" cellpadding="3" cellspacing="0">
			<tr class="row1">
				<td width="50%">
				<table width="100%" border="0" style="border:solid 1px #CCC; background:#FFFFFF" align="left">
					<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">
					<td class="tabledata1" 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="50%">
				<table width="100%" border="0" cellspacing="0" cellpadding="3">
                <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:150px;" onfocus="cal_totalamount()" 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:150px;" 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:150px;"/>
		<input type="hidden" name="vat_cst_per" value="<?php echo $vat_cst_per; ?>"/>
			
		</td>
		</tr>
		<tr class="row1">
					<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:150px;"> </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:150px;" 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:150px;" 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:150px;" 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:150px;" readonly="readonly" /></td>
                </tr>
              </table>
				</td>
			</tr>
			<tr class="row1">
<td class="tabledata1"><strong>Remarks</strong> </td>
<td ><textarea  name="remarks" id="remarks" style="width:150px;" ><?php echo $remarks; ?></textarea></td>
</tr>
		</table>
	</td>
</tr>

</table>

 </div>
 <br />
<?php 
if($_REQUEST['CPID']!='')
{?>
  <p align="center" style="color:#FF0000;">Purchase Order Already Generated</p>
<?php }?>
