Skip to content

Commit

Permalink
excel report on details job works
Browse files Browse the repository at this point in the history
  • Loading branch information
tareq89 committed Oct 3, 2016
1 parent c9e9ef0 commit 5118d59
Show file tree
Hide file tree
Showing 5 changed files with 199 additions and 7 deletions.
64 changes: 64 additions & 0 deletions calculate.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,69 @@ module.exports = {
}
}
return report;
},

detailsReport: function (report, job) {
var moment = require('moment');
var utility = require('./utility');
var entry = {};

entry.trackingNumber = job.HRID
entry.Client = job.User.Type

entry.OrderingDate = moment(job.CreateTime).format('LL');
entry.OrderingTime = moment(job.CreateTime).format('LT');

entry.DeliveryDate = moment(job.ETA).format('LL');
entry.DeliveryDate = moment(job.ETA).format('LT');


entry.DeliveryType = job.Order.Type;

entry.UserName = job.User.UserName;
entry.UserPhone = job.User.PhoneNumber;

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


entry.ProductDescription = job.Order.Description;

entry.Product = utility.getProductNames(job.Order.OrderCart.PackageList);
// entry.Qty = job.Order.OrderCart.PackageList[0].Quantity
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.DeliveryPerson = utility.getDeliveryPersonNames(job.Assets);

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.DeliveryStartTime = moment(job.Tasks[2].Started).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.Status = job.State
entry.PaymentStatus = job.PaymentStatus


entry.VendorInvoiceNo = null;
entry.Commission = null;
entry.CashRecieved = null;
entry.KM = null;
entry.ProductType = null;
entry.Comment = null;

return entry;
}
}
97 changes: 95 additions & 2 deletions excelCreator.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
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);
Expand Down Expand Up @@ -33,5 +33,98 @@ module.exports = {
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', 34, report.length);

sheet1.set(1, 1, 'trackingNumber');
sheet1.set(2, 1, 'Client');
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');

for (var row = 2; row < report.length; row++) {
var e = report[row-2];

console.log(row-2)

sheet1.set(1, row, e.trackingNumber);
sheet1.set(2, row, e.Client);
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);

}

return {
workbookFilePath: reportFileName,
workbook: workbook
}

}
}
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.1",
"mongodb": "^2.2.10",
"mongoose": "^4.6.0",
"msexcel-builder": "0.0.2"
Expand Down
22 changes: 17 additions & 5 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ router.get('/', function(req, res){
});


// Parameters:
// usertype = USER BIKE_MESSENGER ENTERPRISE
// userid = Asset's user id
// startdate = ISOdate
// enddate = ISOdate
// generateexcel = boolean

router.get('/report', function (req, res) {
console.log("\n\n/report : ");
Expand All @@ -39,8 +45,6 @@ router.get('/report', function (req, res) {
MongoClient.connect(url, function (err, db) {
assert.equal(null, err);
var query = queryMaker.reportQuery(req);
console.log(req.query.generateexcel);
console.log(query)
var cursor = db.collection('Jobs').find(query);
cursor.each(function (err, job) {
assert.equal(err, null);
Expand Down Expand Up @@ -69,6 +73,13 @@ router.get('/report', function (req, res) {
});



// Parameters:
// usertype = USER BIKE_MESSENGER ENTERPRISE
// userid = Asset's user id
// startdate = ISOdate
// enddate = ISOdate
// generateexcel = boolean
router.get('/details', function (req, res) {
var paramValid = utility.reportParamChecker(req);
if (!paramValid.valid) {
Expand All @@ -83,12 +94,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
22 changes: 22 additions & 0 deletions utility.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,27 @@ module.exports = {
valid: false
}
else return {valid: true};
},

getProductNames : function (PackageList) {
var packages = PackageList.map(function (package) {
return "Name: " + package.Item +
", Quantity :" + package.Quantity +
", Price: " + package.Price +
", Weight: " + package.Weight;
});
var package = "";
for (var i = packages.length - 1; i >= 0; i--) {
package += packages[i] + "\n";
}
return package;
},

getDeliveryPersonNames : function (Assets) {
var assetNames = "";
for (var i = Object.keys(Assets).length - 1; i >= 0; i--) {
assetNames = Assets[Object.keys(Assets)[i]].UserName;
}
return assetNames;
}
}

0 comments on commit 5118d59

Please sign in to comment.