|
|
@ -629,32 +629,48 @@ 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); |
|
|
|
$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) |
|
|
|
private function deleteRelative($activity_id, $company_id) |
|
|
|
{ |
|
|
|
{ |
|
|
|
UserToActivity::where('activity_id', $activity_id)->delete(); |
|
|
|
DB::transaction(function() use($activity_id, $company_id) { |
|
|
|
AssignMaterial::where('activity_id', $activity_id)->delete(); |
|
|
|
UserToActivity::where('activity_id', $activity_id)->delete(); |
|
|
|
$dataAd = ActivityDokumen::where("activity_id", $activity_id)->get(); |
|
|
|
AssignMaterial::where('activity_id', $activity_id)->delete(); |
|
|
|
$company = Company::find($company_id); |
|
|
|
$dataAd = ActivityDokumen::where("activity_id", $activity_id)->get(); |
|
|
|
if($company) { |
|
|
|
$company = Company::find($company_id); |
|
|
|
$destinationPath = $this->setCustomeDirectoryUpload($company['company_name']); |
|
|
|
if($company) { |
|
|
|
foreach ($dataAd as $ad) { |
|
|
|
$destinationPath = $this->setCustomeDirectoryUpload($company['company_name']); |
|
|
|
if (file_exists($destinationPath['pathActivityDocument'] . $ad->file)) { |
|
|
|
foreach ($dataAd as $ad) { |
|
|
|
unlink($destinationPath['pathActivityDocument'] . $ad->file); |
|
|
|
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) |
|
|
|
public function getUpdate($id) |
|
|
|