Browse Source

update payload search

pull/1/head
wahyun 7 months ago
parent
commit
d58194a117
  1. 133
      app/Http/Controllers/Controller.php

133
app/Http/Controllers/Controller.php

@ -46,10 +46,14 @@ class Controller extends BaseController
protected function setCustomeDirectoryUpload($company_name) protected function setCustomeDirectoryUpload($company_name)
{ {
$pathImage = 'assets/' . $company_name . '/image/'; $current_date = date('Y-m-d');
$pathDocument = 'assets/' . $company_name . '/file/project/'; [$year, $month] = explode('-', $current_date);
$pathTmpImport = 'assets/' . $company_name . '/file/tmpimport/'; $yearMonth = $year.'-'.$month;
$pathActivityDocument = 'assets/' . $company_name . '/file/activity/';
$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 [ return [
'pathImage' => $pathImage, 'pathImage' => $pathImage,
@ -118,75 +122,76 @@ class Controller extends BaseController
} }
} }
protected function setLimitsStorage($company, $dokumen, $name, $initPath, $destinatePath) protected function setLimitsStorage($company, $dokumen, $initPath, $destinatePath)
{ {
$totalSize = 0; $countCreate = false;
$sizeFile = $dokumen->getSize(); DB::transaction(function() use($company, $dokumen, $initPath, $destinatePath, &$countCreate) {
// Path $totalSize = 0;
$folderPath = $destinatePath['pathDocument']; $sizeFile = $dokumen->getSize();
$folderPathImage = $destinatePath['pathImage']; // Path
$folderPathTmpImport = $destinatePath['pathTmpImport']; $folderPath = $destinatePath['pathDocument'];
$folderPathActivityDocument = $destinatePath['pathActivityDocument']; $folderPathImage = $destinatePath['pathImage'];
// Create Directory $folderPathTmpImport = $destinatePath['pathTmpImport'];
if (!file_exists($initPath)) { $folderPathActivityDocument = $destinatePath['pathActivityDocument'];
mkdir($initPath, 0777, true); // Create Directory
} if (!file_exists($initPath)) {
// Scanning & Existing Folder mkdir($initPath, 0777, true);
if (file_exists($folderPathImage)) { }
$files = scandir($folderPathImage); // Scanning & Existing Folder
foreach ($files as $file) { if (file_exists($folderPathImage)) {
if (is_file($folderPathImage . '/' . $file)) { $files = scandir($folderPathImage);
$totalSize += filesize($folderPathImage . '/' . $file); foreach ($files as $file) {
if (is_file($folderPathImage . '/' . $file)) {
$totalSize += filesize($folderPathImage . '/' . $file);
}
} }
} }
} 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)) { $totalSize += filesize($folderPath . '/' . $file);
$totalSize += filesize($folderPath . '/' . $file); }
} }
} }
} 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)) { $totalSize += filesize($folderPathTmpImport . '/' . $file);
$totalSize += filesize($folderPathTmpImport . '/' . $file); }
} }
} }
} 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)) { $totalSize += filesize($folderPathActivityDocument . '/' . $file);
$totalSize += filesize($folderPathActivityDocument . '/' . $file); }
} }
} }
} // Logic
// Logic $totalSize += $sizeFile;
$totalSize += $sizeFile; $transaction = ProductTransaction::query()
$transaction = ProductTransaction::query() ->where('company_id', $company['id']);
->where('company_id', $company['id']); $cloneQueryTransaction = clone $transaction;
$cloneQueryTransaction = clone $transaction; if ($transaction->where([['type_paket', 'Basic'], ['amount', '!=', null]])->exists()) {
$countCreate = false; $maximumSize = 500 * 1024 * 1024;
if ($transaction->where([['type_paket', 'Basic'], ['amount', '!=', null]])->exists()) { $countCreate = true;
$maximumSize = 500 * 1024 * 1024; } elseif ($cloneQueryTransaction->where([['type_paket', 'Free'], ['amount', 0]])->exists()) {
$countCreate = true; $maximumSize = 50 * 1024 * 1024;
} elseif ($cloneQueryTransaction->where([['type_paket', 'Free'], ['amount', 0]])->exists()) { $countCreate = true;
$maximumSize = 50 * 1024 * 1024; } else {
$countCreate = true; $countCreate = true;
}
if ($countCreate) {
if ($totalSize > $maximumSize) {
return response()->json(['status' => 'failed', 'message' => 'Limited storage maximum!', 'code' => 500], 500);
} }
}
$resultMove = $dokumen->move($initPath, $name);
return [ if ($countCreate) {
'resultMove' => $resultMove if (floatval($totalSize) > floatval($maximumSize)) {
]; $countCreate = false;
}
}
});
return $countCreate;
} }
protected function setUpPayload($condition, $tableSelf) protected function setUpPayload($condition, $tableSelf)
@ -334,6 +339,10 @@ class Controller extends BaseController
$query = $query->whereIn($tableColumn . "." . $column, $value); $query = $query->whereIn($tableColumn . "." . $column, $value);
} else if ($operator == "notin") { } else if ($operator == "notin") {
$query = $query->whereNotIn($tableColumn . "." . $column, $value); $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 { } else {
$query = $query->where($tableColumn . "." . $column, $operator, $value); $query = $query->where($tableColumn . "." . $column, $operator, $value);
} }

Loading…
Cancel
Save