@shushed/helpers 0.0.226-fix-erp-631-20260105150238 → 0.0.226-fix-erp-631-20260105165140
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/dist/cjs/src-public/bcOrder.js +35 -62
- package/package.json +1 -1
|
@@ -169,30 +169,33 @@ function transformMasterOrder(payload) {
|
|
|
169
169
|
if (desc)
|
|
170
170
|
skuByDescription[desc] = sku;
|
|
171
171
|
});
|
|
172
|
-
const
|
|
173
|
-
const
|
|
174
|
-
|
|
172
|
+
const isShippableItem = (line) => {
|
|
173
|
+
const itemNo = String(line?.item_no || line?.no || '');
|
|
174
|
+
const variantCode = String(line?.variant_code || '');
|
|
175
|
+
const amount = Number(line?.amount || line?.amount_excl_vat || 0);
|
|
176
|
+
const amountGross = Number(line?.amount_including_vat || line?.amount_incl_vat || 0);
|
|
177
|
+
const quantity = Number(line?.quantity || 0);
|
|
178
|
+
const hasStyleAndColour = itemNo.includes('-');
|
|
179
|
+
const hasSize = variantCode.trim().length > 0;
|
|
180
|
+
const hasValue = amount > 0 || amountGross > 0 || quantity > 0;
|
|
181
|
+
const hasQuantity = quantity > 0;
|
|
182
|
+
return Boolean(hasStyleAndColour && hasSize && hasValue && hasQuantity);
|
|
175
183
|
};
|
|
176
184
|
const returnedQtyBySku = {};
|
|
177
185
|
(payload.credit_memos || []).forEach((cm) => {
|
|
178
186
|
(cm.credit_memo_lines || []).forEach((l) => {
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
187
|
+
if (!isShippableItem(l)) {
|
|
188
|
+
const desc = String(l?.description || '');
|
|
189
|
+
if (desc && skuByDescription[desc]) {
|
|
190
|
+
const sku = skuByDescription[desc];
|
|
191
|
+
returnedQtyBySku[sku] = (returnedQtyBySku[sku] || 0) + (l.quantity || 0);
|
|
192
|
+
}
|
|
184
193
|
return;
|
|
185
|
-
const typeStr = String(l?.type || '').toLowerCase();
|
|
186
|
-
const isTypeItem = typeStr.includes('item');
|
|
187
|
-
if (isTypeItem) {
|
|
188
|
-
const variant = String(l?.variant_code || '');
|
|
189
|
-
const sku = variant ? `${itemNo}-${variant}` : itemNo;
|
|
190
|
-
returnedQtyBySku[sku] = (returnedQtyBySku[sku] || 0) + (l.quantity || 0);
|
|
191
|
-
}
|
|
192
|
-
else if (desc && skuByDescription[desc]) {
|
|
193
|
-
const sku = skuByDescription[desc];
|
|
194
|
-
returnedQtyBySku[sku] = (returnedQtyBySku[sku] || 0) + (l.quantity || 0);
|
|
195
194
|
}
|
|
195
|
+
const itemNo = String(l?.item_no || l?.no || '');
|
|
196
|
+
const variant = String(l?.variant_code || '');
|
|
197
|
+
const sku = variant ? `${itemNo}-${variant}` : itemNo;
|
|
198
|
+
returnedQtyBySku[sku] = (returnedQtyBySku[sku] || 0) + (l.quantity || 0);
|
|
196
199
|
});
|
|
197
200
|
});
|
|
198
201
|
(payload.sales || []).forEach((sale) => {
|
|
@@ -200,14 +203,9 @@ function transformMasterOrder(payload) {
|
|
|
200
203
|
if (!docTypeRaw.toLowerCase().includes('return'))
|
|
201
204
|
return;
|
|
202
205
|
(sale.sale_lines || []).forEach((l) => {
|
|
203
|
-
|
|
204
|
-
const desc = String(l?.description || '');
|
|
205
|
-
if (itemNo.toUpperCase() === 'X DELCHR' || itemNo.toUpperCase() === 'REFUND')
|
|
206
|
-
return;
|
|
207
|
-
if ((l?.quantity || 0) <= 0)
|
|
208
|
-
return;
|
|
209
|
-
if (!isItemish(l?.type, itemNo, desc))
|
|
206
|
+
if (!isShippableItem(l))
|
|
210
207
|
return;
|
|
208
|
+
const itemNo = String(l?.item_no || l?.no || '');
|
|
211
209
|
const variant = String(l?.variant_code || '');
|
|
212
210
|
const sku = variant ? `${itemNo}-${variant}` : itemNo;
|
|
213
211
|
returnedQtyBySku[sku] = (returnedQtyBySku[sku] || 0) + (l.quantity || 0);
|
|
@@ -237,18 +235,12 @@ function transformMasterOrder(payload) {
|
|
|
237
235
|
const shippedQtyBySku = {};
|
|
238
236
|
(payload.shipments || []).forEach((s) => {
|
|
239
237
|
(s.shipment_lines || []).forEach((l) => {
|
|
240
|
-
|
|
241
|
-
if (itemNo.toUpperCase() === 'X DELCHR')
|
|
242
|
-
return;
|
|
243
|
-
const desc = String(l?.description || '');
|
|
244
|
-
const looksProduct = itemNo.includes('-') || desc.includes(' - ');
|
|
245
|
-
const qty = Number(l?.quantity || 0);
|
|
246
|
-
if (!looksProduct)
|
|
247
|
-
return;
|
|
248
|
-
if (qty <= 0)
|
|
238
|
+
if (!isShippableItem(l))
|
|
249
239
|
return;
|
|
240
|
+
const itemNo = String(l?.item_no || l?.no || "");
|
|
250
241
|
const variant = String(l?.variant_code || "");
|
|
251
242
|
const sku = variant ? `${itemNo}-${variant}` : itemNo;
|
|
243
|
+
const qty = Number(l?.quantity || 0);
|
|
252
244
|
shippedQtyBySku[sku] = (shippedQtyBySku[sku] || 0) + qty;
|
|
253
245
|
});
|
|
254
246
|
});
|
|
@@ -539,17 +531,10 @@ function transformMasterOrder(payload) {
|
|
|
539
531
|
};
|
|
540
532
|
const mappedShipments = (payload.shipments || []).map((s) => {
|
|
541
533
|
const rawLines = (s.shipment_lines || [])
|
|
542
|
-
.filter((l) => (l
|
|
543
|
-
.filter((l) => String(l?.item_no || '').toUpperCase() !== 'X DELCHR')
|
|
544
|
-
.filter((l) => {
|
|
545
|
-
const itemNo = String(l?.item_no || '');
|
|
546
|
-
const desc = String(l?.description || '');
|
|
547
|
-
const looksProduct = itemNo.includes('-') || desc.includes(' - ');
|
|
548
|
-
return looksProduct;
|
|
549
|
-
});
|
|
534
|
+
.filter((l) => isShippableItem(l));
|
|
550
535
|
const qtyBySku = new Map();
|
|
551
536
|
rawLines.forEach((l) => {
|
|
552
|
-
const itemNo = String(l?.item_no || '');
|
|
537
|
+
const itemNo = String(l?.item_no || l?.no || '');
|
|
553
538
|
const variant = String(l?.variant_code || '');
|
|
554
539
|
const sku = variant ? `${itemNo}-${variant}` : itemNo;
|
|
555
540
|
const q = Number(l?.quantity || 0);
|
|
@@ -582,10 +567,12 @@ function transformMasterOrder(payload) {
|
|
|
582
567
|
const shipmentsBySku = new Map();
|
|
583
568
|
(payload.shipments || []).forEach((s) => {
|
|
584
569
|
(s.shipment_lines || []).forEach((sl) => {
|
|
585
|
-
|
|
570
|
+
if (!isShippableItem(sl))
|
|
571
|
+
return;
|
|
572
|
+
const itemNo = String(sl?.item_no || sl?.no || '');
|
|
586
573
|
const variant = String(sl?.variant_code || '');
|
|
587
574
|
const sku = variant ? `${itemNo}-${variant}` : itemNo;
|
|
588
|
-
if (
|
|
575
|
+
if (!shipmentsBySku.has(sku)) {
|
|
589
576
|
shipmentsBySku.set(sku, s);
|
|
590
577
|
}
|
|
591
578
|
});
|
|
@@ -593,25 +580,11 @@ function transformMasterOrder(payload) {
|
|
|
593
580
|
const returnShipments = (payload.credit_memos || [])
|
|
594
581
|
.filter((cm) => {
|
|
595
582
|
const lines = cm?.credit_memo_lines || [];
|
|
596
|
-
return lines.some((l) =>
|
|
597
|
-
const itemNo = String(l?.item_no || l?.no || "");
|
|
598
|
-
const upper = itemNo.toUpperCase();
|
|
599
|
-
if (upper === 'X DELCHR' || upper === 'REFUND')
|
|
600
|
-
return false;
|
|
601
|
-
const looksProduct = itemNo.includes('-');
|
|
602
|
-
return (l?.quantity || 0) > 0 && looksProduct;
|
|
603
|
-
});
|
|
583
|
+
return lines.some((l) => isShippableItem(l));
|
|
604
584
|
})
|
|
605
585
|
.map((cm, idx) => {
|
|
606
586
|
const rawLines = (cm.credit_memo_lines || [])
|
|
607
|
-
.filter((l) => (l
|
|
608
|
-
.filter((l) => {
|
|
609
|
-
const itemNo = String(l?.item_no || l?.no || '');
|
|
610
|
-
const upper = itemNo.toUpperCase();
|
|
611
|
-
if (upper === 'X DELCHR' || upper === 'REFUND')
|
|
612
|
-
return false;
|
|
613
|
-
return itemNo.includes('-');
|
|
614
|
-
});
|
|
587
|
+
.filter((l) => isShippableItem(l));
|
|
615
588
|
const qtyBySku = new Map();
|
|
616
589
|
rawLines.forEach((l) => {
|
|
617
590
|
const itemNo = String(l?.item_no || l?.no || '');
|
|
@@ -810,7 +783,7 @@ function transformMasterOrder(payload) {
|
|
|
810
783
|
return acc + (s.amount_incl_vat || 0);
|
|
811
784
|
}
|
|
812
785
|
const lineAmounts = (s.shipment_lines || []).reduce((lineAcc, l) => {
|
|
813
|
-
if (
|
|
786
|
+
if (!isShippableItem(l))
|
|
814
787
|
return lineAcc;
|
|
815
788
|
const orderLineNo = Number(l?.order_line_no || -1);
|
|
816
789
|
let sourceLine = orderLineNo > 0 ? sourceLineMap.get(orderLineNo) : null;
|