Skip to content

Commit

Permalink
details report generation fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
tareq89 committed Nov 6, 2016
1 parent c8a0fcc commit 978dab9
Show file tree
Hide file tree
Showing 5 changed files with 355 additions and 9 deletions.
127 changes: 127 additions & 0 deletions calculate.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,132 @@ module.exports = {
}
}
return report;
},

detailsReport: function (report, job) {

var utility = require('./utility');
var entry = {};

entry.trackingNumber = job.HRID
entry.DeliveryType = job.Order.Type;

entry.Status = job.State;
entry.PaymentStatus = job.PaymentStatus;

entry.OrderingDate = utility.getDate(job.CreateTime);
entry.OrderingTime = utility.getTime(job.CreateTime);

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 = utility.getDate(job.CompletionTime);
entry.CompleteTime = utility.getTime(job.CompletionTime);

// User, DeliveryMan info
entry.ClientType = utility.getClientType(job.User.Type);
entry.UserName = job.User.UserName;
entry.UserPhone = job.User.PhoneNumber;
entry.DeliveryPerson = utility.getDeliveryPersonNames(job.Assets);

entry.PickupAddress = job.Order.From.Address;
entry.PickupArea = job.Order.From.Locality;
entry.DeliveryAddress = job.Order.To.Address;
entry.DeliveryArea = job.Order.To.Locality;


// Package Info
entry.ProductDescription = job.Order.Description;
entry.Product = utility.getProductNames(job.Order.OrderCart.PackageList);
entry.Weight = job.Order.OrderCart.TotalWeight;
entry.TotalProductPrice = job.Order.OrderCart.SubTotal;
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;
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 = utility.getDate(pickupEta.ETA);
entry.PickupETATime = utility.getTime(pickupEta.ETA);
}
}
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;
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 = utility.getDate(deliveryEta.ETA);
entry.DeliveryETATime = utility.getTime(deliveryEta.ETA);
}
}

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;
entry.CashDeliveryStartTime = "Not Applicable";
entry.CashDeliveryCompleteDate;
entry.CashDeliveryCompleteTime = "Not Applicable";
entry.TotalCashDeliveryTime = "Not Applicable";
entry.CashDeliveryETADate;
entry.CashDeliveryETATime = "Not Applicable";
if (job.Tasks[3]) {
entry.CashDeliveryStatus = job.Tasks[3].State;

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 = utility.getDate(cashDeliveryEta.ETA);
entry.CashDeliveryETATime = utility.getTime(cashDeliveryEta.ETA);
}
}
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.VendorInvoiceNo = null;
entry.Commission = null;
entry.CashRecieved = null;
entry.KM = null;
entry.ProductType = null;
entry.Comment = null;

return entry;
}
}
149 changes: 144 additions & 5 deletions excelCreator.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
module.exports = {

getSummaryReport : function (report, callback) {
getSummaryReport: function (report) {
var excelbuilder = require('msexcel-builder');
var directoryName = __dirname + "/excel/";
var workbookName = Date.now().toString() + 'sample.xlsx';
var workbookName = Date.now().toString() + 'summary.xlsx';
var reportFileName = directoryName + workbookName;

var workbook = excelbuilder.createWorkbook(directoryName, workbookName);
var sheet1 = workbook.createSheet('sheet1', 10, 12);
var workbook = excelbuilder.createWorkbook(directoryName, workbookName);
console.log(Object.keys(report).length)
var sheet1 = workbook.createSheet('sheet1', 8, Object.keys(report).length+1);
sheet1.set(1, 1, 'Name');
sheet1.set(2, 1, 'Delivery');
sheet1.set(3, 1, 'Pending');
Expand All @@ -16,10 +17,16 @@ module.exports = {
sheet1.set(6, 1, 'Cancelled');
sheet1.set(7, 1, 'ProductPrice');
sheet1.set(8, 1, 'DeliveryCharge');
for (var row = 2; row <= 10; row++) {
console.log(Object.keys(report).length);
for (var row = 2; row <= Object.keys(report).length + 1; row++) {
var reportBaseIndex = row - 2;
console.log(reportBaseIndex)
var key = Object.keys(report)[reportBaseIndex];
sheet1.set(1, row, key);
if (report[key].TotalDelivery === undefined) {
console.log()
console.log(report[key])
}
sheet1.set(2, row, report[key].TotalDelivery);
sheet1.set(3, row, report[key].TotalPending);
sheet1.set(4, row, report[key].TotalInProgress);
Expand All @@ -29,6 +36,138 @@ module.exports = {
sheet1.set(8, row, report[key].TotalDeliveryCharge);
}

return {
workbookFilePath: reportFileName,
workbook: workbook
}
},
getDetailsReport: function (report) {
var excelbuilder = require('msexcel-builder');
var directoryName = __dirname + "/excel/";
var workbookName = Date.now().toString() + 'details.xlsx';
var reportFileName = directoryName + workbookName;

var workbook = excelbuilder.createWorkbook(directoryName, workbookName);
var sheet1 = workbook.createSheet('sheet1', 55, report.length + 1);

sheet1.set(1, 1, 'trackingNumber');
sheet1.set(2, 1, 'DeliveryType');
sheet1.set(3, 1, 'OrderingDate');
sheet1.set(4, 1, 'OrderingTime');
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');

console.log(report.length);
for (var row = 2; row <= (report.length+1); row++) {
var e = report[row-2];
console.log(row-2);
sheet1.set(1, row, e.trackingNumber);
sheet1.set(2, row, e.DeliveryType);
sheet1.set(3, row, e.OrderingDate);
sheet1.set(4, row, e.OrderingTime);
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);

}

return {
workbookFilePath: reportFileName,
workbook: workbook
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"body-parser": "^1.15.2",
"cors": "^2.8.1",
"express": "^4.14.0",
"moment": "^2.15.2",
"mongodb": "^2.2.10",
"mongoose": "^4.6.0",
"msexcel-builder": "0.0.2"
Expand Down
9 changes: 5 additions & 4 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ var MongoClient = require('mongodb').MongoClient;
var url = 'mongodb://gofetch.cloudapp.net:27017/taskcat';
var productDbUrl = 'mongodb://gofetch.cloudapp.net:27017/test';

var port = process.env.PORT || 8000;
var port = process.env.PORT || 80;
var router = express.Router();

app.use(bodyParser.urlencoded({ extended: true }));
Expand Down Expand Up @@ -84,12 +84,13 @@ router.get('/details', function (req, res) {
var cursor = db.collection('Jobs').find(query);
cursor.each(function (err, job) {
assert.equal(err, null);
if(job!=null){
report.push(job);
if(job!=null){
var entry = calculate.detailsReport(report, job);
report.push(entry);
} else {
db.close();
if (req.query.generateexcel == "true") {
var excelReport = excelCreator.getSummaryReport(report);
var excelReport = excelCreator.getDetailsReport(report);

excelReport.workbook.save(function(ok){
console.log(ok)
Expand Down
Loading

0 comments on commit 978dab9

Please sign in to comment.