diff --git a/resources/js/lib/rupiah.ts b/resources/js/lib/rupiah.ts index 08ac6cf..5c86850 100644 --- a/resources/js/lib/rupiah.ts +++ b/resources/js/lib/rupiah.ts @@ -11,3 +11,28 @@ export function formatRupiah(value: string | number): string { return Number(digits).toLocaleString('id-ID'); } + +export function formatRupiahShort(value: number): string { + const abs = Math.abs(value); + const sign = value < 0 ? '-' : ''; + + if (abs >= 1_000_000_000) { + const v = abs / 1_000_000_000; + + return sign + (v % 1 === 0 ? v.toFixed(0) : v.toFixed(1).replace('.', ',')) + 'M'; + } + + if (abs >= 1_000_000) { + const v = abs / 1_000_000; + + return sign + (v % 1 === 0 ? v.toFixed(0) : v.toFixed(1).replace('.', ',')) + 'jt'; + } + + if (abs >= 1_000) { + const v = abs / 1_000; + + return sign + (v % 1 === 0 ? v.toFixed(0) : v.toFixed(1).replace('.', ',')) + 'rb'; + } + + return sign + abs.toString(); +} diff --git a/resources/js/pages/admin/Analysis.vue b/resources/js/pages/admin/Analysis.vue index 5f590ce..bc8950e 100644 --- a/resources/js/pages/admin/Analysis.vue +++ b/resources/js/pages/admin/Analysis.vue @@ -19,7 +19,7 @@ import { DatePicker } from '@/components/ui/date-picker'; import { Select, SelectContent, SelectGroup, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select'; import { useCan } from '@/composables/useCan'; import AdminLayout from '@/layouts/AdminLayout.vue'; -import { formatRupiah } from '@/lib/rupiah'; +import { formatRupiah, formatRupiahShort } from '@/lib/rupiah'; import admin from '@/routes/admin'; const { can, hasRole } = useCan(); @@ -184,8 +184,6 @@ const revenueChartConfig = { }, } satisfies ChartConfig; -const activeRevenueChart = ref<'total' | 'net' | 'deduction'>('total'); - const revenueTotals = computed(() => ({ total: props.revenueSummary.total_revenue, net: props.revenueSummary.total_revenue - props.revenueSummary.total_deduction, @@ -214,8 +212,6 @@ const expenseChartConfig = { }, } satisfies ChartConfig; -const activeExpenseChart = ref<'total' | 'purchase' | 'expense' | 'advance'>('total'); - const expenseTotals = computed(() => ({ total: props.expenseSummary.total, purchase: props.expenseSummary.purchase_total, @@ -233,6 +229,40 @@ const visibleExpenseCharts = computed(() => { return charts; }); +const expenseYAccessors = computed(() => { + if (hasRole('admin-toko')) { + return [ + (d: MonthlyExpenseData) => d.total, + (d: MonthlyExpenseData) => d.expense, + (d: MonthlyExpenseData) => d.advance, + ]; + } + + return [ + (d: MonthlyExpenseData) => d.total, + (d: MonthlyExpenseData) => d.purchase, + (d: MonthlyExpenseData) => d.expense, + (d: MonthlyExpenseData) => d.advance, + ]; +}); + +const expenseColors = computed(() => { + if (hasRole('admin-toko')) { + return [ + expenseChartConfig.total.color, + expenseChartConfig.expense.color, + expenseChartConfig.advance.color, + ]; + } + + return [ + expenseChartConfig.total.color, + expenseChartConfig.purchase.color, + expenseChartConfig.expense.color, + expenseChartConfig.advance.color, + ]; +}); + // Busy Hours Chart type BusyHourData = { hour: string; orders: number }; @@ -283,26 +313,40 @@ const barSelector = GroupedBar.selectors.bar; function revenueTooltip(d: any) { const item = d as MonthlyRevenueData; - return `
+ return `

${item.month}

- - ${revenueChartConfig[activeRevenueChart.value].label} - Rp${formatRupiah(item[activeRevenueChart.value])} + + ${revenueChartConfig.total.label} + Rp${formatRupiah(item.total)} +

+

+ + ${revenueChartConfig.net.label} + Rp${formatRupiah(item.net)} +

+

+ + ${revenueChartConfig.deduction.label} + Rp${formatRupiah(item.deduction)}

`; } function expenseTooltip(d: any) { const item = d as MonthlyExpenseData; + const charts = visibleExpenseCharts.value; + const rows = charts.map((chart) => + `

+ + ${expenseChartConfig[chart].label} + Rp${formatRupiah(item[chart])} +

` + ).join(''); - return `
+ return `

${item.month}

-

- - ${expenseChartConfig[activeExpenseChart.value].label} - Rp${formatRupiah(item[activeExpenseChart.value])} -

+ ${rows}
`; } @@ -537,36 +581,48 @@ watch([startDate, endDate], () => { Pendapatan
- +
- - - - - - - - +
+
+
+ + {{ revenueChartConfig[chart].label }} +
+
+ + + + + + + + +
Belum ada data pendapatan
@@ -580,36 +636,41 @@ watch([startDate, endDate], () => { Pengeluaran
- +
- - - - - - - - +
+
+
+ + {{ expenseChartConfig[chart].label }} +
+
+ + + + + + + + +
Belum ada data pengeluaran
@@ -622,7 +683,6 @@ watch([startDate, endDate], () => {
Jam Sibuk Toko - Distribusi pesanan berdasarkan jam dalam sehari

Jam Tersibuk

@@ -714,7 +774,7 @@ watch([startDate, endDate], () => { :tick-format="(d: number) => supplierBarData[d]?.name ?? ''" :tick-values="supplierBarData.map((_, i) => i)" /> + :tick-format="(d: number) => 'Rp' + formatRupiahShort(d)" /> @@ -742,7 +802,7 @@ watch([startDate, endDate], () => { :tick-format="(d: number) => customerBarData[d]?.name ?? ''" :tick-values="customerBarData.map((_, i) => i)" /> + :tick-format="(d: number) => 'Rp' + formatRupiahShort(d)" />