(function(s,u) { s.add({ uploadExisting: function(data,success,error) { u.post_file(`${this.host}/api/upload/existing/upload`, data, success, error); }, downloadTemplate: function(success, error) { u.get(`${this.host}/api/upload/existing/template`, success, error); } }); })(window.service, window.utility); (function ($, s, u, $scope) { $(function () { $scope.search_grid = u.default_grid("#grdSearchResults", "#grdSearchResultsPager", "Existing Policies Upload", [ "POLICY NO.","FULLNAME", "PHONE", "EMAIL", "POLICY TYPE", "CURRENCY", "VEHICLE USAGE", "CC", "NO. OF SEATS", "VEHICLE REG NO.", "REG. YEAR", "YEAR OF MANUFACTURE", "VEHICLE VALUE", "EXTRA TPPD", "EXCESS", "MAKE-MODEL", "BODY TYPE", "START DATE", "EXPIRY DATE", "BRANCH", "AGENT CODE", "AGENT NAME", "COLOUR", /*"STATUS", "Narration"*/ "Agent Code" ], [ { name: "EP_POLICY_NUMBER", index: "EP_POLICY_NUMBER" }, { name: "EP_FULLNAME", index: "EP_FULLNAME" }, { name: "EP_PHONE", index: "EP_PHONE" }, { name: "EP_EMAIL", index: "EP_EMAIL" }, { name: "EP_POL_TYPE", index: "EP_POL_TYPE" }, { name: "EP_CUR_CODE", index: "EP_CUR_CODE" }, { name: "EP_VEH_USAGE", index: "EP_VEH_USAGE" }, { name: "EP_CC", index: "EP_CC" }, { name: "EP_NO_SEATS", index: "EP_NO_SEATS" }, { name: "EP_VEH_REG_NO", index: "EP_VEH_REG_NO" }, { name: "EP_REG_YEAR", index: "EP_REG_YEAR" }, { name: "EP_YEAR_MANUF", index: "EP_YEAR_MANUF" }, { name: "EP_MAKE", index: "EP_MAKE" }, { name: "EP_BODY_TYPE", index: "EP_BODY_TYPE" }, { name: "EP_START_DATE", index: "EP_START_DATE" }, { name: "EP_END_DATE", index: "EP_END_DATE" }, { name: "EP_BRANCH_CODE", index: "EP_BRANCH_CODE" }, { name: "EP_AGENCY_CODE", index: "EP_AGENCY_CODE" }, { name: "EP_AGENCY_NAME", index: "EP_AGENCY_NAME" }, { name: "EP_COLOR", index: "EP_COLOR" }, { name: "EP_VEHICLE_VALUE", index: "EP_VEHICLE_VALUE" }, { name: "EP_EXTRA_TPPD_AMOUNT", index: "EP_EXTRA_TPPD_AMOUNT" }, { name: "EP_EXCESS", index: "EP_EXCESS" }, { name: "EP_AGENCY_CODE", index: "EP_AGENCY_CODE" } //{ name: "STATUS", index: "STATUS" }, //{ name: "NARRATION", index: "NARRATION" } ]); //onload fetch a listing of the quotes // u.lovDropDown("#PRD_CODE", "getProductLov"); u.set_datepicker(".date"); $scope.index = 0; $("#upload").click(function () { if ($("#file")[0].files && $("#file")[0].files.length > 0) { const formData = new FormData(); formData.append("Existing", $("#file")[0].files[0]); s.uploadExisting(formData, function (result) { u.clear_grid_data($scope.search_grid); if (!result.state) return u.growl_error(result.message); u.bigDataPopulate($scope.search_grid, result.data); return u.growl_success(result.message); //if (result.data && (result.data.success.length > 0 || result.data.error.length > 0)) { // u.clear_grid_data($scope.search_grid); // $scope.index = 0; // for (let i in result.data.success) { // result.data.success[i]["STATUS"] = 1; // result.data.success[i]["NARRATION"] = "SUCCESS"; // result.data.success[i]["ID"] = ++$scope.index; // $scope.search_grid.addRowData($scope.index, result.data.success[i]); // } // for (let i in result.data.error) { // result.data.error[i]["STATUS"] = 0; // result.data.error[i]["NARRATION"] = "VEHICLE ALREADY EXISTS"; // result.data.error[i]["ID"] = ++$scope.index; // $scope.search_grid.addRowData($scope.index, result.data.error[i]); // } // $scope.colorCode(); //} else { // u.growl_info("Couldnt find a ny result for the filters selected"); //} }); } else { u.growl_warning("Please select a files"); } }); $scope.colorCode = function() { const data = u.get_grid_data($scope.search_grid); for (let i in data) { if (data[i]["STATUS"] == 1) { $(`#${data[i]["ID"]}`).css({ color: "green" }); } else { $(`#${data[i]["ID"]}`).css({ color: "red" }); } } } $("#export").click(function () { u.excel_export($scope.search_grid, ["ID"], "Existing Product Upload Excel Report"); }); $("#template").click(() => { s.downloadTemplate(function (result) { if (!result.state) return u.growl_error(result.message); u.downloadFile(`${s.host}/${result.data}`); }); }); }); })(window.jQuery, window.service, window.utility, {})