b2m-utils 0.0.231 → 0.0.234
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/build/index.esm.js +55 -17
- package/build/index.esm.js.gz +0 -0
- package/build/index.esm.js.map +1 -1
- package/build/index.js +55 -17
- package/build/index.js.gz +0 -0
- package/build/index.js.map +1 -1
- package/package.json +1 -1
package/build/index.esm.js
CHANGED
|
@@ -218,12 +218,12 @@ var getRatecardFromCte = function (cte) {
|
|
|
218
218
|
var _a, _b, _c, _d, _e, _f, _g;
|
|
219
219
|
var ratecard = null;
|
|
220
220
|
if (((_a = cte.carrier) === null || _a === void 0 ? void 0 : _a.Ratecard) && ((_c = (_b = cte.carrier) === null || _b === void 0 ? void 0 : _b.Ratecard) === null || _c === void 0 ? void 0 : _c.length) > 0) {
|
|
221
|
-
var
|
|
221
|
+
var emissionDate_1 = cte.emissionDate ? new Date(cte.emissionDate) : new Date();
|
|
222
222
|
switch (cte.ratecardModalId) {
|
|
223
223
|
case RatecardModalEnum.ROAD_DOMESTIC_FTL:
|
|
224
224
|
var ratecardForRoadFTL = cte.carrier.Ratecard.find(function (ratecard) {
|
|
225
225
|
var _a;
|
|
226
|
-
var isValidDate = (ratecard === null || ratecard === void 0 ? void 0 : ratecard.startsAt) && (ratecard === null || ratecard === void 0 ? void 0 : ratecard.endsAt) &&
|
|
226
|
+
var isValidDate = (ratecard === null || ratecard === void 0 ? void 0 : ratecard.startsAt) && (ratecard === null || ratecard === void 0 ? void 0 : ratecard.endsAt) && emissionDate_1 >= new Date(ratecard.startsAt) && emissionDate_1 <= new Date(ratecard.endsAt);
|
|
227
227
|
var isValidModal = (ratecard === null || ratecard === void 0 ? void 0 : ratecard.modalId) === cte.ratecardModalId;
|
|
228
228
|
var hasOriginCity = (_a = ratecard === null || ratecard === void 0 ? void 0 : ratecard.ratecard_origin_cities) === null || _a === void 0 ? void 0 : _a.some(function (city) { return city.cityId === cte.cityOriginId; });
|
|
229
229
|
return isValidDate && isValidModal && hasOriginCity;
|
|
@@ -235,7 +235,7 @@ var getRatecardFromCte = function (cte) {
|
|
|
235
235
|
// Rota inversa: Verificar se cidade de destino está em ratecard_origin_cities
|
|
236
236
|
var reverseRatecardForRoadFTL = cte.carrier.Ratecard.find(function (ratecard) {
|
|
237
237
|
var _a;
|
|
238
|
-
var isValidDate = (ratecard === null || ratecard === void 0 ? void 0 : ratecard.startsAt) && (ratecard === null || ratecard === void 0 ? void 0 : ratecard.endsAt) &&
|
|
238
|
+
var isValidDate = (ratecard === null || ratecard === void 0 ? void 0 : ratecard.startsAt) && (ratecard === null || ratecard === void 0 ? void 0 : ratecard.endsAt) && emissionDate_1 >= new Date(ratecard.startsAt) && emissionDate_1 <= new Date(ratecard.endsAt);
|
|
239
239
|
var isValidModal = (ratecard === null || ratecard === void 0 ? void 0 : ratecard.modalId) === cte.ratecardModalId;
|
|
240
240
|
var hasDestinationCity = (_a = ratecard === null || ratecard === void 0 ? void 0 : ratecard.ratecard_origin_cities) === null || _a === void 0 ? void 0 : _a.some(function (city) { return city.cityId === cte.cityDestinationId; });
|
|
241
241
|
return isValidDate && isValidModal && hasDestinationCity;
|
|
@@ -251,7 +251,7 @@ var getRatecardFromCte = function (cte) {
|
|
|
251
251
|
var originUf_1 = (_g = (_f = cte.cityOrigin) === null || _f === void 0 ? void 0 : _f.state) === null || _g === void 0 ? void 0 : _g.uf;
|
|
252
252
|
var ratecardFromThisYear = cte.carrier.Ratecard.find(function (ratecard) {
|
|
253
253
|
var _a;
|
|
254
|
-
var isValidDate = (ratecard === null || ratecard === void 0 ? void 0 : ratecard.startsAt) && (ratecard === null || ratecard === void 0 ? void 0 : ratecard.endsAt) &&
|
|
254
|
+
var isValidDate = (ratecard === null || ratecard === void 0 ? void 0 : ratecard.startsAt) && (ratecard === null || ratecard === void 0 ? void 0 : ratecard.endsAt) && emissionDate_1 >= new Date(ratecard.startsAt) && emissionDate_1 <= new Date(ratecard.endsAt);
|
|
255
255
|
var isValidModal = (ratecard === null || ratecard === void 0 ? void 0 : ratecard.modalId) === cte.ratecardModalId;
|
|
256
256
|
// Verificar se existe lane com a rota (cityOriginId -> ufDestination)
|
|
257
257
|
var hasDirectLane = (_a = ratecard === null || ratecard === void 0 ? void 0 : ratecard.RatecardLane) === null || _a === void 0 ? void 0 : _a.some(function (lane) {
|
|
@@ -266,7 +266,7 @@ var getRatecardFromCte = function (cte) {
|
|
|
266
266
|
// Rota reversa: Verificar se existe lane com rota inversa (cityDestinationId -> originUf)
|
|
267
267
|
var reverseRatecardFromThisYear = cte.carrier.Ratecard.find(function (ratecard) {
|
|
268
268
|
var _a;
|
|
269
|
-
var isValidDate = (ratecard === null || ratecard === void 0 ? void 0 : ratecard.startsAt) && (ratecard === null || ratecard === void 0 ? void 0 : ratecard.endsAt) &&
|
|
269
|
+
var isValidDate = (ratecard === null || ratecard === void 0 ? void 0 : ratecard.startsAt) && (ratecard === null || ratecard === void 0 ? void 0 : ratecard.endsAt) && emissionDate_1 >= new Date(ratecard.startsAt) && emissionDate_1 <= new Date(ratecard.endsAt);
|
|
270
270
|
var isValidModal = (ratecard === null || ratecard === void 0 ? void 0 : ratecard.modalId) === cte.ratecardModalId;
|
|
271
271
|
// Verificar se existe lane com a rota inversa (cityDestinationId -> originUf)
|
|
272
272
|
var hasReverseLane = (_a = ratecard === null || ratecard === void 0 ? void 0 : ratecard.RatecardLane) === null || _a === void 0 ? void 0 : _a.some(function (lane) {
|
|
@@ -417,7 +417,7 @@ var filterSiblingFees = function (fees) {
|
|
|
417
417
|
};
|
|
418
418
|
|
|
419
419
|
var calculateFee = function (ratecardLaneFee, cte, allFees, debug, allFeesForCalc) {
|
|
420
|
-
var _a, _b, _c, _d;
|
|
420
|
+
var _a, _b, _c, _d, _e, _f;
|
|
421
421
|
if (debug === void 0) { debug = false; }
|
|
422
422
|
if (ratecardLaneFee.fee) {
|
|
423
423
|
var value = ratecardLaneFee.value, fee_1 = ratecardLaneFee.fee;
|
|
@@ -489,7 +489,7 @@ var calculateFee = function (ratecardLaneFee, cte, allFees, debug, allFeesForCal
|
|
|
489
489
|
if (totalValueFromAllFees && !isNaN(+totalValueFromAllFees)) {
|
|
490
490
|
var valueToMultiply = (+value / 100);
|
|
491
491
|
var total_1 = +totalValueFromAllFees * valueToMultiply;
|
|
492
|
-
var
|
|
492
|
+
var _g = applyRedeliveryMultiplier(total_1, cte), adjustedTotal_1 = _g.adjustedTotal, redeliveryInfo_1 = _g.redeliveryInfo;
|
|
493
493
|
total_1 = adjustedTotal_1;
|
|
494
494
|
var totalValueFromAllFeesCurrency = convertNumberToCurrency(+totalValueFromAllFees, 'pt-br');
|
|
495
495
|
var resultCurrency_1 = (+total_1).toLocaleString('pt-BR', {
|
|
@@ -507,7 +507,7 @@ var calculateFee = function (ratecardLaneFee, cte, allFees, debug, allFeesForCal
|
|
|
507
507
|
if ((cte === null || cte === void 0 ? void 0 : cte.taxedWeight) && !isNaN(+(cte === null || cte === void 0 ? void 0 : cte.taxedWeight))) {
|
|
508
508
|
var fractions = Math.ceil(+cte.taxedWeight / 100);
|
|
509
509
|
var total_2 = fractions * value;
|
|
510
|
-
var
|
|
510
|
+
var _h = applyRedeliveryMultiplier(total_2, cte), adjustedTotal_2 = _h.adjustedTotal, redeliveryInfo_2 = _h.redeliveryInfo;
|
|
511
511
|
total_2 = adjustedTotal_2;
|
|
512
512
|
var valueCurrency_1 = (+value).toLocaleString('pt-br', {
|
|
513
513
|
style: 'currency',
|
|
@@ -526,7 +526,7 @@ var calculateFee = function (ratecardLaneFee, cte, allFees, debug, allFeesForCal
|
|
|
526
526
|
if (value && (cte === null || cte === void 0 ? void 0 : cte.freightValue)) {
|
|
527
527
|
if (!isNaN(+value) && !isNaN(+cte.freightValue)) {
|
|
528
528
|
var total_3 = +cte.freightValue * (+value / 100);
|
|
529
|
-
var
|
|
529
|
+
var _j = applyRedeliveryMultiplier(total_3, cte), adjustedTotal_3 = _j.adjustedTotal, redeliveryInfo_3 = _j.redeliveryInfo;
|
|
530
530
|
total_3 = adjustedTotal_3;
|
|
531
531
|
var freightValueCurrency = (+cte.freightValue).toLocaleString('pt-br', {
|
|
532
532
|
style: 'currency',
|
|
@@ -561,7 +561,7 @@ var calculateFee = function (ratecardLaneFee, cte, allFees, debug, allFeesForCal
|
|
|
561
561
|
case FeeCalculationTypeEnum.MIN_VALUE:
|
|
562
562
|
case FeeCalculationTypeEnum.FIXED:
|
|
563
563
|
var total = +value;
|
|
564
|
-
var
|
|
564
|
+
var _k = applyRedeliveryMultiplier(total, cte), adjustedTotal = _k.adjustedTotal, redeliveryInfo = _k.redeliveryInfo;
|
|
565
565
|
total = adjustedTotal;
|
|
566
566
|
var valueCurrency = (+value).toLocaleString('pt-br', {
|
|
567
567
|
style: 'currency',
|
|
@@ -613,7 +613,7 @@ var calculateFee = function (ratecardLaneFee, cte, allFees, debug, allFeesForCal
|
|
|
613
613
|
// Somar ao total
|
|
614
614
|
total_4 += additionalValue;
|
|
615
615
|
// Aplicar multiplicador de redelivery ao valor final
|
|
616
|
-
var
|
|
616
|
+
var _l = applyRedeliveryMultiplier(total_4, cte), adjustedTotal_4 = _l.adjustedTotal, redeliveryInfo_4 = _l.redeliveryInfo;
|
|
617
617
|
total_4 = adjustedTotal_4;
|
|
618
618
|
var valueCurrency_2 = (+highestIntervalFee.value).toLocaleString('pt-br', {
|
|
619
619
|
style: 'currency',
|
|
@@ -630,6 +630,21 @@ var calculateFee = function (ratecardLaneFee, cte, allFees, debug, allFeesForCal
|
|
|
630
630
|
}
|
|
631
631
|
// Lógica de intervalo de KM para FTL
|
|
632
632
|
else if ((cte === null || cte === void 0 ? void 0 : cte.ratecardModalId) === RatecardModalEnum.ROAD_DOMESTIC_FTL && (cte === null || cte === void 0 ? void 0 : cte.distance) && !ratecardLaneFee.maxKm && ratecardLaneFee.minKm && +cte.distance >= +ratecardLaneFee.minKm) {
|
|
633
|
+
console.log('[calculateFee] FTL - Entrando no condicional de intervalo KM', {
|
|
634
|
+
cteId: cte.id,
|
|
635
|
+
cteNumber: cte.number,
|
|
636
|
+
ratecardModalId: cte.ratecardModalId,
|
|
637
|
+
distance: cte.distance,
|
|
638
|
+
ratecardLaneFee: {
|
|
639
|
+
id: ratecardLaneFee.id,
|
|
640
|
+
feeId: (_a = ratecardLaneFee.fee) === null || _a === void 0 ? void 0 : _a.id,
|
|
641
|
+
feeName: (_b = ratecardLaneFee.fee) === null || _b === void 0 ? void 0 : _b.name,
|
|
642
|
+
value: ratecardLaneFee.value,
|
|
643
|
+
minKm: ratecardLaneFee.minKm,
|
|
644
|
+
maxKm: ratecardLaneFee.maxKm,
|
|
645
|
+
},
|
|
646
|
+
allFeesForCalcCount: allFeesForCalc === null || allFeesForCalc === void 0 ? void 0 : allFeesForCalc.length,
|
|
647
|
+
});
|
|
633
648
|
// Não tem maxKm - é o último intervalo
|
|
634
649
|
// Encontrar todas as taxas do mesmo tipo que têm maxKm
|
|
635
650
|
var feesWithMaxKm = allFeesForCalc === null || allFeesForCalc === void 0 ? void 0 : allFeesForCalc.filter(function (fee) {
|
|
@@ -639,10 +654,33 @@ var calculateFee = function (ratecardLaneFee, cte, allFees, debug, allFeesForCal
|
|
|
639
654
|
(cte === null || cte === void 0 ? void 0 : cte.distance) &&
|
|
640
655
|
+fee.maxKm < +cte.distance;
|
|
641
656
|
});
|
|
657
|
+
console.log('[calculateFee] FTL - Fees com maxKm encontradas', {
|
|
658
|
+
cteId: cte.id,
|
|
659
|
+
feesWithMaxKmCount: feesWithMaxKm === null || feesWithMaxKm === void 0 ? void 0 : feesWithMaxKm.length,
|
|
660
|
+
feesWithMaxKm: feesWithMaxKm === null || feesWithMaxKm === void 0 ? void 0 : feesWithMaxKm.map(function (f) { return ({
|
|
661
|
+
id: f.id,
|
|
662
|
+
value: f.value,
|
|
663
|
+
minKm: f.minKm,
|
|
664
|
+
maxKm: f.maxKm,
|
|
665
|
+
}); }),
|
|
666
|
+
});
|
|
667
|
+
console.log({
|
|
668
|
+
cte: cte,
|
|
669
|
+
});
|
|
642
670
|
// Ordenar pelo maxKm do maior para o menor
|
|
643
671
|
feesWithMaxKm === null || feesWithMaxKm === void 0 ? void 0 : feesWithMaxKm.sort(function (a, b) { return b.maxKm - a.maxKm; });
|
|
644
672
|
// Pegar o primeiro (maior maxKm)
|
|
645
673
|
var highestIntervalFee = feesWithMaxKm === null || feesWithMaxKm === void 0 ? void 0 : feesWithMaxKm[0];
|
|
674
|
+
console.log('[calculateFee] FTL - Maior intervalo selecionado', {
|
|
675
|
+
cteId: cte.id,
|
|
676
|
+
hasHighestIntervalFee: !!highestIntervalFee,
|
|
677
|
+
highestIntervalFee: highestIntervalFee ? {
|
|
678
|
+
id: highestIntervalFee.id,
|
|
679
|
+
value: highestIntervalFee.value,
|
|
680
|
+
minKm: highestIntervalFee.minKm,
|
|
681
|
+
maxKm: highestIntervalFee.maxKm,
|
|
682
|
+
} : null,
|
|
683
|
+
});
|
|
646
684
|
if (highestIntervalFee) {
|
|
647
685
|
// Calcula baseado na taxa do intervalo mais alto que tem maxKm
|
|
648
686
|
var total_5 = +highestIntervalFee.value;
|
|
@@ -653,7 +691,7 @@ var calculateFee = function (ratecardLaneFee, cte, allFees, debug, allFeesForCal
|
|
|
653
691
|
// Somar ao total
|
|
654
692
|
total_5 += additionalValue;
|
|
655
693
|
// Aplicar multiplicador de redelivery ao valor final
|
|
656
|
-
var
|
|
694
|
+
var _m = applyRedeliveryMultiplier(total_5, cte), adjustedTotal_5 = _m.adjustedTotal, redeliveryInfo_5 = _m.redeliveryInfo;
|
|
657
695
|
total_5 = adjustedTotal_5;
|
|
658
696
|
var valueCurrency_3 = (+highestIntervalFee.value).toLocaleString('pt-br', {
|
|
659
697
|
style: 'currency',
|
|
@@ -671,9 +709,9 @@ var calculateFee = function (ratecardLaneFee, cte, allFees, debug, allFeesForCal
|
|
|
671
709
|
break;
|
|
672
710
|
case FeeCalculationTypeEnum.COMMODITY_VALUE:
|
|
673
711
|
if (value) {
|
|
674
|
-
var commodityValue = (
|
|
712
|
+
var commodityValue = (_c = cte === null || cte === void 0 ? void 0 : cte.commodityValue) !== null && _c !== void 0 ? _c : 0;
|
|
675
713
|
var total_6 = +commodityValue * (+value / 100);
|
|
676
|
-
var
|
|
714
|
+
var _o = applyRedeliveryMultiplier(total_6, cte), adjustedTotal_6 = _o.adjustedTotal, redeliveryInfo_6 = _o.redeliveryInfo;
|
|
677
715
|
total_6 = adjustedTotal_6;
|
|
678
716
|
var resultCurrency_6 = (+total_6).toLocaleString('pt-br', {
|
|
679
717
|
style: 'currency',
|
|
@@ -686,9 +724,9 @@ var calculateFee = function (ratecardLaneFee, cte, allFees, debug, allFeesForCal
|
|
|
686
724
|
break;
|
|
687
725
|
case FeeCalculationTypeEnum.TAXED_WEIGHT:
|
|
688
726
|
if (value) {
|
|
689
|
-
var taxedWeight = (
|
|
727
|
+
var taxedWeight = (_d = cte === null || cte === void 0 ? void 0 : cte.taxedWeight) !== null && _d !== void 0 ? _d : 0;
|
|
690
728
|
var total_7 = +taxedWeight * +value;
|
|
691
|
-
var
|
|
729
|
+
var _p = applyRedeliveryMultiplier(total_7, cte), adjustedTotal_7 = _p.adjustedTotal, redeliveryInfo_7 = _p.redeliveryInfo;
|
|
692
730
|
total_7 = adjustedTotal_7;
|
|
693
731
|
var resultCurrency_7 = (+total_7).toLocaleString('pt-br', {
|
|
694
732
|
style: 'currency',
|
|
@@ -804,7 +842,7 @@ var calculateFee = function (ratecardLaneFee, cte, allFees, debug, allFeesForCal
|
|
|
804
842
|
return 0;
|
|
805
843
|
});
|
|
806
844
|
if ((siblingFeesResults === null || siblingFeesResults === void 0 ? void 0 : siblingFeesResults.length) > 0) {
|
|
807
|
-
if (((
|
|
845
|
+
if (((_e = siblingFeesResults[0]) === null || _e === void 0 ? void 0 : _e.totalFee) && ((_f = siblingFeesResults[0]) === null || _f === void 0 ? void 0 : _f.totalFee) > totalFee) {
|
|
808
846
|
totalToCalc = 0;
|
|
809
847
|
}
|
|
810
848
|
}
|
package/build/index.esm.js.gz
CHANGED
|
Binary file
|