ok
This commit is contained in:
@@ -18,7 +18,7 @@ import ButtonWithReplica from "../components/ButtonWithReplica";
|
||||
dayjs.extend(utc);
|
||||
dayjs.extend(timezone);
|
||||
|
||||
export default function Transactions({ shop, shopId, propsShopId, sendParam, deviceType, paymentUrl, setModal }) {
|
||||
export default function Transactions({ shop, shopId, propsShopId, sendParam, deviceType, paymentUrl, setModal, newTransaction }) {
|
||||
const { shopIdentifier, tableId } = useParams();
|
||||
if (sendParam) sendParam({ shopIdentifier, tableId });
|
||||
|
||||
@@ -34,38 +34,38 @@ export default function Transactions({ shop, shopId, propsShopId, sendParam, dev
|
||||
setMatchedItems(searchAndAggregateItems(transactions, searchTerm));
|
||||
}, [searchTerm, transactions]);
|
||||
|
||||
|
||||
useEffect(() => {
|
||||
const fetchTransactions = async () => {
|
||||
try {
|
||||
|
||||
// response = await getMyTransactions(shopId || propsShopId, 5);
|
||||
// setMyTransactions(response);
|
||||
setLoading(true);
|
||||
let response = await getTransactionsFromCafe(shopId || propsShopId, 5, false);
|
||||
|
||||
setLoading(false);
|
||||
if (response) setTransactions(response);
|
||||
|
||||
|
||||
// response = await getMyTransactions(shopId || propsShopId, 5);
|
||||
// setMyTransactions(response);
|
||||
} catch (error) {
|
||||
console.error("Error fetching transactions:", error);
|
||||
}
|
||||
};
|
||||
|
||||
fetchTransactions();
|
||||
}, [deviceType]);
|
||||
}, [deviceType, newTransaction]);
|
||||
|
||||
const calculateTotalPrice = (detailedTransactions) => {
|
||||
return detailedTransactions.reduce((total, dt) => {
|
||||
return total + dt.qty * (dt.promoPrice ? dt.promoPrice : dt.price);
|
||||
}, 0);
|
||||
};
|
||||
|
||||
const calculateAllTransactionsTotal = (transactions) => {
|
||||
return transactions.reduce((grandTotal, transaction) => {
|
||||
const calculateAllTransactionsTotal = (transactions) => {
|
||||
return transactions
|
||||
.filter(transaction => transaction.confirmed > 1) // Filter transactions where confirmed > 1
|
||||
.reduce((grandTotal, transaction) => {
|
||||
return grandTotal + calculateTotalPrice(transaction.DetailedTransactions);
|
||||
}, 0);
|
||||
};
|
||||
};
|
||||
|
||||
const searchAndAggregateItems = (transactions, searchTerm) => {
|
||||
if (!searchTerm.trim()) return [];
|
||||
|
||||
@@ -148,7 +148,7 @@ export default function Transactions({ shop, shopId, propsShopId, sendParam, dev
|
||||
return (
|
||||
<div className={styles.Transactions}>
|
||||
<h2 className={styles["Transactions-title"]}>
|
||||
Daftar transaksi Rp {calculateAllTransactionsTotal(transactions)}
|
||||
Transaksi selesai Rp {calculateAllTransactionsTotal(transactions)}
|
||||
</h2>
|
||||
|
||||
<input
|
||||
|
||||
Reference in New Issue
Block a user