washday-sdk 0.0.10 → 0.0.12

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.
@@ -1,42 +1,42 @@
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
- const axios_1 = __importDefault(require("axios"));
7
- // Define the type for the Axios instance
8
- let axiosInstance = null;
9
- const BASE_URL = 'https://washday-backend.herokuapp.com/';
10
- // Function to create or return the singleton instance
11
- const getAxiosInstance = () => {
12
- if (!axiosInstance) {
13
- axiosInstance = axios_1.default.create({
14
- baseURL: BASE_URL,
15
- headers: {
16
- 'Content-Type': 'application/json',
17
- // Add any default headers here
18
- },
19
- });
20
- // Add interceptor to set token and other options for every request
21
- axiosInstance.interceptors.request.use((config) => {
22
- const { token, contentType = 'application/json', responseType = 'json', contentDisposition } = config.params || {};
23
- if (token) {
24
- config.headers.Authorization = `Bearer ${token}`;
25
- }
26
- if (contentType) {
27
- config.headers['Content-Type'] = contentType;
28
- }
29
- if (responseType) {
30
- config.responseType = responseType;
31
- }
32
- if (contentDisposition) {
33
- config.headers['Content-Disposition'] = contentDisposition;
34
- }
35
- return config;
36
- }, (error) => {
37
- return Promise.reject(error);
38
- });
39
- }
40
- return axiosInstance;
41
- };
42
- exports.default = getAxiosInstance();
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
+ const axios_1 = __importDefault(require("axios"));
7
+ // Define the type for the Axios instance
8
+ let axiosInstance = null;
9
+ const BASE_URL = 'https://washday-backend.herokuapp.com/';
10
+ // Function to create or return the singleton instance
11
+ const getAxiosInstance = () => {
12
+ if (!axiosInstance) {
13
+ axiosInstance = axios_1.default.create({
14
+ baseURL: BASE_URL,
15
+ headers: {
16
+ 'Content-Type': 'application/json',
17
+ // Add any default headers here
18
+ },
19
+ });
20
+ // Add interceptor to set token and other options for every request
21
+ axiosInstance.interceptors.request.use((config) => {
22
+ const { token, contentType = 'application/json', responseType = 'json', contentDisposition } = config.params || {};
23
+ if (token) {
24
+ config.headers.Authorization = `Bearer ${token}`;
25
+ }
26
+ if (contentType) {
27
+ config.headers['Content-Type'] = contentType;
28
+ }
29
+ if (responseType) {
30
+ config.responseType = responseType;
31
+ }
32
+ if (contentDisposition) {
33
+ config.headers['Content-Disposition'] = contentDisposition;
34
+ }
35
+ return config;
36
+ }, (error) => {
37
+ return Promise.reject(error);
38
+ });
39
+ }
40
+ return axiosInstance;
41
+ };
42
+ exports.default = getAxiosInstance();
@@ -1,48 +1,48 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.getCustomerHighlightsById = exports.getCustomerById = void 0;
16
- const axiosInstance_1 = __importDefault(require("../axiosInstance"));
17
- const GET_SET_CUSTOMERS = 'api/customer';
18
- const REQUEST_PARAMS = {
19
- token: 'LOGGED_USER_TOKEN',
20
- };
21
- const getCustomerById = function (customerId) {
22
- return __awaiter(this, void 0, void 0, function* () {
23
- try {
24
- REQUEST_PARAMS.token = this.apiToken;
25
- const response = yield axiosInstance_1.default.get(`${GET_SET_CUSTOMERS}/${customerId}`, { params: Object.assign({}, REQUEST_PARAMS) });
26
- return response.data;
27
- }
28
- catch (error) {
29
- console.error('Error fetching customer:', error);
30
- throw error;
31
- }
32
- });
33
- };
34
- exports.getCustomerById = getCustomerById;
35
- const getCustomerHighlightsById = function (customerId) {
36
- return __awaiter(this, void 0, void 0, function* () {
37
- try {
38
- REQUEST_PARAMS.token = this.apiToken;
39
- const response = yield axiosInstance_1.default.get(`${GET_SET_CUSTOMERS}/${customerId}/highlights`, { params: Object.assign({}, REQUEST_PARAMS) });
40
- return response.data;
41
- }
42
- catch (error) {
43
- console.error('Error fetching customer:', error);
44
- throw error;
45
- }
46
- });
47
- };
48
- exports.getCustomerHighlightsById = getCustomerHighlightsById;
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.getCustomerHighlightsById = exports.getCustomerById = void 0;
16
+ const axiosInstance_1 = __importDefault(require("../axiosInstance"));
17
+ const GET_SET_CUSTOMERS = 'api/customer';
18
+ const REQUEST_PARAMS = {
19
+ token: 'LOGGED_USER_TOKEN',
20
+ };
21
+ const getCustomerById = function (customerId) {
22
+ return __awaiter(this, void 0, void 0, function* () {
23
+ try {
24
+ REQUEST_PARAMS.token = this.apiToken;
25
+ const response = yield axiosInstance_1.default.get(`${GET_SET_CUSTOMERS}/${customerId}`, { params: Object.assign({}, REQUEST_PARAMS) });
26
+ return response.data;
27
+ }
28
+ catch (error) {
29
+ console.error('Error fetching customer:', error);
30
+ throw error;
31
+ }
32
+ });
33
+ };
34
+ exports.getCustomerById = getCustomerById;
35
+ const getCustomerHighlightsById = function (customerId) {
36
+ return __awaiter(this, void 0, void 0, function* () {
37
+ try {
38
+ REQUEST_PARAMS.token = this.apiToken;
39
+ const response = yield axiosInstance_1.default.get(`${GET_SET_CUSTOMERS}/${customerId}/highlights`, { params: Object.assign({}, REQUEST_PARAMS) });
40
+ return response.data;
41
+ }
42
+ catch (error) {
43
+ console.error('Error fetching getCustomerHighlightsById:', error);
44
+ throw error;
45
+ }
46
+ });
47
+ };
48
+ exports.getCustomerHighlightsById = getCustomerHighlightsById;
@@ -1 +1 @@
1
- "use strict";
1
+ "use strict";
package/dist/api/index.js CHANGED
@@ -1,12 +1,17 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const get_1 = require("./customers/get");
4
- const WashdayClient = function WashdayClient(apiToken) {
5
- this.apiToken = apiToken;
6
- WashdayClient.prototype.customers.apiToken = apiToken;
7
- };
8
- WashdayClient.prototype.customers = {
9
- getCustomerById: get_1.getCustomerById,
10
- getCustomerHighlightsById: get_1.getCustomerHighlightsById
11
- };
12
- exports.default = WashdayClient;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const get_1 = require("./customers/get");
4
+ const get_2 = require("./stores/get");
5
+ const WashdayClient = function WashdayClient(apiToken) {
6
+ this.apiToken = apiToken;
7
+ WashdayClient.prototype.customers.apiToken = apiToken;
8
+ };
9
+ WashdayClient.prototype.customers = {
10
+ getCustomerById: get_1.getCustomerById,
11
+ getCustomerHighlightsById: get_1.getCustomerHighlightsById
12
+ };
13
+ WashdayClient.prototype.stores = {
14
+ getStores: get_2.getStores,
15
+ getStoreById: get_2.getStoreById
16
+ };
17
+ exports.default = WashdayClient;
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.getStoreById = exports.getStores = void 0;
16
+ const axiosInstance_1 = __importDefault(require("../axiosInstance"));
17
+ const GET_SET_STORES = 'api/store';
18
+ const REQUEST_PARAMS = {
19
+ token: 'LOGGED_USER_TOKEN',
20
+ };
21
+ const getStores = function () {
22
+ return __awaiter(this, void 0, void 0, function* () {
23
+ var _a, _b;
24
+ try {
25
+ REQUEST_PARAMS.token = this.apiToken;
26
+ const response = yield axiosInstance_1.default.get(`${GET_SET_STORES}`, { params: Object.assign({}, REQUEST_PARAMS) });
27
+ return ((_b = (_a = response.data) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.stores) || [];
28
+ }
29
+ catch (error) {
30
+ console.error('Error fetching getStores:', error);
31
+ throw error;
32
+ }
33
+ });
34
+ };
35
+ exports.getStores = getStores;
36
+ const getStoreById = function (storeId) {
37
+ return __awaiter(this, void 0, void 0, function* () {
38
+ var _a;
39
+ try {
40
+ REQUEST_PARAMS.token = this.apiToken;
41
+ const response = yield axiosInstance_1.default.get(`${GET_SET_STORES}/${storeId}`, { params: Object.assign({}, REQUEST_PARAMS) });
42
+ return ((_a = response.data) === null || _a === void 0 ? void 0 : _a.data) || {};
43
+ }
44
+ catch (error) {
45
+ console.error('Error fetching getStoreById:', error);
46
+ throw error;
47
+ }
48
+ });
49
+ };
50
+ exports.getStoreById = getStoreById;
@@ -1,15 +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 = {}));
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 CHANGED
@@ -1,33 +1,33 @@
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
- var __importDefault = (this && this.__importDefault) || function (mod) {
26
- return (mod && mod.__esModule) ? mod : { "default": mod };
27
- };
28
- Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.utils = exports.WashdayClient = void 0;
30
- const utils = __importStar(require("./utils"));
31
- exports.utils = utils;
32
- const api_1 = __importDefault(require("./api"));
33
- exports.WashdayClient = api_1.default;
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
+ var __importDefault = (this && this.__importDefault) || function (mod) {
26
+ return (mod && mod.__esModule) ? mod : { "default": mod };
27
+ };
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ exports.utils = exports.WashdayClient = void 0;
30
+ const utils = __importStar(require("./utils"));
31
+ exports.utils = utils;
32
+ const api_1 = __importDefault(require("./api"));
33
+ exports.WashdayClient = api_1.default;
@@ -1,2 +1,2 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1 +1 @@
1
- "use strict";
1
+ "use strict";
@@ -1,2 +1,2 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,2 +1,2 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,2 +1,2 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,2 +1,2 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,2 +1,2 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,2 +1,2 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,2 +1,2 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,2 +1,2 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,17 +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);
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);
@@ -1,33 +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;
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;
@@ -1,65 +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;
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;
@@ -1,74 +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;
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;
@@ -1,64 +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;
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;
@@ -1,5 +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; } });
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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "washday-sdk",
3
- "version": "0.0.10",
3
+ "version": "0.0.12",
4
4
  "description": "Washday utilities functions and API",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {