farhantock
1 year ago
5 changed files with 149 additions and 137 deletions
@ -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' |
||||||
]; |
]; |
||||||
} |
} |
||||||
|
@ -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' |
||||||
]; |
]; |
||||||
} |
} |
||||||
|
@ -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(); |
||||||
} |
} |
||||||
} |
} |
||||||
} |
} |
||||||
|
Loading…
Reference in new issue