refactor: menambahkan relasi user biography dan where barbershop dan menambahkan kolom penginput di view serta menyesuaikan order di datatable

This commit is contained in:
Yoga Pangestu 2024-11-28 20:02:42 +07:00
parent 167f5a111a
commit 38a9441ca8
15 changed files with 28 additions and 16 deletions

View File

@ -20,7 +20,7 @@ public function index(): View
{ {
return view('pages.admin.finance.expenses', [ return view('pages.admin.finance.expenses', [
'pageTitle' => 'Pengeluaran', 'pageTitle' => 'Pengeluaran',
'expenses' => Expense::latest()->get(), 'expenses' => Expense::with(['user', 'user.biography'])->barbershop()->latest()->get(),
]); ]);
} }

View File

@ -26,7 +26,7 @@ public function index(Request $request): View|JsonResponse
return DataTables::eloquent($attendances) return DataTables::eloquent($attendances)
->addIndexColumn() ->addIndexColumn()
->editColumn('date', function ($item) { ->editColumn('created_at', function ($item) {
return formatDateIndo($item->created_at); return formatDateIndo($item->created_at);
}) })
->addColumn('working_time', function ($item) { ->addColumn('working_time', function ($item) {

View File

@ -20,7 +20,7 @@ public function index(): View
{ {
return view('pages.admin.manage.inventory', [ return view('pages.admin.manage.inventory', [
'pageTitle' => 'Barang', 'pageTitle' => 'Barang',
'inventory' => Inventory::latest()->get(), 'inventory' => Inventory::with(['user', 'user.biography'])->barbershop()->latest()->get(),
]); ]);
} }

View File

@ -23,7 +23,7 @@ public function index(): View
{ {
return view('pages.admin.manage.transaction.index', [ return view('pages.admin.manage.transaction.index', [
'pageTitle' => 'Transaksi', 'pageTitle' => 'Transaksi',
'transactions' => Transaction::latest()->get(), 'transactions' => Transaction::with(['user', 'user.biography'])->barbershop()->latest()->get(),
]); ]);
} }

View File

@ -18,7 +18,7 @@ public function index(): View
{ {
return view('pages.admin.master.customers', [ return view('pages.admin.master.customers', [
'pageTitle' => 'Pelanggan', 'pageTitle' => 'Pelanggan',
'customers' => Customer::latest()->get(), 'customers' => Customer::with(['user', 'user.biography'])->barbershop()->latest()->get(),
]); ]);
} }

View File

@ -4,7 +4,7 @@ window.columns = [
orderable: false, orderable: false,
searchable: false searchable: false
}, },
{ data: 'date' }, { data: 'created_at' },
{ data: 'check_in' }, { data: 'check_in' },
{ data: 'check_in_image' }, { data: 'check_in_image' },
{ data: 'check_out' }, { data: 'check_out' },
@ -15,7 +15,7 @@ window.columns = [
function updateWorkingTime() { function updateWorkingTime() {
const today = moment().format('YYYY-MM-DD'); const today = moment().format('YYYY-MM-DD');
$('table tbody tr').each(function() { $('table tbody tr').each(function () {
const dateCell = $(this).find('td:nth-child(2)'); const dateCell = $(this).find('td:nth-child(2)');
const checkOutCell = $(this).find('td:nth-child(5)'); const checkOutCell = $(this).find('td:nth-child(5)');
const workingTimeCell = $(this).find('td:nth-child(7)'); const workingTimeCell = $(this).find('td:nth-child(7)');
@ -23,7 +23,6 @@ function updateWorkingTime() {
const rowDate = moment(dateCell.text(), 'ddd, DD MMM YYYY').format('YYYY-MM-DD'); const rowDate = moment(dateCell.text(), 'ddd, DD MMM YYYY').format('YYYY-MM-DD');
const checkOutText = checkOutCell.text().trim(); const checkOutText = checkOutCell.text().trim();
// Cek apakah baris adalah hari ini dan check_out masih '-'
if (rowDate === today && checkOutText === '-') { if (rowDate === today && checkOutText === '-') {
const checkInCell = $(this).find('td:nth-child(3)'); const checkInCell = $(this).find('td:nth-child(3)');
const checkInTime = checkInCell.text().trim(); const checkInTime = checkInCell.text().trim();
@ -53,17 +52,12 @@ function updateWorkingTime() {
}); });
} }
// Panggil fungsi updateWorkingTime setiap detik $(document).ready(function () {
$(document).ready(function() {
// Pastikan moment.js sudah diinclude
if (typeof moment !== 'undefined') { if (typeof moment !== 'undefined') {
// Set moment locale ke Indonesia
moment.locale('id'); moment.locale('id');
// Update pertama kali saat halaman dimuat
updateWorkingTime(); updateWorkingTime();
// Set interval untuk update setiap detik
setInterval(updateWorkingTime, 1000); setInterval(updateWorkingTime, 1000);
} else { } else {
console.error('moment.js library tidak ditemukan'); console.error('moment.js library tidak ditemukan');

View File

@ -1,4 +1,9 @@
(function ($) { (function ($) {
function getColumnIndex(columns, columnName) {
return columns.findIndex(column => column.data === columnName);
}
const createdAtIndex = getColumnIndex(columns, 'created_at');
$('#datatable').DataTable({ $('#datatable').DataTable({
serverSide: true, serverSide: true,
processing: true, processing: true,
@ -20,5 +25,6 @@
[10, 25, 50, 100], [10, 25, 50, 100],
[10, 25, 50, 100] [10, 25, 50, 100]
], ],
order: createdAtIndex !== -1 ? [[createdAtIndex, "desc"]] : [],
}); });
})(jQuery); })(jQuery);

View File

@ -22,6 +22,7 @@ class="btn btn-primary">
<thead> <thead>
<tr> <tr>
<th>No</th> <th>No</th>
<th>Penginput</th>
<th>Nama</th> <th>Nama</th>
<th>Jumlah</th> <th>Jumlah</th>
<th>Tanggal</th> <th>Tanggal</th>
@ -32,6 +33,7 @@ class="btn btn-primary">
@foreach ($cashes as $cash) @foreach ($cashes as $cash)
<tr> <tr>
<td>{{ $loop->iteration }}</td> <td>{{ $loop->iteration }}</td>
<td>{{ $cash->user->biography->full_name ?? '-deleted-' }}</td>
<td>{{ $cash->name }}</td> <td>{{ $cash->name }}</td>
<td>{{ formatToRupiah($cash->amount) ?? '-' }}</td> <td>{{ formatToRupiah($cash->amount) ?? '-' }}</td>
<td>{{ formatDateIndo($cash->created_at) }}</td> <td>{{ formatDateIndo($cash->created_at) }}</td>

View File

@ -22,6 +22,7 @@
<thead> <thead>
<tr> <tr>
<th>No</th> <th>No</th>
<th>Penginput</th>
<th>Nama</th> <th>Nama</th>
<th>Jumlah</th> <th>Jumlah</th>
<th>Bukti</th> <th>Bukti</th>
@ -33,6 +34,7 @@
@foreach ($expenses as $expense) @foreach ($expenses as $expense)
<tr> <tr>
<td>{{ $loop->iteration }}</td> <td>{{ $loop->iteration }}</td>
<td>{{ $expense->user->biography->full_name ?? '-deleted-' }}</td>
<td>{{ $expense->name }}</td> <td>{{ $expense->name }}</td>
<td>{{ formatToRupiah($expense->amount) ?? '-' }}</td> <td>{{ formatToRupiah($expense->amount) ?? '-' }}</td>
<td> <td>

View File

@ -67,7 +67,7 @@
<div class="col-lg-6 position-relative"> <div class="col-lg-6 position-relative">
<label class="form-label" for="shaving_result">Hasil Mencukur</label> <label class="form-label" for="shaving_result">Hasil Mencukur</label>
<input name="shaving_result" class="form-control @error('shaving_result') is-invalid @enderror" <input name="shaving_result" class="form-control @error('shaving_result') is-invalid @enderror"
id="shaving_result" type="text" placeholder="Silahkan Pilih Pegawai" id="shaving_result" type="text" placeholder="Silakan Pilih Pegawai"
value="{{ old('shaving_result') }}" readonly> value="{{ old('shaving_result') }}" readonly>
@error('shaving_result') @error('shaving_result')
<div class="invalid-feedback"> <div class="invalid-feedback">

View File

@ -63,7 +63,7 @@
<div class="col-lg-6 position-relative"> <div class="col-lg-6 position-relative">
<label class="form-label" for="shaving_result">Hasil Mencukur</label> <label class="form-label" for="shaving_result">Hasil Mencukur</label>
<input name="shaving_result" class="form-control @error('shabing_result') is-invalid @enderror" <input name="shaving_result" class="form-control @error('shabing_result') is-invalid @enderror"
id="shaving_result" type="text" placeholder="Silahkan Pilih Pegawai" id="shaving_result" type="text" placeholder="Silakan Pilih Pegawai"
value="{{ old('shaving_result', formatToRupiah($payroll->shaving_result)) }}" readonly> value="{{ old('shaving_result', formatToRupiah($payroll->shaving_result)) }}" readonly>
@error('shaving_result') @error('shaving_result')
<div class="invalid-feedback"> <div class="invalid-feedback">

View File

@ -22,6 +22,7 @@
<thead> <thead>
<tr> <tr>
<th>No</th> <th>No</th>
<th>Penginput</th>
<th>Nama</th> <th>Nama</th>
<th>Kuantitas</th> <th>Kuantitas</th>
<th>Harga</th> <th>Harga</th>
@ -36,6 +37,7 @@
@foreach ($inventory as $item) @foreach ($inventory as $item)
<tr> <tr>
<td>{{ $loop->iteration }}</td> <td>{{ $loop->iteration }}</td>
<td>{{ $item->user->biography->full_name ?? '-deleted-' }}</td>
<td>{{ $item->name }}</td> <td>{{ $item->name }}</td>
<td>{{ $item->quantity }}</td> <td>{{ $item->quantity }}</td>
<td>{{ formatToRupiah($item->price) }}</td> <td>{{ formatToRupiah($item->price) }}</td>

View File

@ -18,6 +18,7 @@
<thead> <thead>
<tr> <tr>
<th>No</th> <th>No</th>
<th>Penginput</th>
<th>Pelanggan</th> <th>Pelanggan</th>
<th>Layanan</th> <th>Layanan</th>
<th>Harga</th> <th>Harga</th>
@ -33,6 +34,7 @@
@foreach ($transactions as $transaction) @foreach ($transactions as $transaction)
<tr> <tr>
<td>{{ $loop->iteration }}</td> <td>{{ $loop->iteration }}</td>
<td>{{ $transaction->user->biography->full_name ?? '-deleted-' }}</td>
<td>{{ $transaction->customer->name }}</td> <td>{{ $transaction->customer->name }}</td>
<td>{{ $transaction->service->name }}</td> <td>{{ $transaction->service->name }}</td>
<td>{{ formatToRupiah($transaction->price) }}</td> <td>{{ formatToRupiah($transaction->price) }}</td>

View File

@ -22,6 +22,7 @@
<thead> <thead>
<tr> <tr>
<th>No</th> <th>No</th>
<th>Penginput</th>
<th>Nama</th> <th>Nama</th>
<th>Kontak</th> <th>Kontak</th>
<th>Tanggal</th> <th>Tanggal</th>
@ -32,6 +33,7 @@
@foreach ($customers as $customer) @foreach ($customers as $customer)
<tr> <tr>
<td>{{ $loop->iteration }}</td> <td>{{ $loop->iteration }}</td>
<td>{{ $customer->user->biography->full_name ?? 'deleted-' }}</td>
<td>{{ $customer->name }}</td> <td>{{ $customer->name }}</td>
<td>{{ $customer->contact_number ?? '-' }}</td> <td>{{ $customer->contact_number ?? '-' }}</td>
<td>{{ formatDateIndo($customer->created_at) }}</td> <td>{{ formatDateIndo($customer->created_at) }}</td>

View File

@ -18,6 +18,7 @@
<thead> <thead>
<tr> <tr>
<th>No</th> <th>No</th>
<th>Penginput</th>
<th>Nama</th> <th>Nama</th>
<th>Harga</th> <th>Harga</th>
<th>Deskripsi</th> <th>Deskripsi</th>
@ -29,6 +30,7 @@
@foreach ($services as $service) @foreach ($services as $service)
<tr> <tr>
<td>{{ $loop->iteration }}</td> <td>{{ $loop->iteration }}</td>
<td>{{ $service->user->biography->full_name ?? '-deleted-' }}</td>
<td>{{ $service->name }}</td> <td>{{ $service->name }}</td>
<td>{{ formatToRupiah($service->price) }}</td> <td>{{ formatToRupiah($service->price) }}</td>
<td>{{ $service->description }}</td> <td>{{ $service->description }}</td>