var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; var Bizgaze; (function (Bizgaze) { let Apps; (function (Apps) { let Transact; (function (Transact) { let Components; (function (Components) { class PurchasePlan extends Unibase.Platform.Core.BaseComponent { constructor() { super(); this.orderid = 0; this.EstimateId = 0; this.VisibleContainerId = ""; this.IsLoadDetailsFromList = false; } cssFiles() { return []; } jsFiles() { return ['apps/transact/managers/orders/ordermanager.js', 'apps/transact/controls/orders/order.component.js', 'apps/transact/controls/orders/orderitems.component.js', 'platform/forms/components/formviewer/formviewer.js' ]; } html(id, containerid) { let instance = this; instance.VisibleContainerId = containerid; var html = `
`; $("." + containerid).html(html); return ""; } init(containerid) { var instance = this; var id = 0; var InstalledAppId = Unibase.Themes.Providers.DetailHelper.installedAppId; for (let obj of Unibase.Themes.Providers.Detail_Settings.Instance().InputParameters) { if (obj.Key === "hf_" + InstalledAppId + "_recordid") { id = Number(obj.Value.toString()); } } instance.load(id, containerid, null); if (instance.VisibleContainerId == "") { instance.VisibleContainerId = Unibase.Platform.Helpers.NavigationHelper.ModalContainerIds[Unibase.Platform.Helpers.NavigationHelper.ModalContainerIds.length - 1]; } } load(id, containerid, callback) { var instance = this; instance.fileCacheHelper.loadJsFiles(['apps/transact/managers/orders/ordermanager.js', 'apps/transact/controls/orders/order.component.js', 'apps/transact/controls/orders/orderitems.component.js', 'platform/forms/components/formviewer/formviewer.js', 'apps/transact/managers/estimates/estimatemanager.js', "platform/core/helpers/numberhelper/numberhelper.js"], function () { instance._orderManager = Bizgaze.Apps.Transact.Managers.OrderManager.Instance(); instance._orderItems = Bizgaze.Apps.Transact.Controls.OrderItems.Instance(); instance._order = Bizgaze.Apps.Transact.Controls.Order.Instance(); instance.html(id, containerid); instance.orderid = Number(id); let InputParameters = Unibase.Themes.Providers.Detail_Settings.Instance().InputParameters; let InstalledAppId = Unibase.Themes.Providers.DetailHelper.installedAppId; let EstimateId = Number(InputParameters.find(x => x.Key == "hf_" + InstalledAppId + "_estimateid").Value); instance.EstimateId = EstimateId; instance.fileCacheHelper.loadJsFile("apps/transact/managers/estimates/estimatemanager.js", function () { Bizgaze.Apps.Transact.Managers.EstimateManager.Instance().getEstimate(EstimateId).then(function (response) { return __awaiter(this, void 0, void 0, function* () { let data = response.result; let BranchIds = data.BranchIds; let BranchNames = data.BranchIds_Text; let CompanyIds = data.CompanyIds; let CompanyNames = data.CompanyIds_Text; let IsGenerateForAllBranches = data.IsGenerateForAllBranches; let VisibleContainerId = instance.VisibleContainerId; $("#" + VisibleContainerId).find("#btnSection_Apply").addClass("text-white"); $("#" + VisibleContainerId).find(".btnSection_GeneratePurchasePlan").removeClass("mt-20").addClass('btn text-white'); $("#" + VisibleContainerId).find("#divSectionProperties_MoreOptions").removeClass('mt-10').addClass("mt-30"); let url = _appsettings.server_url() + '/apis/v4/bizgaze/crm/companies/getcompaniesAutoComplete'; AutoCompleteHelper.getHelper().Create("#select2_CompanyId_" + instance.VisibleContainerId, "#hfAutoComplete_Company_" + instance.VisibleContainerId, url, null); let Comp_Ids = "0"; var Company_Ids = []; var Company_Names = []; var Branch_Ids = []; var Branch_Names = []; if (CompanyIds != "" && CompanyIds != null && CompanyIds != "0") { Comp_Ids = CompanyIds.replace("|", ","); Company_Ids = CompanyIds.split("|"); Company_Names = CompanyNames.split("|"); } url = _appsettings.server_url() + '/apis/v4/bizgaze/crm/companies/getbranchesbycompaniesAutoComplete/companyids/' + Comp_Ids; AutoCompleteHelper.getHelper().Create("#select2_BranchId_" + instance.VisibleContainerId, "#hfAutoComplete_Branch_" + instance.VisibleContainerId, url, null); if (BranchIds != "" && BranchIds != null && BranchIds != "0") { Branch_Ids = BranchIds.split("|"); Branch_Names = BranchNames.split("|"); } if (CompanyIds == "" || CompanyIds == null && CompanyIds != "0") { $("#" + VisibleContainerId).find("#select2_CompanyId_" + instance.VisibleContainerId).val(null).trigger('change'); } else { for (let c = 0; c < Company_Ids.length; c++) { var company_option = new Option(Company_Names[c], Company_Ids[c], true, true); $("#" + VisibleContainerId).find("#select2_CompanyId_" + instance.VisibleContainerId).append(company_option).trigger('change'); } } if (BranchIds == "" || BranchIds == null && BranchIds != "0") { $("#" + VisibleContainerId).find("#select2_BranchId_" + instance.VisibleContainerId).val(null).trigger('change'); } else { for (let b = 0; b < Branch_Ids.length; b++) { var branch_option = new Option(Branch_Names[b], Branch_Ids[b], true, true); $("#" + VisibleContainerId).find("#select2_BranchId_" + instance.VisibleContainerId).append(branch_option).trigger('change'); } } if (IsGenerateForAllBranches) { $("#" + VisibleContainerId).find("#chkSection_GenerateForAllBranches_" + instance.VisibleContainerId).prop("checked", true); $("#" + VisibleContainerId).find("#select2_BranchId_" + instance.VisibleContainerId).val(null).trigger('change'); $("#" + VisibleContainerId).find("#select2_CompanyId_" + instance.VisibleContainerId).val(null).trigger('change'); $("#" + VisibleContainerId).find("#select2_CompanyId_" + instance.VisibleContainerId).prop('disabled', true); $("#" + VisibleContainerId).find("#select2_BranchId_" + instance.VisibleContainerId).prop('disabled', true); } instance.DisableOrEnableApplyButton(); instance.purchasePlanEvents(); }); }); }); }); } purchasePlanEvents() { var instance = this; $("#" + instance.VisibleContainerId).find("#select2_CompanyId_" + instance.VisibleContainerId).change(function () { let Ids = instance.getCompanyIds(); if (Ids == "") { Ids = "0"; $("#" + instance.VisibleContainerId).find("#select2_BranchId_" + instance.VisibleContainerId).prop('disabled', true); } else { $("#" + instance.VisibleContainerId).find("#select2_BranchId_" + instance.VisibleContainerId).removeAttr('disabled'); } let url = _appsettings.server_url() + '/apis/v4/bizgaze/crm/companies/getbranchesbycompaniesAutoComplete/companyids/' + Ids; AutoCompleteHelper.getHelper().Create("#select2_BranchId_" + instance.VisibleContainerId, "#hfAutoComplete_Branch_" + instance.VisibleContainerId, url, null); $("#" + instance.VisibleContainerId).find("#select2_BranchId_" + instance.VisibleContainerId).val('').trigger("change"); instance.DisableOrEnableApplyButton(); }); $("#" + instance.VisibleContainerId).find("#select2_BranchId_" + instance.VisibleContainerId).change(function () { instance.DisableOrEnableApplyButton(); }); $("#" + instance.VisibleContainerId).find("#btnSection_Apply").unbind().click(function () { let IsGenerateForAllBranches = $('#chkSection_GenerateForAllBranches_' + instance.VisibleContainerId).prop("checked"); let CompanyIds = ""; let CompanyNames = ""; let Company_Ids = $("#select2_CompanyId_" + instance.VisibleContainerId).select2('data'); for (let c = 0; c < Company_Ids.length; c++) { CompanyIds = CompanyIds.concat(Company_Ids[c].id, "|"); CompanyNames = CompanyNames.concat(Company_Ids[c].text, "|"); } let BranchIds = ""; let BranchNames = ""; let Branch_Ids = $("#select2_BranchId_" + instance.VisibleContainerId).select2('data'); for (let c = 0; c < Branch_Ids.length; c++) { BranchIds = BranchIds.concat(Branch_Ids[c].id, "|"); BranchNames = BranchNames.concat(Branch_Ids[c].text, "|"); } BranchIds = BranchIds.substring(0, BranchIds.length - 1); BranchNames = BranchNames.substring(0, BranchNames.length - 1); CompanyIds = CompanyIds.substring(0, CompanyIds.length - 1); CompanyNames = CompanyNames.substring(0, CompanyNames.length - 1); let postData = { EstimateId: instance.EstimateId, BranchIds: BranchIds, CompanyIds: CompanyIds, BranchNames: BranchNames, CompanyNames: CompanyNames, IsGenerateForAllBranches: IsGenerateForAllBranches }; instance.fileCacheHelper.loadJsFile("apps/transact/managers/orders/ordermanager.js", function () { Bizgaze.Apps.Transact.Managers.OrderManager.Instance().updatePurchasePlanDetails(postData).then(function (response) { return __awaiter(this, void 0, void 0, function* () { if (response.errors == null) { var detailInstance = Unibase.Themes.Compact.Components.Details.Instance(); var panel = "#" + detailInstance._containerId; var obj = Unibase.Themes.Compact.Components.Details.Instance(); obj._recordId = Unibase.Themes.Providers.DetailHelper.recordId; obj._installedAppId = Unibase.Themes.Providers.DetailHelper.installedAppId; instance.IsLoadDetailsFromList = false; detailInstance.loadAppDefaultWidget(obj, panel, detailInstance._containerId, function () { detailInstance.loadDefaultWidgets(obj._installedAppId, panel); detailInstance.LoadApprovals(obj._recordId, obj._installedAppId); }); MessageHelper.Instance().showSuccess(response.message, ""); } else { MessageHelper.Instance().showError(response.message, "div_message"); } }); }); }); }); $("#" + instance.VisibleContainerId).find('#chkSection_GenerateForAllBranches_' + instance.VisibleContainerId).click(function () { if ($("#" + instance.VisibleContainerId).find('#chkSection_GenerateForAllBranches_' + instance.VisibleContainerId).is(':checked')) { $("#" + instance.VisibleContainerId).find("#select2_BranchId_" + instance.VisibleContainerId).val(null).trigger('change'); $("#" + instance.VisibleContainerId).find("#select2_CompanyId_" + instance.VisibleContainerId).val(null).trigger('change'); $("#" + instance.VisibleContainerId).find("#select2_CompanyId_" + instance.VisibleContainerId).prop('disabled', true); $("#" + instance.VisibleContainerId).find("#select2_BranchId_" + instance.VisibleContainerId).prop('disabled', true); } else { $("#" + instance.VisibleContainerId).find("#select2_CompanyId_" + instance.VisibleContainerId).removeAttr('disabled'); $("#" + instance.VisibleContainerId).find("#select2_BranchId_" + instance.VisibleContainerId).removeAttr('disabled'); } let CompanyIds = instance.getCompanyIds(); if (CompanyIds == "") { $("#" + instance.VisibleContainerId).find("#select2_BranchId_" + instance.VisibleContainerId).prop('disabled', true); } instance.DisableOrEnableApplyButton(); }); } DisableOrEnableApplyButton() { let instance = this; let CompanyIds = instance.getCompanyIds(); let BranchIds = instance.getBranchIds(); if ((CompanyIds == "" || BranchIds == "") && !$("#" + instance.VisibleContainerId).find('#chkSection_GenerateForAllBranches_' + instance.VisibleContainerId).is(':checked')) { $("#" + instance.VisibleContainerId).find("#btnSection_Apply").addClass("disabled").css("cursor", "not-allowed"); } else { $("#" + instance.VisibleContainerId).find("#btnSection_Apply").removeClass("disabled").removeAttr("style"); } } savePurchasePlanItems(searchtext) { let instance = this; instance._order.g_PendingItemsSortBy = 0; let InstalledAppId = Unibase.Themes.Providers.DetailHelper.installedAppId; let InputParameters = Unibase.Themes.Providers.Detail_Settings.Instance().InputParameters; let EstimateId = Number(InputParameters.find(x => x.Key == "hf_" + InstalledAppId + "_estimateid").Value); instance.fileCacheHelper.loadJsFile("apps/transact/managers/estimates/estimatemanager.js", function () { Bizgaze.Apps.Transact.Managers.EstimateManager.Instance().getEstimate(EstimateId).then(function (response) { return __awaiter(this, void 0, void 0, function* () { let data = response.result; let BranchIds = Bizgaze.Apps.Transact.Components.PurchasePlan.Instance().getBranchIds(); let CompanyIds = Bizgaze.Apps.Transact.Components.PurchasePlan.Instance().getCompanyIds(); let LobId = Number(data.LobId); let ShippingAddressId = Number(data.ShippingAddressId); let ShipFromAddressId = Number(data.ShipFromAddressId); let BillingAddressId = Number(data.BillingAddressId); let OrganizationId = Number(data.OrganizationId); let contactId = OrganizationId; if (contactId == undefined || contactId == 0) contactId = 0; let CompositePrice = false; if ($('#chk_CompositePrice').is(':checked')) { CompositePrice = true; } let Postdata = { BranchIds: BranchIds, ContactId: Number(OrganizationId), LobId: LobId, CompanyIds: CompanyIds, SortBy: Number(instance._order.g_PendingItemsSortBy), Page: Number(0), Rows: 0, InventoryApplyType: instance._order.g_InventoryApplyType, Query: searchtext, OfferOnly: instance._order.g_LoadOffersOnly, IsComposite: CompositePrice, BranchId: Number(BillingAddressId), ShippingAddressId: Number(ShipFromAddressId), WareHouseId: Number(ShippingAddressId), EstimateId: EstimateId, OrderTypeId: data.EstimateTypeId }; Bizgaze.Apps.Transact.Managers.OrderManager.Instance().predictPurchasePlan(Postdata).then(function (response) { var data = response; if (response.errors == null) { MessageHelper.Instance().showSuccess(data.message, ""); } else { MessageHelper.Instance().showError(response.message, "div_message"); } }); }); }); }); } preditPurchasePlan_proc() { let instance = this; instance._order.g_PendingItemsSortBy = 0; let InstalledAppId = Unibase.Themes.Providers.DetailHelper.installedAppId; let InputParameters = Unibase.Themes.Providers.Detail_Settings.Instance().InputParameters; let EstimateId = Number(InputParameters.find(x => x.Key == "hf_" + InstalledAppId + "_estimateid").Value); instance.fileCacheHelper.loadJsFile("apps/transact/managers/orders/ordermanager.js", function () { Bizgaze.Apps.Transact.Managers.OrderManager.Instance().predictPurchasePlan_proc(EstimateId).then(function (response) { var data = response; if (response.errors == null) { MessageHelper.Instance().showSuccess(data.message, ""); } else { MessageHelper.Instance().showError(response.message, "div_message"); } }); }); } refreshPurchasePlanCalculations_proc() { let instance = this; instance._order.g_PendingItemsSortBy = 0; let InstalledAppId = Unibase.Themes.Providers.DetailHelper.installedAppId; let InputParameters = Unibase.Themes.Providers.Detail_Settings.Instance().InputParameters; let EstimateId = Number(InputParameters.find(x => x.Key == "hf_" + InstalledAppId + "_estimateid").Value); instance.fileCacheHelper.loadJsFile("apps/transact/managers/orders/ordermanager.js", function () { Bizgaze.Apps.Transact.Managers.OrderManager.Instance().refreshPurchasePlanCalculations_proc(EstimateId, 0).then(function (response) { var data = response; if (response.errors == null) { MessageHelper.Instance().showSuccess(data.message, ""); } else { MessageHelper.Instance().showError(response.message, "div_message"); } }); }); } ShowPurchasePlanCalculations(ItemId, Tenant_Id, Branch_Id) { let instance = this; let InstalledAppId = Unibase.Themes.Providers.DetailHelper.installedAppId; let InputParameters = Unibase.Themes.Providers.Detail_Settings.Instance().InputParameters; let EstimateId = Number(InputParameters.find(x => x.Key == "hf_" + InstalledAppId + "_estimateid").Value); instance.fileCacheHelper.loadJsFile("apps/transact/managers/orders/ordermanager.js", function () { Bizgaze.Apps.Transact.Managers.OrderManager.Instance().getPurchasePlanCalculations(EstimateId, ItemId, Tenant_Id, Branch_Id).then(function (response) { var data = response; if (response.errors == null) { if (data.result != 0 && data.result.length > 0) { let ModalHtml = `
`; $("#_bizgaze_modal").html(ModalHtml); $('#PurchasePlanCalculationsModal').modal(); } } else { MessageHelper.Instance().showError(response.message, "div_message"); } }); }); } ShowTenantWisePurchasePlanCalculations(ItemId, TenantId) { let instance = this; let InstalledAppId = Unibase.Themes.Providers.DetailHelper.installedAppId; let InputParameters = Unibase.Themes.Providers.Detail_Settings.Instance().InputParameters; let EstimateId = Number(InputParameters.find(x => x.Key == "hf_" + InstalledAppId + "_estimateid").Value); instance.fileCacheHelper.loadJsFile("apps/transact/managers/orders/ordermanager.js", function () { Bizgaze.Apps.Transact.Managers.OrderManager.Instance().getTenantWisePurchasePlanCalculations(EstimateId, ItemId, TenantId).then(function (response) { var data = response; if (response.errors == null) { if (data.result != 0 && data.result.length > 0) { let ModalHtml = `
`; $("#_bizgaze_modal").html(ModalHtml); $('#PurchasePlanCalculationsModal').modal(); } } else { MessageHelper.Instance().showError(response.message, "div_message"); } }); }); } closeCalculationsModal() { $('#PurchasePlanCalculationsModal').modal("hide"); } ShoworHidePredictButton(IsShowPredictPopup = true) { let instance = this; let InstalledAppId = Unibase.Themes.Providers.DetailHelper.installedAppId; let detailContainer = "#" + Unibase.Platform.Helpers.NavigationHelper.ModalContainerIds[Unibase.Platform.Helpers.NavigationHelper.ModalContainerIds.length - 1]; $(detailContainer).find(".DetailSetting_" + InstalledAppId + "_Predict").removeClass("btn-undefined").addClass("btn-warning"); let RefStatusId = Number(Unibase.Themes.Providers.Detail_Settings.Instance().InputParameters.find(x => x.Key == "hf_" + InstalledAppId + "_refstatusid").Value); let ClosedDate = Unibase.Themes.Providers.Detail_Settings.Instance().InputParameters.find(x => x.Key == "hf_" + InstalledAppId + "_closedate").Value; if (RefStatusId != 1 && RefStatusId != 4 && RefStatusId != 6) { if (ClosedDate.indexOf("01/01/0001") == -1) { $(detailContainer).find(".li_DetailSetting_" + InstalledAppId + "_PredictDate").remove(); $(detailContainer).find('#div_App_DefaultWidgetSettings').append(`

Values shown below are generated on ` + ClosedDate + `, click on 'Predict' to get latest values.

`); $(detailContainer).find('#div_App_DefaultWidgetSettings').addClass('pb-0'); } $(detailContainer).find('.li_DetailSetting_' + InstalledAppId + '_Predict').removeClass("hidden"); if (IsShowPredictPopup && RefStatusId != 6 && RefStatusId != 7 && instance.IsLoadDetailsFromList && ClosedDate.indexOf("01/01/0001") == -1) { instance.fileCacheHelper.loadJsFile("platform/core/helpers/datetimehelper/datetimehelper.js", function () { let DaysFromNow = Unibase.Platform.Helpers.DateTimeHelper.Instance().daysFromNow(moment(ClosedDate, "DD/MM/YYYY").format("YYYY-MM-DD")); if (DaysFromNow > 1) { bootbox.confirm({ message: "Values shown are generated on " + ClosedDate + ", Do you want get latest values ?", closeButton: false, buttons: { confirm: { label: 'Yes', className: 'btn-success' }, cancel: { label: 'No', className: 'btn-danger' } }, callback: function (result) { if (result) { instance.DisableAllButtons(); instance.savePurchasePlanItems(''); } } }); } }); } } else { $(detailContainer).find('.li_DetailSetting_' + InstalledAppId + '_Predict').addClass("hidden"); } $(detailContainer).find(".DetailSetting_" + InstalledAppId + "_Predict").unbind().click(function () { if (RefStatusId >= 3) { bootbox.confirm({ message: "You are about to Reset Predicted Data. Are You Sure ?", closeButton: false, buttons: { confirm: { label: 'Yes', className: 'btn-success' }, cancel: { label: 'No', className: 'btn-danger' } }, callback: function (result) { if (result) { instance.DisableAllButtons(); instance.savePurchasePlanItems(''); } } }); } else { instance.DisableAllButtons(); instance.savePurchasePlanItems(''); } }); } ShoworHidePredictButton_proc(IsShowPredictPopup = true) { let instance = this; let InstalledAppId = Unibase.Themes.Providers.DetailHelper.installedAppId; let detailContainer = "#" + Unibase.Platform.Helpers.NavigationHelper.ModalContainerIds[Unibase.Platform.Helpers.NavigationHelper.ModalContainerIds.length - 1]; $(detailContainer).find(".DetailSetting_" + InstalledAppId + "_Predict").removeClass("btn-undefined").addClass("btn-warning"); let RefStatusId = Number(Unibase.Themes.Providers.Detail_Settings.Instance().InputParameters.find(x => x.Key == "hf_" + InstalledAppId + "_refstatusid").Value); let ClosedDate = Unibase.Themes.Providers.Detail_Settings.Instance().InputParameters.find(x => x.Key == "hf_" + InstalledAppId + "_closedate").Value; if (RefStatusId != 1 && RefStatusId != 4 && RefStatusId != 6) { if (ClosedDate.indexOf("01/01/0001") == -1) { $(detailContainer).find(".li_DetailSetting_" + InstalledAppId + "_PredictDate").remove(); $(detailContainer).find('#div_App_DefaultWidgetSettings').append(`

Values shown below are generated on ` + ClosedDate + `, click on 'Predict' to get latest values.

`); $(detailContainer).find('#div_App_DefaultWidgetSettings').addClass('pb-0'); } $(detailContainer).find('.li_DetailSetting_' + InstalledAppId + '_Predict').removeClass("hidden"); if (IsShowPredictPopup && RefStatusId != 6 && RefStatusId != 7 && instance.IsLoadDetailsFromList && ClosedDate.indexOf("01/01/0001") == -1) { instance.fileCacheHelper.loadJsFile("platform/core/helpers/datetimehelper/datetimehelper.js", function () { let DaysFromNow = Unibase.Platform.Helpers.DateTimeHelper.Instance().daysFromNow(moment(ClosedDate, "DD/MM/YYYY").format("YYYY-MM-DD")); if (DaysFromNow > 1) { bootbox.confirm({ message: "Values shown are generated on " + ClosedDate + ", Do you want get latest values ?", closeButton: false, buttons: { confirm: { label: 'Yes', className: 'btn-success' }, cancel: { label: 'No', className: 'btn-danger' } }, callback: function (result) { if (result) { instance.DisableAllButtons(); instance.preditPurchasePlan_proc(); } } }); } }); } } else { $(detailContainer).find('.li_DetailSetting_' + InstalledAppId + '_Predict').addClass("hidden"); } $(detailContainer).find(".DetailSetting_" + InstalledAppId + "_Predict").unbind().click(function () { if (RefStatusId >= 3) { bootbox.confirm({ message: "You are about to Reset Predicted Data. Are You Sure ?", closeButton: false, buttons: { confirm: { label: 'Yes', className: 'btn-success' }, cancel: { label: 'No', className: 'btn-danger' } }, callback: function (result) { if (result) { instance.DisableAllButtons(); instance.preditPurchasePlan_proc(); } } }); } else { instance.DisableAllButtons(); instance.preditPurchasePlan_proc(); } }); } ShoworHideConfirmButton(IsShowPopup = true) { let instance = this; let InstalledAppId = Unibase.Themes.Providers.DetailHelper.installedAppId; let detailContainer = "#" + Unibase.Platform.Helpers.NavigationHelper.ModalContainerIds[Unibase.Platform.Helpers.NavigationHelper.ModalContainerIds.length - 1]; $(detailContainer).find(".DetailSetting_" + InstalledAppId + "_Confirm").removeClass("btn-undefined").addClass("btn-warning"); let RefStatusId = Number(Unibase.Themes.Providers.Detail_Settings.Instance().InputParameters.find(x => x.Key == "hf_" + InstalledAppId + "_refstatusid").Value); if (RefStatusId == 3) { $(detailContainer).find('.li_DetailSetting_' + InstalledAppId + '_Confirm').removeClass("hidden"); } else { $(detailContainer).find('.li_DetailSetting_' + InstalledAppId + '_Confirm').addClass("hidden"); } $(detailContainer).find(".DetailSetting_" + InstalledAppId + "_Confirm").unbind().click(function () { if (IsShowPopup) { let ClosedDate = Unibase.Themes.Providers.Detail_Settings.Instance().InputParameters.find(x => x.Key == "hf_" + InstalledAppId + "_closedate").Value; instance.fileCacheHelper.loadJsFile("platform/core/helpers/datetimehelper/datetimehelper.js", function () { let DaysFromNow = moment(moment(ClosedDate, "DD/MM/YYYY hh:mm:ss A").format("YYYY-MM-DD hh:mm:ss A")).fromNow(); bootbox.confirm({ message: "Values are generated " + DaysFromNow + ". Do you want to go ahead ?", closeButton: false, buttons: { confirm: { label: 'Yes', className: 'btn-success' }, cancel: { label: 'No', className: 'btn-danger' } }, callback: function (result) { if (result) { instance.DisableAllButtons(); MessageHelper.Instance().showSuccess("You will receive a notification once Purchase Order is saved", ""); instance.savePurchasePlanOrder(); } } }); }); } }); } savePurchasePlanOrder() { let instance = this; let InstalledAppId = Unibase.Themes.Providers.DetailHelper.installedAppId; let InputParameters = Unibase.Themes.Providers.Detail_Settings.Instance().InputParameters; let EstimateId = Number(InputParameters.find(x => x.Key == "hf_" + InstalledAppId + "_estimateid").Value); instance.fileCacheHelper.loadJsFile("apps/transact/managers/orders/ordermanager.js", function () { Bizgaze.Apps.Transact.Managers.OrderManager.Instance().savePurchasePlanOrder(EstimateId).then(function (response) { return __awaiter(this, void 0, void 0, function* () { if (response.errors == null) { } else { MessageHelper.Instance().showError(response.message, "div_message"); } }); }); }); } ShoworHideEditButton() { let instance = this; let InstalledAppId = Unibase.Themes.Providers.DetailHelper.installedAppId; let detailContainer = "#" + Unibase.Platform.Helpers.NavigationHelper.ModalContainerIds[Unibase.Platform.Helpers.NavigationHelper.ModalContainerIds.length - 1]; $(detailContainer).find(".DetailSetting_" + InstalledAppId + "_Edit").removeClass("btn-undefined").addClass("btn-warning"); let RefStatusId = Number(Unibase.Themes.Providers.Detail_Settings.Instance().InputParameters.find(x => x.Key == "hf_" + InstalledAppId + "_refstatusid").Value); if (RefStatusId == 3) { $(detailContainer).find('.li_DetailSetting_' + InstalledAppId + '_Edit').removeClass("hidden"); $(detailContainer).find('.CheckPlusIcon').removeClass("hidden"); } else { $(detailContainer).find('.li_DetailSetting_' + InstalledAppId + '_Edit').addClass("hidden"); $(detailContainer).find('.CheckPlusIcon').addClass("hidden"); } $(detailContainer).find(".DetailSetting_" + InstalledAppId + "_Edit").unbind().click(function () { instance.loadPurchaseOrderForm(); }); } DisableAllButtons() { Unibase.Platform.Helpers.FileCacheHelper.Instance().loadJsFile("tenants/themes/compact/components/details/details.js", function () { Unibase.Themes.Compact.Components.Details.Instance().changeStage(0, Unibase.Themes.Providers.DetailHelper.installedAppId, 0, '', 4); }); } loadEditROQ(ItemId) { let instance = this; let InstalledAppId = Unibase.Themes.Providers.DetailHelper.installedAppId; let InputParameters = Unibase.Themes.Providers.Detail_Settings.Instance().InputParameters; let EstimateId = Number(InputParameters.find(x => x.Key == "hf_" + InstalledAppId + "_estimateid").Value); var uniqueid = 'Bizgaze_Extensions_Transact_Form_EditItemROQ'; Unibase.Platform.Forms.Managers.FormManager.Instance().getFormbyUniqueId(uniqueid).then(function (response) { var successCallBack = { CallBack: function (id) { if ($(".variant-list").is(":visible")) { instance._orderItems.loadPurchasePlanItems($("#txt_SearchItem").val()); } else { var detailInstance = Unibase.Themes.Compact.Components.Details.Instance(); var panel = "#" + detailInstance._containerId; var obj = Unibase.Themes.Compact.Components.Details.Instance(); obj._recordId = Unibase.Themes.Providers.DetailHelper.recordId; obj._installedAppId = Unibase.Themes.Providers.DetailHelper.installedAppId; instance.IsLoadDetailsFromList = false; detailInstance.loadAppDefaultWidget(obj, panel, detailInstance._containerId, function () { detailInstance.loadDefaultWidgets(obj._installedAppId, panel); detailInstance.LoadApprovals(obj._recordId, obj._installedAppId); }); } }, Parameters: null, }; var formviewerObj = { FormId: response.result.FormId, AppConfigurationId: 0, Pk_Value: 0, PortletWidgetId: 0, OnSuccess: successCallBack, OnFail: null, OnLoad: null, }; Unibase.Platform.Forms.Components.FormViewer.Instance().init(formviewerObj); instance.navigationHelper.hideLoading(); setTimeout(function () { Bizgaze.Apps.Transact.Managers.OrderManager.Instance().getPurchasePlanItems(EstimateId, 0, null, ItemId).then(function (response) { $(".number_minqty, .number_roq, .number_avg").attr("disabled", "true").css("cursor", "not-allowed"); let data = response.result[0]; let MinQty = data.MinPacks; let ROQ = data.ReorderPacks; let AVG = data.AvgPacks; let LeadTime = data.LeadTime; let SDLeadTime = data.SDLeadTime; let ServiceLevel = data.ServiceLevel; let IsManualEntry = data.IsManualEntry; if (IsManualEntry == true) { $('.chk_ismanualentry').prop('checked', 'checked').trigger("change"); $('#hdnchk_ismanualentry').val('true'); } else { $('.chk_ismanualentry').prop('checked', '').trigger("change"); $('#hdnchk_ismanualentry').val('false'); } $(".hdn_estimateid").val(EstimateId); $(".hdn_itemid").val(ItemId); $(".number_minqty").val(MinQty); $(".number_roq").val(ROQ); $(".number_avg").val(AVG); $(".number_leadtime").val(LeadTime); $(".number_sdleadtime").val(SDLeadTime); $(".number_servicelevel").val(ServiceLevel); $("#div_leadtime, #div_sdleadtime, #div_servicelevel, #div_minqty, #div_roq, #div_avg").addClass("floating-label-form-group-with-value"); instance.enableorDisableManualEntry(); $(".chk_ismanualentry").change(function () { instance.enableorDisableManualEntry(); }); }); }, 1000); }); } enableorDisableManualEntry() { let IsEnableManualEntry = $(".chk_ismanualentry").prop("checked"); if (IsEnableManualEntry) { $(".number_minqty").removeAttr("disabled").css("cursor", "auto"); $(".number_roq").removeAttr("disabled").css("cursor", "auto"); $(".number_avg").removeAttr("disabled").css("cursor", "auto"); } else { $(".number_minqty").attr("disabled", "true").css("cursor", "not-allowed"); $(".number_roq").attr("disabled", "true").css("cursor", "not-allowed"); $(".number_avg").attr("disabled", "true").css("cursor", "not-allowed"); } } ResetMOQ() { let instance = this; let InstalledAppId = Unibase.Themes.Providers.DetailHelper.installedAppId; let detailContainer = "#" + Unibase.Platform.Helpers.NavigationHelper.ModalContainerIds[Unibase.Platform.Helpers.NavigationHelper.ModalContainerIds.length - 1]; let InputParameters = Unibase.Themes.Providers.Detail_Settings.Instance().InputParameters; let LobId = Number(InputParameters.find(x => x.Key == "hf_" + InstalledAppId + "_lobid").Value); let BillingAddressId = Number(InputParameters.find(x => x.Key == "hf_" + InstalledAppId + "_billingaddressid").Value); let OrganizationId = Number(InputParameters.find(x => x.Key == "hf_" + InstalledAppId + "_organizationid").Value); let RefStatusId = Number(Unibase.Themes.Providers.Detail_Settings.Instance().InputParameters.find(x => x.Key == "hf_" + InstalledAppId + "_refstatusid").Value); let EstimateId = Number(Unibase.Themes.Providers.Detail_Settings.Instance().InputParameters.find(x => x.Key == "hf_" + InstalledAppId + "_estimateid").Value); if (RefStatusId != 4) { $(detailContainer).find('.li_DetailSetting_' + InstalledAppId + '_ResetMOQ').removeClass("hidden"); } else { $(detailContainer).find('.li_DetailSetting_' + InstalledAppId + '_ResetMOQ').addClass("hidden"); } $(detailContainer).find(".DetailSetting_" + InstalledAppId + "_ResetMOQ").unbind().click(function () { instance.fileCacheHelper.loadJsFile("apps/transact/managers/orders/ordermanager.js", function () { bootbox.confirm({ message: "You are about to Reset MoQ. Are you sure ?", closeButton: false, buttons: { confirm: { label: 'Yes', className: 'btn-success' }, cancel: { label: 'No', className: 'btn-danger' } }, callback: function (result) { if (result) { Bizgaze.Apps.Transact.Managers.OrderManager.Instance().resetMoQ(LobId, BillingAddressId, OrganizationId, EstimateId).then(function (response) { if (response.errors == null) { var detailInstance = Unibase.Themes.Compact.Components.Details.Instance(); var panel = "#" + detailInstance._containerId; var obj = Unibase.Themes.Compact.Components.Details.Instance(); obj._recordId = Unibase.Themes.Providers.DetailHelper.recordId; obj._installedAppId = Unibase.Themes.Providers.DetailHelper.installedAppId; instance.IsLoadDetailsFromList = false; detailInstance.loadAppDefaultWidget(obj, panel, detailInstance._containerId, function () { detailInstance.loadDefaultWidgets(obj._installedAppId, panel); detailInstance.LoadApprovals(obj._recordId, obj._installedAppId); }); MessageHelper.Instance().showSuccess(response.message, ""); } else { MessageHelper.Instance().showError(response.message, "div_message"); } }); } } }); }); }); } ResetMOQ_proc() { let instance = this; let InstalledAppId = Unibase.Themes.Providers.DetailHelper.installedAppId; let detailContainer = "#" + Unibase.Platform.Helpers.NavigationHelper.ModalContainerIds[Unibase.Platform.Helpers.NavigationHelper.ModalContainerIds.length - 1]; let RefStatusId = Number(Unibase.Themes.Providers.Detail_Settings.Instance().InputParameters.find(x => x.Key == "hf_" + InstalledAppId + "_refstatusid").Value); let EstimateId = Number(Unibase.Themes.Providers.Detail_Settings.Instance().InputParameters.find(x => x.Key == "hf_" + InstalledAppId + "_estimateid").Value); if (RefStatusId != 4) { $(detailContainer).find('.li_DetailSetting_' + InstalledAppId + '_ResetMOQ').removeClass("hidden"); } else { $(detailContainer).find('.li_DetailSetting_' + InstalledAppId + '_ResetMOQ').addClass("hidden"); } $(detailContainer).find(".DetailSetting_" + InstalledAppId + "_ResetMOQ").unbind().click(function () { instance.fileCacheHelper.loadJsFile("apps/transact/managers/orders/ordermanager.js", function () { bootbox.confirm({ message: "You are about to Reset MoQ. Are you sure ?", closeButton: false, buttons: { confirm: { label: 'Yes', className: 'btn-success' }, cancel: { label: 'No', className: 'btn-danger' } }, callback: function (result) { if (result) { Bizgaze.Apps.Transact.Managers.OrderManager.Instance().resetMoQ_Proc(EstimateId).then(function (response) { if (response.errors == null) { var detailInstance = Unibase.Themes.Compact.Components.Details.Instance(); var panel = "#" + detailInstance._containerId; var obj = Unibase.Themes.Compact.Components.Details.Instance(); obj._recordId = Unibase.Themes.Providers.DetailHelper.recordId; obj._installedAppId = Unibase.Themes.Providers.DetailHelper.installedAppId; instance.IsLoadDetailsFromList = false; detailInstance.loadAppDefaultWidget(obj, panel, detailInstance._containerId, function () { detailInstance.loadDefaultWidgets(obj._installedAppId, panel); detailInstance.LoadApprovals(obj._recordId, obj._installedAppId); }); MessageHelper.Instance().showSuccess(response.message, ""); } else { MessageHelper.Instance().showError(response.message, "div_message"); } }); } } }); }); }); } loadPurchaseOrderForm() { let instance = this; var uniqueid = 'Bizgaze_Extension_Transact_PurchaseOrder_App_PurchaseOrder_CreatePurchaseOrder'; Unibase.Platform.Forms.Managers.FormManager.Instance().getFormbyUniqueId(uniqueid).then(function (response) { var successCallBack = { CallBack: function (id) { }, Parameters: null, }; var formviewerObj = { FormId: response.result.FormId, AppConfigurationId: 0, Pk_Value: 0, PortletWidgetId: 0, OnSuccess: successCallBack, OnFail: null, OnLoad: null, }; Unibase.Platform.Forms.Components.FormViewer.Instance().init(formviewerObj); setTimeout(function () { instance.navigationHelper.hideLoading(); instance.bindPODetails(); }, 1500); }); } bindPODetails() { let instance = this; let InputParameters = Unibase.Themes.Providers.Detail_Settings.Instance().InputParameters; let InstalledAppId = Unibase.Themes.Providers.DetailHelper.installedAppId; let OrganizationName = InputParameters.find(x => x.Key == "hf_" + InstalledAppId + "_organizationname").Value; let OrganizationId = Number(InputParameters.find(x => x.Key == "hf_" + InstalledAppId + "_organizationid").Value); let Organization = new Option(OrganizationName, OrganizationId.toString(), true); $(".txtAutoComplete_organizationid").append(Organization).val(OrganizationId).trigger("change"); instance._order.g_IsPurchasePlanning = true; $("#ItemLoadType").empty(); instance._order.g_ItemLoadTypes = ["Immediate", "Extra"]; for (let i = 0; i < instance._order.g_ItemLoadTypes.length; i++) { let j = i + 1; $("#ItemLoadType").append(''); } let VisibleContainerId = Unibase.Platform.Helpers.NavigationHelper.ModalContainerIds[Unibase.Platform.Helpers.NavigationHelper.ModalContainerIds.length - 1]; let EstimateTypeId = Number(Unibase.Themes.Providers.Detail_Settings.Instance().InputParameters.find(x => x.Key == "hf_" + InstalledAppId + "_estimatetypeid").Value); let FormName = "Purchase Plan Items"; if (EstimateTypeId == Bizgaze.Apps.Transact.Enums.OrderType.ProductionPlanning) { FormName = "Production Plan Items"; } $("#" + VisibleContainerId).find("#div_FormName").text(FormName); $("#" + VisibleContainerId).find(".Section").addClass("hidden"); $("#" + VisibleContainerId).find(".section_Items,.section_Calculations").removeClass("hidden"); $("#" + VisibleContainerId).find(".section_Calculations").find(".card-header").addClass("hidden"); $("#" + VisibleContainerId).find(".section_Calculations").css("position", "sticky").css("top", 0).css("z-index", "1"); $("#" + VisibleContainerId).find(".section_Items").css("z-index", "0"); $("#" + VisibleContainerId).find("#btn_Checkout").addClass("hidden"); $(".divselectall").removeClass('hidden'); $(".labelSection_Gross_Value, .labelSection_Discount_Value, .labelSection_Total_Value").text("0.00"); $(".labelSection_Gross_Value, .labelSection_Discount_Value, .labelSection_Total_Value, .labelSection_GrossAmount, .labelSection_DiscountAmount, .labelSection_NetTotal").addClass("font-weight-bold").addClass("col-sm-12").addClass("text-center"); $("#btn_CloseForm_" + $("#hf_FormId").val()).click(function () { var detailInstance = Unibase.Themes.Compact.Components.Details.Instance(); var panel = "#" + detailInstance._containerId; var obj = Unibase.Themes.Compact.Components.Details.Instance(); obj._recordId = Unibase.Themes.Providers.DetailHelper.recordId; obj._installedAppId = Unibase.Themes.Providers.DetailHelper.installedAppId; instance.IsLoadDetailsFromList = false; detailInstance.loadAppDefaultWidget(obj, panel, detailInstance._containerId, function () { detailInstance.loadDefaultWidgets(obj._installedAppId, panel); detailInstance.LoadApprovals(obj._recordId, obj._installedAppId); }); }); } getCompanyIds() { let instance = this; let CompanyIds = ''; let data = $("#" + instance.VisibleContainerId).find('#select2_CompanyId_' + instance.VisibleContainerId).select2('data'); if (data.length > 0) { let options = ''; for (let i = 0; i < data.length; i++) { if (data[i].toString() != '000' && data[i] != undefined) options += data[i].id + ","; } if (options != '') { options = options.replace(/\|$/, ''); CompanyIds = options; } } if (CompanyIds != '') { CompanyIds = CompanyIds.replace(/\:$/, ''); } else CompanyIds = '0'; CompanyIds = CompanyIds.slice(0, -1); return CompanyIds; } getBranchIds() { let instance = this; let BranchIds = ''; let data = $("#" + instance.VisibleContainerId).find('#select2_BranchId_' + instance.VisibleContainerId).select2('data'); if (data.length > 0) { let options = ''; for (let i = 0; i < data.length; i++) { if (data[i].toString() != '000' && data[i] != undefined) options += data[i].id + ","; } if (options != '') { options = options.replace(/\|$/, ''); BranchIds = options; } } if (BranchIds != '') BranchIds = BranchIds.replace(/\:$/, ''); BranchIds = BranchIds.slice(0, -1); return BranchIds; } numberhelper_Inverse(p) { var a = [-3.969683028665376e+01, 2.209460984245205e+02, -2.759285104469687e+02, 1.383577518672690e+02, -3.066479806614716e+01, 2.506628277459239e+00 ]; var b = [-5.447609879822406e+01, 1.615858368580409e+02, -1.556989798598866e+02, 6.680131188771972e+01, -1.328068155288572e+01 ]; var c = [-7.784894002430293e-03, -3.223964580411365e-01, -2.400758277161838e+00, -2.549732539343734e+00, 4.374664141464968e+00, 2.938163982698783e+00 ]; var d = [7.784695709041462e-03, 3.224671290700398e-01, 2.445134137142996e+00, 3.754408661907416e+00]; var plow = 0.02425; var phigh = 1 - plow; if (p < plow) { var q = Math.sqrt(-2 * Math.log(p)); return (((((c[0] * q + c[1]) * q + c[2]) * q + c[3]) * q + c[4]) * q + c[5]) / ((((d[0] * q + d[1]) * q + d[2]) * q + d[3]) * q + 1); } if (phigh < p) { var q = Math.sqrt(-2 * Math.log(1 - p)); return -(((((c[0] * q + c[1]) * q + c[2]) * q + c[3]) * q + c[4]) * q + c[5]) / ((((d[0] * q + d[1]) * q + d[2]) * q + d[3]) * q + 1); } var q1 = p - 0.5; var r = q1 * q1; return (((((a[0] * r + a[1]) * r + a[2]) * r + a[3]) * r + a[4]) * r + a[5]) * q1 / (((((b[0] * r + b[1]) * r + b[2]) * r + b[3]) * r + b[4]) * r + 1); } static Instance() { if (this._instance === undefined) this._instance = new PurchasePlan(); return this._instance; } } Components.PurchasePlan = PurchasePlan; })(Components = Transact.Components || (Transact.Components = {})); })(Transact = Apps.Transact || (Apps.Transact = {})); })(Apps = Bizgaze.Apps || (Bizgaze.Apps = {})); })(Bizgaze || (Bizgaze = {}));