Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions plugins/kiosk/accounts.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,19 @@ Account.prototype.booking = function (bookingId) {
return new Booking(booking);
};

Account.prototype.bookingByRelatedBookingId = function (relatedBookingId) {
var booking;

for (var i = 0; i < this._bookings.length; i++) {
booking = this._bookings[i];
if (booking.relatedBookingId && booking.relatedBookingId === relatedBookingId) {
return new Booking(booking);
}
}

return null;
};

Account.prototype.bookings = function () {
var bookings = [];
for (var i = 0; i < this._bookings.length; i++) {
Expand Down
51 changes: 50 additions & 1 deletion plugins/kiosk/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ exports.init = function (y, config, messages, cron, logger) {
dataDir,
app,
authCheck,
merchantBooking,
purchaseItem,
tallyCarryOver,
archiveAll,
Expand Down Expand Up @@ -107,6 +108,48 @@ exports.init = function (y, config, messages, cron, logger) {
callback();
};

merchantBooking = function (userId, userBooking, reverse) {
var account, booking, type, name, originalBooking;

if (typeof reverse === 'undefined') { reverse = false; }
account = accounts.get(config.kiosk.merchant_user);

if (reverse) {
originalBooking = account.bookingByRelatedBookingId(userBooking.id());
account.reverse(originalBooking.id(), function (err, bookingId) {
kioskLogger.log(userId, account, account.booking(bookingId));
});


} else {
if (userBooking.type() === 'purchase' || userBooking.type() === 'tally carry over') {
type = 'sell';
name = '[sell] ' + userBooking.name();
}

if (userBooking.type() === 'stock') {
type = 'buy';
name = '[buy] ' + userBooking.name();
}

booking = new Booking({
'id' : bookings.uuid(),
'itemId' : userBooking.itemId(),
'time' : Date.now(),
'amount' : userBooking.amount() * -1,
'name' : name,
'description' : name,
'type' : type,
'relatedBookingId' : userBooking.id()
});

account.book(booking, function (err, bookingId) {
kioskLogger.log(userId, account, account.booking(bookingId));
});
}

};

purchaseItem = function (userId, itemId, callback) {
var account, item, booking;

Expand Down Expand Up @@ -148,7 +191,7 @@ exports.init = function (y, config, messages, cron, logger) {

booking = new Booking({
'id' : bookings.uuid(),
'itemId' : null,
'itemId' : rec.item.id(),
'time' : Date.now(),
'amount' : rec.total * -1,
'name' : rec.marks + ' x ' + rec.item.name(),
Expand Down Expand Up @@ -243,6 +286,8 @@ exports.init = function (y, config, messages, cron, logger) {

res.redirect('/paid/' + bookingId);
kioskLogger.log(userId, account, account.booking(bookingId));

merchantBooking(userId, account.booking(bookingId));
});
});
});
Expand Down Expand Up @@ -278,6 +323,7 @@ exports.init = function (y, config, messages, cron, logger) {

res.redirect('/account');
kioskLogger.log(userId, account, account.booking(bookingId));
merchantBooking(userId, account.booking(oldBooking.id()), true);
});
});
});
Expand Down Expand Up @@ -464,6 +510,8 @@ exports.init = function (y, config, messages, cron, logger) {
}

kioskLogger.log(userId, account, account.booking(bookingId));

merchantBooking(userId, account.booking(bookingId));
});

});
Expand Down Expand Up @@ -644,6 +692,7 @@ exports.init = function (y, config, messages, cron, logger) {
var stock, text;

kioskLogger.log(userId, account, account.booking(bookingId));
merchantBooking(userId, account.booking(bookingId));
bookings.push(account.booking(bookingId));

if (rec.item.isStockable()) {
Expand Down