Ranish666

purchase invoice js

May 10th, 2021
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var isTax = 0, isAddTax = 0, isImport = 0, ismultipleunit = 0, PId = 0, unitConversionId = 0, productName = '', purchaseDetailsId = 0, purchaseMasterId = 0;
  2. var isfree = 0, lastkeyPI = 0, originalRate = 0;
  3. var lastkeyAdd = 0, lastkeyTax = 0, lastkeyCharge = 0;
  4. var datas = [], Additionaldatas = [], taxdatas = [], chargedatas = [], chargeList = [], purchaselist = [], stockpostinglist = [], taxLists = [], addcpstList = [], purchacid = 0, cashpartyid = 0, addcrlist = [], addDrlist = [], ledgerpostingId = [], ledgers = [];
  5. //make them zero
  6. var grossAmt = 0, disAmt = 0, netAmt = 0, taxAmt = 0, netTotal = 0, CosttoParty = 0, gCosttoParty = 0, TotalAdditionalCost = 0, taxable = 0, nonTaxable = 0, totalInvoice = 0, totalGrand = 0;
  7. var zero = 0, NetAmtWithImport = 0, pindex = 0, productType = 0;
  8. var deleteid = 0;
  9. var addcostlpid = [], addcostid = 0, chargelpid = [], taxlpid = [], purchlpid = 0, cashbanklpid = 0, discountlpid = 0, partyBalanceId = 0, stockpostid = 0;
  10. var PrintBill = 0;
  11. var ledgerId = 0;
  12. var typeOfVoucher = '';
  13. var materialReceiptMasterId = 0;
  14. var materialReceiptDetailsId = 0;
  15. var purchaseOrderMasterId = 0;
  16. var purchaseOrderDetailsId = 0;
  17. var orderQTY = 0, masterAction = '', invoiceNo = 0;
  18. var accountgpId = 0, CashAmount = 0, id = 0, editId = 0, chargeAmt = 0;
  19. negativeCash = parseInt(JSON.parse(localStorage.getItem("KeyCompanyDetails")).negativeCash);
  20.  
  21. var ServRate = 0, ServAmt = 0,
  22.     numberOfDecimal = parseInt($.trim(JSON.parse(localStorage.getItem("KeyCompanyDetails")).numberOfDecimal) === '' ?
  23.         3 : JSON.parse(localStorage.getItem("KeyCompanyDetails")).numberOfDecimal);
  24. var BillDiscountPercentage = 0, billDiscount = 0, BillExciseDutyAmount = 0, BillExciseDutyPercentage = 0,
  25.     BillTaxAmount = 0, BillTaxPercentage = 0;
  26.  
  27. $(window).on('load', function () {
  28.     $('#loading').fadeOut();
  29. });
  30. $(document).on('ready', function () {
  31.     $('#loading').fadeOut();
  32. });
  33.  
  34. function getSequence() {
  35.     $.ajax({
  36.         url: '/TransactionSequence/TransactionSequence_GetbyType',
  37.         data: {
  38.             Type: 'purchase'
  39.         },
  40.         success: function (data) {
  41.             var h = ``;
  42.             $.each(data, (i, val) => {
  43.                 if (i === 0) {
  44.                     h += ` <div><label>${val.Sequence} :</label>
  45.                             <input type="text" class="ts percentage form-control tranSQPer_${val.Sequence.replace(/\s/g, "")}"
  46.                              placeholder = "%"
  47.                             onkeypress="calPerTans('first', 'tranSQPer_${val.Sequence.replace(/\s/g, "")}', 'tranSQAmt_${val.Sequence.replace(/\s/g, "")}')"
  48.                             id="tranSQPer_${val.Sequence.replace(/\s/g, "")}" />
  49.                             <input type="text" class="ts amt form-control tranSQAmt_${val.Sequence.replace(/\s/g, "")}"
  50.                             placeholder = "Amount"
  51.                             onkeypress="calTans('first', 'tranSQAmt_${val.Sequence.replace(/\s/g, "")}', 'tranSQPer_${val.Sequence.replace(/\s/g, "")}')"
  52.                             id="tranSQAmt_${val.Sequence.replace(/\s/g, "")}" />
  53.                     </div>`;
  54.                 }
  55.                 else {
  56.                     if (val.Sequence.replace(/\s/g, "") === 'BillDiscount') {
  57.                         h += ` <div><label>${val.Sequence} :</label>
  58.                             <input type="text" class="ts percentage form-control tranSQPer_${val.Sequence.replace(/\s/g, "")}"
  59.                              placeholder = "%"
  60.                             onkeypress="calPerTans('discount', 'tranSQPer_${val.Sequence.replace(/\s/g, "")}', 'tranSQAmt_${val.Sequence.replace(/\s/g, "")}')"
  61.                             id="tranSQPer_${val.Sequence.replace(/\s/g, "")}" />
  62.                             <input type="text" class="ts amt form-control tranSQAmt_${val.Sequence.replace(/\s/g, "")}"
  63.                             placeholder = "Amount"
  64.                             onkeypress="calTans('discount', 'tranSQAmt_${val.Sequence.replace(/\s/g, "")}', 'tranSQPer_${val.Sequence.replace(/\s/g, "")}')"
  65.                             id="tranSQAmt_${val.Sequence.replace(/\s/g, "")}" />
  66.                         </div>`;
  67.                     }
  68.                     else {
  69.                         h += ` <div><label>${val.Sequence} :</label>
  70.                             <input type="text" class="ts percentage form-control tranSQPer_${val.Sequence.replace(/\s/g, "")}"
  71.                             placeholder = "%"
  72.                             onkeypress="calPerTans('other', 'tranSQPer_${val.Sequence.replace(/\s/g, "")}', 'tranSQAmt_${val.Sequence.replace(/\s/g, "")}')"
  73.                             id="tranSQPer_${val.Sequence.replace(/\s/g, "")}" />
  74.                             <input type="text" class="ts amt form-control tranSQAmt_${val.Sequence.replace(/\s/g, "")}"
  75.                             placeholder = "Amount"
  76.                             onkeypress="calTans('other', 'tranSQAmt_${val.Sequence.replace(/\s/g, "")}', 'tranSQPer_${val.Sequence.replace(/\s/g, "")}')"
  77.                             id="tranSQAmt_${val.Sequence.replace(/\s/g, "")}" />
  78.                         </div>`;
  79.                     }
  80.                 }
  81.             });
  82.             $('#tranSeq').html(h);
  83.             $.each(data, (i, val) => {
  84.                 $('#tranSQAmt_' + val.Sequence.replace(/\s/g, "")).keypress(function (e) {
  85.                     if (e.which === 46) {
  86.                         if ($(this).val().indexOf('.') !== -1) {
  87.                             return false;
  88.                         }
  89.                     }
  90.                     if (e.which !== 8 && e.which !== 0 && e.which !== 46 && (e.which < 48 || e.which > 57)) {
  91.                         return false;
  92.                     }
  93.                 });
  94.                 $('#tranSQPer_' + val.Sequence.replace(/\s/g, "")).keypress(function (e) {
  95.                     if (e.which === 46) {
  96.                         if ($(this).val().indexOf('.') !== -1) {
  97.                             return false;
  98.                         }
  99.                     }
  100.                     if (e.which !== 8 && e.which !== 0 && e.which !== 46 && (e.which < 48 || e.which > 57)) {
  101.                         return false;
  102.                     }
  103.                 });
  104.             });
  105.         }
  106.     });
  107. }
  108. var transAmt = 0;
  109. function calTans(seq, id, sid) {
  110.     if (event.keyCode === 13) {
  111.         if (seq === 'first') {
  112.             transAmt = $('#billAmount').val();
  113.             $('.' + sid).val(parseFloat($('.' + id).val() / parseFloat(transAmt) * 100).toFixed(numberOfDecimal));
  114.             transAmt = parseFloat(transAmt) + parseFloat($('.' + id).val());
  115.         }
  116.         else if (seq === 'discount') {
  117.             transAmt = parseFloat($('#billAmount').val()) +
  118.                 parseFloat($('.' + id).parent().prev().find('input.ts.amt').val()) +
  119.                 parseFloat(typeof ($('.' + id).parent().prev().prev().find('input.ts.amt').val()) === 'undefined' ? 0 :
  120.                     parseFloat($('.' + id).parent().prev().prev().find('input.ts.amt').val()))
  121.                 - parseFloat($('.' + id).val());
  122.             $('.' + sid).val(parseFloat($('.' + id).val() / parseFloat(transAmt) * 100).toFixed(numberOfDecimal));
  123.         }
  124.         else {
  125.             transAmt = parseFloat($('#billAmount').val()) +
  126.                 parseFloat($('.' + id).parent().prev().find('input.ts.amt').val()) +
  127.                 parseFloat(typeof ($('.' + id).parent().prev().prev().find('input.ts.amt').val()) === 'undefined' ? 0 :
  128.                     parseFloat($('.' + id).parent().prev().prev().find('input.ts.amt').val()))
  129.                 + parseFloat($('.' + id).val());
  130.             $('.' + sid).val(parseFloat($('.' + id).val() / parseFloat(transAmt) * 100).toFixed(numberOfDecimal));
  131.         }
  132.         $('.' + sid).parent().next().find('input.ts').val('0');
  133.         $('.' + sid).parent().next().next().find('input.ts').val('0');
  134.         $('#totalAmount').val(parseFloat(transAmt).toFixed(numberOfDecimal));
  135.         $('#gtotal').text(parseFloat(transAmt).toFixed(numberOfDecimal));
  136.  
  137.         if (id === 'tranSQAmt_BillTax') {
  138.             BillTaxAmount = $('.' + id).val(); BillTaxPercentage = $('.' + sid).val();
  139.         }
  140.         else if (id === 'tranSQAmt_ExciseDuty') {
  141.             BillExciseDutyAmount = $('.' + id).val(); BillExciseDutyPercentage = $('.' + sid).val();
  142.         }
  143.         else if (id === 'tranSQAmt_BillDiscount') {
  144.             billDiscount = $('.' + id).val(); BillDiscountPercentage = $('.' + sid).val();
  145.         }
  146.  
  147.         $('.' + id).parent().next().find('input.percentage').focus();
  148.         $('.' + id).parent().next().find('input.percentage').val($('.' + id).parent().next().find('input.percentage').val()).focus();
  149.         event.preventDefault();
  150.         return false;
  151.     }
  152. }
  153.  
  154. function calPerTans(seq, id, sid) {
  155.     if (event.keyCode === 13) {
  156.         if (seq === 'first') {
  157.             transAmt = $('#billAmount').val();
  158.             $('.' + sid).val(parseFloat($('.' + id).val() * parseFloat(transAmt) / 100).toFixed(numberOfDecimal));
  159.             transAmt = parseFloat(transAmt) + parseFloat($('.' + id).val() * parseFloat(transAmt) / 100);
  160.  
  161.         }
  162.         else if (seq === 'discount') {
  163.             transAmt = parseFloat($('#billAmount').val()) +
  164.                 parseFloat($('.' + id).parent().prev().find('input.ts.amt').val()) +
  165.                 parseFloat(typeof ($('.' + id).parent().prev().prev().find('input.ts.amt').val()) === 'undefined' ? 0 :
  166.                     parseFloat($('.' + id).parent().prev().prev().find('input.ts.amt').val()));
  167.             $('.' + sid).val(parseFloat($('.' + id).val() * parseFloat(transAmt) / 100).toFixed(numberOfDecimal));
  168.             transAmt = parseFloat(transAmt) - parseFloat($('.' + id).val() * parseFloat(transAmt) / 100);
  169.         }
  170.         else {
  171.             transAmt = parseFloat($('#billAmount').val()) +
  172.                 parseFloat($('.' + id).parent().prev().find('input.ts.amt').val()) +
  173.                 parseFloat(typeof ($('.' + id).parent().prev().prev().find('input.ts.amt').val()) === 'undefined' ? 0 :
  174.                     parseFloat($('.' + id).parent().prev().prev().find('input.ts.amt').val()));
  175.             $('.' + sid).val(parseFloat($('.' + id).val() * parseFloat(transAmt) / 100).toFixed(numberOfDecimal));
  176.             transAmt = parseFloat(transAmt) + parseFloat($('.' + id).val() * parseFloat(transAmt) / 100);
  177.         }
  178.         $('.' + sid).parent().next().find('input.ts').val('0');
  179.         $('.' + sid).parent().next().next().find('input.ts').val('0');
  180.         $('#totalAmount').val(parseFloat(transAmt).toFixed(numberOfDecimal));
  181.         $('#gtotal').text(parseFloat(transAmt).toFixed(numberOfDecimal));
  182.  
  183.         if (id === 'tranSQPer_BillTax') {
  184.             BillTaxPercentage = $('.' + id).val(); BillTaxAmount = $('.' + sid).val();
  185.         }
  186.         else if (id === 'tranSQPer_ExciseDuty') {
  187.             BillExciseDutyPercentage = $('.' + id).val(); BillExciseDutyAmount = $('.' + sid).val();
  188.         }
  189.         else if (id === 'tranSQPer_BillDiscount') {
  190.             BillDiscountPercentage = $('.' + id).val(); billDiscount = $('.' + sid).val();
  191.         }
  192.         $('.' + id).parent().next().find('input.percentage').focus();
  193.         $('.' + id).parent().next().find('input.percentage').val($('.' + id).parent().next().find('input.percentage').val()).focus();
  194.         event.preventDefault();
  195.         return false;
  196.     }
  197. }
  198.  
  199. function CashOrPartyComboFill() {
  200.     $.ajax({
  201.         url: '/PurchaseInvoice/CashOrPartyComboFill',
  202.         type: 'get',
  203.         async: false,
  204.         data: { DbName: DbName },
  205.         success: function (data) {
  206.             $('#CashOrPartyComboFill').empty();
  207.             $('#CashOrPartyComboFill').append('<option value="0"> Choose one</option>');
  208.             $.each(data, function (i, item) {
  209.                 $('#CashOrPartyComboFill').append('<option value="' + item.ledgerId + '" data-agid="' + item.accountGroupId + '"> ' + item.ledgerName + '</option>');
  210.             });
  211.         },
  212.         error: function () {
  213.             toastr.error('system error');
  214.         }
  215.     });
  216. }
  217. function CashorBankorPartyComboFill() {
  218.     $.ajax({
  219.         url: '/PurchaseInvoice/CashorBankorPartyComboFill',
  220.         data: { DbName: DbName },
  221.         type: 'get',
  222.         async: false,
  223.         success: function (data) {
  224.             $('#cashPartyAdditional').empty();
  225.             $('#cashPartyAdditional').append('<option value="0"> Choose one</option>');
  226.             $.each(data, function (i, item) {
  227.                 $('#cashPartyAdditional').append('<option value="' + item.ledgerId + '" data-gid="' + item.accountGroupId + '"> ' + item.ledgerName + '</option>');
  228.             });
  229.         },
  230.         error: function () {
  231.             toastr.error('system error');
  232.         }
  233.     });
  234. }
  235. function PurchaseAccountComboFill() {
  236.     $.ajax({
  237.         url: '/PurchaseInvoice/PurchaseAccountComboFill',
  238.         data: { DbName: DbName },
  239.         type: 'get',
  240.         async: false,
  241.         success: function (data) {
  242.             $('#PurchaseAccountComboFill').empty();
  243.             $('#PurchaseAccountComboFill').append('<option value="0"> Choose one</option>');
  244.             $.each(data, function (i, item) {
  245.                 $('#PurchaseAccountComboFill').append('<option value="' + item.ledgerId + '"> ' + item.ledgerName + '</option>');
  246.             });
  247.         },
  248.         error: function () {
  249.             toastr.error('system error');
  250.         }
  251.     });
  252. }
  253. function AdditionalCostComboFill() {
  254.     $.ajax({
  255.         url: '/PurchaseInvoice/AdditionalCostComboFill',
  256.         data: { DbName: DbName },
  257.         type: 'get',
  258.         async: false,
  259.         success: function (data) {
  260.             $('#AdditionalCostComboFill').empty();
  261.             $('#AdditionalCostComboFill').append('<option value="0"> Choose one</option>');
  262.             $.each(data, function (i, item) {
  263.                 $('#AdditionalCostComboFill').append('<option value="' + item.ledgerId + '"> ' + item.ledgerName + '</option>');
  264.             });
  265.         },
  266.         error: function () {
  267.             toastr.error('system error');
  268.         }
  269.     });
  270. }
  271. function RackViewAllByGodownForCombo(id) {
  272.     $.ajax({
  273.         url: '/PurchaseInvoice/RackViewAllByGodownForCombo?DbName=' + DbName + '&GId=' + id,
  274.         type: 'get',
  275.         async: false,
  276.         success: function (data) {
  277.             $('#rackId').empty();
  278.             //$('#rackId').append('<option value="0"> Choose one</option>');
  279.             $.each(data, function (i, item) {
  280.                 $('#rackId').append('<option value="' + item.rackId + '"> ' + item.rackName + '</option>');
  281.             });
  282.         },
  283.         error: function () {
  284.             toastr.error('system error: rack loading error');
  285.         }
  286.     });
  287. }
  288. function UnitViewAllByProductId(id) {
  289.     $.ajax({
  290.         url: '/PurchaseInvoice/UnitViewAllByProductId?DbName=' + DbName + '&PId=' + id,
  291.         type: 'get',
  292.         async: false,
  293.         success: function (data) {
  294.             $('#unitId').empty();
  295.             $.each(data, function (i, item) {
  296.                 $('#unitId').append('<option value="' + item.unitId + '"> ' + item.unitName + '</option>');
  297.             });
  298.         },
  299.         error: function () {
  300.             toastr.error('system error');
  301.         }
  302.     });
  303. }
  304. function unitdp() {
  305.     $.ajax({
  306.         url: '/PurchaseInvoice/UnitAllComboFill?DbName=' + DbName,
  307.         type: 'get',
  308.         async: false,
  309.         success: function (data) {
  310.             $('#unitId').empty();
  311.             $('#unitId').append('<option value="0"> Choose one</option>');
  312.             $.each(data, function (i, item) {
  313.                 $('#unitId').append('<option value="' + item.unitId + '"> ' + item.unitName + '</option>');
  314.             });
  315.         },
  316.         error: function () {
  317.             toastr.error('system error');
  318.         }
  319.     });
  320. }
  321. function rackdp() {
  322.     $.ajax({
  323.         url: '/PurchaseInvoice/RackAllComboFill?DbName=' + DbName,
  324.         type: 'get',
  325.         async: false,
  326.         success: function (data) {
  327.             $('#rackId').empty();
  328.             $('#rackId').append('<option value="0"> Choose one</option>');
  329.             $.each(data, function (i, item) {
  330.                 $('#rackId').append('<option value="' + item.rackId + '"> ' + item.rackName + '</option>');
  331.             });
  332.         },
  333.         error: function () {
  334.             toastr.error('system error: rack loading error');
  335.         }
  336.     });
  337. }
  338. function caldiscount() {
  339.     totalInvoice = $('#netTotalF').text();
  340.     if ($('#gbillDiscount').val() >= 0) {
  341.         bilDis = $('#gbillDiscount').val();
  342.         amt = parseFloat($('#netTotalF').text()) - parseFloat($('#gbillDiscount').val());
  343.         gCosttoParty = parseFloat($('#CosttoParty').text()) + parseFloat($('#netTotalF').text()) - parseFloat($('#gbillDiscount').val());
  344.         $('#ginvoiceTotal').text(parseFloat(amt).toFixed(numberOfDecimal));
  345.         $('#billAmount').val(parseFloat(amt).toFixed(numberOfDecimal));
  346.         transAmt = $('#billAmount').val();
  347.         $('#totalAmount').val(parseFloat(amt).toFixed(numberOfDecimal));
  348.         $('#gCostToparty').text(parseFloat(gCosttoParty).toFixed(numberOfDecimal));
  349.         event.preventDefault();
  350.         if (isTax === 1) {
  351.             if (taxAmt === 0) {
  352.                 //check for vouchertype tax for auto tax add if individual tax for each item is zero
  353.                 $.ajax({
  354.                     url: '/PurchaseInvoice/VoucherTypeTaxGetByVoucherType?DbName=' + DbName,
  355.                     type: 'get',
  356.                     async: false,
  357.                     success: function (data) {
  358.                         //var rate = data.rate;
  359.                         if (data.rate !== 0 || data.rate !== '') {
  360.                             $('#gtaxAble').val(parseFloat(amt).toFixed(numberOfDecimal));
  361.                             taxAmt = parseFloat(data.rate) * amt / 100;
  362.                             amt = taxAmt + amt;
  363.                             $('#gTaxAmt').val(parseFloat(taxAmt).toFixed(numberOfDecimal));
  364.                             $('#gtotal').text(parseFloat(amt).toFixed(numberOfDecimal));
  365.                         }
  366.                         else {
  367.                             toastr.error('tax rate is zero');
  368.                         }
  369.                     },
  370.                     error: function () {
  371.                         toastr.error('system error');
  372.                     }
  373.                 });
  374.             }
  375.             else {
  376.                 $('#gtaxAble').val(parseFloat(taxable).toFixed(numberOfDecimal));
  377.                 $('#gTaxAmt').val(parseFloat(taxAmt).toFixed(numberOfDecimal));
  378.                 totalGrand = nonTaxable + taxable + parseFloat($('#gTaxAmt').val()) - parseFloat($('#gbillDiscount').val());
  379.                 //amt1 = totalGrand - bilDis;
  380.                 $('#gtotal').text(parseFloat(totalGrand).toFixed(numberOfDecimal));
  381.             }
  382.         }
  383.     }
  384.     grtGrandtotal();
  385. }
  386. function grtGrandtotal() {
  387.     var tadd = 0, tbd = 0, gin = 0;
  388.     if ($('#TotalAdditionalCost').text() > 0) {
  389.         tadd = $('#TotalAdditionalCost').text();
  390.     }
  391.     if ($('#gbillDiscount').val() > 0) {
  392.         tbd = 0;
  393.     }
  394.     if ($('#ginvoiceTotal').text() > 0) {
  395.         gin = $('#ginvoiceTotal').text();
  396.     }
  397.     totalGrand = parseFloat(tadd) + parseFloat(tbd) + parseFloat(gin);
  398.     $('#gtotal').text(parseFloat(totalGrand).toFixed(numberOfDecimal));
  399. }
  400. function getAllProduct() {
  401.     $.ajax({
  402.         url: '/PurchaseInvoice/ProductbyName?DbName=' + DbName + '&name=' + '',
  403.         type: 'get',
  404.         async: false,
  405.         success: function (data) {
  406.             $('#productName').empty();
  407.             //$('#productName').append('<option value="0"> Choose one </option>');
  408.             $.each(data, function (k, item) {
  409.                 $('#productName').append('<option value="' + item.productCode + '"> ' + item.productName + ' </option>');
  410.             });
  411.         }
  412.     });
  413. }
  414. function checkvendorInvoiceNoIfExist(vendorInvoiceNo) {
  415.     $.ajax({
  416.         url: '/PurchaseInvoice/checkvendorInvoiceNoIfExist?DbName=' + DbName + '&vendorInvoiceNo=' + vendorInvoiceNo,
  417.         type: 'get',
  418.         async: false,
  419.         success: function (data) {
  420.             if (data === 1 || data === '1') {
  421.                 toastr.error("This bill number has been entered already!");
  422.             }
  423.         },
  424.         error: function (data) { toastr.error(data); }
  425.     });
  426. }
  427. function ChargeGet_ByProductId(productId) {
  428.     $.ajax({
  429.         url: '/PurchaseInvoice/ChargeGet_ByProductId',
  430.         type: 'get',
  431.         data: {
  432.             productId: productId
  433.         },
  434.         async: false,
  435.         success: function (data) {
  436.             $('#chargeId').empty();
  437.             if (data.length > 0) {
  438.                 $('#chargeId').append('<option value="1">N/A</option>');
  439.                 $.each(data, function (k, item) {
  440.                     $('#chargeId').append('<option value="' + item.taxId + '"> ' + item.taxName + ' </option>');
  441.                 });
  442.             }
  443.             else {
  444.                 $('#chargeId').append('<option value="1">N/A</option>');
  445.             }
  446.         }
  447.     });
  448. }
  449.  
  450. function calproDiscountbyper() {
  451.     if ($('#disPer').val() <= 100) {
  452.         var discper = $('#disPer').val();
  453.         discamt = (discper / 100) * $('#grossValue').val();
  454.         $('#disAmt').val(parseFloat(discamt).toFixed(numberOfDecimal));
  455.         $('#Netamt').val(parseFloat(parseFloat($('#grossValue').val() - discamt)).toFixed(numberOfDecimal));
  456.     }
  457.     else {
  458.         toastr.info('Discount is more than 100%');
  459.     }
  460.     calTax();
  461. }
  462. function calprodDiscountbyAmt() {
  463.     var discamt = $('#disAmt').val();
  464.     var disPerA = parseFloat(discamt * 100 / $('#grossValue').val());
  465.     var dispers = parseInt($('#rate').val()) === 0 ? 0 : disPerA;
  466.     $('#disPer').val(parseFloat(dispers).toFixed(numberOfDecimal));
  467.     $('#Netamt').val(parseFloat($('#grossValue').val() - discamt).toFixed(numberOfDecimal));
  468.     calTax();
  469. }
  470. function PopUp(data) {
  471.     var mywindow = window.open('', '', 'left=0,top=0,width=950,height=600,toolbar=0,scrollbars=0,status=0,addressbar=0');
  472.     var is_chrome = Boolean(mywindow.chrome);
  473.     var isPrinting = false;
  474.     mywindow.document.write(data);
  475.     mywindow.document.close(); // necessary for IE >= 10 and necessary before onload for chrome
  476.     if (is_chrome) {
  477.         mywindow.onload = function () { // wait until all resources loaded
  478.             isPrinting = true;
  479.             mywindow.focus(); // necessary for IE >= 10
  480.             mywindow.print();  // change window to mywindow
  481.             //mywindow.close();// change window to mywindow
  482.             isPrinting = false;
  483.         };
  484.         //if (!isPrinting) {
  485.         //    mywindow.print(); //mywindow.close();
  486.         //}
  487.         setTimeout(function () {
  488.             if (!isPrinting) {
  489.                 mywindow.print();
  490.                 mywindow.close();
  491.             }
  492.         }, 300);
  493.     }
  494.     else {
  495.         mywindow.document.close(); // necessary for IE >= 10
  496.         mywindow.focus(); // necessary for IE >= 10
  497.         mywindow.print();
  498.         mywindow.close();
  499.     }
  500.     return true;
  501. }
  502.  
  503. function PrintVoucher(invoiceno) {
  504.     var name = 'Purchase';
  505.     $.ajax({
  506.         url: '/VoucherPrint/PurchasePrint?DbName=' + DbName + '&typename=' + name + '&invoiceno=' + invoiceno + '&voucherTypeid=13',
  507.         type: "POST",
  508.         dataType: "JSON",
  509.         contentType: "application/json,charset=utf-8",
  510.         success: function (data) {
  511.             PopUp(data);
  512.             $('#loading').fadeOut();
  513.             $('#save').modal('hide');
  514.         }
  515.     });
  516. }
  517.  
  518. function checkMaterialOrderCmp() {
  519.     count = localStorage.length;
  520.     if (localStorage.length > 0) {
  521.         for (var i = 0; i < localStorage.length; i++) {
  522.             if (localStorage.getItem('keyPI' + i)) {
  523.                 if (JSON.parse(localStorage.getItem('keyPI' + i)).action === 'Accepted') {
  524.                     count = count;
  525.                 }
  526.                 else {
  527.                     count -= 1;
  528.                 }
  529.             }
  530.             else {
  531.                 count -= 1;
  532.             }
  533.  
  534.         }
  535.     }
  536.     if (count === 0) {
  537.         return false;
  538.     }
  539.     else {
  540.         return true;
  541.     }
  542. }
  543. function checkPurchaseOrderCmp() {
  544.     count = localStorage.length;
  545.     if (localStorage.length > 0) {
  546.         for (var i = 0; i < localStorage.length; i++) {
  547.             if (localStorage.getItem('keyPI' + i)) {
  548.                 if (JSON.parse(localStorage.getItem('keyPI' + i)).action === 'Accepted') {
  549.                     count = count;
  550.                 }
  551.                 else {
  552.                     count -= 1;
  553.                 }
  554.             }
  555.             else {
  556.                 count -= 1;
  557.             }
  558.  
  559.         }
  560.     }
  561.     if (count === 0) {
  562.         return false;
  563.     }
  564.     else {
  565.         return true;
  566.     }
  567. }
  568.  
  569. $(function () {
  570.     $("#ExAD").datepicker({
  571.         dateFormat: "mm/dd/yy",
  572.         minDate: 'today',
  573.         showButtonPanel: true,
  574.         changeYear: true,
  575.         changeMonth: true
  576.     }).datepicker('setDate', 'today');
  577.  
  578.     $('#save').on('hidden.bs.modal', function () {
  579.         $('#loading').fadeOut();
  580.     });
  581.     $('#update').on('hidden.bs.modal', function () {
  582.         $('#loading').fadeOut();
  583.     });
  584.     $(".PrintBill").prop('checked', true);
  585.     $(".btnprintyes").on("click", function () {
  586.         invoiceno = $(this).data('invoiceno');
  587.         PrintVoucher(invoiceno);
  588.     });
  589.     //clearPI localstorage
  590.     resetForm();
  591.     clearPI();
  592.     getSequence();
  593.     //show btns
  594.     $('#btnPISave').show();
  595.     $('#btnPIUpdate').hide();
  596.     $('#PInarration').addClass('active');
  597.     $('.savePI').addClass('active');
  598.     $('.updatePI').addClass('active');
  599.     $('.resetPI').addClass('active');
  600.     $('#ImportValue').addClass('disabled');
  601.     $('#ImportValue').prop('disabled', true);
  602.     $('#crPeriod').val('0');
  603.     //load CashOrPartyComboFill
  604.     CashOrPartyComboFill();
  605.  
  606.     //load VoucherTypeSelectionComboFill
  607.     //VoucherType();
  608.  
  609.     //load CashorBankorPartyComboFill
  610.     CashorBankorPartyComboFill();
  611.     //load PurchaseAccountComboFill
  612.     PurchaseAccountComboFill();
  613.     //load UnitAllComboFill
  614.     unitdp();
  615.     //load RackViewAll
  616.     rackdp();
  617.     //load AdditionalCostComboFill
  618.     AdditionalCostComboFill();
  619.     //load tax dp
  620.     $.ajax({
  621.         url: '/PurchaseInvoice/TaxViewForDp?DbName=' + DbName,
  622.         type: 'get',
  623.         async: false,
  624.         success: function (data) {
  625.             $('#taxId').empty();
  626.             //$('#taxId').append('<option value="0"> All</option>');
  627.             $.each(data, function (i, item) {
  628.                 $('#taxId').append('<option value="' + item.taxId + '"> ' + item.taxName + '</option>');
  629.             });
  630.         },
  631.         error: function () {
  632.             toastr.error('system error');
  633.         }
  634.     });
  635.     //load godown dp
  636.     $.ajax({
  637.         url: '/PurchaseInvoice/GodownForDp?DbName=' + DbName,
  638.         type: 'get',
  639.         async: false,
  640.         success: function (data) {
  641.             $('#goDownid').empty();
  642.             $('#goDownid').append('<option value="0"> Choose one</option>');
  643.             $.each(data, function (i, item) {
  644.                 $('#goDownid').append('<option value="' + item.godownId + '"> ' + item.godownName + '</option>');
  645.             });
  646.         },
  647.         error: function () {
  648.             toastr.error('system error');
  649.         }
  650.     });
  651.     //load product name
  652.     getAllProduct();
  653.     //product code input
  654.     $('#productCode').keydown(function (e) {
  655.         if (event.keyCode === 13 || event.keyCode === 9) {
  656.  
  657.             unitdp();
  658.             rackdp();
  659.             if ($('#productCode').val() === '') {
  660.                 //$('#ProductList').modal('show');
  661.                 $('#productName').focus();
  662.  
  663.             }
  664.             else {
  665.                 $('#productName').val($('#productCode').val()).select2();
  666.                 productName = $('#productName').children('option').filter(':selected').text();
  667.                 if (typeOfVoucher === 'NA' || $('#purchaseMode').children('option').filter(':selected').text() === 'NA') {
  668.                     //$('#productCode').val($('#productName').val());
  669.                     productName = $('#productName').children('option').filter(':selected').text();
  670.                     ProductDetailsgetPerticlular($('#productName').val());
  671.                     $('#qty').val('0');
  672.                     $('#batchId').val('');
  673.                     $('#disPer').val('0');
  674.                     $('#grossValue').val('0');
  675.                     $('#disAmt').val('0');
  676.                     $('#Netamt').val('0');
  677.                     $('#ImportValue').val('0');
  678.                     $('#taxAmt').val('0');
  679.                     $('#NetTotal').val('0');
  680.                 }
  681.                 else if (typeOfVoucher === 'Material Receipt' || $('#purchaseMode').children('option').filter(':selected').text() === 'Material Receipt') {
  682.                     materialReceiptDetailsId = $('#productName').children('option').filter(':selected').data('materialreceiptdetailsid');
  683.                     //$('#productCode').val($('#productName').val());
  684.                     productName = $('#productName').children('option').filter(':selected').text();
  685.                     GetProductDetailsFromMaterialReceiptDetails($('#productName').val(), materialReceiptDetailsId);
  686.                 }
  687.                 else if (typeOfVoucher === 'Purchase Order' || $('#purchaseMode').children('option').filter(':selected').text() === 'Purchase Order') {
  688.                     purchaseOrderDetailsId = $('#productName').children('option').filter(':selected').data('purchaseorderdetailsid');
  689.                     //$('#productCode').val($('#productName').val());
  690.                     productName = $('#productName').children('option').filter(':selected').text();
  691.                     GetProductDetailsFromPurchaseOrderDetails($('#productName').val(), purchaseOrderDetailsId);
  692.                 }
  693.             }
  694.             e.preventDefault();
  695.             return false;
  696.         }
  697.         else if (e.altKey && (event.keyCode === 78)) {
  698.             $('#productName').select2('close');
  699.             $('#ProductModal').modal('show');
  700.             e.preventDefault();
  701.             return false;
  702.         }
  703.     });
  704.     //ProductDetailsgetbyName
  705.     //$('#productName').keydown(function () {
  706.     //    if (event.keyCode === 13) {
  707.     //        $('#ProductList').modal('show');
  708.     //        //$('#modalHit').trigger('click');
  709.     //    }
  710.     //});
  711.     $('#productName').on('select2:close', function () {
  712.         unitdp();
  713.         rackdp();
  714.         if (typeOfVoucher === 'NA' || $('#purchaseMode').children('option').filter(':selected').text() === 'NA') {
  715.             if ($('#productName').val() > 0 || $('#productName').val() !== '') {
  716.                 $('#productCode').val($('#productName').val());
  717.                 productName = $('#productName').children('option').filter(':selected').text();
  718.                 ProductDetailsgetPerticlular($('#productName').val());
  719.             }
  720.             else {
  721.                 setTimeout(function () { $('#productName').focus(); }, 500);
  722.             }
  723.             $('#qty').val('0');
  724.             $('#batchId').val('');
  725.             $('#disPer').val('0');
  726.             $('#grossValue').val('0');
  727.             $('#disAmt').val('0');
  728.             $('#Netamt').val('0');
  729.             $('#ImportValue').val('0');
  730.             $('#taxAmt').val('0');
  731.             $('#NetTotal').val('0');
  732.         }
  733.         else if (typeOfVoucher === 'Material Receipt' || $('#purchaseMode').children('option').filter(':selected').text() === 'Material Receipt') {
  734.             if ($('#productName').val() > 0 || $('#productName').val() !== '') {
  735.                 materialReceiptDetailsId = $('#productName').children('option').filter(':selected').data('materialreceiptdetailsid');
  736.                 $('#productCode').val($('#productName').val());
  737.                 productName = $('#productName').children('option').filter(':selected').text();
  738.                 GetProductDetailsFromMaterialReceiptDetails($('#productName').val(), materialReceiptDetailsId);
  739.             }
  740.             else {
  741.                 setTimeout(function () { $('#productName').focus(); }, 500);
  742.             }
  743.         }
  744.         else if (typeOfVoucher === 'Purchase Order' || $('#purchaseMode').children('option').filter(':selected').text() === 'Purchase Order') {
  745.             if ($('#productName').val() > 0 || $('#productName').val() !== '') {
  746.                 purchaseOrderDetailsId = $('#productName').children('option').filter(':selected').data('purchaseorderdetailsid');
  747.                 $('#productCode').val($('#productName').val());
  748.                 productName = $('#productName').children('option').filter(':selected').text();
  749.                 GetProductDetailsFromPurchaseOrderDetails($('#productName').val(), purchaseOrderDetailsId);
  750.             }
  751.             else {
  752.                 setTimeout(function () { $('#productName').focus(); }, 500);
  753.             }
  754.         }
  755.     });
  756.  
  757.     $('#VoucherTypeSelectionComboFill').change(function () {
  758.         taxIdByVoucherType($('#VoucherTypeSelectionComboFill').val());
  759.     });
  760.     //calculation part
  761.     $('#qty').on('input', function () {
  762.         if ($('#rate').val() !== '') {
  763.             var amt = parseFloat($('#rate').val() * $('#qty').val());
  764.             $('#grossValue').val(amt);
  765.             $('#Netamt').val(amt);
  766.             $('#NetTotal').val(amt);
  767.             calprodDiscountbyAmt();
  768.         }
  769.     });
  770.     $('#rate').on('input', function () {
  771.         if ($('#qty').val() !== '') {
  772.             var amt = parseFloat($('#rate').val() * $('#qty').val());
  773.             $('#grossValue').val(amt);
  774.             $('#Netamt').val(amt);
  775.             $('#NetTotal').val(amt);
  776.             calprodDiscountbyAmt();
  777.         }
  778.     });
  779.     $('#disPer').keydown(function (e) {
  780.         if (event.keyCode === 13) {
  781.             if ($('#disPer').val() !== '0' || $('#disPer').val() !== '') {
  782.                 calproDiscountbyper();
  783.             }
  784.             $('#disAmt').focus();
  785.         }
  786.     });
  787.     $('#disAmt').keydown(function (e) {
  788.         if (event.keyCode === 13) {
  789.             if ($('#disAmt').val() !== '0' || $('#disAmt').val() !== '') {
  790.                 calprodDiscountbyAmt();
  791.             }
  792.  
  793.             setTimeout(function () { $('#chargeId').focus(); }, 100);
  794.         }
  795.     });
  796.  
  797.     $('#chargeId').on('select2:close', function () {
  798.         if (parseInt($('#chargeId').val()) > 0) {
  799.             calCharge();
  800.  
  801.             if ($('#ImportValue').hasClass('disabled')) {
  802.                 if ($('#taxId').hasClass('disabled')) {
  803.                     setTimeout(function () { $('#addBill').focus(); }, 200);
  804.                 }
  805.                 else {
  806.                     setTimeout(function () { $('#taxId').focus(); }, 200);
  807.                 }
  808.             }
  809.             else {
  810.                 setTimeout(function () { $('#ImportValue').focus(); }, 200);
  811.             }
  812.         }
  813.     });
  814.  
  815.     $('#ImportValue').on('input', function () {
  816.         NetAmtWithImport = parseFloat($('#ImportValue').val());
  817.         calTax();
  818.     });
  819.     //clearPI local storage
  820.     //add to dispaly table
  821.     var thistaxamt = 0;
  822.     $('#addBill').on('click', function () {
  823.         if ($('#productCode').val() === '') {
  824.             $('#productCode').focus();
  825.             toastr.info('Purchase code is empty');
  826.         }
  827.         else {
  828.             if ($('#qty').val() === '' || $('#qty').val() === '0') {
  829.                 $('#qty').focus();
  830.                 toastr.info('Quantity is empty');
  831.             }
  832.             else {
  833.                 if ($('#rate').val() === '' || $('#rate').val() === '0') {
  834.                     if ($('.isFreeQTY').is(':checked')) {
  835.                         addProductsGrid();
  836.                     }
  837.                     else {
  838.                         $('#rate').focus();
  839.                         toastr.info('Rate is empty');
  840.                     }
  841.                 }
  842.                 else {
  843.                     addProductsGrid();
  844.                 }
  845.             }
  846.         }
  847.         $('#PInarration').addClass('active');
  848.     });
  849.     //add additional cost
  850.     $('#additionalBtn').click(function () {
  851.         if ($('#AdditionalCostComboFill').val() === '0') {
  852.             $('#AdditionalCostComboFill').focus();
  853.             toastr.info('Please select ledger');
  854.         }
  855.         else {
  856.             if ($('#cashPartyAdditional').val() === '0') {
  857.                 $('#cashPartyAdditional').focus();
  858.                 toastr.info('Please select cash or party');
  859.             }
  860.             else {
  861.                 if ($('#additionalAmt').val() === '0' || $('#additionalAmt').val() === '') {
  862.                     $('#additionalAmt').focus();
  863.                     toastr.info('Please add Amount');
  864.                 }
  865.                 else {
  866.                     var i = 0;
  867.                     while (localStorage.getItem('keyAdd' + i)) {
  868.                         i++;
  869.                     }
  870.                     var check = checkAddtionalLedger();
  871.                     if (check) {
  872.                         toastr.info('Ledger name exist in table below. Please Edit and Update');
  873.                     }
  874.                     else {
  875.                         TotalAdditionalCost += parseFloat($('#additionalAmt').val());
  876.                         $('#TotalAdditionalCost').text(parseFloat(TotalAdditionalCost).toFixed(numberOfDecimal));
  877.                         //if ($('#cashPartyAdditional').find('option:selected').data('gid') === 27 ||
  878.                         //    $('#cashPartyAdditional').find('option:selected').data('gid') === 28) {
  879.                         //    $('#TotalAdditionalCost').text(parseFloat(TotalAdditionalCost).toFixed(numberOfDecimal));
  880.                         //}
  881.                         //else {
  882.                         //    CosttoParty += parseFloat($('#additionalAmt').val());
  883.                         //    if ($('#CashOrPartyComboFill').val() === $('#cashPartyAdditional').val()) {
  884.                         //        gCosttoParty += parseFloat(TotalAdditionalCost);
  885.                         //    }
  886.                         //    $('#CosttoParty').text(parseFloat(CosttoParty).toFixed(numberOfDecimal));
  887.                         //    $('#gCostToparty').text(parseFloat(gCosttoParty).toFixed(numberOfDecimal));
  888.                         //    $('#TotalAdditionalCost').text(parseFloat(TotalAdditionalCost).toFixed(numberOfDecimal));
  889.                         //}
  890.                         if ($('#CashOrPartyComboFill').val() === $('#cashPartyAdditional').val()) {
  891.                             CosttoParty += parseFloat($('#additionalAmt').val());
  892.                         }
  893.                         $('#CosttoParty').text(parseFloat(CosttoParty).toFixed(numberOfDecimal));
  894.                         gCosttoParty = parseFloat(CosttoParty) + parseFloat($('#ginvoiceTotal').text());
  895.                         $('#gCostToparty').text(parseFloat(gCosttoParty).toFixed(numberOfDecimal));
  896.                         $('#TotalAdditionalCost').text(parseFloat(TotalAdditionalCost).toFixed(numberOfDecimal));
  897.                         if (isAddTax === 1) {
  898.                             taxable += parseFloat($('#additionalAmt').val());
  899.                         }
  900.                         else {
  901.                             nonTaxable += parseFloat($('#additionalAmt').val());
  902.                         }
  903.                         var discount = 0;
  904.                         if ($('#gbillDiscount').val() > 0) {
  905.                             discount = $('#gbillDiscount').val();
  906.                         }
  907.                         totalGrand = parseFloat($('#TotalAdditionalCost').text()) + parseFloat($('#ginvoiceTotal').text()) + parseFloat(discount);
  908.                         totalInvoice = $('#netTotalF').text();
  909.                         $('#NonTaxableAmt').text(parseFloat(nonTaxable).toFixed(numberOfDecimal));
  910.                         $('#gtotal').text(parseFloat(totalGrand).toFixed(numberOfDecimal));
  911.                         //$('#ginvoiceTotal').text(parseFloat(totalInvoice).toFixed(numberOfDecimal));
  912.                         localStorage.setItem('keyAdd' + i, JSON.stringify({
  913.                             keyidAdd: i,
  914.                             AdditionalLedger: $('#AdditionalCostComboFill').val(),
  915.                             addcostid: addcostid,
  916.                             AddLedgerName: $('#AdditionalCostComboFill').children('option').filter(':selected').text(),
  917.                             AdditionalCashparty: $('#cashPartyAdditional').val(),
  918.                             AddCashpartyName: $('#cashPartyAdditional').children('option').filter(':selected').text(),
  919.                             AddtionalAmount: $('#additionalAmt').val(),
  920.                             isAddTax: isAddTax
  921.                         }));
  922.                         if (i > lastkeyAdd) {
  923.                             lastkeyAdd = i;
  924.                         }
  925.                         resetAdditional();
  926.                         //clearparty();
  927.                         showTableAddtional();
  928.                         $('#AdditionalCostComboFill').focus();
  929.                     }
  930.                 }
  931.             }
  932.         }
  933.     });
  934.     //give bill discount
  935.     $('#gbillDiscount').keydown(function () {
  936.         if (event.keyCode === 13) {
  937.             caldiscount();
  938.             $('#PInarration').focus();
  939.         }
  940.     });
  941.     //select2 dropdown
  942.     $('#PurchaseAccountComboFill').select2();
  943.     $('#CashOrPartyComboFill').select2();
  944.     $('#purchaseMode').val(0).select2();
  945.     $('#VoucherTypeSelectionComboFill').val('0').select2();
  946.     $('#orderNo').select2();
  947.     $('#ReceiptNo').select2();
  948.     $('#unitId').select2();
  949.     $('#goDownid').select2();
  950.     $('#rackId').select2();
  951.     $('#chargeId').select2();
  952.     $('#taxId').select2();
  953.     $('#AdditionalCostComboFill').select2();
  954.     $('#cashPartyAdditional').select2();
  955.     $('#productName').select2();
  956.     //on focus
  957.     //setTimeout(function () {
  958.     //    $('#PurchaseAccountComboFill').focus();
  959.     //}, 200);
  960.     $("#InAD").change(function (event) {
  961.         $('#InBS').focus();
  962.         $('#InBS').trigger('click');
  963.     });
  964.     $("#InBS").on("dateSelect", function (event) {
  965.         $('#VAD').focus();
  966.         $('.nepali-date-picker').hide();
  967.     });
  968.     $('#InAD').keydown(function () {
  969.         if (event.keyCode === 13) {
  970.             $('#InBS').focus();
  971.             $('#InBS').trigger('click');
  972.             event.preventDefault();
  973.             return false;
  974.         }
  975.     });
  976.     $('#InBS').keydown(function () {
  977.         if (event.keyCode === 13) {
  978.             $('#VAD').focus();
  979.             $('.nepali-date-picker').hide();
  980.             event.preventDefault();
  981.             return false;
  982.         }
  983.     });
  984.     $('#VAD').keydown(function () {
  985.         if (event.keyCode === 13) {
  986.             $('#VBS').focus();
  987.             $('#VBS').trigger('click');
  988.             event.preventDefault();
  989.             return false;
  990.         }
  991.     });
  992.     $('#VBS').keydown(function () {
  993.         if (event.keyCode === 13) {
  994.             $('#CashOrPartyComboFill').focus();
  995.             $('.nepali-date-picker').hide();
  996.             event.preventDefault();
  997.             return false;
  998.         }
  999.     });
  1000.     $("#VAD").change(function (event) {
  1001.         $('#VBS').focus();
  1002.         $('#VBS').trigger('click');
  1003.     });
  1004.     $("#VBS").on("dateSelect", function (event) {
  1005.         $('#CashOrPartyComboFill').focus();
  1006.         $('.nepali-date-picker').hide();
  1007.     });
  1008.     $('#qty').on('keydown', function () {
  1009.         if (event.keyCode === 13) {
  1010.             if ($('#qty').val() === '' || $('#qty').val() === '0') {
  1011.                 $('#qty').focus();
  1012.             }
  1013.             else {
  1014.                 if ($('#unitId').hasClass('disabled')) {
  1015.                     if ($('#rate').hasClass('disabled')) {
  1016.                         $('#goDownid').focus();
  1017.                     }
  1018.                     else {
  1019.                         $('#rate').focus();
  1020.                     }
  1021.                 }
  1022.                 else {
  1023.                     $('#unitId').focus();
  1024.                 }
  1025.             }
  1026.         }
  1027.     });
  1028.     $('#rate').on('keydown', function () {
  1029.         if (event.keyCode === 13) {
  1030.             if ($('#qty').val() !== '') {
  1031.                 var amt = parseFloat($('#rate').val() * $('#qty').val());
  1032.                 $('#grossValue').val(amt);
  1033.                 $('#Netamt').val(amt);
  1034.                 $('#NetTotal').val(amt);
  1035.                 calprodDiscountbyAmt();
  1036.             }
  1037.             if ($('#rate').val() === '' || $('#rate').val() === '0') {
  1038.                 if ($('.isFreeQTY').is(':checked')) {
  1039.                    
  1040.                     if (!$('#goDownid').hasClass('disabled')) {
  1041.                         setTimeout(function () {
  1042.                             $('#goDownid').focus();
  1043.                         }, 200);
  1044.                     }
  1045.                     else if (!$('#rackId').hasClass('disabled')) {
  1046.                         setTimeout(function () {
  1047.                             $('#rackId').focus();
  1048.                         }, 200);
  1049.                     }
  1050.                     else {
  1051.                         $('#batchId').focus();
  1052.                     }
  1053.                 }
  1054.                 else {
  1055.                     $('#rate').focus();
  1056.                 }
  1057.             }
  1058.             else if (!$('#goDownid').hasClass('disabled')) {
  1059.                 setTimeout(function () {
  1060.                     $('#goDownid').focus();
  1061.                 }, 200);
  1062.             }
  1063.             else if (!$('#rackId').hasClass('disabled')) {
  1064.                 setTimeout(function () {
  1065.                     $('#rackId').focus();
  1066.                 }, 200);
  1067.             }
  1068.             else {
  1069.                 $('#batchId').focus();
  1070.             }
  1071.         }
  1072.     });
  1073.     $("#ExAD").change(function (event) {
  1074.         $('#disPer').focus();
  1075.     });
  1076.     $('#ExAD').keydown(function () {
  1077.         if (event.keyCode === 13) {
  1078.             $('#disPer').focus();
  1079.             event.preventDefault();
  1080.             return false;
  1081.         }
  1082.     });
  1083.     $('#PurchaseAccountComboFill').on('select2:close', function () {
  1084.         if ($('#PurchaseAccountComboFill').val() === '0') {
  1085.             $('#PurchaseAccountComboFill').focus();
  1086.         }
  1087.         else {
  1088.             setTimeout(function () {
  1089.                 $('#invoiceNo').focus();
  1090.             }, 200);
  1091.             //tax // import // free // check
  1092.             $.ajax({
  1093.                 url: '/PurchaseInvoice/AccountLedgerIdGetbyId?DbName=' + DbName + '&id=' + $('#PurchaseAccountComboFill').val(),
  1094.                 async: false,
  1095.                 type: 'get',
  1096.                 success: function (data) {
  1097.                     //  isfree  isimport  isfixedpurchased  iseffectonvat
  1098.                     if (data.isfree === 1) {
  1099.                         isfree = 1;
  1100.                     }
  1101.                     if (data.isimport === 1) {
  1102.                         isImport = 1;
  1103.                     }
  1104.                     if (data.iseffectonvat === 1) {
  1105.                         isTax = 1;
  1106.                     }
  1107.                 }
  1108.             });
  1109.             $('#taxId').prop('disabled', true);
  1110.             $('#taxId').val('0').select2();
  1111.             if (isTax === 1) {
  1112.                 $('#ImportValue').addClass('disabled');
  1113.                 $('#ImportValue').prop('disabled', true);
  1114.             }
  1115.             if (isfree === 1) {
  1116.                 $('#taxId').prop('disabled', true);
  1117.                 $('#taxId').val('0').select2();
  1118.                 $('#ImportValue').addClass('disabled');
  1119.                 $('#ImportValue').prop('disabled', true);
  1120.             }
  1121.             if (isImport === 1) {
  1122.                 $('#ImportValue').removeClass('disabled');
  1123.                 $('#ImportValue').prop('disabled', false);
  1124.             }
  1125.         }
  1126.     });
  1127.     $('#CashOrPartyComboFill').on('select2:close', function () {
  1128.         if ($('#CashOrPartyComboFill').val() === '0') {
  1129.             $('#CashOrPartyComboFill').focus();
  1130.             accountgpId = 0;
  1131.         }
  1132.         else {
  1133.             accountgpId = parseInt($('#CashOrPartyComboFill').find("option:selected").attr("data-agid"));
  1134.             if (parseInt(accountgpId) === 27) {
  1135.                 $.ajax({
  1136.                     type: 'get',
  1137.                     async: false,
  1138.                     url: '/PaymentVoucher/BalanceCheckWithLedgerID?DbName=' + DbName + '&ledgerId=' + $("#CashOrPartyComboFill").val(),
  1139.                     success: function (data) {
  1140.                         CashAmount = data.balance;
  1141.                     },
  1142.                     error: function () {
  1143.                     }
  1144.                 });
  1145.             }
  1146.             setTimeout(function () {
  1147.                 $('#crPeriod').focus();
  1148.             }, 200);
  1149.             ledgerId = $('#CashOrPartyComboFill').val();
  1150.             $('#cashPartyAdditional').val($('#CashOrPartyComboFill').val()).select2();
  1151.         }
  1152.     });
  1153.  
  1154.     $('#purchaseMode').on('select2:close', function () {
  1155.         if ($('#purchaseMode').val() === '0') {
  1156.             typeOfVoucher = 'NA';
  1157.             $('#VoucherTypeSelectionComboFill').empty();
  1158.             $("#VoucherTypeSelectionComboFill").append('<option value="0">NA</option>');
  1159.             setTimeout(function () {
  1160.                 $('.VoucherType').addClass('displayNone');
  1161.                 $('#divOrderNo').addClass('displayNone');
  1162.                 $('#divReceiptNo').addClass('displayNone');
  1163.                 $('#productCode').focus();
  1164.             }, 200);
  1165.         }
  1166.         else {
  1167.             if ($('#purchaseMode').val() === 'Against PurchaseOrder') {
  1168.                 //$('#labelName').text('Order No.');
  1169.                 typeOfVoucher = 'Purchase Order';
  1170.                 VoucherTypeSelectionComboFill(typeOfVoucher);
  1171.                 GetPurchaseOrderNoForPurchaseInvoice();
  1172.                 setTimeout(function () {
  1173.                     $('.VoucherType').removeClass('displayNone');
  1174.                     $('#divOrderNo').removeClass('displayNone');
  1175.                     $('#divReceiptNo').addClass('displayNone');
  1176.                     $('#orderNo').focus();
  1177.                 }, 200);
  1178.             }
  1179.             else if ($('#purchaseMode').val() === 'Against MaterialReceipt') {
  1180.                 //$('#labelName').text('Material Receipt No.');
  1181.                 typeOfVoucher = 'Material Receipt';
  1182.                 VoucherTypeSelectionComboFill(typeOfVoucher);
  1183.                 GetMaterialReceiptNoForPurchaseInvoice();
  1184.                 setTimeout(function () {
  1185.                     $('.VoucherType').removeClass('displayNone');
  1186.                     $('#divOrderNo').addClass('displayNone');
  1187.                     $('#divReceiptNo').removeClass('displayNone');
  1188.                     $('#ReceiptNo').focus();
  1189.                 }, 200);
  1190.             }
  1191.         }
  1192.     });
  1193.  
  1194.     $('#ReceiptNo').on('select2:close', function () {
  1195.         if ($('#ReceiptNo').val() === '0') {
  1196.             setTimeout(function () {
  1197.                 $('#ReceiptNo').focus();
  1198.             }, 200);
  1199.         }
  1200.         else {
  1201.             ReceiptNo = $('#ReceiptNo').val();
  1202.             getMaterialMaster(ReceiptNo);
  1203.         }
  1204.     });
  1205.  
  1206.     $('#orderNo').on('select2:close', function () {
  1207.         if ($('#orderNo').val() === '0') {
  1208.             setTimeout(function () {
  1209.                 $('#orderNo').focus();
  1210.             }, 200);
  1211.         }
  1212.         else {
  1213.             orderNo = $('#orderNo').val();
  1214.             getPurchaseOrderMaster(orderNo);
  1215.         }
  1216.     });
  1217.  
  1218.     $('#invoiceNo').keydown(function () {
  1219.         if (event.keyCode === 13) {
  1220.             if ($('#invoiceNo').val().trim() !== '') {
  1221.                 checkvendorInvoiceNoIfExist($('#invoiceNo').val());
  1222.             }
  1223.             $('#InAD').focus();
  1224.             event.preventDefault();
  1225.             return false;
  1226.         }
  1227.     });
  1228.     var conversionRate = 0, thisrate = 0;
  1229.     $('#unitId').on('select2:close', function () {
  1230.         if ($('#unitId').val() === '0') {
  1231.             $('#unitId').focus();
  1232.         }
  1233.         else {
  1234.             if (ismultipleunit === 1) {
  1235.                 if ($('#unitId').children('option:first-child').is(':selected')) {
  1236.                     unitConversionId = 0; conversionRate = 0;
  1237.                     thisrate = originalRate;
  1238.                 }
  1239.                 else {
  1240.                     $.ajax({
  1241.                         url: '/PurchaseInvoice/UnitConversionrategetbyunitandproductID?DbName=' + DbName + '&productId=' + PId + '&unitId=' + $('#unitId').val(),
  1242.                         type: 'get',
  1243.                         async: false,
  1244.                         success: function (data) {
  1245.                             if (data !== "") {
  1246.                                 unitConversionId = data.unitConversionId; conversionRate = data.conversionRate;
  1247.                                 thisrate = conversionRate * originalRate;
  1248.                             }
  1249.                         }
  1250.                     });
  1251.                 }
  1252.                 $('#rate').val(thisrate);
  1253.                 if ($('#qty').val() !== '') {
  1254.                     var amt = parseFloat($('#rate').val() * $('#qty').val());
  1255.                     $('#grossValue').val(amt);
  1256.                     $('#Netamt').val(amt);
  1257.                     $('#NetTotal').val(amt);
  1258.                     calTax();
  1259.                 }
  1260.             }
  1261.             else {
  1262.                 unitConversionId = 0;
  1263.             }
  1264.             if ($('#rate').hasClass('disabled')) {
  1265.                 setTimeout(function () {
  1266.                     $('#goDownid').focus();
  1267.                 }, 200);
  1268.             }
  1269.             else {
  1270.                 setTimeout(function () {
  1271.                     $('#rate').focus();
  1272.                 }, 200);
  1273.             }
  1274.  
  1275.         }
  1276.     });
  1277.     $('#goDownid').on('select2:close', function () {
  1278.         if ($('#goDownid').val() === '0') {
  1279.             $('#goDownid').focus();
  1280.         }
  1281.         else {
  1282.             RackViewAllByGodownForCombo($('#goDownid').val());
  1283.             setTimeout(function () {
  1284.                 $('#rackId').focus();
  1285.             }, 200);
  1286.         }
  1287.     });
  1288.     $('#rackId').on('select2:close', function () {
  1289.         if ($('#rackId').val() === '0') {
  1290.             $('#rackId').focus();
  1291.         }
  1292.         else {
  1293.             if ($('#batchId').hasClass('disabled')) {
  1294.                 setTimeout(function () {
  1295.                     $('#disPer').focus();
  1296.                 }, 200);
  1297.             }
  1298.             else {
  1299.                 setTimeout(function () {
  1300.                     $('#batchId').focus();
  1301.                 }, 200);
  1302.             }
  1303.         }
  1304.     });
  1305.     $('#taxId').on('select2:close', function () {
  1306.         if ($('#taxId').val() === '0') {
  1307.             $('#taxId').focus();
  1308.         }
  1309.         else {
  1310.             calTax();
  1311.             setTimeout(function () { $('#addBill').focus(); }, 200);
  1312.         }
  1313.     });
  1314.     $('#AdditionalCostComboFill').on('select2:close', function () {
  1315.         if ($('#AdditionalCostComboFill').val() === '0') {
  1316.             $('#AdditionalCostComboFill').focus();
  1317.         }
  1318.         else {
  1319.             //tax // import // free // check
  1320.             $.ajax({
  1321.                 url: '/PurchaseInvoice/AccountLedgerIdGetbyId?DbName=' + DbName + '&id=' + $('#AdditionalCostComboFill').val(),
  1322.                 async: false,
  1323.                 type: 'get',
  1324.                 success: function (data) {
  1325.                     if (data.iseffectonvat === 1) {
  1326.                         isAddTax = 1;
  1327.                     }
  1328.                 }
  1329.             });
  1330.             setTimeout(function () {
  1331.                 $('#cashPartyAdditional').focus();
  1332.             }, 200);
  1333.         }
  1334.     });
  1335.     $('#cashPartyAdditional').on('select2:close', function () {
  1336.         if ($('#cashPartyAdditional').val() === '0') {
  1337.             $('#cashPartyAdditional').focus();
  1338.         }
  1339.         else {
  1340.             setTimeout(function () {
  1341.                 $('#additionalAmt').focus();
  1342.             }, 200);
  1343.         }
  1344.     });
  1345.  
  1346.     //event of focus
  1347.     $('#crPeriod').focus(function () {
  1348.         $('#crPeriod').val($('#crPeriod').val()).select();
  1349.     });
  1350.     $('#qty').focus(function () {
  1351.         $('#qty').val($('#qty').val()).select();
  1352.     });
  1353.     $('#rate').focus(function () {
  1354.         var thisval = $('#rate').val();
  1355.         $('#rate').val(thisval).select();
  1356.     });
  1357.     $('#disPer').focus(function () {
  1358.         $('#disPer').val($('#disPer').val()).select();
  1359.     });
  1360.     $('#disAmt').focus(function () {
  1361.         $('#disAmt').val($('#disAmt').val()).select();
  1362.     });
  1363.     $('#productCode').focus(function () {
  1364.         if ($('#productCode').val() !== '') {
  1365.             $('#productCode').val($('#productCode').val()).select();
  1366.         }
  1367.     });
  1368.  
  1369.     //load data in dblclick
  1370.     $('#PIbody').on('dblclick', '.PIdata', function () {
  1371.         purchaseDetailsId = 0; stockpostid = 0;
  1372.         editId = $(this).data('id');
  1373.         i = JSON.parse(localStorage.getItem('keyPI' + editId)).keyidPI;
  1374.         purchaseDetailsId = JSON.parse(localStorage.getItem('keyPI' + i)).purchaseDetailsId;
  1375.         stockpostid = JSON.parse(localStorage.getItem('keyPI' + i)).stockpostid;
  1376.         productType = JSON.parse(localStorage.getItem('keyPI' + i)).productType;
  1377.         $('#ProductId').val(JSON.parse(localStorage.getItem('keyPI' + editId)).ProductId);
  1378.         $('#productCode').val(JSON.parse(localStorage.getItem('keyPI' + editId)).ProductCode);
  1379.         //$('#productName').val(JSON.parse(localStorage.getItem('keyPI' + editId)).ProductName);
  1380.         $('#productName').val(JSON.parse(localStorage.getItem('keyPI' + editId)).ProductCode).select2();
  1381.         productName = $('#productName').children("option").filter(":selected").text();
  1382.         $('#qty').val(JSON.parse(localStorage.getItem('keyPI' + editId)).Qty);
  1383.         $('#rate').val(JSON.parse(localStorage.getItem('keyPI' + editId)).Rate);
  1384.         unitConversionId = JSON.parse(localStorage.getItem('keyPI' + editId)).unitConversionId;
  1385.         $('#unitId').val(JSON.parse(localStorage.getItem('keyPI' + editId)).UnitID).select2();
  1386.         $('#goDownid').val(JSON.parse(localStorage.getItem('keyPI' + editId)).GodownID).select2();
  1387.         $('#rackId').val(JSON.parse(localStorage.getItem('keyPI' + editId)).RackID).select2();
  1388.         $('#batchId').val(JSON.parse(localStorage.getItem('keyPI' + editId)).Batch);
  1389.         $('#disPer').val(JSON.parse(localStorage.getItem('keyPI' + editId)).DisPer);
  1390.         $('#disAmt').val(JSON.parse(localStorage.getItem('keyPI' + editId)).Discount);
  1391.         $('#grossValue').val(JSON.parse(localStorage.getItem('keyPI' + editId)).GrossValue);
  1392.         $('#Netamt').val(JSON.parse(localStorage.getItem('keyPI' + editId)).TotalAmt);
  1393.         $('#chargeId').val(JSON.parse(localStorage.getItem('keyPI' + editId)).ChargeID).select2();
  1394.         $('#chargeAmt').val(JSON.parse(localStorage.getItem('keyPI' + editId)).chargeAmt);
  1395.         if (JSON.parse(localStorage.getItem('keyPI' + editId)).ImportValue > 0) {
  1396.             $('#ImportValue').prop('disabled', false);
  1397.         }
  1398.         else {
  1399.             $('#ImportValue').prop('disabled', true);
  1400.         }
  1401.         $('#ImportValue').val(JSON.parse(localStorage.getItem('keyPI' + editId)).ImportValue);
  1402.         $('#taxId').val(JSON.parse(localStorage.getItem('keyPI' + editId)).TaxID).select2();
  1403.         $('#taxAmt').val(JSON.parse(localStorage.getItem('keyPI' + editId)).TaxAmt);
  1404.         $('#NetTotal').val(JSON.parse(localStorage.getItem('keyPI' + editId)).Total);
  1405.         $('#ExAD').val(JSON.parse(localStorage.getItem('keyPI' + editId)).expiryDate);
  1406.         grossAmt -= parseFloat(JSON.parse(localStorage.getItem('keyPI' + i)).GrossValue);
  1407.         disAmt -= parseFloat(JSON.parse(localStorage.getItem('keyPI' + i)).Discount);
  1408.         netAmt -= parseFloat(JSON.parse(localStorage.getItem('keyPI' + i)).NetValue);
  1409.         netTotal -= parseFloat(JSON.parse(localStorage.getItem('keyPI' + i)).Total);
  1410.  
  1411.         if (parseFloat(JSON.parse(localStorage.getItem('keyPI' + i)).TaxAmt) === 0) {
  1412.             taxable -= parseFloat((JSON.parse(localStorage.getItem('keyPI' + editId)).NetValue));
  1413.             if (isTax === 1) {
  1414.                 $('#TaxableAmt').text(parseFloat(taxable).toFixed(numberOfDecimal));
  1415.                 $('#gtaxAble').val(parseFloat(taxable).toFixed(numberOfDecimal));
  1416.             }
  1417.         }
  1418.         if (parseFloat(JSON.parse(localStorage.getItem('keyPI' + i)).TaxAmt) > 0) {
  1419.             nonTaxable -= parseFloat((JSON.parse(localStorage.getItem('keyPI' + editId)).NetValue));
  1420.             $('#NonTaxableAmt').text(parseFloat(nonTaxable).toFixed(numberOfDecimal));
  1421.             taxAmt -= parseFloat(JSON.parse(localStorage.getItem('keyPI' + i)).TaxAmt);
  1422.             $('#taxAmtF').text(parseFloat(taxAmt).toFixed(numberOfDecimal));
  1423.             $('#gTaxAmt').val(parseFloat(taxAmt).toFixed(numberOfDecimal));
  1424.         }
  1425.  
  1426.         $('#grossAmtF').text(parseFloat(grossAmt).toFixed(numberOfDecimal));
  1427.         $('#disAmtF').text(parseFloat(disAmt).toFixed(numberOfDecimal));
  1428.         $('#netAmtF').text(parseFloat(netAmt).toFixed(numberOfDecimal));
  1429.         $('#netTotalF').text(parseFloat(netTotal).toFixed(numberOfDecimal));
  1430.  
  1431.         totalGrand = netTotal + parseFloat($('#TotalAdditionalCost').text());
  1432.         //$('#NonTaxableAmt').text(parseFloat(nonTaxable).toFixed(numberOfDecimal));
  1433.         $('#ginvoiceTotal').text(parseFloat(netTotal).toFixed(numberOfDecimal));
  1434.         $('#billAmount').val(parseFloat(netTotal).toFixed(numberOfDecimal));
  1435.         transAmt = $('#billAmount').val();
  1436.         $('#totalAmount').val(parseFloat(netTotal).toFixed(numberOfDecimal));
  1437.         gCosttoParty = parseFloat(netTotal) + parseFloat($('#CosttoParty').text());
  1438.         $('#gCostToparty').text(parseFloat(gCosttoParty).toFixed(numberOfDecimal));
  1439.         $('#gtotal').text(parseFloat(totalGrand).toFixed(numberOfDecimal));
  1440.  
  1441.         for (var ij = 0; ij < lastkeyTax + 1; ij++) {
  1442.             if (localStorage.getItem('keyTax' + ij)) {
  1443.                 if (JSON.parse(localStorage.getItem('keyPI' + editId)).TaxID === JSON.parse(localStorage.getItem('keyTax' + ij)).TaxID) {
  1444.                     var thisTaxid = JSON.parse(localStorage.getItem('keyTax' + ij)).keyidTax;
  1445.                     var thistax = JSON.parse(localStorage.getItem('keyTax' + thisTaxid)).TaxID;
  1446.                     var thisTaxAmt = JSON.parse(localStorage.getItem('keyTax' + thisTaxid)).TaxAmt;
  1447.                     var uptaxAmt = parseFloat(thisTaxAmt) - parseFloat(JSON.parse(localStorage.getItem('keyPI' + editId)).TaxAmt);
  1448.                     localStorage.removeItem('keyTax' + thisTaxid);
  1449.                     localStorage.setItem('keyTax' + thisTaxid, JSON.stringify({
  1450.                         keyidTax: thisTaxid,
  1451.                         TaxID: thistax,
  1452.                         TaxAmt: parseFloat(uptaxAmt).toFixed(numberOfDecimal)
  1453.                     }));
  1454.                 }
  1455.             }
  1456.         }
  1457.         localStorage.removeItem('keyPI' + editId);
  1458.         showTablePI();
  1459.  
  1460.         setTimeout(function () { $('#productName').focus(); }, 1000);
  1461.     });
  1462.     $('#additionalBody').on('dblclick', '.additionalBodydata', function () {
  1463.         var id = $(this).data('id');
  1464.         i = JSON.parse(localStorage.getItem('keyAdd' + id)).keyidAdd;
  1465.         addcostid = JSON.parse(localStorage.getItem('keyAdd' + id)).addcostid;
  1466.         isAddTax = JSON.parse(localStorage.getItem('keyAdd' + id)).isAddTax;
  1467.         $('#AdditionalCostComboFill').val(JSON.parse(localStorage.getItem('keyAdd' + id)).AdditionalLedger).select2();
  1468.         $('#cashPartyAdditional').val(JSON.parse(localStorage.getItem('keyAdd' + id)).AdditionalCashparty).select2();
  1469.         $('#additionalAmt').val(JSON.parse(localStorage.getItem('keyAdd' + id)).AddtionalAmount);
  1470.         TotalAdditionalCost -= parseFloat(JSON.parse(localStorage.getItem('keyAdd' + id)).AddtionalAmount);
  1471.         if (parseInt($('#CashOrPartyComboFill').val()) === JSON.parse(localStorage.getItem('keyAdd' + id)).AdditionalCashparty ||
  1472.             $('#CashOrPartyComboFill').val() === JSON.parse(localStorage.getItem('keyAdd' + id)).AdditionalCashparty) {
  1473.             CosttoParty -= parseFloat(JSON.parse(localStorage.getItem('keyAdd' + id)).AddtionalAmount);
  1474.         }
  1475.         if (parseFloat(JSON.parse(localStorage.getItem('keyAdd' + id)).isAddTax) === 1) {
  1476.             taxable -= parseFloat(JSON.parse(localStorage.getItem('keyAdd' + id)).AddtionalAmount);
  1477.         }
  1478.         else {
  1479.             nonTaxable -= parseFloat(JSON.parse(localStorage.getItem('keyAdd' + id)).AddtionalAmount);
  1480.         }
  1481.         var discount = 0;
  1482.         if ($('#gbillDiscount').val() > 0) {
  1483.             discount = $('#gbillDiscount').val();
  1484.         }
  1485.         $('#TotalAdditionalCost').text(parseFloat(TotalAdditionalCost).toFixed(numberOfDecimal));
  1486.         //totalGrand = parseFloat(nonTaxable) + parseFloat(taxable) + parseFloat($('#gTaxAmt').val());
  1487.  
  1488.         totalGrand = parseFloat($('#TotalAdditionalCost').text()) + parseFloat($('#ginvoiceTotal').text()) + parseFloat(discount);
  1489.         totalInvoice = $('#netTotalF').text();
  1490.         $('#AdditionalCostComboFill').focus(); $('#NonTaxableAmt').text(parseFloat(nonTaxable).toFixed(numberOfDecimal));
  1491.         $('#gtotal').text(parseFloat(totalGrand).toFixed(numberOfDecimal));
  1492.         $('#ginvoiceTotal').text(parseFloat(totalInvoice).toFixed(numberOfDecimal));
  1493.         $('#billAmount').val(parseFloat(totalInvoice).toFixed(numberOfDecimal));
  1494.         transAmt = $('#billAmount').val();
  1495.         $('#totalAmount').val(parseFloat(totalInvoice).toFixed(numberOfDecimal));
  1496.         $('#CosttoParty').text(parseFloat(CosttoParty).toFixed(numberOfDecimal));
  1497.         gCosttoParty = parseFloat(CosttoParty) + parseFloat($('#ginvoiceTotal').text());
  1498.         $('#gCostToparty').text(parseFloat(gCosttoParty).toFixed(numberOfDecimal));
  1499.         localStorage.removeItem('keyAdd' + id);
  1500.         showTableAddtional();
  1501.     });
  1502.  
  1503.     //event of account ledger modal shown
  1504.     $('#btnPA').click(function () {
  1505.         $('#AccountLEDGER').modal('show');
  1506.         $('#legderGroupid').val('11').select2();
  1507.     });
  1508.     $('#btnCP').click(() => {
  1509.         $('#AccountLEDGER').modal('show');
  1510.         $('#legderGroupid').val('22').select2();
  1511.     });
  1512.     $('#AccountLEDGER').on('shown.bs.modal', function () {
  1513.         $('#PurchaseAccountComboFill').select2('close');
  1514.         $('#CashOrPartyComboFill').select2('close');
  1515.         $('#legderNameid').focus();
  1516.         $('.savebtnMain').addClass('active');
  1517.         $('.resetbtnMain').addClass('active');
  1518.         $('#PInarration').removeClass('active');
  1519.         $('#ledgerNarration').addClass('active');
  1520.  
  1521.         $('.savePI').removeClass('active');
  1522.         $('.updatePI').removeClass('active');
  1523.         $('.resetPI').removeClass('active');
  1524.  
  1525.         if ($("#legderGroupid").val() > 0) {
  1526.             enableDisable($("#legderGroupid").val());
  1527.         }
  1528.         $('#savebtnMain').show();
  1529.         $('#resetbtnMain').show();
  1530.         $('#updatebtnMain').hide();
  1531.         $('#deletebtnMain').hide();
  1532.         $('#updatebtnSec').hide();
  1533.     });
  1534.     $('#AccountLEDGER').on('hidden.bs.modal', function () {
  1535.         $('.savebtnMain').removeClass('active');
  1536.         $('.resetbtnMain').removeClass('active');
  1537.         $('#PInarration').addClass('active');
  1538.         $('#ledgerNarration').addClass('active');
  1539.  
  1540.         $('.savePI').addClass('active');
  1541.         $('.updatePI').addClass('active');
  1542.         $('.resetPI').addClass('active');
  1543.         resetLedgerform();
  1544.         //load CashOrPartyComboFill
  1545.         CashOrPartyComboFill();
  1546.         //load CashorBankorPartyComboFill
  1547.         CashorBankorPartyComboFill();
  1548.         //load PurchaseAccountComboFill
  1549.         PurchaseAccountComboFill();
  1550.         //load AdditionalCostComboFill
  1551.         AdditionalCostComboFill();
  1552.         setTimeout(function () { $('#PurchaseAccountComboFill').focus(); }, 1000);
  1553.     });
  1554.     //focus on narration
  1555.     //press Alt+N for pop up account ledger
  1556.     //press space for focus in narration
  1557.     $(document).keydown(function () {
  1558.         //for narration
  1559.         if (event.keyCode === 192) {
  1560.             //$('#PurchaseAccountComboFill').select2('close');
  1561.             //$('#CashOrPartyComboFill').select2('close');
  1562.             //$('#purchaseMode').val(0).select2('close');
  1563.             //$('#VoucherTypeSelectionComboFill').select2('close');
  1564.             //$('#orderNo').select2('close');
  1565.             //$('#unitId').select2('close');
  1566.             //$('#goDownid').select2('close');
  1567.             //$('#rackId').select2('close');
  1568.             //$('#taxId').select2('close');
  1569.             //$('#AdditionalCostComboFill').select2('close');
  1570.             //$('#cashPartyAdditional').select2('close');
  1571.  
  1572.             $('#InAD').datepicker('hide');
  1573.             $('#VAD').datepicker('hide');
  1574.             $('#currentAD').datepicker('hide');
  1575.             $('.nepali-date-picker').css({ 'display': 'none' });
  1576.             //e.preventDefault();
  1577.             //return false;
  1578.             if ($('#ledgerNarration').hasClass('active')) {
  1579.                 setTimeout(function () { $('#ledgerNarration.active').focus(); }, 2000);
  1580.             }
  1581.             if ($('#PInarration').hasClass('active')) {
  1582.                 setTimeout(function () { $('#PInarration.active').focus(); }, 2000);
  1583.             }
  1584.             event.preventDefault();
  1585.             return false;
  1586.         }
  1587.         //to create new account ledger atl + N
  1588.         if (event.altKey && (event.keyCode === 78)) {
  1589.             if ($('.PurchaseID span.select2').hasClass('select2-container--open')) {
  1590.                 $('#PurchaseAccountComboFill').select2('close');
  1591.                 $('.AddLedgerPI').trigger('click');
  1592.             }
  1593.             else if ($('.CashParty span.select2').hasClass('select2-container--open')) {
  1594.                 $('#CashOrPartyComboFill').select2('close');
  1595.                 $('.AddLedgerPI').trigger('click');
  1596.             }
  1597.             else if ($('.ProductName span.select2').hasClass('select2-container--open')) {
  1598.                 $('#productName').select2('close');
  1599.                 $('#ProductModal').modal('show');
  1600.             }
  1601.             e.preventDefault();
  1602.             return false;
  1603.         }
  1604.         //press CTRL+S and CTRL+R
  1605.         //for ctrl+s to save
  1606.         if (event.ctrlKey && (event.which === 83)) {
  1607.             if ($('.savePI.active').is(':visible')) {
  1608.                 $('.savePI.active').trigger('click');
  1609.             }
  1610.             else if ($('.updatePI.active').is(':visible')) {
  1611.                 $('.updatePI.active').trigger('click');
  1612.             }
  1613.             else if ($('.savebtnMain.active').is(':visible')) {
  1614.                 $('.savebtnMain.active').trigger('click');
  1615.             }
  1616.             else if ($('.savebtnSec.active').is(':visible')) {
  1617.                 $('.savebtnSec.active').trigger('click');
  1618.             }
  1619.             else if ($('.updatebtnMain.active').is(':visible')) {
  1620.                 $('.updatebtnMain.active').trigger('click');
  1621.             }
  1622.             else if ($('.updatebtnSec.active').is(':visible')) {
  1623.                 $('.updatebtnSec.active').trigger('click');
  1624.             }
  1625.             else if ($('.savebtnAganist.active').is(':visible')) {
  1626.                 $('.savebtnAganist.active').trigger('click');
  1627.             }
  1628.             event.preventDefault();
  1629.             return false;
  1630.         }
  1631.         //ctrl + r for reset
  1632.         if (event.ctrlKey && (event.which === 82)) {
  1633.             if ($('.resetPI.active').is(':visible')) {
  1634.                 $('.resetPI.active').trigger('click');
  1635.             }
  1636.             else if ($('.resetbtnMain.active').is(':visible')) {
  1637.                 $('.resetbtnMain.active').trigger('click');
  1638.             }
  1639.             else if ($('.resetbtnSec.active').is(':visible')) {
  1640.                 $('.resetbtnSec.active').trigger('click');
  1641.             }
  1642.             else if ($('.resetbtnAganist.active').is(':visible')) {
  1643.                 $('.resetbtnAganist.active').trigger('click');
  1644.             }
  1645.             event.preventDefault();
  1646.             return false;
  1647.         }
  1648.     });
  1649.     //double enter
  1650.     var count = 0;
  1651.     $('#PInarration').on('keydown', function (e) {
  1652.         if (event.keyCode === 32) {
  1653.             $('#PInarration').val($('#PInarration').val() + '');
  1654.         }
  1655.         $('#PInarration').removeClass('active');
  1656.         if (event.keyCode === 13) {
  1657.             count++;
  1658.             setTimeout(function () {
  1659.                 count--;
  1660.             }, 500);
  1661.             if (count === 2) {
  1662.                 $('#TransportationCompany').focus();
  1663.                 e.preventDefault();
  1664.                 return false;
  1665.             }
  1666.         }
  1667.     });
  1668.     $('#TransportationCompany').on('keydown', function (e) {
  1669.         $('#PInarration').removeClass('active');
  1670.         if (event.keyCode === 13) {
  1671.             $('#LRNo').focus();
  1672.             e.preventDefault();
  1673.             return false;
  1674.         }
  1675.         if (event.keyCode === 32) {
  1676.             $('#TransportationCompany').val($('#TransportationCompany').val() + '');
  1677.         }
  1678.     });
  1679.     $('#LRNo').on('keydown', function (e) {
  1680.         $('#PInarration').removeClass('active');
  1681.         if (event.keyCode === 13) {
  1682.             $('#btnPISave.active').focus();
  1683.             $('#btnPIUpdate.active').focus();
  1684.             e.preventDefault();
  1685.             return false;
  1686.         }
  1687.         if (event.keyCode === 32) {
  1688.             $('#LRNo').val($('#LRNo').val() + ' ');
  1689.         }
  1690.     });
  1691.  
  1692.     $('#ImportValue').keydown(function () {
  1693.         if (event.keyCode === 13) {
  1694.             if (isfree === 0) {
  1695.                 setTimeout(function () {
  1696.                     $('#taxId').focus();
  1697.                 }, 100);
  1698.             }
  1699.         }
  1700.     });
  1701.     $('#additionalAmt').keydown(function (e) {
  1702.         if (event.keyCode === 13) {
  1703.             $('#additionalBtn').focus();
  1704.         }
  1705.     });
  1706.     //validation  for ammount and interger
  1707.     $('#rate').keypress(function (e) {
  1708.         if (e.which === 46) {
  1709.             if ($(this).val().indexOf('.') !== -1) {
  1710.                 return false;
  1711.             }
  1712.         }
  1713.         if (e.which !== 8 && e.which !== 0 && e.which !== 46 && (e.which < 48 || e.which > 57)) {
  1714.             return false;
  1715.         }
  1716.     });
  1717.     $('#qty').keypress(function (e) {
  1718.         if (e.which === 46) {
  1719.             if ($(this).val().indexOf('.') !== -1) {
  1720.                 return false;
  1721.             }
  1722.         }
  1723.         if (e.which !== 8 && e.which !== 0 && e.which !== 46 && (e.which < 48 || e.which > 57)) {
  1724.             return false;
  1725.         }
  1726.     });
  1727.     $('#disAmt').keypress(function (e) {
  1728.         if (e.which === 46) {
  1729.             if ($(this).val().indexOf('.') !== -1) {
  1730.                 return false;
  1731.             }
  1732.         }
  1733.         if (e.which !== 8 && e.which !== 0 && e.which !== 46 && (e.which < 48 || e.which > 57)) {
  1734.             return false;
  1735.         }
  1736.     });
  1737.     $('#additionalAmt').keypress(function (e) {
  1738.         if (e.which === 46) {
  1739.             if ($(this).val().indexOf('.') !== -1) {
  1740.                 return false;
  1741.             }
  1742.         }
  1743.         if (e.which !== 8 && e.which !== 0 && e.which !== 46 && (e.which < 48 || e.which > 57)) {
  1744.             return false;
  1745.         }
  1746.     });
  1747.     $('#gbillDiscount').keypress(function (e) {
  1748.         if (e.which === 46) {
  1749.             if ($(this).val().indexOf('.') !== -1) {
  1750.                 return false;
  1751.             }
  1752.         }
  1753.         if (e.which !== 8 && e.which !== 0 && e.which !== 46 && (e.which < 48 || e.which > 57)) {
  1754.             return false;
  1755.         }
  1756.     });
  1757.     $('#disPer').keypress(function (e) {
  1758.         if (e.which === 46) {
  1759.             if ($(this).val().indexOf('.') !== -1) {
  1760.                 return false;
  1761.             }
  1762.         }
  1763.         if (e.which !== 8 && e.which !== 0 && e.which !== 46 && (e.which < 48 || e.which > 57)) {
  1764.             return false;
  1765.         }
  1766.     });
  1767.     $('#crPeriod').keypress(function (e) {
  1768.         var key = e.which;
  1769.         if (!(key >= 48 && key <= 57))
  1770.             e.preventDefault();
  1771.     });
  1772.     //$('#invoiceNo').addClass('intergerValidation');
  1773.  
  1774.     $('#prSearch').click(function () {
  1775.         getPR('ProductbyName', $('#prName').val());
  1776.         droptable();
  1777.     });
  1778.     $('#prName').keydown(function () {
  1779.         if (event.keyCode === 13) {
  1780.             $('#prSearch').trigger('click');
  1781.             event.preventDefault();
  1782.             return false;
  1783.         }
  1784.     });
  1785.     $('#ProductList').on('shown.bs.modal', function () {
  1786.         getPR('ProductbyName', '');
  1787.         $('#PInarration').removeClass('active');
  1788.         droptable();
  1789.         if ($('tbody#modalPRBody.tbody tr').is(':focus')) {
  1790.             $(document).keydown(function (e) {
  1791.                 if (event.keyCode === 13) {
  1792.                     if ($('tbody#modalPRBody.tbody tr:focus').data('id') !== undefined) {
  1793.                         var thisid = $('tbody#modalPRBody.tbody tr:focus').data('id');
  1794.                         $('#productCode').val(thisid);
  1795.                         $('#ProductList').modal('hide');
  1796.                         ProductDetailsgetPerticlular(thisid);
  1797.                     }
  1798.                     e.preventDefault();
  1799.                     return false;
  1800.                 }
  1801.             });
  1802.         }
  1803.     });
  1804.     $('#ProductList').on('hidden.bs.modal', function (e) {
  1805.         $('#PInarration').addClass('active');
  1806.         if (event.keyCode === 13) {
  1807.             if ($('#productName').val() === '') {
  1808.                 $('#productName').focus();
  1809.             }
  1810.             else {
  1811.                 $('#qty').focus();
  1812.             }
  1813.             e.preventDefault();
  1814.             return false;
  1815.         }
  1816.         $('#prName').val('');
  1817.     });
  1818.  
  1819.     //for update
  1820.     $('#voucherNo').keydown(function (e) {
  1821.         if (event.keyCode === 13) {
  1822.             $('#loading').fadeIn();
  1823.             clearPI();
  1824.             getMaster($('#voucherNo').val());
  1825.             $('#PurchaseAccountComboFill').focus();
  1826.             $('#btnPISave').hide();
  1827.             $('#btnPIUpdate').show();
  1828.             e.preventDefault();
  1829.             return false;
  1830.         }
  1831.     });
  1832.  
  1833.     //delete all
  1834.     $('#btnDeleteAll').on('click', function () {
  1835.         ConfirmDeleteAll();
  1836.         $('#delete-modal').modal('hide');
  1837.     });
  1838.     $('#delete-modal').on('hidden.bs.modal', function () {
  1839.         $('.yes').removeClass('pi');
  1840.         $('.yes').removeClass('additional');
  1841.         $('.yes').removeClass('singleAdd');
  1842.         $('.yes').removeClass('singlePi');
  1843.     });
  1844.  
  1845.     $('#ProductModal').on('shown.bs.modal', function () {
  1846.         setTimeout(function () { $('#txtProductName').focus(); }, 100);
  1847.     });
  1848.     $('#ProductModal').on('hidden.bs.modal', function () {
  1849.         setTimeout(function () { $('#productCode').focus(); }, 100);
  1850.     });
  1851.  
  1852.     $('#update').on('shown.bs.modal', function () {
  1853.         $('#loading').fadeIn();
  1854.         $('#btnUpdateYes').click(function () {
  1855.             if ($('.btnyes').hasClass('PI')) {
  1856.  
  1857.                 $('#btnNumb').focus();
  1858.                 var errorCount = 0;
  1859.                 //delete product
  1860.                 if (localStorage.length > 0) {
  1861.                     for (var kl = 0; kl < localStorage.length; kl++) {
  1862.                         if (localStorage.getItem('keyPI' + kl)) {
  1863.                             for (var jl = 0; jl < purchaselist.length; jl++) {
  1864.                                 var checkpurchid = getcheckpurchid(purchaselist[jl]);
  1865.                                 if (checkpurchid) {
  1866.                                     continue;
  1867.                                 }
  1868.                                 else {
  1869.                                     if (JSON.parse(localStorage.getItem('keyPI' + kl)).purchaseDetailsId !== 0) {
  1870.                                         $.ajax({
  1871.                                             url: '/PurchaseInvoice/PurchaseDetailsDelete?DbName=' + DbName + '&purchaseDetailsId=' + purchaselist[jl],
  1872.                                             type: 'post',
  1873.                                             async: false,
  1874.                                             success: function () {
  1875.                                                 $.ajax({
  1876.                                                     url: '/PurchaseInvoice/StockPostingDelete?DbName=' + DbName + '&stockPostingId=' + stockpostinglist[jl],
  1877.                                                     type: 'post',
  1878.                                                     async: false,
  1879.                                                     success: function () {
  1880.  
  1881.                                                     },
  1882.                                                     error: function () {
  1883.                                                         //toastr.error(ledgerIDList[i]);
  1884.                                                         errorCount++;
  1885.                                                     }
  1886.                                                 });
  1887.                                             },
  1888.                                             error: function () {
  1889.                                                 //toastr.error(ledgerIDList[i]);
  1890.                                                 errorCount++;
  1891.                                             }
  1892.                                         });
  1893.                                     }
  1894.                                 }
  1895.                             }
  1896.  
  1897.                         }
  1898.                     }
  1899.                 }
  1900.                 if (localStorage.length > 0) {
  1901.                     for (var kle = 0; kle < localStorage.length; kle++) {
  1902.                         for (var add = 0; add < addcpstList.length; add++) {
  1903.                             var checkaddcostid = getcheckaddcostid(addcpstList[add]);
  1904.                             if (checkaddcostid) {
  1905.                                 continue;
  1906.                             }
  1907.                             else {
  1908.                                 $.ajax({
  1909.                                     url: '/PurchaseInvoice/AdditionalCostDelete?DbName=' + DbName + '&additionalCostId=' + addcpstList[add],
  1910.                                     type: 'post',
  1911.                                     async: false,
  1912.                                     success: function () {
  1913.  
  1914.                                     },
  1915.                                     error: function () {
  1916.                                         //toastr.error(ledgerIDList[i]);
  1917.                                         errorCount++;
  1918.                                     }
  1919.                                 });
  1920.                             }
  1921.                         }
  1922.                     }
  1923.                 }
  1924.                 if (errorCount === 0) {
  1925.                     let di = 0, adi = 0, taxi = 0, chargi = 0;
  1926.                     for (var i = 0; i < lastkeyPI + 1; i++) {
  1927.                         if (localStorage.getItem('keyPI' + i)) {
  1928.                             datas[di] = JSON.stringify({
  1929.                                 purchaseDetailsId: JSON.parse(localStorage.getItem('keyPI' + i)).purchaseDetailsId,
  1930.                                 stockpostid: JSON.parse(localStorage.getItem('keyPI' + i)).stockpostid,
  1931.                                 ProductId: JSON.parse(localStorage.getItem('keyPI' + i)).ProductId,
  1932.                                 productType: JSON.parse(localStorage.getItem('keyPI' + i)).productType,
  1933.                                 ProductCode: JSON.parse(localStorage.getItem('keyPI' + i)).ProductCode,
  1934.                                 ProductName: JSON.parse(localStorage.getItem('keyPI' + i)).ProductName,
  1935.                                 unitConversionId: JSON.parse(localStorage.getItem('keyPI' + i)).unitConversionId,
  1936.                                 Qty: JSON.parse(localStorage.getItem('keyPI' + i)).Qty,
  1937.                                 Unit: JSON.parse(localStorage.getItem('keyPI' + i)).Unit,
  1938.                                 UnitID: JSON.parse(localStorage.getItem('keyPI' + i)).UnitID,
  1939.                                 Godown: JSON.parse(localStorage.getItem('keyPI' + i)).Godown,
  1940.                                 GodownID: JSON.parse(localStorage.getItem('keyPI' + i)).GodownID,
  1941.                                 Rack: JSON.parse(localStorage.getItem('keyPI' + i)).Rack,
  1942.                                 RackID: JSON.parse(localStorage.getItem('keyPI' + i)).RackID,
  1943.                                 Batch: JSON.parse(localStorage.getItem('keyPI' + i)).Batch,
  1944.                                 Rate: JSON.parse(localStorage.getItem('keyPI' + i)).Rate,
  1945.                                 DisPer: JSON.parse(localStorage.getItem('keyPI' + i)).DisPer,
  1946.                                 GrossValue: JSON.parse(localStorage.getItem('keyPI' + i)).GrossValue,
  1947.                                 Discount: JSON.parse(localStorage.getItem('keyPI' + i)).Discount,
  1948.                                 TotalAmt: JSON.parse(localStorage.getItem('keyPI' + i)).TotalAmt,
  1949.                                 ChargeID: JSON.parse(localStorage.getItem('keyPI' + i)).ChargeID,
  1950.                                 chargeAmt: JSON.parse(localStorage.getItem('keyPI' + i)).chargeAmt,
  1951.                                 TaxableVal: JSON.parse(localStorage.getItem('keyPI' + i)).TaxableVal,
  1952.                                 ImportValue: JSON.parse(localStorage.getItem('keyPI' + i)).ImportValue,
  1953.                                 Tax: JSON.parse(localStorage.getItem('keyPI' + i)).Tax,
  1954.                                 TaxID: JSON.parse(localStorage.getItem('keyPI' + i)).TaxID,
  1955.                                 TaxAmt: JSON.parse(localStorage.getItem('keyPI' + i)).TaxAmt,
  1956.                                 Total: JSON.parse(localStorage.getItem('keyPI' + i)).Total,
  1957.                                 expiryDate: JSON.parse(localStorage.getItem('keyPI' + i)).expiryDate
  1958.                             });
  1959.                             di++;
  1960.                         }
  1961.                     }
  1962.                     for (var j = 0; j < lastkeyAdd + 1; j++) {
  1963.                         if (localStorage.getItem('keyAdd' + j)) {
  1964.                             if (parseInt(JSON.parse(localStorage.getItem('keyAdd' + j)).AddtionalAmount) > 0) {
  1965.                                 Additionaldatas[adi] = JSON.stringify({
  1966.                                     AddCashpartyName: JSON.parse(localStorage.getItem('keyAdd' + j)).AddCashpartyName,
  1967.                                     addcostid: JSON.parse(localStorage.getItem('keyAdd' + j)).addcostid,
  1968.                                     AddLedgerName: JSON.parse(localStorage.getItem('keyAdd' + j)).AddLedgerName,
  1969.                                     AdditionalCashparty: JSON.parse(localStorage.getItem('keyAdd' + j)).AdditionalCashparty,
  1970.                                     AdditionalLedger: JSON.parse(localStorage.getItem('keyAdd' + j)).AdditionalLedger,
  1971.                                     AddtionalAmount: JSON.parse(localStorage.getItem('keyAdd' + j)).AddtionalAmount
  1972.                                 });
  1973.                                 adi++;
  1974.                             }
  1975.                         }
  1976.                     }
  1977.                     for (var k = 0; k < lastkeyTax + 1; k++) {
  1978.                         if (localStorage.getItem('keyTax' + k)) {
  1979.                             taxdatas[taxi] = JSON.stringify({
  1980.                                 TaxID: JSON.parse(localStorage.getItem('keyTax' + k)).TaxID,
  1981.                                 TaxAmt: JSON.parse(localStorage.getItem('keyTax' + k)).TaxAmt
  1982.                             });
  1983.                             taxi++;
  1984.                         }
  1985.                     }
  1986.                     for (var l = 0; l < lastkeyCharge + 1; l++) {
  1987.                         if (localStorage.getItem('keyCharge' + l)) {
  1988.                             if (parseInt(JSON.parse(localStorage.getItem('keyCharge' + l)).ChargeAmt) > 0) {
  1989.                                 chargedatas[chargi] = JSON.stringify({
  1990.                                     ChargeID: JSON.parse(localStorage.getItem('keyCharge' + l)).ChargeID,
  1991.                                     ChargeAmt: JSON.parse(localStorage.getItem('keyCharge' + l)).ChargeAmt
  1992.                                 });
  1993.                                 chargi++;
  1994.                             }
  1995.                         }
  1996.                     }
  1997.                     var totalDiscount = parseFloat(billDiscount) + parseFloat($('#disAmtF').text());
  1998.                     var dataObj = {
  1999.                         DbName: DbName,
  2000.                         date: $('#VAD').val(),
  2001.                         purchaseMasterId: purchaseMasterId,
  2002.                         ledgerId: $('#CashOrPartyComboFill').val(),
  2003.                         vendorInvoiceNo: $('#invoiceNo').val().trim(),
  2004.                         vendorInvoiceDate: $('#InAD').val(),
  2005.                         creditPeriod: $('#crPeriod').val().trim(),
  2006.                         narration: $('#PInarration').val().trim(),
  2007.                         purchaseAccount: $('#PurchaseAccountComboFill').val(),
  2008.                         additionalCost: $('#TotalAdditionalCost').text(),
  2009.                         totalTax: $('#gTaxAmt').val(),//total tax
  2010.                         costtoParty: $('#gCostToparty').text(),
  2011.                         grandTotal: $('#gtotal').text(),
  2012.                         invoiceTotal: $('#ginvoiceTotal').text(),// party amount
  2013.                         lrNo: $('#LRNo').val().trim(),
  2014.                         transportationCompany: $('#TransportationCompany').val().trim(),
  2015.                         ProductNetTotal: $('#netTotalF').text(),
  2016.                         grossValue: $('#grossAmtF').text(),
  2017.                         totalDiscount: totalDiscount, //total discount
  2018.                         list: datas,
  2019.                         partyBalanceId: partyBalanceId,
  2020.                         addList: Additionaldatas,
  2021.                         taxlist: taxdatas,
  2022.                         addcostlpid: addcostlpid,
  2023.                         purchlpid: purchlpid,
  2024.                         cashbanklpid: cashbanklpid,
  2025.                         taxlpid: taxlpid,
  2026.                         chargelpid: chargelpid,
  2027.                         discountlpid: discountlpid,
  2028.                         chargeList: chargedatas,
  2029.                         BillTaxPercentage: BillTaxPercentage,
  2030.                         BillTaxAmount: BillTaxAmount,
  2031.                         BillExciseDutyPercentage: BillExciseDutyPercentage,
  2032.                         BillExciseDutyAmount: BillExciseDutyAmount,
  2033.                         BillDiscountPercentage: BillDiscountPercentage,
  2034.                         billDiscount: billDiscount//$('#gbillDiscount').val()
  2035.                     };
  2036.                     $.ajax({
  2037.                         type: 'post',
  2038.                         dataType: 'json',
  2039.                         data: dataObj,
  2040.                         url: '/PurchaseInvoice/UpdatePI',
  2041.                         success: function (data) {
  2042.                             if (data.data === '1') {
  2043.                                 toastr.success('Updated Successfully');
  2044.                                 resetForm();
  2045.                                 $('#btnPISave').show();
  2046.                                 $('#btnPIUpdate').hide();
  2047.                                 console.log(data.invoiceNo);
  2048.                                 $(".btnprintyes").attr('data-invoiceno', data.invoiceNo);
  2049.                                 if ($(".PrintBill").is(":checked")) {
  2050.                                     $(".btnprintyes").trigger('click');
  2051.                                 }
  2052.                                 $('#loading').fadeOut();
  2053.                             }
  2054.                             else {
  2055.                                 toastr.error('Not added : ' + data);
  2056.                                 $('#loading').fadeOut();
  2057.                                 setTimeout(function () {
  2058.                                     $('#PurchaseAccountComboFill').focus();
  2059.                                 }, 100);
  2060.                             }
  2061.                             $('#update').modal('hide');
  2062.                         },
  2063.                         error: function (ex) {
  2064.                             toastr.error('Unable to update data' + ex.statusText);
  2065.                             $('#loading').fadeOut();
  2066.                             $('#update').modal('hide');
  2067.                             setTimeout(function () {
  2068.                                 $('#PurchaseAccountComboFill').focus();
  2069.                             }, 100);
  2070.                         }
  2071.                     });
  2072.                 }
  2073.                 else {
  2074.                     $('#loading').fadeOut();
  2075.                     toastr.error('system error: record update could not be saved');
  2076.                     $('#update').modal('hide');
  2077.                     setTimeout(function () {
  2078.                         $('#PurchaseAccountComboFill').focus();
  2079.                     }, 100);
  2080.                 }
  2081.                 $('#btnUpdateYes').removeClass('PI');
  2082.             }
  2083.         });
  2084.     });
  2085.  
  2086. });
  2087. // add after free QTY
  2088. function addProductsGrid() {
  2089.     if ($('.isFreeQTY').is(':checked')) {
  2090.         addBills();
  2091.     }
  2092.     else {
  2093.         if ($('#NetTotal').val() === '' || $('#NetTotal').val() === '0' ||
  2094.             $('#Netamt').val() === '' || $('#Netamt').val() === '0' ||
  2095.             $('#grossValue').val() === '' || $('#grossValue').val() === '0') {
  2096.             $('#productCode').focus();
  2097.             toastr.error('Fill required field');
  2098.         }
  2099.         else {
  2100.  
  2101.             if (accountgpId === 27) {
  2102.                 if (negativeCash === 0) {
  2103.                     if ($('#NetTotal').val() > CashAmount) {
  2104.                         toastr.error('Net Total is greater than Cash Amount');
  2105.                     }
  2106.                     else {
  2107.                         addBills();
  2108.                     }
  2109.                 }
  2110.                 else {
  2111.                     addBills();
  2112.                 }
  2113.             }
  2114.             else {
  2115.                 addBills();
  2116.             }
  2117.         }
  2118.     }
  2119. }
  2120. //add product details for purchase
  2121. function addBills() {
  2122.  
  2123.     var i = 0;
  2124.     var action = '';
  2125.     while (localStorage.getItem('keyPI' + i)) {
  2126.         i++;
  2127.     }
  2128.  
  2129.     if (parseFloat(orderQTY) === parseFloat($('#qty').val())) {
  2130.         action = 'Accepted';
  2131.     }
  2132.     else {
  2133.         action = 'Partial';
  2134.     }
  2135.  
  2136.     var check = checkProductnamePI();
  2137.     let batch = '';
  2138.     if ($('#batchId').val().trim() === '') {
  2139.         batch = "N/A";
  2140.     }
  2141.     else {
  2142.         batch = $('#batchId').val();
  2143.     }
  2144.     if ($('.isFreeQTY').is(':checked')) {
  2145.         if ($('#taxAmt').val() < 0) {
  2146.             taxable += parseFloat($('#Netamt').val());
  2147.         }
  2148.         thistaxamt = $('#taxAmt').val();
  2149.         localStorage.setItem('keyPI' + i, JSON.stringify({
  2150.             keyidPI: i,
  2151.             ProductId: $('#ProductId').val(),
  2152.             ProductCode: $('#productCode').val(),
  2153.             purchaseDetailsId: purchaseDetailsId,
  2154.             stockpostid: stockpostid,
  2155.             ProductName: productName,
  2156.             Qty: $('#qty').val(),
  2157.             Unit: $('#unitId').children('option').filter(':selected').text(),
  2158.             UnitID: $('#unitId').val(),
  2159.             Godown: $('#goDownid').children('option').filter(':selected').text(),
  2160.             GodownID: $('#goDownid').val(),
  2161.             Rack: $('#rackId').children('option').filter(':selected').text(),
  2162.             RackID: $('#rackId').val(),
  2163.             unitConversionId: unitConversionId,
  2164.             Batch: batch,
  2165.             Rate: $('#rate').val(),
  2166.             DisPer: $('#disPer').val(),
  2167.             GrossValue: $('#grossValue').val(),
  2168.             Discount: $('#disAmt').val(),
  2169.             TotalAmt: $('#Netamt').val(),
  2170.             Charge: $('#chargeId').children('option').filter(':selected').text(),
  2171.             ChargeID: $('#chargeId').val(),
  2172.             chargeAmt: $('#chargeAmt').val(),
  2173.             TaxableVal: $('#TaxableVal').val(),
  2174.             ImportValue: $('#ImportValue').val(),
  2175.             Tax: $('#taxId').children('option').filter(':selected').text(),
  2176.             TaxID: $('#taxId').val(),
  2177.             TaxAmt: $('#taxAmt').val(),
  2178.             Total: $('#NetTotal').val(),
  2179.             productType: productType,
  2180.             expiryDate: $('#ExAD').val(),
  2181.             materialReceiptMasterId: materialReceiptMasterId,
  2182.             purchaseOrderMasterId: purchaseOrderMasterId,
  2183.             action: action
  2184.  
  2185.         }));
  2186.         if (i > lastkeyPI) {
  2187.             lastkeyPI = i;
  2188.         }
  2189.         showTablePI();
  2190.     }
  2191.     else {
  2192.         if (check) {
  2193.             toastr.info('Product name exist in table below. Please Edit and Update');
  2194.         }
  2195.         else {
  2196.             if ($('#taxAmt').val() < 0) {
  2197.                 taxable += parseFloat($('#Netamt').val());
  2198.             }
  2199.             thistaxamt = $('#taxAmt').val();
  2200.             localStorage.setItem('keyPI' + i, JSON.stringify({
  2201.                 keyidPI: i,
  2202.                 ProductId: $('#ProductId').val(),
  2203.                 ProductCode: $('#productCode').val(),
  2204.                 purchaseDetailsId: parseFloat(purchaseDetailsId),
  2205.                 stockpostid: parseFloat(stockpostid),
  2206.                 ProductName: productName,
  2207.                 Qty: parseFloat($('#qty').val()),
  2208.                 Unit: $('#unitId').children('option').filter(':selected').text(),
  2209.                 UnitID: $('#unitId').val(),
  2210.                 Godown: $('#goDownid').children('option').filter(':selected').text(),
  2211.                 GodownID: $('#goDownid').val(),
  2212.                 Rack: $('#rackId').children('option').filter(':selected').text(),
  2213.                 RackID: $('#rackId').val(),
  2214.                 unitConversionId: unitConversionId,
  2215.                 Batch: batch,
  2216.                 Rate: parseFloat($('#rate').val()),
  2217.                 DisPer: parseFloat($('#disPer').val()),
  2218.                 GrossValue: parseFloat($('#grossValue').val()),
  2219.                 Discount: parseFloat($('#disAmt').val()),
  2220.                 TotalAmt: parseFloat($('#Netamt').val()),
  2221.                 Charge: $('#chargeId').children('option').filter(':selected').text(),
  2222.                 ChargeID: $('#chargeId').val(),
  2223.                 chargeAmt: parseFloat($('#chargeAmt').val()),
  2224.                 TaxableVal: parseFloat($('#TaxableVal').val()),
  2225.                 ImportValue: parseFloat($('#ImportValue').val()),
  2226.                 Tax: $('#taxId').children('option').filter(':selected').text(),
  2227.                 TaxID: $('#taxId').val(),
  2228.                 TaxAmt: parseFloat($('#taxAmt').val()),
  2229.                 Total: parseFloat($('#NetTotal').val()),
  2230.                 productType: productType,
  2231.                 expiryDate: $('#ExAD').val(),
  2232.                 materialReceiptMasterId: parseFloat(materialReceiptMasterId),
  2233.                 purchaseOrderMasterId: parseFloat(purchaseOrderMasterId),
  2234.                 action: action
  2235.  
  2236.             }));
  2237.             if (i > lastkeyPI) {
  2238.                 lastkeyPI = i;
  2239.             }
  2240.             showTablePI();
  2241.         }
  2242.     }
  2243.     $('#productCode').focus();
  2244.     unitdp();
  2245.     rackdp();
  2246.     reset(); reset();
  2247. }
  2248.  
  2249. //get product list
  2250. function GetProductDetailsFromMaterialReceiptDetails(id, materialReceiptDetailsId) {
  2251.     $('#loading').fadeIn();
  2252.     $.ajax({
  2253.         url: '/PurchaseInvoice/GetProductDetailsFromMaterialReceiptDetails?DbName=' + DbName + '&materialReceiptDetailsId=' + materialReceiptDetailsId + '&productcode=' + id,
  2254.         type: 'get',
  2255.         async: false,
  2256.         success: function (data) {
  2257.             if (data !== '') {
  2258.                 PId = data.productId;
  2259.                 orderQTY = data.qty;
  2260.                 var productCode = data.productCode;
  2261.                 $.ajax({
  2262.                     url: '/PurchaseInvoice/ProductDetailsgetPerticlular?DbName=' + DbName + '&producttype=' + 1 + '&productcode=' + productCode,
  2263.                     type: 'get',
  2264.                     async: false,
  2265.                     success: function (data1) {
  2266.                         if (data1 !== '') {
  2267.                             if (data1.ismultipleunit === 1) {
  2268.                                 ismultipleunit = 1;
  2269.                                 UnitViewAllByProductId(data1.productId);
  2270.                                 $('#unitId').removeClass('disabled');
  2271.                                 $('#unitId').prop('disabled', false);
  2272.                             }
  2273.                             else {
  2274.                                 $('#unitId').addClass('disabled');
  2275.                                 $('#unitId').prop('disabled', true);
  2276.                             }
  2277.                             $('#unitId').val(data1.unitId).select2();
  2278.                             $('#goDownid').val(data1.godownId).select2();
  2279.                             $('#rackId').val(data1.rackId).select2();
  2280.                             if (data1.taxId > 0) {
  2281.                                 $('#taxId').removeClass('disabled');
  2282.                                 $('#taxId').prop('disabled', false);
  2283.                                 $('#taxId').val(data1.taxId).select2();
  2284.                             }
  2285.                             else {
  2286.                                 $('#taxId').addClass('disabled');
  2287.                                 $('#taxId').prop('disabled', true);
  2288.                                 $('#taxId').val(1).select2();
  2289.                             }
  2290.                             if (data1.isallowBatch === 0) {
  2291.                                 $('#batchId').prop('disabled', true);
  2292.                                 $('#batchId').addClass('disabled');
  2293.                                 $('#ExAD').prop('disabled', true);
  2294.                                 $('#ExAD').addClass('disabled');
  2295.                                 $('#batchId').val('N/A');
  2296.                             }
  2297.                             else if (data1.isallowBatch === 1) {
  2298.                                 $('#batchId').prop('disabled', false);
  2299.                                 $('#batchId').removeClass('disabled');
  2300.                                 $('#ExAD').prop('disabled', false);
  2301.                                 $('#ExAD').removeClass('disabled');
  2302.                             }
  2303.                             //if (data1.ratefixed === 0) {
  2304.                             //    $("#rate").removeClass('disabled');
  2305.                             //    $("#rate").prop('disabled', false);
  2306.                             //    $('#rate').val(data1.purchaseRate);
  2307.                             //}
  2308.                             //else if (data1.ratefixed === 1) {
  2309.                             //    $('#rate').addClass('disabled');
  2310.                             //    $('#rate').prop('disabled', true);
  2311.                             //    $('#rate').val(data1.purchaseRate);
  2312.                             //}
  2313.                         }
  2314.                     }
  2315.                 });
  2316.                 $('#rate').val(data.rate);
  2317.                 $('#ProductId').val(data.productId);
  2318.                 $('#productName').val(data.productName);
  2319.                 $('#qty').val(data.qty);
  2320.  
  2321.  
  2322.                 //originalRate = data.purchaseRate;
  2323.                 productType = data.purchasetype;
  2324.                 $('#disPer').val('0');
  2325.                 $('#grossValue').val('0');
  2326.                 $('#disAmt').val('0');
  2327.                 $('#Netamt').val('0');
  2328.                 $('#ImportValue').val('0');
  2329.                 $('#taxAmt').val('0');
  2330.                 $('#NetTotal').val('0');
  2331.                 setTimeout(function () { $('#qty').focus(); }, 500);
  2332.             }
  2333.             $('#loading').fadeOut();
  2334.         },
  2335.         error: function () {
  2336.             $('#loading').fadeOut();
  2337.             toastr.error('enter correct product code');
  2338.         }
  2339.     });
  2340. }
  2341.  
  2342. function GetProductDetailsFromPurchaseOrderDetails(id, purchaseOrderDetailsId) {
  2343.     $('#loading').fadeIn();
  2344.     $.ajax({
  2345.         url: '/PurchaseInvoice/GetProductDetailsFromPurchaseOrderDetails?DbName=' + DbName + '&purchaseOrderDetailsId=' + purchaseOrderDetailsId + '&productcode=' + id,
  2346.         type: 'get',
  2347.         async: false,
  2348.         success: function (data) {
  2349.             if (data !== '') {
  2350.                 PId = data.productId;
  2351.                 orderQTY = data.qty;
  2352.                 var productCode = data.productCode;
  2353.                 $.ajax({
  2354.                     url: '/PurchaseInvoice/ProductDetailsgetPerticlular?DbName=' + DbName + '&producttype=' + 1 + '&productcode=' + productCode,
  2355.                     type: 'get',
  2356.                     async: false,
  2357.                     success: function (data1) {
  2358.                         if (data1 !== '') {
  2359.                             if (data1.ismultipleunit === 1) {
  2360.                                 ismultipleunit = 1;
  2361.                                 UnitViewAllByProductId(data1.productId);
  2362.                                 $('#unitId').removeClass('disabled');
  2363.                                 $('#unitId').prop('disabled', false);
  2364.                             }
  2365.                             else {
  2366.                                 $('#unitId').addClass('disabled');
  2367.                                 $('#unitId').prop('disabled', true);
  2368.                             }
  2369.                             $('#unitId').val(data1.unitId).select2();
  2370.                             $('#goDownid').val(data1.godownId).select2();
  2371.                             $('#rackId').val(data1.rackId).select2();
  2372.                             if (data1.taxId > 0) {
  2373.                                 $('#taxId').removeClass('disabled');
  2374.                                 $('#taxId').prop('disabled', false);
  2375.                                 $('#taxId').val(data1.taxId).select2();
  2376.                             }
  2377.                             else {
  2378.                                 $('#taxId').addClass('disabled');
  2379.                                 $('#taxId').prop('disabled', true);
  2380.                                 $('#taxId').val(1).select2();
  2381.                             }
  2382.                             if (data1.isallowBatch === 0) {
  2383.                                 $('#batchId').prop('disabled', true);
  2384.                                 $('#batchId').addClass('disabled');
  2385.                                 $('#ExAD').prop('disabled', true);
  2386.                                 $('#ExAD').addClass('disabled');
  2387.                                 $('#batchId').val('N/A');
  2388.                             }
  2389.                             else if (data1.isallowBatch === 1) {
  2390.                                 $('#batchId').prop('disabled', false);
  2391.                                 $('#batchId').removeClass('disabled');
  2392.                                 $('#ExAD').prop('disabled', false);
  2393.                                 $('#ExAD').removeClass('disabled');
  2394.                             }
  2395.                             //if (data1.ratefixed === 0) {
  2396.                             //    $("#rate").removeClass('disabled');
  2397.                             //    $("#rate").prop('disabled', false);
  2398.                             //    $('#rate').val(data1.purchaseRate);
  2399.                             //}
  2400.                             //else if (data1.ratefixed === 1) {
  2401.                             //    $('#rate').addClass('disabled');
  2402.                             //    $('#rate').prop('disabled', true);
  2403.                             //    $('#rate').val(data1.purchaseRate);
  2404.                             //}
  2405.                         }
  2406.                     }
  2407.                 });
  2408.                 $('#ProductId').val(data.productId);
  2409.                 $('#productName').val(data.productName);
  2410.                 $('#qty').val(data.qty);
  2411.                 $('#rate').val(data.rate);
  2412.  
  2413.                 //originalRate = data.purchaseRate;
  2414.                 productType = data.purchasetype;
  2415.                 $('#disPer').val('0');
  2416.                 $('#grossValue').val('0');
  2417.                 $('#disAmt').val('0');
  2418.                 $('#Netamt').val('0');
  2419.                 $('#ImportValue').val('0');
  2420.                 $('#taxAmt').val('0');
  2421.                 $('#NetTotal').val('0');
  2422.                 setTimeout(function () { $('#qty').focus(); }, 500);
  2423.             }
  2424.             $('#loading').fadeOut();
  2425.         },
  2426.         error: function () {
  2427.             $('#loading').fadeOut();
  2428.             toastr.error('enter correct product code');
  2429.         }
  2430.     });
  2431. }
  2432.  
  2433. function ProductDetailsgetPerticlular(id) {
  2434.     $('#loading').fadeIn();
  2435.     $.ajax({
  2436.         url: '/PurchaseInvoice/ProductDetailsgetPerticlular?DbName=' + DbName + '&producttype=' + 1 + '&productcode=' + id,
  2437.         type: 'get',
  2438.         async: false,
  2439.         success: function (data) {
  2440.             if (data !== '') {
  2441.                 PId = data.productId;
  2442.                 ChargeGet_ByProductId(PId);
  2443.                 $('#ProductId').val(data.productId);
  2444.                 $('#productName').val(data.productName);
  2445.                 if (data.ismultipleunit === 1) {
  2446.                     ismultipleunit = 1;
  2447.                     UnitViewAllByProductId(data.productId);
  2448.                     $('#unitId').removeClass('disabled');
  2449.                     $('#unitId').prop('disabled', false);
  2450.                 } else {
  2451.                     $('#unitId').addClass('disabled');
  2452.                     $('#unitId').prop('disabled', true);
  2453.                 }
  2454.                 $('#unitId').val(data.unitId).select2();
  2455.                 $('#goDownid').val(data.godownId).select2();
  2456.                 $('#rackId').val(data.rackId).select2();
  2457.                 if (data.taxId > 0) {
  2458.                     $('#taxId').removeClass('disabled');
  2459.                     $('#taxId').prop('disabled', false);
  2460.                     $('#taxId').val(data.taxId).select2();
  2461.                 }
  2462.                 else {
  2463.                     $('#taxId').addClass('disabled');
  2464.                     $('#taxId').prop('disabled', true);
  2465.                     $('#taxId').val(1).select2();
  2466.                 }
  2467.                 if (data.isallowBatch === 0) {
  2468.                     $('#batchId').prop('disabled', true);
  2469.                     $('#batchId').addClass('disabled');
  2470.                     $('#ExAD').prop('disabled', true);
  2471.                     $('#ExAD').addClass('disabled');
  2472.                     $('#batchId').val('N/A');
  2473.                 }
  2474.                 if (data.isallowBatch === 1) {
  2475.                     $('#batchId').prop('disabled', false);
  2476.                     $('#batchId').removeClass('disabled');
  2477.                     $('#ExAD').prop('disabled', false);
  2478.                     $('#ExAD').removeClass('disabled');
  2479.                 }
  2480.                 //if (data.ratefixed === 0) {
  2481.                 //    $("#rate").removeClass('disabled');
  2482.                 //    $("#rate").prop('disabled', false);                    
  2483.                 //    $('#rate').val(data.purchaseRate);
  2484.                 //}
  2485.                 //else if (data.ratefixed === 1) {
  2486.                 //    $('#rate').addClass('disabled');
  2487.                 //    $('#rate').prop('disabled', true);                  
  2488.                 //    $('#rate').val(data.purchaseRate);
  2489.                 //}
  2490.                 originalRate = data.purchaseRate;
  2491.                 $('#rate').val(data.purchaseRate);
  2492.                 productType = data.purchasetype;
  2493.                 setTimeout(function () { $('#qty').focus(); }, 500);
  2494.             }
  2495.             $('#loading').fadeOut();
  2496.         },
  2497.         error: function () {
  2498.             $('#loading').fadeOut();
  2499.             toastr.error('enter correct product code');
  2500.         }
  2501.     });
  2502. }
  2503.  
  2504. function getPR(url, name) {
  2505.     $.ajax({
  2506.         url: '/PurchaseInvoice/' + url + '?DbName=' + DbName + '&name=' + name,
  2507.         type: 'get',
  2508.         async: false,
  2509.         success: function (data) {
  2510.             var h = '', j = 0;
  2511.             $.each(data, function (k, item) {
  2512.                 k++;
  2513.                 h += '<tr data-id="' + item.productCode + '" data-name="' + item.productName + '" tabindex="' + j + '" >';
  2514.                 h += '<td>' + k + '</td>';
  2515.                 h += '<td>' + item.productName + '</td>';
  2516.                 h += '</tr>';
  2517.                 j++;
  2518.                 pindex = j;
  2519.             });
  2520.             $('#modalPRBody').html(h);
  2521.         }
  2522.     });
  2523. }
  2524. function droptable() {
  2525.     $('tr[tabindex=0]').focus();
  2526.     document.onkeydown = checkKey;
  2527. }
  2528. function checkKey(e) {
  2529.     var event = window.event ? window.event : e;
  2530.     if (event.keyCode === 40) { //down
  2531.         var idx = $('tr:focus').attr('tabindex');
  2532.         idx++;
  2533.         if (idx > pindex) {
  2534.             idx = 0;
  2535.         }
  2536.         $('tr[tabindex=' + idx + ']').focus();
  2537.     }
  2538.     if (event.keyCode === 38) { //up
  2539.         idx = $('tr:focus').attr('tabindex');
  2540.         idx--;
  2541.         if (idx < 0) {
  2542.             idx = pindex;
  2543.         }
  2544.         $('tr[tabindex=' + idx + ']').focus();
  2545.     }
  2546.     if (event.keyCode === 32) {
  2547.         $('#prName').focus();
  2548.         event.preventDefault();
  2549.         return false;
  2550.     }
  2551. }
  2552.  
  2553. //reset this from
  2554. function resetForm() {
  2555.     resetAdditional();
  2556.     reset();
  2557.     clearPI();
  2558.     $('#PurchaseAccountComboFill').val('0').select2();
  2559.     $('#crPeriod').val('0');
  2560.     $('#invoiceNo').val('');
  2561.     $('#voucherNo').val('');
  2562.     $('#InAD').val('');
  2563.     $('#InBS').val('');
  2564.     $('#InBS').val('');
  2565.     $("#VAD").datepicker({
  2566.         dateFormat: "mm/dd/yy",
  2567.         maxDate: todate,
  2568.         minDate: fromdate,
  2569.         showButtonPanel: true
  2570.     }).datepicker('setDate', 'today');
  2571.     CommomAdDateToBs("#VAD", "#VBS");
  2572.     $('#CashOrPartyComboFill').val('0').select2();
  2573.     //$('#purchaseMode').val(0).select2();
  2574.     $('#VoucherTypeSelectionComboFill').val('0').select2();
  2575.     //$('#orderNo').val('0').select2();
  2576.     $('#gbillDiscount').val('');
  2577.     $('#gtaxAble').val('');
  2578.     $('#gTaxAmt').val('');
  2579.     $('#PInarration').val('');
  2580.     $('#TransportationCompany').val('');
  2581.     $('#LRNo').val('');
  2582.     showTableAddtional();
  2583.     showTablePI();
  2584.  
  2585.     $('#grossAmtF').text(parseFloat(zero).toFixed(numberOfDecimal));
  2586.     $('#disAmtF').text(parseFloat(zero).toFixed(numberOfDecimal));
  2587.     $('#netAmtF').text(parseFloat(zero).toFixed(numberOfDecimal));
  2588.     $('#chargeAmtF').text(parseFloat(zero).toFixed(numberOfDecimal));
  2589.     $('#taxAmtF').text(parseFloat(zero).toFixed(numberOfDecimal));
  2590.     $('#netTotalF').text(parseFloat(zero).toFixed(numberOfDecimal));
  2591.     $('#TaxableAmt').text(parseFloat(zero).toFixed(numberOfDecimal));
  2592.     $('#NonTaxableAmt').text(parseFloat(zero).toFixed(numberOfDecimal));
  2593.     $('#CosttoParty').text(parseFloat(zero).toFixed(numberOfDecimal));
  2594.     $('#TotalAdditionalCost').text(parseFloat(zero).toFixed(numberOfDecimal));
  2595.     $('#gtotal').text(parseFloat(zero).toFixed(numberOfDecimal));
  2596.     $('#gCostToparty').text(parseFloat(zero).toFixed(numberOfDecimal));
  2597.     $('#ginvoiceTotal').text(parseFloat(zero).toFixed(numberOfDecimal));
  2598.     $('#billAmount').val(parseFloat(zero).toFixed(numberOfDecimal));
  2599.     transAmt = $('#billAmount').val();
  2600.     $('#totalAmount').val(parseFloat(zero).toFixed(numberOfDecimal));
  2601.     $('.tranSQPer_BillTax').val(parseFloat(zero).toFixed(numberOfDecimal));
  2602.     $('.tranSQAmt_BillTax').val(parseFloat(zero).toFixed(numberOfDecimal));
  2603.     $('.tranSQPer_ExciseDuty').val(parseFloat(zero).toFixed(numberOfDecimal));
  2604.     $('.tranSQAmt_ExciseDuty').val(parseFloat(zero).toFixed(numberOfDecimal));
  2605.     $('.tranSQPer_BillDiscount').val(parseFloat(zero).toFixed(numberOfDecimal));
  2606.     $('.tranSQAmt_BillDiscount').val(parseFloat(zero).toFixed(numberOfDecimal));
  2607.     ChargeGet_ByProductId(0);
  2608.     setTimeout(function () {
  2609.         $('.VoucherType').addClass('displayNone');
  2610.         $('#divOrderNo').addClass('displayNone');
  2611.         $('#divReceiptNo').addClass('displayNone');
  2612.         $('#PurchaseAccountComboFill').focus();
  2613.     }, 200);
  2614.  
  2615. }
  2616. //clearPI
  2617. function clearPI() {
  2618.     for (var i = 0; i < localStorage.length + 1000; i++) {
  2619.         localStorage.removeItem('keyPI' + i);
  2620.     }
  2621.     for (var j = 0; j < localStorage.length + 1000; j++) {
  2622.         localStorage.removeItem('keyAdd' + j);
  2623.     }
  2624.     for (var k = 0; k < localStorage.length + 1000; k++) {
  2625.         localStorage.removeItem('keyTax' + k);
  2626.     }
  2627.     lastkeyTax = 0;
  2628.     isTax = 0;
  2629.     isImport = 0;
  2630.     lastkeyPI = 0;
  2631.     lastkeyAdd = 0;
  2632.  
  2633.     $('#qty').val(0);
  2634.     $('#disPer').val(0);
  2635.     $('#disAmt').val(0);
  2636.     $('#taxAmt').val(0);
  2637.     $('#rate').val(0);
  2638.     $('#productName').children('option:first-child').select2();
  2639.     //make them zero
  2640.     taxable = 0;
  2641.     nonTaxable = 0;
  2642.     grossAmt = 0;
  2643.     disAmt = 0;
  2644.     netAmt = 0;
  2645.     taxAmt = 0;
  2646.     netTotal = 0;
  2647.     CosttoParty = 0; gCosttoParty = 0;
  2648.     TotalAdditionalCost = 0;
  2649.     totalInvoice = 0;
  2650.     unitConversionId = 0;
  2651.     purchacid = 0; cashpartyid = 0; datas = []; Additionaldatas = []; purchaselist = []; addcpstList = [];
  2652.     purchaseDetailsId = 0; addcrlist = []; addDrlist = [];
  2653.     purchlpid = 0; cashbanklpid = 0; discountlpid = 0; partyBalanceId = 0; stockpostid = 0;
  2654.     addcostlpid = []; addcostid = 0; taxlpid = []; chargedatas = [];
  2655.     datas = []; Additionaldatas = []; taxdatas = [];
  2656.     chargedatas = []; chargeList = []; purchaselist = []; stockpostinglist = []; taxLists = []; addcpstList = [];
  2657.     purchacid = 0; cashpartyid = 0; addcrlist = []; addDrlist = []; ledgerpostingId = []; ledgers = [];
  2658. }
  2659. //show entry table
  2660. function showTableAddtional() {
  2661.     var h = '';
  2662.     for (var i = 0; i < lastkeyAdd + 1; i++) {
  2663.         if (localStorage.getItem('keyAdd' + i)) {
  2664.             h += '<tr class="additionalBodydata" data-id="' + JSON.parse(localStorage.getItem('keyAdd' + i)).keyidAdd + '">';
  2665.             h += '<td>' + JSON.parse(localStorage.getItem('keyAdd' + i)).AddLedgerName + '</td>';
  2666.             h += '<td>' + JSON.parse(localStorage.getItem('keyAdd' + i)).AddCashpartyName + '</td>';
  2667.             h += '<td>' + JSON.parse(localStorage.getItem('keyAdd' + i)).AddtionalAmount + '</td>';
  2668.             h += '<td><button title="Delete" type="button" class="btn btn-danger" data-id="' + parseFloat(JSON.parse(localStorage.getItem('keyAdd' + i)).keyidAdd) + '"' +
  2669.                 'onclick="deleteAdd(' + parseFloat(JSON.parse(localStorage.getItem('keyAdd' + i)).keyidAdd) + ')"><i class="fa fa-trash-alt"></i></button></td>';
  2670.             h += '</tr>';
  2671.         }
  2672.     }
  2673.     $('#additionalBody').html(h);
  2674. }
  2675. //show entry table
  2676. var id = 0;
  2677. function showTablePI() {
  2678.     var h = '';
  2679.     grossAmt = 0;
  2680.     disAmt = 0;
  2681.     netAmt = 0;
  2682.     taxAmt = 0;
  2683.     netTotal = 0;
  2684.     chargeAmt = 0;
  2685.     j = 1;
  2686.     for (var i = 0; i < lastkeyPI + 1; i++) {
  2687.         if (localStorage.getItem('keyPI' + i)) {
  2688.             h += '<tr class="PIdata" data-id="' + JSON.parse(localStorage.getItem('keyPI' + i)).keyidPI + '">';
  2689.             h += '<td>' + j + '</td>';
  2690.             h += '<td>' + JSON.parse(localStorage.getItem('keyPI' + i)).ProductCode + '</td>';
  2691.             h += '<td>' + JSON.parse(localStorage.getItem('keyPI' + i)).ProductName + '</td>';
  2692.             h += '<td>' + JSON.parse(localStorage.getItem('keyPI' + i)).Qty + '</td>';
  2693.             h += '<td>' + JSON.parse(localStorage.getItem('keyPI' + i)).Unit + '</td>';
  2694.             h += '<td>' + JSON.parse(localStorage.getItem('keyPI' + i)).Godown + '</td>';
  2695.             h += '<td>' + JSON.parse(localStorage.getItem('keyPI' + i)).Rack + '</td>';
  2696.             h += '<td>' + JSON.parse(localStorage.getItem('keyPI' + i)).Batch + '</td>';
  2697.             h += '<td>' + JSON.parse(localStorage.getItem('keyPI' + i)).Rate + '</td>';
  2698.             h += '<td>' + JSON.parse(localStorage.getItem('keyPI' + i)).GrossValue + '</td>';
  2699.             grossAmt += parseFloat(JSON.parse(localStorage.getItem('keyPI' + i)).GrossValue);
  2700.             h += '<td>' + JSON.parse(localStorage.getItem('keyPI' + i)).DisPer + '</td>';
  2701.             h += '<td>' + JSON.parse(localStorage.getItem('keyPI' + i)).Discount + '</td>';
  2702.             if (JSON.parse(localStorage.getItem('keyPI' + i)).Discount > 0) {
  2703.                 disAmt += parseFloat(JSON.parse(localStorage.getItem('keyPI' + i)).Discount);
  2704.             }
  2705.             h += '<td>' + JSON.parse(localStorage.getItem('keyPI' + i)).TotalAmt + '</td>';
  2706.             netAmt += parseFloat(JSON.parse(localStorage.getItem('keyPI' + i)).TotalAmt);
  2707.             h += '<td>' + JSON.parse(localStorage.getItem('keyPI' + i)).Charge + '</td>';
  2708.             h += '<td>' + JSON.parse(localStorage.getItem('keyPI' + i)).chargeAmt + '</td>';
  2709.             if (JSON.parse(localStorage.getItem('keyPI' + i)).chargeAmt > 0) {
  2710.                 chargeAmt += parseFloat(JSON.parse(localStorage.getItem('keyPI' + i)).chargeAmt);
  2711.             }
  2712.             h += '<td>' + JSON.parse(localStorage.getItem('keyPI' + i)).TaxableVal + '</td>';
  2713.             h += '<td>' + JSON.parse(localStorage.getItem('keyPI' + i)).ImportValue + '</td>';
  2714.             h += '<td>' + JSON.parse(localStorage.getItem('keyPI' + i)).Tax + '</td>';
  2715.             h += '<td>' + JSON.parse(localStorage.getItem('keyPI' + i)).TaxAmt + '</td>';
  2716.             taxAmt += parseFloat(JSON.parse(localStorage.getItem('keyPI' + i)).TaxAmt);
  2717.             h += '<td>' + JSON.parse(localStorage.getItem('keyPI' + i)).Total + '</td>';
  2718.             netTotal += parseFloat(JSON.parse(localStorage.getItem('keyPI' + i)).Total);
  2719.             h += '<td><button title="Delete" type="button" class="btn btn-sm btn-danger" data-id="' + parseFloat(JSON.parse(localStorage.getItem('keyPI' + i)).keyidPI) + '"' +
  2720.                 'onclick="deletePI(' + parseFloat(JSON.parse(localStorage.getItem('keyPI' + i)).keyidPI) + ')"><i class="fa fa-trash-alt"></i></button></td>';
  2721.             h += '</tr>';
  2722.             j++;
  2723.             $('#grossAmtF').text(parseFloat(grossAmt).toFixed(numberOfDecimal));
  2724.             $('#disAmtF').text(parseFloat(disAmt).toFixed(numberOfDecimal));
  2725.             $('#netAmtF').text(parseFloat(netAmt).toFixed(numberOfDecimal));
  2726.             $('#taxAmtF').text(parseFloat(taxAmt).toFixed(numberOfDecimal));
  2727.             $('#chargeAmtF').text(parseFloat(chargeAmt).toFixed(numberOfDecimal));
  2728.             $('#netTotalF').text(parseFloat(netTotal).toFixed(numberOfDecimal));
  2729.             if (isTax === 1) {
  2730.                 //$('#TaxableAmt').text(parseFloat(taxable).toFixed(numberOfDecimal));
  2731.                 if (parseFloat(JSON.parse(localStorage.getItem('keyPI' + i)).TaxAmt) > 0) {
  2732.                     $('#gtaxAble').val(parseFloat(taxable).toFixed(numberOfDecimal));
  2733.                 }
  2734.             }
  2735.  
  2736.             if (taxAmt > 0) {
  2737.                 $('#gTaxAmt').val(parseFloat(taxAmt).toFixed(numberOfDecimal));
  2738.             }
  2739.             else {
  2740.                 $('#gTaxAmt').val(parseFloat(zero).toFixed(numberOfDecimal));
  2741.             }
  2742.  
  2743.             totalGrand = netTotal + parseFloat($('#TotalAdditionalCost').text());
  2744.             //$('#NonTaxableAmt').text(parseFloat(nonTaxable).toFixed(numberOfDecimal));
  2745.             $('#ginvoiceTotal').text(parseFloat(netTotal).toFixed(numberOfDecimal));
  2746.             $('#billAmount').val(parseFloat(netTotal).toFixed(numberOfDecimal));
  2747.             transAmt = $('#billAmount').val();
  2748.             $('#totalAmount').val(parseFloat(netTotal).toFixed(numberOfDecimal));
  2749.             $('#gtotal').text(parseFloat(netTotal).toFixed(numberOfDecimal));
  2750.             gCosttoParty = parseFloat(netTotal) + parseFloat($('#CosttoParty').text());
  2751.             $('#gCostToparty').text(parseFloat(gCosttoParty).toFixed(numberOfDecimal));
  2752.             $('#gtotal').text(parseFloat(totalGrand).toFixed(numberOfDecimal));
  2753.  
  2754.         }
  2755.     }
  2756.     $('#PIbody').html(h);
  2757.     for (var k = 0; k < localStorage.length + 100; k++) {
  2758.         localStorage.removeItem('keyTax' + k);
  2759.     }
  2760.     lastkeyTax = 0;
  2761.     gettaxdetails();
  2762.  
  2763.     for (var l = 0; l < localStorage.length + 100; l++) {
  2764.         localStorage.removeItem('keyCharge' + l);
  2765.     }
  2766.     lastkeyCharge = 0;
  2767.     getChargeDetails();
  2768.     purchaseDetailsId = 0; stockpostid = 0;
  2769. }
  2770. //
  2771. function gettaxdetails() {
  2772.     var thisTaxid = 0;
  2773.     for (var k = 0; k < lastkeyPI + 1; k++) {
  2774.         if (localStorage.getItem('keyPI' + k)) {
  2775.             //add tax details
  2776.             if (JSON.parse(localStorage.getItem('keyPI' + k)).TaxAmt > 0) {
  2777.                 for (var ij = 0; ij < lastkeyTax + 1; ij++) {
  2778.                     if (localStorage.getItem('keyTax' + parseInt(lastkeyTax - ij))) {
  2779.                         if (parseInt(JSON.parse(localStorage.getItem('keyPI' + id)).TaxID) === parseInt(JSON.parse(localStorage.getItem('keyTax' + parseInt(lastkeyTax - ij))).TaxID)) {
  2780.                             thisTaxid = JSON.parse(localStorage.getItem('keyTax' + parseInt(lastkeyTax - ij))).keyidTax;
  2781.  
  2782.                             var thistax = JSON.parse(localStorage.getItem('keyTax' + thisTaxid)).TaxID;
  2783.                             var thisTaxAmt = JSON.parse(localStorage.getItem('keyTax' + thisTaxid)).TaxAmt;
  2784.                             var uptaxAmt = parseFloat(thisTaxAmt) + parseFloat(JSON.parse(localStorage.getItem('keyPI' + k)).TaxAmt);
  2785.                             localStorage.removeItem('keyTax' + thisTaxid);
  2786.                             localStorage.setItem('keyTax' + thisTaxid, JSON.stringify({
  2787.                                 keyidTax: thisTaxid,
  2788.                                 TaxID: thistax,
  2789.                                 TaxAmt: parseFloat(uptaxAmt).toFixed(numberOfDecimal)
  2790.                             }));
  2791.                             lastkeyTax = thisTaxid;
  2792.                         }
  2793.                     }
  2794.                     else {
  2795.                         lastkeyTax = ij;
  2796.                         localStorage.setItem('keyTax' + ij, JSON.stringify({
  2797.                             keyidTax: ij,
  2798.                             TaxID: JSON.parse(localStorage.getItem('keyPI' + ij)).TaxID,
  2799.                             TaxAmt: JSON.parse(localStorage.getItem('keyPI' + ij)).TaxAmt
  2800.                         }));
  2801.                     }
  2802.                 }
  2803.             }
  2804.             //var checktax = checkTaxnamePI();
  2805.             //if (checktax) {
  2806.             //    var thistax = '', thisTaxAmt = 0;
  2807.             //    //get tax details
  2808.             //    thistax = JSON.parse(localStorage.getItem('keyPI' + k)).TaxID;
  2809.             //    thisTaxAmt = JSON.parse(localStorage.getItem('keyPI' + k)).TaxAmt;
  2810.             //    var taxlpid = JSON.parse(localStorage.getItem('keyPI' + k)).taxlpid;
  2811.             //    //remove tax details
  2812.             //    thisTaxAmt = parseFloat(JSON.parse(localStorage.getItem('keyPI' + parseInt(k - 1))).TaxAmt) + parseFloat(JSON.parse(localStorage.getItem('keyPI' + k)).TaxAmt);
  2813.             //    localStorage.removeItem('keyTax' + parseInt(k - 1));
  2814.             //    localStorage.setItem('keyTax' + parseInt(k - 1), JSON.stringify({
  2815.             //        keyidTax: parseInt(k - 1),
  2816.             //        TaxID: thistax,
  2817.             //        taxlpid: taxlpid,
  2818.             //        TaxAmt: thisTaxAmt
  2819.             //    }));
  2820.             //}
  2821.             //else {
  2822.             //    localStorage.setItem('keyTax' + k, JSON.stringify({
  2823.             //        keyidTax: k,
  2824.             //        TaxID: JSON.parse(localStorage.getItem('keyPI' + k)).TaxID,
  2825.             //        taxlpid: JSON.parse(localStorage.getItem('keyPI' + k)).taxlpid,
  2826.             //        TaxAmt: JSON.parse(localStorage.getItem('keyPI' + k)).TaxAmt
  2827.             //    }));
  2828.             //}
  2829.             //if (ij > lastkeyTax) {
  2830.             //    lastkeyTax = ij;
  2831.             //}
  2832.         }
  2833.     }
  2834. }
  2835. //
  2836. function getChargeDetails() {
  2837.     let thisChargeid = 0;
  2838.     for (let k = 0; k < lastkeyPI + 1; k++) {
  2839.         if (localStorage.getItem('keyPI' + k)) {
  2840.             //add charge details
  2841.             if (JSON.parse(localStorage.getItem('keyPI' + k)).chargeAmt > 0) {
  2842.                 for (var ij = 0; ij < lastkeyCharge + 1; ij++) {
  2843.                     if (localStorage.getItem('keyCharge' + parseInt(lastkeyCharge - ij))) {
  2844.                         if (parseInt(JSON.parse(localStorage.getItem('keyPI' + id)).ChargeID) === parseInt(JSON.parse(localStorage.getItem('keyCharge' + parseInt(lastkeyCharge - ij))).ChargeID)) {
  2845.                             thisChargeid = JSON.parse(localStorage.getItem('keyCharge' + parseInt(lastkeyCharge - ij))).keyidTax;
  2846.  
  2847.                             var thistax = JSON.parse(localStorage.getItem('keyCharge' + thisChargeid)).ChargeID;
  2848.                             var thisChargeAmt = JSON.parse(localStorage.getItem('keyCharge' + thisChargeid)).ChargeAmt;
  2849.                             var upChargeAmt = parseFloat(thisChargeAmt) + parseFloat(JSON.parse(localStorage.getItem('keyPI' + k)).chargeAmt);
  2850.                             localStorage.removeItem('keyCharge' + thisChargeid);
  2851.                             localStorage.setItem('keyCharge' + thisChargeid, JSON.stringify({
  2852.                                 keyidTax: thisChargeid,
  2853.                                 ChargeID: thistax,
  2854.                                 ChargeAmt: parseFloat(upChargeAmt).toFixed(numberOfDecimal)
  2855.                             }));
  2856.                             lastkeyCharge = thisChargeid;
  2857.                         }
  2858.                     }
  2859.                     else {
  2860.                         lastkeyCharge = ij;
  2861.                         localStorage.setItem('keyCharge' + ij, JSON.stringify({
  2862.                             keyidTax: ij,
  2863.                             ChargeID: JSON.parse(localStorage.getItem('keyPI' + ij)).ChargeID,
  2864.                             ChargeAmt: JSON.parse(localStorage.getItem('keyPI' + ij)).chargeAmt
  2865.                         }));
  2866.                     }
  2867.                 }
  2868.             }
  2869.         }
  2870.     }
  2871. }
  2872. //reset
  2873. function resetAdditional() {
  2874.     $('#AdditionalCostComboFill').val('0').select2();
  2875.     $('#cashPartyAdditional').val('0').select2();
  2876.     $('#additionalAmt').val('');
  2877. }
  2878. //reset
  2879. function reset() {
  2880.     $('#barCode').val('');
  2881.     $('#productCode').val('');
  2882.     $('#productName').val('');
  2883.     $('#qty').val('0');
  2884.     $('#unitId').val('0').select2();
  2885.     $('#goDownid').val('0').select2();
  2886.     $('#rackId').val('0').select2();
  2887.     $('#batchId').val('');
  2888.     $('#rate').val('0');
  2889.     $('#disPer').val('0');
  2890.     $('#grossValue').val('0');
  2891.     $('#disAmt').val('0');
  2892.     $('#Netamt').val('0');
  2893.     $('#ImportValue').val('0');
  2894.     $('#taxId').val('1').select2();
  2895.     $('#chargeAmt').val('0');
  2896.     $('#TaxableVal').val('0');
  2897.     $('#taxAmt').val('0');
  2898.     $('#NetTotal').val('0');
  2899.     unitConversionId = 0;
  2900.     NetAmtWithImport = 0;
  2901.     purchaseDetailsId = 0; stockpostid = 0;
  2902.     productType = 0;
  2903.  
  2904.     purchaseDetailsId = 0; stockpostid = 0;
  2905. }
  2906. //check ledger name exist
  2907. function checkAddtionalLedger() {
  2908.     count = localStorage.length;
  2909.     if (localStorage.length > 0) {
  2910.         for (var i = 0; i < localStorage.length; i++) {
  2911.             if (localStorage.getItem('keyAdd' + i)) {
  2912.                 if (parseInt(JSON.parse(localStorage.getItem('keyAdd' + i)).AdditionalLedger) === parseInt($('#AdditionalCostComboFill').val())) {
  2913.                     count = count;
  2914.                 }
  2915.                 else {
  2916.                     count -= 1;
  2917.                 }
  2918.             }
  2919.             else {
  2920.                 count -= 1;
  2921.             }
  2922.  
  2923.         }
  2924.     }
  2925.     if (count === 0) {
  2926.         return false;
  2927.     }
  2928.     else {
  2929.         return true;
  2930.     }
  2931. }
  2932. //check product name exist
  2933. function checkProductnamePI() {
  2934.     count = localStorage.length;
  2935.     if (localStorage.length > 0) {
  2936.         for (var i = 0; i < localStorage.length; i++) {
  2937.             if (localStorage.getItem('keyPI' + i)) {
  2938.                 if (JSON.parse(localStorage.getItem('keyPI' + i)).ProductCode === $('#productCode').val()) {
  2939.                     count = count;
  2940.                 }
  2941.                 else {
  2942.                     count -= 1;
  2943.                 }
  2944.             }
  2945.             else {
  2946.                 count -= 1;
  2947.             }
  2948.  
  2949.         }
  2950.     }
  2951.     if (count === 0) {
  2952.         return false;
  2953.     }
  2954.     else {
  2955.         return true;
  2956.     }
  2957. }
  2958. //check product details id exist
  2959. function getcheckpurchid(purchaseDetailsId) {
  2960.     count = localStorage.length;
  2961.     if (localStorage.length > 0) {
  2962.         for (var i = 0; i < localStorage.length; i++) {
  2963.             if (localStorage.getItem('keyPI' + i)) {
  2964.                 if (JSON.parse(localStorage.getItem('keyPI' + i)).purchaseDetailsId === purchaseDetailsId) {
  2965.                     count = count;
  2966.                 }
  2967.                 else {
  2968.                     count -= 1;
  2969.                 }
  2970.             }
  2971.             else {
  2972.                 count -= 1;
  2973.             }
  2974.  
  2975.         }
  2976.     }
  2977.     if (count === 0) {
  2978.         return false;
  2979.     }
  2980.     else {
  2981.         return true;
  2982.     }
  2983. }
  2984. //check addcostid exist
  2985. function getcheckaddcostid(additionalCostId) {
  2986.     count = localStorage.length;
  2987.     if (localStorage.length > 0) {
  2988.         for (var i = 0; i < localStorage.length; i++) {
  2989.             if (localStorage.getItem('keyAdd' + i)) {
  2990.                 if (parseInt(JSON.parse(localStorage.getItem('keyAdd' + i)).addcostid) === parseInt(additionalCostId)) {
  2991.                     count = count;
  2992.                 }
  2993.                 else {
  2994.                     count -= 1;
  2995.                 }
  2996.             }
  2997.             else {
  2998.                 count -= 1;
  2999.             }
  3000.  
  3001.         }
  3002.     }
  3003.     if (count === 0) {
  3004.         return false;
  3005.     }
  3006.     else {
  3007.         return true;
  3008.     }
  3009. }
  3010. //check tax id exist
  3011. function checkTaxnamePI() {
  3012.     count = localStorage.length;
  3013.     if (localStorage.length > 0) {
  3014.         for (var i = 0; i < localStorage.length; i++) {
  3015.             if (localStorage.getItem('keyTax' + i)) {
  3016.                 for (var h = 0; h < taxLists.length; h++) {
  3017.                     if (JSON.parse(localStorage.getItem('keyTax' + i)).TaxID === taxLists[h]) {
  3018.                         count = count;
  3019.                     }
  3020.                     else {
  3021.                         count -= 1;
  3022.                     }
  3023.                 }
  3024.             }
  3025.             else {
  3026.                 count -= 1;
  3027.             }
  3028.         }
  3029.     }
  3030.     if (count === 0) {
  3031.         return false;
  3032.     }
  3033.     else {
  3034.         return true;
  3035.     }
  3036. }
  3037. //calculate tax
  3038. function calTax() {
  3039.     var taxper = 0, taxamt = 0;
  3040.     if ($('#taxId').val() > 0) {
  3041.         taxper = getRate($('#taxId').val());
  3042.         if (taxper > 0) {
  3043.             taxamt = (taxper / 100) * $('#TaxableVal').val();
  3044.         }
  3045.     }
  3046.     $('#taxAmt').val(parseFloat(taxamt).toFixed(numberOfDecimal));
  3047.     //$('#NetTotal').val((parseFloat($('#Netamt').val()) + parseFloat(taxamt)).toFixed(numberOfDecimal));
  3048.     $('#NetTotal').val((parseFloat(NetAmtWithImport) + parseFloat($('#TaxableVal').val()) + parseFloat(taxamt)).toFixed(numberOfDecimal));
  3049. }
  3050. //calculate tax
  3051. function calCharge() {
  3052.     var taxper = 0, taxamt = 0;
  3053.     if ($('#chargeId').val() > 1) {
  3054.         taxper = getRate($('#chargeId').val());
  3055.         if (taxper > 0) {
  3056.             taxamt = (taxper / 100) * $('#Netamt').val();
  3057.         }
  3058.     }
  3059.     $('#chargeAmt').val(parseFloat(taxamt).toFixed(numberOfDecimal));
  3060.     //$('#NetTotal').val((parseFloat($('#Netamt').val()) + parseFloat(taxamt)).toFixed(numberOfDecimal));
  3061.     $('#TaxableVal').val((parseFloat($('#Netamt').val()) + parseFloat(taxamt)).toFixed(numberOfDecimal));
  3062. }
  3063. //get rate for taxdp
  3064. function getRate(taxId) {
  3065.     var r = 0;
  3066.     $('#PInarration').addClass('active');
  3067.     if (taxId > 0) {
  3068.         $.ajax({
  3069.             url: '/PurchaseInvoice/TaxView?DbName=' + DbName + '&taxId=' + taxId,
  3070.             type: 'get',
  3071.             async: false,
  3072.             success: function (data) {
  3073.                 r = data.rate;
  3074.             },
  3075.             error: function () {
  3076.                 toastr.error('system error');
  3077.             }
  3078.         });
  3079.     }
  3080.     return r;
  3081. }
  3082. //load VoucherTypeSelectionComboFill
  3083. function VoucherTypeSelectionComboFill(name) {
  3084.     $.ajax({
  3085.         url: '/PurchaseInvoice/VoucherTypeSelectionComboFill?DbName=' + DbName + '&name=' + name,
  3086.         type: 'get',
  3087.         async: false,
  3088.         success: function (data) {
  3089.             $('#VoucherTypeSelectionComboFill').empty();
  3090.             //$('#VoucherTypeSelectionComboFill').append('<option value="0"> Choose one</option>');
  3091.             $('#VoucherTypeSelectionComboFill').append('<option value="' + data.voucherTypeId + '"> ' + data.voucherTypeName + '</option>');
  3092.         },
  3093.         error: function () {
  3094.             toastr.error('system error');
  3095.         }
  3096.     });
  3097. }
  3098.  
  3099. //load VoucherTypeSelectionComboFill
  3100. function VoucherType() {
  3101.     $.ajax({
  3102.         url: '/VoucherTypeTax/VoucherTypeDP?DbName=' + DbName,
  3103.         type: 'get',
  3104.         async: false,
  3105.         success: function (data) {
  3106.             $('#VoucherTypeSelectionComboFill').empty();
  3107.             $('#VoucherTypeSelectionComboFill').append('<option value="0"> NA</option>');
  3108.             $.each(data, function (i, item) {
  3109.                 $('#VoucherTypeSelectionComboFill').append('<option value="' + item.voucherTypeId + '"> ' + item.voucherTypeName + '</option>');
  3110.             });
  3111.         },
  3112.         error: function () {
  3113.             toastr.error('system error');
  3114.         }
  3115.     });
  3116. }
  3117.  
  3118. function GetMaterialReceiptNoForPurchaseInvoice() {
  3119.     $.ajax({
  3120.         url: '/MaterialIn/GetMaterialReceiptNoForPurchaseInvoice?DbName=' + DbName + '&ledgerId=' + ledgerId,
  3121.         type: 'get',
  3122.         async: false,
  3123.         success: function (data) {
  3124.             $('#ReceiptNo').empty();
  3125.             $('#ReceiptNo').append('<option value="0"> Choose one</option>');
  3126.             $.each(data, function (i, item) {
  3127.                 $('#ReceiptNo').append('<option value="' + item.materialReceiptMasterId + '"> ' + item.invoiceNo + '</option>');
  3128.             });
  3129.         },
  3130.         error: function () {
  3131.             toastr.error('system error');
  3132.         }
  3133.     });
  3134. }
  3135.  
  3136. function GetPurchaseOrderNoForPurchaseInvoice() {
  3137.     $.ajax({
  3138.         url: '/PurchaseOrder/GetPurchaseOrderNoForPurchaseInvoice?DbName=' + DbName + '&ledgerId=' + ledgerId,
  3139.         type: 'get',
  3140.         async: false,
  3141.         success: function (data) {
  3142.             $('#orderNo').empty();
  3143.             $('#orderNo').append('<option value="0"> Choose one</option>');
  3144.             $.each(data, function (i, item) {
  3145.                 $('#orderNo').append('<option value="' + item.purchaseOrderMasterId + '"> ' + item.orderNo + '</option>');
  3146.             });
  3147.         },
  3148.         error: function () {
  3149.             toastr.error('system error');
  3150.         }
  3151.     });
  3152. }
  3153.  
  3154.  
  3155. //save PI
  3156. function SavePI() {
  3157.     $('#loading').fadeIn();
  3158.     if ($('#PurchaseAccountComboFill').val() === '0') {
  3159.         toastr.info('Please Select Purchase Account Ledger');
  3160.         $('#loading').fadeOut();
  3161.         $('#PurchaseAccountComboFill').focus();
  3162.     }
  3163.     else {
  3164.         if ($('#invoiceNo').val() === '') {
  3165.             toastr.info('Please Enter Invoice Number');
  3166.             $('#loading').fadeOut();
  3167.             $('#invoiceNo').focus();
  3168.         }
  3169.         else {
  3170.             if ($('#InAD').val() === '') {
  3171.                 toastr.info('Please Select Invoice Date');
  3172.                 $('#loading').fadeOut();
  3173.                 $('#InAD').focus();
  3174.             }
  3175.             else {
  3176.                 if ($('#CashOrPartyComboFill').val() === '0') {
  3177.                     toastr.info('Please Select Party Ledger');
  3178.                     $('#loading').fadeOut();
  3179.                     $('#CashOrPartyComboFill').focus();
  3180.                 }
  3181.                 else {
  3182.                     if (accountgpId === 27) {
  3183.                         if (negativeCash === 0) {
  3184.                             if ($('#ginvoiceTotal').text() > CashAmount) {
  3185.                                 toastr.error('Invoice Total is greater than Cash Amount');
  3186.                             }
  3187.                             else {
  3188.                                 $('#btnSaveYes').addClass('savePI');
  3189.                                 $('#save').modal('show');
  3190.                             }
  3191.                         }
  3192.                         else {
  3193.                             $('#btnSaveYes').addClass('savePI');
  3194.                             $('#save').modal('show');
  3195.                         }
  3196.                     }
  3197.                     else {
  3198.                         $('#btnSaveYes').addClass('savePI');
  3199.                         $('#save').modal('show');
  3200.                     }
  3201.                 }
  3202.             }
  3203.         }
  3204.     }
  3205. }
  3206. //save after confirm
  3207. //Kritika Changed this
  3208. async function ConfirmSave() {
  3209.     if ($('.btnyes').hasClass('savePI')) {
  3210.         $('#loading').fadeIn();
  3211.         $('#btnNumb').focus();
  3212.         let di = 0, adi = 0, taxi = 0, chargi = 0;
  3213.         for (var i = 0; i < lastkeyPI + 1; i++) {
  3214.             if (localStorage.getItem('keyPI' + i)) {
  3215.                 datas[di] = JSON.stringify({
  3216.                     ProductId: JSON.parse(localStorage.getItem('keyPI' + i)).ProductId,
  3217.                     productType: JSON.parse(localStorage.getItem('keyPI' + i)).productType,
  3218.                     ProductCode: JSON.parse(localStorage.getItem('keyPI' + i)).ProductCode,
  3219.                     ProductName: JSON.parse(localStorage.getItem('keyPI' + i)).ProductName,
  3220.                     Qty: JSON.parse(localStorage.getItem('keyPI' + i)).Qty,
  3221.                     Unit: JSON.parse(localStorage.getItem('keyPI' + i)).Unit,
  3222.                     UnitID: JSON.parse(localStorage.getItem('keyPI' + i)).UnitID,
  3223.                     Godown: JSON.parse(localStorage.getItem('keyPI' + i)).Godown,
  3224.                     GodownID: JSON.parse(localStorage.getItem('keyPI' + i)).GodownID,
  3225.                     Rack: JSON.parse(localStorage.getItem('keyPI' + i)).Rack,
  3226.                     RackID: JSON.parse(localStorage.getItem('keyPI' + i)).RackID,
  3227.                     unitConversionId: JSON.parse(localStorage.getItem('keyPI' + i)).unitConversionId,
  3228.                     Batch: JSON.parse(localStorage.getItem('keyPI' + i)).Batch,
  3229.                     Rate: JSON.parse(localStorage.getItem('keyPI' + i)).Rate,
  3230.                     DisPer: JSON.parse(localStorage.getItem('keyPI' + i)).DisPer,
  3231.                     GrossValue: JSON.parse(localStorage.getItem('keyPI' + i)).GrossValue,
  3232.                     Discount: JSON.parse(localStorage.getItem('keyPI' + i)).Discount,
  3233.                     TotalAmt: JSON.parse(localStorage.getItem('keyPI' + i)).TotalAmt,
  3234.                     ChargeID: JSON.parse(localStorage.getItem('keyPI' + i)).ChargeID,
  3235.                     chargeAmt: JSON.parse(localStorage.getItem('keyPI' + i)).chargeAmt,
  3236.                     TaxableVal: JSON.parse(localStorage.getItem('keyPI' + i)).TaxableVal,
  3237.                     ImportValue: JSON.parse(localStorage.getItem('keyPI' + i)).ImportValue,
  3238.                     Tax: JSON.parse(localStorage.getItem('keyPI' + i)).Tax,
  3239.                     TaxID: JSON.parse(localStorage.getItem('keyPI' + i)).TaxID,
  3240.                     TaxAmt: JSON.parse(localStorage.getItem('keyPI' + i)).TaxAmt,
  3241.                     Total: JSON.parse(localStorage.getItem('keyPI' + i)).Total,
  3242.                     expiryDate: JSON.parse(localStorage.getItem('keyPI' + i)).expiryDate,
  3243.                     purchaseOrderMasterId: JSON.parse(localStorage.getItem('keyPI' + i)).purchaseOrderMasterId,
  3244.                     materialReceiptMasterId: JSON.parse(localStorage.getItem('keyPI' + i)).materialReceiptMasterId,
  3245.                     //action: JSON.parse(localStorage.getItem('keyPI' + i)).action
  3246.                 });
  3247.                 di++;
  3248.             }
  3249.         }
  3250.         for (var j = 0; j < lastkeyAdd + 1; j++) {
  3251.             if (localStorage.getItem('keyAdd' + j)) {
  3252.                 Additionaldatas[adi] = JSON.stringify({
  3253.                     AddCashpartyName: JSON.parse(localStorage.getItem('keyAdd' + j)).AddCashpartyName,
  3254.                     AddLedgerName: JSON.parse(localStorage.getItem('keyAdd' + j)).AddLedgerName,
  3255.                     AdditionalCashparty: JSON.parse(localStorage.getItem('keyAdd' + j)).AdditionalCashparty,
  3256.                     AdditionalLedger: JSON.parse(localStorage.getItem('keyAdd' + j)).AdditionalLedger,
  3257.                     AddtionalAmount: JSON.parse(localStorage.getItem('keyAdd' + j)).AddtionalAmount
  3258.                 });
  3259.                 adi++;
  3260.             }
  3261.         }
  3262.         for (var k = 0; k < lastkeyTax + 1; k++) {
  3263.             if (localStorage.getItem('keyTax' + k)) {
  3264.                 taxdatas[taxi] = JSON.stringify({
  3265.                     TaxID: JSON.parse(localStorage.getItem('keyTax' + k)).TaxID,
  3266.                     TaxAmt: JSON.parse(localStorage.getItem('keyTax' + k)).TaxAmt
  3267.                 });
  3268.                 taxi++;
  3269.             }
  3270.         }
  3271.         for (var l = 0; l < lastkeyCharge + 1; l++) {
  3272.             if (localStorage.getItem('keyCharge' + l)) {
  3273.                 if (parseInt(JSON.parse(localStorage.getItem('keyCharge' + l)).ChargeAmt) > 0) {
  3274.                     chargedatas[chargi] = JSON.stringify({
  3275.                         ChargeID: JSON.parse(localStorage.getItem('keyCharge' + l)).ChargeID,
  3276.                         ChargeAmt: JSON.parse(localStorage.getItem('keyCharge' + l)).ChargeAmt
  3277.                     });
  3278.                     chargi++;
  3279.                 }
  3280.             }
  3281.         }
  3282.         checkMOD = checkMaterialOrderCmp();
  3283.         if (checkMOD) {
  3284.             masterAction = 'Accepted';
  3285.         }
  3286.         else {
  3287.             masterAction = 'Partial';
  3288.         }
  3289.  
  3290.         checkPOD = checkPurchaseOrderCmp();
  3291.         if (checkPOD) {
  3292.             masterAction = 'Accepted';
  3293.         }
  3294.         else {
  3295.             masterAction = 'Partial';
  3296.         }
  3297.  
  3298.         var totalDiscount = parseFloat(billDiscount) + parseFloat($('#disAmtF').text());
  3299.         var dataObj = {
  3300.             DbName: DbName,
  3301.             date: $('#VAD').val(),
  3302.             purchaseOrderMasterId: $('#orderNo').val(),
  3303.             materialReceiptMasterId: $('#ReceiptNo').val(),
  3304.             ledgerId: $('#CashOrPartyComboFill').val(),
  3305.             vendorInvoiceNo: $('#invoiceNo').val().trim(),
  3306.             vendorInvoiceDate: $('#InAD').val(),
  3307.             creditPeriod: $('#crPeriod').val().trim(),
  3308.             narration: $('#PInarration').val().trim(),
  3309.             purchaseAccount: $('#PurchaseAccountComboFill').val(),
  3310.             additionalCost: $('#TotalAdditionalCost').text(),
  3311.             totalTax: $('#taxAmtF').text(),//total tax
  3312.             costtoParty: $('#gCostToparty').text(),
  3313.             grandTotal: $('#gtotal').text(),
  3314.             invoiceTotal: $('#ginvoiceTotal').text(),// party amount
  3315.             lrNo: $('#LRNo').val().trim(),
  3316.             orderType: $('#purchaseMode').val(),
  3317.             transportationCompany: $('#TransportationCompany').val().trim(),
  3318.             ProductNetTotal: $('#netTotalF').text(),
  3319.             //grossValue: $('#netTotalF').text(),//Kritika Changed this
  3320.             grossValue: $('#grossAmtF').text(),
  3321.             totalDiscount: totalDiscount, //total discount
  3322.             list: datas,
  3323.             addList: Additionaldatas,
  3324.             taxlist: taxdatas,
  3325.             chargeList: chargedatas,
  3326.             masterAction: masterAction,
  3327.             BillTaxPercentage: BillTaxPercentage,
  3328.             BillTaxAmount: BillTaxAmount,
  3329.             BillExciseDutyPercentage: BillExciseDutyPercentage,
  3330.             BillExciseDutyAmount: BillExciseDutyAmount,
  3331.             BillDiscountPercentage: BillDiscountPercentage,
  3332.             billDiscount: billDiscount//$('#gbillDiscount').val()
  3333.         };
  3334.         if ($(".PrintBill").is(":checked")) {
  3335.             PrintBill = 1;
  3336.         }
  3337.         else {
  3338.             PrintBill = 0;
  3339.         }
  3340.         await $.ajax({
  3341.             type: 'post',
  3342.             dataType: 'json',
  3343.             async: false,
  3344.             data: dataObj,
  3345.             url: '/PurchaseInvoice/SavePI',
  3346.             success: function (data) {
  3347.                 if (data.data === '1') {
  3348.                     toastr.success('Added Successfully');
  3349.                     resetForm();
  3350.                     $(".btnprintyes").attr('data-invoiceno', data.invoiceNo);
  3351.                     if (PrintBill === 1) {
  3352.                         $(".btnprintyes").trigger('click');
  3353.                     }
  3354.                     $('#loading').fadeOut();
  3355.                 }
  3356.                 else if (data.data === '0') {
  3357.                     toastr.error('Not added' + data);
  3358.                     $('#loading').fadeOut();
  3359.                     setTimeout(function () {
  3360.                         $('#PurchaseAccountComboFill').focus();
  3361.                     }, 100);
  3362.                 }
  3363.                 else {
  3364.                     toastr.error(data.data);
  3365.                     $('#loading').fadeOut();
  3366.                     setTimeout(function () {
  3367.                         $('#PurchaseAccountComboFill').focus();
  3368.                     }, 100);
  3369.                 }
  3370.                 $('#save').modal('hide');
  3371.             },
  3372.             error: function (ex) {
  3373.                 toastr.error('Unable to add/record data: ' + ex.statusText);
  3374.                 $('#loading').fadeOut();
  3375.                 $('#save').modal('hide');
  3376.                 setTimeout(function () {
  3377.                     $('#PurchaseAccountComboFill').focus();
  3378.                 }, 100);
  3379.             }
  3380.         });
  3381.         $('.btnyes').removeClass('savePI');
  3382.     }
  3383. }
  3384. //delete functions
  3385. function DeleteAllpi() {
  3386.     $('#delete-modal').modal('show');
  3387.     $('#btnDeleteAll').addClass('pi');
  3388. }
  3389. function ConfirmDeleteAll() {
  3390.     if ($('.yes').hasClass('pi')) {
  3391.         for (var i = 0; i < localStorage.length + 2; i++) {
  3392.             if (localStorage.getItem('keyPI' + i)) {
  3393.                 grossAmt -= parseFloat(JSON.parse(localStorage.getItem('keyPI' + i)).GrossValue);
  3394.                 if (JSON.parse(localStorage.getItem('keyPI' + i)).Discount > 0) {
  3395.                     disAmt -= parseFloat(JSON.parse(localStorage.getItem('keyPI' + i)).Discount);
  3396.                 }
  3397.                 netAmt -= parseFloat(JSON.parse(localStorage.getItem('keyPI' + i)).NetValue);
  3398.                 taxAmt -= parseFloat(JSON.parse(localStorage.getItem('keyPI' + i)).TaxAmt);
  3399.                 netTotal -= parseFloat(JSON.parse(localStorage.getItem('keyPI' + i)).Total);
  3400.                 if (parseFloat(JSON.parse(localStorage.getItem('keyPI' + i)).TaxAmt) === 0) {
  3401.                     taxable -= parseFloat((JSON.parse(localStorage.getItem('keyPI' + i)).NetValue));
  3402.                     if (isTax === 1) {
  3403.                         $('#TaxableAmt').text(parseFloat(taxable).toFixed(numberOfDecimal));
  3404.                         $('#gtaxAble').val(parseFloat(taxable).toFixed(numberOfDecimal));
  3405.                     }
  3406.                 }
  3407.                 if (parseFloat(JSON.parse(localStorage.getItem('keyPI' + i)).TaxAmt) > 0) {
  3408.                     nonTaxable -= parseFloat((JSON.parse(localStorage.getItem('keyPI' + i)).NetValue));
  3409.                     $('#NonTaxableAmt').text(parseFloat(nonTaxable).toFixed(numberOfDecimal));
  3410.                     taxAmt -= parseFloat(JSON.parse(localStorage.getItem('keyPI' + i)).TaxAmt);
  3411.                     $('#taxAmtF').text(parseFloat(taxAmt).toFixed(numberOfDecimal));
  3412.                     $('#gTaxAmt').val(parseFloat(taxAmt).toFixed(numberOfDecimal));
  3413.                 }
  3414.  
  3415.                 $('#grossAmtF').text(parseFloat(grossAmt).toFixed(numberOfDecimal));
  3416.                 $('#disAmtF').text(parseFloat(disAmt).toFixed(numberOfDecimal));
  3417.                 $('#netAmtF').text(parseFloat(netAmt).toFixed(numberOfDecimal));
  3418.                 $('#netTotalF').text(parseFloat(netTotal).toFixed(numberOfDecimal));
  3419.  
  3420.                 totalGrand = netTotal + parseFloat($('#TotalAdditionalCost').text());
  3421.                 //$('#NonTaxableAmt').text(parseFloat(nonTaxable).toFixed(numberOfDecimal));
  3422.                 $('#ginvoiceTotal').text(parseFloat(netTotal).toFixed(numberOfDecimal));
  3423.                 $('#billAmount').val(parseFloat(netTotal).toFixed(numberOfDecimal));
  3424.                 transAmt = $('#billAmount').val();
  3425.                 $('#totalAmount').val(parseFloat(netTotal).toFixed(numberOfDecimal));
  3426.                 gCosttoParty = parseFloat(netTotal) + parseFloat($('#CosttoParty').text());
  3427.                 $('#gCostToparty').text(parseFloat(gCosttoParty).toFixed(numberOfDecimal));
  3428.                 $('#gtotal').text(parseFloat(totalGrand).toFixed(numberOfDecimal));
  3429.                 localStorage.removeItem('keyPI' + i);
  3430.             }
  3431.         }
  3432.         lastkeyPI = 0;
  3433.         toastr.success('All Record Deleted!');
  3434.         showTablePI();
  3435.         $('#productCode').focus();
  3436.         //caldiscount();
  3437.     }
  3438.     else if ($('.yes').hasClass('additional')) {
  3439.         for (var j = 0; j < localStorage.length + 2; j++) {
  3440.             if (localStorage.getItem('keyAdd' + j)) {
  3441.                 TotalAdditionalCost -= parseFloat(JSON.parse(localStorage.getItem('keyAdd' + j)).AddtionalAmount);
  3442.                 gCosttoParty -= parseFloat(JSON.parse(localStorage.getItem('keyAdd' + j)).AddtionalAmount);
  3443.                 if (parseInt($('#CashOrPartyComboFill').val()) === JSON.parse(localStorage.getItem('keyAdd' + j)).AdditionalCashparty ||
  3444.                     $('#CashOrPartyComboFill').val() === JSON.parse(localStorage.getItem('keyAdd' + j)).AdditionalCashparty) {
  3445.  
  3446.                     CosttoParty -= parseFloat(JSON.parse(localStorage.getItem('keyAdd' + j)).AddtionalAmount);
  3447.                 }
  3448.                 if (parseFloat(JSON.parse(localStorage.getItem('keyAdd' + j)).isAddTax) === 1) {
  3449.                     taxable -= parseFloat(JSON.parse(localStorage.getItem('keyAdd' + j)).AddtionalAmount);
  3450.                 }
  3451.                 else {
  3452.                     nonTaxable -= parseFloat(JSON.parse(localStorage.getItem('keyAdd' + j)).AddtionalAmount);
  3453.                 }
  3454.                 var discount = 0;
  3455.                 if ($('#gbillDiscount').val() > 0) {
  3456.                     discount = $('#gbillDiscount').val();
  3457.                 }
  3458.                 $('#TotalAdditionalCost').text(parseFloat(TotalAdditionalCost).toFixed(numberOfDecimal));
  3459.                 //totalGrand = parseFloat(nonTaxable) + parseFloat(taxable) + parseFloat($('#gTaxAmt').val());
  3460.  
  3461.                 totalGrand = parseFloat($('#TotalAdditionalCost').text()) + parseFloat($('#ginvoiceTotal').text()) + parseFloat(discount);
  3462.                 totalInvoice = parseFloat($('#netTotalF').text()) - parseFloat($('#gbillDiscount').val());
  3463.                 $('#AdditionalCostComboFill').focus(); $('#NonTaxableAmt').text(parseFloat(nonTaxable).toFixed(numberOfDecimal));
  3464.                 $('#gtotal').text(parseFloat(totalGrand).toFixed(numberOfDecimal));
  3465.                 $('#ginvoiceTotal').text(parseFloat(totalInvoice).toFixed(numberOfDecimal));
  3466.                 $('#billAmount').val(parseFloat(totalInvoice).toFixed(numberOfDecimal));
  3467.                 transAmt = $('#billAmount').val();
  3468.                 $('#totalAmount').val(parseFloat(totalInvoice).toFixed(numberOfDecimal));
  3469.                 $('#CosttoParty').text(parseFloat(CosttoParty).toFixed(numberOfDecimal));
  3470.                 gCosttoParty = parseFloat(CosttoParty) + parseFloat($('#ginvoiceTotal').text());
  3471.                 $('#gCostToparty').text(parseFloat(gCosttoParty).toFixed(numberOfDecimal));
  3472.                 localStorage.removeItem('keyAdd' + j);
  3473.  
  3474.             }
  3475.         }
  3476.         lastkeyAdd = 0;
  3477.         toastr.success('All Record Deleted!');
  3478.         showTableAddtional();
  3479.         $('#AdditionalCostComboFill').focus();
  3480.     }
  3481.     else if ($('.yes').hasClass('singleAdd')) {
  3482.         TotalAdditionalCost -= parseFloat(JSON.parse(localStorage.getItem('keyAdd' + deleteid)).AddtionalAmount);
  3483.         gCosttoParty -= parseFloat(JSON.parse(localStorage.getItem('keyAdd' + deleteid)).AddtionalAmount);
  3484.         if (parseInt($('#CashOrPartyComboFill').val()) === JSON.parse(localStorage.getItem('keyAdd' + deleteid)).AdditionalCashparty ||
  3485.             $('#CashOrPartyComboFill').val() === JSON.parse(localStorage.getItem('keyAdd' + deleteid)).AdditionalCashparty) {
  3486.             CosttoParty -= parseFloat(JSON.parse(localStorage.getItem('keyAdd' + deleteid)).AddtionalAmount);
  3487.         }
  3488.         if (parseFloat(JSON.parse(localStorage.getItem('keyAdd' + deleteid)).isAddTax) === 1) {
  3489.             taxable -= parseFloat(JSON.parse(localStorage.getItem('keyAdd' + deleteid)).AddtionalAmount);
  3490.         }
  3491.         else {
  3492.             nonTaxable -= parseFloat(JSON.parse(localStorage.getItem('keyAdd' + deleteid)).AddtionalAmount);
  3493.         }
  3494.         var gdiscount = 0;
  3495.         if ($('#gbillDiscount').val() > 0) {
  3496.             gdiscount = $('#gbillDiscount').val();
  3497.         }
  3498.         $('#TotalAdditionalCost').text(parseFloat(TotalAdditionalCost).toFixed(numberOfDecimal));
  3499.         //totalGrand = parseFloat(nonTaxable) + parseFloat(taxable) + parseFloat($('#gTaxAmt').val());
  3500.  
  3501.         totalGrand = parseFloat($('#TotalAdditionalCost').text()) + parseFloat($('#ginvoiceTotal').text()) + parseFloat(gdiscount);
  3502.         totalInvoice = parseFloat($('#netTotalF').text()) - parseFloat($('#gbillDiscount').val());
  3503.         toastr.success('Record Deleted!');
  3504.         $('#AdditionalCostComboFill').focus(); $('#NonTaxableAmt').text(parseFloat(nonTaxable).toFixed(numberOfDecimal));
  3505.         $('#gtotal').text(parseFloat(totalGrand).toFixed(numberOfDecimal));
  3506.         $('#ginvoiceTotal').text(parseFloat(totalInvoice).toFixed(numberOfDecimal));
  3507.         $('#billAmount').val(parseFloat(totalInvoice).toFixed(numberOfDecimal));
  3508.         transAmt = $('#billAmount').val();
  3509.         $('#totalAmount').val(parseFloat(totalInvoice).toFixed(numberOfDecimal));
  3510.         $('#CosttoParty').text(parseFloat(CosttoParty).toFixed(numberOfDecimal));
  3511.         gCosttoParty = parseFloat(CosttoParty) + parseFloat($('#ginvoiceTotal').text());
  3512.         $('#gCostToparty').text(parseFloat(gCosttoParty).toFixed(numberOfDecimal));
  3513.         localStorage.removeItem('keyAdd' + deleteid);
  3514.         showTableAddtional();
  3515.         //caldiscount();
  3516.     }
  3517.     else if ($('.yes').hasClass('singlePi')) {
  3518.         grossAmt -= parseFloat(JSON.parse(localStorage.getItem('keyPI' + deleteid)).GrossValue);
  3519.         if (JSON.parse(localStorage.getItem('keyPI' + deleteid)).Discount > 0) {
  3520.             disAmt -= parseFloat(JSON.parse(localStorage.getItem('keyPI' + deleteid)).Discount);
  3521.         }
  3522.         netAmt -= parseFloat(JSON.parse(localStorage.getItem('keyPI' + deleteid)).NetValue);
  3523.         taxAmt -= parseFloat(JSON.parse(localStorage.getItem('keyPI' + deleteid)).TaxAmt);
  3524.         netTotal -= parseFloat(JSON.parse(localStorage.getItem('keyPI' + deleteid)).Total);
  3525.         if (parseFloat(JSON.parse(localStorage.getItem('keyPI' + deleteid)).TaxAmt) === 0) {
  3526.             taxable -= parseFloat((JSON.parse(localStorage.getItem('keyPI' + deleteid)).NetValue));
  3527.             if (isTax === 1) {
  3528.                 $('#TaxableAmt').text(parseFloat(taxable).toFixed(numberOfDecimal));
  3529.                 $('#gtaxAble').val(parseFloat(taxable).toFixed(numberOfDecimal));
  3530.             }
  3531.         }
  3532.         if (parseFloat(JSON.parse(localStorage.getItem('keyPI' + deleteid)).TaxAmt) > 0) {
  3533.             nonTaxable -= parseFloat((JSON.parse(localStorage.getItem('keyPI' + deleteid)).NetValue));
  3534.             $('#NonTaxableAmt').text(parseFloat(nonTaxable).toFixed(numberOfDecimal));
  3535.             taxAmt -= parseFloat(JSON.parse(localStorage.getItem('keyPI' + deleteid)).TaxAmt);
  3536.             $('#taxAmtF').text(parseFloat(taxAmt).toFixed(numberOfDecimal));
  3537.             $('#gTaxAmt').val(parseFloat(taxAmt).toFixed(numberOfDecimal));
  3538.         }
  3539.  
  3540.         $('#grossAmtF').text(parseFloat(grossAmt).toFixed(numberOfDecimal));
  3541.         $('#disAmtF').text(parseFloat(disAmt).toFixed(numberOfDecimal));
  3542.         $('#netAmtF').text(parseFloat(netAmt).toFixed(numberOfDecimal));
  3543.         $('#netTotalF').text(parseFloat(netTotal).toFixed(numberOfDecimal));
  3544.  
  3545.         totalGrand = netTotal + parseFloat($('#TotalAdditionalCost').text());
  3546.         //$('#NonTaxableAmt').text(parseFloat(nonTaxable).toFixed(numberOfDecimal));
  3547.         $('#ginvoiceTotal').text(parseFloat(netTotal).toFixed(numberOfDecimal));
  3548.         $('#billAmount').val(parseFloat(netTotal).toFixed(numberOfDecimal));
  3549.         transAmt = $('#billAmount').val();
  3550.         $('#totalAmount').val(parseFloat(netTotal).toFixed(numberOfDecimal));
  3551.         gCosttoParty = parseFloat(netTotal) + parseFloat($('#CosttoParty').text());
  3552.         $('#gCostToparty').text(parseFloat(gCosttoParty).toFixed(numberOfDecimal));
  3553.         $('#gtotal').text(parseFloat(totalGrand).toFixed(numberOfDecimal));
  3554.  
  3555.         localStorage.removeItem('keyPI' + deleteid);
  3556.         toastr.success('Record Deleted!');
  3557.         showTablePI();
  3558.         $('#productCode').focus();
  3559.     }
  3560. }
  3561. function DeleteAlladd() {
  3562.     $('#delete-modal').modal('show');
  3563.     $('#btnDeleteAll').addClass('additional');
  3564. }
  3565. function deleteAdd(id) {
  3566.     deleteid = id;
  3567.     $('#delete-modal').modal('show');
  3568.     $('#btnDeleteAll').addClass('singleAdd');
  3569. }
  3570. function deletePI(id) {
  3571.     deleteid = id;
  3572.     $('#delete-modal').modal('show');
  3573.     $('#btnDeleteAll').addClass('singlePi');
  3574. }
  3575.  
  3576.  
  3577. function getMaterialMaster(id) {
  3578.     taxAmt = 0;
  3579.     CosttoParty = 0; gCosttoParty = 0;
  3580.     TotalAdditionalCost = 0;
  3581.     nonTaxable = 0;
  3582.     totalInvoice = 0; totalGrand = 0; purchacid = 0; cashpartyid = 0;
  3583.     materialReceiptMasterId = 0;
  3584.     $.ajax({
  3585.         url: '/MaterialIn/MaterialReceiptMasterViewByReceiptMasterId?DbName=' + DbName + '&MaterialReceiptMasterId=' + id,
  3586.         type: 'get',
  3587.         async: false,
  3588.         success: function (data) {
  3589.             $('#PInarration').val(data.narration);
  3590.             $('#TransportationCompany').val(data.transportationCompany);
  3591.             $('#LRNo').val(data.lrNo);
  3592.             $('#ginvoiceTotal').text(data.totalAmount);
  3593.             $('#billAmount').val(data.totalAmount);
  3594.             transAmt = $('#billAmount').val();
  3595.             $('#totalAmount').val(data.totalAmount);
  3596.             materialReceiptMasterId = data.materialReceiptMasterId;
  3597.             taxAmt = data.totalTax;
  3598.             totalInvoice = data.totalAmount; totalGrand = data.grandTotal;
  3599.             gCosttoParty += data.totalAmount;
  3600.             $('#gtotal').text(parseFloat(totalGrand).toFixed(numberOfDecimal));
  3601.             $('#ginvoiceTotal').text(parseFloat(totalInvoice).toFixed(numberOfDecimal));
  3602.             $('#billAmount').val(parseFloat(totalInvoice).toFixed(numberOfDecimal));
  3603.             transAmt = $('#billAmount').val();
  3604.             $('#totalAmount').val(parseFloat(totalInvoice).toFixed(numberOfDecimal));
  3605.             getMaterialDetails(data.materialReceiptMasterId);
  3606.         },
  3607.         error: function () {
  3608.             $('#loading').fadeOut();
  3609.             toastr.error('system error: Purchase invoice get by voucher number');
  3610.         }
  3611.     });
  3612.     LedgerpostingGetDetailsList(id);
  3613. }
  3614.  
  3615. function getPurchaseOrderMaster(id) {
  3616.     taxAmt = 0;
  3617.     CosttoParty = 0; gCosttoParty = 0;
  3618.     TotalAdditionalCost = 0;
  3619.     nonTaxable = 0;
  3620.     totalInvoice = 0; totalGrand = 0; purchacid = 0; cashpartyid = 0;
  3621.     purchaseOrderMasterId = 0;
  3622.     $.ajax({
  3623.         url: '/PurchaseOrder/PurchaseOrderMasterViewByOrderMasterId?DbName=' + DbName + '&purchaseOrderMasterId=' + id,
  3624.         type: 'get',
  3625.         async: false,
  3626.         success: function (data) {
  3627.             $('#PInarration').val(data.narration);
  3628.             $('#ginvoiceTotal').text(data.totalAmount);
  3629.             $('#billAmount').val(data.totalAmount);
  3630.             transAmt = $('#billAmount').val();
  3631.             $('#totalAmount').val(data.totalAmount);
  3632.             purchaseOrderMasterId = data.purchaseOrderMasterId;
  3633.             taxAmt = data.totalTax;
  3634.             totalInvoice = data.totalAmount; totalGrand = data.grandTotal;
  3635.             gCosttoParty += data.totalAmount;
  3636.             $('#gtotal').text(parseFloat(totalGrand).toFixed(numberOfDecimal));
  3637.             $('#ginvoiceTotal').text(parseFloat(totalInvoice).toFixed(numberOfDecimal));
  3638.             $('#billAmount').val(parseFloat(totalInvoice).toFixed(numberOfDecimal));
  3639.             transAmt = $('#billAmount').val();
  3640.             $('#totalAmount').val(parseFloat(totalInvoice).toFixed(numberOfDecimal));
  3641.             getPurchaseOrderDetails(purchaseOrderMasterId);
  3642.         },
  3643.         error: function () {
  3644.             $('#loading').fadeOut();
  3645.             toastr.error('system error: Purchase invoice get by voucher number');
  3646.         }
  3647.     });
  3648.     LedgerpostingGetDetailsList(id);
  3649. }
  3650.  
  3651. //purchase invoice update
  3652. function getMaster(id) {
  3653.     taxAmt = 0;
  3654.     CosttoParty = 0; gCosttoParty = 0;
  3655.     TotalAdditionalCost = 0;
  3656.     nonTaxable = 0;
  3657.     totalInvoice = 0; totalGrand = 0; purchacid = 0; cashpartyid = 0;
  3658.     LedgerpostingGetDetailsList(id);
  3659.  
  3660.     $.ajax({
  3661.         url: '/PurchaseInvoice/PurchaseMasterbyInvoiceNoVoucherTypeId',
  3662.         type: 'get',
  3663.         async: false,
  3664.         data: {
  3665.             DbName: DbName,
  3666.             invoiceNo: $('#voucherNo').val(),
  3667.             voucherTypeId: 13
  3668.         },
  3669.         success: function (data) {
  3670.             $('#VAD').val(getDate(data.date));
  3671.             $('#InAD').val(getDate(data.vendorInvoiceDate));
  3672.             purchacid = data.purchaseAccount; cashpartyid = data.ledgerId;
  3673.             purchlpid = getledgers(id, data.purchaseAccount);
  3674.             cashbanklpid = getledgers(id, data.ledgerId);
  3675.             partyBalanceId = getpartyBalanceId(id, data.ledgerId);
  3676.             $('#PurchaseAccountComboFill').val(data.purchaseAccount).select2();
  3677.             $('#CashOrPartyComboFill').val(data.ledgerId).select2();
  3678.             CommomAdDateToBs('#InAD', '#InBS');
  3679.             CommomAdDateToBs('#VAD', '#VBS');
  3680.             $('#invoiceNo').val(data.vendorInvoiceNo);
  3681.             $('#crPeriod').val(data.creditPeriod);
  3682.             $('#PInarration').val(data.narration);
  3683.             $('#TransportationCompany').val(data.transportationCompany);
  3684.             $('#LRNo').val(data.lrNo);
  3685.             $('#gbillDiscount').val(data.billDiscount);
  3686.             //$('#gCostToparty').text(data.additionalCost);
  3687.             $('#gTaxAmt').val(data.totalTax);
  3688.             $('#gtotal').text(data.grandTotal);
  3689.             $('#ginvoiceTotal').text(data.totalAmount);
  3690.             $('#billAmount').val(data.totalAmount);
  3691.             transAmt = $('#billAmount').val();
  3692.             $('#totalAmount').val(data.totalAmount);
  3693.             purchaseMasterId = data.purchaseMasterId;
  3694.             taxAmt = data.totalTax;
  3695.             //nonTaxable = data.additionalCost;
  3696.  
  3697.             totalInvoice = data.totalAmount; totalGrand = data.grandTotal;
  3698.             //totalInvoice = $('#netTotalF').text() - $('#gbillDiscount').val();
  3699.             //totalGrand = nonTaxable + taxable + 0;
  3700.             gCosttoParty += data.totalAmount;
  3701.             //$('#NonTaxableAmt').text(parseFloat(nonTaxable).toFixed(numberOfDecimal));
  3702.             $('#gtotal').text(parseFloat(totalGrand).toFixed(numberOfDecimal));
  3703.             $('#ginvoiceTotal').text(parseFloat(totalInvoice).toFixed(numberOfDecimal));
  3704.             $('#billAmount').val(parseFloat(totalInvoice).toFixed(numberOfDecimal));
  3705.             transAmt = $('#billAmount').val();
  3706.             $('#totalAmount').val(parseFloat(totalInvoice).toFixed(numberOfDecimal));
  3707.             getDetails(data.purchaseMasterId, id);
  3708.             getAdditionalCost(id);
  3709.         },
  3710.         error: function () {
  3711.             $('#loading').fadeOut();
  3712.             toastr.error('system error: Purchase invoice get by voucher number');
  3713.         }
  3714.     });
  3715. }
  3716. function Ledgerbyid(id) {
  3717.     var thisacg = 0;
  3718.     $.ajax({
  3719.         url: '/PurchaseInvoice/Ledgerbyid?DbName=' + DbName + '&id=' + id,
  3720.         type: 'get',
  3721.         async: false,
  3722.         success: function (data) {
  3723.             thisacg = data;
  3724.         }
  3725.     });
  3726.     return thisacg;
  3727. }
  3728. function LedgerpostingGetDetailsList(id) {
  3729.     var thislpid = 0;
  3730.     $.ajax({
  3731.         url: '/PurchaseInvoice/LedgerpostingGetDetailsList?DbName=' + DbName + '&invoiceNo=' + id + '&voucherTypeId=13' + '&ledgerId=0',
  3732.         type: 'get',
  3733.         async: false,
  3734.         success: function (data) {
  3735.             var icharge = 0, itax = 0, iadd = 0;
  3736.             $.each(data, function (key, val) {
  3737.                 var thisagid = Ledgerbyid(val.ledgerId);
  3738.                 if (parseInt(thisagid.accountGroupId) === 14) {
  3739.                     if (thisagid.extra2 === 'Charge') {
  3740.                         chargelpid[icharge] = val.ledgerPostingId;
  3741.                     }
  3742.                     else {
  3743.                         discountlpid = val.ledgerPostingId;
  3744.                     }
  3745.                 }
  3746.                 if (parseInt(thisagid.accountGroupId) === 20) {
  3747.                     taxlpid[itax] = val.ledgerPostingId;
  3748.                     itax++;
  3749.                 }
  3750.                 if (parseInt(thisagid.accountGroupId) === 13) {
  3751.                     addcostlpid[iadd] = val.ledgerPostingId;
  3752.                     iadd++;
  3753.                 }
  3754.             });
  3755.         }
  3756.     });
  3757.     return thislpid;
  3758. }
  3759. function getledgers(id, lid) {
  3760.     var thislpid = 0;
  3761.     $.ajax({
  3762.         url: '/PurchaseInvoice/LedgerpostingGetDetails?DbName=' + DbName + '&invoiceNo=' + id + '&voucherTypeId=13' + '&ledgerId=' + lid,
  3763.         type: 'get',
  3764.         async: false,
  3765.         success: function (data) {
  3766.             thislpid = data.ledgerPostingId;
  3767.         }
  3768.     });
  3769.     return thislpid;
  3770. }
  3771.  
  3772. function getMaterialDetails(materialReceiptMasterId) {
  3773.     $.ajax({
  3774.         type: 'get',
  3775.         url: '/MaterialIn/MaterialReceiptDetailsViewByMasterId?DbName=' + DbName + '&MaterialReceiptMasterId=' + materialReceiptMasterId,
  3776.         async: false,
  3777.         success: function (data) {
  3778.             if (data.length > 0) {
  3779.                 $('#productName').empty();
  3780.                 $.each(data, function (key, val) {
  3781.                     $("#productName").append('<option value ="' + val.productCode + '" data-productid="' + val.productId + '" data-rate="' + val.rate + '" data-quantity ="' + val.qty + '" data-batch ="' + val.batchId + '" data-godown="' + val.godownId + '" data-rack="' + val.rackId + '" data-unit="' + val.unitId + '" data-conversionId ="' + val.unitConversionId + '" data-materialreceiptdetailsid ="' + val.materialReceiptDetailsId + '" > ' + val.productName + '</option > ');
  3782.                 });
  3783.                 setTimeout(function () { $('#productName').focus(); }, 500);
  3784.             }
  3785.             else {
  3786.                 toastr.error('No any products');
  3787.             }
  3788.             $('#loading').fadeOut();
  3789.         },
  3790.         error: function () {
  3791.             $('#loading').fadeOut();
  3792.             toastr.error('error while loading sales details');
  3793.         }
  3794.     });
  3795.     //$.ajax({
  3796.     //    url: '/MaterialIn/MaterialReceiptDetailsViewByMasterId?DbName=' + DbName + '&materialReceiptMasterId=' + materialReceiptMasterId,
  3797.     //    type: 'get',
  3798.     //    async: false,
  3799.     //    success: function (data) {
  3800.     //        if (data.length > 0) {
  3801.     //            var j = 0;
  3802.     //            grossAmt = 0;
  3803.     //            disAmt = 0;
  3804.     //            netAmt = 0;
  3805.     //            netTotal = 0;
  3806.     //            $.each(data, function (i, item) {
  3807.     //                var pn = "", un = '', tn = '', gn = '', racn = '', dr = 0;
  3808.     //                purchaselist[i] = item.materialReceiptDetailsId;
  3809.     //                while (localStorage.getItem('keyPI' + j)) {
  3810.     //                    j++;
  3811.     //                }
  3812.     //                $.ajax({
  3813.     //                    url: '/PurchaseInvoice/ProductGetByProductId?DbName=' + DbName + '&productid=' + item.productId,
  3814.     //                    type: 'get',
  3815.     //                    async: false,
  3816.     //                    success: function (data) {
  3817.     //                        pn = data.productName;
  3818.     //                    }
  3819.     //                });
  3820.     //                if (item.unitId === 0) {
  3821.     //                    un = 'NA';
  3822.     //                }
  3823.     //                else {
  3824.     //                    $.ajax({
  3825.     //                        url: '/PurchaseInvoice/Unitbyid?DbName=' + DbName + '&id=' + item.unitId,
  3826.     //                        type: 'get',
  3827.     //                        async: false,
  3828.     //                        success: function (data) {
  3829.     //                            un = data.unitName;
  3830.     //                        }
  3831.     //                    });
  3832.     //                }
  3833.     //                if (item.godownId === 0) {
  3834.     //                    gn = 'NA';
  3835.     //                }
  3836.     //                else {
  3837.     //                    $.ajax({
  3838.     //                        url: '/PurchaseInvoice/GodownView?DbName=' + DbName + '&id=' + item.godownId,
  3839.     //                        type: 'get',
  3840.     //                        async: false,
  3841.     //                        success: function (data) {
  3842.     //                            gn = data.godownName;
  3843.     //                        }
  3844.     //                    });
  3845.     //                }
  3846.     //                if (item.rackId === 0) {
  3847.     //                    racn = 'NA';
  3848.     //                }
  3849.     //                else {
  3850.     //                    $.ajax({
  3851.     //                        url: '/PurchaseInvoice/RackView?DbName=' + DbName + '&id=' + item.rackId,
  3852.     //                        type: 'get',
  3853.     //                        async: false,
  3854.     //                        success: function (data) {
  3855.     //                            racn = data.rackName;
  3856.     //                        }
  3857.     //                    });
  3858.     //                }
  3859.     //                if (item.taxId === 0) {
  3860.     //                    tn = 'NA';
  3861.     //                    nonTaxable += item.netAmount;
  3862.     //                }
  3863.     //                else {
  3864.     //                    taxable += item.netAmount;
  3865.     //                    $.ajax({
  3866.     //                        url: '/PurchaseInvoice/TaxView?DbName=' + DbName + '&taxId=' + item.taxId,
  3867.     //                        type: 'get',
  3868.     //                        async: false,
  3869.     //                        success: function (data) {
  3870.     //                            tn = data.taxName;
  3871.     //                        }
  3872.     //                    });
  3873.     //                }
  3874.     //                if (item.discount === 0) {
  3875.     //                    dr = 0;
  3876.     //                }
  3877.     //                else {
  3878.     //                    dr = parseFloat(item.discount) / parseFloat(item.grossAmount) * 100;
  3879.     //                }
  3880.     //                stockpostid = getstockpostid(id, item.productId);
  3881.     //                stockpostinglist[i] = stockpostid;
  3882.     //                grossAmt += item.grossAmount;
  3883.     //                disAmt += item.discount;
  3884.     //                netAmt += item.netAmount;
  3885.     //                netTotal += item.amount;
  3886.     //                purchaseDetailsId = item.purchaseDetailsId;
  3887.     //                taxLists[i] = item.taxId;
  3888.     //                localStorage.setItem('keyPI' + j, JSON.stringify({
  3889.     //                    keyidPI: j,
  3890.     //                    purchaseDetailsId: purchaseDetailsId,
  3891.     //                    stockpostid: stockpostid,
  3892.     //                    ProductId: item.productId,
  3893.     //                    ProductCode: item.productCode,
  3894.     //                    ProductName: pn,
  3895.     //                    Qty: item.qty,
  3896.     //                    Unit: un,
  3897.     //                    UnitID: item.unitId,
  3898.     //                    Godown: gn,
  3899.     //                    GodownID: item.godownId,
  3900.     //                    Rack: racn,
  3901.     //                    RackID: item.rackId,
  3902.     //                    unitConversionId: item.unitConversionId,
  3903.     //                    Batch: item.batchId,
  3904.     //                    //BatchID: $("#rate").val(),
  3905.     //                    Rate: item.rate,
  3906.     //                    DisPer: dr,
  3907.     //                    GrossValue: item.grossAmount,
  3908.     //                    Discount: item.discount,
  3909.     //                    NetValue: item.netAmount,
  3910.     //                    ImportValue: item.importvalue,
  3911.     //                    Tax: tn,
  3912.     //                    taxlpid: gettaxLedger(item.taxId),
  3913.     //                    TaxID: item.taxId,
  3914.     //                    TaxAmt: item.taxAmount,
  3915.     //                    Total: item.amount,
  3916.     //                    expiryDate: getDate(item.expiryDate)
  3917.     //                }));
  3918.     //                if (j > lastkeyPI) {
  3919.     //                    lastkeyPI = j;
  3920.     //                }
  3921.     //                showTablePI();
  3922.     //            });
  3923.     //        }
  3924.     //    },
  3925.     //    error: function () {
  3926.     //        $('#loading').fadeOut();
  3927.     //        toastr.error('system error: Purchase invoice get details');
  3928.     //    }
  3929.     //});
  3930. }
  3931. function getPurchaseOrderDetails(purchaseOrderMasterId) {
  3932.     $.ajax({
  3933.         type: 'get',
  3934.         url: '/PurchaseOrder/PurchaseOrderDetailsViewByOrderMasterId?DbName=' + DbName + '&purchaseOrderMasterId=' + purchaseOrderMasterId,
  3935.         async: false,
  3936.         success: function (data) {
  3937.             if (data.length > 0) {
  3938.                 $('#productName').empty();
  3939.                 $.each(data, function (key, val) {
  3940.                     $("#productName").append('<option value ="' + val.productCode + '" data-productid="' + val.productId + '" data-rate="' + val.rate + '" data-quantity ="' + val.qty + '" data-batch ="' + val.batchId + '" data-godown="' + val.godownId + '" data-rack="' + val.rackId + '" data-unit="' + val.unitId + '" data-conversionId ="' + val.unitConversionId + '" data-purchaseorderdetailsid ="' + val.purchaseOrderDetailsId + '" > ' + val.productName + '</option > ');
  3941.                 });
  3942.                 setTimeout(function () { $('#productName').focus(); }, 500);
  3943.             }
  3944.             else {
  3945.                 toastr.error('No any products');
  3946.             }
  3947.             $('#loading').fadeOut();
  3948.         },
  3949.         error: function () {
  3950.             $('#loading').fadeOut();
  3951.             toastr.error('error while loading sales details');
  3952.         }
  3953.     });
  3954. }
  3955.  
  3956. function getDetails(purchaseMasterId, id) {
  3957.     $.ajax({
  3958.         url: '/PurchaseInvoice/PurchaseDetailsbypurchaseMasterId?DbName=' + DbName + '&purchaseMasterId=' + purchaseMasterId,
  3959.         type: 'get',
  3960.         async: false,
  3961.         success: function (data) {
  3962.             if (data.length > 0) {
  3963.                 var j = 0;
  3964.                 grossAmt = 0;
  3965.                 disAmt = 0;
  3966.                 netAmt = 0;
  3967.                 netTotal = 0;
  3968.                 $.each(data, function (i, item) {
  3969.                     var pn = "", un = '', charN = '', tn = '', gn = '', racn = '', dr = 0;
  3970.                     purchaselist[i] = item.purchaseDetailsId;
  3971.                     while (localStorage.getItem('keyPI' + j)) {
  3972.                         j++;
  3973.                     }
  3974.                     $.ajax({
  3975.                         url: '/PurchaseInvoice/ProductGetByProductId?DbName=' + DbName + '&productid=' + item.productId,
  3976.                         type: 'get',
  3977.                         async: false,
  3978.                         success: function (data) {
  3979.                             pn = data.productName;
  3980.                         }
  3981.                     });
  3982.                     if (item.unitId === 0) {
  3983.                         un = 'NA';
  3984.                     }
  3985.                     else {
  3986.                         $.ajax({
  3987.                             url: '/PurchaseInvoice/Unitbyid?DbName=' + DbName + '&id=' + item.unitId,
  3988.                             type: 'get',
  3989.                             async: false,
  3990.                             success: function (data) {
  3991.                                 un = data.unitName;
  3992.                             }
  3993.                         });
  3994.                     }
  3995.                     if (item.godownId === 0) {
  3996.                         gn = 'NA';
  3997.                     }
  3998.                     else {
  3999.                         $.ajax({
  4000.                             url: '/PurchaseInvoice/GodownView?DbName=' + DbName + '&id=' + item.godownId,
  4001.                             type: 'get',
  4002.                             async: false,
  4003.                             success: function (data) {
  4004.                                 gn = data.godownName;
  4005.                             }
  4006.                         });
  4007.                     }
  4008.                     if (item.rackId === 0) {
  4009.                         racn = 'NA';
  4010.                     }
  4011.                     else {
  4012.                         $.ajax({
  4013.                             url: '/PurchaseInvoice/RackView?DbName=' + DbName + '&id=' + item.rackId,
  4014.                             type: 'get',
  4015.                             async: false,
  4016.                             success: function (data) {
  4017.                                 racn = data.rackName;
  4018.                             }
  4019.                         });
  4020.                     }
  4021.                     if (item.taxId === 0) {
  4022.                         tn = 'NA';
  4023.                         nonTaxable += item.netAmount;
  4024.                     }
  4025.                     else {
  4026.                         taxable += item.netAmount;
  4027.                         $.ajax({
  4028.                             url: '/PurchaseInvoice/TaxView?DbName=' + DbName + '&taxId=' + item.taxId,
  4029.                             type: 'get',
  4030.                             async: false,
  4031.                             success: function (data) {
  4032.                                 tn = data.taxName;
  4033.                             }
  4034.                         });
  4035.                     }
  4036.                     if (item.discount === 0) {
  4037.                         dr = 0;
  4038.                     }
  4039.                     else {
  4040.                         dr = parseFloat(item.discount) / parseFloat(item.grossAmount) * 100;
  4041.                     }
  4042.                     if (item.ChargeID === 0 || item.ChargeID === 1) {
  4043.                         charN = 'N/A'
  4044.                     }
  4045.                     else {
  4046.                         $.ajax({
  4047.                             url: '/PurchaseInvoice/TaxView?DbName=' + DbName + '&taxId=' + item.ChargeID,
  4048.                             type: 'get',
  4049.                             async: false,
  4050.                             success: function (data) {
  4051.                                 charN = data.taxName;
  4052.                             }
  4053.                         });
  4054.                     }
  4055.                     stockpostid = getstockpostid(id, item.productId);
  4056.                     stockpostinglist[i] = stockpostid;
  4057.                     grossAmt += item.grossAmount;
  4058.                     disAmt += item.discount;
  4059.                     netAmt += item.netAmount;
  4060.                     netTotal += item.amount;
  4061.                     purchaseDetailsId = item.purchaseDetailsId;
  4062.                     taxLists[i] = item.taxId;
  4063.                     localStorage.setItem('keyPI' + j, JSON.stringify({
  4064.                         keyidPI: j,
  4065.                         purchaseDetailsId: purchaseDetailsId,
  4066.                         stockpostid: stockpostid,
  4067.                         ProductId: item.productId,
  4068.                         ProductCode: item.productCode,
  4069.                         ProductName: pn,
  4070.                         Qty: item.qty,
  4071.                         Unit: un,
  4072.                         UnitID: item.unitId,
  4073.                         Godown: gn,
  4074.                         GodownID: item.godownId,
  4075.                         Rack: racn,
  4076.                         RackID: item.rackId,
  4077.                         unitConversionId: item.unitConversionId,
  4078.                         Batch: item.batchId,
  4079.                         //BatchID: $("#rate").val(),
  4080.                         Rate: item.rate,
  4081.                         DisPer: dr,
  4082.                         GrossValue: item.grossAmount,
  4083.                         Discount: item.discount,
  4084.                         TotalAmt: item.netAmount,
  4085.                         Charge: charN,
  4086.                         ChargeID: item.ChargeID,
  4087.                         chargeAmt: item.chargeAmt,
  4088.                         chargelpid: gettaxLedger(item.ChargeID),
  4089.                         TaxableVal: parseFloat(parseFloat(item.netAmount) - parseFloat(item.discount) + parseFloat(item.chargeAmt)).toFixed(numberOfDecimal),
  4090.                         ImportValue: item.importvalue,
  4091.                         Tax: tn,
  4092.                         taxlpid: gettaxLedger(item.taxId),
  4093.                         TaxID: item.taxId,
  4094.                         TaxAmt: item.taxAmount,
  4095.                         Total: item.amount,
  4096.                         expiryDate: getDate(item.expiryDate)
  4097.                     }));
  4098.                     if (j > lastkeyPI) {
  4099.                         lastkeyPI = j;
  4100.                     }
  4101.                     showTablePI();
  4102.                 });
  4103.             }
  4104.         },
  4105.         error: function () {
  4106.             $('#loading').fadeOut();
  4107.             toastr.error('system error: Purchase invoice get details');
  4108.         }
  4109.     });
  4110. }
  4111. function gettaxLedger(taxId) {
  4112.     var id = 0;
  4113.     $.ajax({
  4114.         type: 'get',
  4115.         dataType: 'json',
  4116.         url: '/PurchaseInvoice/TaxView?DbName=' + DbName + '&taxId=' + taxId,
  4117.         success: function (data) {
  4118.             id = data.ledgerId;
  4119.         }
  4120.     });
  4121.     return id;
  4122. }
  4123. function getAdditionalCost(id) {
  4124.     $.ajax({
  4125.         url: '/PurchaseInvoice/AdditionalCostbyInvoiceNoVoucherTypeId?DbName=' + DbName + '&invoiceNo=' + id + '&voucherTypeId= 13',
  4126.         type: 'get',
  4127.         async: false,
  4128.         success: function (data) {
  4129.             if (data.length > 0) {
  4130.                 var j = 0, drname = '', crname = '';
  4131.                 $.each(data, function (i, item) {
  4132.                     addcpstList[i] = item.additionalCostId;
  4133.                     $.ajax({
  4134.                         url: '/PurchaseInvoice/Ledgerbyid?DbName=' + DbName + '&id=' + item.drledgerId,
  4135.                         type: 'get',
  4136.                         async: false,
  4137.                         success: function (data) {
  4138.                             drname = data.ledgerName;
  4139.                         }
  4140.                     });
  4141.                     $.ajax({
  4142.                         url: '/PurchaseInvoice/Ledgerbyid?DbName=' + DbName + '&id=' + item.crledgerId,
  4143.                         type: 'get',
  4144.                         async: false,
  4145.                         success: function (data) {
  4146.                             crname = data.ledgerName;
  4147.                         }
  4148.                     });
  4149.                     while (localStorage.getItem('keyAdd' + j)) {
  4150.                         j++;
  4151.                     }
  4152.                     addcostid = item.additionalCostId;
  4153.                     addcrlist = item.crledgerId; addDrlist = item.drledgerId;
  4154.                     localStorage.setItem('keyAdd' + j, JSON.stringify({
  4155.                         keyidAdd: j,
  4156.                         addcostid: addcostid,
  4157.                         AdditionalLedger: item.drledgerId,
  4158.                         AddLedgerName: drname,
  4159.                         AdditionalCashparty: item.crledgerId,
  4160.                         AddCashpartyName: crname,
  4161.                         AddtionalAmount: item.debit == 0 ? item.credit : item.debit
  4162.                     }));
  4163.                     TotalAdditionalCost += item.debit == 0 ? item.credit : item.debit;
  4164.                     if (item.crledgerId === parseInt($("#CashOrPartyComboFill").val())) {
  4165.                         gCosttoParty += item.debit == 0 ? item.credit : item.debit;
  4166.                         CosttoParty += item.debit == 0 ? item.credit : item.debit;
  4167.                     }
  4168.                     nonTaxable += item.debit == 0 ? item.credit : item.debit;
  4169.                 });
  4170.                 if (j > lastkeyAdd) {
  4171.                     lastkeyAdd = j;
  4172.                 }
  4173.                 showTableAddtional();
  4174.             }
  4175.             totalGrand = 0;
  4176.             $('#gCostToparty').text(parseFloat(gCosttoParty).toFixed(numberOfDecimal));
  4177.             $('#CosttoParty').text(parseFloat(CosttoParty).toFixed(numberOfDecimal));
  4178.             $('#TotalAdditionalCost').text(parseFloat(TotalAdditionalCost).toFixed(numberOfDecimal));
  4179.             $('#NonTaxableAmt').text(parseFloat(nonTaxable).toFixed(numberOfDecimal));
  4180.             caldiscount();
  4181.             $('#loading').fadeOut();
  4182.         },
  4183.         error: function () {
  4184.             toastr.error('system error: Purchase invoice get by voucher number');
  4185.             $('#loading').fadeOut();
  4186.         }
  4187.     });
  4188. }
  4189. function getpartyBalanceId(id, lid) {
  4190.     var thispartyid = 0;
  4191.     $.ajax({
  4192.         url: '/PurchaseInvoice/PartyBalanceDetails?DbName=' + DbName + '&invoiceNo=' + id + '&voucherTypeId=13' + '&ledgerId=' + lid,
  4193.         type: 'get',
  4194.         async: false,
  4195.         success: function (data) {
  4196.             thispartyid = data.partyBalanceId;
  4197.         }
  4198.     });
  4199.     return thispartyid;
  4200. }
  4201. function getstockpostid(id, productId) {
  4202.     var thisstockpostid = 0;
  4203.     $.ajax({
  4204.         url: '/PurchaseInvoice/StockPostingDetails?DbName=' + DbName + '&invoiceNo=' + id + '&voucherTypeId=13' + '&productId=' + productId,
  4205.         type: 'get',
  4206.         async: false,
  4207.         success: function (data) {
  4208.             thisstockpostid = data.stockPostingId;
  4209.         }
  4210.     });
  4211.     return thisstockpostid;
  4212. }
  4213. //update pi
  4214. function updatePI() {
  4215.     $('#loading').fadeIn();
  4216.     if ($('#PurchaseAccountComboFill').val() === '0') {
  4217.         toastr.info('Please Select Purchase Account Ledger');
  4218.         $('#loading').fadeOut();
  4219.         $('#PurchaseAccountComboFill').focus();
  4220.     }
  4221.     else {
  4222.         if ($('#invoiceNo').val() === '') {
  4223.             toastr.info('Please Enter Invoice Number');
  4224.             $('#loading').fadeOut();
  4225.             $('#invoiceNo').focus();
  4226.         }
  4227.         else {
  4228.             if ($('#InAD').val() === '') {
  4229.                 toastr.info('Please Select Invoice Date');
  4230.                 $('#loading').fadeOut();
  4231.                 $('#InAD').focus();
  4232.             }
  4233.             else {
  4234.                 if ($('#CashOrPartyComboFill').val() === '0') {
  4235.                     toastr.info('Please Select Party Ledger');
  4236.                     $('#loading').fadeOut();
  4237.                     $('#CashOrPartyComboFill').focus();
  4238.                 }
  4239.                 else {
  4240.                     $('#btnUpdateYes').addClass('PI');
  4241.                     $('#update').modal('show');
  4242.                 }
  4243.             }
  4244.         }
  4245.     }
  4246. }
  4247. //confirm update
  4248. function ConfirmUpdate() {
  4249.     //$('#loading').fadeIn();
  4250.     //if ($('.btnyes').hasClass('PI')) {
  4251.  
  4252.     //    $('#btnNumb').focus();
  4253.     //    var errorCount = 0;
  4254.     //    //delete product
  4255.     //    if (localStorage.length > 0) {
  4256.     //        for (var kl = 0; kl < localStorage.length; kl++) {
  4257.     //            if (localStorage.getItem('keyPI' + kl)) {
  4258.     //                for (var jl = 0; jl < purchaselist.length; jl++) {
  4259.     //                    var checkpurchid = getcheckpurchid(purchaselist[jl]);
  4260.     //                    if (checkpurchid) {
  4261.     //                        continue;
  4262.     //                    }
  4263.     //                    else {
  4264.     //                        if (JSON.parse(localStorage.getItem('keyPI' + kl)).purchaseDetailsId !== 0) {
  4265.     //                            $.ajax({
  4266.     //                                url: '/PurchaseInvoice/PurchaseDetailsDelete?DbName=' + DbName + '&purchaseDetailsId=' + purchaselist[jl],
  4267.     //                                type: 'post',
  4268.     //                                async: false,
  4269.     //                                success: function () {
  4270.     //                                    $.ajax({
  4271.     //                                        url: '/PurchaseInvoice/StockPostingDelete?DbName=' + DbName + '&stockPostingId=' + stockpostinglist[jl],
  4272.     //                                        type: 'post',
  4273.     //                                        async: false,
  4274.     //                                        success: function () {
  4275.  
  4276.     //                                        },
  4277.     //                                        error: function () {
  4278.     //                                            //toastr.error(ledgerIDList[i]);
  4279.     //                                            errorCount++;
  4280.     //                                        }
  4281.     //                                    });
  4282.     //                                },
  4283.     //                                error: function () {
  4284.     //                                    //toastr.error(ledgerIDList[i]);
  4285.     //                                    errorCount++;
  4286.     //                                }
  4287.     //                            });
  4288.     //                        }
  4289.     //                    }
  4290.     //                }
  4291.  
  4292.     //            }
  4293.     //        }
  4294.     //    }
  4295.     //    if (localStorage.length > 0) {
  4296.     //        for (var kle = 0; kle < localStorage.length; kle++) {
  4297.     //            for (var add = 0; add < addcpstList.length; add++) {
  4298.     //                var checkaddcostid = getcheckaddcostid(addcpstList[add]);
  4299.     //                if (checkaddcostid) {
  4300.     //                    continue;
  4301.     //                }
  4302.     //                else {
  4303.     //                    $.ajax({
  4304.     //                        url: '/PurchaseInvoice/AdditionalCostDelete?DbName=' + DbName + '&additionalCostId=' + addcpstList[add],
  4305.     //                        type: 'post',
  4306.     //                        async: false,
  4307.     //                        success: function () {
  4308.  
  4309.     //                        },
  4310.     //                        error: function () {
  4311.     //                            //toastr.error(ledgerIDList[i]);
  4312.     //                            errorCount++;
  4313.     //                        }
  4314.     //                    });
  4315.     //                }
  4316.     //            }
  4317.     //        }
  4318.     //    }
  4319.     //    if (errorCount === 0) {
  4320.     //        for (var i = 0; i < lastkeyPI + 1; i++) {
  4321.     //            if (localStorage.getItem('keyPI' + i)) {
  4322.     //                datas[i] = JSON.stringify({
  4323.     //                    purchaseDetailsId: JSON.parse(localStorage.getItem('keyPI' + i)).purchaseDetailsId,
  4324.     //                    stockpostid: JSON.parse(localStorage.getItem('keyPI' + i)).stockpostid,
  4325.     //                    ProductId: JSON.parse(localStorage.getItem('keyPI' + i)).ProductId,
  4326.     //                    productType: JSON.parse(localStorage.getItem('keyPI' + i)).productType,
  4327.     //                    ProductCode: JSON.parse(localStorage.getItem('keyPI' + i)).ProductCode,
  4328.     //                    ProductName: JSON.parse(localStorage.getItem('keyPI' + i)).ProductName,
  4329.     //                    unitConversionId: JSON.parse(localStorage.getItem('keyPI' + i)).unitConversionId,
  4330.     //                    Qty: JSON.parse(localStorage.getItem('keyPI' + i)).Qty,
  4331.     //                    Unit: JSON.parse(localStorage.getItem('keyPI' + i)).Unit,
  4332.     //                    UnitID: JSON.parse(localStorage.getItem('keyPI' + i)).UnitID,
  4333.     //                    Godown: JSON.parse(localStorage.getItem('keyPI' + i)).Godown,
  4334.     //                    GodownID: JSON.parse(localStorage.getItem('keyPI' + i)).GodownID,
  4335.     //                    Rack: JSON.parse(localStorage.getItem('keyPI' + i)).Rack,
  4336.     //                    RackID: JSON.parse(localStorage.getItem('keyPI' + i)).RackID,
  4337.     //                    Batch: JSON.parse(localStorage.getItem('keyPI' + i)).Batch,
  4338.     //                    Rate: JSON.parse(localStorage.getItem('keyPI' + i)).Rate,
  4339.     //                    DisPer: JSON.parse(localStorage.getItem('keyPI' + i)).DisPer,
  4340.     //                    GrossValue: JSON.parse(localStorage.getItem('keyPI' + i)).GrossValue,
  4341.     //                    Discount: JSON.parse(localStorage.getItem('keyPI' + i)).Discount,
  4342.     //                    NetValue: JSON.parse(localStorage.getItem('keyPI' + i)).NetValue,
  4343.     //                    ImportValue: JSON.parse(localStorage.getItem('keyPI' + i)).ImportValue,
  4344.     //                    Tax: JSON.parse(localStorage.getItem('keyPI' + i)).Tax,
  4345.     //                    TaxID: JSON.parse(localStorage.getItem('keyPI' + i)).TaxID,
  4346.     //                    TaxAmt: JSON.parse(localStorage.getItem('keyPI' + i)).TaxAmt,
  4347.     //                    Total: JSON.parse(localStorage.getItem('keyPI' + i)).Total,
  4348.     //                    expiryDate: JSON.parse(localStorage.getItem('keyPI' + i)).expiryDate
  4349.     //                });
  4350.     //            }
  4351.     //        }
  4352.     //        for (var j = 0; j < lastkeyAdd + 1; j++) {
  4353.     //            if (localStorage.getItem('keyAdd' + j)) {
  4354.     //                Additionaldatas[j] = JSON.stringify({
  4355.     //                    AddCashpartyName: JSON.parse(localStorage.getItem('keyAdd' + j)).AddCashpartyName,
  4356.     //                    addcostid: JSON.parse(localStorage.getItem('keyAdd' + j)).addcostid,
  4357.     //                    AddLedgerName: JSON.parse(localStorage.getItem('keyAdd' + j)).AddLedgerName,
  4358.     //                    AdditionalCashparty: JSON.parse(localStorage.getItem('keyAdd' + j)).AdditionalCashparty,
  4359.     //                    AdditionalLedger: JSON.parse(localStorage.getItem('keyAdd' + j)).AdditionalLedger,
  4360.     //                    AddtionalAmount: JSON.parse(localStorage.getItem('keyAdd' + j)).AddtionalAmount
  4361.     //                });
  4362.     //            }
  4363.     //        }
  4364.     //        for (var k = 0; k < lastkeyTax + 1; k++) {
  4365.     //            if (localStorage.getItem('keyTax' + k)) {
  4366.     //                taxdatas[k] = JSON.stringify({
  4367.     //                    TaxID: JSON.parse(localStorage.getItem('keyTax' + k)).TaxID,
  4368.     //                    TaxAmt: JSON.parse(localStorage.getItem('keyTax' + k)).TaxAmt
  4369.     //                });
  4370.     //            }
  4371.     //        }
  4372.     //        var totalDiscount = parseFloat($('#gbillDiscount').val()) + parseFloat($('#disAmtF').text());
  4373.     //        var dataObj = {
  4374.     //            DbName: DbName,
  4375.     //            purchaseMasterId: purchaseMasterId,
  4376.     //            ledgerId: $('#CashOrPartyComboFill').val(),
  4377.     //            vendorInvoiceNo: $('#invoiceNo').val().trim(),
  4378.     //            vendorInvoiceDate: $('#InAD').val(),
  4379.     //            creditPeriod: $('#crPeriod').val().trim(),
  4380.     //            narration: $('#PInarration').val().trim(),
  4381.     //            purchaseAccount: $('#PurchaseAccountComboFill').val(),
  4382.     //            additionalCost: $('#TotalAdditionalCost').text(),
  4383.     //            totalTax: $('#gTaxAmt').val(),//total tax
  4384.     //            billDiscount: $('#gbillDiscount').val(),
  4385.     //            costtoParty: $('#gCostToparty').text(),
  4386.     //            grandTotal: $('#gtotal').text(),
  4387.     //            invoiceTotal: $('#ginvoiceTotal').text(),// party amount
  4388.     //            lrNo: $('#LRNo').val().trim(),
  4389.     //            transportationCompany: $('#TransportationCompany').val().trim(),
  4390.     //            ProductNetTotal: $('#netTotalF').text(),
  4391.     //            grossValue: $('#grossAmtF').text(),
  4392.     //            totalDiscount: totalDiscount, //total discount
  4393.     //            list: datas,
  4394.     //            partyBalanceId: partyBalanceId,
  4395.     //            addList: Additionaldatas,
  4396.     //            taxlist: taxdatas,
  4397.     //            addcostlpid: addcostlpid,
  4398.     //            purchlpid: purchlpid,
  4399.     //            cashbanklpid: cashbanklpid,
  4400.     //            taxlpid: taxlpid,
  4401.     //            discountlpid: discountlpid
  4402.     //        };
  4403.     //        $.ajax({
  4404.     //            type: 'post',
  4405.     //            dataType: 'json',
  4406.     //            data: dataObj,
  4407.     //            url: '/PurchaseInvoice/UpdatePI',
  4408.     //            success: function (data) {
  4409.     //                if (data === 1) {
  4410.     //                    toastr.success('Updated Successfully');
  4411.     //                    resetForm();
  4412.     //                    $('#btnPISave').show();
  4413.     //                    $('#btnPIUpdate').hide();
  4414.     //                    $('#loading').fadeOut();
  4415.     //                }
  4416.     //                else {
  4417.     //                    toastr.error('Not added' + data);
  4418.     //                    $('#loading').fadeOut();
  4419.     //                    setTimeout(function () {
  4420.     //                        $('#PurchaseAccountComboFill').focus();
  4421.     //                    }, 100);
  4422.     //                }
  4423.     //                $('#update').modal('hide');
  4424.     //            },
  4425.     //            error: function (ex) {
  4426.     //                toastr.error('Unable to update data' + ex.statusText);
  4427.     //                $('#loading').fadeOut();
  4428.     //                $('#update').modal('hide');
  4429.     //                setTimeout(function () {
  4430.     //                    $('#PurchaseAccountComboFill').focus();
  4431.     //                }, 100);
  4432.     //            }
  4433.     //        });
  4434.     //    }
  4435.     //    else {
  4436.     //        $('#loading').fadeOut();
  4437.     //        toastr.error('system error: record update could not be saved');
  4438.     //        $('#update').modal('hide');
  4439.     //        setTimeout(function () {
  4440.     //            $('#PurchaseAccountComboFill').focus();
  4441.     //        }, 100);
  4442.     //    }
  4443.     //    $('#btnUpdateYes').removeClass('PI');
  4444.     //}
  4445. }
Add Comment
Please, Sign In to add comment