|
|
@ -5,6 +5,7 @@ namespace App\Models; |
|
|
|
use Illuminate\Database\Eloquent\Model; |
|
|
|
use Illuminate\Database\Eloquent\Model; |
|
|
|
use App\Models\RequestMaterial; |
|
|
|
use App\Models\RequestMaterial; |
|
|
|
use App\Models\Activity; |
|
|
|
use App\Models\Activity; |
|
|
|
|
|
|
|
use Carbon\Carbon; |
|
|
|
|
|
|
|
|
|
|
|
class AssignMaterial extends Model |
|
|
|
class AssignMaterial extends Model |
|
|
|
{ |
|
|
|
{ |
|
|
@ -29,14 +30,32 @@ class AssignMaterial extends Model |
|
|
|
static::created(function($data) { |
|
|
|
static::created(function($data) { |
|
|
|
$activity = Activity::find($data->activity_id); |
|
|
|
$activity = Activity::find($data->activity_id); |
|
|
|
$material = RequestMaterial::where("id", $data->material_id)->first(); |
|
|
|
$material = RequestMaterial::where("id", $data->material_id)->first(); |
|
|
|
|
|
|
|
$old = $activity->rencana_biaya; |
|
|
|
$activity->rencana_biaya += floatval($material->price) * floatval($data->qty_planning); |
|
|
|
$activity->rencana_biaya += floatval($material->price) * floatval($data->qty_planning); |
|
|
|
$activity->save(); |
|
|
|
$activity->save(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$msg = Carbon::now()->toDateTimeString() . ": ".$activity->id." ".$activity->name.PHP_EOL; |
|
|
|
|
|
|
|
$msg .= "Added: ".$material->desc." (".floatval($material->price)." * ".floatval($data->qty_planning)."), Cost plan old: ".$old." | +".$activity->rencana_biayaPHP_EOL; |
|
|
|
|
|
|
|
$msg .= "Data type (".gettype(floatval($material->price))." * ".gettype(floatval($material->qty_planning))."), ".gettype(floatval($old))." | ".gettype(floatval($activity->rencana_biaya)).PHP_EOL; |
|
|
|
|
|
|
|
$msg .= "Data type origin (".gettype($material->price)." * ".gettype($material->qty_planning)."), ".gettype($old)." | ".gettype($activity->rencana_biaya).PHP_EOL; |
|
|
|
|
|
|
|
$msg .= "------".PHP_EOL; |
|
|
|
|
|
|
|
file_put_contents('activity_log.txt', $msg, FILE_APPEND | LOCK_EX); |
|
|
|
|
|
|
|
|
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
static::deleted(function($data) { |
|
|
|
static::deleted(function($data) { |
|
|
|
$activity = Activity::where('id', $data->activity_id)->first(); |
|
|
|
$activity = Activity::where('id', $data->activity_id)->first(); |
|
|
|
|
|
|
|
$old = $activity->rencana_biaya; |
|
|
|
$activity->rencana_biaya -= floatval($data->budget) * floatval($data->qty_planning); |
|
|
|
$activity->rencana_biaya -= floatval($data->budget) * floatval($data->qty_planning); |
|
|
|
$activity->save(); |
|
|
|
$activity->save(); |
|
|
|
|
|
|
|
$material = RequestMaterial::where("id", $data->material_id)->first(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$msg = Carbon::now()->toDateTimeString() . ": ".$activity->id." ".$activity->name.PHP_EOL; |
|
|
|
|
|
|
|
$msg .= "Deleted: ".$material->desc." (".floatval($data->budget)." * ".floatval($data->qty_planning)."), Cost plan old: ".$old." | -".$activity->rencana_biaya.PHP_EOL; |
|
|
|
|
|
|
|
$msg .= "Data type (".gettype(floatval($data->budget))." * ".gettype(floatval($data->qty_planning))."), ".gettype(floatval($old))." | ".gettype(floatval($activity->rencana_biaya)).PHP_EOL; |
|
|
|
|
|
|
|
$msg .= "Data type origin (".gettype($data->budget)." * ".gettype($data->qty_planning)."), ".gettype($old)." | ".gettype($activity->rencana_biaya).PHP_EOL; |
|
|
|
|
|
|
|
$msg .= "------".PHP_EOL; |
|
|
|
|
|
|
|
file_put_contents('activity_log.txt', $msg, FILE_APPEND | LOCK_EX); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|