Browse Source

Merge pull request 'upload 2023-10-20' (#217) from staging into master

Reviewed-on: ordo/adw-backend#217
pull/3/head
farhantock 1 year ago
parent
commit
d38a726935
  1. 2
      app/Helpers/MasterFunctionsHelper.php
  2. 11
      app/Http/Controllers/ActivityController.php
  3. 190
      app/Http/Controllers/ActivityDokumenController.php
  4. 2
      app/Http/Controllers/DashboardBoDController.php
  5. 5
      app/Http/Controllers/ProjectController.php
  6. 3
      app/Http/Controllers/RoleController.php
  7. 10
      app/Http/Controllers/UserToActivityController.php
  8. 44
      app/Models/CommentActivity.php
  9. 76
      app/Models/HumanResource.php
  10. 2
      app/Models/Role.php
  11. 154
      app/Models/VersionGantt.php
  12. 4
      routes/web.php

2
app/Helpers/MasterFunctionsHelper.php

@ -687,7 +687,7 @@ class MasterFunctionsHelper
// } // }
$totalACWP += $keyActualM->biaya_actual / $keyActualM->duration; $totalACWP += $keyActualM->duration > 0 ? $keyActualM->biaya_actual / $keyActualM->duration : 0;
} catch (\DivisionByZeroError $e) { } catch (\DivisionByZeroError $e) {
return response()->json(['message' => $e->getMessage()]); return response()->json(['message' => $e->getMessage()]);
} }

11
app/Http/Controllers/ActivityController.php

@ -527,6 +527,17 @@ 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 searchAnalysis(Request $request)
{
$dataBuilder = $this->setUpPayload($request->all(), 'm_activity');
$builder = $dataBuilder['builder'];
$dataGet = $builder->select('selfTable.*','m_version_gantt.name_version', 'm_users.name as user_name')
->join('m_version_gantt', 'm_version_gantt.id', '=', 'selfTable.version_gantt_id')
->join('assign_hr_to_activity', 'assign_hr_to_activity.activity_id', '=', 'selfTable.id')
->join('m_users', 'assign_hr_to_activity.user_id', '=', 'm_users.id')
->get();
return response()->json(['status' => 'success', 'code' => 200, 'data' => $dataGet ], 200);
}
// before upload file // before upload file
public function importOld(Request $request) public function importOld(Request $request)
{ {

190
app/Http/Controllers/ActivityDokumenController.php

@ -1,95 +1,95 @@
<?php <?php
namespace App\Http\Controllers; namespace App\Http\Controllers;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use App\Models\ActivityDokumen; use App\Models\ActivityDokumen;
class ActivityDokumenController extends Controller class ActivityDokumenController extends Controller
{ {
public function dokumenByActivityId($id){ public function dokumenByActivityId($id){
if(empty($id) || !is_int((int)$id)) if(empty($id) || !is_int((int)$id))
return response()->json(['status'=>'failed','message'=>'activity id is required!','code'=>400], 400); return response()->json(['status'=>'failed','message'=>'activity id is required!','code'=>400], 400);
$dataDokumen = ActivityDokumen::where("activity_id", $id)->get(); $dataDokumen = ActivityDokumen::where("activity_id", $id)->get();
return response()->json(['status'=>'success','data'=>$dataDokumen,'code'=>200], 200); return response()->json(['status'=>'success','data'=>$dataDokumen,'code'=>200], 200);
} }
public function delete($id) public function delete($id)
{ {
if(empty($id) || !is_int((int)$id)) if(empty($id) || !is_int((int)$id))
return response()->json(['status'=>'failed','message'=>'Id is required!','code'=>400], 400); return response()->json(['status'=>'failed','message'=>'Id is required!','code'=>400], 400);
$document = ActivityDokumen::find($id); $document = ActivityDokumen::find($id);
if(!$document) if(!$document)
return response()->json(['status'=>'failed','message'=>'Data not found!','code'=> 404], 404); return response()->json(['status'=>'failed','message'=>'Data not found!','code'=> 404], 404);
if(file_exists($this->pathActivityDocument.$document->file)) if(file_exists($this->pathActivityDocument.$document->file))
unlink($this->pathActivityDocument.$document->file); unlink($this->pathActivityDocument.$document->file);
$document->delete(); $document->delete();
return response()->json(['status'=>'success','message'=>'Dokumen deleted successfully!','code'=>200], 200); return response()->json(['status'=>'success','message'=>'Dokumen deleted successfully!','code'=>200], 200);
} }
public function uploadProjectDokumen(Request $request) public function uploadProjectDokumen(Request $request)
{ {
if(!$request->hasFile('dokumen')) if(!$request->hasFile('dokumen'))
return response()->json(['status'=>'failed','message'=>'file is required!','code'=>400], 400); return response()->json(['status'=>'failed','message'=>'file is required!','code'=>400], 400);
$activity_id = $request->activity_id; $activity_id = $request->activity_id;
$document = $request->file('dokumen'); $document = $request->file('dokumen');
$name = $document->getClientOriginalName(); $name = $document->getClientOriginalName();
$result = $document->move($this->pathActivityDocument, $name); $result = $document->move($this->pathActivityDocument, $name);
if(!$result) if(!$result)
return response()->json(['status'=>'failed','message'=>'Upload failed!','code'=> 500], 500); return response()->json(['status'=>'failed','message'=>'Upload failed!','code'=> 500], 500);
$data = [ $data = [
'activity_id' => (int)$activity_id, 'activity_id' => (int)$activity_id,
'file' => $name, 'file' => $name,
'description' => $request->description 'description' => $request->description
]; ];
$result = ActivityDokumen::create($data); $result = ActivityDokumen::create($data);
if(!$result){ if(!$result){
unlink($this->pathActivityDocument.$name); unlink($this->pathActivityDocument.$name);
return response()->json(['status'=>'failed','message'=>'Upload failed!','code'=> 500], 500); return response()->json(['status'=>'failed','message'=>'Upload failed!','code'=> 500], 500);
} }
return response()->json(['status'=>'success','message'=>'Upload success!','code'=>200], 200); return response()->json(['status'=>'success','message'=>'Upload success!','code'=>200], 200);
} }
public function searchDocProject(Request $request){ public function searchDocProject(Request $request){
$payload = $request->all(); $payload = $request->all();
$dataBuilder = $this->setUpPayload($payload, 'm_document_activity'); $dataBuilder = $this->setUpPayload($payload, 'm_document_activity');
$builder = $dataBuilder['builder']; $builder = $dataBuilder['builder'];
$countBuilder = $dataBuilder['count']; $countBuilder = $dataBuilder['count'];
$dataGet = $builder->get(); $dataGet = $builder->get();
$totalRecord = $countBuilder->count(); $totalRecord = $countBuilder->count();
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 downloadDokumen($id) public function downloadDokumen($id)
{ {
if(empty($id) || !is_int((int)$id)) if(empty($id) || !is_int((int)$id))
return response()->json(['status'=>'failed','message'=>'Id is required!','code'=>400], 400); return response()->json(['status'=>'failed','message'=>'Id is required!','code'=>400], 400);
$document = ActivityDokumen::find($id); $document = ActivityDokumen::find($id);
if(!$document) if(!$document)
return response()->json(['status'=>'failed','message'=>'Data not found!','code'=>400], 400); return response()->json(['status'=>'failed','message'=>'Data not found!','code'=>400], 400);
if(file_exists($this->pathActivityDocument.$document->file)){ if(file_exists($this->pathActivityDocument.$document->file)){
$pathToFile = $this->pathActivityDocument.$document->file; $pathToFile = $this->pathActivityDocument.$document->file;
return response()->download($pathToFile); return response()->download($pathToFile);
} }
return response()->json(['status'=>'failed','message'=>'Data not found!','code'=>400], 400); return response()->json(['status'=>'failed','message'=>'Data not found!','code'=>400], 400);
} }
} }

2
app/Http/Controllers/DashboardBoDController.php

@ -304,7 +304,7 @@ class DashboardBoDController extends Controller
{ {
$year = $this->interpolateYear($year); $year = $this->interpolateYear($year);
$divisions = Divisi::select('id', 'name') $divisions = Divisi::select('id', 'name', 'color')
->with('children') ->with('children')
->whereNull('parent') ->whereNull('parent')
->get(); ->get();

5
app/Http/Controllers/ProjectController.php

@ -229,6 +229,7 @@ class ProjectController extends Controller
$dataBuilder = $this->setUpPayload($payload, 'm_proyek'); $dataBuilder = $this->setUpPayload($payload, 'm_proyek');
$builder = $dataBuilder['builder']; $builder = $dataBuilder['builder'];
$countBuilder = $dataBuilder['count']; $countBuilder = $dataBuilder['count'];
// $builder->where("selfTable.created_by",$this->currentName);
$dataGet = $builder->get(); $dataGet = $builder->get();
$totalRecord = $countBuilder->count(); $totalRecord = $countBuilder->count();
@ -274,7 +275,9 @@ class ProjectController extends Controller
'created_by', 'created_by',
'updated_at', 'updated_at',
'updated_by' 'updated_by'
)->orderBy('id', 'desc')->get(); )->orderBy('id', 'desc')
// ->where("created_by",$this->currentName)
->get();
$countData = $data->count(); $countData = $data->count();
if(!$data) if(!$data)

3
app/Http/Controllers/RoleController.php

@ -18,6 +18,9 @@ class RoleController extends Controller
$data = $request->all(); $data = $request->all();
$data['created_by'] = $this->currentName; $data['created_by'] = $this->currentName;
if (!isset($data['default_page'])) {
$data['default_page'] = 29; // dashboard
}
$result = Role::create($data); $result = Role::create($data);

10
app/Http/Controllers/UserToActivityController.php

@ -129,6 +129,16 @@ class UserToActivityController extends Controller
return response()->json(['status'=>'success','code'=>200,'data'=>$result], 200); return response()->json(['status'=>'success','code'=>200,'data'=>$result], 200);
} }
public function searchAnalysis(Request $request)
{
$dataBuilder = $this->setUpPayload($request->all(), 'assign_hr_to_activity');
$builder = $dataBuilder['builder'];
$countBuilder = $dataBuilder['count'];
$dataGet = $builder->get();
$totalRecord = $countBuilder->count();
return response()->json(['status' => 'success', 'code' => 200, 'data' => $dataGet, 'totalRecord' => $totalRecord], 200);
}
public function search(Request $request) public function search(Request $request)
{ {
$payload = $request->all(); $payload = $request->all();

44
app/Models/CommentActivity.php

@ -1,22 +1,22 @@
<?php <?php
namespace App\Models; namespace App\Models;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
class CommentActivity extends Model class CommentActivity extends Model
{ {
protected $table = 'm_comment_activity'; protected $table = 'm_comment_activity';
const CREATED_AT = 'created_at'; const CREATED_AT = 'created_at';
const UPDATED_AT = 'updated_at'; const UPDATED_AT = 'updated_at';
protected $fillable = [ protected $fillable = [
'activity_id', 'activity_id',
'comment', 'comment',
'created_at', 'created_at',
'created_by', 'created_by',
'updated_at', 'updated_at',
'updated_by' 'updated_by'
]; ];
} }

76
app/Models/HumanResource.php

@ -1,38 +1,38 @@
<?php <?php
namespace App\Models; namespace App\Models;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
class HumanResource extends Model class HumanResource extends Model
{ {
protected $table = 'm_users'; protected $table = 'm_users';
const CREATED_AT = 'created_at'; const CREATED_AT = 'created_at';
const UPDATED_AT = 'updated_at'; const UPDATED_AT = 'updated_at';
protected $fillable = [ protected $fillable = [
'role_id', 'role_id',
'username', 'username',
'password', 'password',
'session_login', 'session_login',
'name', 'name',
'phone_number', 'phone_number',
'email', 'email',
'address', 'address',
'fcm_token', 'fcm_token',
'gender', 'gender',
'birth_place', 'birth_place',
'birth_date', 'birth_date',
'blood_type', 'blood_type',
'ktp_number', 'ktp_number',
'employee_type', 'employee_type',
'status_resource', 'status_resource',
'created_at', 'created_at',
'created_by', 'created_by',
'updated_at', 'updated_at',
'updated_by', 'updated_by',
'divisi_id', 'divisi_id',
'status_boundary' 'status_boundary'
]; ];
} }

2
app/Models/Role.php

@ -12,6 +12,6 @@ class Role extends Model
const UPDATED_AT = 'updated_at'; const UPDATED_AT = 'updated_at';
protected $fillable = [ protected $fillable = [
'name', 'description', 'created_at', 'created_by', 'updated_at', 'updated_by' 'name', 'description', 'default_page', 'created_at', 'created_by', 'updated_at', 'updated_by'
]; ];
} }

154
app/Models/VersionGantt.php

@ -1,77 +1,77 @@
<?php <?php
namespace App\Models; namespace App\Models;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
use App\Models\Activity; use App\Models\Activity;
use App\Models\Link; use App\Models\Link;
use DateTime; use DateTime;
class VersionGantt extends Model class VersionGantt extends Model
{ {
protected $table = 'm_version_gantt'; protected $table = 'm_version_gantt';
const CREATED_AT = 'created_at'; const CREATED_AT = 'created_at';
const UPDATED_AT = 'updated_at'; const UPDATED_AT = 'updated_at';
protected $fillable = [ protected $fillable = [
'name_version', 'name_version',
'description', 'description',
'date_base_line', 'date_base_line',
'proyek_id', 'proyek_id',
'config_dayoff', 'config_dayoff',
'auto_schedule', 'auto_schedule',
'calculation_type', 'calculation_type',
'committed_cost', 'committed_cost',
'cost_to_complete', 'cost_to_complete',
'progress', 'progress',
'bobot', 'bobot',
'hierarchy_ftth_id', 'hierarchy_ftth_id',
'created_at', 'created_at',
'created_by', 'created_by',
'updated_at', 'updated_at',
'updated_by' 'updated_by'
]; ];
public static function boot() { public static function boot() {
parent::boot(); parent::boot();
static::updated(function($data) { static::updated(function($data) {
$data->updateActDuration(); $data->updateActDuration();
}); });
} }
public function updateActDuration(){ public function updateActDuration(){
$daysOff = explode(',', $this->config_dayoff); $daysOff = explode(',', $this->config_dayoff);
if (in_array('0', $daysOff)) { if (in_array('0', $daysOff)) {
$key = array_search('0', $daysOff, false); $key = array_search('0', $daysOff, false);
$daysOff[$key] = '7'; $daysOff[$key] = '7';
} }
$activities = Activity::where('version_gantt_id', $this->id)->get(); $activities = Activity::where('version_gantt_id', $this->id)->get();
foreach ($activities as $value) { foreach ($activities as $value) {
$exist = Link::where('t_activity_id', $value->id)->exists(); $exist = Link::where('t_activity_id', $value->id)->exists();
$startDate = new DateTime($value->start_date); $startDate = new DateTime($value->start_date);
$endDate = new DateTime($value->end_date); $endDate = new DateTime($value->end_date);
$duration = $endDate->diff($startDate)->days + 1; $duration = $endDate->diff($startDate)->days + 1;
if ($exist) { if ($exist) {
$duration--; $duration--;
} }
// Iterate through each day and subtract the days off // Iterate through each day and subtract the days off
for ($i = 0; $i < $duration; $i++) { for ($i = 0; $i < $duration; $i++) {
$currentDate = clone $startDate; $currentDate = clone $startDate;
$currentDate->modify("+$i day"); $currentDate->modify("+$i day");
$currentDayOfWeek = $currentDate->format('N'); // Get the day of the week (1 - Monday, 7 - Sunday) $currentDayOfWeek = $currentDate->format('N'); // Get the day of the week (1 - Monday, 7 - Sunday)
if (in_array($currentDayOfWeek, $daysOff)) { if (in_array($currentDayOfWeek, $daysOff)) {
$duration--; // Subtract one day from the duration for each day off $duration--; // Subtract one day from the duration for each day off
} }
} }
// Update the activity duration // Update the activity duration
$value->duration = $duration; $value->duration = $duration;
$value->save(); $value->save();
} }
} }
} }

4
routes/web.php

@ -197,6 +197,7 @@ $router->group(['prefix'=>'api', 'middleware' => 'cors'], function () use ($rout
$router->get('/user-to-activity/edit/{id}', 'UserToActivityController@edit'); $router->get('/user-to-activity/edit/{id}', 'UserToActivityController@edit');
$router->put('/user-to-activity/update/{id}', 'UserToActivityController@update'); $router->put('/user-to-activity/update/{id}', 'UserToActivityController@update');
$router->post('/user-to-activity/search', 'UserToActivityController@search'); $router->post('/user-to-activity/search', 'UserToActivityController@search');
$router->post('/user-to-activity/search-analysis', 'UserToActivityController@searchAnalysis');
$router->post('/user-to-activity/list-filtered', 'UserToActivityController@listFiltered'); $router->post('/user-to-activity/list-filtered', 'UserToActivityController@listFiltered');
$router->delete('/user-to-activity/delete/{id}', 'UserToActivityController@delete'); $router->delete('/user-to-activity/delete/{id}', 'UserToActivityController@delete');
$router->get('/user-to-activity/list', 'UserToActivityController@list'); $router->get('/user-to-activity/list', 'UserToActivityController@list');
@ -204,7 +205,8 @@ $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->post('/activity/search', 'ActivityController@search');
$router->post('/activity/search-analysis', 'ActivityController@searchAnalysis');
$router->post('/activity/import', 'ActivityController@import'); $router->post('/activity/import', 'ActivityController@import');
$router->post('/activity/import-update', 'ActivityController@importUpdate'); $router->post('/activity/import-update', 'ActivityController@importUpdate');
$router->post('/activity/import-old', 'ActivityController@importOld'); $router->post('/activity/import-old', 'ActivityController@importOld');

Loading…
Cancel
Save