b2m-utils 0.0.227 → 0.0.229
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 +98 -17
- package/build/index.esm.js.gz +0 -0
- package/build/index.esm.js.map +1 -1
- package/build/index.js +98 -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
|
@@ -215,7 +215,7 @@ var TrackProcessProviderTypeEnum;
|
|
|
215
215
|
})(TrackProcessProviderTypeEnum || (TrackProcessProviderTypeEnum = {}));
|
|
216
216
|
|
|
217
217
|
var getRatecardFromCte = function (cte) {
|
|
218
|
-
var _a, _b, _c;
|
|
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
221
|
var today_1 = new Date();
|
|
@@ -246,12 +246,38 @@ var getRatecardFromCte = function (cte) {
|
|
|
246
246
|
}
|
|
247
247
|
break;
|
|
248
248
|
default:
|
|
249
|
+
// LTL: Busca principal validando rota através de RatecardLane
|
|
250
|
+
var destinationUf_1 = (_e = (_d = cte.cityDestination) === null || _d === void 0 ? void 0 : _d.state) === null || _e === void 0 ? void 0 : _e.uf;
|
|
251
|
+
var originUf_1 = (_g = (_f = cte.cityOrigin) === null || _f === void 0 ? void 0 : _f.state) === null || _g === void 0 ? void 0 : _g.uf;
|
|
249
252
|
var ratecardFromThisYear = cte.carrier.Ratecard.find(function (ratecard) {
|
|
250
|
-
|
|
253
|
+
var _a;
|
|
254
|
+
var isValidDate = (ratecard === null || ratecard === void 0 ? void 0 : ratecard.startsAt) && (ratecard === null || ratecard === void 0 ? void 0 : ratecard.endsAt) && today_1 >= new Date(ratecard.startsAt) && today_1 <= new Date(ratecard.endsAt);
|
|
255
|
+
var isValidModal = (ratecard === null || ratecard === void 0 ? void 0 : ratecard.modalId) === cte.ratecardModalId;
|
|
256
|
+
// Verificar se existe lane com a rota (cityOriginId -> ufDestination)
|
|
257
|
+
var hasDirectLane = (_a = ratecard === null || ratecard === void 0 ? void 0 : ratecard.RatecardLane) === null || _a === void 0 ? void 0 : _a.some(function (lane) {
|
|
258
|
+
return lane.cityOriginId === cte.cityOriginId && lane.ufDestination === destinationUf_1;
|
|
259
|
+
});
|
|
260
|
+
return isValidDate && isValidModal && hasDirectLane;
|
|
251
261
|
});
|
|
252
262
|
if (ratecardFromThisYear) {
|
|
253
263
|
ratecard = ratecardFromThisYear;
|
|
254
264
|
}
|
|
265
|
+
else {
|
|
266
|
+
// Rota reversa: Verificar se existe lane com rota inversa (cityDestinationId -> originUf)
|
|
267
|
+
var reverseRatecardFromThisYear = cte.carrier.Ratecard.find(function (ratecard) {
|
|
268
|
+
var _a;
|
|
269
|
+
var isValidDate = (ratecard === null || ratecard === void 0 ? void 0 : ratecard.startsAt) && (ratecard === null || ratecard === void 0 ? void 0 : ratecard.endsAt) && today_1 >= new Date(ratecard.startsAt) && today_1 <= new Date(ratecard.endsAt);
|
|
270
|
+
var isValidModal = (ratecard === null || ratecard === void 0 ? void 0 : ratecard.modalId) === cte.ratecardModalId;
|
|
271
|
+
// Verificar se existe lane com a rota inversa (cityDestinationId -> originUf)
|
|
272
|
+
var hasReverseLane = (_a = ratecard === null || ratecard === void 0 ? void 0 : ratecard.RatecardLane) === null || _a === void 0 ? void 0 : _a.some(function (lane) {
|
|
273
|
+
return lane.cityOriginId === cte.cityDestinationId && lane.ufDestination === originUf_1;
|
|
274
|
+
});
|
|
275
|
+
return isValidDate && isValidModal && hasReverseLane;
|
|
276
|
+
});
|
|
277
|
+
if (reverseRatecardFromThisYear) {
|
|
278
|
+
ratecard = reverseRatecardFromThisYear;
|
|
279
|
+
}
|
|
280
|
+
}
|
|
255
281
|
break;
|
|
256
282
|
}
|
|
257
283
|
}
|
|
@@ -536,8 +562,23 @@ var calculateFee = function (ratecardLaneFee, cte, allFees, debug, allFeesForCal
|
|
|
536
562
|
currency: 'BRL',
|
|
537
563
|
});
|
|
538
564
|
var result = "".concat(redeliveryInfo ? "".concat(valueCurrency).concat(redeliveryInfo, " = ").concat(resultCurrency) : valueCurrency);
|
|
565
|
+
// Se for FTL com distância e tiver intervalo de KM, adicionar informação na descrição
|
|
566
|
+
if ((cte === null || cte === void 0 ? void 0 : cte.ratecardModalId) === RatecardModalEnum.ROAD_DOMESTIC_FTL && (cte === null || cte === void 0 ? void 0 : cte.distance) && (ratecardLaneFee.minKm || ratecardLaneFee.maxKm)) {
|
|
567
|
+
var kmRange = ratecardLaneFee.maxKm
|
|
568
|
+
? "".concat(ratecardLaneFee.minKm || 0, "-").concat(ratecardLaneFee.maxKm, " km")
|
|
569
|
+
: "".concat(ratecardLaneFee.minKm, "+ km");
|
|
570
|
+
result = "".concat(cte.distance, " km (").concat(kmRange, ") = ").concat(redeliveryInfo ? "".concat(valueCurrency).concat(redeliveryInfo, " = ").concat(resultCurrency) : valueCurrency);
|
|
571
|
+
}
|
|
572
|
+
// Se houver taxedWeight e tiver intervalo de peso, adicionar informação na descrição
|
|
573
|
+
else if ((cte === null || cte === void 0 ? void 0 : cte.taxedWeight) && (ratecardLaneFee.minWeight || ratecardLaneFee.maxWeight)) {
|
|
574
|
+
var weightRange = ratecardLaneFee.maxWeight
|
|
575
|
+
? "".concat(ratecardLaneFee.minWeight || 0, "-").concat(ratecardLaneFee.maxWeight, " kg")
|
|
576
|
+
: "".concat(ratecardLaneFee.minWeight, "+ kg");
|
|
577
|
+
result = "".concat(cte.taxedWeight, " kg (").concat(weightRange, ") = ").concat(redeliveryInfo ? "".concat(valueCurrency).concat(redeliveryInfo, " = ").concat(resultCurrency) : valueCurrency);
|
|
578
|
+
}
|
|
539
579
|
totalFee = total;
|
|
540
580
|
resultFee = result;
|
|
581
|
+
// Lógica de intervalo de peso
|
|
541
582
|
if ((cte === null || cte === void 0 ? void 0 : cte.taxedWeight) && !ratecardLaneFee.maxWeight && ratecardLaneFee.minWeight && Math.ceil(+cte.taxedWeight) >= +ratecardLaneFee.minWeight) {
|
|
542
583
|
// Não tem maxWeight - é o último intervalo
|
|
543
584
|
// Encontrar todas as taxas do mesmo tipo que têm maxWeight
|
|
@@ -577,37 +618,77 @@ var calculateFee = function (ratecardLaneFee, cte, allFees, debug, allFeesForCal
|
|
|
577
618
|
resultFee = result_4;
|
|
578
619
|
}
|
|
579
620
|
}
|
|
621
|
+
// Lógica de intervalo de KM para FTL
|
|
622
|
+
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) {
|
|
623
|
+
// Não tem maxKm - é o último intervalo
|
|
624
|
+
// Encontrar todas as taxas do mesmo tipo que têm maxKm
|
|
625
|
+
var feesWithMaxKm = allFeesForCalc === null || allFeesForCalc === void 0 ? void 0 : allFeesForCalc.filter(function (fee) {
|
|
626
|
+
var _a, _b;
|
|
627
|
+
return ((_a = fee.fee) === null || _a === void 0 ? void 0 : _a.id) === ((_b = ratecardLaneFee.fee) === null || _b === void 0 ? void 0 : _b.id) &&
|
|
628
|
+
fee.maxKm &&
|
|
629
|
+
(cte === null || cte === void 0 ? void 0 : cte.distance) &&
|
|
630
|
+
+fee.maxKm < +cte.distance;
|
|
631
|
+
});
|
|
632
|
+
// Ordenar pelo maxKm do maior para o menor
|
|
633
|
+
feesWithMaxKm === null || feesWithMaxKm === void 0 ? void 0 : feesWithMaxKm.sort(function (a, b) { return b.maxKm - a.maxKm; });
|
|
634
|
+
// Pegar o primeiro (maior maxKm)
|
|
635
|
+
var highestIntervalFee = feesWithMaxKm === null || feesWithMaxKm === void 0 ? void 0 : feesWithMaxKm[0];
|
|
636
|
+
if (highestIntervalFee) {
|
|
637
|
+
// Calcula baseado na taxa do intervalo mais alto que tem maxKm
|
|
638
|
+
var total_5 = +highestIntervalFee.value;
|
|
639
|
+
// Calcular diferença de distância
|
|
640
|
+
var kmDifference = Number((((cte === null || cte === void 0 ? void 0 : cte.distance) || 0) - (highestIntervalFee.maxKm || 0)).toFixed(2));
|
|
641
|
+
// Calcular valor adicional pela diferença de km
|
|
642
|
+
var additionalValue = kmDifference * +ratecardLaneFee.value;
|
|
643
|
+
// Somar ao total
|
|
644
|
+
total_5 += additionalValue;
|
|
645
|
+
// Aplicar multiplicador de redelivery ao valor final
|
|
646
|
+
var _k = applyRedeliveryMultiplier(total_5, cte), adjustedTotal_5 = _k.adjustedTotal, redeliveryInfo_5 = _k.redeliveryInfo;
|
|
647
|
+
total_5 = adjustedTotal_5;
|
|
648
|
+
var valueCurrency_3 = (+highestIntervalFee.value).toLocaleString('pt-br', {
|
|
649
|
+
style: 'currency',
|
|
650
|
+
currency: 'BRL',
|
|
651
|
+
});
|
|
652
|
+
var resultCurrency_5 = (+total_5).toLocaleString('pt-br', {
|
|
653
|
+
style: 'currency',
|
|
654
|
+
currency: 'BRL',
|
|
655
|
+
});
|
|
656
|
+
var result_5 = "".concat(cte.distance, " km = ").concat(valueCurrency_3, " + ").concat(kmDifference, " km x ").concat(convertNumberToCurrency(+ratecardLaneFee.value, 'pt-br')).concat(redeliveryInfo_5, " = ").concat(resultCurrency_5);
|
|
657
|
+
totalFee = total_5;
|
|
658
|
+
resultFee = result_5;
|
|
659
|
+
}
|
|
660
|
+
}
|
|
580
661
|
break;
|
|
581
662
|
case FeeCalculationTypeEnum.COMMODITY_VALUE:
|
|
582
663
|
if (value) {
|
|
583
664
|
var commodityValue = (_a = cte === null || cte === void 0 ? void 0 : cte.commodityValue) !== null && _a !== void 0 ? _a : 0;
|
|
584
|
-
var
|
|
585
|
-
var
|
|
586
|
-
|
|
587
|
-
var
|
|
665
|
+
var total_6 = +commodityValue * (+value / 100);
|
|
666
|
+
var _l = applyRedeliveryMultiplier(total_6, cte), adjustedTotal_6 = _l.adjustedTotal, redeliveryInfo_6 = _l.redeliveryInfo;
|
|
667
|
+
total_6 = adjustedTotal_6;
|
|
668
|
+
var resultCurrency_6 = (+total_6).toLocaleString('pt-br', {
|
|
588
669
|
style: 'currency',
|
|
589
670
|
currency: 'BRL',
|
|
590
671
|
});
|
|
591
|
-
var
|
|
592
|
-
totalFee =
|
|
593
|
-
resultFee =
|
|
672
|
+
var result_6 = "".concat(convertNumberToCurrency(+commodityValue, 'pt-br'), " x ").concat(value, "%").concat(redeliveryInfo_6, " = ").concat(resultCurrency_6);
|
|
673
|
+
totalFee = total_6;
|
|
674
|
+
resultFee = result_6;
|
|
594
675
|
}
|
|
595
676
|
break;
|
|
596
677
|
case FeeCalculationTypeEnum.TAXED_WEIGHT:
|
|
597
678
|
if (value) {
|
|
598
679
|
var taxedWeight = (_b = cte === null || cte === void 0 ? void 0 : cte.taxedWeight) !== null && _b !== void 0 ? _b : 0;
|
|
599
|
-
var
|
|
600
|
-
var
|
|
601
|
-
|
|
602
|
-
var
|
|
680
|
+
var total_7 = +taxedWeight * +value;
|
|
681
|
+
var _m = applyRedeliveryMultiplier(total_7, cte), adjustedTotal_7 = _m.adjustedTotal, redeliveryInfo_7 = _m.redeliveryInfo;
|
|
682
|
+
total_7 = adjustedTotal_7;
|
|
683
|
+
var resultCurrency_7 = (+total_7).toLocaleString('pt-br', {
|
|
603
684
|
style: 'currency',
|
|
604
685
|
currency: 'BRL',
|
|
605
686
|
});
|
|
606
|
-
var
|
|
687
|
+
var result_7 = "".concat(taxedWeight, " kg x ").concat(convertNumberToCurrency(+value, 'pt-br', {
|
|
607
688
|
minimumFractionDigits: 4,
|
|
608
|
-
})).concat(
|
|
609
|
-
totalFee =
|
|
610
|
-
resultFee =
|
|
689
|
+
})).concat(redeliveryInfo_7, " = ").concat(resultCurrency_7);
|
|
690
|
+
totalFee = total_7;
|
|
691
|
+
resultFee = result_7;
|
|
611
692
|
}
|
|
612
693
|
break;
|
|
613
694
|
/*if (ratecardLaneFee.minWeight && cte?.taxedWeight) {
|
package/build/index.esm.js.gz
CHANGED
|
Binary file
|