Browse Source

add logger for activity material

pull/3/head
Muhammad Sulaiman Yusuf 3 years ago
parent
commit
c0d7e250d1
  1. 10
      activity_log.txt
  2. 19
      app/Models/AssignMaterial.php

10
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
------

19
app/Models/AssignMaterial.php

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

Loading…
Cancel
Save