|
|
|
@ -629,32 +629,48 @@ class ActivityController extends Controller
|
|
|
|
|
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); |
|
|
|
|
$this->deleteRelative($id, $company_id); |
|
|
|
|
if (!$data->delete()) |
|
|
|
|
return response()->json(['status' => 'failed', 'action' => 'error', 'message' => 'data activity failed deleted!', 'code' => 500], 500); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$this->deleteRelative($activity_id, $cloneQuery->first()->company_id); |
|
|
|
|
|
|
|
|
|
return response()->json(['status' => 'success', "action" => "deleted", 'message' => 'data activity successfully deleted!', 'code' => 200], 200); |
|
|
|
|
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) |
|
|
|
|
{ |
|
|
|
|
UserToActivity::where('activity_id', $activity_id)->delete(); |
|
|
|
|
AssignMaterial::where('activity_id', $activity_id)->delete(); |
|
|
|
|
$dataAd = ActivityDokumen::where("activity_id", $activity_id)->get(); |
|
|
|
|
$company = Company::find($company_id); |
|
|
|
|
if($company) { |
|
|
|
|
$destinationPath = $this->setCustomeDirectoryUpload($company['company_name']); |
|
|
|
|
foreach ($dataAd as $ad) { |
|
|
|
|
if (file_exists($destinationPath['pathActivityDocument'] . $ad->file)) { |
|
|
|
|
unlink($destinationPath['pathActivityDocument'] . $ad->file); |
|
|
|
|
DB::transaction(function() use($activity_id, $company_id) { |
|
|
|
|
UserToActivity::where('activity_id', $activity_id)->delete(); |
|
|
|
|
AssignMaterial::where('activity_id', $activity_id)->delete(); |
|
|
|
|
$dataAd = ActivityDokumen::where("activity_id", $activity_id)->get(); |
|
|
|
|
$company = Company::find($company_id); |
|
|
|
|
if($company) { |
|
|
|
|
$destinationPath = $this->setCustomeDirectoryUpload($company['company_name']); |
|
|
|
|
foreach ($dataAd as $ad) { |
|
|
|
|
if (file_exists($destinationPath['pathActivityDocument'] . $ad->file)) { |
|
|
|
|
unlink($destinationPath['pathActivityDocument'] . $ad->file); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
ActivityDokumen::where("activity_id", $activity_id)->delete(); |
|
|
|
|
} |
|
|
|
|
ActivityDokumen::where("activity_id", $activity_id)->delete(); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public function getUpdate($id) |
|
|
|
|