  <br>

  <?
  if ($pubtask=="evaluate") {
    $inputstatus="";
    $approvaltype="0";
  } else if ($pubtask=="review") {
    $inputstatus="readonly";
    $approvaltype="2";
  } else if ($pubtask=="approve") {
    $inputstatus="readonly";
    $approvaltype="3";
  } else if ($pubtask=="view") {
    $inputstatus="readonly";
    $buttonstatus="disabled";
  }
  ?>

  <? $total[0]=0; ?>
  <? $total[1]=0; ?>
  <? $total[2]=0; ?>
  <? $total[3]=0; ?>
  <? $total[4]=0; ?>
  <? $total[5]=0; ?>
  <? $total[6]=0; ?>
  <? $total[7]=0; ?>
  <? $total[8]=0; ?>
  <? $total[9]=0; ?>
  <? $total[10]=0; ?>

  <table border=1 cellspacing=1 cellpadding=2 width=1370 style="border: 1px inset;">
  <form action="controllers/inputController.php" method="post" name="itqform" id="itqform">
  <input name="eval_itqpkey" id="eval_itqpkey" type="hidden" value="<?=$itq_data['itq_pkey'];?>">
  <input name="eval_mropkey" id="eval_mropkey" type="hidden" value="<?=$pubitemid;?>">
  <input name="eval_itempkeys" id="eval_itempkeys" type="hidden" value="">
  <input name="eval_supplierpkeys" id="eval_supplierpkeys" type="hidden" value="">
  <input name="eval_zikayrates" id="eval_zikayrates" type="hidden" value="">
  <input name="eval_supplierrates" id="eval_supplierrates" type="hidden" value="">
  <input name="eval_awardedquantities" id="eval_awardedquantities" type="hidden" value="">
  <input name="eval_transportrates" id="eval_transportrates" type="hidden" value="">
  <input name="eval_supplierremarks" id="eval_supplierremarks" type="hidden" value="">
  <input name="eval_approvaltype" id="eval_approvaltype" type="hidden" value="<?=$approvaltype;?>">
  <tr valign=top>
  <td valign=top width=1370 colspan=9 class=listcontent style="background: #f0f0f0;">
  <b>ZIKAY GROUP S/B</b>
  </td>
  </tr>
  <tr valign=top>
  <td valign=top width=40 class=listheader>Item</td>
  <td valign=top width=360 class=listheader>Description</td>
  <td valign=top width=100 class=listheader>Unit</td>
  <td valign=top width=120 class=listheader>Qty</td>
  <td valign=top width=150 class=listheader>Rate (RM)</td>
  <td valign=top width=150 class=listheader>Amount (RM)</td>
  <td valign=top width=450 class=listheader>REMARK</td>
  </tr>

  <? $icount=0; ?>

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

    <? $icount++; ?>

    <?
    if ($myitem['item_rate']=="0.00") {
      $mbl_subitem = $mymblModel->getdata_itqitembysubtrade($pubprojectpkey, $myitem['item_subtradepkey']);
      $mbl_subsubitem = $mymblModel->getdata_itqitembysubsubtrade($pubprojectpkey, $myitem['item_subsubtradepkey']);
      if ($mbl_subsubitem['item_pkey']!="") {
        $myitem['item_rate']=$mbl_subsubitem['item_rate'];
      } else {
        if ($mbl_subitem['item_pkey']!="") {
          $myitem['item_rate']=$mbl_subitem['item_rate'];
        }
      }
    }
    ?>

    <tr valign=top>
    <td valign=top width=40 class=listnumber style="background: #f0f0f0;"><?=$myitem['item_no'];?><?//=$icount;?></td>
    <td valign=top width=360 class=listcontent style="background: #f0f0f0;"><?=unescape($myitem['item_description']);?></td>
    <td valign=top width=100 class=listcontent style="background: #f0f0f0;"><?=$myitem['item_unit'];?></td>
    <td valign=top width=120 class=listcontentnumeric style="background: #f0f0f0;"><?=number_format($myitem['item_quantity'],4);?>
    <input name="quantity-<?=$icount;?>" id="quantity-<?=$icount;?>" type="hidden" value="<?=$myitem['item_quantity'];?>">
    <input name="itempkey-<?=$icount;?>" id="itempkey-<?=$icount;?>" type="hidden" value="<?=$myitem['item_pkey'];?>">
    </td>

    <td valign=top width=150 class=listcontentnumeric style="background: #f0f0f0;">
   
   <!--
   <input name="zikayrate-<?=$icount;?>" id="zikayrate-<?=$icount;?>" value="<?=number_format($myitem['item_rate'],2);?>" <?=$inputstatus;?> style="width: 140px; text-align: right;" onChange="calcZikaySubtotal('<?=$icount;?>');" onKeypress="decimalOnly();">
   -->
   <!-- zikay rate -->
    <input name="zikayrate-<?=$icount;?>" id="zikayrate-<?=$icount;?>" value="<? echo $myitem['item_rate'];?>" <?=$inputstatus;?> style="width: 140px; text-align: right;" onChange="calcZikaySubtotal('<?=$icount;?>');" onKeypress="decimalOnly();">
   
   </td>
    <td valign=top width=150 class=listcontentnumeric style="background: #f0f0f0;">
    <? $total[0]=$total[0]+($myitem['item_rate']*$myitem['item_quantity']); ?>
    <span id="zikaysubtotal-<?=$icount;?>"><?=number_format(($myitem['item_rate']*$myitem['item_quantity']),2);?></span>
    </td>

	<!--
    <td valign=top width=150 class=listcontent>hjhj</td>
    <td valign=top width=150 class=listcontent></td>
    <td valign=top width=150 class=listcontent></td>
    </tr>
     -->
	  <? if ($icount==1) { ?>
        <? if ($supplier_data['itq_remarks']=="") { ?>
          <? $myremarks = "TERMS: ".$mysupplier['supplier_ct']; ?>
        <? } else { ?>
          <? $myremarks = $supplier_data['itq_remarks']; ?>
        <? } ?>
        <td valign=top width=150 rowspan=<?=$icount;?> class=listcontent>
        <textarea name="remarks-<?=$scount;?>" id="remarks-<?=$scount;?>" rows=4 <?=$inputstatus;?> style="width: 140px;"><?=$myremarks;?></textarea>
        </td>
      <? } ?>

      </tr>
  <? } ?>

  <!-- tambah komen di zikay-->
 
  
  
  
  <tr valign=top>
  <td valign=top width=770 colspan=5 class=listcontent style="text-align: right; background: #f0f0f0;"><b>Total</b>&nbsp;&nbsp;&nbsp;&nbsp;</td>
  <td valign=top width=150 class=listcontentnumeric style="background: #f0f0f0;">
  <span id="zikaytotalspan"><?echo $total[0] ;?>mmm</span>
  <input name="zikaytotal" id="zikaytotal" type="hidden" value="<? echo $total[0];?>">
  </td>
  <td valign=top width=450 colspan=3 class=listcontent></td>
  </tr>

  <? $maxitems=$icount; ?>
  <? $scount=0; ?>

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

    <?
    $scount++;
    $mysupplier = $mysupplierModel->getdata_supplier($supplier_data['itq_supplierpkey']);
    ?>

    <tr valign=top>
    <td valign=top width=1370 colspan=9 class=listcontent style="border: 0px;">
    <!--hr size=1--><img src="pixel.gif" style="height: 15px;">
    </td>
    </tr>

    <tr valign=top>
    <td valign=top width=1370 colspan=9 class=listcontent>
    <input name="supplier-<?=$scount;?>" id="supplier-<?=$scount;?>" type="hidden" value="<?=$supplier_data['itq_supplierpkey'];?>">
    <b><?=$mysupplier['supplier_name'];?></b>
    </td>
    </tr>
    <tr valign=top>
    <td valign=top width=40 class=listheader>Item</td>
    <td valign=top width=360 class=listheader>Description</td>
    <td valign=top width=100 class=listheader>Unit</td>
    <td valign=top width=120 class=listheader>Qty</td>
    <td valign=top width=150 class=listheader>Rate (RM)</td>
    <td valign=top width=150 class=listheader>Awarded Qty</td>
    <td valign=top width=150 class=listheader>Amount (RM)</td>
    <td valign=top width=150 class=listheader>Transport</td>
    <td valign=top width=150 class=listheader>Remarks</td>
    </tr>

    <? $icount=0; ?>

    <? reset($mroitem_list); ?>
    <? foreach($mroitem_list as $myitem) { ?>

      <? $icount++; ?>

      <? //$itqitem_list = $myitqModel->getlist_itqevaluationbyitem($myitem['item_mropkey'], $myitem['item_pkey']); ?>
      <? $itqitem_data = $myitqModel->getdata_itqevaluationbysupplier($myitem['item_mropkey'], $myitem['item_pkey'], $supplier_data['itq_supplierpkey']); ?>
      <? $myapproval = $myitqModel->getdata_lastapprovalbysupplier($itq_data['itq_pkey'],$myitem['item_pkey'], $supplier_data['itq_supplierpkey']); ?>

      <? if ($myapproval['approval_quantity']=="") $myapproval['approval_quantity']="0"; ?>

      <? //$mysubtotal=($myitem['item_quantity']*$itqitem_data['eval_supplierrate']); ?>
      <? $mysubtotal=($myapproval['approval_quantity']*$itqitem_data['eval_supplierrate']); ?>
      <? $total[$scount]=$total[$scount]+$mysubtotal; ?>

      <tr valign=top>
      <td valign=top width=40 class=listnumber><?=$myitem['item_no'];?><?//=$icount;?></td>
      <td valign=top width=360 class=listcontent><?=unescape($myitem['item_description']);?></td>
      <td valign=top width=100 class=listcontent><?=$myitem['item_unit'];?></td>
      <td valign=top width=120 class=listcontentnumeric><?=number_format($myitem['item_quantity'],4);?>
      </td>

      <td valign=top width=150 class=listcontentnumeric>
      <input name="rate-<?=$icount;?>-<?=$scount;?>" id="rate-<?=$icount;?>-<?=$scount;?>" value="<?=number_format($itqitem_data['eval_supplierrate'],2);?>" <?=$inputstatus;?> style="width: 140px; text-align: right;" onChange="calcSubtotal('<?=$icount;?>','<?=$scount;?>');" onKeypress="decimalOnly();">
      </td>
      <td valign=top width=150 class=listcontentnumeric>
      
	  <!-- awarded-->
	  <input name="awarded-<?=$icount;?>-<?=$scount;?>" id="awarded-<?=$icount;?>-<?=$scount;?>" value="<?=number_format($myapproval['approval_quantity'],4);?>" <?=$inputstatus;?> style="width: 140px; text-align: right;" onChange="calcSubtotal('<?=$icount;?>','<?=$scount;?>');" onKeypress="decimalOnly();">
      </td>
      <td valign=top width=150 class=listcontentnumeric>
      <span id="subtotal-<?=$icount;?>-<?=$scount;?>"><?=number_format($mysubtotal,2);?></span>
      </td>

      <? if ($icount==1) { ?>
        <td valign=top width=150 rowspan=<?=$maxitems+1;?> class=listcontentnumeric>
        <input name="transport-<?=$scount;?>" id="transport-<?=$scount;?>" value="<?=number_format($supplier_data['itq_transportrate'],2);?>" <?=$inputstatus;?> style="width: 140px; text-align: right;" onKeypress="decimalOnly();">
        </td>
      <? } ?>

      <? if ($icount==1) { ?>
        <? if ($supplier_data['itq_remarks']=="") { ?>
          <? $myremarks = "TERMS: ".$mysupplier['supplier_ct']; ?>
        <? } else { ?>
          <? $myremarks = $supplier_data['itq_remarks']; ?>
        <? } ?>
        <td valign=top width=150 rowspan=<?=$maxitems+1;?> class=listcontent>
        <textarea name="remarks-<?=$scount;?>" id="remarks-<?=$scount;?>" rows=4 <?=$inputstatus;?> style="width: 140px;"><?=$myremarks;?></textarea>
        </td>
      <? } ?>

      </tr>

    <? } ?>

    <tr valign=top>
    <td valign=top width=920 colspan=6 class=listcontent style="text-align: right;"><b>Total</b>&nbsp;&nbsp;&nbsp;&nbsp;</td>
    <td valign=top width=150 class=listcontentnumeric>
    <span id="total-<?=$scount;?>"><?=number_format($total[$scount],2);?></span>
    </td>
    </tr>

  <? } ?>
  
  <input name="job" id="job" type="hidden" value="">
  </form>
  </table>

  <!--button onClick="submitForm();">Test</button-->

  <script type="text/javascript">

  function TS(v) {
    var val = v.toString();
    var result = "";
    var len = val.length;
    var dec = val.substr(len-3);
    val = val.substr(0,len-3);
    len -=3;
    while (len > 3){
      result = ","+val.substr(len-3,3)+result;
      len -=3;
    }
    return val.substr(0,len)+result+dec;
  }

  function calcZikaySubtotal(icount) {
    var objquantity = document.getElementById('quantity-'+icount);
    var objrate = document.getElementById('zikayrate-'+icount);
    var myquantity = objquantity.value
    var myrate = objrate.value
    myquantity = myquantity.replace(/,/g,"");
    myrate = myrate.replace(/,/g,"");
    myquantity = parseFloat(myquantity)
    myrate = parseFloat(myrate)
    var mysubtotal = myquantity * myrate;
    mysubtotal = mysubtotal.toFixed(2);
    var mysubfield = document.getElementById('zikaysubtotal-'+icount);
    if (mysubfield!=null) {
      mysubfield.innerHTML=TS(mysubtotal);
    }
    calcZikayTotal();
  }

  function calcZikayTotal() {
    var total=0;
    for (i=1;i<=100;i++) {
      var objsubtotal = document.getElementById('zikaysubtotal-'+i);
      if (objsubtotal!=null) {
        var valsubtotal = objsubtotal.innerHTML;
        valsubtotal = valsubtotal.replace(/,/g,"");
        var subtotal = parseFloat(valsubtotal);
        total = total + subtotal;
      }
    }
    total = total.toFixed(2);
    var objtotalfield1 = document.getElementById('zikaytotalspan');
    var objtotalfield2 = document.getElementById('zikaytotal');
    if (objtotalfield1!=null) {
      objtotalfield1.innerHTML=TS(total);
    }
    if (objtotalfield2!=null) {
      objtotalfield2.value=TS(total);
    }
  }

  function calcSubtotal(icount,suppcount) {
    var objquantity = document.getElementById('quantity-'+icount);
    var objrate = document.getElementById('rate-'+icount+'-'+suppcount);
    var objawarded = document.getElementById('awarded-'+icount+'-'+suppcount);
    var myquantity = objquantity.value
    var myrate = objrate.value
    var myawarded = objawarded.value
    myquantity = myquantity.replace(/,/g,"");
    myrate = myrate.replace(/,/g,"");
    myawarded = myawarded.replace(/,/g,"");
    myquantity = parseFloat(myquantity)
    myrate = parseFloat(myrate)
    myawarded = parseFloat(myawarded)
    //var mysubtotal = myquantity * myrate;
    var mysubtotal = myawarded * myrate;
    mysubtotal = mysubtotal.toFixed(2);
    var mysubfield = document.getElementById('subtotal-'+icount+'-'+suppcount);
    if (mysubfield!=null) {
      mysubfield.innerHTML=TS(mysubtotal);
    }
    calcTotal(suppcount);
  }

  function calcTotal(suppcount) {
    var total=0;
    var profit=0;
    var diff=0;
    var objzikaytotal = document.getElementById('zikaytotal');
    var valzikaytotal = objzikaytotal.value;
    valzikaytotal = valzikaytotal.replace(/,/g,"");
    valzikaytotal = parseFloat(valzikaytotal);
    //var valzikaytotal = parseFloat(objzikaytotal.value);
    for (i=1;i<=100;i++) {
      var objsubtotal = document.getElementById('subtotal-'+i+'-'+suppcount);
      if (objsubtotal!=null) {
        var valsubtotal = objsubtotal.innerHTML;
        valsubtotal = valsubtotal.replace(/,/g,"");
        var subtotal = parseFloat(valsubtotal);
        total = total + subtotal;
      }
    }
    /*
    profit = valzikaytotal - total;
    if (valzikaytotal>0) {
      diff = (profit/valzikaytotal)*100;
    } else {
      diff = -100;
    }
    */
    total = total.toFixed(2);
    //profit = profit.toFixed(2);
    //diff = diff.toFixed(2);
    var objtotalfield = document.getElementById('total-'+suppcount);
    if (objtotalfield!=null) {
      objtotalfield.innerHTML=TS(total);
    }
    /*
    var objprofitfield = document.getElementById('profit-'+suppcount);
    if (objprofitfield!=null) {
      objprofitfield.innerHTML=TS(profit);
    }
    var objdifffield = document.getElementById('diff-'+suppcount);
    if (objdifffield!=null) {
      objdifffield.innerHTML=TS(diff)+'%';
    }
    */
  }

  function validateForm() {
    var awardfound=false;
    var awardvalue="";
    for (i=1;i<=100;i++) {
      for (j=1;j<=5;j++) {
        var objawarded = document.getElementById('awarded-'+i+'-'+j);
        if (objawarded!=null) {
          awardvalue = objawarded.value;
          awardvalue = awardvalue.replace(/,/g,"");
          awardvalue = parseFloat(awardvalue);
          if (awardvalue>0) {
            awardfound=true;
            return true;
          }
        }
      }
    }
    return awardfound;
  }

  function submitForm() {
    var supplier="";
    var itempkey="";
    var rate="";
    var awarded="";
    var remark="";
    var zikay="";
    var transport="";
    var objitempkeys = document.getElementById('eval_itempkeys');
    var objsupplierpkeys = document.getElementById('eval_supplierpkeys');
    var objsupplierrates = document.getElementById('eval_supplierrates');
    var objawardedquantities = document.getElementById('eval_awardedquantities');
    var objsupplierremarks = document.getElementById('eval_supplierremarks');
    var objzikayrates = document.getElementById('eval_zikayrates');
    var objtransportrates = document.getElementById('eval_transportrates');
    for (i=1;i<=5;i++) {
      var objsupp = document.getElementById('supplier-'+i);
      if (objsupp!=null) {
        supplier = supplier+";"+objsupp.value;
      }
    }
    objsupplierpkeys.value = supplier.substr(1);
    for (i=1;i<=100;i++) {
      var objitem = document.getElementById('itempkey-'+i);
      if (objitem!=null) {
        itempkey = itempkey+";"+objitem.value;
      }
    }
    objitempkeys.value = itempkey.substr(1);
    for (i=1;i<=100;i++) {
      for (j=1;j<=5;j++) {
        var objrate = document.getElementById('rate-'+i+'-'+j);
        if (objrate!=null) {
          rate = rate+";"+objrate.value;
        }
      }
    }
    objsupplierrates.value = rate.substr(1);
    for (i=1;i<=100;i++) {
      for (j=1;j<=5;j++) {
        var objawarded = document.getElementById('awarded-'+i+'-'+j);
        if (objawarded!=null) {
          awarded = awarded+";"+objawarded.value;
        }
      }
    }
    objawardedquantities.value = awarded.substr(1);
    for (i=1;i<=5;i++) {
      var objremark = document.getElementById('remarks-'+i);
      if (objremark!=null) {
        remark = remark+"|"+objremark.value;
      }
    }
    objsupplierremarks.value = remark.substr(1);
    for (i=1;i<=100;i++) {
      var objzikay = document.getElementById('zikayrate-'+i);
      if (objzikay!=null) {
        zikay = zikay+";"+objzikay.value;
      }
    }
    objzikayrates.value = zikay.substr(1);
    for (i=1;i<=5;i++) {
      var objtransport = document.getElementById('transport-'+i);
      if (objtransport!=null) {
        transport = transport+";"+objtransport.value;
      }
    }
    objtransportrates.value = transport.substr(1);
    return true;
  }

  </script>
