fix(transaction): updated TransactionController, TransactionRequest, and transaction edit/view pages to include customer and service selects, added payment method radio buttons, and modified image upload and deletion logic
This commit is contained in:
parent
23c2204927
commit
8f6404b36b
@ -7,6 +7,7 @@
|
||||
use App\Models\Customer;
|
||||
use App\Models\Service;
|
||||
use App\Models\Transaction;
|
||||
use App\Traits\DeleteAttachment;
|
||||
use App\Traits\UploadAttachment;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
@ -16,7 +17,7 @@
|
||||
|
||||
class TransactionController extends Controller
|
||||
{
|
||||
use UploadAttachment;
|
||||
use UploadAttachment, DeleteAttachment;
|
||||
|
||||
public function index(): View
|
||||
{
|
||||
@ -38,12 +39,23 @@ public function create(): View
|
||||
public function store(TransactionRequest $request): RedirectResponse
|
||||
{
|
||||
$validatedData = $request->validated();
|
||||
DB::transaction(function () use ($validatedData) {
|
||||
$findCustomer = Customer::find($validatedData['customer']);
|
||||
DB::transaction(function () use ($validatedData, $findCustomer) {
|
||||
$customer = null;
|
||||
$userId = Auth::id();
|
||||
$barbershopId = Auth::user()->barbershop_id;
|
||||
if (! $findCustomer) {
|
||||
$customer = Customer::create([
|
||||
'user_id' => $userId,
|
||||
'barbershop_id' => $barbershopId,
|
||||
'name' => $validatedData['customer'],
|
||||
]);
|
||||
}
|
||||
$newTransaction = Transaction::create(array_merge($validatedData, [
|
||||
'user_id' => Auth::id(),
|
||||
'barbershop_id' => Auth::user()->barbershop_id,
|
||||
'user_id' => $userId,
|
||||
'barbershop_id' => $barbershopId,
|
||||
'service_id' => $validatedData['service'],
|
||||
'customer_id' => $validatedData['customer'],
|
||||
'customer_id' => $customer ? $customer->id : $validatedData['customer'],
|
||||
]));
|
||||
$this->uploadAttachment($validatedData['image'], 'transactions', Transaction::class, $newTransaction->id);
|
||||
});
|
||||
@ -57,6 +69,8 @@ public function edit(Transaction $transaction): View
|
||||
{
|
||||
return view('pages.admin.manage.transaction.edit', [
|
||||
'pageTitle' => 'Edit Transaksi',
|
||||
'services' => Service::latest()->get(),
|
||||
'customers' => Customer::latest()->get(),
|
||||
'transaction' => $transaction,
|
||||
]);
|
||||
}
|
||||
@ -65,7 +79,15 @@ public function update(Transaction $transaction, TransactionRequest $request): R
|
||||
{
|
||||
$validatedData = $request->validated();
|
||||
|
||||
$transaction->update($validatedData);
|
||||
DB::transaction(function () use ($validatedData, $transaction) {
|
||||
$transaction->update(array_merge($validatedData, [
|
||||
'service_id' => $validatedData['service'],
|
||||
'customer_id' => $validatedData['customer'],
|
||||
]));
|
||||
if (isset($validatedData['image'])) {
|
||||
$this->uploadAttachment($validatedData['image'], 'transactions', Transaction::class, $transaction->id);
|
||||
}
|
||||
});
|
||||
|
||||
notify()->success('Data berhasil diubah', 'Berhasil');
|
||||
|
||||
@ -74,7 +96,10 @@ public function update(Transaction $transaction, TransactionRequest $request): R
|
||||
|
||||
public function delete(Transaction $transaction): RedirectResponse
|
||||
{
|
||||
$transaction->delete();
|
||||
DB::transaction(function () use ($transaction) {
|
||||
$this->deleteAttachment('transactions', $transaction);
|
||||
$transaction->delete();
|
||||
});
|
||||
|
||||
notify()->success('Data berhasil dihapus', 'Berhasil');
|
||||
|
||||
@ -95,7 +120,7 @@ public function getPrice(string $serviceId): JsonResponse
|
||||
return response()->json([
|
||||
'status' => true,
|
||||
'message' => 'Data retrieved successfully',
|
||||
'data' => decimalToInteger($service->price),
|
||||
'data' => formatToRupiah($service->price),
|
||||
], 200);
|
||||
}
|
||||
}
|
||||
|
||||
@ -32,7 +32,7 @@ public function rules(): array
|
||||
|
||||
return [
|
||||
'service' => ['required', Rule::exists('services', 'id')],
|
||||
'customer' => ['required', Rule::exists('customers', 'id')],
|
||||
'customer' => ['required'],
|
||||
'price' => ['required', 'numeric', 'min:0', 'max:999999.99'],
|
||||
'discount' => ['required', 'numeric', 'min:0', 'max:999999.99'],
|
||||
'total' => ['required', 'numeric', 'min:0', 'max:999999.99'],
|
||||
|
||||
@ -2,5 +2,6 @@ $(document).ready(function () {
|
||||
$('.select2').select2({
|
||||
allowClear: true,
|
||||
placeholder: '-- Pilih --',
|
||||
tags: true
|
||||
});
|
||||
})
|
||||
|
||||
@ -1,24 +1,52 @@
|
||||
@extends('layouts.admin')
|
||||
@section('styles')
|
||||
<link rel="stylesheet" href="{{ asset('assets/admin/css/vendors/select2.css') }}">
|
||||
@endsection
|
||||
@section('app')
|
||||
<div class="container-fluid">
|
||||
<div class="list-product-header">
|
||||
<div>
|
||||
<a class="btn btn-dark" href="{{ route('master.services') }}">Kembali</a>
|
||||
<a class="btn btn-dark" href="{{ route('manage.transactions') }}">Kembali</a>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
<form class="row g-3 custom-input" action="{{ route('master.service.update', encryptId($service->id)) }}"
|
||||
method="post">
|
||||
<form class="row g-3 custom-input"
|
||||
action="{{ route('manage.transaction.update', encryptId($transaction->id)) }}" method="post"
|
||||
enctype="multipart/form-data">
|
||||
@csrf
|
||||
@method('put')
|
||||
<div class="col-lg-6 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', $service->name) }}">
|
||||
@error('name')
|
||||
<label class="form-label" for="customer">Pelanggan
|
||||
</label>
|
||||
<select name="customer" class="form-control @error('customer') is-invalid @enderror select2"
|
||||
id="customer">
|
||||
<option value=""></option>
|
||||
@foreach ($customers as $customer)
|
||||
<option value="{{ $customer->id }}" @selected($transaction->customer_id == $customer->id)>
|
||||
{{ $customer->name }}
|
||||
</option>
|
||||
@endforeach
|
||||
</select>
|
||||
@error('customer')
|
||||
<div class="invalid-feedback">
|
||||
{{ $message }}
|
||||
</div>
|
||||
@enderror
|
||||
</div>
|
||||
<div class="col-lg-6 position-relative">
|
||||
<label class="form-label" for="service">Layanan
|
||||
</label>
|
||||
<select name="service" class="form-control @error('service') is-invalid @enderror select2"
|
||||
id="service">
|
||||
<option value=""></option>
|
||||
@foreach ($services as $service)
|
||||
<option value="{{ $service->id }}" @selected($transaction->service_id == $service->id)>
|
||||
{{ $service->name }}
|
||||
</option>
|
||||
@endforeach
|
||||
</select>
|
||||
@error('service')
|
||||
<div class="invalid-feedback">
|
||||
{{ $message }}
|
||||
</div>
|
||||
@ -28,18 +56,76 @@
|
||||
<label class="form-label" for="price">Harga</label>
|
||||
<input name="price" class="form-control rupiah-format @error('price') is-invalid @enderror"
|
||||
id="price" type="text" placeholder="Masukan Harga"
|
||||
value="{{ old('price', formatToRupiah($service->price)) }}" inputmode="numeric">
|
||||
value="{{ old('price', formatToRupiah($transaction->price)) }}" inputmode="numeric" readonly>
|
||||
@error('price')
|
||||
<div class="invalid-feedback">
|
||||
{{ $message }}
|
||||
</div>
|
||||
@enderror
|
||||
</div>
|
||||
<div class="col-lg-6 position-relative">
|
||||
<label class="form-label" for="discount">Diskon</label>
|
||||
<input name="discount" class="form-control rupiah-format @error('discount') is-invalid @enderror"
|
||||
id="discount" type="text" placeholder="Masukan Diskon"
|
||||
value="{{ old('discount', formatToRupiah($transaction->discount)) }}" inputmode="numeric">
|
||||
@error('discount')
|
||||
<div class="invalid-feedback">
|
||||
{{ $message }}
|
||||
</div>
|
||||
@enderror
|
||||
</div>
|
||||
<div class="col-lg-6 position-relative">
|
||||
<label class="form-label" for="total">Total</label>
|
||||
<input name="total" class="form-control rupiah-format @error('total') is-invalid @enderror"
|
||||
id="total" type="text" placeholder="Masukan Total"
|
||||
value="{{ old('total', formatToRupiah($transaction->total)) }}" inputmode="numeric">
|
||||
@error('total')
|
||||
<div class="invalid-feedback">
|
||||
{{ $message }}
|
||||
</div>
|
||||
@enderror
|
||||
</div>
|
||||
<div class="col-lg-6 position-relative">
|
||||
<label class="form-label" for="image">Gambar
|
||||
<span class="form-span"><i>(.jpeg,.png,.jpg,.gif,.svg)</i></span>
|
||||
</label>
|
||||
<input name="image" class="form-control @error('image') is-invalid @enderror" id="image"
|
||||
type="file" value="{{ old('image') }}"
|
||||
accept="image/jpeg,image/png,image/jpg,image/gif,image/svg">
|
||||
@error('image')
|
||||
<div class="invalid-feedback">
|
||||
{{ $message }}
|
||||
</div>
|
||||
@enderror
|
||||
</div>
|
||||
<div class="col-lg-12 position-relative">
|
||||
<label class="form-label" for="description">Deskripsi</label>
|
||||
<textarea name="description" class="form-control @error('description') is-invalid @enderror" id="description"
|
||||
rows="3" placeholder="Masukan Deskripsi">{{ old('description', $service->description) }}</textarea>
|
||||
@error('description')
|
||||
<label class="form-label" for="payment_method">Metode Pembayaran</label>
|
||||
<div class="form-check radio ps-0">
|
||||
<ul class="radio-wrapper">
|
||||
<li>
|
||||
<input class="form-check-input" id="radio-cash" type="radio" name="payment_method"
|
||||
value="1" @checked($transaction->payment_method == '1')>
|
||||
<label class="form-check-label" for="radio-cash">
|
||||
Tunai
|
||||
</label>
|
||||
</li>
|
||||
<li>
|
||||
<input class="form-check-input" id="radio-qris" type="radio" name="payment_method"
|
||||
value="2" @checked($transaction->payment_method == '2')>
|
||||
<label class="form-check-label" for="radio-qris">
|
||||
Qris
|
||||
</label>
|
||||
</li>
|
||||
<li>
|
||||
<input class="form-check-input" id="radio-other" type="radio" name="payment_method"
|
||||
value="3" @checked($transaction->payment_method == '3')>
|
||||
<label class="form-check-label" for="radio-other">
|
||||
Lainnya
|
||||
</label>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
@error('payment_method')
|
||||
<div class="invalid-feedback">
|
||||
{{ $message }}
|
||||
</div>
|
||||
@ -56,4 +142,7 @@
|
||||
@section('afterScripts')
|
||||
<script src="{{ asset('assets/js/forms/button-disable.js?ver=1.0.0') }}"></script>
|
||||
<script src="{{ asset('assets/js/forms/rupiah-format.js?ver=1.0.0') }}"></script>
|
||||
<script src="{{ asset('assets/admin/js/select2/select2.js') }}"></script>
|
||||
<script src="{{ asset('assets/admin/js/select2/select2-config.js?ver=1.0.0') }}"></script>
|
||||
<script src="{{ asset('assets/admin/js/custom/transaction.js?ver=1.0.0') }}"></script>
|
||||
@endsection
|
||||
|
||||
@ -23,6 +23,7 @@
|
||||
<th>Harga</th>
|
||||
<th>Diskon</th>
|
||||
<th>Total</th>
|
||||
<th>Metode Pembayaran</th>
|
||||
<th>Gambar</th>
|
||||
<th>Tanggal</th>
|
||||
<th>Aksi</th>
|
||||
@ -37,6 +38,17 @@
|
||||
<td>{{ formatToRupiah($transaction->price) }}</td>
|
||||
<td>{{ formatToRupiah($transaction->discount) }}</td>
|
||||
<td>{{ formatToRupiah($transaction->total) }}</td>
|
||||
<td>
|
||||
@if ($transaction->payment_method === '1')
|
||||
<span class="badge badge-primary">Tunai</span>
|
||||
@elseif($transaction->payment_method === '2')
|
||||
<span class="badge badge-info">Qris</span>
|
||||
@elseif($transaction->payment_method === '3')
|
||||
<span class="badge badge-success">Lainnya</span>
|
||||
@else
|
||||
<span class="badge badge-danger">Tidak Diketahui</span>
|
||||
@endif
|
||||
</td>
|
||||
<td>
|
||||
@if ($transaction->attachment && $transaction->attachment->formatted_attachment)
|
||||
<a
|
||||
|
||||
Loading…
Reference in New Issue
Block a user