@softwear/latestcollectioncore 1.0.108 → 1.0.109

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -7,35 +7,15 @@ const filtrex_1 = require("filtrex");
7
7
  const types_1 = require("./types");
8
8
  const transaction_1 = __importDefault(require("./transaction"));
9
9
  const date_fns_1 = require("date-fns");
10
+ const index_1 = require("./index");
10
11
  // fields in Vector
11
- const { QTY_TRANSACTION, QTY_STOCK, AMOUNT_STOCK, QTY_SHELF_STOCK, AMOUNT_SHELF_STOCK, AMOUNT_REVALUATE, QTY_RECIEVED, AMOUNT_RECIEVED, QTY_SOLD, AMOUNT_SOLD, AMOUNT_SOLD_EXCL, COSTPRICE_SOLD, QTY_CHANGE, AMOUNT_CHANGE, QTY_TRANSIT, AMOUNT_TRANSIT, QTY_PO, AMOUNT_PO, QTY_PO_COMPLETE, AMOUNT_PO_COMPLETE, QTY_MINIMUM_STOCK, AMOUNT_MINIMUM_STOCK, QTY_CONSIGNMENT, AMOUNT_CONSIGNMENT, COSTPRICE_CONSIGNMENT, QTY_PICKLIST, AMOUNT_PICKLIST, COSTPRICE_PICKLIST, QTY_REORDER, AMOUNT_REORDER, COSTPRICE_REORDER, QTY_ORDER, AMOUNT_ORDER, COSTPRICE_ORDER, QTY_B2B_RESOLD, AMOUNT_B2B_RESOLD, COSTPRICE_B2B_RESOLD, QTY_B2B_RETURN, AMOUNT_B2B_RETURN, COSTPRICE_B2B_RETURN, QTY_B2B_SOLD, AMOUNT_B2B_SOLD, COSTPRICE_B2B_SOLD, } = transaction_1.default.dbTransactionVector;
12
- const DATABASE_VECTOR_LENGTH = 43;
13
- // DERIVED FIELDS
14
- const AMOUNT_SOLD_MAX = DATABASE_VECTOR_LENGTH + 0;
15
- const AMOUNT_SOLD_DISCOUNT = DATABASE_VECTOR_LENGTH + 1;
16
- const MAX_RECIEVE_TIMESTAMP = DATABASE_VECTOR_LENGTH + 2;
17
- const STOCK_TIME_PRODUCT = DATABASE_VECTOR_LENGTH + 3;
18
- const STOCKAMOUNT_TIME_PRODUCT = DATABASE_VECTOR_LENGTH + 4;
19
- const QTY_RETURN = DATABASE_VECTOR_LENGTH + 5;
20
- const AMOUNT_RETURN = DATABASE_VECTOR_LENGTH + 6;
12
+ const { QTY_TRANSACTION, QTY_STOCK, AMOUNT_STOCK, QTY_SHELF_STOCK, AMOUNT_SHELF_STOCK, AMOUNT_REVALUATE, QTY_RECIEVED, AMOUNT_RECIEVED, QTY_SOLD, AMOUNT_SOLD, AMOUNT_SOLD_EXCL, COSTPRICE_SOLD, QTY_CHANGE, AMOUNT_CHANGE, QTY_TRANSIT, AMOUNT_TRANSIT, QTY_PO, AMOUNT_PO, QTY_PO_COMPLETE, AMOUNT_PO_COMPLETE, QTY_MINIMUM_STOCK, AMOUNT_MINIMUM_STOCK, QTY_CONSIGNMENT, AMOUNT_CONSIGNMENT, COSTPRICE_CONSIGNMENT, QTY_PICKLIST, AMOUNT_PICKLIST, COSTPRICE_PICKLIST, QTY_REORDER, AMOUNT_REORDER, COSTPRICE_REORDER, QTY_ORDER, AMOUNT_ORDER, COSTPRICE_ORDER, QTY_B2B_RESOLD, AMOUNT_B2B_RESOLD, COSTPRICE_B2B_RESOLD, QTY_B2B_RETURN, AMOUNT_B2B_RETURN, COSTPRICE_B2B_RETURN, QTY_B2B_SOLD, AMOUNT_B2B_SOLD, COSTPRICE_B2B_SOLD,
13
+ // Derived fields
14
+ AMOUNT_SOLD_MAX, AMOUNT_SOLD_DISCOUNT, MAX_RECIEVE_TIMESTAMP, STOCK_TIME_PRODUCT, STOCKAMOUNT_TIME_PRODUCT, QTY_RETURN, AMOUNT_RETURN,
15
+ // Post aggregation fields
16
+ SELLOUT_PERCENTAGE, ROI, QTY_AVG_STOCK, VALUE_AVG_STOCK, QTY_TURNOVER_VELOCITY, AMOUNT_TURNOVER_VELOCITY, PROFITABILITY, MARGIN, PROFIT, QTY_END_SHELF_STOCK, AMOUNT_END_SHELF_STOCK, QTY_END_STOCK, AMOUNT_END_STOCK, RETURN_PERCENTAGE, QTY_SOLD_BEFORE_RETURNS, } = transaction_1.default.dbTransactionVector;
21
17
  // Vector length to allocate for aggregation
22
- const VECTOR_LENGTH = DATABASE_VECTOR_LENGTH + 7;
23
- // POST AGGREGATION COLUMNS
24
- const SELLOUT_PERCENTAGE = VECTOR_LENGTH + 0;
25
- const ROI = VECTOR_LENGTH + 1;
26
- const QTY_AVG_STOCK = VECTOR_LENGTH + 2;
27
- const VALUE_AVG_STOCK = VECTOR_LENGTH + 3;
28
- const QTY_TURNOVER_VELOCITY = VECTOR_LENGTH + 4;
29
- const AMOUNT_TURNOVER_VELOCITY = VECTOR_LENGTH + 5;
30
- const PROFITABILITY = VECTOR_LENGTH + 6;
31
- const MARGIN = VECTOR_LENGTH + 7;
32
- const PROFIT = VECTOR_LENGTH + 8;
33
- const QTY_END_SHELF_STOCK = VECTOR_LENGTH + 9;
34
- const AMOUNT_END_SHELF_STOCK = VECTOR_LENGTH + 10;
35
- const QTY_END_STOCK = VECTOR_LENGTH + 11;
36
- const AMOUNT_END_STOCK = VECTOR_LENGTH + 12;
37
- const RETURN_PERCENTAGE = VECTOR_LENGTH + 13;
38
- const QTY_SOLD_BEFORE_RETURNS = VECTOR_LENGTH + 14;
18
+ const VECTOR_LENGTH = 50;
39
19
  const BEGIN_STOCK_VECTOR_START = QTY_STOCK;
40
20
  const BEGIN_STOCK_VECTOR_END = AMOUNT_SHELF_STOCK + 1;
41
21
  const msYear = 24 * 3600 * 365 * 1000;
@@ -81,8 +61,12 @@ function addTransactionToAggregations(beginTimestamp, endTimestamp, aggregateKey
81
61
  aggregateVector = new Float64Array(VECTOR_LENGTH);
82
62
  rawAggregations[aggregateKey] = aggregateVector;
83
63
  }
64
+ if (!transaction.vector)
65
+ transaction.vector = transaction_1.default.buildVector(transaction);
66
+ if (Array.isArray(transaction.vector))
67
+ transaction.vector = Float64Array.from(transaction.vector);
84
68
  const v = transaction.vector;
85
- if (transaction.type == '1' && transaction.time > aggregateVector[MAX_RECIEVE_TIMESTAMP])
69
+ if (transaction.type == types_1.transactionTypeE.RECEIVING && transaction.time > aggregateVector[MAX_RECIEVE_TIMESTAMP])
86
70
  aggregateVector[MAX_RECIEVE_TIMESTAMP] = transaction.time;
87
71
  if (transaction.time <= beginTimestamp) {
88
72
  addVectors(aggregateVector, v, BEGIN_STOCK_VECTOR_START, BEGIN_STOCK_VECTOR_END);
@@ -179,11 +163,15 @@ function aggregator({ beginTimestamp, endTimestamp, filterExpression, aggregatio
179
163
  aggregationExpressionCache[aggregationDependency] = aggregateKey;
180
164
  }
181
165
  // Prepare joined values for derived fields
182
- if (transaction.type == '2') {
166
+ if (transaction.type == types_1.transactionTypeE.SALE) {
183
167
  const sku = globalRelations['sku'][transaction.ean];
168
+ if (!transaction.vector)
169
+ transaction.vector = transaction_1.default.buildVector(transaction);
170
+ if (Array.isArray(transaction.vector))
171
+ transaction.vector = Float64Array.from(transaction.vector);
184
172
  const v = transaction.vector;
185
- v[AMOUNT_SOLD_MAX] = ((sku === null || sku === void 0 ? void 0 : sku.price) || 0) * v[QTY_SOLD];
186
- v[AMOUNT_SOLD_DISCOUNT] = v[AMOUNT_SOLD_MAX] - v[AMOUNT_SOLD];
173
+ v[AMOUNT_SOLD_MAX] = (0, index_1.round2)(((sku === null || sku === void 0 ? void 0 : sku.price) || 0) * v[QTY_SOLD]);
174
+ v[AMOUNT_SOLD_DISCOUNT] = (0, index_1.round2)(v[AMOUNT_SOLD_MAX] - v[AMOUNT_SOLD]);
187
175
  }
188
176
  if (totals)
189
177
  addTransactionToAggregations(beginTimestamp, endTimestamp, '** TOTAL **', rawAggregations, transaction, maxRows);
@@ -44,68 +44,30 @@ declare const _default: {
44
44
  QTY_B2B_SOLD: number;
45
45
  AMOUNT_B2B_SOLD: number;
46
46
  COSTPRICE_B2B_SOLD: number;
47
+ AMOUNT_SOLD_MAX: number;
48
+ AMOUNT_SOLD_DISCOUNT: number;
49
+ MAX_RECIEVE_TIMESTAMP: number;
50
+ STOCK_TIME_PRODUCT: number;
51
+ STOCKAMOUNT_TIME_PRODUCT: number;
52
+ QTY_RETURN: number;
53
+ AMOUNT_RETURN: number;
54
+ SELLOUT_PERCENTAGE: number;
55
+ ROI: number;
56
+ QTY_AVG_STOCK: number;
57
+ VALUE_AVG_STOCK: number;
58
+ QTY_TURNOVER_VELOCITY: number;
59
+ AMOUNT_TURNOVER_VELOCITY: number;
60
+ PROFITABILITY: number;
61
+ MARGIN: number;
62
+ PROFIT: number;
63
+ QTY_END_SHELF_STOCK: number;
64
+ AMOUNT_END_SHELF_STOCK: number;
65
+ QTY_END_STOCK: number;
66
+ AMOUNT_END_STOCK: number;
67
+ RETURN_PERCENTAGE: number;
68
+ QTY_SOLD_BEFORE_RETURNS: number;
47
69
  };
48
70
  buildTransaction: (transaction: TransactionI) => dbTransactionI | undefined;
49
- buildVector: (transaction: TransactionI) => number[];
71
+ buildVector: (transaction: TransactionI) => Float64Array;
50
72
  };
51
73
  export default _default;
52
- /**
53
- TODO:
54
-
55
- FOXPRO CODE STILL TO CONVERT FOR WHOLESALE
56
-
57
- CASE _trtype == 96 && TRANSACTION_ORDER
58
- replace ;
59
- n_ordered with qty, ;
60
- a_ordered with qty* _price, ;
61
- c_ordered with qty* _cost
62
- CASE _trtype == 93 && TRANSACTION_PRESOLD
63
- replace ;
64
- n_stock with -qty, ;
65
- a_stock with -qty* _cost, ;
66
- n_sstock with -qty, ;
67
- a_sstock with -qty* _cost, ;
68
- n_presold with qty, ;
69
- a_presold with qty* _price,;
70
- c_presold with qty* _cost
71
- CASE _trtype == 97 && TRANSACTION_PREORDER
72
- replace ;
73
- n_preord with qty, ;
74
- a_preord with qty* _price, ;
75
- c_preord with qty* _cost
76
- CASE _trtype == 94 && TRANSACTION_PICKLIST
77
- replace ;
78
- n_sstock with -qty, ;
79
- a_sstock with -qty* _cost, ;
80
- n_picked with qty, ;
81
- a_picked with qty* _price, ;
82
- c_picked with qty* _cost
83
- CASE _trtype == 95 && TRANSACTION_PREPICKLIST
84
- replace ;
85
- n_sstock with -qty, ;
86
- a_sstock with -qty* _cost, ;
87
- n_prepick with qty, ;
88
- a_prepick with qty* _price, ;
89
- c_prepick with qty* _cost
90
- CASE _trtype == 5 && TRANSACTION_RETURN_SUPPLIER
91
- replace ;
92
- n_stock with -qty, ;
93
- a_stock with -qty* _cost, ;
94
- n_sstock with -qty, ;
95
- a_sstock with -qty* _cost, ;
96
- n_recieved with -qty, ;
97
- a_recieved with -qty* _cost
98
- CASE _trtype == 6 && TRANSACTION_RETURN_CUSTOMER [C ]
99
- replace ;
100
- n_stock with qty, ;
101
- a_stock with qty* _cost, ;
102
- n_sstock with qty, ;
103
- a_sstock with qty* _cost, ;
104
- n_return with qty, ;
105
- a_return with qty* _price, ;
106
- c_return with qty* _cost
107
-
108
- CASE _trtype == 7 && TRANSACTION_CREDIT [CK]
109
- replace ;
110
- a_return with qty* _price
111
- */
@@ -47,12 +47,35 @@ const dbTransactionVector = {
47
47
  QTY_B2B_SOLD: 40,
48
48
  AMOUNT_B2B_SOLD: 41,
49
49
  COSTPRICE_B2B_SOLD: 42,
50
+ // Derived fields
51
+ AMOUNT_SOLD_MAX: 43,
52
+ AMOUNT_SOLD_DISCOUNT: 44,
53
+ MAX_RECIEVE_TIMESTAMP: 45,
54
+ STOCK_TIME_PRODUCT: 46,
55
+ STOCKAMOUNT_TIME_PRODUCT: 47,
56
+ QTY_RETURN: 48,
57
+ AMOUNT_RETURN: 49,
58
+ // Post aggregation fields
59
+ SELLOUT_PERCENTAGE: 50,
60
+ ROI: 51,
61
+ QTY_AVG_STOCK: 52,
62
+ VALUE_AVG_STOCK: 53,
63
+ QTY_TURNOVER_VELOCITY: 54,
64
+ AMOUNT_TURNOVER_VELOCITY: 55,
65
+ PROFITABILITY: 56,
66
+ MARGIN: 57,
67
+ PROFIT: 58,
68
+ QTY_END_SHELF_STOCK: 59,
69
+ AMOUNT_END_SHELF_STOCK: 60,
70
+ QTY_END_STOCK: 61,
71
+ AMOUNT_END_STOCK: 62,
72
+ RETURN_PERCENTAGE: 63,
73
+ QTY_SOLD_BEFORE_RETURNS: 64,
50
74
  };
51
75
  const tv = dbTransactionVector;
52
76
  const buildVector = function (transaction) {
53
77
  if (transaction.type == types_1.transactionTypeE.RECEIVING) {
54
- const vector = new Array(tv.AMOUNT_RECIEVED + 1);
55
- vector.fill(0);
78
+ const vector = new Float64Array(tv.AMOUNT_RECIEVED + 1);
56
79
  vector[tv.QTY_TRANSACTION] = transaction.qty;
57
80
  vector[tv.QTY_STOCK] = transaction.qty;
58
81
  vector[tv.AMOUNT_STOCK] = (0, index_1.round2)(transaction.buyprice * transaction.qty);
@@ -63,8 +86,7 @@ const buildVector = function (transaction) {
63
86
  return vector;
64
87
  }
65
88
  if (transaction.type == types_1.transactionTypeE.SALE) {
66
- const vector = new Array(tv.COSTPRICE_SOLD + 1);
67
- vector.fill(0);
89
+ const vector = new Float64Array(tv.AMOUNT_SOLD_DISCOUNT + 1);
68
90
  vector[tv.QTY_TRANSACTION] = transaction.qty;
69
91
  vector[tv.QTY_STOCK] = -transaction.qty;
70
92
  vector[tv.AMOUNT_STOCK] = (0, index_1.round2)(-transaction.buyprice * transaction.qty);
@@ -76,9 +98,20 @@ const buildVector = function (transaction) {
76
98
  vector[tv.COSTPRICE_SOLD] = (0, index_1.round2)(transaction.buyprice * transaction.qty);
77
99
  return vector;
78
100
  }
101
+ if (transaction.type == types_1.transactionTypeE.RE_SOLD) {
102
+ const vector = new Float64Array(tv.COSTPRICE_B2B_SOLD + 1);
103
+ vector[tv.QTY_TRANSACTION] = transaction.qty;
104
+ vector[tv.QTY_STOCK] = -transaction.qty;
105
+ vector[tv.AMOUNT_STOCK] = (0, index_1.round2)(-transaction.buyprice * transaction.qty);
106
+ vector[tv.QTY_SHELF_STOCK] = -transaction.qty;
107
+ vector[tv.AMOUNT_SHELF_STOCK] = (0, index_1.round2)(-transaction.buyprice * transaction.qty);
108
+ vector[tv.QTY_B2B_SOLD] = transaction.qty;
109
+ vector[tv.AMOUNT_B2B_SOLD] = (0, index_1.round2)(transaction.sellprice * transaction.qty);
110
+ vector[tv.COSTPRICE_B2B_SOLD] = (0, index_1.round2)(transaction.buyprice * transaction.qty);
111
+ return vector;
112
+ }
79
113
  if (transaction.type == types_1.transactionTypeE.TRANSIT) {
80
- const vector = new Array(tv.AMOUNT_TRANSIT + 1);
81
- vector.fill(0);
114
+ const vector = new Float64Array(tv.AMOUNT_TRANSIT + 1);
82
115
  vector[tv.QTY_TRANSACTION] = transaction.qty;
83
116
  vector[tv.QTY_STOCK] = transaction.qty;
84
117
  vector[tv.AMOUNT_STOCK] = (0, index_1.round2)(transaction.buyprice * transaction.qty);
@@ -89,8 +122,7 @@ const buildVector = function (transaction) {
89
122
  return vector;
90
123
  }
91
124
  if (transaction.type == types_1.transactionTypeE.CHANGE || transaction.type == types_1.transactionTypeE.START_STOCK) {
92
- const vector = new Array(tv.AMOUNT_CHANGE + 1);
93
- vector.fill(0);
125
+ const vector = new Float64Array(tv.AMOUNT_CHANGE + 1);
94
126
  vector[tv.QTY_TRANSACTION] = transaction.qty;
95
127
  vector[tv.QTY_STOCK] = transaction.qty;
96
128
  vector[tv.AMOUNT_STOCK] = (0, index_1.round2)(transaction.buyprice * transaction.qty);
@@ -101,8 +133,7 @@ const buildVector = function (transaction) {
101
133
  return vector;
102
134
  }
103
135
  if (transaction.type == types_1.transactionTypeE.RE_VALUATION) {
104
- const vector = new Array(tv.AMOUNT_REVALUATE + 1);
105
- vector.fill(0);
136
+ const vector = new Float64Array(tv.AMOUNT_REVALUATE + 1);
106
137
  vector[tv.QTY_TRANSACTION] = transaction.qty;
107
138
  vector[tv.AMOUNT_STOCK] = (0, index_1.round2)(transaction.buyprice * transaction.qty);
108
139
  vector[tv.AMOUNT_SHELF_STOCK] = (0, index_1.round2)(transaction.buyprice * transaction.qty);
@@ -110,38 +141,78 @@ const buildVector = function (transaction) {
110
141
  return vector;
111
142
  }
112
143
  if (transaction.type == types_1.transactionTypeE.START_SHELF_STOCK) {
113
- const vector = new Array(tv.AMOUNT_SHELF_STOCK + 1);
114
- vector.fill(0);
144
+ const vector = new Float64Array(tv.AMOUNT_SHELF_STOCK + 1);
115
145
  vector[tv.QTY_TRANSACTION] = transaction.qty;
116
146
  vector[tv.QTY_SHELF_STOCK] = transaction.qty;
117
147
  vector[tv.AMOUNT_SHELF_STOCK] = (0, index_1.round2)(transaction.buyprice * transaction.qty);
118
148
  return vector;
119
149
  }
120
150
  if (transaction.type == types_1.transactionTypeE.PURCHASE_ORDER) {
121
- const vector = new Array(tv.AMOUNT_PO + 1);
122
- vector.fill(0);
151
+ const vector = new Float64Array(tv.AMOUNT_PO + 1);
123
152
  vector[tv.QTY_TRANSACTION] = transaction.qty;
124
153
  vector[tv.QTY_PO] = transaction.qty;
125
154
  vector[tv.AMOUNT_PO] = (0, index_1.round2)(transaction.buyprice * transaction.qty);
126
155
  return vector;
127
156
  }
128
157
  if (transaction.type == types_1.transactionTypeE.PURCHASE_ORDER_COMPLETE) {
129
- const vector = new Array(tv.AMOUNT_PO_COMPLETE + 1);
130
- vector.fill(0);
158
+ const vector = new Float64Array(tv.AMOUNT_PO_COMPLETE + 1);
131
159
  vector[tv.QTY_TRANSACTION] = transaction.qty;
132
160
  vector[tv.QTY_PO_COMPLETE] = transaction.qty;
133
161
  vector[tv.AMOUNT_PO_COMPLETE] = (0, index_1.round2)(transaction.buyprice * transaction.qty);
134
162
  return vector;
135
163
  }
136
164
  if (transaction.type == types_1.transactionTypeE.MINIMUM_STOCK) {
137
- const vector = new Array(tv.AMOUNT_MINIMUM_STOCK + 1);
138
- vector.fill(0);
165
+ const vector = new Float64Array(tv.AMOUNT_MINIMUM_STOCK + 1);
139
166
  vector[tv.QTY_TRANSACTION] = transaction.qty;
140
167
  vector[tv.QTY_MINIMUM_STOCK] = transaction.qty;
141
168
  vector[tv.AMOUNT_MINIMUM_STOCK] = (0, index_1.round2)(transaction.buyprice * transaction.qty);
142
169
  return vector;
143
170
  }
144
- return [];
171
+ if (transaction.type == types_1.transactionTypeE.ORDER) {
172
+ const vector = new Float64Array(tv.COSTPRICE_ORDER + 1);
173
+ vector[tv.QTY_TRANSACTION] = transaction.qty;
174
+ vector[tv.QTY_ORDER] = transaction.qty;
175
+ vector[tv.AMOUNT_ORDER] = (0, index_1.round2)(transaction.sellprice * transaction.qty);
176
+ vector[tv.COSTPRICE_ORDER] = (0, index_1.round2)(transaction.buyprice * transaction.qty);
177
+ return vector;
178
+ }
179
+ if (transaction.type == types_1.transactionTypeE.RE_ORDER) {
180
+ const vector = new Float64Array(tv.COSTPRICE_REORDER + 1);
181
+ vector[tv.QTY_TRANSACTION] = transaction.qty;
182
+ vector[tv.QTY_REORDER] = transaction.qty;
183
+ vector[tv.AMOUNT_REORDER] = (0, index_1.round2)(transaction.sellprice * transaction.qty);
184
+ vector[tv.COSTPRICE_REORDER] = (0, index_1.round2)(transaction.buyprice * transaction.qty);
185
+ return vector;
186
+ }
187
+ if (transaction.type == types_1.transactionTypeE.PICK_LIST) {
188
+ const vector = new Float64Array(tv.COSTPRICE_PICKLIST + 1);
189
+ vector[tv.QTY_TRANSACTION] = transaction.qty;
190
+ vector[tv.QTY_SHELF_STOCK] = transaction.qty;
191
+ vector[tv.AMOUNT_SHELF_STOCK] = (0, index_1.round2)(transaction.buyprice * transaction.qty);
192
+ vector[tv.QTY_PICKLIST] = transaction.qty;
193
+ vector[tv.AMOUNT_PICKLIST] = (0, index_1.round2)(transaction.sellprice * transaction.qty);
194
+ vector[tv.COSTPRICE_PICKLIST] = (0, index_1.round2)(transaction.buyprice * transaction.qty);
195
+ return vector;
196
+ }
197
+ if (transaction.type == types_1.transactionTypeE.RETURN_CUSTOMER) {
198
+ const vector = new Float64Array(tv.COSTPRICE_B2B_RETURN + 1);
199
+ vector[tv.QTY_TRANSACTION] = transaction.qty;
200
+ vector[tv.QTY_STOCK] = transaction.qty;
201
+ vector[tv.AMOUNT_STOCK] = (0, index_1.round2)(transaction.buyprice * transaction.qty);
202
+ vector[tv.QTY_SHELF_STOCK] = transaction.qty;
203
+ vector[tv.AMOUNT_SHELF_STOCK] = (0, index_1.round2)(transaction.buyprice * transaction.qty);
204
+ vector[tv.QTY_B2B_RETURN] = transaction.qty;
205
+ vector[tv.AMOUNT_B2B_RETURN] = (0, index_1.round2)(transaction.sellprice * transaction.qty);
206
+ vector[tv.COSTPRICE_B2B_RETURN] = (0, index_1.round2)(transaction.buyprice * transaction.qty);
207
+ return vector;
208
+ }
209
+ if (transaction.type == types_1.transactionTypeE.CREDIT_INVOICE) {
210
+ const vector = new Float64Array(tv.AMOUNT_B2B_RETURN + 1);
211
+ vector[tv.QTY_TRANSACTION] = transaction.qty;
212
+ vector[tv.AMOUNT_B2B_RETURN] = (0, index_1.round2)(transaction.sellprice * transaction.qty);
213
+ return vector;
214
+ }
215
+ return new Float64Array();
145
216
  };
146
217
  /**
147
218
  *
@@ -169,63 +240,3 @@ const buildTransaction = function (transaction) {
169
240
  return dbTransaction;
170
241
  };
171
242
  exports.default = { dbTransactionVector, buildTransaction, buildVector };
172
- /**
173
- TODO:
174
-
175
- FOXPRO CODE STILL TO CONVERT FOR WHOLESALE
176
-
177
- CASE _trtype == 96 && TRANSACTION_ORDER
178
- replace ;
179
- n_ordered with qty, ;
180
- a_ordered with qty* _price, ;
181
- c_ordered with qty* _cost
182
- CASE _trtype == 93 && TRANSACTION_PRESOLD
183
- replace ;
184
- n_stock with -qty, ;
185
- a_stock with -qty* _cost, ;
186
- n_sstock with -qty, ;
187
- a_sstock with -qty* _cost, ;
188
- n_presold with qty, ;
189
- a_presold with qty* _price,;
190
- c_presold with qty* _cost
191
- CASE _trtype == 97 && TRANSACTION_PREORDER
192
- replace ;
193
- n_preord with qty, ;
194
- a_preord with qty* _price, ;
195
- c_preord with qty* _cost
196
- CASE _trtype == 94 && TRANSACTION_PICKLIST
197
- replace ;
198
- n_sstock with -qty, ;
199
- a_sstock with -qty* _cost, ;
200
- n_picked with qty, ;
201
- a_picked with qty* _price, ;
202
- c_picked with qty* _cost
203
- CASE _trtype == 95 && TRANSACTION_PREPICKLIST
204
- replace ;
205
- n_sstock with -qty, ;
206
- a_sstock with -qty* _cost, ;
207
- n_prepick with qty, ;
208
- a_prepick with qty* _price, ;
209
- c_prepick with qty* _cost
210
- CASE _trtype == 5 && TRANSACTION_RETURN_SUPPLIER
211
- replace ;
212
- n_stock with -qty, ;
213
- a_stock with -qty* _cost, ;
214
- n_sstock with -qty, ;
215
- a_sstock with -qty* _cost, ;
216
- n_recieved with -qty, ;
217
- a_recieved with -qty* _cost
218
- CASE _trtype == 6 && TRANSACTION_RETURN_CUSTOMER [C ]
219
- replace ;
220
- n_stock with qty, ;
221
- a_stock with qty* _cost, ;
222
- n_sstock with qty, ;
223
- a_sstock with qty* _cost, ;
224
- n_return with qty, ;
225
- a_return with qty* _price, ;
226
- c_return with qty* _cost
227
-
228
- CASE _trtype == 7 && TRANSACTION_CREDIT [CK]
229
- replace ;
230
- a_return with qty* _price
231
- */
package/dist/types.d.ts CHANGED
@@ -240,11 +240,10 @@ declare enum transactionTypeE {
240
240
  PURCHASE_ORDER = "14",
241
241
  PURCHASE_ORDER_COMPLETE = "15",
242
242
  MINIMUM_STOCK = "18",
243
- PRE_SOLD = "93",
243
+ RE_SOLD = "93",
244
244
  PICK_LIST = "94",
245
- PRE_PICK_LIST = "95",
246
245
  ORDER = "96",
247
- PRE_ORDER = "97",
246
+ RE_ORDER = "97",
248
247
  OFFER = "98"
249
248
  }
250
249
  interface dbTransactionI {
@@ -255,9 +254,13 @@ interface dbTransactionI {
255
254
  customer?: string;
256
255
  docnr: string;
257
256
  time: number;
258
- vector: number[];
257
+ vector?: Float64Array;
259
258
  row?: number;
260
259
  unixtime?: number;
260
+ qty?: number;
261
+ sellprice?: number;
262
+ vat?: number;
263
+ buyprice?: number;
261
264
  }
262
265
  interface TransactionI {
263
266
  type: transactionTypeE;
package/dist/types.js CHANGED
@@ -46,11 +46,10 @@ var transactionTypeE;
46
46
  transactionTypeE["PURCHASE_ORDER"] = "14";
47
47
  transactionTypeE["PURCHASE_ORDER_COMPLETE"] = "15";
48
48
  transactionTypeE["MINIMUM_STOCK"] = "18";
49
- transactionTypeE["PRE_SOLD"] = "93";
49
+ transactionTypeE["RE_SOLD"] = "93";
50
50
  transactionTypeE["PICK_LIST"] = "94";
51
- transactionTypeE["PRE_PICK_LIST"] = "95";
52
51
  transactionTypeE["ORDER"] = "96";
53
- transactionTypeE["PRE_ORDER"] = "97";
52
+ transactionTypeE["RE_ORDER"] = "97";
54
53
  transactionTypeE["OFFER"] = "98";
55
54
  })(transactionTypeE || (transactionTypeE = {}));
56
55
  exports.transactionTypeE = transactionTypeE;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@softwear/latestcollectioncore",
3
- "version": "1.0.108",
3
+ "version": "1.0.109",
4
4
  "description": "Core functions for LatestCollections applications",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -1,7 +1,8 @@
1
1
  import { compileExpression } from 'filtrex'
2
- import { TransactionI, RaGI, AggregateFnI, AggregatorFnI, HrTimeframeI, TimeGranularityE, SkuI } from './types'
3
- import transaction from './transaction'
2
+ import { TransactionI, RaGI, AggregateFnI, AggregatorFnI, HrTimeframeI, TimeGranularityE, SkuI, transactionTypeE } from './types'
3
+ import transactionFunctions from './transaction'
4
4
  import { format, parse } from 'date-fns'
5
+ import { round2 } from './index'
5
6
 
6
7
  // fields in Vector
7
8
  const {
@@ -48,38 +49,36 @@ const {
48
49
  QTY_B2B_SOLD,
49
50
  AMOUNT_B2B_SOLD,
50
51
  COSTPRICE_B2B_SOLD,
51
- } = transaction.dbTransactionVector
52
52
 
53
- const DATABASE_VECTOR_LENGTH = 43
53
+ // Derived fields
54
+ AMOUNT_SOLD_MAX,
55
+ AMOUNT_SOLD_DISCOUNT,
56
+ MAX_RECIEVE_TIMESTAMP,
57
+ STOCK_TIME_PRODUCT,
58
+ STOCKAMOUNT_TIME_PRODUCT,
59
+ QTY_RETURN,
60
+ AMOUNT_RETURN,
54
61
 
55
- // DERIVED FIELDS
56
- const AMOUNT_SOLD_MAX = DATABASE_VECTOR_LENGTH + 0
57
- const AMOUNT_SOLD_DISCOUNT = DATABASE_VECTOR_LENGTH + 1
58
- const MAX_RECIEVE_TIMESTAMP = DATABASE_VECTOR_LENGTH + 2
59
- const STOCK_TIME_PRODUCT = DATABASE_VECTOR_LENGTH + 3
60
- const STOCKAMOUNT_TIME_PRODUCT = DATABASE_VECTOR_LENGTH + 4
61
- const QTY_RETURN = DATABASE_VECTOR_LENGTH + 5
62
- const AMOUNT_RETURN = DATABASE_VECTOR_LENGTH + 6
62
+ // Post aggregation fields
63
+ SELLOUT_PERCENTAGE,
64
+ ROI,
65
+ QTY_AVG_STOCK,
66
+ VALUE_AVG_STOCK,
67
+ QTY_TURNOVER_VELOCITY,
68
+ AMOUNT_TURNOVER_VELOCITY,
69
+ PROFITABILITY,
70
+ MARGIN,
71
+ PROFIT,
72
+ QTY_END_SHELF_STOCK,
73
+ AMOUNT_END_SHELF_STOCK,
74
+ QTY_END_STOCK,
75
+ AMOUNT_END_STOCK,
76
+ RETURN_PERCENTAGE,
77
+ QTY_SOLD_BEFORE_RETURNS,
78
+ } = transactionFunctions.dbTransactionVector
63
79
 
64
80
  // Vector length to allocate for aggregation
65
- const VECTOR_LENGTH = DATABASE_VECTOR_LENGTH + 7
66
-
67
- // POST AGGREGATION COLUMNS
68
- const SELLOUT_PERCENTAGE = VECTOR_LENGTH + 0
69
- const ROI = VECTOR_LENGTH + 1
70
- const QTY_AVG_STOCK = VECTOR_LENGTH + 2
71
- const VALUE_AVG_STOCK = VECTOR_LENGTH + 3
72
- const QTY_TURNOVER_VELOCITY = VECTOR_LENGTH + 4
73
- const AMOUNT_TURNOVER_VELOCITY = VECTOR_LENGTH + 5
74
- const PROFITABILITY = VECTOR_LENGTH + 6
75
- const MARGIN = VECTOR_LENGTH + 7
76
- const PROFIT = VECTOR_LENGTH + 8
77
- const QTY_END_SHELF_STOCK = VECTOR_LENGTH + 9
78
- const AMOUNT_END_SHELF_STOCK = VECTOR_LENGTH + 10
79
- const QTY_END_STOCK = VECTOR_LENGTH + 11
80
- const AMOUNT_END_STOCK = VECTOR_LENGTH + 12
81
- const RETURN_PERCENTAGE = VECTOR_LENGTH + 13
82
- const QTY_SOLD_BEFORE_RETURNS = VECTOR_LENGTH + 14
81
+ const VECTOR_LENGTH = 50
83
82
 
84
83
  const BEGIN_STOCK_VECTOR_START = QTY_STOCK
85
84
  const BEGIN_STOCK_VECTOR_END = AMOUNT_SHELF_STOCK + 1
@@ -128,8 +127,10 @@ function addTransactionToAggregations(beginTimestamp: number, endTimestamp: numb
128
127
  aggregateVector = new Float64Array(VECTOR_LENGTH)
129
128
  rawAggregations[aggregateKey] = aggregateVector
130
129
  }
130
+ if (!transaction.vector) transaction.vector = transactionFunctions.buildVector(transaction)
131
+ if (Array.isArray(transaction.vector)) transaction.vector = Float64Array.from(transaction.vector)
131
132
  const v = transaction.vector
132
- if (transaction.type == '1' && transaction.time > aggregateVector[MAX_RECIEVE_TIMESTAMP]) aggregateVector[MAX_RECIEVE_TIMESTAMP] = transaction.time
133
+ if (transaction.type == transactionTypeE.RECEIVING && transaction.time > aggregateVector[MAX_RECIEVE_TIMESTAMP]) aggregateVector[MAX_RECIEVE_TIMESTAMP] = transaction.time
133
134
  if (transaction.time <= beginTimestamp) {
134
135
  addVectors(aggregateVector, v, BEGIN_STOCK_VECTOR_START, BEGIN_STOCK_VECTOR_END)
135
136
  addVectors(aggregateVector, v, QTY_CONSIGNMENT, COSTPRICE_PICKLIST + 1)
@@ -239,11 +240,13 @@ function aggregator({
239
240
  aggregationExpressionCache[aggregationDependency] = aggregateKey
240
241
  }
241
242
  // Prepare joined values for derived fields
242
- if (transaction.type == '2') {
243
+ if (transaction.type == transactionTypeE.SALE) {
243
244
  const sku = globalRelations['sku'][transaction.ean]
245
+ if (!transaction.vector) transaction.vector = transactionFunctions.buildVector(transaction)
246
+ if (Array.isArray(transaction.vector)) transaction.vector = Float64Array.from(transaction.vector)
244
247
  const v = transaction.vector
245
- v[AMOUNT_SOLD_MAX] = (sku?.price || 0) * v[QTY_SOLD]
246
- v[AMOUNT_SOLD_DISCOUNT] = v[AMOUNT_SOLD_MAX] - v[AMOUNT_SOLD]
248
+ v[AMOUNT_SOLD_MAX] = round2((sku?.price || 0) * v[QTY_SOLD])
249
+ v[AMOUNT_SOLD_DISCOUNT] = round2(v[AMOUNT_SOLD_MAX] - v[AMOUNT_SOLD])
247
250
  }
248
251
 
249
252
  if (totals) addTransactionToAggregations(beginTimestamp, endTimestamp, '** TOTAL **', rawAggregations, transaction, maxRows)