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