b2m-utils 0.0.226 → 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 +81 -62
- package/build/index.esm.js.gz +0 -0
- package/build/index.esm.js.map +1 -1
- package/build/index.js +81 -62
- 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
|
@@ -536,8 +536,23 @@ var calculateFee = function (ratecardLaneFee, cte, allFees, debug, allFeesForCal
|
|
|
536
536
|
currency: 'BRL',
|
|
537
537
|
});
|
|
538
538
|
var result = "".concat(redeliveryInfo ? "".concat(valueCurrency).concat(redeliveryInfo, " = ").concat(resultCurrency) : valueCurrency);
|
|
539
|
+
// Se for FTL com distância e tiver intervalo de KM, adicionar informação na descrição
|
|
540
|
+
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)) {
|
|
541
|
+
var kmRange = ratecardLaneFee.maxKm
|
|
542
|
+
? "".concat(ratecardLaneFee.minKm || 0, "-").concat(ratecardLaneFee.maxKm, " km")
|
|
543
|
+
: "".concat(ratecardLaneFee.minKm, "+ km");
|
|
544
|
+
result = "".concat(cte.distance, " km (").concat(kmRange, ") = ").concat(redeliveryInfo ? "".concat(valueCurrency).concat(redeliveryInfo, " = ").concat(resultCurrency) : valueCurrency);
|
|
545
|
+
}
|
|
546
|
+
// Se houver taxedWeight e tiver intervalo de peso, adicionar informação na descrição
|
|
547
|
+
else if ((cte === null || cte === void 0 ? void 0 : cte.taxedWeight) && (ratecardLaneFee.minWeight || ratecardLaneFee.maxWeight)) {
|
|
548
|
+
var weightRange = ratecardLaneFee.maxWeight
|
|
549
|
+
? "".concat(ratecardLaneFee.minWeight || 0, "-").concat(ratecardLaneFee.maxWeight, " kg")
|
|
550
|
+
: "".concat(ratecardLaneFee.minWeight, "+ kg");
|
|
551
|
+
result = "".concat(cte.taxedWeight, " kg (").concat(weightRange, ") = ").concat(redeliveryInfo ? "".concat(valueCurrency).concat(redeliveryInfo, " = ").concat(resultCurrency) : valueCurrency);
|
|
552
|
+
}
|
|
539
553
|
totalFee = total;
|
|
540
554
|
resultFee = result;
|
|
555
|
+
// Lógica de intervalo de peso
|
|
541
556
|
if ((cte === null || cte === void 0 ? void 0 : cte.taxedWeight) && !ratecardLaneFee.maxWeight && ratecardLaneFee.minWeight && Math.ceil(+cte.taxedWeight) >= +ratecardLaneFee.minWeight) {
|
|
542
557
|
// Não tem maxWeight - é o último intervalo
|
|
543
558
|
// Encontrar todas as taxas do mesmo tipo que têm maxWeight
|
|
@@ -577,37 +592,77 @@ var calculateFee = function (ratecardLaneFee, cte, allFees, debug, allFeesForCal
|
|
|
577
592
|
resultFee = result_4;
|
|
578
593
|
}
|
|
579
594
|
}
|
|
595
|
+
// Lógica de intervalo de KM para FTL
|
|
596
|
+
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) {
|
|
597
|
+
// Não tem maxKm - é o último intervalo
|
|
598
|
+
// Encontrar todas as taxas do mesmo tipo que têm maxKm
|
|
599
|
+
var feesWithMaxKm = allFeesForCalc === null || allFeesForCalc === void 0 ? void 0 : allFeesForCalc.filter(function (fee) {
|
|
600
|
+
var _a, _b;
|
|
601
|
+
return ((_a = fee.fee) === null || _a === void 0 ? void 0 : _a.id) === ((_b = ratecardLaneFee.fee) === null || _b === void 0 ? void 0 : _b.id) &&
|
|
602
|
+
fee.maxKm &&
|
|
603
|
+
(cte === null || cte === void 0 ? void 0 : cte.distance) &&
|
|
604
|
+
+fee.maxKm < +cte.distance;
|
|
605
|
+
});
|
|
606
|
+
// Ordenar pelo maxKm do maior para o menor
|
|
607
|
+
feesWithMaxKm === null || feesWithMaxKm === void 0 ? void 0 : feesWithMaxKm.sort(function (a, b) { return b.maxKm - a.maxKm; });
|
|
608
|
+
// Pegar o primeiro (maior maxKm)
|
|
609
|
+
var highestIntervalFee = feesWithMaxKm === null || feesWithMaxKm === void 0 ? void 0 : feesWithMaxKm[0];
|
|
610
|
+
if (highestIntervalFee) {
|
|
611
|
+
// Calcula baseado na taxa do intervalo mais alto que tem maxKm
|
|
612
|
+
var total_5 = +highestIntervalFee.value;
|
|
613
|
+
// Calcular diferença de distância
|
|
614
|
+
var kmDifference = Number((((cte === null || cte === void 0 ? void 0 : cte.distance) || 0) - (highestIntervalFee.maxKm || 0)).toFixed(2));
|
|
615
|
+
// Calcular valor adicional pela diferença de km
|
|
616
|
+
var additionalValue = kmDifference * +ratecardLaneFee.value;
|
|
617
|
+
// Somar ao total
|
|
618
|
+
total_5 += additionalValue;
|
|
619
|
+
// Aplicar multiplicador de redelivery ao valor final
|
|
620
|
+
var _k = applyRedeliveryMultiplier(total_5, cte), adjustedTotal_5 = _k.adjustedTotal, redeliveryInfo_5 = _k.redeliveryInfo;
|
|
621
|
+
total_5 = adjustedTotal_5;
|
|
622
|
+
var valueCurrency_3 = (+highestIntervalFee.value).toLocaleString('pt-br', {
|
|
623
|
+
style: 'currency',
|
|
624
|
+
currency: 'BRL',
|
|
625
|
+
});
|
|
626
|
+
var resultCurrency_5 = (+total_5).toLocaleString('pt-br', {
|
|
627
|
+
style: 'currency',
|
|
628
|
+
currency: 'BRL',
|
|
629
|
+
});
|
|
630
|
+
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);
|
|
631
|
+
totalFee = total_5;
|
|
632
|
+
resultFee = result_5;
|
|
633
|
+
}
|
|
634
|
+
}
|
|
580
635
|
break;
|
|
581
636
|
case FeeCalculationTypeEnum.COMMODITY_VALUE:
|
|
582
637
|
if (value) {
|
|
583
638
|
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
|
|
639
|
+
var total_6 = +commodityValue * (+value / 100);
|
|
640
|
+
var _l = applyRedeliveryMultiplier(total_6, cte), adjustedTotal_6 = _l.adjustedTotal, redeliveryInfo_6 = _l.redeliveryInfo;
|
|
641
|
+
total_6 = adjustedTotal_6;
|
|
642
|
+
var resultCurrency_6 = (+total_6).toLocaleString('pt-br', {
|
|
588
643
|
style: 'currency',
|
|
589
644
|
currency: 'BRL',
|
|
590
645
|
});
|
|
591
|
-
var
|
|
592
|
-
totalFee =
|
|
593
|
-
resultFee =
|
|
646
|
+
var result_6 = "".concat(convertNumberToCurrency(+commodityValue, 'pt-br'), " x ").concat(value, "%").concat(redeliveryInfo_6, " = ").concat(resultCurrency_6);
|
|
647
|
+
totalFee = total_6;
|
|
648
|
+
resultFee = result_6;
|
|
594
649
|
}
|
|
595
650
|
break;
|
|
596
651
|
case FeeCalculationTypeEnum.TAXED_WEIGHT:
|
|
597
652
|
if (value) {
|
|
598
653
|
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
|
|
654
|
+
var total_7 = +taxedWeight * +value;
|
|
655
|
+
var _m = applyRedeliveryMultiplier(total_7, cte), adjustedTotal_7 = _m.adjustedTotal, redeliveryInfo_7 = _m.redeliveryInfo;
|
|
656
|
+
total_7 = adjustedTotal_7;
|
|
657
|
+
var resultCurrency_7 = (+total_7).toLocaleString('pt-br', {
|
|
603
658
|
style: 'currency',
|
|
604
659
|
currency: 'BRL',
|
|
605
660
|
});
|
|
606
|
-
var
|
|
661
|
+
var result_7 = "".concat(taxedWeight, " kg x ").concat(convertNumberToCurrency(+value, 'pt-br', {
|
|
607
662
|
minimumFractionDigits: 4,
|
|
608
|
-
})).concat(
|
|
609
|
-
totalFee =
|
|
610
|
-
resultFee =
|
|
663
|
+
})).concat(redeliveryInfo_7, " = ").concat(resultCurrency_7);
|
|
664
|
+
totalFee = total_7;
|
|
665
|
+
resultFee = result_7;
|
|
611
666
|
}
|
|
612
667
|
break;
|
|
613
668
|
/*if (ratecardLaneFee.minWeight && cte?.taxedWeight) {
|
|
@@ -7193,94 +7248,58 @@ var getFilteredFeesToAudit = function (_a) {
|
|
|
7193
7248
|
};
|
|
7194
7249
|
|
|
7195
7250
|
var getLaneFromRatecard = function (cte) {
|
|
7196
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p
|
|
7251
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
|
|
7197
7252
|
var ratecard = getRatecardFromCte(cte);
|
|
7198
|
-
console.log('🔍 Ratecard encontrado:', {
|
|
7199
|
-
id: ratecard === null || ratecard === void 0 ? void 0 : ratecard.id,
|
|
7200
|
-
name: ratecard === null || ratecard === void 0 ? void 0 : ratecard.name,
|
|
7201
|
-
modalId: ratecard === null || ratecard === void 0 ? void 0 : ratecard.modalId,
|
|
7202
|
-
modalName: (_a = ratecard === null || ratecard === void 0 ? void 0 : ratecard.modal) === null || _a === void 0 ? void 0 : _a.name,
|
|
7203
|
-
originCities: ratecard === null || ratecard === void 0 ? void 0 : ratecard.ratecard_origin_cities,
|
|
7204
|
-
lanesCount: (_b = ratecard === null || ratecard === void 0 ? void 0 : ratecard.RatecardLane) === null || _b === void 0 ? void 0 : _b.length
|
|
7205
|
-
});
|
|
7206
7253
|
var cityOriginId = cte.cityOriginId, cityDestination = cte.cityDestination;
|
|
7207
|
-
var destinationUf = (
|
|
7254
|
+
var destinationUf = (_a = cityDestination === null || cityDestination === void 0 ? void 0 : cityDestination.state) === null || _a === void 0 ? void 0 : _a.uf;
|
|
7208
7255
|
// Encontrar a ratecardRegion da cidade de destino
|
|
7209
|
-
var destinationRatecardRegionId = (
|
|
7210
|
-
if (!(ratecard === null || ratecard === void 0 ? void 0 : ratecard.RatecardLane) || ((
|
|
7211
|
-
console.log('❌ Nenhuma lane encontrada no ratecard');
|
|
7256
|
+
var destinationRatecardRegionId = (_c = (_b = ratecard === null || ratecard === void 0 ? void 0 : ratecard.RatecardRegionCity) === null || _b === void 0 ? void 0 : _b.find(function (regionCity) { return regionCity.cityId === (cityDestination === null || cityDestination === void 0 ? void 0 : cityDestination.id); })) === null || _c === void 0 ? void 0 : _c.ratecardRegionId;
|
|
7257
|
+
if (!(ratecard === null || ratecard === void 0 ? void 0 : ratecard.RatecardLane) || ((_d = ratecard === null || ratecard === void 0 ? void 0 : ratecard.RatecardLane) === null || _d === void 0 ? void 0 : _d.length) === 0) {
|
|
7212
7258
|
return undefined;
|
|
7213
7259
|
}
|
|
7214
|
-
console.log('📍 Dados do CTE:', {
|
|
7215
|
-
cityOriginId: cityOriginId,
|
|
7216
|
-
cityOriginName: (_g = cte.cityOrigin) === null || _g === void 0 ? void 0 : _g.name,
|
|
7217
|
-
cityOriginUf: (_j = (_h = cte.cityOrigin) === null || _h === void 0 ? void 0 : _h.state) === null || _j === void 0 ? void 0 : _j.uf,
|
|
7218
|
-
cityDestinationId: cityDestination === null || cityDestination === void 0 ? void 0 : cityDestination.id,
|
|
7219
|
-
cityDestinationName: cityDestination === null || cityDestination === void 0 ? void 0 : cityDestination.name,
|
|
7220
|
-
destinationUf: destinationUf
|
|
7221
|
-
});
|
|
7222
7260
|
// Lógica diferenciada por modal
|
|
7223
7261
|
switch (ratecard.modalId) {
|
|
7224
7262
|
case RatecardModalEnum.ROAD_DOMESTIC_FTL:
|
|
7225
|
-
console.log('🚛 Modal FTL detectado - iniciando busca de lane');
|
|
7226
7263
|
// FTL: Verificar rota por UF de destino
|
|
7227
7264
|
if (destinationUf) {
|
|
7228
|
-
console.log('1️⃣ Tentando rota direta por UF de destino:', destinationUf);
|
|
7229
7265
|
var directLane = ratecard.RatecardLane.find(function (i) {
|
|
7230
7266
|
return i.ufDestination === destinationUf && i.ratecardRegionId === destinationRatecardRegionId;
|
|
7231
7267
|
});
|
|
7232
7268
|
if (directLane) {
|
|
7233
|
-
console.log('✅ Rota direta encontrada!', directLane.id);
|
|
7234
7269
|
return directLane;
|
|
7235
7270
|
}
|
|
7236
|
-
console.log('⚠️ Rota direta não encontrada');
|
|
7237
7271
|
// Fallback: Verificar se existe lane única com fees de KM e cidade origem no ratecard_origin_cities
|
|
7238
7272
|
var uniqueLane = ratecard.RatecardLane[0];
|
|
7239
7273
|
// Verificar se a lane tem fees com intervalo de KM
|
|
7240
|
-
var hasKmFees = (
|
|
7241
|
-
console.log('2️⃣ Verificando fallback com KM - hasKmFees:', hasKmFees);
|
|
7274
|
+
var hasKmFees = (_e = uniqueLane === null || uniqueLane === void 0 ? void 0 : uniqueLane.RatecardLaneFee) === null || _e === void 0 ? void 0 : _e.some(function (fee) { return fee.minKm !== null; });
|
|
7242
7275
|
// Verificar se a cidade de origem está no ratecard_origin_cities
|
|
7243
|
-
var hasOriginCity = (
|
|
7244
|
-
console.log(' Cidade origem em ratecard_origin_cities:', hasOriginCity);
|
|
7276
|
+
var hasOriginCity = (_f = ratecard.ratecard_origin_cities) === null || _f === void 0 ? void 0 : _f.some(function (originCity) { return originCity.cityId === cityOriginId; });
|
|
7245
7277
|
if (hasKmFees && hasOriginCity) {
|
|
7246
|
-
console.log('✅ Fallback com KM encontrado!');
|
|
7247
7278
|
// Mockar informações para exibição no frontend
|
|
7248
7279
|
return __assign(__assign({}, uniqueLane), { city: cte.cityOrigin, ufDestination: destinationUf, ratecardRegion: uniqueLane.ratecardRegion || { name: destinationUf } });
|
|
7249
7280
|
}
|
|
7250
|
-
console.log('⚠️ Fallback com KM não aplicável');
|
|
7251
7281
|
// Rota inversa FTL: Verificar se cidade de destino está em ratecard_origin_cities
|
|
7252
|
-
var originUf_1 = (
|
|
7253
|
-
console.log('3️⃣ Tentando rota inversa - originUf:', originUf_1);
|
|
7282
|
+
var originUf_1 = (_h = (_g = cte.cityOrigin) === null || _g === void 0 ? void 0 : _g.state) === null || _h === void 0 ? void 0 : _h.uf;
|
|
7254
7283
|
if (originUf_1) {
|
|
7255
7284
|
// Verificar se existe lane com ufDestination = originUf
|
|
7256
7285
|
var reverseLane = ratecard.RatecardLane.find(function (i) {
|
|
7257
7286
|
return i.ufDestination === originUf_1;
|
|
7258
7287
|
});
|
|
7259
|
-
console.log(' Lane com ufDestination =', originUf_1, ':', reverseLane ? 'encontrada' : 'não encontrada');
|
|
7260
7288
|
if (reverseLane) {
|
|
7261
7289
|
// Verificar se a cidade de destino está no ratecard_origin_cities
|
|
7262
|
-
var hasDestinationCity = (
|
|
7263
|
-
console.log(' Cidade destino em ratecard_origin_cities:', hasDestinationCity);
|
|
7290
|
+
var hasDestinationCity = (_j = ratecard.ratecard_origin_cities) === null || _j === void 0 ? void 0 : _j.some(function (originCity) { return originCity.cityId === (cityDestination === null || cityDestination === void 0 ? void 0 : cityDestination.id); });
|
|
7264
7291
|
if (hasDestinationCity) {
|
|
7265
|
-
console.log('✅ Rota inversa encontrada!', reverseLane.id);
|
|
7266
7292
|
return reverseLane;
|
|
7267
7293
|
}
|
|
7268
7294
|
}
|
|
7269
|
-
console.log('⚠️ Rota inversa não encontrada');
|
|
7270
7295
|
// Fallback inverso: Lane única com cidade de destino em ratecard_origin_cities
|
|
7271
|
-
|
|
7272
|
-
var hasDestinationCityInOrigins = (_q = ratecard.ratecard_origin_cities) === null || _q === void 0 ? void 0 : _q.some(function (originCity) { return originCity.cityId === (cityDestination === null || cityDestination === void 0 ? void 0 : cityDestination.id); });
|
|
7273
|
-
console.log(' Cidade destino em ratecard_origin_cities:', hasDestinationCityInOrigins);
|
|
7274
|
-
console.log(' hasKmFees:', hasKmFees);
|
|
7296
|
+
var hasDestinationCityInOrigins = (_k = ratecard.ratecard_origin_cities) === null || _k === void 0 ? void 0 : _k.some(function (originCity) { return originCity.cityId === (cityDestination === null || cityDestination === void 0 ? void 0 : cityDestination.id); });
|
|
7275
7297
|
if (hasKmFees && hasDestinationCityInOrigins) {
|
|
7276
|
-
console.log('✅ Fallback inverso com KM encontrado!');
|
|
7277
7298
|
// Mockar informações para exibição no frontend (rota inversa)
|
|
7278
7299
|
return __assign(__assign({}, uniqueLane), { city: cityDestination, ufDestination: originUf_1, ratecardRegion: uniqueLane.ratecardRegion || { name: originUf_1 } });
|
|
7279
7300
|
}
|
|
7280
|
-
console.log('⚠️ Fallback inverso não aplicável');
|
|
7281
7301
|
}
|
|
7282
7302
|
}
|
|
7283
|
-
console.log('❌ Nenhuma lane FTL encontrada');
|
|
7284
7303
|
break;
|
|
7285
7304
|
case RatecardModalEnum.ROAD_DOMESTIC_LTL:
|
|
7286
7305
|
default:
|
|
@@ -7295,9 +7314,9 @@ var getLaneFromRatecard = function (cte) {
|
|
|
7295
7314
|
}
|
|
7296
7315
|
// Se não encontrar rota direta, buscar rota inversa (Destino -> Origem)
|
|
7297
7316
|
// Para isso, precisamos encontrar a UF da origem e sua ratecardRegion
|
|
7298
|
-
var originUf_2 = (
|
|
7317
|
+
var originUf_2 = (_m = (_l = cte.cityOrigin) === null || _l === void 0 ? void 0 : _l.state) === null || _m === void 0 ? void 0 : _m.uf;
|
|
7299
7318
|
// Encontrar a ratecardRegion da cidade de origem
|
|
7300
|
-
var originRatecardRegionId_1 = (
|
|
7319
|
+
var originRatecardRegionId_1 = (_p = (_o = ratecard === null || ratecard === void 0 ? void 0 : ratecard.RatecardRegionCity) === null || _o === void 0 ? void 0 : _o.find(function (regionCity) { return regionCity.cityId === cityOriginId; })) === null || _p === void 0 ? void 0 : _p.ratecardRegionId;
|
|
7301
7320
|
if (originUf_2) {
|
|
7302
7321
|
var reverseLane = ratecard.RatecardLane.find(function (i) {
|
|
7303
7322
|
return i.cityOriginId === (cityDestination === null || cityDestination === void 0 ? void 0 : cityDestination.id) && i.ufDestination === originUf_2 && i.ratecardRegionId === originRatecardRegionId_1;
|
package/build/index.esm.js.gz
CHANGED
|
Binary file
|