Browse Source

Merge pull request 'dev-wahyun' (#69) from dev-wahyun into staging

Reviewed-on: ibnu/generic-ospro-backend#69
pull/1/head
ibnu 7 months ago
parent
commit
e1abaf1b6c
  1. 29
      app/Http/Controllers/ActivityController.php
  2. 5
      app/Http/Controllers/ActivityDokumenController.php
  3. 35
      app/Http/Controllers/Controller.php
  4. 42
      app/Http/Controllers/FolderDocumentProyekController.php
  5. 37
      app/Http/Controllers/ImageController.php
  6. 7
      app/Http/Controllers/ProjectController.php
  7. 47
      app/Http/Controllers/ProjectDokumenController.php
  8. 4
      app/Models/Project.php
  9. 2
      routes/web.php

29
app/Http/Controllers/ActivityController.php

@ -21,6 +21,7 @@ use App\Models\ProductTransaction;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
use App\Helpers\MasterFunctionsHelper;
use Carbon\Carbon;
class ActivityController extends Controller
{
@ -1126,33 +1127,49 @@ class ActivityController extends Controller
public function uploadTmpImport(Request $request)
{
DB::beginTransaction();
if ($request->hasFile('dokumen')) {
$document = $request->file('dokumen');
$gantt_id = $request->gantt_id;
$name = $document->getClientOriginalName();
$timeNow = Carbon::now();
$originalFilename = $document->getClientOriginalName();
$extension = pathinfo($originalFilename, PATHINFO_EXTENSION);
$filename = pathinfo($originalFilename, PATHINFO_FILENAME);
$name = $filename . '_' . $timeNow->format('d-m-y-His') . '.' . $extension;
// 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);
$getLimitStorage = $this->setLimitsStorage($company, $document, $destinationPath['pathTmpImport'], $destinationPath);
}
if (isset($getLimitStorage) && $getLimitStorage['resultMove']) {
if (isset($getLimitStorage)) {
if($getLimitStorage === false) {
DB::rollBack();
return response()->json(['status' => 'failed', 'message' => 'Limited storage maximum!', 'code' => 500], 500);
}
$data = [
'gantt_id' => (int) $gantt_id,
'file' => $name,
'type_dokumen' => $request->type_dokumen
];
$getLimitStorage['resultMove'] = TmpImport::create($data);
$result = TmpImport::create($data);
if (!$getLimitStorage['resultMove']) {
unlink($this->pathTmpImport . $name);
if (!$document->move($destinationPath['pathTmpImport'], $name) && $result) {
unlink($destinationPath['pathTmpImport'].$name);
DB::rollBack();
return response()->json(['status' => 'failed', 'message' => 'Upload failed!', 'code' => 500], 500);
}
DB::commit();
return response()->json(['status' => 'success', 'message' => 'Upload successful!', 'code' => 200], 200);
}
DB::rollBack();
return response()->json(['status' => 'failed', 'message' => 'Upload failed!', 'code' => 500], 500);
}
DB::rollBack();
return response()->json(['status' => 'failed', 'message' => 'File is required!', 'code' => 400], 400);
}

5
app/Http/Controllers/ActivityDokumenController.php

@ -51,15 +51,16 @@ class ActivityDokumenController extends Controller
$destinationPath = $this->setCustomeDirectoryUpload($company['company_name']);
$result = $document->move($destinationPath['pathActivityDocument'], $name);
}
if(!$result || !$company)
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 || !$company){
if(!$result || !$company) {
unlink($destinationPath['pathActivityDocument'].$name);
return response()->json(['status'=>'failed','message'=>'Upload failed!','code'=> 500], 500);
}

35
app/Http/Controllers/Controller.php

@ -46,10 +46,14 @@ class Controller extends BaseController
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/';
$current_date = date('Y-m-d');
[$year, $month] = explode('-', $current_date);
$yearMonth = $year.'-'.$month;
$pathImage = 'assets/' . $company_name .'/'. $yearMonth . '/image/';
$pathDocument = 'assets/' . $company_name .'/'. $yearMonth . '/file/project/';
$pathTmpImport = 'assets/' . $company_name .'/'. $yearMonth . '/file/tmpimport/';
$pathActivityDocument = 'assets/' . $company_name .'/'. $yearMonth . '/file/activity/';
return [
'pathImage' => $pathImage,
@ -118,8 +122,10 @@ class Controller extends BaseController
}
}
protected function setLimitsStorage($company, $dokumen, $name, $initPath, $destinatePath)
protected function setLimitsStorage($company, $dokumen, $initPath, $destinatePath)
{
$countCreate = false;
DB::transaction(function() use($company, $dokumen, $initPath, $destinatePath, &$countCreate) {
$totalSize = 0;
$sizeFile = $dokumen->getSize();
// Path
@ -169,24 +175,23 @@ class Controller extends BaseController
$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;
} else {
$countCreate = true;
}
if ($countCreate) {
if ($totalSize > $maximumSize) {
return response()->json(['status' => 'failed', 'message' => 'Limited storage maximum!', 'code' => 500], 500);
if (floatval($totalSize) > floatval($maximumSize)) {
$countCreate = false;
}
}
$resultMove = $dokumen->move($initPath, $name);
return [
'resultMove' => $resultMove
];
});
return $countCreate;
}
protected function setUpPayload($condition, $tableSelf)
@ -334,6 +339,10 @@ class Controller extends BaseController
$query = $query->whereIn($tableColumn . "." . $column, $value);
} else if ($operator == "notin") {
$query = $query->whereNotIn($tableColumn . "." . $column, $value);
} else if ($operator == "isnull") {
$query = $query->WhereNull($tableColumn . "." . $column);
} else if ($operator == "notnull") {
$query = $query->WhereNotNull($tableColumn . "." . $column);
} else {
$query = $query->where($tableColumn . "." . $column, $operator, $value);
}

42
app/Http/Controllers/FolderDocumentProyekController.php

@ -2,9 +2,12 @@
namespace App\Http\Controllers;
use App\Models\Company;
use Illuminate\Http\Request;
use App\Models\FolderDocumentProyek;
use App\Models\DokumenProject;
use App\Models\FolderDocumentProyek;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
class FolderDocumentProyekController extends Controller
{
@ -44,23 +47,31 @@ class FolderDocumentProyekController extends Controller
}
}
public function delete($id)
public function delete($id, $company_id)
{
DB::beginTransaction();
$data = FolderDocumentProyek::find($id);
if($data){
$delete = $data->delete();
}else{
return response()->json(['status'=>'failed','message'=>'data Folder Document Proyek not found!','code'=>400], 400);
die();
}
if($delete){
$company = Company::find($company_id);
if($data && $company) {
$destinationPath = $this->setCustomeDirectoryUpload($company['company_name']);
$dir = $destinationPath['pathDocument'];
$dataFile = DokumenProject::where([['type_dokumen', 'project-document-in-folder'],['ref_id', $data['id']]])->orderByRaw('id ASC')->get();
if (is_dir($dir)) {
foreach ($dataFile as $file) {
unlink($dir.$file['file']);
}
}
if($data->delete()) {
DB::commit();
return response()->json(['status'=>'success','message'=>'Folder Document Proyek successfully deleted!','code'=>200], 200);
}else{
} else {
DB::rollBack();
return response()->json(['status'=>'failed','message'=>'Folder Document Proyek failed deleted!','code'=>400], 400);
}
} else {
DB::rollBack();
return response()->json(['status'=>'failed','message'=>'Data Folder Document Proyek not found!','code'=>400], 400);
}
}
public function search(Request $request)
@ -85,6 +96,7 @@ class FolderDocumentProyekController extends Controller
return response()->json(['status'=>'failed','message'=>'failed get list tools request, please try again later!','code'=>400], 400);
}
}
public function getTree($id)
{
$data = FolderDocumentProyek::where('proyek_id', $id)->whereNull('parent_id')->orderByRaw('id ASC')->get();
@ -100,7 +112,7 @@ class FolderDocumentProyekController extends Controller
foreach($dataFile as $objRowFile) {
$objRowFile->key = rand(1, 1000);
$objRowFile->isDir = false;
$objRowFile->proyek_id = $id;
$objRowFile->proyek_id = (int)$id;
$finalData[] = $objRowFile;
}
@ -122,7 +134,7 @@ class FolderDocumentProyekController extends Controller
foreach($dataFile as $objRowFile) {
$objRowFile->key = rand(1, 1000);
$objRowFile->isDir = false;
$objRowFile->proyek_id = $proyek_id;
$objRowFile->proyek_id = (int)$proyek_id;
$finalData[] = $objRowFile;
}

37
app/Http/Controllers/ImageController.php

@ -6,11 +6,13 @@ use App\Models\Image;
use App\Models\Company;
use Illuminate\Http\Request;
use App\Models\ProductTransaction;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
class ImageController extends Controller
{
public function uploadImage(Request $request){
DB::beginTransaction();
if($request->hasFile('files')){
$this->validate($request, [
@ -27,9 +29,13 @@ class ImageController extends Controller
$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);
$getLimitStorage = $this->setLimitsStorage($company, $dokumen, $destinationPath['pathImage'], $destinationPath);
}
if(isset($getLimitStorage)) {
if($getLimitStorage === false) {
DB::rollBack();
return response()->json(['status' => 'failed', 'message' => 'Limited storage maximum!', 'code' => 500], 500);
}
if(isset($getLimitStorage) && $getLimitStorage['resultMove']) {
$data = [
'ref_id' => (int)$ref_id,
'image' => $name,
@ -54,27 +60,30 @@ class ImageController extends Controller
if($company && $category === 'company_logo_header') {
$company->update([
'logo_header' => array('content'=>$name)
'logo_header' => array('content' => $name)
]);
}
if($company && $category === 'company_favicon') {
$company->update([
'favicon_image' => array('content'=>$name)
'favicon_image' => array('content' => $name)
]);
}
if($result){
return response()->json(['status'=>'success', "name_image"=>$name,'message'=>'image upload is successfully!','code'=>200], 200);
}else{
if($dokumen->move($destinationPath['pathImage'], $name) && $result) {
DB::commit();
return response()->json(['status' => 'success', "name_image" => $name,'message' => 'image upload is successfully!','code' => 200], 200);
} else {
DB::rollBack();
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! pertama' ,'code' => 400], 400);
}
}else{
return response()->json(['status'=>'failed','message'=>'image upload is failed!','code'=>400], 400);
} else {
DB::rollBack();
return response()->json(['status'=>'failed','message'=>'image upload is failed! kedua','code'=>400], 400);
}
}else{
} else {
DB::rollBack();
return response()->json(['status'=>'failed','message'=>'image is required!','code'=>400], 400);
}
}
@ -210,7 +219,7 @@ class ImageController extends Controller
public function deleteByRef($id, $category, $company_id)
{
$data = Image::where("ref_id", intval($id))->where("category", $category)->first();
$data = Image::where("ref_id", (int)$id)->where("category", $category)->first();
$company = Company::find($company_id);
if($data && $company){
$destinationPath = $this->setCustomeDirectoryUpload($company['company_name']);

7
app/Http/Controllers/ProjectController.php

@ -13,6 +13,7 @@ use App\Models\{ReportActivityMaterial,ProjectToChecklistK3,FolderDocumentProyek
use Illuminate\Database\Query\Builder;
use Illuminate\Support\Facades\{Artisan,DB};
use App\Helpers\MasterFunctionsHelper;
use Carbon\Carbon;
const API_GEOLOCATION = "https://nominatim.oslogdev.com/search/ADDR?format=json&addressdetails=1&limit=1";
@ -178,9 +179,11 @@ class ProjectController extends Controller
{
DB::beginTransaction();
$data = Project::find($id);
$dateNow = Carbon::now();
if ($data) {
$this->deleteRelative($id, $company_id);
if ($data->delete()) {
// $this->deleteRelative($id, $company_id);
// if ($data->delete()) {
if ($data->update(['deleted_at' => $dateNow, 'deleted_by_id' => $this->currentId])) {
DB::commit();
return response()->json(['status' => 'success', 'message' => 'Data deleted!', 'code' => 200], 200);
} else {

47
app/Http/Controllers/ProjectDokumenController.php

@ -2,10 +2,10 @@
namespace App\Http\Controllers;
use App\Models\Company;
use Illuminate\Http\Request;
use App\Models\DokumenProject;
use App\Models\ProductTransaction;
use App\Models\{DokumenProject,Company};
use Carbon\Carbon;
use Illuminate\Support\Facades\DB;
class ProjectDokumenController extends Controller
{
@ -35,8 +35,8 @@ class ProjectDokumenController extends Controller
$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);
if(file_exists($destinationPath['pathDocument'].$document['file'])){
unlink($destinationPath['pathDocument'].$document['file']);
}
}
$document->delete();
@ -45,33 +45,47 @@ class ProjectDokumenController extends Controller
public function uploadProjectDokumen(Request $request)
{
DB::beginTransaction();
$timeNow = Carbon::now();
if($request->hasFile('dokumen')){
$document = $request->file('dokumen');
$ref_id = $request->ref_id;
$name = $document->getClientOriginalName();
$originalFilename = $document->getClientOriginalName();
$extension = pathinfo($originalFilename, PATHINFO_EXTENSION);
$filename = pathinfo($originalFilename, PATHINFO_FILENAME);
$name = $filename . '_' . $timeNow->format('d-m-y-His') . '.' . $extension;
// Limited Storage
$company = Company::where('company_name', $request->company_name)->first();
$company = Company::whereId($request->company_id)->first();
if($company) {
$destinationPath = $this->setCustomeDirectoryUpload($company['company_name']);
$getLimitStorage = $this->setLimitsStorage($company, $document, $name, $destinationPath['pathDocument'],$destinationPath);
$getLimitStorage = $this->setLimitsStorage($company, $document, $destinationPath['pathDocument'],$destinationPath);
}
if(isset($getLimitStorage)) {
if($getLimitStorage === false) {
DB::rollBack();
return response()->json(['status' => 'failed', 'message' => 'Limited storage maximum!', 'code' => 500], 500);
}
if(isset($getLimitStorage) && $getLimitStorage['resultMove']) {
$data = [
'ref_id' => (int)$ref_id,
'file' => $name,
'type_dokumen' => isset($request->type_dokumen) ? $request->type_dokumen : 'project-document'
];
$getLimitStorage['resultMove'] = DokumenProject::create($data);
$result = DokumenProject::create($data);
if(!$getLimitStorage['resultMove']){
if(!$document->move($destinationPath['pathDocument'], $name) && $result) {
unlink($destinationPath['pathDocument'].$name);
DB::rollBack();
return response()->json(['status'=>'failed','message'=>'Dokumen project gagal diupload!','code'=> 500], 500);
}
DB::commit();
return response()->json(['status'=>'success','message'=>'Dokumen project berhasil diupload!','code'=>200], 200);
}
DB::rollBack();
return response()->json(['status'=>'failed','message'=>'Dokumen project gagal diupload!','code'=> 500], 500);
}
DB::rollBack();
return response()->json(['status'=>'failed','message'=>'File is required!','code'=>400], 400);
}
@ -94,15 +108,18 @@ class ProjectDokumenController extends Controller
}
$document = DokumenProject::find($id);
$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)) {
return response()->json(['status'=>'failed','message'=>'Data not found!','code'=> 404], 404);
$destinationPath = $this->setCustomeDirectoryUpload($company['company_name']);
$pathToFile = $destinationPath['pathDocument'].$document['file'];
if(!file_exists($pathToFile)) {
return response()->json(['status'=>'failed','message'=>'Directory not found!','code'=> 404], 404);
}
if($company) {
$destinationPath = $this->setCustomeDirectoryUpload($company['company_name']);
$pathToFile = $destinationPath['pathDocument'].$document->file;
$name = pathinfo($pathToFile, PATHINFO_FILENAME) . "." . pathinfo($pathToFile, PATHINFO_EXTENSION);
}
$headers = [

4
app/Models/Project.php

@ -52,6 +52,8 @@ class Project extends Model
'updated_at',
'updated_by',
'created_by_id',
'company_id'
'company_id',
'deleted_at',
'deleted_by_id'
];
}

2
routes/web.php

@ -494,7 +494,7 @@ $router->group(['prefix' => 'api', 'middleware' => 'cors'], function () use ($ro
$router->get('/folder-document-proyek/edit/{id}', 'FolderDocumentProyekController@edit');
$router->put('/folder-document-proyek/update/{id}', 'FolderDocumentProyekController@update');
$router->post('/folder-document-proyek/search', 'FolderDocumentProyekController@search');
$router->delete('/folder-document-proyek/delete/{id}', 'FolderDocumentProyekController@delete');
$router->delete('/folder-document-proyek/delete/{id}/{company_id}', 'FolderDocumentProyekController@delete');
$router->get('/folder-document-proyek/list', 'FolderDocumentProyekController@list');
$router->get('/folder-document-proyek/get-tree/{id}', 'FolderDocumentProyekController@getTree');

Loading…
Cancel
Save