b2m-utils 0.0.250 → 0.0.251
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/enums/RatecardFeeConfigKeyEnum.d.ts +1 -11
- package/build/index.esm.js +25 -33
- package/build/index.esm.js.gz +0 -0
- package/build/index.esm.js.map +1 -1
- package/build/index.js +25 -33
- package/build/index.js.gz +0 -0
- package/build/index.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,13 +1,3 @@
|
|
|
1
1
|
export declare enum RatecardFeeConfigKeyEnum {
|
|
2
|
-
MIN_WEIGHT_FOR_FRACTION = "min_weight_for_fraction"
|
|
3
|
-
FRACTION_UNIT = "fraction_unit",
|
|
4
|
-
MIN_VALUE = "min_value",
|
|
5
|
-
MIN_WEIGHT = "min_weight",
|
|
6
|
-
MAX_WEIGHT = "max_weight",
|
|
7
|
-
ROUNDING_TYPE = "rounding_type",
|
|
8
|
-
APPLY_ONLY_IF_GREATER_THAN = "apply_only_if_greater_than",
|
|
9
|
-
MAX_APPLICATIONS = "max_applications",
|
|
10
|
-
PERCENTAGE_VALUE = "percentage_value",
|
|
11
|
-
APPLY_ONLY_WEEKENDS = "apply_only_weekends",
|
|
12
|
-
APPLY_ONLY_WEEKDAYS = "apply_only_weekdays"
|
|
2
|
+
MIN_WEIGHT_FOR_FRACTION = "min_weight_for_fraction"
|
|
13
3
|
}
|
package/build/index.esm.js
CHANGED
|
@@ -183,21 +183,6 @@ var RatecardFeeConfigKeyEnum;
|
|
|
183
183
|
(function (RatecardFeeConfigKeyEnum) {
|
|
184
184
|
// Configurações de fração de peso
|
|
185
185
|
RatecardFeeConfigKeyEnum["MIN_WEIGHT_FOR_FRACTION"] = "min_weight_for_fraction";
|
|
186
|
-
RatecardFeeConfigKeyEnum["FRACTION_UNIT"] = "fraction_unit";
|
|
187
|
-
RatecardFeeConfigKeyEnum["MIN_VALUE"] = "min_value";
|
|
188
|
-
// Configurações de peso
|
|
189
|
-
RatecardFeeConfigKeyEnum["MIN_WEIGHT"] = "min_weight";
|
|
190
|
-
RatecardFeeConfigKeyEnum["MAX_WEIGHT"] = "max_weight";
|
|
191
|
-
// Configurações de arredondamento
|
|
192
|
-
RatecardFeeConfigKeyEnum["ROUNDING_TYPE"] = "rounding_type";
|
|
193
|
-
// Configurações de aplicação
|
|
194
|
-
RatecardFeeConfigKeyEnum["APPLY_ONLY_IF_GREATER_THAN"] = "apply_only_if_greater_than";
|
|
195
|
-
RatecardFeeConfigKeyEnum["MAX_APPLICATIONS"] = "max_applications";
|
|
196
|
-
// Configurações de percentual
|
|
197
|
-
RatecardFeeConfigKeyEnum["PERCENTAGE_VALUE"] = "percentage_value";
|
|
198
|
-
// Configurações condicionais
|
|
199
|
-
RatecardFeeConfigKeyEnum["APPLY_ONLY_WEEKENDS"] = "apply_only_weekends";
|
|
200
|
-
RatecardFeeConfigKeyEnum["APPLY_ONLY_WEEKDAYS"] = "apply_only_weekdays";
|
|
201
186
|
})(RatecardFeeConfigKeyEnum || (RatecardFeeConfigKeyEnum = {}));
|
|
202
187
|
|
|
203
188
|
var RatecardFeeConfigTypeEnum;
|
|
@@ -446,9 +431,11 @@ var filterSiblingFees = function (fees) {
|
|
|
446
431
|
};
|
|
447
432
|
|
|
448
433
|
var calculateFee = function (ratecardLaneFee, cte, allFees, debug, allFeesForCalc) {
|
|
449
|
-
var _a, _b, _c, _d, _e, _f;
|
|
434
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
450
435
|
if (debug === void 0) { debug = false; }
|
|
451
436
|
if (ratecardLaneFee.fee) {
|
|
437
|
+
// Buscar o ratecard correto do CTE usando getRatecardFromCte
|
|
438
|
+
var ratecard = getRatecardFromCte(cte);
|
|
452
439
|
var value = ratecardLaneFee.value, fee_1 = ratecardLaneFee.fee;
|
|
453
440
|
var totalFee = 0;
|
|
454
441
|
var resultFee = '';
|
|
@@ -518,7 +505,7 @@ var calculateFee = function (ratecardLaneFee, cte, allFees, debug, allFeesForCal
|
|
|
518
505
|
if (totalValueFromAllFees && !isNaN(+totalValueFromAllFees)) {
|
|
519
506
|
var valueToMultiply = (+value / 100);
|
|
520
507
|
var total_1 = +totalValueFromAllFees * valueToMultiply;
|
|
521
|
-
var
|
|
508
|
+
var _h = applyRedeliveryMultiplier(total_1, cte), adjustedTotal_1 = _h.adjustedTotal, redeliveryInfo_1 = _h.redeliveryInfo;
|
|
522
509
|
total_1 = adjustedTotal_1;
|
|
523
510
|
var totalValueFromAllFeesCurrency = convertNumberToCurrency(+totalValueFromAllFees, 'pt-br');
|
|
524
511
|
var resultCurrency_1 = (+total_1).toLocaleString('pt-BR', {
|
|
@@ -534,9 +521,14 @@ var calculateFee = function (ratecardLaneFee, cte, allFees, debug, allFeesForCal
|
|
|
534
521
|
break;
|
|
535
522
|
case FeeCalculationTypeEnum.FRACTIONED:
|
|
536
523
|
if ((cte === null || cte === void 0 ? void 0 : cte.taxedWeight) && !isNaN(+(cte === null || cte === void 0 ? void 0 : cte.taxedWeight))) {
|
|
537
|
-
|
|
524
|
+
// Buscar configuração de peso mínimo para aplicar fração
|
|
525
|
+
var minWeightConfig = (_a = ratecard === null || ratecard === void 0 ? void 0 : ratecard.RatecardFeeConfig) === null || _a === void 0 ? void 0 : _a.find(function (config) { var _a; return config.feeId === fee_1.id && ((_a = config.feeConfig) === null || _a === void 0 ? void 0 : _a.configKey) === RatecardFeeConfigKeyEnum.MIN_WEIGHT_FOR_FRACTION; });
|
|
526
|
+
var minWeightForFraction = (minWeightConfig === null || minWeightConfig === void 0 ? void 0 : minWeightConfig.configValue) ? Number(minWeightConfig.configValue) : 0;
|
|
527
|
+
// Só aplica fração se o peso for maior que o mínimo configurado
|
|
528
|
+
var shouldApplyFraction = +cte.taxedWeight > minWeightForFraction;
|
|
529
|
+
var fractions = shouldApplyFraction ? Math.ceil(+cte.taxedWeight / 100) : 1;
|
|
538
530
|
var total_2 = fractions * value;
|
|
539
|
-
var
|
|
531
|
+
var _j = applyRedeliveryMultiplier(total_2, cte), adjustedTotal_2 = _j.adjustedTotal, redeliveryInfo_2 = _j.redeliveryInfo;
|
|
540
532
|
total_2 = adjustedTotal_2;
|
|
541
533
|
var valueCurrency_1 = (+value).toLocaleString('pt-br', {
|
|
542
534
|
style: 'currency',
|
|
@@ -546,7 +538,9 @@ var calculateFee = function (ratecardLaneFee, cte, allFees, debug, allFeesForCal
|
|
|
546
538
|
style: 'currency',
|
|
547
539
|
currency: 'BRL',
|
|
548
540
|
});
|
|
549
|
-
var result_2 =
|
|
541
|
+
var result_2 = shouldApplyFraction
|
|
542
|
+
? "".concat(cte.taxedWeight, " kg = ").concat(fractions, " fra\u00E7\u00F5es x ").concat(valueCurrency_1).concat(redeliveryInfo_2, " = ").concat(resultCurrency_2)
|
|
543
|
+
: "".concat(cte.taxedWeight, " kg (abaixo do m\u00EDnimo ").concat(minWeightForFraction, " kg) = ").concat(valueCurrency_1).concat(redeliveryInfo_2, " = ").concat(resultCurrency_2);
|
|
550
544
|
totalFee = total_2;
|
|
551
545
|
resultFee = result_2;
|
|
552
546
|
}
|
|
@@ -555,7 +549,7 @@ var calculateFee = function (ratecardLaneFee, cte, allFees, debug, allFeesForCal
|
|
|
555
549
|
if (value && (cte === null || cte === void 0 ? void 0 : cte.freightValue)) {
|
|
556
550
|
if (!isNaN(+value) && !isNaN(+cte.freightValue)) {
|
|
557
551
|
var total_3 = +cte.freightValue * (+value / 100);
|
|
558
|
-
var
|
|
552
|
+
var _k = applyRedeliveryMultiplier(total_3, cte), adjustedTotal_3 = _k.adjustedTotal, redeliveryInfo_3 = _k.redeliveryInfo;
|
|
559
553
|
total_3 = adjustedTotal_3;
|
|
560
554
|
var freightValueCurrency = (+cte.freightValue).toLocaleString('pt-br', {
|
|
561
555
|
style: 'currency',
|
|
@@ -590,7 +584,7 @@ var calculateFee = function (ratecardLaneFee, cte, allFees, debug, allFeesForCal
|
|
|
590
584
|
case FeeCalculationTypeEnum.MIN_VALUE:
|
|
591
585
|
case FeeCalculationTypeEnum.FIXED:
|
|
592
586
|
var total = +value;
|
|
593
|
-
var
|
|
587
|
+
var _l = applyRedeliveryMultiplier(total, cte), adjustedTotal = _l.adjustedTotal, redeliveryInfo = _l.redeliveryInfo;
|
|
594
588
|
total = adjustedTotal;
|
|
595
589
|
var valueCurrency = (+value).toLocaleString('pt-br', {
|
|
596
590
|
style: 'currency',
|
|
@@ -642,7 +636,7 @@ var calculateFee = function (ratecardLaneFee, cte, allFees, debug, allFeesForCal
|
|
|
642
636
|
// Somar ao total
|
|
643
637
|
total_4 += additionalValue;
|
|
644
638
|
// Aplicar multiplicador de redelivery ao valor final
|
|
645
|
-
var
|
|
639
|
+
var _m = applyRedeliveryMultiplier(total_4, cte), adjustedTotal_4 = _m.adjustedTotal, redeliveryInfo_4 = _m.redeliveryInfo;
|
|
646
640
|
total_4 = adjustedTotal_4;
|
|
647
641
|
var valueCurrency_2 = (+highestIntervalFee.value).toLocaleString('pt-br', {
|
|
648
642
|
style: 'currency',
|
|
@@ -659,12 +653,10 @@ var calculateFee = function (ratecardLaneFee, cte, allFees, debug, allFeesForCal
|
|
|
659
653
|
}
|
|
660
654
|
// Lógica de intervalo de KM para FTL
|
|
661
655
|
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) {
|
|
662
|
-
|
|
663
|
-
var ratecard = getRatecardFromCte(cte);
|
|
664
|
-
var lane = (_a = ratecard === null || ratecard === void 0 ? void 0 : ratecard.RatecardLane) === null || _a === void 0 ? void 0 : _a.find(function (l) { return l.id === ratecardLaneFee.laneId; });
|
|
656
|
+
var lane = (_b = ratecard === null || ratecard === void 0 ? void 0 : ratecard.RatecardLane) === null || _b === void 0 ? void 0 : _b.find(function (l) { return l.id === ratecardLaneFee.laneId; });
|
|
665
657
|
// Não tem maxKm - é o último intervalo
|
|
666
658
|
// Encontrar todas as taxas do mesmo tipo que têm maxKm no ratecard
|
|
667
|
-
var feesWithMaxKm = (
|
|
659
|
+
var feesWithMaxKm = (_c = lane === null || lane === void 0 ? void 0 : lane.RatecardLaneFee) === null || _c === void 0 ? void 0 : _c.filter(function (fee) {
|
|
668
660
|
var _a, _b;
|
|
669
661
|
return ((_a = fee.fee) === null || _a === void 0 ? void 0 : _a.id) === ((_b = ratecardLaneFee.fee) === null || _b === void 0 ? void 0 : _b.id) &&
|
|
670
662
|
(!fee.vehicleTypeId || fee.vehicleTypeId === cte.vehicleTypeId) &&
|
|
@@ -686,7 +678,7 @@ var calculateFee = function (ratecardLaneFee, cte, allFees, debug, allFeesForCal
|
|
|
686
678
|
// Somar ao total
|
|
687
679
|
total_5 += additionalValue;
|
|
688
680
|
// Aplicar multiplicador de redelivery ao valor final
|
|
689
|
-
var
|
|
681
|
+
var _o = applyRedeliveryMultiplier(total_5, cte), adjustedTotal_5 = _o.adjustedTotal, redeliveryInfo_5 = _o.redeliveryInfo;
|
|
690
682
|
total_5 = adjustedTotal_5;
|
|
691
683
|
var valueCurrency_3 = (+highestIntervalFee.value).toLocaleString('pt-br', {
|
|
692
684
|
style: 'currency',
|
|
@@ -704,9 +696,9 @@ var calculateFee = function (ratecardLaneFee, cte, allFees, debug, allFeesForCal
|
|
|
704
696
|
break;
|
|
705
697
|
case FeeCalculationTypeEnum.COMMODITY_VALUE:
|
|
706
698
|
if (value) {
|
|
707
|
-
var commodityValue = (
|
|
699
|
+
var commodityValue = (_d = cte === null || cte === void 0 ? void 0 : cte.commodityValue) !== null && _d !== void 0 ? _d : 0;
|
|
708
700
|
var total_6 = +commodityValue * (+value / 100);
|
|
709
|
-
var
|
|
701
|
+
var _p = applyRedeliveryMultiplier(total_6, cte), adjustedTotal_6 = _p.adjustedTotal, redeliveryInfo_6 = _p.redeliveryInfo;
|
|
710
702
|
total_6 = adjustedTotal_6;
|
|
711
703
|
var resultCurrency_6 = (+total_6).toLocaleString('pt-br', {
|
|
712
704
|
style: 'currency',
|
|
@@ -719,9 +711,9 @@ var calculateFee = function (ratecardLaneFee, cte, allFees, debug, allFeesForCal
|
|
|
719
711
|
break;
|
|
720
712
|
case FeeCalculationTypeEnum.TAXED_WEIGHT:
|
|
721
713
|
if (value) {
|
|
722
|
-
var taxedWeight = (
|
|
714
|
+
var taxedWeight = (_e = cte === null || cte === void 0 ? void 0 : cte.taxedWeight) !== null && _e !== void 0 ? _e : 0;
|
|
723
715
|
var total_7 = +taxedWeight * +value;
|
|
724
|
-
var
|
|
716
|
+
var _q = applyRedeliveryMultiplier(total_7, cte), adjustedTotal_7 = _q.adjustedTotal, redeliveryInfo_7 = _q.redeliveryInfo;
|
|
725
717
|
total_7 = adjustedTotal_7;
|
|
726
718
|
var resultCurrency_7 = (+total_7).toLocaleString('pt-br', {
|
|
727
719
|
style: 'currency',
|
|
@@ -837,7 +829,7 @@ var calculateFee = function (ratecardLaneFee, cte, allFees, debug, allFeesForCal
|
|
|
837
829
|
return 0;
|
|
838
830
|
});
|
|
839
831
|
if ((siblingFeesResults === null || siblingFeesResults === void 0 ? void 0 : siblingFeesResults.length) > 0) {
|
|
840
|
-
if (((
|
|
832
|
+
if (((_f = siblingFeesResults[0]) === null || _f === void 0 ? void 0 : _f.totalFee) && ((_g = siblingFeesResults[0]) === null || _g === void 0 ? void 0 : _g.totalFee) > totalFee) {
|
|
841
833
|
totalToCalc = 0;
|
|
842
834
|
}
|
|
843
835
|
}
|
package/build/index.esm.js.gz
CHANGED
|
Binary file
|