ok
This commit is contained in:
@@ -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 => (
|
||||
<div
|
||||
key={item.itemId}
|
||||
className={styles.RoundedRectangle}
|
||||
key={`${item.itemId}-${item.confirmedGroup}`}
|
||||
className={styles.RoundedRectangle}
|
||||
style={{ overflow: "hidden" }}
|
||||
>
|
||||
<ul>
|
||||
|
||||
Reference in New Issue
Block a user