Browse Source

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

Reviewed-on: ibnu/generic-ospro-backend#54
pull/1/head
farhantock 9 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 Laravel\Lumen\Routing\Controller as BaseController;
use RecursiveIteratorIterator;
use RecursiveDirectoryIterator;
class Controller extends BaseController
{
@ -41,10 +43,10 @@ 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/';
$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,
@ -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;
$sizeFile = $dokumen->getSize();
// Path
@ -63,11 +77,11 @@ class Controller extends BaseController
$folderPathTmpImport = $destinatePath['pathTmpImport'];
$folderPathActivityDocument = $destinatePath['pathActivityDocument'];
// Create Directory
if(!file_exists($initPath)) {
if (!file_exists($initPath)) {
mkdir($initPath, 0777, true);
}
// Scanning & Existing Folder
if(file_exists($folderPathImage)) {
if (file_exists($folderPathImage)) {
$files = scandir($folderPathImage);
foreach ($files as $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);
foreach ($filesImage as $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);
foreach ($filesTmpImport as $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);
foreach ($filesActivityDocument as $file) {
if (is_file($folderPathActivityDocument . '/' . $file)) {
@ -105,16 +119,16 @@ class Controller extends BaseController
->where('company_id', $company['id']);
$cloneQueryTransaction = clone $transaction;
$countCreate = false;
if($transaction->where([['type_paket','Basic'], ['amount','!=',null]])->exists()) {
if ($transaction->where([['type_paket', 'Basic'], ['amount', '!=', null]])->exists()) {
$maximumSize = 500 * 1024 * 1024;
$countCreate = true;
} elseif ($cloneQueryTransaction->where([['type_paket','Free'], ['amount', 0]])->exists()) {
} elseif ($cloneQueryTransaction->where([['type_paket', 'Free'], ['amount', 0]])->exists()) {
$maximumSize = 50 * 1024 * 1024;
$countCreate = true;
}
if($countCreate) {
if ($countCreate) {
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);

4
routes/web.php

@ -9,7 +9,7 @@ $router->group(['prefix' => 'api', 'middleware' => 'cors'], function () use ($ro
// Landing Route
$router->post('/send-email', 'AuthController@sendEmail');
$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('/human-resource-user/add', 'HumanResourceController@add_user');
$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->delete('/demo-management/delete/{id}', 'DemoController@delete');
$router->get('/demo-management/list', 'DemoController@list');
$router->get('information-storage/{company_name}', 'Controller@storage');
});
});

Loading…
Cancel
Save