Fixes and updates.

This commit is contained in:
Wynne Crisman
2020-01-16 09:31:12 -08:00
parent 2e57558ef4
commit a20e42e360
25 changed files with 346 additions and 820 deletions

View File

@@ -128,13 +128,15 @@ if(Meteor.isServer) {
if(!_.isNumber(skipCount) || skipCount < 0) skipCount = 0;
dbQuery = dbQuery.length > 0 ? {$and: dbQuery} : {};
return Meteor.collections.Batches.find(dbQuery, {limit: limit, sort, skip: skipCount});
//console.log("dbQuery=" + JSON.stringify(dbQuery));
//console.log("Result Count: " + Batches.find(query).count());
return Batches.find(dbQuery, {limit: limit, sort, skip: skipCount});
});
Meteor.methods({
getBatchCount: function(query) {
//TODO: Validate the query?
return Sales.find(query).count();
return Batches.find(query).count();
},
insertBatches: function(batches) { //Insert one or more batches (if one, you can pass just the batch).
if(Roles.userIsInRole(this.userId, [Meteor.UserRoles.ROLE_UPDATE])) {
@@ -198,40 +200,44 @@ if(Meteor.isServer) {
}
else throw new Meteor.Error(403, "Not authorized.");
},
editBatchComment: function(id, comment) {
//editBatchComment: function(id, comment) {
// check(id, String);
// check(comment, String);
// //Trim and convert empty comment to undefined.
// comment = comment ? comment.trim() : undefined;
// comment = comment && comment.length > 0 ? comment : undefined;
//
// if(Roles.userIsInRole(this.userId, [Meteor.UserRoles.ROLE_UPDATE])) {
// console.log("Changed comment of " + id + " to: " + comment);
//
// if(comment) {
// Batches.update(id, {$set: {comment}}, function(error, count) {
// if(error) throw new Meteor.Error(400, "Unexpected database error: " + error);
// });
// }
// else {
// Batches.update(id, {$unset: {comment: ""}}, function(error, count) {
// if(error) throw new Meteor.Error(400, "Unexpected database error: " + error);
// });
// }
// }
// else throw new Meteor.Error(403, "Not authorized.");
//},
updateBatch: function(id, amount, comment) {
check(id, String);
check(comment, String);
check(amount, Number);
check(comment, Match.OneOf(String, undefined));
//Trim and convert empty comment to undefined.
comment = comment ? comment.trim() : undefined;
comment = comment && comment.length > 0 ? comment : undefined;
if(Roles.userIsInRole(this.userId, [Meteor.UserRoles.ROLE_UPDATE])) {
console.log("Changed comment of " + id + " to: " + comment);
if(comment) {
Batches.update(id, {$set: {comment}}, function(error, count) {
if(error) throw new Meteor.Error(400, "Unexpected database error: " + error);
});
}
else {
Batches.update(id, {$unset: {comment: ""}}, function(error, count) {
if(error) throw new Meteor.Error(400, "Unexpected database error: " + error);
});
}
}
else throw new Meteor.Error(403, "Not authorized.");
},
updateBatch: function(id, date, amount) {
check(id, String);
check(date, Number); // TODO: Check that the format is YYYYMMDD
check(amount, Number);
let dateString = date.toString();
let timestamp = new Date(dateString.substring(0, 4) + "-" + dateString.substring(4, 6) + "-" + dateString.substring(6, 8) + "T00:00:00Z");
let weekOfYear = timestamp.getWeek().toString();
//let dateString = date.toString();
//let timestamp = new Date(dateString.substring(0, 4) + "-" + dateString.substring(4, 6) + "-" + dateString.substring(6, 8) + "T00:00:00Z");
//let weekOfYear = timestamp.getWeek().toString();
if(Roles.userIsInRole(this.userId, [Meteor.UserRoles.ROLE_UPDATE])) {
Batches.update(id, {$set: {date, amount, timestamp, weekOfYear}}, function(err, id) {
Batches.update(id, {$set: {comment, amount}}, function(err, id) {
if(err) console.log(err);
}, {bypassCollection2: true});
}

View File

@@ -2,54 +2,15 @@ import { Meteor } from 'meteor/meteor';
import { Mongo } from 'meteor/mongo';
import { check } from 'meteor/check';
import {SimpleSchema} from 'meteor/aldeed:simple-schema';
import LabelFormats from '/imports/LabelFormats.js';
if(Meteor.isServer) {
const puppeteer = require('puppeteer');
//let Future = Npm.require('fibers/future');
//
//async function printLabels(data, callback) {
// let params = "";
// let url = Meteor.absoluteUrl("/LabelPrint");
//
// params = Object.keys(data).map(function(k) {
// return encodeURIComponent(k) + "=" + encodeURIComponent(data[k]);
// }).join('&');
//
// url += "?" + params;
//
// const browser = await puppeteer.launch();
// const page = await browser.newPage();
// console.log("Going to: " + url);
// await page.goto(url, {waitUntil: 'networkidle0'});
// // By removing the `path` option, we will receive a `Buffer` from `page.pdf`.
// const pdf = await page.pdf({ width: "6in", height: "4in"}); // format: "A4" //path: 'C:\\Users\\Grumpy\\label.pdf'
//
// await browser.close();
// callback(null, pdf);
//}
Meteor.methods({
//printLabels: function(width, height, layout, title1, title2, ingredients, date) {
// console.log("Loaded Label");
// let future = new Future();
//
// let boundCallback = Meteor.bindEnvironment(function(err, res) {
// if(err) {
// future.throw(err);
// }
// else {
// future.return(res);
// }
// });
//
// printLabels({width, height, layout, title1, title2, ingredients, date}, boundCallback);
//
// return future.wait();
//}
async printLabels(width, height, layout, title1, title2, ingredients, date) {
let data = {width, height, layout, title1, title2, ingredients, date};
async printLabels(format, title1, title2, ingredients, date) {
let data = {format, title1, title2, ingredients, date};
let params = "";
let url = Meteor.absoluteUrl("/PrintLabel");
@@ -64,11 +25,8 @@ if(Meteor.isServer) {
const browser = await puppeteer.launch();
const page = await browser.newPage();
//url = Meteor.absoluteUrl("/StaticTest.html");
//url = Meteor.absoluteUrl("/StaticTest.html");
console.log("Going to: " + url);
await page.goto(url, {waitUntil: 'networkidle0'}); //, {waitUntil: 'networkidle0'}
const pdf = await page.pdf({width: '3in', height: '2in'}); //path: 'C:\\Users\\Grumpy\\label.pdf',
const pdf = await page.pdf({width: LabelFormats[format].width, height: LabelFormats[format].height}); //path: 'C:\\Users\\Grumpy\\label.pdf',
//const pdf = await page.pdf({format: 'A4'});
//await page.pdf({path: 'C:\\Users\\Grumpy\\label.pdf', width: '6in', height: '4in'});
await browser.close();
@@ -85,7 +43,6 @@ if(Meteor.isServer) {
//Note: Price data looks like this: {XZ5Z3CM49NDrJNADA /* MeasureID */: {price: 10.5, effectiveDate: ISODate("2017-01-12T13:14:18.876-08:00"), previousPrice: 9}, ...}
//Measures is an array of MeasureIDs valid for this product.
let products = Meteor.collections.Products.find({}, {fields: {_id: 1, name: 1, measures: 1, prices: 1}, sort: {order: 1}}).fetch();
//let measuresById = measures.reduce((map, measure) => (map[measure._id] = measure), {});
let measuresById = {};
let barcodesByProductAndMeasureIds = {};
let result = {};
@@ -93,11 +50,6 @@ if(Meteor.isServer) {
for(measure of measures) measuresById[measure._id] = measure;
for(barcode of barcodes) barcodesByProductAndMeasureIds[barcode.productAndMeasureId] = barcode.barcodeId;
//console.log(measuresById);
//for(let measureId of Object.keys(measuresById)) {
// console.log(measureId + ":" + measuresById[measureId].name);
//}
for(let product of products) {
for(let measureId of product.measures) {

View File

@@ -14,7 +14,7 @@ import {SimpleSchema} from 'meteor/aldeed:simple-schema';
* A product that is hidden is one that exists in the system as a historical artifact due to there still being data attached to it (sales for example). It should not normally show in lists, and should show up with a red indicator if it is displayed.
*/
Products = new Mongo.Collection('Products');
let Products = new Mongo.Collection('Products');
const ProductsSchema = new SimpleSchema({
name: {

View File

@@ -2,6 +2,7 @@ import { Meteor } from 'meteor/meteor';
import { Mongo } from 'meteor/mongo';
import { check } from 'meteor/check';
import {SimpleSchema} from 'meteor/aldeed:simple-schema';
import Batches from "./Batch";
/**
* Notes:
@@ -131,6 +132,10 @@ if(Meteor.isServer) {
if(!_.isNumber(skipCount) || skipCount < 0) skipCount = 0;
dbQuery = dbQuery.length > 0 ? {$and: dbQuery} : {};
//console.log("dbQuery=" + JSON.stringify(dbQuery));
//console.log("Result Count: " + Batches.find(query).count());
return Meteor.collections.Sales.find(dbQuery, {limit: limit, sort, skip: skipCount});
});
Meteor.publish('duplicateSales', function(query, includeIgnoredDuplicates) {

View File

@@ -12,7 +12,7 @@ if(Meteor.isServer) {
"insertUser": function(user) {
check(user, {
username: String,
email: String,
emails: [{address: String, verified: Match.Maybe(Boolean)}],
roles: [String]
});
@@ -21,7 +21,8 @@ if(Meteor.isServer) {
//Verify the user name isn't already used.
if(Meteor.collections.Users.findOne({username: user.username}) === undefined) {
let pwd = Random.secret(20);
let id = Accounts.createUser({password: pwd, username: user.username, email: user.email});
console.log("Email: " + user.emails[0]);
let id = Accounts.createUser({password: pwd, username: user.username, email: user.emails[0].address});
//Requires the alanning:roles package.
Roles.addUsersToRoles(id, user.roles);