Browse Source

Merge pull request 'add kanban feature, limits storage and user' (#49) from dev-wahyun into staging

Reviewed-on: ibnu/generic-ospro-backend#49
pull/1/head
farhantock 10 months ago
parent
commit
d017044847
  1. 30
      app/Http/Controllers/ActivityController.php
  2. 59
      app/Http/Controllers/ActivityDokumenController.php
  3. 122
      app/Http/Controllers/Controller.php
  4. 40
      app/Http/Controllers/HumanResourceController.php
  5. 78
      app/Http/Controllers/ImageController.php
  6. 115
      app/Http/Controllers/KanbanBoardController.php
  7. 258
      app/Http/Controllers/KanbanCardController.php
  8. 49
      app/Http/Controllers/ProjectController.php
  9. 61
      app/Http/Controllers/ProjectDokumenController.php
  10. 21
      app/Http/Controllers/UserToProyekController.php
  11. 17
      app/Models/KanbanBoard.php
  12. 17
      app/Models/KanbanCard.php
  13. 2
      app/Models/Satuan.php
  14. 30
      routes/web.php

30
app/Http/Controllers/ActivityController.php

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

122
app/Http/Controllers/Controller.php

@ -2,16 +2,17 @@
namespace App\Http\Controllers; namespace App\Http\Controllers;
use Illuminate\Support\Facades\DB; use App\Models\User;
use Illuminate\Support\Facades\Http; use App\Models\Divisi;
use App\Models\UserToActivity;
use App\Models\Activity; use App\Models\Activity;
use App\Models\AssignMaterial; 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\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 class Controller extends BaseController
{ {
@ -38,6 +39,91 @@ class Controller extends BaseController
$this->pathActivityDocument = config('assets.activity'); $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) protected function setUpPayload($condition, $tableSelf)
{ {
$alias = "selfTable"; $alias = "selfTable";
@ -280,6 +366,28 @@ class Controller extends BaseController
return $totalCost; 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) protected function getLoc($lat, $lng)
{ {
// $response = Http::get(config('api.nominatim') . "/reverse?lat=".$lat."&lon=".$lng."&format=json"); // $response = Http::get(config('api.nominatim') . "/reverse?lat=".$lat."&lon=".$lng."&format=json");

40
app/Http/Controllers/HumanResourceController.php

@ -41,7 +41,7 @@ class HumanResourceController extends Controller
->where('company_id', $request->company_id) ->where('company_id', $request->company_id)
->first(); ->first();
if($transaction->where([['type_paket','Basic'],['amount','!=',null]])->exists()) { if($transaction->where([['type_paket','Basic'],['amount','!=',null]])->exists()) {
if($projectResult['total_hr'] < 10) { if($projectResult['total_hr'] < 50) {
$countCreate = true; $countCreate = true;
} }
} elseif ($cloneQueryTransaction->where([['type_paket','Free'],['amount',0]])->exists()) { } elseif ($cloneQueryTransaction->where([['type_paket','Free'],['amount',0]])->exists()) {
@ -74,7 +74,7 @@ class HumanResourceController extends Controller
'employee_type' => 'required', 'employee_type' => 'required',
'company_id' => 'required', 'company_id' => 'required',
'username' => 'required', 'username' => 'required',
'email' => 'required' 'email' => 'required|unique:m_users,email|email'
]); ]);
$data = $request->all(); $data = $request->all();
@ -113,10 +113,38 @@ class HumanResourceController extends Controller
{ {
if (!$id || (int) $id < 0 || $id == "") { if (!$id || (int) $id < 0 || $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);
} }
$humanresource = HumanResource::find($id); $humanresource = HumanResource::find($id);
if(empty($humanresource)) {
return response()->json(['status' => 'failed', 'message' => 'Data Human Resource not found!', 'code' => 400], 400);
}
$transaction = ProductTransaction::query()
->where('company_id', $request->company_id);
$cloneQueryTransaction = clone $transaction;
if($request->company_id && isset($request->password) && isset($request->username)) :
$countCreate = false;
$projectResult = HumanResource::query()
->selectRaw('count(*) as total_hr')
->where([
['company_id', $request->company_id],
['username', '!=', null],
['password', '!=', null]
])
->first();
if($transaction->where([['type_paket','Basic'],['amount','!=',null]])->exists()) {
if($projectResult['total_hr'] < 10) {
$countCreate = true;
}
} elseif ($cloneQueryTransaction->where([['type_paket','Free'],['amount',0]])->exists()) {
if($projectResult['total_hr'] < 1) {
$countCreate = true;
}
} else {
$countCreate = true;
}
endif;
$request->ktp_number !== $humanresource['ktp_number'] ? $this->validate($request,['ktp_number'=>'unique:m_users,ktp_number|string']) : ''; $request->ktp_number !== $humanresource['ktp_number'] ? $this->validate($request,['ktp_number'=>'unique:m_users,ktp_number|string']) : '';
$request->email !== $humanresource['email'] ? $this->validate($request,['email'=>'unique:m_users,email|email']) : ''; $request->email !== $humanresource['email'] ? $this->validate($request,['email'=>'unique:m_users,email|email']) : '';
$request->password ? $this->validate($request,['password'=>'required|min:8']) : ''; $request->password ? $this->validate($request,['password'=>'required|min:8']) : '';
@ -131,11 +159,10 @@ class HumanResourceController extends Controller
return response()->json(['status' => 'failed', 'message' => 'Username already exists!', 'code' => 400], 400); return response()->json(['status' => 'failed', 'message' => 'Username already exists!', 'code' => 400], 400);
} }
if ($humanresource) { if ($countCreate) {
$result = $humanresource->update($data); $result = $humanresource->update($data);
} else { } else {
return response()->json(['status' => 'failed', 'message' => 'data Human Resource Pool not found!', 'code' => 400], 400); return response()->json(['status' => 'failed', 'message' => 'Limited to create human resource!', 'code' => 500], 500);
die();
} }
if ($result) { if ($result) {
@ -153,7 +180,6 @@ class HumanResourceController extends Controller
$delete = $data->delete(); $delete = $data->delete();
} else { } else {
return response()->json(['status' => 'failed', 'message' => 'data Human Resource Pool not found!', 'code' => 400], 400); return response()->json(['status' => 'failed', 'message' => 'data Human Resource Pool not found!', 'code' => 400], 400);
die();
} }

78
app/Http/Controllers/ImageController.php

@ -2,9 +2,10 @@
namespace App\Http\Controllers; namespace App\Http\Controllers;
use App\Models\Image;
use App\Models\Company; use App\Models\Company;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use App\Models\Image; use App\Models\ProductTransaction;
class ImageController extends Controller class ImageController extends Controller
{ {
@ -22,10 +23,13 @@ class ImageController extends Controller
$extension = $dokumen->extension(); $extension = $dokumen->extension();
$category = $request->category; $category = $request->category;
$name = $ref_id.date("YmdHis").".".$extension; $name = $ref_id.date("YmdHis").".".$extension;
// Limited Storage
$resultMove = $dokumen->move($this->pathImage, $name); $company = Company::where('company_name', $request->company_name)->first();
if($company) {
if($resultMove){ $destinationPath = $this->setCustomeDirectoryUpload($company['company_name']);
$getLimitStorage = $this->setLimitsStorage($company, $dokumen, $name, $destinationPath['pathImage'], $destinationPath);
}
if(isset($getLimitStorage) && $getLimitStorage['resultMove']) {
$data = [ $data = [
'ref_id' => (int)$ref_id, 'ref_id' => (int)$ref_id,
'image' => $name, 'image' => $name,
@ -63,7 +67,7 @@ class ImageController extends Controller
if($result){ if($result){
return response()->json(['status'=>'success', "name_image"=>$name,'message'=>'image upload is successfully!','code'=>200], 200); return response()->json(['status'=>'success', "name_image"=>$name,'message'=>'image upload is successfully!','code'=>200], 200);
}else{ }else{
unlink($this->pathImage.$name); unlink($destinationPath['pathImage'].$name);
return response()->json(['status'=>'failed','message'=>'image upload is failed!','code'=>400], 400); 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'); $dokumen = $request->file('files');
$successCount = 0; $successCount = 0;
$imageSlider = []; $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) { foreach ($dokumen as $file) {
$extension = $file->extension(); $extension = $file->extension();
$name = $ref_id.date("YmdHis").$successCount.".".$extension; $name = $ref_id.date("YmdHis").$successCount.".".$extension;
$resultMove = $file->move($this->pathImage, $name); $resultMove = $file->move($folderPath, $name);
if ($resultMove) { if ($resultMove) {
$data = [ $data = [
@ -107,7 +150,7 @@ class ImageController extends Controller
if ($result) { if ($result) {
$successCount++; $successCount++;
} else { } 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); return response()->json(['status'=>'failed','message'=>'data image not found!','code'=>400], 400);
die(); die();
} }
if($delete){ if($delete){
return response()->json(['status'=>'success','message'=>'data image successfully deleted!','code'=>200], 200); return response()->json(['status'=>'success','message'=>'data image successfully deleted!','code'=>200], 200);
}else{ }else{
@ -167,12 +208,13 @@ class ImageController extends Controller
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 deleteByRef($id, $category) public function deleteByRef($id, $category, $company_id)
{ {
$data = Image::where("ref_id", intval($id))->where("category", $category)->first(); $data = Image::where("ref_id", intval($id))->where("category", $category)->first();
$company = Company::find($company_id);
if($data){ if($data && $company){
unlink($this->pathImage.$data->image); $destinationPath = $this->setCustomeDirectoryUpload($company['company_name']);
unlink($destinationPath['pathImage'].$data->image);
$delete = $data->delete(); $delete = $data->delete();
}else{ }else{
return response()->json(['status'=>'failed','message'=>'data image not found!','code'=>400], 400); 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; $successCount = 0;
$data = Image::where([ $data = Image::where([
["ref_id", intval($id)], ["ref_id", intval($id)],
["category", $category] ["category", $category]
])->get(); ])->get();
if($data->isNotEmpty()) { $company = Company::find($company_id);
if($data->isNotEmpty() && $company) {
$destinationPath = $this->setCustomeDirectoryUpload($company['company_name']);
foreach($data as $img) { foreach($data as $img) {
unlink($this->pathImage.$img->image); unlink($destinationPath['pathImage'].$img->image);
$delete = $img->delete(); $delete = $img->delete();
if($delete){ if($delete){
$successCount++; $successCount++;

115
app/Http/Controllers/KanbanBoardController.php

@ -0,0 +1,115 @@
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\KanbanBoard;
class KanbanBoardController extends Controller
{
public function add(Request $request){
$this->validate($request, [
'name_board' => 'required',
'header_color' => 'required',
'body_color' => 'required',
'proyek_id' => 'required',
'version_gantt_id' => 'required',
'status_progress' => 'required'
]);
$data = $request->all();
$data['created_by'] = $this->currentName;
$statusCount = KanbanBoard::where('version_gantt_id', $request->version_gantt_id)
->where('status_progress', $request->status_progress)
->get()
->count();
if ($statusCount < 1 || $request->status_progress == 'none') {
$result = KanbanBoard::create($data);
} else {
return response()->json(['status'=>'failed','message'=>'Board kanban failed created','code'=>400], 400);
}
if($result){
return response()->json(['status'=>'success','message'=>'Board kanban successfull created','code'=>200], 200);
}else{
return response()->json(['status'=>'failed','message'=>'Board kanban failed created','code'=>400], 400);
}
}
public function update(Request $request, $id){
if(!$id || (int) $id < 0 || $id==""){
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400);
}
$data = KanbanBoard::find($id);
if($data){
$result = $data->update($request->all());
}else{
return response()->json(['status'=>'failed','message'=>'Data Board kanban not found!','code'=>400], 400);
die();
}
if($result){
return response()->json(['status'=>'success','message'=>'Board kanban successfully updated!','code'=>200], 200);
}else{
return response()->json(['status'=>'failed','message'=>'Board kanban failed updated!','code'=>400], 400);
}
}
public function delete($id)
{
$data = KanbanBoard::find($id);
if($data){
$delete = $data->delete();
}else{
return response()->json(['status'=>'failed','message'=>'Data Board kanban not found!','code'=>400], 400);
die();
}
if($delete){
return response()->json(['status'=>'success','message'=>'Board kanban successfully deleted!','code'=>200], 200);
}else{
return response()->json(['status'=>'failed','message'=>'Board kanban failed deleted!','code'=>400], 400);
}
}
public function edit($id){
if(!$id || (int) $id < 0 || $id==""){
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400);
die();
}
$result = KanbanBoard::find($id);
if($result){
return response()->json(['status'=>'success','code'=>200,'data'=>$result], 200);
}else{
return response()->json(['status'=>'failed','message'=>'failed get data Board kanban, please try again later!','code'=>400], 400);
}
}
public function search(Request $request)
{
$payload = $request->all();
$dataBuilder = $this->setUpPayload($payload, 'kanban_board');
$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 list(Request $request)
{
$query = KanbanBoard::select("*");
$countData = $query->count();
$data = $this->paramsMethodGet($query, $countData, $request);
if($data)
return response()->json(['status'=>'success','code'=>200,'data'=>$data, 'totalRecord'=>count($data)], 200);
return response()->json(['status'=>'failed','message'=>'failed get Board kanban, please try again later!','code'=>400], 400);
}
}

258
app/Http/Controllers/KanbanCardController.php

@ -0,0 +1,258 @@
<?php
namespace App\Http\Controllers;
use App\Models\User;
use App\Models\Project;
use App\Models\Activity;
use App\Models\KanbanCard;
use App\Models\KanbanBoard;
// use Illuminate\Support\Arr;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
class KanbanCardController extends Controller
{
private function add($board_id, $gantt_id, $type_activity, $status_progress)
{
$dataActivity = Activity::where("version_gantt_id", $gantt_id)
->where("type_activity", $type_activity)
->get();
foreach ($dataActivity as $keyA) {
// $this->add($keyA->id, $gantt_id, $board_id);
$data = array(
'activity_id' => $keyA->id,
'kanban_board_id' => $board_id,
'version_gantt_id' => $gantt_id,
'created_by' => $this->currentName
);
switch ($status_progress) {
case 'open':
if ($keyA->persentase_progress == 0) {
$add = KanbanCard::create($data);
}
break;
case 'on-progress':
if ($keyA->persentase_progress > 0 && $keyA->persentase_progress < 100) {
$cardIds = DB::table('kanban_card as kc')
->join('m_activity as ma', 'kc.activity_id', '=', 'ma.id')
->where('kc.activity_id', '=', $keyA->id)
->select('kc.id')
->get();
foreach ($cardIds as $cardId) {
$this->delete($cardId->id);
}
$add = KanbanCard::create($data);
}
break;
case 'done':
if ($keyA->persentase_progress == 100) {
$cardIds = DB::table('kanban_card as kc')
->join('m_activity as ma', 'kc.activity_id', '=', 'ma.id')
->where('kc.activity_id', '=', $keyA->id)
->select('kc.id')
->get();
foreach ($cardIds as $cardId) {
$this->delete($cardId->id);
}
$add = KanbanCard::create($data);
}
break;
}
}
return "success";
}
public function update(Request $request, $id)
{
if (!$id || (int) $id < 0 || $id == "") {
return response()->json(['status' => 'failed', 'message' => 'id is required!', 'code' => 400], 400);
}
$data = KanbanCard::where("activity_id", $id);
if ($data) {
$result = $data->update($request->all());
} else {
return response()->json(['status' => 'failed', 'message' => 'Data Card kanban not found!', 'code' => 400], 400);
die();
}
$board = KanbanBoard::find($request->kanban_board_id);
$activity = Activity::find($id);
if ($board->status_progress == "done" && $activity) {
$activity->update(['persentase_progress' => 100]);
} else{
if($activity['persentase_progress'] != 95 && $activity['persentase_progress'] != 100){
$activity->update(['persentase_progress' => 0]);
}else{
$activity->update(['persentase_progress' => 95]);
}
}
if ($result) {
return response()->json(['status' => 'success', 'message' => 'Board kanban successfully updated!', 'code' => 200], 200);
} else {
return response()->json(['status' => 'failed', 'message' => 'Board kanban failed updated!', 'code' => 400], 400);
}
}
public function delete($id)
{
$data = KanbanCard::find($id);
if ($data) {
$delete = $data->delete();
} else {
return response()->json(['status' => 'failed', 'message' => 'Data Board kanban not found!', 'code' => 400], 400);
die();
}
if ($delete) {
return response()->json(['status' => 'success', 'message' => 'Board kanban successfully deleted!', 'code' => 200], 200);
} else {
return response()->json(['status' => 'failed', 'message' => 'Board kanban failed deleted!', 'code' => 400], 400);
}
}
public function edit($id)
{
if (!$id || (int) $id < 0 || $id == "") {
return response()->json(['status' => 'failed', 'message' => 'id is required!', 'code' => 400], 400);
die();
}
$result = KanbanCard::find($id);
if ($result) {
return response()->json(['status' => 'success', 'code' => 200, 'data' => $result], 200);
} else {
return response()->json(['status' => 'failed', 'message' => 'failed get data Board kanban, please try again later!', 'code' => 400], 400);
}
}
public function search(Request $request)
{
$payload = $request->all();
$dataBuilder = $this->setUpPayload($payload, 'kanban_board');
$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 getData($project_id, $gantt_id, $board_id, Request $request)
{
// cek ketika dia owner dari project maka
$SESSIONID = $request->session;
$status_progress = KanbanBoard::select("status_progress")->where('id', $board_id)->first();
if ($status_progress) {
if (DB::table('user_to_version_gantt')->where('user_id', $SESSIONID)->where('version_gantt_id', $gantt_id)->exists()) {
$dataCard = $this->getDataAll($project_id, $gantt_id, $board_id, $status_progress->status_progress, true);
} else {
$dataCard = $this->getDataContributor($project_id, $gantt_id, $board_id, $request, $status_progress->status_progress, true);
}
} else {
return response()->json(['status' => 'empty', 'message' => 'data board is empty, please you insert!', 'code' => 200], 200);
}
if ($dataCard && count($dataCard) > 0){
return response()->json(['status' => 'success', 'code' => 200, 'data' => $dataCard, "totalRecord" => count($dataCard)], 200);
}else{
return response()->json(['status' => 'empty', 'message' => 'data card is empty, please you insert!', 'code' => 200], 200);
}
}
private function getDataAll($project_id, $gantt_id, $board_id, $status_progress, $status)
{
$dataFinal = [];
if($status == true){
if ($status_progress != 'none') {
if (KanbanCard::where('kanban_board_id', $board_id)->where("version_gantt_id", $gantt_id)->count() == 0) {
$this->add($board_id, $gantt_id, 'task', $status_progress);
$this->getDataAll($project_id, $gantt_id, $board_id, $status_progress, false);
}
}
}
$dataCard = DB::table("kanban_card as kc")
->select("ma.id as activity_id", "ma.name", "ma.start_date", "ma.end_date", "ma.persentase_bobot", "ma.jumlah_pekerjaan", "ma.bobot_planning", "ma.persentase_progress")
->join("m_activity as ma", "ma.id", "=", "kc.activity_id")
->where("kc.kanban_board_id", $board_id)
->where("kc.version_gantt_id", $gantt_id)
->orderBy('ma.sortorder')
->get();
foreach ($dataCard as $keyCard) {
$query = DB::table("assign_hr_to_activity as ahta")
->select("ahta.id", "mu.name", "mu.id as id_hr")
->join("m_users as mu", "mu.id", "=", "ahta.user_id")
->where("ahta.activity_id", $keyCard->activity_id)
->get();
$dataArray = array(
"id" => $keyCard->activity_id,
"assign_hr" => $query,
"activity" => $keyCard->name,
"start_date" => $keyCard->start_date,
"end_date" => $keyCard->end_date,
"jumlah_pekerjaan" => $keyCard->jumlah_pekerjaan,
"bobot_planning" => $keyCard->bobot_planning,
"persentase_progress" => $keyCard->persentase_progress
);
$dataFinal[] = $dataArray;
}
// }
return $dataFinal;
}
private function getDataContributor($project_id, $gantt_id, $board_id, $request, $status_progress, $status)
{
$dataFinal = [];
if($status == true){
if ($status_progress != 'none') {
if (KanbanCard::where('kanban_board_id', $board_id)->where("version_gantt_id", $gantt_id)->count() == 0) {
$this->add($board_id, $gantt_id, 'task', $status_progress);
$this->getDataContributor($project_id, $gantt_id, $board_id, $request, $status_progress, false);
}
}
$dataUser = User::whereId($request->session)->first();
$dataCard = DB::table("kanban_card as kc")
->select("ma.id as activity_id", "ma.name", "ma.start_date", "ma.end_date", "ma.persentase_bobot", "ma.jumlah_pekerjaan", "ma.bobot_planning", "ma.persentase_progress")
->join("m_activity as ma", "ma.id", "=", "kc.activity_id")
->where([
["kc.created_by", $dataUser['name']],
["kc.kanban_board_id", $board_id],
["kc.version_gantt_id", $gantt_id]
])
->orderBy('ma.sortorder')
->get();
foreach ($dataCard as $keyCard) {
$query = DB::table("assign_hr_to_activity as ahta")
->select("ahta.id", "mu.name", "mu.id as id_hr")
->join("m_users as mu", "mu.id", "=", "ahta.user_id")
->where("ahta.activity_id", $keyCard->activity_id)
->get();
$dataArray = array(
"id" => $keyCard->activity_id,
"assign_hr" => $query,
"activity" => $keyCard->name,
"start_date" => $keyCard->start_date,
"end_date" => $keyCard->end_date,
"jumlah_pekerjaan" => $keyCard->jumlah_pekerjaan,
"bobot_planning" => $keyCard->bobot_planning,
"persentase_progress" => $keyCard->persentase_progress,
"test" => $request->session
);
$dataFinal[] = $dataArray;
}
}
return $dataFinal;
}
}

49
app/Http/Controllers/ProjectController.php

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

61
app/Http/Controllers/ProjectDokumenController.php

@ -2,8 +2,10 @@
namespace App\Http\Controllers; namespace App\Http\Controllers;
use App\Models\Company;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use App\Models\DokumenProject; use App\Models\DokumenProject;
use App\Models\ProductTransaction;
class ProjectDokumenController extends Controller class ProjectDokumenController extends Controller
{ {
@ -20,7 +22,7 @@ class ProjectDokumenController extends Controller
return response()->json(['status'=>'success','data'=> $document ,'code'=>200], 200); 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)) { 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);
@ -30,13 +32,14 @@ class ProjectDokumenController extends Controller
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);
} }
$company = Company::find($company_id);
if(file_exists($this->pathDocument.$document->file)){ if($company) {
unlink($this->pathDocument.$document->file); $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);
} }
@ -46,25 +49,28 @@ class ProjectDokumenController extends Controller
$document = $request->file('dokumen'); $document = $request->file('dokumen');
$ref_id = $request->ref_id; $ref_id = $request->ref_id;
$name = $document->getClientOriginalName(); $name = $document->getClientOriginalName();
// Limited Storage
$result = $document->move($this->pathDocument, $name); $company = Company::where('company_name', $request->company_name)->first();
if($result){ if($company) {
$destinationPath = $this->setCustomeDirectoryUpload($company['company_name']);
$getLimitStorage = $this->setLimitsStorage($company, $document, $name, $destinationPath['pathDocument'],$destinationPath);
}
if(isset($getLimitStorage) && $getLimitStorage['resultMove']) {
$data = [ $data = [
'ref_id' => (int)$ref_id, 'ref_id' => (int)$ref_id,
'file' => $name, 'file' => $name,
'type_dokumen' => isset($request->type_dokumen) ? $request->type_dokumen : 'project-document' 'type_dokumen' => isset($request->type_dokumen) ? $request->type_dokumen : 'project-document'
]; ];
$result = DokumenProject::create($data); $getLimitStorage['resultMove'] = DokumenProject::create($data);
if(!$result){ if(!$getLimitStorage['resultMove']){
unlink($this->pathDocument.$name); unlink($destinationPath['pathDocument'].$name);
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'=>'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); 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); 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); 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);
}
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); 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); $name = pathinfo($pathToFile, PATHINFO_FILENAME) . "." . pathinfo($pathToFile, PATHINFO_EXTENSION);
}
$headers = [ $headers = [
'Content-Disposition' => 'attachment; filename="'.$name.'"' 'Content-Disposition' => 'attachment; filename="'.$name.'"'
]; ];
// dd($name, $headers);
return response()->download($pathToFile, $name, $headers); return response()->download($pathToFile, $name, $headers);
} }
} }

21
app/Http/Controllers/UserToProyekController.php

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

17
app/Models/KanbanBoard.php

@ -0,0 +1,17 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class KanbanBoard extends Model
{
protected $table = 'kanban_board';
const CREATED_AT = 'created_at';
const UPDATED_AT = 'updated_at';
protected $fillable = [
'name_board', 'header_color', 'body_color', 'status_progress', 'proyek_id', 'version_gantt_id', 'created_at', 'created_by', 'updated_at', 'updated_by'
];
}

17
app/Models/KanbanCard.php

@ -0,0 +1,17 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class KanbanCard extends Model
{
protected $table = 'kanban_card';
const CREATED_AT = 'created_at';
const UPDATED_AT = 'updated_at';
protected $fillable = [
'activity_id', 'kanban_board_id', 'version_gantt_id', 'created_at', 'created_by', 'updated_at', 'updated_by'
];
}

2
app/Models/Satuan.php

@ -12,6 +12,6 @@ class Satuan extends Model
const UPDATED_AT = 'updated_at'; const UPDATED_AT = 'updated_at';
protected $fillable = [ protected $fillable = [
'name', 'description', 'created_at', 'created_by', 'updated_at', 'updated_by' 'name', 'description', 'created_at', 'created_by', 'updated_at', 'updated_by', 'company_id'
]; ];
} }

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->post('/document-project/upload', 'ProjectDokumenController@uploadProjectDokumen');
$router->get('/document-project/get/{id}', 'ProjectDokumenController@dokumenByProyekId'); $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->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->post('/document-activity/upload', 'ActivityDokumenController@uploadProjectDokumen');
$router->get('/document-activity/get/{id}', 'ActivityDokumenController@dokumenByActivityId'); $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->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->get('/project-by-customer/{id}', 'ProjectController@getByUser');
$router->post('/project/search', 'ProjectController@search'); $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->put('/project/update/{id}', 'ProjectController@update');
$router->get('/project/edit/{id}', 'ProjectController@edit'); $router->get('/project/edit/{id}', 'ProjectController@edit');
$router->get('/project/detail/{id}[/{gantt_id}[/{s_curve}]]', 'ProjectController@detail'); $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/list', 'ProjectController@list');
$router->get('/project/set-baseline/{gantt_id}', 'ProjectController@setBaseline'); $router->get('/project/set-baseline/{gantt_id}', 'ProjectController@setBaseline');
$router->get('/project/set-baseline-activity/{activity_id}/{gantt_id}', 'ProjectController@setBaselineActivity'); $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->get('/task/edit/{id}', 'ActivityController@edit');
$router->put('/task/{id}', 'ActivityController@update'); $router->put('/task/{id}', 'ActivityController@update');
$router->put('/task/update-regular/{id}', 'ActivityController@updateRegular'); $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->get('/task/get-update/{id}', 'ActivityController@getUpdate');
$router->post('/tmp-import/upload', 'ActivityController@uploadTmpImport'); $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->post('/image/search', 'ImageController@search');
$router->delete('/image/delete/{id}', 'ImageController@delete'); $router->delete('/image/delete/{id}', 'ImageController@delete');
$router->delete('/image/delete/{id}/{category}', 'ImageController@deleteByRef'); $router->delete('/image/delete/{id}/{category}/{company_id}', 'ImageController@deleteByRef');
$router->delete('/image/multiple-delete/{id}/{category}', 'ImageController@deleteByRefMultiple'); $router->delete('/image/multiple-delete/{id}/{category}/{company_id}', 'ImageController@deleteByRefMultiple');
$router->post('/image/upload', 'ImageController@uploadImage'); $router->post('/image/upload', 'ImageController@uploadImage');
$router->post('/image/multiple-upload', 'ImageController@uploadMultipleImage'); $router->post('/image/multiple-upload', 'ImageController@uploadMultipleImage');
$router->get('/image/{id}/{category}', 'ImageController@getByRefId'); $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/list', 'ProjectIssuesController@list');
$router->get('/project-issues/{where}/{val}', 'ProjectIssuesController@customWhere'); $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->post('/project-risks/add', 'ProjectRisksController@add');
$router->get('/project-risks/edit/{id}', 'ProjectRisksController@edit'); $router->get('/project-risks/edit/{id}', 'ProjectRisksController@edit');
$router->put('/project-issues/update/{id}', 'ProjectRisksController@update'); $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->get('/user-to-proyek/edit/{id}', 'UserToProyekController@edit');
$router->put('/user-to-proyek/update/{id}', 'UserToProyekController@update'); $router->put('/user-to-proyek/update/{id}', 'UserToProyekController@update');
$router->post('/user-to-proyek/search', 'UserToProyekController@search'); $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/list', 'UserToProyekController@list');
$router->get('/user-to-proyek/select', 'UserToProyekController@select'); $router->get('/user-to-proyek/select', 'UserToProyekController@select');
$router->get('/user-to-proyek/get-employee-integration', 'UserToProyekController@getEmployeeIntegration'); $router->get('/user-to-proyek/get-employee-integration', 'UserToProyekController@getEmployeeIntegration');

Loading…
Cancel
Save