var Unibase; (function (Unibase) { let Forms; (function (Forms) { let Controls; (function (Controls) { class MRPDetails 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(); } jsFiles() { return ["platform/controls/itemdetails/item.mrp.js"]; } cssFiles() { return []; } load(containerid) { var instance = this; $("#btn_InvoiceItem_Close").click(function () { instance.navigationHelper.closePopUp(); }); } loadForm(FormId, Pk_Value, AppConfigurationId, Callback, ElementId) { } html() { var html = '
Amount: 0.00
'; return html; } init(element, ItemName, type) { $(".InvoiceItemName").text(ItemName); $(".EnabledType").text(type); this.Type = type; this.SplitedInvoiceItemList.push({ orderItemId: 0, invoiceItemId: 0, itemName: "test", itemId: 0, itemSKU: 0, unitName: 0, packSize: 0, packCount: 0, packs: 0, quantity: 0, availPacks: 0, availQty: 0, listPrice: 0, description: "", taxGroupName: "", taxGroupId: 0, isTaxInclusive: $("#hfId_IsTaxInclusive").val(), addlDiscountPercent: 0, addlDiscountValue: 0, creditNote: 0, priceListId: 0, batchId: 0, unitPrice: 0, invoiceallocations: null, exciseInvoiceItem: null, accountId: 0, accountName: "", walletId: 0, Adjustment: 0, IsFoc: 0, TariffNo: "", exciseAmount: 0, discountName: "", discountId: 0, refNo: "", DiscountGroupId: 0, DiscountGroupName: "", ExchangeItem: 0, maxQty: 0, RefInvoiceItemId: 0, MrpId: 0, taxAdjustment: 0, assesableAdjustment: 0, inventoryTypeId: 0, IsBoMItem: 0, dcItemId: 0, TotalRowAmount: 0, TotalDiscount: 0, BatchId: 0, }); var ItemExist = false; for (var i = 0; i < this.SplitedInvoiceItemList.length; i++) { if (this.SplitedInvoiceItemList[i].itemId == $("#hf_ItemId").val()) { ItemExist = true; MRPDetails.Instance().addMrpRowWithData(this.SplitedInvoiceItemList[i]); } } $("#hf_ItemId").val(element.find(".selectedItemId").val()); $(".hf_AvailQty").text(element.find(".prodAvail").text()); if ($("#hf_" + $("#hfLayout_InstalledPageId").val() + "_OrderId").val() != "0" && $("#hf_" + $("#hfLayout_InstalledPageId").val() + "_OrderId").val() != undefined) { $(".hf_pendingQty").text(element.find(".maxQty").val()); this.PendingQty = element.find(".maxQty").val(); } $("#btnInvoice_Batch").click(function () { MRPDetails.Instance().addMrpRow(element); }); $("#btn_InvoiceItem_Save").click(function () { }); $(document).click(function (e) { var container = $(".div_Item_MoreDetails"); }); if (ItemExist == false) var orderid = $("#hf_" + $("#hfLayout_InstalledPageId").val() + "_OrderId").val(); var dcid = $("#hf_" + $("#hfLayout_InstalledPageId").val() + "_DcId").val(); var InvoiceId = $("#hf_" + $("#hfLayout_InstalledPageId").val() + "_InvoiceId").val(); var OrdersettingId = 2; if (OrdersettingId == 1 || ((orderid == "0" || orderid == undefined) && (dcid != "0" && dcid != undefined) && (InvoiceId == "0" || InvoiceId == "null"))) $("#btnInvoice_Batch").addClass('hidden'); } addMrpRow(element) { 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 }; MRPDetails.Instance().addMrpRowWithData(array); } addMrpRowWithData(row) { this.rowIndex = $(".SplInvoiceItemRow").length + 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 (Type == "MRP") { Class = "Mrp-row Mrp-addedrow"; } else if (Type == "BatchNo") { Class = "Batch-row Batch-addedrow"; } else if (Type == "SerialNo") { Class = "Serial-row Serial-addedrow"; } var readonlyPrice = ""; var readonlyDisc = ""; var readonlyTax = ""; var readonlyQty = ""; var ManageInvoice = 1; var ManageInvoiceTax = 1; if (ManageInvoice == 1 && AutoDc == false) { readonlyQty = "readonly"; readonlyPrice = "readonly"; readonlyDisc = "readonly"; readonlyTax = "readonly"; } if ($('#hfInv_Invoicetype').val() == "Sales" && ManageInvoiceTax == 1 && AutoDc == false) { readonlyTax = "readonly"; } var html = '
' + '
' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '
' + '
' + ' ' + '' + '' + '
' + '
' + '
' + '' + '
' + '
' + '
' + '' + '
' + '
' + '
' + '' + '' + '' + '' + '
' + '' + '' + '
' + '
' + '' + '
' + '
' + '
' + '' + '' + '' + ''; if ($("#hfInv_Invoicetype").val() == "Purchase" || $("#hfInv_Invoicetype").val() == "PurchaseReturn" || $("#hfInv_Invoicetype").val() == "DebitNote") { html += ''; html += ''; } else { html += '

0.00

'; } html += '
'; html += '
'; var element = ""; var Type = "MRP"; if (Type == "MRP") { $(".Mrp-row:last").after(html); element = $(".Mrp-addedrow:last"); } else if (Type == "BatchNo") { $(".Batch-row:last").after(html); element = $(".Batch-addedrow:last"); } else if (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); if ((row.orderItemId != 0 && row.dcItemId != 0 && OrdersettingId == 1) || (row.orderItemId == 0 && row.dcItemId != 0 && AutoDc == false)) { element.find('.select_' + 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(); }); this.Load(element); var OrdersettingId = 2; var AutoDc = false; if (row.dcItemId != 0 && OrdersettingId != 2 && AutoDc == false) element.find(".Quantity").prop('disabled', true); if (row.invoiceItemId != 0 || row.dcItemId != 0 || row.orderItemId != 0) { if (Type == "MRP") { row.Name = element.find('.hf_' + Type + '_Name').val(); } else if (Type == "BatchNo") { row.Name = element.find('.hf_' + Type + '_Name').val(); } else if (Type == "SerialNo") { row.Name = element.find('.hf_' + Type + '_Name').val(); } } if (row.Name != '') { if (Type == "MRP") { if (row.MrpId != 0) { element.find(".select_" + Type + "").empty(); element.find(".select_" + Type + "").append(new Option(row.Name, row.MrpId, true)); element.find('.hf_' + Type + '_Id').val(row.MrpId); } } else if (Type == "BatchNo") { if (row.BatchId != 0) { element.find(".select_" + Type + "").empty(); element.find(".select_" + Type + "").append(new Option(row.Name, row.BatchId, true)); element.find('.hf_' + Type + '_Id').val(row.BatchId); } } else if (Type == "SerialNo") { if (row.SerialId != 0) { element.find(".select_" + Type + "").empty(); element.find(".select_" + Type + "").append(new Option(row.Name, row.SerialId, true)); element.find('.hf_' + Type + '_Id').val(row.SerialId); } } } 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('.AjustmentRow').click(function () { }); var url = _appsettings.server_url() + '/apis/v4/unibase/transact/items/getitems/itemids/' + ',' + '/lobid/' + 100284890000001; AutoCompleteHelper.getHelper().Create("#select_itemMrp_" + this.rowIndex, "#hf_itemMrp_" + this.rowIndex, url, function (response) { var data = response; }); MRPDetails.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); } }); } 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 < this.SplitedInvoiceItemList.length; i++) { if (this.SplitedInvoiceItemList[i].invoiceItemId == _this.parents('.SplInvoiceItemRow').find('.hf_selectedInvoiceItemId').val()) { x.push(i); } } for (var i = x.length - 1; i >= 0; i--) { this.SplitedInvoiceItemList.splice(x[i], 1); } _this.parents('.SplInvoiceItemRow').remove(); } } else { if (confirm("You are about to Delete the invoice item. Are you sure?")) { _this.parents('.SplInvoiceItemRow').remove(); } } }); 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); } }); } Load(element) { var Type = ""; var Ids = []; var AutoText = element.find(".select_" + Type + ""); var hdnAutoId = element.find(".hf_" + Type + "_Id"); Ids = [0]; $(".hf_" + Type + "_Id").each(function () { Ids.push($(this).val()); }); var InvoiceType = 'Purchase'; var BranchId = $("#ddl_ShipToAddressId").val(); if ($('#hfInv_Invoicetype').val() == 'Sales' || $('#hfInv_Invoicetype').val() == 'PurchaseReturn' || $('#hfInv_Invoicetype').val() == 'CreditNote') { InvoiceType = 'Sales'; BranchId = $("#ddl_ShipFromAddressId").val(); } var url; if (Type == "MRP") { if ($("#hf_FormAppTitle").val() == "Sales Return" || $("#hf_FormAppTitle").val() == "Purchase Return") { } else { } } else if (Type == "BatchNo") { } else if (Type == "SerialNo") { } var AutoText = element.find(".select_" + Type + ""); var hdnAutoId = element.find(".hf_" + Type + "_Id"); } SaveItem(elements) { var qty = false; var avlqty = false; var UnitPrice = false; var CreateBatch_Validation = 'frm_Bizgazetransact_Invoice_createInvoiceItem'; if (!CreateBatch_Validation) { MessageHelper.Instance().showError(" Mandatory fields are missing ", "bizgaze_CreateBatchErrorMessages"); return false; } $(".SplInvoiceItemRow").each(function () { if ($(this).find(".Quantity").val() == 0) { qty = true; } }); $(".SplInvoiceItemRow").each(function () { if ($(this).find(".Price ").val() == 0) { UnitPrice = true; } }); var OrdersettingId = 1; var AutoDc = false; var qty = true; var UnitPrice = true; var avlqty = true; if ($('#hfInv_Invoicetype').val() == 'Sales' || $('#hfInv_Invoicetype').val() == 'PurchaseReturn') { $(".SplInvoiceItemRow").each(function () { if (OrdersettingId == 1 || AutoDc == true) { if (Number($(this).find(".Quantity").val()) > Number($(this).find('.spn_Avail').text())) { avlqty = true; } } }); } if (qty == true) { MessageHelper.Instance().showError("Item quantity should not be zero.", "bizgaze_CreateBatchErrorMessages"); return false; } if (UnitPrice == true) { MessageHelper.Instance().showError("Unit Price should not be zero.", "bizgaze_CreateBatchErrorMessages"); return false; } if (avlqty == true) { MessageHelper.Instance().showError("Available Quantity is less for an item", 'bizgaze_CreateBatchErrorMessages'); return false; } var x = []; for (var i = 0; i < this.SplitedInvoiceItemList.length; i++) { if (this.SplitedInvoiceItemList[i].itemId == $("#hf_ItemId").val()) { x.push(i); var index = this.DcItemIds.indexOf(this.SplitedInvoiceItemList[i].dcItemId); if (index > -1) this.DcItemIds.splice(index, 1); } } for (var i = x.length - 1; i >= 0; i--) { this.SplitedInvoiceItemList.splice(x[i], 1); } var TotalQuantity = 0; var TotalAmount = 0; var TotalDisc = 0; var RowExist = false; var TaxGroupId = elements.find('.hfProdTax').val(); var Taxgroupname = elements.find('.txtProdTax').val(); var AccountId = elements.find('.hf_Account').val(); var AccountName = elements.find('.txt_AccountName').val(); var instance = this; $(".SplInvoiceItemRow").each(function () { var element = $(this); var BatchId = 0; var SerialNoId = 0; var MrpId = 0; var Name = ''; var Type = "MRP"; if (Type == "MRP") { MrpId = Number(element.find('.hf_MRP_Id').val()); Name = element.find('.select_' + Type + ' option[value=' + MrpId + ']').text(); } else if (Type == "BatchNo") { BatchId = Number(element.find('.select_' + Type + '').val()); MrpId = Number(element.find(".hf_MrpId").val()); Name = element.find('.select_' + Type + ' option[value =' + BatchId + ']').text(); } else if (Type == "SerialNo") { SerialNoId = Number(element.find('.select_' + Type + '').val()); MrpId = Number(element.find(".hf_MrpId").val()); Name = element.find('.select_' + Type + ' option[value=' + SerialNoId + ']').text(); } if (element.find("#hf_" + Type + "_Id").val() != '' && element.find("#hf_" + 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(".btnOrder_DiscType option:selected").text().trim(); instance.SplitedInvoiceItemList.push({ invoiceItemId: element.find(".hf_selectedInvoiceItemId").val(), orderItemId: element.find(".hf_orderItemId").val(), itemId: element.find(".hf_selectedItemId").val(), taxGroupId: TaxGroupId, taxGroupName: Taxgroupname, 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: AccountId, accountName: AccountName, 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: elements.find(".hfProdTaxPercent").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(discount); TotalDisc += discount; if ($("#hfInv_Invoicetype").val() == "Purchase" || $("#hfInv_Invoicetype").val() == "PurchaseReturn" || $("#hfInv_Invoicetype").val() == "DebitNote") { TotalAmount += Number(element.find(".txt_RowTotalwithAdjustment").val()); } else { TotalAmount += Number(element.find(".TotalPrice").text()); } instance.DcItemIds.push(Number(element.find(".hf_dcItemId").val())); } }); var Type = "MRP"; if (RowExist = true) elements.find('.spn_InvoiceItem').text("View " + Type); else elements.find('.spn_InvoiceItem').text("Select " + Type); elements.find('.prodQuantity').val(); elements.find('.prodQuantity').val(TotalQuantity); elements.find('#inv_txtdiscount').val(); elements.find('#inv_txtdiscount').val(TotalDisc); if ($("#hfInv_Invoicetype").val() == "Purchase" || $("#hfInv_Invoicetype").val() == "PurchaseReturn" || $("#hfInv_Invoicetype").val() == "DebitNote") { elements.find(".txtRowTotalwithAdjustment").val(); elements.find(".txtRowTotalwithAdjustment").val(TotalAmount); } else { elements.find('.prodTotalPrice').text(''); elements.find('.prodTotalPrice').text(TotalAmount); } this.navigationHelper.closePopUp(); } static Instance() { return new MRPDetails(); } } MRPDetails.element = ""; Controls.MRPDetails = MRPDetails; })(Controls = Forms.Controls || (Forms.Controls = {})); })(Forms = Unibase.Forms || (Unibase.Forms = {})); })(Unibase || (Unibase = {}));