@softwear/latestcollectioncore 1.0.103 → 1.0.105
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/articleStatus.d.ts +1 -0
- package/dist/articleStatus.js +73 -9
- package/dist/types.d.ts +4 -0
- package/package.json +1 -1
- package/src/articleStatus.ts +73 -7
- package/src/types.ts +4 -0
- package/test/articleStatus.spec.js +28 -0
package/dist/articleStatus.d.ts
CHANGED
|
@@ -17,6 +17,7 @@ declare function getTimeGrouper(groupers: string[]): TimeGranularityE | undefine
|
|
|
17
17
|
declare function runQuery(timeframe: HrTimeframeI, rawAggregations: RaGI, beginStock: boolean, transactions: TransactionI[], selectedGroupsValues: string[], skus: SkuI[], warehouses: any[], customers: any[], subtotalsForOuterGrouper: boolean, computedFilter: string, parentGroupTotals: boolean): RaGI;
|
|
18
18
|
declare const _default: {
|
|
19
19
|
getDateRangeFromPicker: (inputDates: string[]) => HrTimeframeI;
|
|
20
|
+
getDateRangeFromDatePair: (inputDates: string[]) => HrTimeframeI;
|
|
20
21
|
getTimeGrouper: typeof getTimeGrouper;
|
|
21
22
|
filtrexOptions: {
|
|
22
23
|
extraFunctions: {
|
package/dist/articleStatus.js
CHANGED
|
@@ -231,21 +231,21 @@ function whichShardsToProcess(dateRange, granularity) {
|
|
|
231
231
|
};
|
|
232
232
|
const result = [];
|
|
233
233
|
if (granularity == 'year')
|
|
234
|
-
for (let year = dateRange.
|
|
234
|
+
for (let year = dateRange.utcFromYear; year <= dateRange.utcToYear; year++)
|
|
235
235
|
result.push(year);
|
|
236
236
|
else
|
|
237
|
-
for (let year = dateRange.
|
|
238
|
-
if (year == dateRange.
|
|
239
|
-
for (let month = dateRange.
|
|
237
|
+
for (let year = dateRange.utcFromYear; year <= dateRange.utcToYear; year++) {
|
|
238
|
+
if (year == dateRange.utcFromYear && year < dateRange.utcToYear)
|
|
239
|
+
for (let month = dateRange.utcFromMonth; month <= 12; month++)
|
|
240
240
|
result.push('' + year + '' + padl(month));
|
|
241
|
-
if (year == dateRange.
|
|
242
|
-
for (let month = dateRange.
|
|
241
|
+
if (year == dateRange.utcFromYear && year == dateRange.utcToYear)
|
|
242
|
+
for (let month = dateRange.utcFromMonth; month <= dateRange.utcToMonth; month++)
|
|
243
243
|
result.push('' + year + '' + padl(month));
|
|
244
|
-
if (year != dateRange.
|
|
244
|
+
if (year != dateRange.utcFromYear && year != dateRange.utcToYear)
|
|
245
245
|
for (let month = 1; month <= 12; month++)
|
|
246
246
|
result.push('' + year + '' + padl(month));
|
|
247
|
-
if (year != dateRange.
|
|
248
|
-
for (let month = 1; month <= dateRange.
|
|
247
|
+
if (year != dateRange.utcFromYear && year == dateRange.utcToYear)
|
|
248
|
+
for (let month = 1; month <= dateRange.utcToMonth; month++)
|
|
249
249
|
result.push('' + year + '' + padl(month));
|
|
250
250
|
}
|
|
251
251
|
return result;
|
|
@@ -335,12 +335,19 @@ function runQuery(timeframe, rawAggregations, beginStock, transactions, selected
|
|
|
335
335
|
}
|
|
336
336
|
return rawAggregations;
|
|
337
337
|
}
|
|
338
|
+
/**
|
|
339
|
+
* @param inputDates array of two YYYY-MM-DD strings
|
|
340
|
+
*/
|
|
338
341
|
const getDateRangeFromPicker = function (inputDates) {
|
|
339
342
|
if (!Array.isArray(inputDates))
|
|
340
343
|
return {
|
|
341
344
|
beginTimeStamp: 0,
|
|
342
345
|
endTimeStamp: 0,
|
|
343
346
|
timeFrame: 0,
|
|
347
|
+
utcFromYear: 0,
|
|
348
|
+
utcToYear: 0,
|
|
349
|
+
utcFromMonth: 0,
|
|
350
|
+
utcToMonth: 0,
|
|
344
351
|
fromYear: 0,
|
|
345
352
|
toYear: 0,
|
|
346
353
|
fromMonth: 0,
|
|
@@ -365,6 +372,62 @@ const getDateRangeFromPicker = function (inputDates) {
|
|
|
365
372
|
beginTimeStamp,
|
|
366
373
|
endTimeStamp,
|
|
367
374
|
timeFrame,
|
|
375
|
+
utcFromYear: fromDate.getUTCFullYear(),
|
|
376
|
+
utcToYear: toDate.getUTCFullYear(),
|
|
377
|
+
utcFromMonth: fromDate.getUTCMonth(),
|
|
378
|
+
utcToMonth: toDate.getUTCMonth(),
|
|
379
|
+
fromYear: parseInt((0, date_fns_1.format)(fromDate, 'yyyy')),
|
|
380
|
+
toYear: toDate.getUTCFullYear(),
|
|
381
|
+
fromMonth: parseInt((0, date_fns_1.format)(fromDate, 'MM')),
|
|
382
|
+
toMonth: parseInt((0, date_fns_1.format)(toDate, 'MM')),
|
|
383
|
+
hrYear: (0, date_fns_1.format)(fromDate, 'yyyy'),
|
|
384
|
+
hrQuarter: (0, date_fns_1.format)(fromDate, 'yyyy-QQQ'),
|
|
385
|
+
hrMonth: (0, date_fns_1.format)(fromDate, 'yyyy-MM'),
|
|
386
|
+
hrWeek: (0, date_fns_1.format)(fromDate, 'RRRR-II'),
|
|
387
|
+
hrDay: (0, date_fns_1.format)(fromDate, 'yyyy-MM-dd'),
|
|
388
|
+
};
|
|
389
|
+
};
|
|
390
|
+
/**
|
|
391
|
+
* @param inputDates array of two ISO Date strings
|
|
392
|
+
*/
|
|
393
|
+
const getDateRangeFromDatePair = function (inputDates) {
|
|
394
|
+
if (!Array.isArray(inputDates))
|
|
395
|
+
return {
|
|
396
|
+
beginTimeStamp: 0,
|
|
397
|
+
endTimeStamp: 0,
|
|
398
|
+
timeFrame: 0,
|
|
399
|
+
utcFromYear: 0,
|
|
400
|
+
utcToYear: 0,
|
|
401
|
+
utcFromMonth: 0,
|
|
402
|
+
utcToMonth: 0,
|
|
403
|
+
fromYear: 0,
|
|
404
|
+
toYear: 0,
|
|
405
|
+
fromMonth: 0,
|
|
406
|
+
toMonth: 0,
|
|
407
|
+
hrYear: '',
|
|
408
|
+
hrQuarter: '',
|
|
409
|
+
hrMonth: '',
|
|
410
|
+
hrWeek: '',
|
|
411
|
+
hrDay: '',
|
|
412
|
+
};
|
|
413
|
+
const dates = inputDates.slice();
|
|
414
|
+
dates.sort((a, b) => {
|
|
415
|
+
return ('' + a).localeCompare(b);
|
|
416
|
+
});
|
|
417
|
+
const fromDate = new Date(Date.parse(dates[0]));
|
|
418
|
+
fromDate.setSeconds(fromDate.getSeconds());
|
|
419
|
+
const toDate = new Date(Date.parse(dates[1]));
|
|
420
|
+
const beginTimeStamp = fromDate.getTime();
|
|
421
|
+
const endTimeStamp = toDate.getTime();
|
|
422
|
+
const timeFrame = endTimeStamp - beginTimeStamp;
|
|
423
|
+
return {
|
|
424
|
+
beginTimeStamp,
|
|
425
|
+
endTimeStamp,
|
|
426
|
+
timeFrame,
|
|
427
|
+
utcFromYear: fromDate.getUTCFullYear(),
|
|
428
|
+
utcToYear: toDate.getUTCFullYear(),
|
|
429
|
+
utcFromMonth: fromDate.getUTCMonth(),
|
|
430
|
+
utcToMonth: toDate.getUTCMonth(),
|
|
368
431
|
fromYear: parseInt((0, date_fns_1.format)(fromDate, 'yyyy')),
|
|
369
432
|
toYear: parseInt((0, date_fns_1.format)(toDate, 'yyyy')),
|
|
370
433
|
fromMonth: parseInt((0, date_fns_1.format)(fromDate, 'MM')),
|
|
@@ -378,6 +441,7 @@ const getDateRangeFromPicker = function (inputDates) {
|
|
|
378
441
|
};
|
|
379
442
|
exports.default = {
|
|
380
443
|
getDateRangeFromPicker,
|
|
444
|
+
getDateRangeFromDatePair,
|
|
381
445
|
getTimeGrouper,
|
|
382
446
|
filtrexOptions,
|
|
383
447
|
postAgg,
|
package/dist/types.d.ts
CHANGED
|
@@ -304,6 +304,10 @@ interface HrTimeframeI {
|
|
|
304
304
|
beginTimeStamp: number;
|
|
305
305
|
endTimeStamp: number;
|
|
306
306
|
timeFrame: number;
|
|
307
|
+
utcFromYear: number;
|
|
308
|
+
utcToYear: number;
|
|
309
|
+
utcFromMonth: number;
|
|
310
|
+
utcToMonth: number;
|
|
307
311
|
fromYear: number;
|
|
308
312
|
toYear: number;
|
|
309
313
|
fromMonth: number;
|
package/package.json
CHANGED
package/src/articleStatus.ts
CHANGED
|
@@ -304,14 +304,14 @@ function whichShardsToProcess(dateRange: any, granularity: 'year' | 'month'): an
|
|
|
304
304
|
return '0' + s
|
|
305
305
|
}
|
|
306
306
|
const result = [] as any[]
|
|
307
|
-
if (granularity == 'year') for (let year = dateRange.
|
|
307
|
+
if (granularity == 'year') for (let year = dateRange.utcFromYear; year <= dateRange.utcToYear; year++) result.push(year)
|
|
308
308
|
else
|
|
309
|
-
for (let year = dateRange.
|
|
310
|
-
if (year == dateRange.
|
|
311
|
-
if (year == dateRange.
|
|
312
|
-
for (let month = dateRange.
|
|
313
|
-
if (year != dateRange.
|
|
314
|
-
if (year != dateRange.
|
|
309
|
+
for (let year = dateRange.utcFromYear; year <= dateRange.utcToYear; year++) {
|
|
310
|
+
if (year == dateRange.utcFromYear && year < dateRange.utcToYear) for (let month = dateRange.utcFromMonth; month <= 12; month++) result.push('' + year + '' + padl(month))
|
|
311
|
+
if (year == dateRange.utcFromYear && year == dateRange.utcToYear)
|
|
312
|
+
for (let month = dateRange.utcFromMonth; month <= dateRange.utcToMonth; month++) result.push('' + year + '' + padl(month))
|
|
313
|
+
if (year != dateRange.utcFromYear && year != dateRange.utcToYear) for (let month = 1; month <= 12; month++) result.push('' + year + '' + padl(month))
|
|
314
|
+
if (year != dateRange.utcFromYear && year == dateRange.utcToYear) for (let month = 1; month <= dateRange.utcToMonth; month++) result.push('' + year + '' + padl(month))
|
|
315
315
|
}
|
|
316
316
|
return result
|
|
317
317
|
}
|
|
@@ -405,12 +405,19 @@ function runQuery(
|
|
|
405
405
|
return rawAggregations
|
|
406
406
|
}
|
|
407
407
|
|
|
408
|
+
/**
|
|
409
|
+
* @param inputDates array of two YYYY-MM-DD strings
|
|
410
|
+
*/
|
|
408
411
|
const getDateRangeFromPicker = function (inputDates: string[]): HrTimeframeI {
|
|
409
412
|
if (!Array.isArray(inputDates))
|
|
410
413
|
return {
|
|
411
414
|
beginTimeStamp: 0,
|
|
412
415
|
endTimeStamp: 0,
|
|
413
416
|
timeFrame: 0,
|
|
417
|
+
utcFromYear: 0,
|
|
418
|
+
utcToYear: 0,
|
|
419
|
+
utcFromMonth: 0,
|
|
420
|
+
utcToMonth: 0,
|
|
414
421
|
fromYear: 0,
|
|
415
422
|
toYear: 0,
|
|
416
423
|
fromMonth: 0,
|
|
@@ -436,6 +443,64 @@ const getDateRangeFromPicker = function (inputDates: string[]): HrTimeframeI {
|
|
|
436
443
|
beginTimeStamp,
|
|
437
444
|
endTimeStamp,
|
|
438
445
|
timeFrame,
|
|
446
|
+
utcFromYear: fromDate.getUTCFullYear(),
|
|
447
|
+
utcToYear: toDate.getUTCFullYear(),
|
|
448
|
+
utcFromMonth: fromDate.getUTCMonth(),
|
|
449
|
+
utcToMonth: toDate.getUTCMonth(),
|
|
450
|
+
fromYear: parseInt(format(fromDate, 'yyyy')),
|
|
451
|
+
toYear: toDate.getUTCFullYear(),
|
|
452
|
+
fromMonth: parseInt(format(fromDate, 'MM')),
|
|
453
|
+
toMonth: parseInt(format(toDate, 'MM')),
|
|
454
|
+
hrYear: format(fromDate, 'yyyy'),
|
|
455
|
+
hrQuarter: format(fromDate, 'yyyy-QQQ'),
|
|
456
|
+
hrMonth: format(fromDate, 'yyyy-MM'),
|
|
457
|
+
hrWeek: format(fromDate, 'RRRR-II'),
|
|
458
|
+
hrDay: format(fromDate, 'yyyy-MM-dd'),
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
/**
|
|
463
|
+
* @param inputDates array of two ISO Date strings
|
|
464
|
+
*/
|
|
465
|
+
const getDateRangeFromDatePair = function (inputDates: string[]): HrTimeframeI {
|
|
466
|
+
if (!Array.isArray(inputDates))
|
|
467
|
+
return {
|
|
468
|
+
beginTimeStamp: 0,
|
|
469
|
+
endTimeStamp: 0,
|
|
470
|
+
timeFrame: 0,
|
|
471
|
+
utcFromYear: 0,
|
|
472
|
+
utcToYear: 0,
|
|
473
|
+
utcFromMonth: 0,
|
|
474
|
+
utcToMonth: 0,
|
|
475
|
+
fromYear: 0,
|
|
476
|
+
toYear: 0,
|
|
477
|
+
fromMonth: 0,
|
|
478
|
+
toMonth: 0,
|
|
479
|
+
hrYear: '',
|
|
480
|
+
hrQuarter: '',
|
|
481
|
+
hrMonth: '',
|
|
482
|
+
hrWeek: '',
|
|
483
|
+
hrDay: '',
|
|
484
|
+
}
|
|
485
|
+
const dates = inputDates.slice()
|
|
486
|
+
dates.sort((a, b) => {
|
|
487
|
+
return ('' + a).localeCompare(b)
|
|
488
|
+
})
|
|
489
|
+
const fromDate = new Date(Date.parse(dates[0]))
|
|
490
|
+
fromDate.setSeconds(fromDate.getSeconds())
|
|
491
|
+
|
|
492
|
+
const toDate = new Date(Date.parse(dates[1]))
|
|
493
|
+
const beginTimeStamp = fromDate.getTime()
|
|
494
|
+
const endTimeStamp = toDate.getTime()
|
|
495
|
+
const timeFrame = endTimeStamp - beginTimeStamp
|
|
496
|
+
return {
|
|
497
|
+
beginTimeStamp,
|
|
498
|
+
endTimeStamp,
|
|
499
|
+
timeFrame,
|
|
500
|
+
utcFromYear: fromDate.getUTCFullYear(),
|
|
501
|
+
utcToYear: toDate.getUTCFullYear(),
|
|
502
|
+
utcFromMonth: fromDate.getUTCMonth(),
|
|
503
|
+
utcToMonth: toDate.getUTCMonth(),
|
|
439
504
|
fromYear: parseInt(format(fromDate, 'yyyy')),
|
|
440
505
|
toYear: parseInt(format(toDate, 'yyyy')),
|
|
441
506
|
fromMonth: parseInt(format(fromDate, 'MM')),
|
|
@@ -450,6 +515,7 @@ const getDateRangeFromPicker = function (inputDates: string[]): HrTimeframeI {
|
|
|
450
515
|
|
|
451
516
|
export default {
|
|
452
517
|
getDateRangeFromPicker,
|
|
518
|
+
getDateRangeFromDatePair,
|
|
453
519
|
getTimeGrouper,
|
|
454
520
|
filtrexOptions,
|
|
455
521
|
postAgg,
|
package/src/types.ts
CHANGED
|
@@ -323,6 +323,10 @@ interface HrTimeframeI {
|
|
|
323
323
|
beginTimeStamp: number
|
|
324
324
|
endTimeStamp: number
|
|
325
325
|
timeFrame: number
|
|
326
|
+
utcFromYear: number
|
|
327
|
+
utcToYear: number
|
|
328
|
+
utcFromMonth: number
|
|
329
|
+
utcToMonth: number
|
|
326
330
|
fromYear: number
|
|
327
331
|
toYear: number
|
|
328
332
|
fromMonth: number
|
|
@@ -242,5 +242,33 @@ describe('#articleStatus', () => {
|
|
|
242
242
|
expect(JSON.stringify(result[2].vector[articleStatus.VALUE_AVG_STOCK])).to.equal('90.00000031709791')
|
|
243
243
|
expect(JSON.stringify(result[2].vector[articleStatus.MARGIN])).to.equal('50')
|
|
244
244
|
})
|
|
245
|
+
describe('#getDateRangeFromPicker', () => {
|
|
246
|
+
const dateRange = articleStatus.getDateRangeFromPicker(['2024-01-01', '2024-12-31'])
|
|
247
|
+
expect(dateRange.beginTimeStamp).to.equal(1704063600000)
|
|
248
|
+
expect(dateRange.fromYear).to.equal(2024)
|
|
249
|
+
expect(dateRange.fromMonth).to.equal(1)
|
|
250
|
+
expect(dateRange.toYear).to.equal(2024)
|
|
251
|
+
expect(dateRange.toMonth).to.equal(12)
|
|
252
|
+
expect(dateRange.hrYear).to.equal('2024')
|
|
253
|
+
expect(dateRange.hrQuarter).to.equal('2024-Q1')
|
|
254
|
+
expect(dateRange.hrMonth).to.equal('2024-01')
|
|
255
|
+
expect(dateRange.hrWeek).to.equal('2024-01')
|
|
256
|
+
expect(dateRange.hrDay).to.equal('2024-01-01')
|
|
257
|
+
expect(dateRange.timeFrame).to.equal(366 * 24 * 3600 * 1000)
|
|
258
|
+
})
|
|
259
|
+
describe('#getDateRangeFromDatePair', () => {
|
|
260
|
+
const dateRange = articleStatus.getDateRangeFromDatePair(['2023-12-31T23:00:00.000Z', '2024-12-31T23:00:00.000Z'])
|
|
261
|
+
expect(dateRange.beginTimeStamp).to.equal(1704063600000)
|
|
262
|
+
expect(dateRange.fromYear).to.equal(2024)
|
|
263
|
+
expect(dateRange.fromMonth).to.equal(1)
|
|
264
|
+
expect(dateRange.toYear).to.equal(2025)
|
|
265
|
+
expect(dateRange.hrQuarter).to.equal('2024-Q1')
|
|
266
|
+
expect(dateRange.toMonth).to.equal(1)
|
|
267
|
+
expect(dateRange.hrYear).to.equal('2024')
|
|
268
|
+
expect(dateRange.hrMonth).to.equal('2024-01')
|
|
269
|
+
expect(dateRange.hrWeek).to.equal('2024-01')
|
|
270
|
+
expect(dateRange.hrDay).to.equal('2024-01-01')
|
|
271
|
+
expect(dateRange.timeFrame).to.equal(366 * 24 * 3600 * 1000)
|
|
272
|
+
})
|
|
245
273
|
})
|
|
246
274
|
})
|