  <br>
  <table border=1 cellspacing=1 cellpadding=2 width=928 style="border: 1px inset;">
  <form action="index.php?module=supplier&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>Name :</td>
  <td valign=top width=140 class=listcontent><input name="suppliername" id="suppliername" value="<?=$filtersuppliername;?>" style="width: 135px;"></td>
  <!--<td valign=top width=190 class=listcontent>Name: <input name="suppliername" id="suppliername" value="<?=$filtersuppliername;?>" style="width: 135px;"></td>-->
  <td valign=top width=70 class=listcontent>Approved?</td>
  <td valign=top width=60 class=listcontent>
  <select name="approvedstatus" id="approvedstatus" style="width: 50px;">
  <option value="" selected>Any</option>
  <option value="1" <? if ($filterapprovedstatus=="1") echo "selected"; ?>>Yes</option>
  <option value="0" <? if ($filterapprovedstatus=="0") echo "selected"; ?>>No</option>
  </select>
  </td>
  <td valign=top width=60 class=listcontent>Status :</td>
  <td valign=top width=70 class=listcontent>
  <select name="activestatus" id="activestatus" style="width: 60px;">
  <option value="" selected>Any</option>
  <option value="1" <? if ($filteractivestatus=="1") echo "selected"; ?>>Active</option>
  <option value="0" <? if ($filteractivestatus=="0") echo "selected"; ?>>Inactive</option>
  <option value="2" <? if ($filteractivestatus=="2") echo "selected"; ?>>Blacklisted</option>
  </select>
  </td>
  <td valign=top width=140 class=listcontent>Nature of Business :</td>
  <td valign=top width=130 class=listcontent>
  <select name="suppliernob" id="suppliernob" style="width: 125px;">
  <option value="" selected>--Any--</option>
  <option value="MANUFACTURER" <? if ($filtersuppliernob=="MANUFACTURER") echo "selected"; ?>>MANUFACTURER</option>
  <option value="TRADING" <? if ($filtersuppliernob=="TRADING") echo "selected"; ?>>TRADING</option>
  <option value="OTHERS" <? if ($filtersuppliernob=="OTHERS") echo "selected"; ?>>OTHERS</option>
  </select>
  </td>
  <td valign=top width=208 class=listcontent>
  <input name="pageno" id="pageno" 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=2008 style="border: 1px inset;">
  <form action="controllers/inputController.php" method="post" name="supplierform" id="supplierform">

  <tr valign=top>
  <td valign=top width=48 rowspan=2 class=listheader>No.</td>
  <td valign=top width=100 rowspan=2 class=listheader>Register Date</td>
  <td valign=top width=100 rowspan=2 class=listheader>Approved Date</td>
  <td valign=top width=100 rowspan=2 class=listheader>Supplier Reg No</td>
  <td valign=top width=240 rowspan=2 class=listheader>Supplier Name<br>Address/Tel/Fax/Email</td>
  <td valign=top width=160 rowspan=2 class=listheader>Contact Person</td>
  <td valign=top width=120 rowspan=2 class=listheader>Contact Number (PIC)</td>
  <td valign=top width=120 rowspan=2 class=listheader>Credit Terms</td>
  <td valign=top width=120 rowspan=2 class=listheader>Nature of Business</td>
  <td valign=top width=120 rowspan=2 class=listheader>Products</td>
  <td valign=top width=100 rowspan=2 class=listheader>Status</td>
  <td valign=top width=480 colspan=4 class=listheader>Credit Facilities</td>
  <td valign=top width=80 rowspan=2 class=listheader>Options</td>
  <td valign=top width=120 rowspan=2 class=listheader>Operations</td>
  </tr>
  <tr valign=top>
  <td valign=top width=120 class=listheader>Bank Guarantee</td>
  <td valign=top width=120 class=listheader>Personal Guarantee</td>
  <td valign=top width=120 class=listheader>Amount</td>
  <td valign=top width=120 class=listheader>Remarks</td>
  </tr>

  <? $cindex=0; ?>

  <?
  $firstrec = (($pubpageno-1)*5)+1;
  $lastrec = $firstrec + 4;
  $pagecount = 1;
  ?>

  <? foreach ($supplier_list as $mysupplier) { ?>

    <? if (($mysupplier['recordno']>=$firstrec)&&($mysupplier['recordno']<=$lastrec)) { ?>

      <? $aindex=0; ?>
      <? unset($myapproval); ?>

      <? foreach ($approval_list[$cindex] as $myapprovalitem) { ?>
        <? $myapproval = $myapprovalitem; ?>
        <? $aindex++; ?>
      <? } ?>

      <tr valign=top>
      <td valign=top width=48 class=listnumber><?=$mysupplier['recordno'];?></td>
      <td valign=top width=100 class=listcontent><?=unconverttounixslash($mysupplier['supplier_regdate']);?>&nbsp;</td>
      <td valign=top width=100 class=listcontent><? if ($mysupplier['supplier_approved']==1) { ?><?=unconverttounixslash($myapproval['approval_date']);?>&nbsp;<a href="index.php?module=supplier&task=approvals&itemid=<?=$mysupplier['supplier_pkey'];?>"><img src="gfx/options/b_find3.png" border=0 title="View Approvals" alt="View Approvals"></a><? } ?>&nbsp;</td>
      <td valign=top width=100 class=listcontent><? if ($mysupplier['supplier_regid']!=0) { ?><?=idstr($mysupplier['supplier_regid']);?><? } ?>&nbsp;</td>
      <td valign=top width=240 class=listcontent><?=$mysupplier['supplier_name'];?><br><?=$mysupplier['supplier_address'];?><br>Tel: <?=$mysupplier['supplier_phone'];?><br>Fax: <?=$mysupplier['supplier_fax'];?><br>Email: <?=$mysupplier['supplier_email'];?>&nbsp;</td>
      <td valign=top width=160 class=listcontent><?=$mysupplier['supplier_pic'];?>&nbsp;</td>
      <td valign=top width=120 class=listcontent><?=$mysupplier['supplier_picphone'];?>&nbsp;</td>
      <td valign=top width=120 class=listcontent><?=$mysupplier['supplier_ct'];?>&nbsp;</td>
      <td valign=top width=120 class=listcontent><?=$mysupplier['supplier_nob'];?>&nbsp;</td>
      <td valign=top width=120 class=listcontent><?=$mysupplier['supplier_products'];?>&nbsp;</td>
      <td valign=top width=100 class=listcontent>
      <? // TODO: colour coding (blue/red/?)..
      if ($mysupplier['supplier_status']==1) {
        echo "<font color='#00c000'><b>Active</b></font>"; 
      } else if ($mysupplier['supplier_status']==0) {
        echo "<font color='#0000ff'><b>Inactive</b></font>";
      } else if ($mysupplier['supplier_status']==2) {
        echo "<font color='#ff0000'><b>Blacklisted</b></font>";
      } else if ($mysupplier['supplier_status']==8) {
        echo "<font color='#ff0000'><b>Inactive 2</b></font>";
      }
      ?>
      &nbsp;</td>
      <td valign=top width=120 class=listcontentnumeric><?=number_format($bgtotal[$cindex]['bg_banktotal'],2);?>&nbsp;</td>
      <td valign=top width=120 class=listcontentnumeric><?=number_format($mysupplier['supplier_personalamount'],2);?>&nbsp;</td>
      <td valign=top width=120 class=listcontentnumeric><?=number_format($bgtotal[$cindex]['bg_fulltotal'],2);?>&nbsp;</td>
      <td valign=top width=120 class=listcontent><? if ($bgtotal[$cindex]['bg_fullremarks']!="") { ?><?=$bgtotal[$cindex]['bg_fullremarks'];?><? } else { ?>&nbsp;<? } ?>&nbsp;</td>
      <td valign=top width=80 class=listcontent>
      <a href="index.php?module=supplier&task=view&itemid=<?=$mysupplier['supplier_pkey'];?>"><img src="gfx/options/b_view.png" border=0 title="View" alt="View"></a>
      <? //if ($pubuseraccess['access_supplier_edit']==1) { ?>
        <!--
        <a href="index.php?module=supplier&task=edit&itemid=<?=$mysupplier['supplier_pkey'];?>"><img src="gfx/options/b_edit.png" border=0 title="Edit" alt="Edit"></a>
        <a href="index.php?module=supplier&task=delete&itemid=<?=$mysupplier['supplier_pkey'];?>"><img src="gfx/options/b_drop.png" border=0 title="Delete" alt="Delete"></a>
        -->
      <? //} ?>
      </td>
      <td valign=top width=120 class=listcontent>
      <? if ($aindex==0) { ?>
        <? if (($pubuseraccess['access_supplier_recommend']==1)||($pubuserrole>=2)) { ?>
          <button name="recommend" id="recommend" style="width: 100px;" onClick="supplier_button_recommend('<?=$mysupplier['supplier_pkey'];?>');">Recommend</button><br>
        <? } ?>
      <? } else { ?>
        <? if ($myapproval['approval_type']==1) { ?>
          <? if (($pubuseraccess['access_supplier_approve']==1)||($pubuserrole>=2)) { ?>
            <button name="approve" id="approve" style="width: 100px;" onClick="supplier_button_approve('<?=$mysupplier['supplier_pkey'];?>');">Approve</button><br>
          <? } ?>
        <? } else if ($myapproval['approval_type']==2) { ?>
          <!--<button name="approve" id="approve" style="width: 100px;" onClick="supplier_button_approve('<?=$mysupplier['supplier_pkey'];?>');">Approve</button>-->
        <? } else { ?>
          <? if (($pubuseraccess['access_supplier_recommend']==1)||($pubuserrole>=2)) { ?>
            <button name="recommend" id="recommend" style="width: 100px;" onClick="supplier_button_recommend('<?=$mysupplier['supplier_pkey'];?>');">Recommend</button><br>
          <? } ?>
        <? } ?>
      <? } ?>
      <? if ($mysupplier['supplier_status']==1) { ?>
        <? if (($pubuseraccess['access_supplier_activate']==1)||($pubuserrole>=2)) { ?>
          <button name="deactivate" id="deactivate" style="width: 100px;" onClick="supplier_button_deactivate('<?=$mysupplier['supplier_pkey'];?>');">Blacklist</button><br>
        <? } ?>
      <? } else if ($mysupplier['supplier_status']==2) { ?>
        <? if (($pubuseraccess['access_supplier_activate']==1)||($pubuserrole>=2)) { ?>
          <button name="activate" id="activate" style="width: 100px;" onClick="supplier_button_activate('<?=$mysupplier['supplier_pkey'];?>');">Unblacklist</button><br>
        <? } ?>
      <? } ?>
      &nbsp;
      </td>
      </tr>

	<?php  
	  //total in page
	  $ybg2 += $bgtotal[$cindex]['bg_banktotal']; 
	  $ypg2 += $mysupplier['supplier_personalamount'];
	  $ya2 += $bgtotal[$cindex]['bg_fulltotal'];
	 ?>
    <? } ?>

    <? $cindex++; ?>

  <?php 
 
  //grand total
  $ybg += $bgtotal[$cindex]['bg_banktotal']; 
  $ypg += $mysupplier['supplier_personalamount'];
  $ya += $bgtotal[$cindex]['bg_fulltotal'];
  ?>
	
  <? } ?>
 
  <?
  $pagecount = intval($mysupplier['recordno']/5) + 1;
  ?>
  
  <input name="reporttype" id="reporttype" type="hidden" value="sup">
  <input name="job" id="job" type="hidden" value="report_print">
  
  <!-- total in page -->
  <tr><td colspan=11 style="text-align:right; font-weight:bold;background:#fff; border=0" class=listcontent> TOTAL(in page) : </td>
  <td class=listcontent style="background:#ddd; text-align:right;"><?php  echo number_format($ybg2,2); ?></td>
  <td class=listcontent style="background:#ddd; text-align:right;"><?php echo number_format($ypg2,2);?></td>
  <td class=listcontent style="background:#ddd; text-align:right;"><?php echo number_format($ya2,2);?></td>
  <td class=listcontent></td><td></td></tr>
  <!-- grand total -->
  <tr><td colspan=11 style="text-align:right; font-weight:bold;background:#fff; border=0" class=listcontent> GRAND TOTAL : </td>
  <td class=listcontent style="background:#ddd; text-align:right;"><?php  echo number_format($ybg,2); ?></td>
  <td class=listcontent style="background:#ddd; text-align:right;"><?php echo number_format($ypg,2);?></td>
  <td class=listcontent style="background:#ddd; text-align:right;"><?php echo number_format($ya,2);?></td>
  <td class=listcontent></td><td></td></tr>
  <!-- grand total end -->
  </form>
  </table>

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

  <script type="text/javascript">

  function unFilter() {
    document.filterform.suppliername.value="";
    document.filterform.approvedstatus.value="";
    document.filterform.activestatus.value="";
    document.filterform.suppliernob.value="";
    document.filterform.submit();
  }

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

  </script>
