ibnu
1 year ago
8 changed files with 190 additions and 100 deletions
@ -1,61 +1,63 @@ |
|||||||
<?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; |
||||||
|
|
||||||
class UserToActivity extends Model |
class UserToActivity extends Model |
||||||
{ |
{ |
||||||
protected $table = 'assign_hr_to_activity'; |
protected $table = 'assign_hr_to_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 = [ |
||||||
'user_id', |
'user_id', |
||||||
'proyek_id', |
'proyek_id', |
||||||
'version_gantt_id', |
'version_gantt_id', |
||||||
'role_proyek_id', |
'role_proyek_id', |
||||||
'activity_id', |
'activity_id', |
||||||
'created_at', |
'start_date', |
||||||
'created_by', |
'end_date', |
||||||
'updated_at', |
'created_at', |
||||||
'updated_by' |
'created_by', |
||||||
]; |
'updated_at', |
||||||
|
'updated_by' |
||||||
public static function boot() { |
]; |
||||||
parent::boot(); |
|
||||||
|
public static function boot() { |
||||||
static::created(function($data) { |
parent::boot(); |
||||||
$activity = Activity::find($data->activity_id); |
|
||||||
$getWorkingHours = UserToProyek::where('user_id', $data->user_id)->where('proyek_id', $activity->proyek_id)->first(); |
static::created(function($data) { |
||||||
|
$activity = Activity::find($data->activity_id); |
||||||
$salary = ($getWorkingHours->standart_rate * $activity->duration) * ($getWorkingHours->max_used / 100); |
$getWorkingHours = UserToProyek::where('user_id', $data->user_id)->where('proyek_id', $activity->proyek_id)->first(); |
||||||
|
|
||||||
if($getWorkingHours->uom_standart_rate == "Hour") |
$salary = ($getWorkingHours->standart_rate * $activity->duration) * ($getWorkingHours->max_used / 100); |
||||||
$salary = ($getWorkingHours->standart_rate * 8) * $activity->duration * ($getWorkingHours->max_used / 100); |
|
||||||
|
if($getWorkingHours->uom_standart_rate == "Hour") |
||||||
$activity->rencana_biaya += $salary; |
$salary = ($getWorkingHours->standart_rate * 8) * $activity->duration * ($getWorkingHours->max_used / 100); |
||||||
$activity->save(); |
|
||||||
}); |
$activity->rencana_biaya += $salary; |
||||||
|
$activity->save(); |
||||||
static::deleted(function($data) { |
}); |
||||||
$activity = Activity::find($data->activity_id); |
|
||||||
|
static::deleted(function($data) { |
||||||
$getWorkingHours = UserToProyek::where('user_id', $data->user_id)->where('proyek_id', $activity->proyek_id)->first(); |
$activity = Activity::find($data->activity_id); |
||||||
$salary = ($getWorkingHours->standart_rate * $activity->duration) * ($getWorkingHours->max_used / 100); |
|
||||||
if($getWorkingHours->uom_standart_rate == "Hour"){ |
$getWorkingHours = UserToProyek::where('user_id', $data->user_id)->where('proyek_id', $activity->proyek_id)->first(); |
||||||
$salary = ($getWorkingHours->standart_rate * 8) * $activity->duration * ($getWorkingHours->max_used / 100); |
$salary = ($getWorkingHours->standart_rate * $activity->duration) * ($getWorkingHours->max_used / 100); |
||||||
} |
if($getWorkingHours->uom_standart_rate == "Hour"){ |
||||||
|
$salary = ($getWorkingHours->standart_rate * 8) * $activity->duration * ($getWorkingHours->max_used / 100); |
||||||
$activity->rencana_biaya -= $salary; |
} |
||||||
if ($activity->rencana_biaya < 0) { |
|
||||||
$activity->rencana_biaya = 0; |
$activity->rencana_biaya -= $salary; |
||||||
} |
if ($activity->rencana_biaya < 0) { |
||||||
$activity->save(); |
$activity->rencana_biaya = 0; |
||||||
}); |
} |
||||||
|
$activity->save(); |
||||||
} |
}); |
||||||
|
|
||||||
} |
} |
||||||
|
|
||||||
|
} |
||||||
|
Loading…
Reference in new issue