feat: pengeluaran = pengeluaran + penggajian,menambahkan scope ke Payroll model

This commit is contained in:
Yoga Pangestu 2024-11-30 20:12:03 +07:00
parent d2200d6006
commit a80f3ce878
5 changed files with 32 additions and 8 deletions

View File

@ -5,6 +5,7 @@
use App\Http\Controllers\Controller;
use App\Models\Expense;
use App\Models\Inventory;
use App\Models\Payroll;
use App\Models\Service;
use App\Models\Transaction;
use App\Models\User;
@ -20,6 +21,7 @@ public function index(): View
{
$totalIncome = Transaction::query()->barbershop()->sum('total');
$totalExpense = Expense::query()->barbershop()->sum('amount');
$totalPayroll = Payroll::query()->barbershop()->sum('total');
$totalShaving = Transaction::query()->barbershop()->count();
$topService = Service::query()->barbershop()->withCount('transactions')->get();
@ -48,7 +50,7 @@ public function index(): View
return view('pages.admin.dashboard.analytic', [
'pageTitle' => 'Analitik',
'totalIncome' => $totalIncome,
'totalExpense' => $totalExpense,
'totalExpense' => $totalExpense + $totalPayroll,
'totalShaving' => $totalShaving,
'topService' => $topService,
'paymentMethod' => $paymentMethod,
@ -82,6 +84,14 @@ public function filter(Request $request): JsonResponse
])
->sum('amount');
$totalPayroll = Payroll::query()
->barbershop()
->whereBetween('created_at', [
Carbon::parse($startDate)->startOfDay(),
Carbon::parse($endDate)->endOfDay(),
])
->sum('amount');
$totalShaving = Transaction::query()
->barbershop()
->whereBetween('created_at', [
@ -174,7 +184,7 @@ public function filter(Request $request): JsonResponse
'startDate' => $startDate,
'endDate' => $endDate,
'totalIncome' => $totalIncome,
'totalExpense' => $totalExpense,
'totalExpense' => $totalExpense + $totalPayroll,
'totalShaving' => $totalShaving,
'topService' => $topService,
'paymentMethod' => $paymentMethod,

View File

@ -5,6 +5,7 @@
use App\Http\Controllers\Controller;
use App\Models\Barbershop;
use App\Models\Expense;
use App\Models\Payroll;
use App\Models\Transaction;
use App\Models\User;
use Illuminate\Http\RedirectResponse;
@ -47,6 +48,8 @@ public function index()
$todayExpense = Expense::query()->barbershop()->today()->sum('amount');
$yesterdayExpense = Expense::query()->barbershop()->yesterday()->sum('amount');
$todayPayroll = Payroll::query()->barbershop()->today()->sum('total');
$yesterdayPayroll = Payroll::query()->barbershop()->yesterday()->sum('amount');
$todayNewCustomer = Transaction::with('customer')->whereDoesntHave('customer.transactions', function ($query) {
$query->where('id', '<>', DB::raw('transactions.id'));
@ -87,8 +90,8 @@ public function index()
'yesterdayIncome' => $yesterdayIncome,
'todayShaving' => $todayShaving,
'yesterdayShaving' => $yesterdayShaving,
'todayExpense' => $todayExpense,
'yesterdayExpense' => $yesterdayExpense,
'todayExpense' => $todayExpense + $todayPayroll,
'yesterdayExpense' => $yesterdayExpense + $yesterdayPayroll,
'todayNewCustomer' => $todayNewCustomer,
'yesterdayNewCustomer' => $yesterdayNewCustomer,
'cash' => Barbershop::findOrFail(Auth::user()->barbershop_id)->cash,

View File

@ -52,7 +52,7 @@ public function store(ExpenseRequest $request): RedirectResponse
$barbershop->decrement('cash', $validatedData['amount']);
}
$this->uploadAttachment($validatedData['proof'], 'expenses', Expense::class, $newExpense->id);
$this->uploadAttachment($validatedData['proof'], 'expenses', Expense::class, $newExpense->id, 'expenses');
});
notify()->success('Data berhasil ditambahkan', 'Berhasil');
@ -88,7 +88,7 @@ public function update(ExpenseRequest $request, Expense $expense): RedirectRespo
}
if (isset($validatedData['proof'])) {
$this->uploadAttachment($validatedData['proof'], 'expenses', Expense::class, $expense->id);
$this->uploadAttachment($validatedData['proof'], 'expenses', Expense::class, $expense->id, 'expenses');
}
});

View File

@ -2,6 +2,7 @@
namespace App\Models;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
@ -32,6 +33,16 @@ public function scopeBarbershop(Builder $query): Builder
return $query->where('barbershop_id', Auth::user()->barbershop_id);
}
public function scopeToday(Builder $query): Builder
{
return $query->whereDate('created_at', Carbon::today());
}
public function scopeYesterday(Builder $query): Builder
{
return $query->whereDate('created_at', Carbon::yesterday());
}
public function user(): BelongsTo
{
return $this->belongsTo(User::class);

View File

@ -6,7 +6,7 @@
<div class="row size-column">
<div class="col-xxl-10 col-md-12 box-col-8 grid-ed-12">
<div class="row">
<div class="col-xxl-5 col-md-7 box-col-7">
<div class="col-xxl-7 col-md-12 ">
<div class="row">
<div class="col-sm-12">
<div class="card o-hidden">
@ -99,7 +99,7 @@
</div>
</div>
</div>
<div class="col-xxl-7 col-md-5 col-sm-6 box-col-5">
<div class="col-xxl-5 col-md-12 ">
<div class="appointment">
<div class="card">
<div class="card-header card-no-border">