<link rel="stylesheet" type="text/css" href="css/professional/table_frize.css">
<?php
   $PageName = 'MaterialReceiptNote';
   $url_cancel = "index.php?route=Inventory/transation/material_receipt_note_index" . $rurl;
   $url_add = "index.php?route=Inventory/transation/material_receipt_note_add" . $rurl;
   //************INSERT RECORD HERE******START HERE**********14-06-2013***********AS**********************************
   
   //************INSERT RECORD HERE******END HERE**********14-06-2013***********AS**********************************
   
   $mrn_query = "select * from addmrn where id='" . $_REQUEST['mrnid'] . "'";
   $mrn_query_res = DB_query($mrn_query, $db) or die(DB_error());
   $mrn_query_result = DB_fetch_assoc($mrn_query_res);
   ?>
<!-------------------------------------------JS PART START HERE--------------AS---------14-06-2013---------------->
<div id="PickedItems" style="display:none"></div>
<script type="text/javascript">
   //$.noConflict();
   $(document).ready(function() {
       //var cnt=document.getElementById("count").value;
       $('input[name=profile_popup]').click(function() {
           var tt = this.id;
           var tt1 = tt.split("_");
           var tt2 = tt1[1];
           var site = document.getElementById("sitecode").value;
   
           //var LeaveType=document.getElementById("LeaveType_"+tt2).value;
           $("#PickedItems").dialog({
               title: 'Item List',
               modal: true,
               resizable: false,
               width: 900,
               height: 400,
               closeText: 'fechar',
               draggable: true,
               show: 'fade',
               hide: 'fade',
               dialogClass: 'main-dialog-class',
               buttons: {
                   Exit: function() {
                       $(this).dialog("close");
                   }
               }
   
           });
           GetitemListForDirectPO(site);
       });
   });
   
   function GetitemListForDirectPO(str) {
       if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari
           xmlhttp = new XMLHttpRequest();
       } else { // code for IE6, IE5
           xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
       }
       xmlhttp.onreadystatechange = function() {
           if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
               document.getElementById("PickedItems").innerHTML = xmlhttp.responseText;
           }
       }
       xmlhttp.open("GET", "direct_po_items1.php?site=" + str, true);
       xmlhttp.send();
   }
   
   function getItemsList(id, code, shade, desc, unit, netrate, mrprate, stock, ctr, rate) {
   
       var dup = 'empty';
       var itemcount = parseInt(document.getElementById('hiditemcount').value) + 1;
       var edit_cnt = document.getElementById('edit_cnt').value;
       if (edit_cnt == '') {
           var counter = 1;
       } else if (edit_cnt > itemcount) {
           var counter = edit_cnt;
           var itemcount = parseFloat(counter) + parseFloat(itemcount);
       } else {
           var counter = edit_cnt;
       }
   
       if (document.getElementById("row_id_" + ctr).checked == true) {
   
           for (var i = counter; i < itemcount; i++) {
   
               for (var j = 0; j < itemcount; j++) {
                   if (document.getElementById('itemid_' + j)) {
                       if (document.getElementById('itemid_' + j).value == id) {
                           alert("Duplicate Value");
                           document.getElementById("row_id_" + ctr).checked = false;
                           var dup = "dup";
                           break;
                       }
                   }
               }
               if (dup == 'empty') {
                   var data = addRow_mrn('dataTable');
   
                   if (document.getElementById('itemid_' + i)) {
                       if (document.getElementById('itemid_' + i).value == '') {
                           document.getElementById('itemid_' + i).value = id;
                           document.getElementById('itemcode_' + i).value = code;
                           document.getElementById('itemname_' + i).value = shade;
                           document.getElementById('total_stock_' + i).value = stock;
                           document.getElementById('itemdesc_' + i).value = desc;
                           document.getElementById('price_' + i).value = netrate;
                           document.getElementById('mrpper_' + i).value = mrprate;
   
                           break;
                       }
                   } else {
                       continue;
                   }
               }
           }
   
       } else {
           for (var i = counter; i < itemcount; i++) {
               if (document.getElementById('itemid_' + i)) {
                   if (document.getElementById('itemid_' + i).value == document.getElementById("row_id_" + ctr).value) {
                       document.getElementById('itemid_' + i).value = '';
                       document.getElementById('itemcode_' + i).value = '';
                       document.getElementById('itemname_' + i).value = '';
                       document.getElementById('total_stock_' + i).value = '';
                       document.getElementById('itemdesc_' + i).value = '';
                       document.getElementById('price_' + i).value = '';
                       document.getElementById('mrpper_' + i).value = '';
                   }
               }
           }
       }
   }
   
   
   function calculateTaxable(i1) {
       var id = i1.split("_");
       var i = id[2];
   
       var exciseValue = document.getElementById("exciseValue_" + i).value;
       var ECessValue = document.getElementById("ECessValue_" + i).value;
       var SAHCessValue = document.getElementById("SAHCessValue_" + i).value;
       if (exciseValue == '') {
           exciseValue = 0;
       }
       if (ECessValue == '') {
           ECessValue = 0;
       }
       if (SAHCessValue == '') {
           SAHCessValue = 0;
       }
       var TOTAL = parseFloat(exciseValue) + parseFloat(ECessValue) + parseFloat(SAHCessValue);
       document.getElementById("taxable_amt_" + i).value = TOTAL.toFixed(2);
   } <
   !-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --INPORT ORDER CALCULATION PART-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- >
   
   function GetStore(str) {
       if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari
           xmlhttp = new XMLHttpRequest();
       } else { // code for IE6, IE5
           xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
       }
       xmlhttp.onreadystatechange = function() {
           if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
               document.getElementById("storecode").innerHTML = xmlhttp.responseText;
           }
       }
       xmlhttp.open("GET", "ajax_getstore.php?branchcode=" + str, true);
       xmlhttp.send();
   }
   
   
   function ChkGRNType(str) {
       if (str == 'Indent') {
           //$(".sh").hide();
           document.getElementById("poname").innerHTML = "";
           document.getElementById("inprno").innerHTML = "";
           return;
       } else {
           //$(".sh").show();
       }
       if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari
           xmlhttp = new XMLHttpRequest();
       } else { // code for IE6, IE5
           xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
       }
       xmlhttp.onreadystatechange = function() {
           if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
               var data = xmlhttp.responseText.split("__");
               document.getElementById("GtT1").innerHTML = data[0];
               document.getElementById("GtT2").innerHTML = data[1];
               document.getElementById("GtT3").innerHTML = data[2];
               document.getElementById("GtT4").innerHTML = data[3];
               document.getElementById("GtT5").innerHTML = data[4];
               document.getElementById("GtT6").innerHTML = data[5];
           }
       }
       xmlhttp.open("GET", "ajax_get_chechgrntype.php?GRNTYPE=" + str, true);
       xmlhttp.send();
   }
   
   
   function GetIndentPONo(str) {
       if (str.length == 0) {
           document.getElementById("poname").innerHTML = "";
           document.getElementById("inprno").innerHTML = "";
           return;
       }
       if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari
           xmlhttp = new XMLHttpRequest();
       } else { // code for IE6, IE5
           xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
       }
       xmlhttp.onreadystatechange = function() {
           if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
               var data = xmlhttp.responseText.split("__");
               document.getElementById("poname").innerHTML = data[0];
               document.getElementById("inprno").innerHTML = data[1];
           }
       }
       var site = document.getElementById("sitecode").value;
       var receag = document.getElementById("receiviedagaist").value;
       var purtype = document.getElementById("PoType").value;
       xmlhttp.open("GET", "ajax_get_indent_po_no.php?supplierId=" + str + "&ReciveAng=" + receag + "&POType=" + purtype + "&Branch=" + site, true);
       xmlhttp.send();
   }
   
   
   function GetPODetails(str) {
       if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari
           xmlhttp = new XMLHttpRequest();
       } else { // code for IE6, IE5
           xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
       }
       xmlhttp.onreadystatechange = function() {
           if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
               var data = xmlhttp.responseText.split("__");
               document.getElementById("alldatadetails").innerHTML = data[0];
               document.getElementById("basicamtdetails").innerHTML = data[1];
           }
       }
       var purtype = document.getElementById("PoType").value;
       xmlhttp.open("GET", "ajax_getpodetails.php?POID=" + str + "&POType=" + purtype, true);
       xmlhttp.send();
   }
   
   
   
   
   function check_bill_qty(str, id) {
       var iddata = id1.split("_");
       var id = idata[1];
       var poqty = parseInt(document.getElementById("pending_qty_" + id).value);
       var tolerance = document.getElementById("tolerance_" + id).value;
       if (tolerance == '') {
           tolerance = 0;
       }
       str1 = parseInt(str);
       if (poqty != '') {
           var qty = (poqty * tolerance) / 100;
           var poqty1 = parseInt(poqty) + parseInt(qty);
           //var poqty2=poqty-qty;	
           if (str1 > poqty1) {
               var altmsg = "Quantity As Per Bill Cannot Be Greater Than " + tolerance + " % more of PO Quantity";
               alert(altmsg);
               document.getElementById("qtyasper_bill_" + id).value = '';
               document.getElementById("qty_received_" + id).value = '';
               document.getElementById("qtyasper_bill_" + id).focus();
               return false;
           }
       }
   }
   
   
   
   function check_po_qty1(k) {
       var k1 = k.split("_");
       var i = k[1];
       var poqty = parseInt(document.getElementById("pending_qty_" + i).value);
       var str = parseInt(document.getElementById("qty_received_" + i).value);
       var tolerance = document.getElementById("tolerance_" + i).value;
       if (tolerance == '') {
           tolerance = 0;
       }
       str1 = parseInt(str);
       if (poqty != '') {
           var qty = (poqty * tolerance) / 100;
           var poqty1 = parseInt(poqty) + parseInt(qty);
           //var poqty2=poqty-qty;	
           if (str1 > poqty1) {
               var altmsg = "QTY Received Cannot Be Greater Than " + tolerance + " % more of PO Quantity";
               alert(altmsg);
               document.getElementById("qty_received_" + i).value = '';
               document.getElementById("qty_received_" + i).focus();
               return false;
           }
       }
   }
   
   
   function calculate_poshort(id1) {
       var i = id1.split("_");
       var id = i[2];
   
       var qty_per_bill = parseInt(document.getElementById("qtyasper_bill_" + id).value);
       var reciveqty = parseInt(document.getElementById("qty_received_" + id).value);
       if (document.getElementById("qty_received_" + id).value == '') {
           var reciveqty = 0;
       } else {
           var reciveqty = parseInt(document.getElementById("qty_received_" + id).value);
       }
       var short_accessid = qty_per_bill - reciveqty;
       if (short_accessid < 0) {
           short_accessid = 0;
       }
       document.getElementById("short_qty_" + id).value = short_accessid;
   }
   
   
   function calc_total_price(str1) {
       var id = str1.split("_");
       var str = id[1];
       var item_total_rate = 0;
       var reciveqty = document.getElementById("qty_received_" + str).value;
       var itemrate = document.getElementById("Rate_" + str).value;
   
       if (reciveqty != '' && itemrate != '') {
           document.getElementById("totalValue_" + str).value = (parseFloat(reciveqty) * parseFloat(itemrate)).toFixed(2);
       }
   }
   
   function DiscountAmount(DA, i1) {
       var str = i1.split("_");
       var i = str[1];
       var discount_percent = document.getElementById("PerAmo_" + i).value;
       var rate = document.getElementById("Rate_" + i).value;
       var discount = document.getElementById("Discount_" + i).value;
       var quantity = document.getElementById("qty_received_" + i).value;
       var totalPrice = parseFloat(quantity) * parseFloat(rate);
       if (discount_percent == 'PercentAmt') {
           if (discount == '') {
               discount = 0;
           }
           var percent = parseFloat(totalPrice) * parseFloat(discount) / 100;
           var subTotal = parseFloat(totalPrice) - parseFloat(percent);
       } else if (discount_percent == 'Amount') {
           var percent = parseFloat(document.getElementById("Discount_" + i).value);
           if (isNaN(percent)) {
               percent = 0;
           }
           var subTotal = totalPrice - parseFloat(percent);
       }
       document.getElementById("perc_" + i).value = percent.toFixed(2);
       document.getElementById("NetRate_" + i).value = subTotal.toFixed(2);
       //document.getElementById("basic_"+i).value=subTotal.toFixed(2);
   }
   
   
   
   
   function CustomDutyType(val, i) {
       if (document.getElementById("cuntomDuty_Flag_" + i).value == '2') {
           document.getElementById("Custon_Duty_" + i).value = '';
           document.getElementById("CustomDutyAmt_" + i).value = '';
           document.getElementById("Custon_Duty_" + i).disabled = true;
           document.getElementById("CustomDutyAmt_" + i).disabled = true;
       } else {
           document.getElementById("Custon_Duty_" + i).value = document.getElementById("custonduty1_" + i).value;
           document.getElementById("CustomDutyAmt_" + i).value = document.getElementById("custondutyamt1_" + i).value;
           document.getElementById("Custon_Duty_" + i).disabled = false;
           document.getElementById("CustomDutyAmt_" + i).disabled = false;
       }
   }
   
   
   
   
   function cal_grandtotalImp(i1) {
       var id = i1.split("_");
       var i = id[2]
   
       //var type_of_bill=document.getElementById("cuntomDuty_Flag_"+i).value;
       var basic = document.getElementById("basic_" + i).value;
       var Totaltaxable = document.getElementById("CustomDutyAmt_" + i).value;
       var Totaltaxable1 = document.getElementById("TotalSpecial_" + i).value;
       var Totaltaxable2 = document.getElementById("customecess_" + i).value;
       var Totaltaxable3 = document.getElementById("customsececess_" + i).value;
       var Totaltaxable4 = document.getElementById("adduty_" + i).value;
   
       if (basic == '') {
           basic = 0;
       }
       if (Totaltaxable1 == '') {
           Totaltaxable1 = 0;
       }
       if (Totaltaxable2 == '') {
           Totaltaxable2 = 0;
       }
       if (Totaltaxable3 == '') {
           Totaltaxable3 = 0;
       }
       if (Totaltaxable4 == '') {
           Totaltaxable4 = 0;
       }
       if (Totaltaxable == '') {
           Totaltaxable = 0;
       }
   
       var grand_tot1 = parseFloat(basic) + parseFloat(Totaltaxable) + parseFloat(Totaltaxable1) + parseFloat(Totaltaxable2) +
           parseFloat(Totaltaxable3) + parseFloat(Totaltaxable4);
       var grand_tot = grand_tot1.toFixed(2);
   
   
       document.getElementById("TotalSpecial_amt_" + i).value = grand_tot;
   }
   
   
   function cal_totalamount_count() {
       var total = 0;
       var t = document.getElementById("conterimp").value;
   
       for (var i = 0; i < t; i++) {
           if (document.getElementById("TotalSpecial_amt_" + i))
               var amt = parseFloat(document.getElementById("TotalSpecial_amt_" + i).value);
           else
               var amt = 0;
   
           total = parseFloat(total) + amt;
       }
       var fintotal = parseFloat(total);
       document.getElementById("total_item_amount").value = fintotal.toFixed(2);
   
   
       var hdcnt = document.getElementById("conterimp").value;
       var flag1 = 0;
       if (hdcnt != '') {
           for (var j = 0; j < hdcnt; j++) {
               if (document.getElementById("cuntomDuty_Flag_" + j)) {
                   if (document.getElementById("cuntomDuty_Flag_" + j).value == 1) {
                       flag1 = 1;
                   }
               }
           }
       }
       if (flag1 == 1) {
           document.getElementById("CustomDuty").disabled = true;
       } else {
           document.getElementById("CustomDuty").disabled = false;
       }
   
   }
   
   
   
   
   function cal_totalamount_consoliedate() {
       var total = 0;
       var t = document.getElementById("conterimp").value;
   
       for (var i = 0; i < t; i++) {
           if (document.getElementById("basic_" + i))
               var amt = parseFloat(document.getElementById("basic_" + i).value);
           else
               var amt = 0;
   
           total = parseFloat(total) + amt;
       }
       var fintotal = parseFloat(total);
       document.getElementById("total_item_amount").value = fintotal.toFixed(2);
   
   
       var hdcnt = document.getElementById("conterimp").value;
       var flag1 = 0;
       if (hdcnt != '') {
           for (var j = 0; j < hdcnt; j++) {
               if (document.getElementById("cuntomDuty_Flag_" + j)) {
                   if (document.getElementById("cuntomDuty_Flag_" + j).value == 1) {
                       flag1 = 1;
                   }
               }
           }
       }
       if (flag1 == 1) {
           document.getElementById("CustomDuty").disabled = true;
       } else {
           document.getElementById("CustomDuty").disabled = false;
       }
   
   }
   
   function cal_totalamount() {
   
       if (document.getElementById("PoType").value == 'DO' && document.getElementById("dutytype").value == 'Itemwise') {
           var total = 0;
           var t = document.getElementById("conterimp").value;
   
           for (var i = 0; i < t; i++) {
               if (document.getElementById("basic_" + i))
                   var amt = parseFloat(document.getElementById("basic_" + i).value);
               else
                   var amt = 0;
   
               total = parseFloat(total) + amt;
           }
           var fintotal = parseFloat(total);
           document.getElementById("total_item_amount").value = fintotal.toFixed(2);
   
   
           var hdcnt = document.getElementById("conterimp").value;
           var flag1 = 0;
           if (hdcnt != '') {
               for (var j = 0; j < hdcnt; j++) {
                   if (document.getElementById("cuntomDuty_Flag_" + j)) {
                       if (document.getElementById("cuntomDuty_Flag_" + j).value == 1) {
                           flag1 = 1;
                       }
                   }
               }
           }
           if (flag1 == 1) {
               document.getElementById("CustomDuty").disabled = true;
           } else {
               document.getElementById("CustomDuty").disabled = false;
           }
   
   
       } else {
   
           var total = 0;
           var t = document.getElementById("conterimp").value;
   
           for (var i = 0; i < t; i++) {
               if (document.getElementById("TotalSpecial_" + i))
                   var amt = parseFloat(document.getElementById("TotalSpecial_" + i).value);
               else
                   var amt = 0;
   
               total = parseFloat(total) + amt;
           }
           var fintotal = parseFloat(total);
           document.getElementById("total_item_amount").value = fintotal.toFixed(2);
   
   
           var hdcnt = document.getElementById("conterimp").value;
           var flag1 = 0;
           if (hdcnt != '') {
               for (var j = 0; j < hdcnt; j++) {
                   if (document.getElementById("cuntomDuty_Flag_" + j)) {
                       if (document.getElementById("cuntomDuty_Flag_" + j).value == 1) {
                           flag1 = 1;
                       }
                   }
               }
           }
           if (flag1 == 1) {
               document.getElementById("CustomDuty").disabled = true;
           } else {
               document.getElementById("CustomDuty").disabled = false;
           }
   
   
       }
   
   }
   
   
   function CalculateCustomDuty(id, val) {
   
       if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari
           xmlhttp = new XMLHttpRequest();
       } else { // code for IE6, IE5
           xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
       }
       xmlhttp.onreadystatechange = function() {
           if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
               var data = xmlhttp.responseText.split("__");
               var k = data[0];
               document.getElementById("CustomDutyAmt_" + k).value = data[1];
           }
       }
       var id1 = id.split("_");
       var i = id1[2];
       var basicamt = document.getElementById("basic_" + i).value;
       xmlhttp.open("GET", "ajax_get_cutom_duty.php?ids=" + id + "&vls=" + val + "&bamt=" + basicamt, true);
       xmlhttp.send();
   }
   
   
   function claculateExcisetotal(id, str) {
       var b = document.getElementById("total_item_amount").value;
   
       if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari
           xmlhttp = new XMLHttpRequest();
       } else { // code for IE6, IE5
           xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
       }
       xmlhttp.onreadystatechange = function() {
           if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
               var data = xmlhttp.responseText.split("__");
               document.getElementById("rateval").value = data[0];
               document.getElementById("custondutyval").value = data[1];
           }
       }
       xmlhttp.open("GET", "ajax_calculate_customduty.php?quotTaxId=" + str + "&data=" + b, true);
       xmlhttp.send();
   
   
   }
   
   
   function cal_totalamountwithduty() {
       var hdcnt = document.getElementById("conterimp").value;
       var chka = document.getElementById("CustomDuty").value;
       if (chka == 0) {
           var total = 0;
           for (var j = 0; j < hdcnt; j++) {
               if (document.getElementById("CustomDutyAmt_" + j).value != '') {
                   var amt = parseFloat(document.getElementById("CustomDutyAmt_" + j).value);
                   total = parseFloat(total) + amt;
               } else {
                   total = 0;
               }
           }
           total = total;
           document.getElementById("custondutyval").value = total.toFixed(2);
       } else {
           var basic = document.getElementById("total_item_amount").value;
           var rate = document.getElementById("rateval").value;
           if (basic == '') {
               basic = 0;
           }
           var calexc = (basic * rate) / 100;
           document.getElementById("custondutyval").value = calexc.toFixed(2);
   
       }
   }
   
   
   
   
   function calsuroctamtipm(str) {
       var amt = parseFloat(document.getElementById("total_item_amount").value);
       var amount = (amt * str) / 100;
       document.getElementById("insurancecharges_amt").value = amount.toFixed(2);
   }
   
   function reversecalsuroctamt(str) {
       var amt = parseFloat(document.getElementById("total_item_amount").value);
       var amount = (100 * str) / amt;
       document.getElementById("insurancecharges").value = amount.toFixed(2);
   }
   
   function caloverfreight(str) {
       var amt = parseFloat(document.getElementById("total_item_amount").value);
       var amount = (amt * str) / 100;
       document.getElementById("overseasfrieght_amt").value = amount.toFixed(2);
   }
   
   function reversecaloverfreight(str) {
       var amt = parseFloat(document.getElementById("total_item_amount").value);
       var amount = (100 * str) / amt;
       document.getElementById("overseasfrieght").value = amount.toFixed(2);
   }
   
   function callocalfreight(str) {
       var amt = parseFloat(document.getElementById("total_item_amount").value);
       var amount = (amt * str) / 100;
       document.getElementById("localfreight_amt").value = amount.toFixed(2);
   }
   
   function reversecallocalfreight(str) {
       var amt = parseFloat(document.getElementById("total_item_amount").value);
       var per = parseFloat(document.getElementById("localfreight").value);
       var amount = (100 * str) / amt;
       document.getElementById("localfreight").value = amount.toFixed(2);
   }
   
   
   function calclearingforwarding(str) {
       var amt = parseFloat(document.getElementById("total_item_amount").value);
       var amount = (amt * str) / 100;
       document.getElementById("calclearingforwarding_amt").value = amount.toFixed(2);
   }
   
   function reversecalclearingforwarding(str) {
       var amt = parseFloat(document.getElementById("total_item_amount").value);
       var per = parseFloat(document.getElementById("clearingforwarding").value);
       var amount = (100 * str) / amt;
       document.getElementById("clearingforwarding").value = amount.toFixed(2);
   }
   
   function caldetetioncharges(str) {
       var amt = parseFloat(document.getElementById("total_item_amount").value);
       var amount = (amt * str) / 100;
       document.getElementById("detetioncharges_amt").value = amount.toFixed(2);
   }
   
   function reversecaldetetioncharges(str) {
       var amt = parseFloat(document.getElementById("total_item_amount").value);
       var per = parseFloat(document.getElementById("detetioncharges").value);
       var amount = (100 * str) / amt;
       document.getElementById("detetioncharges").value = amount.toFixed(2);
   }
   
   
   
   
   function cal_grandamountimp() {
   
       var total = document.getElementById("total_item_amount").value;
       if (document.getElementById("custondutyval"))
           var cdis_amt = document.getElementById("custondutyval").value;
       else
           var cdis_amt = 0;
       var insurancecharges_amt = document.getElementById("insurancecharges_amt").value;
       var overseasfrieght_amt = document.getElementById("overseasfrieght_amt").value;
       var localfreight_amt = document.getElementById("localfreight_amt").value;
       var calclearingforwarding_amt = document.getElementById("calclearingforwarding_amt").value;
       var detetioncharges_amt = document.getElementById("detetioncharges_amt").value;
       var othercharges = document.getElementById("othercharges").value;
   
       if (total == '') {
           total = 0;
       }
       if (cdis_amt == '') {
           cdis_amt = 0;
       }
       if (insurancecharges_amt == '') {
           insurancecharges_amt = 0;
       }
       if (overseasfrieght_amt == '') {
           overseasfrieght_amt = 0;
       }
       if (localfreight_amt == '') {
           localfreight_amt = 0;
       }
       if (calclearingforwarding_amt == '') {
           calclearingforwarding_amt = 0;
       }
       if (detetioncharges_amt == '') {
           detetioncharges_amt = 0;
       }
       if (othercharges == '') {
           othercharges = 0;
       }
   
       var grand = document.getElementById("GrandTotal").value;
   
       grandtotal = parseFloat(total) + parseFloat(cdis_amt) + parseFloat(insurancecharges_amt) + parseFloat(overseasfrieght_amt) + parseFloat(localfreight_amt) + parseFloat(calclearingforwarding_amt) + parseFloat(detetioncharges_amt) + parseFloat(othercharges);
       document.getElementById("GrandTotal").value = grandtotal.toFixed(2);
       document.getElementById("orig_grand_tot").value = grandtotal.toFixed(2);
   
   }
   
   
   
   function checkCustomtype(i) {
       if (document.getElementById("cuntomDuty_Flag_" + i).value == '') {
           alert("please Select The Custom Duty Flag First !");
           return false;
       }
   }
   
   
   <
   !-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --INPORT ORDER CALCULATION PART-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- >
   
   
   
   
   <
   !-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --DOMESTIC ORDER CALCULATION PART-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- >
   
   
   function checkExcisable(str, i1) {
       var t = i1.split("_");
       var i = t[2];
       if (str == 'NonExcisable') {
           document.getElementById("exciseDuty_" + i).disabled = true;
           document.getElementById("exciseValue_" + i).disabled = true;
           document.getElementById("cess_ID1_" + i).disabled = true;
           document.getElementById("ECessValue_" + i).disabled = true;
           document.getElementById("cess_ID2_" + i).disabled = true;
           document.getElementById("SAHCessValue_" + i).disabled = true;
           document.getElementById("taxable_amt_" + i).disabled = true;
   
   
           document.getElementById("exciseDuty_" + i).value = '0';
           document.getElementById("exciseValue_" + i).value = '';
           document.getElementById("cess_ID1_" + i).value = '';
           document.getElementById("ECessValue_" + i).value = '';
           document.getElementById("cess_ID2_" + i).value = '';
           document.getElementById("SAHCessValue_" + i).value = '';
           document.getElementById("taxable_amt_" + i).value = '';
       } else if (str == 'Excisable' || str == 0) {
   
           document.getElementById("exciseDuty_" + i).disabled = false;
           document.getElementById("exciseValue_" + i).disabled = false;
           document.getElementById("cess_ID1_" + i).disabled = false;
           document.getElementById("ECessValue_" + i).disabled = false;
           document.getElementById("cess_ID2_" + i).disabled = false;
           document.getElementById("SAHCessValue_" + i).disabled = false;
           document.getElementById("taxable_amt_" + i).disabled = false;
       } else {
           document.getElementById("exciseDuty_" + i).disabled = true;
           document.getElementById("exciseValue_" + i).disabled = true;
           document.getElementById("cess_ID1_" + i).disabled = true;
           document.getElementById("ECessValue_" + i).disabled = true;
           document.getElementById("cess_ID2_" + i).disabled = true;
           document.getElementById("SAHCessValue_" + i).disabled = true;
           document.getElementById("taxable_amt_" + i).disabled = true;
   
   
           document.getElementById("exciseDuty_" + i).value = '0';
           document.getElementById("exciseValue_" + i).value = '';
           document.getElementById("cess_ID1_" + i).value = '';
           document.getElementById("ECessValue_" + i).value = '';
           document.getElementById("cess_ID2_" + i).value = '';
           document.getElementById("SAHCessValue_" + i).value = '';
           document.getElementById("taxable_amt_" + i).value = '';
       }
       document.getElementById(i1).value = str;
   }
   
   
   
   function claculateExcise(id, val) {
       if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari
           xmlhttp = new XMLHttpRequest();
       } else { // code for IE6, IE5
           xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
       }
       xmlhttp.onreadystatechange = function() {
           if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
               var data = xmlhttp.responseText.split("__");
               var k = data[0];
               document.getElementById("exciseValue_" + k).value = data[1];
           }
       }
       var id1 = id.split("_");
       var i = id1[1];
       var basicamt = document.getElementById("basic_" + i).value;
       xmlhttp.open("GET", "ajax_getexcisevalue.php?ids=" + id + "&vls=" + val + "&bamt=" + basicamt, true);
       xmlhttp.send();
   }
   
   
   function checkexiseflag(i1) {
       var t = i1.split("_");
       var i = t[1];
       if (document.getElementById("hid_billingtype_" + i).value == '') {
           alert("Select Tax Type");
           document.getElementById("hid_billingtype_" + i).focus();
       }
   }
   
   
   
   function calEcessonchange(id, val) {
   
   
       if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari
           xmlhttp = new XMLHttpRequest();
       } else { // code for IE6, IE5
           xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
       }
       xmlhttp.onreadystatechange = function() {
           if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
               var data = xmlhttp.responseText.split("__");
               var k = data[0];
               document.getElementById("ECessValue_" + k).value = data[1];
           }
       }
       var id1 = id.split("_");
       var i = id1[2];
       var ecessval = document.getElementById("exciseValue_" + i).value;
       xmlhttp.open("GET", "ajax_ecesscalculation.php?ids=" + id + "&vls=" + val + "&Ecessval=" + ecessval, true);
       xmlhttp.send();
   }
   
   
   
   function calSHEcessonchange(id, val) {
   
   
       if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari
           xmlhttp = new XMLHttpRequest();
       } else { // code for IE6, IE5
           xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
       }
       xmlhttp.onreadystatechange = function() {
           if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
               var data = xmlhttp.responseText.split("__");
               var k = data[0];
               document.getElementById("SAHCessValue_" + k).value = data[1];
           }
       }
       var id1 = id.split("_");
       var i = id1[2];
       var ecessval = document.getElementById("exciseValue_" + i).value;
       xmlhttp.open("GET", "ajax_ecesscalculation.php?ids=" + id + "&vls=" + val + "&Ecessval=" + ecessval, true);
       xmlhttp.send();
   }
   
   
   
   
   
   function cal_grandtotal(i1) {
       var t = i1.split("_");
       var i = t[1];
       var type_of_bill = document.getElementById("hid_billingtype_" + i).value;
       var basic = document.getElementById("basic_" + i).value;
       var Totaltaxable = document.getElementById("taxable_amt_" + i).value;
       if (basic == '') {
           basic = 0;
       }
       if (Totaltaxable == '') {
           Totaltaxable = 0;
       }
       if (document.getElementById("hid_billingtype_" + i).value == 'NonExcisable') {
           var grand_tot1 = parseFloat(basic);
           var grand_tot = grand_tot1.toFixed(2);
       } else if (document.getElementById("hid_billingtype_" + i).value == 'IncludeTax') {
           var grand_tot1 = parseFloat(basic);
           var grand_tot = grand_tot1.toFixed(2);
       } else {
           var grand_tot1 = parseFloat(basic) + parseFloat(Totaltaxable);
           var grand_tot = grand_tot1.toFixed(2);
       }
       document.getElementById("TotalSpecial_" + i).value = grand_tot;
   }
   
   
   
   function calcPackaging(str) {
       if (str != '') {
           var tota_amt = document.getElementById("total_item_amount").value;
           var pckgng_val = (str / 100) * tota_amt;
           document.getElementById("pkg_charges1").value = pckgng_val.toFixed(2);
       }
   }
   
   
   
   function tax_rate1(str) {
       var taxableAmount = document.getElementById("total_item_amount").value;
       var taxableAmount1 = document.getElementById("pkg_charges1").value;
       if (taxableAmount1 == '') {
           taxableAmount1 = 0;
       }
       var taxableAmount2 = parseFloat(taxableAmount) + parseFloat(taxableAmount1);
       if (str.length == 0) {
           document.getElementById("taxval").innerHTML = "";
           return;
       }
       if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari
           xmlhttp = new XMLHttpRequest();
       } else { // code for IE6, IE5
           xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
       }
       xmlhttp.onreadystatechange = function() {
           if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
               document.getElementById("taxval").innerHTML = xmlhttp.responseText;
           }
       }
       xmlhttp.open("GET", "get_tax_valdata.php?taxid=" + str + "&amt=" + taxableAmount2, true);
       xmlhttp.send();
   }
   
   
   function calsuroctamt(str) {
       var amt = parseFloat(document.getElementById("taxvalue").value);
       var suroctper = parseFloat(document.getElementById("sur_oct_per").value);
       var amount = (amt * suroctper) / 100;
       document.getElementById("sur_oct_amt").value = amount.toFixed(2);
   }
   
   
   function cal_grandamount() {
   
       var total = document.getElementById("total_item_amount").value;
       var sur_oct_amt = document.getElementById("sur_oct_amt").value;
       var TotalCharge = document.getElementById("TotalCharge").value;
       var taxamt = document.getElementById("taxvalue").value;
       var packagingCharges = document.getElementById("pkg_charges1").value;
       var additionalCharges = document.getElementById("additionalCharges").value;
       if (total == '') {
           total = 0;
       }
       if (sur_oct_amt == '') {
           sur_oct_amt = 0;
       }
       if (TotalCharge == '') {
           TotalCharge = 0;
       }
       if (packagingCharges == '') {
           packagingCharges = 0;
       }
       if (additionalCharges == '') {
           additionalCharges = 0;
       }
       if (taxamt == '') {
           taxamt = 0;
       }
       var grand = document.getElementById("GrandTotal").value;
       grandtotal = parseFloat(total) + parseFloat(sur_oct_amt) + parseFloat(TotalCharge) + parseFloat(packagingCharges) + parseFloat(additionalCharges) + parseFloat(taxamt);
       document.getElementById("GrandTotal").value = grandtotal.toFixed(2);
       document.getElementById("orig_grand_tot").value = grandtotal.toFixed(2);
   }
   
   function showResult(str) {
       var xmlhttp;
       if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari
           xmlhttp = new XMLHttpRequest();
       } else { // code for IE6, IE5
           xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
       }
       xmlhttp.onreadystatechange = function() {
           if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
               var data = xmlhttp.responseText.split("__");
               //alert(data);
               document.getElementById("storecode").innerHTML = data['0'];
               document.getElementById("vendor").innerHTML = data['1'];
   
           }
       }
   
       xmlhttp.open("GET", "check_data_fin.php?section=showVendorMRN&site=" + str, true);
       xmlhttp.send();
   }
   
   function calTotalQty1Direct(val, idd) {
       id1 = idd.split("_");
       id = id1[1];
   
       var totalamt1 = 0;
       if (id == undefined) {
           var qtyRec = document.getElementById("reciveqty").value;
           var qtyBill = document.getElementById("qtyasperbill").value;
           if (qtyRec == '') {
               qtyRec = 0;
           }
   
           if (parseFloat(qtyBill) >= parseFloat(qtyRec)) {
               var diff = parseFloat(qtyBill) - parseFloat(qtyRec);
               document.getElementById("shortaccessid").value = diff.toFixed(2);
               document.getElementById('minSign').style.display = "block";
               document.getElementById('minSign').value = "-";
               //document.getElementById('minSign').style.display="none";
           } else {
               var diff = parseFloat(qtyRec) - parseFloat(qtyBill);
               document.getElementById("shortaccessid").value = diff.toFixed(2);
               document.getElementById('minSign').style.display = "block";
               document.getElementById('minSign').value = "+";
           }
   
   
           document.getElementById("shortaccessid").value = diff.toFixed(2);
           // var firstRow=document.getElementById("qtyasperbill").value;
           var totalamt = 0;
           var countcharges = document.getElementById("hiditemcount").value;
   
           for (var j = 1; j < countcharges; j++) {
               var qtyBill1 = document.getElementById("qtyasperbill_" + i).value;
               if (qtyBill1 == '') {
                   qtyBill1 = 0;
               }
               var totalamt = parseFloat(totalamt) + parseFloat(qtyBill1);
           }
           //alert(totalamt);
           //var finalRes=parseFloat(totalamt)+parseFloat(firstRow);
           document.getElementById("short").value = totalamt.toFixed(2);
   
   
           var poqty = parseInt(document.getElementById("pending").value);
           var tolerance = document.getElementById("tolerances").value;
           if (tolerance == '') {
               tolerance = 0;
           }
           if (poqty == '') {
               poqty = 0;
           }
           str1 = parseInt(val);
           if (str1 == '') {
               str1 = 0;
           }
           if (tolerance == '') {
               if (parseInt(poqty) < parseInt(str1)) {
                   alert('Bill Quantity Cannot Be Greater Than Pending Quantity');
                   document.getElementById("qtyasperbill").focus();
                   document.getElementById("qtyasperbill").value = '';
                   return false;
               }
           } else {
               var p1 = (tolerance * poqty) / 100;
               var p2 = parseFloat(poqty) + parseFloat(p1);
               if (parseInt(p2) < parseInt(str1)) {
                   alert('Bill Quantity Cannot Be Greater Than Pending Quantity');
                   document.getElementById("qtyasperbill").focus();
                   document.getElementById("qtyasperbill").value = '';
                   return false;
               }
           }
       } else {
           var qtyRec = document.getElementById("reciveqty_" + id).value;
   
           var qtyBill = document.getElementById("qtyasperbill_" + id).value;
           if (qtyRec == '') {
               qtyRec = 0;
           }
           if (qtyBill == '') {
               qtyBill = 0;
           }
   
           if (parseFloat(qtyBill) > parseFloat(qtyRec)) {
               var diff = parseFloat(qtyBill) - parseFloat(qtyRec);
               document.getElementById("shortaccessid_" + id).value = diff.toFixed(2);
               //document.getElementById('minSign_'+id).style.display="block";
               document.getElementById('minSign_' + id).value = "-";
   
           }
           if (parseFloat(qtyBill) <= parseFloat(qtyRec)) {
               var diff = parseFloat(qtyRec) - parseFloat(qtyBill);
               document.getElementById("shortaccessid_" + id).value = diff.toFixed(2);
               //document.getElementById('minSign_'+id).style.display="block";
               document.getElementById('minSign_' + id).value = "+";
           }
   
   
   
           //document.getElementById("shortaccessid_"+id).value=diff.toFixed(2);
   
           //var firstRow= document.getElementById("qtyasperbill").value;
           //if(firstRow=='') { firstRow=0; }
           var totalamt = 0;
           var countcharges = document.getElementById("hiditemcount").value;
           // alert(countcharges);
           for (var i = 1; i < countcharges; i++) {
               var qtyBill1 = document.getElementById("qtyasperbill_" + i).value;
               var qtyRec1 = document.getElementById("reciveqty_" + i).value;
   
               if (qtyBill1 == '') {
                   qtyBill1 = 0;
               }
               if (qtyRec1 == '') {
                   qtyRec1 = 0;
               }
   
               var totalamt = parseFloat(totalamt) + parseFloat(qtyBill1);
               var totalamt1 = parseFloat(totalamt1) + parseFloat(qtyRec1);
           }
           // alert(totalamt);
           //var finalRes=parseFloat(totalamt)+parseFloat(firstRow);
           document.getElementById("shortDirect").value = totalamt.toFixed(2);
           document.getElementById("short1Direct").value = totalamt1.toFixed(2);
   
   
           var poqty = parseInt(document.getElementById("pending_" + id).value);
           var tolerance = document.getElementById("tolerances_" + id).value;
           if (tolerance == '') {
               tolerance = 0;
           }
           if (poqty == '') {
               poqty = 0;
           }
           str1 = parseInt(val);
           if (str1 == '') {
               str1 = 0;
           }
           if (tolerance == '') {
               if (parseInt(poqty) < parseInt(str1)) {
                   alert('Bill Quantity Cannot Be Greater Than Pending Quantity');
                   document.getElementById("qtyasperbill_" + id).focus();
                   document.getElementById("qtyasperbill_" + id).value = '';
                   return false;
               }
           } else {
               var p1 = (tolerance * poqty) / 100;
               var p2 = parseFloat(poqty) + parseFloat(p1);
               if (parseInt(p2) < parseInt(str1)) {
                   alert('Bill Quantity Cannot Be Greater Than Pending Quantity');
                   document.getElementById("qtyasperbill_" + id).focus();
                   document.getElementById("qtyasperbill_" + id).value = '';
                   return false;
               }
           }
       }
   }
   
   function deactivate1(str) {
       var confirmText = "Are you sure you want to delete the Document?";
       if (confirm(confirmText)) {
           //var qty=document.getElementById("hrdqty1A_"+str).value;
           //var n=qty.split(",");
           //		var count=n.length;
           //		for(var j=0;j<count;j++)
           //		{
           //			var fin=parseFloat(n[j]);
           //			var hrdqty=parseFloat(document.getElementById("hrdstock_qty2_"+j).value);
           //			var diff=hrdqty-fin;
           //			document.getElementById("hrdstock_qty2_"+j).value=diff;
           //		}
           //document.getElementById("itemid1_"+str).value='';
           //document.getElementById("active_"+str).style.display='block';
   
           document.getElementById("itemid_" + str).value = '';
           document.getElementById("qtyasperbill_" + str).value = '';
           document.getElementById("reciveqty_" + str).value = '';
           document.getElementById("deactive_" + str).style.display = 'none';
           document.getElementById("hide_" + str).style.display = 'none';
           var totalamt = 0;
           var totalamt1 = 0;
           var countcharges = document.getElementById("count3").value;
   
           for (var i = 1; i < countcharges; i++) {
               var qtyBill1 = document.getElementById("qtyasperbill_" + i).value;
               var qtyRec1 = document.getElementById("reciveqty_" + i).value;
   
               if (qtyBill1 == '') {
                   qtyBill1 = 0;
               }
               if (qtyRec1 == '') {
                   qtyRec1 = 0;
               }
   
               var totalamt = parseFloat(totalamt) + parseFloat(qtyBill1);
               var totalamt1 = parseFloat(totalamt1) + parseFloat(qtyRec1);
           }
   
           //var finalRes=parseFloat(totalamt)+parseFloat(firstRow);
           document.getElementById("shortDirect").value = totalamt.toFixed(2);
           document.getElementById("short1Direct").value = totalamt1.toFixed(2);
           //alert('Item removed');
           //calqty(str);
           //caltotal(str);
   
       }
   }
   
   <
   !-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --DOMESTIC ORDER CALCULATION PART-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- >
</script>
<!-------------------------------------------JS PART END HERE--------------AS---------14-06-2013---------------->
<style>
   table.thborder tr td {
   font-size: 12px;
   font-weight: normal;
   border-bottom: #b0b0b0 1px solid;
   padding: 1px 1px !important;
   }
</style>
<input type="hidden" name="mrnid" value="<?php echo $_REQUEST['mrnid']; ?>" />
<link rel="stylesheet" href="css/new_mxerp.css">
<div class="body_contain">
<div class="tab_div">
<h1><?php echo $s->getField('modules_form', 'id', $_REQUEST['frmid'], 'description'); ?></h1>
<form action="" method="post">
   <table width="100%" border="0" cellspacing="0" cellpadding="3">
      <tr class="row1">
         <td width="13%" align="right">Branch <font color="#FF0000">*</font>
         </td>
         <td width="20%">
            <?php $SQLSite = DB_query("Select loccode,locationname from locations where CompanyId='" . $_SESSION['ACGCompanyId'] . "' and loccode in ('" . $_SESSION['AssignedBranch'] . "')", $db); ?>
            <select name="sitecode" id="sitecode" onchange="showResult(this.value)">
               <?php
                  while ($site_row = DB_fetch_array($SQLSite)) {
                      $p = "";
                      if ($mrn_query_result['site'] == $site_row['loccode'])
                          $p = "selected";
                  ?>
               <option value="<?php echo $site_row['loccode']; ?>" <?php echo $p; ?>><?php echo $site_row['locationname']; ?></option>
               <?php } ?>
            </select>
            <input type="hidden" name="grntypedata" value="<?php echo $mrn_query_result['Grn_Type']; ?>" />
         </td>
         <td width="13%" align="right">GRN No.</td>
         <td width="20%"><input type="text" value="<?php echo $mrn_query_result['MRNNo']; ?>" name="MRNNo" readonly="true"></td>
         <td width="13%" align="right">GRN Date</td>
         <td><input type="text" name="MRNdate" value="<?php if (isset($mrn_query_result['MRNDate']))
            echo ConvertSQLDate($mrn_query_result['MRNDate']);
            else echo date('d/m/Y'); ?>" id="MRNdate" class="datepicker"></td>
      </tr>
      <tr class="row1">
         <td align="right">Store <font color="#FF0000">*</font>
         </td>
         <td>
            <select id="storecode" name="storecode" onfocus="check_po()">
               <?php
                  $sql_store = DB_query("SELECT id, StoreName,storecode FROM storetype where Store_Site IN ('" . $_SESSION['AssignedBranch'] . "') and CompanyId='" . $_SESSION['ACGCompanyId'] . "'", $db);
                  while ($row_store = DB_fetch_array($sql_store)) {
                      $p1 = '';
                      if ($mrn_query_result['StoreCode'] == $row_store['id'])
                          $p1 = "selected";
                  ?>
               <option value="<?php echo $row_store['id']; ?>" <?php echo $p1; ?>><?php echo $row_store['StoreName']; ?></option>
               <?php } ?>
            </select>
         </td>
         <td align="right">Recieve Against <font color="#FF0000">*</font>
         </td>
         <td><input type="text" name="receiviedagaist" value="<?php echo $mrn_query_result['ReceivedAgainst']; ?>" />
            <?php if ($mrn_query_result['ReceivedAgainst'] == "PO") {
               $received_flag = 1;
               } ?>
         </td>
         <td align="right">Recevied From</td>
         <td>
            <select name="vendor" id="vendor">
               <option value="">Select</option>
               <?php
                  $sql = "Select id,vendor_name from suppliers where CompanyId='" . $_SESSION['ACGCompanyId'] . "'";
                  $result = DB_query($sql, $db);
                  while ($myrow = DB_fetch_array($result)) {
                      $p = "";
                      if ($mrn_query_result['ReceivedFrom'] == $myrow['id'])
                          $p = "selected";
                  
                  ?>
               <option value="<?php echo $myrow['id']; ?>" <?php echo $p; ?>><?php echo  str_replace(array("M/s ", "M/S"), '', $myrow['vendor_name']); ?></option>
               <?php }    ?>
            </select>
         </td>
      </tr>
      <?php
         if ($mrn_query_result['ReceivedAgainst'] == 'PO') {
             $SQLPo = DB_query("SELECT id ,purchase_ordNo FROM purchorders where id='" . $mrn_query_result['order_no'] . "'", $db);
         } else if ($mrn_query_result['ReceivedAgainst'] == 'Indent') {
             $SQLPo = DB_query("SELECT requisitionno ,Reqno FROM materialrequisitions where requisitionno='" . $mrn_query_result['order_no'] . "'", $db);
         }
         ?>
      <tr class="row1">
         <td id="GtT3" align="right"><?php if ($mrn_query_result['ReceivedAgainst'] == 'Indent') { ?>Indent/PR No.<?php } else { ?>PO No.<?php } ?></td>
         <td id="GtT4">
            <select name="PONo" id="indentprno">
               <?php
                  while ($FetchPodata = DB_fetch_array($SQLPo)) {
                      if ($mrn_query_result['ReceivedAgainst'] == 'Indent') { ?>
               <option value="<?php echo $FetchPodata['requisitionno'];  ?>"><?php echo $FetchPodata['Reqno']; ?></option>
               <?php } else  if ($mrn_query_result['ReceivedAgainst'] == 'PO') { ?>
               <option value="<?php echo $FetchPodata['id'];  ?>"><?php echo $FetchPodata['purchase_ordNo']; ?></option>
               <?php }
                  } ?>
            </select>
         </td>
         <td align="right">PO Type</td>
         <td>
            <input type="text" readonly name="poTypes" id="poTypes" value="<?php if ($mrn_query_result['Type'] == 'DO') {
               echo "Domestic Order";
               } elseif ($mrn_query_result['Type'] == 'IO') {
               echo 'Import Order';
               } ?>" />
            <!--  <select name='PoType' id='PoType'	style='width:100%;'>
               <option value=''>Select</option>
               <option value='IO' <?php if ($mrn_query_result['Type'] == 'IO') {
                  echo "selected";
                  } ?> >Import Order</option>
               <option value='DO' <?php if ($mrn_query_result['Type'] == 'DO') {
                  echo "selected";
                  } ?> >Domestic Order</option>
               <option value='SO' <?php if ($mrn_query_result['Type'] == 'SO') {
                  echo "selected";
                  } ?> >Service Order</option>
               <option value='AO' <?php if ($mrn_query_result['Type'] == 'AO') {
                  echo "selected";
                  } ?> >Asset Order</option>
               		</select>-->
         </td>
         <td align="right">PO Category</td>
         <td>
            <select name='Pocategory' id='Pocategory'>
               <option value=''>Select</option>
               <option value='AT' <?php if ($mrn_query_result['Po_category'] == "AT") {
                  echo "selected";
                  } ?>>Asset</option>
               <option value='MT' <?php if ($mrn_query_result['Po_category'] == "MT") {
                  echo "selected";
                  } ?>>Material</option>
               <option value='SV' <?php if ($mrn_query_result['Po_category'] == "SV") {
                  echo "selected";
                  } ?>>Service</option>
            </select>
         </td>
      </tr>
      <tr class="row1">
         <td align="right">Document Type</td>
         <td>
            <select name="DocumentType" id="DocumentType">
               <option value="Challan" <?php if ($mrn_query_result['DocumentType'] == "Challan") {
                  echo "selected";
                  } ?>>Challan</option>
               <option value="Bill" <?php if ($mrn_query_result['DocumentType'] == "Bill") {
                  echo "selected";
                  } ?>>Bill</option>
            </select>
         </td>
         <td align="right">Document No.</td>
         <td><input name="billno" type="text" id="billno" value="<?php echo $mrn_query_result['BillNo']; ?>" /></td>
         <td align="right">Challan / Bill Date</td>
         <td><input type="text" name="MRNVoucherDate" class="datepicker" onblur="valdate();" value="<?php echo ConvertSQLDate($mrn_query_result['MRNVoucherDate']); ?>" /></td>
      </tr>
      <tr class="row1">
         <td align="right">Gate Entry No. <font color="#FF0000">*</font>
         </td>
         <td>
            <input type="text" name="gatepassno" id="gatepassno" value="<?php echo $mrn_query_result['GetPassNo']; ?>"
               onkeyup="checkgatentyno(this.value)" ; />
            <div id="entrycheck1"><input type="hidden" name="entrycheck" id="entrycheck" value="<?php echo $entrycheck; ?>" /></div>
         </td>
         <td align="right">Gate Entry Date <font color="#FF0000">*</font>
         </td>
         <td align="left" valign="top"><input type="text" name="gatepassdate" id="gatepassdate" class="datepicker" value="<?php echo ConvertSQLDate($mrn_query_result['gatepassdate']); ?>" /></td>
         <td align="right">Vehicle No.</td>
         <td><input name="vehicalno" type="text" id="vehicalno" value="<?php echo $mrn_query_result['VehicleNo']; ?>" /></td>
      </tr>
      <tr class="row1">
         <td align="right">Receiving Time</td>
         <td>
            <select name="timein" id="timein" style="width:49%">
               <option value="Day" <?php if ($mrn_query_result['TimeIn'] == "Day") {
                  echo "selected";
                  } ?>>Day</option>
               <option value="Night" <?php if ($mrn_query_result['TimeIn'] == "Night") {
                  echo "selected";
                  } ?>>Night</option>
            </select>
            <input type="text" name="timeout" value="<?php if (isset($mrn_query_result['Timeout'])) echo $mrn_query_result['Timeout'];
               else echo date("h:i:s", time()); ?>" style="width:49%;">
         </td>
         <td align="right">L R No.</td>
         <td><input name="lrno" type="text" id="lrno" value="<?php echo $mrn_query_result['LRno']; ?>" /></td>
         <td align="right">L R Date</td>
         <td><input name="lrdate" type="text" id="lrdate" value="<?php if (isset($_SESSION['lrdate'])) echo $lrdate;
            else echo date('d/m/Y'); ?>" onblur="LRdate();" class="datepicker" /></td>
      </tr>
      <tr class="row1">
         <td align="right">Form Type</td>
         <td><input type="text" name="form_type" id="form_type" value="<?php echo $mrn_query_result['form_type']; ?>" /></td>
         <td align="right">Form No.</td>
         <td><input type="text" name="form_no" id="form_no" value="<?php echo $mrn_query_result['form_no']; ?>" /></td>
         <td align="right">Transporter Name</td>
         <td>
            <select name="transport" id="transport">
               <option value="0">Select</option>
               <?php
                  $trans = DB_query("select * from transport_master where CompanyId='" . $_SESSION['ACGCompanyId'] . "'", $db);
                  while ($trow = DB_fetch_array($trans)) {
                      $p = '';
                      if ($trow['id'] == $mrn_query_result['Transp_name'])
                          $p = "selected";
                  ?>
               <option value="<?php echo $trow['id']; ?>" <?php echo $p; ?>><?php echo $trow['TransportName']; ?></option>
               <?php } ?>
            </select>
         </td>
      </tr>
      <!--<tr>
         <th align="left" valign="top">Duty Type</strong></th>
         <td align="left" valign="top"><?php echo ucwords($mrn_query_result['duty_type']); ?></strong>
         <input type="hidden" name="dutytype" id="dutytype" value="<?php echo $mrn_query_result['duty_type']; ?>" /></td>
         <td colspan="4">&nbsp;</td>
         </tr>-->
      <tr class="row1">
         <td align="right">Remarks</td>
         <td colspan="5"><textarea name="RemarksIfAny" id="RemarksIfAny"><?php echo $mrn_query_result['RemarksIfAny']; ?></textarea></td>
      </tr>
   </table>
   <br>
   <h3>Items Details</h3>
   <?php if ($mrn_query_result['Grn_Type'] == 'Direct') { ?>
   <p align="center"><input type="button" name="profile_popup" value="Pick Items" id="profile_popup" class="search" />
      <input type="button" class="search" onclick="deleteRow2_grn('dataTable')" value="Delete" />
   </p>
   <?php } ?>
   <table width='100%' cellpadding='3' cellspacing='0' border='0' class="thborder">
      <tr>
         <th width="2%">Select</th>
         <th width="1"></th>
         <th width="9%">Item Code</th>
         <th colspan="2">Item Name</th>
         <th width="8%">Specification</th>
         <?php if ($mrn_query_result['ReceivedAgainst'] == 'Indent') { ?>
         <th width="5%">Indent Qty.</th>
         <?php } else if ($mrn_query_result['ReceivedAgainst'] == 'Without PO') { ?>
         <th width="5%">Order Qty.</th>
         <?php } else { ?>
         <th width="5%">PO Qty.</th>
         <th width="5%">Free Qty.</th>
         <?php } ?>
         <?php if ($mrn_query_result['Grn_Type'] == 'Indirect') {  ?>
         <th width="5%">Pending Qty.</th>
         <?php } ?>
         <th width="8%">Batch No.</th>
         <th width="5%">Qty. As Per Bill</th>
         <th width="5%">Qty. Received</th>
         <th width="5%">Free Received</th>
         <th colspan="2">Short Qty.</th>
         <?php if ($mrn_query_result['ReceivedAgainst'] == 'Without PO' || $mrn_query_result['ReceivedAgainst'] == 'Indent') { ?>
         <th width="5%">Rate</th>
         <th width="5%">Amount</th>
         <?php } ?>
         <th width="7%">Expected Date</th>
         <th width="7%">MRP</th>
      </tr>
      <tbody id="dataTable">
         <?php
            $sqlPoRec = DB_query("SELECT * FROM addmrnqty where issue_id='" . $_REQUEST['mrnid'] . "' order by id ", $db);
            $i = 1;
            while ($PORecDetails = DB_fetch_array($sqlPoRec)) {
            
                $ItemCode = $s->GetFieldValue('item_master', "id='" . $PORecDetails['mst_itemid'] . "'", 'StockID');
                $Itemname = $s->GetFieldValue('item_master', "id='" . $PORecDetails['mst_itemid'] . "'", 'item_name');
                $Tolrance = $s->GetFieldValue('item_master', "id='" . $PORecDetails['mst_itemid'] . "'", 'item_mst_form_rate');
            
            
                if ($mrn_query_result['ReceivedAgainst'] == 'Indent')
                    $check_last_mrn = "Select sum(reciveqty),POQty from addmrnqty inner join addmrn on addmrn.id=addmrnqty.issue_id where addmrn.id='" . $mrn_query_result['id'] . "' and addmrnqty.mst_itemid='" . $PORecDetails['mst_itemid'] . "' and ReceivedAgainst='Indent'";
                //$check_last_mrn="Select POQty,sum(reciveqty) from addmrnqty 
                //where issue_id='".$_REQUEST['mrnid']."' and mst_itemid='".$PORecDetails['mst_itemid']."' and ReceivedAgainst='Indent'";
                else
                    $check_last_mrn = "Select sum(reciveqty),POQty from addmrnqty inner join addmrn on addmrn.id=addmrnqty.issue_id where addmrn.order_no='" . $mrn_query_result['order_no'] . "' and addmrnqty.mst_itemid='" . $PORecDetails['mst_itemid'] . "' and ReceivedAgainst='PO'";
                //$check_last_mrn="Select POQty,sum(reciveqty) from addmrnqty 
                //where issue_id='".$_REQUEST['mrnid']."' and mst_itemid='".$PORecDetails['mst_itemid']."' and ReceivedAgainst='PO'";
                $last_mrn_res = DB_query($check_last_mrn, $db);
            
                $last_mrn_row = DB_fetch_array($last_mrn_res);
            
                if ($last_mrn_row['POQty'] != '' && $last_mrn_row['sum(reciveqty)'] != '') {
                    $pending_qty = $last_mrn_row['POQty'] - ($last_mrn_row['sum(reciveqty)']);
                } else {
                    $pending_qty = $PORecDetails['Quantity'];
                }
            
                //							if($PORecDetails['billing_type']=='NonExcisable' || $PORecDetails['billing_type']=='IncludeTax')
                //							{
                //								$disabled='disabled';
                //							}
                //								else
                //								{
                //									$disabled='';
                //								}	 
            ?>
         <tr id='hide_<?php echo $i; ?>'>
            <td><input type="checkbox"></td>
            <td><input type='hidden' name='mst_itemid[]' id='itemid_<?php echo $i; ?>' value='<?php echo $PORecDetails['mst_itemid'] ?>' readonly="true" /></td>
            <td><input type='text' name='itemcode[]' id='itemcode_<?php echo $i; ?>' value='<?php echo $ItemCode ?>' readonly="true" /></td>
            <td><input name="text" type="text" id="itemname_<?php echo $i; ?>" value="<?php echo $Itemname; ?>" readonly="true" /></td>
            <td width="1"><?php echo $s->GetFieldValue('size_master', "id='" . $PORecDetails['size'] . "'", 'size') ?></td>
            <td><?php echo $s->GetFieldValue('product_grade', "id='" . $PORecDetails['Gread'] . "'", 'grade') ?></td>
            <?php if ($mrn_query_result['ReceivedAgainst'] == 'Without PO') {
               $readonly = "";
               } else {
               $readonly = "readonly";
               } ?>
            <td><input type='text' name='poqty[]' id='poqty_<?php echo $i; ?>' value='<?php echo $PORecDetails['POQty'] ?>' <?php echo $readonly; ?> class="text-right" /></td>
            <td><input type='text' name='poqty[]' id='poqty_<?php echo $i; ?>' value='<?php echo $PORecDetails['freeqty'] ?>' <?php echo $readonly; ?> class="text-right" /></td>
            <?php if ($mrn_query_result['Grn_Type'] == 'Indirect') {
               $colspan = '5';  ?>
            <td><input type='text' name='pending_qty[]' id='pending_qty_<?php echo $i; ?>' value='<?php echo $pending_qty; ?>' readonly="true" class="text-right" /></td>
            <?php }  ?>
            <td><input type='text' name='batch_no[]' id='batch_no_<?php echo $i; ?>' value='<?php echo $PORecDetails['batch_no'] ?>' /></td>
            <td><input type='text' name='qty_as_per_bill[]' id='qtyasperbill_<?php echo $i; ?>' onkeyup='calTotalQty1Direct(this.value,this.id)' value="<?php echo $PORecDetails['qty_as_per_bill'] ?>" class="text-right" /></td>
            <td><input type='text' name='reciveqty[]' id='reciveqty_<?php echo $i; ?>' onkeyup='calTotalQty1Direct(this.value,this.id);' value="<?php echo $PORecDetails['reciveqty'] ?>" class="text-right" /></td>
			<td><input type='text' name='freciveqty[]' id='freciveqty_<?php echo $i; ?>' onkeyup='calTotalQty1Direct(this.value,this.id);' value="<?php echo $PORecDetails['free_qty'] ?>"  class="text-right" /></td>
            <td width="3%"><input type='text' name='minSign[]' id='minSign_<?php echo $i; ?>' readonly="true" value="<?php echo $PORecDetails['minSign'] ?>" /></td>
            <td width="4%"><input type='text' name='short_qty[]' id='shortaccessid_<?php echo $i; ?>' onfocus='calculate_poshort(this.id);' value="<?php echo $PORecDetails['short_accessid'] ?>" /></td>
            <?php if ($mrn_query_result['ReceivedAgainst'] == 'Without PO' ||  $mrn_query_result['ReceivedAgainst'] == 'Indent') { ?>
            <td><input type='text' name='Rate[]' id='rate_<?php echo $i; ?>' value="<?php echo $PORecDetails['item_total_rate']; ?> " onkeyup='calculate_amt(this.id,this.value);' class="text-right" /></td>
            <td><input type='text' value="<?php echo $PORecDetails['itemprice']; ?> " name='totalPrice[]' id='totalValue_<?php echo $i; ?>' /></td>
            <?php } ?>
            <td><input type="text" name="ex_date[]" id="exdate_<?php echo $i; ?>" value="<?php echo ($PORecDetails['expected_date']!='' && $PORecDetails['expected_date']!='0000-00-00')?ConvertSQLDate($PORecDetails['expected_date']):''; ?>" class="datepicker"></td>
            <td><input type="text" name="mrp[]" id="mrp_<?php echo $i; ?>" value="<?php echo $PORecDetails['mrprate']; ?>" class="text-right" ></td>
         </tr>
         <?php $i++;
            }     ?>
      </tbody>
      <input type="hidden" name="Input" id="count3" value="<?php echo $i; ?>" />
      <input type="hidden" name="Input" id="edit_cnt" value="<?php echo $i; ?>" />
      <input name="hidden" type='hidden' id='conterimp' value="<?php echo $i; ?>" />
      <input name="hidden" type='hidden' id='hiditemcount' value="<?php echo $i; ?>" />
      <?php
         $data2 .= "<tr>";
         if ($mrn_query_result['Grn_Type'] == 'Indirect') {
             $colspan = '6';
         } else {
             $colspan = '5';
         }
         //$data2.="<td style='text-align:right;'><strong>Total Quantity</td>";
         $data2 .= "<td colspan='9'>&nbsp;</td>";
         $data2 .= "<td style='text-align:right;'><strong>Total Qty.</strong></td>";
         $data2 .= "<td><input readonly name='totalBillQty' type='text' id='shortDirect'  size='8' value='" . $mrn_query_result['totalBillQty'] . "'/></td>";
         $data2 .= "<td><input readonly name='totalRecQty' type='text' id='short1Direct'  size='8' value='" . $mrn_query_result['totalRecQty'] . "'/></td>";
         $data2 .= "<td colspan='5'>&nbsp;</td>";
         //$data2.="<td colspan='2' bgcolor='#fff' style='text-align:right;'><strong>Total Amt.</strong></td>";
         //$data2.="<td><input name='totalitemamount' type='text' id='totalitemamount'  size='8' value='".$mrn_query_result['totalamount']."' /></td>";       
         $data2 .= "</tr>";
         echo $data2;
     ?>
	 <?php echo renderPOItemsTable($mrn_query_result['id']);
	 function renderPOItemsTable($poId) {
		   global $db;
           $html = '';
		   
		   $sql="SELECT IFNULL(NULLIF(total_Item_Amount,''),0) total_Item_Amount,IFNULL(NULLIF(tot_freight,''),0) tot_freight,IFNULL(NULLIF(vat_cst_val,''),0) vat_cst_val,IFNULL(NULLIF(insurancecharges_amt,''),0) insurancecharges_amt,IFNULL(NULLIF(othercharges,''),0) othercharges, round_off,IFNULL(NULLIF(grandtotal,''),0) grandtotal FROM addmrn WHERE id='$poId'";
		   $res=DB_query($sql,$db);$mresult=DB_fetch_assoc($res);
				
   	       $data2 = '';
   		   $data2 .= '<table width="100%" border="0" cellspacing="0" cellpadding="3">';
   		   $data2 .= '<tr class="row1">';
   		   $data2 .= '<td width="36%" align="right">Basic Amount</td>';
   		   $data2 .= '<td><input type="text" name="basic_amt" readonly id="total_item_amount" class="text-right" value="' . $mresult['total_Item_Amount'] . '" /></td>';
   		   $data2 .= '</tr>';
   			
   		   $data2 .= '<tr class="row1">';
   		   $data2 .= '<td align="right">Freight And P&amp;S</td>';
   		   $data2 .= '<td><input type="text" name="Freight" id="TotalCharge" class="text-right" readonly="true" value="' . $mresult['tot_freight'] . '" /></td>';
   		   $data2 .= '</tr>';
   			
   		   $data2 .= '<tr class="row1">';
   		   $data2 .= '<td align="right">GST</td>';
   		   $data2 .= '<td><div id="taxval"><input type="text" class="text-right" value="' . $mresult['vat_cst_val'] . '" ';
   		   $data2 .= 'name="tax_amt" id="taxvalue" readonly="true" /></div></td>';
   		   $data2 .= '</tr>';
   			
   		   $data2 .= '<tr class="row1">';
   		   $data2 .= '<td align="right">Insurance</td>';
   		   $data2 .= '<td><input name="insr_amt" class="text-right" value="' . $mresult['insurancecharges_amt'] . '" ';
   		   $data2 .= 'id="insurance" type="text" readonly /></td>';
   		   $data2 .= '</tr>';
   			
   		   $data2 .= '<tr class="row1">';
   		   $data2 .= '<td align="right">Miscellaneous</td>';
   		   $data2 .= '<td><input type="text" class="text-right" value="' . $mresult['othercharges'] . '" ';
   		   $data2 .= 'name="other_amt" id="miscellaneous" readonly /></td>';
   		   $data2 .= '</tr>';
   			
   			$data2 .= '<tr class="row1">';
   			$data2 .= '<td align="right">Round Off</td>';
   			$data2 .= '<td>';
			$rf = ($mresult['round_off']!='')?explode('0.',$mresult['round_off']):array('+',0.0);
   			$data2 .= '<input type="text" name="pluMin" readonly id="pluMin" style="width:23%;" ';
   			$data2 .= ' value="' . $rf[0] . '" />';
   			$data2 .= '<input type="text" name="roundVal" readonly id="roundVal" class="text-right" style="width:74%;" ';
   			$data2 .= ' value="' . $rf[1] . '" />';
   			$data2 .= '</td></tr>';
   			
   			$data2 .= '<tr class="row1">';
   			$data2 .= '<td align="right">Grand Total</td>';
   			$data2 .= '<td><input type="text" name="GrandTotal" class="text-right" readonly id="GrandTotal" ';
   			$data2 .= ' value="' . $mresult['grandtotal'] . '" /></td>';
   			$data2 .= '</tr>';
   			$data2 .= '</table>';
   			
   		    $html .= '<table border="0" width="100%" cellpadding="2" cellspacing="0">
   			<tr>
   				<td valign="top" colspan="6">&nbsp;</td>
   				<td width="36%" valign="top">
   					<div id="basicamtdetails">' . $data2 . '</div>
   				</td>
   			</tr>
   		</table>';
   
           
           return $html;
       }?>
   </table>
   <br />
</form>