This commit is contained in:
client perkafean
2024-08-26 14:01:58 +00:00
parent 3a2e388a33
commit 082de83558
7 changed files with 66 additions and 26 deletions

View File

@@ -114,7 +114,7 @@ export default function Footer({
</span> </span>
{table.length == 0 && ( {table.length == 0 && (
<img <img
src="https://i.ibb.co.com/Pt2s8N8/qr-scan-icon-2048x2048-aeh36n7y.png" src="https://i.ibb.co.com/y0FWnbh/qr-scan-icon-2048x2048-aeh36n7y.png"
alt="QR Code" alt="QR Code"
className={styles.qrIcon} className={styles.qrIcon}
/> />

View File

@@ -314,14 +314,15 @@ const Header = ({
user.roleId === 1 && ( user.roleId === 1 && (
<> <>
<Child onClick={goToAdminCafes}>see your other cafes</Child> <Child onClick={goToAdminCafes}>see your other cafes</Child>
<Child onClick={() => setModal("add_material")}>
add material {/* <Child onClick={() => setModal("update_stock")}>
</Child>
<Child onClick={() => setModal("update_stock")}>
update stock update stock
</Child> </Child> */}
<Child hasChildren> <Child hasChildren>
{shopName} {shopName}
<Child onClick={() => setModal("add_material")}>
stock
</Child>
<Child onClick={() => setModal("edit_tables")}> <Child onClick={() => setModal("edit_tables")}>
table maps table maps
</Child> </Child>

View File

@@ -117,7 +117,7 @@
.expand-button h5 { .expand-button h5 {
font-weight: 500; font-weight: 500;
margin-top: 0px; margin-top: 0px;
text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.36); text-shadow: 0px 0px 6px rgba(0, 0, 0, 0.36);
} }
.expand-button:hover { .expand-button:hover {

View File

@@ -319,7 +319,7 @@ export const getFavourite = async (cafeId) => {
export const getAnalytics = async (cafeId) => { export const getAnalytics = async (cafeId) => {
const response = await fetch( const response = await fetch(
`${API_BASE_URL}/transaction/get-analytics/${cafeId}`, `${API_BASE_URL}/transaction/get-income/${cafeId}`,
getHeaders() getHeaders()
); );
return response.json(); return response.json();

View File

@@ -4,7 +4,14 @@ import { getFavourite, getAnalytics } from "../helpers/transactionHelpers.js";
import CircularDiagram from "./CircularDiagram"; import CircularDiagram from "./CircularDiagram";
import styles from "./Transactions.module.css"; import styles from "./Transactions.module.css";
const RoundedRectangle = ({ bgColor, title, value, percentage }) => { const RoundedRectangle = ({
onClick,
bgColor,
title,
value,
percentage,
fontSize = "20px",
}) => {
const containerStyle = { const containerStyle = {
display: "flex", display: "flex",
flexDirection: "column", flexDirection: "column",
@@ -36,7 +43,7 @@ const RoundedRectangle = ({ bgColor, title, value, percentage }) => {
}; };
const valueStyle = { const valueStyle = {
fontSize: "20px", fontSize: fontSize,
fontWeight: "bold", fontWeight: "bold",
flex: "1", flex: "1",
textAlign: "left", textAlign: "left",
@@ -59,6 +66,7 @@ const RoundedRectangle = ({ bgColor, title, value, percentage }) => {
...containerStyle, ...containerStyle,
backgroundColor: bgColor, backgroundColor: bgColor,
}} }}
onClick={onClick}
> >
<div style={titleStyle}>{title}</div> <div style={titleStyle}>{title}</div>
<div style={valueAndPercentageContainerStyle}> <div style={valueAndPercentageContainerStyle}>
@@ -69,8 +77,13 @@ const RoundedRectangle = ({ bgColor, title, value, percentage }) => {
color: percentage > 0 ? "#007bff" : "red", color: percentage > 0 ? "#007bff" : "red",
}} }}
> >
{percentage}% {percentage}
<span style={arrowStyle}>{percentage > 0 ? "↗" : ""}</span> {percentage != undefined && "%"}
{percentage != undefined && (
<span style={arrowStyle}>
{percentage > 0 ? "↗" : percentage == 0 ? "-" : "↘"}
</span>
)}
</div> </div>
</div> </div>
</div> </div>
@@ -83,6 +96,7 @@ const App = ({ cafeId }) => {
const [loading, setLoading] = useState(true); const [loading, setLoading] = useState(true);
const [filter, setFilter] = useState("monthly"); // Default filter is 'monthly' const [filter, setFilter] = useState("monthly"); // Default filter is 'monthly'
const [colors, setColors] = useState([]); const [colors, setColors] = useState([]);
const [viewStock, setViewStock] = useState(false);
useEffect(() => { useEffect(() => {
const fetchData = async () => { const fetchData = async () => {
@@ -92,6 +106,7 @@ const App = ({ cafeId }) => {
const analyticsData = await getAnalytics(cafeId); const analyticsData = await getAnalytics(cafeId);
if (items) setFavouriteItems(items); if (items) setFavouriteItems(items);
if (analyticsData) setAnalytics(analyticsData); if (analyticsData) setAnalytics(analyticsData);
console.log(analyticsData);
} catch (error) { } catch (error) {
console.error("Error fetching data:", error); console.error("Error fetching data:", error);
} finally { } finally {
@@ -140,6 +155,25 @@ const App = ({ cafeId }) => {
color: colors[index] || "#cccccc", color: colors[index] || "#cccccc",
})); }));
const formatIncome = (amount) => {
if (amount >= 1_000_000_000) {
// Format for billions
const billions = amount / 1_000_000_000;
return billions.toFixed(0) + "b"; // No decimal places for billions
} else if (amount >= 1_000_000) {
// Format for millions
const millions = amount / 1_000_000;
return millions.toFixed(2).replace(/\.00$/, "") + "m"; // Two decimal places, remove trailing '.00'
} else if (amount >= 1_000) {
// Format for thousands
const thousands = amount / 1_000;
return thousands.toFixed(1).replace(/\.0$/, "") + "k"; // One decimal place, remove trailing '.0'
} else {
// Less than a thousand
return amount.toString();
}
};
return ( return (
<div className={styles.Transactions} style={{ backgroundColor: "#cfcfcf" }}> <div className={styles.Transactions} style={{ backgroundColor: "#cfcfcf" }}>
<h2 className={styles["Transactions-title"]}>Reports</h2> <h2 className={styles["Transactions-title"]}>Reports</h2>
@@ -210,18 +244,23 @@ const App = ({ cafeId }) => {
/> />
)} )}
{filteredItems[0]?.Item == undefined && ( {filteredItems[0]?.Item == undefined && (
<RoundedRectangle bgColor="#E5ECF6" value={"No item"} /> <RoundedRectangle
bgColor="#8989897a"
title={"No fav item"}
value={"-"}
/>
)} )}
<RoundedRectangle <RoundedRectangle
bgColor="#E5ECF6" bgColor={viewStock ? "#979797" : "#E5ECF6"}
title="Transactions" title="Stok"
value={sold} value={viewStock ? ' ˅' : ' ˄'} // Corrected ternary operator syntax
percentage={percentage} onClick={() => setViewStock(!viewStock)} // onClick should be a function
/> />
<RoundedRectangle <RoundedRectangle
bgColor="#E3F5FF" bgColor="#E3F5FF"
title="Transactions" title="Income"
value={sold} fontSize="12px"
value={"Rp" + formatIncome(512520000)}
percentage={percentage} percentage={percentage}
/> />
</div> </div>
@@ -243,7 +282,7 @@ const App = ({ cafeId }) => {
style={{ style={{
textAlign: "left", textAlign: "left",
color: colors[index], color: colors[index],
margin: "5px 0", margin: "10px 0",
}} }}
> >
{item.Item.name}: {item.sold} {item.Item.name}: {item.sold}

View File

@@ -125,8 +125,8 @@ export default function Transactions({ propsShopId, sendParam, deviceType }) {
</ul> </ul>
<h2 className={styles["Transactions-detail"]}> <h2 className={styles["Transactions-detail"]}>
{transaction.serving_type === "pickup" {transaction.serving_type === "pickup"
? "Diambil di kasir" ? "Self pickup"
: `Diantar ke meja nomor ${ : `Serve to ${
transaction.Table ? transaction.Table.tableNo : "N/A" transaction.Table ? transaction.Table.tableNo : "N/A"
}`} }`}
</h2> </h2>
@@ -145,11 +145,11 @@ export default function Transactions({ propsShopId, sendParam, deviceType }) {
{isPaymentLoading ? ( {isPaymentLoading ? (
<ColorRing height="50" width="50" color="white" /> <ColorRing height="50" width="50" color="white" />
) : transaction.confirmed === 1 ? ( ) : transaction.confirmed === 1 ? (
"Confirmed" // Display "Confirmed" if the transaction is confirmed (1) "Confirm has paid" // Display "Confirmed" if the transaction is confirmed (1)
) : transaction.confirmed === -1 ? ( ) : transaction.confirmed === -1 ? (
"Declined" // Display "Declined" if the transaction is declined (-1) "Declined" // Display "Declined" if the transaction is declined (-1)
) : ( ) : (
"Confirm" // Display "Confirm" if the transaction is not confirmed (0) "Confirm availability" // Display "Confirm" if the transaction is not confirmed (0)
)} )}
</button> </button>
</div> </div>

View File

@@ -4,7 +4,7 @@
background-color: white; background-color: white;
display: flex; display: flex;
flex-direction: column; flex-direction: column;
justify-content: center; justify-content: flex-start;
font-size: calc(10px + 2vmin); font-size: calc(10px + 2vmin);
color: rgba(88, 55, 50, 1); color: rgba(88, 55, 50, 1);
background-color: #e9e9e9; background-color: #e9e9e9;
@@ -18,7 +18,7 @@
color: rgba(88, 55, 50, 1); color: rgba(88, 55, 50, 1);
text-align: left; text-align: left;
margin-left: 20px; margin-left: 20px;
margin-top: 17px; margin-top: 30px;
} }
.Transactions-detail { .Transactions-detail {