ok
This commit is contained in:
@@ -6,9 +6,9 @@ import reportWebVitals from './reportWebVitals';
|
|||||||
|
|
||||||
const root = ReactDOM.createRoot(document.getElementById('root'));
|
const root = ReactDOM.createRoot(document.getElementById('root'));
|
||||||
// Disable console methods
|
// Disable console methods
|
||||||
console.log = () => {};
|
// console.log = () => {};
|
||||||
console.warn = () => {};
|
// console.warn = () => {};
|
||||||
console.error = () => {};
|
// console.error = () => {};
|
||||||
|
|
||||||
root.render(
|
root.render(
|
||||||
<React.StrictMode>
|
<React.StrictMode>
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ export default function Transactions({ shop, shopId, propsShopId, sendParam, dev
|
|||||||
// response = await getMyTransactions(shopId || propsShopId, 5);
|
// response = await getMyTransactions(shopId || propsShopId, 5);
|
||||||
// setMyTransactions(response);
|
// setMyTransactions(response);
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
let response = await getTransactionsFromCafe(shopId || propsShopId, 5, false);
|
let response = await getTransactionsFromCafe(shopId || propsShopId, -1, false);
|
||||||
|
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
if (response) setTransactions(response);
|
if (response) setTransactions(response);
|
||||||
@@ -65,39 +65,45 @@ const calculateAllTransactionsTotal = (transactions) => {
|
|||||||
return grandTotal + calculateTotalPrice(transaction.DetailedTransactions);
|
return grandTotal + calculateTotalPrice(transaction.DetailedTransactions);
|
||||||
}, 0);
|
}, 0);
|
||||||
};
|
};
|
||||||
|
const searchAndAggregateItems = (transactions, searchTerm) => {
|
||||||
|
if (!searchTerm.trim()) return [];
|
||||||
|
|
||||||
const searchAndAggregateItems = (transactions, searchTerm) => {
|
const normalizedTerm = searchTerm.trim().toLowerCase();
|
||||||
if (!searchTerm.trim()) return [];
|
// Map with key = `${itemId}-${confirmedGroup}` to keep confirmed groups separate
|
||||||
|
const aggregatedItems = new Map();
|
||||||
|
|
||||||
const normalizedTerm = searchTerm.trim().toLowerCase();
|
transactions.forEach(transaction => {
|
||||||
const aggregatedItems = new Map();
|
// 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 => {
|
||||||
transaction.DetailedTransactions.forEach(detail => {
|
const itemName = detail.Item.name;
|
||||||
const itemName = detail.Item.name;
|
const itemNameLower = itemName.toLowerCase();
|
||||||
const itemNameLower = itemName.toLowerCase();
|
|
||||||
|
|
||||||
if (itemNameLower.includes(normalizedTerm)) {
|
if (itemNameLower.includes(normalizedTerm)) {
|
||||||
const key = detail.itemId;
|
// Combine itemId and confirmedGroup to keep them separated
|
||||||
|
const key = `${detail.itemId}-${confirmedGroup}`;
|
||||||
|
|
||||||
if (!aggregatedItems.has(key)) {
|
if (!aggregatedItems.has(key)) {
|
||||||
aggregatedItems.set(key, {
|
aggregatedItems.set(key, {
|
||||||
itemId: detail.itemId,
|
itemId: detail.itemId,
|
||||||
name: itemName,
|
name: itemName,
|
||||||
totalQty: 0,
|
totalQty: 0,
|
||||||
totalPrice: 0,
|
totalPrice: 0,
|
||||||
});
|
confirmedGroup, // Keep track of which group this belongs to
|
||||||
}
|
});
|
||||||
|
|
||||||
const current = aggregatedItems.get(key);
|
|
||||||
current.totalQty += detail.qty;
|
|
||||||
current.totalPrice += detail.qty * (detail.promoPrice || detail.price);
|
|
||||||
}
|
}
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
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) => {
|
const handleConfirm = async (transactionId) => {
|
||||||
@@ -166,8 +172,8 @@ const calculateAllTransactionsTotal = (transactions) => {
|
|||||||
|
|
||||||
{matchedItems.length > 0 && matchedItems.map(item => (
|
{matchedItems.length > 0 && matchedItems.map(item => (
|
||||||
<div
|
<div
|
||||||
key={item.itemId}
|
key={`${item.itemId}-${item.confirmedGroup}`}
|
||||||
className={styles.RoundedRectangle}
|
className={styles.RoundedRectangle}
|
||||||
style={{ overflow: "hidden" }}
|
style={{ overflow: "hidden" }}
|
||||||
>
|
>
|
||||||
<ul>
|
<ul>
|
||||||
|
|||||||
Reference in New Issue
Block a user