public static function boot() { parent::boot(); static::creating(function ($model) { if ($model->occupationid == '') { $model->occupationid = null; } if ($model->districtid == '') { $model->districtid = null; } if ($model->amphurid == '') { $model->amphurid = null; } if ($model->addprovinceid == '') { $model->addprovinceid = null; } if ($model->birthdate != null && $model->birthdate != '') { $model->birthdate = date('Y-m-d', strtotime($model->birthdate)); } else { $model->birthdate = null; } //$model->isreal = false; $model->statusexpect = 0; $model->createdby = Auth::user()->id; $model->createddate = date("Y-m-d H:i:s"); $model->modifiedby = Auth::user()->id; $model->modifieddate = date("Y-m-d H:i:s"); }); static::created(function ($model) { Log::create(['employeeid' => Auth::user()->id, 'operation' => 'Add', 'date' => date("Y-m-d H:i:s"), 'model' => class_basename(get_class($model)), 'detail' => $model->toJson()]); }); static::updating(function ($model) { if ($model->occupationid == '') { $model->occupationid = null; } if ($model->districtid == '') { $model->districtid = null; } if ($model->amphurid == '') { $model->amphurid = null; } if ($model->addprovinceid == '') { $model->addprovinceid = null; } if ($model->birthdate != null && $model->birthdate != '') { $model->birthdate = date('Y-m-d', strtotime($model->birthdate)); } else { $model->birthdate = null; } $model->modifiedby = Auth::user()->id; $model->modifieddate = date("Y-m-d H:i:s"); }); static::updated(function ($model) { Log::create(['employeeid' => Auth::user()->id, 'operation' => 'Update', 'date' => date("Y-m-d H:i:s"), 'model' => class_basename(get_class($model)), 'detail' => $model->toJson()]); if ($model->statusexpect != 1) { CustomerExpectation::where('customerid', $model->id)->where('active', true)->update(['active' => false]); } }); static::deleted(function ($model) { Log::create(['employeeid' => Auth::user()->id, 'operation' => 'Delete', 'date' => date("Y-m-d H:i:s"), 'model' => class_basename(get_class($model)), 'detail' => $model->toJson()]); }); }
public static function boot() { parent::boot(); static::creating(function ($model) { $employee = Employee::find($model->salesmanemployeeid); $model->salesmanteamid = $employee->teamid; $model->provinceid = $employee->branch->provinceid; $model->branchid = $employee->branchid; $model->status = 0; if ($model->carobjectivetype == 0) { $model->financingfee = null; $model->transferfee = null; $model->transferoperationfee = null; } else { if ($model->carobjectivetype == 1) { $model->cashpledgeredlabel = null; $model->registerprovinceid = null; $model->registrationtype = null; $model->registrationfee = null; } } if ($model->contractdate == '') { $model->contractdate = null; } $model->createdby = Auth::user()->id; $model->createddate = date("Y-m-d H:i:s"); $model->modifiedby = Auth::user()->id; $model->modifieddate = date("Y-m-d H:i:s"); }); static::created(function ($model) { Log::create(['employeeid' => Auth::user()->id, 'operation' => 'Add', 'date' => date("Y-m-d H:i:s"), 'model' => class_basename(get_class($model)), 'detail' => $model->toJson()]); Customer::where('id', $model->bookingcustomerid)->orWhere('id', $model->buyercustomerid)->update(['statusexpect' => 0]); $bookingcustomerid = $model->bookingcustomerid; $buyercustomerid = $model->buyercustomerid; CustomerExpectation::where('active', true)->where(function ($query) use($bookingcustomerid, $buyercustomerid) { $query->where('customerid', $bookingcustomerid)->orWhere('customerid', $buyercustomerid); })->update(['active' => false]); }); static::updating(function ($model) { if ($model->carobjectivetype == 0) { $model->financingfee = null; $model->transferfee = null; $model->transferoperationfee = null; } else { if ($model->carobjectivetype == 1) { $model->cashpledgeredlabel = null; $model->registerprovinceid = null; $model->registrationtype = null; $model->registrationfee = null; } } if ($model->contractdate == '') { $model->contractdate = null; } $model->carPreemptionGiveaways()->delete(); $model->modifiedby = Auth::user()->id; $model->modifieddate = date("Y-m-d H:i:s"); }); static::updated(function ($model) { Log::create(['employeeid' => Auth::user()->id, 'operation' => 'Update', 'date' => date("Y-m-d H:i:s"), 'model' => class_basename(get_class($model)), 'detail' => $model->toJson()]); }); static::deleted(function ($model) { Log::create(['employeeid' => Auth::user()->id, 'operation' => 'Delete', 'date' => date("Y-m-d H:i:s"), 'model' => class_basename(get_class($model)), 'detail' => $model->toJson()]); }); }