|
|
@ -4,6 +4,7 @@ namespace App\Models; |
|
|
|
|
|
|
|
|
|
|
|
use Illuminate\Database\Eloquent\Model; |
|
|
|
use Illuminate\Database\Eloquent\Model; |
|
|
|
use App\Models\Activity; |
|
|
|
use App\Models\Activity; |
|
|
|
|
|
|
|
use Illuminate\Support\Facades\DB; |
|
|
|
|
|
|
|
|
|
|
|
class UserToActivity extends Model |
|
|
|
class UserToActivity extends Model |
|
|
|
{ |
|
|
|
{ |
|
|
@ -29,35 +30,37 @@ class UserToActivity extends Model |
|
|
|
public static function boot() { |
|
|
|
public static function boot() { |
|
|
|
parent::boot(); |
|
|
|
parent::boot(); |
|
|
|
|
|
|
|
|
|
|
|
static::created(function($data) { |
|
|
|
DB::transaction(function(){ |
|
|
|
$activity = Activity::find($data->activity_id); |
|
|
|
static::created(function($data) { |
|
|
|
$getWorkingHours = UserToProyek::where('user_id', $data->user_id)->where('proyek_id', $activity->proyek_id)->first(); |
|
|
|
$activity = Activity::find($data->activity_id); |
|
|
|
|
|
|
|
$getWorkingHours = UserToProyek::where([['user_id', $data->user_id],['proyek_id', $activity->proyek_id]])->first(); |
|
|
|
|
|
|
|
$salary = 0; |
|
|
|
|
|
|
|
if($getWorkingHours->uom_standart_rate == "Hour") { |
|
|
|
|
|
|
|
$salary = (doubleval($getWorkingHours->standart_rate) * 8) * (int)$activity->duration * ($getWorkingHours->max_used / 100); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
$salary = (doubleval($getWorkingHours->standart_rate) * (int)$activity->duration) * ($getWorkingHours->max_used / 100); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
$activity->rencana_biaya += doubleval($salary); |
|
|
|
|
|
|
|
$activity->save(); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
$salary = ($getWorkingHours->standart_rate * $activity->duration) * ($getWorkingHours->max_used / 100); |
|
|
|
static::deleted(function($data) { |
|
|
|
|
|
|
|
$activity = Activity::find($data->activity_id); |
|
|
|
if($getWorkingHours->uom_standart_rate == "Hour") |
|
|
|
$getWorkingHours = UserToProyek::where([['user_id', $data->user_id],['proyek_id', $activity->proyek_id]])->first(); |
|
|
|
$salary = ($getWorkingHours->standart_rate * 8) * $activity->duration * ($getWorkingHours->max_used / 100); |
|
|
|
$salary = 0; |
|
|
|
|
|
|
|
if($getWorkingHours->uom_standart_rate == "Hour"){ |
|
|
|
$activity->rencana_biaya += $salary; |
|
|
|
$salary = (doubleval($getWorkingHours->standart_rate) * 8) * (int)$activity->duration * ($getWorkingHours->max_used / 100); |
|
|
|
$activity->save(); |
|
|
|
} else { |
|
|
|
}); |
|
|
|
$salary = (doubleval($getWorkingHours->standart_rate) * (int)$activity->duration) * ($getWorkingHours->max_used / 100); |
|
|
|
|
|
|
|
} |
|
|
|
static::deleted(function($data) { |
|
|
|
$activity->rencana_biaya -= doubleval($salary); |
|
|
|
$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; |
|
|
|
|
|
|
|
if ($activity->rencana_biaya < 0) { |
|
|
|
|
|
|
|
$activity->rencana_biaya = 0; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
$activity->save(); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ($activity->rencana_biaya < 0) { |
|
|
|
|
|
|
|
$activity->rencana_biaya = 0; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
$activity->save(); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
}, 5); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|