feat: pengeluaran = pengeluaran + penggajian,menambahkan scope ke Payroll model
This commit is contained in:
parent
d2200d6006
commit
a80f3ce878
@ -5,6 +5,7 @@
|
|||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Controller;
|
||||||
use App\Models\Expense;
|
use App\Models\Expense;
|
||||||
use App\Models\Inventory;
|
use App\Models\Inventory;
|
||||||
|
use App\Models\Payroll;
|
||||||
use App\Models\Service;
|
use App\Models\Service;
|
||||||
use App\Models\Transaction;
|
use App\Models\Transaction;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
@ -20,6 +21,7 @@ public function index(): View
|
|||||||
{
|
{
|
||||||
$totalIncome = Transaction::query()->barbershop()->sum('total');
|
$totalIncome = Transaction::query()->barbershop()->sum('total');
|
||||||
$totalExpense = Expense::query()->barbershop()->sum('amount');
|
$totalExpense = Expense::query()->barbershop()->sum('amount');
|
||||||
|
$totalPayroll = Payroll::query()->barbershop()->sum('total');
|
||||||
$totalShaving = Transaction::query()->barbershop()->count();
|
$totalShaving = Transaction::query()->barbershop()->count();
|
||||||
|
|
||||||
$topService = Service::query()->barbershop()->withCount('transactions')->get();
|
$topService = Service::query()->barbershop()->withCount('transactions')->get();
|
||||||
@ -48,7 +50,7 @@ public function index(): View
|
|||||||
return view('pages.admin.dashboard.analytic', [
|
return view('pages.admin.dashboard.analytic', [
|
||||||
'pageTitle' => 'Analitik',
|
'pageTitle' => 'Analitik',
|
||||||
'totalIncome' => $totalIncome,
|
'totalIncome' => $totalIncome,
|
||||||
'totalExpense' => $totalExpense,
|
'totalExpense' => $totalExpense + $totalPayroll,
|
||||||
'totalShaving' => $totalShaving,
|
'totalShaving' => $totalShaving,
|
||||||
'topService' => $topService,
|
'topService' => $topService,
|
||||||
'paymentMethod' => $paymentMethod,
|
'paymentMethod' => $paymentMethod,
|
||||||
@ -82,6 +84,14 @@ public function filter(Request $request): JsonResponse
|
|||||||
])
|
])
|
||||||
->sum('amount');
|
->sum('amount');
|
||||||
|
|
||||||
|
$totalPayroll = Payroll::query()
|
||||||
|
->barbershop()
|
||||||
|
->whereBetween('created_at', [
|
||||||
|
Carbon::parse($startDate)->startOfDay(),
|
||||||
|
Carbon::parse($endDate)->endOfDay(),
|
||||||
|
])
|
||||||
|
->sum('amount');
|
||||||
|
|
||||||
$totalShaving = Transaction::query()
|
$totalShaving = Transaction::query()
|
||||||
->barbershop()
|
->barbershop()
|
||||||
->whereBetween('created_at', [
|
->whereBetween('created_at', [
|
||||||
@ -174,7 +184,7 @@ public function filter(Request $request): JsonResponse
|
|||||||
'startDate' => $startDate,
|
'startDate' => $startDate,
|
||||||
'endDate' => $endDate,
|
'endDate' => $endDate,
|
||||||
'totalIncome' => $totalIncome,
|
'totalIncome' => $totalIncome,
|
||||||
'totalExpense' => $totalExpense,
|
'totalExpense' => $totalExpense + $totalPayroll,
|
||||||
'totalShaving' => $totalShaving,
|
'totalShaving' => $totalShaving,
|
||||||
'topService' => $topService,
|
'topService' => $topService,
|
||||||
'paymentMethod' => $paymentMethod,
|
'paymentMethod' => $paymentMethod,
|
||||||
|
|||||||
@ -5,6 +5,7 @@
|
|||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Controller;
|
||||||
use App\Models\Barbershop;
|
use App\Models\Barbershop;
|
||||||
use App\Models\Expense;
|
use App\Models\Expense;
|
||||||
|
use App\Models\Payroll;
|
||||||
use App\Models\Transaction;
|
use App\Models\Transaction;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use Illuminate\Http\RedirectResponse;
|
use Illuminate\Http\RedirectResponse;
|
||||||
@ -47,6 +48,8 @@ public function index()
|
|||||||
|
|
||||||
$todayExpense = Expense::query()->barbershop()->today()->sum('amount');
|
$todayExpense = Expense::query()->barbershop()->today()->sum('amount');
|
||||||
$yesterdayExpense = Expense::query()->barbershop()->yesterday()->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) {
|
$todayNewCustomer = Transaction::with('customer')->whereDoesntHave('customer.transactions', function ($query) {
|
||||||
$query->where('id', '<>', DB::raw('transactions.id'));
|
$query->where('id', '<>', DB::raw('transactions.id'));
|
||||||
@ -87,8 +90,8 @@ public function index()
|
|||||||
'yesterdayIncome' => $yesterdayIncome,
|
'yesterdayIncome' => $yesterdayIncome,
|
||||||
'todayShaving' => $todayShaving,
|
'todayShaving' => $todayShaving,
|
||||||
'yesterdayShaving' => $yesterdayShaving,
|
'yesterdayShaving' => $yesterdayShaving,
|
||||||
'todayExpense' => $todayExpense,
|
'todayExpense' => $todayExpense + $todayPayroll,
|
||||||
'yesterdayExpense' => $yesterdayExpense,
|
'yesterdayExpense' => $yesterdayExpense + $yesterdayPayroll,
|
||||||
'todayNewCustomer' => $todayNewCustomer,
|
'todayNewCustomer' => $todayNewCustomer,
|
||||||
'yesterdayNewCustomer' => $yesterdayNewCustomer,
|
'yesterdayNewCustomer' => $yesterdayNewCustomer,
|
||||||
'cash' => Barbershop::findOrFail(Auth::user()->barbershop_id)->cash,
|
'cash' => Barbershop::findOrFail(Auth::user()->barbershop_id)->cash,
|
||||||
|
|||||||
@ -52,7 +52,7 @@ public function store(ExpenseRequest $request): RedirectResponse
|
|||||||
$barbershop->decrement('cash', $validatedData['amount']);
|
$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');
|
notify()->success('Data berhasil ditambahkan', 'Berhasil');
|
||||||
@ -88,7 +88,7 @@ public function update(ExpenseRequest $request, Expense $expense): RedirectRespo
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (isset($validatedData['proof'])) {
|
if (isset($validatedData['proof'])) {
|
||||||
$this->uploadAttachment($validatedData['proof'], 'expenses', Expense::class, $expense->id);
|
$this->uploadAttachment($validatedData['proof'], 'expenses', Expense::class, $expense->id, 'expenses');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace App\Models;
|
namespace App\Models;
|
||||||
|
|
||||||
|
use Carbon\Carbon;
|
||||||
use Illuminate\Database\Eloquent\Builder;
|
use Illuminate\Database\Eloquent\Builder;
|
||||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
@ -32,6 +33,16 @@ public function scopeBarbershop(Builder $query): Builder
|
|||||||
return $query->where('barbershop_id', Auth::user()->barbershop_id);
|
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
|
public function user(): BelongsTo
|
||||||
{
|
{
|
||||||
return $this->belongsTo(User::class);
|
return $this->belongsTo(User::class);
|
||||||
|
|||||||
@ -6,7 +6,7 @@
|
|||||||
<div class="row size-column">
|
<div class="row size-column">
|
||||||
<div class="col-xxl-10 col-md-12 box-col-8 grid-ed-12">
|
<div class="col-xxl-10 col-md-12 box-col-8 grid-ed-12">
|
||||||
<div class="row">
|
<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="row">
|
||||||
<div class="col-sm-12">
|
<div class="col-sm-12">
|
||||||
<div class="card o-hidden">
|
<div class="card o-hidden">
|
||||||
@ -99,7 +99,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</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="appointment">
|
||||||
<div class="card">
|
<div class="card">
|
||||||
<div class="card-header card-no-border">
|
<div class="card-header card-no-border">
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user