|
|
@ -629,19 +629,34 @@ class ActivityController extends Controller |
|
|
|
return response()->json(['status' => 'success', 'message' => 'Activity Updated!', 'code' => 200], 200); |
|
|
|
return response()->json(['status' => 'success', 'message' => 'Activity Updated!', 'code' => 200], 200); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public function delete($id, $company_id) |
|
|
|
public function delete($id) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (!$data = Activity::find($id)) |
|
|
|
DB::beginTransaction(); |
|
|
|
|
|
|
|
$activity_id = (int)$id; |
|
|
|
|
|
|
|
$data = Activity::query() |
|
|
|
|
|
|
|
->from('m_activity as ma') |
|
|
|
|
|
|
|
->select('mp.company_id') |
|
|
|
|
|
|
|
->join('m_proyek as mp','ma.proyek_id','mp.id') |
|
|
|
|
|
|
|
->where('ma.id', $activity_id); |
|
|
|
|
|
|
|
$cloneQuery = clone $data; |
|
|
|
|
|
|
|
if (!$data->exists()) { |
|
|
|
|
|
|
|
DB::rollBack(); |
|
|
|
return response()->json(['status' => 'failed', 'action' => 'error', 'message' => 'Data not found!', 'code' => 404], 404); |
|
|
|
return response()->json(['status' => 'failed', 'action' => 'error', 'message' => 'Data not found!', 'code' => 404], 404); |
|
|
|
$this->deleteRelative($id, $company_id); |
|
|
|
} |
|
|
|
if (!$data->delete()) |
|
|
|
|
|
|
|
return response()->json(['status' => 'failed', 'action' => 'error', 'message' => 'data activity failed deleted!', 'code' => 500], 500); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return response()->json(['status' => 'success', "action" => "deleted", 'message' => 'data activity successfully deleted!', 'code' => 200], 200); |
|
|
|
$this->deleteRelative($activity_id, $cloneQuery->first()->company_id); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!$data->delete()) { |
|
|
|
|
|
|
|
DB::rollBack(); |
|
|
|
|
|
|
|
return response()->json(['status' => 'failed', 'action' => 'error', 'message' => 'Data activity failed deleted!', 'code' => 500], 500); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
DB::commit(); |
|
|
|
|
|
|
|
return response()->json(['status' => 'success', "action" => "deleted", 'message' => 'Data activity successfully deleted!', 'code' => 200], 200); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private function deleteRelative($activity_id, $company_id) |
|
|
|
private function deleteRelative($activity_id, $company_id) |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
DB::transaction(function() use($activity_id, $company_id) { |
|
|
|
UserToActivity::where('activity_id', $activity_id)->delete(); |
|
|
|
UserToActivity::where('activity_id', $activity_id)->delete(); |
|
|
|
AssignMaterial::where('activity_id', $activity_id)->delete(); |
|
|
|
AssignMaterial::where('activity_id', $activity_id)->delete(); |
|
|
|
$dataAd = ActivityDokumen::where("activity_id", $activity_id)->get(); |
|
|
|
$dataAd = ActivityDokumen::where("activity_id", $activity_id)->get(); |
|
|
@ -655,6 +670,7 @@ class ActivityController extends Controller |
|
|
|
} |
|
|
|
} |
|
|
|
ActivityDokumen::where("activity_id", $activity_id)->delete(); |
|
|
|
ActivityDokumen::where("activity_id", $activity_id)->delete(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public function getUpdate($id) |
|
|
|
public function getUpdate($id) |
|
|
|