Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var isTax = 0, isAddTax = 0, isImport = 0, ismultipleunit = 0, PId = 0, unitConversionId = 0, productName = '', purchaseDetailsId = 0, purchaseMasterId = 0;
- var isfree = 0, lastkeyPI = 0, originalRate = 0;
- var lastkeyAdd = 0, lastkeyTax = 0, lastkeyCharge = 0;
- var datas = [], Additionaldatas = [], taxdatas = [], chargedatas = [], chargeList = [], purchaselist = [], stockpostinglist = [], taxLists = [], addcpstList = [], purchacid = 0, cashpartyid = 0, addcrlist = [], addDrlist = [], ledgerpostingId = [], ledgers = [];
- //make them zero
- 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;
- var zero = 0, NetAmtWithImport = 0, pindex = 0, productType = 0;
- var deleteid = 0;
- var addcostlpid = [], addcostid = 0, chargelpid = [], taxlpid = [], purchlpid = 0, cashbanklpid = 0, discountlpid = 0, partyBalanceId = 0, stockpostid = 0;
- var PrintBill = 0;
- var ledgerId = 0;
- var typeOfVoucher = '';
- var materialReceiptMasterId = 0;
- var materialReceiptDetailsId = 0;
- var purchaseOrderMasterId = 0;
- var purchaseOrderDetailsId = 0;
- var orderQTY = 0, masterAction = '', invoiceNo = 0;
- var accountgpId = 0, CashAmount = 0, id = 0, editId = 0, chargeAmt = 0;
- negativeCash = parseInt(JSON.parse(localStorage.getItem("KeyCompanyDetails")).negativeCash);
- var ServRate = 0, ServAmt = 0,
- numberOfDecimal = parseInt($.trim(JSON.parse(localStorage.getItem("KeyCompanyDetails")).numberOfDecimal) === '' ?
- 3 : JSON.parse(localStorage.getItem("KeyCompanyDetails")).numberOfDecimal);
- var BillDiscountPercentage = 0, billDiscount = 0, BillExciseDutyAmount = 0, BillExciseDutyPercentage = 0,
- BillTaxAmount = 0, BillTaxPercentage = 0;
- $(window).on('load', function () {
- $('#loading').fadeOut();
- });
- $(document).on('ready', function () {
- $('#loading').fadeOut();
- });
- function getSequence() {
- $.ajax({
- url: '/TransactionSequence/TransactionSequence_GetbyType',
- data: {
- Type: 'purchase'
- },
- success: function (data) {
- var h = ``;
- $.each(data, (i, val) => {
- if (i === 0) {
- h += ` <div><label>${val.Sequence} :</label>
- <input type="text" class="ts percentage form-control tranSQPer_${val.Sequence.replace(/\s/g, "")}"
- placeholder = "%"
- onkeypress="calPerTans('first', 'tranSQPer_${val.Sequence.replace(/\s/g, "")}', 'tranSQAmt_${val.Sequence.replace(/\s/g, "")}')"
- id="tranSQPer_${val.Sequence.replace(/\s/g, "")}" />
- <input type="text" class="ts amt form-control tranSQAmt_${val.Sequence.replace(/\s/g, "")}"
- placeholder = "Amount"
- onkeypress="calTans('first', 'tranSQAmt_${val.Sequence.replace(/\s/g, "")}', 'tranSQPer_${val.Sequence.replace(/\s/g, "")}')"
- id="tranSQAmt_${val.Sequence.replace(/\s/g, "")}" />
- </div>`;
- }
- else {
- if (val.Sequence.replace(/\s/g, "") === 'BillDiscount') {
- h += ` <div><label>${val.Sequence} :</label>
- <input type="text" class="ts percentage form-control tranSQPer_${val.Sequence.replace(/\s/g, "")}"
- placeholder = "%"
- onkeypress="calPerTans('discount', 'tranSQPer_${val.Sequence.replace(/\s/g, "")}', 'tranSQAmt_${val.Sequence.replace(/\s/g, "")}')"
- id="tranSQPer_${val.Sequence.replace(/\s/g, "")}" />
- <input type="text" class="ts amt form-control tranSQAmt_${val.Sequence.replace(/\s/g, "")}"
- placeholder = "Amount"
- onkeypress="calTans('discount', 'tranSQAmt_${val.Sequence.replace(/\s/g, "")}', 'tranSQPer_${val.Sequence.replace(/\s/g, "")}')"
- id="tranSQAmt_${val.Sequence.replace(/\s/g, "")}" />
- </div>`;
- }
- else {
- h += ` <div><label>${val.Sequence} :</label>
- <input type="text" class="ts percentage form-control tranSQPer_${val.Sequence.replace(/\s/g, "")}"
- placeholder = "%"
- onkeypress="calPerTans('other', 'tranSQPer_${val.Sequence.replace(/\s/g, "")}', 'tranSQAmt_${val.Sequence.replace(/\s/g, "")}')"
- id="tranSQPer_${val.Sequence.replace(/\s/g, "")}" />
- <input type="text" class="ts amt form-control tranSQAmt_${val.Sequence.replace(/\s/g, "")}"
- placeholder = "Amount"
- onkeypress="calTans('other', 'tranSQAmt_${val.Sequence.replace(/\s/g, "")}', 'tranSQPer_${val.Sequence.replace(/\s/g, "")}')"
- id="tranSQAmt_${val.Sequence.replace(/\s/g, "")}" />
- </div>`;
- }
- }
- });
- $('#tranSeq').html(h);
- $.each(data, (i, val) => {
- $('#tranSQAmt_' + val.Sequence.replace(/\s/g, "")).keypress(function (e) {
- if (e.which === 46) {
- if ($(this).val().indexOf('.') !== -1) {
- return false;
- }
- }
- if (e.which !== 8 && e.which !== 0 && e.which !== 46 && (e.which < 48 || e.which > 57)) {
- return false;
- }
- });
- $('#tranSQPer_' + val.Sequence.replace(/\s/g, "")).keypress(function (e) {
- if (e.which === 46) {
- if ($(this).val().indexOf('.') !== -1) {
- return false;
- }
- }
- if (e.which !== 8 && e.which !== 0 && e.which !== 46 && (e.which < 48 || e.which > 57)) {
- return false;
- }
- });
- });
- }
- });
- }
- var transAmt = 0;
- function calTans(seq, id, sid) {
- if (event.keyCode === 13) {
- if (seq === 'first') {
- transAmt = $('#billAmount').val();
- $('.' + sid).val(parseFloat($('.' + id).val() / parseFloat(transAmt) * 100).toFixed(numberOfDecimal));
- transAmt = parseFloat(transAmt) + parseFloat($('.' + id).val());
- }
- else if (seq === 'discount') {
- transAmt = parseFloat($('#billAmount').val()) +
- parseFloat($('.' + id).parent().prev().find('input.ts.amt').val()) +
- parseFloat(typeof ($('.' + id).parent().prev().prev().find('input.ts.amt').val()) === 'undefined' ? 0 :
- parseFloat($('.' + id).parent().prev().prev().find('input.ts.amt').val()))
- - parseFloat($('.' + id).val());
- $('.' + sid).val(parseFloat($('.' + id).val() / parseFloat(transAmt) * 100).toFixed(numberOfDecimal));
- }
- else {
- transAmt = parseFloat($('#billAmount').val()) +
- parseFloat($('.' + id).parent().prev().find('input.ts.amt').val()) +
- parseFloat(typeof ($('.' + id).parent().prev().prev().find('input.ts.amt').val()) === 'undefined' ? 0 :
- parseFloat($('.' + id).parent().prev().prev().find('input.ts.amt').val()))
- + parseFloat($('.' + id).val());
- $('.' + sid).val(parseFloat($('.' + id).val() / parseFloat(transAmt) * 100).toFixed(numberOfDecimal));
- }
- $('.' + sid).parent().next().find('input.ts').val('0');
- $('.' + sid).parent().next().next().find('input.ts').val('0');
- $('#totalAmount').val(parseFloat(transAmt).toFixed(numberOfDecimal));
- $('#gtotal').text(parseFloat(transAmt).toFixed(numberOfDecimal));
- if (id === 'tranSQAmt_BillTax') {
- BillTaxAmount = $('.' + id).val(); BillTaxPercentage = $('.' + sid).val();
- }
- else if (id === 'tranSQAmt_ExciseDuty') {
- BillExciseDutyAmount = $('.' + id).val(); BillExciseDutyPercentage = $('.' + sid).val();
- }
- else if (id === 'tranSQAmt_BillDiscount') {
- billDiscount = $('.' + id).val(); BillDiscountPercentage = $('.' + sid).val();
- }
- $('.' + id).parent().next().find('input.percentage').focus();
- $('.' + id).parent().next().find('input.percentage').val($('.' + id).parent().next().find('input.percentage').val()).focus();
- event.preventDefault();
- return false;
- }
- }
- function calPerTans(seq, id, sid) {
- if (event.keyCode === 13) {
- if (seq === 'first') {
- transAmt = $('#billAmount').val();
- $('.' + sid).val(parseFloat($('.' + id).val() * parseFloat(transAmt) / 100).toFixed(numberOfDecimal));
- transAmt = parseFloat(transAmt) + parseFloat($('.' + id).val() * parseFloat(transAmt) / 100);
- }
- else if (seq === 'discount') {
- transAmt = parseFloat($('#billAmount').val()) +
- parseFloat($('.' + id).parent().prev().find('input.ts.amt').val()) +
- parseFloat(typeof ($('.' + id).parent().prev().prev().find('input.ts.amt').val()) === 'undefined' ? 0 :
- parseFloat($('.' + id).parent().prev().prev().find('input.ts.amt').val()));
- $('.' + sid).val(parseFloat($('.' + id).val() * parseFloat(transAmt) / 100).toFixed(numberOfDecimal));
- transAmt = parseFloat(transAmt) - parseFloat($('.' + id).val() * parseFloat(transAmt) / 100);
- }
- else {
- transAmt = parseFloat($('#billAmount').val()) +
- parseFloat($('.' + id).parent().prev().find('input.ts.amt').val()) +
- parseFloat(typeof ($('.' + id).parent().prev().prev().find('input.ts.amt').val()) === 'undefined' ? 0 :
- parseFloat($('.' + id).parent().prev().prev().find('input.ts.amt').val()));
- $('.' + sid).val(parseFloat($('.' + id).val() * parseFloat(transAmt) / 100).toFixed(numberOfDecimal));
- transAmt = parseFloat(transAmt) + parseFloat($('.' + id).val() * parseFloat(transAmt) / 100);
- }
- $('.' + sid).parent().next().find('input.ts').val('0');
- $('.' + sid).parent().next().next().find('input.ts').val('0');
- $('#totalAmount').val(parseFloat(transAmt).toFixed(numberOfDecimal));
- $('#gtotal').text(parseFloat(transAmt).toFixed(numberOfDecimal));
- if (id === 'tranSQPer_BillTax') {
- BillTaxPercentage = $('.' + id).val(); BillTaxAmount = $('.' + sid).val();
- }
- else if (id === 'tranSQPer_ExciseDuty') {
- BillExciseDutyPercentage = $('.' + id).val(); BillExciseDutyAmount = $('.' + sid).val();
- }
- else if (id === 'tranSQPer_BillDiscount') {
- BillDiscountPercentage = $('.' + id).val(); billDiscount = $('.' + sid).val();
- }
- $('.' + id).parent().next().find('input.percentage').focus();
- $('.' + id).parent().next().find('input.percentage').val($('.' + id).parent().next().find('input.percentage').val()).focus();
- event.preventDefault();
- return false;
- }
- }
- function CashOrPartyComboFill() {
- $.ajax({
- url: '/PurchaseInvoice/CashOrPartyComboFill',
- type: 'get',
- async: false,
- data: { DbName: DbName },
- success: function (data) {
- $('#CashOrPartyComboFill').empty();
- $('#CashOrPartyComboFill').append('<option value="0"> Choose one</option>');
- $.each(data, function (i, item) {
- $('#CashOrPartyComboFill').append('<option value="' + item.ledgerId + '" data-agid="' + item.accountGroupId + '"> ' + item.ledgerName + '</option>');
- });
- },
- error: function () {
- toastr.error('system error');
- }
- });
- }
- function CashorBankorPartyComboFill() {
- $.ajax({
- url: '/PurchaseInvoice/CashorBankorPartyComboFill',
- data: { DbName: DbName },
- type: 'get',
- async: false,
- success: function (data) {
- $('#cashPartyAdditional').empty();
- $('#cashPartyAdditional').append('<option value="0"> Choose one</option>');
- $.each(data, function (i, item) {
- $('#cashPartyAdditional').append('<option value="' + item.ledgerId + '" data-gid="' + item.accountGroupId + '"> ' + item.ledgerName + '</option>');
- });
- },
- error: function () {
- toastr.error('system error');
- }
- });
- }
- function PurchaseAccountComboFill() {
- $.ajax({
- url: '/PurchaseInvoice/PurchaseAccountComboFill',
- data: { DbName: DbName },
- type: 'get',
- async: false,
- success: function (data) {
- $('#PurchaseAccountComboFill').empty();
- $('#PurchaseAccountComboFill').append('<option value="0"> Choose one</option>');
- $.each(data, function (i, item) {
- $('#PurchaseAccountComboFill').append('<option value="' + item.ledgerId + '"> ' + item.ledgerName + '</option>');
- });
- },
- error: function () {
- toastr.error('system error');
- }
- });
- }
- function AdditionalCostComboFill() {
- $.ajax({
- url: '/PurchaseInvoice/AdditionalCostComboFill',
- data: { DbName: DbName },
- type: 'get',
- async: false,
- success: function (data) {
- $('#AdditionalCostComboFill').empty();
- $('#AdditionalCostComboFill').append('<option value="0"> Choose one</option>');
- $.each(data, function (i, item) {
- $('#AdditionalCostComboFill').append('<option value="' + item.ledgerId + '"> ' + item.ledgerName + '</option>');
- });
- },
- error: function () {
- toastr.error('system error');
- }
- });
- }
- function RackViewAllByGodownForCombo(id) {
- $.ajax({
- url: '/PurchaseInvoice/RackViewAllByGodownForCombo?DbName=' + DbName + '&GId=' + id,
- type: 'get',
- async: false,
- success: function (data) {
- $('#rackId').empty();
- //$('#rackId').append('<option value="0"> Choose one</option>');
- $.each(data, function (i, item) {
- $('#rackId').append('<option value="' + item.rackId + '"> ' + item.rackName + '</option>');
- });
- },
- error: function () {
- toastr.error('system error: rack loading error');
- }
- });
- }
- function UnitViewAllByProductId(id) {
- $.ajax({
- url: '/PurchaseInvoice/UnitViewAllByProductId?DbName=' + DbName + '&PId=' + id,
- type: 'get',
- async: false,
- success: function (data) {
- $('#unitId').empty();
- $.each(data, function (i, item) {
- $('#unitId').append('<option value="' + item.unitId + '"> ' + item.unitName + '</option>');
- });
- },
- error: function () {
- toastr.error('system error');
- }
- });
- }
- function unitdp() {
- $.ajax({
- url: '/PurchaseInvoice/UnitAllComboFill?DbName=' + DbName,
- type: 'get',
- async: false,
- success: function (data) {
- $('#unitId').empty();
- $('#unitId').append('<option value="0"> Choose one</option>');
- $.each(data, function (i, item) {
- $('#unitId').append('<option value="' + item.unitId + '"> ' + item.unitName + '</option>');
- });
- },
- error: function () {
- toastr.error('system error');
- }
- });
- }
- function rackdp() {
- $.ajax({
- url: '/PurchaseInvoice/RackAllComboFill?DbName=' + DbName,
- type: 'get',
- async: false,
- success: function (data) {
- $('#rackId').empty();
- $('#rackId').append('<option value="0"> Choose one</option>');
- $.each(data, function (i, item) {
- $('#rackId').append('<option value="' + item.rackId + '"> ' + item.rackName + '</option>');
- });
- },
- error: function () {
- toastr.error('system error: rack loading error');
- }
- });
- }
- function caldiscount() {
- totalInvoice = $('#netTotalF').text();
- if ($('#gbillDiscount').val() >= 0) {
- bilDis = $('#gbillDiscount').val();
- amt = parseFloat($('#netTotalF').text()) - parseFloat($('#gbillDiscount').val());
- gCosttoParty = parseFloat($('#CosttoParty').text()) + parseFloat($('#netTotalF').text()) - parseFloat($('#gbillDiscount').val());
- $('#ginvoiceTotal').text(parseFloat(amt).toFixed(numberOfDecimal));
- $('#billAmount').val(parseFloat(amt).toFixed(numberOfDecimal));
- transAmt = $('#billAmount').val();
- $('#totalAmount').val(parseFloat(amt).toFixed(numberOfDecimal));
- $('#gCostToparty').text(parseFloat(gCosttoParty).toFixed(numberOfDecimal));
- event.preventDefault();
- if (isTax === 1) {
- if (taxAmt === 0) {
- //check for vouchertype tax for auto tax add if individual tax for each item is zero
- $.ajax({
- url: '/PurchaseInvoice/VoucherTypeTaxGetByVoucherType?DbName=' + DbName,
- type: 'get',
- async: false,
- success: function (data) {
- //var rate = data.rate;
- if (data.rate !== 0 || data.rate !== '') {
- $('#gtaxAble').val(parseFloat(amt).toFixed(numberOfDecimal));
- taxAmt = parseFloat(data.rate) * amt / 100;
- amt = taxAmt + amt;
- $('#gTaxAmt').val(parseFloat(taxAmt).toFixed(numberOfDecimal));
- $('#gtotal').text(parseFloat(amt).toFixed(numberOfDecimal));
- }
- else {
- toastr.error('tax rate is zero');
- }
- },
- error: function () {
- toastr.error('system error');
- }
- });
- }
- else {
- $('#gtaxAble').val(parseFloat(taxable).toFixed(numberOfDecimal));
- $('#gTaxAmt').val(parseFloat(taxAmt).toFixed(numberOfDecimal));
- totalGrand = nonTaxable + taxable + parseFloat($('#gTaxAmt').val()) - parseFloat($('#gbillDiscount').val());
- //amt1 = totalGrand - bilDis;
- $('#gtotal').text(parseFloat(totalGrand).toFixed(numberOfDecimal));
- }
- }
- }
- grtGrandtotal();
- }
- function grtGrandtotal() {
- var tadd = 0, tbd = 0, gin = 0;
- if ($('#TotalAdditionalCost').text() > 0) {
- tadd = $('#TotalAdditionalCost').text();
- }
- if ($('#gbillDiscount').val() > 0) {
- tbd = 0;
- }
- if ($('#ginvoiceTotal').text() > 0) {
- gin = $('#ginvoiceTotal').text();
- }
- totalGrand = parseFloat(tadd) + parseFloat(tbd) + parseFloat(gin);
- $('#gtotal').text(parseFloat(totalGrand).toFixed(numberOfDecimal));
- }
- function getAllProduct() {
- $.ajax({
- url: '/PurchaseInvoice/ProductbyName?DbName=' + DbName + '&name=' + '',
- type: 'get',
- async: false,
- success: function (data) {
- $('#productName').empty();
- //$('#productName').append('<option value="0"> Choose one </option>');
- $.each(data, function (k, item) {
- $('#productName').append('<option value="' + item.productCode + '"> ' + item.productName + ' </option>');
- });
- }
- });
- }
- function checkvendorInvoiceNoIfExist(vendorInvoiceNo) {
- $.ajax({
- url: '/PurchaseInvoice/checkvendorInvoiceNoIfExist?DbName=' + DbName + '&vendorInvoiceNo=' + vendorInvoiceNo,
- type: 'get',
- async: false,
- success: function (data) {
- if (data === 1 || data === '1') {
- toastr.error("This bill number has been entered already!");
- }
- },
- error: function (data) { toastr.error(data); }
- });
- }
- function ChargeGet_ByProductId(productId) {
- $.ajax({
- url: '/PurchaseInvoice/ChargeGet_ByProductId',
- type: 'get',
- data: {
- productId: productId
- },
- async: false,
- success: function (data) {
- $('#chargeId').empty();
- if (data.length > 0) {
- $('#chargeId').append('<option value="1">N/A</option>');
- $.each(data, function (k, item) {
- $('#chargeId').append('<option value="' + item.taxId + '"> ' + item.taxName + ' </option>');
- });
- }
- else {
- $('#chargeId').append('<option value="1">N/A</option>');
- }
- }
- });
- }
- function calproDiscountbyper() {
- if ($('#disPer').val() <= 100) {
- var discper = $('#disPer').val();
- discamt = (discper / 100) * $('#grossValue').val();
- $('#disAmt').val(parseFloat(discamt).toFixed(numberOfDecimal));
- $('#Netamt').val(parseFloat(parseFloat($('#grossValue').val() - discamt)).toFixed(numberOfDecimal));
- }
- else {
- toastr.info('Discount is more than 100%');
- }
- calTax();
- }
- function calprodDiscountbyAmt() {
- var discamt = $('#disAmt').val();
- var disPerA = parseFloat(discamt * 100 / $('#grossValue').val());
- var dispers = parseInt($('#rate').val()) === 0 ? 0 : disPerA;
- $('#disPer').val(parseFloat(dispers).toFixed(numberOfDecimal));
- $('#Netamt').val(parseFloat($('#grossValue').val() - discamt).toFixed(numberOfDecimal));
- calTax();
- }
- function PopUp(data) {
- var mywindow = window.open('', '', 'left=0,top=0,width=950,height=600,toolbar=0,scrollbars=0,status=0,addressbar=0');
- var is_chrome = Boolean(mywindow.chrome);
- var isPrinting = false;
- mywindow.document.write(data);
- mywindow.document.close(); // necessary for IE >= 10 and necessary before onload for chrome
- if (is_chrome) {
- mywindow.onload = function () { // wait until all resources loaded
- isPrinting = true;
- mywindow.focus(); // necessary for IE >= 10
- mywindow.print(); // change window to mywindow
- //mywindow.close();// change window to mywindow
- isPrinting = false;
- };
- //if (!isPrinting) {
- // mywindow.print(); //mywindow.close();
- //}
- setTimeout(function () {
- if (!isPrinting) {
- mywindow.print();
- mywindow.close();
- }
- }, 300);
- }
- else {
- mywindow.document.close(); // necessary for IE >= 10
- mywindow.focus(); // necessary for IE >= 10
- mywindow.print();
- mywindow.close();
- }
- return true;
- }
- function PrintVoucher(invoiceno) {
- var name = 'Purchase';
- $.ajax({
- url: '/VoucherPrint/PurchasePrint?DbName=' + DbName + '&typename=' + name + '&invoiceno=' + invoiceno + '&voucherTypeid=13',
- type: "POST",
- dataType: "JSON",
- contentType: "application/json,charset=utf-8",
- success: function (data) {
- PopUp(data);
- $('#loading').fadeOut();
- $('#save').modal('hide');
- }
- });
- }
- function checkMaterialOrderCmp() {
- count = localStorage.length;
- if (localStorage.length > 0) {
- for (var i = 0; i < localStorage.length; i++) {
- if (localStorage.getItem('keyPI' + i)) {
- if (JSON.parse(localStorage.getItem('keyPI' + i)).action === 'Accepted') {
- count = count;
- }
- else {
- count -= 1;
- }
- }
- else {
- count -= 1;
- }
- }
- }
- if (count === 0) {
- return false;
- }
- else {
- return true;
- }
- }
- function checkPurchaseOrderCmp() {
- count = localStorage.length;
- if (localStorage.length > 0) {
- for (var i = 0; i < localStorage.length; i++) {
- if (localStorage.getItem('keyPI' + i)) {
- if (JSON.parse(localStorage.getItem('keyPI' + i)).action === 'Accepted') {
- count = count;
- }
- else {
- count -= 1;
- }
- }
- else {
- count -= 1;
- }
- }
- }
- if (count === 0) {
- return false;
- }
- else {
- return true;
- }
- }
- $(function () {
- $("#ExAD").datepicker({
- dateFormat: "mm/dd/yy",
- minDate: 'today',
- showButtonPanel: true,
- changeYear: true,
- changeMonth: true
- }).datepicker('setDate', 'today');
- $('#save').on('hidden.bs.modal', function () {
- $('#loading').fadeOut();
- });
- $('#update').on('hidden.bs.modal', function () {
- $('#loading').fadeOut();
- });
- $(".PrintBill").prop('checked', true);
- $(".btnprintyes").on("click", function () {
- invoiceno = $(this).data('invoiceno');
- PrintVoucher(invoiceno);
- });
- //clearPI localstorage
- resetForm();
- clearPI();
- getSequence();
- //show btns
- $('#btnPISave').show();
- $('#btnPIUpdate').hide();
- $('#PInarration').addClass('active');
- $('.savePI').addClass('active');
- $('.updatePI').addClass('active');
- $('.resetPI').addClass('active');
- $('#ImportValue').addClass('disabled');
- $('#ImportValue').prop('disabled', true);
- $('#crPeriod').val('0');
- //load CashOrPartyComboFill
- CashOrPartyComboFill();
- //load VoucherTypeSelectionComboFill
- //VoucherType();
- //load CashorBankorPartyComboFill
- CashorBankorPartyComboFill();
- //load PurchaseAccountComboFill
- PurchaseAccountComboFill();
- //load UnitAllComboFill
- unitdp();
- //load RackViewAll
- rackdp();
- //load AdditionalCostComboFill
- AdditionalCostComboFill();
- //load tax dp
- $.ajax({
- url: '/PurchaseInvoice/TaxViewForDp?DbName=' + DbName,
- type: 'get',
- async: false,
- success: function (data) {
- $('#taxId').empty();
- //$('#taxId').append('<option value="0"> All</option>');
- $.each(data, function (i, item) {
- $('#taxId').append('<option value="' + item.taxId + '"> ' + item.taxName + '</option>');
- });
- },
- error: function () {
- toastr.error('system error');
- }
- });
- //load godown dp
- $.ajax({
- url: '/PurchaseInvoice/GodownForDp?DbName=' + DbName,
- type: 'get',
- async: false,
- success: function (data) {
- $('#goDownid').empty();
- $('#goDownid').append('<option value="0"> Choose one</option>');
- $.each(data, function (i, item) {
- $('#goDownid').append('<option value="' + item.godownId + '"> ' + item.godownName + '</option>');
- });
- },
- error: function () {
- toastr.error('system error');
- }
- });
- //load product name
- getAllProduct();
- //product code input
- $('#productCode').keydown(function (e) {
- if (event.keyCode === 13 || event.keyCode === 9) {
- unitdp();
- rackdp();
- if ($('#productCode').val() === '') {
- //$('#ProductList').modal('show');
- $('#productName').focus();
- }
- else {
- $('#productName').val($('#productCode').val()).select2();
- productName = $('#productName').children('option').filter(':selected').text();
- if (typeOfVoucher === 'NA' || $('#purchaseMode').children('option').filter(':selected').text() === 'NA') {
- //$('#productCode').val($('#productName').val());
- productName = $('#productName').children('option').filter(':selected').text();
- ProductDetailsgetPerticlular($('#productName').val());
- $('#qty').val('0');
- $('#batchId').val('');
- $('#disPer').val('0');
- $('#grossValue').val('0');
- $('#disAmt').val('0');
- $('#Netamt').val('0');
- $('#ImportValue').val('0');
- $('#taxAmt').val('0');
- $('#NetTotal').val('0');
- }
- else if (typeOfVoucher === 'Material Receipt' || $('#purchaseMode').children('option').filter(':selected').text() === 'Material Receipt') {
- materialReceiptDetailsId = $('#productName').children('option').filter(':selected').data('materialreceiptdetailsid');
- //$('#productCode').val($('#productName').val());
- productName = $('#productName').children('option').filter(':selected').text();
- GetProductDetailsFromMaterialReceiptDetails($('#productName').val(), materialReceiptDetailsId);
- }
- else if (typeOfVoucher === 'Purchase Order' || $('#purchaseMode').children('option').filter(':selected').text() === 'Purchase Order') {
- purchaseOrderDetailsId = $('#productName').children('option').filter(':selected').data('purchaseorderdetailsid');
- //$('#productCode').val($('#productName').val());
- productName = $('#productName').children('option').filter(':selected').text();
- GetProductDetailsFromPurchaseOrderDetails($('#productName').val(), purchaseOrderDetailsId);
- }
- }
- e.preventDefault();
- return false;
- }
- else if (e.altKey && (event.keyCode === 78)) {
- $('#productName').select2('close');
- $('#ProductModal').modal('show');
- e.preventDefault();
- return false;
- }
- });
- //ProductDetailsgetbyName
- //$('#productName').keydown(function () {
- // if (event.keyCode === 13) {
- // $('#ProductList').modal('show');
- // //$('#modalHit').trigger('click');
- // }
- //});
- $('#productName').on('select2:close', function () {
- unitdp();
- rackdp();
- if (typeOfVoucher === 'NA' || $('#purchaseMode').children('option').filter(':selected').text() === 'NA') {
- if ($('#productName').val() > 0 || $('#productName').val() !== '') {
- $('#productCode').val($('#productName').val());
- productName = $('#productName').children('option').filter(':selected').text();
- ProductDetailsgetPerticlular($('#productName').val());
- }
- else {
- setTimeout(function () { $('#productName').focus(); }, 500);
- }
- $('#qty').val('0');
- $('#batchId').val('');
- $('#disPer').val('0');
- $('#grossValue').val('0');
- $('#disAmt').val('0');
- $('#Netamt').val('0');
- $('#ImportValue').val('0');
- $('#taxAmt').val('0');
- $('#NetTotal').val('0');
- }
- else if (typeOfVoucher === 'Material Receipt' || $('#purchaseMode').children('option').filter(':selected').text() === 'Material Receipt') {
- if ($('#productName').val() > 0 || $('#productName').val() !== '') {
- materialReceiptDetailsId = $('#productName').children('option').filter(':selected').data('materialreceiptdetailsid');
- $('#productCode').val($('#productName').val());
- productName = $('#productName').children('option').filter(':selected').text();
- GetProductDetailsFromMaterialReceiptDetails($('#productName').val(), materialReceiptDetailsId);
- }
- else {
- setTimeout(function () { $('#productName').focus(); }, 500);
- }
- }
- else if (typeOfVoucher === 'Purchase Order' || $('#purchaseMode').children('option').filter(':selected').text() === 'Purchase Order') {
- if ($('#productName').val() > 0 || $('#productName').val() !== '') {
- purchaseOrderDetailsId = $('#productName').children('option').filter(':selected').data('purchaseorderdetailsid');
- $('#productCode').val($('#productName').val());
- productName = $('#productName').children('option').filter(':selected').text();
- GetProductDetailsFromPurchaseOrderDetails($('#productName').val(), purchaseOrderDetailsId);
- }
- else {
- setTimeout(function () { $('#productName').focus(); }, 500);
- }
- }
- });
- $('#VoucherTypeSelectionComboFill').change(function () {
- taxIdByVoucherType($('#VoucherTypeSelectionComboFill').val());
- });
- //calculation part
- $('#qty').on('input', function () {
- if ($('#rate').val() !== '') {
- var amt = parseFloat($('#rate').val() * $('#qty').val());
- $('#grossValue').val(amt);
- $('#Netamt').val(amt);
- $('#NetTotal').val(amt);
- calprodDiscountbyAmt();
- }
- });
- $('#rate').on('input', function () {
- if ($('#qty').val() !== '') {
- var amt = parseFloat($('#rate').val() * $('#qty').val());
- $('#grossValue').val(amt);
- $('#Netamt').val(amt);
- $('#NetTotal').val(amt);
- calprodDiscountbyAmt();
- }
- });
- $('#disPer').keydown(function (e) {
- if (event.keyCode === 13) {
- if ($('#disPer').val() !== '0' || $('#disPer').val() !== '') {
- calproDiscountbyper();
- }
- $('#disAmt').focus();
- }
- });
- $('#disAmt').keydown(function (e) {
- if (event.keyCode === 13) {
- if ($('#disAmt').val() !== '0' || $('#disAmt').val() !== '') {
- calprodDiscountbyAmt();
- }
- setTimeout(function () { $('#chargeId').focus(); }, 100);
- }
- });
- $('#chargeId').on('select2:close', function () {
- if (parseInt($('#chargeId').val()) > 0) {
- calCharge();
- if ($('#ImportValue').hasClass('disabled')) {
- if ($('#taxId').hasClass('disabled')) {
- setTimeout(function () { $('#addBill').focus(); }, 200);
- }
- else {
- setTimeout(function () { $('#taxId').focus(); }, 200);
- }
- }
- else {
- setTimeout(function () { $('#ImportValue').focus(); }, 200);
- }
- }
- });
- $('#ImportValue').on('input', function () {
- NetAmtWithImport = parseFloat($('#ImportValue').val());
- calTax();
- });
- //clearPI local storage
- //add to dispaly table
- var thistaxamt = 0;
- $('#addBill').on('click', function () {
- if ($('#productCode').val() === '') {
- $('#productCode').focus();
- toastr.info('Purchase code is empty');
- }
- else {
- if ($('#qty').val() === '' || $('#qty').val() === '0') {
- $('#qty').focus();
- toastr.info('Quantity is empty');
- }
- else {
- if ($('#rate').val() === '' || $('#rate').val() === '0') {
- if ($('.isFreeQTY').is(':checked')) {
- addProductsGrid();
- }
- else {
- $('#rate').focus();
- toastr.info('Rate is empty');
- }
- }
- else {
- addProductsGrid();
- }
- }
- }
- $('#PInarration').addClass('active');
- });
- //add additional cost
- $('#additionalBtn').click(function () {
- if ($('#AdditionalCostComboFill').val() === '0') {
- $('#AdditionalCostComboFill').focus();
- toastr.info('Please select ledger');
- }
- else {
- if ($('#cashPartyAdditional').val() === '0') {
- $('#cashPartyAdditional').focus();
- toastr.info('Please select cash or party');
- }
- else {
- if ($('#additionalAmt').val() === '0' || $('#additionalAmt').val() === '') {
- $('#additionalAmt').focus();
- toastr.info('Please add Amount');
- }
- else {
- var i = 0;
- while (localStorage.getItem('keyAdd' + i)) {
- i++;
- }
- var check = checkAddtionalLedger();
- if (check) {
- toastr.info('Ledger name exist in table below. Please Edit and Update');
- }
- else {
- TotalAdditionalCost += parseFloat($('#additionalAmt').val());
- $('#TotalAdditionalCost').text(parseFloat(TotalAdditionalCost).toFixed(numberOfDecimal));
- //if ($('#cashPartyAdditional').find('option:selected').data('gid') === 27 ||
- // $('#cashPartyAdditional').find('option:selected').data('gid') === 28) {
- // $('#TotalAdditionalCost').text(parseFloat(TotalAdditionalCost).toFixed(numberOfDecimal));
- //}
- //else {
- // CosttoParty += parseFloat($('#additionalAmt').val());
- // if ($('#CashOrPartyComboFill').val() === $('#cashPartyAdditional').val()) {
- // gCosttoParty += parseFloat(TotalAdditionalCost);
- // }
- // $('#CosttoParty').text(parseFloat(CosttoParty).toFixed(numberOfDecimal));
- // $('#gCostToparty').text(parseFloat(gCosttoParty).toFixed(numberOfDecimal));
- // $('#TotalAdditionalCost').text(parseFloat(TotalAdditionalCost).toFixed(numberOfDecimal));
- //}
- if ($('#CashOrPartyComboFill').val() === $('#cashPartyAdditional').val()) {
- CosttoParty += parseFloat($('#additionalAmt').val());
- }
- $('#CosttoParty').text(parseFloat(CosttoParty).toFixed(numberOfDecimal));
- gCosttoParty = parseFloat(CosttoParty) + parseFloat($('#ginvoiceTotal').text());
- $('#gCostToparty').text(parseFloat(gCosttoParty).toFixed(numberOfDecimal));
- $('#TotalAdditionalCost').text(parseFloat(TotalAdditionalCost).toFixed(numberOfDecimal));
- if (isAddTax === 1) {
- taxable += parseFloat($('#additionalAmt').val());
- }
- else {
- nonTaxable += parseFloat($('#additionalAmt').val());
- }
- var discount = 0;
- if ($('#gbillDiscount').val() > 0) {
- discount = $('#gbillDiscount').val();
- }
- totalGrand = parseFloat($('#TotalAdditionalCost').text()) + parseFloat($('#ginvoiceTotal').text()) + parseFloat(discount);
- totalInvoice = $('#netTotalF').text();
- $('#NonTaxableAmt').text(parseFloat(nonTaxable).toFixed(numberOfDecimal));
- $('#gtotal').text(parseFloat(totalGrand).toFixed(numberOfDecimal));
- //$('#ginvoiceTotal').text(parseFloat(totalInvoice).toFixed(numberOfDecimal));
- localStorage.setItem('keyAdd' + i, JSON.stringify({
- keyidAdd: i,
- AdditionalLedger: $('#AdditionalCostComboFill').val(),
- addcostid: addcostid,
- AddLedgerName: $('#AdditionalCostComboFill').children('option').filter(':selected').text(),
- AdditionalCashparty: $('#cashPartyAdditional').val(),
- AddCashpartyName: $('#cashPartyAdditional').children('option').filter(':selected').text(),
- AddtionalAmount: $('#additionalAmt').val(),
- isAddTax: isAddTax
- }));
- if (i > lastkeyAdd) {
- lastkeyAdd = i;
- }
- resetAdditional();
- //clearparty();
- showTableAddtional();
- $('#AdditionalCostComboFill').focus();
- }
- }
- }
- }
- });
- //give bill discount
- $('#gbillDiscount').keydown(function () {
- if (event.keyCode === 13) {
- caldiscount();
- $('#PInarration').focus();
- }
- });
- //select2 dropdown
- $('#PurchaseAccountComboFill').select2();
- $('#CashOrPartyComboFill').select2();
- $('#purchaseMode').val(0).select2();
- $('#VoucherTypeSelectionComboFill').val('0').select2();
- $('#orderNo').select2();
- $('#ReceiptNo').select2();
- $('#unitId').select2();
- $('#goDownid').select2();
- $('#rackId').select2();
- $('#chargeId').select2();
- $('#taxId').select2();
- $('#AdditionalCostComboFill').select2();
- $('#cashPartyAdditional').select2();
- $('#productName').select2();
- //on focus
- //setTimeout(function () {
- // $('#PurchaseAccountComboFill').focus();
- //}, 200);
- $("#InAD").change(function (event) {
- $('#InBS').focus();
- $('#InBS').trigger('click');
- });
- $("#InBS").on("dateSelect", function (event) {
- $('#VAD').focus();
- $('.nepali-date-picker').hide();
- });
- $('#InAD').keydown(function () {
- if (event.keyCode === 13) {
- $('#InBS').focus();
- $('#InBS').trigger('click');
- event.preventDefault();
- return false;
- }
- });
- $('#InBS').keydown(function () {
- if (event.keyCode === 13) {
- $('#VAD').focus();
- $('.nepali-date-picker').hide();
- event.preventDefault();
- return false;
- }
- });
- $('#VAD').keydown(function () {
- if (event.keyCode === 13) {
- $('#VBS').focus();
- $('#VBS').trigger('click');
- event.preventDefault();
- return false;
- }
- });
- $('#VBS').keydown(function () {
- if (event.keyCode === 13) {
- $('#CashOrPartyComboFill').focus();
- $('.nepali-date-picker').hide();
- event.preventDefault();
- return false;
- }
- });
- $("#VAD").change(function (event) {
- $('#VBS').focus();
- $('#VBS').trigger('click');
- });
- $("#VBS").on("dateSelect", function (event) {
- $('#CashOrPartyComboFill').focus();
- $('.nepali-date-picker').hide();
- });
- $('#qty').on('keydown', function () {
- if (event.keyCode === 13) {
- if ($('#qty').val() === '' || $('#qty').val() === '0') {
- $('#qty').focus();
- }
- else {
- if ($('#unitId').hasClass('disabled')) {
- if ($('#rate').hasClass('disabled')) {
- $('#goDownid').focus();
- }
- else {
- $('#rate').focus();
- }
- }
- else {
- $('#unitId').focus();
- }
- }
- }
- });
- $('#rate').on('keydown', function () {
- if (event.keyCode === 13) {
- if ($('#qty').val() !== '') {
- var amt = parseFloat($('#rate').val() * $('#qty').val());
- $('#grossValue').val(amt);
- $('#Netamt').val(amt);
- $('#NetTotal').val(amt);
- calprodDiscountbyAmt();
- }
- if ($('#rate').val() === '' || $('#rate').val() === '0') {
- if ($('.isFreeQTY').is(':checked')) {
- if (!$('#goDownid').hasClass('disabled')) {
- setTimeout(function () {
- $('#goDownid').focus();
- }, 200);
- }
- else if (!$('#rackId').hasClass('disabled')) {
- setTimeout(function () {
- $('#rackId').focus();
- }, 200);
- }
- else {
- $('#batchId').focus();
- }
- }
- else {
- $('#rate').focus();
- }
- }
- else if (!$('#goDownid').hasClass('disabled')) {
- setTimeout(function () {
- $('#goDownid').focus();
- }, 200);
- }
- else if (!$('#rackId').hasClass('disabled')) {
- setTimeout(function () {
- $('#rackId').focus();
- }, 200);
- }
- else {
- $('#batchId').focus();
- }
- }
- });
- $("#ExAD").change(function (event) {
- $('#disPer').focus();
- });
- $('#ExAD').keydown(function () {
- if (event.keyCode === 13) {
- $('#disPer').focus();
- event.preventDefault();
- return false;
- }
- });
- $('#PurchaseAccountComboFill').on('select2:close', function () {
- if ($('#PurchaseAccountComboFill').val() === '0') {
- $('#PurchaseAccountComboFill').focus();
- }
- else {
- setTimeout(function () {
- $('#invoiceNo').focus();
- }, 200);
- //tax // import // free // check
- $.ajax({
- url: '/PurchaseInvoice/AccountLedgerIdGetbyId?DbName=' + DbName + '&id=' + $('#PurchaseAccountComboFill').val(),
- async: false,
- type: 'get',
- success: function (data) {
- // isfree isimport isfixedpurchased iseffectonvat
- if (data.isfree === 1) {
- isfree = 1;
- }
- if (data.isimport === 1) {
- isImport = 1;
- }
- if (data.iseffectonvat === 1) {
- isTax = 1;
- }
- }
- });
- $('#taxId').prop('disabled', true);
- $('#taxId').val('0').select2();
- if (isTax === 1) {
- $('#ImportValue').addClass('disabled');
- $('#ImportValue').prop('disabled', true);
- }
- if (isfree === 1) {
- $('#taxId').prop('disabled', true);
- $('#taxId').val('0').select2();
- $('#ImportValue').addClass('disabled');
- $('#ImportValue').prop('disabled', true);
- }
- if (isImport === 1) {
- $('#ImportValue').removeClass('disabled');
- $('#ImportValue').prop('disabled', false);
- }
- }
- });
- $('#CashOrPartyComboFill').on('select2:close', function () {
- if ($('#CashOrPartyComboFill').val() === '0') {
- $('#CashOrPartyComboFill').focus();
- accountgpId = 0;
- }
- else {
- accountgpId = parseInt($('#CashOrPartyComboFill').find("option:selected").attr("data-agid"));
- if (parseInt(accountgpId) === 27) {
- $.ajax({
- type: 'get',
- async: false,
- url: '/PaymentVoucher/BalanceCheckWithLedgerID?DbName=' + DbName + '&ledgerId=' + $("#CashOrPartyComboFill").val(),
- success: function (data) {
- CashAmount = data.balance;
- },
- error: function () {
- }
- });
- }
- setTimeout(function () {
- $('#crPeriod').focus();
- }, 200);
- ledgerId = $('#CashOrPartyComboFill').val();
- $('#cashPartyAdditional').val($('#CashOrPartyComboFill').val()).select2();
- }
- });
- $('#purchaseMode').on('select2:close', function () {
- if ($('#purchaseMode').val() === '0') {
- typeOfVoucher = 'NA';
- $('#VoucherTypeSelectionComboFill').empty();
- $("#VoucherTypeSelectionComboFill").append('<option value="0">NA</option>');
- setTimeout(function () {
- $('.VoucherType').addClass('displayNone');
- $('#divOrderNo').addClass('displayNone');
- $('#divReceiptNo').addClass('displayNone');
- $('#productCode').focus();
- }, 200);
- }
- else {
- if ($('#purchaseMode').val() === 'Against PurchaseOrder') {
- //$('#labelName').text('Order No.');
- typeOfVoucher = 'Purchase Order';
- VoucherTypeSelectionComboFill(typeOfVoucher);
- GetPurchaseOrderNoForPurchaseInvoice();
- setTimeout(function () {
- $('.VoucherType').removeClass('displayNone');
- $('#divOrderNo').removeClass('displayNone');
- $('#divReceiptNo').addClass('displayNone');
- $('#orderNo').focus();
- }, 200);
- }
- else if ($('#purchaseMode').val() === 'Against MaterialReceipt') {
- //$('#labelName').text('Material Receipt No.');
- typeOfVoucher = 'Material Receipt';
- VoucherTypeSelectionComboFill(typeOfVoucher);
- GetMaterialReceiptNoForPurchaseInvoice();
- setTimeout(function () {
- $('.VoucherType').removeClass('displayNone');
- $('#divOrderNo').addClass('displayNone');
- $('#divReceiptNo').removeClass('displayNone');
- $('#ReceiptNo').focus();
- }, 200);
- }
- }
- });
- $('#ReceiptNo').on('select2:close', function () {
- if ($('#ReceiptNo').val() === '0') {
- setTimeout(function () {
- $('#ReceiptNo').focus();
- }, 200);
- }
- else {
- ReceiptNo = $('#ReceiptNo').val();
- getMaterialMaster(ReceiptNo);
- }
- });
- $('#orderNo').on('select2:close', function () {
- if ($('#orderNo').val() === '0') {
- setTimeout(function () {
- $('#orderNo').focus();
- }, 200);
- }
- else {
- orderNo = $('#orderNo').val();
- getPurchaseOrderMaster(orderNo);
- }
- });
- $('#invoiceNo').keydown(function () {
- if (event.keyCode === 13) {
- if ($('#invoiceNo').val().trim() !== '') {
- checkvendorInvoiceNoIfExist($('#invoiceNo').val());
- }
- $('#InAD').focus();
- event.preventDefault();
- return false;
- }
- });
- var conversionRate = 0, thisrate = 0;
- $('#unitId').on('select2:close', function () {
- if ($('#unitId').val() === '0') {
- $('#unitId').focus();
- }
- else {
- if (ismultipleunit === 1) {
- if ($('#unitId').children('option:first-child').is(':selected')) {
- unitConversionId = 0; conversionRate = 0;
- thisrate = originalRate;
- }
- else {
- $.ajax({
- url: '/PurchaseInvoice/UnitConversionrategetbyunitandproductID?DbName=' + DbName + '&productId=' + PId + '&unitId=' + $('#unitId').val(),
- type: 'get',
- async: false,
- success: function (data) {
- if (data !== "") {
- unitConversionId = data.unitConversionId; conversionRate = data.conversionRate;
- thisrate = conversionRate * originalRate;
- }
- }
- });
- }
- $('#rate').val(thisrate);
- if ($('#qty').val() !== '') {
- var amt = parseFloat($('#rate').val() * $('#qty').val());
- $('#grossValue').val(amt);
- $('#Netamt').val(amt);
- $('#NetTotal').val(amt);
- calTax();
- }
- }
- else {
- unitConversionId = 0;
- }
- if ($('#rate').hasClass('disabled')) {
- setTimeout(function () {
- $('#goDownid').focus();
- }, 200);
- }
- else {
- setTimeout(function () {
- $('#rate').focus();
- }, 200);
- }
- }
- });
- $('#goDownid').on('select2:close', function () {
- if ($('#goDownid').val() === '0') {
- $('#goDownid').focus();
- }
- else {
- RackViewAllByGodownForCombo($('#goDownid').val());
- setTimeout(function () {
- $('#rackId').focus();
- }, 200);
- }
- });
- $('#rackId').on('select2:close', function () {
- if ($('#rackId').val() === '0') {
- $('#rackId').focus();
- }
- else {
- if ($('#batchId').hasClass('disabled')) {
- setTimeout(function () {
- $('#disPer').focus();
- }, 200);
- }
- else {
- setTimeout(function () {
- $('#batchId').focus();
- }, 200);
- }
- }
- });
- $('#taxId').on('select2:close', function () {
- if ($('#taxId').val() === '0') {
- $('#taxId').focus();
- }
- else {
- calTax();
- setTimeout(function () { $('#addBill').focus(); }, 200);
- }
- });
- $('#AdditionalCostComboFill').on('select2:close', function () {
- if ($('#AdditionalCostComboFill').val() === '0') {
- $('#AdditionalCostComboFill').focus();
- }
- else {
- //tax // import // free // check
- $.ajax({
- url: '/PurchaseInvoice/AccountLedgerIdGetbyId?DbName=' + DbName + '&id=' + $('#AdditionalCostComboFill').val(),
- async: false,
- type: 'get',
- success: function (data) {
- if (data.iseffectonvat === 1) {
- isAddTax = 1;
- }
- }
- });
- setTimeout(function () {
- $('#cashPartyAdditional').focus();
- }, 200);
- }
- });
- $('#cashPartyAdditional').on('select2:close', function () {
- if ($('#cashPartyAdditional').val() === '0') {
- $('#cashPartyAdditional').focus();
- }
- else {
- setTimeout(function () {
- $('#additionalAmt').focus();
- }, 200);
- }
- });
- //event of focus
- $('#crPeriod').focus(function () {
- $('#crPeriod').val($('#crPeriod').val()).select();
- });
- $('#qty').focus(function () {
- $('#qty').val($('#qty').val()).select();
- });
- $('#rate').focus(function () {
- var thisval = $('#rate').val();
- $('#rate').val(thisval).select();
- });
- $('#disPer').focus(function () {
- $('#disPer').val($('#disPer').val()).select();
- });
- $('#disAmt').focus(function () {
- $('#disAmt').val($('#disAmt').val()).select();
- });
- $('#productCode').focus(function () {
- if ($('#productCode').val() !== '') {
- $('#productCode').val($('#productCode').val()).select();
- }
- });
- //load data in dblclick
- $('#PIbody').on('dblclick', '.PIdata', function () {
- purchaseDetailsId = 0; stockpostid = 0;
- editId = $(this).data('id');
- i = JSON.parse(localStorage.getItem('keyPI' + editId)).keyidPI;
- purchaseDetailsId = JSON.parse(localStorage.getItem('keyPI' + i)).purchaseDetailsId;
- stockpostid = JSON.parse(localStorage.getItem('keyPI' + i)).stockpostid;
- productType = JSON.parse(localStorage.getItem('keyPI' + i)).productType;
- $('#ProductId').val(JSON.parse(localStorage.getItem('keyPI' + editId)).ProductId);
- $('#productCode').val(JSON.parse(localStorage.getItem('keyPI' + editId)).ProductCode);
- //$('#productName').val(JSON.parse(localStorage.getItem('keyPI' + editId)).ProductName);
- $('#productName').val(JSON.parse(localStorage.getItem('keyPI' + editId)).ProductCode).select2();
- productName = $('#productName').children("option").filter(":selected").text();
- $('#qty').val(JSON.parse(localStorage.getItem('keyPI' + editId)).Qty);
- $('#rate').val(JSON.parse(localStorage.getItem('keyPI' + editId)).Rate);
- unitConversionId = JSON.parse(localStorage.getItem('keyPI' + editId)).unitConversionId;
- $('#unitId').val(JSON.parse(localStorage.getItem('keyPI' + editId)).UnitID).select2();
- $('#goDownid').val(JSON.parse(localStorage.getItem('keyPI' + editId)).GodownID).select2();
- $('#rackId').val(JSON.parse(localStorage.getItem('keyPI' + editId)).RackID).select2();
- $('#batchId').val(JSON.parse(localStorage.getItem('keyPI' + editId)).Batch);
- $('#disPer').val(JSON.parse(localStorage.getItem('keyPI' + editId)).DisPer);
- $('#disAmt').val(JSON.parse(localStorage.getItem('keyPI' + editId)).Discount);
- $('#grossValue').val(JSON.parse(localStorage.getItem('keyPI' + editId)).GrossValue);
- $('#Netamt').val(JSON.parse(localStorage.getItem('keyPI' + editId)).TotalAmt);
- $('#chargeId').val(JSON.parse(localStorage.getItem('keyPI' + editId)).ChargeID).select2();
- $('#chargeAmt').val(JSON.parse(localStorage.getItem('keyPI' + editId)).chargeAmt);
- if (JSON.parse(localStorage.getItem('keyPI' + editId)).ImportValue > 0) {
- $('#ImportValue').prop('disabled', false);
- }
- else {
- $('#ImportValue').prop('disabled', true);
- }
- $('#ImportValue').val(JSON.parse(localStorage.getItem('keyPI' + editId)).ImportValue);
- $('#taxId').val(JSON.parse(localStorage.getItem('keyPI' + editId)).TaxID).select2();
- $('#taxAmt').val(JSON.parse(localStorage.getItem('keyPI' + editId)).TaxAmt);
- $('#NetTotal').val(JSON.parse(localStorage.getItem('keyPI' + editId)).Total);
- $('#ExAD').val(JSON.parse(localStorage.getItem('keyPI' + editId)).expiryDate);
- grossAmt -= parseFloat(JSON.parse(localStorage.getItem('keyPI' + i)).GrossValue);
- disAmt -= parseFloat(JSON.parse(localStorage.getItem('keyPI' + i)).Discount);
- netAmt -= parseFloat(JSON.parse(localStorage.getItem('keyPI' + i)).NetValue);
- netTotal -= parseFloat(JSON.parse(localStorage.getItem('keyPI' + i)).Total);
- if (parseFloat(JSON.parse(localStorage.getItem('keyPI' + i)).TaxAmt) === 0) {
- taxable -= parseFloat((JSON.parse(localStorage.getItem('keyPI' + editId)).NetValue));
- if (isTax === 1) {
- $('#TaxableAmt').text(parseFloat(taxable).toFixed(numberOfDecimal));
- $('#gtaxAble').val(parseFloat(taxable).toFixed(numberOfDecimal));
- }
- }
- if (parseFloat(JSON.parse(localStorage.getItem('keyPI' + i)).TaxAmt) > 0) {
- nonTaxable -= parseFloat((JSON.parse(localStorage.getItem('keyPI' + editId)).NetValue));
- $('#NonTaxableAmt').text(parseFloat(nonTaxable).toFixed(numberOfDecimal));
- taxAmt -= parseFloat(JSON.parse(localStorage.getItem('keyPI' + i)).TaxAmt);
- $('#taxAmtF').text(parseFloat(taxAmt).toFixed(numberOfDecimal));
- $('#gTaxAmt').val(parseFloat(taxAmt).toFixed(numberOfDecimal));
- }
- $('#grossAmtF').text(parseFloat(grossAmt).toFixed(numberOfDecimal));
- $('#disAmtF').text(parseFloat(disAmt).toFixed(numberOfDecimal));
- $('#netAmtF').text(parseFloat(netAmt).toFixed(numberOfDecimal));
- $('#netTotalF').text(parseFloat(netTotal).toFixed(numberOfDecimal));
- totalGrand = netTotal + parseFloat($('#TotalAdditionalCost').text());
- //$('#NonTaxableAmt').text(parseFloat(nonTaxable).toFixed(numberOfDecimal));
- $('#ginvoiceTotal').text(parseFloat(netTotal).toFixed(numberOfDecimal));
- $('#billAmount').val(parseFloat(netTotal).toFixed(numberOfDecimal));
- transAmt = $('#billAmount').val();
- $('#totalAmount').val(parseFloat(netTotal).toFixed(numberOfDecimal));
- gCosttoParty = parseFloat(netTotal) + parseFloat($('#CosttoParty').text());
- $('#gCostToparty').text(parseFloat(gCosttoParty).toFixed(numberOfDecimal));
- $('#gtotal').text(parseFloat(totalGrand).toFixed(numberOfDecimal));
- for (var ij = 0; ij < lastkeyTax + 1; ij++) {
- if (localStorage.getItem('keyTax' + ij)) {
- if (JSON.parse(localStorage.getItem('keyPI' + editId)).TaxID === JSON.parse(localStorage.getItem('keyTax' + ij)).TaxID) {
- var thisTaxid = JSON.parse(localStorage.getItem('keyTax' + ij)).keyidTax;
- var thistax = JSON.parse(localStorage.getItem('keyTax' + thisTaxid)).TaxID;
- var thisTaxAmt = JSON.parse(localStorage.getItem('keyTax' + thisTaxid)).TaxAmt;
- var uptaxAmt = parseFloat(thisTaxAmt) - parseFloat(JSON.parse(localStorage.getItem('keyPI' + editId)).TaxAmt);
- localStorage.removeItem('keyTax' + thisTaxid);
- localStorage.setItem('keyTax' + thisTaxid, JSON.stringify({
- keyidTax: thisTaxid,
- TaxID: thistax,
- TaxAmt: parseFloat(uptaxAmt).toFixed(numberOfDecimal)
- }));
- }
- }
- }
- localStorage.removeItem('keyPI' + editId);
- showTablePI();
- setTimeout(function () { $('#productName').focus(); }, 1000);
- });
- $('#additionalBody').on('dblclick', '.additionalBodydata', function () {
- var id = $(this).data('id');
- i = JSON.parse(localStorage.getItem('keyAdd' + id)).keyidAdd;
- addcostid = JSON.parse(localStorage.getItem('keyAdd' + id)).addcostid;
- isAddTax = JSON.parse(localStorage.getItem('keyAdd' + id)).isAddTax;
- $('#AdditionalCostComboFill').val(JSON.parse(localStorage.getItem('keyAdd' + id)).AdditionalLedger).select2();
- $('#cashPartyAdditional').val(JSON.parse(localStorage.getItem('keyAdd' + id)).AdditionalCashparty).select2();
- $('#additionalAmt').val(JSON.parse(localStorage.getItem('keyAdd' + id)).AddtionalAmount);
- TotalAdditionalCost -= parseFloat(JSON.parse(localStorage.getItem('keyAdd' + id)).AddtionalAmount);
- if (parseInt($('#CashOrPartyComboFill').val()) === JSON.parse(localStorage.getItem('keyAdd' + id)).AdditionalCashparty ||
- $('#CashOrPartyComboFill').val() === JSON.parse(localStorage.getItem('keyAdd' + id)).AdditionalCashparty) {
- CosttoParty -= parseFloat(JSON.parse(localStorage.getItem('keyAdd' + id)).AddtionalAmount);
- }
- if (parseFloat(JSON.parse(localStorage.getItem('keyAdd' + id)).isAddTax) === 1) {
- taxable -= parseFloat(JSON.parse(localStorage.getItem('keyAdd' + id)).AddtionalAmount);
- }
- else {
- nonTaxable -= parseFloat(JSON.parse(localStorage.getItem('keyAdd' + id)).AddtionalAmount);
- }
- var discount = 0;
- if ($('#gbillDiscount').val() > 0) {
- discount = $('#gbillDiscount').val();
- }
- $('#TotalAdditionalCost').text(parseFloat(TotalAdditionalCost).toFixed(numberOfDecimal));
- //totalGrand = parseFloat(nonTaxable) + parseFloat(taxable) + parseFloat($('#gTaxAmt').val());
- totalGrand = parseFloat($('#TotalAdditionalCost').text()) + parseFloat($('#ginvoiceTotal').text()) + parseFloat(discount);
- totalInvoice = $('#netTotalF').text();
- $('#AdditionalCostComboFill').focus(); $('#NonTaxableAmt').text(parseFloat(nonTaxable).toFixed(numberOfDecimal));
- $('#gtotal').text(parseFloat(totalGrand).toFixed(numberOfDecimal));
- $('#ginvoiceTotal').text(parseFloat(totalInvoice).toFixed(numberOfDecimal));
- $('#billAmount').val(parseFloat(totalInvoice).toFixed(numberOfDecimal));
- transAmt = $('#billAmount').val();
- $('#totalAmount').val(parseFloat(totalInvoice).toFixed(numberOfDecimal));
- $('#CosttoParty').text(parseFloat(CosttoParty).toFixed(numberOfDecimal));
- gCosttoParty = parseFloat(CosttoParty) + parseFloat($('#ginvoiceTotal').text());
- $('#gCostToparty').text(parseFloat(gCosttoParty).toFixed(numberOfDecimal));
- localStorage.removeItem('keyAdd' + id);
- showTableAddtional();
- });
- //event of account ledger modal shown
- $('#btnPA').click(function () {
- $('#AccountLEDGER').modal('show');
- $('#legderGroupid').val('11').select2();
- });
- $('#btnCP').click(() => {
- $('#AccountLEDGER').modal('show');
- $('#legderGroupid').val('22').select2();
- });
- $('#AccountLEDGER').on('shown.bs.modal', function () {
- $('#PurchaseAccountComboFill').select2('close');
- $('#CashOrPartyComboFill').select2('close');
- $('#legderNameid').focus();
- $('.savebtnMain').addClass('active');
- $('.resetbtnMain').addClass('active');
- $('#PInarration').removeClass('active');
- $('#ledgerNarration').addClass('active');
- $('.savePI').removeClass('active');
- $('.updatePI').removeClass('active');
- $('.resetPI').removeClass('active');
- if ($("#legderGroupid").val() > 0) {
- enableDisable($("#legderGroupid").val());
- }
- $('#savebtnMain').show();
- $('#resetbtnMain').show();
- $('#updatebtnMain').hide();
- $('#deletebtnMain').hide();
- $('#updatebtnSec').hide();
- });
- $('#AccountLEDGER').on('hidden.bs.modal', function () {
- $('.savebtnMain').removeClass('active');
- $('.resetbtnMain').removeClass('active');
- $('#PInarration').addClass('active');
- $('#ledgerNarration').addClass('active');
- $('.savePI').addClass('active');
- $('.updatePI').addClass('active');
- $('.resetPI').addClass('active');
- resetLedgerform();
- //load CashOrPartyComboFill
- CashOrPartyComboFill();
- //load CashorBankorPartyComboFill
- CashorBankorPartyComboFill();
- //load PurchaseAccountComboFill
- PurchaseAccountComboFill();
- //load AdditionalCostComboFill
- AdditionalCostComboFill();
- setTimeout(function () { $('#PurchaseAccountComboFill').focus(); }, 1000);
- });
- //focus on narration
- //press Alt+N for pop up account ledger
- //press space for focus in narration
- $(document).keydown(function () {
- //for narration
- if (event.keyCode === 192) {
- //$('#PurchaseAccountComboFill').select2('close');
- //$('#CashOrPartyComboFill').select2('close');
- //$('#purchaseMode').val(0).select2('close');
- //$('#VoucherTypeSelectionComboFill').select2('close');
- //$('#orderNo').select2('close');
- //$('#unitId').select2('close');
- //$('#goDownid').select2('close');
- //$('#rackId').select2('close');
- //$('#taxId').select2('close');
- //$('#AdditionalCostComboFill').select2('close');
- //$('#cashPartyAdditional').select2('close');
- $('#InAD').datepicker('hide');
- $('#VAD').datepicker('hide');
- $('#currentAD').datepicker('hide');
- $('.nepali-date-picker').css({ 'display': 'none' });
- //e.preventDefault();
- //return false;
- if ($('#ledgerNarration').hasClass('active')) {
- setTimeout(function () { $('#ledgerNarration.active').focus(); }, 2000);
- }
- if ($('#PInarration').hasClass('active')) {
- setTimeout(function () { $('#PInarration.active').focus(); }, 2000);
- }
- event.preventDefault();
- return false;
- }
- //to create new account ledger atl + N
- if (event.altKey && (event.keyCode === 78)) {
- if ($('.PurchaseID span.select2').hasClass('select2-container--open')) {
- $('#PurchaseAccountComboFill').select2('close');
- $('.AddLedgerPI').trigger('click');
- }
- else if ($('.CashParty span.select2').hasClass('select2-container--open')) {
- $('#CashOrPartyComboFill').select2('close');
- $('.AddLedgerPI').trigger('click');
- }
- else if ($('.ProductName span.select2').hasClass('select2-container--open')) {
- $('#productName').select2('close');
- $('#ProductModal').modal('show');
- }
- e.preventDefault();
- return false;
- }
- //press CTRL+S and CTRL+R
- //for ctrl+s to save
- if (event.ctrlKey && (event.which === 83)) {
- if ($('.savePI.active').is(':visible')) {
- $('.savePI.active').trigger('click');
- }
- else if ($('.updatePI.active').is(':visible')) {
- $('.updatePI.active').trigger('click');
- }
- else if ($('.savebtnMain.active').is(':visible')) {
- $('.savebtnMain.active').trigger('click');
- }
- else if ($('.savebtnSec.active').is(':visible')) {
- $('.savebtnSec.active').trigger('click');
- }
- else if ($('.updatebtnMain.active').is(':visible')) {
- $('.updatebtnMain.active').trigger('click');
- }
- else if ($('.updatebtnSec.active').is(':visible')) {
- $('.updatebtnSec.active').trigger('click');
- }
- else if ($('.savebtnAganist.active').is(':visible')) {
- $('.savebtnAganist.active').trigger('click');
- }
- event.preventDefault();
- return false;
- }
- //ctrl + r for reset
- if (event.ctrlKey && (event.which === 82)) {
- if ($('.resetPI.active').is(':visible')) {
- $('.resetPI.active').trigger('click');
- }
- else if ($('.resetbtnMain.active').is(':visible')) {
- $('.resetbtnMain.active').trigger('click');
- }
- else if ($('.resetbtnSec.active').is(':visible')) {
- $('.resetbtnSec.active').trigger('click');
- }
- else if ($('.resetbtnAganist.active').is(':visible')) {
- $('.resetbtnAganist.active').trigger('click');
- }
- event.preventDefault();
- return false;
- }
- });
- //double enter
- var count = 0;
- $('#PInarration').on('keydown', function (e) {
- if (event.keyCode === 32) {
- $('#PInarration').val($('#PInarration').val() + '');
- }
- $('#PInarration').removeClass('active');
- if (event.keyCode === 13) {
- count++;
- setTimeout(function () {
- count--;
- }, 500);
- if (count === 2) {
- $('#TransportationCompany').focus();
- e.preventDefault();
- return false;
- }
- }
- });
- $('#TransportationCompany').on('keydown', function (e) {
- $('#PInarration').removeClass('active');
- if (event.keyCode === 13) {
- $('#LRNo').focus();
- e.preventDefault();
- return false;
- }
- if (event.keyCode === 32) {
- $('#TransportationCompany').val($('#TransportationCompany').val() + '');
- }
- });
- $('#LRNo').on('keydown', function (e) {
- $('#PInarration').removeClass('active');
- if (event.keyCode === 13) {
- $('#btnPISave.active').focus();
- $('#btnPIUpdate.active').focus();
- e.preventDefault();
- return false;
- }
- if (event.keyCode === 32) {
- $('#LRNo').val($('#LRNo').val() + ' ');
- }
- });
- $('#ImportValue').keydown(function () {
- if (event.keyCode === 13) {
- if (isfree === 0) {
- setTimeout(function () {
- $('#taxId').focus();
- }, 100);
- }
- }
- });
- $('#additionalAmt').keydown(function (e) {
- if (event.keyCode === 13) {
- $('#additionalBtn').focus();
- }
- });
- //validation for ammount and interger
- $('#rate').keypress(function (e) {
- if (e.which === 46) {
- if ($(this).val().indexOf('.') !== -1) {
- return false;
- }
- }
- if (e.which !== 8 && e.which !== 0 && e.which !== 46 && (e.which < 48 || e.which > 57)) {
- return false;
- }
- });
- $('#qty').keypress(function (e) {
- if (e.which === 46) {
- if ($(this).val().indexOf('.') !== -1) {
- return false;
- }
- }
- if (e.which !== 8 && e.which !== 0 && e.which !== 46 && (e.which < 48 || e.which > 57)) {
- return false;
- }
- });
- $('#disAmt').keypress(function (e) {
- if (e.which === 46) {
- if ($(this).val().indexOf('.') !== -1) {
- return false;
- }
- }
- if (e.which !== 8 && e.which !== 0 && e.which !== 46 && (e.which < 48 || e.which > 57)) {
- return false;
- }
- });
- $('#additionalAmt').keypress(function (e) {
- if (e.which === 46) {
- if ($(this).val().indexOf('.') !== -1) {
- return false;
- }
- }
- if (e.which !== 8 && e.which !== 0 && e.which !== 46 && (e.which < 48 || e.which > 57)) {
- return false;
- }
- });
- $('#gbillDiscount').keypress(function (e) {
- if (e.which === 46) {
- if ($(this).val().indexOf('.') !== -1) {
- return false;
- }
- }
- if (e.which !== 8 && e.which !== 0 && e.which !== 46 && (e.which < 48 || e.which > 57)) {
- return false;
- }
- });
- $('#disPer').keypress(function (e) {
- if (e.which === 46) {
- if ($(this).val().indexOf('.') !== -1) {
- return false;
- }
- }
- if (e.which !== 8 && e.which !== 0 && e.which !== 46 && (e.which < 48 || e.which > 57)) {
- return false;
- }
- });
- $('#crPeriod').keypress(function (e) {
- var key = e.which;
- if (!(key >= 48 && key <= 57))
- e.preventDefault();
- });
- //$('#invoiceNo').addClass('intergerValidation');
- $('#prSearch').click(function () {
- getPR('ProductbyName', $('#prName').val());
- droptable();
- });
- $('#prName').keydown(function () {
- if (event.keyCode === 13) {
- $('#prSearch').trigger('click');
- event.preventDefault();
- return false;
- }
- });
- $('#ProductList').on('shown.bs.modal', function () {
- getPR('ProductbyName', '');
- $('#PInarration').removeClass('active');
- droptable();
- if ($('tbody#modalPRBody.tbody tr').is(':focus')) {
- $(document).keydown(function (e) {
- if (event.keyCode === 13) {
- if ($('tbody#modalPRBody.tbody tr:focus').data('id') !== undefined) {
- var thisid = $('tbody#modalPRBody.tbody tr:focus').data('id');
- $('#productCode').val(thisid);
- $('#ProductList').modal('hide');
- ProductDetailsgetPerticlular(thisid);
- }
- e.preventDefault();
- return false;
- }
- });
- }
- });
- $('#ProductList').on('hidden.bs.modal', function (e) {
- $('#PInarration').addClass('active');
- if (event.keyCode === 13) {
- if ($('#productName').val() === '') {
- $('#productName').focus();
- }
- else {
- $('#qty').focus();
- }
- e.preventDefault();
- return false;
- }
- $('#prName').val('');
- });
- //for update
- $('#voucherNo').keydown(function (e) {
- if (event.keyCode === 13) {
- $('#loading').fadeIn();
- clearPI();
- getMaster($('#voucherNo').val());
- $('#PurchaseAccountComboFill').focus();
- $('#btnPISave').hide();
- $('#btnPIUpdate').show();
- e.preventDefault();
- return false;
- }
- });
- //delete all
- $('#btnDeleteAll').on('click', function () {
- ConfirmDeleteAll();
- $('#delete-modal').modal('hide');
- });
- $('#delete-modal').on('hidden.bs.modal', function () {
- $('.yes').removeClass('pi');
- $('.yes').removeClass('additional');
- $('.yes').removeClass('singleAdd');
- $('.yes').removeClass('singlePi');
- });
- $('#ProductModal').on('shown.bs.modal', function () {
- setTimeout(function () { $('#txtProductName').focus(); }, 100);
- });
- $('#ProductModal').on('hidden.bs.modal', function () {
- setTimeout(function () { $('#productCode').focus(); }, 100);
- });
- $('#update').on('shown.bs.modal', function () {
- $('#loading').fadeIn();
- $('#btnUpdateYes').click(function () {
- if ($('.btnyes').hasClass('PI')) {
- $('#btnNumb').focus();
- var errorCount = 0;
- //delete product
- if (localStorage.length > 0) {
- for (var kl = 0; kl < localStorage.length; kl++) {
- if (localStorage.getItem('keyPI' + kl)) {
- for (var jl = 0; jl < purchaselist.length; jl++) {
- var checkpurchid = getcheckpurchid(purchaselist[jl]);
- if (checkpurchid) {
- continue;
- }
- else {
- if (JSON.parse(localStorage.getItem('keyPI' + kl)).purchaseDetailsId !== 0) {
- $.ajax({
- url: '/PurchaseInvoice/PurchaseDetailsDelete?DbName=' + DbName + '&purchaseDetailsId=' + purchaselist[jl],
- type: 'post',
- async: false,
- success: function () {
- $.ajax({
- url: '/PurchaseInvoice/StockPostingDelete?DbName=' + DbName + '&stockPostingId=' + stockpostinglist[jl],
- type: 'post',
- async: false,
- success: function () {
- },
- error: function () {
- //toastr.error(ledgerIDList[i]);
- errorCount++;
- }
- });
- },
- error: function () {
- //toastr.error(ledgerIDList[i]);
- errorCount++;
- }
- });
- }
- }
- }
- }
- }
- }
- if (localStorage.length > 0) {
- for (var kle = 0; kle < localStorage.length; kle++) {
- for (var add = 0; add < addcpstList.length; add++) {
- var checkaddcostid = getcheckaddcostid(addcpstList[add]);
- if (checkaddcostid) {
- continue;
- }
- else {
- $.ajax({
- url: '/PurchaseInvoice/AdditionalCostDelete?DbName=' + DbName + '&additionalCostId=' + addcpstList[add],
- type: 'post',
- async: false,
- success: function () {
- },
- error: function () {
- //toastr.error(ledgerIDList[i]);
- errorCount++;
- }
- });
- }
- }
- }
- }
- if (errorCount === 0) {
- let di = 0, adi = 0, taxi = 0, chargi = 0;
- for (var i = 0; i < lastkeyPI + 1; i++) {
- if (localStorage.getItem('keyPI' + i)) {
- datas[di] = JSON.stringify({
- purchaseDetailsId: JSON.parse(localStorage.getItem('keyPI' + i)).purchaseDetailsId,
- stockpostid: JSON.parse(localStorage.getItem('keyPI' + i)).stockpostid,
- ProductId: JSON.parse(localStorage.getItem('keyPI' + i)).ProductId,
- productType: JSON.parse(localStorage.getItem('keyPI' + i)).productType,
- ProductCode: JSON.parse(localStorage.getItem('keyPI' + i)).ProductCode,
- ProductName: JSON.parse(localStorage.getItem('keyPI' + i)).ProductName,
- unitConversionId: JSON.parse(localStorage.getItem('keyPI' + i)).unitConversionId,
- Qty: JSON.parse(localStorage.getItem('keyPI' + i)).Qty,
- Unit: JSON.parse(localStorage.getItem('keyPI' + i)).Unit,
- UnitID: JSON.parse(localStorage.getItem('keyPI' + i)).UnitID,
- Godown: JSON.parse(localStorage.getItem('keyPI' + i)).Godown,
- GodownID: JSON.parse(localStorage.getItem('keyPI' + i)).GodownID,
- Rack: JSON.parse(localStorage.getItem('keyPI' + i)).Rack,
- RackID: JSON.parse(localStorage.getItem('keyPI' + i)).RackID,
- Batch: JSON.parse(localStorage.getItem('keyPI' + i)).Batch,
- Rate: JSON.parse(localStorage.getItem('keyPI' + i)).Rate,
- DisPer: JSON.parse(localStorage.getItem('keyPI' + i)).DisPer,
- GrossValue: JSON.parse(localStorage.getItem('keyPI' + i)).GrossValue,
- Discount: JSON.parse(localStorage.getItem('keyPI' + i)).Discount,
- TotalAmt: JSON.parse(localStorage.getItem('keyPI' + i)).TotalAmt,
- ChargeID: JSON.parse(localStorage.getItem('keyPI' + i)).ChargeID,
- chargeAmt: JSON.parse(localStorage.getItem('keyPI' + i)).chargeAmt,
- TaxableVal: JSON.parse(localStorage.getItem('keyPI' + i)).TaxableVal,
- ImportValue: JSON.parse(localStorage.getItem('keyPI' + i)).ImportValue,
- Tax: JSON.parse(localStorage.getItem('keyPI' + i)).Tax,
- TaxID: JSON.parse(localStorage.getItem('keyPI' + i)).TaxID,
- TaxAmt: JSON.parse(localStorage.getItem('keyPI' + i)).TaxAmt,
- Total: JSON.parse(localStorage.getItem('keyPI' + i)).Total,
- expiryDate: JSON.parse(localStorage.getItem('keyPI' + i)).expiryDate
- });
- di++;
- }
- }
- for (var j = 0; j < lastkeyAdd + 1; j++) {
- if (localStorage.getItem('keyAdd' + j)) {
- if (parseInt(JSON.parse(localStorage.getItem('keyAdd' + j)).AddtionalAmount) > 0) {
- Additionaldatas[adi] = JSON.stringify({
- AddCashpartyName: JSON.parse(localStorage.getItem('keyAdd' + j)).AddCashpartyName,
- addcostid: JSON.parse(localStorage.getItem('keyAdd' + j)).addcostid,
- AddLedgerName: JSON.parse(localStorage.getItem('keyAdd' + j)).AddLedgerName,
- AdditionalCashparty: JSON.parse(localStorage.getItem('keyAdd' + j)).AdditionalCashparty,
- AdditionalLedger: JSON.parse(localStorage.getItem('keyAdd' + j)).AdditionalLedger,
- AddtionalAmount: JSON.parse(localStorage.getItem('keyAdd' + j)).AddtionalAmount
- });
- adi++;
- }
- }
- }
- for (var k = 0; k < lastkeyTax + 1; k++) {
- if (localStorage.getItem('keyTax' + k)) {
- taxdatas[taxi] = JSON.stringify({
- TaxID: JSON.parse(localStorage.getItem('keyTax' + k)).TaxID,
- TaxAmt: JSON.parse(localStorage.getItem('keyTax' + k)).TaxAmt
- });
- taxi++;
- }
- }
- for (var l = 0; l < lastkeyCharge + 1; l++) {
- if (localStorage.getItem('keyCharge' + l)) {
- if (parseInt(JSON.parse(localStorage.getItem('keyCharge' + l)).ChargeAmt) > 0) {
- chargedatas[chargi] = JSON.stringify({
- ChargeID: JSON.parse(localStorage.getItem('keyCharge' + l)).ChargeID,
- ChargeAmt: JSON.parse(localStorage.getItem('keyCharge' + l)).ChargeAmt
- });
- chargi++;
- }
- }
- }
- var totalDiscount = parseFloat(billDiscount) + parseFloat($('#disAmtF').text());
- var dataObj = {
- DbName: DbName,
- date: $('#VAD').val(),
- purchaseMasterId: purchaseMasterId,
- ledgerId: $('#CashOrPartyComboFill').val(),
- vendorInvoiceNo: $('#invoiceNo').val().trim(),
- vendorInvoiceDate: $('#InAD').val(),
- creditPeriod: $('#crPeriod').val().trim(),
- narration: $('#PInarration').val().trim(),
- purchaseAccount: $('#PurchaseAccountComboFill').val(),
- additionalCost: $('#TotalAdditionalCost').text(),
- totalTax: $('#gTaxAmt').val(),//total tax
- costtoParty: $('#gCostToparty').text(),
- grandTotal: $('#gtotal').text(),
- invoiceTotal: $('#ginvoiceTotal').text(),// party amount
- lrNo: $('#LRNo').val().trim(),
- transportationCompany: $('#TransportationCompany').val().trim(),
- ProductNetTotal: $('#netTotalF').text(),
- grossValue: $('#grossAmtF').text(),
- totalDiscount: totalDiscount, //total discount
- list: datas,
- partyBalanceId: partyBalanceId,
- addList: Additionaldatas,
- taxlist: taxdatas,
- addcostlpid: addcostlpid,
- purchlpid: purchlpid,
- cashbanklpid: cashbanklpid,
- taxlpid: taxlpid,
- chargelpid: chargelpid,
- discountlpid: discountlpid,
- chargeList: chargedatas,
- BillTaxPercentage: BillTaxPercentage,
- BillTaxAmount: BillTaxAmount,
- BillExciseDutyPercentage: BillExciseDutyPercentage,
- BillExciseDutyAmount: BillExciseDutyAmount,
- BillDiscountPercentage: BillDiscountPercentage,
- billDiscount: billDiscount//$('#gbillDiscount').val()
- };
- $.ajax({
- type: 'post',
- dataType: 'json',
- data: dataObj,
- url: '/PurchaseInvoice/UpdatePI',
- success: function (data) {
- if (data.data === '1') {
- toastr.success('Updated Successfully');
- resetForm();
- $('#btnPISave').show();
- $('#btnPIUpdate').hide();
- console.log(data.invoiceNo);
- $(".btnprintyes").attr('data-invoiceno', data.invoiceNo);
- if ($(".PrintBill").is(":checked")) {
- $(".btnprintyes").trigger('click');
- }
- $('#loading').fadeOut();
- }
- else {
- toastr.error('Not added : ' + data);
- $('#loading').fadeOut();
- setTimeout(function () {
- $('#PurchaseAccountComboFill').focus();
- }, 100);
- }
- $('#update').modal('hide');
- },
- error: function (ex) {
- toastr.error('Unable to update data' + ex.statusText);
- $('#loading').fadeOut();
- $('#update').modal('hide');
- setTimeout(function () {
- $('#PurchaseAccountComboFill').focus();
- }, 100);
- }
- });
- }
- else {
- $('#loading').fadeOut();
- toastr.error('system error: record update could not be saved');
- $('#update').modal('hide');
- setTimeout(function () {
- $('#PurchaseAccountComboFill').focus();
- }, 100);
- }
- $('#btnUpdateYes').removeClass('PI');
- }
- });
- });
- });
- // add after free QTY
- function addProductsGrid() {
- if ($('.isFreeQTY').is(':checked')) {
- addBills();
- }
- else {
- if ($('#NetTotal').val() === '' || $('#NetTotal').val() === '0' ||
- $('#Netamt').val() === '' || $('#Netamt').val() === '0' ||
- $('#grossValue').val() === '' || $('#grossValue').val() === '0') {
- $('#productCode').focus();
- toastr.error('Fill required field');
- }
- else {
- if (accountgpId === 27) {
- if (negativeCash === 0) {
- if ($('#NetTotal').val() > CashAmount) {
- toastr.error('Net Total is greater than Cash Amount');
- }
- else {
- addBills();
- }
- }
- else {
- addBills();
- }
- }
- else {
- addBills();
- }
- }
- }
- }
- //add product details for purchase
- function addBills() {
- var i = 0;
- var action = '';
- while (localStorage.getItem('keyPI' + i)) {
- i++;
- }
- if (parseFloat(orderQTY) === parseFloat($('#qty').val())) {
- action = 'Accepted';
- }
- else {
- action = 'Partial';
- }
- var check = checkProductnamePI();
- let batch = '';
- if ($('#batchId').val().trim() === '') {
- batch = "N/A";
- }
- else {
- batch = $('#batchId').val();
- }
- if ($('.isFreeQTY').is(':checked')) {
- if ($('#taxAmt').val() < 0) {
- taxable += parseFloat($('#Netamt').val());
- }
- thistaxamt = $('#taxAmt').val();
- localStorage.setItem('keyPI' + i, JSON.stringify({
- keyidPI: i,
- ProductId: $('#ProductId').val(),
- ProductCode: $('#productCode').val(),
- purchaseDetailsId: purchaseDetailsId,
- stockpostid: stockpostid,
- ProductName: productName,
- Qty: $('#qty').val(),
- Unit: $('#unitId').children('option').filter(':selected').text(),
- UnitID: $('#unitId').val(),
- Godown: $('#goDownid').children('option').filter(':selected').text(),
- GodownID: $('#goDownid').val(),
- Rack: $('#rackId').children('option').filter(':selected').text(),
- RackID: $('#rackId').val(),
- unitConversionId: unitConversionId,
- Batch: batch,
- Rate: $('#rate').val(),
- DisPer: $('#disPer').val(),
- GrossValue: $('#grossValue').val(),
- Discount: $('#disAmt').val(),
- TotalAmt: $('#Netamt').val(),
- Charge: $('#chargeId').children('option').filter(':selected').text(),
- ChargeID: $('#chargeId').val(),
- chargeAmt: $('#chargeAmt').val(),
- TaxableVal: $('#TaxableVal').val(),
- ImportValue: $('#ImportValue').val(),
- Tax: $('#taxId').children('option').filter(':selected').text(),
- TaxID: $('#taxId').val(),
- TaxAmt: $('#taxAmt').val(),
- Total: $('#NetTotal').val(),
- productType: productType,
- expiryDate: $('#ExAD').val(),
- materialReceiptMasterId: materialReceiptMasterId,
- purchaseOrderMasterId: purchaseOrderMasterId,
- action: action
- }));
- if (i > lastkeyPI) {
- lastkeyPI = i;
- }
- showTablePI();
- }
- else {
- if (check) {
- toastr.info('Product name exist in table below. Please Edit and Update');
- }
- else {
- if ($('#taxAmt').val() < 0) {
- taxable += parseFloat($('#Netamt').val());
- }
- thistaxamt = $('#taxAmt').val();
- localStorage.setItem('keyPI' + i, JSON.stringify({
- keyidPI: i,
- ProductId: $('#ProductId').val(),
- ProductCode: $('#productCode').val(),
- purchaseDetailsId: parseFloat(purchaseDetailsId),
- stockpostid: parseFloat(stockpostid),
- ProductName: productName,
- Qty: parseFloat($('#qty').val()),
- Unit: $('#unitId').children('option').filter(':selected').text(),
- UnitID: $('#unitId').val(),
- Godown: $('#goDownid').children('option').filter(':selected').text(),
- GodownID: $('#goDownid').val(),
- Rack: $('#rackId').children('option').filter(':selected').text(),
- RackID: $('#rackId').val(),
- unitConversionId: unitConversionId,
- Batch: batch,
- Rate: parseFloat($('#rate').val()),
- DisPer: parseFloat($('#disPer').val()),
- GrossValue: parseFloat($('#grossValue').val()),
- Discount: parseFloat($('#disAmt').val()),
- TotalAmt: parseFloat($('#Netamt').val()),
- Charge: $('#chargeId').children('option').filter(':selected').text(),
- ChargeID: $('#chargeId').val(),
- chargeAmt: parseFloat($('#chargeAmt').val()),
- TaxableVal: parseFloat($('#TaxableVal').val()),
- ImportValue: parseFloat($('#ImportValue').val()),
- Tax: $('#taxId').children('option').filter(':selected').text(),
- TaxID: $('#taxId').val(),
- TaxAmt: parseFloat($('#taxAmt').val()),
- Total: parseFloat($('#NetTotal').val()),
- productType: productType,
- expiryDate: $('#ExAD').val(),
- materialReceiptMasterId: parseFloat(materialReceiptMasterId),
- purchaseOrderMasterId: parseFloat(purchaseOrderMasterId),
- action: action
- }));
- if (i > lastkeyPI) {
- lastkeyPI = i;
- }
- showTablePI();
- }
- }
- $('#productCode').focus();
- unitdp();
- rackdp();
- reset(); reset();
- }
- //get product list
- function GetProductDetailsFromMaterialReceiptDetails(id, materialReceiptDetailsId) {
- $('#loading').fadeIn();
- $.ajax({
- url: '/PurchaseInvoice/GetProductDetailsFromMaterialReceiptDetails?DbName=' + DbName + '&materialReceiptDetailsId=' + materialReceiptDetailsId + '&productcode=' + id,
- type: 'get',
- async: false,
- success: function (data) {
- if (data !== '') {
- PId = data.productId;
- orderQTY = data.qty;
- var productCode = data.productCode;
- $.ajax({
- url: '/PurchaseInvoice/ProductDetailsgetPerticlular?DbName=' + DbName + '&producttype=' + 1 + '&productcode=' + productCode,
- type: 'get',
- async: false,
- success: function (data1) {
- if (data1 !== '') {
- if (data1.ismultipleunit === 1) {
- ismultipleunit = 1;
- UnitViewAllByProductId(data1.productId);
- $('#unitId').removeClass('disabled');
- $('#unitId').prop('disabled', false);
- }
- else {
- $('#unitId').addClass('disabled');
- $('#unitId').prop('disabled', true);
- }
- $('#unitId').val(data1.unitId).select2();
- $('#goDownid').val(data1.godownId).select2();
- $('#rackId').val(data1.rackId).select2();
- if (data1.taxId > 0) {
- $('#taxId').removeClass('disabled');
- $('#taxId').prop('disabled', false);
- $('#taxId').val(data1.taxId).select2();
- }
- else {
- $('#taxId').addClass('disabled');
- $('#taxId').prop('disabled', true);
- $('#taxId').val(1).select2();
- }
- if (data1.isallowBatch === 0) {
- $('#batchId').prop('disabled', true);
- $('#batchId').addClass('disabled');
- $('#ExAD').prop('disabled', true);
- $('#ExAD').addClass('disabled');
- $('#batchId').val('N/A');
- }
- else if (data1.isallowBatch === 1) {
- $('#batchId').prop('disabled', false);
- $('#batchId').removeClass('disabled');
- $('#ExAD').prop('disabled', false);
- $('#ExAD').removeClass('disabled');
- }
- //if (data1.ratefixed === 0) {
- // $("#rate").removeClass('disabled');
- // $("#rate").prop('disabled', false);
- // $('#rate').val(data1.purchaseRate);
- //}
- //else if (data1.ratefixed === 1) {
- // $('#rate').addClass('disabled');
- // $('#rate').prop('disabled', true);
- // $('#rate').val(data1.purchaseRate);
- //}
- }
- }
- });
- $('#rate').val(data.rate);
- $('#ProductId').val(data.productId);
- $('#productName').val(data.productName);
- $('#qty').val(data.qty);
- //originalRate = data.purchaseRate;
- productType = data.purchasetype;
- $('#disPer').val('0');
- $('#grossValue').val('0');
- $('#disAmt').val('0');
- $('#Netamt').val('0');
- $('#ImportValue').val('0');
- $('#taxAmt').val('0');
- $('#NetTotal').val('0');
- setTimeout(function () { $('#qty').focus(); }, 500);
- }
- $('#loading').fadeOut();
- },
- error: function () {
- $('#loading').fadeOut();
- toastr.error('enter correct product code');
- }
- });
- }
- function GetProductDetailsFromPurchaseOrderDetails(id, purchaseOrderDetailsId) {
- $('#loading').fadeIn();
- $.ajax({
- url: '/PurchaseInvoice/GetProductDetailsFromPurchaseOrderDetails?DbName=' + DbName + '&purchaseOrderDetailsId=' + purchaseOrderDetailsId + '&productcode=' + id,
- type: 'get',
- async: false,
- success: function (data) {
- if (data !== '') {
- PId = data.productId;
- orderQTY = data.qty;
- var productCode = data.productCode;
- $.ajax({
- url: '/PurchaseInvoice/ProductDetailsgetPerticlular?DbName=' + DbName + '&producttype=' + 1 + '&productcode=' + productCode,
- type: 'get',
- async: false,
- success: function (data1) {
- if (data1 !== '') {
- if (data1.ismultipleunit === 1) {
- ismultipleunit = 1;
- UnitViewAllByProductId(data1.productId);
- $('#unitId').removeClass('disabled');
- $('#unitId').prop('disabled', false);
- }
- else {
- $('#unitId').addClass('disabled');
- $('#unitId').prop('disabled', true);
- }
- $('#unitId').val(data1.unitId).select2();
- $('#goDownid').val(data1.godownId).select2();
- $('#rackId').val(data1.rackId).select2();
- if (data1.taxId > 0) {
- $('#taxId').removeClass('disabled');
- $('#taxId').prop('disabled', false);
- $('#taxId').val(data1.taxId).select2();
- }
- else {
- $('#taxId').addClass('disabled');
- $('#taxId').prop('disabled', true);
- $('#taxId').val(1).select2();
- }
- if (data1.isallowBatch === 0) {
- $('#batchId').prop('disabled', true);
- $('#batchId').addClass('disabled');
- $('#ExAD').prop('disabled', true);
- $('#ExAD').addClass('disabled');
- $('#batchId').val('N/A');
- }
- else if (data1.isallowBatch === 1) {
- $('#batchId').prop('disabled', false);
- $('#batchId').removeClass('disabled');
- $('#ExAD').prop('disabled', false);
- $('#ExAD').removeClass('disabled');
- }
- //if (data1.ratefixed === 0) {
- // $("#rate").removeClass('disabled');
- // $("#rate").prop('disabled', false);
- // $('#rate').val(data1.purchaseRate);
- //}
- //else if (data1.ratefixed === 1) {
- // $('#rate').addClass('disabled');
- // $('#rate').prop('disabled', true);
- // $('#rate').val(data1.purchaseRate);
- //}
- }
- }
- });
- $('#ProductId').val(data.productId);
- $('#productName').val(data.productName);
- $('#qty').val(data.qty);
- $('#rate').val(data.rate);
- //originalRate = data.purchaseRate;
- productType = data.purchasetype;
- $('#disPer').val('0');
- $('#grossValue').val('0');
- $('#disAmt').val('0');
- $('#Netamt').val('0');
- $('#ImportValue').val('0');
- $('#taxAmt').val('0');
- $('#NetTotal').val('0');
- setTimeout(function () { $('#qty').focus(); }, 500);
- }
- $('#loading').fadeOut();
- },
- error: function () {
- $('#loading').fadeOut();
- toastr.error('enter correct product code');
- }
- });
- }
- function ProductDetailsgetPerticlular(id) {
- $('#loading').fadeIn();
- $.ajax({
- url: '/PurchaseInvoice/ProductDetailsgetPerticlular?DbName=' + DbName + '&producttype=' + 1 + '&productcode=' + id,
- type: 'get',
- async: false,
- success: function (data) {
- if (data !== '') {
- PId = data.productId;
- ChargeGet_ByProductId(PId);
- $('#ProductId').val(data.productId);
- $('#productName').val(data.productName);
- if (data.ismultipleunit === 1) {
- ismultipleunit = 1;
- UnitViewAllByProductId(data.productId);
- $('#unitId').removeClass('disabled');
- $('#unitId').prop('disabled', false);
- } else {
- $('#unitId').addClass('disabled');
- $('#unitId').prop('disabled', true);
- }
- $('#unitId').val(data.unitId).select2();
- $('#goDownid').val(data.godownId).select2();
- $('#rackId').val(data.rackId).select2();
- if (data.taxId > 0) {
- $('#taxId').removeClass('disabled');
- $('#taxId').prop('disabled', false);
- $('#taxId').val(data.taxId).select2();
- }
- else {
- $('#taxId').addClass('disabled');
- $('#taxId').prop('disabled', true);
- $('#taxId').val(1).select2();
- }
- if (data.isallowBatch === 0) {
- $('#batchId').prop('disabled', true);
- $('#batchId').addClass('disabled');
- $('#ExAD').prop('disabled', true);
- $('#ExAD').addClass('disabled');
- $('#batchId').val('N/A');
- }
- if (data.isallowBatch === 1) {
- $('#batchId').prop('disabled', false);
- $('#batchId').removeClass('disabled');
- $('#ExAD').prop('disabled', false);
- $('#ExAD').removeClass('disabled');
- }
- //if (data.ratefixed === 0) {
- // $("#rate").removeClass('disabled');
- // $("#rate").prop('disabled', false);
- // $('#rate').val(data.purchaseRate);
- //}
- //else if (data.ratefixed === 1) {
- // $('#rate').addClass('disabled');
- // $('#rate').prop('disabled', true);
- // $('#rate').val(data.purchaseRate);
- //}
- originalRate = data.purchaseRate;
- $('#rate').val(data.purchaseRate);
- productType = data.purchasetype;
- setTimeout(function () { $('#qty').focus(); }, 500);
- }
- $('#loading').fadeOut();
- },
- error: function () {
- $('#loading').fadeOut();
- toastr.error('enter correct product code');
- }
- });
- }
- function getPR(url, name) {
- $.ajax({
- url: '/PurchaseInvoice/' + url + '?DbName=' + DbName + '&name=' + name,
- type: 'get',
- async: false,
- success: function (data) {
- var h = '', j = 0;
- $.each(data, function (k, item) {
- k++;
- h += '<tr data-id="' + item.productCode + '" data-name="' + item.productName + '" tabindex="' + j + '" >';
- h += '<td>' + k + '</td>';
- h += '<td>' + item.productName + '</td>';
- h += '</tr>';
- j++;
- pindex = j;
- });
- $('#modalPRBody').html(h);
- }
- });
- }
- function droptable() {
- $('tr[tabindex=0]').focus();
- document.onkeydown = checkKey;
- }
- function checkKey(e) {
- var event = window.event ? window.event : e;
- if (event.keyCode === 40) { //down
- var idx = $('tr:focus').attr('tabindex');
- idx++;
- if (idx > pindex) {
- idx = 0;
- }
- $('tr[tabindex=' + idx + ']').focus();
- }
- if (event.keyCode === 38) { //up
- idx = $('tr:focus').attr('tabindex');
- idx--;
- if (idx < 0) {
- idx = pindex;
- }
- $('tr[tabindex=' + idx + ']').focus();
- }
- if (event.keyCode === 32) {
- $('#prName').focus();
- event.preventDefault();
- return false;
- }
- }
- //reset this from
- function resetForm() {
- resetAdditional();
- reset();
- clearPI();
- $('#PurchaseAccountComboFill').val('0').select2();
- $('#crPeriod').val('0');
- $('#invoiceNo').val('');
- $('#voucherNo').val('');
- $('#InAD').val('');
- $('#InBS').val('');
- $('#InBS').val('');
- $("#VAD").datepicker({
- dateFormat: "mm/dd/yy",
- maxDate: todate,
- minDate: fromdate,
- showButtonPanel: true
- }).datepicker('setDate', 'today');
- CommomAdDateToBs("#VAD", "#VBS");
- $('#CashOrPartyComboFill').val('0').select2();
- //$('#purchaseMode').val(0).select2();
- $('#VoucherTypeSelectionComboFill').val('0').select2();
- //$('#orderNo').val('0').select2();
- $('#gbillDiscount').val('');
- $('#gtaxAble').val('');
- $('#gTaxAmt').val('');
- $('#PInarration').val('');
- $('#TransportationCompany').val('');
- $('#LRNo').val('');
- showTableAddtional();
- showTablePI();
- $('#grossAmtF').text(parseFloat(zero).toFixed(numberOfDecimal));
- $('#disAmtF').text(parseFloat(zero).toFixed(numberOfDecimal));
- $('#netAmtF').text(parseFloat(zero).toFixed(numberOfDecimal));
- $('#chargeAmtF').text(parseFloat(zero).toFixed(numberOfDecimal));
- $('#taxAmtF').text(parseFloat(zero).toFixed(numberOfDecimal));
- $('#netTotalF').text(parseFloat(zero).toFixed(numberOfDecimal));
- $('#TaxableAmt').text(parseFloat(zero).toFixed(numberOfDecimal));
- $('#NonTaxableAmt').text(parseFloat(zero).toFixed(numberOfDecimal));
- $('#CosttoParty').text(parseFloat(zero).toFixed(numberOfDecimal));
- $('#TotalAdditionalCost').text(parseFloat(zero).toFixed(numberOfDecimal));
- $('#gtotal').text(parseFloat(zero).toFixed(numberOfDecimal));
- $('#gCostToparty').text(parseFloat(zero).toFixed(numberOfDecimal));
- $('#ginvoiceTotal').text(parseFloat(zero).toFixed(numberOfDecimal));
- $('#billAmount').val(parseFloat(zero).toFixed(numberOfDecimal));
- transAmt = $('#billAmount').val();
- $('#totalAmount').val(parseFloat(zero).toFixed(numberOfDecimal));
- $('.tranSQPer_BillTax').val(parseFloat(zero).toFixed(numberOfDecimal));
- $('.tranSQAmt_BillTax').val(parseFloat(zero).toFixed(numberOfDecimal));
- $('.tranSQPer_ExciseDuty').val(parseFloat(zero).toFixed(numberOfDecimal));
- $('.tranSQAmt_ExciseDuty').val(parseFloat(zero).toFixed(numberOfDecimal));
- $('.tranSQPer_BillDiscount').val(parseFloat(zero).toFixed(numberOfDecimal));
- $('.tranSQAmt_BillDiscount').val(parseFloat(zero).toFixed(numberOfDecimal));
- ChargeGet_ByProductId(0);
- setTimeout(function () {
- $('.VoucherType').addClass('displayNone');
- $('#divOrderNo').addClass('displayNone');
- $('#divReceiptNo').addClass('displayNone');
- $('#PurchaseAccountComboFill').focus();
- }, 200);
- }
- //clearPI
- function clearPI() {
- for (var i = 0; i < localStorage.length + 1000; i++) {
- localStorage.removeItem('keyPI' + i);
- }
- for (var j = 0; j < localStorage.length + 1000; j++) {
- localStorage.removeItem('keyAdd' + j);
- }
- for (var k = 0; k < localStorage.length + 1000; k++) {
- localStorage.removeItem('keyTax' + k);
- }
- lastkeyTax = 0;
- isTax = 0;
- isImport = 0;
- lastkeyPI = 0;
- lastkeyAdd = 0;
- $('#qty').val(0);
- $('#disPer').val(0);
- $('#disAmt').val(0);
- $('#taxAmt').val(0);
- $('#rate').val(0);
- $('#productName').children('option:first-child').select2();
- //make them zero
- taxable = 0;
- nonTaxable = 0;
- grossAmt = 0;
- disAmt = 0;
- netAmt = 0;
- taxAmt = 0;
- netTotal = 0;
- CosttoParty = 0; gCosttoParty = 0;
- TotalAdditionalCost = 0;
- totalInvoice = 0;
- unitConversionId = 0;
- purchacid = 0; cashpartyid = 0; datas = []; Additionaldatas = []; purchaselist = []; addcpstList = [];
- purchaseDetailsId = 0; addcrlist = []; addDrlist = [];
- purchlpid = 0; cashbanklpid = 0; discountlpid = 0; partyBalanceId = 0; stockpostid = 0;
- addcostlpid = []; addcostid = 0; taxlpid = []; chargedatas = [];
- datas = []; Additionaldatas = []; taxdatas = [];
- chargedatas = []; chargeList = []; purchaselist = []; stockpostinglist = []; taxLists = []; addcpstList = [];
- purchacid = 0; cashpartyid = 0; addcrlist = []; addDrlist = []; ledgerpostingId = []; ledgers = [];
- }
- //show entry table
- function showTableAddtional() {
- var h = '';
- for (var i = 0; i < lastkeyAdd + 1; i++) {
- if (localStorage.getItem('keyAdd' + i)) {
- h += '<tr class="additionalBodydata" data-id="' + JSON.parse(localStorage.getItem('keyAdd' + i)).keyidAdd + '">';
- h += '<td>' + JSON.parse(localStorage.getItem('keyAdd' + i)).AddLedgerName + '</td>';
- h += '<td>' + JSON.parse(localStorage.getItem('keyAdd' + i)).AddCashpartyName + '</td>';
- h += '<td>' + JSON.parse(localStorage.getItem('keyAdd' + i)).AddtionalAmount + '</td>';
- h += '<td><button title="Delete" type="button" class="btn btn-danger" data-id="' + parseFloat(JSON.parse(localStorage.getItem('keyAdd' + i)).keyidAdd) + '"' +
- 'onclick="deleteAdd(' + parseFloat(JSON.parse(localStorage.getItem('keyAdd' + i)).keyidAdd) + ')"><i class="fa fa-trash-alt"></i></button></td>';
- h += '</tr>';
- }
- }
- $('#additionalBody').html(h);
- }
- //show entry table
- var id = 0;
- function showTablePI() {
- var h = '';
- grossAmt = 0;
- disAmt = 0;
- netAmt = 0;
- taxAmt = 0;
- netTotal = 0;
- chargeAmt = 0;
- j = 1;
- for (var i = 0; i < lastkeyPI + 1; i++) {
- if (localStorage.getItem('keyPI' + i)) {
- h += '<tr class="PIdata" data-id="' + JSON.parse(localStorage.getItem('keyPI' + i)).keyidPI + '">';
- h += '<td>' + j + '</td>';
- h += '<td>' + JSON.parse(localStorage.getItem('keyPI' + i)).ProductCode + '</td>';
- h += '<td>' + JSON.parse(localStorage.getItem('keyPI' + i)).ProductName + '</td>';
- h += '<td>' + JSON.parse(localStorage.getItem('keyPI' + i)).Qty + '</td>';
- h += '<td>' + JSON.parse(localStorage.getItem('keyPI' + i)).Unit + '</td>';
- h += '<td>' + JSON.parse(localStorage.getItem('keyPI' + i)).Godown + '</td>';
- h += '<td>' + JSON.parse(localStorage.getItem('keyPI' + i)).Rack + '</td>';
- h += '<td>' + JSON.parse(localStorage.getItem('keyPI' + i)).Batch + '</td>';
- h += '<td>' + JSON.parse(localStorage.getItem('keyPI' + i)).Rate + '</td>';
- h += '<td>' + JSON.parse(localStorage.getItem('keyPI' + i)).GrossValue + '</td>';
- grossAmt += parseFloat(JSON.parse(localStorage.getItem('keyPI' + i)).GrossValue);
- h += '<td>' + JSON.parse(localStorage.getItem('keyPI' + i)).DisPer + '</td>';
- h += '<td>' + JSON.parse(localStorage.getItem('keyPI' + i)).Discount + '</td>';
- if (JSON.parse(localStorage.getItem('keyPI' + i)).Discount > 0) {
- disAmt += parseFloat(JSON.parse(localStorage.getItem('keyPI' + i)).Discount);
- }
- h += '<td>' + JSON.parse(localStorage.getItem('keyPI' + i)).TotalAmt + '</td>';
- netAmt += parseFloat(JSON.parse(localStorage.getItem('keyPI' + i)).TotalAmt);
- h += '<td>' + JSON.parse(localStorage.getItem('keyPI' + i)).Charge + '</td>';
- h += '<td>' + JSON.parse(localStorage.getItem('keyPI' + i)).chargeAmt + '</td>';
- if (JSON.parse(localStorage.getItem('keyPI' + i)).chargeAmt > 0) {
- chargeAmt += parseFloat(JSON.parse(localStorage.getItem('keyPI' + i)).chargeAmt);
- }
- h += '<td>' + JSON.parse(localStorage.getItem('keyPI' + i)).TaxableVal + '</td>';
- h += '<td>' + JSON.parse(localStorage.getItem('keyPI' + i)).ImportValue + '</td>';
- h += '<td>' + JSON.parse(localStorage.getItem('keyPI' + i)).Tax + '</td>';
- h += '<td>' + JSON.parse(localStorage.getItem('keyPI' + i)).TaxAmt + '</td>';
- taxAmt += parseFloat(JSON.parse(localStorage.getItem('keyPI' + i)).TaxAmt);
- h += '<td>' + JSON.parse(localStorage.getItem('keyPI' + i)).Total + '</td>';
- netTotal += parseFloat(JSON.parse(localStorage.getItem('keyPI' + i)).Total);
- h += '<td><button title="Delete" type="button" class="btn btn-sm btn-danger" data-id="' + parseFloat(JSON.parse(localStorage.getItem('keyPI' + i)).keyidPI) + '"' +
- 'onclick="deletePI(' + parseFloat(JSON.parse(localStorage.getItem('keyPI' + i)).keyidPI) + ')"><i class="fa fa-trash-alt"></i></button></td>';
- h += '</tr>';
- j++;
- $('#grossAmtF').text(parseFloat(grossAmt).toFixed(numberOfDecimal));
- $('#disAmtF').text(parseFloat(disAmt).toFixed(numberOfDecimal));
- $('#netAmtF').text(parseFloat(netAmt).toFixed(numberOfDecimal));
- $('#taxAmtF').text(parseFloat(taxAmt).toFixed(numberOfDecimal));
- $('#chargeAmtF').text(parseFloat(chargeAmt).toFixed(numberOfDecimal));
- $('#netTotalF').text(parseFloat(netTotal).toFixed(numberOfDecimal));
- if (isTax === 1) {
- //$('#TaxableAmt').text(parseFloat(taxable).toFixed(numberOfDecimal));
- if (parseFloat(JSON.parse(localStorage.getItem('keyPI' + i)).TaxAmt) > 0) {
- $('#gtaxAble').val(parseFloat(taxable).toFixed(numberOfDecimal));
- }
- }
- if (taxAmt > 0) {
- $('#gTaxAmt').val(parseFloat(taxAmt).toFixed(numberOfDecimal));
- }
- else {
- $('#gTaxAmt').val(parseFloat(zero).toFixed(numberOfDecimal));
- }
- totalGrand = netTotal + parseFloat($('#TotalAdditionalCost').text());
- //$('#NonTaxableAmt').text(parseFloat(nonTaxable).toFixed(numberOfDecimal));
- $('#ginvoiceTotal').text(parseFloat(netTotal).toFixed(numberOfDecimal));
- $('#billAmount').val(parseFloat(netTotal).toFixed(numberOfDecimal));
- transAmt = $('#billAmount').val();
- $('#totalAmount').val(parseFloat(netTotal).toFixed(numberOfDecimal));
- $('#gtotal').text(parseFloat(netTotal).toFixed(numberOfDecimal));
- gCosttoParty = parseFloat(netTotal) + parseFloat($('#CosttoParty').text());
- $('#gCostToparty').text(parseFloat(gCosttoParty).toFixed(numberOfDecimal));
- $('#gtotal').text(parseFloat(totalGrand).toFixed(numberOfDecimal));
- }
- }
- $('#PIbody').html(h);
- for (var k = 0; k < localStorage.length + 100; k++) {
- localStorage.removeItem('keyTax' + k);
- }
- lastkeyTax = 0;
- gettaxdetails();
- for (var l = 0; l < localStorage.length + 100; l++) {
- localStorage.removeItem('keyCharge' + l);
- }
- lastkeyCharge = 0;
- getChargeDetails();
- purchaseDetailsId = 0; stockpostid = 0;
- }
- //
- function gettaxdetails() {
- var thisTaxid = 0;
- for (var k = 0; k < lastkeyPI + 1; k++) {
- if (localStorage.getItem('keyPI' + k)) {
- //add tax details
- if (JSON.parse(localStorage.getItem('keyPI' + k)).TaxAmt > 0) {
- for (var ij = 0; ij < lastkeyTax + 1; ij++) {
- if (localStorage.getItem('keyTax' + parseInt(lastkeyTax - ij))) {
- if (parseInt(JSON.parse(localStorage.getItem('keyPI' + id)).TaxID) === parseInt(JSON.parse(localStorage.getItem('keyTax' + parseInt(lastkeyTax - ij))).TaxID)) {
- thisTaxid = JSON.parse(localStorage.getItem('keyTax' + parseInt(lastkeyTax - ij))).keyidTax;
- var thistax = JSON.parse(localStorage.getItem('keyTax' + thisTaxid)).TaxID;
- var thisTaxAmt = JSON.parse(localStorage.getItem('keyTax' + thisTaxid)).TaxAmt;
- var uptaxAmt = parseFloat(thisTaxAmt) + parseFloat(JSON.parse(localStorage.getItem('keyPI' + k)).TaxAmt);
- localStorage.removeItem('keyTax' + thisTaxid);
- localStorage.setItem('keyTax' + thisTaxid, JSON.stringify({
- keyidTax: thisTaxid,
- TaxID: thistax,
- TaxAmt: parseFloat(uptaxAmt).toFixed(numberOfDecimal)
- }));
- lastkeyTax = thisTaxid;
- }
- }
- else {
- lastkeyTax = ij;
- localStorage.setItem('keyTax' + ij, JSON.stringify({
- keyidTax: ij,
- TaxID: JSON.parse(localStorage.getItem('keyPI' + ij)).TaxID,
- TaxAmt: JSON.parse(localStorage.getItem('keyPI' + ij)).TaxAmt
- }));
- }
- }
- }
- //var checktax = checkTaxnamePI();
- //if (checktax) {
- // var thistax = '', thisTaxAmt = 0;
- // //get tax details
- // thistax = JSON.parse(localStorage.getItem('keyPI' + k)).TaxID;
- // thisTaxAmt = JSON.parse(localStorage.getItem('keyPI' + k)).TaxAmt;
- // var taxlpid = JSON.parse(localStorage.getItem('keyPI' + k)).taxlpid;
- // //remove tax details
- // thisTaxAmt = parseFloat(JSON.parse(localStorage.getItem('keyPI' + parseInt(k - 1))).TaxAmt) + parseFloat(JSON.parse(localStorage.getItem('keyPI' + k)).TaxAmt);
- // localStorage.removeItem('keyTax' + parseInt(k - 1));
- // localStorage.setItem('keyTax' + parseInt(k - 1), JSON.stringify({
- // keyidTax: parseInt(k - 1),
- // TaxID: thistax,
- // taxlpid: taxlpid,
- // TaxAmt: thisTaxAmt
- // }));
- //}
- //else {
- // localStorage.setItem('keyTax' + k, JSON.stringify({
- // keyidTax: k,
- // TaxID: JSON.parse(localStorage.getItem('keyPI' + k)).TaxID,
- // taxlpid: JSON.parse(localStorage.getItem('keyPI' + k)).taxlpid,
- // TaxAmt: JSON.parse(localStorage.getItem('keyPI' + k)).TaxAmt
- // }));
- //}
- //if (ij > lastkeyTax) {
- // lastkeyTax = ij;
- //}
- }
- }
- }
- //
- function getChargeDetails() {
- let thisChargeid = 0;
- for (let k = 0; k < lastkeyPI + 1; k++) {
- if (localStorage.getItem('keyPI' + k)) {
- //add charge details
- if (JSON.parse(localStorage.getItem('keyPI' + k)).chargeAmt > 0) {
- for (var ij = 0; ij < lastkeyCharge + 1; ij++) {
- if (localStorage.getItem('keyCharge' + parseInt(lastkeyCharge - ij))) {
- if (parseInt(JSON.parse(localStorage.getItem('keyPI' + id)).ChargeID) === parseInt(JSON.parse(localStorage.getItem('keyCharge' + parseInt(lastkeyCharge - ij))).ChargeID)) {
- thisChargeid = JSON.parse(localStorage.getItem('keyCharge' + parseInt(lastkeyCharge - ij))).keyidTax;
- var thistax = JSON.parse(localStorage.getItem('keyCharge' + thisChargeid)).ChargeID;
- var thisChargeAmt = JSON.parse(localStorage.getItem('keyCharge' + thisChargeid)).ChargeAmt;
- var upChargeAmt = parseFloat(thisChargeAmt) + parseFloat(JSON.parse(localStorage.getItem('keyPI' + k)).chargeAmt);
- localStorage.removeItem('keyCharge' + thisChargeid);
- localStorage.setItem('keyCharge' + thisChargeid, JSON.stringify({
- keyidTax: thisChargeid,
- ChargeID: thistax,
- ChargeAmt: parseFloat(upChargeAmt).toFixed(numberOfDecimal)
- }));
- lastkeyCharge = thisChargeid;
- }
- }
- else {
- lastkeyCharge = ij;
- localStorage.setItem('keyCharge' + ij, JSON.stringify({
- keyidTax: ij,
- ChargeID: JSON.parse(localStorage.getItem('keyPI' + ij)).ChargeID,
- ChargeAmt: JSON.parse(localStorage.getItem('keyPI' + ij)).chargeAmt
- }));
- }
- }
- }
- }
- }
- }
- //reset
- function resetAdditional() {
- $('#AdditionalCostComboFill').val('0').select2();
- $('#cashPartyAdditional').val('0').select2();
- $('#additionalAmt').val('');
- }
- //reset
- function reset() {
- $('#barCode').val('');
- $('#productCode').val('');
- $('#productName').val('');
- $('#qty').val('0');
- $('#unitId').val('0').select2();
- $('#goDownid').val('0').select2();
- $('#rackId').val('0').select2();
- $('#batchId').val('');
- $('#rate').val('0');
- $('#disPer').val('0');
- $('#grossValue').val('0');
- $('#disAmt').val('0');
- $('#Netamt').val('0');
- $('#ImportValue').val('0');
- $('#taxId').val('1').select2();
- $('#chargeAmt').val('0');
- $('#TaxableVal').val('0');
- $('#taxAmt').val('0');
- $('#NetTotal').val('0');
- unitConversionId = 0;
- NetAmtWithImport = 0;
- purchaseDetailsId = 0; stockpostid = 0;
- productType = 0;
- purchaseDetailsId = 0; stockpostid = 0;
- }
- //check ledger name exist
- function checkAddtionalLedger() {
- count = localStorage.length;
- if (localStorage.length > 0) {
- for (var i = 0; i < localStorage.length; i++) {
- if (localStorage.getItem('keyAdd' + i)) {
- if (parseInt(JSON.parse(localStorage.getItem('keyAdd' + i)).AdditionalLedger) === parseInt($('#AdditionalCostComboFill').val())) {
- count = count;
- }
- else {
- count -= 1;
- }
- }
- else {
- count -= 1;
- }
- }
- }
- if (count === 0) {
- return false;
- }
- else {
- return true;
- }
- }
- //check product name exist
- function checkProductnamePI() {
- count = localStorage.length;
- if (localStorage.length > 0) {
- for (var i = 0; i < localStorage.length; i++) {
- if (localStorage.getItem('keyPI' + i)) {
- if (JSON.parse(localStorage.getItem('keyPI' + i)).ProductCode === $('#productCode').val()) {
- count = count;
- }
- else {
- count -= 1;
- }
- }
- else {
- count -= 1;
- }
- }
- }
- if (count === 0) {
- return false;
- }
- else {
- return true;
- }
- }
- //check product details id exist
- function getcheckpurchid(purchaseDetailsId) {
- count = localStorage.length;
- if (localStorage.length > 0) {
- for (var i = 0; i < localStorage.length; i++) {
- if (localStorage.getItem('keyPI' + i)) {
- if (JSON.parse(localStorage.getItem('keyPI' + i)).purchaseDetailsId === purchaseDetailsId) {
- count = count;
- }
- else {
- count -= 1;
- }
- }
- else {
- count -= 1;
- }
- }
- }
- if (count === 0) {
- return false;
- }
- else {
- return true;
- }
- }
- //check addcostid exist
- function getcheckaddcostid(additionalCostId) {
- count = localStorage.length;
- if (localStorage.length > 0) {
- for (var i = 0; i < localStorage.length; i++) {
- if (localStorage.getItem('keyAdd' + i)) {
- if (parseInt(JSON.parse(localStorage.getItem('keyAdd' + i)).addcostid) === parseInt(additionalCostId)) {
- count = count;
- }
- else {
- count -= 1;
- }
- }
- else {
- count -= 1;
- }
- }
- }
- if (count === 0) {
- return false;
- }
- else {
- return true;
- }
- }
- //check tax id exist
- function checkTaxnamePI() {
- count = localStorage.length;
- if (localStorage.length > 0) {
- for (var i = 0; i < localStorage.length; i++) {
- if (localStorage.getItem('keyTax' + i)) {
- for (var h = 0; h < taxLists.length; h++) {
- if (JSON.parse(localStorage.getItem('keyTax' + i)).TaxID === taxLists[h]) {
- count = count;
- }
- else {
- count -= 1;
- }
- }
- }
- else {
- count -= 1;
- }
- }
- }
- if (count === 0) {
- return false;
- }
- else {
- return true;
- }
- }
- //calculate tax
- function calTax() {
- var taxper = 0, taxamt = 0;
- if ($('#taxId').val() > 0) {
- taxper = getRate($('#taxId').val());
- if (taxper > 0) {
- taxamt = (taxper / 100) * $('#TaxableVal').val();
- }
- }
- $('#taxAmt').val(parseFloat(taxamt).toFixed(numberOfDecimal));
- //$('#NetTotal').val((parseFloat($('#Netamt').val()) + parseFloat(taxamt)).toFixed(numberOfDecimal));
- $('#NetTotal').val((parseFloat(NetAmtWithImport) + parseFloat($('#TaxableVal').val()) + parseFloat(taxamt)).toFixed(numberOfDecimal));
- }
- //calculate tax
- function calCharge() {
- var taxper = 0, taxamt = 0;
- if ($('#chargeId').val() > 1) {
- taxper = getRate($('#chargeId').val());
- if (taxper > 0) {
- taxamt = (taxper / 100) * $('#Netamt').val();
- }
- }
- $('#chargeAmt').val(parseFloat(taxamt).toFixed(numberOfDecimal));
- //$('#NetTotal').val((parseFloat($('#Netamt').val()) + parseFloat(taxamt)).toFixed(numberOfDecimal));
- $('#TaxableVal').val((parseFloat($('#Netamt').val()) + parseFloat(taxamt)).toFixed(numberOfDecimal));
- }
- //get rate for taxdp
- function getRate(taxId) {
- var r = 0;
- $('#PInarration').addClass('active');
- if (taxId > 0) {
- $.ajax({
- url: '/PurchaseInvoice/TaxView?DbName=' + DbName + '&taxId=' + taxId,
- type: 'get',
- async: false,
- success: function (data) {
- r = data.rate;
- },
- error: function () {
- toastr.error('system error');
- }
- });
- }
- return r;
- }
- //load VoucherTypeSelectionComboFill
- function VoucherTypeSelectionComboFill(name) {
- $.ajax({
- url: '/PurchaseInvoice/VoucherTypeSelectionComboFill?DbName=' + DbName + '&name=' + name,
- type: 'get',
- async: false,
- success: function (data) {
- $('#VoucherTypeSelectionComboFill').empty();
- //$('#VoucherTypeSelectionComboFill').append('<option value="0"> Choose one</option>');
- $('#VoucherTypeSelectionComboFill').append('<option value="' + data.voucherTypeId + '"> ' + data.voucherTypeName + '</option>');
- },
- error: function () {
- toastr.error('system error');
- }
- });
- }
- //load VoucherTypeSelectionComboFill
- function VoucherType() {
- $.ajax({
- url: '/VoucherTypeTax/VoucherTypeDP?DbName=' + DbName,
- type: 'get',
- async: false,
- success: function (data) {
- $('#VoucherTypeSelectionComboFill').empty();
- $('#VoucherTypeSelectionComboFill').append('<option value="0"> NA</option>');
- $.each(data, function (i, item) {
- $('#VoucherTypeSelectionComboFill').append('<option value="' + item.voucherTypeId + '"> ' + item.voucherTypeName + '</option>');
- });
- },
- error: function () {
- toastr.error('system error');
- }
- });
- }
- function GetMaterialReceiptNoForPurchaseInvoice() {
- $.ajax({
- url: '/MaterialIn/GetMaterialReceiptNoForPurchaseInvoice?DbName=' + DbName + '&ledgerId=' + ledgerId,
- type: 'get',
- async: false,
- success: function (data) {
- $('#ReceiptNo').empty();
- $('#ReceiptNo').append('<option value="0"> Choose one</option>');
- $.each(data, function (i, item) {
- $('#ReceiptNo').append('<option value="' + item.materialReceiptMasterId + '"> ' + item.invoiceNo + '</option>');
- });
- },
- error: function () {
- toastr.error('system error');
- }
- });
- }
- function GetPurchaseOrderNoForPurchaseInvoice() {
- $.ajax({
- url: '/PurchaseOrder/GetPurchaseOrderNoForPurchaseInvoice?DbName=' + DbName + '&ledgerId=' + ledgerId,
- type: 'get',
- async: false,
- success: function (data) {
- $('#orderNo').empty();
- $('#orderNo').append('<option value="0"> Choose one</option>');
- $.each(data, function (i, item) {
- $('#orderNo').append('<option value="' + item.purchaseOrderMasterId + '"> ' + item.orderNo + '</option>');
- });
- },
- error: function () {
- toastr.error('system error');
- }
- });
- }
- //save PI
- function SavePI() {
- $('#loading').fadeIn();
- if ($('#PurchaseAccountComboFill').val() === '0') {
- toastr.info('Please Select Purchase Account Ledger');
- $('#loading').fadeOut();
- $('#PurchaseAccountComboFill').focus();
- }
- else {
- if ($('#invoiceNo').val() === '') {
- toastr.info('Please Enter Invoice Number');
- $('#loading').fadeOut();
- $('#invoiceNo').focus();
- }
- else {
- if ($('#InAD').val() === '') {
- toastr.info('Please Select Invoice Date');
- $('#loading').fadeOut();
- $('#InAD').focus();
- }
- else {
- if ($('#CashOrPartyComboFill').val() === '0') {
- toastr.info('Please Select Party Ledger');
- $('#loading').fadeOut();
- $('#CashOrPartyComboFill').focus();
- }
- else {
- if (accountgpId === 27) {
- if (negativeCash === 0) {
- if ($('#ginvoiceTotal').text() > CashAmount) {
- toastr.error('Invoice Total is greater than Cash Amount');
- }
- else {
- $('#btnSaveYes').addClass('savePI');
- $('#save').modal('show');
- }
- }
- else {
- $('#btnSaveYes').addClass('savePI');
- $('#save').modal('show');
- }
- }
- else {
- $('#btnSaveYes').addClass('savePI');
- $('#save').modal('show');
- }
- }
- }
- }
- }
- }
- //save after confirm
- //Kritika Changed this
- async function ConfirmSave() {
- if ($('.btnyes').hasClass('savePI')) {
- $('#loading').fadeIn();
- $('#btnNumb').focus();
- let di = 0, adi = 0, taxi = 0, chargi = 0;
- for (var i = 0; i < lastkeyPI + 1; i++) {
- if (localStorage.getItem('keyPI' + i)) {
- datas[di] = JSON.stringify({
- ProductId: JSON.parse(localStorage.getItem('keyPI' + i)).ProductId,
- productType: JSON.parse(localStorage.getItem('keyPI' + i)).productType,
- ProductCode: JSON.parse(localStorage.getItem('keyPI' + i)).ProductCode,
- ProductName: JSON.parse(localStorage.getItem('keyPI' + i)).ProductName,
- Qty: JSON.parse(localStorage.getItem('keyPI' + i)).Qty,
- Unit: JSON.parse(localStorage.getItem('keyPI' + i)).Unit,
- UnitID: JSON.parse(localStorage.getItem('keyPI' + i)).UnitID,
- Godown: JSON.parse(localStorage.getItem('keyPI' + i)).Godown,
- GodownID: JSON.parse(localStorage.getItem('keyPI' + i)).GodownID,
- Rack: JSON.parse(localStorage.getItem('keyPI' + i)).Rack,
- RackID: JSON.parse(localStorage.getItem('keyPI' + i)).RackID,
- unitConversionId: JSON.parse(localStorage.getItem('keyPI' + i)).unitConversionId,
- Batch: JSON.parse(localStorage.getItem('keyPI' + i)).Batch,
- Rate: JSON.parse(localStorage.getItem('keyPI' + i)).Rate,
- DisPer: JSON.parse(localStorage.getItem('keyPI' + i)).DisPer,
- GrossValue: JSON.parse(localStorage.getItem('keyPI' + i)).GrossValue,
- Discount: JSON.parse(localStorage.getItem('keyPI' + i)).Discount,
- TotalAmt: JSON.parse(localStorage.getItem('keyPI' + i)).TotalAmt,
- ChargeID: JSON.parse(localStorage.getItem('keyPI' + i)).ChargeID,
- chargeAmt: JSON.parse(localStorage.getItem('keyPI' + i)).chargeAmt,
- TaxableVal: JSON.parse(localStorage.getItem('keyPI' + i)).TaxableVal,
- ImportValue: JSON.parse(localStorage.getItem('keyPI' + i)).ImportValue,
- Tax: JSON.parse(localStorage.getItem('keyPI' + i)).Tax,
- TaxID: JSON.parse(localStorage.getItem('keyPI' + i)).TaxID,
- TaxAmt: JSON.parse(localStorage.getItem('keyPI' + i)).TaxAmt,
- Total: JSON.parse(localStorage.getItem('keyPI' + i)).Total,
- expiryDate: JSON.parse(localStorage.getItem('keyPI' + i)).expiryDate,
- purchaseOrderMasterId: JSON.parse(localStorage.getItem('keyPI' + i)).purchaseOrderMasterId,
- materialReceiptMasterId: JSON.parse(localStorage.getItem('keyPI' + i)).materialReceiptMasterId,
- //action: JSON.parse(localStorage.getItem('keyPI' + i)).action
- });
- di++;
- }
- }
- for (var j = 0; j < lastkeyAdd + 1; j++) {
- if (localStorage.getItem('keyAdd' + j)) {
- Additionaldatas[adi] = JSON.stringify({
- AddCashpartyName: JSON.parse(localStorage.getItem('keyAdd' + j)).AddCashpartyName,
- AddLedgerName: JSON.parse(localStorage.getItem('keyAdd' + j)).AddLedgerName,
- AdditionalCashparty: JSON.parse(localStorage.getItem('keyAdd' + j)).AdditionalCashparty,
- AdditionalLedger: JSON.parse(localStorage.getItem('keyAdd' + j)).AdditionalLedger,
- AddtionalAmount: JSON.parse(localStorage.getItem('keyAdd' + j)).AddtionalAmount
- });
- adi++;
- }
- }
- for (var k = 0; k < lastkeyTax + 1; k++) {
- if (localStorage.getItem('keyTax' + k)) {
- taxdatas[taxi] = JSON.stringify({
- TaxID: JSON.parse(localStorage.getItem('keyTax' + k)).TaxID,
- TaxAmt: JSON.parse(localStorage.getItem('keyTax' + k)).TaxAmt
- });
- taxi++;
- }
- }
- for (var l = 0; l < lastkeyCharge + 1; l++) {
- if (localStorage.getItem('keyCharge' + l)) {
- if (parseInt(JSON.parse(localStorage.getItem('keyCharge' + l)).ChargeAmt) > 0) {
- chargedatas[chargi] = JSON.stringify({
- ChargeID: JSON.parse(localStorage.getItem('keyCharge' + l)).ChargeID,
- ChargeAmt: JSON.parse(localStorage.getItem('keyCharge' + l)).ChargeAmt
- });
- chargi++;
- }
- }
- }
- checkMOD = checkMaterialOrderCmp();
- if (checkMOD) {
- masterAction = 'Accepted';
- }
- else {
- masterAction = 'Partial';
- }
- checkPOD = checkPurchaseOrderCmp();
- if (checkPOD) {
- masterAction = 'Accepted';
- }
- else {
- masterAction = 'Partial';
- }
- var totalDiscount = parseFloat(billDiscount) + parseFloat($('#disAmtF').text());
- var dataObj = {
- DbName: DbName,
- date: $('#VAD').val(),
- purchaseOrderMasterId: $('#orderNo').val(),
- materialReceiptMasterId: $('#ReceiptNo').val(),
- ledgerId: $('#CashOrPartyComboFill').val(),
- vendorInvoiceNo: $('#invoiceNo').val().trim(),
- vendorInvoiceDate: $('#InAD').val(),
- creditPeriod: $('#crPeriod').val().trim(),
- narration: $('#PInarration').val().trim(),
- purchaseAccount: $('#PurchaseAccountComboFill').val(),
- additionalCost: $('#TotalAdditionalCost').text(),
- totalTax: $('#taxAmtF').text(),//total tax
- costtoParty: $('#gCostToparty').text(),
- grandTotal: $('#gtotal').text(),
- invoiceTotal: $('#ginvoiceTotal').text(),// party amount
- lrNo: $('#LRNo').val().trim(),
- orderType: $('#purchaseMode').val(),
- transportationCompany: $('#TransportationCompany').val().trim(),
- ProductNetTotal: $('#netTotalF').text(),
- //grossValue: $('#netTotalF').text(),//Kritika Changed this
- grossValue: $('#grossAmtF').text(),
- totalDiscount: totalDiscount, //total discount
- list: datas,
- addList: Additionaldatas,
- taxlist: taxdatas,
- chargeList: chargedatas,
- masterAction: masterAction,
- BillTaxPercentage: BillTaxPercentage,
- BillTaxAmount: BillTaxAmount,
- BillExciseDutyPercentage: BillExciseDutyPercentage,
- BillExciseDutyAmount: BillExciseDutyAmount,
- BillDiscountPercentage: BillDiscountPercentage,
- billDiscount: billDiscount//$('#gbillDiscount').val()
- };
- if ($(".PrintBill").is(":checked")) {
- PrintBill = 1;
- }
- else {
- PrintBill = 0;
- }
- await $.ajax({
- type: 'post',
- dataType: 'json',
- async: false,
- data: dataObj,
- url: '/PurchaseInvoice/SavePI',
- success: function (data) {
- if (data.data === '1') {
- toastr.success('Added Successfully');
- resetForm();
- $(".btnprintyes").attr('data-invoiceno', data.invoiceNo);
- if (PrintBill === 1) {
- $(".btnprintyes").trigger('click');
- }
- $('#loading').fadeOut();
- }
- else if (data.data === '0') {
- toastr.error('Not added' + data);
- $('#loading').fadeOut();
- setTimeout(function () {
- $('#PurchaseAccountComboFill').focus();
- }, 100);
- }
- else {
- toastr.error(data.data);
- $('#loading').fadeOut();
- setTimeout(function () {
- $('#PurchaseAccountComboFill').focus();
- }, 100);
- }
- $('#save').modal('hide');
- },
- error: function (ex) {
- toastr.error('Unable to add/record data: ' + ex.statusText);
- $('#loading').fadeOut();
- $('#save').modal('hide');
- setTimeout(function () {
- $('#PurchaseAccountComboFill').focus();
- }, 100);
- }
- });
- $('.btnyes').removeClass('savePI');
- }
- }
- //delete functions
- function DeleteAllpi() {
- $('#delete-modal').modal('show');
- $('#btnDeleteAll').addClass('pi');
- }
- function ConfirmDeleteAll() {
- if ($('.yes').hasClass('pi')) {
- for (var i = 0; i < localStorage.length + 2; i++) {
- if (localStorage.getItem('keyPI' + i)) {
- grossAmt -= parseFloat(JSON.parse(localStorage.getItem('keyPI' + i)).GrossValue);
- if (JSON.parse(localStorage.getItem('keyPI' + i)).Discount > 0) {
- disAmt -= parseFloat(JSON.parse(localStorage.getItem('keyPI' + i)).Discount);
- }
- netAmt -= parseFloat(JSON.parse(localStorage.getItem('keyPI' + i)).NetValue);
- taxAmt -= parseFloat(JSON.parse(localStorage.getItem('keyPI' + i)).TaxAmt);
- netTotal -= parseFloat(JSON.parse(localStorage.getItem('keyPI' + i)).Total);
- if (parseFloat(JSON.parse(localStorage.getItem('keyPI' + i)).TaxAmt) === 0) {
- taxable -= parseFloat((JSON.parse(localStorage.getItem('keyPI' + i)).NetValue));
- if (isTax === 1) {
- $('#TaxableAmt').text(parseFloat(taxable).toFixed(numberOfDecimal));
- $('#gtaxAble').val(parseFloat(taxable).toFixed(numberOfDecimal));
- }
- }
- if (parseFloat(JSON.parse(localStorage.getItem('keyPI' + i)).TaxAmt) > 0) {
- nonTaxable -= parseFloat((JSON.parse(localStorage.getItem('keyPI' + i)).NetValue));
- $('#NonTaxableAmt').text(parseFloat(nonTaxable).toFixed(numberOfDecimal));
- taxAmt -= parseFloat(JSON.parse(localStorage.getItem('keyPI' + i)).TaxAmt);
- $('#taxAmtF').text(parseFloat(taxAmt).toFixed(numberOfDecimal));
- $('#gTaxAmt').val(parseFloat(taxAmt).toFixed(numberOfDecimal));
- }
- $('#grossAmtF').text(parseFloat(grossAmt).toFixed(numberOfDecimal));
- $('#disAmtF').text(parseFloat(disAmt).toFixed(numberOfDecimal));
- $('#netAmtF').text(parseFloat(netAmt).toFixed(numberOfDecimal));
- $('#netTotalF').text(parseFloat(netTotal).toFixed(numberOfDecimal));
- totalGrand = netTotal + parseFloat($('#TotalAdditionalCost').text());
- //$('#NonTaxableAmt').text(parseFloat(nonTaxable).toFixed(numberOfDecimal));
- $('#ginvoiceTotal').text(parseFloat(netTotal).toFixed(numberOfDecimal));
- $('#billAmount').val(parseFloat(netTotal).toFixed(numberOfDecimal));
- transAmt = $('#billAmount').val();
- $('#totalAmount').val(parseFloat(netTotal).toFixed(numberOfDecimal));
- gCosttoParty = parseFloat(netTotal) + parseFloat($('#CosttoParty').text());
- $('#gCostToparty').text(parseFloat(gCosttoParty).toFixed(numberOfDecimal));
- $('#gtotal').text(parseFloat(totalGrand).toFixed(numberOfDecimal));
- localStorage.removeItem('keyPI' + i);
- }
- }
- lastkeyPI = 0;
- toastr.success('All Record Deleted!');
- showTablePI();
- $('#productCode').focus();
- //caldiscount();
- }
- else if ($('.yes').hasClass('additional')) {
- for (var j = 0; j < localStorage.length + 2; j++) {
- if (localStorage.getItem('keyAdd' + j)) {
- TotalAdditionalCost -= parseFloat(JSON.parse(localStorage.getItem('keyAdd' + j)).AddtionalAmount);
- gCosttoParty -= parseFloat(JSON.parse(localStorage.getItem('keyAdd' + j)).AddtionalAmount);
- if (parseInt($('#CashOrPartyComboFill').val()) === JSON.parse(localStorage.getItem('keyAdd' + j)).AdditionalCashparty ||
- $('#CashOrPartyComboFill').val() === JSON.parse(localStorage.getItem('keyAdd' + j)).AdditionalCashparty) {
- CosttoParty -= parseFloat(JSON.parse(localStorage.getItem('keyAdd' + j)).AddtionalAmount);
- }
- if (parseFloat(JSON.parse(localStorage.getItem('keyAdd' + j)).isAddTax) === 1) {
- taxable -= parseFloat(JSON.parse(localStorage.getItem('keyAdd' + j)).AddtionalAmount);
- }
- else {
- nonTaxable -= parseFloat(JSON.parse(localStorage.getItem('keyAdd' + j)).AddtionalAmount);
- }
- var discount = 0;
- if ($('#gbillDiscount').val() > 0) {
- discount = $('#gbillDiscount').val();
- }
- $('#TotalAdditionalCost').text(parseFloat(TotalAdditionalCost).toFixed(numberOfDecimal));
- //totalGrand = parseFloat(nonTaxable) + parseFloat(taxable) + parseFloat($('#gTaxAmt').val());
- totalGrand = parseFloat($('#TotalAdditionalCost').text()) + parseFloat($('#ginvoiceTotal').text()) + parseFloat(discount);
- totalInvoice = parseFloat($('#netTotalF').text()) - parseFloat($('#gbillDiscount').val());
- $('#AdditionalCostComboFill').focus(); $('#NonTaxableAmt').text(parseFloat(nonTaxable).toFixed(numberOfDecimal));
- $('#gtotal').text(parseFloat(totalGrand).toFixed(numberOfDecimal));
- $('#ginvoiceTotal').text(parseFloat(totalInvoice).toFixed(numberOfDecimal));
- $('#billAmount').val(parseFloat(totalInvoice).toFixed(numberOfDecimal));
- transAmt = $('#billAmount').val();
- $('#totalAmount').val(parseFloat(totalInvoice).toFixed(numberOfDecimal));
- $('#CosttoParty').text(parseFloat(CosttoParty).toFixed(numberOfDecimal));
- gCosttoParty = parseFloat(CosttoParty) + parseFloat($('#ginvoiceTotal').text());
- $('#gCostToparty').text(parseFloat(gCosttoParty).toFixed(numberOfDecimal));
- localStorage.removeItem('keyAdd' + j);
- }
- }
- lastkeyAdd = 0;
- toastr.success('All Record Deleted!');
- showTableAddtional();
- $('#AdditionalCostComboFill').focus();
- }
- else if ($('.yes').hasClass('singleAdd')) {
- TotalAdditionalCost -= parseFloat(JSON.parse(localStorage.getItem('keyAdd' + deleteid)).AddtionalAmount);
- gCosttoParty -= parseFloat(JSON.parse(localStorage.getItem('keyAdd' + deleteid)).AddtionalAmount);
- if (parseInt($('#CashOrPartyComboFill').val()) === JSON.parse(localStorage.getItem('keyAdd' + deleteid)).AdditionalCashparty ||
- $('#CashOrPartyComboFill').val() === JSON.parse(localStorage.getItem('keyAdd' + deleteid)).AdditionalCashparty) {
- CosttoParty -= parseFloat(JSON.parse(localStorage.getItem('keyAdd' + deleteid)).AddtionalAmount);
- }
- if (parseFloat(JSON.parse(localStorage.getItem('keyAdd' + deleteid)).isAddTax) === 1) {
- taxable -= parseFloat(JSON.parse(localStorage.getItem('keyAdd' + deleteid)).AddtionalAmount);
- }
- else {
- nonTaxable -= parseFloat(JSON.parse(localStorage.getItem('keyAdd' + deleteid)).AddtionalAmount);
- }
- var gdiscount = 0;
- if ($('#gbillDiscount').val() > 0) {
- gdiscount = $('#gbillDiscount').val();
- }
- $('#TotalAdditionalCost').text(parseFloat(TotalAdditionalCost).toFixed(numberOfDecimal));
- //totalGrand = parseFloat(nonTaxable) + parseFloat(taxable) + parseFloat($('#gTaxAmt').val());
- totalGrand = parseFloat($('#TotalAdditionalCost').text()) + parseFloat($('#ginvoiceTotal').text()) + parseFloat(gdiscount);
- totalInvoice = parseFloat($('#netTotalF').text()) - parseFloat($('#gbillDiscount').val());
- toastr.success('Record Deleted!');
- $('#AdditionalCostComboFill').focus(); $('#NonTaxableAmt').text(parseFloat(nonTaxable).toFixed(numberOfDecimal));
- $('#gtotal').text(parseFloat(totalGrand).toFixed(numberOfDecimal));
- $('#ginvoiceTotal').text(parseFloat(totalInvoice).toFixed(numberOfDecimal));
- $('#billAmount').val(parseFloat(totalInvoice).toFixed(numberOfDecimal));
- transAmt = $('#billAmount').val();
- $('#totalAmount').val(parseFloat(totalInvoice).toFixed(numberOfDecimal));
- $('#CosttoParty').text(parseFloat(CosttoParty).toFixed(numberOfDecimal));
- gCosttoParty = parseFloat(CosttoParty) + parseFloat($('#ginvoiceTotal').text());
- $('#gCostToparty').text(parseFloat(gCosttoParty).toFixed(numberOfDecimal));
- localStorage.removeItem('keyAdd' + deleteid);
- showTableAddtional();
- //caldiscount();
- }
- else if ($('.yes').hasClass('singlePi')) {
- grossAmt -= parseFloat(JSON.parse(localStorage.getItem('keyPI' + deleteid)).GrossValue);
- if (JSON.parse(localStorage.getItem('keyPI' + deleteid)).Discount > 0) {
- disAmt -= parseFloat(JSON.parse(localStorage.getItem('keyPI' + deleteid)).Discount);
- }
- netAmt -= parseFloat(JSON.parse(localStorage.getItem('keyPI' + deleteid)).NetValue);
- taxAmt -= parseFloat(JSON.parse(localStorage.getItem('keyPI' + deleteid)).TaxAmt);
- netTotal -= parseFloat(JSON.parse(localStorage.getItem('keyPI' + deleteid)).Total);
- if (parseFloat(JSON.parse(localStorage.getItem('keyPI' + deleteid)).TaxAmt) === 0) {
- taxable -= parseFloat((JSON.parse(localStorage.getItem('keyPI' + deleteid)).NetValue));
- if (isTax === 1) {
- $('#TaxableAmt').text(parseFloat(taxable).toFixed(numberOfDecimal));
- $('#gtaxAble').val(parseFloat(taxable).toFixed(numberOfDecimal));
- }
- }
- if (parseFloat(JSON.parse(localStorage.getItem('keyPI' + deleteid)).TaxAmt) > 0) {
- nonTaxable -= parseFloat((JSON.parse(localStorage.getItem('keyPI' + deleteid)).NetValue));
- $('#NonTaxableAmt').text(parseFloat(nonTaxable).toFixed(numberOfDecimal));
- taxAmt -= parseFloat(JSON.parse(localStorage.getItem('keyPI' + deleteid)).TaxAmt);
- $('#taxAmtF').text(parseFloat(taxAmt).toFixed(numberOfDecimal));
- $('#gTaxAmt').val(parseFloat(taxAmt).toFixed(numberOfDecimal));
- }
- $('#grossAmtF').text(parseFloat(grossAmt).toFixed(numberOfDecimal));
- $('#disAmtF').text(parseFloat(disAmt).toFixed(numberOfDecimal));
- $('#netAmtF').text(parseFloat(netAmt).toFixed(numberOfDecimal));
- $('#netTotalF').text(parseFloat(netTotal).toFixed(numberOfDecimal));
- totalGrand = netTotal + parseFloat($('#TotalAdditionalCost').text());
- //$('#NonTaxableAmt').text(parseFloat(nonTaxable).toFixed(numberOfDecimal));
- $('#ginvoiceTotal').text(parseFloat(netTotal).toFixed(numberOfDecimal));
- $('#billAmount').val(parseFloat(netTotal).toFixed(numberOfDecimal));
- transAmt = $('#billAmount').val();
- $('#totalAmount').val(parseFloat(netTotal).toFixed(numberOfDecimal));
- gCosttoParty = parseFloat(netTotal) + parseFloat($('#CosttoParty').text());
- $('#gCostToparty').text(parseFloat(gCosttoParty).toFixed(numberOfDecimal));
- $('#gtotal').text(parseFloat(totalGrand).toFixed(numberOfDecimal));
- localStorage.removeItem('keyPI' + deleteid);
- toastr.success('Record Deleted!');
- showTablePI();
- $('#productCode').focus();
- }
- }
- function DeleteAlladd() {
- $('#delete-modal').modal('show');
- $('#btnDeleteAll').addClass('additional');
- }
- function deleteAdd(id) {
- deleteid = id;
- $('#delete-modal').modal('show');
- $('#btnDeleteAll').addClass('singleAdd');
- }
- function deletePI(id) {
- deleteid = id;
- $('#delete-modal').modal('show');
- $('#btnDeleteAll').addClass('singlePi');
- }
- function getMaterialMaster(id) {
- taxAmt = 0;
- CosttoParty = 0; gCosttoParty = 0;
- TotalAdditionalCost = 0;
- nonTaxable = 0;
- totalInvoice = 0; totalGrand = 0; purchacid = 0; cashpartyid = 0;
- materialReceiptMasterId = 0;
- $.ajax({
- url: '/MaterialIn/MaterialReceiptMasterViewByReceiptMasterId?DbName=' + DbName + '&MaterialReceiptMasterId=' + id,
- type: 'get',
- async: false,
- success: function (data) {
- $('#PInarration').val(data.narration);
- $('#TransportationCompany').val(data.transportationCompany);
- $('#LRNo').val(data.lrNo);
- $('#ginvoiceTotal').text(data.totalAmount);
- $('#billAmount').val(data.totalAmount);
- transAmt = $('#billAmount').val();
- $('#totalAmount').val(data.totalAmount);
- materialReceiptMasterId = data.materialReceiptMasterId;
- taxAmt = data.totalTax;
- totalInvoice = data.totalAmount; totalGrand = data.grandTotal;
- gCosttoParty += data.totalAmount;
- $('#gtotal').text(parseFloat(totalGrand).toFixed(numberOfDecimal));
- $('#ginvoiceTotal').text(parseFloat(totalInvoice).toFixed(numberOfDecimal));
- $('#billAmount').val(parseFloat(totalInvoice).toFixed(numberOfDecimal));
- transAmt = $('#billAmount').val();
- $('#totalAmount').val(parseFloat(totalInvoice).toFixed(numberOfDecimal));
- getMaterialDetails(data.materialReceiptMasterId);
- },
- error: function () {
- $('#loading').fadeOut();
- toastr.error('system error: Purchase invoice get by voucher number');
- }
- });
- LedgerpostingGetDetailsList(id);
- }
- function getPurchaseOrderMaster(id) {
- taxAmt = 0;
- CosttoParty = 0; gCosttoParty = 0;
- TotalAdditionalCost = 0;
- nonTaxable = 0;
- totalInvoice = 0; totalGrand = 0; purchacid = 0; cashpartyid = 0;
- purchaseOrderMasterId = 0;
- $.ajax({
- url: '/PurchaseOrder/PurchaseOrderMasterViewByOrderMasterId?DbName=' + DbName + '&purchaseOrderMasterId=' + id,
- type: 'get',
- async: false,
- success: function (data) {
- $('#PInarration').val(data.narration);
- $('#ginvoiceTotal').text(data.totalAmount);
- $('#billAmount').val(data.totalAmount);
- transAmt = $('#billAmount').val();
- $('#totalAmount').val(data.totalAmount);
- purchaseOrderMasterId = data.purchaseOrderMasterId;
- taxAmt = data.totalTax;
- totalInvoice = data.totalAmount; totalGrand = data.grandTotal;
- gCosttoParty += data.totalAmount;
- $('#gtotal').text(parseFloat(totalGrand).toFixed(numberOfDecimal));
- $('#ginvoiceTotal').text(parseFloat(totalInvoice).toFixed(numberOfDecimal));
- $('#billAmount').val(parseFloat(totalInvoice).toFixed(numberOfDecimal));
- transAmt = $('#billAmount').val();
- $('#totalAmount').val(parseFloat(totalInvoice).toFixed(numberOfDecimal));
- getPurchaseOrderDetails(purchaseOrderMasterId);
- },
- error: function () {
- $('#loading').fadeOut();
- toastr.error('system error: Purchase invoice get by voucher number');
- }
- });
- LedgerpostingGetDetailsList(id);
- }
- //purchase invoice update
- function getMaster(id) {
- taxAmt = 0;
- CosttoParty = 0; gCosttoParty = 0;
- TotalAdditionalCost = 0;
- nonTaxable = 0;
- totalInvoice = 0; totalGrand = 0; purchacid = 0; cashpartyid = 0;
- LedgerpostingGetDetailsList(id);
- $.ajax({
- url: '/PurchaseInvoice/PurchaseMasterbyInvoiceNoVoucherTypeId',
- type: 'get',
- async: false,
- data: {
- DbName: DbName,
- invoiceNo: $('#voucherNo').val(),
- voucherTypeId: 13
- },
- success: function (data) {
- $('#VAD').val(getDate(data.date));
- $('#InAD').val(getDate(data.vendorInvoiceDate));
- purchacid = data.purchaseAccount; cashpartyid = data.ledgerId;
- purchlpid = getledgers(id, data.purchaseAccount);
- cashbanklpid = getledgers(id, data.ledgerId);
- partyBalanceId = getpartyBalanceId(id, data.ledgerId);
- $('#PurchaseAccountComboFill').val(data.purchaseAccount).select2();
- $('#CashOrPartyComboFill').val(data.ledgerId).select2();
- CommomAdDateToBs('#InAD', '#InBS');
- CommomAdDateToBs('#VAD', '#VBS');
- $('#invoiceNo').val(data.vendorInvoiceNo);
- $('#crPeriod').val(data.creditPeriod);
- $('#PInarration').val(data.narration);
- $('#TransportationCompany').val(data.transportationCompany);
- $('#LRNo').val(data.lrNo);
- $('#gbillDiscount').val(data.billDiscount);
- //$('#gCostToparty').text(data.additionalCost);
- $('#gTaxAmt').val(data.totalTax);
- $('#gtotal').text(data.grandTotal);
- $('#ginvoiceTotal').text(data.totalAmount);
- $('#billAmount').val(data.totalAmount);
- transAmt = $('#billAmount').val();
- $('#totalAmount').val(data.totalAmount);
- purchaseMasterId = data.purchaseMasterId;
- taxAmt = data.totalTax;
- //nonTaxable = data.additionalCost;
- totalInvoice = data.totalAmount; totalGrand = data.grandTotal;
- //totalInvoice = $('#netTotalF').text() - $('#gbillDiscount').val();
- //totalGrand = nonTaxable + taxable + 0;
- gCosttoParty += data.totalAmount;
- //$('#NonTaxableAmt').text(parseFloat(nonTaxable).toFixed(numberOfDecimal));
- $('#gtotal').text(parseFloat(totalGrand).toFixed(numberOfDecimal));
- $('#ginvoiceTotal').text(parseFloat(totalInvoice).toFixed(numberOfDecimal));
- $('#billAmount').val(parseFloat(totalInvoice).toFixed(numberOfDecimal));
- transAmt = $('#billAmount').val();
- $('#totalAmount').val(parseFloat(totalInvoice).toFixed(numberOfDecimal));
- getDetails(data.purchaseMasterId, id);
- getAdditionalCost(id);
- },
- error: function () {
- $('#loading').fadeOut();
- toastr.error('system error: Purchase invoice get by voucher number');
- }
- });
- }
- function Ledgerbyid(id) {
- var thisacg = 0;
- $.ajax({
- url: '/PurchaseInvoice/Ledgerbyid?DbName=' + DbName + '&id=' + id,
- type: 'get',
- async: false,
- success: function (data) {
- thisacg = data;
- }
- });
- return thisacg;
- }
- function LedgerpostingGetDetailsList(id) {
- var thislpid = 0;
- $.ajax({
- url: '/PurchaseInvoice/LedgerpostingGetDetailsList?DbName=' + DbName + '&invoiceNo=' + id + '&voucherTypeId=13' + '&ledgerId=0',
- type: 'get',
- async: false,
- success: function (data) {
- var icharge = 0, itax = 0, iadd = 0;
- $.each(data, function (key, val) {
- var thisagid = Ledgerbyid(val.ledgerId);
- if (parseInt(thisagid.accountGroupId) === 14) {
- if (thisagid.extra2 === 'Charge') {
- chargelpid[icharge] = val.ledgerPostingId;
- }
- else {
- discountlpid = val.ledgerPostingId;
- }
- }
- if (parseInt(thisagid.accountGroupId) === 20) {
- taxlpid[itax] = val.ledgerPostingId;
- itax++;
- }
- if (parseInt(thisagid.accountGroupId) === 13) {
- addcostlpid[iadd] = val.ledgerPostingId;
- iadd++;
- }
- });
- }
- });
- return thislpid;
- }
- function getledgers(id, lid) {
- var thislpid = 0;
- $.ajax({
- url: '/PurchaseInvoice/LedgerpostingGetDetails?DbName=' + DbName + '&invoiceNo=' + id + '&voucherTypeId=13' + '&ledgerId=' + lid,
- type: 'get',
- async: false,
- success: function (data) {
- thislpid = data.ledgerPostingId;
- }
- });
- return thislpid;
- }
- function getMaterialDetails(materialReceiptMasterId) {
- $.ajax({
- type: 'get',
- url: '/MaterialIn/MaterialReceiptDetailsViewByMasterId?DbName=' + DbName + '&MaterialReceiptMasterId=' + materialReceiptMasterId,
- async: false,
- success: function (data) {
- if (data.length > 0) {
- $('#productName').empty();
- $.each(data, function (key, val) {
- $("#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 > ');
- });
- setTimeout(function () { $('#productName').focus(); }, 500);
- }
- else {
- toastr.error('No any products');
- }
- $('#loading').fadeOut();
- },
- error: function () {
- $('#loading').fadeOut();
- toastr.error('error while loading sales details');
- }
- });
- //$.ajax({
- // url: '/MaterialIn/MaterialReceiptDetailsViewByMasterId?DbName=' + DbName + '&materialReceiptMasterId=' + materialReceiptMasterId,
- // type: 'get',
- // async: false,
- // success: function (data) {
- // if (data.length > 0) {
- // var j = 0;
- // grossAmt = 0;
- // disAmt = 0;
- // netAmt = 0;
- // netTotal = 0;
- // $.each(data, function (i, item) {
- // var pn = "", un = '', tn = '', gn = '', racn = '', dr = 0;
- // purchaselist[i] = item.materialReceiptDetailsId;
- // while (localStorage.getItem('keyPI' + j)) {
- // j++;
- // }
- // $.ajax({
- // url: '/PurchaseInvoice/ProductGetByProductId?DbName=' + DbName + '&productid=' + item.productId,
- // type: 'get',
- // async: false,
- // success: function (data) {
- // pn = data.productName;
- // }
- // });
- // if (item.unitId === 0) {
- // un = 'NA';
- // }
- // else {
- // $.ajax({
- // url: '/PurchaseInvoice/Unitbyid?DbName=' + DbName + '&id=' + item.unitId,
- // type: 'get',
- // async: false,
- // success: function (data) {
- // un = data.unitName;
- // }
- // });
- // }
- // if (item.godownId === 0) {
- // gn = 'NA';
- // }
- // else {
- // $.ajax({
- // url: '/PurchaseInvoice/GodownView?DbName=' + DbName + '&id=' + item.godownId,
- // type: 'get',
- // async: false,
- // success: function (data) {
- // gn = data.godownName;
- // }
- // });
- // }
- // if (item.rackId === 0) {
- // racn = 'NA';
- // }
- // else {
- // $.ajax({
- // url: '/PurchaseInvoice/RackView?DbName=' + DbName + '&id=' + item.rackId,
- // type: 'get',
- // async: false,
- // success: function (data) {
- // racn = data.rackName;
- // }
- // });
- // }
- // if (item.taxId === 0) {
- // tn = 'NA';
- // nonTaxable += item.netAmount;
- // }
- // else {
- // taxable += item.netAmount;
- // $.ajax({
- // url: '/PurchaseInvoice/TaxView?DbName=' + DbName + '&taxId=' + item.taxId,
- // type: 'get',
- // async: false,
- // success: function (data) {
- // tn = data.taxName;
- // }
- // });
- // }
- // if (item.discount === 0) {
- // dr = 0;
- // }
- // else {
- // dr = parseFloat(item.discount) / parseFloat(item.grossAmount) * 100;
- // }
- // stockpostid = getstockpostid(id, item.productId);
- // stockpostinglist[i] = stockpostid;
- // grossAmt += item.grossAmount;
- // disAmt += item.discount;
- // netAmt += item.netAmount;
- // netTotal += item.amount;
- // purchaseDetailsId = item.purchaseDetailsId;
- // taxLists[i] = item.taxId;
- // localStorage.setItem('keyPI' + j, JSON.stringify({
- // keyidPI: j,
- // purchaseDetailsId: purchaseDetailsId,
- // stockpostid: stockpostid,
- // ProductId: item.productId,
- // ProductCode: item.productCode,
- // ProductName: pn,
- // Qty: item.qty,
- // Unit: un,
- // UnitID: item.unitId,
- // Godown: gn,
- // GodownID: item.godownId,
- // Rack: racn,
- // RackID: item.rackId,
- // unitConversionId: item.unitConversionId,
- // Batch: item.batchId,
- // //BatchID: $("#rate").val(),
- // Rate: item.rate,
- // DisPer: dr,
- // GrossValue: item.grossAmount,
- // Discount: item.discount,
- // NetValue: item.netAmount,
- // ImportValue: item.importvalue,
- // Tax: tn,
- // taxlpid: gettaxLedger(item.taxId),
- // TaxID: item.taxId,
- // TaxAmt: item.taxAmount,
- // Total: item.amount,
- // expiryDate: getDate(item.expiryDate)
- // }));
- // if (j > lastkeyPI) {
- // lastkeyPI = j;
- // }
- // showTablePI();
- // });
- // }
- // },
- // error: function () {
- // $('#loading').fadeOut();
- // toastr.error('system error: Purchase invoice get details');
- // }
- //});
- }
- function getPurchaseOrderDetails(purchaseOrderMasterId) {
- $.ajax({
- type: 'get',
- url: '/PurchaseOrder/PurchaseOrderDetailsViewByOrderMasterId?DbName=' + DbName + '&purchaseOrderMasterId=' + purchaseOrderMasterId,
- async: false,
- success: function (data) {
- if (data.length > 0) {
- $('#productName').empty();
- $.each(data, function (key, val) {
- $("#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 > ');
- });
- setTimeout(function () { $('#productName').focus(); }, 500);
- }
- else {
- toastr.error('No any products');
- }
- $('#loading').fadeOut();
- },
- error: function () {
- $('#loading').fadeOut();
- toastr.error('error while loading sales details');
- }
- });
- }
- function getDetails(purchaseMasterId, id) {
- $.ajax({
- url: '/PurchaseInvoice/PurchaseDetailsbypurchaseMasterId?DbName=' + DbName + '&purchaseMasterId=' + purchaseMasterId,
- type: 'get',
- async: false,
- success: function (data) {
- if (data.length > 0) {
- var j = 0;
- grossAmt = 0;
- disAmt = 0;
- netAmt = 0;
- netTotal = 0;
- $.each(data, function (i, item) {
- var pn = "", un = '', charN = '', tn = '', gn = '', racn = '', dr = 0;
- purchaselist[i] = item.purchaseDetailsId;
- while (localStorage.getItem('keyPI' + j)) {
- j++;
- }
- $.ajax({
- url: '/PurchaseInvoice/ProductGetByProductId?DbName=' + DbName + '&productid=' + item.productId,
- type: 'get',
- async: false,
- success: function (data) {
- pn = data.productName;
- }
- });
- if (item.unitId === 0) {
- un = 'NA';
- }
- else {
- $.ajax({
- url: '/PurchaseInvoice/Unitbyid?DbName=' + DbName + '&id=' + item.unitId,
- type: 'get',
- async: false,
- success: function (data) {
- un = data.unitName;
- }
- });
- }
- if (item.godownId === 0) {
- gn = 'NA';
- }
- else {
- $.ajax({
- url: '/PurchaseInvoice/GodownView?DbName=' + DbName + '&id=' + item.godownId,
- type: 'get',
- async: false,
- success: function (data) {
- gn = data.godownName;
- }
- });
- }
- if (item.rackId === 0) {
- racn = 'NA';
- }
- else {
- $.ajax({
- url: '/PurchaseInvoice/RackView?DbName=' + DbName + '&id=' + item.rackId,
- type: 'get',
- async: false,
- success: function (data) {
- racn = data.rackName;
- }
- });
- }
- if (item.taxId === 0) {
- tn = 'NA';
- nonTaxable += item.netAmount;
- }
- else {
- taxable += item.netAmount;
- $.ajax({
- url: '/PurchaseInvoice/TaxView?DbName=' + DbName + '&taxId=' + item.taxId,
- type: 'get',
- async: false,
- success: function (data) {
- tn = data.taxName;
- }
- });
- }
- if (item.discount === 0) {
- dr = 0;
- }
- else {
- dr = parseFloat(item.discount) / parseFloat(item.grossAmount) * 100;
- }
- if (item.ChargeID === 0 || item.ChargeID === 1) {
- charN = 'N/A'
- }
- else {
- $.ajax({
- url: '/PurchaseInvoice/TaxView?DbName=' + DbName + '&taxId=' + item.ChargeID,
- type: 'get',
- async: false,
- success: function (data) {
- charN = data.taxName;
- }
- });
- }
- stockpostid = getstockpostid(id, item.productId);
- stockpostinglist[i] = stockpostid;
- grossAmt += item.grossAmount;
- disAmt += item.discount;
- netAmt += item.netAmount;
- netTotal += item.amount;
- purchaseDetailsId = item.purchaseDetailsId;
- taxLists[i] = item.taxId;
- localStorage.setItem('keyPI' + j, JSON.stringify({
- keyidPI: j,
- purchaseDetailsId: purchaseDetailsId,
- stockpostid: stockpostid,
- ProductId: item.productId,
- ProductCode: item.productCode,
- ProductName: pn,
- Qty: item.qty,
- Unit: un,
- UnitID: item.unitId,
- Godown: gn,
- GodownID: item.godownId,
- Rack: racn,
- RackID: item.rackId,
- unitConversionId: item.unitConversionId,
- Batch: item.batchId,
- //BatchID: $("#rate").val(),
- Rate: item.rate,
- DisPer: dr,
- GrossValue: item.grossAmount,
- Discount: item.discount,
- TotalAmt: item.netAmount,
- Charge: charN,
- ChargeID: item.ChargeID,
- chargeAmt: item.chargeAmt,
- chargelpid: gettaxLedger(item.ChargeID),
- TaxableVal: parseFloat(parseFloat(item.netAmount) - parseFloat(item.discount) + parseFloat(item.chargeAmt)).toFixed(numberOfDecimal),
- ImportValue: item.importvalue,
- Tax: tn,
- taxlpid: gettaxLedger(item.taxId),
- TaxID: item.taxId,
- TaxAmt: item.taxAmount,
- Total: item.amount,
- expiryDate: getDate(item.expiryDate)
- }));
- if (j > lastkeyPI) {
- lastkeyPI = j;
- }
- showTablePI();
- });
- }
- },
- error: function () {
- $('#loading').fadeOut();
- toastr.error('system error: Purchase invoice get details');
- }
- });
- }
- function gettaxLedger(taxId) {
- var id = 0;
- $.ajax({
- type: 'get',
- dataType: 'json',
- url: '/PurchaseInvoice/TaxView?DbName=' + DbName + '&taxId=' + taxId,
- success: function (data) {
- id = data.ledgerId;
- }
- });
- return id;
- }
- function getAdditionalCost(id) {
- $.ajax({
- url: '/PurchaseInvoice/AdditionalCostbyInvoiceNoVoucherTypeId?DbName=' + DbName + '&invoiceNo=' + id + '&voucherTypeId= 13',
- type: 'get',
- async: false,
- success: function (data) {
- if (data.length > 0) {
- var j = 0, drname = '', crname = '';
- $.each(data, function (i, item) {
- addcpstList[i] = item.additionalCostId;
- $.ajax({
- url: '/PurchaseInvoice/Ledgerbyid?DbName=' + DbName + '&id=' + item.drledgerId,
- type: 'get',
- async: false,
- success: function (data) {
- drname = data.ledgerName;
- }
- });
- $.ajax({
- url: '/PurchaseInvoice/Ledgerbyid?DbName=' + DbName + '&id=' + item.crledgerId,
- type: 'get',
- async: false,
- success: function (data) {
- crname = data.ledgerName;
- }
- });
- while (localStorage.getItem('keyAdd' + j)) {
- j++;
- }
- addcostid = item.additionalCostId;
- addcrlist = item.crledgerId; addDrlist = item.drledgerId;
- localStorage.setItem('keyAdd' + j, JSON.stringify({
- keyidAdd: j,
- addcostid: addcostid,
- AdditionalLedger: item.drledgerId,
- AddLedgerName: drname,
- AdditionalCashparty: item.crledgerId,
- AddCashpartyName: crname,
- AddtionalAmount: item.debit == 0 ? item.credit : item.debit
- }));
- TotalAdditionalCost += item.debit == 0 ? item.credit : item.debit;
- if (item.crledgerId === parseInt($("#CashOrPartyComboFill").val())) {
- gCosttoParty += item.debit == 0 ? item.credit : item.debit;
- CosttoParty += item.debit == 0 ? item.credit : item.debit;
- }
- nonTaxable += item.debit == 0 ? item.credit : item.debit;
- });
- if (j > lastkeyAdd) {
- lastkeyAdd = j;
- }
- showTableAddtional();
- }
- totalGrand = 0;
- $('#gCostToparty').text(parseFloat(gCosttoParty).toFixed(numberOfDecimal));
- $('#CosttoParty').text(parseFloat(CosttoParty).toFixed(numberOfDecimal));
- $('#TotalAdditionalCost').text(parseFloat(TotalAdditionalCost).toFixed(numberOfDecimal));
- $('#NonTaxableAmt').text(parseFloat(nonTaxable).toFixed(numberOfDecimal));
- caldiscount();
- $('#loading').fadeOut();
- },
- error: function () {
- toastr.error('system error: Purchase invoice get by voucher number');
- $('#loading').fadeOut();
- }
- });
- }
- function getpartyBalanceId(id, lid) {
- var thispartyid = 0;
- $.ajax({
- url: '/PurchaseInvoice/PartyBalanceDetails?DbName=' + DbName + '&invoiceNo=' + id + '&voucherTypeId=13' + '&ledgerId=' + lid,
- type: 'get',
- async: false,
- success: function (data) {
- thispartyid = data.partyBalanceId;
- }
- });
- return thispartyid;
- }
- function getstockpostid(id, productId) {
- var thisstockpostid = 0;
- $.ajax({
- url: '/PurchaseInvoice/StockPostingDetails?DbName=' + DbName + '&invoiceNo=' + id + '&voucherTypeId=13' + '&productId=' + productId,
- type: 'get',
- async: false,
- success: function (data) {
- thisstockpostid = data.stockPostingId;
- }
- });
- return thisstockpostid;
- }
- //update pi
- function updatePI() {
- $('#loading').fadeIn();
- if ($('#PurchaseAccountComboFill').val() === '0') {
- toastr.info('Please Select Purchase Account Ledger');
- $('#loading').fadeOut();
- $('#PurchaseAccountComboFill').focus();
- }
- else {
- if ($('#invoiceNo').val() === '') {
- toastr.info('Please Enter Invoice Number');
- $('#loading').fadeOut();
- $('#invoiceNo').focus();
- }
- else {
- if ($('#InAD').val() === '') {
- toastr.info('Please Select Invoice Date');
- $('#loading').fadeOut();
- $('#InAD').focus();
- }
- else {
- if ($('#CashOrPartyComboFill').val() === '0') {
- toastr.info('Please Select Party Ledger');
- $('#loading').fadeOut();
- $('#CashOrPartyComboFill').focus();
- }
- else {
- $('#btnUpdateYes').addClass('PI');
- $('#update').modal('show');
- }
- }
- }
- }
- }
- //confirm update
- function ConfirmUpdate() {
- //$('#loading').fadeIn();
- //if ($('.btnyes').hasClass('PI')) {
- // $('#btnNumb').focus();
- // var errorCount = 0;
- // //delete product
- // if (localStorage.length > 0) {
- // for (var kl = 0; kl < localStorage.length; kl++) {
- // if (localStorage.getItem('keyPI' + kl)) {
- // for (var jl = 0; jl < purchaselist.length; jl++) {
- // var checkpurchid = getcheckpurchid(purchaselist[jl]);
- // if (checkpurchid) {
- // continue;
- // }
- // else {
- // if (JSON.parse(localStorage.getItem('keyPI' + kl)).purchaseDetailsId !== 0) {
- // $.ajax({
- // url: '/PurchaseInvoice/PurchaseDetailsDelete?DbName=' + DbName + '&purchaseDetailsId=' + purchaselist[jl],
- // type: 'post',
- // async: false,
- // success: function () {
- // $.ajax({
- // url: '/PurchaseInvoice/StockPostingDelete?DbName=' + DbName + '&stockPostingId=' + stockpostinglist[jl],
- // type: 'post',
- // async: false,
- // success: function () {
- // },
- // error: function () {
- // //toastr.error(ledgerIDList[i]);
- // errorCount++;
- // }
- // });
- // },
- // error: function () {
- // //toastr.error(ledgerIDList[i]);
- // errorCount++;
- // }
- // });
- // }
- // }
- // }
- // }
- // }
- // }
- // if (localStorage.length > 0) {
- // for (var kle = 0; kle < localStorage.length; kle++) {
- // for (var add = 0; add < addcpstList.length; add++) {
- // var checkaddcostid = getcheckaddcostid(addcpstList[add]);
- // if (checkaddcostid) {
- // continue;
- // }
- // else {
- // $.ajax({
- // url: '/PurchaseInvoice/AdditionalCostDelete?DbName=' + DbName + '&additionalCostId=' + addcpstList[add],
- // type: 'post',
- // async: false,
- // success: function () {
- // },
- // error: function () {
- // //toastr.error(ledgerIDList[i]);
- // errorCount++;
- // }
- // });
- // }
- // }
- // }
- // }
- // if (errorCount === 0) {
- // for (var i = 0; i < lastkeyPI + 1; i++) {
- // if (localStorage.getItem('keyPI' + i)) {
- // datas[i] = JSON.stringify({
- // purchaseDetailsId: JSON.parse(localStorage.getItem('keyPI' + i)).purchaseDetailsId,
- // stockpostid: JSON.parse(localStorage.getItem('keyPI' + i)).stockpostid,
- // ProductId: JSON.parse(localStorage.getItem('keyPI' + i)).ProductId,
- // productType: JSON.parse(localStorage.getItem('keyPI' + i)).productType,
- // ProductCode: JSON.parse(localStorage.getItem('keyPI' + i)).ProductCode,
- // ProductName: JSON.parse(localStorage.getItem('keyPI' + i)).ProductName,
- // unitConversionId: JSON.parse(localStorage.getItem('keyPI' + i)).unitConversionId,
- // Qty: JSON.parse(localStorage.getItem('keyPI' + i)).Qty,
- // Unit: JSON.parse(localStorage.getItem('keyPI' + i)).Unit,
- // UnitID: JSON.parse(localStorage.getItem('keyPI' + i)).UnitID,
- // Godown: JSON.parse(localStorage.getItem('keyPI' + i)).Godown,
- // GodownID: JSON.parse(localStorage.getItem('keyPI' + i)).GodownID,
- // Rack: JSON.parse(localStorage.getItem('keyPI' + i)).Rack,
- // RackID: JSON.parse(localStorage.getItem('keyPI' + i)).RackID,
- // Batch: JSON.parse(localStorage.getItem('keyPI' + i)).Batch,
- // Rate: JSON.parse(localStorage.getItem('keyPI' + i)).Rate,
- // DisPer: JSON.parse(localStorage.getItem('keyPI' + i)).DisPer,
- // GrossValue: JSON.parse(localStorage.getItem('keyPI' + i)).GrossValue,
- // Discount: JSON.parse(localStorage.getItem('keyPI' + i)).Discount,
- // NetValue: JSON.parse(localStorage.getItem('keyPI' + i)).NetValue,
- // ImportValue: JSON.parse(localStorage.getItem('keyPI' + i)).ImportValue,
- // Tax: JSON.parse(localStorage.getItem('keyPI' + i)).Tax,
- // TaxID: JSON.parse(localStorage.getItem('keyPI' + i)).TaxID,
- // TaxAmt: JSON.parse(localStorage.getItem('keyPI' + i)).TaxAmt,
- // Total: JSON.parse(localStorage.getItem('keyPI' + i)).Total,
- // expiryDate: JSON.parse(localStorage.getItem('keyPI' + i)).expiryDate
- // });
- // }
- // }
- // for (var j = 0; j < lastkeyAdd + 1; j++) {
- // if (localStorage.getItem('keyAdd' + j)) {
- // Additionaldatas[j] = JSON.stringify({
- // AddCashpartyName: JSON.parse(localStorage.getItem('keyAdd' + j)).AddCashpartyName,
- // addcostid: JSON.parse(localStorage.getItem('keyAdd' + j)).addcostid,
- // AddLedgerName: JSON.parse(localStorage.getItem('keyAdd' + j)).AddLedgerName,
- // AdditionalCashparty: JSON.parse(localStorage.getItem('keyAdd' + j)).AdditionalCashparty,
- // AdditionalLedger: JSON.parse(localStorage.getItem('keyAdd' + j)).AdditionalLedger,
- // AddtionalAmount: JSON.parse(localStorage.getItem('keyAdd' + j)).AddtionalAmount
- // });
- // }
- // }
- // for (var k = 0; k < lastkeyTax + 1; k++) {
- // if (localStorage.getItem('keyTax' + k)) {
- // taxdatas[k] = JSON.stringify({
- // TaxID: JSON.parse(localStorage.getItem('keyTax' + k)).TaxID,
- // TaxAmt: JSON.parse(localStorage.getItem('keyTax' + k)).TaxAmt
- // });
- // }
- // }
- // var totalDiscount = parseFloat($('#gbillDiscount').val()) + parseFloat($('#disAmtF').text());
- // var dataObj = {
- // DbName: DbName,
- // purchaseMasterId: purchaseMasterId,
- // ledgerId: $('#CashOrPartyComboFill').val(),
- // vendorInvoiceNo: $('#invoiceNo').val().trim(),
- // vendorInvoiceDate: $('#InAD').val(),
- // creditPeriod: $('#crPeriod').val().trim(),
- // narration: $('#PInarration').val().trim(),
- // purchaseAccount: $('#PurchaseAccountComboFill').val(),
- // additionalCost: $('#TotalAdditionalCost').text(),
- // totalTax: $('#gTaxAmt').val(),//total tax
- // billDiscount: $('#gbillDiscount').val(),
- // costtoParty: $('#gCostToparty').text(),
- // grandTotal: $('#gtotal').text(),
- // invoiceTotal: $('#ginvoiceTotal').text(),// party amount
- // lrNo: $('#LRNo').val().trim(),
- // transportationCompany: $('#TransportationCompany').val().trim(),
- // ProductNetTotal: $('#netTotalF').text(),
- // grossValue: $('#grossAmtF').text(),
- // totalDiscount: totalDiscount, //total discount
- // list: datas,
- // partyBalanceId: partyBalanceId,
- // addList: Additionaldatas,
- // taxlist: taxdatas,
- // addcostlpid: addcostlpid,
- // purchlpid: purchlpid,
- // cashbanklpid: cashbanklpid,
- // taxlpid: taxlpid,
- // discountlpid: discountlpid
- // };
- // $.ajax({
- // type: 'post',
- // dataType: 'json',
- // data: dataObj,
- // url: '/PurchaseInvoice/UpdatePI',
- // success: function (data) {
- // if (data === 1) {
- // toastr.success('Updated Successfully');
- // resetForm();
- // $('#btnPISave').show();
- // $('#btnPIUpdate').hide();
- // $('#loading').fadeOut();
- // }
- // else {
- // toastr.error('Not added' + data);
- // $('#loading').fadeOut();
- // setTimeout(function () {
- // $('#PurchaseAccountComboFill').focus();
- // }, 100);
- // }
- // $('#update').modal('hide');
- // },
- // error: function (ex) {
- // toastr.error('Unable to update data' + ex.statusText);
- // $('#loading').fadeOut();
- // $('#update').modal('hide');
- // setTimeout(function () {
- // $('#PurchaseAccountComboFill').focus();
- // }, 100);
- // }
- // });
- // }
- // else {
- // $('#loading').fadeOut();
- // toastr.error('system error: record update could not be saved');
- // $('#update').modal('hide');
- // setTimeout(function () {
- // $('#PurchaseAccountComboFill').focus();
- // }, 100);
- // }
- // $('#btnUpdateYes').removeClass('PI');
- //}
- }
Add Comment
Please, Sign In to add comment