fix filtering dealer and data with base on user login, partial update precheck and postcheck schema and view

This commit is contained in:
2025-07-10 18:04:38 +07:00
parent cec11d6385
commit e52c4d1d27
13 changed files with 2139 additions and 9 deletions

View File

@@ -287,7 +287,11 @@ class ApiController extends Controller
public function logout()
{
Auth::user()->tokens()->delete();
/** @var \App\Models\User $user */
$user = auth('sanctum')->user();
if ($user) {
$user->tokens()->delete();
}
return response()->json([
'message' => 'Logout success',
'status' => true,

View File

@@ -1060,7 +1060,6 @@ class TransactionController extends Controller
'users.name as mechanic_name'
])
->where('transactions.dealer_id', $request->dealer_id)
->where('users.role_id', 4) // Only transactions created by SA
->whereIn('transactions.status', [0, 1]) // Only pending and completed transactions
->orderBy('transactions.date', 'desc');
@@ -1091,6 +1090,7 @@ class TransactionController extends Controller
$data = [];
foreach ($transactions as $transaction) {
$data[] = [
'id' => $transaction->id,
'date' => date('d/m/Y', strtotime($transaction->date)),
'spk' => $transaction->spk,
'police_number' => $transaction->police_number,
@@ -1127,13 +1127,7 @@ class TransactionController extends Controller
case 0: // pending
return '<span class="badge badge-warning">Menunggu</span>';
case 1: // completed
return '<span class="badge badge-success">Selesai</span>';
case 2: // in_progress
return '<span class="badge badge-primary">Sedang Dikerjakan</span>';
case 3: // claimed
return '<span class="badge badge-info">Diklaim</span>';
case 4: // cancelled
return '<span class="badge badge-danger">Dibatalkan</span>';
return '<span class="badge badge-success">Closed</span>';
default:
return '<span class="badge badge-secondary">Tidak Diketahui</span>';
}
@@ -1234,6 +1228,25 @@ class TransactionController extends Controller
$buttons .= '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>';
}
}
}
$buttons .= '<span class="badge badge-info">Sudah Diklaim</span>';
}
}

View File

@@ -0,0 +1,72 @@
<?php
namespace App\Http\Controllers\Transactions;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\Models\Postcheck;
use App\Models\Transaction;
class PostchecksController extends Controller
{
public function index(Transaction $transaction)
{
$acConditions = Postcheck::getAcConditionOptions();
$blowerConditions = Postcheck::getBlowerConditionOptions();
$evaporatorConditions = Postcheck::getEvaporatorConditionOptions();
$compressorConditions = Postcheck::getCompressorConditionOptions();
return view('transaction.postchecks', compact(
'transaction',
'acConditions',
'blowerConditions',
'evaporatorConditions',
'compressorConditions'
));
}
public function store(Request $request, Transaction $transaction)
{
$request->validate([
'kilometer' => 'required|numeric|min:0',
'pressure_high' => 'required|numeric|min:0',
'pressure_low' => 'nullable|numeric|min:0',
'cabin_temperature' => 'nullable|numeric',
'cabin_temperature_image' => 'nullable|string',
'ac_condition' => 'nullable|in:' . implode(',', Postcheck::getAcConditionOptions()),
'ac_image' => 'nullable|string',
'blower_condition' => 'nullable|in:' . implode(',', Postcheck::getBlowerConditionOptions()),
'blower_image' => 'nullable|string',
'evaporator_condition' => 'nullable|in:' . implode(',', Postcheck::getEvaporatorConditionOptions()),
'evaporator_image' => 'nullable|string',
'compressor_condition' => 'nullable|in:' . implode(',', Postcheck::getCompressorConditionOptions()),
'postcheck_notes' => 'nullable|string',
'front_image' => 'required|string',
]);
// Pastikan transaction_id sama dengan $transaction->id
$postcheck = Postcheck::create([
'transaction_id' => $transaction->id,
'postcheck_by' => auth()->id(),
'postcheck_at' => now(),
'police_number' => $transaction->police_number,
'spk_number' => $transaction->spk,
'front_image' => $request->front_image,
'kilometer' => $request->kilometer,
'pressure_high' => $request->pressure_high,
'pressure_low' => $request->pressure_low,
'cabin_temperature' => $request->cabin_temperature,
'cabin_temperature_image' => $request->cabin_temperature_image,
'ac_condition' => $request->ac_condition,
'ac_image' => $request->ac_image,
'blower_condition' => $request->blower_condition,
'blower_image' => $request->blower_image,
'evaporator_condition' => $request->evaporator_condition,
'evaporator_image' => $request->evaporator_image,
'compressor_condition' => $request->compressor_condition,
'postcheck_notes' => $request->postcheck_notes,
]);
return redirect()->route('transaction')->with('success', 'Postcheck berhasil disimpan');
}
}

View File

@@ -0,0 +1,72 @@
<?php
namespace App\Http\Controllers\Transactions;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\Models\Precheck;
use App\Models\Transaction;
class PrechecksController extends Controller
{
public function index(Transaction $transaction)
{
$acConditions = Precheck::getAcConditionOptions();
$blowerConditions = Precheck::getBlowerConditionOptions();
$evaporatorConditions = Precheck::getEvaporatorConditionOptions();
$compressorConditions = Precheck::getCompressorConditionOptions();
return view('transaction.prechecks', compact(
'transaction',
'acConditions',
'blowerConditions',
'evaporatorConditions',
'compressorConditions'
));
}
public function store(Request $request, Transaction $transaction)
{
$request->validate([
'kilometer' => 'required|numeric|min:0',
'pressure_high' => 'required|numeric|min:0',
'pressure_low' => 'nullable|numeric|min:0',
'cabin_temperature' => 'nullable|numeric',
'cabin_temperature_image' => 'nullable|string',
'ac_condition' => 'nullable|in:' . implode(',', Precheck::getAcConditionOptions()),
'ac_image' => 'nullable|string',
'blower_condition' => 'nullable|in:' . implode(',', Precheck::getBlowerConditionOptions()),
'blower_image' => 'nullable|string',
'evaporator_condition' => 'nullable|in:' . implode(',', Precheck::getEvaporatorConditionOptions()),
'evaporator_image' => 'nullable|string',
'compressor_condition' => 'nullable|in:' . implode(',', Precheck::getCompressorConditionOptions()),
'precheck_notes' => 'nullable|string',
'front_image' => 'required|string',
]);
// Pastikan transaction_id sama dengan $transaction->id
$precheck = Precheck::create([
'transaction_id' => $transaction->id,
'precheck_by' => auth()->id(),
'precheck_at' => now(),
'police_number' => $transaction->police_number,
'spk_number' => $transaction->spk,
'front_image' => $request->front_image,
'kilometer' => $request->kilometer,
'pressure_high' => $request->pressure_high,
'pressure_low' => $request->pressure_low,
'cabin_temperature' => $request->cabin_temperature,
'cabin_temperature_image' => $request->cabin_temperature_image,
'ac_condition' => $request->ac_condition,
'ac_image' => $request->ac_image,
'blower_condition' => $request->blower_condition,
'blower_image' => $request->blower_image,
'evaporator_condition' => $request->evaporator_condition,
'evaporator_image' => $request->evaporator_image,
'compressor_condition' => $request->compressor_condition,
'precheck_notes' => $request->precheck_notes,
]);
return redirect()->route('transaction')->with('success', 'Precheck berhasil disimpan');
}
}