ok
This commit is contained in:
@@ -26,9 +26,40 @@ export default function Transactions({ shopId, propsShopId, sendParam, deviceTyp
|
||||
try {
|
||||
let response;
|
||||
response = await getTransactionsFromCafe(shopId || propsShopId, 5, false);
|
||||
setTransactions(response);
|
||||
console.log(response)
|
||||
if(response) {
|
||||
setTransactions(response);
|
||||
return;
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Error fetching transactions:", error);
|
||||
}
|
||||
try {
|
||||
let response;
|
||||
response = await getMyTransactions(shopId || propsShopId, 5);
|
||||
setMyTransactions(response);
|
||||
console.log(response)
|
||||
const combinedTransactions = [];
|
||||
|
||||
response.forEach(cafe => {
|
||||
const { cafeId, name: cafeName, transactions } = cafe;
|
||||
|
||||
transactions.forEach(transaction => {
|
||||
const newTransaction = {
|
||||
...transaction,
|
||||
cafeId,
|
||||
cafeName,
|
||||
DetailedTransactions: transaction.detailedTransactions // Rename here
|
||||
};
|
||||
delete newTransaction.detailedTransactions; // Remove the old key
|
||||
combinedTransactions.push(newTransaction);
|
||||
});
|
||||
});
|
||||
|
||||
// combinedTransactions now contains all transactions with cafe info and renamed key
|
||||
console.log(combinedTransactions)
|
||||
|
||||
// combinedTransactions now contains all transactions with cafe info
|
||||
setTransactions(combinedTransactions);
|
||||
} catch (error) {
|
||||
console.error("Error fetching transactions:", error);
|
||||
}
|
||||
@@ -52,7 +83,7 @@ export default function Transactions({ shopId, propsShopId, sendParam, deviceTyp
|
||||
|
||||
const calculateTotalPrice = (detailedTransactions) => {
|
||||
return detailedTransactions.reduce((total, dt) => {
|
||||
return total + dt.qty * dt.Item.price;
|
||||
return total + dt.qty * (dt.promoPrice ? dt.promoPrice : dt.price);
|
||||
}, 0);
|
||||
};
|
||||
|
||||
@@ -118,7 +149,7 @@ export default function Transactions({ shopId, propsShopId, sendParam, deviceTyp
|
||||
<div className={styles['receipt-header']}>
|
||||
{transaction.confirmed === 1 ? (
|
||||
<ColorRing className={styles['receipt-logo']} />
|
||||
) : transaction.confirmed === -1 || transaction.confirmed === -2 ? (
|
||||
) : transaction.confirmed === -1 || transaction.confirmed === -2 ? (
|
||||
<div style={{ display: 'flex', justifyContent: 'center' }}>
|
||||
<svg
|
||||
style={{ width: '60px', transform: 'Rotate(45deg)' }}
|
||||
@@ -140,7 +171,7 @@ export default function Transactions({ shopId, propsShopId, sendParam, deviceTyp
|
||||
) : transaction.confirmed === 3 ? (
|
||||
"Transaction success"
|
||||
) : (
|
||||
|
||||
|
||||
<ColorRing className={styles['receipt-logo']} />
|
||||
)}
|
||||
|
||||
@@ -184,7 +215,7 @@ export default function Transactions({ shopId, propsShopId, sendParam, deviceTyp
|
||||
{transaction.DetailedTransactions.map((detail) => (
|
||||
<li key={detail.detailedTransactionId}>
|
||||
<span>{detail.Item.name}</span> - {detail.qty} x Rp{" "}
|
||||
{detail.Item.price}
|
||||
{detail.promoPrice ? detail.promoPrice : detail.price}
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
@@ -195,7 +226,7 @@ export default function Transactions({ shopId, propsShopId, sendParam, deviceTyp
|
||||
}`}
|
||||
</h2>
|
||||
|
||||
{transaction.notes != "" && (
|
||||
{transaction.notes && (
|
||||
<>
|
||||
<div className={styles.NoteContainer}>
|
||||
<span>Note :</span>
|
||||
@@ -211,6 +242,7 @@ export default function Transactions({ shopId, propsShopId, sendParam, deviceTyp
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
|
||||
<div className={styles.TotalContainer}>
|
||||
<span>Total:</span>
|
||||
<span>
|
||||
|
||||
Reference in New Issue
Block a user