@softwear/latestcollectioncore 1.0.116 → 1.0.117

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/edifact.d.ts CHANGED
@@ -1,6 +1,8 @@
1
- import { MarkedSkuI } from './types';
1
+ import { MarkedSkuI, DocumentItemI } from './types';
2
2
  declare const _default: {
3
3
  skusToPricat: (skus: MarkedSkuI[], fromGLN: string, toGLN: string, supplierGLN: string, refID: number, date: string) => any[];
4
4
  pricatToCsv: (pricat: any) => string;
5
+ itemsToOrdRsp: (items: DocumentItemI[], fromGLN: string, toGLN: string, supplierGLN: string, refID: number, date: string, orderNumber: string) => any[];
6
+ ordRspToCsv: (order: any) => string;
5
7
  };
6
8
  export default _default;
package/dist/edifact.js CHANGED
@@ -334,4 +334,216 @@ const pricatToCsv = function (pricat) {
334
334
  const linString = lines.join('\n');
335
335
  return envString + hdrString + grpString + linString;
336
336
  };
337
- exports.default = { skusToPricat, pricatToCsv };
337
+ const itemsToOrdRsp = function (items, fromGLN, toGLN, supplierGLN, refID, date, orderNumber) {
338
+ const order = [];
339
+ if (typeof fromGLN != 'string' || fromGLN.length != 13)
340
+ return [];
341
+ if (typeof toGLN != 'string' || toGLN.length != 13)
342
+ return [];
343
+ if (typeof supplierGLN != 'string' || supplierGLN.length != 13)
344
+ return [];
345
+ if (typeof orderNumber != 'string')
346
+ return [];
347
+ if (typeof refID != 'number' || !refID)
348
+ return [];
349
+ if (typeof date != 'string' || date.length != 8)
350
+ return [];
351
+ if (items.length == 0)
352
+ return [];
353
+ const env = { Tag: 'ENV', SenderGLN: fromGLN, RecipientGLN: toGLN, InterchangeReference: refID };
354
+ const hdr = {
355
+ Tag: 'HDR',
356
+ DocumentType: '231',
357
+ DocumentFunction: '29',
358
+ DocumentNumber: refID,
359
+ OrderNumberSupplier: orderNumber,
360
+ HeaderCurrency: '"EUR"',
361
+ SupplierGLN: supplierGLN,
362
+ BuyerGLN: toGLN,
363
+ };
364
+ order.push(env);
365
+ order.push(hdr);
366
+ let lineNumber = 1;
367
+ items.forEach((item) => {
368
+ const lin = {
369
+ LineTag: 'LIN',
370
+ LineNumber: lineNumber++,
371
+ ActionCode: '"1"',
372
+ GTIN: item.barcode,
373
+ OrderedQuantity: item.qty,
374
+ ConfirmedQuantity: item.qty,
375
+ PurchasePriceNet: item.price,
376
+ };
377
+ order.push(lin);
378
+ });
379
+ return order;
380
+ };
381
+ const ordRspToCsv = function (order) {
382
+ if (!order || order.length == 0)
383
+ return '';
384
+ const env = order[0];
385
+ const envValues = ['"ENV"', env.SenderGLN, env.RecipientGLN, env.InterchangeReference, 0, '"FUEB 5.00"', null, null, null, null, null];
386
+ const envString = envValues.join(',') + '\n';
387
+ const hdr = order[1];
388
+ const hdrValues = [
389
+ '"HDR"',
390
+ `"${hdr.DocumentType}"`,
391
+ `"${hdr.DocumentFunction}"`,
392
+ `"${hdr.DocumentNumber}"`,
393
+ null,
394
+ null,
395
+ null,
396
+ null,
397
+ null,
398
+ null,
399
+ null,
400
+ null,
401
+ `"${hdr.OrderNumberSupplier}"`,
402
+ null,
403
+ null,
404
+ null,
405
+ null,
406
+ null,
407
+ null,
408
+ null,
409
+ null,
410
+ hdr.HeaderCurrency,
411
+ hdr.SupplierGLN,
412
+ null,
413
+ null,
414
+ null,
415
+ null,
416
+ null,
417
+ null,
418
+ null,
419
+ null,
420
+ env.RecipientGLN,
421
+ null,
422
+ null,
423
+ null,
424
+ null,
425
+ null,
426
+ null,
427
+ null,
428
+ null,
429
+ null,
430
+ null,
431
+ null,
432
+ null,
433
+ null,
434
+ null,
435
+ null,
436
+ null,
437
+ null,
438
+ null,
439
+ null,
440
+ null,
441
+ null,
442
+ null,
443
+ null,
444
+ null,
445
+ null,
446
+ null,
447
+ null,
448
+ null,
449
+ null,
450
+ null,
451
+ null,
452
+ null,
453
+ null,
454
+ null,
455
+ null,
456
+ null,
457
+ null,
458
+ null,
459
+ null,
460
+ null,
461
+ null,
462
+ null,
463
+ null,
464
+ null,
465
+ null,
466
+ null,
467
+ null,
468
+ null,
469
+ null,
470
+ null,
471
+ null,
472
+ null,
473
+ null,
474
+ null,
475
+ null,
476
+ null,
477
+ null,
478
+ null,
479
+ null,
480
+ null,
481
+ null,
482
+ null,
483
+ null,
484
+ null,
485
+ null,
486
+ null,
487
+ null,
488
+ null,
489
+ null,
490
+ null,
491
+ null,
492
+ null,
493
+ ];
494
+ const hdrString = hdrValues.join(',') + '\n';
495
+ const lines = [];
496
+ order
497
+ .filter((r) => r.LineTag == 'LIN')
498
+ .forEach((r) => {
499
+ const linValues = [
500
+ '"LIN"',
501
+ r.LineNumber,
502
+ 1,
503
+ r.GTIN,
504
+ null,
505
+ null,
506
+ null,
507
+ null,
508
+ null,
509
+ r.OrderedQuantity,
510
+ null,
511
+ r.ConfirmedQuantity,
512
+ null,
513
+ null,
514
+ null,
515
+ null,
516
+ null,
517
+ null,
518
+ null,
519
+ r.PurchasePriceNet,
520
+ null,
521
+ null,
522
+ null,
523
+ null,
524
+ null,
525
+ null,
526
+ null,
527
+ null,
528
+ null,
529
+ null,
530
+ null,
531
+ null,
532
+ null,
533
+ null,
534
+ null,
535
+ null,
536
+ null,
537
+ null,
538
+ null,
539
+ null,
540
+ null,
541
+ null,
542
+ null,
543
+ ];
544
+ lines.push(linValues.join(','));
545
+ });
546
+ const linString = lines.join('\n');
547
+ return envString + hdrString + linString;
548
+ };
549
+ exports.default = { skusToPricat, pricatToCsv, itemsToOrdRsp, ordRspToCsv };
package/dist/types.d.ts CHANGED
@@ -138,6 +138,11 @@ interface SkuI {
138
138
  erpSource?: string;
139
139
  genderSupplier?: string;
140
140
  }
141
+ interface DocumentItemI {
142
+ barcode: barcode;
143
+ qty: number;
144
+ price?: number;
145
+ }
141
146
  interface MarkedSkuI extends SkuI {
142
147
  SOURCE?: string;
143
148
  groups?: Array<GroupI>;
@@ -329,4 +334,4 @@ declare enum TimeGranularityE {
329
334
  QUARTER = "quarter",
330
335
  YEAR = "year"
331
336
  }
332
- export { RowI, StockTransferSelectionI, MarkedSkuI, vatCategoryE, tagTypeE, SkuI, GroupI, ProductI, ImageI, AttributeI, ColorI, MatrixI, StockTransferDataI, StockTransferMatrixI, BrandSettingI, mappingStrategyE, subscriptionE, dbTransactionI, TransactionI, transactionTypeE, HrTimeframeI, TimeGranularityE, AggregatorFnI, AggregateFnI, RaGI, };
337
+ export { RowI, StockTransferSelectionI, MarkedSkuI, vatCategoryE, tagTypeE, SkuI, GroupI, ProductI, ImageI, AttributeI, ColorI, MatrixI, StockTransferDataI, StockTransferMatrixI, BrandSettingI, mappingStrategyE, subscriptionE, dbTransactionI, TransactionI, transactionTypeE, HrTimeframeI, TimeGranularityE, AggregatorFnI, AggregateFnI, RaGI, DocumentItemI, };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@softwear/latestcollectioncore",
3
- "version": "1.0.116",
3
+ "version": "1.0.117",
4
4
  "description": "Core functions for LatestCollections applications",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
package/src/edifact.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { MarkedSkuI } from './types'
1
+ import { MarkedSkuI, DocumentItemI } from './types'
2
2
 
3
3
  const skusToPricat = function (skus: MarkedSkuI[], fromGLN: string, toGLN: string, supplierGLN: string, refID: number, date: string) {
4
4
  const pricat = [] as any[]
@@ -334,4 +334,216 @@ const pricatToCsv = function (pricat: any): string {
334
334
  return envString + hdrString + grpString + linString
335
335
  }
336
336
 
337
- export default { skusToPricat, pricatToCsv }
337
+ const itemsToOrdRsp = function (items: DocumentItemI[], fromGLN: string, toGLN: string, supplierGLN: string, refID: number, date: string, orderNumber: string) {
338
+ const order = [] as any[]
339
+
340
+ if (typeof fromGLN != 'string' || fromGLN.length != 13) return []
341
+ if (typeof toGLN != 'string' || toGLN.length != 13) return []
342
+ if (typeof supplierGLN != 'string' || supplierGLN.length != 13) return []
343
+ if (typeof orderNumber != 'string') return []
344
+ if (typeof refID != 'number' || !refID) return []
345
+ if (typeof date != 'string' || date.length != 8) return []
346
+ if (items.length == 0) return []
347
+ const env = { Tag: 'ENV', SenderGLN: fromGLN, RecipientGLN: toGLN, InterchangeReference: refID }
348
+ const hdr = {
349
+ Tag: 'HDR',
350
+ DocumentType: '231',
351
+ DocumentFunction: '29',
352
+ DocumentNumber: refID,
353
+ OrderNumberSupplier: orderNumber,
354
+ HeaderCurrency: '"EUR"',
355
+ SupplierGLN: supplierGLN,
356
+ BuyerGLN: toGLN,
357
+ }
358
+
359
+ order.push(env)
360
+ order.push(hdr)
361
+ let lineNumber = 1
362
+ items.forEach((item) => {
363
+ const lin = {
364
+ LineTag: 'LIN',
365
+ LineNumber: lineNumber++,
366
+ ActionCode: '"1"',
367
+ GTIN: item.barcode,
368
+ OrderedQuantity: item.qty,
369
+ ConfirmedQuantity: item.qty,
370
+ PurchasePriceNet: item.price,
371
+ }
372
+ order.push(lin)
373
+ })
374
+ return order
375
+ }
376
+
377
+ const ordRspToCsv = function (order: any): string {
378
+ if (!order || order.length == 0) return ''
379
+ const env = order[0]
380
+ const envValues = ['"ENV"', env.SenderGLN, env.RecipientGLN, env.InterchangeReference, 0, '"FUEB 5.00"', null, null, null, null, null]
381
+ const envString = envValues.join(',') + '\n'
382
+
383
+ const hdr = order[1]
384
+ const hdrValues = [
385
+ '"HDR"',
386
+ `"${hdr.DocumentType}"`,
387
+ `"${hdr.DocumentFunction}"`,
388
+ `"${hdr.DocumentNumber}"`,
389
+ null,
390
+ null,
391
+ null,
392
+ null,
393
+ null,
394
+ null,
395
+ null,
396
+ null,
397
+ `"${hdr.OrderNumberSupplier}"`,
398
+ null,
399
+ null,
400
+ null,
401
+ null,
402
+ null,
403
+ null,
404
+ null,
405
+ null,
406
+ hdr.HeaderCurrency,
407
+ hdr.SupplierGLN,
408
+ null,
409
+ null,
410
+ null,
411
+ null,
412
+ null,
413
+ null,
414
+ null,
415
+ null,
416
+ env.RecipientGLN,
417
+ null,
418
+ null,
419
+ null,
420
+ null,
421
+ null,
422
+ null,
423
+ null,
424
+ null,
425
+ null,
426
+ null,
427
+ null,
428
+ null,
429
+ null,
430
+ null,
431
+ null,
432
+ null,
433
+ null,
434
+ null,
435
+ null,
436
+ null,
437
+ null,
438
+ null,
439
+ null,
440
+ null,
441
+ null,
442
+ null,
443
+ null,
444
+ null,
445
+ null,
446
+ null,
447
+ null,
448
+ null,
449
+ null,
450
+ null,
451
+ null,
452
+ null,
453
+ null,
454
+ null,
455
+ null,
456
+ null,
457
+ null,
458
+ null,
459
+ null,
460
+ null,
461
+ null,
462
+ null,
463
+ null,
464
+ null,
465
+ null,
466
+ null,
467
+ null,
468
+ null,
469
+ null,
470
+ null,
471
+ null,
472
+ null,
473
+ null,
474
+ null,
475
+ null,
476
+ null,
477
+ null,
478
+ null,
479
+ null,
480
+ null,
481
+ null,
482
+ null,
483
+ null,
484
+ null,
485
+ null,
486
+ null,
487
+ null,
488
+ null,
489
+ ]
490
+ const hdrString = hdrValues.join(',') + '\n'
491
+
492
+ const lines = [] as string[]
493
+ order
494
+ .filter((r) => r.LineTag == 'LIN')
495
+ .forEach((r) => {
496
+ const linValues = [
497
+ '"LIN"',
498
+ r.LineNumber,
499
+ 1,
500
+ r.GTIN,
501
+ null,
502
+ null,
503
+ null,
504
+ null,
505
+ null,
506
+ r.OrderedQuantity,
507
+ null,
508
+ r.ConfirmedQuantity,
509
+ null,
510
+ null,
511
+ null,
512
+ null,
513
+ null,
514
+ null,
515
+ null,
516
+ r.PurchasePriceNet,
517
+ null,
518
+ null,
519
+ null,
520
+ null,
521
+ null,
522
+ null,
523
+ null,
524
+ null,
525
+ null,
526
+ null,
527
+ null,
528
+ null,
529
+ null,
530
+ null,
531
+ null,
532
+ null,
533
+ null,
534
+ null,
535
+ null,
536
+ null,
537
+ null,
538
+ null,
539
+ null,
540
+ ]
541
+
542
+ lines.push(linValues.join(','))
543
+ })
544
+
545
+ const linString = lines.join('\n')
546
+ return envString + hdrString + linString
547
+ }
548
+
549
+ export default { skusToPricat, pricatToCsv, itemsToOrdRsp, ordRspToCsv }
package/src/types.ts CHANGED
@@ -148,6 +148,12 @@ interface SkuI {
148
148
  genderSupplier?: string
149
149
  }
150
150
 
151
+ interface DocumentItemI {
152
+ barcode: barcode
153
+ qty: number
154
+ price?: number
155
+ }
156
+
151
157
  interface MarkedSkuI extends SkuI {
152
158
  SOURCE?: string
153
159
  groups?: Array<GroupI>
@@ -376,4 +382,5 @@ export {
376
382
  AggregatorFnI,
377
383
  AggregateFnI,
378
384
  RaGI,
385
+ DocumentItemI,
379
386
  }
@@ -4,9 +4,9 @@ chai.config.truncateThreshold = 0 // disables truncation
4
4
  const { expect } = require('chai')
5
5
  const primadonnaSkus = require('./edifact-primadonna')
6
6
 
7
- const { skusToPricat, pricatToCsv } = core.edifact
7
+ const { skusToPricat, pricatToCsv, itemsToOrdRsp, ordRspToCsv } = core.edifact
8
8
 
9
- describe('edifact', () => {
9
+ describe('edifact pricat', () => {
10
10
  it('should check all required parameters, otherwise return an empty arrray', () => {
11
11
  expect(skusToPricat()).to.be.deep.equal([])
12
12
  expect(skusToPricat([], '', '', '')).to.be.deep.equal([])
@@ -19,7 +19,7 @@ describe('edifact', () => {
19
19
  expect(pricat).to.be.deep.equal([])
20
20
  })
21
21
 
22
- it('should return a proper pricat when skus are passed', () => {
22
+ it('should return a Json version of an edifact pricat when skus are passed', () => {
23
23
  const pricat = skusToPricat(primadonnaSkus, '1234567890123', '3210987654321', '1122334455667', 12345, '20240315')
24
24
  expect(pricat.slice(0, 5)).to.be.deep.equal([
25
25
  { Tag: 'ENV', SenderGLN: '1234567890123', RecipientGLN: '3210987654321', InterchangeReference: 12345 },
@@ -79,7 +79,7 @@ describe('edifact', () => {
79
79
  },
80
80
  ])
81
81
  })
82
- it('should perform csv conversion for a proper pricat', () => {
82
+ it('should perform csv conversion for a FashionUnited 5.00 pricat', () => {
83
83
  const pricat = skusToPricat(primadonnaSkus, '1234567890123', '3210987654321', '1122334455667', 12345, '20240315')
84
84
  const csv = pricatToCsv(pricat).split('\n')
85
85
  expect(pricatToCsv([])).to.be.deep.equal('')
@@ -136,3 +136,54 @@ describe('edifact', () => {
136
136
  )
137
137
  })
138
138
  })
139
+
140
+ const testOrderItems = [
141
+ {
142
+ barcode: '5400977135395',
143
+ qty: 3,
144
+ price: 37.25,
145
+ },
146
+ {
147
+ barcode: '5400977135326',
148
+ qty: 2,
149
+ price: 37.1,
150
+ },
151
+ ]
152
+ describe('edifact ordrsp', () => {
153
+ it('should check all required parameters, otherwise return an empty arrray', () => {
154
+ expect(itemsToOrdRsp()).to.be.deep.equal([])
155
+ expect(itemsToOrdRsp([], '', '', '', '')).to.be.deep.equal([])
156
+ expect(itemsToOrdRsp([], '123', '1234567890123', '1122334455667', '', '')).to.be.deep.equal([])
157
+ expect(itemsToOrdRsp([], '1234567890123', 123, '1122334455667', '')).to.be.deep.equal([])
158
+ expect(itemsToOrdRsp([], '1234567890123', 123, '1122334455667', 3.14, '20240101', 12345)).to.be.deep.equal([])
159
+ expect(itemsToOrdRsp([], '1234567890123', 123, '1122334455667', 3.14, '20240101', 'ORD-12345')).to.be.deep.equal([])
160
+ })
161
+ it('should return a Json version of an edifact ordrsp when items are passed', () => {
162
+ expect(itemsToOrdRsp(testOrderItems, '1234567890123', '3210987654321', '1122334455667', 12345, '20240315', 'ORD-12345')).to.be.deep.equal([
163
+ { Tag: 'ENV', SenderGLN: '1234567890123', RecipientGLN: '3210987654321', InterchangeReference: 12345 },
164
+ {
165
+ Tag: 'HDR',
166
+ DocumentType: '231',
167
+ DocumentFunction: '29',
168
+ DocumentNumber: 12345,
169
+ OrderNumberSupplier: 'ORD-12345',
170
+ HeaderCurrency: '"EUR"',
171
+ SupplierGLN: '1122334455667',
172
+ BuyerGLN: '3210987654321',
173
+ },
174
+ { LineTag: 'LIN', LineNumber: 1, ActionCode: '"1"', GTIN: '5400977135395', OrderedQuantity: 3, ConfirmedQuantity: 3, PurchasePriceNet: 37.25 },
175
+ { LineTag: 'LIN', LineNumber: 2, ActionCode: '"1"', GTIN: '5400977135326', OrderedQuantity: 2, ConfirmedQuantity: 2, PurchasePriceNet: 37.1 },
176
+ ])
177
+ })
178
+ it('should perform csv conversion for a FashionUnited 5.00 ordrsp', () => {
179
+ const order = itemsToOrdRsp(testOrderItems, '1234567890123', '3210987654321', '1122334455667', 12345, '20240315', 'ORD-12345')
180
+ const csv = ordRspToCsv(order).split('\n')
181
+ expect(ordRspToCsv([])).to.be.deep.equal('')
182
+ expect(csv[0]).to.be.deep.equal('"ENV",1234567890123,3210987654321,12345,0,"FUEB 5.00",,,,,')
183
+ expect(csv[1]).to.be.deep.equal(
184
+ '"HDR","231","29","12345",,,,,,,,,"ORD-12345",,,,,,,,,"EUR",1122334455667,,,,,,,,,3210987654321,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,'
185
+ )
186
+ expect(csv[2]).to.be.deep.equal('"LIN",1,1,5400977135395,,,,,,3,,3,,,,,,,,37.25,,,,,,,,,,,,,,,,,,,,,,,')
187
+ expect(csv[3]).to.be.deep.equal('"LIN",2,1,5400977135326,,,,,,2,,2,,,,,,,,37.1,,,,,,,,,,,,,,,,,,,,,,,')
188
+ })
189
+ })