<?php session_name('CAKEPHP'); session_start();
$PageSecurity = 2;
include('includes/SQL_CommonFunctions.inc');
include('includes/DefinePOClass.php');
$title = _('Import Purchase Order List');
$PageName ='Import Purchase Order List';
if($_REQUEST['id']!='' && $_REQUEST['act']=='delete')
{
	$delete1=DB_query("Delete from import_purchaseorder where id='".$_REQUEST['id']."'",$db);
	$delete2=DB_query("Delete from import_purchaseorder_details where masterId='".$_REQUEST['id']."'",$db);
	prnMsg( _('Record Deleted Successfully'),'success');
echo "<script>location.href='index.php?route=ImportPOList&modid=".$_REQUEST['modid']."&frmid=".$_REQUEST['frmid']."'</script>";
}
?>
<?php 
if($_REQUEST['id']==''){
?>
<h2 align="center"><strong>Import Purchase Order List</strong></h2>
<a href="index.php?route=ImportPO&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>">ADD NEW PO</a>
<br />
<br />
<table width="100%" border="0" cellspacing="2" cellpadding="2">
  <tr>
    <th>Order No </th>
    <th>Order Date </th>
    <th>Branch</th>
    <th>Vendor</th>
    <th>View</th>
    <th>Edit</th>
    <th>Delete</th>
  </tr>
 <?php 
 $sql=DB_query("select * from import_purchaseorder",$db);
 $i=0;
 while($myrow=DB_fetch_array($sql)){
 ?>
  <tr bgcolor="#FFFFFF">
    <td><?php echo $myrow['orderNo'];?></td>
    <td><?php echo ConvertSQLDate($myrow['orderDate']);?></td>
    <td><?php 
	$sitename=$s->getField('locations','loccode',$myrow['site'],'locationname');
	echo $sitename;?></td>
    <td><?php 
	$vendorname=$s->getField('suppliers','vendor_code',$myrow['vendor'],'vendor_name');
	echo $vendorname;?></td>
    <td><a href="index.php?route=ImportPOList&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>&id=<?php echo $myrow['id'];?>&act=view">View</a></td>
    <td><a href="">Edit</a></td>
    <td><a href="index.php?route=ImportPOList&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>&id=<?php echo $myrow['id'];?>&act=delete" onclick="return confirm('This record will be deleted. Are you sure?')">Delete</a></td>
  </tr>
  <?php } ?>
</table>
<?php } 
if($_REQUEST['id']!='' && $_REQUEST['act']=='view')
{
$sql=DB_query("select * from import_purchaseorder where id='".$_REQUEST['id']."'",$db);
$myrow=DB_fetch_array($sql);
?>
<h2 align="center"><strong>View Import Purchase Order</strong></h2>
<table width="50%" border="0" cellspacing="1" cellpadding="2">
	  <tr>
        <th><strong>BRANCH</strong></th>
		<td><input type="text" value="<?php echo $myrow['site'];?>" class="datepicker" /></td>
        <th>PO NO. </th>
		<td id="POID"><input type="text" value="<?php echo $myrow['orderPrefix'];?>" size="10" />
-		  <input  type="text" value="<?php echo $myrow['orderDigit'];?>" size="5" /></td>
      </tr>
      <tr>        
        <th><strong>VENDOR</strong></th>
		<td><input type="text" value="<?php echo $myrow['vendor'];?>" class="datepicker" /></td>
		<th>PO DATE </th>
		<td><input type="text" value="<?php echo $myrow['orderDate'];?>" class="datepicker" /></td>
      </tr>
      <tr></tr>
  </table>
 <br /><br /> 
  <div style="overflow:auto; width:800px ; height:<?php echo $height;?>"  >
  <table width="99%" border="0" cellspacing="1" cellpadding="5">
    <tr>
      <th scope="col"><strong>Item Code </strong></th>
      <th scope="col"><strong>Item Name </strong></th>
      <th scope="col"><strong>Description</strong></th>
      <th scope="col"><strong>Item No. </strong></th>
      <th scope="col"><strong>Make</strong></th>
      <th scope="col"><strong>Color</strong></th>
      <th scope="col"><strong>Grade</strong></th>
	  <th scope="col"><strong>Size</strong></th>
	  <th scope="col"><strong>GSM</strong></th>
	   <th scope="col"><strong>Quantity</strong></th>
      <th scope="col"><strong>Rate</strong></th>
	   <th scope="col"><strong>Currency</strong></th>
      <th scope="col"><strong>Discount Type</strong></th>
      <th scope="col"><strong>Discount</strong></th>
      <th><strong>Discount Amount</strong></th>
      <th scope="col"><strong>Sub Total </strong></th>
      <th scope="col"><strong>Flexo Offset</strong></th>
      <th scope="col"><strong>Od</strong></th>
      <th scope="col"><strong>Length</strong></th>
      <th scope="col"><strong>Width</strong></th>
      <th scope="col"><strong>Unit</strong></th>
      <th scope="col"><strong>Serial No.</strong></th>
      <th scope="col"><strong>Orignal/Local</strong></th>
      <th scope="col"><strong>Type</strong></th>
      <th scope="col"><strong>Shade</strong></th>
      <th scope="col"><strong>Running Meter/Roll</strong></th>
      <th scope="col"><strong>Volume</strong></th>
      <th scope="col"><strong>Teeth</strong></th>
      <th scope="col"><strong>Bcm</strong></th>
      <th scope="col"><strong>Ups</strong></th>
      <th scope="col"><strong>Quality</strong></th>
      </tr>
    <?php 
	$detailsSql=DB_query("Select * from import_purchaseorder_details where masterId='".$_REQUEST['id']."'",$db);
  $i=0;
  while($detailsRow=DB_fetch_array($detailsSql))
  {
  	//echo "select * from item_master where StockID='".$pp[$i]."'";
	$Query=DB_query("select * from item_master where StockID='".$detailsRow['itemCode']."'",$db);
  	$Query_row=DB_fetch_array($Query);
	
	$_REQUEST['quantity'][$i]=$detailsRow['quantity'];
	$_REQUEST['rate'][$i]=$detailsRow['rate'];
	$_REQUEST['currency'][$i]=$detailsRow['currency'];
	$_REQUEST['discountType'][$i]=$detailsRow['discountType'];
	$_REQUEST['discount'][$i]=$detailsRow['discount'];
	$_REQUEST['discountAmt'][$i]=$detailsRow['discountAmt'];  
	$_REQUEST['subTotal'][$i]=$detailsRow['subTotal'];
  ?>
    <tr bgcolor="#FFFFFF">
      <td><?php echo $detailsRow['itemCode'];?><input type="hidden" name="itemCode[<?php echo $i;?>]" id="itemCode_<?php echo $i;?>" value="<?php echo $detailsRow['itemCode'];?>" /></td>
      <td><?php echo $Query_row['item_name'];?></td>
      <td><?php echo $Query_row['item_desc'];?></td>
      <td><?php echo $Query_row['item_no'];?></td>
     <td>
	 <?php 
	echo $makename=$s->getField('product_manufacture','id',$detailsRow['make'],'manufacturer');
?>
</td>
      <td>
	 <?php 
	echo $colorname=$s->getField('product_color','id',$detailsRow['color'],'color');
?></td>
      <td><?php
	echo $gradername=$s->getField('product_grade','id',$detailsRow['grade'],'grade');
?>
</td>
<td><?php 
	echo $sizename=$s->getField('size_master','id',$detailsRow['size'],'name');
?>
</td>
<td><?php
	echo $gsmname=$s->getField('gsm','id',$detailsRow['gsm'],'gsm');
?>
</td>
	 <td><input type="text" name="quantity[<?php echo $i;?>]" id="quantity_<?php echo $i;?>" value="<?php echo $_REQUEST['quantity'][$i];?>" /></td>
      <td><input type="text" name="rate[<?php echo $i;?>]" id="rate_<?php echo $i;?>" value="<?php echo $_REQUEST['rate'][$i];?>" /></td>
	   <td>
	   <select name="currency[<?php echo $i;?>]" style="width:110px;">
	   <?php 
	   $currSql=DB_query("Select * from currency_master where id='".$_REQUEST['currency'][$i]."'",$db);
	   while($currRow=DB_fetch_array($currSql)){
	   ?>            
	   <option value="<?php echo $currRow['id'];?>"<?php echo ($_REQUEST['currency'][$i]==$currRow['id']?'selected':'')?>><?php echo $currRow['currency']." - ".$currRow['abbreviation'];?></option>
	   <?php } ?>
	   </select>
	   </td>
      <td>
	  <?php echo $_REQUEST['discountType'][$i];?>
	  </td>
      <td><input type="text" name="discount[<?php echo $i;?>]" id="discount_<?php echo $i;?>" value="<?php echo $_REQUEST['discount'][$i];?>" onblur="DiscountAmount(this.value,<?php echo $i;?>)"/></td>
      <td><input type="text" name="discountAmt[<?php echo $i;?>]" id="discountAmt_<?php echo $i;?>" value="<?php echo $_REQUEST['discountAmt'][$i];?>" /></td>
      <td><input type="text" name="subTotal[<?php echo $i;?>]" id="subTotal_<?php echo $i;?>" value="<?php echo $_REQUEST['subTotal'][$i];?>" /></td>
	  <td><?php echo $Query_row['flexo_offset'];?></td>
      <td><?php echo $Query_row['od'];?></td>
      <td><?php echo $Query_row['length'];?></td>
      <td><?php echo $Query_row['width'];?></td>
      <td><?php $unit=$s->getField('unitsofmeasure','unitid',$Query_row['unit'],'unitname'); echo $unit;?></td>
      <td><?php echo $Query_row['serial_no'];?></td>
      <td><?php echo $Query_row['orig_local'];?></td>
      <td><?php echo $Query_row['type_name'];?></td>
      <td><?php echo $Query_row['shade'];?></td>
      <td><?php echo $Query_row['running_roll'];?></td>
      <td><?php echo $Query_row['volume'];?></td>
      <td><?php echo $Query_row['teeth'];?></td>
      <td><?php echo $Query_row['bcm'];?></td>
      <td><?php echo $Query_row['ups'];?></td>
       <td><?php echo $Query_row['quality'];?></td>
    </tr>
    <?php } ?>
	<input type="hidden" name="count" id="count" value="<?php echo $i;?>" />
  </table>
</div>
<br />
<table width="100%">
<tr><td>
<table width="30%" cellpadding="2" cellspacing="2" align="center">
			<tr>
			<th><strong>Basic Amount</strong></th>
			<td><input name="basicAmount" id="basicAmount" type="text" size="15" value="<?php echo $myrow['basicAmount'];?>" readonly ></td>
			</tr>
		<tr><th><strong>Grand Total</strong></th>
		<td><input name="grandTotal" id="grandTotal" type="text" size="15" value="<?php echo $myrow['grandTotal'];?>" readonly></td>
		</tr>
	  </table>
</td></tr>
<tr>
<td>
<table width="90%" align="center">
<tr>
<th>Remarks</th>
<td>
<textarea name="remarks" cols="80" rows="5"><?php echo $myrow['remarks'];?></textarea>
</td>	
</tr>
</table>	
</td>		
</tr>
</table>
<?php 	
}
?>