Browse Source

Merge pull request 'dev-wahyu' (#213) from dev-wahyu into staging

Reviewed-on: ordo/adw-backend#213
pull/3/head
farhantock 1 year ago
parent
commit
ab55fac61e
  1. 11
      app/Http/Controllers/ActivityController.php
  2. 44
      app/Models/CommentActivity.php
  3. 76
      app/Models/HumanResource.php
  4. 154
      app/Models/VersionGantt.php
  5. 1
      routes/web.php

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);
}
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
public function importOld(Request $request)
{

44
app/Models/CommentActivity.php

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

76
app/Models/HumanResource.php

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

154
app/Models/VersionGantt.php

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

1
routes/web.php

@ -206,6 +206,7 @@ $router->group(['prefix'=>'api', 'middleware' => 'cors'], function () use ($rout
$router->get('/sumVolActualM/{id}', 'ActivityController@sumVolumeActualMaterial');
$router->get('/activity/{id}/{proyek_id}/get', 'ActivityController@getByGanttId');
$router->post('/activity/search', 'ActivityController@search');
$router->post('/activity/search-analysis', 'ActivityController@searchAnalysis');
$router->post('/activity/import', 'ActivityController@import');
$router->post('/activity/import-update', 'ActivityController@importUpdate');
$router->post('/activity/import-old', 'ActivityController@importOld');

Loading…
Cancel
Save