@pmcretail/mapper-library 0.0.39 → 0.0.43
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.
- package/README.md +24 -24
- package/esm2022/lib/RJ-mapper.class.mjs +875 -0
- package/esm2022/lib/TransactionDocumentBuilder.mjs +1240 -0
- package/esm2022/lib/WebReturn-mapper.class.mjs +324 -0
- package/esm2022/lib/WebReturnSalesforceMapper.class.mjs +410 -0
- package/esm2022/lib/basket.service.mjs +516 -0
- package/esm2022/lib/mapper-library.component.mjs +22 -0
- package/esm2022/lib/mapper-library.model.mjs +39 -0
- package/esm2022/lib/mapper-library.module.mjs +21 -0
- package/esm2022/lib/number-util.service.mjs +40 -0
- package/esm2022/pmcretail-mapper-library.mjs +5 -0
- package/esm2022/public-api.mjs +9 -0
- package/fesm2022/pmcretail-mapper-library.mjs +3482 -0
- package/fesm2022/pmcretail-mapper-library.mjs.map +1 -0
- package/index.d.ts +6 -0
- package/lib/RJ-mapper.class.d.ts +80 -79
- package/lib/RJ-mapper.class.d.ts.map +1 -0
- package/lib/TransactionDocumentBuilder.d.ts +271 -270
- package/lib/TransactionDocumentBuilder.d.ts.map +1 -0
- package/lib/WebReturn-mapper.class.d.ts +27 -26
- package/lib/WebReturn-mapper.class.d.ts.map +1 -0
- package/lib/WebReturnSalesforceMapper.class.d.ts +35 -34
- package/lib/WebReturnSalesforceMapper.class.d.ts.map +1 -0
- package/lib/basket.service.d.ts +105 -103
- package/lib/basket.service.d.ts.map +1 -0
- package/lib/mapper-library.component.d.ts +9 -5
- package/lib/mapper-library.component.d.ts.map +1 -0
- package/lib/mapper-library.model.d.ts +694 -693
- package/lib/mapper-library.model.d.ts.map +1 -0
- package/lib/mapper-library.module.d.ts +8 -2
- package/lib/mapper-library.module.d.ts.map +1 -0
- package/lib/number-util.service.d.ts +13 -9
- package/lib/number-util.service.d.ts.map +1 -0
- package/package.json +21 -17
- package/pmcretail-mapper-library.d.ts.map +1 -0
- package/public-api.d.ts +6 -5
- package/public-api.d.ts.map +1 -0
- package/bundles/pmcretail-mapper-library.umd.js +0 -8542
- package/bundles/pmcretail-mapper-library.umd.js.map +0 -1
- package/bundles/pmcretail-mapper-library.umd.min.js +0 -16
- package/bundles/pmcretail-mapper-library.umd.min.js.map +0 -1
- package/esm2015/lib/RJ-mapper.class.js +0 -1464
- package/esm2015/lib/TransactionDocumentBuilder.js +0 -1535
- package/esm2015/lib/WebReturn-mapper.class.js +0 -501
- package/esm2015/lib/WebReturnSalesforceMapper.class.js +0 -683
- package/esm2015/lib/basket.service.js +0 -851
- package/esm2015/lib/mapper-library.component.js +0 -27
- package/esm2015/lib/mapper-library.model.js +0 -1442
- package/esm2015/lib/mapper-library.module.js +0 -21
- package/esm2015/lib/number-util.service.js +0 -78
- package/esm2015/pmcretail-mapper-library.js +0 -10
- package/esm2015/public-api.js +0 -14
- package/esm5/lib/RJ-mapper.class.js +0 -1762
- package/esm5/lib/TransactionDocumentBuilder.js +0 -2469
- package/esm5/lib/WebReturn-mapper.class.js +0 -592
- package/esm5/lib/WebReturnSalesforceMapper.class.js +0 -857
- package/esm5/lib/basket.service.js +0 -1076
- package/esm5/lib/mapper-library.component.js +0 -29
- package/esm5/lib/mapper-library.model.js +0 -1442
- package/esm5/lib/mapper-library.module.js +0 -25
- package/esm5/lib/number-util.service.js +0 -95
- package/esm5/pmcretail-mapper-library.js +0 -10
- package/esm5/public-api.js +0 -14
- package/fesm2015/pmcretail-mapper-library.js +0 -6594
- package/fesm2015/pmcretail-mapper-library.js.map +0 -1
- package/fesm5/pmcretail-mapper-library.js +0 -8326
- package/fesm5/pmcretail-mapper-library.js.map +0 -1
- package/pmcretail-mapper-library.d.ts +0 -5
- package/pmcretail-mapper-library.metadata.json +0 -1
|
@@ -0,0 +1,3482 @@
|
|
|
1
|
+
import * as i0 from '@angular/core';
|
|
2
|
+
import { Component, NgModule, Injectable } from '@angular/core';
|
|
3
|
+
import { BehaviorSubject } from 'rxjs';
|
|
4
|
+
import * as i1 from '@angular/common';
|
|
5
|
+
|
|
6
|
+
class MapperLibraryComponent {
|
|
7
|
+
constructor() { }
|
|
8
|
+
ngOnInit() {
|
|
9
|
+
}
|
|
10
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.4", ngImport: i0, type: MapperLibraryComponent, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
|
|
11
|
+
static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "18.2.4", type: MapperLibraryComponent, selector: "lib-mapper-library", ngImport: i0, template: `
|
|
12
|
+
<p>
|
|
13
|
+
mapper-library works!
|
|
14
|
+
</p>
|
|
15
|
+
`, isInline: true }); }
|
|
16
|
+
}
|
|
17
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.4", ngImport: i0, type: MapperLibraryComponent, decorators: [{
|
|
18
|
+
type: Component,
|
|
19
|
+
args: [{ selector: 'lib-mapper-library', template: `
|
|
20
|
+
<p>
|
|
21
|
+
mapper-library works!
|
|
22
|
+
</p>
|
|
23
|
+
` }]
|
|
24
|
+
}], ctorParameters: () => [] });
|
|
25
|
+
|
|
26
|
+
class MapperLibraryModule {
|
|
27
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.4", ngImport: i0, type: MapperLibraryModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
|
|
28
|
+
static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "18.2.4", ngImport: i0, type: MapperLibraryModule, declarations: [MapperLibraryComponent], exports: [MapperLibraryComponent] }); }
|
|
29
|
+
static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "18.2.4", ngImport: i0, type: MapperLibraryModule }); }
|
|
30
|
+
}
|
|
31
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.4", ngImport: i0, type: MapperLibraryModule, decorators: [{
|
|
32
|
+
type: NgModule,
|
|
33
|
+
args: [{
|
|
34
|
+
declarations: [
|
|
35
|
+
MapperLibraryComponent
|
|
36
|
+
],
|
|
37
|
+
imports: [],
|
|
38
|
+
exports: [
|
|
39
|
+
MapperLibraryComponent
|
|
40
|
+
]
|
|
41
|
+
}]
|
|
42
|
+
}] });
|
|
43
|
+
|
|
44
|
+
var TRANSACTION_TYPE;
|
|
45
|
+
(function (TRANSACTION_TYPE) {
|
|
46
|
+
TRANSACTION_TYPE["SALE"] = "SALE";
|
|
47
|
+
TRANSACTION_TYPE["REFUND"] = "REFUND";
|
|
48
|
+
TRANSACTION_TYPE["SALE_REFUND"] = "SALE_REFUND";
|
|
49
|
+
TRANSACTION_TYPE["SALE_EXCHANGE"] = "SALE_EXCHANGE";
|
|
50
|
+
TRANSACTION_TYPE["VOID"] = "VOID";
|
|
51
|
+
TRANSACTION_TYPE["WEB_RETURNS"] = "WEB_RETURNS";
|
|
52
|
+
})(TRANSACTION_TYPE || (TRANSACTION_TYPE = {}));
|
|
53
|
+
var DELIVERY_METHODS;
|
|
54
|
+
(function (DELIVERY_METHODS) {
|
|
55
|
+
DELIVERY_METHODS[DELIVERY_METHODS["DELIVERY"] = 1] = "DELIVERY";
|
|
56
|
+
DELIVERY_METHODS[DELIVERY_METHODS["DROP_SHIP"] = 2] = "DROP_SHIP";
|
|
57
|
+
DELIVERY_METHODS[DELIVERY_METHODS["COLLECT_FROM_STORE"] = 3] = "COLLECT_FROM_STORE";
|
|
58
|
+
DELIVERY_METHODS[DELIVERY_METHODS["SHIP_TO_STORE"] = 4] = "SHIP_TO_STORE";
|
|
59
|
+
})(DELIVERY_METHODS || (DELIVERY_METHODS = {}));
|
|
60
|
+
var DISCOUNTTYPE;
|
|
61
|
+
(function (DISCOUNTTYPE) {
|
|
62
|
+
DISCOUNTTYPE["PERCENT"] = "Percent";
|
|
63
|
+
DISCOUNTTYPE["AMOUNT"] = "AMOUNT";
|
|
64
|
+
})(DISCOUNTTYPE || (DISCOUNTTYPE = {}));
|
|
65
|
+
var INITIATING_MODULE;
|
|
66
|
+
(function (INITIATING_MODULE) {
|
|
67
|
+
INITIATING_MODULE["EBASKET"] = "eBasket";
|
|
68
|
+
})(INITIATING_MODULE || (INITIATING_MODULE = {}));
|
|
69
|
+
var PROVIDERS;
|
|
70
|
+
(function (PROVIDERS) {
|
|
71
|
+
PROVIDERS["SALESFORCE"] = "Salesforce";
|
|
72
|
+
})(PROVIDERS || (PROVIDERS = {}));
|
|
73
|
+
var PROMOTION_LEVEL;
|
|
74
|
+
(function (PROMOTION_LEVEL) {
|
|
75
|
+
PROMOTION_LEVEL["LINE"] = "LINE";
|
|
76
|
+
PROMOTION_LEVEL["TRANSACTION"] = "TRANSACTION";
|
|
77
|
+
})(PROMOTION_LEVEL || (PROMOTION_LEVEL = {}));
|
|
78
|
+
var PROMOTION_TYPE;
|
|
79
|
+
(function (PROMOTION_TYPE) {
|
|
80
|
+
PROMOTION_TYPE["COUPON"] = "COUPON";
|
|
81
|
+
})(PROMOTION_TYPE || (PROMOTION_TYPE = {}));
|
|
82
|
+
|
|
83
|
+
class BasketService {
|
|
84
|
+
get isMixedBasketSales() {
|
|
85
|
+
return this._isMixedBasketSales;
|
|
86
|
+
}
|
|
87
|
+
set isMixedBasketSales(v) {
|
|
88
|
+
this._isMixedBasketSales = v;
|
|
89
|
+
}
|
|
90
|
+
constructor(numberUtilService) {
|
|
91
|
+
this.numberUtilService = numberUtilService;
|
|
92
|
+
this.currentBasket = {
|
|
93
|
+
products: [],
|
|
94
|
+
transactionDiscount: [],
|
|
95
|
+
quantity: 0,
|
|
96
|
+
total: 0,
|
|
97
|
+
saleTotal: 0,
|
|
98
|
+
baseCurrency: ''
|
|
99
|
+
};
|
|
100
|
+
this.basketSource = new BehaviorSubject(null);
|
|
101
|
+
this.basket = this.basketSource.asObservable();
|
|
102
|
+
this.productSource = new BehaviorSubject(null);
|
|
103
|
+
this.product = this.productSource.asObservable();
|
|
104
|
+
this.peerSource = new BehaviorSubject(false);
|
|
105
|
+
this.peerSync = this.peerSource.asObservable();
|
|
106
|
+
this.scanSource = new BehaviorSubject(false);
|
|
107
|
+
this.scanner = this.scanSource.asObservable();
|
|
108
|
+
}
|
|
109
|
+
updateBasket(basket) {
|
|
110
|
+
this.currentBasket = basket;
|
|
111
|
+
this.isMixedBasketSales = this.filterProductListWithWebOrder(true).length > 0;
|
|
112
|
+
this.basketSource.next(basket);
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* calculates the total basket value and quantity
|
|
116
|
+
* @param null
|
|
117
|
+
* @returns void
|
|
118
|
+
*/
|
|
119
|
+
updateBasketTotal(basketDetails, basketState) {
|
|
120
|
+
basketDetails.quantity = 0;
|
|
121
|
+
basketDetails.total = 0;
|
|
122
|
+
for (const p of basketDetails.products) {
|
|
123
|
+
basketDetails.quantity = basketDetails.quantity + p.quantity;
|
|
124
|
+
basketDetails.total =
|
|
125
|
+
this.numberUtilService.trimTo2Decimal(basketDetails.total) +
|
|
126
|
+
this.numberUtilService.trimTo2Decimal(p.total);
|
|
127
|
+
}
|
|
128
|
+
console.log("e:basket :basket service : basketDetails updated values for transaction id", basketDetails.transactionId, JSON.stringify(basketDetails));
|
|
129
|
+
basketDetails.basketTotal = basketDetails.total;
|
|
130
|
+
basketState.updateBasket(basketDetails);
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* add Line promotion
|
|
134
|
+
* @param null
|
|
135
|
+
* @returns basketDetails
|
|
136
|
+
*/
|
|
137
|
+
addlinePromotion(promotionList, basketDetails) {
|
|
138
|
+
console.log("e:basket :basket Service : promotionList and basketDetails for linePromotions", JSON.stringify(promotionList), JSON.stringify(basketDetails));
|
|
139
|
+
if (promotionList &&
|
|
140
|
+
promotionList.result &&
|
|
141
|
+
promotionList.result.linePromotions &&
|
|
142
|
+
promotionList.result.linePromotions.length > 0) {
|
|
143
|
+
for (var element of basketDetails.products) {
|
|
144
|
+
for (var promotionelement of promotionList.result.linePromotions) {
|
|
145
|
+
if (element.itemLineId.toString() ===
|
|
146
|
+
promotionelement.itemLineId.toString()) {
|
|
147
|
+
element.linePromotions = promotionelement;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
return basketDetails;
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* add Transaction promotion
|
|
156
|
+
* @param null
|
|
157
|
+
* @returns basketDetails
|
|
158
|
+
*/
|
|
159
|
+
addTransactionPromotion(promotionList, basketdetails) {
|
|
160
|
+
console.log("e:basket :basket Service : promotionList and basketDetails for transactionPromotion", JSON.stringify(promotionList), JSON.stringify(basketdetails), JSON.stringify(basketdetails.transactionPromotion));
|
|
161
|
+
if (promotionList &&
|
|
162
|
+
promotionList.result &&
|
|
163
|
+
promotionList.result.transactionPromotion &&
|
|
164
|
+
promotionList.result.transactionPromotion.length > 0) {
|
|
165
|
+
promotionList.result.transactionPromotion.forEach((tPromotion) => {
|
|
166
|
+
let transactionPromotionEntryUpdated = Object.assign({}, tPromotion);
|
|
167
|
+
transactionPromotionEntryUpdated.itemLineIds = basketdetails.products.map((product) => {
|
|
168
|
+
return product.itemLineId;
|
|
169
|
+
});
|
|
170
|
+
if (!basketdetails.transactionPromotion) {
|
|
171
|
+
basketdetails.transactionPromotion = [];
|
|
172
|
+
}
|
|
173
|
+
basketdetails.transactionPromotion.push(transactionPromotionEntryUpdated);
|
|
174
|
+
basketdetails = this.transactionPromotionProductPortionCalc(basketdetails, transactionPromotionEntryUpdated);
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
console.log("basket details in refund calculation file", JSON.stringify(basketdetails));
|
|
178
|
+
return basketdetails;
|
|
179
|
+
}
|
|
180
|
+
updateProductTotalForSummary(basketDetails) {
|
|
181
|
+
/*sale- product refundedQuantity = undefined
|
|
182
|
+
partial refund - product refundedQuantity is > 0
|
|
183
|
+
total refund - proudct refundedQuantity is > 0
|
|
184
|
+
exchange - exchange product refundedQuantity is > 0
|
|
185
|
+
new product refundedQuantity = undefined
|
|
186
|
+
old product without exchange refundedQuantity = 0
|
|
187
|
+
unreference refund-product refundedQuantity is > 0 */
|
|
188
|
+
basketDetails.total = 0;
|
|
189
|
+
basketDetails.quantity = 0;
|
|
190
|
+
for (var product of basketDetails.products) {
|
|
191
|
+
if (product.linePromotions) {
|
|
192
|
+
product.total = product.linePromotions.promotionLinePrice;
|
|
193
|
+
}
|
|
194
|
+
else if (product.lineDiscount && !product.linePromotions) {
|
|
195
|
+
product.total = product.lineDiscount.discountedLinePrice;
|
|
196
|
+
}
|
|
197
|
+
else {
|
|
198
|
+
product.total = product.totalLinePrice;
|
|
199
|
+
}
|
|
200
|
+
product.total =
|
|
201
|
+
product.total -
|
|
202
|
+
Math.abs(product.refundedTotal ? product.refundedTotal : 0);
|
|
203
|
+
basketDetails.total += product.total;
|
|
204
|
+
basketDetails.quantity =
|
|
205
|
+
basketDetails.quantity +
|
|
206
|
+
(product.quantity -
|
|
207
|
+
(product.refundedQuantity ? product.refundedQuantity : 0));
|
|
208
|
+
console.log("e-basket:ExchangeSummaryScreen:update basketdetails total :" +
|
|
209
|
+
basketDetails.total +
|
|
210
|
+
" Product line ID : " +
|
|
211
|
+
product.itemLineId +
|
|
212
|
+
" product total : " +
|
|
213
|
+
product.total, "quantity : " + basketDetails.quantity);
|
|
214
|
+
}
|
|
215
|
+
return this.updateBasketTotalForSummary(basketDetails);
|
|
216
|
+
}
|
|
217
|
+
updateBasketTotalForSummary(basketDetails) {
|
|
218
|
+
basketDetails.basketTotal = basketDetails.total;
|
|
219
|
+
console.info("ebasket : basket Service : update Basket Total for transaction transactionDiscount ", JSON.stringify(basketDetails.transactionDiscount));
|
|
220
|
+
console.info("ebasket : basket Service : update Basket Total for transaction transactionPromotion ", JSON.stringify(basketDetails.transactionPromotion));
|
|
221
|
+
basketDetails = this.updateTransactionPromotion(basketDetails);
|
|
222
|
+
basketDetails = this.updateTransactionDiscount(basketDetails);
|
|
223
|
+
basketDetails.basketTotal = Number(basketDetails.basketTotal.toFixed(2));
|
|
224
|
+
console.info("ebasket : basket Service : update Basket Total: basketTotal after promotion applied for basketTotal", basketDetails.basketTotal);
|
|
225
|
+
return basketDetails;
|
|
226
|
+
}
|
|
227
|
+
updateTransactionDiscount(basketDetails) {
|
|
228
|
+
if (basketDetails.transactionDiscount &&
|
|
229
|
+
basketDetails.transactionDiscount.length > 0) {
|
|
230
|
+
const discountTotal = basketDetails.transactionDiscount.reduce((n, { discountAmount }) => n + discountAmount, 0);
|
|
231
|
+
console.log("ebasket : basket Service : discountTotal ", discountTotal);
|
|
232
|
+
basketDetails.basketTotal =
|
|
233
|
+
basketDetails.basketTotal - Math.abs(discountTotal);
|
|
234
|
+
}
|
|
235
|
+
return basketDetails;
|
|
236
|
+
}
|
|
237
|
+
updateTransactionPromotion(basketDetails) {
|
|
238
|
+
if (basketDetails.transactionPromotion &&
|
|
239
|
+
basketDetails.transactionPromotion.length > 0) {
|
|
240
|
+
const discountTotal = basketDetails.transactionPromotion.reduce((n, { promotionAmount }) => n + promotionAmount, 0);
|
|
241
|
+
basketDetails.basketTotal =
|
|
242
|
+
basketDetails.basketTotal - Math.abs(discountTotal);
|
|
243
|
+
}
|
|
244
|
+
return basketDetails;
|
|
245
|
+
}
|
|
246
|
+
updateBasketTotalWithoutDiscount(basket) {
|
|
247
|
+
basket.total = 0;
|
|
248
|
+
basket.quantity = 0;
|
|
249
|
+
for (var product of basket.products) {
|
|
250
|
+
if (product.linePromotions) {
|
|
251
|
+
product.total = product.linePromotions.promotionLinePrice;
|
|
252
|
+
}
|
|
253
|
+
else if (product.lineDiscount && !product.linePromotions) {
|
|
254
|
+
product.total = product.lineDiscount.discountedLinePrice || 0;
|
|
255
|
+
}
|
|
256
|
+
else {
|
|
257
|
+
product.total = product.totalLinePrice;
|
|
258
|
+
}
|
|
259
|
+
product.total =
|
|
260
|
+
product.total -
|
|
261
|
+
Math.abs(product.refundedTotal ? product.refundedTotal : 0);
|
|
262
|
+
basket.total += product.total;
|
|
263
|
+
basket.quantity =
|
|
264
|
+
basket.quantity +
|
|
265
|
+
(product.quantity -
|
|
266
|
+
(product.refundedQuantity ? product.refundedQuantity : 0));
|
|
267
|
+
console.log("e-basket:basket service:update basketdetails total :" +
|
|
268
|
+
JSON.stringify(basket) +
|
|
269
|
+
basket.total +
|
|
270
|
+
" Product line ID : " +
|
|
271
|
+
product.itemLineId +
|
|
272
|
+
" product total : " +
|
|
273
|
+
product.total);
|
|
274
|
+
}
|
|
275
|
+
basket.basketTotal = basket.total;
|
|
276
|
+
return basket;
|
|
277
|
+
}
|
|
278
|
+
updateBasketTotalWithDiscounts(basket) {
|
|
279
|
+
console.log("e:basket :RefundBasketScreen : this.basketDetails new values", basket, JSON.stringify(basket.basketTotal));
|
|
280
|
+
if (basket.transactionPromotion && basket.transactionPromotion.length > 0) {
|
|
281
|
+
const discountTotal = basket.transactionPromotion.reduce((n, { promotionAmount }) => n + promotionAmount, 0);
|
|
282
|
+
basket.basketTotal = basket.basketTotal - discountTotal;
|
|
283
|
+
}
|
|
284
|
+
if (basket.transactionDiscount && basket.transactionDiscount.length > 0) {
|
|
285
|
+
const discountTotal = basket.transactionDiscount.reduce((n, { discountAmount }) => n + discountAmount, 0);
|
|
286
|
+
basket.basketTotal = basket.basketTotal - discountTotal;
|
|
287
|
+
}
|
|
288
|
+
console.log("e:basket :RefundBasketScreen : basket new values", JSON.stringify(basket));
|
|
289
|
+
return basket;
|
|
290
|
+
}
|
|
291
|
+
transactionDiscountAndPromotionProductortionCalculation(basket) {
|
|
292
|
+
if (basket.transactionDiscount && basket.transactionDiscount.length > 0) {
|
|
293
|
+
basket.transactionDiscount.forEach((discount) => (basket = this.transactionDiscountProductPortionCalc(basket, discount)));
|
|
294
|
+
}
|
|
295
|
+
if (basket.transactionPromotion && basket.transactionPromotion.length > 0) {
|
|
296
|
+
basket.transactionPromotion.forEach((promotion) => {
|
|
297
|
+
basket = this.transactionPromotionProductPortionCalc(basket, promotion);
|
|
298
|
+
});
|
|
299
|
+
}
|
|
300
|
+
console.log("ebasket: basket item discount protion calculation", basket, basket.products);
|
|
301
|
+
return basket;
|
|
302
|
+
}
|
|
303
|
+
transactionPromotionProductPortionCalc(basket, promotion) {
|
|
304
|
+
let total = 0;
|
|
305
|
+
let percentage = 0;
|
|
306
|
+
{
|
|
307
|
+
basket.products.forEach((p) => {
|
|
308
|
+
if (promotion.itemLineIds.includes(p.itemLineId)) {
|
|
309
|
+
p = this.validateProductItemDiscount(p);
|
|
310
|
+
const productContributionInTotal = this.numberUtilService.trimTo2Decimal2(p.itemDiscounts.trnDiscountsPortion) +
|
|
311
|
+
this.numberUtilService.trimTo2Decimal2(p.itemDiscounts.trnPromotionsPortion) -
|
|
312
|
+
this.numberUtilService.trimTo2Decimal2(p.itemDiscounts.refundPortion);
|
|
313
|
+
total += (p.total - this.numberUtilService.trimTo2Decimal2(productContributionInTotal));
|
|
314
|
+
}
|
|
315
|
+
});
|
|
316
|
+
console.log(`ebasket: trnsactionPromotion: ${JSON.stringify(promotion)}, selected products total: ${total}`);
|
|
317
|
+
basket.products.forEach((product) => {
|
|
318
|
+
product = this.validateProductItemDiscount(product);
|
|
319
|
+
const productContributionInTotal = this.numberUtilService.trimTo2Decimal2(product.itemDiscounts.trnDiscountsPortion) +
|
|
320
|
+
this.numberUtilService.trimTo2Decimal2(product.itemDiscounts.trnPromotionsPortion) -
|
|
321
|
+
this.numberUtilService.trimTo2Decimal2(product.itemDiscounts.refundPortion);
|
|
322
|
+
if (promotion.itemLineIds.includes(product.itemLineId)) {
|
|
323
|
+
percentage = ((product.total - this.numberUtilService.trimTo2Decimal2(productContributionInTotal)) / total) * 100;
|
|
324
|
+
product.itemDiscounts.trnPromotionsPortion +=
|
|
325
|
+
(promotion.promotionAmount * percentage) / 100;
|
|
326
|
+
product.itemDiscounts.trnPromotionsPortion = this.numberUtilService.trimTo2Decimal2(product.itemDiscounts.trnPromotionsPortion);
|
|
327
|
+
}
|
|
328
|
+
});
|
|
329
|
+
}
|
|
330
|
+
return basket;
|
|
331
|
+
}
|
|
332
|
+
transactionDiscountProductPortionCalc(basket, discount) {
|
|
333
|
+
let total = 0;
|
|
334
|
+
let percentage = 0;
|
|
335
|
+
basket.products.forEach((p) => {
|
|
336
|
+
if (discount.itemLineIds.includes(p.itemLineId)) {
|
|
337
|
+
p = this.validateProductItemDiscount(p);
|
|
338
|
+
const productContributionInTotal = this.numberUtilService.trimTo2Decimal2(p.itemDiscounts.trnDiscountsPortion) +
|
|
339
|
+
this.numberUtilService.trimTo2Decimal2(p.itemDiscounts.trnPromotionsPortion) -
|
|
340
|
+
this.numberUtilService.trimTo2Decimal2(p.itemDiscounts.refundPortion);
|
|
341
|
+
total += (p.total - this.numberUtilService.trimTo2Decimal2(productContributionInTotal));
|
|
342
|
+
}
|
|
343
|
+
});
|
|
344
|
+
console.log(`ebasket: trnsactionDiscount: ${JSON.stringify(discount)}, selected products total: ${total}`);
|
|
345
|
+
basket.products.forEach((product) => {
|
|
346
|
+
product = this.validateProductItemDiscount(product);
|
|
347
|
+
console.log(product.discountable, "ebasket : basket service : discountable in basket service");
|
|
348
|
+
const productContributionInTotal = this.numberUtilService.trimTo2Decimal2(product.itemDiscounts.trnDiscountsPortion) +
|
|
349
|
+
this.numberUtilService.trimTo2Decimal2(product.itemDiscounts.trnPromotionsPortion) -
|
|
350
|
+
this.numberUtilService.trimTo2Decimal2(product.itemDiscounts.refundPortion);
|
|
351
|
+
if (discount.itemLineIds.includes(product.itemLineId) && product.discountable == true) {
|
|
352
|
+
percentage = ((product.total - this.numberUtilService.trimTo2Decimal2(productContributionInTotal)) / total) * 100;
|
|
353
|
+
product.itemDiscounts.trnDiscountsPortion +=
|
|
354
|
+
(discount.discountAmount * percentage) / 100;
|
|
355
|
+
product.itemDiscounts.trnDiscountsPortion = this.numberUtilService.trimTo2Decimal2(product.itemDiscounts.trnDiscountsPortion);
|
|
356
|
+
}
|
|
357
|
+
});
|
|
358
|
+
return basket;
|
|
359
|
+
}
|
|
360
|
+
validateProductItemDiscount(product) {
|
|
361
|
+
if (!product.itemDiscounts) {
|
|
362
|
+
product.itemDiscounts = {
|
|
363
|
+
trnDiscountsPortion: 0,
|
|
364
|
+
trnPromotionsPortion: 0,
|
|
365
|
+
refundPortion: 0,
|
|
366
|
+
};
|
|
367
|
+
}
|
|
368
|
+
return product;
|
|
369
|
+
}
|
|
370
|
+
markProduct(product) {
|
|
371
|
+
this.productSource.next(product);
|
|
372
|
+
}
|
|
373
|
+
stopPeerSyncProcess(peerSync) {
|
|
374
|
+
this.peerSource.next(peerSync);
|
|
375
|
+
}
|
|
376
|
+
scanStart(isScanning) {
|
|
377
|
+
this.scanSource.next(isScanning);
|
|
378
|
+
}
|
|
379
|
+
promotionRemainingCalculation(promotion) {
|
|
380
|
+
var promotionValue = 0;
|
|
381
|
+
promotion.forEach((element) => {
|
|
382
|
+
promotionValue += element.promotionAmount;
|
|
383
|
+
});
|
|
384
|
+
return promotionValue;
|
|
385
|
+
}
|
|
386
|
+
discountRemainingCalculation(discount) {
|
|
387
|
+
var discountValue = 0;
|
|
388
|
+
discount.forEach((element) => {
|
|
389
|
+
discountValue += element.discountAmount;
|
|
390
|
+
});
|
|
391
|
+
return discountValue;
|
|
392
|
+
}
|
|
393
|
+
discountRefundedCalculation(discount) {
|
|
394
|
+
var discountValue = 0;
|
|
395
|
+
discount.forEach((element) => {
|
|
396
|
+
if (element.discountAmount < 0) {
|
|
397
|
+
discountValue += element.discountAmount;
|
|
398
|
+
}
|
|
399
|
+
});
|
|
400
|
+
return discountValue;
|
|
401
|
+
}
|
|
402
|
+
generateNewItemLineId(products) {
|
|
403
|
+
let largestNumber = 0;
|
|
404
|
+
if (products.length > 0) {
|
|
405
|
+
let itemLineIdArray = products.map((product) => {
|
|
406
|
+
return product.itemLineId;
|
|
407
|
+
});
|
|
408
|
+
largestNumber = itemLineIdArray.reduce((a, b) => Math.max(a, b));
|
|
409
|
+
}
|
|
410
|
+
return largestNumber + 1;
|
|
411
|
+
}
|
|
412
|
+
updateBasketProductDataAsPerQuantity(product, quantity) {
|
|
413
|
+
console.log(`ebasket: updateBasketProductDataAsPerQuantity : ${quantity} product: ${JSON.stringify(product)}`);
|
|
414
|
+
product.quantity = quantity;
|
|
415
|
+
if (product.hasOwnProperty("lineDiscount")) {
|
|
416
|
+
// && this.product.quantity !== this.productDetailForm.controls.quantity.value
|
|
417
|
+
product.lineDiscount.discountedLinePrice = Number(this.numberUtilService.getFlooredFixed(product.lineDiscount.unitPrice * quantity, 2));
|
|
418
|
+
product.lineDiscount.discountAmount =
|
|
419
|
+
product.totalLinePrice - product.lineDiscount.discountedLinePrice;
|
|
420
|
+
}
|
|
421
|
+
else {
|
|
422
|
+
product.totalLinePrice =
|
|
423
|
+
quantity * this.numberUtilService.trimTo2Decimal(product.selectedPrice);
|
|
424
|
+
}
|
|
425
|
+
if (product.lineDiscount) {
|
|
426
|
+
product.total = product.lineDiscount.discountedLinePrice;
|
|
427
|
+
}
|
|
428
|
+
else {
|
|
429
|
+
product.total = product.totalLinePrice;
|
|
430
|
+
}
|
|
431
|
+
console.log(`ebasket: updateBasketProductDataAsPerQuantity : ${quantity} product: ${JSON.stringify(product)}`);
|
|
432
|
+
return product;
|
|
433
|
+
}
|
|
434
|
+
filterProductListWithWebOrder(isWebOrder) {
|
|
435
|
+
console.log("ebasket: filterProductListWithWebOrder hit", JSON.stringify(this.currentBasket.products));
|
|
436
|
+
if (isWebOrder)
|
|
437
|
+
return this.currentBasket.products.filter((x) => x.isWebOrder);
|
|
438
|
+
else {
|
|
439
|
+
return this.currentBasket.products.filter((x) => !x.isWebOrder);
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
filterProductListWithDelivery() {
|
|
443
|
+
console.log("ebasket: filterProductListWithDelivery hit", JSON.stringify(this.currentBasket.products));
|
|
444
|
+
return this.currentBasket.products.filter((x) => x.deliveryMethod === DELIVERY_METHODS.DELIVERY.toString());
|
|
445
|
+
}
|
|
446
|
+
filterProductListWithDeliveryGroup(group, products) {
|
|
447
|
+
console.log("ebasket: filterProductListWithDeliveryGroup hit", JSON.stringify(products));
|
|
448
|
+
return products.filter((x) => x.deliveryGroup === group);
|
|
449
|
+
}
|
|
450
|
+
generateNewDeliveryGroupNumber(products) {
|
|
451
|
+
let largestNumber = 0;
|
|
452
|
+
if (products.length > 0) {
|
|
453
|
+
let deliveryGroupArr = products.map((product) => {
|
|
454
|
+
if (product.deliveryGroup) {
|
|
455
|
+
return parseInt(product.deliveryGroup);
|
|
456
|
+
}
|
|
457
|
+
return 0;
|
|
458
|
+
});
|
|
459
|
+
largestNumber = deliveryGroupArr.reduce((a, b) => Math.max(a, b));
|
|
460
|
+
}
|
|
461
|
+
return (largestNumber + 1).toString();
|
|
462
|
+
}
|
|
463
|
+
getDeliveryGroupNumbers(products) {
|
|
464
|
+
console.log("getDeliveryGroupNumbers initiating : ", JSON.stringify(products));
|
|
465
|
+
let uniqueAndsortedResult = [];
|
|
466
|
+
if (products.length > 0) {
|
|
467
|
+
let deliveryGroupArr = products.map((product) => {
|
|
468
|
+
if (product.deliveryGroup) {
|
|
469
|
+
return parseInt(product.deliveryGroup);
|
|
470
|
+
}
|
|
471
|
+
else if (product.deliveryMethod === "1") {
|
|
472
|
+
return 1;
|
|
473
|
+
}
|
|
474
|
+
return 0;
|
|
475
|
+
});
|
|
476
|
+
uniqueAndsortedResult = Array.from(new Set(deliveryGroupArr)).sort((a, b) => a - b);
|
|
477
|
+
console.log("getDeliveryGroupNumbers : ", JSON.stringify(uniqueAndsortedResult));
|
|
478
|
+
}
|
|
479
|
+
return uniqueAndsortedResult;
|
|
480
|
+
}
|
|
481
|
+
updateProductsWithNewDeliveryGroupNumber(products) {
|
|
482
|
+
console.log("updateProductsWithNewDeliveryGroupNumber initiating : ", JSON.stringify(products));
|
|
483
|
+
let newGroupNumber = this.generateNewDeliveryGroupNumber(this.currentBasket.products);
|
|
484
|
+
if (products.length > 0) {
|
|
485
|
+
this.currentBasket.products.forEach(cBProducts => {
|
|
486
|
+
products.forEach(element => {
|
|
487
|
+
if (cBProducts.itemLineId === element.itemLineId) {
|
|
488
|
+
cBProducts.deliveryGroup = newGroupNumber;
|
|
489
|
+
}
|
|
490
|
+
});
|
|
491
|
+
});
|
|
492
|
+
}
|
|
493
|
+
this.updateBasket(this.currentBasket);
|
|
494
|
+
return;
|
|
495
|
+
}
|
|
496
|
+
calculateEstimatedTime(products) {
|
|
497
|
+
try {
|
|
498
|
+
let time;
|
|
499
|
+
let estmatedTime = 0;
|
|
500
|
+
let estimatedDays = "Hours";
|
|
501
|
+
products.forEach((element) => {
|
|
502
|
+
if (element.leadTime.type.toLocaleLowerCase() === "weeks") {
|
|
503
|
+
time = Number(element.leadTime.value) * 24 * 7;
|
|
504
|
+
estmatedTime = Math.max(estmatedTime, time);
|
|
505
|
+
estimatedDays = (estmatedTime === time) ? element.leadTime.type : estimatedDays;
|
|
506
|
+
console.log("week", estmatedTime, estimatedDays);
|
|
507
|
+
}
|
|
508
|
+
else if (element.leadTime.type.toLocaleLowerCase() === "days") {
|
|
509
|
+
time = Number(element.leadTime.value) * 24;
|
|
510
|
+
estmatedTime = Math.max(estmatedTime, time);
|
|
511
|
+
estimatedDays = (estmatedTime === time) ? element.leadTime.type : estimatedDays;
|
|
512
|
+
console.log("days", estmatedTime, estimatedDays);
|
|
513
|
+
}
|
|
514
|
+
else if (element.leadTime.type.toLocaleLowerCase() === "months") {
|
|
515
|
+
time = Number(element.leadTime.value) * 24 * 30;
|
|
516
|
+
estmatedTime = Math.max(estmatedTime, time);
|
|
517
|
+
estimatedDays = (estmatedTime === time) ? element.leadTime.type : estimatedDays;
|
|
518
|
+
console.log("months", estmatedTime, estimatedDays);
|
|
519
|
+
}
|
|
520
|
+
else if (element.leadTime.type.toLocaleLowerCase() === "years") {
|
|
521
|
+
time = Number(element.leadTime.value) * 24 * 365;
|
|
522
|
+
estmatedTime = Math.max(estmatedTime, time);
|
|
523
|
+
estimatedDays = (estmatedTime === time) ? element.leadTime.type : estimatedDays;
|
|
524
|
+
console.log("years", estmatedTime, estimatedDays);
|
|
525
|
+
}
|
|
526
|
+
else {
|
|
527
|
+
time = Number(element.leadTime.value);
|
|
528
|
+
estmatedTime = Math.max(estmatedTime, time);
|
|
529
|
+
estimatedDays = (estmatedTime === time) ? element.leadTime.type : estimatedDays;
|
|
530
|
+
console.log("hours", estmatedTime, estimatedDays);
|
|
531
|
+
}
|
|
532
|
+
});
|
|
533
|
+
if (estimatedDays.toLocaleLowerCase() === "days") {
|
|
534
|
+
estmatedTime = estmatedTime / 24;
|
|
535
|
+
}
|
|
536
|
+
else if (estimatedDays.toLocaleLowerCase() === "weeks") {
|
|
537
|
+
estmatedTime = estmatedTime / (24 * 7);
|
|
538
|
+
}
|
|
539
|
+
else if (estimatedDays.toLocaleLowerCase() === "months") {
|
|
540
|
+
estmatedTime = estmatedTime / (24 * 30);
|
|
541
|
+
}
|
|
542
|
+
else if (estimatedDays.toLocaleLowerCase() === "years") {
|
|
543
|
+
estmatedTime = estmatedTime / (24 * 365);
|
|
544
|
+
}
|
|
545
|
+
let estimate = {
|
|
546
|
+
value: estmatedTime.toString(),
|
|
547
|
+
type: estimatedDays
|
|
548
|
+
};
|
|
549
|
+
return estimate;
|
|
550
|
+
}
|
|
551
|
+
catch (error) {
|
|
552
|
+
console.log("error in calculateEstimatedTime", error);
|
|
553
|
+
}
|
|
554
|
+
return 0;
|
|
555
|
+
}
|
|
556
|
+
updateProductsWithDeliveryGroupNumber(oldGroup, newGroup) {
|
|
557
|
+
console.log("updateProductsWithDeliveryGroupNumber initiating");
|
|
558
|
+
this.currentBasket.products.forEach(cBProducts => {
|
|
559
|
+
if (cBProducts.deliveryGroup === oldGroup) {
|
|
560
|
+
cBProducts.deliveryGroup = newGroup;
|
|
561
|
+
}
|
|
562
|
+
});
|
|
563
|
+
this.updateBasket(this.currentBasket);
|
|
564
|
+
return;
|
|
565
|
+
}
|
|
566
|
+
getDeliveryInfo() {
|
|
567
|
+
console.log("getDeliveryGroupInfor initiating");
|
|
568
|
+
try {
|
|
569
|
+
let groupInfo = {
|
|
570
|
+
groups: []
|
|
571
|
+
};
|
|
572
|
+
this.getDeliveryGroupNumbers(this.currentBasket.products).forEach((groupNumber) => {
|
|
573
|
+
let group = {
|
|
574
|
+
groupNumber: groupNumber,
|
|
575
|
+
items: [],
|
|
576
|
+
estimate: {
|
|
577
|
+
type: "Hours",
|
|
578
|
+
value: "0"
|
|
579
|
+
}
|
|
580
|
+
};
|
|
581
|
+
this.currentBasket.products.forEach(cBProducts => {
|
|
582
|
+
if (cBProducts.deliveryGroup === groupNumber.toString()) {
|
|
583
|
+
group.items.push(cBProducts);
|
|
584
|
+
}
|
|
585
|
+
});
|
|
586
|
+
group.estimate = this.calculateEstimatedTime(group.items);
|
|
587
|
+
groupInfo.groups.push(group);
|
|
588
|
+
});
|
|
589
|
+
return groupInfo;
|
|
590
|
+
}
|
|
591
|
+
catch (error) {
|
|
592
|
+
console.log("error", error);
|
|
593
|
+
}
|
|
594
|
+
}
|
|
595
|
+
}
|
|
596
|
+
|
|
597
|
+
class NumberUtilService {
|
|
598
|
+
constructor(cp) {
|
|
599
|
+
this.cp = cp;
|
|
600
|
+
}
|
|
601
|
+
trimTo2Decimal(no) {
|
|
602
|
+
//return Math.floor(no * 100) / 100;
|
|
603
|
+
return no;
|
|
604
|
+
}
|
|
605
|
+
trimTo2Decimal2(no) {
|
|
606
|
+
// SEAM-11411 - Had to change 2nd param to 3 to fix rounding issue (FIXME - Needs a new story for refactoring)
|
|
607
|
+
return Number(this.getFlooredFixed(no, 3));
|
|
608
|
+
}
|
|
609
|
+
getFlooredFixed(v, d) {
|
|
610
|
+
return (Math.floor(v * Math.pow(10, d)) / Math.pow(10, d)).toFixed(d);
|
|
611
|
+
}
|
|
612
|
+
AppendWithCurrencySymbol(numValue, currencyCode) {
|
|
613
|
+
let returnValue = "";
|
|
614
|
+
if (numValue) {
|
|
615
|
+
const numb = parseFloat(numValue.toString().replace(',', ''));
|
|
616
|
+
returnValue = this.cp.transform(Number(numValue).toFixed(2), currencyCode.toLocaleUpperCase(), "symbol");
|
|
617
|
+
console.log("AppendWithCurrencySymbol :" + returnValue);
|
|
618
|
+
}
|
|
619
|
+
else {
|
|
620
|
+
returnValue = this.cp.transform("0.00", currencyCode.toLocaleUpperCase(), "symbol");
|
|
621
|
+
}
|
|
622
|
+
return returnValue;
|
|
623
|
+
}
|
|
624
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.4", ngImport: i0, type: NumberUtilService, deps: [{ token: i1.CurrencyPipe }], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
625
|
+
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "18.2.4", ngImport: i0, type: NumberUtilService, providedIn: "root" }); }
|
|
626
|
+
}
|
|
627
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.4", ngImport: i0, type: NumberUtilService, decorators: [{
|
|
628
|
+
type: Injectable,
|
|
629
|
+
args: [{
|
|
630
|
+
providedIn: "root",
|
|
631
|
+
}]
|
|
632
|
+
}], ctorParameters: () => [{ type: i1.CurrencyPipe }] });
|
|
633
|
+
|
|
634
|
+
/**
|
|
635
|
+
* Transaction document builder
|
|
636
|
+
*/
|
|
637
|
+
class TransactionDocumentBuilder {
|
|
638
|
+
constructor(transactionDoc, currencyPipe, basketService) {
|
|
639
|
+
this.currencyPipe = currencyPipe;
|
|
640
|
+
this.basketService = basketService;
|
|
641
|
+
this.numberUtilService = new NumberUtilService(currencyPipe);
|
|
642
|
+
this.basketService = new BasketService(this.numberUtilService);
|
|
643
|
+
this.storeInfo = JSON.parse(localStorage.getItem('storeInfo') || '{}');
|
|
644
|
+
if (transactionDoc) {
|
|
645
|
+
this.transactionDocument = transactionDoc;
|
|
646
|
+
}
|
|
647
|
+
else {
|
|
648
|
+
this.transactionDocument = {
|
|
649
|
+
transactionId: "",
|
|
650
|
+
offlineTransactionId: "",
|
|
651
|
+
transactionRef: "",
|
|
652
|
+
dateTime: "",
|
|
653
|
+
orgCode: "",
|
|
654
|
+
storeId: "",
|
|
655
|
+
storeNodeId: "",
|
|
656
|
+
storeNodeStructure: "",
|
|
657
|
+
deviceId: "",
|
|
658
|
+
terminalId: "",
|
|
659
|
+
userId: "",
|
|
660
|
+
initiatingModule: "eBasket",
|
|
661
|
+
export: false,
|
|
662
|
+
basket: {},
|
|
663
|
+
basketSummary: {},
|
|
664
|
+
baseCurrency: "",
|
|
665
|
+
type: "",
|
|
666
|
+
operationStatus: "",
|
|
667
|
+
createdAt: "",
|
|
668
|
+
updatedAt: "",
|
|
669
|
+
id: "",
|
|
670
|
+
currentTransactionDetails: {},
|
|
671
|
+
saleTotal: 0,
|
|
672
|
+
};
|
|
673
|
+
}
|
|
674
|
+
}
|
|
675
|
+
/**
|
|
676
|
+
* Transactions ref
|
|
677
|
+
* @returns ref
|
|
678
|
+
*/
|
|
679
|
+
transactionRef() {
|
|
680
|
+
const storeDetails = JSON.parse(localStorage.getItem('storeInfo') || '{}');
|
|
681
|
+
const date = new Date();
|
|
682
|
+
const random = (((1 + Math.random()) * 0x10000) | 0)
|
|
683
|
+
.toString(16)
|
|
684
|
+
.substring(1);
|
|
685
|
+
this.transactionDocument.transactionRef =
|
|
686
|
+
storeDetails.orgCode + storeDetails.storeId + date.toISOString() + random;
|
|
687
|
+
console.log("ebasket: transaction ref created", this.transactionDocument.transactionRef);
|
|
688
|
+
return this;
|
|
689
|
+
}
|
|
690
|
+
/**
|
|
691
|
+
* Transactions id
|
|
692
|
+
* @param transactionID
|
|
693
|
+
* @returns id
|
|
694
|
+
*/
|
|
695
|
+
transactionId(transactionID, isOnline = true) {
|
|
696
|
+
if (isOnline) {
|
|
697
|
+
this.transactionDocument.transactionId = transactionID;
|
|
698
|
+
}
|
|
699
|
+
return this;
|
|
700
|
+
}
|
|
701
|
+
/**
|
|
702
|
+
* Transactions id
|
|
703
|
+
* @param transactionID
|
|
704
|
+
* @returns id
|
|
705
|
+
*/
|
|
706
|
+
offlineTransactionId(transactionID, isOnline) {
|
|
707
|
+
if (!isOnline) {
|
|
708
|
+
this.transactionDocument.offlineTransactionId = transactionID;
|
|
709
|
+
}
|
|
710
|
+
return this;
|
|
711
|
+
}
|
|
712
|
+
/**
|
|
713
|
+
* storeNode Id
|
|
714
|
+
* @param storeNodeId
|
|
715
|
+
* @returns id
|
|
716
|
+
*/
|
|
717
|
+
storeNodeId(storeNodeId) {
|
|
718
|
+
this.transactionDocument.storeNodeId = storeNodeId;
|
|
719
|
+
return this;
|
|
720
|
+
}
|
|
721
|
+
/**
|
|
722
|
+
* storeNode structure
|
|
723
|
+
* @param storeNodeStructure
|
|
724
|
+
* @returns id
|
|
725
|
+
*/
|
|
726
|
+
storeNodeStructure(storeNodeStructure) {
|
|
727
|
+
this.transactionDocument.storeNodeStructure = storeNodeStructure;
|
|
728
|
+
return this;
|
|
729
|
+
}
|
|
730
|
+
/**
|
|
731
|
+
* Orgs code
|
|
732
|
+
* @param orgCode
|
|
733
|
+
* @returns code
|
|
734
|
+
*/
|
|
735
|
+
orgCode(orgCode) {
|
|
736
|
+
this.transactionDocument.orgCode = orgCode;
|
|
737
|
+
return this;
|
|
738
|
+
}
|
|
739
|
+
/**
|
|
740
|
+
* Stores id
|
|
741
|
+
* @param storeId
|
|
742
|
+
* @returns id
|
|
743
|
+
*/
|
|
744
|
+
storeId(storeId) {
|
|
745
|
+
this.transactionDocument.storeId = storeId;
|
|
746
|
+
return this;
|
|
747
|
+
}
|
|
748
|
+
/**
|
|
749
|
+
* Dates time
|
|
750
|
+
* @returns time
|
|
751
|
+
*/
|
|
752
|
+
dateTime() {
|
|
753
|
+
const date = new Date();
|
|
754
|
+
this.transactionDocument.dateTime = date.toISOString();
|
|
755
|
+
return this;
|
|
756
|
+
}
|
|
757
|
+
/**
|
|
758
|
+
* Devices id
|
|
759
|
+
* @param deviceId
|
|
760
|
+
* @returns id
|
|
761
|
+
*/
|
|
762
|
+
deviceId(deviceId) {
|
|
763
|
+
this.transactionDocument.deviceId = deviceId;
|
|
764
|
+
return this;
|
|
765
|
+
}
|
|
766
|
+
/**
|
|
767
|
+
* terminal id
|
|
768
|
+
* @param terminalId
|
|
769
|
+
* @returns id
|
|
770
|
+
*/
|
|
771
|
+
terminalId(terminalId) {
|
|
772
|
+
this.transactionDocument.terminalId = terminalId;
|
|
773
|
+
return this;
|
|
774
|
+
}
|
|
775
|
+
/**
|
|
776
|
+
* saleExport
|
|
777
|
+
* @param saleExport
|
|
778
|
+
* @returns id
|
|
779
|
+
*/
|
|
780
|
+
export(saleExport) {
|
|
781
|
+
this.transactionDocument.export = saleExport;
|
|
782
|
+
return this;
|
|
783
|
+
}
|
|
784
|
+
/* customer(): TransactionDocumentBuilder {
|
|
785
|
+
const user = JSON.parse(localStorage.getItem('userDetails'));
|
|
786
|
+
this.transactionDocument.customer = user;
|
|
787
|
+
return this;
|
|
788
|
+
} */
|
|
789
|
+
/**
|
|
790
|
+
* Baskets transaction document builder
|
|
791
|
+
* @param basketDetails
|
|
792
|
+
* @returns basket
|
|
793
|
+
*/
|
|
794
|
+
basket(basketDetails) {
|
|
795
|
+
console.log("ebasket: basket details update in transaction document", JSON.stringify(basketDetails));
|
|
796
|
+
this.transactionDocument.subsidiaryId = basketDetails.subsidiaryId || (localStorage.getItem('subsidiaryId') || '');
|
|
797
|
+
this.transactionDocument.basket.products = [];
|
|
798
|
+
this.transactionDocument.basket.lineDiscount = [];
|
|
799
|
+
this.transactionDocument.basket.linePromotion = [];
|
|
800
|
+
this.transactionDocument.basket.transactionPromotion = [];
|
|
801
|
+
basketDetails.products.forEach((product, index) => {
|
|
802
|
+
const p = {};
|
|
803
|
+
p.itemDiscounts = {};
|
|
804
|
+
p.SKU = product.SKU;
|
|
805
|
+
p.excludePromotion = product.excludePromotion;
|
|
806
|
+
p.barCode = product.barcode;
|
|
807
|
+
p.barcodes = product.barcodes;
|
|
808
|
+
p.description = product.description;
|
|
809
|
+
p.itemLineId = product.itemLineId ? product.itemLineId.toString() : "" + (index + 1);
|
|
810
|
+
p.price = product.selectedPrice;
|
|
811
|
+
p.quantity = product.quantity;
|
|
812
|
+
p.totalLinePrice = product.quantity * product.selectedPrice;
|
|
813
|
+
p.imageUrls = product.imageUrls;
|
|
814
|
+
p.selectedRRPPrice = product.selectedRRPPrice;
|
|
815
|
+
//inventory fields
|
|
816
|
+
p.fullfilmentId = product.fullfilmentId ? product.fullfilmentId : this.storeInfo.storeId;
|
|
817
|
+
p.fullfilmentLocationName = product.fullfilmentLocationName;
|
|
818
|
+
p.deliveryGroup = product.deliveryGroup;
|
|
819
|
+
p.leadTime = product.leadTime;
|
|
820
|
+
p.deliveryMethod = product.deliveryMethod;
|
|
821
|
+
p.giftCard = product.giftCard;
|
|
822
|
+
p.giftCardExpiryDate = product.giftCardExpiryDate;
|
|
823
|
+
p.giftCardNumberIssued = product.giftCardNumberIssued;
|
|
824
|
+
p.giftCardRecipientEmail = product.giftCardRecipientEmail;
|
|
825
|
+
p.giftCardRecipientName = product.giftCardRecipientName;
|
|
826
|
+
if (product.refundedQuantity > 0) {
|
|
827
|
+
p.refundedQuantity = product.refundedQuantity;
|
|
828
|
+
p.refundedPromotionalQuantity = product.refundPromotionalQuantity;
|
|
829
|
+
p.refunded = product.refunded;
|
|
830
|
+
p.refundedReasonDescription = product.refundedReasonDescription;
|
|
831
|
+
p.refundedReason = product.refundedReason;
|
|
832
|
+
if (!p.refundedReasonDescription) {
|
|
833
|
+
p.refundedReasonDescription = p.refundedReason;
|
|
834
|
+
}
|
|
835
|
+
p.refundedTotal = product.refundedTotal;
|
|
836
|
+
p.isLastExchanged = product.isLastExchanged;
|
|
837
|
+
}
|
|
838
|
+
if (product.exchange) {
|
|
839
|
+
p.exchange = product.exchange;
|
|
840
|
+
}
|
|
841
|
+
if (product.lineDiscount) {
|
|
842
|
+
p.lineDiscount = product.lineDiscount;
|
|
843
|
+
}
|
|
844
|
+
p.itemDiscounts = product.itemDiscounts;
|
|
845
|
+
this.transactionDocument.basket.products.push(p);
|
|
846
|
+
this.lineDiscount(basketDetails);
|
|
847
|
+
});
|
|
848
|
+
console.info("ebasket: transactiondocument basket details updated", JSON.stringify(this.transactionDocument.basket));
|
|
849
|
+
return this;
|
|
850
|
+
}
|
|
851
|
+
/**
|
|
852
|
+
* current transaction Details Total(New Products)
|
|
853
|
+
* @returns currentTransactionDetails
|
|
854
|
+
*/
|
|
855
|
+
currentTransactionDetails(basket) {
|
|
856
|
+
console.log("ebasket: current transaction details for exchanges", basket);
|
|
857
|
+
this.transactionDocument.currentTransactionDetails.products = [];
|
|
858
|
+
this.transactionDocument.currentTransactionDetails.linePromotion = [];
|
|
859
|
+
this.transactionDocument.currentTransactionDetails.lineDiscount = [];
|
|
860
|
+
this.transactionDocument.currentTransactionDetails.transactionDiscount = [];
|
|
861
|
+
this.transactionDocument.currentTransactionDetails.products = basket.products;
|
|
862
|
+
this.transactionDocument.currentTransactionDetails.products = this.transactionDocument.currentTransactionDetails.products.filter((proj) => proj.refundedQuantity != 0);
|
|
863
|
+
this.transactionDocument.currentTransactionDetails.products.forEach((product) => {
|
|
864
|
+
if (product.refundedQuantity) {
|
|
865
|
+
product.quantity = product.refundedQuantity;
|
|
866
|
+
// updating total line price with actual price to be refunded including the refunding qty
|
|
867
|
+
product.totalLinePrice = Math.abs(product.refundedTotal);
|
|
868
|
+
product.total = product.totalLinePrice;
|
|
869
|
+
if (product.quantity === product.refundedQuantity) {
|
|
870
|
+
product.refunded = true;
|
|
871
|
+
}
|
|
872
|
+
}
|
|
873
|
+
//Updating line promotions and line discounts
|
|
874
|
+
if (product.linePromotions && !product.refundedQuantity) {
|
|
875
|
+
this.transactionDocument.currentTransactionDetails.linePromotion.push(product.linePromotions);
|
|
876
|
+
}
|
|
877
|
+
if (product.lineDiscount && !product.refundedQuantity) {
|
|
878
|
+
this.transactionDocument.currentTransactionDetails.lineDiscount.push(product.lineDiscount);
|
|
879
|
+
}
|
|
880
|
+
});
|
|
881
|
+
console.log("ebasket: current transaction details after removing old products", this.transactionDocument.currentTransactionDetails.products);
|
|
882
|
+
if (basket.transactionDiscount && basket.transactionDiscount.length > 0) {
|
|
883
|
+
this.transactionDocument.currentTransactionDetails.transactionDiscount.push(...basket.transactionDiscount);
|
|
884
|
+
}
|
|
885
|
+
this.transactionDocument.currentTransactionDetails.basketSummary = {};
|
|
886
|
+
this.transactionDocument.currentTransactionDetails.basketSummary.saleTotal = this.numberUtilService.trimTo2Decimal2(this.updateSaleTotal(this.transactionDocument.currentTransactionDetails));
|
|
887
|
+
this.transactionDocument.currentTransactionDetails.basketSummary.totalItems = basket.quantity;
|
|
888
|
+
this.transactionDocument.currentTransactionDetails.basketSummary.basketTotal = basket.basketTotal;
|
|
889
|
+
this.transactionDocument.currentTransactionDetails.basketSummary.refundTotal = this.updateCurrentTransactionDetailsRefundTotal();
|
|
890
|
+
// For partial refund discount is updatied in total line price so discountTotal will always be zero & in case of exchange discount total is calculated
|
|
891
|
+
if (this.transactionDocument.type === TRANSACTION_TYPE.SALE_EXCHANGE) {
|
|
892
|
+
this.transactionDocument.currentTransactionDetails.basketSummary.discountTotal = this.numberUtilService.trimTo2Decimal2(this.updateCurrentTransactionDetailsDiscountTotal());
|
|
893
|
+
}
|
|
894
|
+
else {
|
|
895
|
+
if (this.transactionDocument.currentTransactionDetails.transactionDiscount && this.transactionDocument.currentTransactionDetails.transactionDiscount.length > 0) {
|
|
896
|
+
let discountTotal = 0;
|
|
897
|
+
this.transactionDocument.currentTransactionDetails.transactionDiscount.forEach((discount) => {
|
|
898
|
+
discountTotal += discount.discountAmount;
|
|
899
|
+
});
|
|
900
|
+
this.transactionDocument.currentTransactionDetails.basketSummary.discountTotal = Math.abs(discountTotal);
|
|
901
|
+
}
|
|
902
|
+
else {
|
|
903
|
+
this.transactionDocument.currentTransactionDetails.basketSummary.discountTotal = 0;
|
|
904
|
+
}
|
|
905
|
+
}
|
|
906
|
+
console.log("ebasket:this.transactionDocument.currentTransactionDetails", JSON.stringify(this.transactionDocument.currentTransactionDetails));
|
|
907
|
+
return this;
|
|
908
|
+
}
|
|
909
|
+
/**
|
|
910
|
+
* current transaction Tax Total
|
|
911
|
+
* @returns Tax Total
|
|
912
|
+
*/
|
|
913
|
+
updateCurrentTransactionDetailsTaxBreakdown(basketDetails) {
|
|
914
|
+
let transactionDiscountTotal = 0;
|
|
915
|
+
let taxBreakdown = {
|
|
916
|
+
taxLines: [],
|
|
917
|
+
totalTaxableAmount: 0,
|
|
918
|
+
};
|
|
919
|
+
if (this.transactionDocument.currentTransactionDetails.transactionDiscount && this.transactionDocument.currentTransactionDetails.transactionDiscount.length > 0) {
|
|
920
|
+
this.transactionDocument.currentTransactionDetails.transactionDiscount.forEach((discount) => {
|
|
921
|
+
transactionDiscountTotal += discount.discountAmount;
|
|
922
|
+
});
|
|
923
|
+
}
|
|
924
|
+
if (this.transactionDocument.currentTransactionDetails.products && this.transactionDocument.currentTransactionDetails.products.length > 0) {
|
|
925
|
+
this.transactionDocument.currentTransactionDetails.products.forEach((product) => {
|
|
926
|
+
let taxLine = {
|
|
927
|
+
itemLineId: product.itemLineId,
|
|
928
|
+
VAT: product.selectedVAT ? product.selectedVAT : 0,
|
|
929
|
+
VATCode: product.selectedVATCode,
|
|
930
|
+
taxLineTotal: 0,
|
|
931
|
+
taxableAmount: product.total,
|
|
932
|
+
PreTax: 0
|
|
933
|
+
};
|
|
934
|
+
console.info("Product contribution : item line ID :current transaction Details", product.itemLineId, "tax line :", JSON.stringify(taxLine), JSON.stringify(basketDetails.basketTotal));
|
|
935
|
+
//step 1
|
|
936
|
+
// if Transaction Discount and/or promotion applied, find net selling price of each product as taxableamount
|
|
937
|
+
//If transaction discount/promotion is applied taxable amount should be deducting transaction promotion and transaction disacount portion
|
|
938
|
+
if (product.refundedQuantity && product.refundedQuantity > 0) {
|
|
939
|
+
taxLine.taxableAmount = -Math.abs(taxLine.taxableAmount - product.itemDiscounts.currentRefundPortion);
|
|
940
|
+
}
|
|
941
|
+
else {
|
|
942
|
+
taxLine.taxableAmount = taxLine.taxableAmount - product.itemDiscounts.trnDiscountsPortion - product.itemDiscounts.trnPromotionsPortion;
|
|
943
|
+
}
|
|
944
|
+
//step 2 - find pre tax
|
|
945
|
+
taxLine.PreTax = this.numberUtilService.trimTo2Decimal2((taxLine.taxableAmount * 100) / (100 + taxLine.VAT));
|
|
946
|
+
//step 3 - Update taxbreakdown
|
|
947
|
+
taxBreakdown.totalTaxableAmount += taxLine.taxableAmount;
|
|
948
|
+
taxLine.taxableAmount = this.numberUtilService.trimTo2Decimal2(taxLine.taxableAmount);
|
|
949
|
+
// step 4 - update tax Line total
|
|
950
|
+
taxLine.taxLineTotal = this.numberUtilService.trimTo2Decimal2(taxLine.taxableAmount - taxLine.PreTax);
|
|
951
|
+
taxBreakdown.taxLines.push(taxLine);
|
|
952
|
+
});
|
|
953
|
+
}
|
|
954
|
+
taxBreakdown.totalTaxableAmount = this.numberUtilService.trimTo2Decimal2(taxBreakdown.totalTaxableAmount);
|
|
955
|
+
this.transactionDocument.currentTransactionDetails.taxBreakdown = taxBreakdown;
|
|
956
|
+
if (this.transactionDocument.currentTransactionDetails.taxBreakdown && this.transactionDocument.currentTransactionDetails.taxBreakdown.taxLines && this.transactionDocument.currentTransactionDetails.taxBreakdown.taxLines.length > 0) {
|
|
957
|
+
this.transactionDocument.currentTransactionDetails.basketSummary.VATTotal = this.numberUtilService.trimTo2Decimal2(this.transactionDocument.currentTransactionDetails.taxBreakdown.taxLines.reduce((n, { taxLineTotal }) => n + taxLineTotal, 0));
|
|
958
|
+
}
|
|
959
|
+
else {
|
|
960
|
+
this.transactionDocument.currentTransactionDetails.basketSummary.VATTotal = 0.00;
|
|
961
|
+
}
|
|
962
|
+
console.log("eBasket:after calculating tax currenttransactionDetails", this.transactionDocument.currentTransactionDetails);
|
|
963
|
+
return this;
|
|
964
|
+
}
|
|
965
|
+
updateCurrentTransactionDetailsTotalTaxSummary() {
|
|
966
|
+
console.log("Total Tax Summery Request :", JSON.stringify(this.transactionDocument.currentTransactionDetails.taxBreakdown));
|
|
967
|
+
let totalTaxSummaryArray = [];
|
|
968
|
+
let totalTaxSummaryGroup = [];
|
|
969
|
+
console.log("Tax Lines for Total Tax Summery :", JSON.stringify(this.transactionDocument.currentTransactionDetails.taxBreakdown.taxLines));
|
|
970
|
+
this.transactionDocument.currentTransactionDetails.taxBreakdown.taxLines.forEach((element) => {
|
|
971
|
+
let TaxSummary = {
|
|
972
|
+
VATCode: "",
|
|
973
|
+
VAT: -12345,
|
|
974
|
+
PreTaxSum: 0,
|
|
975
|
+
TaxSum: 0,
|
|
976
|
+
TXrateSum: 0
|
|
977
|
+
};
|
|
978
|
+
TaxSummary.VATCode = element.VATCode;
|
|
979
|
+
TaxSummary.VAT = element.VAT;
|
|
980
|
+
TaxSummary.PreTaxSum = this.numberUtilService.trimTo2Decimal2(element.PreTax);
|
|
981
|
+
TaxSummary.TaxSum = this.numberUtilService.trimTo2Decimal2(element.taxLineTotal);
|
|
982
|
+
TaxSummary.TXrateSum = this.numberUtilService.trimTo2Decimal2(TaxSummary.PreTaxSum + TaxSummary.TaxSum);
|
|
983
|
+
totalTaxSummaryArray.push(TaxSummary);
|
|
984
|
+
});
|
|
985
|
+
console.log("Total Tax Summery Without Grouped : ", JSON.stringify(totalTaxSummaryArray));
|
|
986
|
+
totalTaxSummaryGroup = totalTaxSummaryArray.reduce((preparedArray, currentObj) => {
|
|
987
|
+
let ind = preparedArray.findIndex((x) => x.VAT === currentObj.VAT);
|
|
988
|
+
if (ind === -1) {
|
|
989
|
+
preparedArray.push(currentObj);
|
|
990
|
+
}
|
|
991
|
+
else {
|
|
992
|
+
preparedArray[ind].VATCode = currentObj.VATCode;
|
|
993
|
+
preparedArray[ind].VAT = currentObj.VAT;
|
|
994
|
+
preparedArray[ind].PreTaxSum += currentObj.PreTaxSum;
|
|
995
|
+
preparedArray[ind].TaxSum += currentObj.TaxSum;
|
|
996
|
+
preparedArray[ind].TXrateSum += currentObj.TXrateSum;
|
|
997
|
+
}
|
|
998
|
+
return preparedArray;
|
|
999
|
+
}, []);
|
|
1000
|
+
// listOfTags.map(x => unique.filter(a => a.label == x.label && a.color == x.color).length > 0 ? null : unique.push(x));
|
|
1001
|
+
console.log("Total Tax Summer Group :", JSON.stringify(totalTaxSummaryGroup));
|
|
1002
|
+
this.transactionDocument.currentTransactionDetails.totalTaxSummary = totalTaxSummaryGroup;
|
|
1003
|
+
return this;
|
|
1004
|
+
}
|
|
1005
|
+
/**
|
|
1006
|
+
* current transaction Disocunt Total
|
|
1007
|
+
* @returns Discount Total
|
|
1008
|
+
*/
|
|
1009
|
+
updateCurrentTransactionDetailsDiscountTotal() {
|
|
1010
|
+
let refundTotal = this.transactionDocument.currentTransactionDetails.basketSummary.refundTotal ? this.transactionDocument.currentTransactionDetails.basketSummary.refundTotal : 0;
|
|
1011
|
+
console.log("e-basket: transaction builder updateCurrentTransactionDetailsDiscountTotal: discountTotal", refundTotal, this.transactionDocument.currentTransactionDetails.basketSummary.basketTotal, this.transactionDocument.currentTransactionDetails.basketSummary.saleTotal);
|
|
1012
|
+
const discountTotal = Math.abs(Math.abs(this.transactionDocument.currentTransactionDetails.basketSummary.saleTotal) -
|
|
1013
|
+
(Math.abs(this.transactionDocument.currentTransactionDetails.basketSummary.basketTotal) + Math.abs(refundTotal)));
|
|
1014
|
+
console.log("e-basket: transaction builder updateCurrentTransactionDetailsDiscountTotal: discountTotal", discountTotal);
|
|
1015
|
+
return Number(discountTotal.toFixed(2));
|
|
1016
|
+
}
|
|
1017
|
+
/**
|
|
1018
|
+
* current transaction Refund Total
|
|
1019
|
+
* @returns Refund Total
|
|
1020
|
+
*/
|
|
1021
|
+
updateCurrentTransactionDetailsRefundTotal() {
|
|
1022
|
+
let totalRefund = 0;
|
|
1023
|
+
for (let index = 0; index < this.transactionDocument.currentTransactionDetails.products.length; index++) {
|
|
1024
|
+
const product = this.transactionDocument.currentTransactionDetails.products[index];
|
|
1025
|
+
if (product.refundedTotal) {
|
|
1026
|
+
totalRefund = totalRefund + product.refundedTotal;
|
|
1027
|
+
}
|
|
1028
|
+
console.log("ebasket : transaction Service: totalRefund for Current TransactionDetails" + totalRefund);
|
|
1029
|
+
}
|
|
1030
|
+
return totalRefund;
|
|
1031
|
+
}
|
|
1032
|
+
/**
|
|
1033
|
+
* Baskets summary
|
|
1034
|
+
* @param basketDetails
|
|
1035
|
+
* @returns summary
|
|
1036
|
+
*/
|
|
1037
|
+
basketSummary(basketDetails) {
|
|
1038
|
+
this.transactionDocument.basketSummary.basketTotal = this.numberUtilService.trimTo2Decimal(basketDetails.basketTotal);
|
|
1039
|
+
this.transactionDocument.basketSummary.saleTotal = this.numberUtilService.trimTo2Decimal2(this.updateSaleTotal(basketDetails));
|
|
1040
|
+
this.transactionDocument.basketSummary.refundTotal = this.getRefundTotal();
|
|
1041
|
+
if (this.transactionDocument.basket.lineDiscount ||
|
|
1042
|
+
this.transactionDocument.basket.linePromotion) {
|
|
1043
|
+
this.transactionDocument.basketSummary.discountTotal = this.numberUtilService.trimTo2Decimal2(this.updateDiscountTotal());
|
|
1044
|
+
}
|
|
1045
|
+
this.transactionDocument.basketSummary.totalItems = basketDetails.quantity;
|
|
1046
|
+
if (this.transactionDocument.basket.taxBreakdown) {
|
|
1047
|
+
this.transactionDocument.basketSummary.VATTotal = this.numberUtilService.trimTo2Decimal2(this.transactionDocument.basket.taxBreakdown.taxLines.reduce((n, { taxLineTotal }) => n + taxLineTotal, 0));
|
|
1048
|
+
}
|
|
1049
|
+
else {
|
|
1050
|
+
this.transactionDocument.basketSummary.VATTotal = 0.00;
|
|
1051
|
+
}
|
|
1052
|
+
console.info("ebasket: basketsummary updated in transaction document: ", JSON.stringify(this.transactionDocument.basketSummary));
|
|
1053
|
+
return this;
|
|
1054
|
+
}
|
|
1055
|
+
/**
|
|
1056
|
+
* Line Discount
|
|
1057
|
+
* @param basketDetails
|
|
1058
|
+
* @returns line Discount
|
|
1059
|
+
*/
|
|
1060
|
+
lineDiscount(basketDetails) {
|
|
1061
|
+
this.transactionDocument.basket.lineDiscount = [];
|
|
1062
|
+
for (let index = 0; index < basketDetails.products.length; index++) {
|
|
1063
|
+
const element = basketDetails.products[index];
|
|
1064
|
+
if (element.lineDiscount) {
|
|
1065
|
+
this.transactionDocument.basket.lineDiscount.push(element.lineDiscount);
|
|
1066
|
+
this.transactionDocument.basket.lineDiscount = this.transactionDocument.basket.lineDiscount.reduce((acc, val) => {
|
|
1067
|
+
if (!acc.find((el) => el.itemLineId === val.itemLineId)) {
|
|
1068
|
+
acc.push(val);
|
|
1069
|
+
}
|
|
1070
|
+
return acc;
|
|
1071
|
+
}, []);
|
|
1072
|
+
}
|
|
1073
|
+
// console.info(
|
|
1074
|
+
// "e-basket :line discount updated in transaction document",
|
|
1075
|
+
// this.transactionDocument.basket.lineDiscount
|
|
1076
|
+
// );
|
|
1077
|
+
}
|
|
1078
|
+
return this;
|
|
1079
|
+
}
|
|
1080
|
+
/**
|
|
1081
|
+
* exchange
|
|
1082
|
+
* @param basketDetails
|
|
1083
|
+
* @returns exchange
|
|
1084
|
+
*/
|
|
1085
|
+
exchange(basketDetails) {
|
|
1086
|
+
this.transactionDocument.basket.exchange = basketDetails.exchange && basketDetails.exchange.length > 0 ? [...basketDetails.exchange] : [];
|
|
1087
|
+
for (let index = 0; index < basketDetails.products.length; index++) {
|
|
1088
|
+
const element = basketDetails.products[index];
|
|
1089
|
+
if (element.exchange != undefined) {
|
|
1090
|
+
const isPresent = this.transactionDocument.basket.exchange.some((el) => el.exchangeId === element.exchange.exchangeId);
|
|
1091
|
+
if (!isPresent) {
|
|
1092
|
+
let exchangeItems = [];
|
|
1093
|
+
for (let j = 0; j < element.exchange.newItems.length; j++) {
|
|
1094
|
+
const item = element.exchange.newItems[j];
|
|
1095
|
+
let newItems = { lineItemId: item.itemLineId, Quantity: item.quantity };
|
|
1096
|
+
exchangeItems.push(newItems);
|
|
1097
|
+
}
|
|
1098
|
+
element.exchange.newItems = [...exchangeItems];
|
|
1099
|
+
this.transactionDocument.basket.exchange.push(element.exchange);
|
|
1100
|
+
}
|
|
1101
|
+
}
|
|
1102
|
+
console.log("e-basket :TransactionDocumentBuilder: this.transactionDocument.basket exchange", JSON.stringify(this.transactionDocument.basket.exchange));
|
|
1103
|
+
}
|
|
1104
|
+
return this;
|
|
1105
|
+
}
|
|
1106
|
+
/**
|
|
1107
|
+
* add previous exchange data
|
|
1108
|
+
* @param originalTransactionDocument
|
|
1109
|
+
* @returns line Promotions
|
|
1110
|
+
*/
|
|
1111
|
+
addExchangeData(originalTransactionDocument) {
|
|
1112
|
+
this.transactionDocument.basket.exchange = originalTransactionDocument.basket.exchange ? [...originalTransactionDocument.basket.exchange] : null;
|
|
1113
|
+
return this;
|
|
1114
|
+
}
|
|
1115
|
+
/**
|
|
1116
|
+
* line Promotions
|
|
1117
|
+
* @param basketDetails
|
|
1118
|
+
* @returns line Promotions
|
|
1119
|
+
*/
|
|
1120
|
+
linePromotion(basketDetails) {
|
|
1121
|
+
this.transactionDocument.basket.linePromotion = [];
|
|
1122
|
+
for (let index = 0; index < basketDetails.products.length; index++) {
|
|
1123
|
+
const element = basketDetails.products[index];
|
|
1124
|
+
if (element.linePromotions) {
|
|
1125
|
+
this.transactionDocument.basket.linePromotion.push(element.linePromotions);
|
|
1126
|
+
this.transactionDocument.basket.linePromotion = this.transactionDocument.basket.linePromotion.reduce((acc, val) => {
|
|
1127
|
+
if (!acc.find((el) => el.itemLineId === val.itemLineId)) {
|
|
1128
|
+
acc.push(val);
|
|
1129
|
+
}
|
|
1130
|
+
return acc;
|
|
1131
|
+
}, []);
|
|
1132
|
+
}
|
|
1133
|
+
}
|
|
1134
|
+
return this;
|
|
1135
|
+
}
|
|
1136
|
+
/**
|
|
1137
|
+
* transaction Promotion
|
|
1138
|
+
* @param basketDetails
|
|
1139
|
+
* @returns transaction Promotion
|
|
1140
|
+
*/
|
|
1141
|
+
transactionPromotion(basketDetails) {
|
|
1142
|
+
if (basketDetails.transactionPromotion) {
|
|
1143
|
+
this.transactionDocument.basket.transactionPromotion =
|
|
1144
|
+
basketDetails.transactionPromotion;
|
|
1145
|
+
// for (let index = 0; index < basketDetails.TransactionDiscount.length; index++) {
|
|
1146
|
+
// this.transactionDocument.basket.transactionPromotion.push(element.linePromotions)
|
|
1147
|
+
// this.transactionDocument.basket.transactionPromotion = this.transactionDocument.basket.linePromotions.reduce((acc, val) => {
|
|
1148
|
+
// if (!acc.find(el => el.itemLineId === val.itemLineId)) {
|
|
1149
|
+
// acc.push(val);
|
|
1150
|
+
// }
|
|
1151
|
+
// return acc;
|
|
1152
|
+
// }, []);
|
|
1153
|
+
// }
|
|
1154
|
+
console.log("e-basket :TransactionDocumentBuilder: this.transactionDocument.basket.transactionPromotion", JSON.stringify(this.transactionDocument.basket.transactionPromotion));
|
|
1155
|
+
}
|
|
1156
|
+
return this;
|
|
1157
|
+
}
|
|
1158
|
+
transactionDiscount(basketDetails) {
|
|
1159
|
+
if (basketDetails.transactionDiscount) {
|
|
1160
|
+
this.transactionDocument.basket.transactionDiscount =
|
|
1161
|
+
basketDetails.transactionDiscount;
|
|
1162
|
+
console.log("e-basket :TransactionDocumentBuilder: transaction Discount", JSON.stringify(this.transactionDocument.basket.transactionDiscount));
|
|
1163
|
+
}
|
|
1164
|
+
return this;
|
|
1165
|
+
}
|
|
1166
|
+
/**
|
|
1167
|
+
* Payments details
|
|
1168
|
+
* @param paymentDetails
|
|
1169
|
+
* @returns
|
|
1170
|
+
*/
|
|
1171
|
+
paymentDetails(paymentDetails) {
|
|
1172
|
+
console.info("ebasket : payment details after transaction completed", JSON.stringify(paymentDetails));
|
|
1173
|
+
this.transactionDocument.paymentDetails = paymentDetails;
|
|
1174
|
+
return this;
|
|
1175
|
+
}
|
|
1176
|
+
/**
|
|
1177
|
+
* Payments details
|
|
1178
|
+
* @param paymentDetails
|
|
1179
|
+
* @returns
|
|
1180
|
+
*/
|
|
1181
|
+
splitPayment(splitPayment) {
|
|
1182
|
+
this.transactionDocument.splitPayment = splitPayment;
|
|
1183
|
+
return this;
|
|
1184
|
+
}
|
|
1185
|
+
/**
|
|
1186
|
+
* Payments details
|
|
1187
|
+
* @param paymentDetails
|
|
1188
|
+
* @returns
|
|
1189
|
+
*/
|
|
1190
|
+
isPaymentCompleted(isPaymentCompleted) {
|
|
1191
|
+
this.transactionDocument.isPaymentCompleted = isPaymentCompleted;
|
|
1192
|
+
return this;
|
|
1193
|
+
}
|
|
1194
|
+
/**
|
|
1195
|
+
* Bases currency
|
|
1196
|
+
* @param currency
|
|
1197
|
+
* @returns currency
|
|
1198
|
+
*/
|
|
1199
|
+
baseCurrency(currency) {
|
|
1200
|
+
this.transactionDocument.baseCurrency = currency;
|
|
1201
|
+
return this;
|
|
1202
|
+
}
|
|
1203
|
+
/**
|
|
1204
|
+
* gift option at
|
|
1205
|
+
* @returns at
|
|
1206
|
+
*/
|
|
1207
|
+
giftOption(gift) {
|
|
1208
|
+
console.log("e-basket :TransactionDocumentBuilder: this.transactionDocument.giftoption", gift);
|
|
1209
|
+
if (gift) {
|
|
1210
|
+
this.transactionDocument.giftedReceipt = gift;
|
|
1211
|
+
}
|
|
1212
|
+
return this;
|
|
1213
|
+
}
|
|
1214
|
+
/**
|
|
1215
|
+
|
|
1216
|
+
/**
|
|
1217
|
+
* manual Discount
|
|
1218
|
+
* @param discountData
|
|
1219
|
+
* @returns
|
|
1220
|
+
*/
|
|
1221
|
+
// manualDiscount(discountData : basketDiscount):TransactionDocumentBuilder {
|
|
1222
|
+
// let saleTotal = this.transactionDocument.basketSummary.basketTotal;
|
|
1223
|
+
// if(discountData.discountType =='Percent'){
|
|
1224
|
+
// this.transactionDocument.basketSummary.basketTotal = saleTotal-(saleTotal*(discountData.discountAmount/100));
|
|
1225
|
+
// discountData.discountAmount = -1*(saleTotal-this.transactionDocument.basketSummary.basketTotal);
|
|
1226
|
+
// }else {
|
|
1227
|
+
// this.transactionDocument.basketSummary.basketTotal =saleTotal-discountData.discountAmount;
|
|
1228
|
+
// discountData.discountAmount = -1*discountData.discountAmount;
|
|
1229
|
+
// }
|
|
1230
|
+
// this.transactionDocument.transactionDiscount.push(discountData);
|
|
1231
|
+
// return this;
|
|
1232
|
+
// }
|
|
1233
|
+
/**
|
|
1234
|
+
* Types transaction document builder
|
|
1235
|
+
* @param t
|
|
1236
|
+
* @returns type
|
|
1237
|
+
*/
|
|
1238
|
+
type(t) {
|
|
1239
|
+
this.transactionDocument.type = t;
|
|
1240
|
+
return this;
|
|
1241
|
+
}
|
|
1242
|
+
/**
|
|
1243
|
+
* Operations status
|
|
1244
|
+
* @param o
|
|
1245
|
+
* @returns status
|
|
1246
|
+
*/
|
|
1247
|
+
operationStatus(o) {
|
|
1248
|
+
this.transactionDocument.operationStatus = o;
|
|
1249
|
+
return this;
|
|
1250
|
+
}
|
|
1251
|
+
/**
|
|
1252
|
+
* Created at
|
|
1253
|
+
* @returns at
|
|
1254
|
+
*/
|
|
1255
|
+
createdAt() {
|
|
1256
|
+
const date = new Date();
|
|
1257
|
+
this.transactionDocument.createdAt = date.toISOString();
|
|
1258
|
+
this.transactionDocument.updatedAt = date.toISOString();
|
|
1259
|
+
return this;
|
|
1260
|
+
}
|
|
1261
|
+
/**
|
|
1262
|
+
* Updated at
|
|
1263
|
+
* @returns at
|
|
1264
|
+
*/
|
|
1265
|
+
updatedAt() {
|
|
1266
|
+
const date = new Date();
|
|
1267
|
+
this.transactionDocument.updatedAt = date.toISOString();
|
|
1268
|
+
return this;
|
|
1269
|
+
}
|
|
1270
|
+
/**
|
|
1271
|
+
* transsaction completion at
|
|
1272
|
+
* @returns transaction completion date
|
|
1273
|
+
*/
|
|
1274
|
+
transactionCompletedAt() {
|
|
1275
|
+
const date = new Date();
|
|
1276
|
+
this.transactionDocument.transCompletedAt = date.toISOString();
|
|
1277
|
+
return this;
|
|
1278
|
+
}
|
|
1279
|
+
/**
|
|
1280
|
+
* Builds transaction document builder
|
|
1281
|
+
* @returns build
|
|
1282
|
+
*/
|
|
1283
|
+
build() {
|
|
1284
|
+
return this.transactionDocument;
|
|
1285
|
+
}
|
|
1286
|
+
/**
|
|
1287
|
+
* Sales total in refund
|
|
1288
|
+
* @param saleTotal
|
|
1289
|
+
* @returns total in refund
|
|
1290
|
+
*/
|
|
1291
|
+
saleTotalInRefund(saleTotal) {
|
|
1292
|
+
this.transactionDocument.saleTotal = saleTotal;
|
|
1293
|
+
return this;
|
|
1294
|
+
}
|
|
1295
|
+
/**
|
|
1296
|
+
* Gets basket details
|
|
1297
|
+
* @returns basket details
|
|
1298
|
+
*/
|
|
1299
|
+
getBasketDetails() {
|
|
1300
|
+
console.info("ebasket: Getting Basket for transactionDocument", JSON.stringify(this.transactionDocument));
|
|
1301
|
+
let basket = {
|
|
1302
|
+
subsidiaryId: this.transactionDocument.subsidiaryId,
|
|
1303
|
+
transactionDiscount: this.transactionDocument.basket.transactionDiscount,
|
|
1304
|
+
transactionPromotion: this.transactionDocument.basket.transactionPromotion,
|
|
1305
|
+
transactionId: this.transactionDocument.transactionId,
|
|
1306
|
+
offlineTransactionId: this.transactionDocument.offlineTransactionId,
|
|
1307
|
+
total: this.transactionDocument.basketSummary.basketTotal,
|
|
1308
|
+
basketTotal: this.transactionDocument.basketSummary.basketTotal,
|
|
1309
|
+
discountTotal: this.transactionDocument.basketSummary.discountTotal,
|
|
1310
|
+
saleTotal: this.transactionDocument.basketSummary.saleTotal,
|
|
1311
|
+
refundTotal: this.transactionDocument.basketSummary.refundTotal,
|
|
1312
|
+
quantity: this.transactionDocument.basketSummary.totalItems,
|
|
1313
|
+
products: [],
|
|
1314
|
+
baseCurrency: this.transactionDocument.baseCurrency,
|
|
1315
|
+
customer: this.transactionDocument.customer,
|
|
1316
|
+
};
|
|
1317
|
+
basket.products = [];
|
|
1318
|
+
this.transactionDocument.basket.products.forEach((product, index) => {
|
|
1319
|
+
console.log(JSON.stringify(product), "ebasket: basket detail update in basket");
|
|
1320
|
+
const p = {};
|
|
1321
|
+
p.SKU = product.SKU;
|
|
1322
|
+
p.barcode = product.barCode;
|
|
1323
|
+
p.barcodes = product.barcodes;
|
|
1324
|
+
p.description = product.description;
|
|
1325
|
+
p.imageUrls = product.imageUrls;
|
|
1326
|
+
p.currency = this.transactionDocument.baseCurrency;
|
|
1327
|
+
p.totalLinePrice = product.totalLinePrice;
|
|
1328
|
+
p.itemLineId = Number(product.itemLineId);
|
|
1329
|
+
p.excludePromotion = product.excludePromotion;
|
|
1330
|
+
p.selectedPrice = product.price;
|
|
1331
|
+
p.quantity = product.quantity;
|
|
1332
|
+
p.total = product.totalLinePrice;
|
|
1333
|
+
p.selectedRRPPrice = product.selectedRRPPrice;
|
|
1334
|
+
p.fullfilmentId = product.fullfilmentId;
|
|
1335
|
+
p.fullfilmentLocationName = product.fullfilmentLocationName;
|
|
1336
|
+
p.deliveryGroup = product.deliveryGroup || "1";
|
|
1337
|
+
p.leadTime = product.leadTime;
|
|
1338
|
+
p.deliveryMethod = product.deliveryMethod || DELIVERY_METHODS.COLLECT_FROM_STORE.toString();
|
|
1339
|
+
if (p.fullfilmentId != this.transactionDocument.storeId) {
|
|
1340
|
+
p.isWebOrder = true;
|
|
1341
|
+
}
|
|
1342
|
+
p.giftCard = product.giftCard;
|
|
1343
|
+
p.giftCardExpiryDate = product.giftCardExpiryDate;
|
|
1344
|
+
p.giftCardNumberIssued = product.giftCardNumberIssued;
|
|
1345
|
+
p.giftCardRecipientEmail = product.giftCardRecipientEmail;
|
|
1346
|
+
p.giftCardRecipientName = product.giftCardRecipientName;
|
|
1347
|
+
if (this.transactionDocument.basket.lineDiscount &&
|
|
1348
|
+
this.transactionDocument.basket.lineDiscount.length > 0) {
|
|
1349
|
+
this.transactionDocument.basket.lineDiscount.forEach((lineDiscount) => {
|
|
1350
|
+
if (product.itemLineId === lineDiscount.itemLineId.toString()) {
|
|
1351
|
+
p.lineDiscount = lineDiscount;
|
|
1352
|
+
p.total = lineDiscount.discountedLinePrice;
|
|
1353
|
+
}
|
|
1354
|
+
});
|
|
1355
|
+
}
|
|
1356
|
+
if (this.transactionDocument.basket.linePromotion &&
|
|
1357
|
+
this.transactionDocument.basket.linePromotion.length > 0) {
|
|
1358
|
+
this.transactionDocument.basket.linePromotion.forEach((linePromotion) => {
|
|
1359
|
+
if (product.itemLineId === linePromotion.itemLineId.toString()) {
|
|
1360
|
+
p.linePromotions = linePromotion;
|
|
1361
|
+
p.total = linePromotion.promotionLinePrice;
|
|
1362
|
+
}
|
|
1363
|
+
});
|
|
1364
|
+
}
|
|
1365
|
+
if (this.transactionDocument.basket.taxBreakdown &&
|
|
1366
|
+
this.transactionDocument.basket.taxBreakdown.taxLines.length > 0) {
|
|
1367
|
+
this.transactionDocument.basket.taxBreakdown.taxLines.forEach((taxLine) => {
|
|
1368
|
+
if (product.itemLineId && product.itemLineId === taxLine.itemLineId.toString()) {
|
|
1369
|
+
p.selectedVAT = taxLine.VAT;
|
|
1370
|
+
p.selectedVATCode = taxLine.VATCode;
|
|
1371
|
+
}
|
|
1372
|
+
});
|
|
1373
|
+
}
|
|
1374
|
+
if (this.transactionDocument.type === TRANSACTION_TYPE.REFUND) {
|
|
1375
|
+
p.total = product.refundedTotal;
|
|
1376
|
+
}
|
|
1377
|
+
else if ((this.transactionDocument.type === TRANSACTION_TYPE.SALE_REFUND || TRANSACTION_TYPE.SALE_EXCHANGE) && product.refundedQuantity > 0) {
|
|
1378
|
+
p.refundedReasonDescription = product.refundedReasonDescription;
|
|
1379
|
+
p.refundedReason = product.refundedReason;
|
|
1380
|
+
if (!p.refundedReasonDescription) {
|
|
1381
|
+
p.refundedReasonDescription = p.refundedReason;
|
|
1382
|
+
}
|
|
1383
|
+
p.refundedQuantity = product.refundedQuantity;
|
|
1384
|
+
p.refundPromotionalQuantity = product.refundedPromotionalQuantity;
|
|
1385
|
+
p.refundedTotal = product.refundedTotal;
|
|
1386
|
+
p.total -= Math.abs(p.refundedTotal);
|
|
1387
|
+
p.isLastExchanged = product.isLastExchanged;
|
|
1388
|
+
}
|
|
1389
|
+
if (this.transactionDocument.type === TRANSACTION_TYPE.REFUND) {
|
|
1390
|
+
if (p.total > 0) {
|
|
1391
|
+
p.total *= -1;
|
|
1392
|
+
}
|
|
1393
|
+
}
|
|
1394
|
+
basket.products.push(p);
|
|
1395
|
+
});
|
|
1396
|
+
basket = this.getTransactionDiscountAndTransactionPromotionPortion(basket);
|
|
1397
|
+
basket.total = (basket.basketTotal || 0) + this.getTotalDiscountWithTransactionDiscountsAndPromotions(basket);
|
|
1398
|
+
if (this.transactionDocument.type === TRANSACTION_TYPE.SALE_REFUND) {
|
|
1399
|
+
basket.quantity = this.getRefundedTotalWithQuantity(basket);
|
|
1400
|
+
}
|
|
1401
|
+
console.info("ebasket: Basket created successfully", JSON.stringify(basket));
|
|
1402
|
+
return basket;
|
|
1403
|
+
}
|
|
1404
|
+
/**
|
|
1405
|
+
* Gets basket details
|
|
1406
|
+
* @returns refund basket details
|
|
1407
|
+
*/
|
|
1408
|
+
// getRefundBasketDetails(): Basket {
|
|
1409
|
+
// let basket: Basket = {
|
|
1410
|
+
// subsidiaryId : this.transactionDocument.subsidiaryId,
|
|
1411
|
+
// transactionDiscount: this.transactionDocument.basket.transactionDiscount,
|
|
1412
|
+
// transactionPromotion: this.transactionDocument.basket.transactionPromotion,
|
|
1413
|
+
// transactionId: this.transactionDocument.transactionId,
|
|
1414
|
+
// total: this.transactionDocument.basketSummary.basketTotal,
|
|
1415
|
+
// basketTotal: this.transactionDocument.basketSummary.basketTotal,
|
|
1416
|
+
// discountTotal: this.transactionDocument.basketSummary.discountTotal,
|
|
1417
|
+
// saleTotal: this.transactionDocument.basketSummary.saleTotal,
|
|
1418
|
+
// quantity: this.transactionDocument.basketSummary.totalItems,
|
|
1419
|
+
// products: [],
|
|
1420
|
+
// baseCurrency: this.transactionDocument.baseCurrency,
|
|
1421
|
+
// customer: this.transactionDocument.customer,
|
|
1422
|
+
// };
|
|
1423
|
+
// basket.products = [] as Product[];
|
|
1424
|
+
// this.transactionDocument.basket.products.forEach((product: { SKU: any; barCode: any; barcodes: any; description: any; imageUrls: any; totalLinePrice: any; itemLineId: any; excludePromotion: any; price: number; quantity: any; selectedRRPPrice: any; fullfilmentId: any; fullfilmentLocationName: any; deliveryGroup: string; leadTime: any; deliveryMethod: any; giftCard: any; giftCardExpiryDate: any; giftCardNumberIssued: any; giftCardRecipientEmail: any; giftCardRecipientName: any; itemDiscounts: any; refundedPromotionalQuantity: any; refundedQuantity: number; refunded: any; isLastExchanged: any; exchange: any; refundedTotal: number; }, index: any) => {
|
|
1425
|
+
// const p = {} as Product;
|
|
1426
|
+
// p.SKU = product.SKU;
|
|
1427
|
+
// p.barcode = product.barCode;
|
|
1428
|
+
// p.barcodes = product.barcodes;
|
|
1429
|
+
// p.description = product.description;
|
|
1430
|
+
// p.imageUrls = product.imageUrls;
|
|
1431
|
+
// p.currency = this.transactionDocument.baseCurrency;
|
|
1432
|
+
// p.totalLinePrice = product.totalLinePrice;
|
|
1433
|
+
// p.itemLineId = Number(product.itemLineId);
|
|
1434
|
+
// p.excludePromotion = product.excludePromotion;
|
|
1435
|
+
// p.selectedPrice = product.price;
|
|
1436
|
+
// p.quantity = product.quantity;
|
|
1437
|
+
// p.total = product.totalLinePrice;
|
|
1438
|
+
// p.selectedRRPPrice = product.selectedRRPPrice;
|
|
1439
|
+
// p.fullfilmentId = product.fullfilmentId;
|
|
1440
|
+
// p.fullfilmentLocationName = product.fullfilmentLocationName;
|
|
1441
|
+
// p.deliveryGroup = product.deliveryGroup || "1";
|
|
1442
|
+
// p.leadTime = product.leadTime;
|
|
1443
|
+
// p.deliveryMethod = product.deliveryMethod || DELIVERY_METHODS.COLLECT_FROM_STORE.toString();
|
|
1444
|
+
// p.giftCard = product.giftCard;
|
|
1445
|
+
// p.giftCardExpiryDate = product.giftCardExpiryDate;
|
|
1446
|
+
// p.giftCardNumberIssued = product.giftCardNumberIssued;
|
|
1447
|
+
// p.giftCardRecipientEmail = product.giftCardRecipientEmail;
|
|
1448
|
+
// p.giftCardRecipientName = product.giftCardRecipientName;
|
|
1449
|
+
// if(p.fullfilmentId != this.transactionDocument.storeId)
|
|
1450
|
+
// {
|
|
1451
|
+
// p.isWebOrder = true;
|
|
1452
|
+
// }
|
|
1453
|
+
// if (product.itemDiscounts) {
|
|
1454
|
+
// p.itemDiscounts = product.itemDiscounts as ItemDiscount;
|
|
1455
|
+
// }
|
|
1456
|
+
// // if(!p.itemDiscounts){
|
|
1457
|
+
// // console.log(p.itemDiscounts);
|
|
1458
|
+
// // this.basketService.transactionDiscountAndPromotionProductortionCalculation(basket);
|
|
1459
|
+
// // }
|
|
1460
|
+
// p.refundPromotionalQuantity = product.refundedPromotionalQuantity ? product.refundedPromotionalQuantity : 0;
|
|
1461
|
+
// if (product.refundedQuantity) {
|
|
1462
|
+
// p.quantity = p.quantity - product.refundedQuantity;
|
|
1463
|
+
// p.totalLinePrice = (p.quantity * product.price);
|
|
1464
|
+
// p.total = p.totalLinePrice;
|
|
1465
|
+
// // p.refundPromotionalQuantity = product.refundedPromotionalQuantity;
|
|
1466
|
+
// p.refunded = product.refunded;
|
|
1467
|
+
// p.isLastExchanged = product.isLastExchanged;
|
|
1468
|
+
// }
|
|
1469
|
+
// if (product.exchange) {
|
|
1470
|
+
// p.exchange = product.exchange;
|
|
1471
|
+
// }
|
|
1472
|
+
// if (
|
|
1473
|
+
// this.transactionDocument.basket.lineDiscount &&
|
|
1474
|
+
// this.transactionDocument.basket.lineDiscount.length > 0
|
|
1475
|
+
// ) {
|
|
1476
|
+
// this.transactionDocument.basket.lineDiscount.forEach((lineDiscount: { itemLineId: { toString: () => any; }; discountedLinePrice: any; }) => {
|
|
1477
|
+
// if (product.itemLineId === lineDiscount.itemLineId.toString() && product.refundedQuantity > 0) {
|
|
1478
|
+
// p.lineDiscount = Object.assign({}, lineDiscount);
|
|
1479
|
+
// p.lineDiscount.discountedLinePrice = p.lineDiscount.unitPrice * p.quantity
|
|
1480
|
+
// p.lineDiscount.discountAmount = p.total - p.lineDiscount.discountedLinePrice
|
|
1481
|
+
// p.total = p.lineDiscount.discountedLinePrice;
|
|
1482
|
+
// } else if (product.itemLineId === lineDiscount.itemLineId.toString()) {
|
|
1483
|
+
// p.lineDiscount = lineDiscount;
|
|
1484
|
+
// p.total = lineDiscount.discountedLinePrice
|
|
1485
|
+
// }
|
|
1486
|
+
// });
|
|
1487
|
+
// }
|
|
1488
|
+
// if (
|
|
1489
|
+
// this.transactionDocument.basket.linePromotion &&
|
|
1490
|
+
// this.transactionDocument.basket.linePromotion.length > 0
|
|
1491
|
+
// ) {
|
|
1492
|
+
// this.transactionDocument.basket.linePromotion.forEach((linePromotion: { itemLineId: { toString: () => any; }; refunded: any; }) => {
|
|
1493
|
+
// if (product.itemLineId === linePromotion.itemLineId.toString() && !linePromotion.refunded) {
|
|
1494
|
+
// p.linePromotions = linePromotion;
|
|
1495
|
+
// p.total = p.linePromotions.promotionLinePrice;
|
|
1496
|
+
// p.total = p.total - (product.refundedTotal ? Math.abs(product.refundedTotal) : 0);
|
|
1497
|
+
// }
|
|
1498
|
+
// });
|
|
1499
|
+
// }
|
|
1500
|
+
// p.refundedQuantity = 0;
|
|
1501
|
+
// p.refundedTotal = 0;
|
|
1502
|
+
// if (
|
|
1503
|
+
// this.transactionDocument.basket.taxBreakdown &&
|
|
1504
|
+
// this.transactionDocument.basket.taxBreakdown.taxLines.length > 0
|
|
1505
|
+
// ) {
|
|
1506
|
+
// this.transactionDocument.basket.taxBreakdown.taxLines.forEach((taxLine: { itemLineId: { toString: () => any; }; VAT: any; VATCode: any; }) => {
|
|
1507
|
+
// if (product.itemLineId === taxLine.itemLineId.toString()) {
|
|
1508
|
+
// p.selectedVAT = taxLine.VAT;
|
|
1509
|
+
// p.selectedVATCode = taxLine.VATCode;
|
|
1510
|
+
// }
|
|
1511
|
+
// });
|
|
1512
|
+
// }
|
|
1513
|
+
// if (p.quantity > 0) {
|
|
1514
|
+
// basket.products.push(p);
|
|
1515
|
+
// }
|
|
1516
|
+
// });
|
|
1517
|
+
// // product.itemDiscounts
|
|
1518
|
+
// if (!basket.products[0].hasOwnProperty('itemDiscounts')) {
|
|
1519
|
+
// basket = this.getTransactionDiscountAndTransactionPromotionPortion(basket);
|
|
1520
|
+
// }
|
|
1521
|
+
// console.log("ebasket : TransactionDocumentBuilder :new created refunded basket", JSON.stringify(basket))
|
|
1522
|
+
// basket.quantity = basket.products.reduce(
|
|
1523
|
+
// (n: any, { quantity }: any) => n + quantity,
|
|
1524
|
+
// 0
|
|
1525
|
+
// );
|
|
1526
|
+
// basket.total = this.getTotalWithLineDiscountAndLinePromotionApplied(basket);
|
|
1527
|
+
// basket.basketTotal = basket.total;
|
|
1528
|
+
// basket.basketTotal = basket.basketTotal - this.getTotalDiscountWithTransactionDiscountsAndPromotions(basket);
|
|
1529
|
+
// console.log(
|
|
1530
|
+
// "ebasket : TransactionDocumentBuilder : update Basket Total: after promotion :basketTotal",
|
|
1531
|
+
// basket.basketTotal
|
|
1532
|
+
// );
|
|
1533
|
+
// console.log(
|
|
1534
|
+
// "e:basket :TransactionDocumentBuilder : basketDetails updated values",
|
|
1535
|
+
// JSON.stringify(basket)
|
|
1536
|
+
// );
|
|
1537
|
+
// return basket;
|
|
1538
|
+
// }
|
|
1539
|
+
getTransactionDiscountAndTransactionPromotionPortion(basket) {
|
|
1540
|
+
if (basket.transactionDiscount &&
|
|
1541
|
+
basket.transactionDiscount.length > 0) {
|
|
1542
|
+
basket.transactionDiscount.forEach((discount) => {
|
|
1543
|
+
if (!discount.itemLineIds) {
|
|
1544
|
+
discount.itemLineIds = basket.products.map((product) => {
|
|
1545
|
+
return product.itemLineId;
|
|
1546
|
+
});
|
|
1547
|
+
}
|
|
1548
|
+
basket = this.basketService.transactionDiscountProductPortionCalc(basket, discount);
|
|
1549
|
+
});
|
|
1550
|
+
}
|
|
1551
|
+
if (basket.transactionPromotion &&
|
|
1552
|
+
basket.transactionPromotion.length > 0) {
|
|
1553
|
+
basket.transactionPromotion.forEach((tPromotion) => {
|
|
1554
|
+
if (!tPromotion.itemLineIds) {
|
|
1555
|
+
const filteredData = basket.products.filter((item) => {
|
|
1556
|
+
return item.excludePromotion === false;
|
|
1557
|
+
});
|
|
1558
|
+
tPromotion.itemLineIds =
|
|
1559
|
+
filteredData.map((product) => {
|
|
1560
|
+
return product.itemLineId;
|
|
1561
|
+
});
|
|
1562
|
+
}
|
|
1563
|
+
basket = this.basketService.transactionPromotionProductPortionCalc(basket, tPromotion);
|
|
1564
|
+
});
|
|
1565
|
+
}
|
|
1566
|
+
return basket;
|
|
1567
|
+
}
|
|
1568
|
+
getTotalDiscountWithTransactionDiscountsAndPromotions(basketDetails) {
|
|
1569
|
+
let discountTotal = 0;
|
|
1570
|
+
if (basketDetails.transactionPromotion &&
|
|
1571
|
+
basketDetails.transactionPromotion.length > 0) {
|
|
1572
|
+
discountTotal += basketDetails.transactionPromotion.reduce((n, { promotionAmount }) => n + promotionAmount, 0);
|
|
1573
|
+
}
|
|
1574
|
+
if (basketDetails.transactionDiscount &&
|
|
1575
|
+
basketDetails.transactionDiscount.length > 0) {
|
|
1576
|
+
discountTotal += basketDetails.transactionDiscount.reduce((n, { discountAmount }) => n + discountAmount, 0);
|
|
1577
|
+
}
|
|
1578
|
+
console.log("ebasket : TransactionDocumentBuilder : Transaction discount Total:", discountTotal);
|
|
1579
|
+
return discountTotal;
|
|
1580
|
+
}
|
|
1581
|
+
appendCurrencySymbol(currency, value) {
|
|
1582
|
+
// value=this.decimalpipe.transform(value,'1.2');
|
|
1583
|
+
if (value >= 0) {
|
|
1584
|
+
const returnval = currency + value;
|
|
1585
|
+
console.log(returnval, "ebasket: add currency with value");
|
|
1586
|
+
return returnval;
|
|
1587
|
+
}
|
|
1588
|
+
else {
|
|
1589
|
+
const returnval = "-" + (currency + value * -1);
|
|
1590
|
+
console.log(returnval, "-(currency+(value*-1))");
|
|
1591
|
+
return returnval;
|
|
1592
|
+
}
|
|
1593
|
+
}
|
|
1594
|
+
// /**
|
|
1595
|
+
// * Updates total refund
|
|
1596
|
+
// * @returns total refund
|
|
1597
|
+
// */
|
|
1598
|
+
// updateTotalRefund(): TransactionDocumentBuilder {
|
|
1599
|
+
// this.transactionDocument.basket.products.forEach((product) => {
|
|
1600
|
+
// product.refundedQuantity = product.quantity;
|
|
1601
|
+
// product.refundedTotal = product.totalLinePrice * -1;
|
|
1602
|
+
// console.log(
|
|
1603
|
+
// "ebasket: Transaction price override :",
|
|
1604
|
+
// this.transactionDocument.basket.lineDiscount
|
|
1605
|
+
// );
|
|
1606
|
+
// if (
|
|
1607
|
+
// this.transactionDocument.basket.linePromotion &&
|
|
1608
|
+
// this.transactionDocument.basket.linePromotion.length > 0
|
|
1609
|
+
// ) {
|
|
1610
|
+
// this.transactionDocument.basket.linePromotion.forEach((linePromotion) => {
|
|
1611
|
+
// console.log(
|
|
1612
|
+
// "Promotion: basket linePromotion : ",
|
|
1613
|
+
// this.transactionDocument.basket.linePromotion
|
|
1614
|
+
// );
|
|
1615
|
+
// console.log(
|
|
1616
|
+
// "linePromotion.itemLineId.toString() : ",
|
|
1617
|
+
// linePromotion.itemLineId.toString()
|
|
1618
|
+
// );
|
|
1619
|
+
// console.log(
|
|
1620
|
+
// "condition : " +
|
|
1621
|
+
// (product.itemLineId === linePromotion.itemLineId.toString())
|
|
1622
|
+
// );
|
|
1623
|
+
// if (product.itemLineId === linePromotion.itemLineId.toString()) {
|
|
1624
|
+
// product.refundedTotal =
|
|
1625
|
+
// linePromotion.promotionLinePrice * -1;
|
|
1626
|
+
// }
|
|
1627
|
+
// });
|
|
1628
|
+
// } else
|
|
1629
|
+
// if (
|
|
1630
|
+
// this.transactionDocument.basket.lineDiscount &&
|
|
1631
|
+
// this.transactionDocument.basket.lineDiscount.length > 0
|
|
1632
|
+
// ) {
|
|
1633
|
+
// this.transactionDocument.basket.lineDiscount.forEach((lineDiscount) => {
|
|
1634
|
+
// console.log(
|
|
1635
|
+
// "product.itemLineId : " +
|
|
1636
|
+
// this.transactionDocument.basket.lineDiscount
|
|
1637
|
+
// );
|
|
1638
|
+
// console.log(
|
|
1639
|
+
// "lineDiscount.itemLineId.toString() : " +
|
|
1640
|
+
// lineDiscount.itemLineId.toString()
|
|
1641
|
+
// );
|
|
1642
|
+
// console.log(
|
|
1643
|
+
// "condition : " +
|
|
1644
|
+
// (product.itemLineId === lineDiscount.itemLineId.toString())
|
|
1645
|
+
// );
|
|
1646
|
+
// if (product.itemLineId === lineDiscount.itemLineId.toString()) {
|
|
1647
|
+
// product.refundedTotal = lineDiscount.unitPrice * product.refundedQuantity * -1;
|
|
1648
|
+
// }
|
|
1649
|
+
// });
|
|
1650
|
+
// }
|
|
1651
|
+
// console.log("Product description :" + product.description);
|
|
1652
|
+
// console.log("Product total :" + product.refundedTotal);
|
|
1653
|
+
// // product.displayrefundedamount=this.appendCurrencySymbol(CURRENCY[this.transactionDocument.baseCurrency],product.refundedTotal);
|
|
1654
|
+
// // console.log(product.displayrefundedamount,"displayrefundedamount");
|
|
1655
|
+
// product.refunded = true;
|
|
1656
|
+
// });
|
|
1657
|
+
// const baskettotal = (this.transactionDocument.basketSummary.basketTotal *= -1);
|
|
1658
|
+
// // this.transactionDocument.basketSummary.displaybaskettotal=this.appendCurrencySymbol(CURRENCY[this.transactionDocument.baseCurrency], baskettotal);
|
|
1659
|
+
// const saletotal = (this.transactionDocument.basketSummary.saleTotal *= -1);
|
|
1660
|
+
// // this.transactionDocument.basketSummary.displaysaletotal = this.appendCurrencySymbol(CURRENCY[this.transactionDocument.baseCurrency], saletotal);
|
|
1661
|
+
// (this.transactionDocument.basketSummary.VATTotal *= -1);
|
|
1662
|
+
// return this;
|
|
1663
|
+
// }
|
|
1664
|
+
/**
|
|
1665
|
+
* Sale Total
|
|
1666
|
+
* @param basketDetails
|
|
1667
|
+
* @returns Sale Total
|
|
1668
|
+
*/
|
|
1669
|
+
updateSaleTotal(basketDetails) {
|
|
1670
|
+
const saleTotal = basketDetails.products.reduce((n, { totalLinePrice }) => n + totalLinePrice, 0);
|
|
1671
|
+
return saleTotal;
|
|
1672
|
+
}
|
|
1673
|
+
getTotalWithLineDiscountAndLinePromotionApplied(basketDetails) {
|
|
1674
|
+
let saletotal = 0.0;
|
|
1675
|
+
for (let product of basketDetails.products) {
|
|
1676
|
+
// if (product.linePromotions) {
|
|
1677
|
+
// saletotal += product.linePromotions.promotionLinePrice;
|
|
1678
|
+
// } else if (
|
|
1679
|
+
// product.lineDiscount &&
|
|
1680
|
+
// !product.linePromotions
|
|
1681
|
+
// ) {
|
|
1682
|
+
// saletotal +=
|
|
1683
|
+
// product.quantity * Number(product.lineDiscount.unitPrice.toFixed(2));
|
|
1684
|
+
// } else {
|
|
1685
|
+
// saletotal +=
|
|
1686
|
+
// product.quantity * Number(product.selectedPrice.toFixed(2));
|
|
1687
|
+
// }
|
|
1688
|
+
saletotal += product.total;
|
|
1689
|
+
console.log("e-basket:update product Total:" + saletotal, JSON.stringify(product));
|
|
1690
|
+
}
|
|
1691
|
+
return saletotal;
|
|
1692
|
+
}
|
|
1693
|
+
getRefundedTotalWithQuantity(basketDetails) {
|
|
1694
|
+
let quantity = 0;
|
|
1695
|
+
for (let index = 0; index < basketDetails.products.length; index++) {
|
|
1696
|
+
const product = basketDetails.products[index];
|
|
1697
|
+
if (!product.refundedReasonDescription) {
|
|
1698
|
+
quantity = quantity + product.quantity;
|
|
1699
|
+
}
|
|
1700
|
+
else {
|
|
1701
|
+
quantity = quantity + (product.quantity - product.refundedQuantity);
|
|
1702
|
+
// basketDetails.total = basketDetails.total + product.refundedTotal;
|
|
1703
|
+
}
|
|
1704
|
+
}
|
|
1705
|
+
return quantity;
|
|
1706
|
+
}
|
|
1707
|
+
/**
|
|
1708
|
+
* Discount Total
|
|
1709
|
+
* @returns Discount Total
|
|
1710
|
+
*/
|
|
1711
|
+
updateDiscountTotal() {
|
|
1712
|
+
let refundTotal = this.transactionDocument.basketSummary.refundTotal ? this.transactionDocument.basketSummary.refundTotal : 0;
|
|
1713
|
+
console.info("e-basket: transaction builder: refundTotal", JSON.stringify(refundTotal), JSON.stringify(this.transactionDocument.basketSummary));
|
|
1714
|
+
const discountTotal = Math.abs(Math.abs(this.transactionDocument.basketSummary.saleTotal) -
|
|
1715
|
+
(Math.abs(this.transactionDocument.basketSummary.basketTotal) + Math.abs(refundTotal)));
|
|
1716
|
+
console.log("e-basket: transaction builder: discountTotal", JSON.stringify(discountTotal));
|
|
1717
|
+
return Number(discountTotal.toFixed(2));
|
|
1718
|
+
}
|
|
1719
|
+
updateReasonCode(reasonCode) {
|
|
1720
|
+
this.transactionDocument.reasonCode = reasonCode.code;
|
|
1721
|
+
this.transactionDocument.reasonDescription = reasonCode.name;
|
|
1722
|
+
return this;
|
|
1723
|
+
}
|
|
1724
|
+
updateManagerOverride(useroverride) {
|
|
1725
|
+
this.transactionDocument.override = useroverride;
|
|
1726
|
+
return this;
|
|
1727
|
+
}
|
|
1728
|
+
updateUserID(userID) {
|
|
1729
|
+
this.transactionDocument.userId = userID;
|
|
1730
|
+
return this;
|
|
1731
|
+
}
|
|
1732
|
+
updateUserName(name) {
|
|
1733
|
+
this.transactionDocument.userName = name;
|
|
1734
|
+
return this;
|
|
1735
|
+
}
|
|
1736
|
+
addCustomerDetails(customerDetail) {
|
|
1737
|
+
this.transactionDocument.customer = customerDetail;
|
|
1738
|
+
return this;
|
|
1739
|
+
}
|
|
1740
|
+
updateTaxBreakdown(basketDetails) {
|
|
1741
|
+
// let transactionDiscountTotal = 0;
|
|
1742
|
+
let taxBreakdown = {
|
|
1743
|
+
taxLines: [],
|
|
1744
|
+
totalTaxableAmount: 0,
|
|
1745
|
+
};
|
|
1746
|
+
// if (this.transactionDocument.basket.transactionDiscount && this.transactionDocument.basket.transactionDiscount.length > 0) {
|
|
1747
|
+
// this.transactionDocument.basket.transactionDiscount.forEach((discount) => {
|
|
1748
|
+
// transactionDiscountTotal += discount.discountAmount;
|
|
1749
|
+
// });
|
|
1750
|
+
// }
|
|
1751
|
+
// if (this.transactionDocument.basket.transactionPromotion && this.transactionDocument.basket.transactionPromotion.length > 0) {
|
|
1752
|
+
// this.transactionDocument.basket.transactionPromotion.forEach(
|
|
1753
|
+
// (promotion) => {
|
|
1754
|
+
// transactionDiscountTotal += promotion.promotionAmount;
|
|
1755
|
+
// }
|
|
1756
|
+
// );
|
|
1757
|
+
// }
|
|
1758
|
+
basketDetails.products.forEach((product) => {
|
|
1759
|
+
let taxLine = {
|
|
1760
|
+
itemLineId: product.itemLineId,
|
|
1761
|
+
VAT: product.selectedVAT ? product.selectedVAT : 0,
|
|
1762
|
+
VATCode: product.selectedVATCode,
|
|
1763
|
+
taxLineTotal: 0,
|
|
1764
|
+
taxableAmount: product.total,
|
|
1765
|
+
PreTax: 0
|
|
1766
|
+
};
|
|
1767
|
+
console.info("Product contribution : item line ID :", product.itemLineId, "tax line :", JSON.stringify(taxLine));
|
|
1768
|
+
// step 1
|
|
1769
|
+
// if Transaction Discount and/or promotion applied, find net selling price of each product as taxableamount
|
|
1770
|
+
// if (transactionDiscountTotal > 0) {
|
|
1771
|
+
product = this.basketService.validateProductItemDiscount(product);
|
|
1772
|
+
const productContributionInTotal = product.itemDiscounts.trnDiscountsPortion +
|
|
1773
|
+
product.itemDiscounts.trnPromotionsPortion -
|
|
1774
|
+
product.itemDiscounts.refundPortion;
|
|
1775
|
+
// tp+td-rp;
|
|
1776
|
+
console.info("Product contribution : item line ID :", product.itemLineId, "contribution :", JSON.stringify(productContributionInTotal));
|
|
1777
|
+
// calculate net selling price after applying transaction discount as per product contribution
|
|
1778
|
+
taxLine.taxableAmount -= productContributionInTotal;
|
|
1779
|
+
// }
|
|
1780
|
+
//step 2 - find pre tax
|
|
1781
|
+
taxLine.PreTax = this.numberUtilService.trimTo2Decimal2((taxLine.taxableAmount * 100) / (100 + taxLine.VAT));
|
|
1782
|
+
//step 3 - Update taxbreakdown
|
|
1783
|
+
taxBreakdown.totalTaxableAmount += taxLine.taxableAmount;
|
|
1784
|
+
taxLine.taxableAmount = this.numberUtilService.trimTo2Decimal2(taxLine.taxableAmount);
|
|
1785
|
+
// step 4 - update tax Line total
|
|
1786
|
+
taxLine.taxLineTotal = this.numberUtilService.trimTo2Decimal2(taxLine.taxableAmount - taxLine.PreTax);
|
|
1787
|
+
taxBreakdown.taxLines.push(taxLine);
|
|
1788
|
+
});
|
|
1789
|
+
taxBreakdown.totalTaxableAmount = this.numberUtilService.trimTo2Decimal2(taxBreakdown.totalTaxableAmount);
|
|
1790
|
+
this.transactionDocument.basket.taxBreakdown = taxBreakdown;
|
|
1791
|
+
return this;
|
|
1792
|
+
}
|
|
1793
|
+
updateTotalTaxSummary() {
|
|
1794
|
+
console.log("Total Tax Summery Request :", JSON.stringify(this.transactionDocument.basket.taxBreakdown));
|
|
1795
|
+
let totalTaxSummaryArray = [];
|
|
1796
|
+
let totalTaxSummaryGroup = [];
|
|
1797
|
+
console.log("Tax Lines for Total Tax Summery :", JSON.stringify(this.transactionDocument.basket.taxBreakdown.taxLines));
|
|
1798
|
+
this.transactionDocument.basket.taxBreakdown.taxLines.forEach((element) => {
|
|
1799
|
+
let TaxSummary = {
|
|
1800
|
+
VATCode: "",
|
|
1801
|
+
VAT: -12345,
|
|
1802
|
+
PreTaxSum: 0,
|
|
1803
|
+
TaxSum: 0,
|
|
1804
|
+
TXrateSum: 0
|
|
1805
|
+
};
|
|
1806
|
+
TaxSummary.VATCode = element.VATCode;
|
|
1807
|
+
TaxSummary.VAT = element.VAT;
|
|
1808
|
+
TaxSummary.PreTaxSum = this.numberUtilService.trimTo2Decimal2(element.PreTax);
|
|
1809
|
+
TaxSummary.TaxSum = this.numberUtilService.trimTo2Decimal2(element.taxLineTotal);
|
|
1810
|
+
TaxSummary.TXrateSum = this.numberUtilService.trimTo2Decimal2(TaxSummary.PreTaxSum + TaxSummary.TaxSum);
|
|
1811
|
+
totalTaxSummaryArray.push(TaxSummary);
|
|
1812
|
+
});
|
|
1813
|
+
console.log("Total Tax Summery Without Grouped : ", JSON.stringify(totalTaxSummaryArray));
|
|
1814
|
+
totalTaxSummaryGroup = totalTaxSummaryArray.reduce((preparedArray, currentObj) => {
|
|
1815
|
+
let ind = preparedArray.findIndex((x) => x.VAT === currentObj.VAT);
|
|
1816
|
+
if (ind === -1) {
|
|
1817
|
+
preparedArray.push(currentObj);
|
|
1818
|
+
}
|
|
1819
|
+
else {
|
|
1820
|
+
preparedArray[ind].VATCode = currentObj.VATCode;
|
|
1821
|
+
preparedArray[ind].VAT = currentObj.VAT;
|
|
1822
|
+
preparedArray[ind].PreTaxSum += currentObj.PreTaxSum;
|
|
1823
|
+
preparedArray[ind].TaxSum += currentObj.TaxSum;
|
|
1824
|
+
preparedArray[ind].TXrateSum += currentObj.TXrateSum;
|
|
1825
|
+
}
|
|
1826
|
+
return preparedArray;
|
|
1827
|
+
}, []);
|
|
1828
|
+
console.log("Total Tax Summer Group :", totalTaxSummaryGroup);
|
|
1829
|
+
this.transactionDocument.basket.totalTaxSummary = totalTaxSummaryGroup;
|
|
1830
|
+
return this;
|
|
1831
|
+
}
|
|
1832
|
+
/**
|
|
1833
|
+
* TransactionId
|
|
1834
|
+
* @returns OriginalTransactionId
|
|
1835
|
+
*/
|
|
1836
|
+
addOriginalTransId(tranDoc) {
|
|
1837
|
+
if (this.transactionDocument.type === TRANSACTION_TYPE.REFUND || this.transactionDocument.type === TRANSACTION_TYPE.SALE_REFUND || this.transactionDocument.type === TRANSACTION_TYPE.SALE_EXCHANGE) {
|
|
1838
|
+
this.transactionDocument.originalTransId = tranDoc.transactionId;
|
|
1839
|
+
if (tranDoc.apiResponse && tranDoc.apiResponse.internalId) {
|
|
1840
|
+
this.transactionDocument.originalExternalId = tranDoc.apiResponse.internalId.toString();
|
|
1841
|
+
}
|
|
1842
|
+
}
|
|
1843
|
+
return this;
|
|
1844
|
+
}
|
|
1845
|
+
/**
|
|
1846
|
+
* unreferenced Refund
|
|
1847
|
+
* @returns boolean value
|
|
1848
|
+
*/
|
|
1849
|
+
addUnreferencedRefund() {
|
|
1850
|
+
this.transactionDocument.unreferencedRefund = true;
|
|
1851
|
+
return this;
|
|
1852
|
+
}
|
|
1853
|
+
getRefundTotal() {
|
|
1854
|
+
let totalRefund = 0;
|
|
1855
|
+
for (let index = 0; index < this.transactionDocument.basket.products.length; index++) {
|
|
1856
|
+
const product = this.transactionDocument.basket.products[index];
|
|
1857
|
+
if (product.refundedTotal) {
|
|
1858
|
+
totalRefund = totalRefund + product.refundedTotal;
|
|
1859
|
+
}
|
|
1860
|
+
console.log("ebasket : transaction Service: totalRefund" + totalRefund);
|
|
1861
|
+
}
|
|
1862
|
+
return totalRefund;
|
|
1863
|
+
}
|
|
1864
|
+
docId(docId) {
|
|
1865
|
+
this.transactionDocument.id = docId;
|
|
1866
|
+
return this;
|
|
1867
|
+
}
|
|
1868
|
+
}
|
|
1869
|
+
|
|
1870
|
+
class RJMapperBuilderClass {
|
|
1871
|
+
constructor(transactionDoc) {
|
|
1872
|
+
this.itemCount = 0;
|
|
1873
|
+
this.largestNumber = 0;
|
|
1874
|
+
this.rjObject = {};
|
|
1875
|
+
if (transactionDoc) {
|
|
1876
|
+
this.transactionDocument = transactionDoc;
|
|
1877
|
+
}
|
|
1878
|
+
else {
|
|
1879
|
+
this.transactionDocument = {
|
|
1880
|
+
transactionId: "",
|
|
1881
|
+
offlineTransactionId: "",
|
|
1882
|
+
transactionRef: "",
|
|
1883
|
+
dateTime: "",
|
|
1884
|
+
orgCode: "",
|
|
1885
|
+
storeId: "",
|
|
1886
|
+
storeNodeId: "",
|
|
1887
|
+
storeNodeStructure: "",
|
|
1888
|
+
deviceId: "",
|
|
1889
|
+
terminalId: "",
|
|
1890
|
+
userId: "",
|
|
1891
|
+
initiatingModule: "eBasket",
|
|
1892
|
+
export: false,
|
|
1893
|
+
basket: {},
|
|
1894
|
+
basketSummary: {},
|
|
1895
|
+
baseCurrency: "",
|
|
1896
|
+
type: "",
|
|
1897
|
+
operationStatus: "",
|
|
1898
|
+
createdAt: "",
|
|
1899
|
+
updatedAt: "",
|
|
1900
|
+
id: "",
|
|
1901
|
+
currentTransactionDetails: {},
|
|
1902
|
+
saleTotal: 0,
|
|
1903
|
+
};
|
|
1904
|
+
}
|
|
1905
|
+
this.initilizeItemCount();
|
|
1906
|
+
this.setLineNumberForProducts();
|
|
1907
|
+
this.createdAt = this.getDate(this.transactionDocument.createdAt);
|
|
1908
|
+
this.updatedAt = this.getDate(this.transactionDocument.updatedAt);
|
|
1909
|
+
}
|
|
1910
|
+
getPosbasketInfo() {
|
|
1911
|
+
this.rjObject['Keyword'] = this.generateKeyword();
|
|
1912
|
+
this.rjObject['ID'] = this.generateId(this.createdAt);
|
|
1913
|
+
this.rjObject['XMLSchemaVersion'] = '2';
|
|
1914
|
+
this.rjObject['LastUpdated'] = this.updatedAt;
|
|
1915
|
+
this.rjObject['MajorVersion'] = this.majorVersion;
|
|
1916
|
+
this.rjObject['MinorVersion'] = this.minorVersion;
|
|
1917
|
+
this.rjObject['ManifestVersion'] = this.manifestVersion;
|
|
1918
|
+
this.rjObject['DatabaseSchemaVersion'] = this.databaseSchemaVersion;
|
|
1919
|
+
this.rjObject['BasketType'] = this.basketType;
|
|
1920
|
+
this.rjObject['State'] = this.getState();
|
|
1921
|
+
this.rjObject['ExternalState'] = this.externalState;
|
|
1922
|
+
return this;
|
|
1923
|
+
}
|
|
1924
|
+
getheaderInfo() {
|
|
1925
|
+
this.rjObject['Header'] = {};
|
|
1926
|
+
this.rjObject['Header'].TimeZoneOffset = this.convertToString(this.generateTimezoneoffset(this.transactionDocument.createdAt));
|
|
1927
|
+
this.rjObject['Header'].DateTimeCreated = this.createdAt;
|
|
1928
|
+
this.rjObject['Header'].OriginatedBy = {};
|
|
1929
|
+
this.rjObject['Header'].OriginatedBy.DeviceID = this.deviceId;
|
|
1930
|
+
this.rjObject['Header'].OriginatedBy.CashierID = this.cashierId;
|
|
1931
|
+
this.rjObject['Header'].OriginatedBy.CompanyID = this.companyId;
|
|
1932
|
+
this.rjObject['Header'].OriginatedBy.StoreID = this.transactionDocument.storeId;
|
|
1933
|
+
this.rjObject['Header'].OriginatedBy.BranchID = this.branchId;
|
|
1934
|
+
this.rjObject['Header'].OriginatedBy.TerminalNumber = this.terminalNumber;
|
|
1935
|
+
this.rjObject['Header'].OriginatedBy.TransactionNumber = this.transactionNumber;
|
|
1936
|
+
this.rjObject['Header'].TaxMethodID = this.taxMethodId;
|
|
1937
|
+
this.rjObject['Header'].DynamicStockLookup = this.generateDynamicStockLookUp();
|
|
1938
|
+
this.rjObject['Header'].BasketLanguageID = this.basketLanguageId; //todo
|
|
1939
|
+
this.rjObject['Header'].BasketCountryID = this.basketCountryId; //todo
|
|
1940
|
+
this.rjObject['Header'].BasketCurrencyID = this.transactionDocument.baseCurrency;
|
|
1941
|
+
this.rjObject['Header'].TradingRegionID = this.tradingRegionId;
|
|
1942
|
+
this.rjObject['Header'].Eurozone = " "; //unknown
|
|
1943
|
+
this.rjObject['Header'].EuroBaseExchangeRate = ""; //unknown
|
|
1944
|
+
this.rjObject['Header'].PrintableName = this.transactionDocument.userName; //unknown
|
|
1945
|
+
return this;
|
|
1946
|
+
}
|
|
1947
|
+
rjMapper() {
|
|
1948
|
+
var transactionDiscount = [];
|
|
1949
|
+
if (this.transactionDocument.basket.transactionDiscount && this.transactionDocument.basket.transactionDiscount.length > 0) {
|
|
1950
|
+
transactionDiscount = this.transactionDocument.basket.transactionDiscount;
|
|
1951
|
+
}
|
|
1952
|
+
if (this.transactionDocument.type === TRANSACTION_TYPE.SALE) {
|
|
1953
|
+
this.rjObject['ProductSale'] = [];
|
|
1954
|
+
this.rjObject['ModifierItem'] = [];
|
|
1955
|
+
this.transactionDocument.basket.products.forEach((element) => {
|
|
1956
|
+
let lineDiscount = [];
|
|
1957
|
+
if (this.transactionDocument.basket.lineDiscount && this.transactionDocument.basket.lineDiscount.length > 0) {
|
|
1958
|
+
lineDiscount = this.transactionDocument.basket.lineDiscount.filter((x) => x.itemLineId === element.itemLineId);
|
|
1959
|
+
if (lineDiscount.length > 0) {
|
|
1960
|
+
const index = this.transactionDocument.basket.lineDiscount.indexOf(lineDiscount[0]);
|
|
1961
|
+
if (index > -1) {
|
|
1962
|
+
this.transactionDocument.basket.lineDiscount.splice(index, 1);
|
|
1963
|
+
}
|
|
1964
|
+
}
|
|
1965
|
+
}
|
|
1966
|
+
let data = this.addProduct(element, (lineDiscount.length > 0 ? lineDiscount[0] : null), (transactionDiscount.length > 0 ? transactionDiscount : null));
|
|
1967
|
+
this.rjObject['ProductSale'].push(data);
|
|
1968
|
+
this.getModifierItem(lineDiscount.length > 0 ? lineDiscount[0] : null, element.itemLineId);
|
|
1969
|
+
});
|
|
1970
|
+
let transactionPromotion = [];
|
|
1971
|
+
if (this.transactionDocument.basket.transactionPromotion && this.transactionDocument.basket.transactionPromotion.length > 0) {
|
|
1972
|
+
transactionPromotion = this.transactionDocument.basket.transactionPromotion;
|
|
1973
|
+
this.getTransactionPromotion(transactionPromotion);
|
|
1974
|
+
}
|
|
1975
|
+
}
|
|
1976
|
+
else if (this.transactionDocument.type === TRANSACTION_TYPE.REFUND) {
|
|
1977
|
+
this.rjObject['ProductReturn'] = [];
|
|
1978
|
+
this.rjObject['ModifierItem'] = [];
|
|
1979
|
+
this.transactionDocument.basket.products.forEach((element) => {
|
|
1980
|
+
let data = this.returnProduct(element, (element.hasOwnProperty('lineDiscount') ? element.lineDiscount : null), (transactionDiscount.length > 0 ? transactionDiscount : null));
|
|
1981
|
+
this.rjObject['ProductReturn'].push(data);
|
|
1982
|
+
this.getModifierItem(element.lineDiscount, element.itemLineId);
|
|
1983
|
+
});
|
|
1984
|
+
}
|
|
1985
|
+
else if (this.transactionDocument.type === TRANSACTION_TYPE.SALE_REFUND) {
|
|
1986
|
+
this.rjObject['ProductReturn'] = [];
|
|
1987
|
+
this.rjObject['ModifierItem'] = [];
|
|
1988
|
+
let transactionDoc = new TransactionDocumentBuilder().basket(this.transactionDocument.currentTransactionDetails).build();
|
|
1989
|
+
transactionDoc.basket.products.forEach((element) => {
|
|
1990
|
+
let data = this.returnProduct(element, (element.hasOwnProperty('lineDiscount') ? element.lineDiscount : null), (transactionDiscount.length > 0 ? transactionDiscount : null));
|
|
1991
|
+
let obj = {
|
|
1992
|
+
"OriginalReceiptSupplied": 0,
|
|
1993
|
+
"OriginalBranchID": 0,
|
|
1994
|
+
"OriginalTerminalNumber": 0,
|
|
1995
|
+
"OriginalTransactionNumber": 0,
|
|
1996
|
+
"OriginalCashierNumber": 0
|
|
1997
|
+
};
|
|
1998
|
+
data['Return'] = { ...data['Return'], ...obj };
|
|
1999
|
+
this.rjObject['ProductReturn'].push(data);
|
|
2000
|
+
this.getModifierItem(element.lineDiscount, element.itemLineId);
|
|
2001
|
+
});
|
|
2002
|
+
}
|
|
2003
|
+
else if (this.transactionDocument.type === TRANSACTION_TYPE.SALE_EXCHANGE) {
|
|
2004
|
+
this.rjObject['ProductReturn'] = [];
|
|
2005
|
+
this.rjObject['ProductSale'] = [];
|
|
2006
|
+
this.rjObject['ModifierItem'] = [];
|
|
2007
|
+
let transactionDoc = new TransactionDocumentBuilder().basket(this.transactionDocument.currentTransactionDetails).build();
|
|
2008
|
+
transactionDoc.basket.products.forEach((element) => {
|
|
2009
|
+
if (element.refundedQuantity > 0) {
|
|
2010
|
+
let returnProduct = this.returnProduct(element, (element.hasOwnProperty('lineDiscount') ? element.lineDiscount : null), (transactionDiscount.length > 0 ? transactionDiscount : null));
|
|
2011
|
+
let obj = {
|
|
2012
|
+
"OriginalReceiptSupplied": 0,
|
|
2013
|
+
"OriginalBranchID": 0,
|
|
2014
|
+
"OriginalTerminalNumber": 0,
|
|
2015
|
+
"OriginalTransactionNumber": 0,
|
|
2016
|
+
"OriginalCashierNumber": 0
|
|
2017
|
+
};
|
|
2018
|
+
returnProduct['Return'] = { ...returnProduct['Return'], ...obj };
|
|
2019
|
+
this.rjObject['ProductReturn'].push(returnProduct);
|
|
2020
|
+
}
|
|
2021
|
+
else {
|
|
2022
|
+
let addProduct = this.addProduct(element, (element.hasOwnProperty('lineDiscount') ? element.lineDiscount : null), (transactionDiscount.length > 0 ? transactionDiscount : null));
|
|
2023
|
+
this.rjObject['ProductSale'].push(addProduct);
|
|
2024
|
+
}
|
|
2025
|
+
this.getModifierItem(element.lineDiscount, element.itemLineId);
|
|
2026
|
+
});
|
|
2027
|
+
}
|
|
2028
|
+
return this;
|
|
2029
|
+
}
|
|
2030
|
+
getBasketDiscount() {
|
|
2031
|
+
if (!this.transactionDocument.basket.transactionDiscount)
|
|
2032
|
+
return this;
|
|
2033
|
+
this.rjObject['BasketDiscount'] = [];
|
|
2034
|
+
this.transactionDocument.basket.transactionDiscount.forEach((element) => {
|
|
2035
|
+
let obj = {};
|
|
2036
|
+
obj['XMLSchemaVersion'] = this.xmlSchemaVersion;
|
|
2037
|
+
obj['DeviceID'] = this.deviceId;
|
|
2038
|
+
obj['DateTimeCreated'] = this.updatedAt;
|
|
2039
|
+
obj['NetValue'] = this.convertToString(element.discountAmount * -1);
|
|
2040
|
+
obj['EffectiveNetValue'] = this.convertToString(element.discountAmount * -1);
|
|
2041
|
+
obj['Description'] = element.reasonDisplayText;
|
|
2042
|
+
obj['UserID'] = this.transactionDocument.userName;
|
|
2043
|
+
obj['ReasonCodeID'] = element.reasonCode;
|
|
2044
|
+
obj['DiscountType'] = this.convertToString(element.discountType.toUpperCase() == DISCOUNTTYPE.PERCENT.toUpperCase() ? 0 : 1);
|
|
2045
|
+
obj['RoundingRule'] = this.convertToString(2);
|
|
2046
|
+
obj['ModifiedLineNumber'] = element.itemLineIds;
|
|
2047
|
+
obj['LineNumber'] = this.convertToString(this.generateLineNumber());
|
|
2048
|
+
obj['DiscountedValue'] = this.transactionDocument.basketSummary.basketTotal + this.transactionDocument.basketSummary.discountTotal;
|
|
2049
|
+
if (element.discountType.toUpperCase() == DISCOUNTTYPE.PERCENT.toUpperCase()) {
|
|
2050
|
+
obj['DiscountPercentage'] = this.convertToString((element.discountAmount / this.transactionDocument.basketSummary.basketTotal).toFixed(1));
|
|
2051
|
+
}
|
|
2052
|
+
if (this.transactionDocument.type === 'REFUND') {
|
|
2053
|
+
obj['NetValue'] = this.convertToString(element.discountAmount < 0 ? -element.discountAmount : element.discountAmount);
|
|
2054
|
+
obj['EffectiveNetValue'] = this.convertToString(element.discountAmount < 0 ? -element.discountAmount : element.discountAmount);
|
|
2055
|
+
}
|
|
2056
|
+
this.rjObject['BasketDiscount'].push(obj);
|
|
2057
|
+
});
|
|
2058
|
+
return this;
|
|
2059
|
+
}
|
|
2060
|
+
getModifierItem(data, lineNo) {
|
|
2061
|
+
if (data && lineNo) {
|
|
2062
|
+
let obj = {};
|
|
2063
|
+
obj.XMLSchemaVersion = 1;
|
|
2064
|
+
obj.LineNumber = this.generateLineNumber();
|
|
2065
|
+
obj.NetValue = 0;
|
|
2066
|
+
obj.EffectiveNetValue = 0;
|
|
2067
|
+
obj.Description = data.percentageDiscountReasonName ? data.percentageDiscountReasonName : data.priceOverrideReasonName;
|
|
2068
|
+
obj.DeviceID = this.deviceId;
|
|
2069
|
+
obj.UserID = this.transactionDocument.userName;
|
|
2070
|
+
obj.DateTimeCreated = this.updatedAt;
|
|
2071
|
+
obj.AuthorisingUserID = this.transactionDocument.userName;
|
|
2072
|
+
obj.ReasonCodeID = data.percentageDiscountReasonCode ? data.percentageDiscountReasonCode : data.priceOverrideReasonCode;
|
|
2073
|
+
obj.ModifiedLineNumber = lineNo;
|
|
2074
|
+
obj.ModifiedIndex = 1;
|
|
2075
|
+
this.rjObject['ModifierItem'].push(obj);
|
|
2076
|
+
}
|
|
2077
|
+
}
|
|
2078
|
+
getTrailerInfo() {
|
|
2079
|
+
this.rjObject['Trailer'] = {};
|
|
2080
|
+
this.rjObject.Trailer.DateTimeCompleted = this.updatedAt;
|
|
2081
|
+
this.rjObject.Trailer.CompletedBy = {};
|
|
2082
|
+
this.rjObject.Trailer.CompletedBy.DeviceID = this.deviceId;
|
|
2083
|
+
this.rjObject.Trailer.CompletedBy.CashierID = this.cashierId;
|
|
2084
|
+
this.rjObject.Trailer.CompletedBy.StoreID = this.transactionDocument.storeId;
|
|
2085
|
+
this.rjObject.Trailer.CompletedBy.BranchID = this.branchId;
|
|
2086
|
+
this.rjObject.Trailer.CompletedBy.TerminalNumber = this.terminalNumber;
|
|
2087
|
+
this.rjObject.Trailer.CompletedBy.TransactionNumber = this.transactionNumber;
|
|
2088
|
+
this.rjObject.Trailer.Total = this.convertToString(this.transactionDocument.basketSummary.basketTotal * 100);
|
|
2089
|
+
this.rjObject.Trailer.ItemCount = this.itemCount; //gives total count for product
|
|
2090
|
+
this.rjObject.Trailer.ItemQuantity = this.convertToString(this.transactionDocument.basketSummary.totalItems);
|
|
2091
|
+
this.rjObject.Trailer.NetItemQuantity = this.convertToString(this.transactionDocument.basketSummary.totalItems);
|
|
2092
|
+
this.rjObject.Trailer.TaxTotal = this.convertToString(this.removeDecimal(this.transactionDocument.basketSummary.VATTotal));
|
|
2093
|
+
this.rjObject.Trailer.SequenceDeviceID = this.deviceId;
|
|
2094
|
+
this.rjObject.Trailer.SequenceNumber = 'snsn'; //static for now
|
|
2095
|
+
this.rjObject['Trailer']['TaxItem'] = [];
|
|
2096
|
+
this.transactionDocument.basket.taxBreakdown.taxLines.forEach((element) => {
|
|
2097
|
+
let obj = {};
|
|
2098
|
+
obj['XMLSchemaVersion'] = this.xmlSchemaVersion;
|
|
2099
|
+
obj['TaxRate'] = this.convertToString(element.VATCode);
|
|
2100
|
+
obj['TaxableTotal'] = this.convertToString(this.removeDecimal(element.taxableAmount));
|
|
2101
|
+
obj['TaxTotal'] = this.convertToString(this.removeDecimal(this.removeDecimal(element.taxLineTotal)));
|
|
2102
|
+
obj['TaxDescription'] = this.convertToString(element.VATCode);
|
|
2103
|
+
obj['TaxIncluded'] = '1';
|
|
2104
|
+
obj['TaxPercentage'] = this.addDecimal(element.VAT.toFixed(2)).toFixed(2);
|
|
2105
|
+
this.rjObject['Trailer']['TaxItem'].push(obj);
|
|
2106
|
+
});
|
|
2107
|
+
if (this.transactionDocument.basket.linePromotion.length > 0 || this.transactionDocument.basket.linePromotion.length > 0) {
|
|
2108
|
+
this.rjObject['Trailer']['PromotionItem'] = [];
|
|
2109
|
+
if (this.transactionDocument.basket.linePromotion.length > 0) {
|
|
2110
|
+
this.transactionDocument.basket.linePromotion.forEach((element) => {
|
|
2111
|
+
let obj = {};
|
|
2112
|
+
obj['PromotionID'] = element.promotionId;
|
|
2113
|
+
obj['PromotionSaving'] = element.promotionAmount < 0 ? element.promotionAmount : -element.promotionAmount;
|
|
2114
|
+
obj['PromotionQuantity'] = "1";
|
|
2115
|
+
obj['PromotionDescription'] = element.displayText;
|
|
2116
|
+
obj['PromotionHit'] = {};
|
|
2117
|
+
obj['PromotionHit']['XMLSchemaVersion'] = this.xmlSchemaVersion;
|
|
2118
|
+
obj['PromotionHit']['HitNumber'] = "1";
|
|
2119
|
+
obj['PromotionHit']['HitQuantity'] = "1";
|
|
2120
|
+
obj['PromotionHit']['HitSaving'] = element.promotionAmount < 0 ? element.promotionAmount : -element.promotionAmount;
|
|
2121
|
+
obj['PromotionHit']['PromotionTrigger'] = {};
|
|
2122
|
+
let product = this.transactionDocument.basket.products.find((item) => item.itemLineId == element.itemLineId);
|
|
2123
|
+
obj['PromotionHit']['PromotionTrigger']['XMLSchemaVersion'] = this.xmlSchemaVersion;
|
|
2124
|
+
obj['PromotionHit']['PromotionTrigger']['ProductID'] = product.SKU;
|
|
2125
|
+
obj['PromotionHit']['PromotionTrigger']['UnitValue'] = this.convertToString(element.promotionLinePrice / product.quantity);
|
|
2126
|
+
obj['PromotionHit']['PromotionTrigger']['LineNumber'] = this.getNumber(product.SKU);
|
|
2127
|
+
obj['PromotionHit']['PromotionTrigger']['Quantity'] = this.convertToString(product.quantity.toFixed(1));
|
|
2128
|
+
obj['PromotionHit']['PromotionTrigger']['TaxCode'] = this.transactionDocument.basket.taxBreakdown.taxLines.find((item) => item.itemLineId == element.itemLineId).VATCode;
|
|
2129
|
+
this.rjObject['Trailer']['PromotionItem'].push(obj);
|
|
2130
|
+
});
|
|
2131
|
+
}
|
|
2132
|
+
if (this.transactionDocument.basket.transactionPromotion.length > 0) {
|
|
2133
|
+
this.transactionDocument.basket.transactionPromotion.forEach((element) => {
|
|
2134
|
+
let obj = {};
|
|
2135
|
+
obj['PromotionID'] = element.promotionId;
|
|
2136
|
+
obj['PromotionSaving'] = element.promotionAmount < 0 ? element.promotionAmount : -element.promotionAmount;
|
|
2137
|
+
obj['PromotionQuantity'] = "1";
|
|
2138
|
+
obj['PromotionDescription'] = element.displayText;
|
|
2139
|
+
obj['PromotionHit'] = {};
|
|
2140
|
+
obj['PromotionHit']['XMLSchemaVersion'] = this.xmlSchemaVersion;
|
|
2141
|
+
obj['PromotionHit']['HitNumber'] = "1";
|
|
2142
|
+
obj['PromotionHit']['HitQuantity'] = "1";
|
|
2143
|
+
obj['PromotionHit']['HitSaving'] = element.promotionAmount < 0 ? element.promotionAmount : -element.promotionAmount;
|
|
2144
|
+
obj['PromotionHit']['PromotionTrigger'] = [];
|
|
2145
|
+
this.transactionDocument.basket.products.forEach((product) => {
|
|
2146
|
+
let promotionTrigger = {};
|
|
2147
|
+
element.itemLineIds.forEach((itemLineId) => {
|
|
2148
|
+
if (JSON.stringify(itemLineId) === product.itemLineId) {
|
|
2149
|
+
promotionTrigger['XMLSchemaVersion'] = this.xmlSchemaVersion;
|
|
2150
|
+
promotionTrigger['ProductID'] = product.SKU;
|
|
2151
|
+
promotionTrigger['UnitValue'] = this.convertToString(element.promotionLinePrice / product.quantity);
|
|
2152
|
+
promotionTrigger['LineNumber'] = this.getNumber(product.SKU);
|
|
2153
|
+
promotionTrigger['Quantity'] = this.convertToString(product.quantity);
|
|
2154
|
+
promotionTrigger['TaxCode'] = this.transactionDocument.basket.taxBreakdown.taxLines.find((item) => item.itemLineId == product.itemLineId).VATCode;
|
|
2155
|
+
obj['PromotionHit']['PromotionTrigger'].push(promotionTrigger);
|
|
2156
|
+
}
|
|
2157
|
+
});
|
|
2158
|
+
});
|
|
2159
|
+
this.rjObject['Trailer']['PromotionItem'].push(obj);
|
|
2160
|
+
});
|
|
2161
|
+
}
|
|
2162
|
+
}
|
|
2163
|
+
return this;
|
|
2164
|
+
}
|
|
2165
|
+
getTenderInfo() {
|
|
2166
|
+
if (this.transactionDocument.paymentDetails && this.transactionDocument.paymentDetails.length > 0) {
|
|
2167
|
+
this.transactionDocument.paymentDetails.forEach((element) => {
|
|
2168
|
+
if (element.externalTenderKey) {
|
|
2169
|
+
this.rjObject[element.externalTenderKey] = [];
|
|
2170
|
+
if (element.paymentType.toUpperCase() === 'GIFT CARD') {
|
|
2171
|
+
let obj = {
|
|
2172
|
+
XMLSchemaVersion: this.xmlSchemaVersion,
|
|
2173
|
+
LineNumber: this.generateLineNumber(),
|
|
2174
|
+
NetValue: this.convertToString(-1 * this.removeDecimal((Math.round(element.amount)))),
|
|
2175
|
+
EffectiveNetValue: this.convertToString(-1 * this.removeDecimal((Math.round(element.amount)))),
|
|
2176
|
+
Description: this.getDescription(element),
|
|
2177
|
+
DeviceID: this.deviceId,
|
|
2178
|
+
UserID: this.transactionDocument.userName,
|
|
2179
|
+
DateTimeCreated: this.updatedAt,
|
|
2180
|
+
TenderType: element.externalTenderType ? element.externalTenderType : '',
|
|
2181
|
+
TenderSubType: element.externalSubTenderType ? element.externalSubTenderType : '',
|
|
2182
|
+
TenderAmount: this.convertToString(-1 * this.removeDecimal((Math.round(element.amount)))),
|
|
2183
|
+
CurrencyID: this.transactionDocument.baseCurrency,
|
|
2184
|
+
CurrencyDescription: this.transactionDocument.baseCurrency,
|
|
2185
|
+
GiftVoucherSalesAllowed: '', //todo
|
|
2186
|
+
AllowRechargeableVoucherSales: '', //todo
|
|
2187
|
+
GiftVoucherID: ''
|
|
2188
|
+
};
|
|
2189
|
+
this.rjObject[element.externalTenderKey].push(obj);
|
|
2190
|
+
}
|
|
2191
|
+
else {
|
|
2192
|
+
let obj1 = {
|
|
2193
|
+
XMLSchemaVersion: "1",
|
|
2194
|
+
LineNumber: this.generateLineNumber(), //todo
|
|
2195
|
+
NetValue: this.convertToString(-1 * this.removeDecimal(Math.round(element.amount))),
|
|
2196
|
+
EffectiveNetValue: this.convertToString(-1 * this.removeDecimal(Math.round(element.amount))),
|
|
2197
|
+
Description: this.getDescription(element),
|
|
2198
|
+
DeviceID: this.deviceId,
|
|
2199
|
+
UserID: this.transactionDocument.userName,
|
|
2200
|
+
DateTimeCreated: this.updatedAt,
|
|
2201
|
+
TenderType: element.externalTenderType ? element.externalTenderType : '',
|
|
2202
|
+
TenderSubType: element.externalSubTenderType ? element.externalSubTenderType : '',
|
|
2203
|
+
TenderAmount: this.convertToString(-1 * this.removeDecimal(Math.round(element.amount))),
|
|
2204
|
+
CurrencyID: this.transactionDocument.baseCurrency,
|
|
2205
|
+
CurrencyDescription: this.transactionDocument.baseCurrency,
|
|
2206
|
+
IncludeInTransactionTotalCheck: "1",
|
|
2207
|
+
AllowRechargeableVoucherSales: "1",
|
|
2208
|
+
OpenDrawerAtEnd: "1"
|
|
2209
|
+
};
|
|
2210
|
+
this.rjObject[element.externalTenderKey].push(obj1);
|
|
2211
|
+
}
|
|
2212
|
+
}
|
|
2213
|
+
else {
|
|
2214
|
+
this.rjObject['CashTender'] = [];
|
|
2215
|
+
if (element.paymentType.toUpperCase() === 'GIFT CARD') {
|
|
2216
|
+
let obj = {
|
|
2217
|
+
XMLSchemaVersion: this.xmlSchemaVersion,
|
|
2218
|
+
LineNumber: this.generateLineNumber(),
|
|
2219
|
+
NetValue: JSON.stringify(-1 * this.removeDecimal((Math.round(element.amount)))),
|
|
2220
|
+
EffectiveNetValue: JSON.stringify(-1 * this.removeDecimal((Math.round(element.amount)))),
|
|
2221
|
+
Description: this.getDescription(element),
|
|
2222
|
+
DeviceID: this.deviceId,
|
|
2223
|
+
UserID: this.transactionDocument.userName,
|
|
2224
|
+
DateTimeCreated: this.updatedAt,
|
|
2225
|
+
TenderType: element.externalTenderType ? element.externalTenderType : '',
|
|
2226
|
+
TenderSubType: element.externalSubTenderType ? element.externalSubTenderType : '',
|
|
2227
|
+
TenderAmount: JSON.stringify(-1 * this.removeDecimal((Math.round(element.amount)))),
|
|
2228
|
+
CurrencyID: this.transactionDocument.baseCurrency,
|
|
2229
|
+
CurrencyDescription: this.transactionDocument.baseCurrency,
|
|
2230
|
+
GiftVoucherSalesAllowed: '', //todo
|
|
2231
|
+
AllowRechargeableVoucherSales: '', //todo
|
|
2232
|
+
GiftVoucherID: ''
|
|
2233
|
+
};
|
|
2234
|
+
this.rjObject['CashTender'].push(obj);
|
|
2235
|
+
}
|
|
2236
|
+
else {
|
|
2237
|
+
let obj1 = {
|
|
2238
|
+
XMLSchemaVersion: "1",
|
|
2239
|
+
LineNumber: this.generateLineNumber(),
|
|
2240
|
+
NetValue: JSON.stringify(-1 * this.removeDecimal((Math.round(element.amount)))),
|
|
2241
|
+
EffectiveNetValue: JSON.stringify(-1 * this.removeDecimal((Math.round(element.amount)))),
|
|
2242
|
+
Description: this.getDescription(element),
|
|
2243
|
+
DeviceID: this.deviceId,
|
|
2244
|
+
UserID: this.transactionDocument.userName,
|
|
2245
|
+
DateTimeCreated: this.updatedAt,
|
|
2246
|
+
TenderType: element.externalTenderType ? element.externalTenderType : '',
|
|
2247
|
+
TenderSubType: element.externalSubTenderType ? element.externalSubTenderType : '',
|
|
2248
|
+
TenderAmount: JSON.stringify(-1 * this.removeDecimal((Math.round(element.amount)))),
|
|
2249
|
+
CurrencyID: this.transactionDocument.baseCurrency,
|
|
2250
|
+
CurrencyDescription: this.transactionDocument.baseCurrency,
|
|
2251
|
+
IncludeInTransactionTotalCheck: "1",
|
|
2252
|
+
AllowRechargeableVoucherSales: "1",
|
|
2253
|
+
OpenDrawerAtEnd: "1"
|
|
2254
|
+
};
|
|
2255
|
+
this.rjObject['CashTender'].push(obj1);
|
|
2256
|
+
}
|
|
2257
|
+
}
|
|
2258
|
+
});
|
|
2259
|
+
}
|
|
2260
|
+
return this;
|
|
2261
|
+
}
|
|
2262
|
+
getNumber(productId) {
|
|
2263
|
+
let lineNumber;
|
|
2264
|
+
for (let i = 0; i < this.rjObject['ProductSale'].length; i++) {
|
|
2265
|
+
const element = this.rjObject['ProductSale'][i];
|
|
2266
|
+
if (JSON.stringify(productId) === JSON.stringify(element.ProductID)) {
|
|
2267
|
+
lineNumber = element.LineNumber;
|
|
2268
|
+
break;
|
|
2269
|
+
}
|
|
2270
|
+
}
|
|
2271
|
+
return lineNumber;
|
|
2272
|
+
}
|
|
2273
|
+
setLineNumberForProducts() {
|
|
2274
|
+
let itemLineIdArray = [];
|
|
2275
|
+
itemLineIdArray = this.transactionDocument.basket.products.map((product) => {
|
|
2276
|
+
return parseInt(product.itemLineId);
|
|
2277
|
+
});
|
|
2278
|
+
this.largestNumber = itemLineIdArray.reduce((a, b) => Math.max(a, b));
|
|
2279
|
+
}
|
|
2280
|
+
generateLineNumber() {
|
|
2281
|
+
this.largestNumber += 1;
|
|
2282
|
+
this.itemCount += 1;
|
|
2283
|
+
return this.largestNumber;
|
|
2284
|
+
}
|
|
2285
|
+
initilizeItemCount() {
|
|
2286
|
+
this.itemCount = this.transactionDocument.basket.products.length;
|
|
2287
|
+
}
|
|
2288
|
+
build() {
|
|
2289
|
+
return this.rjObject;
|
|
2290
|
+
}
|
|
2291
|
+
getDescription(element) {
|
|
2292
|
+
if (element.paymentType.toUpperCase() === 'CARD') {
|
|
2293
|
+
return element.cardType;
|
|
2294
|
+
}
|
|
2295
|
+
else {
|
|
2296
|
+
return element.paymentType;
|
|
2297
|
+
}
|
|
2298
|
+
}
|
|
2299
|
+
getMMGROUPID(attributes) {
|
|
2300
|
+
if (attributes && attributes.length > 0) {
|
|
2301
|
+
let filterValue = attributes.filter((attribute) => attribute.name === "MMGROUPID");
|
|
2302
|
+
if (filterValue && filterValue.length > 0) {
|
|
2303
|
+
return filterValue[0].value;
|
|
2304
|
+
}
|
|
2305
|
+
}
|
|
2306
|
+
}
|
|
2307
|
+
setDeviceInfo(id) {
|
|
2308
|
+
this.deviceId = id;
|
|
2309
|
+
return this;
|
|
2310
|
+
}
|
|
2311
|
+
removeDecimal(value) {
|
|
2312
|
+
return value * 100;
|
|
2313
|
+
}
|
|
2314
|
+
addDecimal(value) {
|
|
2315
|
+
return value / 100;
|
|
2316
|
+
}
|
|
2317
|
+
setTransactionNumber(value) {
|
|
2318
|
+
this.transactionNumber = value;
|
|
2319
|
+
return this;
|
|
2320
|
+
}
|
|
2321
|
+
setManifestVersion(value) {
|
|
2322
|
+
this.manifestVersion = value;
|
|
2323
|
+
return this;
|
|
2324
|
+
}
|
|
2325
|
+
setDatabaseSchemaVersion(value) {
|
|
2326
|
+
this.databaseSchemaVersion = value;
|
|
2327
|
+
return this;
|
|
2328
|
+
}
|
|
2329
|
+
setBasketType(value) {
|
|
2330
|
+
this.basketType = value;
|
|
2331
|
+
return this;
|
|
2332
|
+
}
|
|
2333
|
+
setTradingRegionID(value) {
|
|
2334
|
+
this.tradingRegionId = value;
|
|
2335
|
+
return this;
|
|
2336
|
+
}
|
|
2337
|
+
setCompanyID(value) {
|
|
2338
|
+
this.companyId = value;
|
|
2339
|
+
return this;
|
|
2340
|
+
}
|
|
2341
|
+
setTaxMethodID(value) {
|
|
2342
|
+
this.taxMethodId = value;
|
|
2343
|
+
return this;
|
|
2344
|
+
}
|
|
2345
|
+
setMajorVersion(value) {
|
|
2346
|
+
this.majorVersion = value;
|
|
2347
|
+
return this;
|
|
2348
|
+
}
|
|
2349
|
+
setMinorVersion(value) {
|
|
2350
|
+
this.minorVersion = value;
|
|
2351
|
+
return this;
|
|
2352
|
+
}
|
|
2353
|
+
setXMLSchemaVersion(value) {
|
|
2354
|
+
this.xmlSchemaVersion = value;
|
|
2355
|
+
return this;
|
|
2356
|
+
}
|
|
2357
|
+
setExternalState(value) {
|
|
2358
|
+
this.externalState = value;
|
|
2359
|
+
return this;
|
|
2360
|
+
}
|
|
2361
|
+
setCashierID() {
|
|
2362
|
+
this.cashierId = (this.transactionDocument && this.transactionDocument.userName) ? this.transactionDocument.userName : '';
|
|
2363
|
+
return this;
|
|
2364
|
+
}
|
|
2365
|
+
setTerminalNumber(value) {
|
|
2366
|
+
this.terminalNumber = value;
|
|
2367
|
+
return this;
|
|
2368
|
+
}
|
|
2369
|
+
setBasketLanguageID(value) {
|
|
2370
|
+
this.basketLanguageId = value;
|
|
2371
|
+
return this;
|
|
2372
|
+
}
|
|
2373
|
+
setBasketCountryID(value) {
|
|
2374
|
+
this.basketCountryId = value;
|
|
2375
|
+
return this;
|
|
2376
|
+
}
|
|
2377
|
+
setBasketCurrencyID(value) {
|
|
2378
|
+
this.basketCurrencyId = value;
|
|
2379
|
+
return this;
|
|
2380
|
+
}
|
|
2381
|
+
setBranchID(value) {
|
|
2382
|
+
this.branchId = value;
|
|
2383
|
+
return this;
|
|
2384
|
+
}
|
|
2385
|
+
setSalesPersonName(value) {
|
|
2386
|
+
this.salesPersonName = value;
|
|
2387
|
+
return this;
|
|
2388
|
+
}
|
|
2389
|
+
generateId(date) {
|
|
2390
|
+
let newDateTime = date.replace(/[^0-9]/g, '');
|
|
2391
|
+
let id = (this.deviceId + '|' + newDateTime + '|' + this.transactionNumber).toString();
|
|
2392
|
+
return id;
|
|
2393
|
+
}
|
|
2394
|
+
generateTimezoneoffset(date) {
|
|
2395
|
+
let x = date ? date : '';
|
|
2396
|
+
return new Date(x).getTimezoneOffset();
|
|
2397
|
+
}
|
|
2398
|
+
generateKeyword() {
|
|
2399
|
+
let x = (this.companyId + '|' + this.transactionDocument.storeId + '|' + this.terminalNumber + '|' + this.transactionNumber).toString();
|
|
2400
|
+
return x;
|
|
2401
|
+
}
|
|
2402
|
+
getState() {
|
|
2403
|
+
if (this.transactionDocument.operationStatus === 'PAY_SUCCESS') {
|
|
2404
|
+
return 'Completed';
|
|
2405
|
+
}
|
|
2406
|
+
else {
|
|
2407
|
+
return 'Cancelled';
|
|
2408
|
+
}
|
|
2409
|
+
}
|
|
2410
|
+
returnProduct(element, lineDiscount, transactionDiscount) {
|
|
2411
|
+
let obj = {};
|
|
2412
|
+
let taxTotal = this.transactionDocument.basket['taxBreakdown']['taxLines'].find((item) => item.itemLineId == element['itemLineId']);
|
|
2413
|
+
obj['XMLSchemaVersion'] = this.xmlSchemaVersion;
|
|
2414
|
+
obj['LineNumber'] = element['itemLineId'];
|
|
2415
|
+
obj['NetValue'] = this.removeDecimal(element['refundedTotal']);
|
|
2416
|
+
obj['EffectiveNetValue'] = this.removeDecimal(element['refundedTotal']);
|
|
2417
|
+
obj['Description'] = element['description'];
|
|
2418
|
+
obj['DeviceID'] = this.transactionDocument['terminalId'];
|
|
2419
|
+
obj['UserID'] = this.transactionDocument.userName;
|
|
2420
|
+
obj['DateTimeCreated'] = this.createdAt;
|
|
2421
|
+
obj['ExtendedValue'] = this.removeDecimal(element['totalLinePrice'] * -1);
|
|
2422
|
+
obj['UnitPrice'] = this.removeDecimal(element['price']);
|
|
2423
|
+
obj['Quantity'] = this.getQuantity(element);
|
|
2424
|
+
obj['OriginalTaxAmountSet'] = 1;
|
|
2425
|
+
obj['ProductID'] = element['SKU'];
|
|
2426
|
+
obj['HandKeyed'] = 1;
|
|
2427
|
+
obj['LongDescription'] = element['description'];
|
|
2428
|
+
obj['Return'] = {};
|
|
2429
|
+
obj['Return']['ReturnReasonID'] = element['refundedReason'];
|
|
2430
|
+
obj['Return']['ReturnDescription'] = element['refundedReasonDescription'];
|
|
2431
|
+
obj['Return']['ReturnToStock'] = this.getQuantity(element);
|
|
2432
|
+
obj['TaxCode'] = this.transactionDocument.basket['taxBreakdown']['taxLines'].find((item) => item.itemLineId == element['itemLineId']).VATCode;
|
|
2433
|
+
obj['DisplayTaxCode'] = ''; // todo
|
|
2434
|
+
obj['ProductAttributes'] = ''; //todo - not required
|
|
2435
|
+
obj['Perishable'] = this.getMMGROUPID(element.attributes);
|
|
2436
|
+
//obj['MMGroupID'] = this.getCaregories(element);
|
|
2437
|
+
obj['MMGroupID'] = this.getMMGROUPID(element.attributes);
|
|
2438
|
+
obj['CustomerDetails'] = ""; // todo - blank
|
|
2439
|
+
obj['TotalPromotionSaving'] = element['promotionAmount'] || -1; // TODO
|
|
2440
|
+
obj['OriginalTaxAmount'] = this.convertToString((this.removeDecimal(this.getOriginalTax(element, taxTotal.VAT) * -1)).toFixed(2));
|
|
2441
|
+
obj['taxAmount'] = this.removeDecimal(taxTotal.taxLineTotal < 0 ? (taxTotal.taxLineTotal) : (-taxTotal.taxLineTotal));
|
|
2442
|
+
if (lineDiscount) {
|
|
2443
|
+
if (lineDiscount.percentageDiscountReasonName && lineDiscount.percentageDiscountReasonCode) {
|
|
2444
|
+
// line discount
|
|
2445
|
+
obj['Discount'] = {};
|
|
2446
|
+
obj['Discount'].ModifierValue = this.removeDecimal(lineDiscount.discountAmount) * -1;
|
|
2447
|
+
obj['Discount'].ModifierDateTime = obj.DateTimeCreated;
|
|
2448
|
+
obj['Discount'].ModifierReasonID = lineDiscount.percentageDiscountReasonCode;
|
|
2449
|
+
obj['Discount'].ModifierDescription = lineDiscount.percentageDiscountReasonName;
|
|
2450
|
+
obj['Discount'].AuthorisingUserID = this.transactionDocument.userName;
|
|
2451
|
+
obj['Discount'].DiscountType = lineDiscount.discountType;
|
|
2452
|
+
obj['Discount'].XMLSchemaVersion = 1;
|
|
2453
|
+
obj['Discount'].OriginalPrice = this.removeDecimal(lineDiscount.discountAmount + (lineDiscount.discountedLinePrice || 0));
|
|
2454
|
+
obj['Discount'].DiscountedValue = this.removeDecimal(lineDiscount.unitPrice);
|
|
2455
|
+
obj['Discount'].DiscountPercentage = lineDiscount.percentageDiscountValue;
|
|
2456
|
+
obj['Discount'].RoundingRule = 2;
|
|
2457
|
+
}
|
|
2458
|
+
if (lineDiscount.priceOverrideReasonCode && lineDiscount.priceOverrideReasonName) {
|
|
2459
|
+
//price override
|
|
2460
|
+
obj['PriceOverride'] = {};
|
|
2461
|
+
obj['PriceOverride'].ModifierValue = this.removeDecimal(lineDiscount.discountAmount) * -1;
|
|
2462
|
+
obj['PriceOverride'].ModifierDateTime = obj.DateTimeCreated;
|
|
2463
|
+
obj['PriceOverride'].ModifierReasonID = lineDiscount.priceOverrideReasonCode;
|
|
2464
|
+
obj['PriceOverride'].ModifierReasonDescription = lineDiscount.priceOverrideReasonName;
|
|
2465
|
+
obj['PriceOverride'].AuthorisingUserID = this.transactionDocument.userName;
|
|
2466
|
+
obj['PriceOverride'].XMLSchemaVersion = 1;
|
|
2467
|
+
obj['PriceOverride'].NewPrice = this.removeDecimal(lineDiscount.unitPrice);
|
|
2468
|
+
obj['PriceOverride'].OriginalPrice = this.removeDecimal(lineDiscount.discountedLinePrice || 0 + lineDiscount.discountAmount);
|
|
2469
|
+
}
|
|
2470
|
+
//update the product price
|
|
2471
|
+
obj.NetValue = ((lineDiscount.discountedLinePrice || 0) + lineDiscount.discountAmount) * -1;
|
|
2472
|
+
obj.EffectiveNetValue = ((lineDiscount.discountedLinePrice || 0) + lineDiscount.discountAmount) * -1;
|
|
2473
|
+
obj.ExtendedValue = ((lineDiscount.discountedLinePrice || 0) + lineDiscount.discountAmount) * -1;
|
|
2474
|
+
obj.UnitPrice = ((lineDiscount.discountedLinePrice || 0) + lineDiscount.discountAmount) * -1;
|
|
2475
|
+
}
|
|
2476
|
+
if (transactionDiscount) {
|
|
2477
|
+
obj['BasketDiscountModifier'] = [];
|
|
2478
|
+
this.transactionDocument.basket.transactionDiscount.forEach((e) => {
|
|
2479
|
+
let discountObj = {};
|
|
2480
|
+
e.itemLineIds.forEach((x) => {
|
|
2481
|
+
if (x == element.itemLineId) {
|
|
2482
|
+
var discountAmount = this.convertToString(e.discountAmount * -1);
|
|
2483
|
+
discountObj.BasketDiscountLineNumber = this.getLineNumber(e, discountAmount);
|
|
2484
|
+
discountObj.XMLSchemaVersion = this.xmlSchemaVersion;
|
|
2485
|
+
discountObj.DiscountedValue = this.getDiscountedValue(element.totalLinePrice, e.discountAmount);
|
|
2486
|
+
obj['BasketDiscountModifier'].push(discountObj);
|
|
2487
|
+
}
|
|
2488
|
+
});
|
|
2489
|
+
});
|
|
2490
|
+
var totaltransactionDiscount = 0;
|
|
2491
|
+
obj['BasketDiscountModifier'].forEach((value) => {
|
|
2492
|
+
totaltransactionDiscount = totaltransactionDiscount + value.DiscountedValue;
|
|
2493
|
+
});
|
|
2494
|
+
//update the product price
|
|
2495
|
+
obj['EffectiveNetValue'] = obj.EffectiveNetValue + totaltransactionDiscount;
|
|
2496
|
+
}
|
|
2497
|
+
if (this.transactionDocument.basket.transactionPromotion.length > 0) {
|
|
2498
|
+
obj['PromotionSaving'] = [];
|
|
2499
|
+
this.transactionDocument.basket.transactionPromotion.forEach((transactionPromo) => {
|
|
2500
|
+
let promotionObj = {};
|
|
2501
|
+
transactionPromo.itemLineIds.forEach((itemLineId) => {
|
|
2502
|
+
if (itemLineId == element.itemLineId) {
|
|
2503
|
+
promotionObj.ModifierValue = transactionPromo.promotionAmount;
|
|
2504
|
+
promotionObj.ModifierDateTime = this.transactionDocument.createdAt;
|
|
2505
|
+
promotionObj.ModifierDescription = transactionPromo.displayText;
|
|
2506
|
+
promotionObj.XMLSchemaVersion = this.xmlSchemaVersion;
|
|
2507
|
+
promotionObj.PromotionID = transactionPromo.promotionId;
|
|
2508
|
+
promotionObj.PromotionDescription = transactionPromo.displayText;
|
|
2509
|
+
promotionObj.HitNumber = '1';
|
|
2510
|
+
promotionObj.PromotionHitProductQuantity = this.getQuantity(element);
|
|
2511
|
+
promotionObj.PromotionHitQuantity = this.getQuantity(element) * -1;
|
|
2512
|
+
obj['PromotionSaving'].push(promotionObj);
|
|
2513
|
+
}
|
|
2514
|
+
});
|
|
2515
|
+
});
|
|
2516
|
+
}
|
|
2517
|
+
return obj;
|
|
2518
|
+
}
|
|
2519
|
+
addProduct(element, lineDiscount, transactionDiscount) {
|
|
2520
|
+
let taxTotal = this.transactionDocument.basket['taxBreakdown']['taxLines'].find((item) => item.itemLineId == element['itemLineId']);
|
|
2521
|
+
let obj = {
|
|
2522
|
+
XMLSchemaVersion: this.xmlSchemaVersion,
|
|
2523
|
+
LineNumber: element.itemLineId,
|
|
2524
|
+
NetValue: this.removeDecimal(element.totalLinePrice),
|
|
2525
|
+
EffectiveNetValue: this.removeDecimal(element.totalLinePrice),
|
|
2526
|
+
Description: element.description,
|
|
2527
|
+
DeviceID: this.deviceId,
|
|
2528
|
+
UserID: this.transactionDocument.userName,
|
|
2529
|
+
DateTimeCreated: this.createdAt,
|
|
2530
|
+
ExtendedValue: this.removeDecimal(element.price),
|
|
2531
|
+
UnitPrice: this.removeDecimal(element.price),
|
|
2532
|
+
//MMGroupID: this.getCaregories(element),
|
|
2533
|
+
Quantity: element.quantity,
|
|
2534
|
+
SalespersonID: this.transactionDocument.userName,
|
|
2535
|
+
SalespersonName: this.salesPersonName,
|
|
2536
|
+
TaxCode: this.transactionDocument.basket['taxBreakdown']['taxLines'].find((item) => item.itemLineId == element['itemLineId']).VATCode,
|
|
2537
|
+
TaxModifiable: "1", //todo
|
|
2538
|
+
OriginalTaxAmount: this.convertToString((this.removeDecimal(this.getOriginalTax(element, taxTotal.VAT)).toFixed(2))),
|
|
2539
|
+
TaxAmount: this.convertToString(this.removeDecimal(taxTotal.taxLineTotal)),
|
|
2540
|
+
OriginalTaxAmountSet: "1", //todo
|
|
2541
|
+
ProductID: element.SKU,
|
|
2542
|
+
HandKeyed: "1", //todo
|
|
2543
|
+
CustomerDetails: "",
|
|
2544
|
+
Perishable: this.getMMGROUPID(element.attributes),
|
|
2545
|
+
MMGroupID: this.getMMGROUPID(element.attributes)
|
|
2546
|
+
};
|
|
2547
|
+
if (lineDiscount) {
|
|
2548
|
+
if (lineDiscount.percentageDiscountReasonName && lineDiscount.percentageDiscountReasonCode) {
|
|
2549
|
+
// line discount
|
|
2550
|
+
obj['Discount'] = {};
|
|
2551
|
+
obj['Discount'].ModifierValue = this.removeDecimal(lineDiscount.discountAmount) * -1;
|
|
2552
|
+
obj['Discount'].ModifierDateTime = obj.DateTimeCreated;
|
|
2553
|
+
obj['Discount'].ModifierReasonID = lineDiscount.percentageDiscountReasonCode;
|
|
2554
|
+
obj['Discount'].ModifierDescription = lineDiscount.percentageDiscountReasonName;
|
|
2555
|
+
obj['Discount'].AuthorisingUserID = this.transactionDocument.userName;
|
|
2556
|
+
obj['Discount'].DiscountType = lineDiscount.discountType;
|
|
2557
|
+
obj['Discount'].XMLSchemaVersion = 1;
|
|
2558
|
+
obj['Discount'].OriginalPrice = this.removeDecimal(lineDiscount.discountAmount + (lineDiscount.discountedLinePrice || 0));
|
|
2559
|
+
obj['Discount'].DiscountedValue = this.removeDecimal(lineDiscount.unitPrice);
|
|
2560
|
+
obj['Discount'].DiscountPercentage = lineDiscount.percentageDiscountValue;
|
|
2561
|
+
obj['Discount'].RoundingRule = 2;
|
|
2562
|
+
}
|
|
2563
|
+
if (lineDiscount.priceOverrideReasonCode && lineDiscount.priceOverrideReasonName) {
|
|
2564
|
+
//price override
|
|
2565
|
+
obj['PriceOverride'] = {};
|
|
2566
|
+
obj['PriceOverride'].ModifierValue = this.removeDecimal(lineDiscount.discountAmount) * -1;
|
|
2567
|
+
obj['PriceOverride'].ModifierDateTime = obj.DateTimeCreated;
|
|
2568
|
+
obj['PriceOverride'].ModifierReasonID = lineDiscount.priceOverrideReasonCode;
|
|
2569
|
+
obj['PriceOverride'].ModifierReasonDescription = lineDiscount.priceOverrideReasonName;
|
|
2570
|
+
obj['PriceOverride'].AuthorisingUserID = this.transactionDocument.userName;
|
|
2571
|
+
obj['PriceOverride'].XMLSchemaVersion = this.xmlSchemaVersion;
|
|
2572
|
+
obj['PriceOverride'].NewPrice = this.removeDecimal(lineDiscount.unitPrice);
|
|
2573
|
+
obj['PriceOverride'].OriginalPrice = this.removeDecimal(lineDiscount.discountedLinePrice || 0 + lineDiscount.discountAmount);
|
|
2574
|
+
}
|
|
2575
|
+
//update the product price
|
|
2576
|
+
obj['NetValue'] = ((lineDiscount.discountedLinePrice || 0) + lineDiscount.discountAmount);
|
|
2577
|
+
obj['EffectiveNetValue'] = ((lineDiscount.discountedLinePrice || 0) + lineDiscount.discountAmount);
|
|
2578
|
+
obj['ExtendedValue'] = ((lineDiscount.discountedLinePrice || 0) + lineDiscount.discountAmount);
|
|
2579
|
+
obj['UnitPrice'] = ((lineDiscount.discountedLinePrice || 0) + lineDiscount.discountAmount);
|
|
2580
|
+
}
|
|
2581
|
+
if (transactionDiscount) {
|
|
2582
|
+
obj['BasketDiscountModifier'] = [];
|
|
2583
|
+
this.transactionDocument.basket.transactionDiscount.forEach((e) => {
|
|
2584
|
+
let discountObj = {};
|
|
2585
|
+
e.itemLineIds.forEach((itemLineId) => {
|
|
2586
|
+
if (itemLineId == element.itemLineId) {
|
|
2587
|
+
let discountAmount = this.convertToString(e.discountAmount * -1);
|
|
2588
|
+
discountObj.XMLSchemaVersion = this.xmlSchemaVersion;
|
|
2589
|
+
discountObj.DiscountedValue = -(this.getDiscountedValue(element.totalLinePrice, e.discountAmount));
|
|
2590
|
+
discountObj.BasketDiscountLineNumber = this.getLineNumber(e, discountAmount);
|
|
2591
|
+
obj['BasketDiscountModifier'].push(discountObj);
|
|
2592
|
+
}
|
|
2593
|
+
});
|
|
2594
|
+
});
|
|
2595
|
+
let totaltransactionDiscount = 0;
|
|
2596
|
+
obj['BasketDiscountModifier'].forEach((value) => {
|
|
2597
|
+
totaltransactionDiscount = totaltransactionDiscount + value.DiscountedValue;
|
|
2598
|
+
});
|
|
2599
|
+
//update the product price
|
|
2600
|
+
obj['EffectiveNetValue'] = obj.EffectiveNetValue + totaltransactionDiscount;
|
|
2601
|
+
}
|
|
2602
|
+
if (this.transactionDocument.basket.transactionPromotion.length > 0 || this.transactionDocument.basket.linePromotion.length > 0) {
|
|
2603
|
+
obj['DistributedPromotionSaving'] = [];
|
|
2604
|
+
if (this.transactionDocument.basket.transactionPromotion.length > 0) {
|
|
2605
|
+
this.transactionDocument.basket.transactionPromotion.forEach((e) => {
|
|
2606
|
+
let promotionObj = {};
|
|
2607
|
+
e.itemLineIds.forEach((itemLineId) => {
|
|
2608
|
+
if (itemLineId == element.itemLineId) {
|
|
2609
|
+
promotionObj.PromotionID = e.promotionId;
|
|
2610
|
+
promotionObj.Hit = '1';
|
|
2611
|
+
promotionObj.Saving = this.getSaving(element.totalLinePrice, e.promotionAmount);
|
|
2612
|
+
promotionObj.ISaving = this.getSaving(element.totalLinePrice, e.promotionAmount);
|
|
2613
|
+
obj['DistributedPromotionSaving'].push(promotionObj);
|
|
2614
|
+
}
|
|
2615
|
+
});
|
|
2616
|
+
});
|
|
2617
|
+
}
|
|
2618
|
+
if (this.transactionDocument.basket.linePromotion.length > 0) {
|
|
2619
|
+
this.transactionDocument.basket.linePromotion.forEach((linePromotion) => {
|
|
2620
|
+
let promotionObj = {};
|
|
2621
|
+
if (element.itemLineId == linePromotion.itemLineId) {
|
|
2622
|
+
promotionObj.PromotionID = linePromotion.promotionId;
|
|
2623
|
+
promotionObj.Hit = "1";
|
|
2624
|
+
promotionObj.Saving = linePromotion.promotionLinePrice;
|
|
2625
|
+
promotionObj.ISaving = linePromotion.promotionLinePrice;
|
|
2626
|
+
obj['DistributedPromotionSaving'].push(promotionObj);
|
|
2627
|
+
}
|
|
2628
|
+
});
|
|
2629
|
+
}
|
|
2630
|
+
let transactionPromotion = 0;
|
|
2631
|
+
obj['DistributedPromotionSaving'].forEach((value) => {
|
|
2632
|
+
transactionPromotion = transactionPromotion + value.Saving;
|
|
2633
|
+
});
|
|
2634
|
+
obj['EffectiveNetValue'] = obj.EffectiveNetValue + transactionPromotion;
|
|
2635
|
+
}
|
|
2636
|
+
return obj;
|
|
2637
|
+
}
|
|
2638
|
+
getSaving(price, promotionAmount) {
|
|
2639
|
+
let Saving = (price * promotionAmount) / this.transactionDocument.basketSummary.saleTotal;
|
|
2640
|
+
return Saving;
|
|
2641
|
+
}
|
|
2642
|
+
getLineNumber(value, discountAmount) {
|
|
2643
|
+
let lineNumber;
|
|
2644
|
+
for (let i = 0; i < this.rjObject['BasketDiscount'].length; i++) {
|
|
2645
|
+
const element = this.rjObject['BasketDiscount'][i];
|
|
2646
|
+
if (value.reasonCode === element.ReasonCodeID && discountAmount === element.NetValue) {
|
|
2647
|
+
lineNumber = element.LineNumber;
|
|
2648
|
+
break;
|
|
2649
|
+
}
|
|
2650
|
+
}
|
|
2651
|
+
return lineNumber;
|
|
2652
|
+
}
|
|
2653
|
+
getDiscountedValue(price, discountAmount) {
|
|
2654
|
+
let DiscountedValue = ((price * discountAmount) / this.transactionDocument.basketSummary.saleTotal) * 100;
|
|
2655
|
+
return DiscountedValue;
|
|
2656
|
+
}
|
|
2657
|
+
getOriginalTax(element, VAT) {
|
|
2658
|
+
let pricebeforetax = (element.price * 100) / (100 + VAT);
|
|
2659
|
+
let originaltax = element.price - pricebeforetax;
|
|
2660
|
+
return originaltax;
|
|
2661
|
+
}
|
|
2662
|
+
convertToString(value) {
|
|
2663
|
+
try {
|
|
2664
|
+
value = JSON.stringify(value);
|
|
2665
|
+
return value;
|
|
2666
|
+
}
|
|
2667
|
+
catch (e) {
|
|
2668
|
+
console.log(value, 'can not be converted in string', e);
|
|
2669
|
+
}
|
|
2670
|
+
}
|
|
2671
|
+
generateDynamicStockLookUp() {
|
|
2672
|
+
let x = '0';
|
|
2673
|
+
this.transactionDocument.basket.products.forEach((element) => {
|
|
2674
|
+
if (element.deliveryMethod === '1' || element.deliveryMethod === '2') {
|
|
2675
|
+
x = '1';
|
|
2676
|
+
}
|
|
2677
|
+
});
|
|
2678
|
+
return x;
|
|
2679
|
+
}
|
|
2680
|
+
// getAttributes(){
|
|
2681
|
+
// let name: string | any[] = []
|
|
2682
|
+
// this.transactionDocument.basket.products.forEach((element: any) => {
|
|
2683
|
+
// if (element && element.attributes && element.attributes.length > 0) {
|
|
2684
|
+
// name = element.attributes.filter((x: any) => x.name.toUpperCase() === element.name.toUpperCase());
|
|
2685
|
+
// }
|
|
2686
|
+
// });
|
|
2687
|
+
// if (name.length > 0) {
|
|
2688
|
+
// return name[0].value
|
|
2689
|
+
// }
|
|
2690
|
+
// else{
|
|
2691
|
+
// return ""
|
|
2692
|
+
// }
|
|
2693
|
+
// }
|
|
2694
|
+
// getCaregories(element) {
|
|
2695
|
+
// let MMGroupId = " ";
|
|
2696
|
+
// if (element.categories && element.categories.length > 0) {
|
|
2697
|
+
// let categories = element.categories.filter((x) => x.parentId != '');
|
|
2698
|
+
// let value = categories.filter((x) => x.id != x.parentId);
|
|
2699
|
+
// MMGroupId = value[0].name;
|
|
2700
|
+
// }
|
|
2701
|
+
// return MMGroupId;
|
|
2702
|
+
// }
|
|
2703
|
+
getDate(date) {
|
|
2704
|
+
let offset = this.generateTimezoneoffset(date) * -1;
|
|
2705
|
+
let offsetHours = Math.abs(Math.floor(offset / 60));
|
|
2706
|
+
let offsetMinutes = Math.abs(offset) - offsetHours * 60;
|
|
2707
|
+
let offsetSign = '+';
|
|
2708
|
+
if (offset < 0) {
|
|
2709
|
+
offsetSign = '-';
|
|
2710
|
+
}
|
|
2711
|
+
let newdate = date.substring(0, 19);
|
|
2712
|
+
const x = (newdate + offsetSign + String(offsetHours).padStart(2, '0') + ':' + String(offsetMinutes).padStart(2, '0')).toString();
|
|
2713
|
+
return x;
|
|
2714
|
+
}
|
|
2715
|
+
getTransactionPromotion(transactionPromotion) {
|
|
2716
|
+
if (transactionPromotion && transactionPromotion.length > 0) {
|
|
2717
|
+
this.rjObject['PromoVoucherItem'] = {};
|
|
2718
|
+
this.rjObject['PromoVoucherItem']['XMLSchemaVersion'] = this.xmlSchemaVersion;
|
|
2719
|
+
this.rjObject['PromoVoucherItem']['LineNumber'] = this.generateLineNumber();
|
|
2720
|
+
this.rjObject['PromoVoucherItem']['NetValue'] = this.removeDecimal(transactionPromotion[0].promotionLinePrice) * -1;
|
|
2721
|
+
this.rjObject['PromoVoucherItem']['EffectiveNetValue'] = this.removeDecimal(transactionPromotion[0].promotionLinePrice) * -1;
|
|
2722
|
+
this.rjObject['PromoVoucherItem']['Description'] = transactionPromotion[0].promotionInfo;
|
|
2723
|
+
this.rjObject['PromoVoucherItem']['DeviceID'] = this.deviceId;
|
|
2724
|
+
this.rjObject['PromoVoucherItem']['UserID'] = this.transactionDocument.userName;
|
|
2725
|
+
this.rjObject['PromoVoucherItem']['DateTimeCreated'] = this.createdAt;
|
|
2726
|
+
this.rjObject['PromoVoucherItem']['ProductId'] = ""; //todo
|
|
2727
|
+
this.rjObject['PromoVoucherItem']['SerialNumber'] = ""; //todo
|
|
2728
|
+
this.rjObject['PromoVoucherItem']['MMGroupId'] = "";
|
|
2729
|
+
}
|
|
2730
|
+
}
|
|
2731
|
+
getQuantity(element) {
|
|
2732
|
+
let quantity;
|
|
2733
|
+
if (this.transactionDocument.unreferencedRefund) {
|
|
2734
|
+
quantity = element['quantity'] < 0 ? element['quantity'] : (-element['quantity']);
|
|
2735
|
+
}
|
|
2736
|
+
else {
|
|
2737
|
+
quantity = element['refundedQuantity'] < 0 ? element['refundedQuantity'] : (-element['refundedQuantity']);
|
|
2738
|
+
}
|
|
2739
|
+
return quantity;
|
|
2740
|
+
}
|
|
2741
|
+
}
|
|
2742
|
+
|
|
2743
|
+
class WebReturnMapperBuilderClass {
|
|
2744
|
+
constructor(document, currencyPipe) {
|
|
2745
|
+
this.currencyPipe = currencyPipe;
|
|
2746
|
+
this.webReturnObject = {
|
|
2747
|
+
id: '',
|
|
2748
|
+
orgCode: "",
|
|
2749
|
+
storeId: "",
|
|
2750
|
+
storeNodeId: "",
|
|
2751
|
+
storeNodeStructure: "",
|
|
2752
|
+
deviceId: "",
|
|
2753
|
+
terminalId: "",
|
|
2754
|
+
initiatingModule: "",
|
|
2755
|
+
export: false,
|
|
2756
|
+
isInStoreOrder: false,
|
|
2757
|
+
basket: {},
|
|
2758
|
+
basketSummary: {},
|
|
2759
|
+
baseCurrency: "",
|
|
2760
|
+
customer: {
|
|
2761
|
+
firstName: '',
|
|
2762
|
+
lastName: '',
|
|
2763
|
+
email: '',
|
|
2764
|
+
postCode: '',
|
|
2765
|
+
id: '',
|
|
2766
|
+
billingAddress: {},
|
|
2767
|
+
shippingAddress: {},
|
|
2768
|
+
},
|
|
2769
|
+
currentTransactionDetails: {}
|
|
2770
|
+
};
|
|
2771
|
+
if (document) {
|
|
2772
|
+
this.document = document;
|
|
2773
|
+
}
|
|
2774
|
+
this.numberUtilService = new NumberUtilService(currencyPipe);
|
|
2775
|
+
}
|
|
2776
|
+
WebReturnMapper() {
|
|
2777
|
+
this.webReturnObject['type'] = 'WEB_RETURNS';
|
|
2778
|
+
this.webReturnObject['datetime'] = this.getUTCDateTime(this.getText(this.document.updated_at));
|
|
2779
|
+
this.webReturnObject.baseCurrency = this.getText(this.document.base_currency_code);
|
|
2780
|
+
this.webReturnObject.storeId = this.getText(this.document.store_id);
|
|
2781
|
+
this.webReturnObject.subsidiaryId = '1';
|
|
2782
|
+
this.webReturnObject.initiatingModule = 'MAGENTO';
|
|
2783
|
+
this.webReturnObject.createdAt = this.getUTCDateTime(this.getText(this.document.created_at));
|
|
2784
|
+
this.webReturnObject.updatedAt = this.getUTCDateTime(this.getText(this.document.updated_at));
|
|
2785
|
+
this.webReturnObject.export = true;
|
|
2786
|
+
this.webReturnObject.transCompletedAt = this.getUTCDateTime(this.getText(this.document.updated_at));
|
|
2787
|
+
this.webReturnObject['externalTransactionId'] = this.getText(this.document.order_id);
|
|
2788
|
+
// customer
|
|
2789
|
+
this.webReturnObject['customer']['firstName'] = this.getText(this.document.customer_firstname) || '';
|
|
2790
|
+
this.webReturnObject['customer']['lastName'] = this.getText(this.document.customer_lastname) || '';
|
|
2791
|
+
this.webReturnObject['customer']['email'] = this.getText(this.document.customer_email) || '';
|
|
2792
|
+
this.webReturnObject['customer']['postCode'] = '';
|
|
2793
|
+
// Billing address
|
|
2794
|
+
this.webReturnObject['customer']['billingAddress']['address1'] = (this.document.billing_address && this.document.billing_address.street) ? this.getText(this.document.billing_address.street) : '';
|
|
2795
|
+
this.webReturnObject['customer']['billingAddress']['city'] = (this.document.billing_address && this.document.billing_address.city) ? this.getText(this.document.billing_address.city) : '';
|
|
2796
|
+
this.webReturnObject['customer']['billingAddress']['county'] = (this.document.billing_address && this.document.billing_address.region) ? this.getText(this.document.billing_address.region) : '';
|
|
2797
|
+
this.webReturnObject['customer']['billingAddress']['postCode'] = (this.document.billing_address && this.document.billing_address.postcode) ? this.getText(this.document.billing_address.postcode) : '';
|
|
2798
|
+
this.webReturnObject['customer']['billingAddress']['country'] = (this.document.billing_address && this.document.billing_address.country) ? this.getText(this.document.billing_address.country) : '';
|
|
2799
|
+
// Shipping address
|
|
2800
|
+
this.webReturnObject['customer']['shippingAddress']['address1'] = (this.document.shipping_address && this.document.shipping_address.street) ? this.getText(this.document.shipping_address.street) : '';
|
|
2801
|
+
this.webReturnObject['customer']['shippingAddress']['city'] = (this.document.shipping_address && this.document.shipping_address.city) ? this.getText(this.document.shipping_address.city) : '';
|
|
2802
|
+
this.webReturnObject['customer']['shippingAddress']['county'] = (this.document.shipping_address && this.document.shipping_address.region) ? this.getText(this.document.shipping_address.region) : '';
|
|
2803
|
+
this.webReturnObject['customer']['shippingAddress']['postCode'] = (this.document.shipping_address && this.document.shipping_address.postcode) ? this.getText(this.document.shipping_address.postcode) : '';
|
|
2804
|
+
this.webReturnObject['customer']['shippingAddress']['country'] = (this.document.shipping_address && this.document.shipping_address.country) ? this.getText(this.document.shipping_address.country) : '';
|
|
2805
|
+
// basketSummary
|
|
2806
|
+
this.webReturnObject.basketSummary['discountTotal'] = Math.abs(Number(this.document.discount_amount ? this.getText(this.document.discount_amount) : 0));
|
|
2807
|
+
this.webReturnObject.basketSummary['VATTotal'] = Number(this.document.base_total_paid ? this.getText(this.document.base_total_paid) : 0);
|
|
2808
|
+
this.webReturnObject.basketSummary['saleTotal'] = Number(this.document.base_total_invoiced ? this.getText(this.document.base_total_invoiced) : 0);
|
|
2809
|
+
this.webReturnObject.basketSummary['basketTotal'] = Number(this.document.base_total_paid ? this.getText(this.document.base_total_paid) : 0);
|
|
2810
|
+
this.webReturnObject.basketSummary['totalItems'] = Number(this.document.total_qty_ordered ? this.getText(this.document.total_qty_ordered) : 0);
|
|
2811
|
+
this.webReturnObject.basketSummary['refundTotal'] = Number(this.document.base_total_refunded ? this.getText(this.document.base_total_refunded) : 0);
|
|
2812
|
+
// // basket line discount
|
|
2813
|
+
// this.webReturnObject.basket['lineDiscount'] = [];
|
|
2814
|
+
// let lineDiscount = {
|
|
2815
|
+
// itemLineId: (this.document.items && this.document.items.item && this.document.items.item.item_id) ? this.getText(this.document.items.item.item_id) : 0,
|
|
2816
|
+
// discountAmount: (this.document.items && this.document.items.item && this.document.items.item.discount_amount) ? Number(this.getText(this.document.items.item.discount_amount)) : 0
|
|
2817
|
+
// }
|
|
2818
|
+
// this.webReturnObject.basket['lineDiscount'].push(lineDiscount);
|
|
2819
|
+
// basket transaction discount
|
|
2820
|
+
// basket products
|
|
2821
|
+
this.webReturnObject.basket['products'] = [];
|
|
2822
|
+
this.webReturnObject.basket['linePromotion'] = [];
|
|
2823
|
+
this.webReturnObject.basket['transactionDiscount'] = [];
|
|
2824
|
+
this.webReturnObject.basket['transactionPromotion'] = [];
|
|
2825
|
+
// let transactionDiscount = {
|
|
2826
|
+
// discountAmount: (this.document && this.document.discount_amount) ? Number(this.getText(this.document.discount_amount)) : 0
|
|
2827
|
+
// }
|
|
2828
|
+
// this.webReturnObject.basket['transactionDiscount'].push(transactionDiscount);
|
|
2829
|
+
let product = {};
|
|
2830
|
+
if (this.document.items && this.document.items.item) {
|
|
2831
|
+
if (this.document.items.item instanceof Array) {
|
|
2832
|
+
this.document.items.item.forEach((element, index) => {
|
|
2833
|
+
let qty = this.getText(element.qty_ordered) ? Number(this.getText(element.qty_ordered)) : 0;
|
|
2834
|
+
let refundQty = this.getText(element.qty_refunded) ? Number(this.getText(element.qty_refunded)) : 0;
|
|
2835
|
+
let price = this.getText(element.price_incl_tax) ? Number(this.getText(element.price_incl_tax)) : 0;
|
|
2836
|
+
product = {
|
|
2837
|
+
description: (element.name) ? this.getText(element.name) : '',
|
|
2838
|
+
SKU: (element.sku) ? this.getText(element.sku) : '',
|
|
2839
|
+
quantity: (element.qty_ordered) ? Number(this.getText(element.qty_ordered)) : 0,
|
|
2840
|
+
refundedQuantity: (element.qty_refunded) ? Number(this.getText(element.qty_refunded)) : 0,
|
|
2841
|
+
//price: (element.original_price) ? Number(this.getText(element.original_price)) : 0,
|
|
2842
|
+
price: price,
|
|
2843
|
+
itemLineId: (index + 1).toString(),
|
|
2844
|
+
// totalLinePrice: (element.row_invoiced) ? Number(this.getText(element.row_invoiced)) : 0,
|
|
2845
|
+
totalLinePrice: ((qty - refundQty) * price),
|
|
2846
|
+
};
|
|
2847
|
+
let promotionAmount = this.getText(element.discount_amount) ? Number(this.getText(element.discount_amount)) : 0;
|
|
2848
|
+
let appliedIDs = this.getText(element.applied_rule_ids) ? this.getText(element.applied_rule_ids) : '';
|
|
2849
|
+
if (product && product.price != 0) {
|
|
2850
|
+
if (promotionAmount) {
|
|
2851
|
+
let trigger = {};
|
|
2852
|
+
trigger.itemLineId = product.itemLineId;
|
|
2853
|
+
trigger.quantity = product.quantity ? product.quantity : 0;
|
|
2854
|
+
let promotion = {
|
|
2855
|
+
promotionAmount: promotionAmount,
|
|
2856
|
+
promotionId: appliedIDs,
|
|
2857
|
+
itemLineId: product.itemLineId,
|
|
2858
|
+
promotionLinePrice: product.totalLinePrice - promotionAmount,
|
|
2859
|
+
trigger: trigger
|
|
2860
|
+
};
|
|
2861
|
+
this.webReturnObject.basket['linePromotion'].push(promotion);
|
|
2862
|
+
}
|
|
2863
|
+
this.webReturnObject.basket['products'].push(product);
|
|
2864
|
+
}
|
|
2865
|
+
});
|
|
2866
|
+
}
|
|
2867
|
+
else {
|
|
2868
|
+
let qty = (this.document.items && this.document.items.item && this.document.items.item.qty_ordered) ? Number(this.getText(this.document.items.item.qty_ordered)) : 0;
|
|
2869
|
+
let refundQty = (this.document.items && this.document.items.item && this.document.items.item.qty_refunded) ? Number(this.getText(this.document.items.item.qty_refunded)) : 0;
|
|
2870
|
+
let price = (this.document.items && this.document.items.item && this.document.items.item.price_incl_tax) ? Number(this.getText(this.document.items.item.price_incl_tax)) : 0;
|
|
2871
|
+
product = {
|
|
2872
|
+
description: (this.document.items && this.document.items.item && this.document.items.item.name) ? this.getText(this.document.items.item.name) : '',
|
|
2873
|
+
SKU: (this.document.items && this.document.items.item && this.document.items.item.sku) ? this.getText(this.document.items.item.sku) : '',
|
|
2874
|
+
quantity: (this.document.items && this.document.items.item && this.document.items.item.qty_ordered) ? Number(this.getText(this.document.items.item.qty_ordered)) : 0,
|
|
2875
|
+
refundedQuantity: (this.document.items && this.document.items.item && this.document.items.item.qty_refunded) ? Number(this.getText(this.document.items.item.qty_refunded)) : 0,
|
|
2876
|
+
// price: (this.document.items && this.document.items.item && this.document.items.item.original_price) ? Number(this.getText(this.document.items.item.original_price)) : 0,
|
|
2877
|
+
price: price,
|
|
2878
|
+
itemLineId: "1",
|
|
2879
|
+
// totalLinePrice: (this.document.items && this.document.items.item && this.document.items.item.row_invoiced) ? Number(this.getText(this.document.items.item.row_invoiced)) : 0,
|
|
2880
|
+
totalLinePrice: ((qty - refundQty) * price),
|
|
2881
|
+
};
|
|
2882
|
+
let promotionAmount = this.getText(this.document.items.item.discount_amount) ? Number(this.getText(this.document.items.item.discount_amount)) : 0;
|
|
2883
|
+
let appliedIDs = this.getText(this.document.items.item.applied_rule_ids) ? this.getText(this.document.items.item.applied_rule_ids) : '';
|
|
2884
|
+
if (product && product.price != 0) {
|
|
2885
|
+
if (promotionAmount) {
|
|
2886
|
+
let trigger = {};
|
|
2887
|
+
trigger.itemLineId = product.itemLineId;
|
|
2888
|
+
trigger.quantity = product.quantity ? product.quantity : 0;
|
|
2889
|
+
let promotion = {
|
|
2890
|
+
promotionAmount: promotionAmount,
|
|
2891
|
+
promotionId: appliedIDs,
|
|
2892
|
+
itemLineId: product.itemLineId,
|
|
2893
|
+
promotionLinePrice: product.totalLinePrice - promotionAmount,
|
|
2894
|
+
trigger: trigger
|
|
2895
|
+
};
|
|
2896
|
+
this.webReturnObject.basket['linePromotion'].push(promotion);
|
|
2897
|
+
}
|
|
2898
|
+
this.webReturnObject.basket['products'].push(product);
|
|
2899
|
+
}
|
|
2900
|
+
}
|
|
2901
|
+
let couponCode = this.getText(this.document.coupon_code) ? this.getText(this.document.coupon_code) : 0;
|
|
2902
|
+
let appliedIDs = this.getText(this.document.applied_rule_ids) ? this.getText(this.document.applied_rule_ids) : '';
|
|
2903
|
+
let discountDescription = this.getText(this.document.discount_description) ? this.getText(this.document.discount_description) : '';
|
|
2904
|
+
let couponTriggerPromotions = [];
|
|
2905
|
+
if (couponCode && appliedIDs) {
|
|
2906
|
+
let transactionPromotion = {};
|
|
2907
|
+
if (this.webReturnObject.basket['linePromotion'] && this.webReturnObject.basket['linePromotion'].length > 0) {
|
|
2908
|
+
this.webReturnObject.basket['linePromotion'].forEach((promotion) => {
|
|
2909
|
+
if (promotion.promotionId === appliedIDs) {
|
|
2910
|
+
let trigger = {};
|
|
2911
|
+
trigger.itemLineId = promotion.itemLineId;
|
|
2912
|
+
trigger.quantity = promotion.trigger.quantity;
|
|
2913
|
+
trigger.totalQuantity = promotion.trigger.quantity;
|
|
2914
|
+
trigger.promotionAmount = promotion.promotionAmount;
|
|
2915
|
+
trigger.refundedReason = couponCode;
|
|
2916
|
+
trigger.refundedReasonDescription = discountDescription;
|
|
2917
|
+
trigger.promotionId = promotion.promotionId;
|
|
2918
|
+
couponTriggerPromotions.push(trigger);
|
|
2919
|
+
this.webReturnObject.basket['linePromotion'] = this.webReturnObject.basket['linePromotion'].filter((x) => x.itemLineId !== promotion.itemLineId);
|
|
2920
|
+
}
|
|
2921
|
+
});
|
|
2922
|
+
}
|
|
2923
|
+
if (couponTriggerPromotions.length > 0) {
|
|
2924
|
+
transactionPromotion.displayText = couponTriggerPromotions[0].refundedReasonDescription;
|
|
2925
|
+
transactionPromotion.name = couponTriggerPromotions[0].refundedReason;
|
|
2926
|
+
transactionPromotion.promotionAmount = -(couponTriggerPromotions.reduce((n, { promotionAmount }) => n + promotionAmount, 0));
|
|
2927
|
+
transactionPromotion.promotionId = couponTriggerPromotions[0].promotionId;
|
|
2928
|
+
transactionPromotion.promotionInfo = couponTriggerPromotions[0].refundedReasonDescription;
|
|
2929
|
+
transactionPromotion.couponCode = couponCode;
|
|
2930
|
+
transactionPromotion.itemLineIds = [];
|
|
2931
|
+
transactionPromotion.type = PROMOTION_TYPE.COUPON;
|
|
2932
|
+
transactionPromotion.subLevelType = PROMOTION_LEVEL.LINE;
|
|
2933
|
+
transactionPromotion.trigger = couponTriggerPromotions;
|
|
2934
|
+
}
|
|
2935
|
+
console.log("e-basket: update LinePromotion With Coupon", JSON.stringify(transactionPromotion));
|
|
2936
|
+
if (!this.webReturnObject.basket.transactionPromotion) {
|
|
2937
|
+
this.webReturnObject.basket.transactionPromotion = [];
|
|
2938
|
+
}
|
|
2939
|
+
if (transactionPromotion && transactionPromotion.promotionId) {
|
|
2940
|
+
this.webReturnObject.basket.transactionPromotion.push(transactionPromotion);
|
|
2941
|
+
}
|
|
2942
|
+
}
|
|
2943
|
+
this.updateTransactionPromotionPrtionCalc();
|
|
2944
|
+
}
|
|
2945
|
+
return this;
|
|
2946
|
+
}
|
|
2947
|
+
validateProductItemDiscount(product) {
|
|
2948
|
+
if (!product.itemDiscounts) {
|
|
2949
|
+
product.itemDiscounts = {
|
|
2950
|
+
trnDiscountsPortion: 0,
|
|
2951
|
+
trnPromotionsPortion: 0,
|
|
2952
|
+
refundPortion: 0,
|
|
2953
|
+
};
|
|
2954
|
+
}
|
|
2955
|
+
return product;
|
|
2956
|
+
}
|
|
2957
|
+
transactionPromotionProductPortionCalc(txDoc, promotion) {
|
|
2958
|
+
console.log(`ebasket: transactionPromotionProductPortionCalc: trnsactionPromotion: ${JSON.stringify(promotion)}`);
|
|
2959
|
+
if (promotion.type === PROMOTION_TYPE.COUPON && promotion.subLevelType === PROMOTION_LEVEL.LINE) {
|
|
2960
|
+
txDoc.basket.products.forEach((product) => {
|
|
2961
|
+
product = this.validateProductItemDiscount(product);
|
|
2962
|
+
if (promotion.trigger && promotion.trigger.length > 0) {
|
|
2963
|
+
promotion.trigger.forEach((t) => {
|
|
2964
|
+
if (t.itemLineId === product.itemLineId.toString()) {
|
|
2965
|
+
product.itemDiscounts.trnPromotionsPortion += t.promotionAmount;
|
|
2966
|
+
}
|
|
2967
|
+
});
|
|
2968
|
+
}
|
|
2969
|
+
});
|
|
2970
|
+
}
|
|
2971
|
+
else {
|
|
2972
|
+
txDoc.basket.products.forEach((product) => {
|
|
2973
|
+
product = this.validateProductItemDiscount(product);
|
|
2974
|
+
if (promotion.itemLineIds.includes(+product.itemLineId)) {
|
|
2975
|
+
let discountAmount = 0;
|
|
2976
|
+
if (this.document.items.item instanceof Array) {
|
|
2977
|
+
const productItem = this.document.items.item.find(productItem => productItem.sku === product.SKU);
|
|
2978
|
+
discountAmount = productItem.discount_amount ? +productItem.discount_amount : 0;
|
|
2979
|
+
}
|
|
2980
|
+
else {
|
|
2981
|
+
discountAmount = this.document.items.item.sku === product.SKU && this.document.items.item.discount_amount ?
|
|
2982
|
+
+this.document.items.item.discount_amount : 0;
|
|
2983
|
+
}
|
|
2984
|
+
const transactionPromotionPortion = discountAmount;
|
|
2985
|
+
product.itemDiscounts.trnPromotionsPortion += this.numberUtilService.trimTo2Decimal2(transactionPromotionPortion);
|
|
2986
|
+
}
|
|
2987
|
+
});
|
|
2988
|
+
}
|
|
2989
|
+
return txDoc;
|
|
2990
|
+
}
|
|
2991
|
+
updateTransactionPromotionPrtionCalc() {
|
|
2992
|
+
try {
|
|
2993
|
+
if (this.webReturnObject.basket.transactionPromotion && this.webReturnObject.basket.transactionPromotion.length > 0) {
|
|
2994
|
+
this.webReturnObject.basket.transactionPromotion.forEach(tr => {
|
|
2995
|
+
this.transactionPromotionProductPortionCalc(this.webReturnObject, tr);
|
|
2996
|
+
});
|
|
2997
|
+
}
|
|
2998
|
+
}
|
|
2999
|
+
catch (error) {
|
|
3000
|
+
console.log("updateTransactionPromotionPrtionCalc => failed:", JSON.stringify(error));
|
|
3001
|
+
}
|
|
3002
|
+
}
|
|
3003
|
+
deviceId(deviceId) {
|
|
3004
|
+
this.webReturnObject.deviceId = deviceId;
|
|
3005
|
+
return this;
|
|
3006
|
+
}
|
|
3007
|
+
terminalId(terminalId) {
|
|
3008
|
+
this.webReturnObject.terminalId = terminalId;
|
|
3009
|
+
return this;
|
|
3010
|
+
}
|
|
3011
|
+
orgCode(orgCode) {
|
|
3012
|
+
this.webReturnObject.orgCode = orgCode;
|
|
3013
|
+
return this;
|
|
3014
|
+
}
|
|
3015
|
+
storeId(storeId) {
|
|
3016
|
+
this.webReturnObject.storeId = storeId;
|
|
3017
|
+
return this;
|
|
3018
|
+
}
|
|
3019
|
+
storeNodeId(storeNodeId) {
|
|
3020
|
+
this.webReturnObject.storeNodeId = storeNodeId;
|
|
3021
|
+
return this;
|
|
3022
|
+
}
|
|
3023
|
+
storeNodeStructure(storeNodeStructure) {
|
|
3024
|
+
this.webReturnObject.storeNodeStructure = storeNodeStructure;
|
|
3025
|
+
return this;
|
|
3026
|
+
}
|
|
3027
|
+
docId(docId) {
|
|
3028
|
+
this.webReturnObject.id = docId;
|
|
3029
|
+
return this;
|
|
3030
|
+
}
|
|
3031
|
+
updateUserID(userID) {
|
|
3032
|
+
this.webReturnObject.userId = userID;
|
|
3033
|
+
return this;
|
|
3034
|
+
}
|
|
3035
|
+
updateUserName(name) {
|
|
3036
|
+
this.webReturnObject.userName = name;
|
|
3037
|
+
return this;
|
|
3038
|
+
}
|
|
3039
|
+
build() {
|
|
3040
|
+
return this.webReturnObject;
|
|
3041
|
+
}
|
|
3042
|
+
getText(obj) {
|
|
3043
|
+
if (obj && obj.text) {
|
|
3044
|
+
return obj.text;
|
|
3045
|
+
}
|
|
3046
|
+
else {
|
|
3047
|
+
return obj;
|
|
3048
|
+
}
|
|
3049
|
+
}
|
|
3050
|
+
getUTCDateTime(date) {
|
|
3051
|
+
if (date) {
|
|
3052
|
+
return new Date(date).toISOString();
|
|
3053
|
+
}
|
|
3054
|
+
}
|
|
3055
|
+
isInStoreOrder() {
|
|
3056
|
+
console.log("Mapper library: WebReturnMapperBuilderClass: isInStoreOrder mapping started...");
|
|
3057
|
+
if (this.document.payment && this.document.payment.method && this.document.payment.method === 'pos_order') {
|
|
3058
|
+
this.webReturnObject.isInStoreOrder = true;
|
|
3059
|
+
}
|
|
3060
|
+
console.log("Mapper library: WebReturnMapperBuilderClass: isInStoreOrder mapping ended...");
|
|
3061
|
+
return this;
|
|
3062
|
+
}
|
|
3063
|
+
}
|
|
3064
|
+
|
|
3065
|
+
class WebReturnSalesforceMapperBuilderClass {
|
|
3066
|
+
constructor(orderDetails, currencyPipe) {
|
|
3067
|
+
this.currencyPipe = currencyPipe;
|
|
3068
|
+
this.webReturnObject = {
|
|
3069
|
+
id: '',
|
|
3070
|
+
orgCode: "",
|
|
3071
|
+
storeId: "",
|
|
3072
|
+
storeNodeId: "",
|
|
3073
|
+
storeNodeStructure: "",
|
|
3074
|
+
deviceId: "",
|
|
3075
|
+
terminalId: "",
|
|
3076
|
+
initiatingModule: "",
|
|
3077
|
+
export: false,
|
|
3078
|
+
isInStoreOrder: false,
|
|
3079
|
+
basket: {},
|
|
3080
|
+
basketSummary: {},
|
|
3081
|
+
baseCurrency: "",
|
|
3082
|
+
customer: {
|
|
3083
|
+
id: '',
|
|
3084
|
+
email: '',
|
|
3085
|
+
firstName: '',
|
|
3086
|
+
lastName: '',
|
|
3087
|
+
billingAddress: [],
|
|
3088
|
+
shippingAddress: [],
|
|
3089
|
+
shipmentDetails: [],
|
|
3090
|
+
telephone: '',
|
|
3091
|
+
postCode: '',
|
|
3092
|
+
noCustomerSelected: false
|
|
3093
|
+
},
|
|
3094
|
+
currentTransactionDetails: {}
|
|
3095
|
+
};
|
|
3096
|
+
if (orderDetails) {
|
|
3097
|
+
this.orderDetails = orderDetails;
|
|
3098
|
+
}
|
|
3099
|
+
this.numberUtilService = new NumberUtilService(currencyPipe);
|
|
3100
|
+
}
|
|
3101
|
+
webReturnCommonMapper() {
|
|
3102
|
+
console.log("Mapper library: WebReturnSalesforceMapperBuilderClass: webReturnCommonMapper started...");
|
|
3103
|
+
this.webReturnObject['type'] = TRANSACTION_TYPE.WEB_RETURNS;
|
|
3104
|
+
this.webReturnObject['datetime'] = this.getUTCDateTime(this.orderDetails.last_modified);
|
|
3105
|
+
this.webReturnObject.baseCurrency = this.orderDetails.currency;
|
|
3106
|
+
this.webReturnObject.subsidiaryId = '1';
|
|
3107
|
+
this.webReturnObject.export = true;
|
|
3108
|
+
this.webReturnObject.initiatingModule = INITIATING_MODULE.EBASKET;
|
|
3109
|
+
this.webReturnObject.createdAt = this.getUTCDateTime(this.orderDetails.creation_date);
|
|
3110
|
+
this.webReturnObject.updatedAt = this.getUTCDateTime(this.orderDetails.last_modified);
|
|
3111
|
+
this.webReturnObject.transCompletedAt = this.getUTCDateTime(this.orderDetails.last_modified);
|
|
3112
|
+
this.webReturnObject['externalTransactionId'] = this.orderDetails.order_no;
|
|
3113
|
+
console.log("Mapper library: WebReturnSalesforceMapperBuilderClass: webReturnCommonMapper ended...");
|
|
3114
|
+
return this;
|
|
3115
|
+
}
|
|
3116
|
+
// export(status, details) {
|
|
3117
|
+
// console.log("Mapper library: WebReturnSalesforceMapperBuilderClass: export mapping started...");
|
|
3118
|
+
// console.log("Mapper library: WebReturnSalesforceMapperBuilderClass: status:", status);
|
|
3119
|
+
// console.log("Mapper library: WebReturnSalesforceMapperBuilderClass: details:", JSON.stringify(details));
|
|
3120
|
+
// if (status && details && details.providers && details.providers.length > 0) {
|
|
3121
|
+
// details.providers.forEach(
|
|
3122
|
+
// providerObj => {
|
|
3123
|
+
// if (providerObj.provider && providerObj.provider === PROVIDERS.SALESFORCE) {
|
|
3124
|
+
// this.webReturnObject.export = true;
|
|
3125
|
+
// } else {
|
|
3126
|
+
// this.webReturnObject.export = false;
|
|
3127
|
+
// }
|
|
3128
|
+
// }
|
|
3129
|
+
// );
|
|
3130
|
+
// } else {
|
|
3131
|
+
// this.webReturnObject.export = false;
|
|
3132
|
+
// }
|
|
3133
|
+
// console.log("Mapper library: WebReturnSalesforceMapperBuilderClass: export mapping end...")
|
|
3134
|
+
// return this;
|
|
3135
|
+
// }
|
|
3136
|
+
getDeliveryMethod() {
|
|
3137
|
+
if (this.orderDetails.shipments && this.orderDetails.shipments.length > 0) {
|
|
3138
|
+
const shipToStoreShipment = this.orderDetails.shipments.find(shipment => shipment.c_fromStoreId);
|
|
3139
|
+
if (shipToStoreShipment)
|
|
3140
|
+
return DELIVERY_METHODS.SHIP_TO_STORE;
|
|
3141
|
+
else
|
|
3142
|
+
return DELIVERY_METHODS.DELIVERY;
|
|
3143
|
+
}
|
|
3144
|
+
else {
|
|
3145
|
+
return '';
|
|
3146
|
+
}
|
|
3147
|
+
}
|
|
3148
|
+
product() {
|
|
3149
|
+
console.log("Mapper library: WebReturnSalesforceMapperBuilderClass: product mapping started...");
|
|
3150
|
+
this.webReturnObject.basket['products'] = [];
|
|
3151
|
+
if (this.orderDetails.product_items && this.orderDetails.product_items.length > 0) {
|
|
3152
|
+
this.orderDetails.product_items.forEach((product, index) => {
|
|
3153
|
+
const productObj = {
|
|
3154
|
+
description: product.item_text ? product.item_text : '',
|
|
3155
|
+
SKU: product.product_id ? product.product_id : '',
|
|
3156
|
+
quantity: product.quantity ? product.quantity : 0,
|
|
3157
|
+
refundedQuantity: 0,
|
|
3158
|
+
price: product.base_price ? product.base_price : 0,
|
|
3159
|
+
itemLineId: (index + 1).toString(),
|
|
3160
|
+
deliveryMethod: this.getDeliveryMethod().toString(),
|
|
3161
|
+
totalLinePrice: product.price ? product.price : 0
|
|
3162
|
+
};
|
|
3163
|
+
if (product && product.price != 0) {
|
|
3164
|
+
this.webReturnObject.basket['products'].push(productObj);
|
|
3165
|
+
}
|
|
3166
|
+
});
|
|
3167
|
+
}
|
|
3168
|
+
console.log("Mapper library: WebReturnSalesforceMapperBuilderClass: product mapping ended...");
|
|
3169
|
+
return this;
|
|
3170
|
+
}
|
|
3171
|
+
linePromotion() {
|
|
3172
|
+
console.log("Mapper library: WebReturnSalesforceMapperBuilderClass: linePromotion mapping started...");
|
|
3173
|
+
this.webReturnObject.basket.linePromotion = [];
|
|
3174
|
+
let linePromotionArray = [];
|
|
3175
|
+
if (this.orderDetails.product_items && this.orderDetails.product_items.length > 0) {
|
|
3176
|
+
this.orderDetails.product_items.forEach((product, index) => {
|
|
3177
|
+
product.item_id = (index + 1).toString();
|
|
3178
|
+
if (product.price_adjustments && product.price_adjustments.length > 0) {
|
|
3179
|
+
product.price_adjustments.forEach((promotion) => {
|
|
3180
|
+
if (!promotion.coupon_code) {
|
|
3181
|
+
let linePromotionObj = {};
|
|
3182
|
+
let trigger = {};
|
|
3183
|
+
trigger.itemLineId = product.item_id;
|
|
3184
|
+
trigger.quantity = product.quantity ? product.quantity : 0;
|
|
3185
|
+
linePromotionObj.trigger = [];
|
|
3186
|
+
linePromotionObj.trigger.push(trigger);
|
|
3187
|
+
linePromotionObj.itemLineId = index + 1;
|
|
3188
|
+
linePromotionObj.promotionId = promotion.promotion_id ? promotion.promotion_id : '';
|
|
3189
|
+
linePromotionObj.displayText = promotion.item_text ? promotion.item_text : '';
|
|
3190
|
+
linePromotionObj.promotionType = promotion.applied_discount && promotion.applied_discount.type ? promotion.applied_discount.type : '';
|
|
3191
|
+
linePromotionObj.promotionAmount = promotion.price ? Math.abs(promotion.price) : 0;
|
|
3192
|
+
linePromotionObj.name = promotion.coupon_code ? promotion.coupon_code : (promotion.item_text ? promotion.item_text : '');
|
|
3193
|
+
linePromotionObj.promotionInfo = promotion.item_text ? promotion.item_text : '';
|
|
3194
|
+
linePromotionObj.promotionLinePrice = product.price - Math.abs(promotion.price);
|
|
3195
|
+
linePromotionArray.push(linePromotionObj);
|
|
3196
|
+
}
|
|
3197
|
+
});
|
|
3198
|
+
}
|
|
3199
|
+
});
|
|
3200
|
+
}
|
|
3201
|
+
this.webReturnObject.basket.linePromotion = linePromotionArray;
|
|
3202
|
+
console.log("Mapper library: WebReturnSalesforceMapperBuilderClass: linePromotion mapping ended...");
|
|
3203
|
+
return this;
|
|
3204
|
+
}
|
|
3205
|
+
transactionPromotion() {
|
|
3206
|
+
console.log("Mapper library: WebReturnSalesforceMapperBuilderClass: transactionPromotion mapping started...");
|
|
3207
|
+
let transactionPromotionArray = this.getTransactionPromotions(this.orderDetails);
|
|
3208
|
+
this.webReturnObject.basket.transactionPromotion = transactionPromotionArray;
|
|
3209
|
+
console.log("Mapper library: WebReturnSalesforceMapperBuilderClass: transactionPromotion mapping ended...");
|
|
3210
|
+
return this;
|
|
3211
|
+
}
|
|
3212
|
+
getTransactionPromotions(basket) {
|
|
3213
|
+
try {
|
|
3214
|
+
let transactionPromotionArray = [];
|
|
3215
|
+
if (basket.order_price_adjustments && basket.order_price_adjustments.length > 0) {
|
|
3216
|
+
basket.order_price_adjustments.forEach((transactionPromotion) => {
|
|
3217
|
+
let transactionPromotionObj = {};
|
|
3218
|
+
transactionPromotionObj.displayText = transactionPromotion.item_text ? transactionPromotion.item_text : '';
|
|
3219
|
+
transactionPromotionObj.name = transactionPromotion.coupon_code ? transactionPromotion.coupon_code : (transactionPromotion.item_text ? transactionPromotion.item_text : '');
|
|
3220
|
+
transactionPromotionObj.promotionAmount = transactionPromotion.price ? Math.abs(transactionPromotion.price) : 0;
|
|
3221
|
+
transactionPromotionObj.promotionId = transactionPromotion.promotion_id ? transactionPromotion.promotion_id : '';
|
|
3222
|
+
transactionPromotionObj.promotionInfo = transactionPromotion.item_text ? transactionPromotion.item_text : '';
|
|
3223
|
+
transactionPromotionObj.promotionType = transactionPromotion.applied_discount && transactionPromotion.applied_discount.type ? transactionPromotion.applied_discount.type : '';
|
|
3224
|
+
transactionPromotionObj.itemLineIds = this.orderDetails.product_items.map((product, index) => index + 1);
|
|
3225
|
+
if (transactionPromotion.coupon_code) {
|
|
3226
|
+
transactionPromotionObj.type = PROMOTION_TYPE.COUPON;
|
|
3227
|
+
transactionPromotionObj.couponCode = transactionPromotion.coupon_code;
|
|
3228
|
+
transactionPromotionObj.subLevelType = PROMOTION_LEVEL.TRANSACTION;
|
|
3229
|
+
}
|
|
3230
|
+
transactionPromotionArray.push(transactionPromotionObj);
|
|
3231
|
+
});
|
|
3232
|
+
}
|
|
3233
|
+
console.log("Mapper library: WebReturnSalesforceMapperBuilderClass: getTransactionPromotions : ", JSON.stringify(transactionPromotionArray));
|
|
3234
|
+
return transactionPromotionArray;
|
|
3235
|
+
}
|
|
3236
|
+
catch (error) {
|
|
3237
|
+
console.log("Mapper library: WebReturnSalesforceMapperBuilderClass: failed:", error);
|
|
3238
|
+
console.log("Mapper library: WebReturnSalesforceMapperBuilderClass: failed:", JSON.stringify(error));
|
|
3239
|
+
throw new Error(error);
|
|
3240
|
+
}
|
|
3241
|
+
}
|
|
3242
|
+
updateLinePromotionWithCoupon() {
|
|
3243
|
+
try {
|
|
3244
|
+
let transactionPromotion = {};
|
|
3245
|
+
let triggerPromotion = [];
|
|
3246
|
+
if (this.orderDetails.product_items && this.orderDetails.product_items.length > 0) {
|
|
3247
|
+
this.orderDetails.product_items.forEach((product, index) => {
|
|
3248
|
+
product.item_id = (index + 1).toString();
|
|
3249
|
+
if (product.price_adjustments && product.price_adjustments.length > 0) {
|
|
3250
|
+
product.price_adjustments.forEach((promotion) => {
|
|
3251
|
+
if (promotion.coupon_code) {
|
|
3252
|
+
let trigger = {};
|
|
3253
|
+
trigger.itemLineId = product.item_id;
|
|
3254
|
+
trigger.quantity = product.quantity ? product.quantity : 0;
|
|
3255
|
+
trigger.totalQuantity = product.quantity ? product.quantity : 0;
|
|
3256
|
+
trigger.promotionAmount = promotion.price ? Math.abs(promotion.price) : 0;
|
|
3257
|
+
trigger.refundedReason = promotion.coupon_code ? promotion.coupon_code : '';
|
|
3258
|
+
trigger.refundedReasonDescription = promotion.item_text ? promotion.item_text : '';
|
|
3259
|
+
trigger.promotionId = promotion.promotion_id;
|
|
3260
|
+
triggerPromotion.push(trigger);
|
|
3261
|
+
}
|
|
3262
|
+
});
|
|
3263
|
+
}
|
|
3264
|
+
});
|
|
3265
|
+
}
|
|
3266
|
+
if (triggerPromotion.length > 0) {
|
|
3267
|
+
transactionPromotion.displayText = triggerPromotion[0].refundedReasonDescription;
|
|
3268
|
+
transactionPromotion.name = triggerPromotion[0].refundedReason;
|
|
3269
|
+
transactionPromotion.promotionAmount = -(triggerPromotion.reduce((n, { promotionAmount }) => n + promotionAmount, 0));
|
|
3270
|
+
transactionPromotion.promotionId = triggerPromotion[0].promotionId;
|
|
3271
|
+
transactionPromotion.promotionInfo = triggerPromotion[0].refundedReasonDescription;
|
|
3272
|
+
transactionPromotion.couponCode = triggerPromotion[0].refundedReason;
|
|
3273
|
+
transactionPromotion.itemLineIds = [];
|
|
3274
|
+
transactionPromotion.type = PROMOTION_TYPE.COUPON;
|
|
3275
|
+
transactionPromotion.subLevelType = PROMOTION_LEVEL.LINE;
|
|
3276
|
+
transactionPromotion.trigger = triggerPromotion;
|
|
3277
|
+
}
|
|
3278
|
+
console.log("linePromotion mapping ended...");
|
|
3279
|
+
console.log("e-basket: updateLinePromotionWithCoupon", JSON.stringify(transactionPromotion));
|
|
3280
|
+
if (!this.webReturnObject.basket.transactionPromotion) {
|
|
3281
|
+
this.webReturnObject.basket.transactionPromotion = [];
|
|
3282
|
+
}
|
|
3283
|
+
if (transactionPromotion && transactionPromotion.promotionId) {
|
|
3284
|
+
this.webReturnObject.basket.transactionPromotion.push(transactionPromotion);
|
|
3285
|
+
}
|
|
3286
|
+
return this;
|
|
3287
|
+
}
|
|
3288
|
+
catch (error) {
|
|
3289
|
+
console.log("Ebasket: Salesforce: linePromotion mapping=> failed:", error);
|
|
3290
|
+
console.log("Ebasket: Salesforce: linePromotion mapping=> failed:", JSON.stringify(error));
|
|
3291
|
+
throw new Error(error);
|
|
3292
|
+
}
|
|
3293
|
+
}
|
|
3294
|
+
updateTransactionPromotionPrtionCalc() {
|
|
3295
|
+
if (this.webReturnObject.basket.transactionPromotion && this.webReturnObject.basket.transactionPromotion.length > 0) {
|
|
3296
|
+
this.webReturnObject.basket.transactionPromotion.forEach(tr => {
|
|
3297
|
+
this.transactionPromotionProductPortionCalc(this.webReturnObject, tr);
|
|
3298
|
+
});
|
|
3299
|
+
}
|
|
3300
|
+
return this;
|
|
3301
|
+
}
|
|
3302
|
+
transactionPromotionProductPortionCalc(txDoc, promotion) {
|
|
3303
|
+
console.log(`ebasket: transactionPromotionProductPortionCalc: trnsactionPromotion: ${JSON.stringify(promotion)}`);
|
|
3304
|
+
if (promotion.type === PROMOTION_TYPE.COUPON && promotion.subLevelType === PROMOTION_LEVEL.LINE) {
|
|
3305
|
+
txDoc.basket.products.forEach((product) => {
|
|
3306
|
+
product = this.validateProductItemDiscount(product);
|
|
3307
|
+
if (promotion.trigger && promotion.trigger.length > 0) {
|
|
3308
|
+
promotion.trigger.forEach((t) => {
|
|
3309
|
+
if (t.itemLineId === product.itemLineId.toString()) {
|
|
3310
|
+
product.itemDiscounts.trnPromotionsPortion += t.promotionAmount;
|
|
3311
|
+
}
|
|
3312
|
+
});
|
|
3313
|
+
}
|
|
3314
|
+
});
|
|
3315
|
+
}
|
|
3316
|
+
else {
|
|
3317
|
+
txDoc.basket.products.forEach((product) => {
|
|
3318
|
+
product = this.validateProductItemDiscount(product);
|
|
3319
|
+
if (promotion.itemLineIds.includes(+product.itemLineId)) {
|
|
3320
|
+
const productItem = this.orderDetails.product_items.find(productItem => productItem.product_id === product.SKU);
|
|
3321
|
+
const transactionPromotionPortion = (productItem && productItem.price_after_item_discount && productItem.price_after_order_discount) ?
|
|
3322
|
+
(productItem.price_after_item_discount - productItem.price_after_order_discount) : 0;
|
|
3323
|
+
product.itemDiscounts.trnPromotionsPortion += this.numberUtilService.trimTo2Decimal2(transactionPromotionPortion);
|
|
3324
|
+
}
|
|
3325
|
+
});
|
|
3326
|
+
}
|
|
3327
|
+
return txDoc;
|
|
3328
|
+
}
|
|
3329
|
+
validateProductItemDiscount(product) {
|
|
3330
|
+
if (!product.itemDiscounts) {
|
|
3331
|
+
product.itemDiscounts = {
|
|
3332
|
+
trnDiscountsPortion: 0,
|
|
3333
|
+
trnPromotionsPortion: 0,
|
|
3334
|
+
refundPortion: 0,
|
|
3335
|
+
};
|
|
3336
|
+
}
|
|
3337
|
+
return product;
|
|
3338
|
+
}
|
|
3339
|
+
customer() {
|
|
3340
|
+
console.log("Mapper library: WebReturnSalesforceMapperBuilderClass: customer mapping started...");
|
|
3341
|
+
let customerObj = {};
|
|
3342
|
+
customerObj.email = this.orderDetails.customer_info && this.orderDetails.customer_info.email ? this.orderDetails.customer_info.email : '';
|
|
3343
|
+
customerObj.firstName = this.orderDetails.billing_address && this.orderDetails.billing_address.first_name ? this.orderDetails.billing_address.first_name : '';
|
|
3344
|
+
customerObj.lastName = this.orderDetails.billing_address && this.orderDetails.billing_address.last_name ? this.orderDetails.billing_address.last_name : '';
|
|
3345
|
+
let shippingAddress = [];
|
|
3346
|
+
this.orderDetails.shipments.forEach(shipment => {
|
|
3347
|
+
let shippingAddressObj = {};
|
|
3348
|
+
shippingAddressObj.id = shipment.shipping_address && shipment.shipping_address.id ? shipment.shipping_address.id : '';
|
|
3349
|
+
shippingAddressObj.countryCode = shipment.shipping_address && shipment.shipping_address.country_code ? shipment.shipping_address.country_code : '';
|
|
3350
|
+
shippingAddressObj.address1 = shipment.shipping_address && shipment.shipping_address.address1 ? shipment.shipping_address.address1 : '';
|
|
3351
|
+
shippingAddressObj.city = shipment.shipping_address && shipment.shipping_address.city ? shipment.shipping_address.city : '';
|
|
3352
|
+
shippingAddressObj.country = '';
|
|
3353
|
+
shippingAddressObj.postCode = shipment.shipping_address && shipment.shipping_address.postal_code ? shipment.shipping_address.postal_code : '';
|
|
3354
|
+
shippingAddress.push(shippingAddressObj);
|
|
3355
|
+
});
|
|
3356
|
+
customerObj.shippingAddress = shippingAddress;
|
|
3357
|
+
let billingAddress = [];
|
|
3358
|
+
let billingAddressObj = {};
|
|
3359
|
+
billingAddressObj.id = this.orderDetails.billing_address && this.orderDetails.billing_address.id ? this.orderDetails.billing_address.id : '';
|
|
3360
|
+
billingAddressObj.countryCode = this.orderDetails.billing_address && this.orderDetails.billing_address.country_code ? this.orderDetails.billing_address.country_code : '';
|
|
3361
|
+
billingAddressObj.address1 = this.orderDetails.billing_address && this.orderDetails.billing_address.address1 ? this.orderDetails.billing_address.address1 : '';
|
|
3362
|
+
billingAddressObj.city = this.orderDetails.billing_address && this.orderDetails.billing_address.city ? this.orderDetails.billing_address.city : '';
|
|
3363
|
+
billingAddressObj.country = '';
|
|
3364
|
+
billingAddressObj.postCode = '';
|
|
3365
|
+
billingAddress.push(billingAddressObj);
|
|
3366
|
+
customerObj.billingAddress = billingAddress;
|
|
3367
|
+
let shipmentDetails = [];
|
|
3368
|
+
this.orderDetails.shipments.forEach(shipment => {
|
|
3369
|
+
let shipmentDetailsObj = {};
|
|
3370
|
+
shipmentDetailsObj.id = shipment.shipment_id ? shipment.shipment_id : '';
|
|
3371
|
+
shipmentDetailsObj.deliveryGroup = shipment.shipment_id ? shipment.shipment_id : '';
|
|
3372
|
+
shipmentDetails.push(shipmentDetailsObj);
|
|
3373
|
+
});
|
|
3374
|
+
customerObj.shipmentDetails = shipmentDetails;
|
|
3375
|
+
this.webReturnObject.customer = customerObj;
|
|
3376
|
+
console.log("Mapper library: WebReturnSalesforceMapperBuilderClass: customer mapping ended...");
|
|
3377
|
+
return this;
|
|
3378
|
+
}
|
|
3379
|
+
isInStoreOrder() {
|
|
3380
|
+
console.log("Mapper library: WebReturnSalesforceMapperBuilderClass: isInStoreOrder mapping started...");
|
|
3381
|
+
if (this.orderDetails.c_isInStoreOrder) {
|
|
3382
|
+
this.webReturnObject.isInStoreOrder = true;
|
|
3383
|
+
}
|
|
3384
|
+
console.log("Mapper library: WebReturnSalesforceMapperBuilderClass: isInStoreOrder mapping ended...");
|
|
3385
|
+
return this;
|
|
3386
|
+
}
|
|
3387
|
+
externalTransactionDetails() {
|
|
3388
|
+
console.log("Mapper library: WebReturnSalesforceMapperBuilderClass: externalTransactionDetails mapping started...");
|
|
3389
|
+
let externalTransactionDetails = [];
|
|
3390
|
+
if (this.orderDetails.shipments && this.orderDetails.shipments.length > 0) {
|
|
3391
|
+
this.orderDetails.shipments.forEach(shipment => {
|
|
3392
|
+
let externalTransactionDetailsObj = {};
|
|
3393
|
+
let transactionInfo = {};
|
|
3394
|
+
externalTransactionDetailsObj.uniqueId = this.orderDetails.order_no ? this.orderDetails.order_no : '';
|
|
3395
|
+
externalTransactionDetailsObj.providerType = PROVIDERS.SALESFORCE;
|
|
3396
|
+
transactionInfo.shippingId = shipment.shipping_method && shipment.shipping_method.id ? shipment.shipping_method.id : '';
|
|
3397
|
+
transactionInfo.externalShippingId = shipment.shipment_id ? shipment.shipment_id : '';
|
|
3398
|
+
externalTransactionDetailsObj.details = transactionInfo;
|
|
3399
|
+
externalTransactionDetails.push(externalTransactionDetailsObj);
|
|
3400
|
+
});
|
|
3401
|
+
}
|
|
3402
|
+
this.webReturnObject.externalTransactionDetails = externalTransactionDetails;
|
|
3403
|
+
console.log("Mapper library: WebReturnSalesforceMapperBuilderClass: externalTransactionDetails mapping ended...");
|
|
3404
|
+
return this;
|
|
3405
|
+
}
|
|
3406
|
+
basketSummary() {
|
|
3407
|
+
console.log("Mapper library: WebReturnSalesforceMapperBuilderClass: basketSummary mapping started...");
|
|
3408
|
+
let basketSummary = {};
|
|
3409
|
+
let basketSummaryWebOrder = {};
|
|
3410
|
+
const linePromotionTotal = this.webReturnObject.basket.linePromotion.map(linePromotion => linePromotion.promotionAmount).reduce((accumulator, currentValue) => accumulator + currentValue, 0);
|
|
3411
|
+
const transactionPromotionTotal = this.webReturnObject.basket.transactionPromotion.map(transactionPromotion => transactionPromotion.promotionAmount).reduce((accumulator, currentValue) => accumulator + currentValue, 0);
|
|
3412
|
+
basketSummary.discountTotal = linePromotionTotal + transactionPromotionTotal;
|
|
3413
|
+
basketSummary.VATTotal = this.orderDetails.tax_total ? this.orderDetails.tax_total : 0;
|
|
3414
|
+
basketSummary.saleTotal = this.orderDetails.order_total ? this.orderDetails.order_total : 0;
|
|
3415
|
+
basketSummary.basketTotal = this.orderDetails.order_total ? this.orderDetails.order_total : 0;
|
|
3416
|
+
basketSummary.totalItems = this.orderDetails.product_items && this.orderDetails.product_items.length > 0 ? this.orderDetails.product_items.length : 0;
|
|
3417
|
+
basketSummary.shippingTotal = this.orderDetails.shipping_total ? this.orderDetails.shipping_total : 0;
|
|
3418
|
+
basketSummary.basketTotalWithShippingTotal = this.orderDetails.order_total ? this.orderDetails.order_total : 0;
|
|
3419
|
+
basketSummaryWebOrder.shippingTotal = this.orderDetails.shipping_total ? this.orderDetails.shipping_total : 0;
|
|
3420
|
+
basketSummaryWebOrder.basketTotalWithShippingTotal = this.orderDetails.order_total ? this.orderDetails.order_total : 0;
|
|
3421
|
+
basketSummary.webOrder = basketSummaryWebOrder;
|
|
3422
|
+
this.webReturnObject.basketSummary = basketSummary;
|
|
3423
|
+
console.log("Mapper library: WebReturnSalesforceMapperBuilderClass: basketSummary mapping ended...");
|
|
3424
|
+
return this;
|
|
3425
|
+
}
|
|
3426
|
+
deviceId(deviceId) {
|
|
3427
|
+
this.webReturnObject.deviceId = deviceId;
|
|
3428
|
+
return this;
|
|
3429
|
+
}
|
|
3430
|
+
terminalId(terminalId) {
|
|
3431
|
+
this.webReturnObject.terminalId = terminalId;
|
|
3432
|
+
return this;
|
|
3433
|
+
}
|
|
3434
|
+
orgCode(orgCode) {
|
|
3435
|
+
this.webReturnObject.orgCode = orgCode;
|
|
3436
|
+
return this;
|
|
3437
|
+
}
|
|
3438
|
+
storeId(storeId) {
|
|
3439
|
+
this.webReturnObject.storeId = storeId;
|
|
3440
|
+
return this;
|
|
3441
|
+
}
|
|
3442
|
+
storeNodeId(storeNodeId) {
|
|
3443
|
+
this.webReturnObject.storeNodeId = storeNodeId;
|
|
3444
|
+
return this;
|
|
3445
|
+
}
|
|
3446
|
+
storeNodeStructure(storeNodeStructure) {
|
|
3447
|
+
this.webReturnObject.storeNodeStructure = storeNodeStructure;
|
|
3448
|
+
return this;
|
|
3449
|
+
}
|
|
3450
|
+
docId(docId) {
|
|
3451
|
+
this.webReturnObject.id = docId;
|
|
3452
|
+
return this;
|
|
3453
|
+
}
|
|
3454
|
+
updateUserID(userID) {
|
|
3455
|
+
this.webReturnObject.userId = userID;
|
|
3456
|
+
return this;
|
|
3457
|
+
}
|
|
3458
|
+
updateUserName(name) {
|
|
3459
|
+
this.webReturnObject.userName = name;
|
|
3460
|
+
return this;
|
|
3461
|
+
}
|
|
3462
|
+
build() {
|
|
3463
|
+
console.log("Mapper library: WebReturnSalesforceMapperBuilderClass: mapping done...");
|
|
3464
|
+
return this.webReturnObject;
|
|
3465
|
+
}
|
|
3466
|
+
getUTCDateTime(date) {
|
|
3467
|
+
if (date) {
|
|
3468
|
+
return new Date(date).toISOString();
|
|
3469
|
+
}
|
|
3470
|
+
}
|
|
3471
|
+
}
|
|
3472
|
+
|
|
3473
|
+
/*
|
|
3474
|
+
* Public API Surface of mapper-library
|
|
3475
|
+
*/
|
|
3476
|
+
|
|
3477
|
+
/**
|
|
3478
|
+
* Generated bundle index. Do not edit.
|
|
3479
|
+
*/
|
|
3480
|
+
|
|
3481
|
+
export { MapperLibraryComponent, MapperLibraryModule, RJMapperBuilderClass, WebReturnMapperBuilderClass, WebReturnSalesforceMapperBuilderClass };
|
|
3482
|
+
//# sourceMappingURL=pmcretail-mapper-library.mjs.map
|