  <?
  // Tab -----------------------------------------
  $tab_quantity=2;
  $tab_style=1;	// (single-row)
  $tab_name=array("&nbsp;<b>Invoice List</b>&nbsp;","&nbsp;<b>Invoice New (Beta Testing)</b>&nbsp;");
  include_once('tab.php');
  //----------------------------------------------
  ?>
  <table width="99%" border="0" cellspacing="0" cellpadding="0">
  <tr valign=top>
  <td valign=top>

  <div id='tab-body:0' class='tab-body' <? if ($_SESSION['Xactivetab']=="0") { echo "style='border: none; display: block;'"; } else { echo "style='border: none; display: none;'"; } ?>>

  <!--
  Boleh search by MRO no, date request (OR)			
  boleh search by rfq no, mro no, vendor name (OR)			
  boleh search by po no, po date, vendor name (OR)			
  -->

  <table border=1 cellspacing=1 cellpadding=2 width=928 style="border: 1px inset;">
  <form action="index.php?module=invoice&task=main" method="post" name="filterform" id="filterform">
  <tr valign=top>
  <td valign=top width=928 colspan=9 class=listfilterheader>Filters</td>
  </tr>
  <tr valign=top>
  <td valign=top width=50 class=listcontent>PO No :</td>
  <td valign=top width=120 class=listcontent><input name="pono" id="pono" value="<?=$filterpono;?>" style="width: 115px;" onKeypress="integerOnly();"></td>
  <td valign=top width=70 class=listcontent>PO Date:</td>
  <td valign=top width=120 class=listcontent><input name="podate" id="podate" value="<?=$filterpodate;?>" maxlength=10 style="width: 115px;" onKeypress="dateOnly();"></td>
  <td valign=top width=120 class=listcontent>Vendor Name :</td>
  <td valign=top width=240 class=listcontent>
  <select name="vendorname" id="vendorname" style="width: 235px;">
  <? $objsupplierpkey = $filtervendorname; ?>
  <? include('object-selectsupplier.tpl'); ?>
  </select>
  </td>
  <td valign=top width=208 class=listcontent>
  <input name="pageno1" id="pageno1" type="hidden" value="1">
  <button name="filter" id="filter" type="submit" style="width: 80px;">&nbsp;<img src='gfx/options/b_find.png' class='actionbutton'>&nbsp;Search&nbsp;</button>&nbsp;
  <button name="showall" id="showall" style="width: 90px;" onClick="unFilter();">&nbsp;<img src='gfx/options/b_clear.png' class='actionbutton'>&nbsp;Show All&nbsp;</button>&nbsp;
  </td>
  </tr>
  </form>
  </table>
  <br>

  <table border=1 cellspacing=1 cellpadding=2 width=928 style="border: 1px inset;">

  <tr valign=top>
  <td valign=top width=48 class=listheader>No.</td>
  <td valign=top width=110 class=listheader>PO No</td>
  <td valign=top width=120 class=listheader>PO Date</td>
  <td valign=top width=100 class=listheader>MRO No</td>
  <td valign=top width=100 class=listheader>RFQ No</td>
  <td valign=top width=250 class=listheader>Vendor Name</td>
  <td valign=top width=120 class=listheader>Invoice No</td>
  <td valign=top width=80 class=listheader>Options</td>
  </tr>

  <?
  $firstrec1 = (($pubpageno1-1)*20)+1;
  $lastrec1 = $firstrec1 + 19;
  $pagecount1 = 1;
  ?>

  <? foreach ($po_list as $mypo) { ?>

    <? if (($mypo['recordno']>=$firstrec1)&&($mypo['recordno']<=$lastrec1)) { ?>

      <?
      // get po total and do totals

      include_once('models/supplierModel.php');
      include_once('models/mroModel.php');
      include_once('models/itqModel.php');
      $mysupplierModel=new supplierModel;
      $mymroModel=new mroModel;
      $myitqModel=new itqModel;

      $supplier_data = $mysupplierModel->getdata_supplier($mypo['po_supplierpkey']);
      $mro_data = $mymroModel->getdata_mro($mypo['po_mropkey']);
      $itq_data = $myitqModel->getdata_itq($mypo['po_itqpkey']);
      ?>

      <tr valign=top>
      <td valign=top width=48 class=listnumber><?=$mypo['recordno'];?></td>
      <td valign=top width=110 class=listcontent><?=poidstr($mypo['po_no'],$mypo['po_revno']);?>&nbsp;</td>
      <td valign=top width=120 class=listcontent><?=unconverttounixslash($mypo['po_date']);?>&nbsp;</td>
      <td valign=top width=100 class=listcontent><?=mroidstr($mro_data['mro_id']);?>&nbsp;</td>
      <td valign=top width=100 class=listcontent><?=itqidstr($itq_data['itq_rfqno']);?>&nbsp;</td>
      <td valign=top width=250 class=listcontent><?=$supplier_data['supplier_name'];?>&nbsp;</td>
      <td valign=top width=120 class=listcontent>
		<?php
		$sql1 = "SELECT * from zikay_pmsv5.invoice_items WHERE item_popkey = '" .$mypo['po_pkey']. "'";
		$sql2 = mysql_query($sql1);
		$data = mysql_fetch_array($sql2);
	
			echo $data['item_invoiceno'];
			
		?>
	  </td>
      <td valign=top width=80 class=listcontent>
      <? if (($pubuseraccess['access_invoice_edit']==1)||($pubuserrole>=2)) { ?>
        <button name="addinvoice" id="addinvoice" type="button" style="width: 76px;" onClick="addInvoice('<?=$mypo['po_pkey'];?>');">&nbsp;<img src='gfx/options/b_edit.png' class='actionbutton'>&nbsp;Edit&nbsp;</button>
      <? } ?>&nbsp;
      </td>
      </tr>

    <? } ?>

  <? } ?>

  <?
  $pagecount1 = intval($mypo['recordno']/20) + 1;
  ?>

  </table>

  <br>
  <?
  echo "<b>Page : </b>";
  for ($i=1;$i<=$pagecount1;$i++) {
    if ($i==$pubpageno1) {
      echo "[<u>".$i."</u>]&nbsp;";	//-&nbsp;";
    } else {
      echo "<span style='cursor: hand;' onClick='switchPage1(".$i.");'><b>".$i."</b></span>&nbsp;";	//-&nbsp;";
    }
    if (($i % 25)==0) echo "<br>";
  }
  ?>

  </div>
  
   <div id='tab-body:1' class='tab-body' <? if ($_SESSION['Xactivetab']=="1") { echo "style='border: none; display: block;'"; } else { echo "style='border: none; display: none;'"; } ?>>
	Testing
	<table border=1 cellspacing=1 cellpadding=2 width=928 style="border: 1px inset;">
	<tr>
		<td class=listheader>Invoice No</td><td><input type="text"></td><td width="20"></td>
		<td class=listheader>Vendor</td>
			<td><select name=vendorx>
					<option value="">--SELECT VENDOR--</option>
					<!--vendor start-->
					<?php
					$self = $_SERVER['PHP_SELF'];
					$sup1 = "SELECT * FROM po_details WHERE po_projectpkey ='".$_SESSION[Xprojectpkey]."' ORDER by po_no ASC";
					$sup2 = mysql_query($sup1);
					$supx_count = mysql_num_rows($sup2);
					while($sup = mysql_fetch_assoc($sup2))
						{
	
						$supx1 = "SELECT * FROM zikay_cmsv5.settings_suppliers WHERE supplier_pkey ='".$sup['po_supplierpkey']."' ORDER BY supplier_pkey ASC";
						$supx2 = mysql_query($supx1);
						
								while($supx = mysql_fetch_assoc($supx2))
									{
									?>
										<option value="<?php echo $supx['supplier_pkey'];?>" OnChange="window.location='<?php echo $self;?>?module=invoice&task=main&supplier_pkey=<?php echo $supx['supplier_pkey']; ?>'"><?php echo stripslashes($supx['supplier_name']);?></option>
									<?php
									}
						}
					
					?>
					<!--vendor end-->
				</select>(<?php echo $supx_count; ?>)
			</td><td></td><td></td>
	</tr>
	<tr>
		<td class=listheader>Date</td><td><input type="text"></td><td></td><td class=listheader>PO No</td>
			<td><select name=ponox>
				<option value="">--SELECT PO--</option>
					<!--po start-->
					<?php
					$po1 = "SELECT * FROM po_details WHERE po_projectpkey ='".$_SESSION[Xprojectpkey]."' ORDER by po_no ASC";
					$po2 = mysql_query($po1);
					$po_count = mysql_num_rows($po2);
					While($po = mysql_fetch_assoc($po2)){
					?>
						<option value="">PO<?php echo $po['po_no'];?> </option>
					<?php } ?>
					<!--po end-->
				</select>(<?php echo $po_count; ?>)
			</td><td class=listheader>Add.Charges</td><td><input type="text"></td>
	</tr>
	<tr>
		<td class=listheader>Amount</td><td><input type="text"></td><td></td><td class=listheader>DO No</td>
			<td><select name=donox>
					<option value="">--SELECT DO--</option>
					<!--Do Start-->
					<?php 
					$do1 = "SELECT * FROM do_items WHERE item_projectpkey ='".$_SESSION[Xprojectpkey]."' ORDER BY item_dono ASC";
					$do2 = mysql_query($do1);
					$do_count = mysql_num_rows($do2);
					while($do = mysql_fetch_assoc($do2)){
					?>
							<option value=""><?php echo $do['item_dono'];?>
					<?php } ?>
					<!--Do end-->
				</select> (<?php echo $do_count;?>)
			</td><td><td>
	</tr>
	</tr>
	</table>
    <?php
	 Print_r ($_SESSION);
	?>
   </div>

  <script type="text/javascript">

  function unFilter() {
    document.filterform.pono.value="";
    document.filterform.podate.value="";
    document.filterform.vendorname.value="";
    document.filterform.submit();
  }

  function switchPage1(pageno) {
    document.filterform.pageno1.value=pageno;
    document.filterform.submit();
  }

  function addInvoice(popkey) {
    document.location='index.php?module=invoice&task=add&itemid='+popkey;
  }

  </script>
