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); }); }