|
|
|
@ -9,7 +9,8 @@ use Illuminate\Support\Facades\DB;
|
|
|
|
|
|
|
|
|
|
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); |
|
|
|
|
} |
|
|
|
@ -22,7 +23,7 @@ class ProjectDokumenController extends Controller
|
|
|
|
|
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)) { |
|
|
|
|
return response()->json(['status' => 'failed', 'message' => 'id is required!', 'code' => 400], 400); |
|
|
|
@ -32,12 +33,9 @@ class ProjectDokumenController extends Controller
|
|
|
|
|
if (!$document) { |
|
|
|
|
return response()->json(['status' => 'failed', 'message' => 'Data not found!', 'code' => 400], 400); |
|
|
|
|
} |
|
|
|
|
$company = Company::find($company_id); |
|
|
|
|
if($company) { |
|
|
|
|
$destinationPath = $this->setCustomeDirectoryUpload($company['company_name']); |
|
|
|
|
$destinationPath = $this->setCustomeDirectoryUpload(); |
|
|
|
|
if (file_exists($destinationPath['pathDocument'] . $document['file'])) { |
|
|
|
|
unlink($destinationPath['pathDocument'] . $document['file']); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
$document->delete(); |
|
|
|
|
return response()->json(['status' => 'success', 'message' => 'Data deleted!', 'code' => 200], 200); |
|
|
|
@ -55,17 +53,8 @@ class ProjectDokumenController extends Controller
|
|
|
|
|
$extension = pathinfo($originalFilename, PATHINFO_EXTENSION); |
|
|
|
|
$filename = pathinfo($originalFilename, PATHINFO_FILENAME); |
|
|
|
|
$name = $filename . '_' . $timeNow->format('d-m-y-His') . '.' . $extension; |
|
|
|
|
// Limited Storage |
|
|
|
|
$company = Company::whereId($request->company_id)->first(); |
|
|
|
|
if($company) { |
|
|
|
|
$destinationPath = $this->setCustomeDirectoryUpload($company['company_name']); |
|
|
|
|
$getLimitStorage = $this->setLimitsStorage($company, $document, $destinationPath['pathDocument'],$destinationPath); |
|
|
|
|
} |
|
|
|
|
if(isset($getLimitStorage)) { |
|
|
|
|
if($getLimitStorage === false) { |
|
|
|
|
DB::rollBack(); |
|
|
|
|
return response()->json(['status' => 'failed', 'message' => 'Limited storage maximum!', 'code' => 500], 500); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$destinationPath = $this->setCustomeDirectoryUpload(); |
|
|
|
|
$data = [ |
|
|
|
|
'ref_id' => (int)$ref_id, |
|
|
|
|
'file' => $name, |
|
|
|
@ -73,7 +62,6 @@ class ProjectDokumenController extends Controller
|
|
|
|
|
]; |
|
|
|
|
|
|
|
|
|
$result = DokumenProject::create($data); |
|
|
|
|
|
|
|
|
|
if (!$document->move($destinationPath['pathDocument'], $name) && $result) { |
|
|
|
|
unlink($destinationPath['pathDocument'] . $name); |
|
|
|
|
DB::rollBack(); |
|
|
|
@ -82,14 +70,12 @@ class ProjectDokumenController extends Controller
|
|
|
|
|
DB::commit(); |
|
|
|
|
return response()->json(['status' => 'success', 'message' => 'Dokumen project berhasil diupload!', 'code' => 200], 200); |
|
|
|
|
} |
|
|
|
|
DB::rollBack(); |
|
|
|
|
return response()->json(['status'=>'failed','message'=>'Dokumen project gagal diupload!','code'=> 500], 500); |
|
|
|
|
} |
|
|
|
|
DB::rollBack(); |
|
|
|
|
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(); |
|
|
|
|
|
|
|
|
|
$dataBuilder = $this->setUpPayload($payload, 'document_project'); |
|
|
|
@ -101,27 +87,25 @@ class ProjectDokumenController extends Controller
|
|
|
|
|
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); |
|
|
|
|
} |
|
|
|
|
$document = DokumenProject::find($id); |
|
|
|
|
$company = Company::find($company_id); |
|
|
|
|
|
|
|
|
|
if(!$document || !$company) { |
|
|
|
|
if (!$document) { |
|
|
|
|
return response()->json(['status' => 'failed', 'message' => 'Data not found!', 'code' => 404], 404); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$destinationPath = $this->setCustomeDirectoryUpload($company['company_name']); |
|
|
|
|
$destinationPath = $this->setCustomeDirectoryUpload(); |
|
|
|
|
$pathToFile = $destinationPath['pathDocument'] . $document['file']; |
|
|
|
|
|
|
|
|
|
if (!file_exists($pathToFile)) { |
|
|
|
|
return response()->json(['status' => 'failed', 'message' => 'Directory not found!', 'code' => 404], 404); |
|
|
|
|
} |
|
|
|
|
if($company) { |
|
|
|
|
|
|
|
|
|
$name = pathinfo($pathToFile, PATHINFO_FILENAME) . "." . pathinfo($pathToFile, PATHINFO_EXTENSION); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$headers = [ |
|
|
|
|
'Content-Disposition' => 'attachment; filename="' . $name . '"' |
|
|
|
|
]; |
|
|
|
|