shareneus 1.5.17 → 1.5.19
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 +3 -1
- package/dist/index.js +10 -1
- package/dist/inventory/items/item-price-for-pricelist.d.ts +1 -1
- package/dist/inventory/items/item-price-for-pricelist.js +1 -1
- package/dist/sales-receive/sales-total-calculation.js +27 -8
- 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,7 +128,9 @@ 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
|
-
export { GetAgeString } from "./shared/util";
|
|
133
|
+
export { GetAgeString, GetNumber } from "./shared/util";
|
|
133
134
|
export { SalesTotalCalculationsWithDecimals } from "./sales-receive/sales-total-calculation";
|
|
134
135
|
export { ServiceHistoryPDFService } from "./services/service-history-pdf.service";
|
|
136
|
+
export { Add, Subtract, Multiply, Divide } from "./shared/math-operations";
|
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.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;
|
|
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,12 +263,21 @@ 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; } });
|
|
269
272
|
var util_2 = require("./shared/util");
|
|
270
273
|
Object.defineProperty(exports, "GetAgeString", { enumerable: true, get: function () { return util_2.GetAgeString; } });
|
|
274
|
+
Object.defineProperty(exports, "GetNumber", { enumerable: true, get: function () { return util_2.GetNumber; } });
|
|
271
275
|
var sales_total_calculation_1 = require("./sales-receive/sales-total-calculation");
|
|
272
276
|
Object.defineProperty(exports, "SalesTotalCalculationsWithDecimals", { enumerable: true, get: function () { return sales_total_calculation_1.SalesTotalCalculationsWithDecimals; } });
|
|
273
277
|
var service_history_pdf_service_1 = require("./services/service-history-pdf.service");
|
|
274
278
|
Object.defineProperty(exports, "ServiceHistoryPDFService", { enumerable: true, get: function () { return service_history_pdf_service_1.ServiceHistoryPDFService; } });
|
|
279
|
+
var math_operations_1 = require("./shared/math-operations");
|
|
280
|
+
Object.defineProperty(exports, "Add", { enumerable: true, get: function () { return math_operations_1.Add; } });
|
|
281
|
+
Object.defineProperty(exports, "Subtract", { enumerable: true, get: function () { return math_operations_1.Subtract; } });
|
|
282
|
+
Object.defineProperty(exports, "Multiply", { enumerable: true, get: function () { return math_operations_1.Multiply; } });
|
|
283
|
+
Object.defineProperty(exports, "Divide", { enumerable: true, get: function () { return math_operations_1.Divide; } });
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export declare function GetItemPriceForPriceList(item: any, priceList: any, includeMargin?: boolean, quantity?: number): 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,7 +4,7 @@ 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, quantity = 1) {
|
|
7
|
+
function GetItemPriceForPriceList(item, priceList, includeMargin = false, quantity = 1, pricingContext = {}) {
|
|
8
8
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
9
9
|
if (!priceList) {
|
|
10
10
|
return item;
|
|
@@ -31,8 +31,12 @@ function SalesTotalCalculations(items = [], ops = [], isTaxable = false, taxCode
|
|
|
31
31
|
let totalAfterRounded = 0;
|
|
32
32
|
// Returns totals
|
|
33
33
|
let returnSubtotal = 0;
|
|
34
|
+
let nonReturnSubTotal = 0;
|
|
34
35
|
let returnTax = 0;
|
|
36
|
+
let nonReturnTax = 0;
|
|
35
37
|
let returnTotal = 0;
|
|
38
|
+
let nonReturnTotal = 0;
|
|
39
|
+
let returnTotalDiscount = 0;
|
|
36
40
|
// Tax breakdown totals - only calculate if taxable
|
|
37
41
|
let totalSGST = 0;
|
|
38
42
|
let totalCGST = 0;
|
|
@@ -48,11 +52,12 @@ function SalesTotalCalculations(items = [], ops = [], isTaxable = false, taxCode
|
|
|
48
52
|
const itemDisc = (0, util_1.GetNumber)(item.Disc);
|
|
49
53
|
const itemRecDisc = (0, util_1.GetNumber)(item.RecDisc);
|
|
50
54
|
const itemUnAmt = (0, util_1.GetNumber)(item.UnAmt);
|
|
51
|
-
// Calculate return total for items with Ret = true
|
|
55
|
+
// Calculate return total for items with Ret = true (explicitly check for true)
|
|
52
56
|
if (item.Ret === true) {
|
|
53
57
|
const itemNetAmount = (0, math_operations_1.Subtract)(itemUnAmt, (0, math_operations_1.Add)(itemDisc, itemRecDisc));
|
|
58
|
+
returnTotalDiscount = (0, math_operations_1.Add)(returnTotalDiscount, itemDisc, itemRecDisc);
|
|
54
59
|
// Add to return subtotal (net amount after discounts)
|
|
55
|
-
returnSubtotal = (0, math_operations_1.Add)(returnSubtotal,
|
|
60
|
+
returnSubtotal = (0, math_operations_1.Add)(returnSubtotal, itemUnAmt);
|
|
56
61
|
if (isTaxable) {
|
|
57
62
|
const itemSGST = (0, util_1.GetNumber)(item.SGST);
|
|
58
63
|
const itemCGST = (0, util_1.GetNumber)(item.CGST);
|
|
@@ -69,7 +74,7 @@ function SalesTotalCalculations(items = [], ops = [], isTaxable = false, taxCode
|
|
|
69
74
|
}
|
|
70
75
|
}
|
|
71
76
|
else {
|
|
72
|
-
// Process normal items (
|
|
77
|
+
// Process normal items (Ret is false, undefined, or null - all treated as normal items)
|
|
73
78
|
totalDiscountOnItems = (0, math_operations_1.Add)(totalDiscountOnItems, itemDisc, itemRecDisc);
|
|
74
79
|
subtotalOnItems = (0, math_operations_1.Add)(subtotalOnItems, itemUnAmt);
|
|
75
80
|
// Only calculate tax if taxable
|
|
@@ -108,10 +113,16 @@ function SalesTotalCalculations(items = [], ops = [], isTaxable = false, taxCode
|
|
|
108
113
|
totalDiscount = (0, math_operations_1.Add)(totalDiscountOnItems, totalDiscountOnLabor);
|
|
109
114
|
totalTax = (0, math_operations_1.Add)(totalTaxOnItems, totalTaxOnLabor);
|
|
110
115
|
subtotal = (0, math_operations_1.Add)(subtotalOnItems, subtotalOnLabor);
|
|
116
|
+
nonReturnSubTotal = subtotal;
|
|
117
|
+
nonReturnTax = totalTax;
|
|
118
|
+
// Step 2: Add tax if taxable
|
|
119
|
+
nonReturnTotal = isTaxable ? (0, math_operations_1.Add)((0, math_operations_1.Subtract)(subtotal, totalDiscount), totalTax) : (0, math_operations_1.Subtract)(subtotal, totalDiscount);
|
|
111
120
|
// Subtract return subtotal from subtotal
|
|
112
121
|
subtotal = (0, math_operations_1.Subtract)(subtotal, returnSubtotal);
|
|
113
122
|
// Subtract return tax from total tax
|
|
114
123
|
totalTax = (0, math_operations_1.Subtract)(totalTax, returnTax);
|
|
124
|
+
// Subtract return Discount from total discount
|
|
125
|
+
totalDiscount = (0, math_operations_1.Subtract)(totalDiscount, returnTotalDiscount);
|
|
115
126
|
// Calculate combined tax breakdown totals only if taxable
|
|
116
127
|
if (isTaxable) {
|
|
117
128
|
totalSGST = (0, math_operations_1.Add)(totalSGSTOnItems, totalSGSTOnLabor);
|
|
@@ -125,8 +136,8 @@ function SalesTotalCalculations(items = [], ops = [], isTaxable = false, taxCode
|
|
|
125
136
|
total = isTaxable ? (0, math_operations_1.Add)(netAmountAfterDiscount, totalTax) : netAmountAfterDiscount;
|
|
126
137
|
// Step 3: Add adjustments
|
|
127
138
|
total = (0, math_operations_1.Add)(total, (0, util_1.GetNumber)(Adjust));
|
|
128
|
-
// Step 4: Subtract return total from the final total
|
|
129
|
-
total =
|
|
139
|
+
// // Step 4: Subtract return total from the final total
|
|
140
|
+
// total = Subtract(total, returnTotal);
|
|
130
141
|
// FIXED ROUNDING: Use Math.round instead of Math.floor
|
|
131
142
|
const roundedTotal = Math.round(total);
|
|
132
143
|
roundOff = (0, math_operations_1.Subtract)(roundedTotal, total);
|
|
@@ -146,7 +157,10 @@ function SalesTotalCalculations(items = [], ops = [], isTaxable = false, taxCode
|
|
|
146
157
|
netAmountAfterDiscount,
|
|
147
158
|
returnSubtotal,
|
|
148
159
|
returnTax,
|
|
149
|
-
returnTotal
|
|
160
|
+
returnTotal,
|
|
161
|
+
nonReturnSubTotal,
|
|
162
|
+
nonReturnTax,
|
|
163
|
+
nonReturnTotal
|
|
150
164
|
};
|
|
151
165
|
// Only include tax fields and taxSummary if taxable
|
|
152
166
|
if (isTaxable) {
|
|
@@ -163,7 +177,9 @@ function SalesTotalCalculations(items = [], ops = [], isTaxable = false, taxCode
|
|
|
163
177
|
result.totalCGSTOnLabor = totalCGSTOnLabor;
|
|
164
178
|
result.totalIGSTOnLabor = totalIGSTOnLabor;
|
|
165
179
|
// Calculate tax summary only if taxable and taxCodes provided
|
|
166
|
-
|
|
180
|
+
// Filter out items where Ret is true (only include non-return items)
|
|
181
|
+
const nonReturnItems = safeItems.filter((item) => item.Ret !== true);
|
|
182
|
+
result.itemsTaxSummary = safeTaxCodes.length > 0 ? CalculateTaxSummary(nonReturnItems, safeTaxCodes) : [];
|
|
167
183
|
result.opsTaxSummary = safeTaxCodes.length > 0 ? CalculateTaxSummary(safeOps, safeTaxCodes) : [];
|
|
168
184
|
}
|
|
169
185
|
return result;
|
|
@@ -189,7 +205,10 @@ function SalesTotalCalculationsWithDecimals(items = [], ops = [], isTaxable = fa
|
|
|
189
205
|
netAmountAfterDiscount: roundToDecimals(result.netAmountAfterDiscount),
|
|
190
206
|
returnSubtotal: roundToDecimals(result.returnSubtotal),
|
|
191
207
|
returnTax: roundToDecimals(result.returnTax),
|
|
192
|
-
returnTotal: roundToDecimals(result.returnTotal)
|
|
208
|
+
returnTotal: roundToDecimals(result.returnTotal),
|
|
209
|
+
nonReturnSubTotal: roundToDecimals(result.nonReturnSubTotal),
|
|
210
|
+
nonReturnTax: roundToDecimals(result.nonReturnTax),
|
|
211
|
+
nonReturnTotal: roundToDecimals(result.nonReturnTotal)
|
|
193
212
|
};
|
|
194
213
|
// Only include tax fields and taxSummary if taxable
|
|
195
214
|
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
|
+
}
|