shareneus 1.5.16 → 1.5.18
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 +1 -0
- package/dist/index.js +4 -1
- package/dist/inventory/items/item-price-for-pricelist.d.ts +1 -1
- package/dist/inventory/items/item-price-for-pricelist.js +215 -92
- package/dist/sales-receive/sales-total-calculation.js +76 -20
- package/dist/services/service-price-for-pricelist.d.ts +25 -0
- package/dist/services/service-price-for-pricelist.js +235 -0
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -128,6 +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
132
|
export { IsNotNull, IsNull } from "./shared/util";
|
|
132
133
|
export { GetAgeString } from "./shared/util";
|
|
133
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.ServiceHistoryPDFService = exports.SalesTotalCalculationsWithDecimals = exports.GetAgeString = exports.IsNull = exports.IsNotNull = 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.ServiceHistoryPDFService = exports.SalesTotalCalculationsWithDecimals = 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;
|
|
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");
|
|
@@ -263,6 +263,9 @@ var item_price_for_pricelist_1 = require("./inventory/items/item-price-for-price
|
|
|
263
263
|
Object.defineProperty(exports, "GetItemPriceForPriceList", { enumerable: true, get: function () { return item_price_for_pricelist_1.GetItemPriceForPriceList; } });
|
|
264
264
|
var item_price_for_pricelist_2 = require("./inventory/items/item-price-for-pricelist");
|
|
265
265
|
Object.defineProperty(exports, "CalcItemFinalSalePrice", { enumerable: true, get: function () { return item_price_for_pricelist_2.CalcItemFinalSalePrice; } });
|
|
266
|
+
var service_price_for_pricelist_1 = require("./services/service-price-for-pricelist");
|
|
267
|
+
Object.defineProperty(exports, "ApplyServicePriceListToProcedure", { enumerable: true, get: function () { return service_price_for_pricelist_1.ApplyServicePriceListToProcedure; } });
|
|
268
|
+
Object.defineProperty(exports, "ApplyServicePriceListToOpcode", { enumerable: true, get: function () { return service_price_for_pricelist_1.ApplyServicePriceListToOpcode; } });
|
|
266
269
|
var util_1 = require("./shared/util");
|
|
267
270
|
Object.defineProperty(exports, "IsNotNull", { enumerable: true, get: function () { return util_1.IsNotNull; } });
|
|
268
271
|
Object.defineProperty(exports, "IsNull", { enumerable: true, get: function () { return util_1.IsNull; } });
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export declare function GetItemPriceForPriceList(item: any, priceList: any, includeMargin?: boolean): any;
|
|
1
|
+
export declare function GetItemPriceForPriceList(item: any, priceList: any, includeMargin?: boolean, quantity?: number, pricingContext?: any): any;
|
|
2
2
|
/**
|
|
3
3
|
* Calculates the final sale price of an item after applying a discount and optional markup.
|
|
4
4
|
* Optionally includes margin calculation based on cost.
|
|
@@ -4,58 +4,87 @@ exports.GetItemPriceForPriceList = GetItemPriceForPriceList;
|
|
|
4
4
|
exports.CalcItemFinalSalePrice = CalcItemFinalSalePrice;
|
|
5
5
|
const math_operations_1 = require("../../shared/math-operations");
|
|
6
6
|
const util_1 = require("../../shared/util");
|
|
7
|
-
function GetItemPriceForPriceList(item, priceList, includeMargin = false) {
|
|
8
|
-
var _a, _b;
|
|
9
|
-
|
|
7
|
+
function GetItemPriceForPriceList(item, priceList, includeMargin = false, quantity = 1, pricingContext = {}) {
|
|
8
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
9
|
+
if (!priceList) {
|
|
10
|
+
return item;
|
|
11
|
+
}
|
|
12
|
+
const resolvedQty = Math.max(1, Number(quantity) || 1);
|
|
10
13
|
const calcDisc = (_a = priceList.CalcDisc) !== null && _a !== void 0 ? _a : {};
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
+
const markUp = (_b = calcDisc.Mark) !== null && _b !== void 0 ? _b : false;
|
|
15
|
+
const priceListId = (_d = (_c = priceList === null || priceList === void 0 ? void 0 : priceList._id) === null || _c === void 0 ? void 0 : _c.toString) === null || _d === void 0 ? void 0 : _d.call(_c);
|
|
16
|
+
let salePricesByPriceListId = [];
|
|
17
|
+
if (priceListId && (0, util_1.IsNotNull)(item.SalePrices) && item.SalePrices.length > 0) {
|
|
18
|
+
salePricesByPriceListId = item.SalePrices.filter((price) => (price === null || price === void 0 ? void 0 : price.PrListId) && price.PrListId.toString() === priceListId);
|
|
14
19
|
}
|
|
20
|
+
item.PriceTiers = (_e = priceList === null || priceList === void 0 ? void 0 : priceList.QtyTiers) !== null && _e !== void 0 ? _e : undefined;
|
|
21
|
+
item.AppliedPriceTier = undefined;
|
|
15
22
|
if (salePricesByPriceListId.length > 0) {
|
|
16
23
|
item.SalePrices = salePricesByPriceListId;
|
|
17
|
-
|
|
24
|
+
const activeSalePrice = salePricesByPriceListId[0];
|
|
25
|
+
const activeTierList = (_f = activeSalePrice === null || activeSalePrice === void 0 ? void 0 : activeSalePrice.QtyTiers) !== null && _f !== void 0 ? _f : priceList === null || priceList === void 0 ? void 0 : priceList.QtyTiers;
|
|
26
|
+
if (activeTierList) {
|
|
27
|
+
item.PriceTiers = activeTierList;
|
|
28
|
+
}
|
|
29
|
+
if (item.Track === "TR" || item.Track === "SN") {
|
|
18
30
|
item.Sale["MRP"] = item.Sale.Price;
|
|
19
|
-
|
|
20
|
-
|
|
31
|
+
const tier = ResolveTier(resolvedQty, activeSalePrice === null || activeSalePrice === void 0 ? void 0 : activeSalePrice.QtyTiers);
|
|
32
|
+
if (tier) {
|
|
33
|
+
const baseForTier = (0, util_1.IsNotNull)(activeSalePrice.Price) ? activeSalePrice.Price : item.Sale.Price;
|
|
34
|
+
item.Sale.Price = ApplyTierAdjustment(baseForTier, tier, priceList, false);
|
|
35
|
+
item.AppliedPriceTier = BuildAppliedTierMeta("ITEM", tier);
|
|
36
|
+
}
|
|
37
|
+
else if ((0, util_1.IsNotNull)(activeSalePrice.Price) && (0, util_1.IsNotNull)(activeSalePrice.Disc)) {
|
|
38
|
+
item.Sale.Price = CalcItemFinalSalePrice(activeSalePrice.Price, activeSalePrice.Disc, priceList, markUp);
|
|
21
39
|
}
|
|
22
|
-
else if ((0, util_1.IsNotNull)(
|
|
23
|
-
item.Sale.Price = ApplyRounding(
|
|
40
|
+
else if ((0, util_1.IsNotNull)(activeSalePrice.Price) && (0, util_1.IsNull)(activeSalePrice.Disc)) {
|
|
41
|
+
item.Sale.Price = ApplyRounding(activeSalePrice.Price, priceList);
|
|
24
42
|
}
|
|
25
|
-
else if ((0, util_1.IsNull)(
|
|
26
|
-
item.Sale.Price = CalcItemFinalSalePrice(item.Sale.Price,
|
|
43
|
+
else if ((0, util_1.IsNull)(activeSalePrice.Price) && (0, util_1.IsNotNull)(activeSalePrice.Disc)) {
|
|
44
|
+
item.Sale.Price = CalcItemFinalSalePrice(item.Sale.Price, activeSalePrice.Disc, priceList, markUp);
|
|
27
45
|
}
|
|
28
|
-
if (includeMargin) {
|
|
46
|
+
if (includeMargin && (0, util_1.IsNotNull)(item.Pur) && (0, util_1.IsNotNull)(item.Pur.Cost)) {
|
|
29
47
|
item.Margin = (0, math_operations_1.GetMarginValue)(item.Sale.Price, item.Pur.Cost);
|
|
30
48
|
}
|
|
31
49
|
}
|
|
32
|
-
else if (item.Track
|
|
33
|
-
for (
|
|
34
|
-
const
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
50
|
+
else if (item.Track === "BN" && Array.isArray(item.Batches)) {
|
|
51
|
+
for (const element of item.Batches) {
|
|
52
|
+
const batchSalePrice = item.SalePrices.filter((batch) => {
|
|
53
|
+
var _a;
|
|
54
|
+
return priceListId === ((_a = batch === null || batch === void 0 ? void 0 : batch.PrListId) === null || _a === void 0 ? void 0 : _a.toString()) &&
|
|
55
|
+
(element.BN === batch.BN || batch.BN == null);
|
|
56
|
+
});
|
|
57
|
+
const activeBatchSale = batchSalePrice.length > 0 ? batchSalePrice[0] : undefined;
|
|
58
|
+
const tierList = (_h = (_g = activeBatchSale === null || activeBatchSale === void 0 ? void 0 : activeBatchSale.QtyTiers) !== null && _g !== void 0 ? _g : activeSalePrice === null || activeSalePrice === void 0 ? void 0 : activeSalePrice.QtyTiers) !== null && _h !== void 0 ? _h : priceList === null || priceList === void 0 ? void 0 : priceList.QtyTiers;
|
|
59
|
+
if (tierList) {
|
|
60
|
+
element.PriceTiers = tierList;
|
|
38
61
|
}
|
|
39
62
|
element.MRP = element.Price;
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
63
|
+
const tier = ResolveTier(resolvedQty, (_j = activeBatchSale === null || activeBatchSale === void 0 ? void 0 : activeBatchSale.QtyTiers) !== null && _j !== void 0 ? _j : activeSalePrice === null || activeSalePrice === void 0 ? void 0 : activeSalePrice.QtyTiers);
|
|
64
|
+
if (tier) {
|
|
65
|
+
const baseForTier = (0, util_1.IsNotNull)(activeBatchSale === null || activeBatchSale === void 0 ? void 0 : activeBatchSale.Price) ? activeBatchSale.Price : element.Price;
|
|
66
|
+
element.Price = ApplyTierAdjustment(baseForTier, tier, priceList, false);
|
|
67
|
+
element.AppliedPriceTier = BuildAppliedTierMeta("ITEM", tier);
|
|
68
|
+
}
|
|
69
|
+
else if (activeBatchSale) {
|
|
70
|
+
if ((0, util_1.IsNotNull)(activeBatchSale.Price) && (0, util_1.IsNotNull)(activeBatchSale.Disc)) {
|
|
71
|
+
element.Price = CalcItemFinalSalePrice(activeBatchSale.Price, activeBatchSale.Disc, priceList, markUp);
|
|
43
72
|
}
|
|
44
|
-
else if ((0, util_1.IsNotNull)(
|
|
45
|
-
element.Price = ApplyRounding(
|
|
73
|
+
else if ((0, util_1.IsNotNull)(activeBatchSale.Price) && (0, util_1.IsNull)(activeBatchSale.Disc)) {
|
|
74
|
+
element.Price = ApplyRounding(activeBatchSale.Price, priceList);
|
|
46
75
|
}
|
|
47
|
-
else if ((0, util_1.IsNull)(
|
|
48
|
-
element.Price = CalcItemFinalSalePrice(element.Price,
|
|
76
|
+
else if ((0, util_1.IsNull)(activeBatchSale.Price) && (0, util_1.IsNotNull)(activeBatchSale.Disc)) {
|
|
77
|
+
element.Price = CalcItemFinalSalePrice(element.Price, activeBatchSale.Disc, priceList, markUp);
|
|
49
78
|
}
|
|
50
79
|
}
|
|
51
|
-
if (includeMargin) {
|
|
80
|
+
if (includeMargin && (0, util_1.IsNotNull)(element.Cost)) {
|
|
52
81
|
element.Margin = (0, math_operations_1.GetMarginValue)(element.Price, element.Cost);
|
|
53
82
|
}
|
|
54
83
|
}
|
|
55
84
|
}
|
|
56
85
|
return item;
|
|
57
86
|
}
|
|
58
|
-
return CalculatePriceBasedOnPriceList(item, priceList, includeMargin);
|
|
87
|
+
return CalculatePriceBasedOnPriceList(item, priceList, includeMargin, resolvedQty);
|
|
59
88
|
}
|
|
60
89
|
/**
|
|
61
90
|
* Calculates the final sale price of an item after applying a discount and optional markup.
|
|
@@ -70,93 +99,116 @@ function GetItemPriceForPriceList(item, priceList, includeMargin = false) {
|
|
|
70
99
|
* @returns The final price or an object containing margin and final price if includeMargin is true.
|
|
71
100
|
*/
|
|
72
101
|
function CalcItemFinalSalePrice(price, disc, priceList, markup = false, includeMargin = false, cost = 0) {
|
|
73
|
-
// Calculate the price after applying discount or markup
|
|
74
102
|
const calculatedPrice = (0, math_operations_1.CalcDiscPrice)(price, disc, markup);
|
|
75
|
-
// Apply rounding rules from the price list
|
|
76
103
|
const finalPrice = ApplyRounding(calculatedPrice, priceList);
|
|
77
|
-
// If margin calculation is requested, calculate and return both margin and final price
|
|
78
104
|
if (includeMargin) {
|
|
79
105
|
const margin = (0, math_operations_1.GetMarginValue)(finalPrice, cost);
|
|
80
106
|
return { margin: margin, finalPrice: finalPrice };
|
|
81
107
|
}
|
|
82
|
-
// Otherwise, return only the final price
|
|
83
108
|
return finalPrice;
|
|
84
109
|
}
|
|
85
|
-
function CalculatePriceBasedOnPriceList(item, priceList, includeMargin) {
|
|
86
|
-
var _a, _b;
|
|
87
|
-
if (priceList
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
110
|
+
function CalculatePriceBasedOnPriceList(item, priceList, includeMargin, quantity) {
|
|
111
|
+
var _a, _b, _c;
|
|
112
|
+
if (!priceList) {
|
|
113
|
+
return item;
|
|
114
|
+
}
|
|
115
|
+
const calcDisc = (_a = priceList.CalcDisc) !== null && _a !== void 0 ? _a : {};
|
|
116
|
+
const markUp = (_b = calcDisc.Mark) !== null && _b !== void 0 ? _b : false;
|
|
117
|
+
const resolvedQty = Math.max(1, Number(quantity) || 1);
|
|
118
|
+
const tier = ResolveTier(resolvedQty, priceList.QtyTiers);
|
|
119
|
+
if (tier) {
|
|
120
|
+
item.PriceTiers = (_c = priceList.QtyTiers) !== null && _c !== void 0 ? _c : undefined;
|
|
121
|
+
if (item.Track === "TR" || item.Track === "SN") {
|
|
122
|
+
item.Sale["MRP"] = item.Sale.Price;
|
|
123
|
+
const basePrice = DetermineBasePriceForTier(item, priceList);
|
|
124
|
+
item.Sale.Price = ApplyTierAdjustment(basePrice, tier, priceList, markUp);
|
|
125
|
+
item.AppliedPriceTier = BuildAppliedTierMeta("PRICELIST", tier);
|
|
126
|
+
if (includeMargin && (0, util_1.IsNotNull)(item.Pur) && (0, util_1.IsNotNull)(item.Pur.Cost)) {
|
|
127
|
+
item.Margin = (0, math_operations_1.GetMarginValue)(item.Sale.Price, item.Pur.Cost);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
else if (item.Track === "BN" && Array.isArray(item.Batches)) {
|
|
131
|
+
for (const batch of item.Batches) {
|
|
132
|
+
batch.MRP = batch.Price;
|
|
133
|
+
const basePrice = DetermineBatchBasePriceForTier(batch, item, priceList);
|
|
134
|
+
batch.Price = ApplyTierAdjustment(basePrice, tier, priceList, markUp);
|
|
135
|
+
batch.AppliedPriceTier = BuildAppliedTierMeta("PRICELIST", tier);
|
|
136
|
+
if (includeMargin && (0, util_1.IsNotNull)(batch.Cost)) {
|
|
137
|
+
batch.Margin = (0, math_operations_1.GetMarginValue)(batch.Price, batch.Cost);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
return item;
|
|
142
|
+
}
|
|
143
|
+
if (priceList.PrCalc === "FIXED") {
|
|
144
|
+
if (priceList.Fixed && (0, util_1.IsNotNull)(priceList.Fixed.Price)) {
|
|
145
|
+
const fixedPrice = priceList.Fixed.Price;
|
|
146
|
+
const fixedDisc = priceList.Fixed.Disc || 0;
|
|
147
|
+
if (item.Track === "TR" || item.Track === "SN") {
|
|
148
|
+
item.Sale["MRP"] = item.Sale.Price;
|
|
149
|
+
if ((0, util_1.IsNotNull)(fixedDisc) && fixedDisc > 0) {
|
|
150
|
+
item.Sale.Price = CalcItemFinalSalePrice(fixedPrice, fixedDisc, priceList);
|
|
151
|
+
}
|
|
152
|
+
else {
|
|
153
|
+
item.Sale.Price = ApplyRounding(fixedPrice, priceList);
|
|
154
|
+
}
|
|
155
|
+
if (includeMargin && (0, util_1.IsNotNull)(item.Pur) && (0, util_1.IsNotNull)(item.Pur.Cost)) {
|
|
156
|
+
item.Margin = (0, math_operations_1.GetMarginValue)(item.Sale.Price, item.Pur.Cost);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
else if (item.Track === "BN" && Array.isArray(item.Batches)) {
|
|
160
|
+
for (const batch of item.Batches) {
|
|
161
|
+
batch.MRP = batch.Price;
|
|
94
162
|
if ((0, util_1.IsNotNull)(fixedDisc) && fixedDisc > 0) {
|
|
95
|
-
|
|
163
|
+
batch.Price = CalcItemFinalSalePrice(fixedPrice, fixedDisc, priceList);
|
|
96
164
|
}
|
|
97
165
|
else {
|
|
98
|
-
|
|
166
|
+
batch.Price = ApplyRounding(fixedPrice, priceList);
|
|
99
167
|
}
|
|
100
|
-
if (includeMargin) {
|
|
101
|
-
|
|
168
|
+
if (includeMargin && (0, util_1.IsNotNull)(batch.Cost)) {
|
|
169
|
+
batch.Margin = (0, math_operations_1.GetMarginValue)(batch.Price, batch.Cost);
|
|
102
170
|
}
|
|
103
171
|
}
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
else if (priceList.PrCalc === "DISC") {
|
|
176
|
+
const discPerc = calcDisc.Perc || 0;
|
|
177
|
+
if (priceList.BasedOn === "SP") {
|
|
178
|
+
if (item.Track === "TR" || item.Track === "SN") {
|
|
179
|
+
item.Sale["MRP"] = item.Sale.Price;
|
|
180
|
+
item.Sale.Price = CalcItemFinalSalePrice(item.Sale.Price, discPerc, priceList, markUp);
|
|
181
|
+
if (includeMargin && (0, util_1.IsNotNull)(item.Pur) && (0, util_1.IsNotNull)(item.Pur.Cost)) {
|
|
182
|
+
item.Margin = (0, math_operations_1.GetMarginValue)(item.Sale.Price, item.Pur.Cost);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
else if (item.Track === "BN" && Array.isArray(item.Batches)) {
|
|
186
|
+
for (const batch of item.Batches) {
|
|
187
|
+
batch.MRP = batch.Price;
|
|
188
|
+
batch.Price = CalcItemFinalSalePrice(batch.Price, discPerc, priceList, markUp);
|
|
189
|
+
if (includeMargin && (0, util_1.IsNotNull)(batch.Cost)) {
|
|
190
|
+
batch.Margin = (0, math_operations_1.GetMarginValue)(batch.Price, batch.Cost);
|
|
116
191
|
}
|
|
117
192
|
}
|
|
118
193
|
}
|
|
119
194
|
}
|
|
120
|
-
else if (priceList.
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
if (item.Track == 'TR' || item.Track == 'SN') {
|
|
126
|
-
item.Sale["MRP"] = item.Sale.Price;
|
|
127
|
-
item.Sale.Price = CalcItemFinalSalePrice(item.Sale.Price, discPerc, priceList, markUp);
|
|
195
|
+
else if (priceList.BasedOn === "PC") {
|
|
196
|
+
if (item.Track === "TR" || item.Track === "SN") {
|
|
197
|
+
item.Sale["MRP"] = item.Sale.Price;
|
|
198
|
+
if ((0, util_1.IsNotNull)(item.Pur) && (0, util_1.IsNotNull)(item.Pur.Cost)) {
|
|
199
|
+
item.Sale.Price = CalcItemFinalSalePrice(item.Pur.Cost, discPerc, priceList, markUp);
|
|
128
200
|
if (includeMargin) {
|
|
129
201
|
item.Margin = (0, math_operations_1.GetMarginValue)(item.Sale.Price, item.Pur.Cost);
|
|
130
202
|
}
|
|
131
203
|
}
|
|
132
|
-
else if (item.Track == 'BN') {
|
|
133
|
-
for (let batch of item.Batches) {
|
|
134
|
-
batch.MRP = batch.Price;
|
|
135
|
-
batch.Price = CalcItemFinalSalePrice(batch.Price, discPerc, priceList, markUp);
|
|
136
|
-
if (includeMargin) {
|
|
137
|
-
batch.Margin = (0, math_operations_1.GetMarginValue)(batch.Price, batch.Cost);
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
204
|
}
|
|
142
|
-
else if (
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
if ((0, util_1.IsNotNull)(
|
|
146
|
-
|
|
205
|
+
else if (item.Track === "BN" && Array.isArray(item.Batches)) {
|
|
206
|
+
for (const batch of item.Batches) {
|
|
207
|
+
batch.MRP = batch.Price;
|
|
208
|
+
if ((0, util_1.IsNotNull)(batch.Cost)) {
|
|
209
|
+
batch.Price = CalcItemFinalSalePrice(batch.Cost, discPerc, priceList, markUp);
|
|
147
210
|
if (includeMargin) {
|
|
148
|
-
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
else if (item.Track == 'BN') {
|
|
153
|
-
for (let batch of item.Batches) {
|
|
154
|
-
batch.MRP = batch.Price;
|
|
155
|
-
if ((0, util_1.IsNotNull)(batch.Cost)) {
|
|
156
|
-
batch.Price = CalcItemFinalSalePrice(batch.Cost, discPerc, priceList, markUp);
|
|
157
|
-
if (includeMargin) {
|
|
158
|
-
batch.Margin = (0, math_operations_1.GetMarginValue)(batch.Price, batch.Cost);
|
|
159
|
-
}
|
|
211
|
+
batch.Margin = (0, math_operations_1.GetMarginValue)(batch.Price, batch.Cost);
|
|
160
212
|
}
|
|
161
213
|
}
|
|
162
214
|
}
|
|
@@ -189,3 +241,74 @@ function ApplyRounding(price, priceList) {
|
|
|
189
241
|
return price;
|
|
190
242
|
}
|
|
191
243
|
}
|
|
244
|
+
function ResolveTier(quantity, tiers) {
|
|
245
|
+
if (!Array.isArray(tiers) || tiers.length === 0) {
|
|
246
|
+
return null;
|
|
247
|
+
}
|
|
248
|
+
const sorted = [...tiers]
|
|
249
|
+
.filter((tier) => (0, util_1.IsNotNull)(tier) && (0, util_1.IsNotNull)(tier.MinQty))
|
|
250
|
+
.sort((a, b) => a.MinQty - b.MinQty);
|
|
251
|
+
let selected = null;
|
|
252
|
+
for (const tier of sorted) {
|
|
253
|
+
if (quantity >= tier.MinQty) {
|
|
254
|
+
selected = tier;
|
|
255
|
+
}
|
|
256
|
+
else {
|
|
257
|
+
break;
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
return selected;
|
|
261
|
+
}
|
|
262
|
+
function ApplyTierAdjustment(basePrice, tier, priceList, markUp) {
|
|
263
|
+
if ((0, util_1.IsNotNull)(tier === null || tier === void 0 ? void 0 : tier.Price)) {
|
|
264
|
+
return ApplyRounding(tier.Price, priceList);
|
|
265
|
+
}
|
|
266
|
+
if ((0, util_1.IsNotNull)(tier === null || tier === void 0 ? void 0 : tier.Disc)) {
|
|
267
|
+
const targetBase = (0, util_1.IsNotNull)(basePrice) ? basePrice : 0;
|
|
268
|
+
return CalcItemFinalSalePrice(targetBase, tier.Disc, priceList, markUp);
|
|
269
|
+
}
|
|
270
|
+
return ApplyRounding(basePrice, priceList);
|
|
271
|
+
}
|
|
272
|
+
function BuildAppliedTierMeta(source, tier) {
|
|
273
|
+
if (!tier) {
|
|
274
|
+
return undefined;
|
|
275
|
+
}
|
|
276
|
+
return {
|
|
277
|
+
Source: source,
|
|
278
|
+
MinQty: (0, util_1.IsNotNull)(tier.MinQty) ? tier.MinQty : null,
|
|
279
|
+
Price: (0, util_1.IsNotNull)(tier.Price) ? tier.Price : null,
|
|
280
|
+
Disc: (0, util_1.IsNotNull)(tier.Disc) ? tier.Disc : null,
|
|
281
|
+
};
|
|
282
|
+
}
|
|
283
|
+
function DetermineBasePriceForTier(item, priceList) {
|
|
284
|
+
var _a;
|
|
285
|
+
if (priceList.PrCalc === "FIXED") {
|
|
286
|
+
if ((0, util_1.IsNotNull)((_a = priceList.Fixed) === null || _a === void 0 ? void 0 : _a.Price)) {
|
|
287
|
+
return priceList.Fixed.Price;
|
|
288
|
+
}
|
|
289
|
+
return item.Sale.Price;
|
|
290
|
+
}
|
|
291
|
+
if (priceList.PrCalc === "DISC") {
|
|
292
|
+
if (priceList.BasedOn === "PC" && (0, util_1.IsNotNull)(item.Pur) && (0, util_1.IsNotNull)(item.Pur.Cost)) {
|
|
293
|
+
return item.Pur.Cost;
|
|
294
|
+
}
|
|
295
|
+
return item.Sale.Price;
|
|
296
|
+
}
|
|
297
|
+
return item.Sale.Price;
|
|
298
|
+
}
|
|
299
|
+
function DetermineBatchBasePriceForTier(batch, item, priceList) {
|
|
300
|
+
var _a;
|
|
301
|
+
if (priceList.PrCalc === "FIXED") {
|
|
302
|
+
if ((0, util_1.IsNotNull)((_a = priceList.Fixed) === null || _a === void 0 ? void 0 : _a.Price)) {
|
|
303
|
+
return priceList.Fixed.Price;
|
|
304
|
+
}
|
|
305
|
+
return batch.Price;
|
|
306
|
+
}
|
|
307
|
+
if (priceList.PrCalc === "DISC") {
|
|
308
|
+
if (priceList.BasedOn === "PC" && (0, util_1.IsNotNull)(batch.Cost)) {
|
|
309
|
+
return batch.Cost;
|
|
310
|
+
}
|
|
311
|
+
return batch.Price;
|
|
312
|
+
}
|
|
313
|
+
return batch.Price;
|
|
314
|
+
}
|
|
@@ -17,18 +17,26 @@ function SalesTotalCalculations(items = [], ops = [], isTaxable = false, taxCode
|
|
|
17
17
|
const safeOps = safeArray(ops);
|
|
18
18
|
const safeTaxCodes = safeArray(taxCodes);
|
|
19
19
|
// Initialize all totals
|
|
20
|
-
let total = 0;
|
|
21
20
|
let subtotalOnItems = 0;
|
|
21
|
+
let totalTaxOnItems = 0;
|
|
22
|
+
let totalDiscountOnItems = 0;
|
|
22
23
|
let subtotalOnLabor = 0;
|
|
24
|
+
let totalTaxOnLabor = 0;
|
|
25
|
+
let totalDiscountOnLabor = 0;
|
|
26
|
+
let total = 0;
|
|
23
27
|
let subtotal = 0;
|
|
24
28
|
let totalTax = 0;
|
|
25
|
-
let totalTaxOnItems = 0;
|
|
26
|
-
let totalTaxOnLabor = 0;
|
|
27
29
|
let totalDiscount = 0;
|
|
28
|
-
let totalDiscountOnItems = 0;
|
|
29
|
-
let totalDiscountOnLabor = 0;
|
|
30
30
|
let roundOff = 0;
|
|
31
31
|
let totalAfterRounded = 0;
|
|
32
|
+
// Returns totals
|
|
33
|
+
let returnSubtotal = 0;
|
|
34
|
+
let nonReturnSubTotal = 0;
|
|
35
|
+
let returnTax = 0;
|
|
36
|
+
let nonReturnTax = 0;
|
|
37
|
+
let returnTotal = 0;
|
|
38
|
+
let nonReturnTotal = 0;
|
|
39
|
+
let returnTotalDiscount = 0;
|
|
32
40
|
// Tax breakdown totals - only calculate if taxable
|
|
33
41
|
let totalSGST = 0;
|
|
34
42
|
let totalCGST = 0;
|
|
@@ -44,18 +52,41 @@ function SalesTotalCalculations(items = [], ops = [], isTaxable = false, taxCode
|
|
|
44
52
|
const itemDisc = (0, util_1.GetNumber)(item.Disc);
|
|
45
53
|
const itemRecDisc = (0, util_1.GetNumber)(item.RecDisc);
|
|
46
54
|
const itemUnAmt = (0, util_1.GetNumber)(item.UnAmt);
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
55
|
+
// Calculate return total for items with Ret = true (explicitly check for true)
|
|
56
|
+
if (item.Ret === true) {
|
|
57
|
+
const itemNetAmount = (0, math_operations_1.Subtract)(itemUnAmt, (0, math_operations_1.Add)(itemDisc, itemRecDisc));
|
|
58
|
+
// Add to return subtotal (net amount after discounts)
|
|
59
|
+
returnSubtotal = (0, math_operations_1.Add)(returnSubtotal, itemUnAmt);
|
|
60
|
+
if (isTaxable) {
|
|
61
|
+
const itemSGST = (0, util_1.GetNumber)(item.SGST);
|
|
62
|
+
const itemCGST = (0, util_1.GetNumber)(item.CGST);
|
|
63
|
+
const itemIGST = (0, util_1.GetNumber)(item.IGST);
|
|
64
|
+
const itemTotalTax = (0, math_operations_1.Add)(itemSGST, itemCGST, itemIGST);
|
|
65
|
+
// Add to return tax
|
|
66
|
+
returnTax = (0, math_operations_1.Add)(returnTax, itemTotalTax);
|
|
67
|
+
// Return total includes net amount + tax
|
|
68
|
+
returnTotal = (0, math_operations_1.Add)(returnTotal, itemNetAmount, itemTotalTax);
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
// Return total without tax (same as returnSubtotal when not taxable)
|
|
72
|
+
returnTotal = (0, math_operations_1.Add)(returnTotal, itemNetAmount);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
// Process normal items (Ret is false, undefined, or null - all treated as normal items)
|
|
77
|
+
totalDiscountOnItems = (0, math_operations_1.Add)(totalDiscountOnItems, itemDisc, itemRecDisc);
|
|
78
|
+
subtotalOnItems = (0, math_operations_1.Add)(subtotalOnItems, itemUnAmt);
|
|
79
|
+
// Only calculate tax if taxable
|
|
80
|
+
if (isTaxable) {
|
|
81
|
+
const itemSGST = (0, util_1.GetNumber)(item.SGST);
|
|
82
|
+
const itemCGST = (0, util_1.GetNumber)(item.CGST);
|
|
83
|
+
const itemIGST = (0, util_1.GetNumber)(item.IGST);
|
|
84
|
+
// Add individual tax amounts for items
|
|
85
|
+
totalSGSTOnItems = (0, math_operations_1.Add)(totalSGSTOnItems, itemSGST);
|
|
86
|
+
totalCGSTOnItems = (0, math_operations_1.Add)(totalCGSTOnItems, itemCGST);
|
|
87
|
+
totalIGSTOnItems = (0, math_operations_1.Add)(totalIGSTOnItems, itemIGST);
|
|
88
|
+
totalTaxOnItems = (0, math_operations_1.Add)(totalTaxOnItems, itemSGST, itemCGST, itemIGST);
|
|
89
|
+
}
|
|
59
90
|
}
|
|
60
91
|
});
|
|
61
92
|
// Calculate operations/labor totals with null safety
|
|
@@ -81,6 +112,14 @@ function SalesTotalCalculations(items = [], ops = [], isTaxable = false, taxCode
|
|
|
81
112
|
totalDiscount = (0, math_operations_1.Add)(totalDiscountOnItems, totalDiscountOnLabor);
|
|
82
113
|
totalTax = (0, math_operations_1.Add)(totalTaxOnItems, totalTaxOnLabor);
|
|
83
114
|
subtotal = (0, math_operations_1.Add)(subtotalOnItems, subtotalOnLabor);
|
|
115
|
+
nonReturnSubTotal = subtotal;
|
|
116
|
+
nonReturnTax = totalTax;
|
|
117
|
+
// Step 2: Add tax if taxable
|
|
118
|
+
nonReturnTotal = isTaxable ? (0, math_operations_1.Add)((0, math_operations_1.Subtract)(subtotal, totalDiscount), totalTax) : (0, math_operations_1.Subtract)(subtotal, totalDiscount);
|
|
119
|
+
// Subtract return subtotal from subtotal
|
|
120
|
+
subtotal = (0, math_operations_1.Subtract)(subtotal, returnSubtotal);
|
|
121
|
+
// Subtract return tax from total tax
|
|
122
|
+
totalTax = (0, math_operations_1.Subtract)(totalTax, returnTax);
|
|
84
123
|
// Calculate combined tax breakdown totals only if taxable
|
|
85
124
|
if (isTaxable) {
|
|
86
125
|
totalSGST = (0, math_operations_1.Add)(totalSGSTOnItems, totalSGSTOnLabor);
|
|
@@ -92,7 +131,10 @@ function SalesTotalCalculations(items = [], ops = [], isTaxable = false, taxCode
|
|
|
92
131
|
const netAmountAfterDiscount = (0, math_operations_1.Subtract)(subtotal, totalDiscount);
|
|
93
132
|
// Step 2: Add tax if taxable
|
|
94
133
|
total = isTaxable ? (0, math_operations_1.Add)(netAmountAfterDiscount, totalTax) : netAmountAfterDiscount;
|
|
134
|
+
// Step 3: Add adjustments
|
|
95
135
|
total = (0, math_operations_1.Add)(total, (0, util_1.GetNumber)(Adjust));
|
|
136
|
+
// // Step 4: Subtract return total from the final total
|
|
137
|
+
// total = Subtract(total, returnTotal);
|
|
96
138
|
// FIXED ROUNDING: Use Math.round instead of Math.floor
|
|
97
139
|
const roundedTotal = Math.round(total);
|
|
98
140
|
roundOff = (0, math_operations_1.Subtract)(roundedTotal, total);
|
|
@@ -109,7 +151,13 @@ function SalesTotalCalculations(items = [], ops = [], isTaxable = false, taxCode
|
|
|
109
151
|
subtotalOnLabor,
|
|
110
152
|
totalDiscountOnItems,
|
|
111
153
|
totalDiscountOnLabor,
|
|
112
|
-
netAmountAfterDiscount
|
|
154
|
+
netAmountAfterDiscount,
|
|
155
|
+
returnSubtotal,
|
|
156
|
+
returnTax,
|
|
157
|
+
returnTotal,
|
|
158
|
+
nonReturnSubTotal,
|
|
159
|
+
nonReturnTax,
|
|
160
|
+
nonReturnTotal
|
|
113
161
|
};
|
|
114
162
|
// Only include tax fields and taxSummary if taxable
|
|
115
163
|
if (isTaxable) {
|
|
@@ -126,7 +174,9 @@ function SalesTotalCalculations(items = [], ops = [], isTaxable = false, taxCode
|
|
|
126
174
|
result.totalCGSTOnLabor = totalCGSTOnLabor;
|
|
127
175
|
result.totalIGSTOnLabor = totalIGSTOnLabor;
|
|
128
176
|
// Calculate tax summary only if taxable and taxCodes provided
|
|
129
|
-
|
|
177
|
+
// Filter out items where Ret is true (only include non-return items)
|
|
178
|
+
const nonReturnItems = safeItems.filter((item) => item.Ret !== true);
|
|
179
|
+
result.itemsTaxSummary = safeTaxCodes.length > 0 ? CalculateTaxSummary(nonReturnItems, safeTaxCodes) : [];
|
|
130
180
|
result.opsTaxSummary = safeTaxCodes.length > 0 ? CalculateTaxSummary(safeOps, safeTaxCodes) : [];
|
|
131
181
|
}
|
|
132
182
|
return result;
|
|
@@ -149,7 +199,13 @@ function SalesTotalCalculationsWithDecimals(items = [], ops = [], isTaxable = fa
|
|
|
149
199
|
subtotalOnLabor: roundToDecimals(result.subtotalOnLabor),
|
|
150
200
|
totalDiscountOnItems: roundToDecimals(result.totalDiscountOnItems),
|
|
151
201
|
totalDiscountOnLabor: roundToDecimals(result.totalDiscountOnLabor),
|
|
152
|
-
netAmountAfterDiscount: roundToDecimals(result.netAmountAfterDiscount)
|
|
202
|
+
netAmountAfterDiscount: roundToDecimals(result.netAmountAfterDiscount),
|
|
203
|
+
returnSubtotal: roundToDecimals(result.returnSubtotal),
|
|
204
|
+
returnTax: roundToDecimals(result.returnTax),
|
|
205
|
+
returnTotal: roundToDecimals(result.returnTotal),
|
|
206
|
+
nonReturnSubTotal: roundToDecimals(result.nonReturnSubTotal),
|
|
207
|
+
nonReturnTax: roundToDecimals(result.nonReturnTax),
|
|
208
|
+
nonReturnTotal: roundToDecimals(result.nonReturnTotal)
|
|
153
209
|
};
|
|
154
210
|
// Only include tax fields and taxSummary if taxable
|
|
155
211
|
if (isTaxable) {
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
type QuantityTier = {
|
|
2
|
+
MinQty?: number | null;
|
|
3
|
+
Price?: number | null;
|
|
4
|
+
Disc?: number | null;
|
|
5
|
+
};
|
|
6
|
+
type PriceListDoc = {
|
|
7
|
+
_id?: any;
|
|
8
|
+
TType: "SALE" | "PUR";
|
|
9
|
+
PrCalc: "FIXED" | "DISC" | "FORMULA";
|
|
10
|
+
BasedOn?: "SP" | "PC" | "PCBD" | "PCAD";
|
|
11
|
+
Fixed?: {
|
|
12
|
+
Price?: number | null;
|
|
13
|
+
};
|
|
14
|
+
CalcDisc?: {
|
|
15
|
+
Mark?: boolean;
|
|
16
|
+
Perc?: number | null;
|
|
17
|
+
};
|
|
18
|
+
Round?: string | null;
|
|
19
|
+
Deci?: number | null;
|
|
20
|
+
QtyTiers?: QuantityTier[];
|
|
21
|
+
Currency?: string | null;
|
|
22
|
+
};
|
|
23
|
+
export declare function ApplyServicePriceListToProcedure(procedure: any, priceList: PriceListDoc | null, quantity?: number): any;
|
|
24
|
+
export declare function ApplyServicePriceListToOpcode(opcode: any, priceList: PriceListDoc | null, quantity?: number): any;
|
|
25
|
+
export {};
|
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ApplyServicePriceListToProcedure = ApplyServicePriceListToProcedure;
|
|
4
|
+
exports.ApplyServicePriceListToOpcode = ApplyServicePriceListToOpcode;
|
|
5
|
+
const math_operations_1 = require("../shared/math-operations");
|
|
6
|
+
const util_1 = require("../shared/util");
|
|
7
|
+
const ROUND_VALUES = new Set(["-1", "0", "0.99", "0.50", "0.49", "Dec"]);
|
|
8
|
+
function ApplyServicePriceListToProcedure(procedure, priceList, quantity = 1) {
|
|
9
|
+
var _a, _b;
|
|
10
|
+
if (!procedure || !priceList) {
|
|
11
|
+
return procedure;
|
|
12
|
+
}
|
|
13
|
+
const resolvedQty = Math.max(1, Number(quantity) || 1);
|
|
14
|
+
const warnings = [];
|
|
15
|
+
if (priceList.TType === "SALE" && procedure.Sale) {
|
|
16
|
+
const basePrice = (0, util_1.IsNotNull)(procedure.Sale.Price) ? procedure.Sale.Price : null;
|
|
17
|
+
const { value, tierWarnings, appliedTier, appliedCalc } = evaluatePriceBlock(basePrice, procedure.Pur, priceList, resolvedQty);
|
|
18
|
+
procedure.Sale.PriceBeforePriceList = basePrice;
|
|
19
|
+
if (value != null) {
|
|
20
|
+
procedure.Sale.Price = value;
|
|
21
|
+
procedure.Sale.AppliedPriceListId = (_a = priceList._id) !== null && _a !== void 0 ? _a : null;
|
|
22
|
+
procedure.Sale.AppliedPriceTier = appliedTier !== null && appliedTier !== void 0 ? appliedTier : undefined;
|
|
23
|
+
procedure.Sale.AppliedPriceCalc = appliedCalc !== null && appliedCalc !== void 0 ? appliedCalc : undefined;
|
|
24
|
+
}
|
|
25
|
+
if (tierWarnings.length > 0) {
|
|
26
|
+
warnings.push(...tierWarnings);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
if (priceList.TType === "PUR" && procedure.Pur) {
|
|
30
|
+
const baseCost = (0, util_1.IsNotNull)(procedure.Pur.Cost) ? procedure.Pur.Cost : null;
|
|
31
|
+
const { value, tierWarnings, appliedTier, appliedCalc } = evaluatePriceBlock(baseCost, procedure.Pur, priceList, resolvedQty);
|
|
32
|
+
procedure.Pur.CostBeforePriceList = baseCost;
|
|
33
|
+
if (value != null) {
|
|
34
|
+
procedure.Pur.Cost = value;
|
|
35
|
+
procedure.Pur.AppliedPriceListId = (_b = priceList._id) !== null && _b !== void 0 ? _b : null;
|
|
36
|
+
procedure.Pur.AppliedPriceTier = appliedTier !== null && appliedTier !== void 0 ? appliedTier : undefined;
|
|
37
|
+
procedure.Pur.AppliedPriceCalc = appliedCalc !== null && appliedCalc !== void 0 ? appliedCalc : undefined;
|
|
38
|
+
}
|
|
39
|
+
if (tierWarnings.length > 0) {
|
|
40
|
+
warnings.push(...tierWarnings);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
if (warnings.length > 0) {
|
|
44
|
+
procedure.PriceListWarnings = warnings;
|
|
45
|
+
}
|
|
46
|
+
return procedure;
|
|
47
|
+
}
|
|
48
|
+
function ApplyServicePriceListToOpcode(opcode, priceList, quantity = 1) {
|
|
49
|
+
if (!opcode || !priceList) {
|
|
50
|
+
return opcode;
|
|
51
|
+
}
|
|
52
|
+
const resolvedQty = Math.max(1, Number(quantity) || 1);
|
|
53
|
+
const warnings = [];
|
|
54
|
+
if (Array.isArray(opcode.Prices) && opcode.Prices.length > 0) {
|
|
55
|
+
opcode.Prices = opcode.Prices.map((pricing) => {
|
|
56
|
+
var _a, _b;
|
|
57
|
+
const cloned = Object.assign({}, pricing);
|
|
58
|
+
if (cloned.Sale) {
|
|
59
|
+
cloned.Sale = Object.assign({}, cloned.Sale);
|
|
60
|
+
}
|
|
61
|
+
if (cloned.Pur) {
|
|
62
|
+
cloned.Pur = Object.assign({}, cloned.Pur);
|
|
63
|
+
}
|
|
64
|
+
if (priceList.TType === "SALE" &&
|
|
65
|
+
cloned.Sale &&
|
|
66
|
+
(!cloned.PS || cloned.PS === "S" || cloned.PS === "SP")) {
|
|
67
|
+
const basePrice = (0, util_1.IsNotNull)(cloned.Sale.Price) ? cloned.Sale.Price : null;
|
|
68
|
+
const { value, tierWarnings, appliedTier, appliedCalc } = evaluatePriceBlock(basePrice, cloned.Pur, priceList, resolvedQty);
|
|
69
|
+
cloned.Sale.PriceBeforePriceList = basePrice;
|
|
70
|
+
if (value != null) {
|
|
71
|
+
cloned.Sale.Price = value;
|
|
72
|
+
cloned.Sale.AppliedPriceListId = (_a = priceList._id) !== null && _a !== void 0 ? _a : null;
|
|
73
|
+
cloned.Sale.AppliedPriceTier = appliedTier !== null && appliedTier !== void 0 ? appliedTier : undefined;
|
|
74
|
+
cloned.Sale.AppliedPriceCalc = appliedCalc !== null && appliedCalc !== void 0 ? appliedCalc : undefined;
|
|
75
|
+
}
|
|
76
|
+
if (tierWarnings.length > 0) {
|
|
77
|
+
warnings.push(...tierWarnings);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
if (priceList.TType === "PUR" &&
|
|
81
|
+
cloned.Pur &&
|
|
82
|
+
(!cloned.PS || cloned.PS === "P" || cloned.PS === "SP")) {
|
|
83
|
+
const baseCost = (0, util_1.IsNotNull)(cloned.Pur.Cost) ? cloned.Pur.Cost : null;
|
|
84
|
+
const { value, tierWarnings, appliedTier, appliedCalc } = evaluatePriceBlock(baseCost, cloned.Pur, priceList, resolvedQty);
|
|
85
|
+
cloned.Pur.CostBeforePriceList = baseCost;
|
|
86
|
+
if (value != null) {
|
|
87
|
+
cloned.Pur.Cost = value;
|
|
88
|
+
cloned.Pur.AppliedPriceListId = (_b = priceList._id) !== null && _b !== void 0 ? _b : null;
|
|
89
|
+
cloned.Pur.AppliedPriceTier = appliedTier !== null && appliedTier !== void 0 ? appliedTier : undefined;
|
|
90
|
+
cloned.Pur.AppliedPriceCalc = appliedCalc !== null && appliedCalc !== void 0 ? appliedCalc : undefined;
|
|
91
|
+
}
|
|
92
|
+
if (tierWarnings.length > 0) {
|
|
93
|
+
warnings.push(...tierWarnings);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
return cloned;
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
if (warnings.length > 0) {
|
|
100
|
+
opcode.PriceListWarnings = warnings;
|
|
101
|
+
}
|
|
102
|
+
return opcode;
|
|
103
|
+
}
|
|
104
|
+
function evaluatePriceBlock(baseValue, purchaseBlock, priceList, quantity) {
|
|
105
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
106
|
+
const warnings = [];
|
|
107
|
+
const tier = resolveTier(quantity, priceList.QtyTiers);
|
|
108
|
+
if (tier) {
|
|
109
|
+
const tierValue = applyTierAdjustment(baseValue, purchaseBlock, tier, priceList);
|
|
110
|
+
const rounded = applyRounding(priceList, tierValue);
|
|
111
|
+
return {
|
|
112
|
+
value: rounded,
|
|
113
|
+
tierWarnings: warnings,
|
|
114
|
+
appliedTier: buildAppliedTierMeta(tier),
|
|
115
|
+
appliedCalc: "TIER",
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
switch (priceList.PrCalc) {
|
|
119
|
+
case "FIXED": {
|
|
120
|
+
if ((0, util_1.IsNull)((_a = priceList.Fixed) === null || _a === void 0 ? void 0 : _a.Price)) {
|
|
121
|
+
warnings.push("Fixed price list selected but Fixed.Price is not configured.");
|
|
122
|
+
return { value: null, tierWarnings: warnings };
|
|
123
|
+
}
|
|
124
|
+
const rounded = applyRounding(priceList, (_c = (_b = priceList.Fixed) === null || _b === void 0 ? void 0 : _b.Price) !== null && _c !== void 0 ? _c : null);
|
|
125
|
+
return { value: rounded, tierWarnings: warnings, appliedCalc: "FIXED" };
|
|
126
|
+
}
|
|
127
|
+
case "DISC": {
|
|
128
|
+
const base = resolveDiscountBase(priceList, baseValue, purchaseBlock);
|
|
129
|
+
if (base == null) {
|
|
130
|
+
warnings.push("Discount price list requires a base value but none was available.");
|
|
131
|
+
return { value: null, tierWarnings: warnings };
|
|
132
|
+
}
|
|
133
|
+
const perc = (_e = (_d = priceList.CalcDisc) === null || _d === void 0 ? void 0 : _d.Perc) !== null && _e !== void 0 ? _e : 0;
|
|
134
|
+
const mark = (_g = (_f = priceList.CalcDisc) === null || _f === void 0 ? void 0 : _f.Mark) !== null && _g !== void 0 ? _g : false;
|
|
135
|
+
const price = (0, math_operations_1.CalcDiscPrice)(base, perc, mark);
|
|
136
|
+
return {
|
|
137
|
+
value: applyRounding(priceList, price),
|
|
138
|
+
tierWarnings: warnings,
|
|
139
|
+
appliedCalc: "DISCOUNT",
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
case "FORMULA": {
|
|
143
|
+
warnings.push("Formula-based service price lists are not implemented.");
|
|
144
|
+
return { value: null, tierWarnings: warnings };
|
|
145
|
+
}
|
|
146
|
+
default:
|
|
147
|
+
return { value: null, tierWarnings: warnings };
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
function applyTierAdjustment(baseValue, purchaseBlock, tier, priceList) {
|
|
151
|
+
var _a, _b;
|
|
152
|
+
if ((0, util_1.IsNotNull)(tier.Price)) {
|
|
153
|
+
return (_a = tier.Price) !== null && _a !== void 0 ? _a : null;
|
|
154
|
+
}
|
|
155
|
+
const targetBase = resolveDiscountBase(priceList, baseValue, purchaseBlock);
|
|
156
|
+
if (targetBase == null || (0, util_1.IsNull)(tier.Disc)) {
|
|
157
|
+
return baseValue;
|
|
158
|
+
}
|
|
159
|
+
return (0, math_operations_1.CalcDiscPrice)(targetBase, (_b = tier.Disc) !== null && _b !== void 0 ? _b : 0, false);
|
|
160
|
+
}
|
|
161
|
+
function resolveDiscountBase(priceList, baseValue, purchaseBlock) {
|
|
162
|
+
var _a;
|
|
163
|
+
const basedOn = (_a = priceList.BasedOn) !== null && _a !== void 0 ? _a : "SP";
|
|
164
|
+
switch (basedOn) {
|
|
165
|
+
case "SP":
|
|
166
|
+
return baseValue;
|
|
167
|
+
case "PC":
|
|
168
|
+
case "PCBD":
|
|
169
|
+
case "PCAD":
|
|
170
|
+
if (purchaseBlock && (0, util_1.IsNotNull)(purchaseBlock.Cost)) {
|
|
171
|
+
return purchaseBlock.Cost;
|
|
172
|
+
}
|
|
173
|
+
return null;
|
|
174
|
+
default:
|
|
175
|
+
return baseValue;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
function applyRounding(priceList, value) {
|
|
179
|
+
var _a;
|
|
180
|
+
if (value == null) {
|
|
181
|
+
return null;
|
|
182
|
+
}
|
|
183
|
+
if (!priceList.Round || !ROUND_VALUES.has(priceList.Round)) {
|
|
184
|
+
return value;
|
|
185
|
+
}
|
|
186
|
+
switch (priceList.Round) {
|
|
187
|
+
case "-1":
|
|
188
|
+
return value;
|
|
189
|
+
case "0":
|
|
190
|
+
return Math.round(value);
|
|
191
|
+
case "0.99":
|
|
192
|
+
return Math.floor(value) + 0.99;
|
|
193
|
+
case "0.50":
|
|
194
|
+
return Math.round(value * 2) / 2;
|
|
195
|
+
case "0.49":
|
|
196
|
+
return Math.floor(value) + 0.49;
|
|
197
|
+
case "Dec":
|
|
198
|
+
if ((0, util_1.IsNotNull)(priceList.Deci)) {
|
|
199
|
+
const factor = Math.pow(10, (_a = priceList.Deci) !== null && _a !== void 0 ? _a : 0);
|
|
200
|
+
return Math.round(value * factor) / factor;
|
|
201
|
+
}
|
|
202
|
+
return value;
|
|
203
|
+
default:
|
|
204
|
+
return value;
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
function resolveTier(quantity, tiers) {
|
|
208
|
+
var _a;
|
|
209
|
+
if (!Array.isArray(tiers) || tiers.length === 0) {
|
|
210
|
+
return null;
|
|
211
|
+
}
|
|
212
|
+
const sorted = [...tiers]
|
|
213
|
+
.filter((tier) => (0, util_1.IsNotNull)(tier === null || tier === void 0 ? void 0 : tier.MinQty))
|
|
214
|
+
.sort((a, b) => { var _a, _b; return ((_a = a === null || a === void 0 ? void 0 : a.MinQty) !== null && _a !== void 0 ? _a : 0) - ((_b = b === null || b === void 0 ? void 0 : b.MinQty) !== null && _b !== void 0 ? _b : 0); });
|
|
215
|
+
let selected = null;
|
|
216
|
+
for (const tier of sorted) {
|
|
217
|
+
if (quantity >= ((_a = tier === null || tier === void 0 ? void 0 : tier.MinQty) !== null && _a !== void 0 ? _a : 0)) {
|
|
218
|
+
selected = tier !== null && tier !== void 0 ? tier : null;
|
|
219
|
+
}
|
|
220
|
+
else {
|
|
221
|
+
break;
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
return selected;
|
|
225
|
+
}
|
|
226
|
+
function buildAppliedTierMeta(tier) {
|
|
227
|
+
if (!tier) {
|
|
228
|
+
return undefined;
|
|
229
|
+
}
|
|
230
|
+
return {
|
|
231
|
+
MinQty: (0, util_1.IsNotNull)(tier.MinQty) ? tier.MinQty : null,
|
|
232
|
+
Price: (0, util_1.IsNotNull)(tier.Price) ? tier.Price : null,
|
|
233
|
+
Disc: (0, util_1.IsNotNull)(tier.Disc) ? tier.Disc : null,
|
|
234
|
+
};
|
|
235
|
+
}
|