Browse Source

add limits storage

pull/1/head
wahyun 10 months ago
parent
commit
0cc9e67a7e
  1. 30
      app/Http/Controllers/ActivityController.php
  2. 59
      app/Http/Controllers/ActivityDokumenController.php
  3. 122
      app/Http/Controllers/Controller.php
  4. 78
      app/Http/Controllers/ImageController.php
  5. 49
      app/Http/Controllers/ProjectController.php
  6. 61
      app/Http/Controllers/ProjectDokumenController.php
  7. 21
      app/Http/Controllers/UserToProyekController.php
  8. 30
      routes/web.php

30
app/Http/Controllers/ActivityController.php

@ -5,6 +5,7 @@ namespace App\Http\Controllers;
use DateTime;
use App\Models\Link;
use App\Models\User;
use App\Models\Company;
use App\Models\Project;
use App\Models\Activity;
use App\Models\TmpImport;
@ -16,6 +17,7 @@ use App\Models\AssignMaterial;
use App\Models\UserToActivity;
use App\Models\ActivityDokumen;
use App\Models\CommentActivity;
use App\Models\ProductTransaction;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
use App\Helpers\MasterFunctionsHelper;
@ -626,29 +628,33 @@ class ActivityController extends Controller
return response()->json(['status' => 'success', 'message' => 'Activity Updated!', 'code' => 200], 200);
}
public function delete($id)
public function delete($id, $company_id)
{
if (!$data = Activity::find($id))
return response()->json(['status' => 'failed', 'action' => 'error', 'message' => 'Data not found!', 'code' => 404], 404);
$this->deleteRelative($id);
$this->deleteRelative($id, $company_id);
if (!$data->delete())
return response()->json(['status' => 'failed', 'action' => 'error', 'message' => 'data activity failed deleted!', 'code' => 500], 500);
return response()->json(['status' => 'success', "action" => "deleted", 'message' => 'data activity successfully deleted!', 'code' => 200], 200);
}
private function deleteRelative($activity_id)
private function deleteRelative($activity_id, $company_id)
{
UserToActivity::where('activity_id', $activity_id)->delete();
AssignMaterial::where('activity_id', $activity_id)->delete();
$dataAd = ActivityDokumen::where("activity_id", $activity_id)->get();
$company = Company::find($company_id);
if($company) {
$destinationPath = $this->setCustomeDirectoryUpload($company['company_name']);
foreach ($dataAd as $ad) {
if (file_exists($this->pathActivityDocument . $ad->file)) {
unlink($this->pathActivityDocument . $ad->file);
if (file_exists($destinationPath['pathActivityDocument'] . $ad->file)) {
unlink($destinationPath['pathActivityDocument'] . $ad->file);
}
}
ActivityDokumen::where("activity_id", $activity_id)->delete();
}
}
public function getUpdate($id)
{
@ -1124,18 +1130,22 @@ class ActivityController extends Controller
$document = $request->file('dokumen');
$gantt_id = $request->gantt_id;
$name = $document->getClientOriginalName();
$result = $document->move($this->pathTmpImport, $name);
if ($result) {
// Limited Storage
$company = Company::where('company_name', $request->company_name)->first();
if($company) {
$destinationPath = $this->setCustomeDirectoryUpload($company['company_name']);
$getLimitStorage = $this->setLimitsStorage($company, $document, $name, $destinationPath['pathTmpImport'], $destinationPath);
}
if (isset($getLimitStorage) && $getLimitStorage['resultMove']) {
$data = [
'gantt_id' => (int) $gantt_id,
'file' => $name,
'type_dokumen' => $request->type_dokumen
];
$result = TmpImport::create($data);
$getLimitStorage['resultMove'] = TmpImport::create($data);
if (!$result) {
if (!$getLimitStorage['resultMove']) {
unlink($this->pathTmpImport . $name);
return response()->json(['status' => 'failed', 'message' => 'Upload failed!', 'code' => 500], 500);
}

59
app/Http/Controllers/ActivityDokumenController.php

@ -2,6 +2,7 @@
namespace App\Http\Controllers;
use App\Models\Company;
use Illuminate\Http\Request;
use App\Models\ActivityDokumen;
@ -16,50 +17,52 @@ class ActivityDokumenController extends Controller
return response()->json(['status'=>'success','data'=>$dataDokumen,'code'=>200], 200);
}
public function delete($id)
public function delete($id, $company_id)
{
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)
if(!$document) {
return response()->json(['status'=>'failed','message'=>'Data not found!','code'=> 404], 404);
if(file_exists($this->pathActivityDocument.$document->file))
unlink($this->pathActivityDocument.$document->file);
}
$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);
}
}
$document->delete();
return response()->json(['status'=>'success','message'=>'Dokumen deleted successfully!','code'=>200], 200);
}
public function uploadProjectDokumen(Request $request)
{
if(!$request->hasFile('dokumen'))
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();
$result = $document->move($this->pathActivityDocument, $name);
if(!$result)
$company = Company::find($request->company_id);
if($company) {
$destinationPath = $this->setCustomeDirectoryUpload($company['company_name']);
$result = $document->move($destinationPath['pathActivityDocument'], $name);
}
if(!$result || !$company)
return response()->json(['status'=>'failed','message'=>'Upload failed!','code'=> 500], 500);
$data = [
'activity_id' => (int)$activity_id,
'file' => $name,
'description' => $request->description
];
$result = ActivityDokumen::create($data);
if(!$result){
unlink($this->pathActivityDocument.$name);
if(!$result || !$company){
unlink($destinationPath['pathActivityDocument'].$name);
return response()->json(['status'=>'failed','message'=>'Upload failed!','code'=> 500], 500);
}
return response()->json(['status'=>'success','message'=>'Upload success!','code'=>200], 200);
}
@ -75,21 +78,23 @@ class ActivityDokumenController extends Controller
return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>$totalRecord], 200);
}
public function downloadDokumen($id)
public function downloadDokumen($id, $company_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);
}
$document = ActivityDokumen::find($id);
if(!$document)
$company = Company::find($company_id);
if(!$document || !$company) {
return response()->json(['status'=>'failed','message'=>'Data not found!','code'=>400], 400);
if(file_exists($this->pathActivityDocument.$document->file)){
$pathToFile = $this->pathActivityDocument.$document->file;
}
if($company) {
$destinationPath = $this->setCustomeDirectoryUpload($company['company_name']);
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);
}
}

122
app/Http/Controllers/Controller.php

@ -2,16 +2,17 @@
namespace App\Http\Controllers;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Http;
use App\Models\UserToActivity;
use App\Models\User;
use App\Models\Divisi;
use App\Models\Activity;
use App\Models\AssignMaterial;
use App\Models\Divisi;
use App\Models\User;
use Laravel\Lumen\Routing\Controller as BaseController;
use App\Models\ReportK3Detail;
use App\Models\UserToActivity;
use App\Models\ProductTransaction;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Http;
use Laravel\Lumen\Routing\Controller as BaseController;
class Controller extends BaseController
{
@ -38,6 +39,91 @@ class Controller extends BaseController
$this->pathActivityDocument = config('assets.activity');
}
protected function setCustomeDirectoryUpload($company_name)
{
$pathImage = 'assets/'.$company_name.'/image/';
$pathDocument = 'assets/'.$company_name.'/file/project/';
$pathTmpImport = 'assets/'.$company_name.'/file/tmpimport/';
$pathActivityDocument = 'assets/'.$company_name.'/file/activity/';
return [
'pathImage' => $pathImage,
'pathDocument' => $pathDocument,
'pathTmpImport' => $pathTmpImport,
'pathActivityDocument' => $pathActivityDocument
];
}
protected function setLimitsStorage($company, $dokumen, $name, $initPath, $destinatePath) {
$totalSize = 0;
$sizeFile = $dokumen->getSize();
// Path
$folderPath = $destinatePath['pathDocument'];
$folderPathImage = $destinatePath['pathImage'];
$folderPathTmpImport = $destinatePath['pathTmpImport'];
$folderPathActivityDocument = $destinatePath['pathActivityDocument'];
// Create Directory
if(!file_exists($initPath)) {
mkdir($initPath, 0777, true);
}
// Scanning & Existing Folder
if(file_exists($folderPathImage)) {
$files = scandir($folderPathImage);
foreach ($files as $file) {
if (is_file($folderPathImage . '/' . $file)) {
$totalSize += filesize($folderPathImage . '/' . $file);
}
}
}
if(file_exists($folderPath)) {
$filesImage = scandir($folderPath);
foreach ($filesImage as $file) {
if (is_file($folderPath . '/' . $file)) {
$totalSize += filesize($folderPath . '/' . $file);
}
}
}
if(file_exists($folderPathTmpImport)) {
$filesTmpImport = scandir($folderPathTmpImport);
foreach ($filesTmpImport as $file) {
if (is_file($folderPathTmpImport . '/' . $file)) {
$totalSize += filesize($folderPathTmpImport . '/' . $file);
}
}
}
if(file_exists($folderPathActivityDocument)) {
$filesActivityDocument = scandir($folderPathActivityDocument);
foreach ($filesActivityDocument as $file) {
if (is_file($folderPathActivityDocument . '/' . $file)) {
$totalSize += filesize($folderPathActivityDocument . '/' . $file);
}
}
}
// Logic
$totalSize += $sizeFile;
$transaction = ProductTransaction::query()
->where('company_id', $company['id']);
$cloneQueryTransaction = clone $transaction;
$countCreate = false;
if($transaction->where([['type_paket','Basic'], ['amount','!=',null]])->exists()) {
$maximumSize = 500 * 1024 * 1024;
$countCreate = true;
} elseif ($cloneQueryTransaction->where([['type_paket','Free'], ['amount', 0]])->exists()) {
$maximumSize = 50 * 1024 * 1024;
$countCreate = true;
}
if($countCreate) {
if ($totalSize > $maximumSize) {
return response()->json(['status'=>'failed','message'=>'Limited storage maximum!','code'=> 500], 500);
}
}
$resultMove = $dokumen->move($folderPath, $name);
return [
'resultMove' => $resultMove
];
}
protected function setUpPayload($condition, $tableSelf)
{
$alias = "selfTable";
@ -280,6 +366,28 @@ class Controller extends BaseController
return $totalCost;
}
protected function paramsMethodGet($query, $countData, $request)
{
$start = $request->start;
$length = $request->length == '-1' ? $countData : $request->length;
$orderBy = $request->orderby;
$asc = $request->asc == 'false' ? 'desc' : 'asc';
$where = $request->column;
$logicOp = $request->logic;
$valColumn = str_replace("\\", "", "$request->value");
if ($logicOp == 'like' || $logicOp == 'ilike') {
$valColumnFilter = '%' . $valColumn . '%';
} else {
$valColumnFilter = $valColumn;
}
$data = $query->where($where, $logicOp, $valColumnFilter)
->orderBy($orderBy, $asc)
->offset($start)->limit($length)->get();
return $data;
}
protected function getLoc($lat, $lng)
{
// $response = Http::get(config('api.nominatim') . "/reverse?lat=".$lat."&lon=".$lng."&format=json");

78
app/Http/Controllers/ImageController.php

@ -2,9 +2,10 @@
namespace App\Http\Controllers;
use App\Models\Image;
use App\Models\Company;
use Illuminate\Http\Request;
use App\Models\Image;
use App\Models\ProductTransaction;
class ImageController extends Controller
{
@ -22,10 +23,13 @@ class ImageController extends Controller
$extension = $dokumen->extension();
$category = $request->category;
$name = $ref_id.date("YmdHis").".".$extension;
$resultMove = $dokumen->move($this->pathImage, $name);
if($resultMove){
// Limited Storage
$company = Company::where('company_name', $request->company_name)->first();
if($company) {
$destinationPath = $this->setCustomeDirectoryUpload($company['company_name']);
$getLimitStorage = $this->setLimitsStorage($company, $dokumen, $name, $destinationPath['pathImage'], $destinationPath);
}
if(isset($getLimitStorage) && $getLimitStorage['resultMove']) {
$data = [
'ref_id' => (int)$ref_id,
'image' => $name,
@ -63,7 +67,7 @@ class ImageController extends Controller
if($result){
return response()->json(['status'=>'success', "name_image"=>$name,'message'=>'image upload is successfully!','code'=>200], 200);
}else{
unlink($this->pathImage.$name);
unlink($destinationPath['pathImage'].$name);
return response()->json(['status'=>'failed','message'=>'image upload is failed!','code'=>400], 400);
}
@ -88,11 +92,50 @@ class ImageController extends Controller
$dokumen = $request->file('files');
$successCount = 0;
$imageSlider = [];
// Limited Storage
$company = Company::where('company_name', $request->company_name)->first();
if($company) {
$totalSize = 0;
$sizeFile = $dokumen->getSize();
$destinationPath = $this->setCustomeDirectoryUpload($company['company_name']);
$folderPath = $destinationPath['pathImage'];
if (!file_exists($folderPath)) {
mkdir($folderPath, 0777, true);
}
$files = scandir($folderPath);
$totalSize = 0;
foreach ($files as $file) {
if (is_file($folderPath . '/' . $file)) {
$totalSize += filesize($folderPath . '/' . $file);
}
}
$totalSize += $sizeFile;
$transaction = ProductTransaction::query()
->where('company_id', $company['id']);
$cloneQueryTransaction = clone $transaction;
$countCreate = false;
if($transaction->where([['type_paket','Basic'], ['amount','!=',null]])->exists()) {
$maximumSize = 500 * 1024 * 1024;
$countCreate = true;
} elseif ($cloneQueryTransaction->where([['type_paket','Free'], ['amount', 0]])->exists()) {
$maximumSize = 50 * 1024 * 1024;
$countCreate = true;
}
if($countCreate) {
if ($totalSize > $maximumSize) {
return response()->json(['status'=>'failed','message'=>'Limited storage maximum!','code'=> 500], 500);
}
}
}
foreach ($dokumen as $file) {
$extension = $file->extension();
$name = $ref_id.date("YmdHis").$successCount.".".$extension;
$resultMove = $file->move($this->pathImage, $name);
$resultMove = $file->move($folderPath, $name);
if ($resultMove) {
$data = [
@ -107,7 +150,7 @@ class ImageController extends Controller
if ($result) {
$successCount++;
} else {
unlink($this->pathImage . $name);
unlink($folderPath . $name);
}
}
}
@ -147,8 +190,6 @@ class ImageController extends Controller
return response()->json(['status'=>'failed','message'=>'data image not found!','code'=>400], 400);
die();
}
if($delete){
return response()->json(['status'=>'success','message'=>'data image successfully deleted!','code'=>200], 200);
}else{
@ -167,12 +208,13 @@ class ImageController extends Controller
return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>$totalRecord], 200);
}
public function deleteByRef($id, $category)
public function deleteByRef($id, $category, $company_id)
{
$data = Image::where("ref_id", intval($id))->where("category", $category)->first();
if($data){
unlink($this->pathImage.$data->image);
$company = Company::find($company_id);
if($data && $company){
$destinationPath = $this->setCustomeDirectoryUpload($company['company_name']);
unlink($destinationPath['pathImage'].$data->image);
$delete = $data->delete();
}else{
return response()->json(['status'=>'failed','message'=>'data image not found!','code'=>400], 400);
@ -187,16 +229,18 @@ class ImageController extends Controller
}
}
public function deleteByRefMultiple($id, $category)
public function deleteByRefMultiple($id, $category, $company_id)
{
$successCount = 0;
$data = Image::where([
["ref_id", intval($id)],
["category", $category]
])->get();
if($data->isNotEmpty()) {
$company = Company::find($company_id);
if($data->isNotEmpty() && $company) {
$destinationPath = $this->setCustomeDirectoryUpload($company['company_name']);
foreach($data as $img) {
unlink($this->pathImage.$img->image);
unlink($destinationPath['pathImage'].$img->image);
$delete = $img->delete();
if($delete){
$successCount++;

49
app/Http/Controllers/ProjectController.php

@ -6,6 +6,7 @@ use DateTime;
use App\Models\Link;
use App\Models\User;
use App\Models\Image;
use App\Models\Company;
use App\Models\Holiday;
use App\Models\Project;
use App\Models\Activity;
@ -33,15 +34,15 @@ use App\Models\ProjectApproval;
use App\Models\RequestMaterial;
use App\Models\ProjectMileStone;
use App\Models\ProjectChecklists;
use App\Models\ProductTransaction;
use Illuminate\Support\Facades\DB;
use App\Models\ProjectParticipants;
use App\Models\FolderDocumentProyek;
use App\Models\ProjectToChecklistK3;
use App\Helpers\MasterFunctionsHelper;
use App\Models\ProductTransaction;
use App\Models\ReportActivityMaterial;
use Illuminate\Support\Facades\Artisan;
use Illuminate\Database\Query\Builder;
use Illuminate\Support\Facades\Artisan;
const API_GEOLOCATION = "https://nominatim.oslogdev.com/search/ADDR?format=json&addressdetails=1&limit=1";
@ -206,14 +207,14 @@ class ProjectController extends Controller
return true;
}
public function delete($id)
public function delete($id, $company_id)
{
$data = Project::find($id);
if (!$data)
return response()->json(['status' => 'failed', 'message' => 'Data not found!', 'code' => 404], 404);
$this->deleteRelative($id);
$this->deleteRelative($id, $company_id);
if (!$data->delete())
return response()->json(['status' => 'failed', 'message' => 'Delete failed!', 'code' => 500], 500);
@ -221,7 +222,7 @@ class ProjectController extends Controller
return response()->json(['status' => 'success', 'message' => 'Data deleted!', 'code' => 200], 200);
}
private function deleteRelative($project_id)
private function deleteRelative($project_id, $company_id)
{
UserToProyek::where('proyek_id', $project_id)->delete();
UserToActivity::where('proyek_id', $project_id)->delete();
@ -239,30 +240,34 @@ class ProjectController extends Controller
OfficeHours::where('proyek_id', $project_id)->delete();
ReportK3::where('proyek_id', $project_id)->delete();
RequestMaterial::where('proyek_id', $project_id)->delete();
$this->deleteVersionGantt($project_id);
$this->deleteDokumenProject($project_id);
$this->deleteVersionGantt($project_id, $company_id);
$this->deleteDokumenProject($project_id, $company_id);
}
private function deleteVersionGantt($project_id)
private function deleteVersionGantt($project_id, $company_id)
{
$dataVg = VersionGantt::where("proyek_id", $project_id)->pluck("id");
$vhIds = $dataVg->all();
$activity = Activity::whereIn("version_gantt_id", $vhIds)->pluck('id');
$activityIds = $activity->all();
$dataRa = ReportActivity::whereIn("activity_id", $activityIds)->get();
$company = Company::find($company_id);
if($company) {
$destinationPath = $this->setCustomeDirectoryUpload($company['company_name']);
foreach ($dataRa as $ra) {
$images = Image::where("ref_id", $ra->id)->where("category", "report_activity")->get();
foreach ($images as $image) {
if (file_exists($this->pathImage . $image->image)) {
unlink($this->pathImage . $image->image);
if (file_exists($destinationPath['pathImage'] . $image->image)) {
unlink($destinationPath['pathImage'] . $image->image);
}
}
Image::where("ref_id", $ra->id)->where("category", "report_activity")->delete();
}
$dataAd = ActivityDokumen::whereIn("activity_id", $activityIds)->get();
foreach ($dataAd as $ad) {
if (file_exists($this->pathActivityDocument . $ad->file)) {
unlink($this->pathActivityDocument . $ad->file);
if (file_exists($destinationPath['pathActivityDocument'] . $ad->file)) {
unlink($destinationPath['pathActivityDocument'] . $ad->file);
}
}
}
ActivityDokumen::whereIn("activity_id", $activityIds)->delete();
@ -275,23 +280,26 @@ class ProjectController extends Controller
ReportActivity::whereIn("activity_id", $activityIds)->delete();
}
private function deleteDokumenProject($project_id)
private function deleteDokumenProject($project_id, $company_id)
{
$dataDokumen = DokumenProject::where("type_dokumen", "project-document-out-folder")->where('ref_id', $project_id)->get();
$company = Company::find($company_id);
if($company) {
$destinationPath = $this->setCustomeDirectoryUpload($company['company_name']);
foreach ($dataDokumen as $dokumen) {
if (file_exists($this->pathDocument . $dokumen->file)) {
unlink($this->pathDocument . $dokumen->file);
if (file_exists($destinationPath['pathDocument'] . $dokumen->file)) {
unlink($destinationPath['pathDocument'] . $dokumen->file);
}
}
}
DokumenProject::where("type_dokumen", "project-document-out-folder")->where('ref_id', $project_id)->delete();
DokumenProject::where("type_dokumen", "project-document-out-folder")->where('ref_id', $project_id)->delete();
$dataFolder = FolderDocumentProyek::where('proyek_id', $project_id)->pluck("id");
$ref_ids = $dataFolder->all();
$dataDokumen = DokumenProject::where("type_dokumen", "project-document-in-folder")->whereIn('ref_id', $ref_ids)->get();
foreach ($dataDokumen as $dokumen) {
if (file_exists($this->pathDocument . $dokumen->file)) {
unlink($this->pathDocument . $dokumen->file);
if (file_exists($destinationPath['pathDocument'] . $dokumen->file)) {
unlink($destinationPath['pathDocument'] . $dokumen->file);
}
}
@ -520,9 +528,6 @@ class ProjectController extends Controller
}
$activity->save();
}
/* return response()->json(['status'=>'success','data'=> $reports,'code'=>200], 200); */
/* return response()->json(['status'=>'success','data'=> $activities,'code'=>200], 200); */
for ($i = 0; $i < count($reports); $i++) {
$activity = Activity::find($reports[$i]['activity_id']);
if ($reports[$i]['status'] != 'done') {

61
app/Http/Controllers/ProjectDokumenController.php

@ -2,8 +2,10 @@
namespace App\Http\Controllers;
use App\Models\Company;
use Illuminate\Http\Request;
use App\Models\DokumenProject;
use App\Models\ProductTransaction;
class ProjectDokumenController extends Controller
{
@ -20,7 +22,7 @@ class ProjectDokumenController extends Controller
return response()->json(['status'=>'success','data'=> $document ,'code'=>200], 200);
}
public function delete($id)
public function delete($id, $company_id)
{
if(empty($id) || !is_int((int)$id)) {
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400);
@ -30,13 +32,14 @@ class ProjectDokumenController extends Controller
if(!$document){
return response()->json(['status'=>'failed','message'=>'Data not found!','code'=>400], 400);
}
if(file_exists($this->pathDocument.$document->file)){
unlink($this->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();
return response()->json(['status'=>'success','message'=>'Data deleted!','code'=>200], 200);
}
@ -46,25 +49,28 @@ class ProjectDokumenController extends Controller
$document = $request->file('dokumen');
$ref_id = $request->ref_id;
$name = $document->getClientOriginalName();
$result = $document->move($this->pathDocument, $name);
if($result){
// Limited Storage
$company = Company::where('company_name', $request->company_name)->first();
if($company) {
$destinationPath = $this->setCustomeDirectoryUpload($company['company_name']);
$getLimitStorage = $this->setLimitsStorage($company, $document, $name, $destinationPath['pathDocument'],$destinationPath);
}
if(isset($getLimitStorage) && $getLimitStorage['resultMove']) {
$data = [
'ref_id' => (int)$ref_id,
'file' => $name,
'type_dokumen' => isset($request->type_dokumen) ? $request->type_dokumen : 'project-document'
];
$result = DokumenProject::create($data);
$getLimitStorage['resultMove'] = DokumenProject::create($data);
if(!$result){
unlink($this->pathDocument.$name);
return response()->json(['status'=>'failed','message'=>'Upload failed!','code'=> 500], 500);
if(!$getLimitStorage['resultMove']){
unlink($destinationPath['pathDocument'].$name);
return response()->json(['status'=>'failed','message'=>'Dokumen project gagal diupload!','code'=> 500], 500);
}
return response()->json(['status'=>'success','message'=>'Upload successful!','code'=>200], 200);
return response()->json(['status'=>'success','message'=>'Dokumen project berhasil diupload!','code'=>200], 200);
}
return response()->json(['status'=>'failed','message'=>'Upload failed!','code'=> 500], 500);
return response()->json(['status'=>'failed','message'=>'Dokumen project gagal diupload!','code'=> 500], 500);
}
return response()->json(['status'=>'failed','message'=>'File is required!','code'=>400], 400);
}
@ -81,25 +87,28 @@ class ProjectDokumenController extends Controller
return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>$totalRecord], 200);
}
public function downloadDokumen($id)
public function downloadDokumen($id, $company_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);
}
$document = DokumenProject::find($id);
if(!$document)
$company = Company::find($company_id);
if(!$document || !$company) {
return response()->json(['status'=>'failed','message'=>'Data not found!','code'=> 404], 404);
if(!file_exists($this->pathDocument.$document->file))
}
if(!file_exists($this->pathDocument.$document->file)) {
return response()->json(['status'=>'failed','message'=>'Data not found!','code'=> 404], 404);
$pathToFile = $this->pathDocument.$document->file;
}
if($company) {
$destinationPath = $this->setCustomeDirectoryUpload($company['company_name']);
$pathToFile = $destinationPath['pathDocument'].$document->file;
$name = pathinfo($pathToFile, PATHINFO_FILENAME) . "." . pathinfo($pathToFile, PATHINFO_EXTENSION);
}
$headers = [
'Content-Disposition' => 'attachment; filename="'.$name.'"'
];
// dd($name, $headers);
return response()->download($pathToFile, $name, $headers);
}
}

21
app/Http/Controllers/UserToProyekController.php

@ -2,11 +2,12 @@
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\Image;
use App\Models\Company;
use App\Models\UserToProyek;
use App\Models\UserToActivity;
use Illuminate\Http\Request;
use App\Models\ReportActivity;
use App\Models\Image;
use App\Models\UserToActivity;
class UserToProyekController extends Controller
{
@ -111,7 +112,7 @@ class UserToProyekController extends Controller
}
}
public function delete($id)
public function delete($id, $company_id)
{
$data = UserToProyek::find($id);
if($data){
@ -119,7 +120,7 @@ class UserToProyekController extends Controller
$proyekId = $data->proyek_id;
$delete = $data->delete();
if($delete){
$this->deleteRelative($proyekId, $userId);
$this->deleteRelative($proyekId, $userId, $company_id);
}
}else{
return response()->json(['status'=>'failed','message'=>'data assign hr to proyek not found!','code'=>400], 400);
@ -134,22 +135,26 @@ class UserToProyekController extends Controller
}
}
private function deleteRelative($proyekId, $userId)
private function deleteRelative($proyekId, $userId, $company_id)
{
$uta = UserToActivity::where("proyek_id", $proyekId)->where("user_id", $userId)->get();
foreach ($uta as $value) {
$dataRa = ReportActivity::where("activity_id", $value->activity_id)->where("user_id", $value->user_id)->get();
$company = Company::find($company_id);
if($company) {
$destinationPath = $this->setCustomeDirectoryUpload($company['company_name']);
foreach ($dataRa as $ra) {
$images = Image::where("ref_id", $ra->id)->where("category", "report_activity")->get();
foreach ($images as $image) {
if(file_exists($this->pathImage.$image->image)){
unlink($this->pathImage.$image->image);
if(file_exists($destinationPath['pathImage'].$image->image)){
unlink($destinationPath['pathImage'].$image->image);
}
}
Image::where("ref_id", $ra->id)->where("category", "report_activity")->delete();
}
ReportActivity::where("activity_id", $value->activity_id)->where("user_id", $value->user_id)->delete();
}
}
UserToActivity::where("proyek_id", $proyekId)->where("user_id", $userId)->delete();
}

30
routes/web.php

@ -57,15 +57,15 @@ $router->group(['prefix' => 'api', 'middleware' => 'cors'], function () use ($ro
$router->post('/document-project/upload', 'ProjectDokumenController@uploadProjectDokumen');
$router->get('/document-project/get/{id}', 'ProjectDokumenController@dokumenByProyekId');
$router->delete('/document-project/delete/{id}', 'ProjectDokumenController@delete');
$router->delete('/document-project/delete/{id}/{company_id}', 'ProjectDokumenController@delete');
$router->post('/document-project/search', 'ProjectDokumenController@searchDocProject');
$router->get('/document-project/download/{id}', 'ProjectDokumenController@downloadDokumen');
$router->get('/document-project/download/{id}/{company_id}', 'ProjectDokumenController@downloadDokumen');
$router->post('/document-activity/upload', 'ActivityDokumenController@uploadProjectDokumen');
$router->get('/document-activity/get/{id}', 'ActivityDokumenController@dokumenByActivityId');
$router->delete('/document-activity/delete/{id}', 'ActivityDokumenController@delete');
$router->delete('/document-activity/delete/{id}/{company_id}', 'ActivityDokumenController@delete');
$router->post('/document-activity/search', 'ActivityDokumenController@searchDocProject');
$router->get('/document-activity/download/{id}', 'ActivityDokumenController@downloadDokumen');
$router->get('/document-activity/download/{id}/{company_id}', 'ActivityDokumenController@downloadDokumen');
$router->get('/project-by-customer/{id}', 'ProjectController@getByUser');
$router->post('/project/search', 'ProjectController@search');
@ -73,7 +73,7 @@ $router->group(['prefix' => 'api', 'middleware' => 'cors'], function () use ($ro
$router->put('/project/update/{id}', 'ProjectController@update');
$router->get('/project/edit/{id}', 'ProjectController@edit');
$router->get('/project/detail/{id}[/{gantt_id}[/{s_curve}]]', 'ProjectController@detail');
$router->delete('/project/delete/{id}', 'ProjectController@delete');
$router->delete('/project/delete/{id}/{company_id}', 'ProjectController@delete');
$router->get('/project/list', 'ProjectController@list');
$router->get('/project/set-baseline/{gantt_id}', 'ProjectController@setBaseline');
$router->get('/project/set-baseline-activity/{activity_id}/{gantt_id}', 'ProjectController@setBaselineActivity');
@ -263,7 +263,7 @@ $router->group(['prefix' => 'api', 'middleware' => 'cors'], function () use ($ro
$router->get('/task/edit/{id}', 'ActivityController@edit');
$router->put('/task/{id}', 'ActivityController@update');
$router->put('/task/update-regular/{id}', 'ActivityController@updateRegular');
$router->delete('/task/{id}', 'ActivityController@delete');
$router->delete('/task/{id}/{company_id}', 'ActivityController@delete');
$router->get('/task/get-update/{id}', 'ActivityController@getUpdate');
$router->post('/tmp-import/upload', 'ActivityController@uploadTmpImport');
@ -324,8 +324,8 @@ $router->group(['prefix' => 'api', 'middleware' => 'cors'], function () use ($ro
$router->post('/image/search', 'ImageController@search');
$router->delete('/image/delete/{id}', 'ImageController@delete');
$router->delete('/image/delete/{id}/{category}', 'ImageController@deleteByRef');
$router->delete('/image/multiple-delete/{id}/{category}', 'ImageController@deleteByRefMultiple');
$router->delete('/image/delete/{id}/{category}/{company_id}', 'ImageController@deleteByRef');
$router->delete('/image/multiple-delete/{id}/{category}/{company_id}', 'ImageController@deleteByRefMultiple');
$router->post('/image/upload', 'ImageController@uploadImage');
$router->post('/image/multiple-upload', 'ImageController@uploadMultipleImage');
$router->get('/image/{id}/{category}', 'ImageController@getByRefId');
@ -362,6 +362,18 @@ $router->group(['prefix' => 'api', 'middleware' => 'cors'], function () use ($ro
$router->get('/project-issues/list', 'ProjectIssuesController@list');
$router->get('/project-issues/{where}/{val}', 'ProjectIssuesController@customWhere');
$router->get('/kanban-board/list', 'KanbanBoardController@list');
$router->post('/kanban-board/add', 'KanbanBoardController@add');
$router->put('/kanban-board/update/{id}', 'KanbanBoardController@update');
$router->delete('/kanban-board/delete/{id}', 'KanbanBoardController@delete');
$router->post('/kanban-board/search', 'KanbanBoardController@search');
$router->get('/kanban-card/get-data/{project_id}/{gantt_id}/{board_id}', 'KanbanCardController@getData');
$router->post('/kanban-card/add', 'KanbanCardController@add');
$router->put('/kanban-card/update/{id}', 'KanbanCardController@update');
$router->delete('/kanban-card/delete/{id}', 'KanbanCardController@delete');
$router->post('/kanban-card/search', 'KanbanCardController@search');
$router->post('/project-risks/add', 'ProjectRisksController@add');
$router->get('/project-risks/edit/{id}', 'ProjectRisksController@edit');
$router->put('/project-issues/update/{id}', 'ProjectRisksController@update');
@ -464,7 +476,7 @@ $router->group(['prefix' => 'api', 'middleware' => 'cors'], function () use ($ro
$router->get('/user-to-proyek/edit/{id}', 'UserToProyekController@edit');
$router->put('/user-to-proyek/update/{id}', 'UserToProyekController@update');
$router->post('/user-to-proyek/search', 'UserToProyekController@search');
$router->delete('/user-to-proyek/delete/{id}', 'UserToProyekController@delete');
$router->delete('/user-to-proyek/delete/{id}/{company_id}', 'UserToProyekController@delete');
$router->get('/user-to-proyek/list', 'UserToProyekController@list');
$router->get('/user-to-proyek/select', 'UserToProyekController@select');
$router->get('/user-to-proyek/get-employee-integration', 'UserToProyekController@getEmployeeIntegration');

Loading…
Cancel
Save