From 1f086ea51c3df2623cca628784cfc1220e7cac64 Mon Sep 17 00:00:00 2001 From: ibnu Date: Thu, 23 Mar 2023 10:17:33 +0700 Subject: [PATCH] update conflict --- app/Http/Controllers/ActivityController.php | 33 ++++++++++++++------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/app/Http/Controllers/ActivityController.php b/app/Http/Controllers/ActivityController.php index b948351..467147d 100644 --- a/app/Http/Controllers/ActivityController.php +++ b/app/Http/Controllers/ActivityController.php @@ -6,9 +6,9 @@ use App\Models\CommentActivity; use App\Models\Link; use App\Models\Project; use App\Models\TemplateGantt; +use App\Models\TmpImport; use App\Models\VersionGantt; use App\Models\UserToActivity; -use App\Models\TmpImport; use Illuminate\Http\Request; class ActivityController extends Controller @@ -279,9 +279,10 @@ class ActivityController extends Controller $dataGet = $builder->get(); $totalRecord = $countBuilder->count(); return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>$totalRecord], 200); - } + } - public function import(Request $request) + // before upload file + public function importOld(Request $request) { $data = $request->all(); @@ -307,7 +308,7 @@ class ActivityController extends Controller $input['bobot_planning'] = $activity_row['weight']; $input['persentase_progress'] = 0; $input['type_activity'] = $i == 0 ? "header" : "task"; - $input['created_by'] = $this->currentName; + $input['created_by'] = $this->currentName; if (!$activity = Activity::create($input)) { Activity::where('version_gantt_id', $data['ganttId'])->delete(); @@ -386,19 +387,31 @@ class ActivityController extends Controller } return response()->json(['stack' => $activityStack, 'status' => 'success', 'message' => 'Data imported!', 'projectId' => $projectId, 'code' => 200], 200); - } + } + + public function import(Request $request) + { + $data = $request->all(); + $data['created_by'] = $this->currentName; + Activity::where('version_gantt_id', $data['gantt_id'])->delete(); + $projectId = VersionGantt::where('id', $data['gantt_id'])->first()->proyek_id; + // get data excel + $excel = TmpImport::latest('id')->first(); + + return response()->json(['stack' => $excel, 'status' => 'success', 'message' => 'Data imported!', 'data' => $data, 'code' => 200], 200); + } public function uploadTmpImport(Request $request) { if($request->hasFile('dokumen')){ - $document = $request->file('dokumen'); - $ref_id = $request->ref_id; + $document = $request->file('dokumen'); + $gantt_id = $request->gantt_id; $name = $document->getClientOriginalName(); - $result = $document->move($this->pathDocument, $name); + $result = $document->move($this->pathTmpImport, $name); if($result){ $data = [ - 'ref_id' => (int)$ref_id, + 'gantt_id' => (int)$gantt_id, 'file' => $name, 'type_dokumen' => $request->type_dokumen ]; @@ -406,7 +419,7 @@ class ActivityController extends Controller $result = TmpImport::create($data); if(!$result){ - unlink($this->pathDocument.$name); + unlink($this->pathTmpImport.$name); return response()->json(['status'=>'failed','message'=>'Upload failed!','code'=> 500], 500); } return response()->json(['status'=>'success','message'=>'Upload successful!','code'=>200], 200);