(function(s,u) { s.add({ getCustomerQuotes: function (phone, success, error) { u.get(this.host + "/api/quote/customer/" + phone, success, error); }, getCustomerPolicies: function (id, success, error) { u.get(this.host + "/api/policy/customer/" + id, success, error); }, getQuotes: function (success, error) { u.get(this.host + "/api/quote", success, error); }, getChannelQuotes: function (filters, success, error) { u.post(this.host + "/api/quote", filters, success, error); }, getPolicies: function (success, error) { u.get(this.host + "/api/policy", success, error); }, getBranchPolicies: function (branch,success, error) { u.get(`${this.host}/api/policy/branch/${branch}`, success, error); }, getChannelPolicies: function (filters, success, error) { u.post(this.host + "/api/policy/channel", filters, success, error); }, getClaimFilter: function (filters, success, error) { u.post(this.host + "/api/claim/filter", filters, success, error); }, getBranchClaimFilter: function (filters, success, error) { u.post(this.host + "/api/claim/branch/filter", filters, success, error); }, getPolicyFilter: function(filters,success,error) { u.post(this.host + "/api/policy/report", filters, success, error); }, getBranchPolicyFilter: function(filters,success,error) { u.post(this.host + "/api/policy/branch/report", filters, success, error); }, getQouteFilter: function (filters, success, error) { u.post(this.host + "/api/quote/report", filters, success, error); }, getUsers: function (success, error) { u.get("https://serene.sibapps.com/authserver/api/account", success, error); }, getAgentKPIs: function (data, success, error) { u.post(this.host + "/api/agent/kpis", data, success, error); }, postPolicyAsync: async function (data) { try { var response = await $.ajax({ url: `https://liveapi.nicmid.com/apiv1/motor_policies`, data: JSON.stringify(data), headers: { "Authorization": `Basic ${btoa("squashie1:zWIVLqfU")}`, "Token": "C7kf1BkVsmcjLHR1FhKfM4WJ" }, type: "POST", contentType: "application/json; charset=utf-8", dataType: "json" }); return { state: true, message: "Success", data: response.motor_policy }; } catch (e) { console.log(e); var resObj = { state: false, status: e.status, message: "Error posting policy", errors: [] }; switch (e.status) { case 0: resObj.message = "Invalid API URL, please check API setup under settings menu."; return resObj; case 404: resObj.message = "Status: 404 - API URL could not be found, please check API setup under settings menu."; return resObj; case 401: resObj.message = "Status: 401 - Invalid API credentials, please check API setup under settings menu."; return resObj; case 400: resObj.message = e.responseJSON.errors[0]; return resObj; default: return { state: false, status: e.status, message: e.statusText, errors: (e.responseJSON || {}).errors || [] }; } } }, updatePolicySticker: function(policyId, sticker, success, error) { u.get(this.host + `/api/policy/updatesticker/${policyId}/${sticker}`, success, error); }, getBrokerPolicies: function(companyCode, success, error) { u.get(this.host + `/api/policy/brokerpolicies/${companyCode}`, success, error); }, searchBrokerPolicies: function(data, success, error) { u.post(this.host + "/api/policy/brokerpolicies/search", data, success, error); }, adminConfirmPolicy: function(policyId, success, error) { u.post(`${this.host}/api/policy/confirm/CONFIRMED/${policyId}`, { email: "" }, success, error); } }); })(window.service,window.utility); (function($,s,u,$scope) { $(function () { u.ses_del("quote_data"); u.ses_del("policy_data"); u.ses_del("policy_billing_info"); //motor - prem $("#quoteGrid").jsGrid({ width: "100%", height: "500px", controller: { loadData: function () { return $scope.gridSearchDAta; } }, inserting: false, //filtering: true, editing: false, sorting: true, paging: true, rowClick: function (args) { $scope.selQuote = args.item; }, fields: [ { title: "Actions", name: "Actions", type: "html", width: 30}, { title: "Date", name: "QH_CRTE_DATE", type: "text", width: 80}, { title: "Customer Name", name: "QH_FULL_NAME", type: "text", width: 150 }, { title: "Cover Type", name: "QH_PRD_NAME", type: "text", width: 80 }, { title: "Premium", name: "QH_PREM", type: "text",width: 60}, { title: "Sum Insured", name: "QH_SI", type: "text", width: 60 }, { title: "Status", name: "QH_TXT_STATE", type: "text", width: 60 }, { title: "Platform", name: "QH_PLATFORM", type: "text", width: 60 }, ] }); $("#policyGrid").jsGrid({ width: "100%", height: "500px", controller: { loadData: function () { return $scope.gridSearchDAta; } }, inserting: false, //filtering: true, editing: false, sorting: true, paging: true, rowClick: function (args) { $scope.selPolicy = args.item; }, fields: [ { title: "Actions", name: "Actions", type: "html", width: 80 }, { title: "Date", name: "PH_CRTE_DATE", type: "text", width: 60 }, { title: "Policy No", name: "PH_POL_NO", type: "text", width: 90 }, { title: "Customer Name", name: "PH_CUST_NAME", type: "text", width: 110 }, { title: "Cover Type", name: "PH_PRD_NAME", type: "text", width: 100 }, { title: "Premium", name: "PH_PREM", type: "text", width: 70 }, { title: "Sum Insured", name: "PH_SI", type: "text", width: 70 }, { title: "Status", name: "STATUS", type: "html", width: 40 }, { title: "Platform", name: "PH_PLATFORM", type: "text", width: 50 }, { title: "STATE", name: "PH_TXT_STATE", type: "html", width: 40, visible: false, css: "hide" } ] }); $("#claimGrid").jsGrid({ width: "100%", height: "500px", controller: { loadData: function () { return $scope.gridSearchDAta; } }, inserting: false, editing: false, sorting: true, paging: true, rowClick: function (args) { $scope.selClaim = args.item; }, fields: [ { title: "Actions", name: "Actions", type: "html", width: 40 }, { title: "Customer Name", name: "PERSON_NAME", type: "text", width:110 }, { title: "Policy Number", name: "POL_NO", type: "text", width: 90 }, { title: "Phone", name: "PERSON_TEL", type: "text", width: 70 }, { title: "Email", name: "PERSON_EMAIL", type: "text", width: 150 }, { title: "Product Name", name: "PRODUCT_NAME", type: "text", width: 100 }, //{ title: "Cover Type", name: "SUB_PROD_NAME", type: "text", width: 90 }, { title: "Date", name: "CLAIM_DATE", type: "text", width: 80 }, { title: "Status", name: "PROC_STATUS", type: "html", width: 120 }, ] }); $("#commissionsGrid").jsGrid({ width: "100%", height: "500px", controller: { loadData: function () { return $scope.gridSearchDAta; } }, inserting: false, editing: false, sorting: true, paging: true, rowClick: function (args) { $scope.selCommissions = args.item; }, fields: [ { title: "Actions", name: "Actions", type: "html", width: 80 }, { title: "Customer Name", name: "PAC_CUST_NAME", type: "text", width: 150 }, { title: "Policy Number", name: "PAC_POL_NO", type: "text", width: 100 }, { title: "Product", name: "PAC_PROD_NAME", type: "text", width: 80 }, { title: "Premium", name: "PAC_TOTAL_PREM", type: "text", width: 80 }, { title: "Commission Perc(%)", name: "PAC_COMM_RATE", type: "text", width: 80 }, { title: "Commission Amount", name: "PAC_COMM_AMNT", type: "text", width: 80 }, { title: "Status", name: "PAC_PAID_YN", type: "html", width: 100 }, ] }); $scope.host = s.host; /*--------------------------- * year drop down population *--------------------------*/ var year = parseInt(u.getYear(u.get_datetime())); for (var i = year; i >= 1945; i--) { $("#YEAR_MANUFACTURE").append(``); } u.email_validation(".email"); /** * datepicker utility to display a datepicker for a input field */ u.set_datepicker_noback(".no-back-date"); u.set_datepicker(".back-date"); u.set_datepicker(".date"); var user = u.ses_get_json("user_info"); s.countryList("#COUNTRY"); //product drop downs $("#PRODUCT").blur(function () { if (!u.field_empty("#PRODUCT")) { $("#RISK_TYPE .removable").remove(); u.lovDropDown("#RISK_TYPE", "getRiskLov", $("#PRODUCT").val()); } switch ($(this).val()) { case "MP01": $("#VEHICAL_VAL").removeAttr("readonly"); $("#VEHICAL_VAL").prop("required", "required"); $("#BUY_BACK_EXCESS").removeAttr("readonly"); $("#BUY_BACK_EXCESS").prop("required", "required"); break; case "MP02": $("#VEHICAL_VAL").prop("readonly", "readonly"); $("#VEHICAL_VAL").removeAttr("required"); $("#VEHICAL_VAL").val(""); $("#BUY_BACK_EXCESS").prop("readonly", "readonly"); $("#BUY_BACK_EXCESS").removeAttr("required"); $("#VEHICAL_VAL").val(""); break; case "MP03": $("#VEHICAL_VAL").removeAttr("readonly"); $("#VEHICAL_VAL").prop("required", "required"); $("#BUY_BACK_EXCESS").removeAttr("readonly"); $("#BUY_BACK_EXCESS").prop("required", "required"); break; default: } }); //dasboard protocols $scope.getCustomerClaims = function() { s.userClaims(u.getUserId(), function(claims) { //clear any quotes that are present. // $("#ClaimTransactions .table-data-row").remove(); //append quotes // $scope.claimAppend("#ClaimTransactions .transaction-table", claims); u.bigDataPopulate($scope.claim_grid, claims) }); }; $scope.getAllClaims = function() { s.getAllClaims(function (claims) { //clear any quotes that are present. //$("#ClaimTransactions .table-data-row").remove(); //append quotes // $scope.claimAppend("#ClaimTransactions .transaction-table", claims); u.bigDataPopulate($scope.claim_grid, claims) }); }; $scope.getBranchClaims = function() { s.getBranchClaims(u.getBranch(),function (claims) { //clear any quotes that are present. // $("#ClaimTransactions .table-data-row").remove(); //append quotes // $scope.claimAppend("#ClaimTransactions .transaction-table", claims); u.bigDataPopulate($scope.claim_grid, claims) }); }; $scope.getCustomerDashboardData = function () { //1. fetch all pending quotes that belong to the logged user with the aid of the users email s.getCustomerQuotes(u.getPhone(), function (result) { //clear any quotes that are present. //$("#QuoteTransactions .table-data-row").remove(); ////append quotes //$scope.quoteAppend("#QuoteTransactions .transaction-table", result); for (let i in result) { result[i].Status = $scope.getQuoteState(result[i].QH_TXT_STATE) } u.bigDataPopulate($scope.quote_grid, result); s.getCustomerPolicies(u.getUserId(), function (policies) { //clear any policies that are present; //$("#PolicyTransactions .table-data-row").remove(); //} u.bigDataPopulate($scope.policy_grid,policies) u.noTick(); }); }); }; $scope.getAdminDashboarData = function() { s.getQuotes(function(result) { //append quotes //$scope.quoteAppend("#QuoteTransactions .transaction-table", result); for (let i in result) { result[i].Status = $scope.getQuoteState(result[i].QH_TXT_STATE) } u.bigDataPopulate($scope.quote_grid, result); s.getPolicies(function (policies) { u.bigDataPopulate($scope.policy_grid, policies); //append policies //$scope.policyAppend("#PolicyTransactions .transaction-table", policies); u.noTick(); }); }); }; $scope.getBranchAdminDashboarData = function() { s.getQuotes(function(result) { //append quotes //$scope.quoteAppend("#QuoteTransactions .transaction-table", result); s.getPolicies(function (result) { }); u.bigDataPopulate($scope.quote_grid, result) s.getBranchPolicies(u.getBranch(),function(policies) { //append policies //$scope.policyAppend("#PolicyTransactions .transaction-table", policies); u.bigDataPopulate($scope.policy_grid, policies); u.noTick(); }); }); }; if (u.isAdmin()) { //display search filters $("#agentCommissionsLink").addClass("m-hide"); $("#kpiLink").removeClass("m-hide"); $(".filters").show(0); $scope.getAdminDashboarData(); $scope.getAllClaims(); //fetch product listing for product dropdowns u.lovDropDown(".product", "getProductLov"); $("#policySearch").click(function () { u.tick("Loading Policy data..."); const formData = u.parse_form("#policyFilters"); formData["CHANNEL"] = u.getChannel(); formData["BRANCH"] = "All"; s.getPolicyFilter(formData, function (policies) { //clear any policies that are present; //$("#PolicyTransactions .table-data-row").remove(); //append policies //$scope.policyAppend("#policyGrid", policies); // $scope.policyAppend("#PolicyTransactions .transaction-table", policies); u.bigDataPopulate($scope.policy_grid, policies) u.noTick(); }); }); $("#quoteSearch").click(function () { u.tick("Loading Quotes data..."); const formData = u.parse_form("#quoteFilters"); //formData["CHANNEL"] = u.getUserChannel(); s.getQouteFilter(formData, function (result) { //clear any quotes that are present. //$("#QuoteTransactions .table-data-row").remove(); //append quotes //$scope.quoteAppend("#quoteGrid", result); for (let i in result) { result[i].Status = $scope.getQuoteState(result[i].QH_TXT_STATE) } u.bigDataPopulate($scope.quote_grid, result); u.noTick(); }); }); $("#claimSearch").click(function () { u.tick("Loading Claims data..."); const formData = u.parse_form("#claimFilters"); //formData["CHANNEL"] = u.getUserChannel(); s.getClaimFilter(formData, function (result) { //clear any quotes that are present. // $("#QuoteTransactions .table-data-row").remove(); //append quotes // $scope.claimAppend("#claimGrid", result); u.bigDataPopulate($scope.commissions_grid, result) u.noTick(); }); }); u.tick("Loading Dashboard data..."); //s.policyAdminAnalytics(function (data) { // $("#motor-num").text(data["MOTOR_NUM"]); // $("#travel-num").text(data["TRAVEL_NUM"]); // $("#home-num").text(data["HOME_NUM"]); // $("#pa-num").text(data["PA_NUM"]); // $("#motor-prem").text(accounting.formatMoney(data["MOTOR_PREM"], " Ghc ", 2, ",", ".")); // $("#travel-prem").text(accounting.formatMoney(data["TRAVEL_PREM"], " Ghc ", 2, ",", ".")); // $("#home-prem").text(accounting.formatMoney(data["HOME_PREM"], " Ghc ", 2, ",", ".")); // $("#pa-prem").text(accounting.formatMoney(data["PA_PREM"], " Ghc ", 2, ",", ".")); // $("#motor-pending").text(accounting.formatMoney(data["MOTOR_PENDING_PREM"], " Ghc ", 2, ",", ".")); // $("#travel-pending").text(accounting.formatMoney(data["TRAVEL_PENDING_PREM"], " Ghc ", 2, ",", ".")); // $("#home-pending").text(accounting.formatMoney(data["HOME_PENDING_PREM"], " Ghc ", 2, ",", ".")); // $("#pa-pending").text(accounting.formatMoney(data["PA_PENDING_PREM"], " Ghc ", 2, ",", ".")); // var data1 = [10000, 5000, 3000, 3000]; // var data2 = [data["MOTOR_PREM"], data["TRAVEL_PREM"], data["HOME_PREM"], data["PA_PREM"]] // // $scope.chartInit(data1, data2); // s.getUsers(function (response) { // if (response && response.length > 0) { // for (let i in response) { // if (response[i].channel === "BRKR" || response[i].channel === "AGT") { // $("#agentId").append(``); // } // } // $("#agentId").selectize(); // } // }); // u.noTick(); //}); } else if (u.isBranchAdmin() || u.isUser()) { //display search filters $(".filters").show(0); $scope.getBranchAdminDashboarData(); $scope.getBranchClaims(); //fetch product listing for product dropdowns u.lovDropDown(".product", "getProductLov"); $("#policySearch").click(function () { u.tick("Loading Policy data..."); const formData = u.parse_form("#policyFilters"); //formData["CHANNEL"] = u.getUserChannel(); formData["BRANCH"] = u.getBranch(); s.getBranchPolicyFilter(formData, function (policies) { //clear any policies that are present; $("#PolicyTransactions .table-data-row").remove(); //append policies $scope.policyAppend("#policyGrid", policies); u.noTick(); }); }); $("#quoteSearch").click(function () { u.tick("Loading Quotes data..."); const formData = u.parse_form("#quoteFilters"); //formData["CHANNEL"] = u.getUserChannel(); s.getQouteFilter(formData, function (result) { //clear any quotes that are present. $("#QuoteTransactions .table-data-row").remove(); //append quotes $scope.quoteAppend("#quoteGrid", result); u.noTick(); }); }); $("#claimSearch").click(function () { u.tick("Loading Claims data..."); const formData = u.parse_form("#claimFilters"); //formData["CHANNEL"] = u.getUserChannel(); formData["BRANCH"] = u.getBranch(); s.getBranchClaimFilter(formData, function (result) { //clear any quotes that are present. $("#QuoteTransactions .table-data-row").remove(); //append quotes $scope.claimAppend("#claimGrid", result); u.noTick(); }); }); u.tick("Loading Dashboard data..."); s.policyBranchAnalytics(u.getBranch(), function (data) { $("#motor-num").text(data["MOTOR_NUM"]); $("#travel-num").text(data["TRAVEL_NUM"]); $("#home-num").text(data["HOME_NUM"]); $("#pa-num").text(data["PA_NUM"]); $("#motor-prem").text(accounting.formatMoney(data["MOTOR_PREM"], " Ghc ", 2, ",", ".")); $("#travel-prem").text(accounting.formatMoney(data["TRAVEL_PREM"], " Ghc ", 2, ",", ".")); $("#home-prem").text(accounting.formatMoney(data["HOME_PREM"], " Ghc ", 2, ",", ".")); $("#pa-prem").text(accounting.formatMoney(data["PA_PREM"], " Ghc ", 2, ",", ".")); $("#motor-pending").text(accounting.formatMoney(data["MOTOR_PENDING_PREM"], " Ghc ", 2, ",", ".")); $("#travel-pending").text(accounting.formatMoney(data["TRAVEL_PENDING_PREM"], " Ghc ", 2, ",", ".")); $("#home-pending").text(accounting.formatMoney(data["HOME_PENDING_PREM"], " Ghc ", 2, ",", ".")); $("#pa-pending").text(accounting.formatMoney(data["PA_PENDING_PREM"], " Ghc ", 2, ",", ".")); u.noTick(); }); } else if (u.isBrokerAdmin()) { $("#agentCommissionsLink").addClass("m-hide"); $(".filters").show(0); u.tick("Loading Dashboard data..."); u.lovDropDown(".product", "getProductLov"); s.getBrokerPolicies(u.getCompany(), function(response) { if (response.state) { u.clear_grid_data($scope.policy_grid); u.grid_populate($scope.policy_grid,"", response.data); } else { u.growl_error(response.message); } }); u.noTick(); $("#policySearch").click(function () { u.tick("Searching..."); const formData = u.parse_form("#policyFilters"); formData["BRANCH"] = u.getCompany(); s.searchBrokerPolicies(formData, function (policies) { u.grid_populate($scope.policy_grid, "", policies.data); }); u.noTick(); }); } else { if (!u.isAgent()) { $("#agentCommissionsLink").addClass("m-hide"); } u.tick("Loading Dashboard data..."); $scope.getCustomerClaims(); $scope.getCustomerDashboardData(); //s.policyClientAnalytics(u.getUserId(), // function(data) { // $("#motor-num").text(data["MOTOR_NUM"]); // $("#travel-num").text(data["TRAVEL_NUM"]); // $("#home-num").text(data["HOME_NUM"]); // $("#pa-num").text(data["PA_NUM"]); // $("#motor-prem").text(accounting.formatMoney(data["MOTOR_PREM"], " Ghc ", 2, ",", ".")); // $("#travel-prem").text(accounting.formatMoney(data["TRAVEL_PREM"], " Ghc ", 2, ",", ".")); // $("#home-prem").text(accounting.formatMoney(data["HOME_PREM"], " Ghc ", 2, ",", ".")); // $("#pa-prem").text(accounting.formatMoney(data["PA_PREM"], " Ghc ", 2, ",", ".")); // $("#motor-pending").text(accounting.formatMoney(data["MOTOR_PENDING_PREM"], " Ghc ", 2, ",", ".")); // $("#travel-pending") // .text(accounting.formatMoney(data["TRAVEL_PENDING_PREM"], " Ghc ", 2, ",", ".")); // $("#home-pending").text(accounting.formatMoney(data["HOME_PENDING_PREM"], " Ghc ", 2, ",", ".")); // $("#pa-pending").text(accounting.formatMoney(data["PA_PENDING_PREM"], " Ghc ", 2, ",", ".")); // }); } $scope.status = { pending: "pending", completed: "completed", canceled: "cancelled" }; $("body").delegate(".btn-pol-confirm", "click", function () { // var policyData = $(this).parents(".table-data-row").data("policyData"); var policyData = $scope.selPolicy; //if (policyData["INS_PAYMENT_LOG"].length > 0) { // u.tick("Checking whether Payment has been made..."); // $scope.payToken = policyData["INS_PAYMENT_LOG"].Last().PL_TOKEN; // //Todo: we need to cjeck the payment status of the policy // //s.checkMMStatus(policyData["INS_PAYMENT_LOG"][0]["PL_TOKEN"], u.getUserId(), policyData["PH_SYS_ID"], function (response) { // s.checkMMStatus($scope.payToken, function (response) { // if (response.state) { // if (response.data.Status == "Success") { // u.growl_success("Payment Successfully processed"); // u.tick("Confirming Policy..."); // s.policyConfirmation("CONFIRMED", $scope.selPolicy["PH_SYS_ID"], "HUBTEL", function (result) { // u.noTick(); // if (!result.state) { // return u.growl_error(result.message || "Error Confirming policy"); // } // $("#pol-no").text(result.PH_POL_NO); // $("#holder").text(policyData["PH_CUST_NAME"]); // $("#end_date").text(policyData["PH_TO_DATE"]); // $("#prem-value").text(`GHS ${policyData.PH_PREM}`); // $("#policySummaryModal").modal(); // if (u.isAdmin()) { // $scope.getAdminDashboarData(); // } else if (u.isBranchAdmin()) { // $scope.getBranchAdminDashboarData(); // } else { // $scope.getCustomerDashboardData(); // } // //let message = `QIC Customer Payment Confirmation SMS \n`; // //message += `Policy Number: ${result.PH_POL_NO} \n`; // //message += `Policy Holder Name: ${$scope.selPolicy["PH_CUST_NAME"]} \n`; // //message += `Policy Type: ${$scope.selPolicy["PH_PRD_NAME"]} \n`; // //message += `Premium: ${$scope.selPolicy["PH_PREM"]} \n`; // //message += `Sum Insured: ${$scope.selPolicy["PH_SI"]} \n`; // //message += `Period of Insurance: ${u.dateFullDate($scope.selPolicy["PH_FROM_DATE"])} - ${u.dateFullDate($scope.selPolicy["PH_TO_DATE"])} \n`; // //s.sendReceipt({ phone: $scope.selPolicy["PH_CUST_PHONE"], message: message }, // // function (response2) { // // $("#confirm-spinner").modal("hide"); // // $("#cash-spinner").hide(0); // // if (response2.state) { // // u.growl_success("Payment Processed successfully, please check your phone for you sms receipt"); // // } // // }, // // function () { // // $("#cash-spinner").hide(0); // // }); // }, // function(err) { // u.noTick(); // return u.growl_error("Error Confirming policy, please contact QIC customer support for further assistance"); // }); // } else { // u.noTick(); // $("#paymentContinue").modal(); // } // } else { // u.growl_error("Error Confirming payment, please try again later"); // } // }); //} else { // u.growl_error("Payment Log does not exist for this Policy"); //} u.tick("Confirming policy, please wait..."); s.adminConfirmPolicy(policyData.PH_SYS_ID, function(response) { u.noTick(); if (!response.state) return u.growl_error(response.message || "Something went wrong, please try again"); $scope.getAdminDashboarData(); }); }); $("#btnPaymentCont").click(function () { // window.location = `https://checkout.hubtel.com/checkout/invoice/${$scope.payToken}`; $("#card-spinner").show(); var policyData = $scope.selPolicy; var paymentLog = policyData["INS_PAYMENT_LOG"].OrderByDescending(l => l.PL_CRTE_DATA).FirstOrDefault(); s.sendInvoiceV2({ amount: parseFloat(paymentLog.PL_AMOUNT), description: ``, policy: policyData.PH_SYS_ID }, function (response) { if (response.state) { //if invoice is successfully created the we will ned to creata a log info //if (response.data.response_code == "00") { console.log(response); s.logPayment({ POL_ID: policyData.PH_SYS_ID, TOKEN: response.data.data.checkoutId, CLIENT_ID: u.getUserId(), DELIV_YN: policyData.PH_DELIV_YN, BRANCH: policyData.PH_DELIV_BRNCH, ADDRESS: policyData.PH_DELIV_ADRS, //PREMIUM: billingInfo["PREMIUM"], REFERRAL: policyData.PH_REFERAL, //EXTRA_PREM: billingInfo["EXTRA_PREM"], PAYMENT_MODE: "HUBTEL" }, function (result) { $("#card-spinner").hide(); console.log(result); if (result.state) { //set local storage to persit the invoice token and user information //store user information in the local storage u.loc_set_json("user_info", u.ses_get_json("user_info")); //set billing data in the local storage u.loc_set_json("billing_info", { CLIENT_ID: policyData.PH_CLIENT_ID || "", DELIV_YN: policyData.PH_DELIV_YN || "", BRANCH: policyData.PH_DELIV_BRNCH || "", ADDRESS: policyData.PH_DELIV_ADRS || "", PREMIUM: policyData.PH_PREM_FC || 0, REFERRAL: policyData.PH_REFERAL || "", EXTRA_PREM: 0, PHONE: policyData.PH_CUST_PHONE || "", FULL_NAME: policyData.PH_CUST_NAME || "", PRODUCT: policyData.PH_PRD_NAME || "", END_DATE: policyData.PH_TO_DATE || "", START_DATE: policyData.PH_FROM_DATE || "" }); //set invoice data in localstorage u.loc_set_json("invoice_info", response.data.data); //redirect user to the checkout portal window.location = response.data.data.checkoutUrl; } else { u.growl_error("Error Logging payment please click on the pay button again"); } }, function () { u.noTick(); }); //} else { // u.growl_error("Unable to create invoice for payment, please try again"); //} } else { $("#card-spinner").hide(); u.growl_error("Error creating payment invoice. Please click on the pay button again"); } }, function () { }); }); $("body").delegate("helle", "click", function () { //find table-row parent and retrieve quote data //var policyData = $(this).parents(".table-data-row").data("policyData"); const policyData = $scope.selPolicy; //store store quote data in session u.ses_set_json("policy_billing_info", { NetPremBc: policyData["PH_PREM"], NetPremFC: policyData["PH_PREM"], ID: policyData["PH_SYS_ID"], STATUS: policyData["PH_STATUS"], START_DATE: policyData["PH_FROM_DATE"], END_DATE: policyData["PH_TO_DATE"], PRODUCT: policyData["PH_PRD_NAME"], FULL_NAME: user["USR_FULL_NAME"] }); //redirect user to the buy policy page window.location = s.app+"Home/completed"; }); $(".btn-pol-schedule").click(function () { var url = ""; //determine which product schedule to show if ($scope.policy["INS_MOTOR_RISK"].length > 0) { url = `${s.host}/PolicySchedule/MotorSchedule/${$scope.policy["PH_SYS_ID"]}`; } else if ($scope.policy["INS_TRAVEL_RISK"].length > 0) { url = `${s.host}/PolicySchedule/TravelSchedule/${$scope.policy["PH_SYS_ID"]}`; } else if ($scope.policy["INS_PA_RISK"].length > 0) { url = `${s.host}/PolicySchedule/PersonalAccidentSchedule/${$scope.policy["PH_SYS_ID"]}`; } else if ($scope.policy["INS_HOME_RISK"].length > 0) { url = `${s.host}/PolicySchedule/HomeOwnersSchedule/${$scope.policy["PH_SYS_ID"]}`; } //alert($scope.host) //alert(url); window.open(url, "_blank", "width=900,height=1000,toolbar=0,menubar=no,status=no,resizable=yes,location=no,directories=no,scrollbars=yes"); }); $("body").delegate(".btn-pol-prnt", "click", function () { //find table-row parent and retrieve quote data //store store quote data in session const url = ""; $(".doc-lnks, .btn-pol-cert").hide(); $scope.policy = $scope.selPolicy; if ($scope.policy["INS_MOTOR_RISK"].length > 0) { $("#policyMotorPrintModal").modal(); $(".motor").show(); $(".btn-pol-cert").show(); return true; } else if ($scope.policy["INS_TRAVEL_RISK"].length > 0) { $("#policyMotorPrintModal").modal(); $(".travel").show(); return true; // } else if ($scope.policy["INS_HOME_RISK"].length > 0) { $("#policyMotorPrintModal").modal(); $(".home").show(); return true; //u } else if ($scope.policy["INS_PA_RISK"].length > 0) { $("#policyMotorPrintModal").modal(); $(".pa").show(); return true; // } window.open(url, "_blank", "width=900,height=1000,toolbar=0,menubar=no,status=no,resizable=yes,location=no,directories=no,scrollbars=yes"); }); $("body").delegate(".btn-pol-edit, .btn-pol-view, .btn-pol-renew, .btn-pol-buy", "click", function () { //find table-row parent and retrieve quote data //store store quote data in session //u.ses_set_json("policy_data", $(this).parents(".table-data-row").data("policyData")); u.ses_set_json("policy_data", $scope.selPolicy); //redirect user to the buy policy page window.location = s.app+"Home/buy_new_policy"; }); $("body").delegate(".btn-pol-cert", "click", function () { //find table-row parent and retrieve quote data //store store quote data in session const url = `${s.host}/PolicySchedule/MotorCertificate/${$scope.policy["PH_SYS_ID"]}`; window.open(url, "_blank", "width=900,height=1000,toolbar=0,menubar=no,status=no,resizable=yes,location=no,directories=no,scrollbars=yes"); }); $("body").delegate(".btn-pol-cert-no-logo", "click", function () { //find table-row parent and retrieve quote data //store store quote data in session const url = `${s.host}/PolicySchedule/MotorCertificateNoLogo/${$scope.policy["PH_SYS_ID"]}`; window.open(url, "_blank", "width=900,height=1000,toolbar=0,menubar=no,status=no,resizable=yes,location=no,directories=no,scrollbars=yes"); }); $("body").delegate(".btn-quote-buy", "click", function () { //find table-row parent and retrieve quote data //store store quote data in session u.ses_set_json("quote_data", $scope.selQuote); //redirect user to the buy policy page window.location = s.app +"Home/buy_new_policy"; }); $("body").delegate(".btn-claim-view", "click", function () { //find table-row parent and retrieve claim data const claim = $scope.selClaim; $("#claimNarration").text(""); $("#claimNarration").text(claim["CLM_DESC"]||"No Narration"); $("#fileListing").find(".file").remove(); const files = claim["INS_CLAIM_DOCS"]; for (let i in files) { $("#fileListing").append(`
`); } //open claim modal to show claim details $("#claimModal").modal(); }); $("#buyNow").click(function() { //store store quote data in session u.ses_set_json("quote_data", $scope.quoteData); //redirect user to the buy policy page window.location = s.app+"Home/buy_new_policy"; }); $("body").delegate(".btn-quote-edit", "click", function () { //find table-row parent and retrieve quote data //var quote = $(this).parents(".table-data-row").data("quoteData"); var quote = $scope.selQuote; $scope.quoteData = quote; //console.log(quote) var quoteData = { FULL_NAME: quote["QH_FULL_NAME"], PHONE_NO: quote["QH_CONTACT_NO"], CURRENCY: quote["QH_CUR_CODE"], EMAIL: quote["QH_EMAIL"], STATUS: quote["QH_STATUS"], ID: quote["QH_SYS_ID"] }; //check the type of quote we have if (quote["INS_MOTOR_QUOTE"].length > 0) { u.tick("Loading Motor Quote..."); u.form_reset("#MotorQuoteForm"); u.lovDropDown("#PRODUCT", "getProductLov", null, function() { //fetch motor products $("#PRODUCT").val(quote["QH_PRD_CODE"]).trigger("change"); u.lovDropDown(".currency", "getCurencyLov", null, function() { //fetch currency u.lovDropDown("#RISK_TYPE", "getRiskLov", $("#PRODUCT").val(), function() { // fetch motor product risks quoteData["PRODUCT"] = quote["QH_PRD_CODE"]; quoteData["END_DATE"] = quote["QH_TO_DATE"]; quoteData["START_DATE"] = quote["QH_FROM_DATE"]; quoteData["VEHICAL_VAL"] = quote["QH_SI"]; quoteData["SEATING_CAPACITY"] = quote["INS_MOTOR_QUOTE"][0]["MQ_NO_SEATS"]; quoteData["YEAR_MANUFACTURE"] = quote["INS_MOTOR_QUOTE"][0]["MQ_MANUF_YEAR"]; quoteData["ADDITIONAL_TTPD"] = quote["INS_MOTOR_QUOTE"][0]["MQ_ADD_TPPD"]; quoteData["RISK_TYPE"] = quote["QH_RSK_CODE"]; quoteData["REGISTRATION_NUMBER"] = quote["INS_MOTOR_QUOTE"][0]["MQ_REG_NO"]; quoteData["CUBIC_CAPCITY"] = quote["INS_MOTOR_QUOTE"][0]["MQ_CC"]; quoteData["BUY_BACK_EXCESS"] = quote["INS_MOTOR_QUOTE"][0]["MQ_BUY_BACK"]; u.fill_form(quoteData, "#MotorQuoteForm"); $("#ADDITIONAL_TTPD_YN").val(quote["INS_MOTOR_QUOTE"][0]["MQ_ADD_TPPD_YN"]).trigger("change"); $("#motorQuoteModal").modal(); u.noTick(); }); }); }); } else if (quote["INS_TRAVEL_QUOTE"].length > 0) { u.tick("Loading Travel Quote..."); u.form_reset("#TravelQuoteForm"); quoteData["OCCUPATION"] = quote["INS_TRAVEL_QUOTE"][0]["TQ_OCCUPATION"]; quoteData["COUNTRY"] = quote["INS_TRAVEL_QUOTE"][0]["TQ_DESTINATION"]; quoteData["TRAVEL_TYPE"] = quote["INS_TRAVEL_QUOTE"][0]["TQ_TRAVEL_TYPE"]; quoteData["DESTINATION_TYPE"] = quote["INS_TRAVEL_QUOTE"][0]["TQ_DESTINATION_TYPE"]; quoteData["START_DATE"] = quote["QH_FROM_DATE"]; quoteData["END_DATE"] = quote["QH_TO_DATE"]; quoteData["PHONE"] = quote["QH_CONTACT_NO"]; quoteData["NO_TRAVELLERS"] = quote["INS_TRAVEL_QUOTE"][0]["TQ_NO_TRAVELING"]; u.lovDropDown("#Currency", "getCurencyLov", null, function() { u.fill_form(quoteData, "#TravelQuoteModal"); u.lovDropDown("#TRAVEL_TYPE", "travlCategoryLov"); u.lovDropDown("#DESTINATION_TYPE", "destinationLov", null, function (result) { $scope.destination_types = result }); $("#travelQuoteModal").modal(); u.noTick(); }); } else if (quote["INS_HOME_QUOTE"].length > 0) { $scope.covers = [] u.tick("Loading Home Owners Quote..."); u.form_reset("#HomeQuoteForm"); quoteData["COVERS"] = quote["INS_HOME_QUOTE"][0]["INS_HOME_QUOTE_COVER"]; quoteData["END_DATE"] = quote["QH_TO_DATE"]; quoteData["START_DATE"] = quote["QH_FROM_DATE"]; quoteData["PHONE_NUMBER"] = quote["QH_CONTACT_NO"]; quoteData["CURRENCY_CODE"] = quote["QH_CUR_CODE"]; quoteData["TOTAL_SI"] = quote["QH_SI"]; //quoteData["HC01"] = quote["INS_HOME_QUOTE"][0]["INS_HOME_QUOTE_COVER"]["HC_COVER_CODE"]; u.lovcheckbox("#COVER_CODE", "getHomeOwnerCovers", "FP01", function (result) { var cover = quoteData["INS_HOME_QUOTE"][0]["INS_HOME_QUOTE_COVER"]; console.log(cover) var coverValue = (quoteData["INS_HOME_QUOTE"][0]["INS_HOME_QUOTE_COVER"]); for (var i = 0; i < cover.length; i++) { debugger if ($(`input[data-cover="${result[i]["CODE"]}"]`).val() == cover[i]["HC_COVER_CODE"]) { $(`input[data-cover="${result[i]["CODE"]}"]`).prop("checked", true) $(`input[data-value="${result[i]["CODE"]}"]`).val(cover[i]["HC_SI"]) $("#buildingLocat").removeAttr("hidden"); $("#buildingDesc").removeAttr("hidden"); $("#buildingLocation").prop("disabled", false); $("#buildingDescription").prop("disabled", false); $("#contentDescription").prop("disabled", false); } } u.lovDropDown(".currency", "getCurencyLov", null, function() { u.fill_form(quoteData, "#HomeQuoteForm"); $("#homeQuoteModal").modal(); u.noTick(); }); }); } else if (quote["INS_PA_QUOTE"].length > 0) { u.tick("Loading Personal Accident Quote..."); u.form_reset("#PersonalAccidentQuoteForm"); //quoteData["COVER_CODE"] = quote["QH_RSK_CODE"]; quoteData["END_DATE"] = quote["QH_TO_DATE"]; quoteData["START_DATE"] = quote["QH_FROM_DATE"]; quoteData["PHONE"] = quote["QH_CONTACT_NO"]; quoteData["SUM_INSURED"] = quote["QH_SI"]; quoteData["WORK_NATURE"] = quote["INS_PA_QUOTE"][0]["PQ_WORK_NATURE"]; //quoteData["CONTENT_SI"] = quote["INS_HOME_QUOTE"][0]["HQ_CONTENT_VAL"]; //quoteData["PL_SI"] = quote["INS_HOME_QUOTE"][0]["HQ_PUB_LIAB_VAL"]; //quoteData["RENT_SI"] = quote["INS_HOME_QUOTE"][0]["HQ_RENT_VAL"]; //quoteData["PA_SI"] = quote["INS_HOME_QUOTE"][0]["HQ_PERS_ACDNT_VAL"]; u.lovDropDown("#currency", "getCurencyLov", null, function () { u.fill_form(quoteData, "#PersonalAccidentQuoteForm"); $("#paQuoteModal").modal(); u.noTick(); }); } }); //motor quote button $("#btnMotorQuote").click(function () { if (u.form_validation("#MotorQuoteForm")) { $("#motor-spinner").modal(); var quoteData = u.parse_form("#MotorQuoteForm"); //console.log(quoteData); s.getMototQuote(quoteData, function (response) { $("#motor-spinner").modal("hide"); if (response.state) { if (user["USR_MSC_CODE"] === "ADM") { $scope.getAdminDashboarData(); } else { $scope.getCustomerDashboardData(); } $("#prem-currency").text(accounting.formatMoney(quoteData["VEHICAL_VAL"], quoteData["CURRENCY"] + " ", 2, ",", ".")); $("#quote-prem-value").text(accounting.formatMoney(response.data.NetPremFC, quoteData["CURRENCY"] + " ", 2, ",", ".")); $("#quotePremiumModal").modal(); //u.form_reset("#MotorQuoteForm"); } else { u.growl_error(response.message); } }, function () { u.growl_error("Server Error"); $("#motor-spinner").modal("hide"); }); } else { u.growl_warning("All fields marked red are required"); } }); //travel quote button $("#btnTravelQuote").click(function () { if (u.form_validation("#TravelQuoteForm")) { $("#motor-spinner").modal(); var quoteData = u.parse_form("#TravelQuoteForm"); //console.log(quoteData); s.getTravelQuote(quoteData, function(response) { $("#motor-spinner").modal("hide"); if (response.state) { if (user["USR_MSC_CODE"] === "ADM") { $scope.getAdminDashboarData(); } else { $scope.getCustomerDashboardData(); } $("#prem-currency").text(accounting.formatMoney(0, quoteData["CURRENCY"] + " ", 2, ",", ".")); $("#quote-prem-value").text(accounting.formatMoney(response.data.NetPremFC, quoteData["CURRENCY"] + " ", 2, ",", ".")); $("#quotePremiumModal").modal(); } else { u.growl_error(response.message); } }, function () { u.growl_error("Server Error"); $("#motor-spinner").modal("hide"); }); } else { u.growl_warning("All fields marked red are required"); } }); //home owners quote button $("#btnHomeQuote").click(function () { if (u.form_validation("#HomeQuoteForm")) { $("#motor-spinner").modal(); var quoteData = u.parse_form("#HomeQuoteForm"); //console.log(quoteData); s.getHomeQuote(quoteData, function(response) { $("#motor-spinner").modal("hide"); if (response.state) { if (user["USR_MSC_CODE"] === "ADM") { $scope.getAdminDashboarData(); } else { $scope.getCustomerDashboardData(); } $("#prem-currency").text(accounting.formatMoney(quoteData["TOTAL_SI"], quoteData["CURRENCY_CODE"] + " ", 2, ",", ".")); $("#quote-prem-value").text(accounting.formatMoney(response.data.NetPremFC, quoteData["CURRENCY_CODE"] + " ", 2, ",", ".")); $("#quotePremiumModal").modal(); } else { u.growl_error(response.message); } }, function () { u.growl_error("Server Error"); $("#motor-spinner").modal("hide"); }); } else { u.growl_warning("All fields marked red are required"); } }); //personal accident quote modal $("#btnPersonalAccidentQuote").click(function () { if (u.form_validation("#PersonalAccidentQuoteForm")) { $("#motor-spinner").modal(); var quoteData = u.parse_form("#PersonalAccidentQuoteForm"); //console.log(quoteData); s.getPersonalAccidentQuote(quoteData, function (response) { $("#motor-spinner").modal("hide"); if (response.state) { if (user["USR_MSC_CODE"] === "ADM") { $scope.getAdminDashboarData(); } else { $scope.getCustomerDashboardData(); } $("#prem-currency").text(accounting.formatMoney(quoteData["SUM_INSURED"], quoteData["CURRENCY"] + " ", 2, ",", ".")); $("#quote-prem-value").text(accounting.formatMoney(response.data.NetPremFC, quoteData["CURRENCY"] + " ", 2, ",", ".")); $("#quotePremiumModal").modal(); } else { u.growl_error(response.message); } }, function () { u.growl_error("Server Error"); $("#motor-spinner").modal("hide"); }); } else { u.growl_warning("All fields marked red are required"); } }); $scope.claimAppend = function (id, data) { $scope.gridSearchDAta = []; $("#quoteGrid").jsGrid("search"); for (let c in data) { data[c]["Actions"] = ""; data[c]["CLAIM_DATE"] = u.dateFormatUk(data[c]["CLAIM_DATE"]); if (user["USR_MSC_CODE"] === "ADM") { } data[c]["PROC_STATUS"] = $scope.claimStatus(data[c]["PROC_STATUS"]); $("#claimGrid").jsGrid("insertItem", data[c]); } // u.clear_grid_data($scope.claim_grid); //data.ForEach(data => { // data["Actions"] = ""; // data["CLAIM_DATE"] = u.dateFormatUk(data["CLAIM_DATE"]); //}); // u.gridPopulate($scope.claim_grid, data); }; $scope.quoteAppend = function (id, data) { $scope.gridSearchDAta = [] $("#quoteGrid").jsGrid("search"); for (let q in data) { //if (user["USR_MSC_CODE"] === "ADM") { //} data[q]["Actions"] = ""; data[q]["QH_CRTE_DATE"] = u.dateFormatUk(data[q]["QH_CRTE_DATE"]); data[q]["QH_PREM"] = accounting.formatMoney(data[q]["QH_PREM"], "Ghc ", 2, ",", "."); data[q]["QH_SI"] = accounting.formatMoney(data[q]["QH_SI"], "Ghc ", 2, ",", "."); data[q]["QH_TXT_STATE"] = $scope.getQuoteState(data[q]["QH_TXT_STATE"]); $("#quoteGrid").jsGrid("insertItem", data[q]); } //u.clear_grid_data($scope.quote_grid); //data.ForEach(data => { // data["Actions"] = ""; // data["QH_CRTE_DATE"] = u.dateFormatUk(data["QH_CRTE_DATE"]); // data["QH_PREM"] = accounting.formatMoney(data["QH_PREM"], "Ghc ", 2, ",", "."); // data["QH_SI"] = accounting.formatMoney(data["QH_SI"], "Ghc ", 2, ",", "."); // data["QH_TXT_STATE"] = $scope.getQuoteState(data["QH_TXT_STATE"]); //}); //u.gridPopulate($scope.quote_grid, data); }; $scope.policyAppend = function (string, data) { var stateClass; //$scope.gridSearchDAta = []; //$("#policyGrid").jsGrid("search"); for (let p in data) { stateClass = data[p]["PH_TXT_STATE"] === "E" ? "active-state " : data[p]["PH_TXT_STATE"] === "L" ? "expired-status " : ""; data[p]["Actions"] = $scope.setPolicyBtn(data[p]["PH_TXT_STATE"], false); data[p]["STATUS"] = `