update vehicles history maintenance
This commit is contained in:
102
app/Http/Controllers/MaintenanceHistoryController.php
Normal file
102
app/Http/Controllers/MaintenanceHistoryController.php
Normal file
@ -0,0 +1,102 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Auth;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Http\Response;
|
||||
use App\Responses;
|
||||
use App\Models\UserLogs;
|
||||
use Validator;
|
||||
|
||||
class MaintenanceHistoryController extends Controller
|
||||
{
|
||||
/**
|
||||
* API Get data history maintenance
|
||||
*/
|
||||
public function api_get_data_maintenance($vehicleid)
|
||||
{
|
||||
try {
|
||||
$data = DB::table('t_vehicles_maintenance_history as h')
|
||||
->leftJoin('t_maintenance_vhc_type as t', function ($join) {
|
||||
$join->whereRaw('FIND_IN_SET(t.id, h.idservice)');
|
||||
})
|
||||
->select(
|
||||
'h.*',
|
||||
DB::raw('GROUP_CONCAT(t.service_type SEPARATOR ", ") as service_names')
|
||||
)
|
||||
->where('h.vhc_id', $vehicleid)
|
||||
->groupBy('h.id')
|
||||
->get();
|
||||
|
||||
$apiResp = Responses::success("success list maintenance vehicles");
|
||||
$apiResp["data"] = $data;
|
||||
return new Response($apiResp, $apiResp["meta"]["code"]);
|
||||
} catch (\Exception $e) {
|
||||
$apiResp = Responses::error($e->getMessage());
|
||||
return new Response($apiResp, $apiResp["meta"]["code"]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* API Update data history maintenance
|
||||
*/
|
||||
public function api_update_data_maintenance(Request $req, $vehicleid, $id)
|
||||
{
|
||||
try {
|
||||
$now = time();
|
||||
|
||||
$input = [
|
||||
"idservice" => $req->idservice,
|
||||
"odometer" => $req->odometer,
|
||||
"dates" => $req->dates,
|
||||
"ismaintenance"=> $req->ismaintenance
|
||||
];
|
||||
$rulesInput = [
|
||||
"idservice" => "required|string",
|
||||
"odometer" => "required|numeric",
|
||||
"dates" => "required|string",
|
||||
"ismaintenance" => "required|numeric"
|
||||
];
|
||||
|
||||
// validasi input
|
||||
$isValidInput = Validator::make($input, $rulesInput);
|
||||
if (!$isValidInput->passes()) {
|
||||
$apiResp = Responses::bad_input($isValidInput->messages()->first());
|
||||
return new Response($apiResp, $apiResp["meta"]["code"]);
|
||||
}
|
||||
|
||||
DB::beginTransaction();
|
||||
|
||||
$update = [
|
||||
"idservice" => $req->idservice,
|
||||
"vhc_id" => $vehicleid,
|
||||
"odometer" => $req->odometer,
|
||||
"dates" => $req->dates,
|
||||
"ismaintenance" => $req->ismaintenance,
|
||||
// "created_at" => date("Y-m-d H:i:s", $now),
|
||||
// "udt" => date("Y-m-d H:i:s", $now),
|
||||
// "created_by" => Auth::user()->id,
|
||||
// "uby" => Auth::user()->id
|
||||
];
|
||||
DB::table('t_vehicles_maintenance_history')->where('id', $id)->update($update);
|
||||
$apiResp = Responses::created("success update maintenance vehicles");
|
||||
|
||||
DB::commit();
|
||||
|
||||
|
||||
$log = [
|
||||
"module" => "Vehicle Type",
|
||||
"action" => "Create",
|
||||
"desc" => "Add new vehicle maintenance type: " . $req->service_type,
|
||||
];
|
||||
UserLogs::insert(Auth::user()->id, $log);
|
||||
return new Response($apiResp, $apiResp["meta"]["code"]);
|
||||
} catch (\Exception $e) {
|
||||
DB::rollBack();
|
||||
$apiResp = Responses::error($e->getMessage());
|
||||
return new Response($apiResp, $apiResp["meta"]["code"]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -72,7 +72,7 @@ class VehiclesController extends Controller
|
||||
$filter["company"] = $req->cptid;
|
||||
}
|
||||
$list = DB::select("SELECT
|
||||
v.id, v.name, v.device_id, nopol1, nopol2, nopol3, v.sum_milleage,
|
||||
v.id, v.name, v.device_id, nopol1, nopol2, nopol3, v.sum_milleage,
|
||||
fvhc_img, vyear, t.`desc` type_name, c_name company_name, rltm.crt_d, rltm.crt crt_rltm,
|
||||
dvc.crt, dvc.simcard, fuel_curr, dvc.protocol, v.cat_id, vc.name cat_name
|
||||
FROM t_vehicles as v
|
||||
@ -84,7 +84,7 @@ class VehiclesController extends Controller
|
||||
left join t_gps_tracks_rltm rltm on rltm.vhc_id = v.id
|
||||
LEFT JOIN t_vehicles_cats AS vc ON v.cat_id = vc.id
|
||||
WHERE v.dlt is null
|
||||
ORDER BY v.id ASC
|
||||
ORDER BY v.id ASC
|
||||
");
|
||||
|
||||
foreach ($list as $key => $row) {
|
||||
|
||||
Reference in New Issue
Block a user