feat: enhance expense chart visibility based on user roles in Analysis and Dashboard components
This commit is contained in:
parent
d9fb7018b3
commit
eb5eeaf73b
@ -272,6 +272,9 @@ public function getExpenseSummary(?Carbon $startDate = null, ?Carbon $endDate =
|
||||
->first();
|
||||
|
||||
$purchaseTotal = (int) ($purchase->total ?? 0);
|
||||
if (auth()->user()?->hasRole(\App\Enums\Role::ADMIN_TOKO->value)) {
|
||||
$purchaseTotal = 0;
|
||||
}
|
||||
$expenseTotal = (int) ($expenses->total ?? 0);
|
||||
$advanceTotal = (int) ($employeeAdvance->total ?? 0);
|
||||
|
||||
@ -328,6 +331,9 @@ public function getMonthlyExpense(?Carbon $startDate = null, ?Carbon $endDate =
|
||||
$monthLabel = $current->locale('id')->translatedFormat('M Y');
|
||||
|
||||
$purchaseAmount = (int) ($purchases->firstWhere('month_key', $key)->total ?? 0);
|
||||
if (auth()->user()?->hasRole(\App\Enums\Role::ADMIN_TOKO->value)) {
|
||||
$purchaseAmount = 0;
|
||||
}
|
||||
$expenseAmount = (int) ($expenses->firstWhere('month_key', $key)->total ?? 0);
|
||||
$advanceAmount = (int) ($advances->firstWhere('month_key', $key)->total ?? 0);
|
||||
|
||||
@ -400,6 +406,10 @@ public function getProfitMetrics(?Carbon $startDate = null, ?Carbon $endDate = n
|
||||
->when($startDate && $endDate, fn ($q) => $q->whereBetween('purchases.created_at', [$startDate, $endDate]))
|
||||
->sum('total');
|
||||
|
||||
if (auth()->user()?->hasRole(\App\Enums\Role::ADMIN_TOKO->value)) {
|
||||
$purchaseTotal = 0;
|
||||
}
|
||||
|
||||
$expenseTotal = Expense::query()
|
||||
->when($startDate && $endDate, fn ($q) => $q->whereBetween('expenses.created_at', [$startDate, $endDate]))
|
||||
->sum('amount');
|
||||
|
||||
@ -155,6 +155,9 @@ public function getExpenseSummary(): array
|
||||
->first();
|
||||
|
||||
$purchaseTotal = (int) ($purchase->total ?? 0);
|
||||
if (auth()->user()?->hasRole(\App\Enums\Role::ADMIN_TOKO->value)) {
|
||||
$purchaseTotal = 0;
|
||||
}
|
||||
$expenseTotal = (int) ($expenses->total ?? 0);
|
||||
$advanceTotal = (int) ($employeeAdvance->total ?? 0);
|
||||
|
||||
|
||||
@ -21,7 +21,7 @@ import AdminLayout from '@/layouts/AdminLayout.vue';
|
||||
import { formatRupiah } from '@/lib/rupiah';
|
||||
import admin from '@/routes/admin';
|
||||
|
||||
const { can } = useCan();
|
||||
const { can, hasRole } = useCan();
|
||||
|
||||
const props = defineProps<{
|
||||
filters: {
|
||||
@ -229,6 +229,14 @@ const expenseTotals = computed(() => ({
|
||||
kasbon: props.expenseSummary.advance_total,
|
||||
}));
|
||||
|
||||
const visibleExpenseCharts = computed(() => {
|
||||
const charts = ['total', 'belanja', 'pengeluaran', 'kasbon'] as const;
|
||||
if (hasRole('admin-toko')) {
|
||||
return charts.filter((c) => c !== 'belanja');
|
||||
}
|
||||
return charts;
|
||||
});
|
||||
|
||||
// Busy Hours Chart
|
||||
type BusyHourData = { hour: string; orders: number };
|
||||
|
||||
@ -492,7 +500,7 @@ watch([startDate, endDate], () => {
|
||||
<CardTitle>Pengeluaran</CardTitle>
|
||||
</div>
|
||||
<div class="flex">
|
||||
<button v-for="chart in ['total', 'belanja', 'pengeluaran', 'kasbon'] as const" :key="chart"
|
||||
<button v-for="chart in visibleExpenseCharts" :key="chart"
|
||||
:data-active="activeExpenseChart === chart"
|
||||
class="data-[active=true]:bg-muted/50 flex flex-1 flex-col justify-center gap-1 border-t px-6 py-4 text-left even:border-l sm:border-t-0 sm:border-l sm:px-8 sm:py-6"
|
||||
@click="activeExpenseChart = chart">
|
||||
|
||||
@ -89,7 +89,7 @@ interface DashboardProps {
|
||||
|
||||
const props = defineProps<DashboardProps>();
|
||||
|
||||
const { can } = useCan();
|
||||
const { can, hasRole } = useCan();
|
||||
|
||||
const webcamModalOpen = ref(false);
|
||||
const webcamMode = ref<'check-in' | 'check-out'>('check-in');
|
||||
@ -305,10 +305,10 @@ const marketingChartConfig = computed(() => {
|
||||
|
||||
<StatCard v-if="can('dashboard.expense')" title="Pengeluaran" :icon="TrendingDown" main-label="Total"
|
||||
:main-value="'Rp' + formatRupiah(expenseSummary.total)" :items="[
|
||||
{
|
||||
...(!hasRole('admin-toko') ? [{
|
||||
label: 'Belanja',
|
||||
value: 'Rp' + formatRupiah(expenseSummary.purchase_total),
|
||||
},
|
||||
}] : []),
|
||||
{
|
||||
label: 'Pengeluaran',
|
||||
value: 'Rp' + formatRupiah(expenseSummary.expense_total),
|
||||
|
||||
Loading…
Reference in New Issue
Block a user