feat : fitur baru yaitu setor tunai
This commit is contained in:
parent
76bb090234
commit
47277d18e5
@ -0,0 +1,79 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin\Finance;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\Admin\Finance\DepositMoneyRequest;
|
||||
use App\Models\Barbershop;
|
||||
use App\Models\DepositMoney;
|
||||
use App\Traits\UploadAttachment;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class DepositMoneyController extends Controller
|
||||
{
|
||||
use UploadAttachment;
|
||||
|
||||
public function index(): View
|
||||
{
|
||||
return view('pages.admin.finance.deposit-money', [
|
||||
'pageTitle' => '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();
|
||||
}
|
||||
}
|
||||
38
app/Http/Requests/Admin/Finance/DepositMoneyRequest.php
Normal file
38
app/Http/Requests/Admin/Finance/DepositMoneyRequest.php
Normal file
@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Admin\Finance;
|
||||
|
||||
use App\Traits\NotificationTrait;
|
||||
use Illuminate\Contracts\Validation\Validator;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class DepositMoneyRequest extends FormRequest
|
||||
{
|
||||
use NotificationTrait;
|
||||
|
||||
public function authorize(): bool
|
||||
{
|
||||
return Auth::check();
|
||||
}
|
||||
|
||||
protected function prepareForValidation(): void
|
||||
{
|
||||
$this->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);
|
||||
}
|
||||
}
|
||||
@ -90,4 +90,9 @@ public function attachment(): MorphOne
|
||||
{
|
||||
return $this->morphOne(Attachment::class, 'attachmentable');
|
||||
}
|
||||
|
||||
public function depositMoney(): HasMany
|
||||
{
|
||||
return $this->hasMany(DepositMoney::class);
|
||||
}
|
||||
}
|
||||
|
||||
28
app/Models/DepositMoney.php
Normal file
28
app/Models/DepositMoney.php
Normal file
@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class DepositMoney extends Model
|
||||
{
|
||||
protected $fillable = [
|
||||
'user_id',
|
||||
'barbershop_id',
|
||||
'amount',
|
||||
'description',
|
||||
];
|
||||
|
||||
public function scopeBarbershop(Builder $query): Builder
|
||||
{
|
||||
return $query->where('barbershop_id', Auth::user()->barbershop_id);
|
||||
}
|
||||
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
}
|
||||
@ -108,4 +108,9 @@ public function attachments(): MorphMany
|
||||
{
|
||||
return $this->morphMany(Attachment::class, 'attachmentable');
|
||||
}
|
||||
|
||||
public function depositMoney(): HasMany
|
||||
{
|
||||
return $this->hasMany(DepositMoney::class);
|
||||
}
|
||||
}
|
||||
|
||||
@ -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)));
|
||||
|
||||
@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('deposit_money', function (Blueprint $table) {
|
||||
$table->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');
|
||||
}
|
||||
};
|
||||
30
public/assets/admin/js/custom/deposit-money.js
Normal file
30
public/assets/admin/js/custom/deposit-money.js
Normal file
@ -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('');
|
||||
}
|
||||
});
|
||||
});
|
||||
139
resources/views/pages/admin/finance/deposit-money.blade.php
Normal file
139
resources/views/pages/admin/finance/deposit-money.blade.php
Normal file
@ -0,0 +1,139 @@
|
||||
@extends('layouts.admin')
|
||||
@section('styles')
|
||||
<link rel="stylesheet" type="text/css" href="{{ asset('assets/admin/css/vendors/datatables.css') }}">
|
||||
@endsection
|
||||
@section('app')
|
||||
<div class="container-fluid">
|
||||
<div class="row">
|
||||
<div class="col-sm-12">
|
||||
@if (in_array(auth()->user()->role_id, [1, 3, 4]))
|
||||
<div class="list-product-header">
|
||||
<div>
|
||||
<a href="javascript:void(0)" data-bs-toggle="modal" data-bs-target="#createModal"
|
||||
data-modal-title="Tambah Setor Tunai" data-url="{{ route('finance.depositMoney.store') }}"
|
||||
data-medtod="post" class="btn btn-primary">
|
||||
Tambah
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
@endif
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
<div class="table-responsive">
|
||||
<table class="display" id="datatable">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>No</th>
|
||||
<th>Penginput</th>
|
||||
<th>Keterangan</th>
|
||||
<th>Jumlah</th>
|
||||
<th>Tanggal</th>
|
||||
@if (in_array(auth()->user()->role_id, [1, 3, 4]))
|
||||
<th>Aksi</th>
|
||||
@endif
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach ($depositMoney as $item)
|
||||
<tr>
|
||||
<td>{{ $loop->iteration }}</td>
|
||||
<td>{{ $item->user->biography->full_name ?? '-deleted-' }}</td>
|
||||
<td>{{ $item->description }}</td>
|
||||
<td>{{ formatToRupiah($item->amount) ?? '-' }}</td>
|
||||
<td>{{ formatDateIndo($item->created_at) }}</td>
|
||||
@if (in_array(auth()->user()->role_id, [1, 3, 4]))
|
||||
<td>
|
||||
<ul class="action">
|
||||
<li class="edit">
|
||||
<a href="javascript:void(0)" data-bs-toggle="modal"
|
||||
data-bs-target="#createModal"
|
||||
data-modal-title="Edit Setor Tunai"
|
||||
data-url="{{ route('finance.depositMoney.update', encryptId($item->id)) }}"
|
||||
data-method="put"
|
||||
data-description="{{ $item->description }}"
|
||||
data-amount="{{ formatToRupiah($item->amount) }}">
|
||||
<i data-feather="edit"></i>
|
||||
</a>
|
||||
</li>
|
||||
@if (auth()->user()->role_id === 1)
|
||||
<li class="delete">
|
||||
<form
|
||||
action="{{ route('finance.depositMoney.delete', encryptId($item->id)) }}"
|
||||
method="post">
|
||||
@csrf
|
||||
@method('delete')
|
||||
<a href="javascript:void(0)" class="delete-data"
|
||||
data-bs-toggle="tooltip" data-bs-placement="left"
|
||||
data-bs-title="Hapus">
|
||||
<i data-feather="trash-2"></i>
|
||||
</a>
|
||||
</form>
|
||||
</li>
|
||||
@endif
|
||||
</ul>
|
||||
</td>
|
||||
@endif
|
||||
</tr>
|
||||
@endforeach
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="modal fade" id="createModal" tabindex="-1" role="dialog" aria-labelledby="createModal"
|
||||
aria-hidden="true">
|
||||
<div class="modal-dialog modal-dialog-centered" role="document">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title"></h5>
|
||||
<button class="btn-close py-0" type="button" data-bs-dismiss="modal" aria-label="Close"></button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<form class="row g-3 custom-input" method="post" id="form" enctype="multipart/form-data">
|
||||
<input type="hidden" name="_method" id="form-method">
|
||||
@csrf
|
||||
<div class="col-lg-12 position-relative">
|
||||
<label class="form-label" for="description">Keterangan</label>
|
||||
<input name="description" class="form-control @error('description') is-invalid @enderror"
|
||||
id="description" type="text" placeholder="Masukan Keterangan"
|
||||
value="{{ old('description') }}">
|
||||
@error('description')
|
||||
<div class="invalid-feedback">
|
||||
{{ $message }}
|
||||
</div>
|
||||
@enderror
|
||||
</div>
|
||||
<div class="col-lg-12 position-relative">
|
||||
<label class="form-label" for="amount">Jumlah</label>
|
||||
<input name="amount"
|
||||
class="form-control rupiah-format @error('amount') is-invalid @enderror" id="amount"
|
||||
type="text" placeholder="Masukan Jumlah" value="{{ old('amount') }}"
|
||||
inputmode="numeric">
|
||||
@error('amount')
|
||||
<div class="invalid-feedback">
|
||||
{{ $message }}
|
||||
</div>
|
||||
@enderror
|
||||
</div>
|
||||
<div class="col-lg-12 position-relative">
|
||||
<button class="btn btn-secondary" type="button" data-bs-dismiss="modal">Tutup</button>
|
||||
<button class="btn btn-primary">Simpan</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@endsection
|
||||
@section('afterScripts')
|
||||
<script src="{{ asset('assets/admin/js/datatable/jquery.dataTables.min.js?ver=1.0.0') }}"></script>
|
||||
<script src="{{ asset('assets/admin/js/datatable/client-side.js?ver=1.0.0') }}"></script>
|
||||
<script src="{{ asset('assets/js/interactions/confirmation.js?ver=1.0.0') }}"></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
|
||||
<script src="{{ asset('assets/admin/js/custom/deposit-money.js?ver=1.0.0') }}"></script>
|
||||
<script src="{{ asset('assets/js/forms/rupiah-format.js?ver=1.0.0') }}"></script>
|
||||
@endsection
|
||||
@ -115,6 +115,13 @@
|
||||
<span>Pengeluaran Barang</span>
|
||||
</a>
|
||||
</li>
|
||||
<li class="sidebar-list">
|
||||
<i class="fa fa-thumb-tack"></i>
|
||||
<a class="sidebar-link sidebar-title link-nav" href="{{ route('finance.depositMoney') }}">
|
||||
<i data-feather="archive"></i>
|
||||
<span>Setor Uang</span>
|
||||
</a>
|
||||
</li>
|
||||
@endif
|
||||
<li class="sidebar-list">
|
||||
<i class="fa fa-thumb-tack"></i>
|
||||
|
||||
@ -5,6 +5,7 @@
|
||||
use App\Http\Controllers\Admin\Dashboard\OverviewController;
|
||||
use App\Http\Controllers\Admin\Finance\CashController;
|
||||
use App\Http\Controllers\Admin\Finance\DebtController;
|
||||
use App\Http\Controllers\Admin\Finance\DepositMoneyController;
|
||||
use App\Http\Controllers\Admin\Finance\ExpenseController;
|
||||
use App\Http\Controllers\Admin\Finance\GoodsExpenseController;
|
||||
use App\Http\Controllers\Admin\Finance\PayrollController;
|
||||
@ -105,6 +106,15 @@
|
||||
});
|
||||
});
|
||||
|
||||
Route::middleware(['check_role:1,3,4'])->group(function () {
|
||||
Route::prefix('deposit-money')->group(function () {
|
||||
Route::get('/', [DepositMoneyController::class, 'index'])->name('finance.depositMoney');
|
||||
Route::post('store', [DepositMoneyController::class, 'store'])->name('finance.depositMoney.store');
|
||||
Route::put('update/{depositMoney}', [DepositMoneyController::class, 'update'])->name('finance.depositMoney.update');
|
||||
Route::delete('delete/{depositMoney}', [DepositMoneyController::class, 'delete'])->name('finance.depositMoney.delete')->middleware('check_role:1');
|
||||
});
|
||||
});
|
||||
|
||||
Route::get('/payrolls', [PayrollController::class, 'index'])->name('finance.payrolls');
|
||||
Route::prefix('payroll')->group(function () {
|
||||
Route::middleware(['check_role:1,3,4'])->group(function () {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user