b2m-utils 0.0.229 → 0.0.230
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/functions/getAllFeesForCalculation/index.d.ts +6 -0
- package/build/functions/getCteLaneFeesTotal/index.d.ts +1 -1
- package/build/functions/getCtesFeesResult/index.d.ts +1 -1
- package/build/functions/index.d.ts +1 -0
- package/build/index.esm.js +304 -243
- package/build/index.esm.js.gz +0 -0
- package/build/index.esm.js.map +1 -1
- package/build/index.js +304 -242
- 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
|
@@ -363,6 +363,16 @@ function __generator(thisArg, body) {
|
|
|
363
363
|
}
|
|
364
364
|
}
|
|
365
365
|
|
|
366
|
+
function __spreadArray(to, from, pack) {
|
|
367
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
368
|
+
if (ar || !(i in from)) {
|
|
369
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
370
|
+
ar[i] = from[i];
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
374
|
+
}
|
|
375
|
+
|
|
366
376
|
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
367
377
|
var e = new Error(message);
|
|
368
378
|
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
@@ -810,29 +820,6 @@ var calculateFee = function (ratecardLaneFee, cte, allFees, debug, allFeesForCal
|
|
|
810
820
|
}
|
|
811
821
|
};
|
|
812
822
|
|
|
813
|
-
var getCteLane = function (cte) {
|
|
814
|
-
var _a, _b, _c, _d, _e;
|
|
815
|
-
if (cte === null || cte === void 0 ? void 0 : cte.carrier) {
|
|
816
|
-
var carrier = cte === null || cte === void 0 ? void 0 : cte.carrier;
|
|
817
|
-
if ((_a = carrier === null || carrier === void 0 ? void 0 : carrier.Ratecard) === null || _a === void 0 ? void 0 : _a.length) {
|
|
818
|
-
var destinationUf_1 = (_c = (_b = cte === null || cte === void 0 ? void 0 : cte.cityDestination) === null || _b === void 0 ? void 0 : _b.state) === null || _c === void 0 ? void 0 : _c.uf;
|
|
819
|
-
if (carrier === null || carrier === void 0 ? void 0 : carrier.Ratecard[0]) {
|
|
820
|
-
var ratecard = carrier === null || carrier === void 0 ? void 0 : carrier.Ratecard[0];
|
|
821
|
-
if (ratecard.RatecardLane && ((_d = ratecard.RatecardLane) === null || _d === void 0 ? void 0 : _d.length) > 0 && cte.cityOriginId && destinationUf_1) {
|
|
822
|
-
var region = (_e = ratecard.RatecardRegionCity) === null || _e === void 0 ? void 0 : _e.find(function (it) { return it.cityId === cte.cityDestinationId; });
|
|
823
|
-
var regionId_1 = (region === null || region === void 0 ? void 0 : region.ratecardRegionId) ? region.ratecardRegionId : (region === null || region === void 0 ? void 0 : region.regionId) ? region.regionId : 0;
|
|
824
|
-
return ratecard.RatecardLane.find(function (i) {
|
|
825
|
-
if (i.cityOriginId === cte.cityOriginId && i.ufDestination === destinationUf_1 && i.ratecardRegionId === regionId_1) {
|
|
826
|
-
return true;
|
|
827
|
-
}
|
|
828
|
-
return false;
|
|
829
|
-
});
|
|
830
|
-
}
|
|
831
|
-
}
|
|
832
|
-
}
|
|
833
|
-
}
|
|
834
|
-
};
|
|
835
|
-
|
|
836
823
|
var verifyConditionalFee = function (conditionalFeeToVerify, cte) {
|
|
837
824
|
var _a;
|
|
838
825
|
if (conditionalFeeToVerify === null || conditionalFeeToVerify === void 0 ? void 0 : conditionalFeeToVerify.id) {
|
|
@@ -853,83 +840,217 @@ var verifyConditionalFee = function (conditionalFeeToVerify, cte) {
|
|
|
853
840
|
return false;
|
|
854
841
|
};
|
|
855
842
|
|
|
856
|
-
var
|
|
857
|
-
var
|
|
858
|
-
var ratecard =
|
|
859
|
-
var
|
|
860
|
-
|
|
861
|
-
var
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
843
|
+
var getFilteredFeesToAudit = function (_a) {
|
|
844
|
+
var _b;
|
|
845
|
+
var lane = _a.lane, ratecard = _a.ratecard, cte = _a.cte;
|
|
846
|
+
var filteredFees = (_b = lane === null || lane === void 0 ? void 0 : lane.RatecardLaneFee) === null || _b === void 0 ? void 0 : _b.filter(function (i) {
|
|
847
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
848
|
+
var defaultConditionalFees = [
|
|
849
|
+
FeeEnum.SUFRAMA,
|
|
850
|
+
FeeEnum.TDA_FREIGHT,
|
|
851
|
+
FeeEnum.TDA_MIN,
|
|
852
|
+
FeeEnum.TDE_FREIGHT,
|
|
853
|
+
FeeEnum.TDE_MIN,
|
|
854
|
+
FeeEnum.TRT_FREIGHT,
|
|
855
|
+
FeeEnum.TRT_MIN,
|
|
856
|
+
94,
|
|
857
|
+
];
|
|
858
|
+
var collectFees = [
|
|
859
|
+
FeeEnum.COLLECT_PERCENTAGE_TOTAL,
|
|
860
|
+
FeeEnum.COLLECT_REVERSE_PERCENTAGE_TOTAL,
|
|
861
|
+
];
|
|
862
|
+
if (collectFees.includes((_a = i.fee) === null || _a === void 0 ? void 0 : _a.id)) {
|
|
863
|
+
switch ((_b = i.fee) === null || _b === void 0 ? void 0 : _b.id) {
|
|
864
|
+
case FeeEnum.COLLECT_PERCENTAGE_TOTAL:
|
|
865
|
+
return cte.isCollect;
|
|
866
|
+
case FeeEnum.COLLECT_REVERSE_PERCENTAGE_TOTAL:
|
|
867
|
+
return cte.isCollectReverse;
|
|
873
868
|
}
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
869
|
+
}
|
|
870
|
+
var conditionalFeeToVerify;
|
|
871
|
+
var conditionalFees = (_c = ratecard === null || ratecard === void 0 ? void 0 : ratecard.RatecardConditionalFee) === null || _c === void 0 ? void 0 : _c.filter(function (it) { var _a; return it.feeId === ((_a = i.fee) === null || _a === void 0 ? void 0 : _a.id); });
|
|
872
|
+
if (defaultConditionalFees.includes((_d = i.fee) === null || _d === void 0 ? void 0 : _d.id) && !(conditionalFees === null || conditionalFees === void 0 ? void 0 : conditionalFees.length)) {
|
|
873
|
+
return false;
|
|
874
|
+
}
|
|
875
|
+
if (conditionalFees && (conditionalFees === null || conditionalFees === void 0 ? void 0 : conditionalFees.length) > 0) {
|
|
876
|
+
var _loop_1 = function (index) {
|
|
877
|
+
var conditionalFee = conditionalFees[index];
|
|
878
|
+
if (conditionalFee) {
|
|
879
|
+
conditionalFeeToVerify = conditionalFee;
|
|
880
|
+
}
|
|
881
|
+
else if ((_e = i.fee) === null || _e === void 0 ? void 0 : _e.parentId) {
|
|
882
|
+
var siblingFee_1 = (_f = lane === null || lane === void 0 ? void 0 : lane.RatecardLaneFee) === null || _f === void 0 ? void 0 : _f.find(function (it) { var _a, _b; return ((_a = it.fee) === null || _a === void 0 ? void 0 : _a.parentId) === i.fee.parentId && ((_b = it.fee) === null || _b === void 0 ? void 0 : _b.id) !== i.fee.id; });
|
|
883
|
+
if (siblingFee_1) {
|
|
884
|
+
var conditionalFeeSibling = (_g = ratecard === null || ratecard === void 0 ? void 0 : ratecard.RatecardConditionalFee) === null || _g === void 0 ? void 0 : _g.find(function (i) { var _a; return i.feeId === ((_a = siblingFee_1.fee) === null || _a === void 0 ? void 0 : _a.id); });
|
|
885
|
+
if (conditionalFeeSibling) {
|
|
886
|
+
conditionalFeeToVerify = conditionalFeeSibling;
|
|
887
887
|
}
|
|
888
888
|
}
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
}
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
}
|
|
889
|
+
}
|
|
890
|
+
if (conditionalFeeToVerify === null || conditionalFeeToVerify === void 0 ? void 0 : conditionalFeeToVerify.id) {
|
|
891
|
+
var result = verifyConditionalFee(conditionalFeeToVerify, cte);
|
|
892
|
+
if (result) {
|
|
893
|
+
return { value: true };
|
|
894
|
+
}
|
|
895
|
+
else if (index === conditionalFees.length - 1) {
|
|
896
|
+
return { value: false };
|
|
897
897
|
}
|
|
898
|
-
};
|
|
899
|
-
for (var index = 0; index < conditionalFees.length; index++) {
|
|
900
|
-
var state_1 = _loop_1(index);
|
|
901
|
-
if (typeof state_1 === "object")
|
|
902
|
-
return state_1.value;
|
|
903
898
|
}
|
|
899
|
+
};
|
|
900
|
+
for (var index = 0; index < conditionalFees.length; index++) {
|
|
901
|
+
var state_1 = _loop_1(index);
|
|
902
|
+
if (typeof state_1 === "object")
|
|
903
|
+
return state_1.value;
|
|
904
904
|
}
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
return true;
|
|
913
|
-
}
|
|
914
|
-
}
|
|
905
|
+
}
|
|
906
|
+
if (i.minKm !== null && i.minKm !== undefined) {
|
|
907
|
+
if (cte === null || cte === void 0 ? void 0 : cte.distance) {
|
|
908
|
+
var distanceInRange = +cte.distance >= +i.minKm && (!i.maxKm || +cte.distance <= +i.maxKm);
|
|
909
|
+
var vehicleTypeMatches = !i.vehicleTypeId || cte.vehicleTypeId === i.vehicleTypeId;
|
|
910
|
+
if (distanceInRange && vehicleTypeMatches) {
|
|
911
|
+
return true;
|
|
915
912
|
}
|
|
916
913
|
}
|
|
917
|
-
|
|
918
|
-
|
|
914
|
+
}
|
|
915
|
+
else if (i.minWeight) {
|
|
916
|
+
if (cte === null || cte === void 0 ? void 0 : cte.taxedWeight) {
|
|
917
|
+
if (Math.ceil(+cte.taxedWeight) >= +i.minWeight) {
|
|
918
|
+
if (Math.ceil(+cte.taxedWeight) <= +i.maxWeight) {
|
|
919
|
+
return true;
|
|
920
|
+
}
|
|
921
|
+
else if (!i.maxWeight) {
|
|
922
|
+
return true;
|
|
923
|
+
}
|
|
924
|
+
}
|
|
919
925
|
}
|
|
926
|
+
}
|
|
927
|
+
else {
|
|
928
|
+
return true;
|
|
929
|
+
}
|
|
930
|
+
return false;
|
|
931
|
+
});
|
|
932
|
+
// Remover fees duplicadas, mantendo apenas uma ocorrência de cada feeId
|
|
933
|
+
var seenFeeIds = new Set();
|
|
934
|
+
var uniqueFees = filteredFees === null || filteredFees === void 0 ? void 0 : filteredFees.filter(function (fee) {
|
|
935
|
+
if (fee.feeId && seenFeeIds.has(fee.feeId)) {
|
|
920
936
|
return false;
|
|
921
|
-
});
|
|
922
|
-
if ((newFilteredFees === null || newFilteredFees === void 0 ? void 0 : newFilteredFees.length) > 0) {
|
|
923
|
-
return newFilteredFees;
|
|
924
937
|
}
|
|
938
|
+
if (fee.feeId) {
|
|
939
|
+
seenFeeIds.add(fee.feeId);
|
|
940
|
+
}
|
|
941
|
+
return true;
|
|
942
|
+
});
|
|
943
|
+
return uniqueFees;
|
|
944
|
+
};
|
|
945
|
+
|
|
946
|
+
var getAllFeesForCalculation = function (_a) {
|
|
947
|
+
var _b;
|
|
948
|
+
var lane = _a.lane, ratecard = _a.ratecard, cte = _a.cte;
|
|
949
|
+
// Obter taxas aplicáveis (função atual)
|
|
950
|
+
var applicableFees = getFilteredFeesToAudit({ lane: lane, ratecard: ratecard, cte: cte });
|
|
951
|
+
// Extrair tipos de taxas únicos das taxas aplicáveis
|
|
952
|
+
var feeTypes = Array.from(new Set(applicableFees === null || applicableFees === void 0 ? void 0 : applicableFees.map(function (fee) { var _a; return (_a = fee.fee) === null || _a === void 0 ? void 0 : _a.id; }).filter(Boolean)));
|
|
953
|
+
// Encontrar taxas de intervalo do mesmo tipo
|
|
954
|
+
var intervalFees = (_b = lane === null || lane === void 0 ? void 0 : lane.RatecardLaneFee) === null || _b === void 0 ? void 0 : _b.filter(function (fee) {
|
|
955
|
+
var _a;
|
|
956
|
+
return feeTypes.includes((_a = fee.fee) === null || _a === void 0 ? void 0 : _a.id) &&
|
|
957
|
+
(fee.minWeight || fee.maxWeight);
|
|
958
|
+
});
|
|
959
|
+
// Combinar taxas aplicáveis com taxas de intervalo, removendo duplicatas
|
|
960
|
+
var allFees = __spreadArray(__spreadArray([], (applicableFees || []), true), (intervalFees || []), true);
|
|
961
|
+
var uniqueFees = Array.from(new Map(allFees.map(function (fee) { return [fee.id, fee]; })).values());
|
|
962
|
+
return uniqueFees;
|
|
963
|
+
};
|
|
964
|
+
|
|
965
|
+
var getLaneFromRatecard = function (cte) {
|
|
966
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
|
|
967
|
+
var ratecard = getRatecardFromCte(cte);
|
|
968
|
+
var cityOriginId = cte.cityOriginId, cityDestination = cte.cityDestination;
|
|
969
|
+
var destinationUf = (_a = cityDestination === null || cityDestination === void 0 ? void 0 : cityDestination.state) === null || _a === void 0 ? void 0 : _a.uf;
|
|
970
|
+
// Encontrar a ratecardRegion da cidade de destino
|
|
971
|
+
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;
|
|
972
|
+
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) {
|
|
973
|
+
return undefined;
|
|
974
|
+
}
|
|
975
|
+
// Lógica diferenciada por modal
|
|
976
|
+
switch (ratecard.modalId) {
|
|
977
|
+
case RatecardModalEnum.ROAD_DOMESTIC_FTL:
|
|
978
|
+
// FTL: Verificar rota por UF de destino
|
|
979
|
+
if (destinationUf) {
|
|
980
|
+
var directLane = ratecard.RatecardLane.find(function (i) {
|
|
981
|
+
return i.ufDestination === destinationUf && i.ratecardRegionId === destinationRatecardRegionId;
|
|
982
|
+
});
|
|
983
|
+
if (directLane) {
|
|
984
|
+
return directLane;
|
|
985
|
+
}
|
|
986
|
+
// Fallback: Verificar se existe lane única com fees de KM e cidade origem no ratecard_origin_cities
|
|
987
|
+
var uniqueLane = ratecard.RatecardLane[0];
|
|
988
|
+
// Verificar se a lane tem fees com intervalo de KM
|
|
989
|
+
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; });
|
|
990
|
+
// Verificar se a cidade de origem está no ratecard_origin_cities
|
|
991
|
+
var hasOriginCity = (_f = ratecard.ratecard_origin_cities) === null || _f === void 0 ? void 0 : _f.some(function (originCity) { return originCity.cityId === cityOriginId; });
|
|
992
|
+
if (hasKmFees && hasOriginCity) {
|
|
993
|
+
// Mockar informações para exibição no frontend
|
|
994
|
+
return __assign(__assign({}, uniqueLane), { city: cte.cityOrigin, ufDestination: destinationUf, ratecardRegion: uniqueLane.ratecardRegion || { name: destinationUf } });
|
|
995
|
+
}
|
|
996
|
+
// Rota inversa FTL: Verificar se cidade de destino está em ratecard_origin_cities
|
|
997
|
+
var originUf_1 = (_h = (_g = cte.cityOrigin) === null || _g === void 0 ? void 0 : _g.state) === null || _h === void 0 ? void 0 : _h.uf;
|
|
998
|
+
if (originUf_1) {
|
|
999
|
+
// Verificar se existe lane com ufDestination = originUf
|
|
1000
|
+
var reverseLane = ratecard.RatecardLane.find(function (i) {
|
|
1001
|
+
return i.ufDestination === originUf_1;
|
|
1002
|
+
});
|
|
1003
|
+
if (reverseLane) {
|
|
1004
|
+
// Verificar se a cidade de destino está no ratecard_origin_cities
|
|
1005
|
+
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); });
|
|
1006
|
+
if (hasDestinationCity) {
|
|
1007
|
+
return reverseLane;
|
|
1008
|
+
}
|
|
1009
|
+
}
|
|
1010
|
+
// Fallback inverso: Lane única com cidade de destino em ratecard_origin_cities
|
|
1011
|
+
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); });
|
|
1012
|
+
if (hasKmFees && hasDestinationCityInOrigins) {
|
|
1013
|
+
// Mockar informações para exibição no frontend (rota inversa)
|
|
1014
|
+
return __assign(__assign({}, uniqueLane), { city: cityDestination, ufDestination: originUf_1, ratecardRegion: uniqueLane.ratecardRegion || { name: originUf_1 } });
|
|
1015
|
+
}
|
|
1016
|
+
}
|
|
1017
|
+
}
|
|
1018
|
+
break;
|
|
1019
|
+
case RatecardModalEnum.ROAD_DOMESTIC_LTL:
|
|
1020
|
+
default:
|
|
1021
|
+
// LTL: Lógica original (rota direta + inversa)
|
|
1022
|
+
if (cityOriginId && destinationUf) {
|
|
1023
|
+
// Primeiro, buscar rota direta (Origem -> Destino)
|
|
1024
|
+
var directLane = ratecard.RatecardLane.find(function (i) {
|
|
1025
|
+
return i.cityOriginId === cityOriginId && i.ufDestination === destinationUf && i.ratecardRegionId === destinationRatecardRegionId;
|
|
1026
|
+
});
|
|
1027
|
+
if (directLane) {
|
|
1028
|
+
return directLane;
|
|
1029
|
+
}
|
|
1030
|
+
// Se não encontrar rota direta, buscar rota inversa (Destino -> Origem)
|
|
1031
|
+
// Para isso, precisamos encontrar a UF da origem e sua ratecardRegion
|
|
1032
|
+
var originUf_2 = (_m = (_l = cte.cityOrigin) === null || _l === void 0 ? void 0 : _l.state) === null || _m === void 0 ? void 0 : _m.uf;
|
|
1033
|
+
// Encontrar a ratecardRegion da cidade de origem
|
|
1034
|
+
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;
|
|
1035
|
+
if (originUf_2) {
|
|
1036
|
+
var reverseLane = ratecard.RatecardLane.find(function (i) {
|
|
1037
|
+
return i.cityOriginId === (cityDestination === null || cityDestination === void 0 ? void 0 : cityDestination.id) && i.ufDestination === originUf_2 && i.ratecardRegionId === originRatecardRegionId_1;
|
|
1038
|
+
});
|
|
1039
|
+
if (reverseLane) {
|
|
1040
|
+
return reverseLane;
|
|
1041
|
+
}
|
|
1042
|
+
}
|
|
1043
|
+
}
|
|
1044
|
+
break;
|
|
925
1045
|
}
|
|
1046
|
+
return undefined;
|
|
926
1047
|
};
|
|
927
1048
|
|
|
928
|
-
var getCtesFeesResult = function (feesToCalc, cte) {
|
|
1049
|
+
var getCtesFeesResult = function (feesToCalc, cte, allFeesForCalc) {
|
|
929
1050
|
var _a, _b, _c, _d;
|
|
930
1051
|
var results = [];
|
|
931
1052
|
var _loop_1 = function (item) {
|
|
932
|
-
var feeTotal = calculateFee(item, cte, feesToCalc);
|
|
1053
|
+
var feeTotal = calculateFee(item, cte, feesToCalc, true, allFeesForCalc);
|
|
933
1054
|
if (feeTotal === null || feeTotal === void 0 ? void 0 : feeTotal.totalFee) {
|
|
934
1055
|
var totalFee = feeTotal.totalFee, resultFee = feeTotal.resultFee, feeValue = feeTotal.feeValue;
|
|
935
1056
|
var totalToPush = totalFee;
|
|
@@ -973,9 +1094,9 @@ var getCtesFeesResult = function (feesToCalc, cte) {
|
|
|
973
1094
|
return results;
|
|
974
1095
|
};
|
|
975
1096
|
|
|
976
|
-
var getCteLaneFeesTotal = function (feesToCalc, cte) {
|
|
1097
|
+
var getCteLaneFeesTotal = function (feesToCalc, cte, allFeesForCalc) {
|
|
977
1098
|
if ((feesToCalc === null || feesToCalc === void 0 ? void 0 : feesToCalc.length) > 0) {
|
|
978
|
-
var results = getCtesFeesResult(feesToCalc, cte);
|
|
1099
|
+
var results = getCtesFeesResult(feesToCalc, cte, allFeesForCalc);
|
|
979
1100
|
/*const results = [];
|
|
980
1101
|
|
|
981
1102
|
for (const item of feesToCalc) {
|
|
@@ -1048,9 +1169,26 @@ var getCteLaneFeesTotal = function (feesToCalc, cte) {
|
|
|
1048
1169
|
};
|
|
1049
1170
|
|
|
1050
1171
|
var getAuditTotalFromCte = function (cte) {
|
|
1051
|
-
var
|
|
1052
|
-
var
|
|
1053
|
-
|
|
1172
|
+
var lane = getLaneFromRatecard(cte);
|
|
1173
|
+
var ratecard = getRatecardFromCte(cte);
|
|
1174
|
+
// Obter taxas filtradas com lógica de coleta
|
|
1175
|
+
var laneFees = lane && ratecard ?
|
|
1176
|
+
getFilteredFeesToAudit({ lane: lane, ratecard: ratecard, cte: cte }) : [];
|
|
1177
|
+
// Obter todas as taxas para cálculo
|
|
1178
|
+
var allFeesForCalc = lane && ratecard ?
|
|
1179
|
+
getAllFeesForCalculation({
|
|
1180
|
+
lane: lane,
|
|
1181
|
+
ratecard: ratecard,
|
|
1182
|
+
cte: cte
|
|
1183
|
+
}) : [];
|
|
1184
|
+
var total = getCteLaneFeesTotal(laneFees || [], cte, allFeesForCalc);
|
|
1185
|
+
// Se for reentrega, verificar o valor mínimo
|
|
1186
|
+
if (cte.isRedelivery && total) {
|
|
1187
|
+
var ratecard_1 = getRatecardFromCte(cte);
|
|
1188
|
+
if ((ratecard_1 === null || ratecard_1 === void 0 ? void 0 : ratecard_1.redeliveryMinValue) && total < ratecard_1.redeliveryMinValue) {
|
|
1189
|
+
return +ratecard_1.redeliveryMinValue;
|
|
1190
|
+
}
|
|
1191
|
+
}
|
|
1054
1192
|
return total !== null && total !== void 0 ? total : 0;
|
|
1055
1193
|
};
|
|
1056
1194
|
|
|
@@ -7185,176 +7323,99 @@ var getCteDateRange = function (ctes) {
|
|
|
7185
7323
|
return "".concat(formatDate(oldest), " - ").concat(formatDate(newest));
|
|
7186
7324
|
};
|
|
7187
7325
|
|
|
7188
|
-
var
|
|
7189
|
-
var _b;
|
|
7190
|
-
|
|
7191
|
-
|
|
7192
|
-
|
|
7193
|
-
|
|
7194
|
-
|
|
7195
|
-
|
|
7196
|
-
|
|
7197
|
-
|
|
7198
|
-
|
|
7199
|
-
|
|
7200
|
-
|
|
7201
|
-
|
|
7202
|
-
if (defaultConditionalFees.includes((_b = i.fee) === null || _b === void 0 ? void 0 : _b.id) && !(conditionalFees === null || conditionalFees === void 0 ? void 0 : conditionalFees.length)) {
|
|
7203
|
-
return false;
|
|
7204
|
-
}
|
|
7205
|
-
if (conditionalFees && (conditionalFees === null || conditionalFees === void 0 ? void 0 : conditionalFees.length) > 0) {
|
|
7206
|
-
var _loop_1 = function (index) {
|
|
7207
|
-
var conditionalFee = conditionalFees[index];
|
|
7208
|
-
if (conditionalFee) {
|
|
7209
|
-
conditionalFeeToVerify = conditionalFee;
|
|
7210
|
-
}
|
|
7211
|
-
else if ((_c = i.fee) === null || _c === void 0 ? void 0 : _c.parentId) {
|
|
7212
|
-
var siblingFee_1 = (_d = lane === null || lane === void 0 ? void 0 : lane.RatecardLaneFee) === null || _d === void 0 ? void 0 : _d.find(function (it) { var _a, _b; return ((_a = it.fee) === null || _a === void 0 ? void 0 : _a.parentId) === i.fee.parentId && ((_b = it.fee) === null || _b === void 0 ? void 0 : _b.id) !== i.fee.id; });
|
|
7213
|
-
if (siblingFee_1) {
|
|
7214
|
-
var conditionalFeeSibling = (_e = ratecard === null || ratecard === void 0 ? void 0 : ratecard.RatecardConditionalFee) === null || _e === void 0 ? void 0 : _e.find(function (i) { var _a; return i.feeId === ((_a = siblingFee_1.fee) === null || _a === void 0 ? void 0 : _a.id); });
|
|
7215
|
-
if (conditionalFeeSibling) {
|
|
7216
|
-
conditionalFeeToVerify = conditionalFeeSibling;
|
|
7326
|
+
var getCteLane = function (cte) {
|
|
7327
|
+
var _a, _b, _c, _d, _e;
|
|
7328
|
+
if (cte === null || cte === void 0 ? void 0 : cte.carrier) {
|
|
7329
|
+
var carrier = cte === null || cte === void 0 ? void 0 : cte.carrier;
|
|
7330
|
+
if ((_a = carrier === null || carrier === void 0 ? void 0 : carrier.Ratecard) === null || _a === void 0 ? void 0 : _a.length) {
|
|
7331
|
+
var destinationUf_1 = (_c = (_b = cte === null || cte === void 0 ? void 0 : cte.cityDestination) === null || _b === void 0 ? void 0 : _b.state) === null || _c === void 0 ? void 0 : _c.uf;
|
|
7332
|
+
if (carrier === null || carrier === void 0 ? void 0 : carrier.Ratecard[0]) {
|
|
7333
|
+
var ratecard = carrier === null || carrier === void 0 ? void 0 : carrier.Ratecard[0];
|
|
7334
|
+
if (ratecard.RatecardLane && ((_d = ratecard.RatecardLane) === null || _d === void 0 ? void 0 : _d.length) > 0 && cte.cityOriginId && destinationUf_1) {
|
|
7335
|
+
var region = (_e = ratecard.RatecardRegionCity) === null || _e === void 0 ? void 0 : _e.find(function (it) { return it.cityId === cte.cityDestinationId; });
|
|
7336
|
+
var regionId_1 = (region === null || region === void 0 ? void 0 : region.ratecardRegionId) ? region.ratecardRegionId : (region === null || region === void 0 ? void 0 : region.regionId) ? region.regionId : 0;
|
|
7337
|
+
return ratecard.RatecardLane.find(function (i) {
|
|
7338
|
+
if (i.cityOriginId === cte.cityOriginId && i.ufDestination === destinationUf_1 && i.ratecardRegionId === regionId_1) {
|
|
7339
|
+
return true;
|
|
7217
7340
|
}
|
|
7218
|
-
|
|
7219
|
-
|
|
7220
|
-
if (conditionalFeeToVerify === null || conditionalFeeToVerify === void 0 ? void 0 : conditionalFeeToVerify.id) {
|
|
7221
|
-
var result = verifyConditionalFee(conditionalFeeToVerify, cte);
|
|
7222
|
-
if (result) {
|
|
7223
|
-
return { value: true };
|
|
7224
|
-
}
|
|
7225
|
-
else if (index === conditionalFees.length - 1) {
|
|
7226
|
-
return { value: false };
|
|
7227
|
-
}
|
|
7228
|
-
}
|
|
7229
|
-
};
|
|
7230
|
-
for (var index = 0; index < conditionalFees.length; index++) {
|
|
7231
|
-
var state_1 = _loop_1(index);
|
|
7232
|
-
if (typeof state_1 === "object")
|
|
7233
|
-
return state_1.value;
|
|
7234
|
-
}
|
|
7235
|
-
}
|
|
7236
|
-
if (i.minKm !== null && i.minKm !== undefined) {
|
|
7237
|
-
if (cte === null || cte === void 0 ? void 0 : cte.distance) {
|
|
7238
|
-
var distanceInRange = +cte.distance >= +i.minKm && (!i.maxKm || +cte.distance <= +i.maxKm);
|
|
7239
|
-
var vehicleTypeMatches = !i.vehicleTypeId || cte.vehicleTypeId === i.vehicleTypeId;
|
|
7240
|
-
if (distanceInRange && vehicleTypeMatches) {
|
|
7241
|
-
return true;
|
|
7242
|
-
}
|
|
7243
|
-
}
|
|
7244
|
-
}
|
|
7245
|
-
else if (i.minWeight) {
|
|
7246
|
-
if (cte === null || cte === void 0 ? void 0 : cte.taxedWeight) {
|
|
7247
|
-
if (Math.ceil(+cte.taxedWeight) >= +i.minWeight) {
|
|
7248
|
-
if (Math.ceil(+cte.taxedWeight) <= +i.maxWeight) {
|
|
7249
|
-
return true;
|
|
7250
|
-
}
|
|
7251
|
-
else if (!i.maxWeight) {
|
|
7252
|
-
return true;
|
|
7253
|
-
}
|
|
7341
|
+
return false;
|
|
7342
|
+
});
|
|
7254
7343
|
}
|
|
7255
7344
|
}
|
|
7256
7345
|
}
|
|
7257
|
-
|
|
7258
|
-
return true;
|
|
7259
|
-
}
|
|
7260
|
-
return false;
|
|
7261
|
-
});
|
|
7262
|
-
// Remover fees duplicadas, mantendo apenas uma ocorrência de cada feeId
|
|
7263
|
-
var seenFeeIds = new Set();
|
|
7264
|
-
var uniqueFees = filteredFees === null || filteredFees === void 0 ? void 0 : filteredFees.filter(function (fee) {
|
|
7265
|
-
if (fee.feeId && seenFeeIds.has(fee.feeId)) {
|
|
7266
|
-
return false;
|
|
7267
|
-
}
|
|
7268
|
-
if (fee.feeId) {
|
|
7269
|
-
seenFeeIds.add(fee.feeId);
|
|
7270
|
-
}
|
|
7271
|
-
return true;
|
|
7272
|
-
});
|
|
7273
|
-
return uniqueFees;
|
|
7346
|
+
}
|
|
7274
7347
|
};
|
|
7275
7348
|
|
|
7276
|
-
var
|
|
7277
|
-
var _a, _b
|
|
7349
|
+
var getLaneFeesToCalc = function (cte) {
|
|
7350
|
+
var _a, _b;
|
|
7278
7351
|
var ratecard = getRatecardFromCte(cte);
|
|
7279
|
-
var
|
|
7280
|
-
|
|
7281
|
-
|
|
7282
|
-
|
|
7283
|
-
|
|
7284
|
-
|
|
7285
|
-
|
|
7286
|
-
|
|
7287
|
-
|
|
7288
|
-
|
|
7289
|
-
|
|
7290
|
-
|
|
7291
|
-
|
|
7292
|
-
|
|
7293
|
-
|
|
7294
|
-
|
|
7295
|
-
|
|
7296
|
-
|
|
7297
|
-
|
|
7298
|
-
|
|
7299
|
-
|
|
7300
|
-
|
|
7301
|
-
|
|
7302
|
-
|
|
7303
|
-
|
|
7304
|
-
|
|
7305
|
-
|
|
7306
|
-
|
|
7307
|
-
// Rota inversa FTL: Verificar se cidade de destino está em ratecard_origin_cities
|
|
7308
|
-
var originUf_1 = (_h = (_g = cte.cityOrigin) === null || _g === void 0 ? void 0 : _g.state) === null || _h === void 0 ? void 0 : _h.uf;
|
|
7309
|
-
if (originUf_1) {
|
|
7310
|
-
// Verificar se existe lane com ufDestination = originUf
|
|
7311
|
-
var reverseLane = ratecard.RatecardLane.find(function (i) {
|
|
7312
|
-
return i.ufDestination === originUf_1;
|
|
7313
|
-
});
|
|
7314
|
-
if (reverseLane) {
|
|
7315
|
-
// Verificar se a cidade de destino está no ratecard_origin_cities
|
|
7316
|
-
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); });
|
|
7317
|
-
if (hasDestinationCity) {
|
|
7318
|
-
return reverseLane;
|
|
7352
|
+
var lane = getCteLane(cte);
|
|
7353
|
+
if ((_a = lane === null || lane === void 0 ? void 0 : lane.RatecardLaneFee) === null || _a === void 0 ? void 0 : _a.length) {
|
|
7354
|
+
var newFilteredFees = (_b = lane === null || lane === void 0 ? void 0 : lane.RatecardLaneFee) === null || _b === void 0 ? void 0 : _b.filter(function (i) {
|
|
7355
|
+
var _a, _b, _c, _d, _e;
|
|
7356
|
+
var defaultConditionalFees = [
|
|
7357
|
+
FeeEnum.TDA_FREIGHT,
|
|
7358
|
+
FeeEnum.TDA_MIN,
|
|
7359
|
+
FeeEnum.TDE_FREIGHT,
|
|
7360
|
+
FeeEnum.TDE_MIN,
|
|
7361
|
+
];
|
|
7362
|
+
var conditionalFeeToVerify;
|
|
7363
|
+
var conditionalFees = (_a = ratecard === null || ratecard === void 0 ? void 0 : ratecard.RatecardConditionalFee) === null || _a === void 0 ? void 0 : _a.filter(function (it) { var _a; return it.feeId === ((_a = i.fee) === null || _a === void 0 ? void 0 : _a.id); });
|
|
7364
|
+
if (defaultConditionalFees.includes((_b = i.fee) === null || _b === void 0 ? void 0 : _b.id) && !(conditionalFees === null || conditionalFees === void 0 ? void 0 : conditionalFees.length)) {
|
|
7365
|
+
return false;
|
|
7366
|
+
}
|
|
7367
|
+
if (conditionalFees && (conditionalFees === null || conditionalFees === void 0 ? void 0 : conditionalFees.length) > 0) {
|
|
7368
|
+
var _loop_1 = function (index) {
|
|
7369
|
+
var conditionalFee = conditionalFees[index];
|
|
7370
|
+
if (conditionalFee) {
|
|
7371
|
+
conditionalFeeToVerify = conditionalFee;
|
|
7372
|
+
}
|
|
7373
|
+
else if ((_c = i.fee) === null || _c === void 0 ? void 0 : _c.parentId) {
|
|
7374
|
+
var siblingFee_1 = (_d = lane === null || lane === void 0 ? void 0 : lane.RatecardLaneFee) === null || _d === void 0 ? void 0 : _d.find(function (it) { var _a, _b; return ((_a = it.fee) === null || _a === void 0 ? void 0 : _a.parentId) === i.fee.parentId && ((_b = it.fee) === null || _b === void 0 ? void 0 : _b.id) !== i.fee.id; });
|
|
7375
|
+
if (siblingFee_1) {
|
|
7376
|
+
var conditionalFeeSibling = (_e = ratecard === null || ratecard === void 0 ? void 0 : ratecard.RatecardConditionalFee) === null || _e === void 0 ? void 0 : _e.find(function (i) { var _a; return i.feeId === ((_a = siblingFee_1.fee) === null || _a === void 0 ? void 0 : _a.id); });
|
|
7377
|
+
if (conditionalFeeSibling) {
|
|
7378
|
+
conditionalFeeToVerify = conditionalFeeSibling;
|
|
7379
|
+
}
|
|
7319
7380
|
}
|
|
7320
7381
|
}
|
|
7321
|
-
|
|
7322
|
-
|
|
7323
|
-
|
|
7324
|
-
|
|
7325
|
-
|
|
7382
|
+
if (conditionalFeeToVerify === null || conditionalFeeToVerify === void 0 ? void 0 : conditionalFeeToVerify.id) {
|
|
7383
|
+
var result = verifyConditionalFee(conditionalFeeToVerify, cte);
|
|
7384
|
+
if (result) {
|
|
7385
|
+
return { value: true };
|
|
7386
|
+
}
|
|
7387
|
+
else if (index === conditionalFees.length - 1) {
|
|
7388
|
+
return { value: false };
|
|
7389
|
+
}
|
|
7326
7390
|
}
|
|
7391
|
+
};
|
|
7392
|
+
for (var index = 0; index < conditionalFees.length; index++) {
|
|
7393
|
+
var state_1 = _loop_1(index);
|
|
7394
|
+
if (typeof state_1 === "object")
|
|
7395
|
+
return state_1.value;
|
|
7327
7396
|
}
|
|
7328
7397
|
}
|
|
7329
|
-
|
|
7330
|
-
|
|
7331
|
-
|
|
7332
|
-
|
|
7333
|
-
|
|
7334
|
-
|
|
7335
|
-
|
|
7336
|
-
|
|
7337
|
-
|
|
7338
|
-
if (directLane) {
|
|
7339
|
-
return directLane;
|
|
7340
|
-
}
|
|
7341
|
-
// Se não encontrar rota direta, buscar rota inversa (Destino -> Origem)
|
|
7342
|
-
// Para isso, precisamos encontrar a UF da origem e sua ratecardRegion
|
|
7343
|
-
var originUf_2 = (_m = (_l = cte.cityOrigin) === null || _l === void 0 ? void 0 : _l.state) === null || _m === void 0 ? void 0 : _m.uf;
|
|
7344
|
-
// Encontrar a ratecardRegion da cidade de origem
|
|
7345
|
-
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;
|
|
7346
|
-
if (originUf_2) {
|
|
7347
|
-
var reverseLane = ratecard.RatecardLane.find(function (i) {
|
|
7348
|
-
return i.cityOriginId === (cityDestination === null || cityDestination === void 0 ? void 0 : cityDestination.id) && i.ufDestination === originUf_2 && i.ratecardRegionId === originRatecardRegionId_1;
|
|
7349
|
-
});
|
|
7350
|
-
if (reverseLane) {
|
|
7351
|
-
return reverseLane;
|
|
7398
|
+
if (i.minWeight) {
|
|
7399
|
+
if (cte === null || cte === void 0 ? void 0 : cte.taxedWeight) {
|
|
7400
|
+
if (Math.ceil(+cte.taxedWeight) >= +i.minWeight) {
|
|
7401
|
+
if (Math.ceil(+cte.taxedWeight) <= +i.maxWeight) {
|
|
7402
|
+
return true;
|
|
7403
|
+
}
|
|
7404
|
+
else if (!i.maxWeight) {
|
|
7405
|
+
return true;
|
|
7406
|
+
}
|
|
7352
7407
|
}
|
|
7353
7408
|
}
|
|
7354
7409
|
}
|
|
7355
|
-
|
|
7410
|
+
else {
|
|
7411
|
+
return true;
|
|
7412
|
+
}
|
|
7413
|
+
return false;
|
|
7414
|
+
});
|
|
7415
|
+
if ((newFilteredFees === null || newFilteredFees === void 0 ? void 0 : newFilteredFees.length) > 0) {
|
|
7416
|
+
return newFilteredFees;
|
|
7417
|
+
}
|
|
7356
7418
|
}
|
|
7357
|
-
return undefined;
|
|
7358
7419
|
};
|
|
7359
7420
|
|
|
7360
7421
|
var getNormalizedCityName = function (name) {
|
|
@@ -7552,5 +7613,5 @@ var setFormattedDatesInObjects = function (objectFormat) { return __awaiter(void
|
|
|
7552
7613
|
});
|
|
7553
7614
|
}); };
|
|
7554
7615
|
|
|
7555
|
-
export { ApplicationColumnNameEnum, ApplicationEnum, CountryEnum, CteStatusEnum, CteVehicleTypeEnum, CurrencyEnum, DocumentTypeEnum, DomainConfigurationEnum, DomainTypeEnum, FeeCalculationTypeEnum, FeeCategoryEnum, FeeEnum, FreightRegionEnum, ImapHostsEnum, ModalEnum, NotificationTypeEnum, PermissionEnum, RatecardConditionalFeeTypeEnum, RatecardModalEnum, SlaRegionEnum, SpotStatusEnum, TrackProcessProviderTypeEnum, applyRedeliveryMultiplier, calculateFee, convertNumberToCurrency, filterSiblingFees, formatDateString, getAuditTotalFromCte, getConfigurationFromDomain, getContractFromFreight, getContractRouteFromFreight, getCookies, getCteDateRange, getCteLane, getCteLaneFeesTotal, getCtesFeesResult, getDataFromToken, getFilteredFeesToAudit, getFormattedFreightPlaceName, getLaneFeesToCalc, getLaneFromRatecard, getNormalizedCityName, getRatecardFromCte, getRouteDeliveryTimeFromFreight, getRouteOnTimeFromFreight, normalizeString, setFormattedDatesInObjects, verifyConditionalFee, verifyDefaultFees };
|
|
7616
|
+
export { ApplicationColumnNameEnum, ApplicationEnum, CountryEnum, CteStatusEnum, CteVehicleTypeEnum, CurrencyEnum, DocumentTypeEnum, DomainConfigurationEnum, DomainTypeEnum, FeeCalculationTypeEnum, FeeCategoryEnum, FeeEnum, FreightRegionEnum, ImapHostsEnum, ModalEnum, NotificationTypeEnum, PermissionEnum, RatecardConditionalFeeTypeEnum, RatecardModalEnum, SlaRegionEnum, SpotStatusEnum, TrackProcessProviderTypeEnum, applyRedeliveryMultiplier, calculateFee, convertNumberToCurrency, filterSiblingFees, formatDateString, getAllFeesForCalculation, getAuditTotalFromCte, getConfigurationFromDomain, getContractFromFreight, getContractRouteFromFreight, getCookies, getCteDateRange, getCteLane, getCteLaneFeesTotal, getCtesFeesResult, getDataFromToken, getFilteredFeesToAudit, getFormattedFreightPlaceName, getLaneFeesToCalc, getLaneFromRatecard, getNormalizedCityName, getRatecardFromCte, getRouteDeliveryTimeFromFreight, getRouteOnTimeFromFreight, normalizeString, setFormattedDatesInObjects, verifyConditionalFee, verifyDefaultFees };
|
|
7556
7617
|
//# sourceMappingURL=index.esm.js.map
|
package/build/index.esm.js.gz
CHANGED
|
Binary file
|