<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 MRO?')) {
      document.mroform.status.value='1'; document.mroform.submit();
    }
  } else {
    alert('Approval Date is a mandatory field!');
  }
}

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

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

function cancelAction() {
 window.location.href='index.php?module=mro&task=list';
 return false;
}

</script>


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

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

  //$project_data = $myprojectModel->getdata_project

  $myprojectname = $_SESSION['Xprojectname'];
  $mro_data = $mymroModel->getdata_mro($pubitemid);
  $mro_items = $mymroModel->getlist_mroitems($pubitemid);
  ?>

  <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=660 class=rptzikayheader style="text-decoration: none;"><img src="../gfx/zikay.png" width=45px height=56px align=left><br><span style="font-size: 14px;"><u>KEMBANG SERANTAU SDN BHD</u></span></td>-->
  <td valign=top width=560 class=rptzikayheader style="text-decoration: none; text-align: center;"><img src="gfx/zikayheader.png" style="width: 390px; height: 87px;"><!-- 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-F1</td></tr>
    <tr valign=top><td valign=top width=100 class=rptzikayconfidential style="font-size: 10px; text-align: right; border-top: 0px;">Rev : 4</td></tr>
    </table>
  </td>
  </tr>
  <tr valign=top>
  <td valign=top width=760 colspan=3 class=rptzikayheader style="text-decoration: none; text-align: center;"><br><span style="font-size: 12px;"><u>MATERIAL REQUISITION ORDER</u></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=1 cellspacing=0 cellpadding=2 width=760 style="border: 1px solid black; border-collapse: collapse;">
    <tr valign=top>
    <td valign=top width=560 rowspan=2 class=listcontent style="border-left: 1px solid black; border-top: 1px solid black; border-right: 1px solid black; border-bottom: 1px solid black;">
      <table border=0 cellspacing=0 cellpadding=2 width=550>
      <tr valign=top>
      <td valign=top width=180 class=rptlistcontent>
      <b>Project Title</b>
      </td>
      <td valign=top width=10 class=rptlistcontent>:</td>
      <td valign=top width=340 class=rptlistcontent style="border-bottom: 1px solid black;">
      <?=$myprojectname;?>
      </td>
      <td valign=top width=20 class=rptlistcontent>&nbsp;</td>
      </tr>
      <tr valign=top>
      <td valign=top width=180t>&nbsp;</td>
      <td valign=top width=10>&nbsp;</td>
      <td valign=top width=340 class=rptlistcontent style="border-bottom: 1px solid black;">&nbsp;</td>
      <td valign=top width=20 class=rptlistcontent>&nbsp;</td>
      </tr>
      <tr valign=top>
      <td valign=top width=180 class=rptlistcontent>
      <b>Date of Request</b>
      </td>
      <td valign=top width=10 class=rptlistcontent>:</td>
      <td valign=top width=340 class=rptlistcontent style="border-bottom: 1px solid black;">
      <?=unconverttounix($mro_data['mro_requestdate']);?>
      </td>
      <td valign=top width=20 class=rptlistcontent>&nbsp;</td>
      </tr>
      <tr valign=top>
      <td valign=top width=180 class=rptlistcontent>
      <b>Expected Date of Delivery</b>
      </td>
      <td valign=top width=10 class=rptlistcontent>:</td>
      <td valign=top width=340 class=rptlistcontent style="border-bottom: 1px solid black;">
      <?=unconverttounix($mro_data['mro_deliverydate']);?>
      </td>
      <td valign=top width=20 class=rptlistcontent>&nbsp;</td>
      </tr>
      <tr valign=top>
      <td valign=top width=180 class=rptlistcontent>
      <b>Backcharge / Debit Account</b>
      </td>
      <td valign=top width=10 class=rptlistcontent>:</td>
      <td valign=top width=340 class=rptlistcontent style="border-bottom: 1px solid black;">
      <? 
      if (($mro_data['mro_debitaccount']=="")&&($mro_data['mro_subcons']=="")) {
        echo "-NA-"; 
      } else if (strlen($mro_data['mro_subcons'])>32) {
        echo "Please Refer Remarks";
      } else {
        //echo $supplier_data['supplier_name']."&nbsp;"; 
		
		$xx = $mro_data['mro_debitaccount'];
	    $sql1 = "SELECT * FROM `zikay_cmsv5`.`settings_subcontractors` WHERE `subconmasterpkey` = '$xx'";
		$sxx = mysql_query($sql1);
		while($data = mysql_fetch_assoc($sxx))
		{ echo $data['subconname'];}
      }
      ?>
      </td>
      <td valign=top width=20 class=rptlistcontent>&nbsp;</td>
      </tr>
      </table>
    </td>
    <td valign=top width=200 class=listcontent style="border-left: 1px solid black; border-top: 1px solid black; border-right: 1px solid black; border-bottom: 1px solid black;">
      <table border=0 cellspacing=0 cellpadding=2 width=190>
      <tr valign=top>
      <td valign=top width=190 class=rptlistcontent>
      <br>
      <b>MRO No.</b> :&nbsp;&nbsp;&nbsp;&nbsp;<?=mroidstr($mro_data['mro_id']);//,$mro_data['mro_revno']);?>
      <br><br>
      </td>
      </tr>
      </table>
    </td>
    </tr>
    <tr valign=top>
    <td valign=top width=200 class=listcontent style="border-left: 1px solid black; border-top: 1px solid black; border-right: 1px solid black; border-bottom: 1px solid black;">
      <table border=0 cellspacing=0 cellpadding=2 width=190>
      <tr valign=top>
      <td valign=top width=190 class=rptlistcontent>
      Sub-con PO/Ref : <?=$mro_data['mro_subconref'];?>
      </td>
      </tr>
      <tr valign=top>
      <td valign=top width=190 class=rptlistcontent>
      Client MRO NO : <?=$mro_data['mro_clientref'];?>
      </td>
      </tr>
      </table>
    </td>
    </tr>
    </table>
    <br>

  </td>
  </tr>
  <tr valign=top>
  <td valign=top width=100% height=620 class=cboxcontent>
<?php
// tambahan
$dd = "SELECT item_subtradepkey FROM `zikay_pmsv5`.`mro_items` WHERE item_mropkey = '".$_GET['itemid']."'";
$dd2 = mysql_query($dd);
$dd3 = mysql_fetch_assoc($dd2);

$ee = $dd3['item_subtradepkey'];

$ff = "SELECT * FROM `zikay_pmsv5`.`settings_trades` WHERE tradepkey = '" .$ee. "'";
$ff2 = mysql_query($ff);
$ff3 = mysql_fetch_assoc($ff2);

	//echo $ff3['tradedescription'];


?>
    <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=80 class=rptlistheader style="text-transform: none; height: 20px;">Item</td>
    <td valign=top width=280 class=rptlistheader style="text-transform: none;">Description</td>
    <td valign=top width=80 class=rptlistheader style="text-transform: none;">Unit</td>
    <td valign=top width=80 class=rptlistheader style="text-transform: none;">Qty</td>
    <td valign=top width=180 class=rptlistheader style="text-transform: none;">Purpose</td>
    <td valign=top width=80 class=rptlistheader style="text-transform: none;">Remarks</td>
    </tr>
    <tr valign=top>
    <td valign=top class=rptlistnumber style="height: 16px;">&nbsp;</td>
    <td valign=top class=rptlistcontent-left>&nbsp;</td>
    <td valign=top class=rptlistcontent-left style="text-align: center;">&nbsp;</td>
    <td valign=top class=rptlistcontentnumeric-left>&nbsp;</td>
    <td valign=top class=rptlistcontent-left>&nbsp;</td>
    <td valign=top rowspan=500 class=rptlistcontent-left><br><center><?=richtext($mro_data['mro_remarks']);?></center>&nbsp;</td>
    </tr>

	
	<!-- tambahan -->
	<tr valign=top>
        <td valign=top  class=rptlistnumber style="height: 10px;"><b><?php echo $ff3['tradecode'];?></b></td>
        <td valign=top  class=rptlistcontent-left style="text-indent: 2px;"><b><?php echo $ff3['tradedescription']; ?></b></td>
        <td valign=top  class=rptlistcontent-left style="text-align: center;"></td>
        <td valign=top  class=rptlistcontentnumeric-left></td>
        <td valign=top  class=rptlistcontent-left style="text-indent: 2px;"></td>
        <!--<td valign=top width=200 class=rptlistcontent></td>-->
        </tr>
	
	<!-- tambahan tamat-->
	
    <? foreach($mro_items as $myitem) { ?>

      <? if ($myitem['item_quantity']>0) { ?>
        <tr valign=top>
        <td valign=top class=rptlistnumber style="height: 16px;"><?=$myitem['item_no'];?>&nbsp;</td>
        <td valign=top class=rptlistcontent-left style="text-indent: 2px;"><? echo unescape($myitem['item_code']);?> : <?=unescape($myitem['item_description']);?><? if ($myitem['item_remarks']!="") { echo "<br>".papar_break($myitem['item_remarks']); } ?><br>&nbsp;</td>
        <td valign=top class=rptlistcontent-left style="text-align: center;"><?=$myitem['item_unit'];?>&nbsp;</td>
        <td valign=top class=rptlistcontentnumeric-left><?=number_format($myitem['item_quantity'],4);?>&nbsp;</td>
        <td valign=top class=rptlistcontent-left style="text-indent: 2px;"><?=$myitem['item_purpose'];?>&nbsp;</td>
        <!--<td valign=top width=200 class=rptlistcontent></td>-->
        </tr>

      <? } ?>

    <? } ?>

    <? if ($mro_data['mro_status']=="9") { ?>

      <tr valign=top>
      <td valign=top class=rptlistnumber style="height: 16px;">&nbsp;</td>
      <td valign=top class=rptlistcontent-left style="text-indent: 2px;"><b><? if ($mro_data['mro_cancel']=="1") { echo "CANCELLED: "; } else if ($mro_data['mro_cancel']=="2") { echo "REJECTED: "; } ?><?=$mro_rejection['approval_remarks'];?></b>&nbsp;</td>
      <td valign=top class=rptlistcontent-left style="text-align: center;">&nbsp;</td>
      <td valign=top class=rptlistcontentnumeric-left>&nbsp;</td>
      <td valign=top class=rptlistcontent-left style="text-indent: 2px;">&nbsp;</td>
      </tr>

    <? } ?>

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

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

    </table>

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

  <table width="760" border="0" cellspacing=2 cellpadding=0>
  <tr>
    <td width="250" class=rptlistcontent valign="top"><strong>Prepared  and Checked by :</strong></td>
    <td width="5">&nbsp;</td>
    <td width="250" class=rptlistcontent valign="top"><strong>Recommended by :<br><sup>(Non Budgeted Material)</sup></strong></td>
    <td width="5">&nbsp;</td>
    <td width="250" class=rptlistcontent valign="top"><strong>Approved  by :</strong></td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td style="border-bottom: 1px solid black;" class=rptlistcontent>
    <?php
    if($mro_data['mro_requestor'] != '')
	 //echo "" .dottedstr($pubuserfullname,30). "";
      echo $mro_data['mro_requestor'];
	  //echo "ddd";
    else
      echo "&nbsp;";
     ?>
     </td>
    <td>&nbsp;</td>
    <td style="border-bottom: 1px solid black;" class=rptlistcontent>&nbsp;
	<?php echo $mro_data['mro_recommended']; ?>
	</td>
    <td>&nbsp;</td>
    <td style="border-bottom: 1px solid black;" class=rptlistcontent>&nbsp;
	<?php 
    if($mro_data['mro_approver'] != '')
      echo $mro_data['mro_approver'];
    else 
     echo "&nbsp";
    ?>
    <?//=unconverttounixslash($mro_data['mro_requestdate']);?> 
    </td>
  </tr>
  <tr>
    <td class=rptlistcontent>Project QS / Quantity Surveyor</td>
    <td>&nbsp;</td>
    <td class=rptlistcontent>Project Manager</td>
    <td>&nbsp;</td>
    <td class=rptlistcontent>Project Manager / CEO </td>
  </tr>
  <tr>
    <td>&nbsp;</td>
  </tr>
</table>

  <table border=0 cellspacing=2 cellpadding=0 width=760 style="position: absolute; top: 1040px;">
  <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; border-top: 1px solid black;">
    
    </td>
    </tr>
    </table>
  </td>
  </tr>
  </table>
  
  
  
	<?php //} ?>


  </div>

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

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

  <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;"> <a rel="htmltooltip" style="color:red">
  
  PM REMARKS</a><div class="htmltooltip">
  
  <?php
  $sql1 = "SELECT * FROM `zikay_pmsv5`.`mro_approvals` WHERE approval_mropkey = '".$_GET['itemid']."'";
 $sxx = mysql_query($sql1);
 //echo "<p style=\"color:#4D4D4D\"><u>REMARK</u>";
 while($data = mysql_fetch_assoc($sxx))
 {
 echo "".$data['approval_remarks']. "";
 } ?>
  </div>
  
  
  
  
  
  </td>
  <td valign=top width=150 class=formlabel>Action</td>
  </tr>
  <tr valign=top>
  <td valign=top width=100 class=formlabel>Remarks * <br /> </td>
  <td valign=top width=510 class=cboxcontent>
  <textarea name="remarks" id="remarks" rows=6 style="width: 500px;" align="left"><? if ($mro_data['mro_cancel']!="1") { 
     if ($pubtype=="2"){ 
      if (($pubuseraccess['access_mro_recommendvariance']==1)||($pubuserrole>=2)) { 
		echo ""; 
		 } 
     } else if ($pubtype=="3") { 
       if (($pubuseraccess['access_mro_approvenormal']==1)||($pubuseraccess['access_mro_approvevariance']==1)||($pubuserrole>=2)) { 
		
		
		$sql1 = "SELECT * FROM `zikay_cmsv5`.`settings_subcontractors` WHERE `subconmasterpkey` = '$xx'";
		$sxx = mysql_query($sql1);
		while($data = mysql_fetch_assoc($sxx))
		{ echo $data['subconname'];}
		
		// print "Ok. Please do it urgently"; 
	    } 
    } 
     if (($pubuseraccess['access_mro_cancel']==1)||($pubuserrole>=2)) { 
     
	  } 
   } ?></textarea></td>
  
  
  <td valign=top width=150 class=cboxcontent>
  <? if ($mro_data['mro_cancel']!="1") { ?>
    <? if ($pubtype=="2") { ?>
      <? if (($pubuseraccess['access_mro_recommendvariance']==1)||($pubuserrole>=2)) { ?>
        <button name="accept" id="accept" onClick="approveDocument('Recommend');" style="width: 130px; text-align: left;">&nbsp;&nbsp;<img src='gfx/options/b_approve.png' class='actionbutton'>&nbsp;&nbsp;Recommend</button>&nbsp;<br>
        <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;Reject Item</button>&nbsp;<br>
      <? } ?>
    <? } else if ($pubtype=="3") { ?>
      <? if (($pubuseraccess['access_mro_approvenormal']==1)||($pubuseraccess['access_mro_approvevariance']==1)||($pubuserrole>=2)) { ?>
        <button name="accept" id="accept" onClick="approveDocument('Approve');" style="width: 130px; text-align: left;">&nbsp;&nbsp;<img src='gfx/options/b_approve.png' class='actionbutton'>&nbsp;&nbsp;Approve</button>&nbsp;<br>
        <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;Reject 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 MRO</button>&nbsp;<br>
     -->     
	 <? } ?>
    <? } ?>
    <? //if (($pubtask=="approvenormal")||($pubtask=="recommend")) { ?>
      <!--<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;Reject Item</button>&nbsp;<br>-->
    <? //} ?>
    <? if (($pubuseraccess['access_mro_cancel']==1)||($pubuserrole>=2)) { ?>
     <!--
	 <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 MRO</button>&nbsp;<br>
     -->
	<? } ?>
  <? } ?>
  <!--<button name="print" id="print" onClick="itq_button_printeval('<?=$itq_data['itq_pkey'];?>');" style="width: 130px; text-align: left;">&nbsp;&nbsp;<img src='gfx/options/b_print1.png' class='actionbutton'>&nbsp;&nbsp;Print</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 MRO</button>&nbsp;<br>
   
  <button name="back" id="back" onClick="javascript: cancelAction(); return false;" 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="mropkey" id="mropkey" 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="mro_approve">
  </table>

  </form>

  </div>


