feat(analysis): membuat filter period
This commit is contained in:
parent
9cfb5b75a7
commit
00341e13d0
@ -23,6 +23,8 @@
|
|||||||
#[Title('Analisa')]
|
#[Title('Analisa')]
|
||||||
class Analysis extends Component
|
class Analysis extends Component
|
||||||
{
|
{
|
||||||
|
public string $period = 'all';
|
||||||
|
|
||||||
public array $outlets = [];
|
public array $outlets = [];
|
||||||
|
|
||||||
public array $selectedOutletIds = [];
|
public array $selectedOutletIds = [];
|
||||||
@ -46,6 +48,11 @@ public function mount()
|
|||||||
$this->loadData();
|
$this->loadData();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function updatedPeriod(string $period)
|
||||||
|
{
|
||||||
|
$this->loadData();
|
||||||
|
}
|
||||||
|
|
||||||
public function updatedSelectedOutletIds()
|
public function updatedSelectedOutletIds()
|
||||||
{
|
{
|
||||||
$this->loadData();
|
$this->loadData();
|
||||||
@ -54,108 +61,185 @@ public function updatedSelectedOutletIds()
|
|||||||
protected function loadData()
|
protected function loadData()
|
||||||
{
|
{
|
||||||
$outletIds = $this->selectedOutletIds;
|
$outletIds = $this->selectedOutletIds;
|
||||||
|
$period = $this->period;
|
||||||
|
|
||||||
|
$dateQuery = match ($period) {
|
||||||
|
'7' => now()->subDays(1),
|
||||||
|
'30' => now()->subDays(30),
|
||||||
|
'90' => now()->subDays(90),
|
||||||
|
'365' => now()->subDays(365),
|
||||||
|
default => null,
|
||||||
|
};
|
||||||
|
|
||||||
$this->countingData = [
|
$this->countingData = [
|
||||||
[
|
[
|
||||||
'title' => 'Outlet',
|
'title' => 'Outlet',
|
||||||
'value' => Outlet::count(),
|
'value' => Outlet::when($dateQuery, fn ($q) => $q->where('created_at', '>=', $dateQuery))->count(),
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'title' => 'Pegawai',
|
'title' => 'Pegawai',
|
||||||
'value' => User::whereHas('employee')->when(! empty($outletIds), fn ($q) => $q->whereHas('outlets', fn ($q2) => $q2->whereIn('outlets.id', $outletIds)))->count(),
|
'value' => User::whereHas('employee')
|
||||||
|
->when(! empty($outletIds), fn ($q) => $q->whereHas('outlets', fn ($q2) => $q2->whereIn('outlets.id', $outletIds)))
|
||||||
|
->when($dateQuery, fn ($q) => $q->where('created_at', '>=', $dateQuery))
|
||||||
|
->count(),
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'title' => 'Tier',
|
'title' => 'Tier',
|
||||||
'value' => Tier::count(),
|
'value' => Tier::when($dateQuery, fn ($q) => $q->where('created_at', '>=', $dateQuery))->count(),
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'title' => 'Voucher Aktif',
|
'title' => 'Voucher Aktif',
|
||||||
'value' => Voucher::when(! empty($outletIds), fn ($q) => $q->whereHas('outlets', fn ($q2) => $q2->whereIn('outlets.id', $outletIds)))->active()->count(),
|
'value' => Voucher::when(! empty($outletIds), fn ($q) => $q->whereHas('outlets', fn ($q2) => $q2->whereIn('outlets.id', $outletIds)))
|
||||||
|
->when($dateQuery, fn ($q) => $q->where('created_at', '>=', $dateQuery))
|
||||||
|
->active()
|
||||||
|
->count(),
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'title' => 'Member',
|
'title' => 'Member',
|
||||||
'value' => User::whereHas('customer')->when(! empty($outletIds), fn ($q) => $q->whereHas('outlets', fn ($q2) => $q2->whereIn('outlets.id', $outletIds)))->count(),
|
'value' => User::whereHas('customer')
|
||||||
|
->when(! empty($outletIds), fn ($q) => $q->whereHas('outlets', fn ($q2) => $q2->whereIn('outlets.id', $outletIds)))
|
||||||
|
->when($dateQuery, fn ($q) => $q->where('created_at', '>=', $dateQuery))
|
||||||
|
->count(),
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'title' => 'Customer',
|
'title' => 'Customer',
|
||||||
'value' => Customer::whereDoesntHave('user')->count(),
|
'value' => Customer::whereDoesntHave('user')
|
||||||
|
->when($dateQuery, fn ($q) => $q->where('created_at', '>=', $dateQuery))
|
||||||
|
->count(),
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'title' => 'Kategori',
|
'title' => 'Kategori',
|
||||||
'value' => Category::count(),
|
'value' => Category::when($dateQuery, fn ($q) => $q->where('created_at', '>=', $dateQuery))->count(),
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'title' => 'Merek',
|
'title' => 'Merek',
|
||||||
'value' => Brand::count(),
|
'value' => Brand::when($dateQuery, fn ($q) => $q->where('created_at', '>=', $dateQuery))->count(),
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'title' => 'Parfum',
|
'title' => 'Parfum',
|
||||||
'value' => Perfume::when(! empty($outletIds), fn ($q) => $q->whereHas('outlets', fn ($q2) => $q2->whereIn('outlets.id', $outletIds)))->count(),
|
'value' => Perfume::when(! empty($outletIds), fn ($q) => $q->whereHas('outlets', fn ($q2) => $q2->whereIn('outlets.id', $outletIds)))
|
||||||
|
->when($dateQuery, fn ($q) => $q->where('created_at', '>=', $dateQuery))
|
||||||
|
->count(),
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'title' => 'Produk',
|
'title' => 'Produk',
|
||||||
'value' => Product::when(! empty($outletIds), fn ($q) => $q->whereHas('outlets', fn ($q2) => $q2->whereIn('outlets.id', $outletIds)))->count(),
|
'value' => Product::when(! empty($outletIds), fn ($q) => $q->whereHas('outlets', fn ($q2) => $q2->whereIn('outlets.id', $outletIds)))
|
||||||
|
->when($dateQuery, fn ($q) => $q->where('created_at', '>=', $dateQuery))
|
||||||
|
->count(),
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'title' => 'Botol',
|
'title' => 'Botol',
|
||||||
'value' => Bottle::when(! empty($outletIds), fn ($q) => $q->whereHas('outlets', fn ($q2) => $q2->whereIn('outlets.id', $outletIds)))->count(),
|
'value' => Bottle::when(! empty($outletIds), fn ($q) => $q->whereHas('outlets', fn ($q2) => $q2->whereIn('outlets.id', $outletIds)))
|
||||||
|
->when($dateQuery, fn ($q) => $q->where('created_at', '>=', $dateQuery))
|
||||||
|
->count(),
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
|
|
||||||
$this->orders = [
|
$this->orders = [
|
||||||
[
|
[
|
||||||
'title' => 'Total Order',
|
'title' => 'Total Order',
|
||||||
'value' => currency(Order::when(! empty($outletIds), fn ($q) => $q->whereIn('outlet_id', $outletIds))->count()),
|
'value' => currency(
|
||||||
|
Order::when(! empty($outletIds), fn ($q) => $q->whereIn('outlet_id', $outletIds))
|
||||||
|
->when($dateQuery, fn ($q) => $q->where('created_at', '>=', $dateQuery))
|
||||||
|
->count()
|
||||||
|
),
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'title' => 'Pendapatan',
|
'title' => 'Pendapatan',
|
||||||
'value' => currency(Order::when(! empty($outletIds), fn ($q) => $q->whereIn('outlet_id', $outletIds))->sum('total'), 'Rp'),
|
'value' => currency(
|
||||||
|
Order::when(! empty($outletIds), fn ($q) => $q->whereIn('outlet_id', $outletIds))
|
||||||
|
->when($dateQuery, fn ($q) => $q->where('created_at', '>=', $dateQuery))
|
||||||
|
->sum('total'),
|
||||||
|
'Rp'
|
||||||
|
),
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'title' => 'HPP',
|
'title' => 'HPP',
|
||||||
'value' => currency(Order::when(! empty($outletIds), fn ($q) => $q->whereIn('outlet_id', $outletIds))->sum('cogs'), 'Rp'),
|
'value' => currency(
|
||||||
|
Order::when(! empty($outletIds), fn ($q) => $q->whereIn('outlet_id', $outletIds))
|
||||||
|
->when($dateQuery, fn ($q) => $q->where('created_at', '>=', $dateQuery))
|
||||||
|
->sum('cogs'),
|
||||||
|
'Rp'
|
||||||
|
),
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'title' => 'Diskon',
|
'title' => 'Diskon',
|
||||||
'value' => currency(Order::when(! empty($outletIds), fn ($q) => $q->whereIn('outlet_id', $outletIds))->sum('discount'), 'Rp'),
|
'value' => currency(
|
||||||
|
Order::when(! empty($outletIds), fn ($q) => $q->whereIn('outlet_id', $outletIds))
|
||||||
|
->when($dateQuery, fn ($q) => $q->where('created_at', '>=', $dateQuery))
|
||||||
|
->sum('discount'),
|
||||||
|
'Rp'
|
||||||
|
),
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'title' => 'Voucher Terpakai',
|
'title' => 'Voucher Terpakai',
|
||||||
'value' => currency(Order::when(! empty($outletIds), fn ($q) => $q->whereIn('outlet_id', $outletIds))->whereNotNull('voucher_id')->count()),
|
'value' => currency(
|
||||||
|
Order::when(! empty($outletIds), fn ($q) => $q->whereIn('outlet_id', $outletIds))
|
||||||
|
->when($dateQuery, fn ($q) => $q->where('created_at', '>=', $dateQuery))
|
||||||
|
->whereNotNull('voucher_id')->count()
|
||||||
|
),
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'title' => 'Parfum Terjual',
|
'title' => 'Parfum Terjual',
|
||||||
'value' => currency(OrderItem::where('orderable_type', Perfume::class)->whereHas('order', fn ($q) => $q->when(! empty($outletIds), fn ($q2) => $q2->whereIn('outlet_id', $outletIds)))->sum('quantity')).' ml',
|
'value' => currency(
|
||||||
|
OrderItem::where('orderable_type', Perfume::class)
|
||||||
|
->whereHas('order', fn ($q) => $q->when(! empty($outletIds), fn ($q2) => $q2->whereIn('outlet_id', $outletIds))->when($dateQuery, fn ($q) => $q->where('created_at', '>=', $dateQuery)))
|
||||||
|
->sum('quantity')
|
||||||
|
).' ml',
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'title' => 'Produk Terjual',
|
'title' => 'Produk Terjual',
|
||||||
'value' => currency(OrderItem::where('orderable_type', Product::class)->whereHas('order', fn ($q) => $q->when(! empty($outletIds), fn ($q2) => $q2->whereIn('outlet_id', $outletIds)))->sum('quantity')).' pcs',
|
'value' => currency(
|
||||||
|
OrderItem::where('orderable_type', Product::class)
|
||||||
|
->whereHas('order', fn ($q) => $q->when(! empty($outletIds), fn ($q2) => $q2->whereIn('outlet_id', $outletIds))->when($dateQuery, fn ($q) => $q->where('created_at', '>=', $dateQuery)))
|
||||||
|
->sum('quantity')
|
||||||
|
).' pcs',
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'title' => 'Botol Terjual',
|
'title' => 'Botol Terjual',
|
||||||
'value' => currency(OrderItem::where('orderable_type', Bottle::class)->whereHas('order', fn ($q) => $q->when(! empty($outletIds), fn ($q2) => $q2->whereIn('outlet_id', $outletIds)))->sum('quantity')).' pcs',
|
'value' => currency(
|
||||||
|
OrderItem::where('orderable_type', Bottle::class)
|
||||||
|
->whereHas('order', fn ($q) => $q->when(! empty($outletIds), fn ($q2) => $q2->whereIn('outlet_id', $outletIds))->when($dateQuery, fn ($q) => $q->where('created_at', '>=', $dateQuery)))
|
||||||
|
->sum('quantity')
|
||||||
|
).' pcs',
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
|
|
||||||
$this->expenses = [
|
$this->expenses = [
|
||||||
[
|
[
|
||||||
'title' => 'Beban Toko',
|
'title' => 'Beban Toko',
|
||||||
'value' => currency(Expense::when(! empty($outletIds), fn ($q) => $q->whereIn('outlet_id', $outletIds))->sum('amount'), 'Rp'),
|
'value' => currency(
|
||||||
|
Expense::when(! empty($outletIds), fn ($q) => $q->whereIn('outlet_id', $outletIds))
|
||||||
|
->when($dateQuery, fn ($q) => $q->where('created_at', '>=', $dateQuery))
|
||||||
|
->sum('amount'),
|
||||||
|
'Rp'
|
||||||
|
),
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'title' => 'Belanja Barang',
|
'title' => 'Belanja Barang',
|
||||||
'value' => currency(Purchase::when(! empty($outletIds), fn ($q) => $q->whereIn('outlet_id', $outletIds))->sum('total'), 'Rp'),
|
'value' => currency(
|
||||||
|
Purchase::when(! empty($outletIds), fn ($q) => $q->whereIn('outlet_id', $outletIds))
|
||||||
|
->when($dateQuery, fn ($q) => $q->where('created_at', '>=', $dateQuery))
|
||||||
|
->sum('total'),
|
||||||
|
'Rp'
|
||||||
|
),
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'title' => 'Penggajian',
|
'title' => 'Penggajian',
|
||||||
'value' => currency(Payroll::when(! empty($outletIds), fn ($q) => $q->whereHas('user.outlets', fn ($q2) => $q2->whereIn('outlets.id', $outletIds)))->sum('total_salary'), 'Rp'),
|
'value' => currency(
|
||||||
|
Payroll::when(! empty($outletIds), fn ($q) => $q->whereHas('user.outlets', fn ($q2) => $q2->whereIn('outlets.id', $outletIds)))
|
||||||
|
->when($dateQuery, fn ($q) => $q->where('created_at', '>=', $dateQuery))
|
||||||
|
->sum('total_salary'),
|
||||||
|
'Rp'
|
||||||
|
),
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
|
|
||||||
$this->topPerfumes = Perfume::with(['items' => function ($query) use ($outletIds) {
|
$this->topPerfumes = Perfume::with(['items' => function ($query) use ($outletIds, $dateQuery) {
|
||||||
$query->whereNotNull('order_id')
|
$query->whereNotNull('order_id')
|
||||||
->whereHas('order', function ($q) use ($outletIds) {
|
->whereHas('order', function ($q) use ($outletIds, $dateQuery) {
|
||||||
$q->when(! empty($outletIds), fn ($q) => $q->whereIn('outlet_id', $outletIds));
|
$q->when(! empty($outletIds), fn ($q) => $q->whereIn('outlet_id', $outletIds))
|
||||||
|
->when($dateQuery, fn ($q) => $q->where('created_at', '>=', $dateQuery));
|
||||||
});
|
});
|
||||||
}])
|
}])
|
||||||
->select('id', 'name', 'sale_price')
|
->select('id', 'name', 'sale_price')
|
||||||
@ -171,10 +255,11 @@ protected function loadData()
|
|||||||
->take(5)
|
->take(5)
|
||||||
->toArray();
|
->toArray();
|
||||||
|
|
||||||
$this->topProducts = Product::with(['items' => function ($query) use ($outletIds) {
|
$this->topProducts = Product::with(['items' => function ($query) use ($outletIds, $dateQuery) {
|
||||||
$query->whereNotNull('order_id')
|
$query->whereNotNull('order_id')
|
||||||
->whereHas('order', function ($q) use ($outletIds) {
|
->whereHas('order', function ($q) use ($outletIds, $dateQuery) {
|
||||||
$q->when(! empty($outletIds), fn ($q) => $q->whereIn('outlet_id', $outletIds));
|
$q->when(! empty($outletIds), fn ($q) => $q->whereIn('outlet_id', $outletIds))
|
||||||
|
->when($dateQuery, fn ($q) => $q->where('created_at', '>=', $dateQuery));
|
||||||
});
|
});
|
||||||
}])
|
}])
|
||||||
->select('id', 'name', 'sale_price')
|
->select('id', 'name', 'sale_price')
|
||||||
@ -190,10 +275,11 @@ protected function loadData()
|
|||||||
->take(5)
|
->take(5)
|
||||||
->toArray();
|
->toArray();
|
||||||
|
|
||||||
$this->topBottles = Bottle::with(['items' => function ($query) use ($outletIds) {
|
$this->topBottles = Bottle::with(['items' => function ($query) use ($outletIds, $dateQuery) {
|
||||||
$query->whereNotNull('order_id')
|
$query->whereNotNull('order_id')
|
||||||
->whereHas('order', function ($q) use ($outletIds) {
|
->whereHas('order', function ($q) use ($outletIds, $dateQuery) {
|
||||||
$q->when(! empty($outletIds), fn ($q) => $q->whereIn('outlet_id', $outletIds));
|
$q->when(! empty($outletIds), fn ($q) => $q->whereIn('outlet_id', $outletIds))
|
||||||
|
->when($dateQuery, fn ($q) => $q->where('created_at', '>=', $dateQuery));
|
||||||
});
|
});
|
||||||
}])
|
}])
|
||||||
->select('id', 'name', 'sale_price')
|
->select('id', 'name', 'sale_price')
|
||||||
|
|||||||
@ -3,12 +3,25 @@
|
|||||||
<flux:separator />
|
<flux:separator />
|
||||||
|
|
||||||
<div class="mt-6">
|
<div class="mt-6">
|
||||||
<div class="mb-6 grid grid-cols-1 lg:grid-cols-2 gap-4">
|
<div class="flex justify-between items-center mb-6">
|
||||||
<flux:checkbox.group wire:model.live="selectedOutletIds" variant="buttons">
|
<div class="flex items-center gap-2">
|
||||||
@foreach ($outlets as $key => $value)
|
<div class="flex items-center gap-2">
|
||||||
<flux:checkbox value="{{ $key }}" label="{{ $value }}" />
|
<flux:select wire:model.live="period">
|
||||||
@endforeach
|
<option value="all">Semua</option>
|
||||||
</flux:checkbox.group>
|
<option value="7">7 Hari Terakhir</option>
|
||||||
|
<option value="30">30 Hari Terakhir</option>
|
||||||
|
<option value="90">90 Hari Terakhir</option>
|
||||||
|
<option value="365">1 Tahun Terakhir</option>
|
||||||
|
</flux:select>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<flux:separator vertical class="max-lg:hidden mx-2 my-2" />
|
||||||
|
<flux:checkbox.group wire:model.live="selectedOutletIds" variant="buttons">
|
||||||
|
@foreach ($outlets as $key => $value)
|
||||||
|
<flux:checkbox value="{{ $key }}" label="{{ $value }}" />
|
||||||
|
@endforeach
|
||||||
|
</flux:checkbox.group>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<flux:heading>Counting Data</flux:heading>
|
<flux:heading>Counting Data</flux:heading>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user