Browse Source

update uploadTmpImport

pull/1/head
wahyun 7 months ago
parent
commit
90780aec4a
  1. 29
      app/Http/Controllers/ActivityController.php

29
app/Http/Controllers/ActivityController.php

@ -21,6 +21,7 @@ use App\Models\ProductTransaction;
use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Log;
use App\Helpers\MasterFunctionsHelper; use App\Helpers\MasterFunctionsHelper;
use Carbon\Carbon;
class ActivityController extends Controller class ActivityController extends Controller
{ {
@ -1126,33 +1127,49 @@ class ActivityController extends Controller
public function uploadTmpImport(Request $request) public function uploadTmpImport(Request $request)
{ {
DB::beginTransaction();
if ($request->hasFile('dokumen')) { if ($request->hasFile('dokumen')) {
$document = $request->file('dokumen'); $document = $request->file('dokumen');
$gantt_id = $request->gantt_id; $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 // Limited Storage
$company = Company::where('company_name', $request->company_name)->first(); $company = Company::where('company_name', $request->company_name)->first();
if($company) { if($company) {
$destinationPath = $this->setCustomeDirectoryUpload($company['company_name']); $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 = [ $data = [
'gantt_id' => (int) $gantt_id, 'gantt_id' => (int) $gantt_id,
'file' => $name, 'file' => $name,
'type_dokumen' => $request->type_dokumen 'type_dokumen' => $request->type_dokumen
]; ];
$getLimitStorage['resultMove'] = TmpImport::create($data); $result = TmpImport::create($data);
if (!$getLimitStorage['resultMove']) { if (!$document->move($destinationPath['pathTmpImport'], $name) && $result) {
unlink($this->pathTmpImport . $name); unlink($destinationPath['pathTmpImport'].$name);
DB::rollBack();
return response()->json(['status' => 'failed', 'message' => 'Upload failed!', 'code' => 500], 500); return response()->json(['status' => 'failed', 'message' => 'Upload failed!', 'code' => 500], 500);
} }
DB::commit();
return response()->json(['status' => 'success', 'message' => 'Upload successful!', 'code' => 200], 200); return response()->json(['status' => 'success', 'message' => 'Upload successful!', 'code' => 200], 200);
} }
DB::rollBack();
return response()->json(['status' => 'failed', 'message' => 'Upload failed!', 'code' => 500], 500); 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); return response()->json(['status' => 'failed', 'message' => 'File is required!', 'code' => 400], 400);
} }

Loading…
Cancel
Save