var Bizgaze; (function (Bizgaze) { let Apps; (function (Apps) { let Transact; (function (Transact) { let Controls; (function (Controls) { class CustomerCreditHealth extends Unibase.Platform.Core.BaseComponent { constructor() { super(...arguments); this.ContainerId = ""; this.PopUpContainerId = ""; } init(formpropertyid, prop, callback) { var instance = this; instance.loadControlSettings(prop.ControlJsonText, prop.FormPropertyId); instance.loadPropertySettings(prop.PropertySettings, prop.FormPropertyId); } loadControl(containerid, prop) { let instance = this; instance.ContainerId = Unibase.Platform.Helpers.NavigationHelper.Instance().getLastContainerId(); let html = instance.getCustomerCreditHealth_html(); $("#" + containerid).html(html); } getCustomerCreditHealth_html() { var html = '
' + '
' + 'Credit Limit
0
' + '
' + ' Avail Limit
0' + '
' + ' Over Due
' + '0
' + '
' + 'Due
0' + '
' + ' Credits
' + ' 0' + '
' + '
Clearance' + '
0' + '
'; return html; } loadControlSettings(controlsettingjson, formpropertyid) { return null; } loadPropertySettings(propertysettings, formpropertyid) { return null; } bindEditFormDetails(formpropertyid, propval, DocPropertyName) { return null; } getCreditHealth(OrgContactId, OrganizationId, Type) { var instance = this; instance.ContainerId = Unibase.Platform.Helpers.NavigationHelper.Instance().getLastContainerId(); let ContactId = Number(OrganizationId == 0 ? OrgContactId : OrganizationId); if (ContactId == 0) { return; } instance.bindKPIEvents(ContactId, Type); instance.getCCH_KPIDetails(OrgContactId, OrganizationId, Type); } bindKPIEvents(ContactId, Type) { let instance = this; let TypeName = "Sales"; if (Type.toLowerCase().indexOf("purchase") != -1) { TypeName = "Purchase"; } instance.fileCacheHelper.loadJsFile("apps/transact/controls/orders/credithealth.js", function () { $("#" + instance.ContainerId).find("#div_Due").unbind().click(function () { Unibase.Platform.Analytics.Managers.ReportManager.Instance().getReportByUniqueId("Bizgaze_Platform_Analytics_Reports_Due_CCH_" + TypeName + "Orders").then(function (res) { if (res.result != null && res.result != "") { var filter = []; filter.push({ "Key": "organizationid", "Value": ContactId.toString(), ExpOp: 1 }); Unibase.Platform.Analytics.Components.ReportViewer.Instance().report_ViewAllByUniqueId("Bizgaze_Platform_Analytics_Reports_Due_CCH_" + TypeName + "Orders", null, filter, null); } else { instance.getKPIPopUp("Due", "div_Due"); instance.getInvoiceDetails(ContactId, "Due"); } }); }); $("#" + instance.ContainerId).find('#div_OverDue').unbind().click(function () { Unibase.Platform.Analytics.Managers.ReportManager.Instance().getReportByUniqueId("Bizgaze_Platform_Analytics_Reports_OverDue_CCH_" + TypeName + "Orders").then(function (res) { if (res.result != null && res.result != "") { var filter = []; filter.push({ "Key": "organizationid", "Value": ContactId.toString(), ExpOp: 1 }); Unibase.Platform.Analytics.Components.ReportViewer.Instance().report_ViewAllByUniqueId("Bizgaze_Platform_Analytics_Reports_OverDue_CCH_" + TypeName + "Orders", null, filter, null); } else { instance.getKPIPopUp("Over Due", "div_Due"); instance.getInvoiceDetails(ContactId, "OverDue"); } }); }); $("#" + instance.ContainerId).find("#div_Credits").unbind().click(function () { Unibase.Platform.Analytics.Managers.ReportManager.Instance().getReportByUniqueId("Bizgaze_Platform_Analytics_Reports_Credits_CCH_" + TypeName + "Orders").then(function (res) { if (res.result != null && res.result != "") { var filter = []; filter.push({ "Key": "organizationid", "Value": ContactId.toString(), ExpOp: 1 }); Unibase.Platform.Analytics.Components.ReportViewer.Instance().report_ViewAllByUniqueId("Bizgaze_Platform_Analytics_Reports_Credits_CCH_" + TypeName + "Orders", null, filter, null); } else { instance.getKPIPopUp("Credits", "div_Credit"); instance.getCreditNotesDetails(ContactId); } }); }); $("#" + instance.ContainerId).find("#div_Clearance").unbind().click(function () { Unibase.Platform.Analytics.Managers.ReportManager.Instance().getReportByUniqueId("Bizgaze_Platform_Analytics_Reports_Clearance_CCH_Orders").then(function (res) { if (res.result != null && res.result != "") { var filter = []; filter.push({ "Key": "organizationid", "Value": ContactId.toString(), ExpOp: 1 }); Unibase.Platform.Analytics.Components.ReportViewer.Instance().report_ViewAllByUniqueId("Bizgaze_Platform_Analytics_Reports_Clearance_CCH_Orders", null, filter, null); } else { instance.getKPIPopUp("Clearance", "div_Clearance"); instance.getPaymentDetails(ContactId); } }); }); }); } getKPIPopUp(WidgetTitle, CurrentDiv) { let instance = this; instance.PopUpContainerId = '_modal_bizgaze_popup_' + moment().unix(); instance.navigationHelper.popup(0, instance.PopUpContainerId, Bizgaze.Apps.Transact.Orders.CreditHealth.Instance(), null, Unibase.Platform.Helpers.Size.ExtraLarge); $("#" + instance.PopUpContainerId).find("." + CurrentDiv).removeClass("hidden"); $("#" + instance.PopUpContainerId).find(".title_widget").text(WidgetTitle); $("#" + instance.PopUpContainerId).find("#widget_list_container").empty(); } noData() { let instance = this; $("#" + instance.PopUpContainerId).find(".header_list").html('
There is no Data
'); $("#" + instance.PopUpContainerId).find(".span_Listsearch_count").text("0"); $("#" + instance.PopUpContainerId).find(".header_list").removeClass("d-none"); } getKPIData(ReportName, OrganizationId, ResultColName, elem) { let instance = this; let resultData = 0; let ReportUniqueId = "Bizgaze_Platform_Analytics_Reports_" + ReportName; let _numberHelper = Unibase.Core.Helpers.NumberHelper.Instance(); Unibase.Platform.Analytics.Managers.ReportManager.Instance().getReportByUniqueId(ReportUniqueId).then(function (res) { if (res.result != null && res.result != "") { var postData = { "ReportId": res.result.ReportId, "page": 1, "pageSize": 20, "Filter": [], "FilterId": 0, "InputParameters": [ { "Key": "organizationid", "Value": OrganizationId.toString(), "ExpOp": 1 } ], "SearchTerm": null, "DateFilter": null, "DisplayModeTypeId": 1, "FromDate": "", "ToDate": "", "IsPortletWidget": false, "IsShowAll": false, "SortColumn": "" }; Unibase.Platform.Analytics.Managers.ReportManager.Instance().getReportInfo(postData).then(function (report_res) { if (report_res.result != null) { if (report_res.result.ReportJsonData.Result.Data != null && report_res.result.ReportJsonData.Result.Data != "") { let val = JSON.parse(report_res.result.ReportJsonData.Result.Data); resultData = _numberHelper.roundNumber(val[0][ResultColName].toString().replace(/,/g, ''), 2); if (resultData != null && resultData != undefined) { resultData = resultData.replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1,"); } $("#" + instance.ContainerId).find("#" + elem).text(resultData); } } if (resultData == 0) { $("#" + instance.ContainerId).find("#" + elem).text("0.00"); } }); } }); } getCCH_KPIDetails(OrgContactId, OrganizationId, Type) { let instance = this; let TypeName = "Sales"; let CreditLimit = 0; let AvailLimit = 0; let OverDue = 0; let Due = 0; let Credits = 0; let ClearanceAmount = 0; Bizgaze.Apps.Transact.Managers.OrderManager.Instance().getCustomerCreditHealth(OrgContactId, OrganizationId).then(function (response) { let data = response.result; let _numberHelper = Unibase.Core.Helpers.NumberHelper.Instance(); if (data != "" && data != null) { CreditLimit = _numberHelper.roundNumber(data.CreditLimit, 2); AvailLimit = _numberHelper.roundNumber(data.AvailLimit, 2); OverDue = _numberHelper.roundNumber(data.OverDue, 2); Due = _numberHelper.roundNumber(data.OutStandingAmount, 2); Credits = _numberHelper.roundNumber(data.Credits, 2); ClearanceAmount = _numberHelper.roundNumber(data.ClearanceAmount, 2); $("#" + instance.ContainerId).find("#span_CreditLimit").text(CreditLimit); $("#" + instance.ContainerId).find("#span_AvailLimit").text(AvailLimit); $("#" + instance.ContainerId).find("#span_OverDue").text(OverDue); $("#" + instance.ContainerId).find("#span_Due").text(Due); $("#" + instance.ContainerId).find("#span_Credits").text(Credits); $("#" + instance.ContainerId).find("#span_Clearance").text(ClearanceAmount); } if (Type.toLowerCase().indexOf("purchase") != -1) { TypeName = "Purchase"; } instance.getKPIData("CreditLimit_CCH_OrdersKPIWidget", OrganizationId, "creditlimit", "span_CreditLimit"); instance.getKPIData("AvailLimit_CCH_OrdersKPIWidget", OrganizationId, "availlimit", "span_AvailLimit"); instance.getKPIData("OverDue_CCH_" + TypeName + "OrdersKPIWidget", OrganizationId, "overdue", "span_OverDue"); instance.getKPIData("DueAmount_CCH_" + TypeName + "OrdersKPIWidget", OrganizationId, "outstandingamount", "span_Due"); instance.getKPIData("Credits_CCH_" + TypeName + "OrdersKPIWidget", OrganizationId, "credits", "span_Credits"); instance.getKPIData("ClearanceAmount_CCH_OrdersKPIWidget", OrganizationId, "clearanceamount", "span_Clearance"); }); } getInvoiceDetails(ContactId, DueorOverDue) { let instance = this; let IsOverDue = false; if (DueorOverDue == "OverDue") { IsOverDue = true; } Bizgaze.Apps.Transact.Managers.InvoiceManager.Instance().getPendingSalesInvoicesByContactId(ContactId, IsOverDue).then(function (response) { var PendingInvoices = response.result; if (PendingInvoices == "") { instance.noData(); } else { var CurrentDate = new Date(), IsExpired = false, html = ''; $("#" + instance.PopUpContainerId).find("#widget_list_container").html(''); for (var i = 0; i < PendingInvoices.length; i++) { var InvoiceItem = PendingInvoices[i]; var Amount = InvoiceItem.TotalAmount; var DueDate = new Date(InvoiceItem.DueDate); var PaidAmount = Number(InvoiceItem.PaidAmount); var DueAmount = Number(InvoiceItem.TotalAmount) - Number(InvoiceItem.PaidAmount); if (DueDate < CurrentDate) { IsExpired = true; } html += '
  • ' + InvoiceItem.InvoiceNo + ' (' + InvoiceItem.LobShortCode + ')
    ' + Unibase.Platform.Helpers.DateTimeHelper.Instance().formatLocalDate(InvoiceItem.InvoiceDate) + '
    ' + Unibase.Platform.Helpers.DateTimeHelper.Instance().formatLocalDateformat(InvoiceItem.RefDate, 'DD MMM YYYY') + '
    ' + InvoiceItem.RefNo + '
    ' + Unibase.Platform.Helpers.DateTimeHelper.Instance().formatLocalDateformat(DueDate, 'DD MMM YYYY') + '
    ' + Unibase.Platform.Helpers.DateTimeHelper.Instance().daysFromNow(InvoiceItem.InvoiceDate) + ' Days ago
    ' + Amount + '
    ' + PaidAmount + '
    ' + Unibase.Core.Helpers.NumberHelper.Instance().roundNumber(DueAmount, 2) + '
  • ' + InvoiceItem.InvoiceNo + ' (' + InvoiceItem.LobShortCode + ')
    ' + Unibase.Platform.Helpers.DateTimeHelper.Instance().formatLocalDate(InvoiceItem.InvoiceDate) + '
  • '; } $("#" + instance.PopUpContainerId).find(".span_Listsearch_count").text(PendingInvoices.length); if (DueorOverDue == "Due" || (DueorOverDue == "OverDue" && IsExpired == true)) { $("#" + instance.PopUpContainerId).find(".list-Report-Due:last").after(html); } else { instance.noData(); } } }); } getPaymentDetails(ContactId) { let instance = this; Bizgaze.Apps.Transact.Managers.PaymentManager.Instance().getAllPendingPayments(ContactId).then(function (response) { var PendingPayments = response.result; if (PendingPayments == "") { instance.noData(); } else { $("#" + instance.PopUpContainerId).find("#widget_list_container").html(''); var html = ''; for (var i = 0; i < PendingPayments.length; i++) { var PaymentItem = PendingPayments[i]; var CreatedDate = new Date(PaymentItem.CreatedDate); var currdate = new Date(); var diff = new Date(currdate - CreatedDate); var days = Unibase.Core.Helpers.NumberHelper.Instance().roundNumber(diff / 1000 / 60 / 60 / 24, 2); html += '
  • ' + PaymentItem.PaymentNo + ' (' + PaymentItem.RefNo + ')
    ' + Unibase.Platform.Helpers.DateTimeHelper.Instance().formatLocalDate(PaymentItem.PaymentDate) + '
    ' + Unibase.Platform.Helpers.DateTimeHelper.Instance().formatLocalDateformat(PaymentItem.CreatedDate, 'DD MMM YYYY') + '
    ' + PaymentItem.ContactName + '
    ' + days + '
    ' + PaymentItem.TotalAmount + '
    ' + PaymentItem.StageName + '
  • '; } $("#" + instance.PopUpContainerId).find(".list-Report-Clearance:last").after(html); $("#" + instance.PopUpContainerId).find(".span_Listsearch_count").text(PendingPayments.length); } }); } getCreditNotesDetails(ContactId) { var instance = this; Bizgaze.Apps.Transact.Managers.InvoiceManager.Instance().getCreditNotesByContactId(ContactId).then(function (response) { var CreditNotes = response.result; if (CreditNotes.length != 0) { $("#" + instance.PopUpContainerId).find("#widget_list_container").html(''); var html = ''; for (var i = 0; i < CreditNotes.length; i++) { var CreditNoteItem = CreditNotes[i]; var ConsumedAmount = CreditNoteItem.PaidAmount; var TotalAmount = CreditNoteItem.TotalAmount; var RemainingCredit = Number(CreditNoteItem.TotalAmount) - Number(CreditNoteItem.PaidAmount); var html = '
  • ' + CreditNoteItem.InvoiceNo + ' (' + CreditNoteItem.LobShortCode + ')
    ' + Unibase.Platform.Helpers.DateTimeHelper.Instance().formatLocalDateformat(CreditNoteItem.InvoiceDate, 'DD MMM YYYY') + '
    ' + CreditNoteItem.RefNo + '
    ' + Unibase.Platform.Helpers.DateTimeHelper.Instance().formatLocalDateformat(CreditNoteItem.RefDate, 'DD MMM YYYY') + '
    ' + TotalAmount + '
    ' + ConsumedAmount + '
    ' + RemainingCredit + '
    ' + CreditNoteItem.InvoiceNo + ' (' + CreditNoteItem.LobShortCode + ')
    ' + Unibase.Platform.Helpers.DateTimeHelper.Instance().formatLocalDateformat(CreditNoteItem.InvoiceDate, 'DD MMM YYYY') + '
    • Total
    • ' + TotalAmount + '
    • Consumed
    • ' + ConsumedAmount + '
    • Remaining
    • ' + RemainingCredit + '
  • '; $("#" + instance.PopUpContainerId).find(".list-Report-Credits:last").after(html); } } $("#" + instance.PopUpContainerId).find(".span_Listsearch_count").text(CreditNotes.length); if (CreditNotes.length == 0 || CreditNotes == "") { $("#" + instance.PopUpContainerId).find(".header_list").removeClass("d-md-block").addClass("d-none"); } instance.getAdvancePayments(ContactId, CreditNotes.length); }); } getAdvancePayments(ContactId, CreditsCount) { let instance = this; Bizgaze.Apps.Transact.Managers.PaymentManager.Instance().getAdvancePaymentsByOrgId(ContactId).then(function (response) { var AdvancePayments = response.result; $("#" + instance.PopUpContainerId).find("#widget_list_container").append('
    Advance Payments
    '); if (AdvancePayments != "") { var advancepaymentcount = AdvancePayments.length; $(".advacepayment_Listsearch_count").html(advancepaymentcount); if (AdvancePayments.length == 0 && CreditsCount == 0) { instance.noData(); $(".card-advancePayments").addClass("d-none"); } for (var i = 0; i < AdvancePayments.length; i++) { var AdvancePaymentItem = AdvancePayments[i]; var ConsumedAmount = AdvancePaymentItem.AdjustedAmount; var TotalAmount = AdvancePaymentItem.TotalAmount; var RemainingCredit = Number(AdvancePaymentItem.TotalAmount) - Number(AdvancePaymentItem.AdjustedAmount); var ExpTextColor = "text-info"; var html = '
  • ' + AdvancePaymentItem.PaymentNo + '
    ' + Unibase.Platform.Helpers.DateTimeHelper.Instance().formatLocalDateformat(AdvancePaymentItem.PaymentDate, 'DD MMM YYYY') + '
    ' + Unibase.Platform.Helpers.DateTimeHelper.Instance().daysFromNow(AdvancePaymentItem.PaymentDate) + ' days ago
    ' + TotalAmount + '
    ' + ConsumedAmount + '
    ' + RemainingCredit + '
    ' + AdvancePaymentItem.PaymentNo + '
    ' + Unibase.Platform.Helpers.DateTimeHelper.Instance().formatLocalDateformat(AdvancePaymentItem.PaymentDate, 'DD MMM YYYY') + '
    • Total
    • ' + TotalAmount + '
    • Consumed
    • ' + ConsumedAmount + '
    • Remaining
    • ' + RemainingCredit + '
  • '; $("#" + instance.PopUpContainerId).find(".list-Report-Payments:last").after(html); } $("#" + instance.PopUpContainerId).find(".span_Listsearch_count").text(CreditsCount + AdvancePayments.length); } else { instance.noData(); } }); } static Instance() { if (this.instance === undefined) { this.instance = new CustomerCreditHealth(); } return this.instance; } } Controls.CustomerCreditHealth = CustomerCreditHealth; })(Controls = Transact.Controls || (Transact.Controls = {})); })(Transact = Apps.Transact || (Apps.Transact = {})); })(Apps = Bizgaze.Apps || (Bizgaze.Apps = {})); })(Bizgaze || (Bizgaze = {}));