From c0d7e250d1d181a20f46267c27daca275535b44e Mon Sep 17 00:00:00 2001 From: Muhammad Sulaiman Yusuf Date: Mon, 11 Jul 2022 20:23:59 +0700 Subject: [PATCH] add logger for activity material --- activity_log.txt | 10 ++++++++++ app/Models/AssignMaterial.php | 19 +++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100755 activity_log.txt diff --git a/activity_log.txt b/activity_log.txt new file mode 100755 index 0000000..adef32d --- /dev/null +++ b/activity_log.txt @@ -0,0 +1,10 @@ +2022-07-11 20:20:30: Project Plan +Added: (10000 * 5), Cost plan old: 0 | 50000_ +Data type (double * double), double | double +Data type origin (double * NULL), string | double +------ +2022-07-11 20:21:26: Project Plan +Deleted: (10000 * 5), Cost plan old: 50000 | -0_ +Data type (double * double), double | double +Data type origin (double * double), string | double +------ diff --git a/app/Models/AssignMaterial.php b/app/Models/AssignMaterial.php index f7abd89..7060c5c 100644 --- a/app/Models/AssignMaterial.php +++ b/app/Models/AssignMaterial.php @@ -5,6 +5,7 @@ namespace App\Models; use Illuminate\Database\Eloquent\Model; use App\Models\RequestMaterial; use App\Models\Activity; +use Carbon\Carbon; class AssignMaterial extends Model { @@ -29,14 +30,32 @@ class AssignMaterial extends Model static::created(function($data) { $activity = Activity::find($data->activity_id); $material = RequestMaterial::where("id", $data->material_id)->first(); + $old = $activity->rencana_biaya; $activity->rencana_biaya += floatval($material->price) * floatval($data->qty_planning); $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) { $activity = Activity::where('id', $data->activity_id)->first(); + $old = $activity->rencana_biaya; $activity->rencana_biaya -= floatval($data->budget) * floatval($data->qty_planning); $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); }); }