fix form create update postcheck and precheck
This commit is contained in:
@@ -15,6 +15,9 @@ use Illuminate\Support\Carbon;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use App\Models\Precheck;
|
||||
use App\Models\Postcheck;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Exception;
|
||||
|
||||
class TransactionController extends Controller
|
||||
@@ -519,7 +522,6 @@ class TransactionController extends Controller
|
||||
$works_count = count($works);
|
||||
$share = $month_trxs;
|
||||
$month = $request->month;
|
||||
dd($share);
|
||||
|
||||
return view('transaction.recap', compact('month_trxs_total', 'yesterday_month_trxs_total', 'month', 'trx_data', 'sa_names', 'works', 'works_count', 'trxs', 'month_trxs','dealer', 'share', 'mechanic'));
|
||||
}
|
||||
@@ -568,7 +570,6 @@ class TransactionController extends Controller
|
||||
$prev_mth_end = $prev_mth[0].'-'.$prev_mth[1].'-'.date('t');
|
||||
}
|
||||
|
||||
// dd($prev_mth_end);
|
||||
$yesterday_month_trx = Transaction::whereNull('deleted_at')->where('work_id', $work1->id)->where('dealer_id', $id)->whereDate('date', '>=', $prev_mth_start)->whereDate('date', '<=', $prev_mth_end)->sum('qty');
|
||||
|
||||
if(array_key_exists($work1->id, $yesterday_month_trxs_total)) {
|
||||
@@ -678,15 +679,12 @@ class TransactionController extends Controller
|
||||
}
|
||||
}
|
||||
|
||||
// dd($works);
|
||||
// dd([$month_trxs_total, $yesterday_month_trxs_total]);
|
||||
$final_month_trxs_total = [];
|
||||
$final_yesterday_month_trxs_total = [];
|
||||
foreach($works as $work1) {
|
||||
$final_month_trxs_total[$work1->id] = $month_trxs_total[$work1->id];
|
||||
$final_yesterday_month_trxs_total[$work1->id] = $yesterday_month_trxs_total[$work1->id];
|
||||
}
|
||||
// dd([$final_month_trxs_total, $final_yesterday_month_trxs_total]);
|
||||
$month_trxs_total = array_values($final_month_trxs_total);
|
||||
$yesterday_month_trxs_total = array_values($final_yesterday_month_trxs_total);
|
||||
|
||||
@@ -994,19 +992,31 @@ class TransactionController extends Controller
|
||||
|
||||
public function update(Request $request, $id)
|
||||
{
|
||||
Transaction::find($id)->update([
|
||||
$request->validate([
|
||||
'spk' => 'required|string|max:255',
|
||||
'date' => 'required|date',
|
||||
'police_number' => 'required|string|max:255',
|
||||
'work_id' => 'required|exists:works,id',
|
||||
'qty' => 'required|integer|min:1',
|
||||
'warranty' => 'required|in:0,1',
|
||||
'user_sa_id' => 'required|exists:users,id',
|
||||
]);
|
||||
|
||||
$transaction = Transaction::findOrFail($id);
|
||||
|
||||
$transaction->update([
|
||||
"spk" => $request->spk,
|
||||
"date" => $request->date,
|
||||
"police_number" => $request->police_number,
|
||||
"work_id" => $request->work_id,
|
||||
"qty" => $request->qty,
|
||||
"warranty" => $request->warranty,
|
||||
"user_sa_id" => $request->sa_id,
|
||||
"user_sa_id" => $request->user_sa_id,
|
||||
]);
|
||||
|
||||
$response = [
|
||||
"status" => 200,
|
||||
"message" => "Data updated successfully"
|
||||
"message" => "Transaksi berhasil diperbarui"
|
||||
];
|
||||
|
||||
return response()->json($response);
|
||||
@@ -1147,6 +1157,8 @@ class TransactionController extends Controller
|
||||
'sa_name' => $transaction->sa_name,
|
||||
'status' => $this->getStatusBadge($transaction->status),
|
||||
'action' => $this->getActionButtons($transaction),
|
||||
'action_precheck' => $this->getActionButtonsPrecheck($transaction),
|
||||
'action_postcheck' => $this->getActionButtonsPostcheck($transaction),
|
||||
'claimed_at' => $transaction->claimed_at,
|
||||
'claimed_by' => $transaction->claimed_by
|
||||
];
|
||||
@@ -1259,38 +1271,108 @@ class TransactionController extends Controller
|
||||
{
|
||||
$buttons = '';
|
||||
|
||||
// Only show buttons for mechanics
|
||||
// Edit button - show for all users (not just mechanics)
|
||||
$buttons .= '<button class="btn btn-sm btn-warning mr-1"
|
||||
data-action="' . route('transaction.update', $transaction->id) . '"
|
||||
data-url="' . route('transaction.edit', $transaction->id) . '"
|
||||
onclick="editTransaction(' . $transaction->id . ')"
|
||||
id="editTransaction' . $transaction->id . '"
|
||||
title="Edit Transaksi"
|
||||
style="font-size: 11px; padding: 4px 8px;">
|
||||
<i class="fas fa-edit"></i> Edit
|
||||
</button>';
|
||||
|
||||
// Delete button - show for all users
|
||||
$buttons .= '<button class="btn btn-sm btn-danger mr-1"
|
||||
onclick="deleteTransaction(' . $transaction->id . ')"
|
||||
title="Hapus Transaksi"
|
||||
style="font-size: 11px; padding: 4px 8px;">
|
||||
<i class="fas fa-trash"></i> Hapus
|
||||
</button>';
|
||||
|
||||
// Only show claim buttons for mechanics
|
||||
if (Auth::user()->role_id == 3) {
|
||||
|
||||
// Claim button - show only if not claimed yet
|
||||
if (empty($transaction->claimed_at) && empty($transaction->claimed_by)) {
|
||||
$buttons .= '<button class="btn btn-sm btn-success mr-1" onclick="claimTransaction(' . $transaction->id . ')" title="Klaim Pekerjaan">';
|
||||
$buttons .= 'Klaim';
|
||||
$buttons .= '<button class="btn btn-sm btn-success mr-1" onclick="claimTransaction(' . $transaction->id . ')" title="Klaim Pekerjaan" style="font-size: 11px; padding: 4px 8px;">';
|
||||
$buttons .= '<i class="fas fa-hand-paper"></i> Klaim';
|
||||
$buttons .= '</button>';
|
||||
} else {
|
||||
if($transaction->claimed_by == Auth::user()->id) {
|
||||
// Check if precheck exists
|
||||
$precheck = \App\Models\Precheck::where('transaction_id', $transaction->id)->first();
|
||||
if (!$precheck) {
|
||||
$buttons .= '<a href="/transaction/prechecks/' . $transaction->id . '" class="btn btn-sm btn-warning mr-1" title="Precheck">';
|
||||
$buttons .= 'Precheck';
|
||||
$buttons .= '</a>';
|
||||
} else {
|
||||
// Check if postcheck exists
|
||||
$postcheck = \App\Models\Postcheck::where('transaction_id', $transaction->id)->first();
|
||||
if (!$postcheck) {
|
||||
$buttons .= '<a href="/transaction/postchecks/' . $transaction->id . '" class="btn btn-sm btn-info mr-1" title="Postcheck">';
|
||||
$buttons .= 'Postcheck';
|
||||
$buttons .= '</a>';
|
||||
} else {
|
||||
$buttons .= '<span class="badge badge-success">Selesai</span>';
|
||||
}
|
||||
if ($transaction->claimed_by == Auth::user()->id) {
|
||||
$precheck = Precheck::where('transaction_id', $transaction->id)->first();
|
||||
$postcheck = Postcheck::where('transaction_id', $transaction->id)->first();
|
||||
|
||||
if ($precheck && $postcheck) {
|
||||
$buttons .= '<span class="badge badge-success" style="font-size: 10px;"><i class="fas fa-check"></i> Selesai</span>';
|
||||
}
|
||||
}
|
||||
$buttons .= '<span class="badge badge-info">Sudah Diklaim</span>';
|
||||
$buttons .= '<span class="badge badge-info" style="font-size: 10px;"><i class="fas fa-check-circle"></i> Sudah Diklaim</span>';
|
||||
}
|
||||
}
|
||||
|
||||
return $buttons;
|
||||
}
|
||||
|
||||
private function getActionButtonsPrecheck($transaction)
|
||||
{
|
||||
$buttons = '';
|
||||
|
||||
if (Auth::user()->role_id == 3) {
|
||||
$precheck = Precheck::where('transaction_id', $transaction->id)->first();
|
||||
|
||||
if ($precheck) {
|
||||
$buttons .= '<a href="' . route('prechecks.edit', [$transaction->id, $precheck->id]) . '"
|
||||
class="btn btn-sm btn-warning mr-1" title="Edit Precheck" style="font-size: 11px; padding: 4px 8px;">
|
||||
<i class="fas fa-edit"></i> Edit
|
||||
</a>';
|
||||
$buttons .= '<a href="' . route('prechecks.print', $transaction->id) . '"
|
||||
class="btn btn-sm btn-primary mr-1" title="Lihat Precheck" target="_blank" style="font-size: 11px; padding: 4px 8px;">
|
||||
<i class="fas fa-eye"></i> Lihat
|
||||
</a>';
|
||||
} else {
|
||||
if (empty($transaction->claimed_at) && empty($transaction->claimed_by)) {
|
||||
$buttons .= '<span class="badge badge-danger" style="font-size: 10px;">Transaksi Belum Diklaim</span>';
|
||||
}else{
|
||||
$buttons .= '<a href="' . route('prechecks.create', $transaction->id) . '"
|
||||
class="btn btn-sm btn-success mr-1" title="Tambah Precheck" style="font-size: 11px; padding: 4px 8px;">
|
||||
<i class="fas fa-plus"></i> Tambah
|
||||
</a>';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $buttons;
|
||||
}
|
||||
|
||||
private function getActionButtonsPostcheck($transaction)
|
||||
{
|
||||
$buttons = '';
|
||||
|
||||
if (Auth::user()->role_id == 3) {
|
||||
$postcheck = Postcheck::where('transaction_id', $transaction->id)->first();
|
||||
$precheck = Precheck::where('transaction_id', $transaction->id)->first();
|
||||
|
||||
if($precheck){
|
||||
if ($postcheck) {
|
||||
$buttons .= '<a href="' . route('postchecks.edit', [$transaction->id, $postcheck->id]) . '"
|
||||
class="btn btn-sm btn-warning mr-1" title="Edit Postcheck" style="font-size: 11px; padding: 4px 8px;">
|
||||
<i class="fas fa-edit"></i> Edit
|
||||
</a>';
|
||||
$buttons .= '<a href="' . route('postchecks.print', $transaction->id) . '"
|
||||
class="btn btn-sm btn-primary mr-1" title="Lihat Postcheck" target="_blank" style="font-size: 11px; padding: 4px 8px;">
|
||||
<i class="fas fa-eye"></i> Lihat
|
||||
</a>';
|
||||
} else {
|
||||
$buttons .= '<a href="' . route('postchecks.create', $transaction->id) . '"
|
||||
class="btn btn-sm btn-success mr-1" title="Tambah Postcheck" style="font-size: 11px; padding: 4px 8px;">
|
||||
<i class="fas fa-plus"></i> Tambah
|
||||
</a>';
|
||||
}
|
||||
}else{
|
||||
$buttons .= '<span class="badge badge-danger" style="font-size: 10px;">Precheck Belum Disimpan</span>';
|
||||
}
|
||||
}
|
||||
|
||||
return $buttons;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user