var Bizgaze; (function (Bizgaze) { let Apps; (function (Apps) { let Transact; (function (Transact) { let Controls; (function (Controls) { class Estimate extends Unibase.Platform.Core.BaseComponent { constructor() { super(...arguments); this.g_LoadOffersOnly = false; this.g_EstimateType = ""; this.g_OrgContactId = 0; this.g_OrganizationId = 0; this.g_LobId = 0; this.g_PriceCodeId = 0; this.g_IsTaxInclusive = false; this.g_InventoryApplyType = 1; this.g_LeveragePercent = 0; this.g_IsLeverageApplied = false; this.g_IsApprovalRequired = false; this.g_EstimateTypeId = 0; this.g_IsCalculateTax = true; this.g_CompositePriceType = 0; this.g_ExpandItemSettings = false; this.g_CountryId = 0; this.g_IsShowEnablePieceChkbox = 0; this.g_IsManageOfferDiscount = 0; this.g_IsShowAvailability = 0; this.g_IsChangePaymentMode = 0; this.g_IsShowExchangeDc = 0; this.g_IsChangePaymentTerm = 0; this.g_CanProcessOrder = 0; this.g_CreateDC = 0; this.g_CreateGRN = 0; this.g_ShowPrice = 0; this.g_IncreaseQty = 0; this.g_IsAdmin = 1; this.g_CompanyId = 0; this.g_BranchId = 0; this.g_TagGroupId = 0; this.g_IsDealer = false; this.g_ShowSaveAsDraft = true; this.g_IsSeriesDisabled = true; this.g_IsFromPurchaseIndent = false; this.g_ItemLoadTypes = []; this.g_InstalledAppId = 0; this.g_FormId = 0; this.g_ContactName = ""; this.g_IsLead = false; this.g_IsFromLeadApp = false; this.g_IsCreateEstimate = false; this.g_LoadTypeId = 0; this.g_IsShowCategoryButton = false; } init(formpropertyid, prop, callback) { let instance = this; var jsFiles = ["platform/bundle/index.estimate.component.js"]; instance.fileCacheHelper.loadJsFiles(jsFiles, function () { instance.fileCacheHelper.addCacheFiles(["apps/transact/controls/estimates/estimateitems.component.js", "apps/transact/components/estimates/estimatefilter.js", "apps/transact/managers/inventory/itemmanager.js"]); let IsAdmin = Unibase.Platform.Membership.Infos.Identity.getCurrentUser().isAdmin; if (!IsAdmin) { instance.g_IsAdmin = 0; } else { instance.g_IsAdmin = 1; } instance.g_IsDealer = Unibase.Platform.Membership.Infos.Identity.getCurrentUser().isRestrictedUser; instance._estimateItems = Bizgaze.Apps.Transact.Controls.EstimateItems.Instance(); instance.loadControlSettings(prop.ControlJsonText, prop.FormPropertyId); instance.loadPropertySettings(prop.PropertySettings, prop.FormPropertyId); }); } loadControl(containerid, prop) { let instance = this; } loadControlSettings(controlsettingjson, formpropertyid) { let instance = this; instance.g_IsShowCategoryButton = false; $(document).ready(function () { instance.g_EstimateTypeId = Number($(".hdn_estimatetypeid").val()); instance.g_EstimateType = Bizgaze.Apps.Transact.Enums.OrderType[instance.g_EstimateTypeId]; instance.bindEvents(); instance.loadEstimateFromEmployeeRoute(); }); } loadPropertySettings(propertysettings, formpropertyid) { let instance = this; } bindEditFormDetails(formpropertyid, propval, DocPropertyName) { return null; } bindEvents() { var instance = this; instance.g_IsTaxInclusive = false; instance.g_ContainerId = "#" + Unibase.Platform.Helpers.NavigationHelper.ModalContainerIds[Unibase.Platform.Helpers.NavigationHelper.ModalContainerIds.length - 1]; if (Number($(".hdn_estimateid").val()) == 0) { instance.resetAllVariables(); $(".Section").addClass("hidden"); $(".section_ContactName").removeClass("hidden"); $(".section_ContactName").find(".card-header").addClass("hidden"); } $("#spn_TDSApplicable").text('TDS Applicable'); $("#ContinueShopping_Div").removeClass('hidden'); $('#bizgaze_body').on('keyup keypress', function (e) { let keyCode = e.keyCode || e.which; if (keyCode === 13) { e.preventDefault(); return false; } }); $(instance.g_ContainerId).find(".section_Details").addClass("section_EstimateDetails").removeClass("section_Details"); instance.checkDefaultCompany(); $(".btn_Save_Form").addClass("hidden"); let UserId = Unibase.Platform.Membership.Infos.Identity.getCurrentUser().userId; if (instance.g_IsDealer && Number($(".hdn_estimateid").val()) == 0) { Bizgaze.Apps.Crm.Contacts.Managers.ContactManager.Instance().getContactByUserId(UserId).then(function (response) { let contactId = response.result.OrganizationId; let organizationName = response.result.OrganizationName; let contact = new Option(organizationName, contactId.toString(), true); $(".txtAutoComplete_organizationid").append(contact); $(".txtAutoComplete_organizationid").val(contactId).trigger("change"); $("#orgContact_back").addClass("hidden"); }); } instance.g_IsCreateEstimate = false; if (Number($(".hdn_estimateid").val()) == 0) { $(".divCustomProperties_orderdate").addClass("hidden"); } $(".div_refdate, #div_proposeddeliverydate").addClass('floating-label-form-group-with-value'); if ($(".date_estimatedate").length > 0 && $(".date_estimatevaliddate").length > 0 && $(".date_expecteddeliverydate").length > 0) { $('.date_estimatedate, .date_expecteddeliverydate, .date_estimatevaliddate').on('apply.daterangepicker', function () { var AppTitile = "Estimate"; if (instance.g_EstimateTypeId == Bizgaze.Apps.Transact.Enums.OrderType.SalesContract || instance.g_EstimateTypeId == Bizgaze.Apps.Transact.Enums.OrderType.PurchaseContract) { AppTitile = "Contract"; } let EstimateDate = $.datepicker.parseDate('dd/mm/yy', $(".date_estimatedate").val().toString()); let ExpDeliveryDate = $.datepicker.parseDate('dd/mm/yy', $(".date_expecteddeliverydate").val().toString()); let ValidDate = $.datepicker.parseDate('dd/mm/yy', $(".date_estimatevaliddate").val().toString()); $("#Bizgaze-messageInfo").empty(); if (EstimateDate > ExpDeliveryDate && EstimateDate > ValidDate) { $(".bizgaze_FormErrorMessages").removeClass("hidden"); Unibase.Platform.Forms.Components.FormViewer.Instance().showError("Delivery Date and Valid Date must be greater than " + AppTitile + " Date"); $(".btn_Save_Form").find("button").attr("disabled", "disabled").css("cursor", "not-allowed"); return false; } else if (EstimateDate > ExpDeliveryDate) { $(".bizgaze_FormErrorMessages").removeClass("hidden"); Unibase.Platform.Forms.Components.FormViewer.Instance().showError("Delivery Date must be greater than " + AppTitile + " Date"); $(".btn_Save_Form").find("button").attr("disabled", "disabled").css("cursor", "not-allowed"); return false; } else if (EstimateDate > ValidDate) { $(".bizgaze_FormErrorMessages").removeClass("hidden"); Unibase.Platform.Forms.Components.FormViewer.Instance().showError("Valid Date must be greater than " + AppTitile + " Date"); $(".btn_Save_Form").find("button").attr("disabled", "disabled").css("cursor", "not-allowed"); return false; } else { $(".bizgaze_FormErrorMessages").addClass("hidden"); $(".btn_Save_Form").find("button").removeAttr("disabled").css("cursor", "auto"); } }); } $("#btn_CloseForm").after(' Vendor Credit Health `); $(".section_SalesFrequency").find(".card-header").html(` Purchase Frequency `); } else { $(".section_CustomerCreditHealth").find(".card-header").html(` Customer Credit Health `); $(".section_SalesFrequency").find(".card-header").html(` Sales Frequency `); } $(".section_CustomerOfferSummary").find(".card-header").first().html(` Customer Offer Summary
'); if (Number($(".hdn_estimateid").val()) != 0) { instance.editForm(); } if (instance.g_EstimateTypeId == Bizgaze.Apps.Transact.Enums.OrderType.SalesEstimate || instance.g_EstimateTypeId == Bizgaze.Apps.Transact.Enums.OrderType.SalesContract || instance.g_EstimateTypeId == Bizgaze.Apps.Transact.Enums.OrderType.PurchaseEstimate || instance.g_EstimateTypeId == Bizgaze.Apps.Transact.Enums.OrderType.PurchaseContract) { instance.g_ItemLoadTypes = ["All Items", "Offers", "Filter"]; } $("#div_TaxGroupId").addClass('hidden'); $(".hdn_expecteddeliverydate").val($(".date_proposeddeliverydate").val()); $(".date_proposeddeliverydate").change(function () { $(".hdn_expecteddeliverydate").val($(".date_proposeddeliverydate").val()); }); $("#chkSection_TDSApplicable").click(function () { if ($("#chkSection_TDSApplicable").is(':checked')) { $("#TDSAmount").removeClass('hidden'); $("#div_TaxGroupId").removeClass('hidden'); } else { $("#div_TaxGroupId").addClass('hidden'); } }); if (Number($(".hdn_estimateid").val()) == 0) { $("#btn_Save").addClass('hidden'); $(instance.g_ContainerId).find("#formFooter").append(''); } let leadIdIndex = Number(Unibase.Themes.Providers.Detail_Settings.Instance().InputParameters.findIndex(x => x.Key == "hf_" + Unibase.Themes.Providers.DetailHelper.installedAppId + "_leadid")); let leadNameIndex = Number(Unibase.Themes.Providers.Detail_Settings.Instance().InputParameters.findIndex(x => x.Key == "hf_" + Unibase.Themes.Providers.DetailHelper.installedAppId + "_leadname")); if (leadIdIndex != -1 && leadNameIndex != -1) { let leadId = Number(Unibase.Themes.Providers.Detail_Settings.Instance().InputParameters.find(x => x.Key == "hf_" + Unibase.Themes.Providers.DetailHelper.installedAppId + "_leadid").Value); let leadName = Unibase.Themes.Providers.Detail_Settings.Instance().InputParameters.find(x => x.Key == "hf_" + Unibase.Themes.Providers.DetailHelper.installedAppId + "_leadname").Value; let contact = new Option(leadName, leadId.toString(), true); $(".txtAutoComplete_organizationid").append(contact); $(".txtAutoComplete_organizationid").val(leadId).trigger("change"); instance.g_IsCreateEstimate = true; instance.changedOrganization(); } let VisibleContainerId = Unibase.Platform.Helpers.NavigationHelper.ModalContainerIds[Unibase.Platform.Helpers.NavigationHelper.ModalContainerIds.length - 1]; let InputParameters = Unibase.Themes.Providers.Detail_Settings.Instance().InputParameters; let InstalledAppId = Unibase.Themes.Providers.DetailHelper.installedAppId; let AppTitle = InputParameters.find(x => x.Key == "hf_" + InstalledAppId + "_apptitle"); if (InputParameters.length > 0 && AppTitle != undefined) { var AppName = InputParameters.find(x => x.Key == "hf_" + InstalledAppId + "_apptitle").Value; if (AppName == "purchaseindent") { var PurchaseIndentId = Number(InputParameters.find(x => x.Key == "hf_" + InstalledAppId + "_purchaseindentid").Value); var hdn_EstimateId = Number($("#" + VisibleContainerId).find(".hdn_estimateid").val()); if (PurchaseIndentId != undefined && hdn_EstimateId == 0) { instance.navigationHelper.showLoading(); instance.g_IsFromPurchaseIndent = true; instance.bindPurchaseIndentDetails(PurchaseIndentId); instance.navigationHelper.hideLoading(); } } } instance.autoCompleteEvents(); instance._estimateItems.itemSettingsEvents(); } checkDefaultCompany() { var instance = this; let companyId = 0; instance.fileCacheHelper.loadJsFile("apps/transact/managers/estimates/estimatemanager.js", function () { Bizgaze.Apps.Transact.Managers.EstimateManager.Instance().getEstimate(Number($(".hdn_estimateid").val())).then(function (response) { if (response.result != null && response.result != "") { companyId = response.result.CompanyId; } else { if (Unibase.Platform.Membership.Infos.Identity.getCurrentUser().settings != null) { let companySetting = Unibase.Platform.Membership.Infos.Identity.getCurrentUser().settings.find(x => x.settingName == "companyid"); if (companySetting != null && companySetting != undefined) { companyId = companySetting.settingValue; instance.g_BranchId = Number(Unibase.Platform.Membership.Infos.Identity.getCurrentUser().settings.find(x => x.settingName == "branchid").settingValue); } else { instance.defaultBranchError(); } } else { instance.defaultBranchError(); } } if (companyId != 0) { let Parameters = [{ "ColumnName": "companyid", "Value": companyId, }]; if (Number($(".hdn_estimateid").val()) > 0) { let LobId = Number(Unibase.Themes.Providers.Detail_Settings.Instance().InputParameters.find(x => x.Key == "hf_" + Unibase.Themes.Providers.DetailHelper.installedAppId + "_lobid").Value); Parameters = [ { "ColumnName": "companyid", "Value": companyId, }, { "ColumnName": "lobid", "Value": LobId, }, ]; } Unibase.Forms.Controls.AutoComplete.Instance().LoadAutoComplete($(".txtAutoComplete_organizationid"), Parameters); } }); }); } defaultBranchError() { $("#Bizgaze-messageInfo").empty(); $(".bizgaze_FormErrorMessages").removeClass("hidden"); $(".txtAutoComplete_organizationid").attr("disabled", "disabled"); $(".btn_Save_Form").addClass("hidden"); Unibase.Platform.Forms.Components.FormViewer.Instance().showError("Please Configure Default Branch"); return false; } changedOrganization() { let instance = this; let g_VisibleContainerId = Unibase.Platform.Helpers.NavigationHelper.ModalContainerIds[Unibase.Platform.Helpers.NavigationHelper.ModalContainerIds.length - 1]; if (!instance.g_IsFromPurchaseIndent) { instance.g_LobId = 0; } if ($(".txtAutoComplete_organizationid").val() == null) { instance.resetAllVariables(); } else { if (Number($(".hdn_estimateid").val()) == 0) { $("#btnDynamicSave").addClass("hidden"); } let leadid = Number($(".txtAutoComplete_organizationid").val()); instance.fileCacheHelper.loadJsFile("apps/transact/managers/estimates/estimatemanager.js", function () { Bizgaze.Apps.Transact.Managers.EstimateManager.Instance().getLeadByLeadId(leadid).then(function (response) { if (response.result != null && response.result != "") { instance.g_IsLead = true; } if (instance.g_EstimateTypeId == Bizgaze.Apps.Transact.Enums.OrderType.SalesEstimate) { if (instance.g_IsLead || instance.g_IsCreateEstimate) { instance.g_IsLead = true; $("#div_FormName").text("Create Sales Estimate (Lead)"); $(".section_CustomerCreditHealth, .section_SalesFrequency").addClass("hidden"); } else if (!instance.g_IsLead) { instance.g_IsLead = false; $("#div_FormName").text("Create Sales Estimate (Organization)"); } } if ($(".txtAutoComplete_organizationid").text() != "Create New") { if (!instance.g_IsFromPurchaseIndent) { $(".CheckOutButton").removeClass('hidden'); $(".section_ContactName").find(".card-body").addClass("hidden"); $(".OrgContact_Details").remove(); instance.prependCustomerLink(); $(".section_ContactName").removeClass("card"); if (instance.g_EstimateTypeId != Bizgaze.Apps.Transact.Enums.OrderType.PurchasePlanning && instance.g_EstimateTypeId != Bizgaze.Apps.Transact.Enums.OrderType.ProductionPlanning) { $("#" + g_VisibleContainerId).find(".section_CartDetails").addClass('d-none'); if (Number($(".hdn_estimateid").val()) == 0) { $("#" + g_VisibleContainerId).find(".section_Summary").addClass('d-none'); } $("#" + g_VisibleContainerId).find(".section_PriceDetails").addClass('d-none'); } else { $("#" + g_VisibleContainerId).find(".section_CartDetails, .section_Summary, .section_PriceDetails, .section_PurchasePlan, .section_Description").removeClass('hidden'); } } else { $(".CheckOutButton").addClass('hidden'); $("#btn_CloseForm").removeClass('mr-auto'); $("#btn_Save, .section_CartDetails, .section_Summary, #dropup_save, #btn_Save_New, .btn_Save_Form, .section_PriceDetails, .section_PurchasePlan").removeClass('hidden'); } $(".section_EstimateDetails").removeClass("hidden"); $(".section_CustomerCreditHealth, .section_SalesFrequency, .section_CustomerOfferSummary").find(".card-body").addClass("hidden"); $(".section_CustomerCreditHealth, .section_SalesFrequency, .section_CustomerOfferSummary").find(".card-body").addClass("hidden"); if (instance.g_EstimateTypeId == Bizgaze.Apps.Transact.Enums.OrderType.PurchaseEstimate || instance.g_EstimateTypeId == Bizgaze.Apps.Transact.Enums.OrderType.PurchaseContract) { $(".section_CustomerCreditHealth").find(".card-header").html(`` + EstimateResponse.result.Notes + `