You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

230 lines
9.5 KiB
React

1 year ago
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'
1 year ago
import { Head, router } from '@inertiajs/react'
import { usePrevious } from 'react-use'
import moment from 'moment'
1 year ago
import AuthenticatedLayout from '@/Layouts/AuthenticatedLayout'
import { formatIDR } from '@/utils'
import FormInputDateRanger from '@/Components/FormInputDateRange'
import CustomerSelectionInput from './Customer/SelectionInput'
import LocationSelectionInput from './Location/SelectionInput'
ChartJS.register(
CategoryScale,
LinearScale,
BarElement,
Title,
Tooltip,
ArcElement,
Legend
)
export default function Dashboard(props) {
1 year ago
const {
total_voucher,
total_customer,
total_customer_verified,
total_deposit,
total_voucher_sale_this_month,
count_voucher_sale_this_month,
total_voucher_sale_this_day,
count_voucher_sale_this_day,
month,
deposites,
sales,
charts,
_startDate,
_endDate,
} = props
const [dates, setDates] = useState({
startDate: _startDate,
endDate: _endDate,
})
const [customer_id, setCustomerId] = useState(null)
const [location_id, setLocationId] = useState(null)
const preValue = usePrevious(`${dates}${customer_id}${location_id}`)
const options = {
responsive: true,
scales: {
x: {},
},
}
const data = {
labels: charts.map((item) =>
moment(item.date, 'DD/MM/YYYY').format('DD MMM YYYY')
),
1 year ago
datasets: [
{
label: 'Penjualan',
data: charts.map((item) => item.sale_total),
backgroundColor: ['rgba(255, 205, 86, 1)'],
},
],
}
useEffect(() => {
if (preValue) {
router.get(
route(route().current()),
{
start_date: dates.startDate,
end_date: dates.endDate,
1 year ago
customer_id,
location_id,
},
{
replace: true,
preserveState: true,
}
)
}
}, [dates, customer_id, location_id])
return (
<AuthenticatedLayout page={'Dashboard'} action={''}>
<Head title="Dashboard" />
<div>
<div className="mx-auto sm:px-6 lg:px-8 ">
<div className="w-full flex flex-row mt-4 space-x-2 border dark:border-gray-900 rounded-md shadow">
<div className="flex-1 overflow-auto bg-white dark:bg-gray-800 p-4 rounded-md">
<div className="w-full flex flex-col md:flex-row justify-between mb-4">
<div className="text-gray-500 text-xl pb-4">
1 year ago
Penjualan
</div>
<div className="flex flex-row space-x-1">
<LocationSelectionInput
itemSelected={location_id}
onItemSelected={(id) =>
setLocationId(id)
}
placeholder="filter lokasi"
/>
<CustomerSelectionInput
itemSelected={customer_id}
onItemSelected={(id) =>
setCustomerId(id)
}
placeholder="filter customer"
/>
<FormInputDateRanger
selected={dates}
onChange={(dates) => setDates(dates)}
/>
</div>
</div>
<Bar
options={options}
data={data}
className="max-h-96"
/>
</div>
</div>
<div className="bg-white dark:bg-gray-800 rounded-md shadow border dark:border-gray-800 mt-4 w-full">
<div className="text-gray-500 text-xl px-3 py-4">
1 year ago
Deposit Hari Ini
</div>
<table className="w-full text-sm text-left text-gray-500 dark:text-gray-400 mb-4 px-2">
<thead className="text-xs text-gray-700 uppercase bg-gray-50 dark:bg-gray-800 dark:text-gray-400">
1 year ago
<tr>
<th scope="col" className="py-3 px-6">
#
</th>
<th scope="col" className="py-3 px-6">
Customer
</th>
<th scope="col" className="py-3 px-6">
Deposit
</th>
</tr>
</thead>
<tbody>
{deposites.map((deposit, index) => (
<tr
className="bg-white border-b dark:bg-gray-800 dark:border-gray-700"
key={`depo${index}`}
>
<td
scope="row"
className="py-4 px-6 font-medium text-gray-900 whitespace-nowrap dark:text-white"
>
{index + 1}
</td>
<td className="py-4 px-6">
{deposit.customer.name}
</td>
<td className="py-4 px-6">
{formatIDR(deposit.total)}
</td>
</tr>
))}
</tbody>
</table>
</div>
<div className="bg-white dark:bg-gray-800 dark:border-gray-800 rounded-md shadow border mt-2">
1 year ago
<div className="text-gray-500 text-xl px-3 py-4">
Penjualan Hari Ini
</div>
<table className="w-full text-sm text-left text-gray-500 dark:text-gray-400 mb-4 px-2">
<thead className="text-xs text-gray-700 uppercase bg-gray-50 dark:bg-gray-700 dark:text-gray-400">
<tr>
<th scope="col" className="py-3 px-6">
#
</th>
<th scope="col" className="py-3 px-6">
Customer
</th>
<th scope="col" className="py-3 px-6">
Voucher
</th>
<th scope="col" className="py-3 px-6">
Total
</th>
</tr>
</thead>
<tbody>
{sales.map((sale, index) => (
<tr
className="bg-white border-b dark:bg-gray-800 dark:border-gray-700"
key={`sale${index}`}
>
<td
scope="row"
className="py-4 px-6 font-medium text-gray-900 whitespace-nowrap dark:text-white"
>
{index + 1}
</td>
<td className="py-4 px-6">
{sale.name}
</td>
<td className="py-4 px-6">
{formatIDR(sale.count)}
</td>
<td className="py-4 px-6">
{formatIDR(sale.total)}
</td>
</tr>
))}
</tbody>
</table>
</div>
</div>
</div>
</AuthenticatedLayout>
1 year ago
)
}