shareneus 1.4.34 → 1.4.36
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.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.IsNull = exports.IsNotNull = exports.
|
|
5
|
+
exports.IsNull = exports.IsNotNull = exports.GetItemPriceForPriceList = 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("./excel-files/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("./excel-files/category-wise-item-excel.service");
|
|
@@ -247,8 +247,8 @@ var next_service_date_pdf_service_1 = require("./services/next-service-date-pdf.
|
|
|
247
247
|
Object.defineProperty(exports, "NextServiceDatePDFService", { enumerable: true, get: function () { return next_service_date_pdf_service_1.NextServiceDatePDFService; } });
|
|
248
248
|
var item_bar_code_label_pdf_1 = require("./services/item-bar-code-label-pdf");
|
|
249
249
|
Object.defineProperty(exports, "ItemBarCodeLabelPdf", { enumerable: true, get: function () { return item_bar_code_label_pdf_1.ItemBarCodeLabelPdf; } });
|
|
250
|
-
var
|
|
251
|
-
Object.defineProperty(exports, "
|
|
252
|
-
var
|
|
253
|
-
Object.defineProperty(exports, "IsNotNull", { enumerable: true, get: function () { return
|
|
254
|
-
Object.defineProperty(exports, "IsNull", { enumerable: true, get: function () { return
|
|
250
|
+
var item_price_for_pricelist_1 = require("./services/item-price-for-pricelist");
|
|
251
|
+
Object.defineProperty(exports, "GetItemPriceForPriceList", { enumerable: true, get: function () { return item_price_for_pricelist_1.GetItemPriceForPriceList; } });
|
|
252
|
+
var util_1 = require("./shared/util");
|
|
253
|
+
Object.defineProperty(exports, "IsNotNull", { enumerable: true, get: function () { return util_1.IsNotNull; } });
|
|
254
|
+
Object.defineProperty(exports, "IsNull", { enumerable: true, get: function () { return util_1.IsNull; } });
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GetItemPriceForPriceList = GetItemPriceForPriceList;
|
|
4
|
+
exports.CalculatePriceBasedOnPriceList = CalculatePriceBasedOnPriceList;
|
|
5
|
+
exports.ApplyRounding = ApplyRounding;
|
|
6
|
+
const math_operations_1 = require("../shared/math-operations");
|
|
7
|
+
const util_1 = require("../shared/util");
|
|
8
|
+
function GetItemPriceForPriceList(item, priceList, includeMargin) {
|
|
9
|
+
let salePricesByPriceListId = [];
|
|
10
|
+
if ((0, util_1.IsNotNull)(item.SalePrices) && item.SalePrices.length > 0) {
|
|
11
|
+
salePricesByPriceListId = item.SalePrices.filter((price) => priceList._id.toString() == price.PrListId.toString());
|
|
12
|
+
}
|
|
13
|
+
if (salePricesByPriceListId.length > 0) {
|
|
14
|
+
item.SalePrices = salePricesByPriceListId;
|
|
15
|
+
if (item.Track == 'TR' || item.Track == 'SN') {
|
|
16
|
+
item.Sale["MRP"] = item.Sale.Price;
|
|
17
|
+
if ((0, util_1.IsNotNull)(item.SalePrices[0].Price) && (0, util_1.IsNotNull)(item.SalePrices[0].Disc)) {
|
|
18
|
+
const calculatedPrice = (0, math_operations_1.CalcDiscPrice)(item.SalePrices[0].Price, item.SalePrices[0].Disc);
|
|
19
|
+
item.Sale.Price = ApplyRounding(calculatedPrice, priceList);
|
|
20
|
+
}
|
|
21
|
+
else if ((0, util_1.IsNotNull)(item.SalePrices[0].Price) && (0, util_1.IsNull)(item.SalePrices[0].Disc)) {
|
|
22
|
+
item.Sale.Price = ApplyRounding(item.SalePrices[0].Price, priceList);
|
|
23
|
+
}
|
|
24
|
+
else if ((0, util_1.IsNull)(item.SalePrices[0].Price) && (0, util_1.IsNotNull)(item.SalePrices[0].Disc)) {
|
|
25
|
+
const calculatedPrice = (0, math_operations_1.CalcDiscPrice)(item.Sale.Price, item.SalePrices[0].Disc);
|
|
26
|
+
item.Sale.Price = ApplyRounding(calculatedPrice, priceList);
|
|
27
|
+
}
|
|
28
|
+
if (includeMargin) {
|
|
29
|
+
item.Margin = (0, math_operations_1.GetMarginValue)(item.Sale.Price, item.Pur.Cost);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
else if (item.Track == 'BN') {
|
|
33
|
+
for (let index = 0; index < item.Batches.length; index++) {
|
|
34
|
+
const element = item.Batches[index];
|
|
35
|
+
let batchSalePrice = item.SalePrices.filter((batch) => priceList._id.toString() == batch.PrListId.toString() && element.BN == batch.BN);
|
|
36
|
+
if (batchSalePrice.length == 0) {
|
|
37
|
+
batchSalePrice = item.SalePrices.filter((batch) => priceList._id.toString() == batch.PrListId.toString() && batch.BN == null);
|
|
38
|
+
}
|
|
39
|
+
element.MRP = element.Price;
|
|
40
|
+
if (batchSalePrice.length > 0) {
|
|
41
|
+
if ((0, util_1.IsNotNull)(batchSalePrice[0].Price) && (0, util_1.IsNotNull)(batchSalePrice[0].Disc)) {
|
|
42
|
+
const calculatedPrice = (0, math_operations_1.CalcDiscPrice)(batchSalePrice[0].Price, batchSalePrice[0].Disc);
|
|
43
|
+
element.Price = ApplyRounding(calculatedPrice, priceList);
|
|
44
|
+
}
|
|
45
|
+
else if ((0, util_1.IsNotNull)(batchSalePrice[0].Price) && (0, util_1.IsNull)(batchSalePrice[0].Disc)) {
|
|
46
|
+
element.Price = ApplyRounding(batchSalePrice[0].Price, priceList);
|
|
47
|
+
}
|
|
48
|
+
else if ((0, util_1.IsNull)(batchSalePrice[0].Price) && (0, util_1.IsNotNull)(batchSalePrice[0].Disc)) {
|
|
49
|
+
const calculatedPrice = (0, math_operations_1.CalcDiscPrice)(element.Price, batchSalePrice[0].Disc);
|
|
50
|
+
element.Price = ApplyRounding(calculatedPrice, priceList);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
if (includeMargin) {
|
|
54
|
+
element.Margin = (0, math_operations_1.GetMarginValue)(element.Price, element.Cost);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return item;
|
|
59
|
+
}
|
|
60
|
+
return CalculatePriceBasedOnPriceList(item, priceList, includeMargin);
|
|
61
|
+
}
|
|
62
|
+
function CalculatePriceBasedOnPriceList(item, priceList, includeMargin) {
|
|
63
|
+
var _a, _b;
|
|
64
|
+
if (priceList != null) {
|
|
65
|
+
if (priceList.PrCalc == "FIXED") {
|
|
66
|
+
if (priceList.Fixed && (0, util_1.IsNotNull)(priceList.Fixed.Price)) {
|
|
67
|
+
const fixedPrice = priceList.Fixed.Price;
|
|
68
|
+
if (item.Track == 'TR' || item.Track == 'SN') {
|
|
69
|
+
item.Sale["MRP"] = item.Sale.Price;
|
|
70
|
+
item.Sale.Price = ApplyRounding(fixedPrice, priceList);
|
|
71
|
+
if (includeMargin) {
|
|
72
|
+
item.Margin = (0, math_operations_1.GetMarginValue)(item.Sale.Price, item.Pur.Cost);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
else if (item.Track == 'BN') {
|
|
76
|
+
for (let batch of item.Batches) {
|
|
77
|
+
batch.MRP = batch.Price;
|
|
78
|
+
batch.Price = ApplyRounding(fixedPrice, priceList);
|
|
79
|
+
if (includeMargin) {
|
|
80
|
+
batch.Margin = (0, math_operations_1.GetMarginValue)(batch.Price, batch.Cost);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
else if (priceList.PrCalc == "DISC") {
|
|
87
|
+
const calcDisc = (_a = priceList.CalcDisc) !== null && _a !== void 0 ? _a : {};
|
|
88
|
+
let discPerc = calcDisc.Perc || 0;
|
|
89
|
+
let markUp = (_b = calcDisc.Mark) !== null && _b !== void 0 ? _b : false;
|
|
90
|
+
if (priceList.BasedOn == "SP") {
|
|
91
|
+
if (item.Track == 'TR' || item.Track == 'SN') {
|
|
92
|
+
item.Sale["MRP"] = item.Sale.Price;
|
|
93
|
+
const calculatedPrice = (0, math_operations_1.CalcDiscPrice)(item.Sale.Price, discPerc, markUp);
|
|
94
|
+
item.Sale.Price = ApplyRounding(calculatedPrice, priceList);
|
|
95
|
+
if (includeMargin) {
|
|
96
|
+
item.Margin = (0, math_operations_1.GetMarginValue)(item.Sale.Price, item.Pur.Cost);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
else if (item.Track == 'BN') {
|
|
100
|
+
for (let batch of item.Batches) {
|
|
101
|
+
batch.MRP = batch.Price;
|
|
102
|
+
const calculatedPrice = (0, math_operations_1.CalcDiscPrice)(batch.Price, discPerc, markUp);
|
|
103
|
+
batch.Price = ApplyRounding(calculatedPrice, priceList);
|
|
104
|
+
if (includeMargin) {
|
|
105
|
+
batch.Margin = (0, math_operations_1.GetMarginValue)(batch.Price, batch.Cost);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
else if (priceList.BasedOn == "PC") {
|
|
111
|
+
if (item.Track == 'TR' || item.Track == 'SN') {
|
|
112
|
+
item.Sale["MRP"] = item.Sale.Price;
|
|
113
|
+
if ((0, util_1.IsNotNull)(item.Pur) && (0, util_1.IsNotNull)(item.Pur.Cost)) {
|
|
114
|
+
const calculatedPrice = (0, math_operations_1.CalcDiscPrice)(item.Pur.Cost, discPerc, markUp);
|
|
115
|
+
item.Sale.Price = ApplyRounding(calculatedPrice, priceList);
|
|
116
|
+
if (includeMargin) {
|
|
117
|
+
item.Margin = (0, math_operations_1.GetMarginValue)(item.Sale.Price, item.Pur.Cost);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
else if (item.Track == 'BN') {
|
|
122
|
+
for (let batch of item.Batches) {
|
|
123
|
+
batch.MRP = batch.Price;
|
|
124
|
+
if ((0, util_1.IsNotNull)(batch.Cost)) {
|
|
125
|
+
const calculatedPrice = (0, math_operations_1.CalcDiscPrice)(batch.Cost, discPerc, markUp);
|
|
126
|
+
batch.Price = ApplyRounding(calculatedPrice, priceList);
|
|
127
|
+
if (includeMargin) {
|
|
128
|
+
batch.Margin = (0, math_operations_1.GetMarginValue)(batch.Price, batch.Cost);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
return item;
|
|
137
|
+
}
|
|
138
|
+
function ApplyRounding(price, priceList) {
|
|
139
|
+
if (!priceList || !priceList.Round)
|
|
140
|
+
return price;
|
|
141
|
+
switch (priceList.Round) {
|
|
142
|
+
case "-1":
|
|
143
|
+
return price;
|
|
144
|
+
case "0":
|
|
145
|
+
return Math.round(price);
|
|
146
|
+
case "0.99":
|
|
147
|
+
return Math.floor(price) + 0.99;
|
|
148
|
+
case "0.50":
|
|
149
|
+
return Math.round(price * 2) / 2;
|
|
150
|
+
case "0.49":
|
|
151
|
+
return Math.floor(price) + 0.49;
|
|
152
|
+
case "Dec":
|
|
153
|
+
if ((0, util_1.IsNotNull)(priceList.Deci)) {
|
|
154
|
+
const factor = Math.pow(10, priceList.Deci);
|
|
155
|
+
return Math.round(price * factor) / factor;
|
|
156
|
+
}
|
|
157
|
+
return price;
|
|
158
|
+
default:
|
|
159
|
+
return price;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.Add = Add;
|
|
7
|
+
exports.Subtract = Subtract;
|
|
8
|
+
exports.Multiply = Multiply;
|
|
9
|
+
exports.Divide = Divide;
|
|
10
|
+
exports.CalcDiscPrice = CalcDiscPrice;
|
|
11
|
+
exports.CalcMarkup = CalcMarkup;
|
|
12
|
+
exports.CalcMarkdown = CalcMarkdown;
|
|
13
|
+
exports.GetMarginValue = GetMarginValue;
|
|
14
|
+
// Import Big.js for precise decimal arithmetic
|
|
15
|
+
const big_js_1 = __importDefault(require("big.js"));
|
|
16
|
+
// Import utility function for handling number conversions
|
|
17
|
+
const util_js_1 = require("./util.js");
|
|
18
|
+
/**
|
|
19
|
+
* Adds multiple numbers with high precision using Big.js
|
|
20
|
+
* @param numbers - Array of numbers to add
|
|
21
|
+
* @returns The sum as a number
|
|
22
|
+
*/
|
|
23
|
+
function Add(...numbers) {
|
|
24
|
+
// Convert potential null/undefined values to numbers
|
|
25
|
+
numbers = numbers.map(util_js_1.GetNumber);
|
|
26
|
+
if (numbers.length === 0)
|
|
27
|
+
return 0;
|
|
28
|
+
// Initialize result with the first number
|
|
29
|
+
let result = new big_js_1.default(numbers[0]);
|
|
30
|
+
// Add each subsequent number to the result using a for loop
|
|
31
|
+
for (let i = 1; i < numbers.length; i++) {
|
|
32
|
+
const bigNumber = new big_js_1.default(numbers[i]);
|
|
33
|
+
result = result.plus(bigNumber);
|
|
34
|
+
}
|
|
35
|
+
// Convert back to JavaScript number type
|
|
36
|
+
return result.toNumber();
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Subtracts multiple numbers with high precision using Big.js
|
|
40
|
+
* @param numbers - Array of numbers where the first is subtracted by all others
|
|
41
|
+
* @returns The subtraction result as a number
|
|
42
|
+
*/
|
|
43
|
+
function Subtract(...numbers) {
|
|
44
|
+
// Convert potential null/undefined values to numbers
|
|
45
|
+
numbers = numbers.map(util_js_1.GetNumber);
|
|
46
|
+
if (numbers.length === 0)
|
|
47
|
+
return 0;
|
|
48
|
+
// Initialize result with the first number
|
|
49
|
+
let result = new big_js_1.default(numbers[0]);
|
|
50
|
+
// Subtract each subsequent number from the result using a for loop
|
|
51
|
+
for (let i = 1; i < numbers.length; i++) {
|
|
52
|
+
const bigNumber = new big_js_1.default(numbers[i]);
|
|
53
|
+
result = result.minus(bigNumber);
|
|
54
|
+
}
|
|
55
|
+
// Convert back to JavaScript number type
|
|
56
|
+
return result.toNumber();
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Multiplies multiple numbers with high precision using Big.js
|
|
60
|
+
* @param numbers - Array of numbers to multiply
|
|
61
|
+
* @returns The product as a number
|
|
62
|
+
*/
|
|
63
|
+
function Multiply(...numbers) {
|
|
64
|
+
// Convert potential null/undefined values to numbers
|
|
65
|
+
numbers = numbers.map(util_js_1.GetNumber);
|
|
66
|
+
if (numbers.length === 0)
|
|
67
|
+
return 0;
|
|
68
|
+
if (numbers.length === 1)
|
|
69
|
+
return numbers[0];
|
|
70
|
+
// Initialize result with the first number
|
|
71
|
+
let result = new big_js_1.default(numbers[0]);
|
|
72
|
+
// Multiply each subsequent number with the result using a for loop
|
|
73
|
+
for (let i = 1; i < numbers.length; i++) {
|
|
74
|
+
const bigNumber = new big_js_1.default(numbers[i]);
|
|
75
|
+
result = result.mul(bigNumber);
|
|
76
|
+
}
|
|
77
|
+
// Convert back to JavaScript number type
|
|
78
|
+
return result.toNumber();
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Divides multiple numbers with high precision using Big.js
|
|
82
|
+
* @param numbers - Array of numbers where the first is divided by all others
|
|
83
|
+
* @returns The division result as a number
|
|
84
|
+
*/
|
|
85
|
+
function Divide(...numbers) {
|
|
86
|
+
// Convert potential null/undefined values to numbers
|
|
87
|
+
numbers = numbers.map(util_js_1.GetNumber);
|
|
88
|
+
if (numbers.length === 0)
|
|
89
|
+
return 0;
|
|
90
|
+
if (numbers.length === 1)
|
|
91
|
+
return numbers[0];
|
|
92
|
+
// Initialize result with the first number
|
|
93
|
+
let result = new big_js_1.default(numbers[0]);
|
|
94
|
+
// Divide the result by each subsequent number using a for loop
|
|
95
|
+
for (let i = 1; i < numbers.length; i++) {
|
|
96
|
+
// Check for division by zero
|
|
97
|
+
if (numbers[i] === 0) {
|
|
98
|
+
throw new Error('Division by zero is not allowed');
|
|
99
|
+
}
|
|
100
|
+
const bigNumber = new big_js_1.default(numbers[i]);
|
|
101
|
+
result = result.div(bigNumber);
|
|
102
|
+
}
|
|
103
|
+
// Convert back to JavaScript number type
|
|
104
|
+
return result.toNumber();
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Calculates discounted or marked-up price based on a percentage
|
|
108
|
+
* @param originalPrice - The starting price
|
|
109
|
+
* @param discountPercentage - Percentage to apply (discount or markup)
|
|
110
|
+
* @param markUp - When true, adds the percentage; when false, subtracts it
|
|
111
|
+
* @returns The final price after discount/markup as a number
|
|
112
|
+
*/
|
|
113
|
+
function CalcDiscPrice(originalPrice, discountPercentage, markUp = false) {
|
|
114
|
+
console.log("DiscountedPrice");
|
|
115
|
+
console.log(originalPrice);
|
|
116
|
+
console.log(discountPercentage);
|
|
117
|
+
// Convert inputs to Big.js objects for precision
|
|
118
|
+
const price = new big_js_1.default((0, util_js_1.GetNumber)(originalPrice));
|
|
119
|
+
const percentage = new big_js_1.default((0, util_js_1.GetNumber)(discountPercentage)).div(100);
|
|
120
|
+
// Calculate the amount to add or subtract
|
|
121
|
+
const discountAmount = price.mul(percentage);
|
|
122
|
+
console.log(discountAmount.toNumber());
|
|
123
|
+
console.log(markUp);
|
|
124
|
+
// Calculate final price directly with Big.js
|
|
125
|
+
let result;
|
|
126
|
+
if (markUp) {
|
|
127
|
+
// Perform markup calculation (add the calculated amount)
|
|
128
|
+
result = price.plus(discountAmount);
|
|
129
|
+
}
|
|
130
|
+
else {
|
|
131
|
+
// Perform discount calculation (subtract the calculated amount)
|
|
132
|
+
result = price.minus(discountAmount);
|
|
133
|
+
}
|
|
134
|
+
const finalPrice = result.toNumber();
|
|
135
|
+
console.log(finalPrice);
|
|
136
|
+
return finalPrice;
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Calculates a price with markup applied
|
|
140
|
+
* @param originalPrice - The starting price
|
|
141
|
+
* @param markupPercentage - Percentage to mark up by
|
|
142
|
+
* @returns The final marked-up price as a number
|
|
143
|
+
*/
|
|
144
|
+
function CalcMarkup(originalPrice, markupPercentage) {
|
|
145
|
+
// Convert inputs to Big.js objects for precision
|
|
146
|
+
const price = new big_js_1.default((0, util_js_1.GetNumber)(originalPrice));
|
|
147
|
+
const percentage = new big_js_1.default((0, util_js_1.GetNumber)(markupPercentage)).div(100);
|
|
148
|
+
// Calculate markup amount based on percentage of original price
|
|
149
|
+
const markupAmount = price.mul(percentage);
|
|
150
|
+
// Add markup amount to original price
|
|
151
|
+
const result = price.plus(markupAmount);
|
|
152
|
+
return result.toNumber();
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Calculates a price with markdown (discount) applied
|
|
156
|
+
* @param originalPrice - The starting price
|
|
157
|
+
* @param markdownPercentage - Percentage to mark down by
|
|
158
|
+
* @returns The final marked-down price as a number
|
|
159
|
+
*/
|
|
160
|
+
function CalcMarkdown(originalPrice, markdownPercentage) {
|
|
161
|
+
// Convert inputs to Big.js objects for precision
|
|
162
|
+
const price = new big_js_1.default((0, util_js_1.GetNumber)(originalPrice));
|
|
163
|
+
const percentage = new big_js_1.default((0, util_js_1.GetNumber)(markdownPercentage)).div(100);
|
|
164
|
+
// Calculate markdown amount based on percentage of original price
|
|
165
|
+
const markdownAmount = price.mul(percentage);
|
|
166
|
+
// Subtract markdown amount from original price
|
|
167
|
+
const result = price.minus(markdownAmount);
|
|
168
|
+
return result.toNumber();
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Calculates the margin value as a percentage based on price and cost
|
|
172
|
+
* @param price - The selling price of the item
|
|
173
|
+
* @param cost - The cost of the item
|
|
174
|
+
* @returns The margin value as a percentage
|
|
175
|
+
*/
|
|
176
|
+
function GetMarginValue(price, cost) {
|
|
177
|
+
// Ensure inputs are valid numbers using GetNumber utility
|
|
178
|
+
const validPrice = (0, util_js_1.GetNumber)(price);
|
|
179
|
+
const validCost = (0, util_js_1.GetNumber)(cost);
|
|
180
|
+
// Calculate margin percentage: ((price - cost) / price) * 100
|
|
181
|
+
const margin = Multiply(Divide(Subtract(validPrice, validCost), validPrice), 100);
|
|
182
|
+
// Return the calculated margin
|
|
183
|
+
return margin;
|
|
184
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GetNumber = GetNumber;
|
|
4
|
+
exports.IsNull = IsNull;
|
|
5
|
+
exports.IsNotNull = IsNotNull;
|
|
6
|
+
function GetNumber(value, defaultValue = 0) {
|
|
7
|
+
return (value == undefined || value == null || isNaN(value)) ? defaultValue : Number(value);
|
|
8
|
+
}
|
|
9
|
+
function IsNull(value) {
|
|
10
|
+
// return value === null || typeof value === 'undefined';
|
|
11
|
+
return value === null || value === undefined;
|
|
12
|
+
}
|
|
13
|
+
function IsNotNull(value) {
|
|
14
|
+
return !IsNull(value);
|
|
15
|
+
}
|
package/dist/utils/tr-utils.js
CHANGED
|
@@ -1,18 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.TrUtils = void 0;
|
|
4
|
-
exports.IsNull = IsNull;
|
|
5
|
-
exports.IsNotNull = IsNotNull;
|
|
6
4
|
// import { HttpClient } from '@angular/common/http';
|
|
7
5
|
const enums_1 = require("../enums/enums");
|
|
8
6
|
var deepEqual = require('deep-equal');
|
|
9
7
|
// import { LaborStatusEnum } from '../enums/enums';
|
|
10
|
-
function IsNull(Value) {
|
|
11
|
-
return Value === null || typeof Value === 'undefined';
|
|
12
|
-
}
|
|
13
|
-
function IsNotNull(Value) {
|
|
14
|
-
return Value !== null && typeof Value !== 'undefined';
|
|
15
|
-
}
|
|
16
8
|
class TrUtils {
|
|
17
9
|
static IsNull(Value) {
|
|
18
10
|
return Value === null || typeof Value === 'undefined';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "shareneus",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.36",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
"author": "",
|
|
12
12
|
"license": "ISC",
|
|
13
13
|
"devDependencies": {
|
|
14
|
+
"@types/big.js": "^6.2.2",
|
|
14
15
|
"@types/node": "^20.14.11",
|
|
15
16
|
"typescript": "^5.5.4"
|
|
16
17
|
},
|
|
@@ -1,177 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.PricelistItemFinalPriceService = void 0;
|
|
4
|
-
const aggregation_1 = require("../aggregation/aggregation");
|
|
5
|
-
const tr_utils_1 = require("../utils/tr-utils");
|
|
6
|
-
class PricelistItemFinalPriceService {
|
|
7
|
-
static GetItemPriceForPriceList(item, priceList, includeMargin) {
|
|
8
|
-
let salePricesByPriceListId = [];
|
|
9
|
-
if ((0, tr_utils_1.IsNotNull)(item.SalePrices) && item.SalePrices.length > 0) {
|
|
10
|
-
salePricesByPriceListId = item.SalePrices.filter((price) => priceList._id.toString() == price.PrListId.toString());
|
|
11
|
-
}
|
|
12
|
-
if (salePricesByPriceListId.length > 0) {
|
|
13
|
-
item.SalePrices = salePricesByPriceListId;
|
|
14
|
-
if (item.Track == 'TR' || item.Track == 'SN') {
|
|
15
|
-
item.Sale["MRP"] = item.Sale.Price;
|
|
16
|
-
if ((0, tr_utils_1.IsNotNull)(item.SalePrices[0].Price) && (0, tr_utils_1.IsNotNull)(item.SalePrices[0].Disc)) {
|
|
17
|
-
const calculatedPrice = this.CalcDiscPrice(item.SalePrices[0].Price, item.SalePrices[0].Disc);
|
|
18
|
-
item.Sale.Price = this.applyRounding(calculatedPrice, priceList);
|
|
19
|
-
}
|
|
20
|
-
else if ((0, tr_utils_1.IsNotNull)(item.SalePrices[0].Price) && (0, tr_utils_1.IsNull)(item.SalePrices[0].Disc)) {
|
|
21
|
-
item.Sale.Price = this.applyRounding(item.SalePrices[0].Price, priceList);
|
|
22
|
-
}
|
|
23
|
-
else if ((0, tr_utils_1.IsNull)(item.SalePrices[0].Price) && (0, tr_utils_1.IsNotNull)(item.SalePrices[0].Disc)) {
|
|
24
|
-
const calculatedPrice = this.CalcDiscPrice(item.Sale.Price, item.SalePrices[0].Disc);
|
|
25
|
-
item.Sale.Price = this.applyRounding(calculatedPrice, priceList);
|
|
26
|
-
}
|
|
27
|
-
if (includeMargin) {
|
|
28
|
-
item.Margin = this.GetMarginValue(item.Sale.Price, item.Pur.Cost);
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
else if (item.Track == 'BN') {
|
|
32
|
-
for (let index = 0; index < item.Batches.length; index++) {
|
|
33
|
-
const element = item.Batches[index];
|
|
34
|
-
let batchSalePrice = item.SalePrices.filter((batch) => priceList._id.toString() == batch.PrListId.toString() && element.BN == batch.BN);
|
|
35
|
-
if (batchSalePrice.length == 0) {
|
|
36
|
-
batchSalePrice = item.SalePrices.filter((batch) => priceList._id.toString() == batch.PrListId.toString() && batch.BN == null);
|
|
37
|
-
}
|
|
38
|
-
element.MRP = element.Price;
|
|
39
|
-
if (batchSalePrice.length > 0) {
|
|
40
|
-
if ((0, tr_utils_1.IsNotNull)(batchSalePrice[0].Price) && (0, tr_utils_1.IsNotNull)(batchSalePrice[0].Disc)) {
|
|
41
|
-
const calculatedPrice = this.CalcDiscPrice(batchSalePrice[0].Price, batchSalePrice[0].Disc);
|
|
42
|
-
element.Price = this.applyRounding(calculatedPrice, priceList);
|
|
43
|
-
}
|
|
44
|
-
else if ((0, tr_utils_1.IsNotNull)(batchSalePrice[0].Price) && (0, tr_utils_1.IsNull)(batchSalePrice[0].Disc)) {
|
|
45
|
-
element.Price = this.applyRounding(batchSalePrice[0].Price, priceList);
|
|
46
|
-
}
|
|
47
|
-
else if ((0, tr_utils_1.IsNull)(batchSalePrice[0].Price) && (0, tr_utils_1.IsNotNull)(batchSalePrice[0].Disc)) {
|
|
48
|
-
const calculatedPrice = this.CalcDiscPrice(element.Price, batchSalePrice[0].Disc);
|
|
49
|
-
element.Price = this.applyRounding(calculatedPrice, priceList);
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
if (includeMargin) {
|
|
53
|
-
element.Margin = this.GetMarginValue(element.Price, element.Cost);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
return item;
|
|
58
|
-
}
|
|
59
|
-
return this.calculatePriceBasedOnPriceList(item, priceList, includeMargin);
|
|
60
|
-
}
|
|
61
|
-
static calculatePriceBasedOnPriceList(item, priceList, includeMargin) {
|
|
62
|
-
var _a, _b;
|
|
63
|
-
if (priceList != null) {
|
|
64
|
-
if (priceList.PrCalc == "FIXED") {
|
|
65
|
-
if (priceList.Fixed && (0, tr_utils_1.IsNotNull)(priceList.Fixed.Price)) {
|
|
66
|
-
const fixedPrice = priceList.Fixed.Price;
|
|
67
|
-
if (item.Track == 'TR' || item.Track == 'SN') {
|
|
68
|
-
item.Sale["MRP"] = item.Sale.Price;
|
|
69
|
-
item.Sale.Price = this.applyRounding(fixedPrice, priceList);
|
|
70
|
-
if (includeMargin) {
|
|
71
|
-
item.Margin = this.GetMarginValue(item.Sale.Price, item.Pur.Cost);
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
else if (item.Track == 'BN') {
|
|
75
|
-
for (let batch of item.Batches) {
|
|
76
|
-
batch.MRP = batch.Price;
|
|
77
|
-
batch.Price = this.applyRounding(fixedPrice, priceList);
|
|
78
|
-
if (includeMargin) {
|
|
79
|
-
batch.Margin = this.GetMarginValue(batch.Price, batch.Cost);
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
else if (priceList.PrCalc == "DISC") {
|
|
86
|
-
const calcDisc = (_a = priceList.CalcDisc) !== null && _a !== void 0 ? _a : {};
|
|
87
|
-
let discPerc = calcDisc.Perc || 0;
|
|
88
|
-
let markUp = (_b = calcDisc.Mark) !== null && _b !== void 0 ? _b : false;
|
|
89
|
-
if (priceList.BasedOn == "SP") {
|
|
90
|
-
if (item.Track == 'TR' || item.Track == 'SN') {
|
|
91
|
-
item.Sale["MRP"] = item.Sale.Price;
|
|
92
|
-
const calculatedPrice = this.CalcDiscPrice(item.Sale.Price, discPerc, markUp);
|
|
93
|
-
item.Sale.Price = this.applyRounding(calculatedPrice, priceList);
|
|
94
|
-
if (includeMargin) {
|
|
95
|
-
item.Margin = this.GetMarginValue(item.Sale.Price, item.Pur.Cost);
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
else if (item.Track == 'BN') {
|
|
99
|
-
for (let batch of item.Batches) {
|
|
100
|
-
batch.MRP = batch.Price;
|
|
101
|
-
const calculatedPrice = this.CalcDiscPrice(batch.Price, discPerc, markUp);
|
|
102
|
-
batch.Price = this.applyRounding(calculatedPrice, priceList);
|
|
103
|
-
if (includeMargin) {
|
|
104
|
-
batch.Margin = this.GetMarginValue(batch.Price, batch.Cost);
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
else if (priceList.BasedOn == "PC") {
|
|
110
|
-
if (item.Track == 'TR' || item.Track == 'SN') {
|
|
111
|
-
item.Sale["MRP"] = item.Sale.Price;
|
|
112
|
-
if ((0, tr_utils_1.IsNotNull)(item.Pur) && (0, tr_utils_1.IsNotNull)(item.Pur.Cost)) {
|
|
113
|
-
const calculatedPrice = this.CalcDiscPrice(item.Pur.Cost, discPerc, markUp);
|
|
114
|
-
item.Sale.Price = this.applyRounding(calculatedPrice, priceList);
|
|
115
|
-
if (includeMargin) {
|
|
116
|
-
item.Margin = this.GetMarginValue(item.Sale.Price, item.Pur.Cost);
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
else if (item.Track == 'BN') {
|
|
121
|
-
for (let batch of item.Batches) {
|
|
122
|
-
batch.MRP = batch.Price;
|
|
123
|
-
if ((0, tr_utils_1.IsNotNull)(batch.Cost)) {
|
|
124
|
-
const calculatedPrice = this.CalcDiscPrice(batch.Cost, discPerc, markUp);
|
|
125
|
-
batch.Price = this.applyRounding(calculatedPrice, priceList);
|
|
126
|
-
if (includeMargin) {
|
|
127
|
-
batch.Margin = this.GetMarginValue(batch.Price, batch.Cost);
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
return item;
|
|
136
|
-
}
|
|
137
|
-
static applyRounding(price, priceList) {
|
|
138
|
-
if (!priceList || !priceList.Round)
|
|
139
|
-
return price;
|
|
140
|
-
switch (priceList.Round) {
|
|
141
|
-
case "-1":
|
|
142
|
-
return price;
|
|
143
|
-
case "0":
|
|
144
|
-
return Math.round(price);
|
|
145
|
-
case "0.99":
|
|
146
|
-
return Math.floor(price) + 0.99;
|
|
147
|
-
case "0.50":
|
|
148
|
-
return Math.round(price * 2) / 2;
|
|
149
|
-
case "0.49":
|
|
150
|
-
return Math.floor(price) + 0.49;
|
|
151
|
-
case "Dec":
|
|
152
|
-
if ((0, tr_utils_1.IsNotNull)(priceList.Deci)) {
|
|
153
|
-
const factor = Math.pow(10, priceList.Deci);
|
|
154
|
-
return Math.round(price * factor) / factor;
|
|
155
|
-
}
|
|
156
|
-
return price;
|
|
157
|
-
default:
|
|
158
|
-
return price;
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
static CalcDiscPrice(Price, Disc, MarkUp = false) {
|
|
162
|
-
let PriceValue = 0;
|
|
163
|
-
if (MarkUp) {
|
|
164
|
-
PriceValue = (0, aggregation_1.addition)(Price, (0, aggregation_1.division)((0, aggregation_1.multiply)(Price, Disc), 100));
|
|
165
|
-
}
|
|
166
|
-
else {
|
|
167
|
-
PriceValue = (0, aggregation_1.subtraction)(Price, (0, aggregation_1.division)((0, aggregation_1.multiply)(Price, Disc), 100));
|
|
168
|
-
}
|
|
169
|
-
return PriceValue;
|
|
170
|
-
}
|
|
171
|
-
static GetMarginValue(price, cost) {
|
|
172
|
-
let Margin = 0;
|
|
173
|
-
Margin = (0, aggregation_1.multiply)((0, aggregation_1.division)((0, aggregation_1.subtraction)(price, cost), price), 100);
|
|
174
|
-
return Margin;
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
exports.PricelistItemFinalPriceService = PricelistItemFinalPriceService;
|