You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
100 lines
4.0 KiB
100 lines
4.0 KiB
2 years ago
|
<?php
|
||
|
|
||
|
namespace App\Http\Controllers;
|
||
|
|
||
|
use Illuminate\Http\Request;
|
||
|
use App\Models\DokumenProject;
|
||
|
|
||
|
class ProjectDokumenController extends Controller
|
||
|
{
|
||
|
public function dokumenByProyekId($id){
|
||
|
if($id && $id!="" && (int)$id > 0){
|
||
|
$dataDokumen = DokumenProject::where("ref_id", $id)->get();
|
||
|
|
||
|
return response()->json(['status'=>'success','data'=>$dataDokumen,'code'=>200], 200);
|
||
|
}else{
|
||
|
return response()->json(['status'=>'failed','message'=>'project id is required!','code'=>400], 400);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public function delete($id)
|
||
|
{
|
||
|
if($id && $id!="" && (int)$id > 0){
|
||
|
$dokumen = DokumenProject::find($id);
|
||
|
if($dokumen){
|
||
|
if(file_exists($this->pathDocument.$dokumen->file)){
|
||
|
unlink($this->pathDocument.$dokumen->file);
|
||
|
}
|
||
|
$dokumen->delete();
|
||
|
return response()->json(['status'=>'success','message'=>'Dokumen deleted successfully!','code'=>200], 200);
|
||
|
}else{
|
||
|
return response()->json(['status'=>'failed','message'=>'Dokumen not found!','code'=>400], 400);
|
||
|
}
|
||
|
}else{
|
||
|
return response()->json(['status'=>'failed','message'=>'Id is required!','code'=>400], 400);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public function uploadProjectDokumen(Request $request)
|
||
|
{
|
||
|
if($request->hasFile('dokumen')){
|
||
|
$dokumen = $request->file('dokumen');
|
||
|
$ref_id = $request->ref_id;
|
||
|
$extension = $dokumen->extension();
|
||
|
$name = $dokumen->getClientOriginalName();
|
||
|
|
||
|
$result = $dokumen->move($this->pathDocument, $name);
|
||
|
if($result){
|
||
|
$data = [
|
||
|
'ref_id' => (int)$ref_id,
|
||
|
'file' => $name,
|
||
|
'type_dokumen' => isset($request->type_dokumen) ? $request->type_dokumen : 'project-document' // project-document-in-folder / project-document-out-folder
|
||
|
];
|
||
|
|
||
|
$result = DokumenProject::create($data);
|
||
|
|
||
|
if($result){
|
||
|
return response()->json(['status'=>'success','message'=>'file upload is successfully!','code'=>200], 200);
|
||
|
}else{
|
||
|
unlink($this->pathDocument.$name);
|
||
|
return response()->json(['status'=>'failed','message'=>'file upload is failed!','code'=>400], 400);
|
||
|
}
|
||
|
|
||
|
}else{
|
||
|
return response()->json(['status'=>'failed','message'=>'file upload is failed!','code'=>400], 400);
|
||
|
}
|
||
|
}else{
|
||
|
return response()->json(['status'=>'failed','message'=>'file is required!','code'=>400], 400);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public function searchDocProject(Request $request){
|
||
|
$payload = $request->all();
|
||
|
$dataBuilder = $this->setUpPayload($payload, 'document_project');
|
||
|
$builder = $dataBuilder['builder'];
|
||
|
$countBuilder = $dataBuilder['count'];
|
||
|
$dataGet = $builder->get();
|
||
|
$totalRecord = $countBuilder->count();
|
||
|
return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>$totalRecord], 200);
|
||
|
}
|
||
|
|
||
|
public function downloadDokumen($id)
|
||
|
{
|
||
|
if($id && $id!="" && (int)$id > 0){
|
||
|
$dokumen = DokumenProject::find($id);
|
||
|
if($dokumen){
|
||
|
if(file_exists($this->pathDocument.$dokumen->file)){
|
||
|
$pathToFile = $this->pathDocument.$dokumen->file;
|
||
|
return response()->download($pathToFile);
|
||
|
}else{
|
||
|
return response()->json(['status'=>'failed','message'=>'Dokumen not found!','code'=>400], 400);
|
||
|
}
|
||
|
}else{
|
||
|
return response()->json(['status'=>'failed','message'=>'Dokumen not found!','code'=>400], 400);
|
||
|
}
|
||
|
}else{
|
||
|
return response()->json(['status'=>'failed','message'=>'Id is required!','code'=>400], 400);
|
||
|
}
|
||
|
}
|
||
|
}
|