-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpos.js
40 lines (30 loc) · 999 Bytes
/
pos.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
var policyfactory = require('./policyfactory.js');
var PF = new policyfactory();
var data = require('./data.js');
function POS() {}
/**
* @description 统计每种商品的数量
* @return [barcode:num...]
* @type Array
*/
POS.prototype.countOrderItems = function(order) {
var items = {};
var barcode, num;
for (var i in order) {
barcode = order[i].split('-');
num = typeof(barcode[1]) !== 'undefined' ? parseInt(barcode[1]) : 1;
if (typeof(items[barcode[0]]) === 'undefined') {
items[barcode[0]] = num;
} else {
items[barcode[0]] += num;
}
}
return items;
}
POS.prototype.printList = function(order, policyData) {
var POLICY = PF.getPolicy(policyData[0].type);
var items = POLICY.checkItems(this.countOrderItems(order), policyData[0].barcodes);
var result = POLICY.calcAmount(items);
console.log(POLICY.report(result));
}
module.exports = POS;