From 898acb376e133a7b9a9bb2375cc09bacedb55b9f Mon Sep 17 00:00:00 2001 From: Muhammed Tareq Aziz Date: Tue, 4 Oct 2016 18:40:08 +0600 Subject: [PATCH] need to re order the excel columns --- calculate.js | 79 ++++++++++++---------- excelCreator.js | 175 +++++++++++++++++++++++++++++------------------- utility.js | 20 ++++++ 3 files changed, 170 insertions(+), 104 deletions(-) diff --git a/calculate.js b/calculate.js index 62c5fd2..2473548 100644 --- a/calculate.js +++ b/calculate.js @@ -54,21 +54,28 @@ module.exports = { }, detailsReport: function (report, job) { - var moment = require('moment'); + var utility = require('./utility'); var entry = {}; entry.trackingNumber = job.HRID entry.DeliveryType = job.Order.Type; - entry.OrderingDate = moment(job.CreateTime).format('LL'); - entry.OrderingTime = moment(job.CreateTime).format('LT'); + entry.Status = job.State; + entry.PaymentStatus = job.PaymentStatus; + + entry.OrderingDate = utility.getDate(job.CreateTime); + entry.OrderingTime = utility.getTime(job.CreateTime); - entry.CompletionETADate = moment(job.ETA).format('LL'); - entry.CompletionETATime = moment(job.ETA).format('LT'); + entry.CompletionETADate = "Not Completed"; + entry.CompletionETATime = "Not Completed"; + if (job.Order.ETA !== undefined) { + entry.CompletionETADate = utility.getDate(job.ETA); + entry.CompletionETATime = utility.getTime(job.ETA); + } - entry.CompleteDate = moment(job.CompletionTime).format('LL'); - entry.CompleteTime = moment(job.CompletionTime).format('LT'); + entry.CompleteDate = utility.getDate(job.CompletionTime); + entry.CompleteTime = utility.getTime(job.CompletionTime); // User, DeliveryMan info entry.ClientType = utility.getClientType(job.User.Type); @@ -90,78 +97,78 @@ module.exports = { entry.DeliveryCharge = job.Order.OrderCart.ServiceCharge; entry.VAT = job.Order.OrderCart.TotalVATAmount; entry.Total = job.Order.OrderCart.TotalToPay; + entry.SpecialNote = job.Order.NoteToDeliveryMan; // Pickup Info entry.PickupStatus = job.Tasks[1].State; - entry.PickupETADate = "Not Mentioned"; + entry.PickupETADate; entry.PickupETATime = "Not Mentioned"; if (job.Order.JobTaskETAPreference !== undefined && job.Order.JobTaskETAPreference.length > 0) { var pickupEta = utility.getJobTaskPreferenceETA("PackagePickUp" ,job.Order.JobTaskETAPreference); if (pickupEta) { - entry.PickupETADate = moment(pickupEta.ETA).format('LL'); - entry.PickupETATime = moment(pickupEta.ETA).format('LT'); + entry.PickupETADate = utility.getDate(pickupEta.ETA); + entry.PickupETATime = utility.getTime(pickupEta.ETA); } } - entry.PickupStartDate = moment(job.Tasks[1].Started).format('LL'); - entry.PickupStartTime = moment(job.Tasks[1].Started).format('LT'); - entry.PickupCompleteDate = moment(job.Tasks[1].Completed).format('LL'); - entry.PickupCompleteTime = moment(job.Tasks[1].Completed).format('LT'); - entry.TotalPickUpTime = moment.duration(moment(job.Tasks[1].Started).diff(moment(job.Tasks[1].Completed))).asHours(); + entry.PickupStartDate = utility.getDate(job.Tasks[1].InitiationTime); + entry.PickupStartTime = utility.getTime(job.Tasks[1].InitiationTime); + entry.PickupCompleteDate = utility.getDate(job.Tasks[1].CompletionTime); + entry.PickupCompleteTime = utility.getTime(job.Tasks[1].CompletionTime); + entry.TotalPickUpTime = utility.getHoursDifference(job.Tasks[1].InitiationTime, job.Tasks[1].CompletionTime); // Delivery Info entry.DeliveryStatus = job.Tasks[2].State; - entry.DeliveryETADate = "Not Mentioned"; + entry.DeliveryETADate; entry.DeliveryETATime = "Not Mentioned"; if (job.Order.JobTaskETAPreference !== undefined && job.Order.JobTaskETAPreference.length > 0) { var deliveryEta = utility.getJobTaskPreferenceETA("Delivery" ,job.Order.JobTaskETAPreference); if (deliveryEta) { - entry.DeliveryETADate = moment(deliveryEta.ETA).format('LL'); - entry.DeliveryETATime = moment(deliveryEta.ETA).format('LT'); + entry.DeliveryETADate = utility.getDate(deliveryEta.ETA); + entry.DeliveryETATime = utility.getTime(deliveryEta.ETA); } } - entry.DeliveryStartDate = moment(job.Tasks[2].Started).format('LL'); - entry.DeliveryStartTime = moment(job.Tasks[2].Started).format('LT'); - entry.DeliveryCompleteDate = moment(job.Tasks[2].Completed).format('LL'); - entry.DeliveryCompleteTime = moment(job.Tasks[2].Completed).format('LT'); - entry.TotalDeliveryTime = moment.duration(moment(job.Tasks[2].Started).diff(moment(job.Tasks[2].Completed))).asHours(); + entry.DeliveryStartDate = utility.getDate(job.Tasks[2].InitiationTime); + entry.DeliveryStartTime = utility.getTime(job.Tasks[2].InitiationTime); + entry.DeliveryCompleteDate = utility.getDate(job.Tasks[2].CompletionTime); + entry.DeliveryCompleteTime = utility.getTime(job.Tasks[2].CompletionTime); + entry.TotalDeliveryTime = utility.getHoursDifference(job.Tasks[2].InitiationTime, job.Tasks[2].CompletionTime); // Cash Delivery Info entry.CashDeliveryStatus = "Not Applicable"; - entry.CashDeliveryStartDate = "Not Applicable"; + entry.CashDeliveryStartDate; entry.CashDeliveryStartTime = "Not Applicable"; - entry.CashDeliveryCompleteDate = "Not Applicable"; + entry.CashDeliveryCompleteDate; entry.CashDeliveryCompleteTime = "Not Applicable"; entry.TotalCashDeliveryTime = "Not Applicable"; - entry.CashDeliveryETADate = "Not Applicable"; + entry.CashDeliveryETADate; entry.CashDeliveryETATime = "Not Applicable"; if (job.Tasks[3]) { entry.CashDeliveryStatus = job.Tasks[3].State; - entry.CashDeliveryETADate = "Not Mentioned"; + entry.CashDeliveryETADate; entry.CashDeliveryETATime = "Not Mentioned"; if (job.Order.JobTaskETAPreference !== undefined && job.Order.JobTaskETAPreference.length > 0) { var cashDeliveryEta = utility.getJobTaskPreferenceETA("SecureCashDelivery" ,job.Order.JobTaskETAPreference); if (cashDeliveryEta) { - entry.CashDeliveryETADate = moment(cashDeliveryEta.ETA).format('LL'); - entry.CashDeliveryETATime = moment(cashDeliveryEta.ETA).format('LT'); + entry.CashDeliveryETADate = utility.getDate(cashDeliveryEta.ETA); + entry.CashDeliveryETATime = utility.getTime(cashDeliveryEta.ETA); } } - entry.CashDeliveryStartDate = moment(job.Tasks[3].Started).format('LL'); - entry.CashDeliveryStartTime = moment(job.Tasks[3].Started).format('LT'); - entry.CashDeliveryCompleteDate = moment(job.Tasks[3].Completed).format('LL'); - entry.CashDeliveryCompleteTime = moment(job.Tasks[3].Completed).format('LT'); - entry.TotalCashDeliveryTime = moment.duration(moment(job.Tasks[3].Started).diff(moment(job.Tasks[3].Completed))).asHours(); + entry.CashDeliveryStartDate = utility.getDate(job.Tasks[3].InitiationTime); + entry.CashDeliveryStartTime = utility.getTime(job.Tasks[3].InitiationTime); + entry.CashDeliveryCompleteDate = utility.getDate(job.Tasks[3].CompletionTime); + entry.CashDeliveryCompleteTime = utility.getTime(job.Tasks[3].CompletionTime); + entry.TotalCashDeliveryTime = utility.getHoursDifference(job.Tasks[3].InitiationTime, job.Tasks[3].CompletionTime); } - entry.Status = job.State; - entry.PaymentStatus = job.PaymentStatus; + entry.VendorInvoiceNo = null; entry.Commission = null; diff --git a/excelCreator.js b/excelCreator.js index 8f90310..996ce83 100644 --- a/excelCreator.js +++ b/excelCreator.js @@ -42,82 +42,121 @@ module.exports = { var reportFileName = directoryName + workbookName; var workbook = excelbuilder.createWorkbook(directoryName, workbookName); - var sheet1 = workbook.createSheet('sheet1', 34, report.length); + var sheet1 = workbook.createSheet('sheet1', 55, report.length); - sheet1.set(1, 1, 'TrackingNumber'); - sheet1.set(2, 1, 'Client'); + sheet1.set(1, 1, 'trackingNumber'); + sheet1.set(2, 1, 'DeliveryType'); sheet1.set(3, 1, 'OrderingDate'); sheet1.set(4, 1, 'OrderingTime'); - sheet1.set(5, 1, 'DeliveryDate'); - sheet1.set(6, 1, 'DeliveryType'); - sheet1.set(7, 1, 'UserName'); - sheet1.set(8, 1, 'UserPhone'); - sheet1.set(9, 1, 'PickupAddress'); - sheet1.set(10, 1, 'PickupArea'); - sheet1.set(11, 1, 'DeliveryAddress'); - sheet1.set(12, 1, 'DeliveryArea'); - sheet1.set(13, 1, 'Product'); - sheet1.set(14, 1, 'Weight'); - sheet1.set(15, 1, 'TotalProductPrice'); - sheet1.set(16, 1, 'DeliveryCharge'); - sheet1.set(17, 1, 'VAT'); - sheet1.set(18, 1, 'Total'); - sheet1.set(19, 1, 'DeliveryPerson'); - sheet1.set(20, 1, 'PickupStartDate'); - sheet1.set(21, 1, 'PickupStartTime'); - sheet1.set(22, 1, 'PickupCompleteDate'); - sheet1.set(23, 1, 'PickupCompleteTime'); - sheet1.set(24, 1, 'DeliveryStartTime'); - sheet1.set(25, 1, 'DeliveryCompleteTime'); - sheet1.set(26, 1, 'TotalDeliveryTime'); - sheet1.set(27, 1, 'Status'); - sheet1.set(28, 1, 'PaymentStatus'); - sheet1.set(29, 1, 'VendorInvoiceNo'); - sheet1.set(30, 1, 'Commission'); - sheet1.set(31, 1, 'CashRecieved'); - sheet1.set(32, 1, 'KM'); - sheet1.set(33, 1, 'ProductType'); - sheet1.set(34, 1, 'Comment'); + sheet1.set(5, 1, 'CompletionETADate'); + sheet1.set(6, 1, 'CompletionETATime'); + sheet1.set(7, 1, 'CompleteDate'); + sheet1.set(8, 1, 'CompleteTime'); + sheet1.set(9, 1, 'ClientType'); + sheet1.set(10, 1, 'UserName'); + sheet1.set(11, 1, 'UserPhone'); + sheet1.set(12, 1, 'DeliveryPerson'); + sheet1.set(13, 1, 'PickupAddress'); + sheet1.set(14, 1, 'PickupArea'); + sheet1.set(15, 1, 'DeliveryAddress'); + sheet1.set(16, 1, 'DeliveryArea'); + sheet1.set(17, 1, 'ProductDescription'); + sheet1.set(18, 1, 'Product'); + sheet1.set(19, 1, 'Weight'); + sheet1.set(20, 1, 'TotalProductPrice'); + sheet1.set(21, 1, 'DeliveryCharge'); + sheet1.set(22, 1, 'VAT'); + sheet1.set(23, 1, 'Total'); + sheet1.set(24, 1, 'PickupStatus'); + sheet1.set(25, 1, 'PickupETADate'); + sheet1.set(26, 1, 'PickupETATime'); + sheet1.set(27, 1, 'PickupStartDate'); + sheet1.set(28, 1, 'PickupStartTime'); + sheet1.set(29, 1, 'PickupCompleteDate'); + sheet1.set(30, 1, 'PickupCompleteTime'); + sheet1.set(31, 1, 'TotalPickUpTime'); + sheet1.set(32, 1, 'DeliveryStatus'); + sheet1.set(33, 1, 'DeliveryETADate'); + sheet1.set(34, 1, 'DeliveryETATime'); + sheet1.set(35, 1, 'DeliveryStartDate'); + sheet1.set(36, 1, 'DeliveryStartTime'); + sheet1.set(37, 1, 'DeliveryCompleteDate'); + sheet1.set(38, 1, 'DeliveryCompleteTime'); + sheet1.set(39, 1, 'TotalDeliveryTime'); + sheet1.set(40, 1, 'CashDeliveryStatus'); + sheet1.set(41, 1, 'CashDeliveryStartDate'); + sheet1.set(42, 1, 'CashDeliveryStartTime'); + sheet1.set(43, 1, 'CashDeliveryCompleteDate'); + sheet1.set(44, 1, 'CashDeliveryCompleteTime'); + sheet1.set(45, 1, 'TotalCashDeliveryTime'); + sheet1.set(46, 1, 'CashDeliveryETADate'); + sheet1.set(47, 1, 'CashDeliveryETATime'); + sheet1.set(48, 1, 'Status'); + sheet1.set(49, 1, 'PaymentStatus'); + sheet1.set(50, 1, 'VendorInvoiceNo'); + sheet1.set(51, 1, 'Commission'); + sheet1.set(52, 1, 'CashRecieved'); + sheet1.set(53, 1, 'KM'); + sheet1.set(54, 1, 'ProductType'); + sheet1.set(55, 1, 'Comment'); for (var row = 2; row < report.length; row++) { - var e = report[row-2]; - - console.log(row-2) - + var e = report[row-2]; sheet1.set(1, row, e.trackingNumber); - sheet1.set(2, row, e.Client); + sheet1.set(2, row, e.DeliveryType); sheet1.set(3, row, e.OrderingDate); sheet1.set(4, row, e.OrderingTime); - sheet1.set(5, row, e.DeliveryDate); - sheet1.set(6, row, e.DeliveryType); - sheet1.set(7, row, e.UserName); - sheet1.set(8, row, e.UserPhone); - sheet1.set(9, row, e.PickupAddress); - sheet1.set(10, row, e.PickupArea); - sheet1.set(11, row, e.DeliveryAddress); - sheet1.set(12, row, e.DeliveryArea); - sheet1.set(13, row, e.Product); - sheet1.set(14, row, e.Weight); - sheet1.set(15, row, e.TotalProductPrice); - sheet1.set(16, row, e.DeliveryCharge); - sheet1.set(17, row, e.VAT); - sheet1.set(18, row, e.Total); - sheet1.set(19, row, e.DeliveryPerson); - sheet1.set(20, row, e.PickupStartDate); - sheet1.set(21, row, e.PickupStartTime); - sheet1.set(22, row, e.PickupCompleteDate); - sheet1.set(23, row, e.PickupCompleteTime); - sheet1.set(24, row, e.DeliveryStartTime); - sheet1.set(25, row, e.DeliveryCompleteTime); - sheet1.set(26, row, e.TotalDeliveryTime); - sheet1.set(27, row, e.Status); - sheet1.set(28, row, e.PaymentStatus); - sheet1.set(29, row, e.VendorInvoiceNo); - sheet1.set(30, row, e.Commission); - sheet1.set(31, row, e.CashRecieved); - sheet1.set(32, row, e.KM); - sheet1.set(33, row, e.ProductType); - sheet1.set(34, row, e.Comment); + sheet1.set(5, row, e.CompletionETADate); + sheet1.set(6, row, e.CompletionETATime); + sheet1.set(7, row, e.CompleteDate); + sheet1.set(8, row, e.CompleteTime); + sheet1.set(9, row, e.ClientType); + sheet1.set(10, row, e.UserName); + sheet1.set(11, row, e.UserPhone); + sheet1.set(12, row, e.DeliveryPerson); + sheet1.set(13, row, e.PickupAddress); + sheet1.set(14, row, e.PickupArea); + sheet1.set(15, row, e.DeliveryAddress); + sheet1.set(16, row, e.DeliveryArea); + sheet1.set(17, row, e.ProductDescription); + sheet1.set(18, row, e.Product); + sheet1.set(19, row, e.Weight); + sheet1.set(20, row, e.TotalProductPrice); + sheet1.set(21, row, e.DeliveryCharge); + sheet1.set(22, row, e.VAT); + sheet1.set(23, row, e.Total); + sheet1.set(24, row, e.PickupStatus); + sheet1.set(25, row, e.PickupETADate); + sheet1.set(26, row, e.PickupETATime); + sheet1.set(27, row, e.PickupStartDate); + sheet1.set(28, row, e.PickupStartTime); + sheet1.set(29, row, e.PickupCompleteDate); + sheet1.set(30, row, e.PickupCompleteTime); + sheet1.set(31, row, e.TotalPickUpTime); + sheet1.set(32, row, e.DeliveryStatus); + sheet1.set(33, row, e.DeliveryETADate); + sheet1.set(34, row, e.DeliveryETATime); + sheet1.set(35, row, e.DeliveryStartDate); + sheet1.set(36, row, e.DeliveryStartTime); + sheet1.set(37, row, e.DeliveryCompleteDate); + sheet1.set(38, row, e.DeliveryCompleteTime); + sheet1.set(39, row, e.TotalDeliveryTime); + sheet1.set(40, row, e.CashDeliveryStatus); + sheet1.set(41, row, e.CashDeliveryStartDate); + sheet1.set(42, row, e.CashDeliveryStartTime); + sheet1.set(43, row, e.CashDeliveryCompleteDate); + sheet1.set(44, row, e.CashDeliveryCompleteTime); + sheet1.set(45, row, e.TotalCashDeliveryTime); + sheet1.set(46, row, e.CashDeliveryETADate); + sheet1.set(47, row, e.CashDeliveryETATime); + sheet1.set(48, row, e.Status); + sheet1.set(49, row, e.PaymentStatus); + sheet1.set(50, row, e.VendorInvoiceNo); + sheet1.set(51, row, e.Commission); + sheet1.set(52, row, e.CashRecieved); + sheet1.set(53, row, e.KM); + sheet1.set(54, row, e.ProductType); + sheet1.set(55, row, e.Comment); } diff --git a/utility.js b/utility.js index 09cc9ed..279b28f 100644 --- a/utility.js +++ b/utility.js @@ -62,5 +62,25 @@ module.exports = { return taskETA.Type === eta; } return jobTaskPreferenceETA.find(findEta); + }, + + getTime : function (time) { + var moment = require('moment'); + if (time) { + return moment(time).format('LT'); + } else return "Not Mentioned"; + }, + + getDate : function (time) { + var moment = require('moment'); + if (time) { + return moment(time).format('LL') + } else return "Not Mentioned"; + }, + + getHoursDifference: function (startTime, endTime) { + var moment = require('moment'); + if (!startTime || !endTime) return "-" + return moment.duration(moment(startTime).diff(moment(endTime))).asHours(); } } \ No newline at end of file