feat: menambahkan fitur baru yaitu pengeluaran barang dan dan menyesuaikan table nya karena 1 table dengan tabel pengeluaran
This commit is contained in:
parent
8048e0862c
commit
76bb090234
@ -19,9 +19,10 @@ class ExpenseController extends Controller
|
|||||||
public function index(): View
|
public function index(): View
|
||||||
{
|
{
|
||||||
return view('pages.admin.finance.expenses', [
|
return view('pages.admin.finance.expenses', [
|
||||||
'pageTitle' => 'Pengeluaran',
|
'pageTitle' => 'Pengeluaran Tetap',
|
||||||
'expenses' => Expense::with(['user', 'user.biography'])
|
'expenses' => Expense::with(['user', 'user.biography'])
|
||||||
->barbershop()
|
->barbershop()
|
||||||
|
->fixed()
|
||||||
->when(auth()->user()->role_id === 4, function ($query) {
|
->when(auth()->user()->role_id === 4, function ($query) {
|
||||||
return $query->where('user_id', auth()->id());
|
return $query->where('user_id', auth()->id());
|
||||||
})
|
})
|
||||||
|
|||||||
115
app/Http/Controllers/Admin/Finance/GoodsExpenseController.php
Normal file
115
app/Http/Controllers/Admin/Finance/GoodsExpenseController.php
Normal file
@ -0,0 +1,115 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers\Admin\Finance;
|
||||||
|
|
||||||
|
use App\Http\Controllers\Controller;
|
||||||
|
use App\Http\Requests\Admin\Finance\ExpenseRequest;
|
||||||
|
use App\Models\Barbershop;
|
||||||
|
use App\Models\Expense;
|
||||||
|
use App\Traits\UploadAttachment;
|
||||||
|
use Illuminate\Contracts\View\View;
|
||||||
|
use Illuminate\Http\RedirectResponse;
|
||||||
|
use Illuminate\Support\Facades\Auth;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
|
||||||
|
class GoodsExpenseController extends Controller
|
||||||
|
{
|
||||||
|
use UploadAttachment;
|
||||||
|
|
||||||
|
public function index(): View
|
||||||
|
{
|
||||||
|
return view('pages.admin.finance.goods-expense', [
|
||||||
|
'pageTitle' => 'Pengeluaran Barang',
|
||||||
|
'expenses' => Expense::with(['user', 'user.biography'])
|
||||||
|
->barbershop()
|
||||||
|
->goods()
|
||||||
|
->latest()
|
||||||
|
->get(),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function store(ExpenseRequest $request): RedirectResponse
|
||||||
|
{
|
||||||
|
$validatedData = $request->validated();
|
||||||
|
$barbershopId = Auth::user()->barbershop_id;
|
||||||
|
$barbershop = Barbershop::findOrFail($barbershopId);
|
||||||
|
|
||||||
|
if ($validatedData['use_cash'] === '1' && $barbershop->cash < $validatedData['amount']) {
|
||||||
|
notify()->error('Saldo kas tidak mencukupi', 'Gagal');
|
||||||
|
|
||||||
|
return back()->withInput();
|
||||||
|
}
|
||||||
|
|
||||||
|
DB::transaction(function () use ($validatedData, $barbershop, $barbershopId) {
|
||||||
|
$newExpense = Expense::create(array_merge($validatedData, [
|
||||||
|
'user_id' => Auth::id(),
|
||||||
|
'barbershop_id' => $barbershopId,
|
||||||
|
'type' => '2',
|
||||||
|
]));
|
||||||
|
|
||||||
|
if ($validatedData['use_cash'] === '1') {
|
||||||
|
$barbershop->decrement('cash', $validatedData['amount']);
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->uploadAttachment($validatedData['proof'], 'expenses', Expense::class, $newExpense->id, 'expenses');
|
||||||
|
});
|
||||||
|
|
||||||
|
notify()->success('Data berhasil ditambahkan', 'Berhasil');
|
||||||
|
|
||||||
|
return back();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function update(ExpenseRequest $request, Expense $expense): RedirectResponse
|
||||||
|
{
|
||||||
|
$validatedData = $request->validated();
|
||||||
|
$barbershop = Barbershop::findOrFail($expense->barbershop_id);
|
||||||
|
|
||||||
|
$amountDifference = $validatedData['amount'] - $expense->amount;
|
||||||
|
|
||||||
|
if ($validatedData['use_cash'] === '1') {
|
||||||
|
$requiredCash = $barbershop->cash - ($amountDifference < 0 ? 0 : $amountDifference);
|
||||||
|
if ($requiredCash < 0) {
|
||||||
|
notify()->error('Saldo kas tidak mencukupi', 'Gagal');
|
||||||
|
|
||||||
|
return back()->withInput();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
DB::transaction(function () use ($validatedData, $expense, $barbershop) {
|
||||||
|
if ($expense->use_cash === '1') {
|
||||||
|
$barbershop->increment('cash', $expense->amount);
|
||||||
|
}
|
||||||
|
|
||||||
|
$expense->update($validatedData);
|
||||||
|
|
||||||
|
if ($validatedData['use_cash'] === '1') {
|
||||||
|
$barbershop->decrement('cash', $validatedData['amount']);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($validatedData['proof'])) {
|
||||||
|
$this->uploadAttachment($validatedData['proof'], 'expenses', Expense::class, $expense->id, 'expenses');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
notify()->success('Data berhasil diperbarui', 'Berhasil');
|
||||||
|
|
||||||
|
return back();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function delete(Expense $expense): RedirectResponse
|
||||||
|
{
|
||||||
|
$barbershop = Barbershop::findOrFail($expense->barbershop_id);
|
||||||
|
|
||||||
|
DB::transaction(function () use ($expense, $barbershop) {
|
||||||
|
if ($expense->use_cash === '1') {
|
||||||
|
$barbershop->increment('cash', $expense->amount);
|
||||||
|
}
|
||||||
|
|
||||||
|
$expense->delete();
|
||||||
|
});
|
||||||
|
|
||||||
|
notify()->success('Data berhasil dihapus', 'Berhasil');
|
||||||
|
|
||||||
|
return back();
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -24,6 +24,7 @@ class Expense extends Model
|
|||||||
'name',
|
'name',
|
||||||
'amount',
|
'amount',
|
||||||
'use_cash',
|
'use_cash',
|
||||||
|
'type',
|
||||||
];
|
];
|
||||||
|
|
||||||
public function scopeBarbershop(Builder $query): Builder
|
public function scopeBarbershop(Builder $query): Builder
|
||||||
@ -41,6 +42,16 @@ public function scopeYesterday(Builder $query): Builder
|
|||||||
return $query->whereDate('created_at', Carbon::yesterday());
|
return $query->whereDate('created_at', Carbon::yesterday());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function scopeGoods(Builder $query): Builder
|
||||||
|
{
|
||||||
|
return $query->where('type', '2');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function scopeFixed(Builder $query): Builder
|
||||||
|
{
|
||||||
|
return $query->where('type', '1');
|
||||||
|
}
|
||||||
|
|
||||||
public function user(): BelongsTo
|
public function user(): BelongsTo
|
||||||
{
|
{
|
||||||
return $this->belongsTo(User::class);
|
return $this->belongsTo(User::class);
|
||||||
|
|||||||
@ -0,0 +1,28 @@
|
|||||||
|
<?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::table('expenses', function (Blueprint $table) {
|
||||||
|
$table->enum('type', ['1', '2'])->default('1')->after('use_cash')->comment('1:Bukan Barang 2:Barang');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*/
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
Schema::table('expenses', function (Blueprint $table) {
|
||||||
|
$table->dropColumn('type');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
192
resources/views/pages/admin/finance/goods-expense.blade.php
Normal file
192
resources/views/pages/admin/finance/goods-expense.blade.php
Normal file
@ -0,0 +1,192 @@
|
|||||||
|
@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 Pengeluaran" data-url="{{ route('finance.goodsExpense.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>Nama</th>
|
||||||
|
<th>Jumlah</th>
|
||||||
|
<th>Bukti</th>
|
||||||
|
<th>Tanggal</th>
|
||||||
|
@if (in_array(auth()->user()->role_id, [1, 3, 4]))
|
||||||
|
<th>Aksi</th>
|
||||||
|
@endif
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
@foreach ($expenses as $expense)
|
||||||
|
<tr>
|
||||||
|
<td>{{ $loop->iteration }}</td>
|
||||||
|
<td>{{ $expense->user->biography->full_name ?? '-deleted-' }}</td>
|
||||||
|
<td>{{ $expense->name }}</td>
|
||||||
|
<td>{{ formatToRupiah($expense->amount) ?? '-' }}</td>
|
||||||
|
<td>
|
||||||
|
@if ($expense->attachment && $expense->attachment->formatted_attachment)
|
||||||
|
<a
|
||||||
|
href="{{ Storage::url("expenses/{$expense->attachment->formatted_attachment}") }}">
|
||||||
|
<img src="{{ Storage::url("expenses/{$expense->attachment->formatted_attachment}") }}"
|
||||||
|
alt="{{ $expense->name }}" width="77" height="77">
|
||||||
|
</a>
|
||||||
|
@else
|
||||||
|
<a href="{{ asset('assets/images/no-imge.png') }}">
|
||||||
|
<img src="{{ asset('assets/images/no-imge.png') }}"
|
||||||
|
alt="Default Image" style="width: 77px; height: 77px">
|
||||||
|
</a>
|
||||||
|
@endif
|
||||||
|
</td>
|
||||||
|
<td>{{ formatDateIndo($expense->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 Pengeluaran"
|
||||||
|
data-url="{{ route('finance.goodsExpense.update', encryptId($expense->id)) }}"
|
||||||
|
data-method="put" data-name="{{ $expense->name }}"
|
||||||
|
data-amount="{{ formatToRupiah($expense->amount) }}"
|
||||||
|
data-use-cash="{{ $expense->use_cash }}">
|
||||||
|
<i data-feather="edit"></i>
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
@if (auth()->user()->role_id === 1)
|
||||||
|
<li class="delete">
|
||||||
|
<form
|
||||||
|
action="{{ route('finance.goodsExpense.delete', encryptId($expense->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="name">Nama</label>
|
||||||
|
<input name="name" class="form-control @error('name') is-invalid @enderror"
|
||||||
|
id="name" type="text" placeholder="Masukan Nama" value="{{ old('name') }}">
|
||||||
|
@error('name')
|
||||||
|
<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">
|
||||||
|
<label class="form-label" for="use_cash">Gunakan Kas</label>
|
||||||
|
<div class="form-check radio ps-0">
|
||||||
|
<ul class="radio-wrapper">
|
||||||
|
<li>
|
||||||
|
<input class="form-check-input" id="radio-yes" type="radio" name="use_cash"
|
||||||
|
value="1" @checked(old('use_cash') == '1')>
|
||||||
|
<label class="form-check-label" for="radio-yes">
|
||||||
|
<i data-feather="check"></i>
|
||||||
|
</label>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<input class="form-check-input" id="radio-no" type="radio"
|
||||||
|
name="use_cash" value="2" @checked(old('use_cash') == '2')>
|
||||||
|
<label class="form-check-label" for="radio-no">
|
||||||
|
<i data-feather="x"></i>
|
||||||
|
</label>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
@error('use_cash')
|
||||||
|
<div class="invalid-feedback">
|
||||||
|
{{ $message }}
|
||||||
|
</div>
|
||||||
|
@enderror
|
||||||
|
</div>
|
||||||
|
<div class="col-lg-12 position-relative">
|
||||||
|
<label class="form-label" for="proof">Bukti
|
||||||
|
<span class="form-span"><i>(.jpeg,.png,.jpg,.gif,.svg)</i></span>
|
||||||
|
</label>
|
||||||
|
<input name="proof" class="form-control @error('proof') is-invalid @enderror"
|
||||||
|
id="proof" type="file" value="{{ old('proof') }}"
|
||||||
|
accept="image/jpeg,image/png,image/jpg,image/gif,image/svg">
|
||||||
|
@error('proof')
|
||||||
|
<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/expense.js?ver=1.0.0') }}"></script>
|
||||||
|
<script src="{{ asset('assets/js/forms/rupiah-format.js?ver=1.0.0') }}"></script>
|
||||||
|
@endsection
|
||||||
@ -103,7 +103,16 @@
|
|||||||
<i class="fa fa-thumb-tack"></i>
|
<i class="fa fa-thumb-tack"></i>
|
||||||
<a class="sidebar-link sidebar-title link-nav" href="{{ route('finance.expenses') }}">
|
<a class="sidebar-link sidebar-title link-nav" href="{{ route('finance.expenses') }}">
|
||||||
<i data-feather="log-out"></i>
|
<i data-feather="log-out"></i>
|
||||||
<span>Pengeluaran</span>
|
<span>Pengeluaran Tetap</span>
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
@endif
|
||||||
|
@if (in_array(auth()->user()->role_id, [1, 2, 3]))
|
||||||
|
<li class="sidebar-list">
|
||||||
|
<i class="fa fa-thumb-tack"></i>
|
||||||
|
<a class="sidebar-link sidebar-title link-nav" href="{{ route('finance.goodsExpense') }}">
|
||||||
|
<i data-feather="log-out"></i>
|
||||||
|
<span>Pengeluaran Barang</span>
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
@endif
|
@endif
|
||||||
|
|||||||
@ -6,6 +6,7 @@
|
|||||||
use App\Http\Controllers\Admin\Finance\CashController;
|
use App\Http\Controllers\Admin\Finance\CashController;
|
||||||
use App\Http\Controllers\Admin\Finance\DebtController;
|
use App\Http\Controllers\Admin\Finance\DebtController;
|
||||||
use App\Http\Controllers\Admin\Finance\ExpenseController;
|
use App\Http\Controllers\Admin\Finance\ExpenseController;
|
||||||
|
use App\Http\Controllers\Admin\Finance\GoodsExpenseController;
|
||||||
use App\Http\Controllers\Admin\Finance\PayrollController;
|
use App\Http\Controllers\Admin\Finance\PayrollController;
|
||||||
use App\Http\Controllers\Admin\Manage\AttendanceController;
|
use App\Http\Controllers\Admin\Manage\AttendanceController;
|
||||||
use App\Http\Controllers\Admin\Manage\InventoryController;
|
use App\Http\Controllers\Admin\Manage\InventoryController;
|
||||||
@ -95,6 +96,15 @@
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Route::middleware(['check_role:1,3,4'])->group(function () {
|
||||||
|
Route::prefix('goods-expense')->group(function () {
|
||||||
|
Route::get('/', [GoodsExpenseController::class, 'index'])->name('finance.goodsExpense');
|
||||||
|
Route::post('store', [GoodsExpenseController::class, 'store'])->name('finance.goodsExpense.store');
|
||||||
|
Route::put('update/{expense}', [GoodsExpenseController::class, 'update'])->name('finance.goodsExpense.update');
|
||||||
|
Route::delete('delete/{expense}', [GoodsExpenseController::class, 'delete'])->name('finance.goodsExpense.delete')->middleware('check_role:1');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
Route::get('/payrolls', [PayrollController::class, 'index'])->name('finance.payrolls');
|
Route::get('/payrolls', [PayrollController::class, 'index'])->name('finance.payrolls');
|
||||||
Route::prefix('payroll')->group(function () {
|
Route::prefix('payroll')->group(function () {
|
||||||
Route::middleware(['check_role:1,3,4'])->group(function () {
|
Route::middleware(['check_role:1,3,4'])->group(function () {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user