import React, { useState, useEffect } from 'react' import { Chart as ChartJS, CategoryScale, LinearScale, BarElement, Title, Tooltip, ArcElement, Legend, } from 'chart.js' import { Bar } from 'react-chartjs-2' import { Head, router } from '@inertiajs/react' import { usePrevious } from 'react-use' import moment from 'moment' import AuthenticatedLayout from '@/Layouts/AuthenticatedLayout' import { formatIDR } from '@/utils' import FormInputDateRanger from '@/Components/FormInputDateRange' import CustomerSelectionInput from './Customer/SelectionInput' import LocationSelectionInput from './Location/SelectionInput' import FormInputYearPicker from '@/Components/FormInputYearPicker' import Checkbox from '@/Components/Checkbox' ChartJS.register( CategoryScale, LinearScale, BarElement, Title, Tooltip, ArcElement, Legend ) export default function Dashboard(props) { const { deposites, sales, sales_deposit_charts, sales_paylater_charts, _dates, _startDate, _endDate, _payment, deposit_year_sale_charts, paylater_year_sale_charts, _year_payment, _months, _year, } = props // filter perhari const [payment, setPayment] = useState(_payment) const [dates, setDates] = useState({ startDate: _startDate, endDate: _endDate, }) const [customer_id, setCustomerId] = useState(null) const [location_id, setLocationId] = useState(null) // filter per tahun const [year_payment, setYearPayment] = useState(_year_payment) const [year, setYear] = useState(_year) const [year_customer_id, setYearCustomerId] = useState(null) const [year_location_id, setYearLocationId] = useState(null) // filter const preValue = usePrevious({ dates, customer_id, location_id, payment, year, year_customer_id, year_location_id, year_payment, }) const options = { responsive: true, scales: { x: {}, }, } const data = { labels: _dates.map((item) => moment(item.date, 'DD/MM/YYYY').format('DD MMM YYYY') ), datasets: [ { label: 'Penjualan (Rp) Deposit', data: sales_deposit_charts.map((item) => item.sale_total), backgroundColor: ['rgba(255, 205, 86, 1)'], }, { label: 'Penjualan (Rp) Hutang', data: sales_paylater_charts.map((item) => item.sale_total), backgroundColor: ['#b91c1c'], }, ], } const data_month = { labels: _months.map((item) => moment(item.month, 'MM').format('MMM')), datasets: [ { label: 'Penjualan (Rp) Deposit', data: deposit_year_sale_charts.map((item) => item.sale_total), backgroundColor: ['rgba(255, 205, 86, 1)'], }, { label: 'Penjualan (Rp) Hutang', data: paylater_year_sale_charts.map((item) => item.sale_total), backgroundColor: ['#b91c1c'], }, ], } useEffect(() => { if (preValue) { router.get( route(route().current()), { start_date: dates.startDate, end_date: dates.endDate, customer_id, location_id, payment, year, year_customer_id, year_location_id, year_payment, }, { replace: true, preserveState: true, } ) } }, [ dates, customer_id, location_id, payment, year, year_customer_id, year_location_id, year_payment, ]) return (
Penjualan Perhari
setLocationId(id) } placeholder="filter lokasi" /> setCustomerId(id) } placeholder="filter customer" /> setDates(dates)} />
Penjualan Perbulan
setYearLocationId(id) } placeholder="filter lokasi" /> setYearCustomerId(id) } placeholder="filter customer" /> setYear(date)} />
Deposit Hari Ini
{deposites.map((deposit, index) => ( ))}
# Customer Deposit
{index + 1} {deposit.customer.name} {formatIDR(deposit.total)}
Penjualan Hari Ini
{sales.map((sale, index) => ( ))}
# Customer Voucher Total
{index + 1} {sale.name} {formatIDR(sale.count)} {formatIDR(sale.total)}
) }