b2m-utils 0.0.227 → 0.0.228
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 +70 -15
- package/build/index.esm.js.gz +0 -0
- package/build/index.esm.js.map +1 -1
- package/build/index.js +70 -15
- package/build/index.js.gz +0 -0
- package/build/index.js.map +1 -1
- package/package.json +1 -1
package/build/index.js
CHANGED
|
@@ -540,8 +540,23 @@ var calculateFee = function (ratecardLaneFee, cte, allFees, debug, allFeesForCal
|
|
|
540
540
|
currency: 'BRL',
|
|
541
541
|
});
|
|
542
542
|
var result = "".concat(redeliveryInfo ? "".concat(valueCurrency).concat(redeliveryInfo, " = ").concat(resultCurrency) : valueCurrency);
|
|
543
|
+
// Se for FTL com distância e tiver intervalo de KM, adicionar informação na descrição
|
|
544
|
+
if ((cte === null || cte === void 0 ? void 0 : cte.ratecardModalId) === exports.RatecardModalEnum.ROAD_DOMESTIC_FTL && (cte === null || cte === void 0 ? void 0 : cte.distance) && (ratecardLaneFee.minKm || ratecardLaneFee.maxKm)) {
|
|
545
|
+
var kmRange = ratecardLaneFee.maxKm
|
|
546
|
+
? "".concat(ratecardLaneFee.minKm || 0, "-").concat(ratecardLaneFee.maxKm, " km")
|
|
547
|
+
: "".concat(ratecardLaneFee.minKm, "+ km");
|
|
548
|
+
result = "".concat(cte.distance, " km (").concat(kmRange, ") = ").concat(redeliveryInfo ? "".concat(valueCurrency).concat(redeliveryInfo, " = ").concat(resultCurrency) : valueCurrency);
|
|
549
|
+
}
|
|
550
|
+
// Se houver taxedWeight e tiver intervalo de peso, adicionar informação na descrição
|
|
551
|
+
else if ((cte === null || cte === void 0 ? void 0 : cte.taxedWeight) && (ratecardLaneFee.minWeight || ratecardLaneFee.maxWeight)) {
|
|
552
|
+
var weightRange = ratecardLaneFee.maxWeight
|
|
553
|
+
? "".concat(ratecardLaneFee.minWeight || 0, "-").concat(ratecardLaneFee.maxWeight, " kg")
|
|
554
|
+
: "".concat(ratecardLaneFee.minWeight, "+ kg");
|
|
555
|
+
result = "".concat(cte.taxedWeight, " kg (").concat(weightRange, ") = ").concat(redeliveryInfo ? "".concat(valueCurrency).concat(redeliveryInfo, " = ").concat(resultCurrency) : valueCurrency);
|
|
556
|
+
}
|
|
543
557
|
totalFee = total;
|
|
544
558
|
resultFee = result;
|
|
559
|
+
// Lógica de intervalo de peso
|
|
545
560
|
if ((cte === null || cte === void 0 ? void 0 : cte.taxedWeight) && !ratecardLaneFee.maxWeight && ratecardLaneFee.minWeight && Math.ceil(+cte.taxedWeight) >= +ratecardLaneFee.minWeight) {
|
|
546
561
|
// Não tem maxWeight - é o último intervalo
|
|
547
562
|
// Encontrar todas as taxas do mesmo tipo que têm maxWeight
|
|
@@ -581,37 +596,77 @@ var calculateFee = function (ratecardLaneFee, cte, allFees, debug, allFeesForCal
|
|
|
581
596
|
resultFee = result_4;
|
|
582
597
|
}
|
|
583
598
|
}
|
|
599
|
+
// Lógica de intervalo de KM para FTL
|
|
600
|
+
else if ((cte === null || cte === void 0 ? void 0 : cte.ratecardModalId) === exports.RatecardModalEnum.ROAD_DOMESTIC_FTL && (cte === null || cte === void 0 ? void 0 : cte.distance) && !ratecardLaneFee.maxKm && ratecardLaneFee.minKm && +cte.distance >= +ratecardLaneFee.minKm) {
|
|
601
|
+
// Não tem maxKm - é o último intervalo
|
|
602
|
+
// Encontrar todas as taxas do mesmo tipo que têm maxKm
|
|
603
|
+
var feesWithMaxKm = allFeesForCalc === null || allFeesForCalc === void 0 ? void 0 : allFeesForCalc.filter(function (fee) {
|
|
604
|
+
var _a, _b;
|
|
605
|
+
return ((_a = fee.fee) === null || _a === void 0 ? void 0 : _a.id) === ((_b = ratecardLaneFee.fee) === null || _b === void 0 ? void 0 : _b.id) &&
|
|
606
|
+
fee.maxKm &&
|
|
607
|
+
(cte === null || cte === void 0 ? void 0 : cte.distance) &&
|
|
608
|
+
+fee.maxKm < +cte.distance;
|
|
609
|
+
});
|
|
610
|
+
// Ordenar pelo maxKm do maior para o menor
|
|
611
|
+
feesWithMaxKm === null || feesWithMaxKm === void 0 ? void 0 : feesWithMaxKm.sort(function (a, b) { return b.maxKm - a.maxKm; });
|
|
612
|
+
// Pegar o primeiro (maior maxKm)
|
|
613
|
+
var highestIntervalFee = feesWithMaxKm === null || feesWithMaxKm === void 0 ? void 0 : feesWithMaxKm[0];
|
|
614
|
+
if (highestIntervalFee) {
|
|
615
|
+
// Calcula baseado na taxa do intervalo mais alto que tem maxKm
|
|
616
|
+
var total_5 = +highestIntervalFee.value;
|
|
617
|
+
// Calcular diferença de distância
|
|
618
|
+
var kmDifference = Number((((cte === null || cte === void 0 ? void 0 : cte.distance) || 0) - (highestIntervalFee.maxKm || 0)).toFixed(2));
|
|
619
|
+
// Calcular valor adicional pela diferença de km
|
|
620
|
+
var additionalValue = kmDifference * +ratecardLaneFee.value;
|
|
621
|
+
// Somar ao total
|
|
622
|
+
total_5 += additionalValue;
|
|
623
|
+
// Aplicar multiplicador de redelivery ao valor final
|
|
624
|
+
var _k = applyRedeliveryMultiplier(total_5, cte), adjustedTotal_5 = _k.adjustedTotal, redeliveryInfo_5 = _k.redeliveryInfo;
|
|
625
|
+
total_5 = adjustedTotal_5;
|
|
626
|
+
var valueCurrency_3 = (+highestIntervalFee.value).toLocaleString('pt-br', {
|
|
627
|
+
style: 'currency',
|
|
628
|
+
currency: 'BRL',
|
|
629
|
+
});
|
|
630
|
+
var resultCurrency_5 = (+total_5).toLocaleString('pt-br', {
|
|
631
|
+
style: 'currency',
|
|
632
|
+
currency: 'BRL',
|
|
633
|
+
});
|
|
634
|
+
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);
|
|
635
|
+
totalFee = total_5;
|
|
636
|
+
resultFee = result_5;
|
|
637
|
+
}
|
|
638
|
+
}
|
|
584
639
|
break;
|
|
585
640
|
case exports.FeeCalculationTypeEnum.COMMODITY_VALUE:
|
|
586
641
|
if (value) {
|
|
587
642
|
var commodityValue = (_a = cte === null || cte === void 0 ? void 0 : cte.commodityValue) !== null && _a !== void 0 ? _a : 0;
|
|
588
|
-
var
|
|
589
|
-
var
|
|
590
|
-
|
|
591
|
-
var
|
|
643
|
+
var total_6 = +commodityValue * (+value / 100);
|
|
644
|
+
var _l = applyRedeliveryMultiplier(total_6, cte), adjustedTotal_6 = _l.adjustedTotal, redeliveryInfo_6 = _l.redeliveryInfo;
|
|
645
|
+
total_6 = adjustedTotal_6;
|
|
646
|
+
var resultCurrency_6 = (+total_6).toLocaleString('pt-br', {
|
|
592
647
|
style: 'currency',
|
|
593
648
|
currency: 'BRL',
|
|
594
649
|
});
|
|
595
|
-
var
|
|
596
|
-
totalFee =
|
|
597
|
-
resultFee =
|
|
650
|
+
var result_6 = "".concat(convertNumberToCurrency(+commodityValue, 'pt-br'), " x ").concat(value, "%").concat(redeliveryInfo_6, " = ").concat(resultCurrency_6);
|
|
651
|
+
totalFee = total_6;
|
|
652
|
+
resultFee = result_6;
|
|
598
653
|
}
|
|
599
654
|
break;
|
|
600
655
|
case exports.FeeCalculationTypeEnum.TAXED_WEIGHT:
|
|
601
656
|
if (value) {
|
|
602
657
|
var taxedWeight = (_b = cte === null || cte === void 0 ? void 0 : cte.taxedWeight) !== null && _b !== void 0 ? _b : 0;
|
|
603
|
-
var
|
|
604
|
-
var
|
|
605
|
-
|
|
606
|
-
var
|
|
658
|
+
var total_7 = +taxedWeight * +value;
|
|
659
|
+
var _m = applyRedeliveryMultiplier(total_7, cte), adjustedTotal_7 = _m.adjustedTotal, redeliveryInfo_7 = _m.redeliveryInfo;
|
|
660
|
+
total_7 = adjustedTotal_7;
|
|
661
|
+
var resultCurrency_7 = (+total_7).toLocaleString('pt-br', {
|
|
607
662
|
style: 'currency',
|
|
608
663
|
currency: 'BRL',
|
|
609
664
|
});
|
|
610
|
-
var
|
|
665
|
+
var result_7 = "".concat(taxedWeight, " kg x ").concat(convertNumberToCurrency(+value, 'pt-br', {
|
|
611
666
|
minimumFractionDigits: 4,
|
|
612
|
-
})).concat(
|
|
613
|
-
totalFee =
|
|
614
|
-
resultFee =
|
|
667
|
+
})).concat(redeliveryInfo_7, " = ").concat(resultCurrency_7);
|
|
668
|
+
totalFee = total_7;
|
|
669
|
+
resultFee = result_7;
|
|
615
670
|
}
|
|
616
671
|
break;
|
|
617
672
|
/*if (ratecardLaneFee.minWeight && cte?.taxedWeight) {
|
package/build/index.js.gz
CHANGED
|
Binary file
|