diff --git a/app/Http/Controllers/Admin/Finance/DepositMoneyController.php b/app/Http/Controllers/Admin/Finance/DepositMoneyController.php new file mode 100644 index 0000000..4edbedd --- /dev/null +++ b/app/Http/Controllers/Admin/Finance/DepositMoneyController.php @@ -0,0 +1,79 @@ + 'Setor Uang', + 'depositMoney' => DepositMoney::with(['user', 'user.biography']) + ->barbershop() + ->latest() + ->get(), + ]); + } + + public function store(DepositMoneyRequest $request): RedirectResponse + { + $validatedData = $request->validated(); + $barbershopId = Auth::user()->barbershop_id; + $barbershop = Barbershop::findOrFail($barbershopId); + + DB::transaction(function () use ($validatedData, $barbershop) { + DepositMoney::create(array_merge($validatedData, [ + 'user_id' => Auth::id(), + 'barbershop_id' => Auth::user()->barbershop_id, + ])); + $barbershop->decrement('cash', $validatedData['amount']); + }); + + notify()->success('Data berhasil ditambahkan', 'Berhasil'); + + return back(); + } + + public function update(DepositMoneyRequest $request, DepositMoney $depositMoney): RedirectResponse + { + $validatedData = $request->validated(); + $barbershop = Barbershop::findOrFail($depositMoney->barbershop_id); + + DB::transaction(function () use ($validatedData, $depositMoney, $barbershop) { + $barbershop->increment('cash', $depositMoney->amount); + + $depositMoney->update($validatedData); + + $barbershop->decrement('cash', $validatedData['amount']); + }); + + notify()->success('Data berhasil diperbarui', 'Berhasil'); + + return back(); + } + + public function delete(DepositMoney $depositMoney): RedirectResponse + { + $barbershop = Barbershop::findOrFail($depositMoney->barbershop_id); + DB::transaction(function () use ($depositMoney, $barbershop) { + $barbershop->increment('cash', $depositMoney->amount); + $depositMoney->delete(); + }); + + notify()->success('Data berhasil dihapus', 'Berhasil'); + + return back(); + } +} diff --git a/app/Http/Requests/Admin/Finance/DepositMoneyRequest.php b/app/Http/Requests/Admin/Finance/DepositMoneyRequest.php new file mode 100644 index 0000000..696574e --- /dev/null +++ b/app/Http/Requests/Admin/Finance/DepositMoneyRequest.php @@ -0,0 +1,38 @@ +merge([ + 'amount' => removeRupiahFormatting($this->amount), + ]); + } + + public function rules(): array + { + return [ + 'amount' => ['required', 'numeric', 'min:0', 'max:99999999.99'], + 'description' => ['required', 'string', 'max:255'], + ]; + } + + protected function failedValidation(Validator $validator): void + { + $this->handleValidationFailure($validator); + } +} diff --git a/app/Models/Barbershop.php b/app/Models/Barbershop.php index 360c5b7..d7b4554 100644 --- a/app/Models/Barbershop.php +++ b/app/Models/Barbershop.php @@ -90,4 +90,9 @@ public function attachment(): MorphOne { return $this->morphOne(Attachment::class, 'attachmentable'); } + + public function depositMoney(): HasMany + { + return $this->hasMany(DepositMoney::class); + } } diff --git a/app/Models/DepositMoney.php b/app/Models/DepositMoney.php new file mode 100644 index 0000000..4048a1d --- /dev/null +++ b/app/Models/DepositMoney.php @@ -0,0 +1,28 @@ +where('barbershop_id', Auth::user()->barbershop_id); + } + + public function user(): BelongsTo + { + return $this->belongsTo(User::class); + } +} diff --git a/app/Models/User.php b/app/Models/User.php index 9f33fbf..2b2d9a5 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -108,4 +108,9 @@ public function attachments(): MorphMany { return $this->morphMany(Attachment::class, 'attachmentable'); } + + public function depositMoney(): HasMany + { + return $this->hasMany(DepositMoney::class); + } } diff --git a/app/Providers/RouteServiceProvider.php b/app/Providers/RouteServiceProvider.php index 663caf2..f543fc3 100644 --- a/app/Providers/RouteServiceProvider.php +++ b/app/Providers/RouteServiceProvider.php @@ -6,6 +6,7 @@ use App\Models\Cash; use App\Models\Customer; use App\Models\Debt; +use App\Models\DepositMoney; use App\Models\Expense; use App\Models\Inventory; use App\Models\Payroll; @@ -36,6 +37,7 @@ public function boot(): void Route::bind('customer', fn (string $customer) => Customer::findOrFail(decryptId($customer))); Route::bind('service', fn (string $service) => Service::findOrFail(decryptId($service))); Route::bind('expense', fn (string $expense) => Expense::findOrFail(decryptId($expense))); + Route::bind('depositMoney', fn (string $depositMoney) => DepositMoney::findOrFail(decryptId($depositMoney))); Route::bind('payroll', fn (string $payroll) => Payroll::findOrFail(decryptId($payroll))); Route::bind('cash', fn (string $cash) => Cash::findOrFail(decryptId($cash))); Route::bind('debt', fn (string $debt) => Debt::findOrFail(decryptId($debt))); diff --git a/database/migrations/2024_12_30_172526_create_deposit_money_table.php b/database/migrations/2024_12_30_172526_create_deposit_money_table.php new file mode 100644 index 0000000..9002e6f --- /dev/null +++ b/database/migrations/2024_12_30_172526_create_deposit_money_table.php @@ -0,0 +1,32 @@ +id(); + $table->foreignId('user_id')->constrained()->cascadeOnDelete(); + $table->foreignId('barbershop_id')->constrained('barbershop')->cascadeOnDelete(); + $table->decimal('amount', 10, 2); + $table->string('description'); + $table->timestamps(); + $table->softDeletes(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('deposit_money'); + } +}; diff --git a/public/assets/admin/js/custom/deposit-money.js b/public/assets/admin/js/custom/deposit-money.js new file mode 100644 index 0000000..3bac301 --- /dev/null +++ b/public/assets/admin/js/custom/deposit-money.js @@ -0,0 +1,30 @@ +$(document).ready(function () { + $("#createModal").on("show.bs.modal", function (event) { + const button = $(event.relatedTarget); + const data = { + modalTitle: button.data("modal-title"), + url: button.data("url"), + method: button.data("method"), + + description: button.data("description"), + amount: button.data("amount"), + }; + + $(".modal-title").text(data.modalTitle); + $("#form").attr('action', data.url); + $("#form-method").val(data.method); + + if (data.method === 'put') { + $("#description").val(data.description); + $("#amount").val(data.amount); + } + }); + + $('#createModal').on('hidden.bs.modal', function () { + const method = $("#form-method").val(); + if (method === 'put') { + $("#description").val(''); + $("#amount").val(''); + } + }); +}); diff --git a/resources/views/pages/admin/finance/deposit-money.blade.php b/resources/views/pages/admin/finance/deposit-money.blade.php new file mode 100644 index 0000000..e111853 --- /dev/null +++ b/resources/views/pages/admin/finance/deposit-money.blade.php @@ -0,0 +1,139 @@ +@extends('layouts.admin') +@section('styles') + +@endsection +@section('app') +
+
+
+ @if (in_array(auth()->user()->role_id, [1, 3, 4])) +
+
+ + Tambah + +
+
+ @endif +
+
+
+ + + + + + + + + @if (in_array(auth()->user()->role_id, [1, 3, 4])) + + @endif + + + + @foreach ($depositMoney as $item) + + + + + + + @if (in_array(auth()->user()->role_id, [1, 3, 4])) + + @endif + + @endforeach + +
NoPenginputKeteranganJumlahTanggalAksi
{{ $loop->iteration }}{{ $item->user->biography->full_name ?? '-deleted-' }}{{ $item->description }}{{ formatToRupiah($item->amount) ?? '-' }}{{ formatDateIndo($item->created_at) }} +
    +
  • + + + +
  • + @if (auth()->user()->role_id === 1) +
  • +
    + @csrf + @method('delete') + + + +
    +
  • + @endif +
+
+
+
+
+
+
+ + +
+@endsection +@section('afterScripts') + + + + + + +@endsection diff --git a/resources/views/partials/admin/_sidebar.blade.php b/resources/views/partials/admin/_sidebar.blade.php index 5675c02..e4f4888 100644 --- a/resources/views/partials/admin/_sidebar.blade.php +++ b/resources/views/partials/admin/_sidebar.blade.php @@ -115,6 +115,13 @@ Pengeluaran Barang + @endif