Browse Source

Merge pull request 'storage Information' (#54) from Dev-Farhan into staging

Reviewed-on: ibnu/generic-ospro-backend#54
pull/1/head
farhantock 10 months ago
parent
commit
3a02ac196d
  1. 42
      app/Http/Controllers/Controller.php
  2. 4
      routes/web.php

42
app/Http/Controllers/Controller.php

@ -13,6 +13,8 @@ use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Http; use Illuminate\Support\Facades\Http;
use Laravel\Lumen\Routing\Controller as BaseController; use Laravel\Lumen\Routing\Controller as BaseController;
use RecursiveIteratorIterator;
use RecursiveDirectoryIterator;
class Controller extends BaseController class Controller extends BaseController
{ {
@ -41,10 +43,10 @@ class Controller extends BaseController
protected function setCustomeDirectoryUpload($company_name) protected function setCustomeDirectoryUpload($company_name)
{ {
$pathImage = 'assets/'.$company_name.'/image/'; $pathImage = 'assets/' . $company_name . '/image/';
$pathDocument = 'assets/'.$company_name.'/file/project/'; $pathDocument = 'assets/' . $company_name . '/file/project/';
$pathTmpImport = 'assets/'.$company_name.'/file/tmpimport/'; $pathTmpImport = 'assets/' . $company_name . '/file/tmpimport/';
$pathActivityDocument = 'assets/'.$company_name.'/file/activity/'; $pathActivityDocument = 'assets/' . $company_name . '/file/activity/';
return [ return [
'pathImage' => $pathImage, 'pathImage' => $pathImage,
@ -54,7 +56,19 @@ class Controller extends BaseController
]; ];
} }
protected function setLimitsStorage($company, $dokumen, $name, $initPath, $destinatePath) { public function storage($company_name)
{
$directory = 'assets/' . urldecode($company_name);
$size = 0;
foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($directory)) as $file) {
$size += $file->getSize();
}
return round($size / 1048576, 2);
}
protected function setLimitsStorage($company, $dokumen, $name, $initPath, $destinatePath)
{
$totalSize = 0; $totalSize = 0;
$sizeFile = $dokumen->getSize(); $sizeFile = $dokumen->getSize();
// Path // Path
@ -63,11 +77,11 @@ class Controller extends BaseController
$folderPathTmpImport = $destinatePath['pathTmpImport']; $folderPathTmpImport = $destinatePath['pathTmpImport'];
$folderPathActivityDocument = $destinatePath['pathActivityDocument']; $folderPathActivityDocument = $destinatePath['pathActivityDocument'];
// Create Directory // Create Directory
if(!file_exists($initPath)) { if (!file_exists($initPath)) {
mkdir($initPath, 0777, true); mkdir($initPath, 0777, true);
} }
// Scanning & Existing Folder // Scanning & Existing Folder
if(file_exists($folderPathImage)) { if (file_exists($folderPathImage)) {
$files = scandir($folderPathImage); $files = scandir($folderPathImage);
foreach ($files as $file) { foreach ($files as $file) {
if (is_file($folderPathImage . '/' . $file)) { if (is_file($folderPathImage . '/' . $file)) {
@ -75,7 +89,7 @@ class Controller extends BaseController
} }
} }
} }
if(file_exists($folderPath)) { if (file_exists($folderPath)) {
$filesImage = scandir($folderPath); $filesImage = scandir($folderPath);
foreach ($filesImage as $file) { foreach ($filesImage as $file) {
if (is_file($folderPath . '/' . $file)) { if (is_file($folderPath . '/' . $file)) {
@ -83,7 +97,7 @@ class Controller extends BaseController
} }
} }
} }
if(file_exists($folderPathTmpImport)) { if (file_exists($folderPathTmpImport)) {
$filesTmpImport = scandir($folderPathTmpImport); $filesTmpImport = scandir($folderPathTmpImport);
foreach ($filesTmpImport as $file) { foreach ($filesTmpImport as $file) {
if (is_file($folderPathTmpImport . '/' . $file)) { if (is_file($folderPathTmpImport . '/' . $file)) {
@ -91,7 +105,7 @@ class Controller extends BaseController
} }
} }
} }
if(file_exists($folderPathActivityDocument)) { if (file_exists($folderPathActivityDocument)) {
$filesActivityDocument = scandir($folderPathActivityDocument); $filesActivityDocument = scandir($folderPathActivityDocument);
foreach ($filesActivityDocument as $file) { foreach ($filesActivityDocument as $file) {
if (is_file($folderPathActivityDocument . '/' . $file)) { if (is_file($folderPathActivityDocument . '/' . $file)) {
@ -105,16 +119,16 @@ class Controller extends BaseController
->where('company_id', $company['id']); ->where('company_id', $company['id']);
$cloneQueryTransaction = clone $transaction; $cloneQueryTransaction = clone $transaction;
$countCreate = false; $countCreate = false;
if($transaction->where([['type_paket','Basic'], ['amount','!=',null]])->exists()) { if ($transaction->where([['type_paket', 'Basic'], ['amount', '!=', null]])->exists()) {
$maximumSize = 500 * 1024 * 1024; $maximumSize = 500 * 1024 * 1024;
$countCreate = true; $countCreate = true;
} elseif ($cloneQueryTransaction->where([['type_paket','Free'], ['amount', 0]])->exists()) { } elseif ($cloneQueryTransaction->where([['type_paket', 'Free'], ['amount', 0]])->exists()) {
$maximumSize = 50 * 1024 * 1024; $maximumSize = 50 * 1024 * 1024;
$countCreate = true; $countCreate = true;
} }
if($countCreate) { if ($countCreate) {
if ($totalSize > $maximumSize) { if ($totalSize > $maximumSize) {
return response()->json(['status'=>'failed','message'=>'Limited storage maximum!','code'=> 500], 500); return response()->json(['status' => 'failed', 'message' => 'Limited storage maximum!', 'code' => 500], 500);
} }
} }
$resultMove = $dokumen->move($folderPath, $name); $resultMove = $dokumen->move($folderPath, $name);

4
routes/web.php

@ -9,7 +9,7 @@ $router->group(['prefix' => 'api', 'middleware' => 'cors'], function () use ($ro
// Landing Route // Landing Route
$router->post('/send-email', 'AuthController@sendEmail'); $router->post('/send-email', 'AuthController@sendEmail');
$router->post('/company-management-user/add', 'CompanyController@add'); $router->post('/company-management-user/add', 'CompanyController@add');
$router->post('/product-transaction/add','ProductTransactionController@add'); $router->post('/product-transaction/add', 'ProductTransactionController@add');
$router->post('/company-management-user/search', 'CompanyController@search'); $router->post('/company-management-user/search', 'CompanyController@search');
$router->post('/human-resource-user/add', 'HumanResourceController@add_user'); $router->post('/human-resource-user/add', 'HumanResourceController@add_user');
$router->get('/company-management-user/edit/{id}', 'CompanyController@edit'); $router->get('/company-management-user/edit/{id}', 'CompanyController@edit');
@ -587,5 +587,7 @@ $router->group(['prefix' => 'api', 'middleware' => 'cors'], function () use ($ro
$router->post('/demo-management/search', 'DemoController@search'); $router->post('/demo-management/search', 'DemoController@search');
$router->delete('/demo-management/delete/{id}', 'DemoController@delete'); $router->delete('/demo-management/delete/{id}', 'DemoController@delete');
$router->get('/demo-management/list', 'DemoController@list'); $router->get('/demo-management/list', 'DemoController@list');
$router->get('information-storage/{company_name}', 'Controller@storage');
}); });
}); });

Loading…
Cancel
Save