|
|
|
@ -8,51 +8,52 @@ use App\Models\ActivityDokumen;
|
|
|
|
|
|
|
|
|
|
class ActivityDokumenController extends Controller |
|
|
|
|
{ |
|
|
|
|
|
|
|
|
|
public function dokumenByActivityId($id){ |
|
|
|
|
if(empty($id) || !is_int((int)$id)) |
|
|
|
|
return response()->json(['status'=>'failed','message'=>'activity id is required!','code'=>400], 400); |
|
|
|
|
public function dokumenByActivityId($id) |
|
|
|
|
{ |
|
|
|
|
if (empty($id) || !is_int((int)$id)) |
|
|
|
|
return response()->json(['status' => 'failed', 'message' => 'activity id is required!', 'code' => 400], 400); |
|
|
|
|
|
|
|
|
|
$dataDokumen = ActivityDokumen::where("activity_id", $id)->get(); |
|
|
|
|
return response()->json(['status'=>'success','data'=>$dataDokumen,'code'=>200], 200); |
|
|
|
|
return response()->json(['status' => 'success', 'data' => $dataDokumen, 'code' => 200], 200); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public function delete($id, $company_id) |
|
|
|
|
public function delete($id) |
|
|
|
|
{ |
|
|
|
|
if(empty($id) || !is_int((int)$id)) |
|
|
|
|
return response()->json(['status'=>'failed','message'=>'Id is required!','code'=>400], 400); |
|
|
|
|
if (empty($id) || !is_int((int)$id)) |
|
|
|
|
return response()->json(['status' => 'failed', 'message' => 'Id is required!', 'code' => 400], 400); |
|
|
|
|
|
|
|
|
|
$document = ActivityDokumen::find($id); |
|
|
|
|
|
|
|
|
|
if(!$document) { |
|
|
|
|
return response()->json(['status'=>'failed','message'=>'Data not found!','code'=> 404], 404); |
|
|
|
|
} |
|
|
|
|
$company = Company::find($company_id); |
|
|
|
|
if($company) { |
|
|
|
|
$destinationPath = $this->setCustomeDirectoryUpload($company['company_name']); |
|
|
|
|
if(file_exists($destinationPath['pathActivityDocument'].$document->file)){ |
|
|
|
|
unlink($destinationPath['pathActivityDocument'].$document->file); |
|
|
|
|
if (!$document) { |
|
|
|
|
return response()->json(['status' => 'failed', 'message' => 'Data not found!', 'code' => 404], 404); |
|
|
|
|
} |
|
|
|
|
$destinationPath = $this->setCustomeDirectoryUpload(); |
|
|
|
|
if (file_exists($destinationPath['pathActivityDocument'] . $document->file)) { |
|
|
|
|
unlink($destinationPath['pathActivityDocument'] . $document->file); |
|
|
|
|
} |
|
|
|
|
$document->delete(); |
|
|
|
|
return response()->json(['status'=>'success','message'=>'Dokumen deleted successfully!','code'=>200], 200); |
|
|
|
|
return response()->json(['status' => 'success', 'message' => 'Dokumen deleted successfully!', 'code' => 200], 200); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public function uploadProjectDokumen(Request $request) |
|
|
|
|
{ |
|
|
|
|
if(!$request->hasFile('dokumen')) { |
|
|
|
|
return response()->json(['status'=>'failed','message'=>'file is required!','code'=>400], 400); |
|
|
|
|
} |
|
|
|
|
$activity_id = $request->activity_id; |
|
|
|
|
$document = $request->file('dokumen'); |
|
|
|
|
$name = $document->getClientOriginalName(); |
|
|
|
|
$company = Company::find($request->company_id); |
|
|
|
|
if($company) { |
|
|
|
|
$destinationPath = $this->setCustomeDirectoryUpload($company['company_name']); |
|
|
|
|
$result = $document->move($destinationPath['pathActivityDocument'], $name); |
|
|
|
|
$fileSize = $document->getSize(); |
|
|
|
|
$maximumSizeFile = $fileSize > 15 * 1024 * 1024; // 15 MB |
|
|
|
|
if ($maximumSizeFile) { |
|
|
|
|
return response()->json(['status' => 'failed', 'message' => 'This file is too large. Allowed maximum size is 15MB', 'code' => 500], 500); |
|
|
|
|
} |
|
|
|
|
if(!$result || !$company) { |
|
|
|
|
return response()->json(['status'=>'failed','message'=>'Upload failed!','code'=> 500], 500); |
|
|
|
|
$this->validate($request, [ |
|
|
|
|
'dokumen' => 'required|file|max:15360' |
|
|
|
|
]); |
|
|
|
|
if (!$request->hasFile('dokumen')) { |
|
|
|
|
return response()->json(['status' => 'failed', 'message' => 'file is required!', 'code' => 400], 400); |
|
|
|
|
} |
|
|
|
|
$result = $document->move($this->directories['pathActivityDocument'], $name); |
|
|
|
|
if (!$result) { |
|
|
|
|
return response()->json(['status' => 'failed', 'message' => 'Upload failed!', 'code' => 500], 500); |
|
|
|
|
} |
|
|
|
|
$data = [ |
|
|
|
|
'activity_id' => (int)$activity_id, |
|
|
|
@ -60,14 +61,15 @@ class ActivityDokumenController extends Controller
|
|
|
|
|
'description' => $request->description |
|
|
|
|
]; |
|
|
|
|
$result = ActivityDokumen::create($data); |
|
|
|
|
if(!$result || !$company) { |
|
|
|
|
unlink($destinationPath['pathActivityDocument'].$name); |
|
|
|
|
return response()->json(['status'=>'failed','message'=>'Upload failed!','code'=> 500], 500); |
|
|
|
|
if (!$result) { |
|
|
|
|
unlink($this->directories['pathActivityDocument'] . $name); |
|
|
|
|
return response()->json(['status' => 'failed', 'message' => 'Upload failed!', 'code' => 500], 500); |
|
|
|
|
} |
|
|
|
|
return response()->json(['status'=>'success','message'=>'Upload success!','code'=>200], 200); |
|
|
|
|
return response()->json(['status' => 'success', 'message' => 'Upload success!', 'code' => 200], 200); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public function searchDocProject(Request $request){ |
|
|
|
|
public function searchDocProject(Request $request) |
|
|
|
|
{ |
|
|
|
|
$payload = $request->all(); |
|
|
|
|
|
|
|
|
|
$dataBuilder = $this->setUpPayload($payload, 'm_document_activity'); |
|
|
|
@ -76,26 +78,23 @@ class ActivityDokumenController extends Controller
|
|
|
|
|
$dataGet = $builder->get(); |
|
|
|
|
$totalRecord = $countBuilder->count(); |
|
|
|
|
|
|
|
|
|
return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>$totalRecord], 200); |
|
|
|
|
return response()->json(['status' => 'success', 'code' => 200, 'data' => $dataGet, 'totalRecord' => $totalRecord], 200); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public function downloadDokumen($id, $company_id) |
|
|
|
|
public function downloadDokumen($id) |
|
|
|
|
{ |
|
|
|
|
if(empty($id) || !is_int((int)$id)) { |
|
|
|
|
return response()->json(['status'=>'failed','message'=>'Id is required!','code'=>400], 400); |
|
|
|
|
if (empty($id) || !is_int((int)$id)) { |
|
|
|
|
return response()->json(['status' => 'failed', 'message' => 'Id is required!', 'code' => 400], 400); |
|
|
|
|
} |
|
|
|
|
$document = ActivityDokumen::find($id); |
|
|
|
|
$company = Company::find($company_id); |
|
|
|
|
if(!$document || !$company) { |
|
|
|
|
return response()->json(['status'=>'failed','message'=>'Data not found!','code'=>400], 400); |
|
|
|
|
if (!$document) { |
|
|
|
|
return response()->json(['status' => 'failed', 'message' => 'Data not found!', 'code' => 400], 400); |
|
|
|
|
} |
|
|
|
|
if($company) { |
|
|
|
|
$destinationPath = $this->setCustomeDirectoryUpload($company['company_name']); |
|
|
|
|
if(file_exists($destinationPath['pathActivityDocument'].$document->file)) { |
|
|
|
|
$pathToFile = $destinationPath['pathActivityDocument'].$document->file; |
|
|
|
|
$destinationPath = $this->setCustomeDirectoryUpload(); |
|
|
|
|
if (file_exists($destinationPath['pathActivityDocument'] . $document->file)) { |
|
|
|
|
$pathToFile = $destinationPath['pathActivityDocument'] . $document->file; |
|
|
|
|
return response()->download($pathToFile); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return response()->json(['status'=>'failed','message'=>'Data not found!','code'=>400], 400); |
|
|
|
|
return response()->json(['status' => 'failed', 'message' => 'Data not found!', 'code' => 400], 400); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|