@homefile/components-v2 2.36.17 → 2.36.19
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,10 +1,11 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { t } from 'i18next';
|
|
3
3
|
import { Box, Divider, Flex, IconButton, Image, Text } from '@chakra-ui/react';
|
|
4
|
-
import { formatDate } from '../../../utils';
|
|
4
|
+
import { formatDate, toQuantity } from '../../../utils';
|
|
5
5
|
import { DetailsColumn, Edit, PdfButton } from '../../../components';
|
|
6
6
|
import { getReceiptOrigin } from '../../../helpers';
|
|
7
7
|
export const ReceiptDetails = ({ name, cashier = '', itemQuantity, paymentMethod, purchaseDate, tax, store, origin = "", storePhone = '', total, onEdit, onFileClick }) => {
|
|
8
|
+
const quantity = toQuantity(itemQuantity);
|
|
8
9
|
const storeImage = getReceiptOrigin(origin);
|
|
9
10
|
const leftLabels = t('receipts.columnLeft').split(',');
|
|
10
11
|
const rightLabels = t('receipts.columnRight').split(',');
|
|
@@ -25,7 +26,7 @@ export const ReceiptDetails = ({ name, cashier = '', itemQuantity, paymentMethod
|
|
|
25
26
|
const rightColumn = [
|
|
26
27
|
{
|
|
27
28
|
label: rightLabels[0],
|
|
28
|
-
value:
|
|
29
|
+
value: quantity,
|
|
29
30
|
},
|
|
30
31
|
{
|
|
31
32
|
label: rightLabels[1],
|
|
@@ -5,13 +5,13 @@ interface UseDisplayReceiptsI {
|
|
|
5
5
|
export declare const useDisplayReceipts: ({ receipts }: UseDisplayReceiptsI) => {
|
|
6
6
|
formattedReceipts: {
|
|
7
7
|
total: string;
|
|
8
|
+
itemQuantity: number | "";
|
|
8
9
|
__v?: number;
|
|
9
10
|
_id: string;
|
|
10
11
|
assignStatus?: import("../../interfaces").ReceiptAssignStatusProps;
|
|
11
12
|
cashier?: string;
|
|
12
13
|
createAt?: Date;
|
|
13
14
|
home?: string | null;
|
|
14
|
-
itemQuantity: number | string;
|
|
15
15
|
name?: string;
|
|
16
16
|
paymentMethod: string;
|
|
17
17
|
purchaseDate?: Date;
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import { formatCurrency } from '../../utils';
|
|
1
|
+
import { formatCurrency, toQuantity } from '../../utils';
|
|
2
2
|
export const useDisplayReceipts = ({ receipts }) => {
|
|
3
3
|
const formattedReceipts = receipts.map((receipt) => {
|
|
4
|
-
const { total } = receipt;
|
|
5
|
-
const
|
|
6
|
-
|
|
4
|
+
const { total, itemQuantity } = receipt;
|
|
5
|
+
const numericTotal = total.replace(/[^0-9.-]/g, "");
|
|
6
|
+
const totalFormatted = formatCurrency({ value: numericTotal });
|
|
7
|
+
const quantity = toQuantity(itemQuantity);
|
|
8
|
+
return Object.assign(Object.assign({}, receipt), { total: totalFormatted, itemQuantity: quantity });
|
|
7
9
|
});
|
|
8
10
|
return { formattedReceipts };
|
|
9
11
|
};
|
|
@@ -25,6 +25,7 @@ interface FormatCurrencyI {
|
|
|
25
25
|
value: string | number;
|
|
26
26
|
}
|
|
27
27
|
export declare const formatISODate: (value: string) => string;
|
|
28
|
+
export declare const toQuantity: (q: string | number | null | undefined) => number | "";
|
|
28
29
|
export declare const formatCurrency: ({ country, currrency, value, }: FormatCurrencyI) => string;
|
|
29
30
|
export declare const formatCurrencyWithoutDigits: ({ country, currrency, value, }: FormatCurrencyI) => string;
|
|
30
31
|
export declare const formatNumber: (value: string | number) => string | 0;
|
|
@@ -109,6 +109,17 @@ export const formatISODate = (value) => {
|
|
|
109
109
|
: '';
|
|
110
110
|
return displayValue;
|
|
111
111
|
};
|
|
112
|
+
export const toQuantity = (q) => {
|
|
113
|
+
if (typeof q === "number")
|
|
114
|
+
return Number.isFinite(q) ? q : "";
|
|
115
|
+
const cleaned = (q !== null && q !== void 0 ? q : "")
|
|
116
|
+
.toString()
|
|
117
|
+
.replace(/\D/g, ""); // remove all non-digits
|
|
118
|
+
if (!cleaned)
|
|
119
|
+
return ""; // no digits found
|
|
120
|
+
const n = Number(cleaned);
|
|
121
|
+
return Number.isInteger(n) && n > 0 ? n : "";
|
|
122
|
+
};
|
|
112
123
|
export const formatCurrency = ({ country = 'en-US', currrency = 'USD', value, }) => {
|
|
113
124
|
if (!value) {
|
|
114
125
|
return Number(0).toLocaleString(country, {
|