Added a lot of functionality; Fixed a large number of bugs; Removed Bootstrap from the mix and replaced it with SimpleGrid and some choice bits from the bootstrap system; Pricing, Sales, and Product management all now function at basic levels.
This commit is contained in:
@@ -3,79 +3,40 @@ import './Sales.html';
|
||||
import '/imports/util/selectize/selectize.js'
|
||||
import ResizeSensor from '/imports/util/resize/ResizeSensor.js';
|
||||
|
||||
Tracker.autorun(function() {
|
||||
Meteor.subscribe("products");
|
||||
Meteor.subscribe("sales", Session.get('searchQuery'));
|
||||
});
|
||||
let QUERY_LIMIT = 20;
|
||||
let PREFIX = "Sales.";
|
||||
|
||||
Template.Sales.onRendered(function() {
|
||||
// console.log("moving headers");
|
||||
// try {
|
||||
// //Move the headers into the header table that will maintain its position.
|
||||
// //Link the column widths to the header widths.
|
||||
// let newHeaderRow = this.$('.dataTableHeader thead tr:first');
|
||||
// let newFooterRow = this.$('.dataTableFooter thead tr:first');
|
||||
// let oldHeaders = this.$('.dataTable thead tr.headers th');
|
||||
// let oldFooters = this.$('.dataTable thead tr.footers th');
|
||||
//
|
||||
// console.log("header count " + oldHeaders.length);
|
||||
//
|
||||
// for(let index = 0; index < oldHeaders.length; index++) {
|
||||
// let width = this.$('.dataTable tbody tr:first td:eq(' + index + ')').width();
|
||||
// let oldHeader = oldHeaders.eq(index);
|
||||
// let newHeader = $("<th\>");
|
||||
// oldHeader.replaceWith(newHeader);
|
||||
// newHeader.width(width);
|
||||
// oldHeader.appendTo(newHeaderRow);
|
||||
// //Link the two headers so that the visible header changes size with the hidden one.
|
||||
// //TODO: Turn this off if manually resizing the visible headers - while resizing.
|
||||
// new ResizeSensor(newHeader, function() {
|
||||
// oldHeader.width(newHeader.width());
|
||||
// });
|
||||
// }
|
||||
//
|
||||
// for(let index = 0; index < oldFooters.length; index++) {
|
||||
// let width = this.$('.dataTable tbody tr:first td:eq(' + index + ')').width();
|
||||
// let oldFooter = oldFooters.eq(index);
|
||||
// let newFooter = $("<th\>");
|
||||
// oldFooter.replaceWith(newFooter);
|
||||
// newFooter.width(width);
|
||||
// oldFooter.appendTo(newFooterRow);
|
||||
// //Link the two headers so that the visible header changes size with the hidden one.
|
||||
// //TODO: Turn this off if manually resizing the visible headers - while resizing.
|
||||
// new ResizeSensor(newFooter, function() {
|
||||
// oldFooter.width(newFooter.width());
|
||||
// });
|
||||
// }
|
||||
// }
|
||||
// catch(err) {
|
||||
// console.log(err);
|
||||
// }
|
||||
Meteor.subscribe("products");
|
||||
|
||||
Tracker.autorun(function() {
|
||||
Meteor.subscribe("sales", Session.get(PREFIX + 'searchQuery'), QUERY_LIMIT, Session.get(PREFIX + 'skipCount'));
|
||||
Session.set(PREFIX + 'saleCount', Meteor.call('getSalesCount', Session.get(PREFIX + 'searchQuery')));
|
||||
});
|
||||
|
||||
Template.Sales.helpers({
|
||||
sales: function() {
|
||||
return Meteor.collections.Sales.find({}, {sort: {date: -1}});
|
||||
return Meteor.collections.Sales.find({}, {sort: {date: -1, createdAt: -1}});
|
||||
},
|
||||
disablePrev: function() {
|
||||
return (Session.get(PREFIX + 'skipCount') || 0) == 0;
|
||||
},
|
||||
disableNext: function() {
|
||||
return Session.get(PREFIX + 'saleCount') - (Session.get(PREFIX + 'skipCount') || 0) - QUERY_LIMIT <= 0;
|
||||
}
|
||||
});
|
||||
Template.Sales.events({
|
||||
'click .prevButton': function(event, template) {
|
||||
if(!$(event.target).hasClass('disabled'))
|
||||
Session.set(PREFIX + 'skipCount', Math.max(0, (Session.get(PREFIX + 'skipCount') || 0) - QUERY_LIMIT));
|
||||
},
|
||||
'click .nextButton': function(event, template) {
|
||||
if(!$(event.target).hasClass('disabled'))
|
||||
Session.set(PREFIX + 'skipCount', (Session.get(PREFIX + 'skipCount') || 0) + QUERY_LIMIT);
|
||||
}
|
||||
});
|
||||
|
||||
Template.Sale.onCreated(function() {
|
||||
});
|
||||
Template.Sale.events({
|
||||
"click .saleRemove": function(event, template) {
|
||||
let _this = this;
|
||||
bootbox.confirm({
|
||||
message: "Delete the sale?",
|
||||
buttons: {confirm: {label: "Yes", className: 'btn-success'}, cancel: {label: "No", className: "btn-danger"}},
|
||||
callback: function(result) {
|
||||
if(result) {
|
||||
// Meteor.collections.Sales.remove(_this._id);
|
||||
Meteor.call('deleteSale', _this._id);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
Template.Sale.helpers({
|
||||
measureName: function(id) {
|
||||
return Meteor.collections.Measures.findOne({_id: id}, {fields: {name: 1}}).name;
|
||||
@@ -99,11 +60,33 @@ Template.Sale.helpers({
|
||||
return amount > 1;
|
||||
}
|
||||
});
|
||||
Template.Sale.events({
|
||||
"click .saleRemove": function(event, template) {
|
||||
let _this = this;
|
||||
bootbox.confirm({
|
||||
message: "Delete the sale?",
|
||||
buttons: {confirm: {label: "Yes", className: 'btn-success'}, cancel: {label: "No", className: "btn-danger"}},
|
||||
callback: function(result) {
|
||||
if(result) {
|
||||
// Meteor.collections.Sales.remove(_this._id);
|
||||
Meteor.call('deleteSale', _this._id);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
Template.SaleSearch.helpers({
|
||||
searchValue: function() {
|
||||
let searchFields = Session.get(PREFIX + 'searchFields');
|
||||
|
||||
return (searchFields && searchFields[this.columnName]) ? searchFields[this.columnName] : '';
|
||||
}
|
||||
});
|
||||
Template.SaleSearch.events({
|
||||
"keyup .searchInput": _.throttle(function(event, template) {
|
||||
let searchQuery = Session.get('searchQuery') || {};
|
||||
let searchFields = Session.get('searchFields') || {};
|
||||
let searchQuery = Session.get(PREFIX + 'searchQuery') || {};
|
||||
let searchFields = Session.get(PREFIX + 'searchFields') || {};
|
||||
let searchValue = template.$('.searchInput').val();
|
||||
|
||||
if(searchValue) {
|
||||
@@ -127,32 +110,31 @@ Template.SaleSearch.events({
|
||||
delete searchFields[this.columnName];
|
||||
}
|
||||
|
||||
Session.set('searchQuery', searchQuery);
|
||||
Session.set(PREFIX + 'searchQuery', searchQuery);
|
||||
Session.set(PREFIX + 'searchFields', searchFields);
|
||||
}, 500)
|
||||
});
|
||||
Template.SaleSearch.helpers({
|
||||
searchValue: function() {
|
||||
let searchFields = Session.get('searchFields');
|
||||
|
||||
return (searchFields && searchFields[this.columnName]) ? searchFields[this.columnName] : '';
|
||||
}
|
||||
});
|
||||
|
||||
// let SelectedProduct = new ReactiveVar();
|
||||
Template.InsertSale.onCreated(function() {
|
||||
// $('#insertSale').validator();
|
||||
// $('#insertSale').data('bs.validator');
|
||||
// this.products = new ReactiveVar([]);
|
||||
this.selectedDate = new ReactiveVar();
|
||||
this.selectedProduct = new ReactiveVar();
|
||||
this.selectedVenue = new ReactiveVar();
|
||||
});
|
||||
Template.InsertSale.onRendered(function() {
|
||||
$('#insertSale').validator();
|
||||
this.$('.insertSaleForm').validator();
|
||||
// this.$('[name="product"]').
|
||||
// this.autorun(function() {
|
||||
// this.$('[name="product"]').buildCombo(Meteor.collections.Products.find({}).fetch(), {textAttr: 'name', listClass: 'comboList'});
|
||||
// });
|
||||
this.$('[name="product"]').buildCombo({cursor: Meteor.collections.Products.find({}), selection: this.selectedProduct, textAttr: 'name', listClass: 'comboList'});
|
||||
|
||||
//TODO: Highlight deactivated products in combo
|
||||
//TODO: Default the price for each size product based on the date.
|
||||
this.$('[name="product"]').buildCombo({cursor: Meteor.collections.Products.find({$or: [{hidden: false}, {hidden: {$exists:false}}]}), selection: this.selectedProduct, textAttr: 'name', listClass: 'comboList', getClasses: function(data) {
|
||||
return (data && data.deactivated) ? "deactivated" : "";
|
||||
}});
|
||||
this.$('[name="venue"]').buildCombo({cursor: Meteor.collections.Venues.find({}), selection: this.selectedVenue, textAttr: 'name', listClass: 'comboList'});
|
||||
|
||||
// this.autorun(function(){
|
||||
@@ -160,14 +142,17 @@ Template.InsertSale.onRendered(function() {
|
||||
// }.bind(this));
|
||||
});
|
||||
Template.InsertSale.events({
|
||||
'change #InsertSaleProduct': function(event, template) {
|
||||
let selectedId = $('#InsertSaleProduct').val();
|
||||
'change input[name="product"]': function(event, template) {
|
||||
let selectedId = template.$('input[name="product"]').val();
|
||||
let selected = Meteor.collections.Products.findOne(selectedId);
|
||||
template.selectedProduct.set(selected);
|
||||
},
|
||||
'change input[name="date"]': function(event, template) {
|
||||
template.selectedDate.set(moment(event.target.value, "YYYY-MM-DD").toDate());
|
||||
},
|
||||
'click input[type="submit"]': function(event, template) {
|
||||
event.preventDefault();
|
||||
$('#insertSale').data('bs.validator').validate(function(isValid) {
|
||||
template.$('.insertSaleForm').data('bs.validator').validate(function(isValid) {
|
||||
if(isValid) {
|
||||
let sales = [];
|
||||
let sale = {
|
||||
@@ -192,30 +177,20 @@ Template.InsertSale.events({
|
||||
}
|
||||
}
|
||||
|
||||
// let debug = "Inserting: ";
|
||||
// for(next in sales) {
|
||||
// debug += "\n\t" + next;
|
||||
// }
|
||||
// console.log(debug);
|
||||
for(let index = 0; index < sales.length; index++) {
|
||||
let next = sales[index];
|
||||
console.log("Inserting: " + JSON.stringify(next));
|
||||
// Meteor.collections.Sales.insert(next, function(err, id) {
|
||||
// if(err) console.log(err);
|
||||
// });
|
||||
Meteor.call('insertSale', next);
|
||||
//console.log("Inserting: " + JSON.stringify(next));
|
||||
Meteor.call('insertSale', next, function(error) {
|
||||
if(error) sAlert.error("Failed to insert the sale!\n" + error);
|
||||
else sAlert.success("Sale Created");
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
Template.InsertSale.helpers({
|
||||
// sales: function() {
|
||||
// return Meteor.collections.Sales;
|
||||
// },
|
||||
products: function() {
|
||||
//return Meteor.collections.Products.find({});
|
||||
//return this.products;
|
||||
return [{label: "Hermies", value: 1}, {label: "Ralfe", value: 2}, {label: "Bob", value: 3}];
|
||||
},
|
||||
productMeasures: function() {
|
||||
@@ -226,8 +201,8 @@ Template.InsertSale.helpers({
|
||||
result[i] = Meteor.collections.Measures.findOne(result[i]);
|
||||
}
|
||||
|
||||
if(product) console.log("Found " + result.length + " measures for the product " + product.name);
|
||||
else console.log("No product!");
|
||||
// if(product) console.log("Found " + result.length + " measures for the product " + product.name);
|
||||
// else console.log("No product!");
|
||||
|
||||
return result;
|
||||
},
|
||||
@@ -237,29 +212,45 @@ Template.InsertSale.helpers({
|
||||
});
|
||||
|
||||
Template.InsertSaleMeasure.onCreated(function() {
|
||||
let prices = this.parentTemplate().selectedProduct.get().prices;
|
||||
let price = 0;
|
||||
let _this = this;
|
||||
|
||||
if(prices) price = prices[this._id];
|
||||
|
||||
this.price = new ReactiveVar(price);
|
||||
this.price = new ReactiveVar(0);
|
||||
this.amount = new ReactiveVar(0);
|
||||
|
||||
Tracker.autorun(function() {
|
||||
let date = _this.parentTemplate().selectedDate.get();
|
||||
let prices = _this.parentTemplate().selectedProduct.get().prices;
|
||||
let priceData;
|
||||
let price = 0;
|
||||
|
||||
if(prices) priceData = prices[_this.data._id];
|
||||
|
||||
//If this product has pricing data for the given measure, then either use the price, or the previousPrice (if there is one and the effectiveDate is after the sale date).
|
||||
if(priceData) {
|
||||
if(priceData.effectiveDate && date && moment(priceData.effectiveDate).isAfter(date))
|
||||
price = priceData.previousPrice;
|
||||
else
|
||||
price = priceData.price
|
||||
}
|
||||
|
||||
_this.price.set(price);
|
||||
});
|
||||
});
|
||||
Template.InsertSaleMeasure.events({
|
||||
'change .price': function(event, template) {
|
||||
template.price.set(parseFloat($(event.target).val()).toFixed(2));
|
||||
template.price.set(parseFloat($(event.target).val()));
|
||||
},
|
||||
'change .amount': function(event, template) {
|
||||
template.amount.set(parseFloat($(event.target).val()).toFixed(2));
|
||||
template.amount.set(parseFloat($(event.target).val()));
|
||||
}
|
||||
});
|
||||
Template.InsertSaleMeasure.helpers({
|
||||
price: function() {
|
||||
return Template.instance().price.get();
|
||||
return Template.instance().price.get().toFixed(2);
|
||||
},
|
||||
total: function() {
|
||||
let template = Template.instance();
|
||||
return template.price.get() * template.amount.get();
|
||||
return (template.price.get() * template.amount.get()).toFixed(2);
|
||||
},
|
||||
amount: function() {
|
||||
return Template.instance().amount.get();
|
||||
|
||||
Reference in New Issue
Block a user