shareneus 1.5.26 → 1.5.27
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/dist/index.d.ts
CHANGED
|
@@ -128,7 +128,7 @@ export { SalesReceivePrintService } from "./sales-receive/sales-receive-print.se
|
|
|
128
128
|
export { SalesReceiveTotalsService } from "./sales-receive/sales-receive-totals.service";
|
|
129
129
|
export { GetItemPriceForPriceList } from "./inventory/items/item-price-for-pricelist";
|
|
130
130
|
export { CalcItemFinalSalePrice } from "./inventory/items/item-price-for-pricelist";
|
|
131
|
-
export { ApplyServicePriceListToProcedure, ApplyServicePriceListToOpcode } from "./services/service-price-for-pricelist";
|
|
131
|
+
export { ApplyServicePriceListToProcedure, ApplyServicePriceListToOpcode, GetServicePriceForPriceList } from "./services/service-price-for-pricelist";
|
|
132
132
|
export { IsNotNull, IsNull } from "./shared/util";
|
|
133
133
|
export { GetAgeString, GetNumber } from "./shared/util";
|
|
134
134
|
export { SalesTotalCalculationsWithDecimals } from "./sales-receive/sales-total-calculation";
|
package/dist/index.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.DebitNotePdfService = exports.DCWithoutPricePdfService = exports.DCLandscapeWithoutPricePdfService = exports.DCLandscapePdfService = exports.CustomerBalancesService = exports.SalesByCustomerPDFService = exports.CustWiseSalesDetailsService = exports.CreditNoteTotalsService = exports.CreditNotePdfService = exports.ConsultationPDFService = exports.ConsultationFullPrintService = exports.ConsultationFeeReceiptPrintService = exports.CNPrintService = exports.ChecklistsPDFService = exports.CheckListPrintService = exports.CategoryWiseItemPDFService = exports.SalesReceiptprintService = exports.AppointmentTotalsService = exports.AnalysisPDFService = exports.VenBalanceXlsxFileService = exports.TallySalesImportXlsxFileService = exports.StockXlsxFileService = exports.IssueSparesXlsxFileService = exports.ScheduledDrugXlsxFileService = exports.ScheduledDrugSummaryXlsxFileService = exports.SalesByServiceSummaryXlsxFileService = exports.SummaryXlsxFileService = exports.ServiceAdvisorWisePartXlsxFileService = exports.ServiceAdvisorWiseLaborXlsxFileService = exports.RepairOrdersXlsxFileService = exports.PaymentsMadeXlsxFileService = exports.PaymentReceiveXlsxFileService = exports.OperatorWiseSummaryXlsxFileService = exports.OperatorWiseDetailsXlsxFileService = exports.ManfWiseSalesXlsxFileService = exports.ItemsWiseSalesXlsxFileService = exports.ItemWiseMOSummaryXlsxFileService = exports.ItemWiseMODetailsXlsxFileService = exports.ItemWiseDoctorSaleXlsxFileService = exports.InvoicesWiseXlsxFileService = exports.InsuranceExpireXlsxFileService = exports.GSTR2ExcelService = exports.GSTR1ExcelService = exports.GSTROXlsxFileService = exports.ExpiringDrugsXlsxFileService = exports.SalesByCustomerXlsxFileService = exports.CustWiseSalesXlsxFileService = exports.CustBalanceXlsxFileService = exports.CategoryWiseItemXlsxFileService = exports.AnalysisXlsxFileService = void 0;
|
|
4
4
|
exports.SharedPDFService = exports.SharedInvoiceprintService = exports.WOPrintService = exports.ScheduledDrugSummaryPDFService = exports.ScheduledDrugPDFService = exports.SalesTotalsService = exports.SaleReceiptPrintService = exports.SalesReceiptpdfService = exports.SalesPrintService = exports.SalesPdfService = exports.SalesByServiceSummaryPDF = exports.ROTotalsService = exports.ROPrintService = exports.RoprintService = exports.RepairOrdersReportsPDFService = exports.ReorderPointPDFService = exports.ReceiptPrintService = exports.PurchaseOrderPDFService = exports.PurchaseOrderTotalsService = exports.PurchaseOrderPrintService = exports.PosReceiptPrintService = exports.POTotalsService = exports.PaymentsReportPDFService = exports.ReceiptPDFService = exports.PackShipPrintService = exports.PackShipPDFService = exports.OperatorWiseSalesSummaryPDF = exports.OperatorWiseSalesDetailsPDF = exports.MaterialOutprintService = exports.MeetingPdfService = exports.ManfWiseSalesService = exports.ItemWiseSalesPDFService = exports.ItemWiseMOSummaryPDF = exports.ItemWiseMODetailsPDF = exports.ItemWiseDoctorSalePDFService = exports.ItemDetaisPdf = exports.IssuePartsprintService = exports.InvoiceTotalsService = exports.InvoiceLandscapePdfService = exports.InvPrintService = exports.InvoiceprintService = exports.InsuranceExpirePDF = exports.ExpiringDrugPDFService = exports.EstPrintService = exports.EquipmentDesignPdf = exports.DeliveryChallanTotalsService = exports.DeliveryChallanPrintService = exports.DeliveryChallanPdfService = exports.DebitNoteTotalsService = exports.DebitNotePrintService = void 0;
|
|
5
|
-
exports.Divide = exports.Multiply = exports.Subtract = exports.Add = exports.ServiceHistoryPDFService = exports.SalesTotalCalculationsWithDecimals = exports.GetNumber = exports.GetAgeString = exports.IsNull = exports.IsNotNull = exports.ApplyServicePriceListToOpcode = exports.ApplyServicePriceListToProcedure = exports.CalcItemFinalSalePrice = exports.GetItemPriceForPriceList = exports.SalesReceiveTotalsService = exports.SalesReceivePrintService = exports.SalesReceivePdfService = exports.AdjustmentDrugPDFService = exports.HSNSummaryPDFService = exports.HSNSummaryExcelService = exports.ItemBarCodeLabelPdf = exports.NextServiceDatePDFService = exports.NextServiceDateXlsxFileService = exports.ConsultationLetterHeadPDFService = exports.InvoiceLetterheadPdfService = exports.HCInvoiceprintService = exports.InvoicePortraitPrintService = exports.MyDate = exports.TrUtils = exports.VendorDebitNoteTotalsService = exports.VendorDebitNotePrintService = exports.VendorDebitNotePdfService = exports.VendorCreditNoteTotalsService = exports.VendorCreditNotePrintService = exports.VendorCreditNotePDFService = exports.VendorBalancesService = exports.TransferOrderPrintService = exports.TechnicianPrintService = exports.TechnicianpdfService = exports.TaskReportsPDfService = exports.TaskPDfService = exports.PrintSharedService = void 0;
|
|
5
|
+
exports.Divide = exports.Multiply = exports.Subtract = exports.Add = exports.ServiceHistoryPDFService = exports.SalesTotalCalculationsWithDecimals = exports.GetNumber = exports.GetAgeString = exports.IsNull = exports.IsNotNull = exports.GetServicePriceForPriceList = exports.ApplyServicePriceListToOpcode = exports.ApplyServicePriceListToProcedure = exports.CalcItemFinalSalePrice = exports.GetItemPriceForPriceList = exports.SalesReceiveTotalsService = exports.SalesReceivePrintService = exports.SalesReceivePdfService = exports.AdjustmentDrugPDFService = exports.HSNSummaryPDFService = exports.HSNSummaryExcelService = exports.ItemBarCodeLabelPdf = exports.NextServiceDatePDFService = exports.NextServiceDateXlsxFileService = exports.ConsultationLetterHeadPDFService = exports.InvoiceLetterheadPdfService = exports.HCInvoiceprintService = exports.InvoicePortraitPrintService = exports.MyDate = exports.TrUtils = exports.VendorDebitNoteTotalsService = exports.VendorDebitNotePrintService = exports.VendorDebitNotePdfService = exports.VendorCreditNoteTotalsService = exports.VendorCreditNotePrintService = exports.VendorCreditNotePDFService = exports.VendorBalancesService = exports.TransferOrderPrintService = exports.TechnicianPrintService = exports.TechnicianpdfService = exports.TaskReportsPDfService = exports.TaskPDfService = exports.PrintSharedService = void 0;
|
|
6
6
|
var analysis_excel_service_1 = require("./accounting/invoice/reports/excel/analysis-excel.service");
|
|
7
7
|
Object.defineProperty(exports, "AnalysisXlsxFileService", { enumerable: true, get: function () { return analysis_excel_service_1.AnalysisXlsxFileService; } });
|
|
8
8
|
var category_wise_item_excel_service_1 = require("./accounting/invoice/reports/excel/category-wise-item-excel.service");
|
|
@@ -266,6 +266,7 @@ Object.defineProperty(exports, "CalcItemFinalSalePrice", { enumerable: true, get
|
|
|
266
266
|
var service_price_for_pricelist_1 = require("./services/service-price-for-pricelist");
|
|
267
267
|
Object.defineProperty(exports, "ApplyServicePriceListToProcedure", { enumerable: true, get: function () { return service_price_for_pricelist_1.ApplyServicePriceListToProcedure; } });
|
|
268
268
|
Object.defineProperty(exports, "ApplyServicePriceListToOpcode", { enumerable: true, get: function () { return service_price_for_pricelist_1.ApplyServicePriceListToOpcode; } });
|
|
269
|
+
Object.defineProperty(exports, "GetServicePriceForPriceList", { enumerable: true, get: function () { return service_price_for_pricelist_1.GetServicePriceForPriceList; } });
|
|
269
270
|
var util_1 = require("./shared/util");
|
|
270
271
|
Object.defineProperty(exports, "IsNotNull", { enumerable: true, get: function () { return util_1.IsNotNull; } });
|
|
271
272
|
Object.defineProperty(exports, "IsNull", { enumerable: true, get: function () { return util_1.IsNull; } });
|
|
@@ -22,4 +22,9 @@ type PriceListDoc = {
|
|
|
22
22
|
};
|
|
23
23
|
export declare function ApplyServicePriceListToProcedure(procedure: any, priceList: PriceListDoc | null, quantity?: number): any;
|
|
24
24
|
export declare function ApplyServicePriceListToOpcode(opcode: any, priceList: PriceListDoc | null, quantity?: number): any;
|
|
25
|
+
/**
|
|
26
|
+
* Applies price list to Service with support for equipment-based pricing (FitPrices)
|
|
27
|
+
* Handles both simple services (healthcare) and equipment-based services (automotive, HVAC)
|
|
28
|
+
*/
|
|
29
|
+
export declare function GetServicePriceForPriceList(service: any, priceList: PriceListDoc | null, vehicle?: any, quantity?: number): any;
|
|
25
30
|
export {};
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ApplyServicePriceListToProcedure = ApplyServicePriceListToProcedure;
|
|
4
4
|
exports.ApplyServicePriceListToOpcode = ApplyServicePriceListToOpcode;
|
|
5
|
+
exports.GetServicePriceForPriceList = GetServicePriceForPriceList;
|
|
5
6
|
const math_operations_1 = require("../shared/math-operations");
|
|
6
7
|
const util_1 = require("../shared/util");
|
|
7
8
|
const ROUND_VALUES = new Set(["-1", "0", "0.99", "0.50", "0.49", "Dec"]);
|
|
@@ -233,3 +234,292 @@ function buildAppliedTierMeta(tier) {
|
|
|
233
234
|
Disc: (0, util_1.IsNotNull)(tier.Disc) ? tier.Disc : null,
|
|
234
235
|
};
|
|
235
236
|
}
|
|
237
|
+
/**
|
|
238
|
+
* Applies price list to Service with support for equipment-based pricing (FitPrices)
|
|
239
|
+
* Handles both simple services (healthcare) and equipment-based services (automotive, HVAC)
|
|
240
|
+
*/
|
|
241
|
+
function GetServicePriceForPriceList(service, priceList, vehicle = null, quantity = 1) {
|
|
242
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
|
|
243
|
+
if (!service || !priceList) {
|
|
244
|
+
return service;
|
|
245
|
+
}
|
|
246
|
+
const resolvedQty = Math.max(1, Number(quantity) || 1);
|
|
247
|
+
const warnings = [];
|
|
248
|
+
const priceListId = (_b = (_a = priceList === null || priceList === void 0 ? void 0 : priceList._id) === null || _a === void 0 ? void 0 : _a.toString) === null || _b === void 0 ? void 0 : _b.call(_a);
|
|
249
|
+
// Step 1: Determine base pricing (equipment-specific or simple)
|
|
250
|
+
let basePrice = null;
|
|
251
|
+
let basePriceSource = "BASE";
|
|
252
|
+
let matchedFitPriceCost = null;
|
|
253
|
+
if (priceList.TType === "SALE" && service.Sale) {
|
|
254
|
+
// Check if equipment-based service (FitPriceCosts) or simple service (Price)
|
|
255
|
+
if (service.FitPriceCosts && service.FitPriceCosts.length > 0) {
|
|
256
|
+
// Equipment-based service - need vehicle information
|
|
257
|
+
if (!vehicle) {
|
|
258
|
+
warnings.push("Vehicle information required for equipment-based service pricing.");
|
|
259
|
+
service.PriceListWarnings = warnings;
|
|
260
|
+
return service;
|
|
261
|
+
}
|
|
262
|
+
// Find matching FitPriceCost for vehicle
|
|
263
|
+
matchedFitPriceCost = findMatchingFitPriceCost(service.FitPriceCosts, vehicle);
|
|
264
|
+
if (!matchedFitPriceCost || !matchedFitPriceCost.Sale) {
|
|
265
|
+
warnings.push(`No pricing found for ${vehicle.Make || 'Unknown'} ${vehicle.Model || ''}`);
|
|
266
|
+
service.PriceListWarnings = warnings;
|
|
267
|
+
return service;
|
|
268
|
+
}
|
|
269
|
+
basePrice = matchedFitPriceCost.Sale;
|
|
270
|
+
basePriceSource = "FIT";
|
|
271
|
+
}
|
|
272
|
+
else if ((0, util_1.IsNotNull)(service.Sale.Price)) {
|
|
273
|
+
// Simple service - single base price
|
|
274
|
+
basePrice = {
|
|
275
|
+
Price: service.Sale.Price,
|
|
276
|
+
FSale: service.Sale.FSale,
|
|
277
|
+
BHours: service.Sale.BHours,
|
|
278
|
+
Dur: service.Sale.Dur,
|
|
279
|
+
};
|
|
280
|
+
basePriceSource = "BASE";
|
|
281
|
+
}
|
|
282
|
+
else {
|
|
283
|
+
warnings.push("No base pricing configured for service.");
|
|
284
|
+
service.PriceListWarnings = warnings;
|
|
285
|
+
return service;
|
|
286
|
+
}
|
|
287
|
+
// Step 2: Check for item-specific price list overrides (SalePrices)
|
|
288
|
+
// For equipment services: Look inside matched FitPriceCost
|
|
289
|
+
// For simple services: Look at root level
|
|
290
|
+
let salePriceOverride = null;
|
|
291
|
+
if (priceListId) {
|
|
292
|
+
if (matchedFitPriceCost && Array.isArray((_c = matchedFitPriceCost.Sale) === null || _c === void 0 ? void 0 : _c.SalePrices)) {
|
|
293
|
+
// Equipment service - check nested SalePrices inside matched FitPriceCost
|
|
294
|
+
salePriceOverride = matchedFitPriceCost.Sale.SalePrices.find((sp) => (sp === null || sp === void 0 ? void 0 : sp.PrListId) && sp.PrListId.toString() === priceListId);
|
|
295
|
+
}
|
|
296
|
+
else if (Array.isArray(service.SalePrices)) {
|
|
297
|
+
// Simple service - check root-level SalePrices
|
|
298
|
+
salePriceOverride = service.SalePrices.find((sp) => (sp === null || sp === void 0 ? void 0 : sp.PrListId) && sp.PrListId.toString() === priceListId);
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
if (salePriceOverride) {
|
|
302
|
+
// Apply item-specific override
|
|
303
|
+
const originalPrice = basePrice.Price;
|
|
304
|
+
service.Sale.PriceBeforePriceList = originalPrice;
|
|
305
|
+
// Check for quantity tiers in override
|
|
306
|
+
const tierList = (_d = salePriceOverride.QtyTiers) !== null && _d !== void 0 ? _d : priceList.QtyTiers;
|
|
307
|
+
const tier = resolveTier(resolvedQty, tierList);
|
|
308
|
+
if (tier) {
|
|
309
|
+
// Apply tier pricing
|
|
310
|
+
const tierValue = applyTierAdjustmentForSale(basePrice, tier);
|
|
311
|
+
service.Sale.Price = applyRounding(priceList, tierValue);
|
|
312
|
+
service.Sale.AppliedPriceListId = (_e = priceList._id) !== null && _e !== void 0 ? _e : null;
|
|
313
|
+
service.Sale.AppliedPriceTier = buildAppliedTierMeta(tier);
|
|
314
|
+
service.Sale.AppliedPriceCalc = "TIER_OVERRIDE";
|
|
315
|
+
service.Sale.PriceSource = basePriceSource;
|
|
316
|
+
}
|
|
317
|
+
else if ((0, util_1.IsNotNull)(salePriceOverride.Price)) {
|
|
318
|
+
// Fixed price override
|
|
319
|
+
service.Sale.Price = applyRounding(priceList, salePriceOverride.Price);
|
|
320
|
+
service.Sale.AppliedPriceListId = (_f = priceList._id) !== null && _f !== void 0 ? _f : null;
|
|
321
|
+
service.Sale.AppliedPriceCalc = "FIXED_OVERRIDE";
|
|
322
|
+
service.Sale.PriceSource = basePriceSource;
|
|
323
|
+
}
|
|
324
|
+
else if ((0, util_1.IsNotNull)(salePriceOverride.Disc)) {
|
|
325
|
+
// Percentage discount override
|
|
326
|
+
const discountedPrice = (0, math_operations_1.CalcDiscPrice)(originalPrice, salePriceOverride.Disc, false);
|
|
327
|
+
service.Sale.Price = applyRounding(priceList, discountedPrice);
|
|
328
|
+
service.Sale.AppliedPriceListId = (_g = priceList._id) !== null && _g !== void 0 ? _g : null;
|
|
329
|
+
service.Sale.AppliedPriceCalc = "DISCOUNT_OVERRIDE";
|
|
330
|
+
service.Sale.PriceSource = basePriceSource;
|
|
331
|
+
}
|
|
332
|
+
// Apply other override fields
|
|
333
|
+
if ((0, util_1.IsNotNull)(salePriceOverride.BHours)) {
|
|
334
|
+
service.Sale.BHours = salePriceOverride.BHours;
|
|
335
|
+
}
|
|
336
|
+
if ((0, util_1.IsNotNull)(salePriceOverride.Dur)) {
|
|
337
|
+
service.Sale.Dur = salePriceOverride.Dur;
|
|
338
|
+
}
|
|
339
|
+
if ((0, util_1.IsNotNull)(salePriceOverride.FSale)) {
|
|
340
|
+
service.Sale.FSale = salePriceOverride.FSale;
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
else {
|
|
344
|
+
// Step 3: Apply global price list calculation
|
|
345
|
+
const originalPrice = basePrice.Price;
|
|
346
|
+
service.Sale.PriceBeforePriceList = originalPrice;
|
|
347
|
+
const tier = resolveTier(resolvedQty, priceList.QtyTiers);
|
|
348
|
+
if (tier) {
|
|
349
|
+
const tierValue = applyTierAdjustmentForSale(basePrice, tier);
|
|
350
|
+
service.Sale.Price = applyRounding(priceList, tierValue);
|
|
351
|
+
service.Sale.AppliedPriceListId = (_h = priceList._id) !== null && _h !== void 0 ? _h : null;
|
|
352
|
+
service.Sale.AppliedPriceTier = buildAppliedTierMeta(tier);
|
|
353
|
+
service.Sale.AppliedPriceCalc = "TIER";
|
|
354
|
+
service.Sale.PriceSource = basePriceSource;
|
|
355
|
+
}
|
|
356
|
+
else {
|
|
357
|
+
// Apply global calculation
|
|
358
|
+
const { value, tierWarnings, appliedCalc } = evaluatePriceBlock(originalPrice, service.Pur, priceList, resolvedQty);
|
|
359
|
+
if (value != null) {
|
|
360
|
+
service.Sale.Price = value;
|
|
361
|
+
service.Sale.AppliedPriceListId = (_j = priceList._id) !== null && _j !== void 0 ? _j : null;
|
|
362
|
+
service.Sale.AppliedPriceCalc = appliedCalc !== null && appliedCalc !== void 0 ? appliedCalc : "GLOBAL";
|
|
363
|
+
service.Sale.PriceSource = basePriceSource;
|
|
364
|
+
}
|
|
365
|
+
if (tierWarnings.length > 0) {
|
|
366
|
+
warnings.push(...tierWarnings);
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
// Step 4: Handle Purchase pricing (similar logic for Pur side)
|
|
372
|
+
if (priceList.TType === "PUR" && service.Pur) {
|
|
373
|
+
let baseCost = null;
|
|
374
|
+
let baseCostSource = "BASE";
|
|
375
|
+
if (service.FitPriceCosts && service.FitPriceCosts.length > 0) {
|
|
376
|
+
// Equipment-based service - need vehicle information
|
|
377
|
+
if (!vehicle) {
|
|
378
|
+
warnings.push("Vehicle information required for equipment-based service costing.");
|
|
379
|
+
service.PriceListWarnings = warnings;
|
|
380
|
+
return service;
|
|
381
|
+
}
|
|
382
|
+
// Reuse the matchedFitPriceCost from Sale section if available
|
|
383
|
+
const fitPriceCostEntry = matchedFitPriceCost || findMatchingFitPriceCost(service.FitPriceCosts, vehicle);
|
|
384
|
+
if (!fitPriceCostEntry || !fitPriceCostEntry.Pur) {
|
|
385
|
+
warnings.push(`No costing found for ${vehicle.Make || 'Unknown'} ${vehicle.Model || ''}`);
|
|
386
|
+
service.PriceListWarnings = warnings;
|
|
387
|
+
return service;
|
|
388
|
+
}
|
|
389
|
+
baseCost = fitPriceCostEntry.Pur;
|
|
390
|
+
baseCostSource = "FIT";
|
|
391
|
+
matchedFitPriceCost = fitPriceCostEntry; // Store for later use
|
|
392
|
+
}
|
|
393
|
+
else if ((0, util_1.IsNotNull)(service.Pur.Cost)) {
|
|
394
|
+
baseCost = {
|
|
395
|
+
Cost: service.Pur.Cost,
|
|
396
|
+
FCost: service.Pur.FCost,
|
|
397
|
+
};
|
|
398
|
+
baseCostSource = "BASE";
|
|
399
|
+
}
|
|
400
|
+
if (baseCost) {
|
|
401
|
+
// Check for purchase cost overrides
|
|
402
|
+
// For equipment services: Look inside matched FitPriceCost
|
|
403
|
+
// For simple services: Look at root level
|
|
404
|
+
let purchaseCostOverride = null;
|
|
405
|
+
if (priceListId) {
|
|
406
|
+
if (matchedFitPriceCost && Array.isArray((_k = matchedFitPriceCost.Pur) === null || _k === void 0 ? void 0 : _k.PurchaseCosts)) {
|
|
407
|
+
// Equipment service - check nested PurchaseCosts inside matched FitPriceCost
|
|
408
|
+
purchaseCostOverride = matchedFitPriceCost.Pur.PurchaseCosts.find((pc) => (pc === null || pc === void 0 ? void 0 : pc.PrListId) && pc.PrListId.toString() === priceListId);
|
|
409
|
+
}
|
|
410
|
+
else if (Array.isArray(service.PurchaseCosts)) {
|
|
411
|
+
// Simple service - check root-level PurchaseCosts
|
|
412
|
+
purchaseCostOverride = service.PurchaseCosts.find((pc) => (pc === null || pc === void 0 ? void 0 : pc.PrListId) && pc.PrListId.toString() === priceListId);
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
const originalCost = baseCost.Cost;
|
|
416
|
+
service.Pur.CostBeforePriceList = originalCost;
|
|
417
|
+
if (purchaseCostOverride) {
|
|
418
|
+
if ((0, util_1.IsNotNull)(purchaseCostOverride.Cost)) {
|
|
419
|
+
service.Pur.Cost = applyRounding(priceList, purchaseCostOverride.Cost);
|
|
420
|
+
service.Pur.AppliedPriceListId = (_l = priceList._id) !== null && _l !== void 0 ? _l : null;
|
|
421
|
+
service.Pur.CostSource = baseCostSource;
|
|
422
|
+
}
|
|
423
|
+
else if ((0, util_1.IsNotNull)(purchaseCostOverride.Disc)) {
|
|
424
|
+
const discountedCost = (0, math_operations_1.CalcDiscPrice)(originalCost, purchaseCostOverride.Disc, false);
|
|
425
|
+
service.Pur.Cost = applyRounding(priceList, discountedCost);
|
|
426
|
+
service.Pur.AppliedPriceListId = (_m = priceList._id) !== null && _m !== void 0 ? _m : null;
|
|
427
|
+
service.Pur.CostSource = baseCostSource;
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
else {
|
|
431
|
+
const { value, tierWarnings } = evaluatePriceBlock(originalCost, service.Pur, priceList, resolvedQty);
|
|
432
|
+
if (value != null) {
|
|
433
|
+
service.Pur.Cost = value;
|
|
434
|
+
service.Pur.AppliedPriceListId = (_o = priceList._id) !== null && _o !== void 0 ? _o : null;
|
|
435
|
+
service.Pur.CostSource = baseCostSource;
|
|
436
|
+
}
|
|
437
|
+
if (tierWarnings.length > 0) {
|
|
438
|
+
warnings.push(...tierWarnings);
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
if (warnings.length > 0) {
|
|
444
|
+
service.PriceListWarnings = warnings;
|
|
445
|
+
}
|
|
446
|
+
return service;
|
|
447
|
+
}
|
|
448
|
+
/**
|
|
449
|
+
* Finds the matching FitPriceCost entry for a given vehicle
|
|
450
|
+
* Tries most specific match first (Make + Model + Variant), then progressively less specific
|
|
451
|
+
*/
|
|
452
|
+
function findMatchingFitPriceCost(fitPriceCosts, vehicle) {
|
|
453
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
454
|
+
if (!Array.isArray(fitPriceCosts) || fitPriceCosts.length === 0 || !vehicle) {
|
|
455
|
+
return null;
|
|
456
|
+
}
|
|
457
|
+
const vehicleMakeId = (_b = (_a = vehicle.Make_Id) === null || _a === void 0 ? void 0 : _a.toString) === null || _b === void 0 ? void 0 : _b.call(_a);
|
|
458
|
+
const vehicleModelId = (_d = (_c = vehicle.Model_Id) === null || _c === void 0 ? void 0 : _c.toString) === null || _d === void 0 ? void 0 : _d.call(_c);
|
|
459
|
+
const vehicleVarId = ((_f = (_e = vehicle.Var_Id) === null || _e === void 0 ? void 0 : _e.toString) === null || _f === void 0 ? void 0 : _f.call(_e)) || ((_h = (_g = vehicle.Variant_Id) === null || _g === void 0 ? void 0 : _g.toString) === null || _h === void 0 ? void 0 : _h.call(_g));
|
|
460
|
+
// Try Make + Model + Variant
|
|
461
|
+
if (vehicleMakeId && vehicleModelId && vehicleVarId) {
|
|
462
|
+
const match = fitPriceCosts.find((fpc) => {
|
|
463
|
+
if (!Array.isArray(fpc.Fit) || fpc.Fit.length === 0)
|
|
464
|
+
return false;
|
|
465
|
+
return fpc.Fit.some((fit) => {
|
|
466
|
+
var _a, _b, _c, _d, _e, _f;
|
|
467
|
+
return ((_b = (_a = fit.Make_Id) === null || _a === void 0 ? void 0 : _a.toString) === null || _b === void 0 ? void 0 : _b.call(_a)) === vehicleMakeId &&
|
|
468
|
+
((_d = (_c = fit.Model_Id) === null || _c === void 0 ? void 0 : _c.toString) === null || _d === void 0 ? void 0 : _d.call(_c)) === vehicleModelId &&
|
|
469
|
+
((_f = (_e = fit.Var_Id) === null || _e === void 0 ? void 0 : _e.toString) === null || _f === void 0 ? void 0 : _f.call(_e)) === vehicleVarId;
|
|
470
|
+
});
|
|
471
|
+
});
|
|
472
|
+
if (match)
|
|
473
|
+
return match;
|
|
474
|
+
}
|
|
475
|
+
// Try Make + Model
|
|
476
|
+
if (vehicleMakeId && vehicleModelId) {
|
|
477
|
+
const match = fitPriceCosts.find((fpc) => {
|
|
478
|
+
if (!Array.isArray(fpc.Fit) || fpc.Fit.length === 0)
|
|
479
|
+
return false;
|
|
480
|
+
return fpc.Fit.some((fit) => {
|
|
481
|
+
var _a, _b, _c, _d;
|
|
482
|
+
return ((_b = (_a = fit.Make_Id) === null || _a === void 0 ? void 0 : _a.toString) === null || _b === void 0 ? void 0 : _b.call(_a)) === vehicleMakeId &&
|
|
483
|
+
((_d = (_c = fit.Model_Id) === null || _c === void 0 ? void 0 : _c.toString) === null || _d === void 0 ? void 0 : _d.call(_c)) === vehicleModelId &&
|
|
484
|
+
!fit.Var_Id;
|
|
485
|
+
});
|
|
486
|
+
});
|
|
487
|
+
if (match)
|
|
488
|
+
return match;
|
|
489
|
+
}
|
|
490
|
+
// Try Make only
|
|
491
|
+
if (vehicleMakeId) {
|
|
492
|
+
const match = fitPriceCosts.find((fpc) => {
|
|
493
|
+
if (!Array.isArray(fpc.Fit) || fpc.Fit.length === 0)
|
|
494
|
+
return false;
|
|
495
|
+
return fpc.Fit.some((fit) => {
|
|
496
|
+
var _a, _b;
|
|
497
|
+
return ((_b = (_a = fit.Make_Id) === null || _a === void 0 ? void 0 : _a.toString) === null || _b === void 0 ? void 0 : _b.call(_a)) === vehicleMakeId &&
|
|
498
|
+
!fit.Model_Id;
|
|
499
|
+
});
|
|
500
|
+
});
|
|
501
|
+
if (match)
|
|
502
|
+
return match;
|
|
503
|
+
}
|
|
504
|
+
// Try generic (no Make/Model/Variant specified = applies to all)
|
|
505
|
+
const genericMatch = fitPriceCosts.find((fpc) => {
|
|
506
|
+
if (!Array.isArray(fpc.Fit) || fpc.Fit.length === 0)
|
|
507
|
+
return true; // No fit = applies to all
|
|
508
|
+
return fpc.Fit.some((fit) => !fit.Make_Id && !fit.Model_Id && !fit.Var_Id);
|
|
509
|
+
});
|
|
510
|
+
return genericMatch || null;
|
|
511
|
+
}
|
|
512
|
+
/**
|
|
513
|
+
* Applies tier adjustment to sale pricing
|
|
514
|
+
*/
|
|
515
|
+
function applyTierAdjustmentForSale(baseSale, tier) {
|
|
516
|
+
var _a, _b, _c, _d;
|
|
517
|
+
if ((0, util_1.IsNotNull)(tier.Price)) {
|
|
518
|
+
return (_a = tier.Price) !== null && _a !== void 0 ? _a : null;
|
|
519
|
+
}
|
|
520
|
+
if ((0, util_1.IsNotNull)(tier.Disc)) {
|
|
521
|
+
const basePrice = (_b = baseSale === null || baseSale === void 0 ? void 0 : baseSale.Price) !== null && _b !== void 0 ? _b : 0;
|
|
522
|
+
return (0, math_operations_1.CalcDiscPrice)(basePrice, (_c = tier.Disc) !== null && _c !== void 0 ? _c : 0, false);
|
|
523
|
+
}
|
|
524
|
+
return (_d = baseSale === null || baseSale === void 0 ? void 0 : baseSale.Price) !== null && _d !== void 0 ? _d : null;
|
|
525
|
+
}
|