<?php
include_once('../../hdr_general.php');

function right($str, $length) {
     return substr($str, -$length);
}

//convert date
$varTarikhMula = $_REQUEST['varTarikhMula'];
$varTarikhAkhir = $_REQUEST['varTarikAkhir'];

$unixTarikhMula=converttounix($varTarikhMula);
$unixTarikhAkhir=converttounix($varTarikhAkhir);	
//end convert date	

$varSupplierName = $_REQUEST[varSupplierName];

//get project primary key
		$selProKey = mysql_query("select * from project_details where projectname = '$pubprojectname'");		
		while($row = mysql_fetch_array($selProKey))
		{			
			$varProKey = $row['projectpkey'];				
		}
?>

<style type="text/css" media="print,screen" >
	th {
	    font-family:Arial;
	    color:black;
	    background-color:lightgrey;
	}
	thead {
	    display:table-header-group;
	}
	tbody {
	    display:table-row-group;
	}
</style>



<style type="text/css">
<!--
.style1 {
	color: #0066CC;
	font-weight: bold;
}
.style2 {font-size: 24px}
.style5 {
	color: #333333;
	font-size: 14px;
	font-weight: bold;
}
.style6 {color: #FF0000; font-size: 14px; font-weight: bold; }
-->
</style>


<table width="859" border="0">
  <tr>
    <td height="23">&nbsp;</td>
    <td>&nbsp;</td>
    <td colspan="3"><div align="center"><img src="../../gfx/zikayheader.png" width="225" height="82" /></div></td>
  </tr>
  <tr>
    <td height="23">&nbsp;</td>
    <td>&nbsp;</td>
    <td colspan="3"><div align="center" class="style1 style2" style="border-bottom:#000000 medium">SUPPLIER PERFORMANCE  REPORT</div></td>
  </tr>
  <tr>
    <td height="23" class="style5">&nbsp;</td>
    <td>&nbsp;</td>
    <td colspan="3">&nbsp;</td>
  </tr>
  <tr>
    <td height="23">PROJECT TITLE</td>
    <td>:</td>
    <td colspan="3"><?php echo  $pubprojectname; ?></td>
  </tr>
  <tr>
    <td height="23">SUPPLIER</td>
    <td>:</td>
    <td colspan="3"><?php echo $varSupplierName; ?></td>
  </tr>
  <tr>
    <td width="145" height="23">DATE</td>
    <td width="12">:</td>
    <td width="83"><?php echo  $varTarikhMula;  ?></td>
    <td width="45">To</td>
    <td width="552"><?php echo  $varTarikhAkhir; ?></td>
  </tr>
  <tr>
    <td height="23">&nbsp;</td>
    <td>&nbsp;</td>
    <td colspan="3">&nbsp;</td>
  </tr>
</table>



<table width="1107" border cellspacing="0.5">
<thead>
	<tr>
		<th width="34" bgcolor="#0000FF"><span class="style16">No</span></th>
		<th width="299" bgcolor="#0000FF"><span class="style16">SUPPLIER</span></th>
		<th width="77" bgcolor="#0000FF"><span class="style16">PO NO</span></th>
		<th width="96" bgcolor="#0000FF"><span class="style16">PO DATE</span></th>
		<th width="165" bgcolor="#0000FF"><span class="style16">Do NO</span></th>
		<th width="115" bgcolor="#0000FF"><span class="style16">DATE OF DELIVERY</span></th>
		<th width="154" bgcolor="#0000FF"><span class="style16">EXPECTED DELIVERY</span></th>
		<th width="133" bgcolor="#0000FF"><span class="style16">DELIVERY PERIOD</span></th>
	</tr>
  </thead>
 <tbody>  
 
 <?php

$varSupKey = $_REQUEST[varSupKey];
//echo $varSupKey;
$i = 0;

//select po no
if ($varTarikhMula != '' and $varTarikhAkhir != '')
	{$sqlSelPO = "select *  from po_details where po_projectpkey = '$varProKey' and po_supplierpkey = '$varSupKey' and po_date BETWEEN $unixTarikhMula and $unixTarikhAkhir  and po_cancel <> 1 order by po_date";}
else
	{$sqlSelPO = "select *  from po_details where po_projectpkey = '$varProKey' and po_supplierpkey = '$varSupKey'  and po_cancel <> 1 order by po_date";}

$selPO = mysql_query($sqlSelPO);	
	
while($row = mysql_fetch_array($selPO))
{			
	$i = $i + 1;
	$varPKey = $row['po_pkey'];	
	$varPONO = $row['po_no'];
	$varPODate = unconverttounixslash($row['po_date']);		
	$varMROKey = $row['po_mropkey'];
	$varPOStatus = 	$row['po_status'];
	
	//===== check PO len ======
			if (strlen($varPONO) ==1 )
			{
				$varPONO = 'PO000'.$varPONO;
			}
			else if (strlen($varPONO) ==2 )
			{
				$varPONO = 'PO00'.$varPONO;
			}
			else if (strlen($varPONO) ==3 )
			{
				$varPONO = 'PO0'.$varPONO;
			}
			else if (strlen($varPONO) ==4 )
			{
				$varPONO = 'PO'.$varPONO;
			}			
	//======end check PO len ===
	
	if ($varPOStatus == '1')//po outstanding
	{
		echo "<tr>";
	echo "<td><div align='left' class='style6'>$i</td>";
	echo "<td><div align='left' class='style6'>$varSupplierName</td>";
	echo "<td><div align='left' class='style6'>$varPONO</td>";
	echo "<td><div align='left' class='style6'>$varPODate</td>";	
	echo "<td><div align='left' class='style6'>&nbsp;</td>";
	echo "<td><div align='left' class='style6'>&nbsp;</td>";
	echo "<td><div align='left' class='style6'>&nbsp;</td>";
	echo "<td><div align='left' class='style6'>&nbsp;</td>";
	echo "</tr>";
	}
	else //po delived
	{
		echo "<tr>";
		echo "<td><div align='left' class='style5'>$i</td>";
		echo "<td><div align='left' class='style5'>$varSupplierName</td>";
		echo "<td><div align='left' class='style5'>$varPONO</td>";
		echo "<td><div align='left' class='style5'>$varPODate</td>";	
		echo "<td><div align='left' class='style5'>&nbsp;</td>";
		echo "<td><div align='left' class='style5'>&nbsp;</td>";
		echo "<td><div align='left' class='style5'>&nbsp;</td>";
		echo "<td><div align='left' class='style5'>&nbsp;</td>";
		echo "</tr>";
	}
	//select Expected Delivery
	$sqlExDe = "select *  from mro_details where mro_pkey = '$varMROKey'";
	$selExDe = mysql_query($sqlExDe);
	while($row = mysql_fetch_array($selExDe))
	{
		$varExDeOri = $row['mro_deliverydate'];
		$varExDe = unconverttounixslash($row['mro_deliverydate']);		
		//echo "edit   :" .$varExDe;
	}
		
	//select DO details
	$selDO = mysql_query("select *  from do_items where item_popkey = '$varPKey' order by item_dodate");		
	while($row = mysql_fetch_array($selDO))
	{		
	$varDONo = $row['item_dono'];
	$varDODateOri = $row['item_dodate'];					
	$varDODate = unconverttounixslash($row['item_dodate']);				
	
	$offset = $varExDeOri - $varDODateOri;
	$varDePe = floor($offset/60/60/24); 
		
	echo "<tr>";
	echo "<td><div align='right' class='style5'>&nbsp;</td>";	
	echo "<td><div align='left' class='style5'>&nbsp;</td>";
	echo "<td><div align='left' class='style5'>&nbsp;</td>";
	echo "<td><div align='right' class='style5'>&nbsp;</td>";			
	echo "<td><div align='left' class='style5'>$varDONo</td>";
	echo "<td><div align='right' class='style5'>$varDODate</td>";
	echo "<td><div align='right' class='style5'>$varExDe</td>";
	
	$varCheckNeg = substr($varDePe, 0, 1);
	if ($varCheckNeg  == "-")
		{echo "<td><div align='right' class='style6'>$varDePe</td>";}
	else
		{echo "<td><div align='right' class='style5'>$varDePe</td>";}
	echo "</tr>";
	}
}
?>
 
 
 
 </tbody> 
</table>
		
<!--</form>-->
