|
|
|
@ -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); |
|
|
|
|