washday-sdk 0.0.23 → 0.0.24
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/babel.config.js +7 -7
- package/dist/api/index.js +8 -2
- package/dist/api/products/get.js +7 -0
- package/dist/api/products/post.js +7 -0
- package/dist/api/products/put.js +36 -0
- package/dist/api/stores/post.js +37 -0
- package/dist/utils/receipt/generateReceiptHTML.js +157 -0
- package/dist/utils/util.js +46 -0
- package/package.json +29 -28
- package/src/api/axiosInstance.ts +46 -46
- package/src/api/customers/get.ts +32 -32
- package/src/api/index.ts +37 -29
- package/src/api/products/get.ts +9 -0
- package/src/api/products/post.ts +11 -0
- package/src/api/products/put.ts +21 -0
- package/src/api/stores/get.ts +36 -36
- package/src/api/stores/post.ts +23 -0
- package/src/api/stores/put.ts +20 -20
- package/src/enum/index.ts +10 -10
- package/src/index.ts +4 -4
- package/src/interfaces/Api.ts +2 -2
- package/src/interfaces/Customer.ts +51 -51
- package/src/interfaces/Order.ts +95 -95
- package/src/interfaces/Permission.ts +24 -24
- package/src/interfaces/Product.ts +58 -58
- package/src/interfaces/Section.ts +14 -14
- package/src/interfaces/Store.ts +350 -350
- package/src/interfaces/StoreImage.ts +9 -9
- package/src/interfaces/User.ts +42 -42
- package/src/utils/index.ts +1 -1
- package/src/utils/orders/calculateOrderTotal.test.js +399 -399
- package/src/utils/orders/calculateOrderTotal.ts +60 -60
- package/src/utils/orders/calculateTotalTaxesIncluded.ts +75 -75
- package/src/utils/orders/calculateTotalTaxesOverPrice.ts +82 -82
- package/src/utils/orders/helpers.ts +73 -73
- package/src/utils/orders/index.ts +4 -4
- package/src/utils/receipt/generateReceiptHTML.ts +163 -0
- package/src/utils/util.ts +47 -0
- package/tsconfig.json +9 -9
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
// import moment from "moment";
|
|
2
|
+
// import { formatMoneyString, truncateOrFill } from "../util";
|
|
3
|
+
|
|
4
|
+
// export const generateReceiptThermalPrinter = (order, storeSettings, ticketStructure, charsPerLine = 32) => {
|
|
5
|
+
// //THIS STRING IS FORMED WITH THE EXPECTED USE OF react-native-thermal-receipt-printer PACKAGE
|
|
6
|
+
|
|
7
|
+
// const PAPER_LINE_LENGTH = charsPerLine;
|
|
8
|
+
// const orderProducts = order?.products || [];
|
|
9
|
+
// const orderBuyAndGerProducts = order?.buyAndGetProducts || [];
|
|
10
|
+
// const orderAllProducts = [...orderProducts, ...orderBuyAndGerProducts];
|
|
11
|
+
|
|
12
|
+
// console.log('PAPER_LINE_LENGTH', PAPER_LINE_LENGTH);
|
|
13
|
+
// const paymentLinesTotal =
|
|
14
|
+
// order.paymentLines?.reduce((prev, next) => {
|
|
15
|
+
// return prev + (next?.amountPaid || 0);
|
|
16
|
+
// }, 0) || 0;
|
|
17
|
+
|
|
18
|
+
// let headers = `
|
|
19
|
+
// ${ticketStructure.showStoreName ? `<CM>${storeSettings.name}</CM>` : ''}
|
|
20
|
+
// ${ticketStructure.showStorePhone ? `Tel: ${storeSettings.phone}` : ''}
|
|
21
|
+
// ${'-'.repeat(PAPER_LINE_LENGTH)}
|
|
22
|
+
// ${ticketStructure.showEmisionDate
|
|
23
|
+
// ? `Fecha emision: ${moment(order?.createdDate).format('DD/MM/YYYY')}`
|
|
24
|
+
// : ''
|
|
25
|
+
// }
|
|
26
|
+
// ${ticketStructure.showEmisionTime
|
|
27
|
+
// ? `Hora emision: ${moment(order?.createdDate).format('hh:mm a')}`
|
|
28
|
+
// : ''
|
|
29
|
+
// }
|
|
30
|
+
// ${ticketStructure.showCreatedByName ? `Atendio: ${order.createdBy.name}` : ''}
|
|
31
|
+
// Pedido: WD-${order.sequence}
|
|
32
|
+
// ${ticketStructure.showCustomerName ? `Cliente: ${order.customer.name}` : ''}
|
|
33
|
+
// ${ticketStructure.showDeliveryDate
|
|
34
|
+
// ? `Entrega: ${moment(order?.deliveryInfo?.date).format('DD/MM/YYYY')} ${ticketStructure.showDeliveryTime
|
|
35
|
+
// ? moment(order?.deliveryInfo?.fromTime).format('HH:mm')
|
|
36
|
+
// : ''
|
|
37
|
+
// }`
|
|
38
|
+
// : ''
|
|
39
|
+
// }
|
|
40
|
+
// ${ticketStructure.showTotalPieces ? `Piezas: ${orderAllProducts?.reduce((prev, curr) => {
|
|
41
|
+
// return prev + +curr.pieces * curr.quantity;
|
|
42
|
+
// }, 0)}` : ''}
|
|
43
|
+
// ${ticketStructure.showOrderNotes && order.notes ? `${order.notes}` : ''}
|
|
44
|
+
// `;
|
|
45
|
+
// let middle = '';
|
|
46
|
+
// //Add order products
|
|
47
|
+
// orderAllProducts.forEach(prod => {
|
|
48
|
+
// //CHARS PER LINE: 32 in 58MM PAPER
|
|
49
|
+
// const quantityFixed = truncateOrFill(
|
|
50
|
+
// `x${prod.quantity.toString()}`,
|
|
51
|
+
// 3,
|
|
52
|
+
// 'right',
|
|
53
|
+
// );
|
|
54
|
+
// const prodNameFixed = truncateOrFill(
|
|
55
|
+
// prod.name,
|
|
56
|
+
// PAPER_LINE_LENGTH - 3 - 7 - 7 - 3,
|
|
57
|
+
// 'right',
|
|
58
|
+
// );
|
|
59
|
+
// const unitPriceFixed = truncateOrFill(
|
|
60
|
+
// formatMoneyString(
|
|
61
|
+
// (order?.express ? +prod.expressPrice : +prod.price) +
|
|
62
|
+
// (+prod.extraAmount / +prod.quantity || 0),
|
|
63
|
+
// ),
|
|
64
|
+
// 7,
|
|
65
|
+
// 'left',
|
|
66
|
+
// );
|
|
67
|
+
// const totalPriceFixed = truncateOrFill(
|
|
68
|
+
// formatMoneyString(
|
|
69
|
+
// (order?.express ? +prod.expressPrice : +prod.price) * +prod.quantity +
|
|
70
|
+
// (+prod.extraAmount || 0),
|
|
71
|
+
// ),
|
|
72
|
+
// 7,
|
|
73
|
+
// 'left',
|
|
74
|
+
// );
|
|
75
|
+
// middle =
|
|
76
|
+
// middle +
|
|
77
|
+
// `${quantityFixed} ${prodNameFixed} ${unitPriceFixed} ${totalPriceFixed}\n`;
|
|
78
|
+
// });
|
|
79
|
+
|
|
80
|
+
// let footer = '';
|
|
81
|
+
// footer =
|
|
82
|
+
// footer +
|
|
83
|
+
// `\n${truncateOrFill(
|
|
84
|
+
// 'Subtotal: ' +
|
|
85
|
+
// formatMoneyString(order.productTotalWithoutDiscount || 0),
|
|
86
|
+
// PAPER_LINE_LENGTH,
|
|
87
|
+
// 'left',
|
|
88
|
+
// )}`;
|
|
89
|
+
// if (ticketStructure.showDiscounts) {
|
|
90
|
+
// footer =
|
|
91
|
+
// footer +
|
|
92
|
+
// `\n${truncateOrFill(
|
|
93
|
+
// 'Descuento: ' + formatMoneyString(order.totalDiscountAmount || 0),
|
|
94
|
+
// PAPER_LINE_LENGTH,
|
|
95
|
+
// 'left',
|
|
96
|
+
// )}`;
|
|
97
|
+
// }
|
|
98
|
+
// if (ticketStructure.showCredit) {
|
|
99
|
+
// footer =
|
|
100
|
+
// footer +
|
|
101
|
+
// `\n${truncateOrFill(
|
|
102
|
+
// 'Credito: ' + formatMoneyString(order.creditApplied || 0),
|
|
103
|
+
// PAPER_LINE_LENGTH,
|
|
104
|
+
// 'left',
|
|
105
|
+
// )}`;
|
|
106
|
+
// }
|
|
107
|
+
// if (ticketStructure.showTaxes) {
|
|
108
|
+
// footer =
|
|
109
|
+
// footer +
|
|
110
|
+
// `\n${truncateOrFill(
|
|
111
|
+
// 'Impuestos: ' + formatMoneyString(order.taxesTotal || 0),
|
|
112
|
+
// PAPER_LINE_LENGTH,
|
|
113
|
+
// 'left',
|
|
114
|
+
// )}`;
|
|
115
|
+
// }
|
|
116
|
+
// footer =
|
|
117
|
+
// footer +
|
|
118
|
+
// `${order.delivery || order.pickup
|
|
119
|
+
// ? `\n${truncateOrFill(
|
|
120
|
+
// 'Servicio a domicilio: ' +
|
|
121
|
+
// formatMoneyString(order.shippingServiceTotal || 0),
|
|
122
|
+
// PAPER_LINE_LENGTH,
|
|
123
|
+
// 'left',
|
|
124
|
+
// )}`
|
|
125
|
+
// : ''
|
|
126
|
+
// }`;
|
|
127
|
+
// footer =
|
|
128
|
+
// footer +
|
|
129
|
+
// '\n' +
|
|
130
|
+
// `${truncateOrFill(
|
|
131
|
+
// 'Total: ' + formatMoneyString(order.total || 0),
|
|
132
|
+
// PAPER_LINE_LENGTH,
|
|
133
|
+
// 'left',
|
|
134
|
+
// )}`;
|
|
135
|
+
// footer =
|
|
136
|
+
// footer +
|
|
137
|
+
// '\n' +
|
|
138
|
+
// `${truncateOrFill(
|
|
139
|
+
// 'Pago: ' + formatMoneyString(paymentLinesTotal),
|
|
140
|
+
// PAPER_LINE_LENGTH,
|
|
141
|
+
// 'left',
|
|
142
|
+
// )}`;
|
|
143
|
+
// footer =
|
|
144
|
+
// footer +
|
|
145
|
+
// '\n' +
|
|
146
|
+
// `${truncateOrFill(
|
|
147
|
+
// 'Debe: ' + ((order.total || 0) - paymentLinesTotal).toFixed(2),
|
|
148
|
+
// PAPER_LINE_LENGTH,
|
|
149
|
+
// 'left',
|
|
150
|
+
// )}`;
|
|
151
|
+
// footer = footer + `\n${'-'.repeat(PAPER_LINE_LENGTH)}\n`;
|
|
152
|
+
// // footer = footer + `${ticketStructure.showPaymentMethod ? `<C>${translatePaymentType(order.paymentMethod)}</C>\n` : ''}`
|
|
153
|
+
// footer =
|
|
154
|
+
// footer +
|
|
155
|
+
// `${ticketStructure.showLegend
|
|
156
|
+
// ? `<C>${ticketStructure.ticketLegendText}</C>`
|
|
157
|
+
// : ''
|
|
158
|
+
// }`;
|
|
159
|
+
|
|
160
|
+
// const ticket = headers + '\n' + middle + '\n' + footer;
|
|
161
|
+
|
|
162
|
+
// return ticket;
|
|
163
|
+
// }
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
|
|
2
|
+
// export function truncateOrFill(str: string, n: number, side: string = 'right') {
|
|
3
|
+
// let needSpacesQty = n - str.length;
|
|
4
|
+
// let whiteSpace = '';
|
|
5
|
+
// if (needSpacesQty > 0) {
|
|
6
|
+
// for (let i = 0; i < needSpacesQty; i++) {
|
|
7
|
+
// whiteSpace += ' ';
|
|
8
|
+
// }
|
|
9
|
+
// }
|
|
10
|
+
// return str.length > n
|
|
11
|
+
// ? str.substr(0, n - 3) + '...'
|
|
12
|
+
// : side === 'right'
|
|
13
|
+
// ? str + whiteSpace
|
|
14
|
+
// : whiteSpace + str;
|
|
15
|
+
// }
|
|
16
|
+
|
|
17
|
+
// export const formatMoneyString = (
|
|
18
|
+
// amount: string | number = 0,
|
|
19
|
+
// decimalCount: number = 2,
|
|
20
|
+
// decimal = '.',
|
|
21
|
+
// thousands = ',',
|
|
22
|
+
// currencySymbol = '$',
|
|
23
|
+
// ) => {
|
|
24
|
+
// try {
|
|
25
|
+
// decimalCount = Math.abs(decimalCount);
|
|
26
|
+
// decimalCount = isNaN(decimalCount) ? 2 : decimalCount;
|
|
27
|
+
// const negativeSign = amount < 0 ? '-' : '';
|
|
28
|
+
// let i = parseInt(
|
|
29
|
+
// (amount = Math.abs(Number(amount) || 0).toFixed(decimalCount)),
|
|
30
|
+
// ).toString();
|
|
31
|
+
// let j = i.length > 3 ? i.length % 3 : 0;
|
|
32
|
+
// return (
|
|
33
|
+
// currencySymbol +
|
|
34
|
+
// negativeSign +
|
|
35
|
+
// (j ? i.substr(0, j) + thousands : '') +
|
|
36
|
+
// i.substr(j).replace(/(\d{3})(?=\d)/g, '$1' + thousands) +
|
|
37
|
+
// (decimalCount
|
|
38
|
+
// ? decimal +
|
|
39
|
+
// Math.abs(amount - i)
|
|
40
|
+
// .toFixed(decimalCount)
|
|
41
|
+
// .slice(2)
|
|
42
|
+
// : '')
|
|
43
|
+
// );
|
|
44
|
+
// } catch (e) {
|
|
45
|
+
// console.log(e);
|
|
46
|
+
// }
|
|
47
|
+
// };
|
package/tsconfig.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"target": "es6",
|
|
4
|
-
"module": "commonjs",
|
|
5
|
-
"outDir": "./dist",
|
|
6
|
-
"strict": true,
|
|
7
|
-
"esModuleInterop": true
|
|
8
|
-
},
|
|
9
|
-
"include": ["src/**/*.ts"]
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "es6",
|
|
4
|
+
"module": "commonjs",
|
|
5
|
+
"outDir": "./dist",
|
|
6
|
+
"strict": true,
|
|
7
|
+
"esModuleInterop": true
|
|
8
|
+
},
|
|
9
|
+
"include": ["src/**/*.ts"]
|
|
10
10
|
}
|