Added graphs and charts; Updated a lot of the collections for security and consistency; Updated all of the page to fix bugs and propagate fixes to all templates; Added the d3 library for graphing; Added a real ui for Measures and Venues.
This commit is contained in:
@@ -92,6 +92,86 @@ if(Meteor.isServer) {
|
||||
dbQuery = dbQuery.length > 0 ? {$and: dbQuery} : {};
|
||||
return Meteor.collections.Sales.find(dbQuery, {limit: limit, sort: {date: -1, createdAt: -1}, skip: skipCount});
|
||||
});
|
||||
// time: expects either undefined, 'weekly', or 'monthly'
|
||||
// options: expects either undefined, 'markets', or 'types'
|
||||
Meteor.publish('salesTotals', function(time, options) {
|
||||
let pipeline = [];
|
||||
let group = {
|
||||
$group: {
|
||||
_id: {
|
||||
year: {$dateToString: {format: '%Y', date: '$date'}}//{$year: '$date'}
|
||||
},
|
||||
'total': {
|
||||
$sum: {
|
||||
$multiply: ['$price', '$amount']
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
let project = {
|
||||
$project: {
|
||||
year: '$_id.year',
|
||||
date: '$_id.year',
|
||||
total: true,
|
||||
_id: {$concat: ['$_id.year']}
|
||||
}
|
||||
};
|
||||
|
||||
pipeline.push(group);
|
||||
pipeline.push(project);
|
||||
|
||||
//Annual is assumed if not week or month.
|
||||
if(time === 'weekly') {
|
||||
group.$group._id.week = {$dateToString: {format: '%U', date: '$date'}}; //{$week: '$date'};
|
||||
project.$project.week = '$_id.week';
|
||||
project.$project.date = {$concat: ['$_id.week', '-', '$_id.year']};
|
||||
project.$project._id.$concat.push('$_id.week');
|
||||
}
|
||||
else if(time === 'monthly') {
|
||||
group.$group._id.month = {$dateToString: {format: '%m', date: '$date'}}; //{$month: '$date'};
|
||||
project.$project.month = '$_id.month';
|
||||
project.$project.date = {$concat: ['$_id.month', '-', '$_id.year']};
|
||||
project.$project._id.$concat.push('$_id.month');
|
||||
}
|
||||
|
||||
if(options === 'markets') {
|
||||
group.$group._id.venueId = '$venueId';
|
||||
project.$project.venueId = '$_id.venueId';
|
||||
project.$project._id.$concat.push('$_id.venueId');
|
||||
pipeline.push({$lookup: {from: 'Venues', localField: 'venueId', foreignField: '_id', as: 'venue'}});
|
||||
pipeline.push({$project: {year: 1, week: 1, month: 1, total: 1, venueId: 1, venue: {$arrayElemAt: ['$venue', 0]}}});
|
||||
pipeline.push({$project: {year: 1, week: 1, month: 1, total: 1, venueId: 1, venue: '$venue.name'}});
|
||||
}
|
||||
else if(options === 'types') {
|
||||
//query[0].$group.month = {$month: '$date'};
|
||||
//TODO: Need to divide the sales up by:
|
||||
// Sweets
|
||||
// Savories
|
||||
// Meats
|
||||
// VAP
|
||||
// Egg
|
||||
// Other Produce
|
||||
// Total Produce
|
||||
// Jars
|
||||
}
|
||||
|
||||
|
||||
ReactiveAggregate(this, Sales, pipeline, {clientCollection: 'salesTotals'});
|
||||
|
||||
/*
|
||||
{$sales: {
|
||||
_id: Random.id(),
|
||||
year: $_id.$year,
|
||||
total: $total
|
||||
}}
|
||||
*/
|
||||
//ReactiveAggregate(this, Sales, [query], {clientCollection: 'salesTotals', transform: function(doc) {
|
||||
// console.log("Running transform function");
|
||||
// Object.assign(doc._id, doc);
|
||||
// doc._id = Random.id();
|
||||
// return doc;
|
||||
//}});
|
||||
});
|
||||
|
||||
Meteor.methods({
|
||||
getSalesCount: function(query) {
|
||||
@@ -105,7 +185,7 @@ if(Meteor.isServer) {
|
||||
if(Roles.userIsInRole(this.userId, [Meteor.UserRoles.ROLE_UPDATE])) {
|
||||
Sales.insert(sale, function(err, id) {
|
||||
if(err) console.log(err);
|
||||
});
|
||||
}, {bypassCollection2: true});
|
||||
}
|
||||
else throw new Meteor.Error(403, "Not authorized.");
|
||||
},
|
||||
@@ -113,7 +193,7 @@ if(Meteor.isServer) {
|
||||
check(id, String);
|
||||
|
||||
if(Roles.userIsInRole(this.userId, [Meteor.UserRoles.ROLE_UPDATE])) {
|
||||
Sales.remove(id);
|
||||
Sales.remove(id, {bypassCollection2: true});
|
||||
}
|
||||
else throw new Meteor.Error(403, "Not authorized.");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user