proyecto_obj === null) { $this->proyecto_obj = $this->setRelationship(Proyecto::class, 'id', 'proyecto')->one(); } return $this->proyecto_obj; //return $this->belongsTo(Proyecto::class, 'proyecto')->findOne(); } public function fecha(\DateTime $fecha = null) { if ($fecha == null) { return Carbon::parse($this->fecha, $this->container->get('settings')->app->timezone); } $this->fecha = $fecha->format('Y-m-d'); } protected $pagare; public function pagare() { if ($this->pagare == null) { $this->pagare = $this->hasMany(Pagare::class, 'estado_pago', 'numero') ->where('proyecto', $this->proyecto) ->findOne(); } return $this->pagare; } protected $pagares; public function pagares() { if ($this->pagares == null) { $this->pagares = $this->hasMany(Pagare::class, 'estado_pago', 'numero') ->where('proyecto', $this->proyecto) ->findMany(); } return $this->pagares; } public function uf() { if ($this->uf == 0) { $uf = $this->container->get('uf')($this->fecha()); if ($uf->total > 0) { $this->uf = $uf->uf->value; $this->save(); } } return $this->uf; } public function pagado($tipo = 'ufs') { if ($tipo == 'ufs') { return $this->pagado / $this->uf(); } return $this->pagado; } public function fechaPago(\DateTime $fecha = null) { if ($fecha == null) { return Carbon::parse($this->fecha_pagado, $this->container->get('settings')->app->timezone); } $this->fecha_pagado = $fecha->format('Y-m-d'); } public function edit(array $data) { foreach ($data as $column => $value) { if (isset($this->$column) and $this->$column != $value) { $this->$column = $value; } } $this->save(); } }