  <?
  include_once('models/mroModel.php');
  $mymroModel=new mroModel;

  // get project info
  // get mro details and items

  //$project_data = $myprojectModel->getdata_project

  $myprojectid = $_SESSION['Xprojectid'];
  $myprojectname = $_SESSION['Xprojectname'];
  $po_data = $mypoModel->getdata_po($pubitemid);
  $po_items = $mypoModel->getlist_poitems($pubitemid);

  $mro_data = $mymroModel->getdata_mro($po_data['po_mropkey']);
  $mro_items = $mymroModel->getlist_mroitems($po_data['po_mropkey']);

  $supplier_data = $mysupplierModel->getdata_supplier($po_data['po_supplierpkey']);
  ?>

  <div style="background: #ffffff;">
  <!--div style="background: #ffffff; height: 400; overflow: auto; overflow-x:none; overflow-y:scroll;"-->

  <table border=0 cellspacing=2 cellpadding=0 width=760>
  <tr valign=top>
  <td valign=top width=100>&nbsp;</td>
  <td valign=top width=560 class=rptzikayheader style="text-decoration: none; text-align: center;"><img src="gfx/zikayheader.png" style="width: 416px; height: 93px;"><!-- 390/87 416/93 519/116 --><!--<br><span style="font-size: 14px;"><u>KEMBANG SERANTAU SDN. BHD.</u></span>--></td>
  <td valign=top width=100>
    <table border=0 cellspacing=0 cellpadding=2 width=100>
    <tr valign=top><td valign=top width=100 class=rptzikayconfidential style="font-size: 10px; text-align: right;">PU-SP-01-F5</td></tr>
    <tr valign=top><td valign=top width=100 class=rptzikayconfidential style="font-size: 10px; text-align: right; border-top: 0px;">Rev : 1</td></tr>
    </table>
  </td>
  </tr>
  <tr valign=top>
  <td valign=top width=760 colspan=3 class=rptzikayheader style="text-decoration: none; text-align: center;"><span style="font-size: 14px;"><b><u>PURCHASE ORDER</u></b></span></td>
  </tr>
  </table>
  <br>

  <table border=0 cellspacing=2 cellpadding=0 width=760>
  <tr valign=top>
  <td valign=top width=100% class=cboxcontent>
    <table border=0 cellspacing=0 cellpadding=2 width=760 style="border: 0px;">
    <tr valign=top>
    <td valign=top width=400 class=listcontent style="border: 0px;">
      <table border=0 cellspacing=0 cellpadding=2 width=350>
      <tr valign=top>
      <td valign=top width=4 class=rptlistcontent style="border-left: 1px solid black; border-top: 1px solid black;"><img src="pixel.gif" border=0 width=1 height="1"></td>
      <td valign=top width=10 class=rptlistcontent style="border-top: 1px solid black;"><img src="pixel.gif" border=0 width=9 height="1"></td>
      <td valign=top width=322 class=rptlistcontent>
      </td>
      <td valign=top width=10 class=rptlistcontent style="border-top: 1px solid black;"><img src="pixel.gif" border=0 width=9 height="1"></td>
      <td valign=top width=4 class=rptlistcontent style="border-right: 1px solid black; border-top: 1px solid black;"><img src="pixel.gif" border=0 width=1 height="1"></td>
      </tr>
      <tr valign=top>
      <td valign=top width=4 class=rptlistcontent style="border-left: 1px solid black; height: 9px;">
      <img src="pixel.gif" border=0 width=1 height=9>
      </td>
      <td valign=top width=342 colspan=3 rowspan=5 class=rptlistcontent style="height: 100%;">
        <table border=0 cellspacing=0 cellpadding=2 width=350>
        <tr valign=top>
        <td valign=top width=330 class=rptlistcontent>
        <?=$supplier_data['supplier_name'];?><br><?=richtext($supplier_data['supplier_address']);?><br><?=$po_data['po_attn'];?><br>Phone: <?=$supplier_data['supplier_phone'];?><br>Fax: <?=$supplier_data['supplier_fax'];?>
        </td>
        </tr>
        </table>
      </td>
      <td valign=top width=4 class=rptlistcontent style="border-right: 1px solid black; height: 9px;">
      <img src="pixel.gif" border=0 width=1 height=9>
      </td>
      </tr>
      <tr valign=top>
      <td valign=top width=4 class=rptlistcontent style="height: 100%;">&nbsp;
      </td>
      <td valign=top width=4 class=rptlistcontent style="height: 100%;">&nbsp;
      </td>
      </tr>
      <tr valign=top>
      <td valign=top width=4 class=rptlistcontent style="height: 100%;">&nbsp;
      </td>
      <td valign=top width=4 class=rptlistcontent style="height: 100%;">&nbsp;
      </td>
      </tr>
      <tr valign=top>
      <td valign=top width=4 class=rptlistcontent style="height: 100%;">&nbsp;
      </td>
      <td valign=top width=4 class=rptlistcontent style="height: 100%;">&nbsp;
      </td>
      </tr>
      <tr valign=top>
      <td valign=top width=4 class=rptlistcontent style="border-left: 1px solid black; height: 9px;">
      <img src="pixel.gif" border=0 width=1 height=9>
      </td>
      <td valign=top width=4 class=rptlistcontent style="border-right: 1px solid black; height: 9px;">
      <img src="pixel.gif" border=0 width=1 height=9>
      </td>
      </tr>
      <tr valign=top>
      <td valign=top width=4 class=rptlistcontent style="border-left: 1px solid black; border-bottom: 1px solid black;"><img src="pixel.gif" border=0 width=1 height="1"></td>
      <td valign=top width=10 class=rptlistcontent style="border-bottom: 1px solid black;"><img src="pixel.gif" border=0 width=9 height="1"></td>
      <td valign=top width=322 class=rptlistcontent>
      </td>
      <td valign=top width=10 class=rptlistcontent style="border-bottom: 1px solid black;"><img src="pixel.gif" border=0 width=9 height="1"></td>
      <td valign=top width=4 class=rptlistcontent style="border-right: 1px solid black; border-bottom: 1px solid black;"><img src="pixel.gif" border=0 width=1 height="1"></td>
      </tr>
      </table>
    </td>
    <td valign=top width=360 class=listcontent style="border: 0px; text-align: right;">
      <br>
      <table border=0 cellspacing=0 cellpadding=4 width=350 style="border: 1px solid black; border-collapse: collapse;">
      <tr valign=top>
      <td valign=top width=90 class=rptlistcontent>
      P.O. No
      </td>
      <td valign=top width=120 class=rptlistcontent>
      : <?=poidstr($po_data['po_no']);//,$po_data['po_revno']);?>
      </td>
      <td valign=top width=60 class=rptlistcontent>
      MRO No
      </td>
      <td valign=top width=80 class=rptlistcontent>
      : <?=mroidstr($mro_data['mro_id']);?>
      </td>
      </tr>
      <tr valign=top>
      <td valign=top width=90 class=rptlistcontent>
      Credit Terms
      </td>
      <td valign=top width=120 class=rptlistcontent>
      : <?=$po_data['po_top']." days";?>
      </td>
      <td valign=top width=140 colspan=2 class=rptlistcontent>
      &nbsp;
      </td>
      </tr>
      <tr valign=top>
      <td valign=top width=90 class=rptlistcontent>
      Date
      </td>
      <td valign=top width=120 class=rptlistcontent>
      : <?=unconverttounix($po_data['po_date']);?>
      </td>
      <td valign=top width=140 colspan=2 class=rptlistcontent>
      &nbsp;
      </td>
      </tr>
      <tr valign=top>
      <td valign=top width=90 class=rptlistcontent>
      Project No.
      </td>
      <td valign=top width=260 colspan=3 class=rptlistcontent>
      : <?=$myprojectid;?>
      </td>
      </tr>
      </table>
    </td>
    </tr>
    </table>
    <br>

  </td>
  </tr>
  <tr valign=top>
  <td valign=top width=100% height=490 class=cboxcontent>

    <table border=0 cellspacing=0 cellpadding=0 width=760 style="border: 1px solid black; border-collapse: collapse; height: 100%;">
    <tr valign=top>
    <td valign=top width=100 class=rptlistheader style="text-transform: none; height: 20px;">ITEM</td>
    <td valign=top width=260 class=rptlistheader style="text-transform: none;">DESCRIPTION</td>
    <td valign=top width=100 class=rptlistheader style="text-transform: none;">QTY</td>
    <td valign=top width=100 class=rptlistheader style="text-transform: none;">UNIT</td>
    <td valign=top width=100 class=rptlistheader style="text-transform: none;">UNIT PRICE</td>
    <td valign=top width=100 class=rptlistheader style="text-transform: none;">AMOUNT</td>
    </tr>

    <? $poitemcount=0; ?>
    <? $pototalamount=0; ?>
    <? $pototalstring=""; ?>

    <? foreach($po_items as $myitem) { ?>

      <? $posubtotal = ($myitem['item_rate']*$myitem['item_quantity']); ?>

      <tr valign=top>
      <td valign=top width=100 class=rptlistnumber style="height: 16px;"><?=unescape($myitem['item_code']);?></td>
      <td valign=top width=260 class=rptlistcontent-left style="text-indent: 2px;">
	  <?=unescape($myitem['item_description']);?>
	  <? if ($myitem['item_remarks']!="") { echo "<br>".$myitem['item_remarks']; } ?>
	  <br /><br />
	  <?php 
	  /********************** 
	     cancel remark add
	     quick edit : yusr   
         remark : function at below/end of this script.		 
	   **********************/
	  //echo po_cancel_show($po_data['po_cancel'],$_GET['itemid'],$poitemcount);
	 
	   
	  ?>
	  </td>
      <td valign=top width=100 class=rptlistcontentnumeric-left><?=number_format($myitem['item_quantity'],4);?>&nbsp;</td>
      <td valign=top width=100 class=rptlistcontent-left style="text-align: center;"><?=$myitem['item_unit'];?>&nbsp;</td>
      <td valign=top width=100 class=rptlistcontentnumeric-left><?=number_format($myitem['item_rate'],2);?>&nbsp;</td>
      <td valign=top width=100 class=rptlistcontentnumeric-left><?=number_format($posubtotal,2);?>&nbsp;</td>
      </tr>

	  <?php echo po_cancel_show($po_data['po_cancel'],$_GET['itemid'],$poitemcount); ?>
	  
	  
      <? $poitemcount++; ?>
      <? $pototalamount += $posubtotal; ?>

    <? } ?>

    <tr valign=top>
    <td valign=top width=100 class=rptlistnumber style="height: 100%;">&nbsp;</td>
    <td valign=top width=260 class=rptlistcontent-left>&nbsp;</td>
    <td valign=top width=100 class=rptlistcontentnumeric-left>&nbsp;</td>
    <td valign=top width=100 class=rptlistcontent-left style="text-align: center;">&nbsp;</td>
    <td valign=top width=100 class=rptlistcontentnumeric-left>&nbsp;</td>
    <td valign=top width=100 class=rptlistcontentnumeric-left>&nbsp;</td>
    </tr>

    <tr valign=top>
    <td valign=top width=100 class=rptlistnumber style="height: 16px;">&nbsp;</td>
    <td valign=top width=260 class=rptlistcontent-left>
	
	<b>Note: Total Items <?=$myitem['item_no'];?> Only</b><br><br>
	</td>
    <td valign=top width=100 class=rptlistcontentnumeric-left>&nbsp;</td>
    <td valign=top width=100 class=rptlistcontent-left style="text-align: center;">&nbsp;</td>
    <td valign=top width=100 class=rptlistcontentnumeric-left>&nbsp;</td>
    <td valign=top width=100 class=rptlistcontentnumeric-left>&nbsp;</td>
    </tr>

    <?
    $pototalstring=number_format($pototalamount,2);	// test "561,246.23/00";
    $pototalstring=str_replace(",","",$pototalstring);
    $postrings = explode(".", $pototalstring);
    $ponum = number_to_words($postrings[0])." Ringgit";
    if ($postrings[1]!="00") {
      $podec = " and ".number_to_words($postrings[1])." Cents";
    }
    ?>

    <tr valign=top>
    <td valign=top width=560 colspan=4 class=rptlistcontent style="border-top: 1px solid black; height: 16px;">Ringgit Malaysia: <u><?=$ponum.$podec." Only";?></u></td>
    <td valign=top width=100 class=rptlistcontent-left style="border-top: 1px solid black;"><b>TOTAL</b><br><br></td>
    <td valign=top width=100 class=rptlistcontentnumeric-left style="border-top: 1px solid black;"><b><?=number_format($pototalamount,2);?></b>&nbsp;</td>
    </tr>

    </table>

  </td>
  </tr>
  <tr valign=top>
  <td valign=top width=100% class=cboxcontent>

    <table border=0 cellspacing=0 cellpadding=4 width=760 style="border: 1px solid black; border-collapse: collapse;">
    <tr valign=top>
    <td valign=top width=380 class=rptlistcontent-leftrightbottom>

      <table border=0 cellspacing=0 cellpadding=0 width=370 style="border: 0px;">
      <tr valign=top>
      <td valign=top width=100 class=rptlistcontent>
      Project Location:
      </td>
      <td valign=top width=270 class=rptlistcontent>
      <br>
      <? if ($po_data['po_co']!="") { echo $po_data['po_co']."<br>"; } ?>
	  <?=$myprojectname;?><br>
	  
	  <?
	  ////////////////////////////////////////////////////
	  $sql1 = "SELECT * FROM zikay_pmsv5.project_details WHERE projectname = '$myprojectname'";
	  $sql2 = mysql_query($sql1);
	  while($data = mysql_fetch_array($sql2)) {
	  echo $data['projectdescription'];
	  
	  }
	  
	  ?>
	  <br><?=$po_data['po_contactnumber'];?><br><br><?=$po_data['po_contactperson'];?><br><br>
      
	  </td>
      </tr>
      </table>

    </td>
    <td valign=top width=380 class=rptlistcontent-leftrightbottom>

      <table border=0 cellspacing=0 cellpadding=0 width=370 style="border: 0px;">
      <tr valign=top>
      <td valign=top width=370 class=rptlistcontent style="font-family: times new roman; font-size: 11px;">
      <u>CONDITION AND INSTRUCTION</u><br>
        <table border=0 cellspacing=0 cellpadding=0 width=370 style="border: 0px;">
        <tr valign=top>
        <td valign=top width=15 class=rptlistcontent>
        1.
        </td>
        <td valign=top width=355 class=rptlistcontent style="font-family: times new roman; font-size: 10px;">
        No goods are to be delivered without a written order signed by any Person Authorised by the company.
        </td>
        </tr>
        <tr valign=top>
        <td valign=top width=15 class=rptlistcontent>
        2.
        </td>
        <td valign=top width=355 class=rptlistcontent style="font-family: times new roman; font-size: 10px;">
        Materials must not be in excess of quantity ordered and must be of the required quality, and must meet the specification of our order, otherwise they will be returned at supplier's risk and expenses.
        </td>
        </tr>
        <tr valign=top>
        <td valign=top width=15 class=rptlistcontent>
        3.
        </td>
        <td valign=top width=355 class=rptlistcontent style="font-family: times new roman; font-size: 10px;">
        Delivery time is essence of the contract and we have the option to cancel the contract, to charge late penalty charges or refuse acceptance if not complied with for KEMBANG SERANTAU SDN BHD.
        </td>
        </tr>
        </table>
      </td>
      </tr>
      </table>

    </td>
    </tr>

    <tr valign=top>
    <td valign=top width=380 class=rptlistcontent-left>

      <table border=0 cellspacing=0 cellpadding=0 width=370 style="border: 0px;">
      <tr valign=top>
      <td valign=top width=100 class=rptlistcontent>
      <u>Prepared By:</u>
      </td>
      <td valign=top width=270 class=rptlistcontent>
      <br><br>
      <u>&nbsp; <? echo $po_data['po_requestor'];?><? // echo $pubuserfullname;?><br>
	  <? //$po_data['po_requestor'];?>&nbsp;<!--&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;--></u>
      </td>
      </tr>
      </table>

    </td>
    <td valign=top width=380 class=rptlistcontent-left>

      <table border=0 cellspacing=0 cellpadding=0 width=370 style="border: 0px;">
      <tr valign=top>
      <td valign=top width=130 class=rptlistcontent>
      <u>Authorised Signature:</u>
      </td>
      <td valign=top width=240 class=rptlistcontent>
      <br><br>
	  
      <u>&nbsp;<?php  echo $po_data['po_approver']; ?>&nbsp;</u>
      </td>
      </tr>
      </table>

    </td>
    </tr>

    </table>

  </td>
  </tr>
  </table>
  <br>

  <table border=0 cellspacing=2 cellpadding=0 width=760 style="position: absolute; top: 1000px;">
  <tr valign=top>
  <td valign=top width=100% class=cboxcontent>
    <table border=0 cellspacing=0 cellpadding=2 width=750>
    <tr valign=top>
    <td valign=top width=750 class=rptlistcontent style="text-align: center;">
    <span style="font-family: times new roman; font-size: 11px;">THIS IS A COMPUTER GENERATED FORM AND IT DOES NOT REQUIRE ANY SIGNATURE</span>
    </td>
    </tr>
    </table>
  </td>
  </tr>
  </table>

  <table border=0 cellspacing=2 cellpadding=0 width=760 style="position: absolute; top: 1020px;">
  <tr valign=top>
  <td valign=top width=100% class=cboxcontent>
    <table border=0 cellspacing=0 cellpadding=2 width=760>
    <tr valign=top>
    <td valign=top width=750 class=listcontent style="border-left: 0px; border-top: 0px; border-right: 0px; border-bottom: 0px;">
      <table border=0 cellspacing=0 cellpadding=2 width=750>
      <tr valign=top>
      <td valign=top width=750 class=rptlistcontent style="text-align: center; border-top: 1px solid black;">
      <span style="font-family: times new roman; font-size: 11px;"><b>ARAS 8, BANGUNAN ZIKAY, JALAN RAJA ALANG, KAMPUNG BARU, 50300 KUALA LUMPUR.</b></span><br><span style="font-family: arial; font-size: 11px;"><b>TEL: 03-26988789 &nbsp;&nbsp;&nbsp; FAX: 03-26936775</b></span>
      </td>
      </tr>
    </td>
    </tr>
    </table>

  </td>
  </tr>
  </table>

  </div>

  <div style="background: #f0f0f0;">

  <form action="controllers/inputController.php" method="post" name="poform" id="poform">

  <table border=1 cellspacing=2 cellpadding=0 width=760 style="background: #f0f0f0;">
  <tr valign=top>
  <td valign=top width=100 class=formlabel>Date *</td>
  <td valign=top width=510 class=cboxcontent><input name="date" id="date" type="text" value="<?=unconverttounixslash(gettimestamp());?>" style="width: 90px;"></td>
  <td valign=top width=150 class=formlabel>Action</td>
  </tr>
  <tr valign=top>
  <td valign=top width=100 class=formlabel>Remarks *</td>
  <td valign=top width=510 class=cboxcontent><textarea name="remarks" id="remarks" rows=6 style="width: 500px;"></textarea></td>
  <td valign=top width=150 class=cboxcontent>
  <? if ($po_data['po_cancel']=="0" and $_SESSION['Xuseraccess']['access_po_cancel'] == "1") { ?>
    <button name="reject" id="reject" onClick="rejectDocument();" style="width: 130px; text-align: left;">&nbsp;&nbsp;<img src='gfx/options/b_stop.png' class='actionbutton'>&nbsp;&nbsp;Cancel Item</button>&nbsp;<br>
    <button name="cancel" id="cancel" onClick="cancelDocument();" style="width: 130px; text-align: left;">&nbsp;&nbsp;<img src='gfx/options/b_cancel.png' class='actionbutton'>&nbsp;&nbsp;Cancel PO</button>&nbsp;<br>
  <? } ?>
  <button name="print" id="print" onClick="po_button_print('<?=$pubitemid;?>');" style="width: 130px; text-align: left;">&nbsp;&nbsp;<img src='gfx/options/b_print1.png' class='actionbutton'>&nbsp;&nbsp;Print&nbsp;</button>&nbsp;<br>
  <button name="back" id="back" onClick="cancelAction();" style="width: 130px; text-align: left;">&nbsp;&nbsp;<img src='gfx/options/b_back.png' class='actionbutton'>&nbsp;&nbsp;Back</button>&nbsp;
  </td>
  </tr>
  <input name="popkey" id="popkey" type="hidden" value="<?=$pubitemid;?>">
  <input name="type" id="type" type="hidden" value="<?=$pubtype;?>">
  <input name="userpkey" id="userpkey" type="hidden" value="<?=$_SESSION['Xuserpkey'];?>">
  <input name="officername" id="officername" type="hidden" value="<?=$_SESSION['Xstaffname'];?>">
  <input name="status" id="status" type="hidden" value="">
  <input name="job" id="job" type="hidden" value="po_approve">

  </form>

  </div>

<script type="text/javascript">

function validDateOnly() {
  var isvalid = true;
  var objdate = document.getElementById('date');
  if (objdate.value=="") isvalid = false;
  return isvalid;
}

function validRemarks() {
  var isvalid = true;
  var objremarks = document.getElementById('remarks');
  var objdate = document.getElementById('date');
  if ((objremarks.value=="")||(objdate.value=="")) isvalid = false;
  return isvalid;
}

function approveDocument(actiontype) {
  if (validDateOnly()) {
    if (confirm('Are you sure to ' + actiontype + ' this PO?')) {
      document.poform.status.value='1'; document.poform.submit();
    }
  } else {
    alert('Approval Date is a mandatory field!');
  }
}

function rejectDocument() {
  if (validRemarks()) {
    if (confirm('Are you sure to Cancel this PO (Cancel Item)?')) {
      document.poform.status.value='3'; document.poform.submit();
    }
  } else {
    alert('Date and Remarks are mandatory fields!');
  }
}

function cancelDocument() {
  if (validRemarks()) {
    if (confirm('Are you sure to Cancel this PO?')) {
      document.poform.status.value='2'; document.poform.submit();
    }
  } else {
    alert('Date and Remarks are mandatory fields!');
  }
}

function cancelAction() {
  document.location='index.php?module=po&task=main';
}

</script>
<pre>
<?php 
//echo $_SESSION['Xuseraccess']['access_po_cancel'];
//print_r($_SESSION);?>
</pre>
<?php
// quick function yusr.
function po_cancel_show($po_data_cancel, $itemid, $kaunt)
	{
	
	 if($po_data_cancel == 1) // if po's = 1 (cancel)
	  {
	  
	  $sqlx1 = mysql_query("select * from zikay_pmsv5.po_approvals where approval_popkey ='".$_GET['itemid']."'");
	  $datax1 = mysql_fetch_assoc($sqlx1);
		if($kaunt == 0){
		return  "
		<tr valign=top><td></td><td colspan=\"4\" style='color:red; font-weight:bold; text-align:center; padding:10px 10px 10px 10px;'>
		". $datax1['approval_remarks']."<br />
		@ ".unconverttounixslash($datax1['approval_date']).
		"</td><td></td><td></td></tr>";
		}else{
		return "";
		}
	  }
	}
?>