|
|
@ -3,93 +3,79 @@ |
|
|
|
namespace App\Http\Controllers; |
|
|
|
namespace App\Http\Controllers; |
|
|
|
|
|
|
|
|
|
|
|
use Illuminate\Http\Request; |
|
|
|
use Illuminate\Http\Request; |
|
|
|
use App\Models\{DokumenProject,Company}; |
|
|
|
use App\Models\{DokumenProject, Company}; |
|
|
|
use Carbon\Carbon; |
|
|
|
use Carbon\Carbon; |
|
|
|
use Illuminate\Support\Facades\DB; |
|
|
|
use Illuminate\Support\Facades\DB; |
|
|
|
|
|
|
|
|
|
|
|
class ProjectDokumenController extends Controller |
|
|
|
class ProjectDokumenController extends Controller |
|
|
|
{ |
|
|
|
{ |
|
|
|
public function dokumenByProyekId($id){ |
|
|
|
public function dokumenByProyekId($id) |
|
|
|
if(empty($id) || !is_int((int)$id)) { |
|
|
|
{ |
|
|
|
return response()->json(['status'=>'failed','message'=>'project id is required!','code'=>400], 400); |
|
|
|
if (empty($id) || !is_int((int)$id)) { |
|
|
|
|
|
|
|
return response()->json(['status' => 'failed', 'message' => 'project id is required!', 'code' => 400], 400); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
$document = DokumenProject::where("ref_id", $id)->get(); |
|
|
|
$document = DokumenProject::where("ref_id", $id)->get(); |
|
|
|
|
|
|
|
|
|
|
|
if(count($document) == 0) |
|
|
|
if (count($document) == 0) |
|
|
|
return response()->json(['status'=>'','message'=>'Data not found!' ,'code'=>404], 404); |
|
|
|
return response()->json(['status' => '', 'message' => 'Data not found!', 'code' => 404], 404); |
|
|
|
|
|
|
|
|
|
|
|
return response()->json(['status'=>'success','data'=> $document ,'code'=>200], 200); |
|
|
|
return response()->json(['status' => 'success', 'data' => $document, 'code' => 200], 200); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public function delete($id, $company_id) |
|
|
|
public function delete($id) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if(empty($id) || !is_int((int)$id)) { |
|
|
|
if (empty($id) || !is_int((int)$id)) { |
|
|
|
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); |
|
|
|
return response()->json(['status' => 'failed', 'message' => 'id is required!', 'code' => 400], 400); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
$document = DokumenProject::find($id); |
|
|
|
$document = DokumenProject::find($id); |
|
|
|
if(!$document){ |
|
|
|
if (!$document) { |
|
|
|
return response()->json(['status'=>'failed','message'=>'Data not found!','code'=>400], 400); |
|
|
|
return response()->json(['status' => 'failed', 'message' => 'Data not found!', 'code' => 400], 400); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
$destinationPath = $this->setCustomeDirectoryUpload(); |
|
|
|
|
|
|
|
if (file_exists($destinationPath['pathDocument'] . $document['file'])) { |
|
|
|
|
|
|
|
unlink($destinationPath['pathDocument'] . $document['file']); |
|
|
|
} |
|
|
|
} |
|
|
|
$company = Company::find($company_id); |
|
|
|
|
|
|
|
if($company) { |
|
|
|
|
|
|
|
$destinationPath = $this->setCustomeDirectoryUpload($company['company_name']); |
|
|
|
|
|
|
|
if(file_exists($destinationPath['pathDocument'].$document['file'])){ |
|
|
|
|
|
|
|
unlink($destinationPath['pathDocument'].$document['file']); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
$document->delete(); |
|
|
|
$document->delete(); |
|
|
|
return response()->json(['status'=>'success','message'=>'Data deleted!','code'=>200], 200); |
|
|
|
return response()->json(['status' => 'success', 'message' => 'Data deleted!', 'code' => 200], 200); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public function uploadProjectDokumen(Request $request) |
|
|
|
public function uploadProjectDokumen(Request $request) |
|
|
|
{ |
|
|
|
{ |
|
|
|
DB::beginTransaction(); |
|
|
|
DB::beginTransaction(); |
|
|
|
$timeNow = Carbon::now(); |
|
|
|
$timeNow = Carbon::now(); |
|
|
|
if($request->hasFile('dokumen')){ |
|
|
|
if ($request->hasFile('dokumen')) { |
|
|
|
$document = $request->file('dokumen'); |
|
|
|
$document = $request->file('dokumen'); |
|
|
|
$ref_id = $request->ref_id; |
|
|
|
$ref_id = $request->ref_id; |
|
|
|
|
|
|
|
|
|
|
|
$originalFilename = $document->getClientOriginalName(); |
|
|
|
$originalFilename = $document->getClientOriginalName(); |
|
|
|
$extension = pathinfo($originalFilename, PATHINFO_EXTENSION); |
|
|
|
$extension = pathinfo($originalFilename, PATHINFO_EXTENSION); |
|
|
|
$filename = pathinfo($originalFilename, PATHINFO_FILENAME); |
|
|
|
$filename = pathinfo($originalFilename, PATHINFO_FILENAME); |
|
|
|
$name = $filename . '_' . $timeNow->format('d-m-y-His') . '.' . $extension; |
|
|
|
$name = $filename . '_' . $timeNow->format('d-m-y-His') . '.' . $extension; |
|
|
|
// Limited Storage |
|
|
|
|
|
|
|
$company = Company::whereId($request->company_id)->first(); |
|
|
|
$destinationPath = $this->setCustomeDirectoryUpload(); |
|
|
|
if($company) { |
|
|
|
$data = [ |
|
|
|
$destinationPath = $this->setCustomeDirectoryUpload($company['company_name']); |
|
|
|
'ref_id' => (int)$ref_id, |
|
|
|
$getLimitStorage = $this->setLimitsStorage($company, $document, $destinationPath['pathDocument'],$destinationPath); |
|
|
|
'file' => $name, |
|
|
|
} |
|
|
|
'type_dokumen' => isset($request->type_dokumen) ? $request->type_dokumen : 'project-document' |
|
|
|
if(isset($getLimitStorage)) { |
|
|
|
]; |
|
|
|
if($getLimitStorage === false) { |
|
|
|
|
|
|
|
DB::rollBack(); |
|
|
|
$result = DokumenProject::create($data); |
|
|
|
return response()->json(['status' => 'failed', 'message' => 'Limited storage maximum!', 'code' => 500], 500); |
|
|
|
if (!$document->move($destinationPath['pathDocument'], $name) && $result) { |
|
|
|
} |
|
|
|
unlink($destinationPath['pathDocument'] . $name); |
|
|
|
$data = [ |
|
|
|
DB::rollBack(); |
|
|
|
'ref_id' => (int)$ref_id, |
|
|
|
return response()->json(['status' => 'failed', 'message' => 'Dokumen project gagal diupload!', 'code' => 500], 500); |
|
|
|
'file' => $name, |
|
|
|
|
|
|
|
'type_dokumen' => isset($request->type_dokumen) ? $request->type_dokumen : 'project-document' |
|
|
|
|
|
|
|
]; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$result = DokumenProject::create($data); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(!$document->move($destinationPath['pathDocument'], $name) && $result) { |
|
|
|
|
|
|
|
unlink($destinationPath['pathDocument'].$name); |
|
|
|
|
|
|
|
DB::rollBack(); |
|
|
|
|
|
|
|
return response()->json(['status'=>'failed','message'=>'Dokumen project gagal diupload!','code'=> 500], 500); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
DB::commit(); |
|
|
|
|
|
|
|
return response()->json(['status'=>'success','message'=>'Dokumen project berhasil diupload!','code'=>200], 200); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
DB::rollBack(); |
|
|
|
DB::commit(); |
|
|
|
return response()->json(['status'=>'failed','message'=>'Dokumen project gagal diupload!','code'=> 500], 500); |
|
|
|
return response()->json(['status' => 'success', 'message' => 'Dokumen project berhasil diupload!', 'code' => 200], 200); |
|
|
|
} |
|
|
|
} |
|
|
|
DB::rollBack(); |
|
|
|
DB::rollBack(); |
|
|
|
return response()->json(['status'=>'failed','message'=>'File is required!','code'=>400], 400); |
|
|
|
return response()->json(['status' => 'failed', 'message' => 'File is required!', 'code' => 400], 400); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public function searchDocProject(Request $request){ |
|
|
|
public function searchDocProject(Request $request) |
|
|
|
|
|
|
|
{ |
|
|
|
$payload = $request->all(); |
|
|
|
$payload = $request->all(); |
|
|
|
|
|
|
|
|
|
|
|
$dataBuilder = $this->setUpPayload($payload, 'document_project'); |
|
|
|
$dataBuilder = $this->setUpPayload($payload, 'document_project'); |
|
|
@ -98,34 +84,32 @@ class ProjectDokumenController extends Controller |
|
|
|
$dataGet = $builder->get(); |
|
|
|
$dataGet = $builder->get(); |
|
|
|
$totalRecord = $countBuilder->count(); |
|
|
|
$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)) { |
|
|
|
if (empty($id) || !is_int((int)$id)) { |
|
|
|
return response()->json(['status'=>'failed','message'=>'Id is required!','code'=>400], 400); |
|
|
|
return response()->json(['status' => 'failed', 'message' => 'Id is required!', 'code' => 400], 400); |
|
|
|
} |
|
|
|
} |
|
|
|
$document = DokumenProject::find($id); |
|
|
|
$document = DokumenProject::find($id); |
|
|
|
$company = Company::find($company_id); |
|
|
|
|
|
|
|
|
|
|
|
if (!$document) { |
|
|
|
if(!$document || !$company) { |
|
|
|
return response()->json(['status' => 'failed', 'message' => 'Data not found!', 'code' => 404], 404); |
|
|
|
return response()->json(['status'=>'failed','message'=>'Data not found!','code'=> 404], 404); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
$destinationPath = $this->setCustomeDirectoryUpload(); |
|
|
|
$destinationPath = $this->setCustomeDirectoryUpload($company['company_name']); |
|
|
|
$pathToFile = $destinationPath['pathDocument'] . $document['file']; |
|
|
|
$pathToFile = $destinationPath['pathDocument'].$document['file']; |
|
|
|
if (!file_exists($pathToFile)) { |
|
|
|
|
|
|
|
return response()->json(['status' => 'failed', 'message' => 'Directory not found!', 'code' => 404], 404); |
|
|
|
if(!file_exists($pathToFile)) { |
|
|
|
} |
|
|
|
return response()->json(['status'=>'failed','message'=>'Directory not found!','code'=> 404], 404); |
|
|
|
|
|
|
|
} |
|
|
|
$name = pathinfo($pathToFile, PATHINFO_FILENAME) . "." . pathinfo($pathToFile, PATHINFO_EXTENSION); |
|
|
|
if($company) { |
|
|
|
|
|
|
|
$name = pathinfo($pathToFile, PATHINFO_FILENAME) . "." . pathinfo($pathToFile, PATHINFO_EXTENSION); |
|
|
|
$headers = [ |
|
|
|
} |
|
|
|
'Content-Disposition' => 'attachment; filename="' . $name . '"' |
|
|
|
$headers = [ |
|
|
|
]; |
|
|
|
'Content-Disposition' => 'attachment; filename="'.$name.'"' |
|
|
|
|
|
|
|
]; |
|
|
|
return response()->download($pathToFile, $name, $headers); |
|
|
|
|
|
|
|
|
|
|
|
return response()->download($pathToFile, $name, $headers); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|