washday-sdk 0.0.1
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/enum/index.js +15 -0
- package/dist/index.js +28 -0
- package/dist/interfaces/Company.js +1 -0
- package/dist/interfaces/Customer.js +2 -0
- package/dist/interfaces/Order.js +2 -0
- package/dist/interfaces/Permission.js +2 -0
- package/dist/interfaces/Product.js +2 -0
- package/dist/interfaces/Section.js +2 -0
- package/dist/interfaces/Store.js +2 -0
- package/dist/interfaces/StoreImage.js +2 -0
- package/dist/interfaces/User.js +2 -0
- package/dist/utils/index.js +17 -0
- package/dist/utils/orders/calculateOrderTotal.js +33 -0
- package/dist/utils/orders/calculateTotalTaxesIncluded.js +65 -0
- package/dist/utils/orders/calculateTotalTaxesOverPrice.js +74 -0
- package/dist/utils/orders/helpers.js +64 -0
- package/dist/utils/orders/index.js +5 -0
- package/package.json +23 -0
- package/src/enum/index.ts +11 -0
- package/src/index.ts +5 -0
- package/src/interfaces/Company.ts +0 -0
- package/src/interfaces/Customer.ts +51 -0
- package/src/interfaces/Order.ts +85 -0
- package/src/interfaces/Permission.ts +24 -0
- package/src/interfaces/Product.ts +59 -0
- package/src/interfaces/Section.ts +14 -0
- package/src/interfaces/Store.ts +350 -0
- package/src/interfaces/StoreImage.ts +9 -0
- package/src/interfaces/User.ts +43 -0
- package/src/utils/index.ts +1 -0
- package/src/utils/orders/calculateOrderTotal.ts +60 -0
- package/src/utils/orders/calculateTotalTaxesIncluded.ts +75 -0
- package/src/utils/orders/calculateTotalTaxesOverPrice.ts +83 -0
- package/src/utils/orders/helpers.ts +73 -0
- package/src/utils/orders/index.ts +5 -0
- package/tsconfig.json +10 -0
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BuyAndGetConditionsTypes = exports.DiscountCodeTypes = void 0;
|
|
4
|
+
var DiscountCodeTypes;
|
|
5
|
+
(function (DiscountCodeTypes) {
|
|
6
|
+
DiscountCodeTypes["PERCENTAGE"] = "percentage";
|
|
7
|
+
DiscountCodeTypes["NUMBER"] = "number";
|
|
8
|
+
DiscountCodeTypes["FREE_DELIVERY"] = "freeDelivery";
|
|
9
|
+
DiscountCodeTypes["BUY_X_GET_Y"] = "buyXGetY";
|
|
10
|
+
})(DiscountCodeTypes || (exports.DiscountCodeTypes = DiscountCodeTypes = {}));
|
|
11
|
+
var BuyAndGetConditionsTypes;
|
|
12
|
+
(function (BuyAndGetConditionsTypes) {
|
|
13
|
+
BuyAndGetConditionsTypes["PERCENTAGE"] = "percentage";
|
|
14
|
+
BuyAndGetConditionsTypes["FREE"] = "free";
|
|
15
|
+
})(BuyAndGetConditionsTypes || (exports.BuyAndGetConditionsTypes = BuyAndGetConditionsTypes = {}));
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.utils = void 0;
|
|
27
|
+
const utils = __importStar(require("./utils"));
|
|
28
|
+
exports.utils = utils;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./orders"), exports);
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.calculateOrderTotal = void 0;
|
|
4
|
+
const enum_1 = require("../../enum");
|
|
5
|
+
const calculateTotalTaxesIncluded_1 = require("./calculateTotalTaxesIncluded");
|
|
6
|
+
const calculateTotalTaxesOverPrice_1 = require("./calculateTotalTaxesOverPrice");
|
|
7
|
+
const helpers_1 = require("./helpers");
|
|
8
|
+
const calculateOrderTotal = (order, selectedCustomer, storeSettings, hasShippingCost, storeDiscounts = [], discountCodeObj) => {
|
|
9
|
+
var _a;
|
|
10
|
+
try {
|
|
11
|
+
const appliedOrderDiscounts = {};
|
|
12
|
+
const productTableCalculator = (storeSettings === null || storeSettings === void 0 ? void 0 : storeSettings.taxesType) === 'over_price' ? calculateTotalTaxesOverPrice_1.calculateTotalTaxesOverPrice : calculateTotalTaxesIncluded_1.calculateTotalTaxesIncluded;
|
|
13
|
+
const productTableImports = productTableCalculator(order, selectedCustomer, storeSettings, storeDiscounts, appliedOrderDiscounts, discountCodeObj);
|
|
14
|
+
// PRODUCT LINE TOTALS
|
|
15
|
+
const { totalQuantity, totalImportWithDiscount, totalImportWithoutDiscount, totalImporTaxes, totalDiscountAmount } = (0, helpers_1.getProductLineTotals)(productTableImports);
|
|
16
|
+
// DISCOUNT TOTAL AND SHIPPING SERVICE COST
|
|
17
|
+
let discountCodeAmount = 0;
|
|
18
|
+
let shippingCost = (0, helpers_1.getShippingCost)(discountCodeObj, hasShippingCost, storeSettings);
|
|
19
|
+
if (discountCodeObj && discountCodeObj.type === enum_1.DiscountCodeTypes.NUMBER && discountCodeObj.applyOnceOnOrder) {
|
|
20
|
+
const includesProducts = discountCodeObj.applyToAllProducts || order.products.some((curr) => discountCodeObj.products.includes(curr._id));
|
|
21
|
+
discountCodeAmount = includesProducts ? discountCodeObj.value : 0;
|
|
22
|
+
}
|
|
23
|
+
// ORDER TOTAL CALCULATION AND CREDIT APPLIED
|
|
24
|
+
let orderTotalWithOutCredit = +(totalImportWithDiscount + totalImporTaxes + shippingCost - discountCodeAmount).toFixed(2);
|
|
25
|
+
let creditApplied = (0, helpers_1.getCreditApplied)(selectedCustomer, orderTotalWithOutCredit);
|
|
26
|
+
let orderTotal = +(orderTotalWithOutCredit - creditApplied).toFixed(2);
|
|
27
|
+
return Object.assign(Object.assign({}, order), { totalQuantity, customerDiscount: order.discountCode ? 0 : (_a = selectedCustomer === null || selectedCustomer === void 0 ? void 0 : selectedCustomer.customer) === null || _a === void 0 ? void 0 : _a.discount, productTotal: totalImportWithDiscount, taxesTotal: totalImporTaxes, total: orderTotal, creditApplied, productTotalWithoutDiscount: totalImportWithoutDiscount, totalDiscountAmount: totalDiscountAmount + discountCodeAmount, shippingServiceTotal: shippingCost, appliedOrderDiscounts });
|
|
28
|
+
}
|
|
29
|
+
catch (error) {
|
|
30
|
+
throw error;
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
exports.calculateOrderTotal = calculateOrderTotal;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.calculateTotalTaxesIncluded = void 0;
|
|
4
|
+
const helpers_1 = require("./helpers");
|
|
5
|
+
const calculateTotalTaxesIncluded = (order, selectedCustomer, storeSettings, storeDiscounts, appliedOrderDiscounts, discountCodeObj) => {
|
|
6
|
+
const productTableImports = [...order.products, ...order.buyAndGetProducts].map((current) => {
|
|
7
|
+
var _a, _b;
|
|
8
|
+
let discPercentageInteger = 0;
|
|
9
|
+
let productPercentageDiscount = 0;
|
|
10
|
+
let customerDiscount = 0;
|
|
11
|
+
let qty = current.qty || 0;
|
|
12
|
+
const extraAmountPerUnit = current.extraAmount / qty;
|
|
13
|
+
const prodPrice = (order.express ? current.expressPrice : current.price) + extraAmountPerUnit;
|
|
14
|
+
if (!order.discountCode) {
|
|
15
|
+
const discountsToApply = storeDiscounts.filter((discount) => discount.products.includes(current._id) && discount.isActive);
|
|
16
|
+
customerDiscount = ((_a = selectedCustomer === null || selectedCustomer === void 0 ? void 0 : selectedCustomer.customer) === null || _a === void 0 ? void 0 : _a.discount) || 0;
|
|
17
|
+
productPercentageDiscount = discountsToApply.reduce((prev, next) => {
|
|
18
|
+
if (next.type === 'percentage') {
|
|
19
|
+
return prev + next.value;
|
|
20
|
+
}
|
|
21
|
+
return prev;
|
|
22
|
+
}, 0);
|
|
23
|
+
discPercentageInteger = +((productPercentageDiscount + customerDiscount) / 100).toFixed(2);
|
|
24
|
+
discountsToApply.forEach((discount) => (appliedOrderDiscounts[discount._id] = discount));
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
if ((discountCodeObj === null || discountCodeObj === void 0 ? void 0 : discountCodeObj.type) === 'percentage') {
|
|
28
|
+
discPercentageInteger = +(discountCodeObj.value / 100).toFixed(2);
|
|
29
|
+
if (!discountCodeObj.applyToAllProducts) {
|
|
30
|
+
discPercentageInteger = ((_b = discountCodeObj.products) === null || _b === void 0 ? void 0 : _b.includes(current._id))
|
|
31
|
+
? +(discountCodeObj.value / 100).toFixed(2)
|
|
32
|
+
: 0;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
if ((discountCodeObj === null || discountCodeObj === void 0 ? void 0 : discountCodeObj.type) === 'buyXGetY') {
|
|
36
|
+
const discountType = discountCodeObj.buyAndGetConditions[0].getDiscountType;
|
|
37
|
+
const discountValue = discountCodeObj.buyAndGetConditions[0].discountValue;
|
|
38
|
+
if (discountType === 'percentage' && current.isBuyAndGetProduct) {
|
|
39
|
+
discPercentageInteger = +(discountValue / 100).toFixed(2);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
const taxPercentage = (0, helpers_1.getProductTaxesPercentage)(current, storeSettings);
|
|
44
|
+
const taxPercentageInteger = taxPercentage / 100;
|
|
45
|
+
const unitPrice = prodPrice / (1 + taxPercentageInteger);
|
|
46
|
+
const discountAmountPerUnit = discPercentageInteger
|
|
47
|
+
? unitPrice * discPercentageInteger
|
|
48
|
+
: (current.discountAmount || 0) / (1 + taxPercentageInteger);
|
|
49
|
+
const prodPriceWithDiscountPerUnit = unitPrice - discountAmountPerUnit;
|
|
50
|
+
const taxesAmountPerUnit = prodPriceWithDiscountPerUnit * taxPercentageInteger;
|
|
51
|
+
const totalTaxesApplied = +(taxesAmountPerUnit * qty).toFixed(2);
|
|
52
|
+
const lineDiscount = qty * discountAmountPerUnit;
|
|
53
|
+
const prodLinePriceWithDiscount = +(qty * prodPriceWithDiscountPerUnit).toFixed(2);
|
|
54
|
+
return {
|
|
55
|
+
product: current,
|
|
56
|
+
qty: qty,
|
|
57
|
+
productLineImportTotal: unitPrice * qty,
|
|
58
|
+
productLineTotalWithDiscount: prodLinePriceWithDiscount,
|
|
59
|
+
productLineTaxesTotal: totalTaxesApplied,
|
|
60
|
+
lineDiscountAmount: lineDiscount
|
|
61
|
+
};
|
|
62
|
+
});
|
|
63
|
+
return productTableImports;
|
|
64
|
+
};
|
|
65
|
+
exports.calculateTotalTaxesIncluded = calculateTotalTaxesIncluded;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.calculateTotalTaxesOverPrice = void 0;
|
|
4
|
+
const enum_1 = require("../../enum");
|
|
5
|
+
const helpers_1 = require("./helpers");
|
|
6
|
+
const calculateTotalTaxesOverPrice = (order, selectedCustomer, storeSettings, storeDiscounts, appliedOrderDiscounts, discountCodeObj) => {
|
|
7
|
+
const productTableImports = [...order.products, ...order.buyAndGetProducts].map((current) => {
|
|
8
|
+
var _a;
|
|
9
|
+
let discPercentageInteger = 0;
|
|
10
|
+
let productPercentageDiscount = 0;
|
|
11
|
+
let customerDiscount = 0;
|
|
12
|
+
let qty = current.qty;
|
|
13
|
+
// extraAmount es en general sin importar el qty, entonces aqui lo repartimos por igual
|
|
14
|
+
const extraAmountPerUnit = current.extraAmount / qty;
|
|
15
|
+
const prodPrice = (order.express ? current.expressPrice : current.price) + extraAmountPerUnit;
|
|
16
|
+
if (!order.discountCode) {
|
|
17
|
+
//IF ORDER HAS A DISCOUNT CODE WE DON'T APPLY ANY OTHER DISCOUNT (AUTOMATICALLY OR CUSTOMER DISCOUNT)
|
|
18
|
+
//THIS WILL GET THE DISCOUNTS OF THE CURRENT PRODUCT
|
|
19
|
+
// get store discounts if product applies and customer discount
|
|
20
|
+
const discountsToApply = storeDiscounts.filter((discount) => discount.products.includes(current._id) && discount.isActive);
|
|
21
|
+
customerDiscount = ((_a = selectedCustomer === null || selectedCustomer === void 0 ? void 0 : selectedCustomer.customer) === null || _a === void 0 ? void 0 : _a.discount) || 0;
|
|
22
|
+
productPercentageDiscount = discountsToApply.reduce((prev, next) => {
|
|
23
|
+
if (next.type === 'percentage') {
|
|
24
|
+
// for now we just sum percetange type discounts
|
|
25
|
+
return prev + next.value;
|
|
26
|
+
}
|
|
27
|
+
return prev;
|
|
28
|
+
}, 0);
|
|
29
|
+
discPercentageInteger = +((productPercentageDiscount + customerDiscount) / 100).toFixed(2);
|
|
30
|
+
discountsToApply.forEach((discount) => (appliedOrderDiscounts[discount._id] = discount)); // it will do this for every product, if two products has the same discount it will just overwrite
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
if (discountCodeObj.type === enum_1.DiscountCodeTypes.PERCENTAGE) {
|
|
34
|
+
discPercentageInteger = +(discountCodeObj.value / 100).toFixed(2);
|
|
35
|
+
if (!discountCodeObj.applyToAllProducts) {
|
|
36
|
+
discPercentageInteger = discountCodeObj.products.includes(current._id)
|
|
37
|
+
? +(discountCodeObj.value / 100).toFixed(2)
|
|
38
|
+
: 0;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
if (discountCodeObj.type === enum_1.DiscountCodeTypes.BUY_X_GET_Y) {
|
|
42
|
+
const discountType = discountCodeObj.buyAndGetConditions[0].getDiscountType;
|
|
43
|
+
const discountValue = discountCodeObj.buyAndGetConditions[0].discountValue;
|
|
44
|
+
if (discountType === enum_1.BuyAndGetConditionsTypes.PERCENTAGE && current.isBuyAndGetProduct) {
|
|
45
|
+
discPercentageInteger = +(discountValue / 100).toFixed(2);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
//GET DISCOUNT AMOUNT (IN CASE discPercentageInteger is 0 it could be a discount of a integer number)
|
|
50
|
+
const discountAmountPerUnit = discPercentageInteger
|
|
51
|
+
? prodPrice * discPercentageInteger
|
|
52
|
+
: (current.discountAmount || 0);
|
|
53
|
+
//GET PRODUCT PRICE WITH DISCOUNT
|
|
54
|
+
const prodPriceWithDiscountPerUnit = prodPrice - discountAmountPerUnit;
|
|
55
|
+
//GET PRODUCT TAXES APPLIED TO FINAL PRICE PER UNIT
|
|
56
|
+
const taxPercentage = (0, helpers_1.getProductTaxesPercentage)(current, storeSettings);
|
|
57
|
+
const taxPercentageInteger = taxPercentage / 100;
|
|
58
|
+
const prodPriceWithoutTaxesPerUnit = prodPriceWithDiscountPerUnit;
|
|
59
|
+
const taxesAmountPerUnit = prodPriceWithoutTaxesPerUnit * taxPercentageInteger;
|
|
60
|
+
const totalTaxesApplied = +(taxesAmountPerUnit * qty).toFixed(2);
|
|
61
|
+
let lineDiscount = qty * discountAmountPerUnit;
|
|
62
|
+
let prodLinePriceWithDiscount = +(qty * prodPriceWithDiscountPerUnit).toFixed(2);
|
|
63
|
+
return {
|
|
64
|
+
product: current,
|
|
65
|
+
qty: qty,
|
|
66
|
+
productLineImportTotal: prodPrice * qty, //this is line without discount
|
|
67
|
+
productLineTotalWithDiscount: prodLinePriceWithDiscount,
|
|
68
|
+
productLineTaxesTotal: totalTaxesApplied,
|
|
69
|
+
lineDiscountAmount: lineDiscount
|
|
70
|
+
};
|
|
71
|
+
});
|
|
72
|
+
return productTableImports;
|
|
73
|
+
};
|
|
74
|
+
exports.calculateTotalTaxesOverPrice = calculateTotalTaxesOverPrice;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getCreditApplied = exports.getShippingCost = exports.getProductLineTotals = exports.getProductTaxesPercentage = void 0;
|
|
4
|
+
const enum_1 = require("../../enum");
|
|
5
|
+
const getProductTaxesPercentage = (productObj, store) => {
|
|
6
|
+
const getTaxValue = (tax, isTaxExempt) => {
|
|
7
|
+
if (!tax) {
|
|
8
|
+
// If no store tax configured, always return 0
|
|
9
|
+
return 0;
|
|
10
|
+
}
|
|
11
|
+
if (isTaxExempt) {
|
|
12
|
+
// If store tax is configured and taxExempt is true, return 0
|
|
13
|
+
return 0;
|
|
14
|
+
}
|
|
15
|
+
// If store tax configured and taxExempt is false, return store tax
|
|
16
|
+
return tax.value;
|
|
17
|
+
};
|
|
18
|
+
const tax1 = getTaxValue(store.taxOne, !productObj.taxExemptOne);
|
|
19
|
+
const tax2 = getTaxValue(store.taxTwo, !productObj.taxExemptTwo);
|
|
20
|
+
const tax3 = getTaxValue(store.taxThree, !productObj.taxExemptThree);
|
|
21
|
+
return tax1 + tax2 + tax3;
|
|
22
|
+
};
|
|
23
|
+
exports.getProductTaxesPercentage = getProductTaxesPercentage;
|
|
24
|
+
const getProductLineTotals = (productLinesTotals) => {
|
|
25
|
+
const totalQuantity = +productLinesTotals.reduce((acum, line) => acum + line.qty, 0).toFixed(2);
|
|
26
|
+
const totalImportWithDiscount = +productLinesTotals
|
|
27
|
+
.reduce((acum, line) => acum + line.productLineTotalWithDiscount, 0)
|
|
28
|
+
.toFixed(2);
|
|
29
|
+
const totalImportWithoutDiscount = +productLinesTotals
|
|
30
|
+
.reduce((acum, line) => acum + line.productLineImportTotal, 0)
|
|
31
|
+
.toFixed(2);
|
|
32
|
+
const totalImporTaxes = +productLinesTotals
|
|
33
|
+
.reduce((acum, line) => acum + line.productLineTaxesTotal, 0)
|
|
34
|
+
.toFixed(2);
|
|
35
|
+
const totalDiscountAmount = +productLinesTotals
|
|
36
|
+
.reduce((acum, line) => acum + line.lineDiscountAmount, 0)
|
|
37
|
+
.toFixed(2);
|
|
38
|
+
return {
|
|
39
|
+
totalQuantity,
|
|
40
|
+
totalImportWithDiscount,
|
|
41
|
+
totalImportWithoutDiscount,
|
|
42
|
+
totalImporTaxes,
|
|
43
|
+
totalDiscountAmount
|
|
44
|
+
};
|
|
45
|
+
};
|
|
46
|
+
exports.getProductLineTotals = getProductLineTotals;
|
|
47
|
+
const getShippingCost = (discountObject, requireShippingService, store) => {
|
|
48
|
+
var _a, _b;
|
|
49
|
+
const shippingCost = requireShippingService ? (_b = (_a = store === null || store === void 0 ? void 0 : store.orderPageConfig) === null || _a === void 0 ? void 0 : _a.shippingServiceCost) !== null && _b !== void 0 ? _b : 0 : 0;
|
|
50
|
+
if ((discountObject === null || discountObject === void 0 ? void 0 : discountObject.type) === enum_1.DiscountCodeTypes.FREE_DELIVERY) {
|
|
51
|
+
return 0;
|
|
52
|
+
}
|
|
53
|
+
return shippingCost;
|
|
54
|
+
};
|
|
55
|
+
exports.getShippingCost = getShippingCost;
|
|
56
|
+
const getCreditApplied = (selectedCustomer, orderTotal) => {
|
|
57
|
+
var _a, _b;
|
|
58
|
+
const customerCredit = (_b = (_a = selectedCustomer === null || selectedCustomer === void 0 ? void 0 : selectedCustomer.customer) === null || _a === void 0 ? void 0 : _a.credit) !== null && _b !== void 0 ? _b : 0;
|
|
59
|
+
if (customerCredit === 0 || !selectedCustomer) {
|
|
60
|
+
return 0;
|
|
61
|
+
}
|
|
62
|
+
return Math.min(customerCredit, orderTotal);
|
|
63
|
+
};
|
|
64
|
+
exports.getCreditApplied = getCreditApplied;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.calculateOrderTotal = void 0;
|
|
4
|
+
const calculateOrderTotal_1 = require("./calculateOrderTotal");
|
|
5
|
+
Object.defineProperty(exports, "calculateOrderTotal", { enumerable: true, get: function () { return calculateOrderTotal_1.calculateOrderTotal; } });
|
package/package.json
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "washday-sdk",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "Washday utilities functions and API",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"test": "test",
|
|
8
|
+
"build": "tsc",
|
|
9
|
+
"publish": "npm run build && npm publish --access public"
|
|
10
|
+
},
|
|
11
|
+
"keywords": [
|
|
12
|
+
"washday"
|
|
13
|
+
],
|
|
14
|
+
"author": "Washday",
|
|
15
|
+
"license": "ISC",
|
|
16
|
+
"devDependencies": {
|
|
17
|
+
"typescript": "^5.4.4"
|
|
18
|
+
},
|
|
19
|
+
"dependencies": {
|
|
20
|
+
"axios": "^1.6.8",
|
|
21
|
+
"joi": "^17.12.3"
|
|
22
|
+
}
|
|
23
|
+
}
|
package/src/index.ts
ADDED
|
File without changes
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { IStore } from './Store'
|
|
2
|
+
import { IUser } from "./User"
|
|
3
|
+
|
|
4
|
+
interface IInvoiceInfo {
|
|
5
|
+
legal_name: string,
|
|
6
|
+
tax_system: string,
|
|
7
|
+
zipCode: string
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
interface IAddresses {
|
|
11
|
+
addressString: string,
|
|
12
|
+
addressName: string,
|
|
13
|
+
location: {
|
|
14
|
+
latitude: string,
|
|
15
|
+
longitude: string
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
interface IPaymentMethod {
|
|
20
|
+
stripeId: string,
|
|
21
|
+
brand: string,
|
|
22
|
+
exp_month: string,
|
|
23
|
+
exp_year: string,
|
|
24
|
+
last4: string,
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export interface ICustomer {
|
|
28
|
+
name: string,
|
|
29
|
+
phone: string,
|
|
30
|
+
address: string,
|
|
31
|
+
rfc?: string,
|
|
32
|
+
email: string,
|
|
33
|
+
notes?: string,
|
|
34
|
+
privateNotes?: string,
|
|
35
|
+
discount: number,
|
|
36
|
+
credit: number,
|
|
37
|
+
isActive: boolean,
|
|
38
|
+
createdIn: IStore | string,
|
|
39
|
+
createdBy: IUser | string,
|
|
40
|
+
// company: ICompany | string,
|
|
41
|
+
createdDate: Date,
|
|
42
|
+
password?: string,
|
|
43
|
+
google?: boolean,
|
|
44
|
+
facebook?: boolean,
|
|
45
|
+
apple?: boolean,
|
|
46
|
+
useStoreApp?: boolean,
|
|
47
|
+
addresses?: [IAddresses],
|
|
48
|
+
paymentMethods?: [IPaymentMethod],
|
|
49
|
+
stripeCustomerId?: string,
|
|
50
|
+
invoiceInfo?: IInvoiceInfo,
|
|
51
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { ICustomer } from "./Customer";
|
|
2
|
+
import { IOrderProduct } from "./Product";
|
|
3
|
+
import { ICashierBox, IStore, ITaxConfig } from "./Store";
|
|
4
|
+
import { IUser } from "./User";
|
|
5
|
+
|
|
6
|
+
interface IDeliveryInfo {
|
|
7
|
+
date: Date,
|
|
8
|
+
fromTime: string,
|
|
9
|
+
toTime: string
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
interface IPickupInfo {
|
|
13
|
+
date: Date,
|
|
14
|
+
fromTime: string,
|
|
15
|
+
toTime: string
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface IOrderPaymentLines {
|
|
19
|
+
_id?: any,
|
|
20
|
+
amountPaid: number,
|
|
21
|
+
isOnACashUpReport: Boolean,
|
|
22
|
+
cashierBox: ICashierBox | string
|
|
23
|
+
paymentDate: Date,
|
|
24
|
+
paymentMethod: string,
|
|
25
|
+
description: string,
|
|
26
|
+
createdBy: IUser | string,
|
|
27
|
+
facturapiPaymentInvoiceID?: string | null,
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export interface IOrder {
|
|
31
|
+
delivery: boolean,
|
|
32
|
+
pickup: boolean,
|
|
33
|
+
express: boolean,
|
|
34
|
+
deliveryInfo: IDeliveryInfo,
|
|
35
|
+
pickupInfo?: IPickupInfo,
|
|
36
|
+
phone: string,
|
|
37
|
+
email?: string,
|
|
38
|
+
address: string,
|
|
39
|
+
notes?: string,
|
|
40
|
+
privateNotes?: string,
|
|
41
|
+
isActive: boolean,
|
|
42
|
+
taxesType: string,
|
|
43
|
+
products: Array<IOrderProduct> | Array<string>,
|
|
44
|
+
buyAndGetProducts: Array<IOrderProduct> | Array<string>,
|
|
45
|
+
taxOne?: ITaxConfig,
|
|
46
|
+
taxTwo?: ITaxConfig,
|
|
47
|
+
taxThree?: ITaxConfig,
|
|
48
|
+
creditApplied: number,
|
|
49
|
+
taxesTotal: number,
|
|
50
|
+
total: number,
|
|
51
|
+
totalQuantity: number,
|
|
52
|
+
productTotal: number,
|
|
53
|
+
productTotalWithoutDiscount: number,
|
|
54
|
+
shippingServiceTotal: number,
|
|
55
|
+
totalDiscountAmount: number,
|
|
56
|
+
amountPaid: number,
|
|
57
|
+
prepaidAmount: number | null,
|
|
58
|
+
createdIn: IStore | string,
|
|
59
|
+
createdBy: IUser | string,
|
|
60
|
+
customer: ICustomer | string,
|
|
61
|
+
customerDiscount?: number | null,
|
|
62
|
+
createdDate: Date,
|
|
63
|
+
pickingUpDateTime: Date | null,
|
|
64
|
+
cleanedDateTime: Date | null,
|
|
65
|
+
readyDateTime: Date | null,
|
|
66
|
+
deliveringDateTime: Date | null,
|
|
67
|
+
collectedDateTime: Date | null,
|
|
68
|
+
cancelledDateTime: Date | null,
|
|
69
|
+
paidDateTime: Date | null,
|
|
70
|
+
paymentMethod: string | null
|
|
71
|
+
prepaidPaymentMethod: string | null
|
|
72
|
+
status: string,
|
|
73
|
+
pickupRoute: string | null,
|
|
74
|
+
deliveryRoute: string | null,
|
|
75
|
+
sequence?: string | null,
|
|
76
|
+
notifyBy: string,
|
|
77
|
+
stripePaymentIntentId?: string | null,
|
|
78
|
+
markedCleanedBy: IUser | string,
|
|
79
|
+
markedCollectedBy: IUser | string,
|
|
80
|
+
markedCancelledBy: IUser | string,
|
|
81
|
+
appliedStoreDiscounts: Array<string> | null,
|
|
82
|
+
appliedDiscountCodes: Array<string> | null,
|
|
83
|
+
paymentLines: Array<IOrderPaymentLines> | Array<string> | any,
|
|
84
|
+
facturapiInvoiceID?: string | null,
|
|
85
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
|
|
2
|
+
export interface IPermissionType {
|
|
3
|
+
canView: Boolean,
|
|
4
|
+
canMutate: Boolean
|
|
5
|
+
}
|
|
6
|
+
export interface IPermissionViewType {
|
|
7
|
+
canView: Boolean,
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export interface IPermission {
|
|
11
|
+
product: IPermissionType,
|
|
12
|
+
section: IPermissionType,
|
|
13
|
+
auth: IPermissionType,
|
|
14
|
+
staff: IPermissionType,
|
|
15
|
+
company: IPermissionType,
|
|
16
|
+
store: IPermissionType,
|
|
17
|
+
settings: IPermissionViewType,
|
|
18
|
+
cashierBoxes: IPermissionType,
|
|
19
|
+
reports: IPermissionViewType,
|
|
20
|
+
customers: IPermissionType,
|
|
21
|
+
discounts: IPermissionType,
|
|
22
|
+
reviews: IPermissionViewType,
|
|
23
|
+
inventory: IPermissionType,
|
|
24
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { IStore } from "./Store"
|
|
2
|
+
import { IStoreImage } from "./StoreImage"
|
|
3
|
+
import { IUser } from "./User"
|
|
4
|
+
|
|
5
|
+
export interface ProductLineTotals {
|
|
6
|
+
product: IOrderProduct,
|
|
7
|
+
qty: number,
|
|
8
|
+
productLineImportTotal: number,
|
|
9
|
+
productLineTotalWithDiscount: number,
|
|
10
|
+
productLineTaxesTotal: number,
|
|
11
|
+
lineDiscountAmount: number
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
export interface IProduct {
|
|
16
|
+
_id?: string
|
|
17
|
+
name: string,
|
|
18
|
+
price: number,
|
|
19
|
+
expressPrice: number,
|
|
20
|
+
extraAmount?: number,
|
|
21
|
+
image?: IStoreImage | string,
|
|
22
|
+
overlayText: string,
|
|
23
|
+
sku: string,
|
|
24
|
+
pieces: String,
|
|
25
|
+
taxExemptOne: boolean,
|
|
26
|
+
taxExemptTwo: boolean,
|
|
27
|
+
taxExemptThree: boolean,
|
|
28
|
+
type: String,
|
|
29
|
+
isActive: boolean,
|
|
30
|
+
showInApp: boolean,
|
|
31
|
+
owner: IUser | string,
|
|
32
|
+
store: IStore | string,
|
|
33
|
+
order: number,
|
|
34
|
+
productSupplies?: [IProductSupplies],
|
|
35
|
+
invoice_description?: string,
|
|
36
|
+
invoice_product_key?: string,
|
|
37
|
+
invoice_product_unit_key?: string,
|
|
38
|
+
invoice_product_unit_name?: string
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export interface IProductSupplies {
|
|
42
|
+
supplyId: String,
|
|
43
|
+
// supplyName: String,
|
|
44
|
+
// supplyUsageUnit: String,
|
|
45
|
+
usageAmount: number,
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export interface IStoreProduct extends IProduct { }
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
export interface IOrderProduct extends IProduct {
|
|
52
|
+
extraAmount: number,
|
|
53
|
+
properties: Array<string>,
|
|
54
|
+
quantity: number,
|
|
55
|
+
discountAmount: number,
|
|
56
|
+
isBuyAndGetProduct: boolean,
|
|
57
|
+
storeProductId: IStoreProduct | string
|
|
58
|
+
qty?: number
|
|
59
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { IProduct } from './Product'
|
|
2
|
+
import { IStore } from "./Store"
|
|
3
|
+
import { IUser } from "./User"
|
|
4
|
+
|
|
5
|
+
export interface ISection {
|
|
6
|
+
name: string,
|
|
7
|
+
order: number,
|
|
8
|
+
boxColor: string,
|
|
9
|
+
isActive: boolean,
|
|
10
|
+
products?: IProduct[] | Array<string>
|
|
11
|
+
owner: IUser | string
|
|
12
|
+
store: IStore | string,
|
|
13
|
+
showInApp?: boolean,
|
|
14
|
+
}
|