This commit is contained in:
zadit
2025-01-06 02:06:30 +07:00
parent 59a9d299c5
commit 918c923143
8 changed files with 219 additions and 50 deletions

View File

@@ -27,8 +27,26 @@
flex-grow: 1; flex-grow: 1;
text-align: center; text-align: center;
padding: 10px; padding: 10px;
border-radius: 10px 10px 0 0;
transition: all 0.3s ease-in-out; transition: all 0.3s ease-in-out;
font-weight: 600;
}
.dateSelector:first-child {
flex-grow: 1;
text-align: center;
padding: 10px;
border-radius: 10px 0 0 0;
transition: all 0.3s ease-in-out;
font-weight: 600;
}
.dateSelector:last-child {
flex-grow: 1;
text-align: center;
padding: 10px;
border-radius: 0 10px 0 0;
transition: all 0.3s ease-in-out;
font-weight: 600;
} }
.dateSelectorActive { .dateSelectorActive {
@@ -43,5 +61,6 @@
.chartWrapper { .chartWrapper {
border: 1px solid rgb(179, 177, 177); border: 1px solid rgb(179, 177, 177);
border-radius: 0 0 11px 11px;
} }

View File

@@ -2,7 +2,7 @@ import React, { useState, useEffect } from "react";
import Chart from "react-apexcharts"; import Chart from "react-apexcharts";
import styles from "./BarChart.module.css"; // Import the CSS module import styles from "./BarChart.module.css"; // Import the CSS module
const BarChart = ({ transactionGraph, colors, type, aggregatedReports }) => { const DailyCharts = ({ transactionGraph, colors, type }) => {
const [selectedIndex, setSelectedIndex] = useState(-1); const [selectedIndex, setSelectedIndex] = useState(-1);
useEffect(() => { useEffect(() => {
@@ -12,20 +12,6 @@ const BarChart = ({ transactionGraph, colors, type, aggregatedReports }) => {
const processData = (graphData) => { const processData = (graphData) => {
if (!graphData) return null; if (!graphData) return null;
return graphData.map((dayData) => { return graphData.map((dayData) => {
const monthly = [
"minggu 1",
"minggu 2",
"minggu 3",
"minggu 4",
];
const yearly = [
"Q1",
"Q2",
"Q3",
"Q4",
];
const categories = [ const categories = [
"0-3", "0-3",
"3-6", "3-6",
@@ -103,12 +89,15 @@ const BarChart = ({ transactionGraph, colors, type, aggregatedReports }) => {
key={indexx} key={indexx}
className={`${styles.dateSelector} ${index === indexx ? styles.dateSelectorActive : styles.dateSelectorInactive className={`${styles.dateSelector} ${index === indexx ? styles.dateSelectorActive : styles.dateSelectorInactive
}`} }`}
style={{border: (index==0||index==1) && selectedIndex != index && selectedIndex != indexx || selectedIndex ==-1 && index == 0 || selectedIndex == index && index == indexx ?
'1px solid rgb(179, 177, 177)' : 'none' }}
onClick={() => onClick={() =>
selectedIndex !== index ? setSelectedIndex(index) : setSelectedIndex(-1) type == 'yesterday' && selectedIndex == -1 || type != 'yesterday' && selectedIndex !== index ? setSelectedIndex(index) : setSelectedIndex(-1)
} }
style={{ backgroundColor: index === indexx ? colors[index % colors.length] : 'transparent' }} // style={{ backgroundColor: index === indexx ? colors[index % colors.length] : 'transparent' }}
> >
<div> <div
style={{ color: index === indexx ? colors[index % colors.length] : 'transparent' }}>
{indexx !== chartData.length - 1 ? ( {indexx !== chartData.length - 1 ? (
<> <>
{day}{" "} {day}{" "}
@@ -126,6 +115,7 @@ const BarChart = ({ transactionGraph, colors, type, aggregatedReports }) => {
<div className={styles.chartWrapper}> <div className={styles.chartWrapper}>
<Chart <Chart
options={{ options={{
tooltip: { enabled: false },
chart: { chart: {
id: `chart-${index}`, id: `chart-${index}`,
type: "area", type: "area",
@@ -173,4 +163,4 @@ const BarChart = ({ transactionGraph, colors, type, aggregatedReports }) => {
); );
}; };
export default BarChart; export default DailyCharts;

View File

@@ -316,7 +316,7 @@ const Header = ({
</Title> </Title>
<div style={{ visibility: showProfile ? "visible" : "hidden" }}> <div style={{ visibility: showProfile ? "visible" : "hidden" }}>
<ProfileImage <ProfileImage
src={user.username == undefined? shopImage : "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcS-DjX_bGBax4NL14ULvkAdU4FP3FKoWXWu5w&s"} src={user.username == undefined? shopImage || 'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcS-DjX_bGBax4NL14ULvkAdU4FP3FKoWXWu5w&s': "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcS-DjX_bGBax4NL14ULvkAdU4FP3FKoWXWu5w&s"}
alt="Profile" alt="Profile"
onClick={user.username !== undefined?handleImageClick: null} onClick={user.username !== undefined?handleImageClick: null}
animate={showRectangle && animate} animate={showRectangle && animate}

View File

@@ -271,7 +271,7 @@
height: 200px; height: 200px;
overflow: hidden; overflow: hidden;
border: 3px dashed #fbebcd; border: 3px dashed #fbebcd;
border-radius: 11px; border-radius: 11px 11px 0 0;
/* Flexbox for centering */ /* Flexbox for centering */
display: flex; display: flex;

View File

@@ -0,0 +1,156 @@
import React, { useState, useEffect } from "react";
import Chart from "react-apexcharts";
import styles from "./BarChart.module.css"; // Import the CSS module
const PeriodCharts = ({ type, aggregatedCurrentReports, aggregatedPreviousReports, colors }) => {
const [selectedIndex, setSelectedIndex] = useState(-1);
useEffect(() => {
setSelectedIndex(-1);
}, [aggregatedCurrentReports, aggregatedPreviousReports]);
const monthly = ["1 - 7", "8 - 14", "15 - 21", "22 - 28", "29 - 31"];
const yearly = ["Kuartal 1", "Kuartal 2", "Kuartal 3", "Kuartal 4"];
const cat = type == 'monthly' ? monthly : yearly;
// Map the data for the current reports
let currentIncomeData, currentOutcomeData, currentTransactionData, previousIncomeData, previousOutcomeData, previousTransactionData = null;
if (aggregatedCurrentReports) {
currentIncomeData = aggregatedCurrentReports.map((report) => report.income);
currentOutcomeData = aggregatedCurrentReports.map((report) => report.outcome);
currentTransactionData = aggregatedCurrentReports.map((report) => report.transactions);
}
if (aggregatedPreviousReports) {
// Map the data for the previous reports
previousIncomeData = aggregatedPreviousReports.map((report) => report.income);
previousOutcomeData = aggregatedPreviousReports.map((report) => report.outcome);
previousTransactionData = aggregatedPreviousReports.map((report) => report.transactions);
}
let globalMax = null;
if (aggregatedCurrentReports || aggregatedPreviousReports)
// Find the global maximum for the y-axis
globalMax = Math.max(
// ...currentIncomeData,
// ...currentOutcomeData,
...currentTransactionData,
// ...previousIncomeData,
// ...previousOutcomeData,
...previousTransactionData
);
return (
<div className={styles.chartItemContainer}>
{aggregatedPreviousReports && (
<div className={`${styles.chartItemWrapper} ${selectedIndex !== -1 && selectedIndex !== 0
? styles.chartItemWrapperActive
: styles.chartItemWrapperInactive
}`}>
<div className={styles.dateSelectorWrapper}>
<div className={styles.dateSelector}
onClick={() =>
selectedIndex === -1 ? setSelectedIndex(0) : setSelectedIndex(-1)
}
style={{border: '1px solid rgb(179, 177, 177)', color: colors[0]}}
>
<div>{type == 'monthly' ? 'bulan lalu' : 'tahun lalu'}</div>
</div>
<div
className={`${styles.dateSelector} ${styles.dateSelectorInactive
}`}
onClick={() =>
selectedIndex === 0 ? setSelectedIndex(-1) : setSelectedIndex(1)
}>
<div>{type == 'monthly' ? 'bulan ini' : 'tahun ini'}</div>
</div>
</div>
<div className={styles.chartWrapper}>
<Chart
options={{
tooltip: { enabled: false },
chart: { type: "area", zoom: { enabled: false }, toolbar: { show: false } },
xaxis: {
categories: cat,
axisBorder: {
show: false, // Removes the x-axis line
},
axisTicks: {
show: false, // Removes the ticks on the x-axis
},
},
yaxis: { max: globalMax, min: 0, labels: { style: { colors: "transparent" } } },
grid: { show: false },
fill: { opacity: 0.5 },
colors: [colors[0]],
}}
series={[
// { name: "Pemasukan", data: previousIncomeData },
// { name: "Pengaluaran", data: previousOutcomeData },
{ name: "Total transaksi", data: previousTransactionData },
]}
type="area"
height={200}
width="100%"
/>
</div>
</div>
)}
{aggregatedCurrentReports && (
<div className={`${styles.chartItemWrapper} ${selectedIndex !== -1 && selectedIndex !== 1
? styles.chartItemWrapperActive
: styles.chartItemWrapperInactive
}`}>
<div className={styles.dateSelectorWrapper}>
<div
className={`${styles.dateSelector} ${styles.dateSelectorInactive
}`}
onClick={() =>
selectedIndex === 1 ? setSelectedIndex(-1) : setSelectedIndex(0)
}>
<div>{type == 'monthly' ? 'bulan lalu' : 'tahun lalu'}</div>
</div>
<div className={styles.dateSelector}
onClick={() =>
selectedIndex === -1 ? setSelectedIndex(1) : setSelectedIndex(-1)
}
style={{border: '1px solid rgb(179, 177, 177)', color: colors[1]}}>
<div>{type == 'monthly' ? 'bulan ini' : 'tahun ini'}</div>
</div>
</div>
<div className={styles.chartWrapper}>
<Chart
options={{
tooltip: { enabled: false },
chart: { type: "area", zoom: { enabled: false }, toolbar: { show: false } },
xaxis: {
categories: cat,
axisBorder: {
show: false, // Removes the x-axis line
},
axisTicks: {
show: false, // Removes the ticks on the x-axis
}, },
yaxis: { max: globalMax, min: 0, labels: { style: { colors: "transparent" } } },
grid: { show: false },
fill: { opacity: 0.5 },
colors: [colors[1]],
}}
series={[
// { name: "Pemasukan", data: currentIncomeData },
// { name: "Pengeluaran", data: currentOutcomeData },
{ name: "Total transaksi", data: currentTransactionData },
]}
type="area"
height={200}
width="100%"
/>
</div>
</div>
)}
</div>
);
};
export default PeriodCharts;

View File

@@ -10,7 +10,7 @@ import { ThreeDots } from "react-loader-spinner";
import Header from '../components/Header'; import Header from '../components/Header';
import CircularDiagram from "./CircularDiagram"; import CircularDiagram from "./CircularDiagram";
import API_BASE_URL from '../config'; import API_BASE_URL from '../config';
import BarChart from '../components/BarChart'; import DailyCharts from '../components/DailyCharts';
const LinktreePage = ({ user, setModal }) => { const LinktreePage = ({ user, setModal }) => {
const navigate = useNavigate(); const navigate = useNavigate();
@@ -746,7 +746,7 @@ const sortedMaterials = allMaterials.sort((a, b) => new Date(a.date) - new Date(
</div> </div>
<h3>penambahan stok</h3> <h3>penambahan stok</h3>
<BarChart Data={selectedItems?.report?.materialsPurchased || sortedMaterials} /> <DailyCharts Data={selectedItems?.report?.materialsPurchased || sortedMaterials} />
<div style={{ height: '24vh' }}></div> <div style={{ height: '24vh' }}></div>
</div> </div>

View File

@@ -325,7 +325,6 @@ const MaterialList = ({ cafeId, handleClose }) => {
)} )}
<div style={styles.cardContent}> <div style={styles.cardContent}>
<h3 style={styles.cardTitle}>{currentMaterial.name}</h3> <h3 style={styles.cardTitle}>{currentMaterial.name}</h3>
<p>{currentMaterial.unit}</p>
</div> </div>
<div style={styles.buttonContainer}> <div style={styles.buttonContainer}>
<button <button
@@ -542,10 +541,10 @@ const styles = {
marginBottom: "5px", marginBottom: "5px",
}, },
image: { image: {
width: "250px", width: "100px",
height: "150px", height: "100px",
borderRadius: '50%',
objectFit: "contain", objectFit: "contain",
borderRadius: "8px",
marginBottom: "10px", marginBottom: "10px",
}, },
error: { error: {

View File

@@ -7,7 +7,8 @@ import styles from "./Transactions.module.css";
import "./Switch.css"; import "./Switch.css";
import MultiSwitch from "react-multi-switch-toggle"; import MultiSwitch from "react-multi-switch-toggle";
import BarChart from '../components/BarChart'; import DailyCharts from '../components/DailyCharts.js';
import PeriodCharts from '../components/PeriodCharts.js';
const RoundedRectangle = ({ const RoundedRectangle = ({
onClick, onClick,
@@ -128,28 +129,28 @@ const App = ({ cafeId,
const filteredItems = analytics.itemSales || []; const filteredItems = analytics.itemSales || [];
const colors = [ const colors = [
"#FF0000", // Red "#E63946", // Bright Red
"#FF6F00", // Dark Orange "#F4A261", // Soft Orange
"#FFD700", // Gold "#FFD166", // Sunshine Yellow
"#32CD32", // Lime Green "#06D6A0", // Mint Green
"#00CED1", // Dark Turquoise "#118AB2", // Rich Teal
"#1E90FF", // Dodger Blue "#9D4EDD", // Vivid Violet
"#8A2BE2", // BlueViolet "#FF66B3", // Bubblegum Pink
"#FF00FF", // Magenta "#FF7F50", // Coral
"#FF1493", // Deep Pink "#FFA07A", // Light Salmon
"#FF4500", // OrangeRed "#F7CAD0", // Blush Pink
"#FFDAB9", // Peach Puff "#A8DADC", // Aqua Blue
"#4B0082", // Indigo "#457B9D", // Steel Blue
"#00FF7F", // Spring Green "#2A9D8F", // Jungle Green
"#C71585", // Medium Violet Red "#FFB703", // Mustard Yellow
"#F0E68C", // Khaki "#E9C46A", // Honey Gold
"#FF6347", // Tomato "#264653", // Charcoal Green
"#006400", // Dark Green "#D4A5A5", // Rose Beige
"#8B4513", // SaddleBrown "#A6D6F0", // Sky Blue
"#00BFFF", // Deep Sky Blue "#BC4749", // Cranberry Red
"#FF69B4", // Hot Pink
]; ];
const segments = filteredItems.map((item, index) => ({ const segments = filteredItems.map((item, index) => ({
percentage: item.percentage, percentage: item.percentage,
color: colors[index] || "#cccccc", color: colors[index] || "#cccccc",
@@ -321,7 +322,11 @@ const App = ({ cafeId,
))} ))}
</div> </div>
</div> </div>
<BarChart transactionGraph={analytics?.transactionGraph} type={analytics?.type} aggregatedReports={analytics?.aggregatedReports} colors={colors}/> {filter == 'yesterday' || filter == 'weekly' ?
<DailyCharts transactionGraph={analytics?.transactionGraph} type={filter} colors={colors}/>
:
<PeriodCharts type={filter} aggregatedCurrentReports={analytics?.aggregatedCurrentReports} aggregatedPreviousReports={analytics?.aggregatedPreviousReports} colors={colors}/>
}
</div> </div>
<div class="ItemLister_PaymentOption__YZlDL"><div style={{ marginTop: '20px' }} onClick={handleClose} class="ItemLister_Pay2Button__+MIxX">Kembali</div></div> <div class="ItemLister_PaymentOption__YZlDL"><div style={{ marginTop: '20px' }} onClick={handleClose} class="ItemLister_Pay2Button__+MIxX">Kembali</div></div>
</div> </div>