From fa5bab4d5f6bf8990bf0d1c939de3d72d5d5c3c9 Mon Sep 17 00:00:00 2001 From: zadit <75159257+insvrgent@users.noreply.github.com> Date: Mon, 3 Feb 2025 07:17:53 +0700 Subject: [PATCH] ok --- src/components/Coupon.js | 2 +- src/components/DailyCharts.js | 6 +- src/components/PeriodCharts.js | 44 +++++++----- src/pages/CreateUserWithCoupon.js | 2 +- src/pages/Join.js | 34 +++++++++- src/pages/Join.module.css | 2 + src/pages/Reports.js | 108 ++++++++++++++++++++++++++++-- src/pages/Transactions.module.css | 31 ++++++++- 8 files changed, 199 insertions(+), 30 deletions(-) diff --git a/src/components/Coupon.js b/src/components/Coupon.js index 38fc2ca..d083067 100644 --- a/src/components/Coupon.js +++ b/src/components/Coupon.js @@ -52,7 +52,7 @@ const Coupon = ({ code, value, period, type, expiration }) => { {/*
*/}
-

{code == null ? 'Voucher tidak ditemukan' : formattedValue}

+

{code == null ? 'Voucher tidak ada' : formattedValue}

{type && {type}} {/* Display type if provided */}

{code == null ? '-' : value === 0 ? `Masa berlangganan ${period} minggu` : `Masa Voucher ${period} minggu`} diff --git a/src/components/DailyCharts.js b/src/components/DailyCharts.js index 4b7cdd6..592e977 100644 --- a/src/components/DailyCharts.js +++ b/src/components/DailyCharts.js @@ -22,7 +22,7 @@ const DailyCharts = ({ transactionGraph, colors, type }) => { "18-21", "21-24", ]; - + console.log(dayData) const seriesData = [ dayData.hour0To3Transactions.reduce((acc, t) => acc + t.sold, 0), dayData.hour3To6Transactions.reduce((acc, t) => acc + t.sold, 0), @@ -75,7 +75,7 @@ const DailyCharts = ({ transactionGraph, colors, type }) => { }; return ( -

+
{chartData && chartData.map((data, index) => (
{ } // style={{ backgroundColor: index === indexx ? colors[index % colors.length] : 'transparent' }} > -
+
{indexx !== chartData.length - 1 ? ( diff --git a/src/components/PeriodCharts.js b/src/components/PeriodCharts.js index 18bb112..e8c68df 100644 --- a/src/components/PeriodCharts.js +++ b/src/components/PeriodCharts.js @@ -2,7 +2,7 @@ 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 PeriodCharts = ({ type, graphFilter, aggregatedCurrentReports, aggregatedPreviousReports, colors }) => { const [selectedIndex, setSelectedIndex] = useState(-1); useEffect(() => { @@ -20,6 +20,12 @@ const PeriodCharts = ({ type, aggregatedCurrentReports, aggregatedPreviousReport currentOutcomeData = aggregatedCurrentReports.map((report) => report.outcome); currentTransactionData = aggregatedCurrentReports.map((report) => report.transactions); + if (type == 'monthly' && currentIncomeData.length === 4) { + currentIncomeData.push(null); + } + if (type == 'monthly' && currentOutcomeData.length === 4) { + currentOutcomeData.push(null); + } if (type == 'monthly' && currentTransactionData.length === 4) { currentTransactionData.push(null); } @@ -30,21 +36,27 @@ const PeriodCharts = ({ type, aggregatedCurrentReports, aggregatedPreviousReport previousOutcomeData = aggregatedPreviousReports.map((report) => report.outcome); previousTransactionData = aggregatedPreviousReports.map((report) => report.transactions); + if (type == 'monthly' && previousIncomeData.length === 4) { + previousIncomeData.push(null); + } + if (type == 'monthly' && previousOutcomeData.length === 4) { + previousOutcomeData.push(null); + } if (type == 'monthly' && previousTransactionData.length === 4) { previousTransactionData.push(null); } } - let globalMax = null; - if (aggregatedCurrentReports || aggregatedPreviousReports) - // Find the global maximum for the y-axis - globalMax = Math.max( - // ...currentIncomeData, - // ...currentOutcomeData, - ...currentTransactionData, - // ...previousIncomeData, - // ...previousOutcomeData, - ...previousTransactionData - ); +let globalMax = null; +if (aggregatedCurrentReports || aggregatedPreviousReports) { + // Find the global maximum for the y-axis + globalMax = Math.max( + ...(graphFilter === 'income' + ? [...currentIncomeData, ...previousIncomeData] + : graphFilter === 'outcome' + ? [...currentOutcomeData, ...previousOutcomeData] + : [...currentTransactionData, ...previousTransactionData]) + ); +} return (
@@ -61,7 +73,7 @@ const PeriodCharts = ({ type, aggregatedCurrentReports, aggregatedPreviousReport } style={{ color: 'black', position: 'relative' }} > -
+
{type == 'monthly' ? 'bulan lalu' : 'tahun lalu'}
-
+
{type == 'monthly' ? 'bulan ini' : 'tahun ini'}
@@ -162,7 +174,7 @@ const PeriodCharts = ({ type, aggregatedCurrentReports, aggregatedPreviousReport series={[ // { name: "Pemasukan", data: currentIncomeData }, // { name: "Pengeluaran", data: currentOutcomeData }, - { name: "Total transaksi", data: currentTransactionData }, + { name: "Total transaksi", data: graphFilter == 'income' ? currentIncomeData : graphFilter == 'outcome' ? currentOutcomeData : currentTransactionData }, ]} type="area" height={200} diff --git a/src/pages/CreateUserWithCoupon.js b/src/pages/CreateUserWithCoupon.js index 883583b..efded44 100644 --- a/src/pages/CreateUserWithCoupon.js +++ b/src/pages/CreateUserWithCoupon.js @@ -114,7 +114,7 @@ const LinktreePage = ({ setModal }) => { /> setRetypePassword(e.target.value)} maxLength="30" diff --git a/src/pages/Join.js b/src/pages/Join.js index b23bacd..393b4f0 100644 --- a/src/pages/Join.js +++ b/src/pages/Join.js @@ -4,6 +4,9 @@ import styles from './Join.module.css'; // Import the module.css file import { checkCoupon, logCouponForUser } from '../helpers/couponHelpers'; // Import the new helper import Coupon from '../components/Coupon'; +import { + getLocalStorage, +} from "../helpers/localStorageHelpers"; const LinktreePage = ({ data, setModal }) => { const queryParams = new URLSearchParams(window.location.search); @@ -21,9 +24,24 @@ const LinktreePage = ({ data, setModal }) => { console.log(code) if (modal == 'claim-coupon') { + if (!getLocalStorage('auth')) { + + // Preserve the couponCode query param while navigating to the claim-coupon modal + const newUrl = `?modal=join${code ? `&couponCode=${code}` : ''}`; + window.location.href = newUrl; // This will update the URL and reload the page + } + setIsOnlyClaimCoupon(true) setIsUsingCoupon(true); // Automatically switch to the coupon input state } + else { + if (getLocalStorage('auth')) { + + // Preserve the couponCode query param while navigating to the claim-coupon modal + const newUrl = `?modal=claim-coupon${code ? `&couponCode=${code}` : ''}`; + window.location.href = newUrl; // This will update the URL and reload the page + } + } if (code) { setCouponCode(code); setIsUsingCoupon(true); // Automatically switch to the coupon input state @@ -104,9 +122,9 @@ const LinktreePage = ({ data, setModal }) => {
) : (
-
{isOnlyClaimCoupon ? 'Aktifkan Voucher' : 'Daftar Menggunakan Voucher'}
+
{isOnlyClaimCoupon ? 'Aktifkan Voucher' : 'Daftar Dengan Voucher'}
- Voucher dapat digunakan untuk pembuatan akun penyewa maupun untuk memperpanjang masa berlangganan. + Voucher dapat digunakan untuk pembuatan akun bisnis maupun untuk memperpanjang masa berlangganan.
{couponStatus === 0 ? (
e.preventDefault()}> @@ -152,7 +170,7 @@ const LinktreePage = ({ data, setModal }) => { } }} > - {isOnlyClaimCoupon ? 'Aktifkan untuk akun ini' : 'Buat akun dengan voucher ini'} + {isOnlyClaimCoupon ? 'Aktifkan untuk akun ini' : 'Buat akun bisnis dengan voucher ini'}
@@ -161,6 +179,16 @@ const LinktreePage = ({ data, setModal }) => { )}
+ {!getLocalStorage('auth') && + + Sudah punya akun bisnis? + +} { + const cafeTotal = (cafe.report?.materialSpend || []).reduce((sum, item) => sum + item.spend, 0); + return total + cafeTotal; + }, 0); + // Define a color palette or generate colors dynamically const colorPalette = colors; @@ -214,6 +221,42 @@ const App = ({ forCafe = true, cafeId = -1, segments.sort((a, b) => b.sold - a.sold); + + let materialSegments = (selectedCafeId == 0 || selectedCafeId == -1) ? filteredItems.flatMap((cafe) => { + const cafeItems = cafe.report?.materialSpend || []; + console.log(cafeItems); // Log all items for the cafe + + return cafeItems.map((item, index) => { + const percentage = totalSpendAcrossAllCafes > 0 + ? ((item.spend / totalSpendAcrossAllCafes) * 100).toFixed(2) + : 0; + + console.log(`${item.materialName}: ${(percentage)}%`); // Log item name and percentage + + // Assign a unique color from the color palette + const color = colorPalette[colorIndex % colorPalette.length]; // Use modulo to cycle through colors + + colorIndex++; // Increment to ensure a new color for the next item + + return { + itemName: item.materialName, + sold: item.spend, + percentage: percentage, + color: color, + }; + }); + }) : filteredItems.map((item, index) => { + const color = colorPalette[colorIndex % colorPalette.length]; // Use modulo to cycle through colors + colorIndex++; // Increment to ensure a new color for the next item + return { + itemName: item.materialName, + percentage: item.percentage, + color: color, + }; + }); + + materialSegments.sort((a, b) => b.spend - a.spend); + console.log(selectedCafeId) console.log(segments) @@ -474,23 +517,46 @@ const App = ({ forCafe = true, cafeId = -1, `Data dihitung dengan membandingkan ${comparisonText} hari terakhir dengan ${comparisonText} hari sebelumnya, dengan penghitungan dimulai dari data kemarin.` : - (filter == 'monthly') ? `Data dihitung dengan membandingkan antara awal hingga akhir bulan ini dan bulan lalu, dengan penghitungan dimulai dari data kemarin` : `Data dihitung dengan membandingkan antara awal hingga akhir tahun ini dan tahun lalu, dengan penghitungan dimulai dari data kemarin`} + (filter == 'monthly') ? `Data dihitung dengan membandingkan antara awal hingga akhir bulan ini dan bulan lalu, dengan penghitungan berakhir pada data kemarin.` : `Data dihitung dengan membandingkan antara awal hingga akhir tahun ini dan tahun lalu, dengan penghitungan berakhir pada data kemarin.`}
+ +
+
+ setCircularFilter('item') + } + style={{ color: 'black', position: 'relative' }} + > +
Item laku
+
+
+ setCircularFilter('material') + } + > +
Bahan baku
+
+
- +
- {segments.map((item, index) => ( + {(circularFilter === 'item' ? segments : materialSegments).map((item, index) => (
+ +
+
+ setGraphFilter('income') + } + style={{ color: 'black', position: 'relative' }} + > +
Pemasukan
+
+
+ setGraphFilter('outcome') + } + > +
Pengeluaran
+
+
+ setGraphFilter('transactions') + } + > +
Transaksi
+
+
{filter == 'yesterday' || filter == 'weekly' ? : - + }
} diff --git a/src/pages/Transactions.module.css b/src/pages/Transactions.module.css index 8b02582..452b59f 100644 --- a/src/pages/Transactions.module.css +++ b/src/pages/Transactions.module.css @@ -293,7 +293,7 @@ justify-content: space-around; position: relative; overflow: hidden; - width: calc(100vw - 30px); + width: calc(100vw - 50px); } .dateSelector { @@ -342,4 +342,33 @@ margin-bottom: 10px; width: 100%; height: 52px; +} + + +.filterSelectorWrapper { + display: flex; + justify-content: space-around; + position: relative; + overflow: hidden; + width: calc(100vw - 60px); + margin: 10px 30px 10px 30px; +} +.filterSelector { + flex-grow: 1; + padding: 6px; + width: calc(30vw - 30px); + background-color: #00000045; + border-radius: 20px; + font-size: 14px; + margin: 3px; +} +.filterSelectorInactive { + flex-grow: 1; + padding: 6px; + width: calc(30vw - 30px); + border-radius: 20px; + font-size: 14px; + margin: 3px; + background-color: white; + border: 1px solid black; } \ No newline at end of file