<?php
include_once('../../hdr_general.php');
include_once('../../lib/lib_general.php');
include_once('../../dbincludes.php');
include_once('../../libincludes.php');
include_once('../../classincludes.php');
// start include db
include_once("../../db/db_config.php");

$con = mysql_connect($db_config_pms['server'],$db_config_pms['username'],$db_config_pms['password']);

if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db($db_config_pms['db'], $con);
// end include db
?>

<style type="text/css">
<!--
.style1 {
	color: #0066CC;
	font-weight: bold;
}
.style2 {font-size: 24px}
.style10 {font-size: 14px; color: #FFFFFF; font-weight: bold; }
.style15 {
	color: #333333;
	font-size: 14px;
}
.style15 {
	font-size: 12px;
	color: #666666;
}
-->
</style>

<!--<form method="post" name="frmMain">-->
<?php
		
		$varSupplier = $_REQUEST[varsupplier];
		$varSubCon = $_REQUEST[varsubconkey];		
		
		//convert date
		$varTarikhMula = $_REQUEST['tarikhMula'];
		$varTarikhAkhir = $_REQUEST['tarikhAkhir'];
		
		$unixTarikhMula=converttounix($varTarikhMula);
		$unixTarikhAkhir=converttounix($varTarikhAkhir);	
		//end convert date		
		
		//get project primary key
		$selProKey = mysql_query("select * from project_details where projectname = '$pubprojectname'");		
		while($row = mysql_fetch_array($selProKey))
		{			
			$varProKey = $row['projectpkey'];				
		}
				
			// start include cms db			
			$con2 = mysql_connect($db_config_cms['server'],$db_config_cms['username'],$db_config_cms['password']);			
			if (!$con2)
			  {die('Could not connect: ' . mysql_error());}			
			mysql_select_db($db_config_cms['db'], $con);
			// end include cms  db
			
			 $selSubCon = mysql_query("select * from settings_subcontractors where subconmasterpkey ='$varSubCon'");		
			while($row = mysql_fetch_array($selSubCon))
			{	
				$varSubConName =  $row['subconname'];				
			}
		
		
?>
<table width="870" border="0">
  <tr>
    <td width="179" height="23">&nbsp;</td>
    <td width="10">&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="left" class="style1 style2" style="border-bottom:#000000 medium">
      <div align="center">SUB-CON MATERIAL REPORT</div>
    </div></td>
  </tr>
  
  <tr>
    <td height="23">&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">SUB-CONTRACTOR</td>
    <td>:</td>
    <td colspan="3"><?php echo $varSubConName;?></td>
  </tr>
  
  <tr>
    <td height="23">DATE</td>
    <td>:</td>
    <td width="49"><?php echo $_REQUEST[tarikhMula]?></td>
    <td width="41">To</td>
    <td width="569"><?php echo $_REQUEST[tarikhAkhir]?></td>
  </tr>
</table>

<br>
<table width="1008" border cellspacing="0.5">
  <tr>
    <td width="35" bgcolor="#0066FF"><div align="center" class="style10">No</div></td>
    <td width="326" bgcolor="#0066FF"><div align="center" class="style10">SUPPLIER</div></td>
    <td width="80" bgcolor="#0066FF"><div align="center" class="style10">PO NO</div></td>
    <td width="78" bgcolor="#0066FF"><div align="center" class="style10">PO DATE</div></td>
    <td width="128" bgcolor="#0066FF"><div align="center" class="style10">PO AMOUNT(RM)</div></td>
    <td width="101" bgcolor="#0066FF"><div align="center" class="style10">INVOICE NO </div></td>
    <td width="118" bgcolor="#0066FF"><div align="center" class="style10">INVOICE DATE </div></td>
    <td width="108" bgcolor="#0066FF"><div align="center" class="style10">AMOUNT(RM)</div></td>
  </tr>
 
 <?php 
 			// start include pms db			
			$con2 = mysql_connect($db_config_pms['server'],$db_config_pms['username'],$db_config_pms['password']);			
			if (!$con2)
			  {die('Could not connect: ' . mysql_error());}			
			mysql_select_db($db_config_pms['db'], $con);
			// end include pms  db
						
			
			$selCountPO = "select * from rpt_scm_details order by data_suppliername";				
			$selTotalPO = mysql_query($selCountPO);
			 
			 $i=0;	
		while($row = mysql_fetch_array($selTotalPO))
		{			
			$i = $i +1;
			
			$varSupplierName =  $row['data_suppliername'];
			
			//check supplier still sama tak
			if ($varSupplierName != $varCurrSupplierName)
			{								
				//display sub amount
				//$varTotalPO = $varTotalPO + $varSubTotalPO;
				$varSubTotalInvoice =  number_format($varSubTotalInvoice,2);
				$varSubTotalPO =  number_format($varSubTotalPO,2);								
				
				//disable first row
				if ($varCurrSupplierName !='')
				{
				echo "<tr>";
					echo "<td><div align='left' style='font-size:14px' style='color:#666666'>&nbsp;</td>";
					echo "<td><div align='left' style='font-size:14px' style='color:#666666'>&nbsp;</td>";
					echo "<td><div align='left' style='font-size:14px' style='color:#666666'>&nbsp;</td>";
					echo "<td><div align='left' style='font-size:14px' style='color:#666666'>&nbsp;</td>";
					echo "<td><div align='right' style='font-size:14px' style='color:#666666'><strong>$varSubTotalPO</strong> </td>";		
					echo "<td><div align='left' style='font-size:14px' style='color:#666666'>&nbsp;</td>";
					echo "<td><div align='left' style='font-size:14px' style='color:#666666'>&nbsp;</td>";
					echo "<td><div align='right' style='font-size:14px' style='color:#666666'><strong>$varSubTotalInvoice</strong> </td>";		
				echo "</tr>";
				}
				//kosong kan sub total invoice
				$varSubTotalInvoice = 0;
				$varSubTotalPO = 0;
				$varCurrSupplierName =  $row['data_suppliername'];
			}
			
			$varPONO =  $row['data_pono'];
			$varPODate =  $row['data_podate'];
			$varPOAmt =  $row['data_poamount'];
			$varSubTotalPO =  $varSubTotalPO + $varPOAmt;
			$varInvoiceNo =  $row['data_invoiceno'];
			$varInvoiceDate =  $row['data_invoicedate'];
			$varInvoiceAmt =  $row['data_amount'];
			$varSubTotalInvoice =$varSubTotalInvoice  + $varInvoiceAmt;
			$varTotalInvoice =  $varTotalInvoice + $varInvoiceAmt;
			$varTotalPO = $varTotalPO + $varPOAmt;
			
			//change format
			$varPOAmt = number_format($varPOAmt,2);
			$varInvoiceAmt = number_format($varInvoiceAmt,2);			
			
			
			echo "<tr>";
					echo "<td><div align='left' style='font-size:14px' style='color:#666666'>$i</td>";
					echo "<td><div align='left' style='font-size:14px' style='color:#666666'>$varSupplierName</td>";
					echo "<td><div align='right' style='font-size:14px' style='color:#666666'>$varPONO</td>";
					echo "<td><div align='right' style='font-size:14px' style='color:#666666'>$varPODate</td>";
					echo "<td><div align='right' style='font-size:14px' style='color:#666666'>$varPOAmt </td>";
					echo "<td><div align='right' style='font-size:14px' style='color:#666666'>$varInvoiceNo</td>";
					echo "<td><div align='right' style='font-size:14px' style='color:#666666'>$varInvoiceDate</td>";
					echo "<td><div align='right' style='font-size:14px' style='color:#666666'>$varInvoiceAmt</td>";
				echo "</tr>";
		}	
			
	
  
 //Total
$varTotalPO = number_format($varTotalPO,2);
$varTotalInvoice = number_format($varTotalInvoice,2);
	echo "<tr>";		
		echo "<td><div align='left' class='style7'>&nbsp;</td>";
		echo "<td><div align='left' class='style7'>&nbsp;</td>";
		echo "<td><div align='left' class='style7'>&nbsp;</td>";
		echo "<td><div align='right' class='style7'><strong>Total PO</strong></td>";
		echo "<td><div align='right' class='style7'><strong>$varTotalPO</strong> </td>";						
		echo "<td><div align='left' class='style7'>&nbsp;</td>";
		echo "<td><div align='right' class='style7'><strong>Total Invoice</strong></td>";
		echo "<td><div align='right' class='style7'><strong>$varTotalInvoice</strong></td>";		
	echo "</tr>";  
  ?>
</table>
		

<!--</form>-->