|
|
|
@ -3,6 +3,7 @@
|
|
|
|
|
namespace App\Models; |
|
|
|
|
|
|
|
|
|
use Illuminate\Database\Eloquent\Model; |
|
|
|
|
use App\Models\Activity; |
|
|
|
|
|
|
|
|
|
class UserToActivity extends Model |
|
|
|
|
{ |
|
|
|
@ -17,9 +18,41 @@ class UserToActivity extends Model
|
|
|
|
|
'version_gantt_id', |
|
|
|
|
'role_proyek_id', |
|
|
|
|
'activity_id', |
|
|
|
|
'created_at', |
|
|
|
|
'created_by', |
|
|
|
|
'updated_at', |
|
|
|
|
'created_at', |
|
|
|
|
'created_by', |
|
|
|
|
'updated_at', |
|
|
|
|
'updated_by' |
|
|
|
|
]; |
|
|
|
|
|
|
|
|
|
public static function boot() { |
|
|
|
|
parent::boot(); |
|
|
|
|
|
|
|
|
|
static::created(function($data) { |
|
|
|
|
$activity = Activity::find($data->activity_id); |
|
|
|
|
$getWorkingHours = UserToProyek::where('user_id', $data->user_id)->where('proyek_id', $activity->proyek_id)->first(); |
|
|
|
|
|
|
|
|
|
$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; |
|
|
|
|
$activity->save(); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
static::deleted(function($data) { |
|
|
|
|
$activity = Activity::find($data->activity_id); |
|
|
|
|
|
|
|
|
|
$getWorkingHours = UserToProyek::where('user_id', $data->user_id)->where('proyek_id', $activity->proyek_id)->first(); |
|
|
|
|
$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; |
|
|
|
|
$activity->save(); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|