diff --git a/src/index.js b/src/index.js index a8e87ac..6b1560b 100644 --- a/src/index.js +++ b/src/index.js @@ -6,9 +6,9 @@ import reportWebVitals from './reportWebVitals'; const root = ReactDOM.createRoot(document.getElementById('root')); // Disable console methods -console.log = () => {}; -console.warn = () => {}; -console.error = () => {}; +// console.log = () => {}; +// console.warn = () => {}; +// console.error = () => {}; root.render( diff --git a/src/pages/Transactions.js b/src/pages/Transactions.js index 4be2dc0..9cb6de6 100644 --- a/src/pages/Transactions.js +++ b/src/pages/Transactions.js @@ -41,7 +41,7 @@ export default function Transactions({ shop, shopId, propsShopId, sendParam, dev // response = await getMyTransactions(shopId || propsShopId, 5); // setMyTransactions(response); setLoading(true); - let response = await getTransactionsFromCafe(shopId || propsShopId, 5, false); + let response = await getTransactionsFromCafe(shopId || propsShopId, -1, false); setLoading(false); if (response) setTransactions(response); @@ -65,39 +65,45 @@ const calculateAllTransactionsTotal = (transactions) => { return grandTotal + calculateTotalPrice(transaction.DetailedTransactions); }, 0); }; +const searchAndAggregateItems = (transactions, searchTerm) => { + if (!searchTerm.trim()) return []; - const searchAndAggregateItems = (transactions, searchTerm) => { - if (!searchTerm.trim()) return []; + const normalizedTerm = searchTerm.trim().toLowerCase(); + // Map with key = `${itemId}-${confirmedGroup}` to keep confirmed groups separate + const aggregatedItems = new Map(); - const normalizedTerm = searchTerm.trim().toLowerCase(); - const aggregatedItems = new Map(); + transactions.forEach(transaction => { + // Determine confirmed group as a string key + const confirmedGroup = transaction.confirmed >= 0 && transaction.confirmed > 1 ? 'confirmed_gt_1' : 'confirmed_le_1'; - transactions.forEach(transaction => { - transaction.DetailedTransactions.forEach(detail => { - const itemName = detail.Item.name; - const itemNameLower = itemName.toLowerCase(); + transaction.DetailedTransactions.forEach(detail => { + const itemName = detail.Item.name; + const itemNameLower = itemName.toLowerCase(); - if (itemNameLower.includes(normalizedTerm)) { - const key = detail.itemId; + if (itemNameLower.includes(normalizedTerm)) { + // Combine itemId and confirmedGroup to keep them separated + const key = `${detail.itemId}-${confirmedGroup}`; - if (!aggregatedItems.has(key)) { - aggregatedItems.set(key, { - itemId: detail.itemId, - name: itemName, - totalQty: 0, - totalPrice: 0, - }); - } - - const current = aggregatedItems.get(key); - current.totalQty += detail.qty; - current.totalPrice += detail.qty * (detail.promoPrice || detail.price); + if (!aggregatedItems.has(key)) { + aggregatedItems.set(key, { + itemId: detail.itemId, + name: itemName, + totalQty: 0, + totalPrice: 0, + confirmedGroup, // Keep track of which group this belongs to + }); } - }); - }); - return Array.from(aggregatedItems.values()); - }; + const current = aggregatedItems.get(key); + current.totalQty += detail.qty; + current.totalPrice += detail.qty * (detail.promoPrice || detail.price); + } + }); + }); +console.log(aggregatedItems.values()) + return Array.from(aggregatedItems.values()); +}; + const handleConfirm = async (transactionId) => { @@ -166,8 +172,8 @@ const calculateAllTransactionsTotal = (transactions) => { {matchedItems.length > 0 && matchedItems.map(item => (