import React, { useEffect, useState } from 'react' import AuthenticatedLayout from '@/Layouts/AuthenticatedLayout' import { Head, router } from '@inertiajs/react' import { formatIDR } from '@/utils' import { Chart as ChartJS, CategoryScale, LinearScale, BarElement, Title, Tooltip, ArcElement, Legend, } from 'chart.js' import { Bar, Doughnut } from 'react-chartjs-2' import { BiSortAlt2 } from 'react-icons/bi' import moment from 'moment' import FormInputDateRanger from '@/Components/FormInputDateRange' import { usePrevious } from 'react-use' import SearchInput from '@/Components/SearchInput' ChartJS.register( CategoryScale, LinearScale, BarElement, Title, Tooltip, ArcElement, Legend ) export default function Dashboard(props) { const { total_item_today, total_item_price_today, sale_days, _startDate, _endDate, _order, _p_q, _c_q, list_favorite_product, list_customer, favorite_categories, month, total_sale_month, targets, target, } = props const [dates, setDates] = useState({ startDate: _startDate, endDate: _endDate, }) const [order, setOrder] = useState(_order) const [p_q, setPq] = useState(_p_q) const [c_q, setCq] = useState(_c_q) const options = { responsive: true, scales: { x: {}, x2: { display: false, }, }, } const data = { labels: sale_days.map((item) => moment(item.date).format('DD MMM YYYY') ), datasets: [ { label: 'Penjualan', data: sale_days.map((item) => item.stotal), backgroundColor: ['rgba(255, 205, 86, 1)'], }, { label: 'Target', data: targets, backgroundColor: ['rgba(200, 30, 30, 1)'], xAxisID: 'x2', }, ], } const names = favorite_categories.map( (c) => `${c.product.category.name} - ${c.qty}` ) const count = favorite_categories.map((c) => c.qty) const dataDounat = { labels: names, datasets: [ { label: '# Jumlah', data: count, backgroundColor: [ 'rgba(255, 99, 132, 1)', 'rgba(54, 162, 235, 1)', 'rgba(255, 206, 86, 1)', 'rgba(75, 192, 192, 1)', 'rgba(153, 102, 255, 1)', 'rgba(255, 159, 64, 1)', '#b91c1c', '#c2410c', '#b45309', '#15803d', '#047857', '#0f766e', '#0369a1', '#1d4ed8', '#6d28d9', '#a21caf', ], borderColor: [ 'rgba(255, 99, 132, 1)', 'rgba(54, 162, 235, 1)', 'rgba(255, 206, 86, 1)', 'rgba(75, 192, 192, 1)', 'rgba(153, 102, 255, 1)', 'rgba(255, 159, 64, 1)', '#b91c1c', '#c2410c', '#b45309', '#15803d', '#047857', '#0f766e', '#0369a1', '#1d4ed8', '#6d28d9', '#a21caf', ], borderWidth: 1, }, ], } const optionsDounat = { responsive: true, plugins: { legend: { display: true, position: 'right', }, }, } const preValue = usePrevious({ dates, order, c_q, p_q, }) useEffect(() => { if (preValue) { router.get( route(route().current()), { start_date: dates.startDate, end_date: dates.endDate, order, c_q, p_q, }, { replace: true, preserveState: true, } ) } }, [dates, order, c_q, p_q]) return (
Target Penjualan
Bulan {month}
Rp. {formatIDR(target)}
Total Penjualan
Bulan {month}
Rp. {formatIDR(total_sale_month)}
Total Penjualan
Hari Ini
Rp. {formatIDR(total_item_price_today)}
Jumlah Produk Terjual
Hari Ini
{total_item_today}
{/* Chart : jumlah transaksi 7 hari terkahir */}
Penjualan 7 Hari Terakhir
setDates(dates) } />
Kategori Produk yang laku Terjual pada Bulan{' '} {month}
{/* list produk paling laris dengan jumlah penjualan */}
Produk Terlaris
setOrder( order === 'asc' ? 'desc' : 'asc' ) } >
setPq(e.target.value)} />
{list_favorite_product.map((product) => ( ))}
Kode Produk Jumlah
{product.product.code} {product.product.name} {formatIDR(product.qty)}
{/* list customer yang bertransaksi dengan total transaksi */}
Pelanggan Hari Ini
setOrder( order === 'asc' ? 'desc' : 'asc' ) } >
setCq(e.target.value)} />
{list_customer.map((customer) => ( ))}
Pelanggan Total Belanja
{customer.customer !== null ? customer.customer.name : 'Umum'} Rp. {formatIDR(customer.stotal)}
) }