@managesome/eposmatic-toolkit 0.4.82 → 0.4.84
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/esm/helpers/order/generate-warehouse-purchase-order.js +90 -0
- package/esm/helpers/store/common-tenant-purchase-order-actions.js +18 -0
- package/esm/helpers/store/common-warehouse-purchase-order-actions.js +18 -0
- package/esm/helpers/store/tenant-purchase-orders-cart-actions.js +36 -0
- package/esm/helpers/store/warehouse-purchase-orders-cart-actions.js +30 -0
- package/esm/schemas/models/tenant_purchase_orders.js +19 -0
- package/esm/schemas/models/tenants.js +8 -0
- package/esm/schemas/models/warehouse_purchase_orders.js +72 -0
- package/esm/schemas/models/warehouses.js +8 -0
- package/lib/helpers/order/generate-warehouse-purchase-order.js +90 -0
- package/lib/helpers/store/common-tenant-purchase-order-actions.js +18 -0
- package/lib/helpers/store/common-warehouse-purchase-order-actions.js +18 -0
- package/lib/helpers/store/tenant-purchase-orders-cart-actions.js +36 -0
- package/lib/helpers/store/warehouse-purchase-orders-cart-actions.d.ts +8 -0
- package/lib/helpers/store/warehouse-purchase-orders-cart-actions.js +30 -0
- package/lib/schemas/models/tenant_purchase_orders.d.ts +96 -0
- package/lib/schemas/models/tenant_purchase_orders.js +19 -0
- package/lib/schemas/models/tenants.d.ts +6 -0
- package/lib/schemas/models/tenants.js +8 -0
- package/lib/schemas/models/warehouse_purchase_orders.d.ts +96 -0
- package/lib/schemas/models/warehouse_purchase_orders.js +72 -0
- package/lib/schemas/models/warehouses.d.ts +6 -0
- package/lib/schemas/models/warehouses.js +8 -0
- package/lib/schemas/types/tenant_purchase_orders.d.ts +8 -0
- package/lib/schemas/types/tenants.d.ts +2 -0
- package/lib/schemas/types/warehouse_purchase_orders.d.ts +8 -0
- package/lib/schemas/types/warehouses.d.ts +2 -0
- package/package.json +1 -1
|
@@ -20,6 +20,10 @@ function getCommonOptionalBoolFieldsPurchaseOrderIteration(order, partial) {
|
|
|
20
20
|
is_gst_inclusive: order.is_gst_inclusive || defaultValue,
|
|
21
21
|
exclude_discount_from_gst: order.exclude_discount_from_gst || defaultValue,
|
|
22
22
|
is_gst_percentage: order.is_gst_percentage ?? (partial ? undefined : true),
|
|
23
|
+
is_labor_charges_percentage: order.is_labor_charges_percentage ?? defaultValue,
|
|
24
|
+
is_labor_charges_taxable: order.is_labor_charges_taxable || defaultValue,
|
|
25
|
+
is_freight_charges_percentage: order.is_freight_charges_percentage ?? defaultValue,
|
|
26
|
+
is_freight_charges_taxable: order.is_freight_charges_taxable || defaultValue,
|
|
23
27
|
};
|
|
24
28
|
}
|
|
25
29
|
function getCommonOptionalNumFieldsPurchaseOrderIteration(order, partial) {
|
|
@@ -28,6 +32,10 @@ function getCommonOptionalNumFieldsPurchaseOrderIteration(order, partial) {
|
|
|
28
32
|
gst: order.gst || defaultValue,
|
|
29
33
|
gst_amount: order.gst_amount || defaultValue,
|
|
30
34
|
total_discount_applied: order.total_discount_applied || defaultValue,
|
|
35
|
+
labor_charges: order.labor_charges || defaultValue,
|
|
36
|
+
labor_charges_amount: order.labor_charges_amount || defaultValue,
|
|
37
|
+
freight_charges: order.freight_charges || defaultValue,
|
|
38
|
+
freight_charges_amount: order.freight_charges_amount || defaultValue,
|
|
31
39
|
};
|
|
32
40
|
}
|
|
33
41
|
export function generateWarehousePurchaseOrderIteration(order, partial = true, skipItemMetadata) {
|
|
@@ -111,6 +119,40 @@ export function generateWarehousePurchaseOrderOnCreate(order, withIterations) {
|
|
|
111
119
|
delete newOrder.is_gst_inclusive;
|
|
112
120
|
}
|
|
113
121
|
}
|
|
122
|
+
if (!newOrder.labor_charges) {
|
|
123
|
+
delete newOrder.labor_charges;
|
|
124
|
+
delete newOrder.labor_charges_amount;
|
|
125
|
+
delete newOrder.is_labor_charges_percentage;
|
|
126
|
+
delete newOrder.is_labor_charges_taxable;
|
|
127
|
+
}
|
|
128
|
+
else {
|
|
129
|
+
if (newOrder.labor_charges_amount === 0) {
|
|
130
|
+
delete newOrder.labor_charges_amount;
|
|
131
|
+
}
|
|
132
|
+
if (newOrder.is_labor_charges_percentage === false) {
|
|
133
|
+
delete newOrder.is_labor_charges_percentage;
|
|
134
|
+
}
|
|
135
|
+
if (newOrder.is_labor_charges_taxable === false) {
|
|
136
|
+
delete newOrder.is_labor_charges_taxable;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
if (!newOrder.freight_charges) {
|
|
140
|
+
delete newOrder.freight_charges;
|
|
141
|
+
delete newOrder.freight_charges_amount;
|
|
142
|
+
delete newOrder.is_freight_charges_percentage;
|
|
143
|
+
delete newOrder.is_freight_charges_taxable;
|
|
144
|
+
}
|
|
145
|
+
else {
|
|
146
|
+
if (newOrder.freight_charges_amount === 0) {
|
|
147
|
+
delete newOrder.freight_charges_amount;
|
|
148
|
+
}
|
|
149
|
+
if (newOrder.is_freight_charges_percentage === false) {
|
|
150
|
+
delete newOrder.is_freight_charges_percentage;
|
|
151
|
+
}
|
|
152
|
+
if (newOrder.is_freight_charges_taxable === false) {
|
|
153
|
+
delete newOrder.is_freight_charges_taxable;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
114
156
|
if (newOrder.payments?.some((payment) => payment.payment_type === PAYMENT_TYPE_ENUM.PAY_LATER && payment.payment_status === PAYMENT_STATUS_ENUM.PENDING)) {
|
|
115
157
|
newOrder.deferred_settlement = true;
|
|
116
158
|
}
|
|
@@ -177,6 +219,54 @@ export function generateWarehousePurchaseOrderOnUpdate(partialUpdatedOrder) {
|
|
|
177
219
|
unset['is_gst_inclusive'] = '';
|
|
178
220
|
}
|
|
179
221
|
}
|
|
222
|
+
if (set.labor_charges === 0) {
|
|
223
|
+
delete set.labor_charges;
|
|
224
|
+
delete set.labor_charges_amount;
|
|
225
|
+
delete set.is_labor_charges_percentage;
|
|
226
|
+
delete set.is_labor_charges_taxable;
|
|
227
|
+
unset['labor_charges'] = '';
|
|
228
|
+
unset['labor_charges_amount'] = '';
|
|
229
|
+
unset['is_labor_charges_percentage'] = '';
|
|
230
|
+
unset['is_labor_charges_taxable'] = '';
|
|
231
|
+
}
|
|
232
|
+
else {
|
|
233
|
+
if (set.labor_charges_amount === 0) {
|
|
234
|
+
delete set.labor_charges_amount;
|
|
235
|
+
unset['labor_charges_amount'] = '';
|
|
236
|
+
}
|
|
237
|
+
if (set.is_labor_charges_percentage === false) {
|
|
238
|
+
delete set.is_labor_charges_percentage;
|
|
239
|
+
unset['is_labor_charges_percentage'] = '';
|
|
240
|
+
}
|
|
241
|
+
if (set.is_labor_charges_taxable === false) {
|
|
242
|
+
delete set.is_labor_charges_taxable;
|
|
243
|
+
unset['is_labor_charges_taxable'] = '';
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
if (set.freight_charges === 0) {
|
|
247
|
+
delete set.freight_charges;
|
|
248
|
+
delete set.freight_charges_amount;
|
|
249
|
+
delete set.is_freight_charges_percentage;
|
|
250
|
+
delete set.is_freight_charges_taxable;
|
|
251
|
+
unset['freight_charges'] = '';
|
|
252
|
+
unset['freight_charges_amount'] = '';
|
|
253
|
+
unset['is_freight_charges_percentage'] = '';
|
|
254
|
+
unset['is_freight_charges_taxable'] = '';
|
|
255
|
+
}
|
|
256
|
+
else {
|
|
257
|
+
if (set.freight_charges_amount === 0) {
|
|
258
|
+
delete set.freight_charges_amount;
|
|
259
|
+
unset['freight_charges_amount'] = '';
|
|
260
|
+
}
|
|
261
|
+
if (set.is_freight_charges_percentage === false) {
|
|
262
|
+
delete set.is_freight_charges_percentage;
|
|
263
|
+
unset['is_freight_charges_percentage'] = '';
|
|
264
|
+
}
|
|
265
|
+
if (set.is_freight_charges_taxable === false) {
|
|
266
|
+
delete set.is_freight_charges_taxable;
|
|
267
|
+
unset['is_freight_charges_taxable'] = '';
|
|
268
|
+
}
|
|
269
|
+
}
|
|
180
270
|
if (set.payments != null) {
|
|
181
271
|
if (set.payments.some((payment) => payment.payment_type === PAYMENT_TYPE_ENUM.PAY_LATER &&
|
|
182
272
|
payment.payment_status === PAYMENT_STATUS_ENUM.PENDING)) {
|
|
@@ -104,6 +104,16 @@ export function getTenantPurchaseOrderWithPrice(order, writeable) {
|
|
|
104
104
|
...(order.total_discount_applied != null
|
|
105
105
|
? { total_discount_applied: convertToPrice(order.total_discount_applied) }
|
|
106
106
|
: {}),
|
|
107
|
+
...(order.labor_charges != null && order.is_labor_charges_percentage !== true
|
|
108
|
+
? { labor_charges: convertToPrice(order.labor_charges) }
|
|
109
|
+
: {}),
|
|
110
|
+
...(order.labor_charges_amount != null ? { labor_charges_amount: convertToPrice(order.labor_charges_amount) } : {}),
|
|
111
|
+
...(order.freight_charges != null && order.is_freight_charges_percentage !== true
|
|
112
|
+
? { freight_charges: convertToPrice(order.freight_charges) }
|
|
113
|
+
: {}),
|
|
114
|
+
...(order.freight_charges_amount != null
|
|
115
|
+
? { freight_charges_amount: convertToPrice(order.freight_charges_amount) }
|
|
116
|
+
: {}),
|
|
107
117
|
};
|
|
108
118
|
return payload;
|
|
109
119
|
}
|
|
@@ -143,6 +153,10 @@ function getCommonOptionalBoolFieldsTenantPurchaseOrder(order, partial) {
|
|
|
143
153
|
is_reopened: order['is_reopened'] || defaultValue,
|
|
144
154
|
exclude_discount_from_gst: order['exclude_discount_from_gst'] || defaultValue,
|
|
145
155
|
is_gst_percentage: order['is_gst_percentage'] ?? (partial ? undefined : true),
|
|
156
|
+
is_labor_charges_percentage: order['is_labor_charges_percentage'] ?? defaultValue,
|
|
157
|
+
is_labor_charges_taxable: order['is_labor_charges_taxable'] || defaultValue,
|
|
158
|
+
is_freight_charges_percentage: order['is_freight_charges_percentage'] ?? defaultValue,
|
|
159
|
+
is_freight_charges_taxable: order['is_freight_charges_taxable'] || defaultValue,
|
|
146
160
|
};
|
|
147
161
|
}
|
|
148
162
|
function getCommonOptionalNumFieldsTenantPurchaseOrder(order, partial) {
|
|
@@ -151,6 +165,10 @@ function getCommonOptionalNumFieldsTenantPurchaseOrder(order, partial) {
|
|
|
151
165
|
gst: order['gst'] || defaultValue,
|
|
152
166
|
gst_amount: order['gst_amount'] || defaultValue,
|
|
153
167
|
total_discount_applied: order['total_discount_applied'] || defaultValue,
|
|
168
|
+
labor_charges: order['labor_charges'] || defaultValue,
|
|
169
|
+
labor_charges_amount: order['labor_charges_amount'] || defaultValue,
|
|
170
|
+
freight_charges: order['freight_charges'] || defaultValue,
|
|
171
|
+
freight_charges_amount: order['freight_charges_amount'] || defaultValue,
|
|
154
172
|
};
|
|
155
173
|
}
|
|
156
174
|
export function getTenantPurchaseOrderWithAllFields(order, skipItemMetadata) {
|
|
@@ -108,6 +108,16 @@ export function getWarehousePurchaseOrderWithPrice(order, writeable) {
|
|
|
108
108
|
...(order.total_discount_applied != null
|
|
109
109
|
? { total_discount_applied: convertToPrice(order.total_discount_applied) }
|
|
110
110
|
: {}),
|
|
111
|
+
...(order.labor_charges != null && order.is_labor_charges_percentage !== true
|
|
112
|
+
? { labor_charges: convertToPrice(order.labor_charges) }
|
|
113
|
+
: {}),
|
|
114
|
+
...(order.labor_charges_amount != null ? { labor_charges_amount: convertToPrice(order.labor_charges_amount) } : {}),
|
|
115
|
+
...(order.freight_charges != null && order.is_freight_charges_percentage !== true
|
|
116
|
+
? { freight_charges: convertToPrice(order.freight_charges) }
|
|
117
|
+
: {}),
|
|
118
|
+
...(order.freight_charges_amount != null
|
|
119
|
+
? { freight_charges_amount: convertToPrice(order.freight_charges_amount) }
|
|
120
|
+
: {}),
|
|
111
121
|
};
|
|
112
122
|
return payload;
|
|
113
123
|
}
|
|
@@ -147,6 +157,10 @@ function getCommonOptionalBoolFieldsPurchaseOrder(order, partial) {
|
|
|
147
157
|
is_gst_inclusive: order['is_gst_inclusive'] || defaultValue,
|
|
148
158
|
is_reopened: order['is_reopened'] || defaultValue,
|
|
149
159
|
is_gst_percentage: order['is_gst_percentage'] ?? (partial ? undefined : true),
|
|
160
|
+
is_labor_charges_percentage: order['is_labor_charges_percentage'] ?? defaultValue,
|
|
161
|
+
is_labor_charges_taxable: order['is_labor_charges_taxable'] || defaultValue,
|
|
162
|
+
is_freight_charges_percentage: order['is_freight_charges_percentage'] ?? defaultValue,
|
|
163
|
+
is_freight_charges_taxable: order['is_freight_charges_taxable'] || defaultValue,
|
|
150
164
|
};
|
|
151
165
|
}
|
|
152
166
|
function getCommonOptionalNumFieldsPurchaseOrder(order, partial) {
|
|
@@ -154,6 +168,10 @@ function getCommonOptionalNumFieldsPurchaseOrder(order, partial) {
|
|
|
154
168
|
return {
|
|
155
169
|
gst: order['gst'] || defaultValue,
|
|
156
170
|
gst_amount: order['gst_amount'] || defaultValue,
|
|
171
|
+
labor_charges: order['labor_charges'] || defaultValue,
|
|
172
|
+
labor_charges_amount: order['labor_charges_amount'] || defaultValue,
|
|
173
|
+
freight_charges: order['freight_charges'] || defaultValue,
|
|
174
|
+
freight_charges_amount: order['freight_charges_amount'] || defaultValue,
|
|
157
175
|
};
|
|
158
176
|
}
|
|
159
177
|
export function getWarehousePurchaseOrderWithAllFields(order, skipItemMetadata) {
|
|
@@ -87,6 +87,33 @@ export function calculateCartTenantPurchaseOrderInfoAndSyncData(data, calculateI
|
|
|
87
87
|
if (!applyGSTOnOriginalPrice) {
|
|
88
88
|
grand_total -= total_discount_applied;
|
|
89
89
|
}
|
|
90
|
+
// Order-level charges (labor, freight): entered per PO, either a fixed amount
|
|
91
|
+
// or a percentage of the post-discount items value. The matching
|
|
92
|
+
// `is_*_charges_taxable` flag (snapshot of the tenant setting) decides the
|
|
93
|
+
// placement, exactly like `is_service_fee_taxable` on a POS order: taxable =>
|
|
94
|
+
// added BEFORE GST so the tax applies to it (an inclusive rate treats it as
|
|
95
|
+
// tax-inclusive); untaxed => added after GST.
|
|
96
|
+
const chargesBase = parseNum(Math.max(0, subtotal - total_discount_applied));
|
|
97
|
+
const getOrderCharge = (value, isPercentage) => {
|
|
98
|
+
const entered = parseNum(Math.max(0, value ?? 0));
|
|
99
|
+
return {
|
|
100
|
+
entered,
|
|
101
|
+
amount: isPercentage ? parseNum(getPercentageAmount(chargesBase, entered)) : entered,
|
|
102
|
+
};
|
|
103
|
+
};
|
|
104
|
+
const labor = getOrderCharge(data.labor_charges, data.is_labor_charges_percentage);
|
|
105
|
+
const freight = getOrderCharge(data.freight_charges, data.is_freight_charges_percentage);
|
|
106
|
+
const labor_charges = labor.entered;
|
|
107
|
+
const labor_charges_amount = labor.amount;
|
|
108
|
+
const freight_charges = freight.entered;
|
|
109
|
+
const freight_charges_amount = freight.amount;
|
|
110
|
+
const isLaborTaxable = data.is_labor_charges_taxable === true;
|
|
111
|
+
const isFreightTaxable = data.is_freight_charges_taxable === true;
|
|
112
|
+
// Taxable charges join the GST base here; untaxed ones are added further down.
|
|
113
|
+
const taxableCharges = (isLaborTaxable ? labor_charges_amount : 0) + (isFreightTaxable ? freight_charges_amount : 0);
|
|
114
|
+
if (taxableCharges > 0) {
|
|
115
|
+
grand_total += taxableCharges;
|
|
116
|
+
}
|
|
90
117
|
let gst_amount = 0;
|
|
91
118
|
const gst = data.gst ?? 0;
|
|
92
119
|
const isGstPercentage = data.is_gst_percentage !== false;
|
|
@@ -112,6 +139,11 @@ export function calculateCartTenantPurchaseOrderInfoAndSyncData(data, calculateI
|
|
|
112
139
|
if (applyGSTOnOriginalPrice) {
|
|
113
140
|
grand_total -= total_discount_applied;
|
|
114
141
|
}
|
|
142
|
+
// Untaxed charges sit outside the GST base, so they are added after the tax.
|
|
143
|
+
const untaxedCharges = (isLaborTaxable ? 0 : labor_charges_amount) + (isFreightTaxable ? 0 : freight_charges_amount);
|
|
144
|
+
if (untaxedCharges > 0) {
|
|
145
|
+
grand_total += untaxedCharges;
|
|
146
|
+
}
|
|
115
147
|
const { cardCharges, amountCollected } = getCardChargesAndAmountCollected(data.payments);
|
|
116
148
|
grand_total += cardCharges;
|
|
117
149
|
grand_total = parseNum(grand_total);
|
|
@@ -168,6 +200,10 @@ export function calculateCartTenantPurchaseOrderInfoAndSyncData(data, calculateI
|
|
|
168
200
|
order_discount_details,
|
|
169
201
|
total_discount_applied,
|
|
170
202
|
gst_amount,
|
|
203
|
+
labor_charges,
|
|
204
|
+
labor_charges_amount,
|
|
205
|
+
freight_charges,
|
|
206
|
+
freight_charges_amount,
|
|
171
207
|
price: parseNum(subtotal),
|
|
172
208
|
grand_total,
|
|
173
209
|
};
|
|
@@ -84,6 +84,27 @@ export function calculateCartWarehousePurchaseOrderInfoAndSyncData(data, calcula
|
|
|
84
84
|
if (!applyGSTOnOriginalPrice) {
|
|
85
85
|
grand_total -= total_discount_applied;
|
|
86
86
|
}
|
|
87
|
+
const postDiscountSubtotal = parseNum(Math.max(0, subtotal - total_discount_applied));
|
|
88
|
+
const getOrderCharge = (value, isPercentage) => {
|
|
89
|
+
const entered = parseNum(Math.max(0, value ?? 0));
|
|
90
|
+
return {
|
|
91
|
+
entered,
|
|
92
|
+
amount: isPercentage ? parseNum(getPercentageAmount(postDiscountSubtotal, entered)) : entered,
|
|
93
|
+
};
|
|
94
|
+
};
|
|
95
|
+
const labor = getOrderCharge(data.labor_charges, data.is_labor_charges_percentage);
|
|
96
|
+
const freight = getOrderCharge(data.freight_charges, data.is_freight_charges_percentage);
|
|
97
|
+
const labor_charges = labor.entered;
|
|
98
|
+
const labor_charges_amount = labor.amount;
|
|
99
|
+
const freight_charges = freight.entered;
|
|
100
|
+
const freight_charges_amount = freight.amount;
|
|
101
|
+
const isLaborTaxable = data.is_labor_charges_taxable === true;
|
|
102
|
+
const isFreightTaxable = data.is_freight_charges_taxable === true;
|
|
103
|
+
// Taxable charges join the GST base here; untaxed ones are added further down.
|
|
104
|
+
const taxableCharges = (isLaborTaxable ? labor_charges_amount : 0) + (isFreightTaxable ? freight_charges_amount : 0);
|
|
105
|
+
if (taxableCharges > 0) {
|
|
106
|
+
grand_total += taxableCharges;
|
|
107
|
+
}
|
|
87
108
|
// GST can be entered as a percentage (default) or as a fixed amount.
|
|
88
109
|
// In both cases `gst_amount` is the computed tax total.
|
|
89
110
|
let gst_amount = 0;
|
|
@@ -115,6 +136,11 @@ export function calculateCartWarehousePurchaseOrderInfoAndSyncData(data, calcula
|
|
|
115
136
|
if (applyGSTOnOriginalPrice) {
|
|
116
137
|
grand_total -= total_discount_applied;
|
|
117
138
|
}
|
|
139
|
+
// Untaxed charges sit outside the GST base, so they are added after the tax.
|
|
140
|
+
const untaxedCharges = (isLaborTaxable ? 0 : labor_charges_amount) + (isFreightTaxable ? 0 : freight_charges_amount);
|
|
141
|
+
if (untaxedCharges > 0) {
|
|
142
|
+
grand_total += untaxedCharges;
|
|
143
|
+
}
|
|
118
144
|
// Add Card Charges to grand_total
|
|
119
145
|
const { cardCharges, amountCollected } = getCardChargesAndAmountCollected(data.payments);
|
|
120
146
|
grand_total += cardCharges;
|
|
@@ -172,6 +198,10 @@ export function calculateCartWarehousePurchaseOrderInfoAndSyncData(data, calcula
|
|
|
172
198
|
order_discount_details,
|
|
173
199
|
total_discount_applied,
|
|
174
200
|
gst_amount,
|
|
201
|
+
labor_charges,
|
|
202
|
+
labor_charges_amount,
|
|
203
|
+
freight_charges,
|
|
204
|
+
freight_charges_amount,
|
|
175
205
|
price: parseNum(subtotal),
|
|
176
206
|
grand_total,
|
|
177
207
|
};
|
|
@@ -93,6 +93,14 @@ const IterationsOrderSchema = new Schema({
|
|
|
93
93
|
gst_amount: { type: Number, min: 0, required: false },
|
|
94
94
|
is_gst_inclusive: { type: Boolean, required: false },
|
|
95
95
|
is_gst_percentage: { type: Boolean, required: false },
|
|
96
|
+
labor_charges: { type: Number, min: 0, required: false },
|
|
97
|
+
labor_charges_amount: { type: Number, min: 0, required: false },
|
|
98
|
+
is_labor_charges_percentage: { type: Boolean, required: false },
|
|
99
|
+
is_labor_charges_taxable: { type: Boolean, required: false },
|
|
100
|
+
freight_charges: { type: Number, min: 0, required: false },
|
|
101
|
+
freight_charges_amount: { type: Number, min: 0, required: false },
|
|
102
|
+
is_freight_charges_percentage: { type: Boolean, required: false },
|
|
103
|
+
is_freight_charges_taxable: { type: Boolean, required: false },
|
|
96
104
|
tax_number: { type: String, default: '' },
|
|
97
105
|
updatedAt: { type: Schema.Types.Date, required: true },
|
|
98
106
|
}, { _id: false, timestamps: false, versionKey: false });
|
|
@@ -134,6 +142,17 @@ export const TenantPurchaseOrderSchema = new Schema({
|
|
|
134
142
|
is_gst_inclusive: { type: Boolean, required: false },
|
|
135
143
|
// true/undefined => `gst` is a percentage, false => `gst` is a fixed amount
|
|
136
144
|
is_gst_percentage: { type: Boolean, required: false },
|
|
145
|
+
labor_charges: { type: Number, min: 0, required: false },
|
|
146
|
+
labor_charges_amount: { type: Number, min: 0, required: false },
|
|
147
|
+
// true => `labor_charges` is a percentage of the post-discount subtotal
|
|
148
|
+
is_labor_charges_percentage: { type: Boolean, required: false },
|
|
149
|
+
// true => the labor charge is inside the GST base (added before GST)
|
|
150
|
+
is_labor_charges_taxable: { type: Boolean, required: false },
|
|
151
|
+
// freight charge, mirrors the labor fields above
|
|
152
|
+
freight_charges: { type: Number, min: 0, required: false },
|
|
153
|
+
freight_charges_amount: { type: Number, min: 0, required: false },
|
|
154
|
+
is_freight_charges_percentage: { type: Boolean, required: false },
|
|
155
|
+
is_freight_charges_taxable: { type: Boolean, required: false },
|
|
137
156
|
is_deleted: { type: Boolean, default: false },
|
|
138
157
|
order_status_updated_at: {
|
|
139
158
|
type: Schema.Types.Date,
|
|
@@ -478,6 +478,14 @@ export const TenantSchema = new Schema({
|
|
|
478
478
|
enum: ALL_GST_TYPES,
|
|
479
479
|
required: false,
|
|
480
480
|
},
|
|
481
|
+
is_labor_charges_taxable: {
|
|
482
|
+
type: Boolean,
|
|
483
|
+
default: false,
|
|
484
|
+
},
|
|
485
|
+
is_freight_charges_taxable: {
|
|
486
|
+
type: Boolean,
|
|
487
|
+
default: false,
|
|
488
|
+
},
|
|
481
489
|
web_design_type: {
|
|
482
490
|
type: String,
|
|
483
491
|
enum: ALL_ONLINE_ORDERING_DESIGN_TYPES,
|
|
@@ -203,6 +203,42 @@ const IterationsOrderSchema = new Schema({
|
|
|
203
203
|
type: Boolean,
|
|
204
204
|
required: false,
|
|
205
205
|
},
|
|
206
|
+
labor_charges: {
|
|
207
|
+
type: Number,
|
|
208
|
+
min: 0,
|
|
209
|
+
required: false,
|
|
210
|
+
},
|
|
211
|
+
labor_charges_amount: {
|
|
212
|
+
type: Number,
|
|
213
|
+
min: 0,
|
|
214
|
+
required: false,
|
|
215
|
+
},
|
|
216
|
+
is_labor_charges_percentage: {
|
|
217
|
+
type: Boolean,
|
|
218
|
+
required: false,
|
|
219
|
+
},
|
|
220
|
+
is_labor_charges_taxable: {
|
|
221
|
+
type: Boolean,
|
|
222
|
+
required: false,
|
|
223
|
+
},
|
|
224
|
+
freight_charges: {
|
|
225
|
+
type: Number,
|
|
226
|
+
min: 0,
|
|
227
|
+
required: false,
|
|
228
|
+
},
|
|
229
|
+
freight_charges_amount: {
|
|
230
|
+
type: Number,
|
|
231
|
+
min: 0,
|
|
232
|
+
required: false,
|
|
233
|
+
},
|
|
234
|
+
is_freight_charges_percentage: {
|
|
235
|
+
type: Boolean,
|
|
236
|
+
required: false,
|
|
237
|
+
},
|
|
238
|
+
is_freight_charges_taxable: {
|
|
239
|
+
type: Boolean,
|
|
240
|
+
required: false,
|
|
241
|
+
},
|
|
206
242
|
tax_number: {
|
|
207
243
|
type: String,
|
|
208
244
|
default: '',
|
|
@@ -336,6 +372,42 @@ export const PurchaseOrderSchema = new Schema({
|
|
|
336
372
|
type: Boolean,
|
|
337
373
|
required: false,
|
|
338
374
|
},
|
|
375
|
+
labor_charges: {
|
|
376
|
+
type: Number,
|
|
377
|
+
min: 0,
|
|
378
|
+
required: false,
|
|
379
|
+
},
|
|
380
|
+
labor_charges_amount: {
|
|
381
|
+
type: Number,
|
|
382
|
+
min: 0,
|
|
383
|
+
required: false,
|
|
384
|
+
},
|
|
385
|
+
is_labor_charges_percentage: {
|
|
386
|
+
type: Boolean,
|
|
387
|
+
required: false,
|
|
388
|
+
},
|
|
389
|
+
is_labor_charges_taxable: {
|
|
390
|
+
type: Boolean,
|
|
391
|
+
required: false,
|
|
392
|
+
},
|
|
393
|
+
freight_charges: {
|
|
394
|
+
type: Number,
|
|
395
|
+
min: 0,
|
|
396
|
+
required: false,
|
|
397
|
+
},
|
|
398
|
+
freight_charges_amount: {
|
|
399
|
+
type: Number,
|
|
400
|
+
min: 0,
|
|
401
|
+
required: false,
|
|
402
|
+
},
|
|
403
|
+
is_freight_charges_percentage: {
|
|
404
|
+
type: Boolean,
|
|
405
|
+
required: false,
|
|
406
|
+
},
|
|
407
|
+
is_freight_charges_taxable: {
|
|
408
|
+
type: Boolean,
|
|
409
|
+
required: false,
|
|
410
|
+
},
|
|
339
411
|
//
|
|
340
412
|
is_deleted: {
|
|
341
413
|
type: Boolean,
|
|
@@ -92,6 +92,14 @@ export const WarehouseSchema = new Schema({
|
|
|
92
92
|
type: Boolean,
|
|
93
93
|
required: false,
|
|
94
94
|
},
|
|
95
|
+
is_labor_charges_taxable: {
|
|
96
|
+
type: Boolean,
|
|
97
|
+
default: false,
|
|
98
|
+
},
|
|
99
|
+
is_freight_charges_taxable: {
|
|
100
|
+
type: Boolean,
|
|
101
|
+
default: false,
|
|
102
|
+
},
|
|
95
103
|
po_card_gst: {
|
|
96
104
|
type: Number,
|
|
97
105
|
default: 0,
|
|
@@ -29,6 +29,10 @@ function getCommonOptionalBoolFieldsPurchaseOrderIteration(order, partial) {
|
|
|
29
29
|
is_gst_inclusive: order.is_gst_inclusive || defaultValue,
|
|
30
30
|
exclude_discount_from_gst: order.exclude_discount_from_gst || defaultValue,
|
|
31
31
|
is_gst_percentage: order.is_gst_percentage ?? (partial ? undefined : true),
|
|
32
|
+
is_labor_charges_percentage: order.is_labor_charges_percentage ?? defaultValue,
|
|
33
|
+
is_labor_charges_taxable: order.is_labor_charges_taxable || defaultValue,
|
|
34
|
+
is_freight_charges_percentage: order.is_freight_charges_percentage ?? defaultValue,
|
|
35
|
+
is_freight_charges_taxable: order.is_freight_charges_taxable || defaultValue,
|
|
32
36
|
};
|
|
33
37
|
}
|
|
34
38
|
function getCommonOptionalNumFieldsPurchaseOrderIteration(order, partial) {
|
|
@@ -37,6 +41,10 @@ function getCommonOptionalNumFieldsPurchaseOrderIteration(order, partial) {
|
|
|
37
41
|
gst: order.gst || defaultValue,
|
|
38
42
|
gst_amount: order.gst_amount || defaultValue,
|
|
39
43
|
total_discount_applied: order.total_discount_applied || defaultValue,
|
|
44
|
+
labor_charges: order.labor_charges || defaultValue,
|
|
45
|
+
labor_charges_amount: order.labor_charges_amount || defaultValue,
|
|
46
|
+
freight_charges: order.freight_charges || defaultValue,
|
|
47
|
+
freight_charges_amount: order.freight_charges_amount || defaultValue,
|
|
40
48
|
};
|
|
41
49
|
}
|
|
42
50
|
function generateWarehousePurchaseOrderIteration(order, partial = true, skipItemMetadata) {
|
|
@@ -120,6 +128,40 @@ function generateWarehousePurchaseOrderOnCreate(order, withIterations) {
|
|
|
120
128
|
delete newOrder.is_gst_inclusive;
|
|
121
129
|
}
|
|
122
130
|
}
|
|
131
|
+
if (!newOrder.labor_charges) {
|
|
132
|
+
delete newOrder.labor_charges;
|
|
133
|
+
delete newOrder.labor_charges_amount;
|
|
134
|
+
delete newOrder.is_labor_charges_percentage;
|
|
135
|
+
delete newOrder.is_labor_charges_taxable;
|
|
136
|
+
}
|
|
137
|
+
else {
|
|
138
|
+
if (newOrder.labor_charges_amount === 0) {
|
|
139
|
+
delete newOrder.labor_charges_amount;
|
|
140
|
+
}
|
|
141
|
+
if (newOrder.is_labor_charges_percentage === false) {
|
|
142
|
+
delete newOrder.is_labor_charges_percentage;
|
|
143
|
+
}
|
|
144
|
+
if (newOrder.is_labor_charges_taxable === false) {
|
|
145
|
+
delete newOrder.is_labor_charges_taxable;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
if (!newOrder.freight_charges) {
|
|
149
|
+
delete newOrder.freight_charges;
|
|
150
|
+
delete newOrder.freight_charges_amount;
|
|
151
|
+
delete newOrder.is_freight_charges_percentage;
|
|
152
|
+
delete newOrder.is_freight_charges_taxable;
|
|
153
|
+
}
|
|
154
|
+
else {
|
|
155
|
+
if (newOrder.freight_charges_amount === 0) {
|
|
156
|
+
delete newOrder.freight_charges_amount;
|
|
157
|
+
}
|
|
158
|
+
if (newOrder.is_freight_charges_percentage === false) {
|
|
159
|
+
delete newOrder.is_freight_charges_percentage;
|
|
160
|
+
}
|
|
161
|
+
if (newOrder.is_freight_charges_taxable === false) {
|
|
162
|
+
delete newOrder.is_freight_charges_taxable;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
123
165
|
if (newOrder.payments?.some((payment) => payment.payment_type === constants_1.PAYMENT_TYPE_ENUM.PAY_LATER && payment.payment_status === constants_1.PAYMENT_STATUS_ENUM.PENDING)) {
|
|
124
166
|
newOrder.deferred_settlement = true;
|
|
125
167
|
}
|
|
@@ -186,6 +228,54 @@ function generateWarehousePurchaseOrderOnUpdate(partialUpdatedOrder) {
|
|
|
186
228
|
unset['is_gst_inclusive'] = '';
|
|
187
229
|
}
|
|
188
230
|
}
|
|
231
|
+
if (set.labor_charges === 0) {
|
|
232
|
+
delete set.labor_charges;
|
|
233
|
+
delete set.labor_charges_amount;
|
|
234
|
+
delete set.is_labor_charges_percentage;
|
|
235
|
+
delete set.is_labor_charges_taxable;
|
|
236
|
+
unset['labor_charges'] = '';
|
|
237
|
+
unset['labor_charges_amount'] = '';
|
|
238
|
+
unset['is_labor_charges_percentage'] = '';
|
|
239
|
+
unset['is_labor_charges_taxable'] = '';
|
|
240
|
+
}
|
|
241
|
+
else {
|
|
242
|
+
if (set.labor_charges_amount === 0) {
|
|
243
|
+
delete set.labor_charges_amount;
|
|
244
|
+
unset['labor_charges_amount'] = '';
|
|
245
|
+
}
|
|
246
|
+
if (set.is_labor_charges_percentage === false) {
|
|
247
|
+
delete set.is_labor_charges_percentage;
|
|
248
|
+
unset['is_labor_charges_percentage'] = '';
|
|
249
|
+
}
|
|
250
|
+
if (set.is_labor_charges_taxable === false) {
|
|
251
|
+
delete set.is_labor_charges_taxable;
|
|
252
|
+
unset['is_labor_charges_taxable'] = '';
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
if (set.freight_charges === 0) {
|
|
256
|
+
delete set.freight_charges;
|
|
257
|
+
delete set.freight_charges_amount;
|
|
258
|
+
delete set.is_freight_charges_percentage;
|
|
259
|
+
delete set.is_freight_charges_taxable;
|
|
260
|
+
unset['freight_charges'] = '';
|
|
261
|
+
unset['freight_charges_amount'] = '';
|
|
262
|
+
unset['is_freight_charges_percentage'] = '';
|
|
263
|
+
unset['is_freight_charges_taxable'] = '';
|
|
264
|
+
}
|
|
265
|
+
else {
|
|
266
|
+
if (set.freight_charges_amount === 0) {
|
|
267
|
+
delete set.freight_charges_amount;
|
|
268
|
+
unset['freight_charges_amount'] = '';
|
|
269
|
+
}
|
|
270
|
+
if (set.is_freight_charges_percentage === false) {
|
|
271
|
+
delete set.is_freight_charges_percentage;
|
|
272
|
+
unset['is_freight_charges_percentage'] = '';
|
|
273
|
+
}
|
|
274
|
+
if (set.is_freight_charges_taxable === false) {
|
|
275
|
+
delete set.is_freight_charges_taxable;
|
|
276
|
+
unset['is_freight_charges_taxable'] = '';
|
|
277
|
+
}
|
|
278
|
+
}
|
|
189
279
|
if (set.payments != null) {
|
|
190
280
|
if (set.payments.some((payment) => payment.payment_type === constants_1.PAYMENT_TYPE_ENUM.PAY_LATER &&
|
|
191
281
|
payment.payment_status === constants_1.PAYMENT_STATUS_ENUM.PENDING)) {
|
|
@@ -121,6 +121,16 @@ function getTenantPurchaseOrderWithPrice(order, writeable) {
|
|
|
121
121
|
...(order.total_discount_applied != null
|
|
122
122
|
? { total_discount_applied: convertToPrice(order.total_discount_applied) }
|
|
123
123
|
: {}),
|
|
124
|
+
...(order.labor_charges != null && order.is_labor_charges_percentage !== true
|
|
125
|
+
? { labor_charges: convertToPrice(order.labor_charges) }
|
|
126
|
+
: {}),
|
|
127
|
+
...(order.labor_charges_amount != null ? { labor_charges_amount: convertToPrice(order.labor_charges_amount) } : {}),
|
|
128
|
+
...(order.freight_charges != null && order.is_freight_charges_percentage !== true
|
|
129
|
+
? { freight_charges: convertToPrice(order.freight_charges) }
|
|
130
|
+
: {}),
|
|
131
|
+
...(order.freight_charges_amount != null
|
|
132
|
+
? { freight_charges_amount: convertToPrice(order.freight_charges_amount) }
|
|
133
|
+
: {}),
|
|
124
134
|
};
|
|
125
135
|
return payload;
|
|
126
136
|
}
|
|
@@ -160,6 +170,10 @@ function getCommonOptionalBoolFieldsTenantPurchaseOrder(order, partial) {
|
|
|
160
170
|
is_reopened: order['is_reopened'] || defaultValue,
|
|
161
171
|
exclude_discount_from_gst: order['exclude_discount_from_gst'] || defaultValue,
|
|
162
172
|
is_gst_percentage: order['is_gst_percentage'] ?? (partial ? undefined : true),
|
|
173
|
+
is_labor_charges_percentage: order['is_labor_charges_percentage'] ?? defaultValue,
|
|
174
|
+
is_labor_charges_taxable: order['is_labor_charges_taxable'] || defaultValue,
|
|
175
|
+
is_freight_charges_percentage: order['is_freight_charges_percentage'] ?? defaultValue,
|
|
176
|
+
is_freight_charges_taxable: order['is_freight_charges_taxable'] || defaultValue,
|
|
163
177
|
};
|
|
164
178
|
}
|
|
165
179
|
function getCommonOptionalNumFieldsTenantPurchaseOrder(order, partial) {
|
|
@@ -168,6 +182,10 @@ function getCommonOptionalNumFieldsTenantPurchaseOrder(order, partial) {
|
|
|
168
182
|
gst: order['gst'] || defaultValue,
|
|
169
183
|
gst_amount: order['gst_amount'] || defaultValue,
|
|
170
184
|
total_discount_applied: order['total_discount_applied'] || defaultValue,
|
|
185
|
+
labor_charges: order['labor_charges'] || defaultValue,
|
|
186
|
+
labor_charges_amount: order['labor_charges_amount'] || defaultValue,
|
|
187
|
+
freight_charges: order['freight_charges'] || defaultValue,
|
|
188
|
+
freight_charges_amount: order['freight_charges_amount'] || defaultValue,
|
|
171
189
|
};
|
|
172
190
|
}
|
|
173
191
|
function getTenantPurchaseOrderWithAllFields(order, skipItemMetadata) {
|
|
@@ -124,6 +124,16 @@ function getWarehousePurchaseOrderWithPrice(order, writeable) {
|
|
|
124
124
|
...(order.total_discount_applied != null
|
|
125
125
|
? { total_discount_applied: convertToPrice(order.total_discount_applied) }
|
|
126
126
|
: {}),
|
|
127
|
+
...(order.labor_charges != null && order.is_labor_charges_percentage !== true
|
|
128
|
+
? { labor_charges: convertToPrice(order.labor_charges) }
|
|
129
|
+
: {}),
|
|
130
|
+
...(order.labor_charges_amount != null ? { labor_charges_amount: convertToPrice(order.labor_charges_amount) } : {}),
|
|
131
|
+
...(order.freight_charges != null && order.is_freight_charges_percentage !== true
|
|
132
|
+
? { freight_charges: convertToPrice(order.freight_charges) }
|
|
133
|
+
: {}),
|
|
134
|
+
...(order.freight_charges_amount != null
|
|
135
|
+
? { freight_charges_amount: convertToPrice(order.freight_charges_amount) }
|
|
136
|
+
: {}),
|
|
127
137
|
};
|
|
128
138
|
return payload;
|
|
129
139
|
}
|
|
@@ -163,6 +173,10 @@ function getCommonOptionalBoolFieldsPurchaseOrder(order, partial) {
|
|
|
163
173
|
is_gst_inclusive: order['is_gst_inclusive'] || defaultValue,
|
|
164
174
|
is_reopened: order['is_reopened'] || defaultValue,
|
|
165
175
|
is_gst_percentage: order['is_gst_percentage'] ?? (partial ? undefined : true),
|
|
176
|
+
is_labor_charges_percentage: order['is_labor_charges_percentage'] ?? defaultValue,
|
|
177
|
+
is_labor_charges_taxable: order['is_labor_charges_taxable'] || defaultValue,
|
|
178
|
+
is_freight_charges_percentage: order['is_freight_charges_percentage'] ?? defaultValue,
|
|
179
|
+
is_freight_charges_taxable: order['is_freight_charges_taxable'] || defaultValue,
|
|
166
180
|
};
|
|
167
181
|
}
|
|
168
182
|
function getCommonOptionalNumFieldsPurchaseOrder(order, partial) {
|
|
@@ -170,6 +184,10 @@ function getCommonOptionalNumFieldsPurchaseOrder(order, partial) {
|
|
|
170
184
|
return {
|
|
171
185
|
gst: order['gst'] || defaultValue,
|
|
172
186
|
gst_amount: order['gst_amount'] || defaultValue,
|
|
187
|
+
labor_charges: order['labor_charges'] || defaultValue,
|
|
188
|
+
labor_charges_amount: order['labor_charges_amount'] || defaultValue,
|
|
189
|
+
freight_charges: order['freight_charges'] || defaultValue,
|
|
190
|
+
freight_charges_amount: order['freight_charges_amount'] || defaultValue,
|
|
173
191
|
};
|
|
174
192
|
}
|
|
175
193
|
function getWarehousePurchaseOrderWithAllFields(order, skipItemMetadata) {
|