Browse Source

update tmp import

pull/3/head
ibnu 2 years ago
parent
commit
627dd6b9c1
  1. 38
      app/Http/Controllers/ActivityController.php
  2. 1
      app/Http/Controllers/Controller.php
  3. 17
      app/Models/TmpImport.php
  4. 3
      routes/web.php

38
app/Http/Controllers/ActivityController.php

@ -6,6 +6,7 @@ use App\Models\CommentActivity;
use App\Models\Link; use App\Models\Link;
use App\Models\Project; use App\Models\Project;
use App\Models\TemplateGantt; use App\Models\TemplateGantt;
use App\Models\TmpImport;
use App\Models\VersionGantt; use App\Models\VersionGantt;
use App\Models\UserToActivity; use App\Models\UserToActivity;
use Illuminate\Http\Request; use Illuminate\Http\Request;
@ -280,9 +281,9 @@ class ActivityController extends Controller
return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>$totalRecord], 200); return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>$totalRecord], 200);
} }
public function import(Request $request) public function import(Request $request)
{ {
$data = $request->all(); $data = $request->all();
$data['created_by'] = $this->currentName; $data['created_by'] = $this->currentName;
@ -306,7 +307,7 @@ class ActivityController extends Controller
$input['bobot_planning'] = $activity_row['weight']; $input['bobot_planning'] = $activity_row['weight'];
$input['persentase_progress'] = 0; $input['persentase_progress'] = 0;
$input['type_activity'] = $i == 0 ? "header" : "task"; $input['type_activity'] = $i == 0 ? "header" : "task";
$input['created_by'] = $this->currentName; $input['created_by'] = $this->currentName;
if (!$activity = Activity::create($input)) { if (!$activity = Activity::create($input)) {
Activity::where('version_gantt_id', $data['ganttId'])->delete(); Activity::where('version_gantt_id', $data['ganttId'])->delete();
@ -385,5 +386,34 @@ class ActivityController extends Controller
} }
return response()->json(['stack' => $activityStack, 'status' => 'success', 'message' => 'Data imported!', 'projectId' => $projectId, 'code' => 200], 200); return response()->json(['stack' => $activityStack, 'status' => 'success', 'message' => 'Data imported!', 'projectId' => $projectId, 'code' => 200], 200);
} }
public function uploadTmpImport(Request $request)
{
if($request->hasFile('dokumen')){
$document = $request->file('dokumen');
$gantt_id = $request->gantt_id;
$name = $document->getClientOriginalName();
$result = $document->move($this->pathDocument, $name);
if($result){
$data = [
'ref_id' => (int)$gantt_id,
'file' => $name,
'type_dokumen' => $request->type_dokumen
];
$result = TmpImport::create($data);
if(!$result){
unlink($this->pathDocument.$name);
return response()->json(['status'=>'failed','message'=>'Upload failed!','code'=> 500], 500);
}
return response()->json(['status'=>'success','message'=>'Upload successful!','code'=>200], 200);
}
return response()->json(['status'=>'failed','message'=>'Upload failed!','code'=> 500], 500);
}
return response()->json(['status'=>'failed','message'=>'File is required!','code'=>400], 400);
}
} }

1
app/Http/Controllers/Controller.php

@ -11,6 +11,7 @@ class Controller extends BaseController
{ {
protected $pathImage = "assets/image/"; protected $pathImage = "assets/image/";
protected $pathDocument = "assets/file/project/"; protected $pathDocument = "assets/file/project/";
protected $pathTmpImport = "assets/file/tmpimport/";
protected $pathActivityDocument = "assets/file/activity/"; protected $pathActivityDocument = "assets/file/activity/";
protected $listJoinAll = ['first', 'second', 'third', 'fourth', 'fifth', protected $listJoinAll = ['first', 'second', 'third', 'fourth', 'fifth',
'sixth', 'seventh', 'eighth', 'ninth', 'tenth']; 'sixth', 'seventh', 'eighth', 'ninth', 'tenth'];

17
app/Models/TmpImport.php

@ -0,0 +1,17 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class TmpImport extends Model
{
protected $table = 'tmp_import';
const CREATED_AT = 'created_at';
const UPDATED_AT = 'created_by';
protected $fillable = [
'file', 'type_dokumen', 'gantt_id', 'created_at', 'created_by'
];
}

3
routes/web.php

@ -200,13 +200,14 @@ $router->group(['prefix'=>'api', 'middleware' => 'cors'], function () use ($rout
$router->get('/sumVolActualM/{id}', 'ActivityController@sumVolumeActualMaterial'); $router->get('/sumVolActualM/{id}', 'ActivityController@sumVolumeActualMaterial');
$router->get('/activity/{id}/{proyek_id}/get', 'ActivityController@getByGanttId'); $router->get('/activity/{id}/{proyek_id}/get', 'ActivityController@getByGanttId');
$router->get('/activity/search', 'ActivityController@search'); $router->get('/activity/search', 'ActivityController@search');
$router->post('/activity/import', 'ActivityController@import'); $router->post('/activity/import', 'ActivityController@import');
$router->post('/task', 'ActivityController@add'); $router->post('/task', 'ActivityController@add');
$router->get('/task/edit/{id}', 'ActivityController@edit'); $router->get('/task/edit/{id}', 'ActivityController@edit');
$router->put('/task/{id}', 'ActivityController@update'); $router->put('/task/{id}', 'ActivityController@update');
$router->put('/task/update-regular/{id}', 'ActivityController@updateRegular'); $router->put('/task/update-regular/{id}', 'ActivityController@updateRegular');
$router->delete('/task/{id}', 'ActivityController@delete'); $router->delete('/task/{id}', 'ActivityController@delete');
$router->get('/task/get-update/{id}', 'ActivityController@getUpdate'); $router->get('/task/get-update/{id}', 'ActivityController@getUpdate');
$router->post('/tmp-import/upload', 'ActivityController@uploadTmpImport');
$router->post('/link', 'LinkController@add'); $router->post('/link', 'LinkController@add');
$router->put('/link/{id}', 'LinkController@update'); $router->put('/link/{id}', 'LinkController@update');

Loading…
Cancel
Save