|
|
|
@ -126,68 +126,83 @@ class NewTvRequest extends Model {
|
|
|
|
public static function approveFromRequest(Request $request) {
|
|
|
|
public static function approveFromRequest(Request $request) {
|
|
|
|
$request->validate([
|
|
|
|
$request->validate([
|
|
|
|
'id' => 'required|integer|exists:App\Models\NewTvRequest',
|
|
|
|
'id' => 'required|integer|exists:App\Models\NewTvRequest',
|
|
|
|
'tv' => 'required|array',
|
|
|
|
'tv' => 'nullable|array',
|
|
|
|
]);
|
|
|
|
'existingTv' => 'nullable|array',
|
|
|
|
|
|
|
|
'action' => 'required|string',
|
|
|
|
$tvRequest = new Request($request->tv);
|
|
|
|
|
|
|
|
if($tvRequest->code) $tvRequest->merge(['code' => strtoupper($tvRequest->code)]);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$tvRequest->validate([
|
|
|
|
|
|
|
|
'company_name' => 'nullable|string',
|
|
|
|
|
|
|
|
'address' => 'nullable|string',
|
|
|
|
|
|
|
|
'street_address' => 'nullable|string',
|
|
|
|
|
|
|
|
'col1' => 'nullable|string',
|
|
|
|
|
|
|
|
'col2' => 'nullable|string',
|
|
|
|
|
|
|
|
'col3' => 'nullable|string',
|
|
|
|
|
|
|
|
'col4' => 'nullable|string',
|
|
|
|
|
|
|
|
'col5' => 'nullable|string',
|
|
|
|
|
|
|
|
'col6' => 'nullable|string',
|
|
|
|
|
|
|
|
'col7' => 'nullable|string',
|
|
|
|
|
|
|
|
'col8' => 'nullable|string',
|
|
|
|
|
|
|
|
'col9' => 'nullable|string',
|
|
|
|
|
|
|
|
'col10' => 'nullable|string',
|
|
|
|
|
|
|
|
'notes' => 'nullable|string',
|
|
|
|
|
|
|
|
]);
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
|
|
$newTvReq = NewTvRequest::addColumnCanApprove()
|
|
|
|
$newTvReq = NewTvRequest::addColumnCanApprove()
|
|
|
|
->findOrFail($request->id);
|
|
|
|
->findOrFail($request->id);
|
|
|
|
if(!$newTvReq->can_approve) throw new \Exception('Cannot approve current request');
|
|
|
|
if(!$newTvReq->can_approve) throw new \Exception('Cannot approve current request');
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
DB::beginTransaction();
|
|
|
|
$tv = null;
|
|
|
|
$tv = new Tv();
|
|
|
|
if($request->action == 'existing') {
|
|
|
|
$tv->code = TV::generateUniqueCode();
|
|
|
|
$existingTvRequest = new Request($request->existingTv);
|
|
|
|
$tv->company_name = $tvRequest->company_name;
|
|
|
|
$existingTvRequest->validate([
|
|
|
|
$tv->address = $tvRequest->address;
|
|
|
|
'id' => 'required|integer|exists:App\Models\Tv',
|
|
|
|
$tv->street_address = $tvRequest->street_address;
|
|
|
|
]);
|
|
|
|
$tv->col1 = $tvRequest->col1;
|
|
|
|
|
|
|
|
$tv->col2 = $tvRequest->col2;
|
|
|
|
$tv = TV::findOrFail($existingTvRequest->id);
|
|
|
|
$tv->col3 = $tvRequest->col3;
|
|
|
|
} else if ($request->action == 'new') {
|
|
|
|
$tv->col4 = $tvRequest->col4;
|
|
|
|
$tvRequest = new Request($request->tv);
|
|
|
|
$tv->col5 = $tvRequest->col5;
|
|
|
|
if($tvRequest->code) $tvRequest->merge(['code' => strtoupper($tvRequest->code)]);
|
|
|
|
$tv->col6 = $tvRequest->col6;
|
|
|
|
|
|
|
|
$tv->col7 = $tvRequest->col7;
|
|
|
|
$tvRequest->validate([
|
|
|
|
$tv->col8 = $tvRequest->col8;
|
|
|
|
'company_name' => 'nullable|string',
|
|
|
|
$tv->col9 = $tvRequest->col9;
|
|
|
|
'address' => 'nullable|string',
|
|
|
|
$tv->col10 = $tvRequest->col10;
|
|
|
|
'street_address' => 'nullable|string',
|
|
|
|
$tv->notes = $tvRequest->notes;
|
|
|
|
'col1' => 'nullable|string',
|
|
|
|
$tv->device_info = $newTvReq->device_info;
|
|
|
|
'col2' => 'nullable|string',
|
|
|
|
$tv->installed_at = now();
|
|
|
|
'col3' => 'nullable|string',
|
|
|
|
$tv->save();
|
|
|
|
'col4' => 'nullable|string',
|
|
|
|
TVLog::historyCreate($request->user(), $tv->id, $tv);
|
|
|
|
'col5' => 'nullable|string',
|
|
|
|
|
|
|
|
'col6' => 'nullable|string',
|
|
|
|
|
|
|
|
'col7' => 'nullable|string',
|
|
|
|
|
|
|
|
'col8' => 'nullable|string',
|
|
|
|
|
|
|
|
'col9' => 'nullable|string',
|
|
|
|
|
|
|
|
'col10' => 'nullable|string',
|
|
|
|
|
|
|
|
'notes' => 'nullable|string',
|
|
|
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
DB::beginTransaction();
|
|
|
|
|
|
|
|
$tv = new Tv();
|
|
|
|
|
|
|
|
$tv->code = TV::generateUniqueCode();
|
|
|
|
|
|
|
|
$tv->company_name = $tvRequest->company_name;
|
|
|
|
|
|
|
|
$tv->address = $tvRequest->address;
|
|
|
|
|
|
|
|
$tv->street_address = $tvRequest->street_address;
|
|
|
|
|
|
|
|
$tv->col1 = $tvRequest->col1;
|
|
|
|
|
|
|
|
$tv->col2 = $tvRequest->col2;
|
|
|
|
|
|
|
|
$tv->col3 = $tvRequest->col3;
|
|
|
|
|
|
|
|
$tv->col4 = $tvRequest->col4;
|
|
|
|
|
|
|
|
$tv->col5 = $tvRequest->col5;
|
|
|
|
|
|
|
|
$tv->col6 = $tvRequest->col6;
|
|
|
|
|
|
|
|
$tv->col7 = $tvRequest->col7;
|
|
|
|
|
|
|
|
$tv->col8 = $tvRequest->col8;
|
|
|
|
|
|
|
|
$tv->col9 = $tvRequest->col9;
|
|
|
|
|
|
|
|
$tv->col10 = $tvRequest->col10;
|
|
|
|
|
|
|
|
$tv->notes = $tvRequest->notes;
|
|
|
|
|
|
|
|
$tv->device_info = $newTvReq->device_info;
|
|
|
|
|
|
|
|
$tv->installed_at = now();
|
|
|
|
|
|
|
|
$tv->save();
|
|
|
|
|
|
|
|
TVLog::historyCreate($request->user(), $tv->id, $tv);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// TODO: waiting execution until update from ops
|
|
|
|
|
|
|
|
// NEED TO REFACTOR (cause by add existing tv code)
|
|
|
|
|
|
|
|
// // try to sys_to_sys with indokargo
|
|
|
|
|
|
|
|
// DB::commit();
|
|
|
|
|
|
|
|
// $jsonResponse = Indokargo::createTVAddress($tvRequest, $tv->id);
|
|
|
|
|
|
|
|
// return $jsonResponse;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
throw new \Exception('INVALID FORM ACTION');
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$newTvReq->approved_at = now();
|
|
|
|
$newTvReq->approved_at = now();
|
|
|
|
$newTvReq->tv_fk = $tv->id;
|
|
|
|
$newTvReq->tv_fk = $tv->id;
|
|
|
|
$newTvReq->save();
|
|
|
|
$newTvReq->save();
|
|
|
|
|
|
|
|
|
|
|
|
DB::commit();
|
|
|
|
DB::commit();
|
|
|
|
return JSONResponse::Success(['message'=>'Success to update tv data']);
|
|
|
|
return JSONResponse::Success(['message'=>'Success to approve new tv request']);
|
|
|
|
|
|
|
|
|
|
|
|
// TODO: waiting execution until update from ops
|
|
|
|
|
|
|
|
// // try to sys_to_sys with indokargo
|
|
|
|
|
|
|
|
// DB::commit();
|
|
|
|
|
|
|
|
// $jsonResponse = Indokargo::createTVAddress($tvRequest, $tv->id);
|
|
|
|
|
|
|
|
// return $jsonResponse;
|
|
|
|
|
|
|
|
} catch(\Throwable $th) {
|
|
|
|
} catch(\Throwable $th) {
|
|
|
|
DB::rollback();
|
|
|
|
DB::rollback();
|
|
|
|
throw $th;
|
|
|
|
throw $th;
|
|
|
|
|