var Bizgaze; (function (Bizgaze) { let Apps; (function (Apps) { let Transact; (function (Transact) { let Controls; (function (Controls) { let Invoices; (function (Invoices) { class SplitItem extends Unibase.Platform.Core.BaseComponent { constructor() { super(...arguments); this.Type = ""; this.PendingQty = 0; this.SplitedInvoiceItemList = new Array(); this.rowIndex = 0; this.container = ""; this.DcItemIds = new Array(); this.Delete_InvoiceItems = new Array(); } jsFiles() { return ["apps/transact/controls/pricelist/mrp.js", "/platform/forms/managers/interfaces/iformmanager.js", "/platform/forms/managers/formmanager.js", "platform/forms/components/formviewer/formviewer.js", 'libs/parsley/parsley.min.js', 'apps/transact/controls/pricelist/managers/pricelistmanager.js', "apps/transact/controls/inventory/batch.js"]; } cssFiles() { return []; } load(item) { var instance = this; SplitItem.Instance().DcItemIds = [0]; $("#btn_InvoiceItem_Close").click(function () { instance.navigationHelper.closePopUp(); }); let element = item[0].element; let type = item[0].type; this.Type = item[0].type; $(".InvoiceItemName").text(element.find(".selectedItemName").text()); $(".EnabledType").text(type); $("#hf_ItemId").val(element.find(".selectedItemId").val()); $(".hf_AvailQty").text(element.find(".prodAvail").text()); let orderid = Bizgaze.Apps.Transact.Controls.InvoiceItem.Instance().orderid; if (orderid != undefined && orderid != null && orderid != 0) { $(".hf_pendingQty").text(element.find(".maxQty").val()); this.PendingQty = element.find(".maxQty").val(); } this.Type = type; $("#btnInvoice_Batch").click(function () { Invoices.SplitItem.Instance().addMrpRow(element); }); $(".btn_InvoiceItem_Save").click(function () { Invoices.SplitItem.Instance().SaveItem(element); }); $(document).click(function (e) { var container = $(".div_Item_MoreDetails"); if ($(e.target).closest("[class^='div_Item_MoreDetails']").length <= 0 && $(e.target).closest("[class^='Quantity']").length <= 0 && $(e.target).closest("[class^='Price']").length <= 0) { $("[class^='div_Item_MoreDetails']").addClass('hidden'); } }); let dcid = Bizgaze.Apps.Transact.Controls.InvoiceItem.Instance().dcid; let InvoiceId = $(".hdn_invoiceid").val(); let ItemExist = false; for (var i = 0; i < Bizgaze.Apps.Transact.Controls.InvoiceItem.Instance().SplitedInvoiceItemList.length; i++) { if (Bizgaze.Apps.Transact.Controls.InvoiceItem.Instance().SplitedInvoiceItemList[i].itemId == $("#hf_ItemId").val()) { if (Bizgaze.Apps.Transact.Controls.InvoiceItem.Instance().AutoDc == false && (Bizgaze.Apps.Transact.Controls.InvoiceItem.Instance().OrderSettingId == 1 || (Bizgaze.Apps.Transact.Controls.InvoiceItem.Instance().orderid == 0 && Bizgaze.Apps.Transact.Controls.InvoiceItem.Instance().dcid != 0)) && (InvoiceId == "0")) { if (SplitItem.Instance().Type == "MRP") { SplitItem.Instance().DcItemIds.push(Bizgaze.Apps.Transact.Controls.InvoiceItem.Instance().SplitedInvoiceItemList[i].MrpId); } else if (SplitItem.Instance().Type == "BatchNo") { SplitItem.Instance().DcItemIds.push(Bizgaze.Apps.Transact.Controls.InvoiceItem.Instance().SplitedInvoiceItemList[i].BatchId); } } ItemExist = true; Invoices.SplitItem.Instance().addMrpRowWithData(Bizgaze.Apps.Transact.Controls.InvoiceItem.Instance().SplitedInvoiceItemList[i]); var accid = Bizgaze.Apps.Transact.Controls.InvoiceItem.Instance().SplitedInvoiceItemList[i].accountId; var taxgrpid = Bizgaze.Apps.Transact.Controls.InvoiceItem.Instance().SplitedInvoiceItemList[i].taxGroupId; var taxgrptext = Bizgaze.Apps.Transact.Controls.InvoiceItem.Instance().SplitedInvoiceItemList[i].taxGroupName; var acctext = Bizgaze.Apps.Transact.Controls.InvoiceItem.Instance().SplitedInvoiceItemList[i].accountName; element.find(".hf_Account").val(Bizgaze.Apps.Transact.Controls.InvoiceItem.Instance().SplitedInvoiceItemList[i].accountId); element.find(".hfProdTax").val(Bizgaze.Apps.Transact.Controls.InvoiceItem.Instance().SplitedInvoiceItemList[i].taxGroupId); element.find(".txtProdTax").val(Bizgaze.Apps.Transact.Controls.InvoiceItem.Instance().SplitedInvoiceItemList[i].taxGroupName); element.find(".txt_AccountName").val(Bizgaze.Apps.Transact.Controls.InvoiceItem.Instance().SplitedInvoiceItemList[i].accountName); if (accid != 0) { $("#hf_AccountId").val(accid); $("#ddl_AccountId").append(new Option(acctext, accid, true)); } if (taxgrpid != 0) { $("#hf_TaxGroupId").val(taxgrpid); $("#ddl_TaxGroupId").append(new Option(taxgrptext, taxgrpid, true)); Invoices.SplitItem.Instance().update_TaxPercentage(taxgrpid); } } } Invoices.SplitItem.Instance().loadTaxGroupAutoComplete(element); if (ItemExist == false) this.addMrpRow(element); } loadTaxGroupAutoComplete(element) { var hfProdTax = element.find(".hfProdTax"); var accid = element.find(".hf_Account").val(); var taxgrpid = element.find(".hfProdTax").val(); var taxgrptext = element.find(".txtProdTax").val(); var acctext = element.find(".txt_AccountName").val(); AutoCompleteHelper.getHelper().Create("#ddl_TaxGroupId", "#hf_TaxGroupId", _appsettings.server_url() + "/apis/v4/bizgaze/transact/tax/taxgroupautocomplete", function (result) { Invoices.SplitItem.Instance().update_TaxPercentage($("#hf_TaxGroupId").val()); }); var url = _appsettings.server_url() + '/apis/v4/bizgaze/transact/ledgers/ledgerautocomplete'; AutoCompleteHelper.getHelper().Create("#ddl_AccountId", "#hf_AccountId", url, function (response) { }); if (taxgrpid != 0) { $("#hf_TaxGroupId").val(taxgrpid); if ($("#ddl_TaxGroupId option[value='" + taxgrpid + "']").attr("selected", "selected").length == 0) { $("#ddl_TaxGroupId").append(new Option(taxgrptext, taxgrpid, true)); } else { $("#ddl_TaxGroupId option[value='" + taxgrpid + "']").attr("selected", "selected"); } Invoices.SplitItem.Instance().update_TaxPercentage($("#hf_TaxGroupId").val()); } if (accid != 0) { $("#hf_AccountId").val(accid); if ($("#ddl_AccountId option[value='" + accid + "']").attr("selected", "selected").length == 0) { $("#ddl_AccountId").append(new Option(acctext, accid, true)); } else { $("#ddl_AccountId option[value='" + accid + "']").attr("selected", "selected"); } } } update_TaxPercentage(taxGroupId) { var hfTaxPercent = $(".hf_ProdTaxPercent"); var percentage = 0; if (taxGroupId == "0" || taxGroupId == "" || taxGroupId == undefined) return percentage; var isExcise = false; if ($('#hfInv_InvoiceMode').val() == 'Excise') isExcise = true; let branchid = Unibase.Platform.Membership.Infos.Identity.getSetting("branchid"); Bizgaze.Apps.Transact.Managers.InvoiceManager.Instance().gettaxpercentages(taxGroupId, branchid).then(function (response) { var percentstring = ""; if (response.result.length > 0) { var percentages = response.result; for (var i = 0; i < percentages.length; i++) { percentstring += percentages[i].LedgerId + ":" + percentages[i].Percentage + ","; } hfTaxPercent.val(percentstring); } }); } html() { var html = '
'; return html; } addMrpRow(element) { let item = false; $(".Mrp-addedrow").each(function () { if ($(this).find('.select_' + Invoices.SplitItem.Instance().Type + '').val() == undefined || $(this).find('.select_' + Invoices.SplitItem.Instance().Type + '').val() == null) { item = true; } }); if (item) { MessageHelper.Instance().showError("Please Select " + Invoices.SplitItem.Instance().Type, "bizgaze_CreateBatchErrorMessages"); return false; } var array = { orderItemId: element.find('.orderItemId').val(), invoiceItemId: 0, itemId: element.find('.selectedItemId').val(), packSize: 0, packCount: 0, packs: 0, quantity: 0, availPacks: 0, availQty: 0, Description: "", isTaxInclusive: $("#hfIsTaxInclusive").val(), addlDiscountPercent: 0, addlDiscountValue: 0, creditNote: 0, priceListId: element.find('.hf_PriceList').val(), invoiceallocations: null, exciseInvoiceItem: null, walletId: 0, Adjustment: 0, IsFoc: 0, TariffNo: "", exciseAmount: 0, discountName: "", discountId: 0, description: "", RefNo: "", DiscountGroupId: 0, DiscountGroupName: '', RefInvoiceItemId: 0, taxAdjustment: element.find('.hfItemTaxAdjsutmentVal').val(), assesableAdjustment: element.find('.hfItemAssesableAdjustmentVal').val(), inventoryTypeId: 0, dcItemId: 0, ExchangeItem: element.find('.IsExchangeItem').val(), unitPrice: element.find('.prodPrice').val(), taxGroupId: $("#hf_TaxGroupId").val(), BatchId: 0, MrpId: 0, SerialId: 0, Name: '', maxQty: 0, AccountId: element.find('.txt_Account').val(), AccountName: element.find('.txt_Account').text() }; Invoices.SplitItem.Instance().addMrpRowWithData(array); } addMrpRowWithData(row) { this.rowIndex += 1; var activeDiscVal = ""; var activeDiscPercent = ""; var activeDiscMul = ""; var activeDiscText = ""; var discValue = 0; if (row.addlDiscountPercent > 0) { discValue = row.addlDiscountPercent; activeDiscPercent = "active"; activeDiscText = "%"; } else if (row.addlDiscountValue > 0 && row.DiscountGroupId > 0) { discValue = row.addlDiscountValue; activeDiscMul = "active"; activeDiscText = "Mul"; } else { discValue = row.addlDiscountValue; activeDiscVal = "active"; activeDiscText = "Val"; } var Class = ""; if (SplitItem.Instance().Type == "MRP") { Class = "Mrp-row Mrp-addedrow"; } else if (SplitItem.Instance().Type == "BatchNo") { Class = "Batch-row Batch-addedrow"; } else if (SplitItem.Instance().Type == "SerialNo") { Class = "Serial-row Serial-addedrow"; } var readonlyPrice = ""; var readonlyDisc = ""; var readonlyTax = ""; var readonlyQty = ""; var ManageInvoice = 2; var ManageInvoiceTax = 1; if (ManageInvoice == 1 && AutoDc == false) { readonlyQty = "readonly"; readonlyPrice = "readonly"; readonlyDisc = "readonly"; readonlyTax = "readonly"; } if ($('.hdn_invoicetypeid').val() == "1" && ManageInvoiceTax == 1 && AutoDc == false) { readonlyTax = "readonly"; } if (($(".hdn_invoicetypeid").val() == "3" || $(".hdn_invoicetypeid").val() == "4") && $('#hfInv_IsRetun').val() == "1") { row.invoiceallocations = null; row.invoiceItemId = 0; } var html = '
' + '
' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '
' + '
' + ' ' + '' + '' + '
' + '
' + '
' + '' + '
' + '
' + '
' + '' + '
' + '
' + '
' + '' + '' + '' + '' + '
' + '' + '' + '
' + '
' + '' + '
' + '
' + '
' + '' + '' + '' + ''; if ($(".hdn_invoicetypeid").val() == "2" || $(".hdn_invoicetypeid").val() == "3" || $(".hdn_invoicetypeid").val() == "7") { html += ''; html += ''; } else { html += '

0.00

'; } html += '
'; html += '
'; var element = ""; if (SplitItem.Instance().Type == "MRP") { $(".Mrp-row:last").after(html); element = $(".Mrp-addedrow:last"); } else if (SplitItem.Instance().Type == "BatchNo") { $(".Batch-row:last").after(html); element = $(".Batch-addedrow:last"); } else if (SplitItem.Instance().Type == "SerialNo") { $(".Serial-row:last").after(html); element = $(".Serial-addedrow:last"); } element.find(".btn_item_DiscType option[value='" + activeDiscText + "']").prop("selected", true); if (row.description != null && row.description != '' && row.description != 'null') { element.find('#txt_Item_Description').val(row.description); element.find('#txt_Item_Description').parent(".desc").addClass("floating-label-form-group-with-value"); } if ((row.orderItemId != 0 && row.dcItemId != 0 && Bizgaze.Apps.Transact.Controls.InvoiceItem.Instance().OrderSettingId == 1) || (row.orderItemId == 0 && row.dcItemId != 0 && AutoDc == false)) { element.find('.select_' + SplitItem.Instance().Type + '').prop('disabled', true); } $('.txt_addldiscount').keypress(function (event) { if ((event.which > 47 && event.which < 58) || (event.which == 46 || event.which == 8)) { } else { event.preventDefault(); } }).on('paste', function (event) { event.preventDefault(); }); $('.Quantity').keypress(function (event) { if ((event.which > 47 && event.which < 58) || (event.which == 46 || event.which == 8)) { } else { event.preventDefault(); } }).on('paste', function (event) { event.preventDefault(); }); $('.Price').keypress(function (event) { if ((event.which > 47 && event.which < 58) || (event.which == 46 || event.which == 8)) { } else { event.preventDefault(); } }).on('paste', function (event) { event.preventDefault(); }); var AutoDc = Bizgaze.Apps.Transact.Controls.InvoiceItem.Instance().AutoDc; if (row.dcItemId != 0 || row.MrpId != 0 || row.BatchId != 0) { if (SplitItem.Instance().Type == "MRP") { if ((row.MrpId != 0 && row.MrpId != undefined) || row.dcItemId != 0) { element.find('.hf_' + SplitItem.Instance().Type + '_Id').val(row.MrpId); Invoices.SplitItem.Instance().GetMrpandBatchQty(row.MrpId, element, "", 0, row); } else { Invoices.SplitItem.Instance().Load(element); } } else if (SplitItem.Instance().Type == "BatchNo") { if ((row.BatchId != 0 && row.BatchId != undefined)) { element.find('.hf_' + SplitItem.Instance().Type + '_Id').val(row.BatchId); Unibase.Platform.Helpers.FileCacheHelper.Instance().loadJsFile("apps/transact/controls/pricelist/managers/pricelistmanager.js", function () { Bizgaze.Apps.Transact.Managers.PriceListManager.Instance().getbatch(row.BatchId).then(function (result) { Invoices.SplitItem.Instance().GetMrpandBatchQty(result.result.MrpId, element, result.result.BatchNo, row.BatchId, row); }); }); } else { Invoices.SplitItem.Instance().Load(element); } } else if (SplitItem.Instance().Type == "SerialNo") { if (row.SerialId != 0 || row.dcItemId != 0) { Invoices.SplitItem.Instance().GetMrpandBatchQty(row.SerialNoId, element, "", 0, null); row.Name = element.find('.hf_' + SplitItem.Instance().Type + '_Name').val(); element.find('.hf_' + SplitItem.Instance().Type + '_Id').val(row.SerialId); } } } else { Invoices.SplitItem.Instance().Load(element); } element.find(".Price,.Quantity,.txt_addldiscount ").focusin(function () { $(".div_Item_MoreDetails").addClass("hidden"); element.find(".div_Item_MoreDetails").removeClass("hidden"); }); element.find(".prodName").focusin(function () { $(".div_Item_MoreDetails").addClass("hidden"); }); element.find(".txt_addldiscount").change(function () { if (element.find(".btn_item_DiscType").val() == "%") { if (Number(element.find(".txt_addldiscount").val()) > 100) element.find(".txt_addldiscount").val("100"); } }); element.find(".select_" + SplitItem.Instance().Type).change(function () { let obj = []; obj.push({ ItemId: $("#hf_ItemId").val(), element: element, }); if ($(".hdn_invoicetypeid").val() == "2" || $(".hdn_invoicetypeid").val() == "3") { if (element.find(".select_" + SplitItem.Instance().Type + " option:selected").text() == "Create MRP") { var itemobj = Bizgaze.Apps.Transact.Controls.MRP.Instance(); Unibase.Platform.Helpers.NavigationHelper.Instance().popup(obj, "", itemobj, null, Unibase.Platform.Helpers.Size.DockLeft); } else if (element.find(".select_" + SplitItem.Instance().Type + " option:selected").text() == "Create Batch") { Unibase.Platform.Helpers.FileCacheHelper.Instance().loadJsFile("apps/transact/controls/inventory/batch.js", function () { var item = Bizgaze.Apps.Transact.Controls.Batch.Instance(); Unibase.Platform.Helpers.NavigationHelper.Instance().popup(Number($("#hf_ItemId").val()), "", item, null, Unibase.Platform.Helpers.Size.DockLeft); }); } } }); Invoices.SplitItem.Instance().update_row_total(element); if ($(".hdn_invoicetypeid").val() == "2") { element.find('.AjustmentRow').click(function () { Bizgaze.Apps.Transact.Controls.InvoiceItem.Instance().editInvItemTaxAllocs(row.invoiceItemId, row.taxGroupId, row.itemId, row.orderItemId, element); }); } Invoices.SplitItem.Instance().RemoveRow(element); element.find('.btn_item_DiscType').change(function () { if (element.find(".btn_item_DiscType").val() == "%") { if (Number(element.find(".txt_addldiscount").val()) > 100) element.find(".txt_addldiscount").val("100"); } if (element.find(".btn_item_DiscType option:selected").text().trim() == 'Val') { element.find('#hf_ItemDiscountGroupId').val(0); element.find('#hf_ItemDiscountGroupName').val(''); element.find('.txt_addldiscount').prop('disabled', false); } else if (element.find(".btn_item_DiscType option:selected").text().trim() == '%') { element.find('#hf_ItemDiscountGroupId').val(0); element.find('#hf_ItemDiscountGroupName').val(''); element.find('.txt_addldiscount').prop('disabled', false); } }); } GetMrpandBatchQty(id, element, BatchNo, batchid, row) { var mrpid; var name = ""; var url = ''; let Mrpid = id; if (Mrpid == -1) Mrpid = 0; if ($(".hdn_invoicetypeid").val() == "2" || $(".hdn_invoicetypeid").val() == "3" || $(".hdn_invoicetypeid").val() == "7") { url = 'apis/v4/bizgaze/transact/items/getitemmrpavailability/itemid/' + $("#hf_ItemId").val() + '/branchid/' + $(".txtAutoComplete_shiptoaddressid").val() + '/mrpid/' + Mrpid; } else { url = 'apis/v4/bizgaze/transact/items/getitemmrpavailability/itemid/' + $("#hf_ItemId").val() + '/branchid/' + $(".txtAutoComplete_shipfromaddressid").val() + '/mrpid/' + Mrpid; } Bizgaze.Apps.Transact.Managers.InvoiceManager.Instance().GetMrpandBatchQty(url).then(function (response) { let AvailItemQuntity = 0; if (response.result != null && response.result != '') { AvailItemQuntity = response.result.Quantity; element.find(".spn_Avail").text(Unibase.Core.Helpers.NumberHelper.Instance().roundNumber(Number(AvailItemQuntity), 2)); if (Invoices.SplitItem.Instance().Type == "MRP") { element.find('.hf_' + Invoices.SplitItem.Instance().Type + '_Name').val(Unibase.Core.Helpers.NumberHelper.Instance().roundNumber(Number(response.result.Mrp), 2) + ' (' + Unibase.Core.Helpers.NumberHelper.Instance().roundNumber(Number(AvailItemQuntity), 2) + ')'); name = element.find('.hf_' + SplitItem.Instance().Type + '_Name').val(); element.find(".select_" + SplitItem.Instance().Type + "").empty(); element.find(".select_" + SplitItem.Instance().Type + "").append(new Option(name, id)); element.find(".select_" + SplitItem.Instance().Type + "").val(id).trigger("change"); element.find(".select_" + SplitItem.Instance().Type + "").val(id); element.find(".spn_Mrp").text(response.result.Mrp); element.find(".hf_MrpId").val(id); Invoices.SplitItem.Instance().Load(element); if (row != null) { if (row.addlDiscountPercent > 0) element.find("#txt_discount").val(row.addlDiscountPercent); else element.find("#txt_discount").val(row.addlDiscountValue); element.find(".Quantity").val(row.quantity); Invoices.SplitItem.Instance().update_row_total(element); } } else if (Invoices.SplitItem.Instance().Type == "BatchNo") { element.find('.hf_' + Invoices.SplitItem.Instance().Type + '_Name').val('Batch No: ' + BatchNo + ' (' + Unibase.Core.Helpers.NumberHelper.Instance().roundNumber(Number(AvailItemQuntity), 3) + ')'); element.find(".hf_MrpId").val(id); element.find(".spn_Mrp").text(response.result.Mrp); name = element.find('.hf_' + SplitItem.Instance().Type + '_Name').val(); element.find(".select_" + SplitItem.Instance().Type + "").empty(); element.find(".select_" + SplitItem.Instance().Type + "").append(new Option(name, batchid, true)); Invoices.SplitItem.Instance().Load(element); if (row != null) { ``; if (row.addlDiscountPercent > 0) element.find("#txt_discount").val(row.addlDiscountPercent); else element.find("#txt_discount").val(row.addlDiscountValue); element.find(".Quantity").val(row.quantity); Invoices.SplitItem.Instance().update_row_total(element); } } } }); } RemoveRow(element) { element.find(".delete-row").on('click', function () { var _this = $(this); _this.parents('.SplInvoiceItemRow'); var invoiceitemid = _this.parents('.SplInvoiceItemRow').find(".hf_selectedInvoiceItemId").val(); if (invoiceitemid != 0) { if (confirm("You are about to Delete the invoice item. Are you sure?")) { var x = []; for (var i = 0; i < Bizgaze.Apps.Transact.Controls.InvoiceItem.Instance().SplitedInvoiceItemList.length; i++) { if (Bizgaze.Apps.Transact.Controls.InvoiceItem.Instance().SplitedInvoiceItemList[i].invoiceItemId == _this.parents('.SplInvoiceItemRow').find('.hf_selectedInvoiceItemId').val()) { x.push(i); SplitItem.Instance().Delete_InvoiceItems.push(invoiceitemid); } } for (var i = x.length - 1; i >= 0; i--) { Bizgaze.Apps.Transact.Controls.InvoiceItem.Instance().SplitedInvoiceItemList.splice(x[i], 1); } SplitItem.Instance().updateQuantity(); } } else if (Bizgaze.Apps.Transact.Controls.InvoiceItem.Instance().AutoDc == false && (Bizgaze.Apps.Transact.Controls.InvoiceItem.Instance().OrderSettingId == 1 || (Bizgaze.Apps.Transact.Controls.InvoiceItem.Instance().orderid == 0 && Bizgaze.Apps.Transact.Controls.InvoiceItem.Instance().dcid != 0)) && ($(".hdn_invoiceid").val() == "0") && element.find('.hf_' + Invoices.SplitItem.Instance().Type + '_Id').val() != "0") { var x = []; for (var i = 0; i < SplitItem.Instance().DcItemIds.length; i++) { if (Number(SplitItem.Instance().DcItemIds[i]) == Number(element.find('.hf_' + Invoices.SplitItem.Instance().Type + '_Id').val())) { x.push(i); } } for (var i = x.length - 1; i >= 0; i--) { SplitItem.Instance().DcItemIds.splice(x[i], 1); } _this.parents('.SplInvoiceItemRow').remove(); SplitItem.Instance().updateQuantity(); } else { _this.parents('.SplInvoiceItemRow').remove(); SplitItem.Instance().updateQuantity(); } }); element.find('.btn_item_DiscType').change(function () { if (element.find(".btn_item_DiscType").val() == "%") { if (Number(element.find(".txt_addldiscount").val()) > 100) element.find(".txt_addldiscount").val("100"); } if (element.find(".btn_item_DiscType option:selected").text().trim() == 'Val') { element.find('#hf_ItemDiscountGroupId').val(0); element.find('#hf_ItemDiscountGroupName').val(''); element.find('.txt_addldiscount').prop('disabled', false); } else if (element.find(".btn_item_DiscType option:selected").text().trim() == '%') { element.find('#hf_ItemDiscountGroupId').val(0); element.find('#hf_ItemDiscountGroupName').val(''); element.find('.txt_addldiscount').prop('disabled', false); } }); element.find(".Price,.exciseAmount,.txt_addldiscount").blur(function () { Invoices.SplitItem.Instance().update_price(element); }); element.find(".btn_item_DiscType").change(function () { Invoices.SplitItem.Instance().update_price(element); }); element.find(".Quantity").blur(function () { Invoices.SplitItem.Instance().CheckAvailableQuantity(element); }); } CheckAvailableQuantity(elements) { var quantity = elements.find('.Quantity').val(); var element = elements; if (element.find('.hf_' + Invoices.SplitItem.Instance().Type + '_Id').val() == "0") { MessageHelper.Instance().showError("Please Select " + Invoices.SplitItem.Instance().Type, 'bizgaze_CreateBatchErrorMessages'); } if (($('.hdn_invoicetypeid').val() == '1' || $('.hdn_invoicetypeid').val() == '4' || $('.hdn_invoicetypeid').val() == '6') && Bizgaze.Apps.Transact.Controls.InvoiceItem.Instance().OrderSettingId != 1) { if (element.find('.hf_' + Invoices.SplitItem.Instance().Type + '_Id').val() != '0') { if (Number(quantity) > Number(element.find('.spn_Avail').text())) { MessageHelper.Instance().showError("Check available quantity", 'bizgaze_CreateBatchErrorMessages'); if (Number(element.find('.spn_Avail').text()) > 0) elements.find('.Quantity').val(element.find('.spn_Avail').text()); else { elements.find('.Quantity').val(); } } } } if ((Bizgaze.Apps.Transact.Controls.InvoiceItem.Instance().OrderSettingId == 1 && element.find('.hf_dcItemId').val() != "0") || (element.find('.hf_orderItemId').val() == "0" && element.find('.hf_dcItemId').val() != "0" && Bizgaze.Apps.Transact.Controls.InvoiceItem.Instance().AutoDc == false)) { if (Number(quantity) > Number(element.find('.hf_maxQty').val())) { elements.find('.Quantity').val(Number(element.find('.hf_maxQty').val())); } } if (element.find('.hf_orderItemId').val() != 0) { var totalqty = 0; $('.SplInvoiceItemRow').each(function () { totalqty += Number($(this).find('.Quantity').val()); }); if (Number(Invoices.SplitItem.Instance().PendingQty) < totalqty) { var d = totalqty - Number(Invoices.SplitItem.Instance().PendingQty); elements.find('.Quantity').val(Number(quantity) - d); } } Invoices.SplitItem.Instance().update_row_total(element); } update_price(element) { Invoices.SplitItem.Instance().update_row_total(element); } update_row_total(element) { var row = element; var rowTotal = row.find('.Price').val() * (Number(row.find('.Quantity').val())); var rowTotalwithAdjustment = row.find('.Price').val() * (Number(row.find('.Quantity').val())); rowTotal += Number(row.find('.hf_RowTotalAdjustment').val()); Number($(this).find('.txt_RowTotalwithAdjustment').val()); rowTotalwithAdjustment += Number(row.find('.hf_RowTotalAdjustment').val()); var exciseAmount = element.find(".exciseAmount").val(); if (exciseAmount != undefined) { rowTotal += Number(exciseAmount); rowTotalwithAdjustment += Number(exciseAmount); } var asbAdjAmt = 0; asbAdjAmt = row.find('.hf_ItemAssesableAdjustmentVal').val(); if (!isNaN(asbAdjAmt)) rowTotalwithAdjustment += Number(asbAdjAmt); rowTotal = Unibase.Core.Helpers.NumberHelper.Instance().roundNumber(rowTotal, 2); let assesableAdjustment = Number(element.find('.hf_ItemAssesableAdjustmentVal').val()); if (!isNaN(assesableAdjustment)) { assesableAdjustment = Unibase.Core.Helpers.NumberHelper.Instance().roundNumber(assesableAdjustment, 2); } else { assesableAdjustment = 0; } rowTotalwithAdjustment += Number(assesableAdjustment); rowTotalwithAdjustment = Unibase.Core.Helpers.NumberHelper.Instance().roundNumber(rowTotalwithAdjustment, 2); if (isNaN(rowTotal)) { element.find('.TotalPrice').html("N/A"); element.find('.hf_RowTotal').val("0"); element.find('.hf_RowTotalwithAdjustment').val("0"); } else { element.find('.hf_RowTotal').val(rowTotal); element.find('.hf_RowTotalwithAdjustment').val(rowTotalwithAdjustment); element.find('.TotalPrice').html(rowTotal); } Invoices.SplitItem.Instance().update_Discount(element); Invoices.SplitItem.Instance().updateQuantity(); } updateQuantity() { var TotalAmt = 0; var totalqty = 0; $(".SplInvoiceItemRow").each(function () { if ($(".hdn_invoicetypeid").val() == "2" || $(".hdn_invoicetypeid").val() == "3" || $(".hdn_invoicetypeid").val() == "7") TotalAmt += Number($(this).find('.txt_RowTotalwithAdjustment').val()); else TotalAmt += Number($(this).find('.TotalPrice').text()); if ($("#hf_" + $("#hfLayout_InstalledPageId").val() + "_OrderId").val() != "0" && $("#hf_" + $("#hfLayout_InstalledPageId").val() + "_OrderId").val() != undefined) { totalqty += Number($(this).find('.Quantity').val()); } }); $('.hf_nettotal').text(Unibase.Core.Helpers.NumberHelper.Instance().roundNumber(TotalAmt, 2)); $(".hf_pendingQty").text(Number(Invoices.SplitItem.Instance().PendingQty) - totalqty); Controls.InvoiceItem.Instance().GetDiscounts(); } update_Discount(element) { let totalLineAmount = element.find('.hf_RowTotal').val(); if (!isNaN(totalLineAmount)) var discountPercent = 0; var discountValue = 0; var quantity = Number(element.find(".Quantity").val()); var unitPrice = Number(element.find(".Price").val()); totalLineAmount = element.find('.Price').val().replace("$", "") * quantity; var exciseAmount = Number(element.find(".exciseAmount").val()); if (isNaN(exciseAmount)) exciseAmount = 0; var nonexciseAmount = totalLineAmount - exciseAmount; if (element.find(".btn_item_DiscType option:selected").text().trim() == 'Val' && element.find('.txt_addldiscount').val() != '' && element.find('.txt_addldiscount').val() != undefined) { discountValue = Number(element.find('.txt_addldiscount').val()); } else if (element.find(".btn_item_DiscType option:selected").text().trim() == '%' && element.find('.txt_addldiscount').val() != '' && element.find('.txt_addldiscount').val() != undefined) { discountPercent = Number(element.find('.txt_addldiscount').val()); } var discountAmount = 0; discountAmount = (Number(nonexciseAmount) * Number(discountPercent) / 100) + (Number(quantity) * Number(discountValue)); discountAmount = Number(Unibase.Core.Helpers.NumberHelper.Instance().roundNumber(discountAmount, 2)); let discountedAmount = Number(totalLineAmount) - Number(discountAmount); element.find(".hf_DiscountedAmount").val(discountAmount); if ($(".hdn_invoicetypeid").val() == "2" || $(".hdn_invoicetypeid").val() == "3" || $(".hdn_invoicetypeid").val() == "7") { var assesableAdjustment = Number(element.find('.hf_ItemAssesableAdjustmentVal').val()); element.find(".txt_RowTotalwithAdjustment").val(Unibase.Core.Helpers.NumberHelper.Instance().roundNumber(totalLineAmount - discountAmount + assesableAdjustment, 2)); } else { element.find(".TotalPrice").html(Unibase.Core.Helpers.NumberHelper.Instance().roundNumber(totalLineAmount - discountAmount, 2)); element.find(".hf_RowTotal").val(Unibase.Core.Helpers.NumberHelper.Instance().roundNumber(totalLineAmount - discountAmount, 2)); } } Load(element) { var Ids = []; var AutoText = element.find(".select_" + SplitItem.Instance().Type + ""); var hdnAutoId = element.find(".hf_" + SplitItem.Instance().Type + "_Id"); Ids = [0]; $(".hf_" + SplitItem.Instance().Type + "_Id").each(function (index) { if ($(this).val() == element.find(".hf_" + SplitItem.Instance().Type + "_Id").val()) { } else Ids.push($(this).val()); }); var InvoiceType = 'Purchase'; var dctypeid = 1; var BranchId = $(".txtAutoComplete_shiptoaddressid").val(); if ($('.hdn_invoicetypeid').val() == '1' || $('.hdn_invoicetypeid').val() == '4' || $('.hdn_invoicetypeid').val() == '6') { InvoiceType = 'Sales'; BranchId = $(".txtAutoComplete_shipfromaddressid").val(); dctypeid = 2; } let url; if (SplitItem.Instance().Type == "MRP") { url = _appsettings.server_url() + '/apis/v4/bizgaze/transact/pricelists/MrpsAutoComplete/itemid/' + $("#hf_ItemId").val() + '/mrpids/' + Ids.toString() + '/invoicetype/' + InvoiceType + '/dctype/' + dctypeid + '/branchid/' + BranchId + '/isinvoice/true'; } else if (SplitItem.Instance().Type == "BatchNo") { url = _appsettings.server_url() + '/apis/v4/bizgaze/transact/pricelists/BatchAutoComplete/itemid/' + $("#hf_ItemId").val() + '/ids/' + Ids.toString() + '/invoicetype/' + InvoiceType + '/dctype/' + dctypeid + '/branchid/' + BranchId + '/isinvoice/true'; } else if (SplitItem.Instance().Type == "SerialNo") { url = _appsettings.server_url() + "/api/v3/MRPs/Item/" + $("#hf_ItemId").val() + "/SerialNos/" + Ids.toString() + "/InvoiceType/" + InvoiceType + "/DCtype/0/"; } var AutoText = element.find(".select_" + SplitItem.Instance().Type); var hdnAutoId = element.find(".hf_" + SplitItem.Instance().Type + "_Id"); AutoCompleteHelper.getHelper().Create(AutoText, hdnAutoId, url, function (result) { var ids = $(hdnAutoId).val(); if (ids != '0' && result.id != 0 && result.addlData != undefined) { element.find(".Quantity").val("0"); element.find("Price").val(element.find('.hf_UnitPrice').val()); element.find("#txt_discount").val("0"); Invoices.SplitItem.Instance().update_row_total(element); if (Bizgaze.Apps.Transact.Controls.InvoiceItem.Instance().AutoDc == false && (Bizgaze.Apps.Transact.Controls.InvoiceItem.Instance().OrderSettingId == 1 || (Bizgaze.Apps.Transact.Controls.InvoiceItem.Instance().orderid == 0 && Bizgaze.Apps.Transact.Controls.InvoiceItem.Instance().dcid != 0) && result.addlData != undefined) && ($(".hdn_invoiceid").val() == "0")) { SplitItem.Instance().DcItemIds.push(result.id); element.find(".hf_dcItemId").val(result.addlData.split(':')[1]); element.find(".hf_orderItemId").val(result.addlData.split(':')[2]); element.find(".Quantity").val(result.addlData.split(':')[3]); element.find(".spn_Avail").text(result.addlData.split(':')[0]); } else { element.find(".spn_Avail").text(result.addlData); } if (SplitItem.Instance().Type == "MRP") { if (result.id.search(":") != -1) element.find(".hf_MrpId").val(result.id); else element.find(".hf_MrpId").val(result.id); } else if (SplitItem.Instance().Type == 'BatchNo') { Bizgaze.Apps.Transact.Managers.PriceListManager.Instance().getbatch(result.id).then(function (result) { element.find(".hf_MrpId").val(result.result.MrpId); element.find(".spn_Mrp").text(result.result.Mrp); }); } Ids = [0]; $(".hf_" + SplitItem.Instance().Type + "_Id").each(function () { Ids.push($(this).val()); }); } }); } SaveItem(elements) { this.fileCacheHelper.loadJsFile("libs/parsley/parsley.min.js", null); var qty = false; var avlqty = false; var UnitPrice = false; let appcontrolid = "frm_Bizgazetransact_Invoice_createInvoiceItem"; let itemcount = 0; var MRPandBatch = false; $(".SplInvoiceItemRow").each(function () { itemcount += 1; if ($(this).find(".Quantity").val() == 0) { qty = true; } if ($(this).find(".Price ").val() == 0) { UnitPrice = true; } if (($(this).find(".select_" + Invoices.SplitItem.Instance().Type).text()) == "") { MRPandBatch = true; } }); if (itemcount == 0) { MessageHelper.Instance().showError("Please Select " + Invoices.SplitItem.Instance().Type, "bizgaze_CreateBatchErrorMessages"); return false; } if (MRPandBatch) { MessageHelper.Instance().showError("Please Select " + Invoices.SplitItem.Instance().Type, "bizgaze_CreateBatchErrorMessages"); return false; } let result = Unibase.Platform.Forms.Components.FormViewer.Instance().requiredFieldValidation(appcontrolid); if (result == false) { MessageHelper.Instance().showError("Mandatory fields are missing", "bizgaze_CreateBatchErrorMessages"); return false; } if ($('#hf_InventoryTypeId').val() == '1' || $('#hf_InventoryTypeId').val() == '4' || $('#hf_InventoryTypeId').val() == '5') { $(".SplInvoiceItemRow").each(function () { if (Bizgaze.Apps.Transact.Controls.InvoiceItem.Instance().OrderSettingId != 1) { if (Number($(this).find(".Quantity").val()) > Number($(this).find('.spn_Avail').text())) { avlqty = true; } } }); } if (qty) { MessageHelper.Instance().showError("Item quantity should not be zero.", "bizgaze_CreateBatchErrorMessages"); return false; } if (UnitPrice) { MessageHelper.Instance().showError("Unit Price should not be zero.", "bizgaze_CreateBatchErrorMessages"); return false; } if (avlqty) { MessageHelper.Instance().showError("Check available quantity", 'bizgaze_CreateBatchErrorMessages'); return false; } var x = []; for (var i = 0; i < Bizgaze.Apps.Transact.Controls.InvoiceItem.Instance().SplitedInvoiceItemList.length; i++) { if (Bizgaze.Apps.Transact.Controls.InvoiceItem.Instance().SplitedInvoiceItemList[i].itemId == $("#hf_ItemId").val()) { x.push(i); } } for (var i = 0; i < SplitItem.Instance().Delete_InvoiceItems.length; i++) { Bizgaze.Apps.Transact.Controls.InvoiceItem.Instance().deleted_invoiceItems.push(i); } for (var i = x.length - 1; i >= 0; i--) { Bizgaze.Apps.Transact.Controls.InvoiceItem.Instance().SplitedInvoiceItemList.splice(x[i], 1); } var TotalQuantity = 0; var TotalAmount = 0; var TotalDisc = 0; var RowExist = false; $(".SplInvoiceItemRow").each(function () { var element = $(this); var BatchId = 0; var SerialNoId = 0; var MrpId = 0; var Name = ''; if (Invoices.SplitItem.Instance().Type == "MRP") { MrpId = Number(element.find('.hf_MRP_Id').val()); Name = element.find('.select_' + Invoices.SplitItem.Instance().Type + ' option[value=' + MrpId + ']').text(); } else if (Invoices.SplitItem.Instance().Type == "BatchNo") { BatchId = Number(element.find('.select_' + Invoices.SplitItem.Instance().Type + '').val()); MrpId = Number(element.find(".hf_MrpId").val()); Name = element.find('.select_' + Invoices.SplitItem.Instance().Type + ' option[value =' + BatchId + ']').text(); } else if (Invoices.SplitItem.Instance().Type == "SerialNo") { SerialNoId = Number(element.find('.select_' + Invoices.SplitItem.Instance().Type + '').val()); MrpId = Number(element.find(".hf_MrpId").val()); Name = element.find('.select_' + Invoices.SplitItem.Instance().Type + ' option[value=' + SerialNoId + ']').text(); } if (element.find("#hf_" + Invoices.SplitItem.Instance().Type + "_Id").val() != '' && element.find("#hf_" + Invoices.SplitItem.Instance().Type + "_Id").val() != 0) { RowExist = true; var discountAmount = 0; var discountPercent = 0; if ((element.find(".btn_item_DiscType option:selected").text().trim() == 'Val' || element.find(".btnOrder_DiscType option:selected").text().trim() == 'Mul') && element.find('.txt_addldiscount').val() != '' && element.find('.txt_addldiscount').val() != undefined) { discountAmount = Number(element.find('.txt_addldiscount').val()); } else if (element.find(".btn_item_DiscType option:selected").text().trim() == '%' && element.find('.txt_addldiscount').val() != '' && element.find('.txt_addldiscount').val() != undefined) { discountPercent = Number(element.find('.txt_addldiscount').val()); } var DiscType = element.find(".btn_item_DiscType option:selected").text().trim(); var AccountId = elements.find(".hf_Account").val(); var TaxGroupId = elements.find(".hfProdTax").val(); Bizgaze.Apps.Transact.Controls.InvoiceItem.Instance().SplitedInvoiceItemList.push({ invoiceItemId: element.find(".hf_selectedInvoiceItemId").val(), orderItemId: element.find(".hf_orderItemId").val(), itemId: element.find(".hf_selectedItemId").val(), taxGroupId: $("#ddl_TaxGroupId").val(), taxGroupName: $("#ddl_TaxGroupId option:selected").text(), description: element.find("#txt_Item_Description").val(), priceListId: element.find(".hf_PriceList").val(), unitPrice: element.find(".Price").val(), addlDiscountValue: discountAmount, addlDiscountPercent: discountPercent, IsTaxInclusive: $('#hfId_IsTaxInclusive').val(), accountId: $("#ddl_AccountId").val(), accountName: $("#ddl_AccountId option:selected").text(), Adjustment: element.find(".hf_RowTotalAdjustment").val(), TotalAmount: element.find(".hf_RowTotal").val(), quantity: element.find(".Quantity").val(), exciseAmount: element.find(".exciseAmount").val(), refNo: element.find(".hf_refNo").val(), DiscountGroupId: element.find("#hf_ItemDiscountGroupId").val(), RefInvoiceItemId: element.find(".hf_refInvoiceItemId").val(), MrpId: MrpId, dcItemId: element.find(".hf_dcItemId").val(), BatchId: BatchId, SerialId: SerialNoId, ExchangeItem: element.find('.hf_IsExchangeItem').val(), taxAdjustment: element.find('.hf_ItemTaxAdjsutmentVal').val(), assesableAdjustment: element.find('.hf_ItemAssesableAdjustmentVal').val(), DiscountGroupName: element.find('.hf_ItemDiscountGroupName').val(), DiscountedAmount: element.find(".hf_DiscountedAmount").val(), TaxPercent: $(".hf_ProdTaxPercent").val(), Name: Name, DiscType: DiscType, maxQty: element.find('.hf_maxQty').val() }); TotalQuantity += Number(element.find(".Quantity").val()); var discount = 0; var qyt = Number(element.find(".Quantity").val()); var price = Number(element.find(".Price").val()); var excamt = Number(element.find(".exciseAmount").val()); var assesableAdjustment = Number(element.find('.hf_ItemAssesableAdjustmentVal').val()); var ItemAdjustment = Number(element.find(".hf_RowTotalAdjustment").val()); discount = (((qyt * price) + assesableAdjustment + ItemAdjustment - excamt) * Number(discountPercent) / 100) + (Number(qyt) * Number(discountAmount)); discount = Number(Unibase.Core.Helpers.NumberHelper.Instance().roundNumber(discount, 3)); TotalDisc += discount; if ($(".hdn_invoicetypeid").val() == "2" || $(".hdn_invoicetypeid").val() == "3" || $(".hdn_invoicetypeid").val() == "7") { TotalAmount += Number(element.find(".txt_RowTotalwithAdjustment").val()); } else { TotalAmount += Number(element.find(".TotalPrice").text()); } } }); if (RowExist = true) elements.find('.spn_InvoiceItem').text("View " + Invoices.SplitItem.Instance().Type); else elements.find('.spn_InvoiceItem').text("Select " + Invoices.SplitItem.Instance().Type); elements.find('.prodQuantity').val(); elements.find('.prodQuantity').val(TotalQuantity); elements.find('#inv_txtdiscount').val(); elements.find('#inv_txtdiscount').val(TotalDisc); if (($(".hdn_invoicetypeid").val() == "2" || $(".hdn_invoicetypeid").val() == "4" || $(".hdn_invoicetypeid").val() == "6") && $(".hdn_invoiceid").val() != "0") { elements.find(".txtRowTotalwithAdjustment").val(); elements.find(".txtRowTotalwithAdjustment").val(Unibase.Core.Helpers.NumberHelper.Instance().roundNumber(TotalAmount, 2)); } else { elements.find('.prodTotalPrice').text(''); elements.find('.prodTotalPrice').text(Unibase.Core.Helpers.NumberHelper.Instance().roundNumber(TotalAmount, 2)); } Invoices.SplitItem.Instance().navigationHelper.closePopUp(); if (Unibase.Themes.Providers.Detail_Settings.Instance().InputParameters.length > 0) { let OrderId = Number(Unibase.Themes.Providers.Detail_Settings.Instance().InputParameters.find(x => x.Key == "hf_" + Unibase.Themes.Providers.DetailHelper.installedAppId + "_orderid") == undefined ? 0 : Unibase.Themes.Providers.Detail_Settings.Instance().InputParameters.find(x => x.Key == "hf_" + Unibase.Themes.Providers.DetailHelper.installedAppId + "_orderid").Value); if (OrderId == 0) { Bizgaze.Apps.Transact.Controls.InvoiceItem.Instance().GetPlanItems(elements.find(".selectedItemId").val(), TotalQuantity, elements); } } Bizgaze.Apps.Transact.Controls.InvoiceItem.Instance().update_total(); Bizgaze.Apps.Transact.Controls.InvoiceItem.Instance().TotalAdjustment(); Bizgaze.Apps.Transact.Controls.InvoiceItem.Instance().update_discount_total(); } bindDetails(response, element) { var data = JSON.parse(response.result); if (SplitItem.instance.Type == "MRP") { element.find(".select_" + SplitItem.Instance().Type).empty(); element.find(".select_" + SplitItem.Instance().Type).append(new Option(data.Mrp + '(0)', data.MrpId, true)); element.find(".hf_" + SplitItem.Instance().Type + "_Id").val(data.MrpId); Invoices.SplitItem.Instance().GetMrpandBatchQty(data.MrpId, element, "", 0, null); } else if (SplitItem.instance.Type == "Batch") { element.find(".select_" + SplitItem.Instance().Type).empty(); element.find(".select_" + SplitItem.Instance().Type).append(new Option(data.BatchNo + '(0)', data.BatchId, true)); element.find(".hf_" + SplitItem.Instance().Type + "_Id").val(data.BatchId); } } refreshInvoiceTypes() { Unibase.Platform.Helpers.FileCacheHelper.Instance().loadJsFile("apps/transact/managers/invoicemanager.js", function () { Bizgaze.Apps.Transact.Managers.InvoiceManager.Instance().refreshInvoiceTypes().then(function (response) { MessageHelper.Instance().showSuccess(response.message, ''); }); }); } static Instance() { if (this.instance === undefined) { this.instance = new Invoices.SplitItem(); } return this.instance; } } SplitItem.element = ""; Invoices.SplitItem = SplitItem; })(Invoices = Controls.Invoices || (Controls.Invoices = {})); })(Controls = Transact.Controls || (Transact.Controls = {})); })(Transact = Apps.Transact || (Apps.Transact = {})); })(Apps = Bizgaze.Apps || (Bizgaze.Apps = {})); })(Bizgaze || (Bizgaze = {}));