Optimizaciones y funciones
This commit is contained in:
@ -14,24 +14,25 @@ use Incoviba\Common\Alias\OldModel as Model;
|
||||
* @property double $uf
|
||||
* @property \DateTime $fecha_pagado
|
||||
*/
|
||||
class AvanceConstruccion extends Model
|
||||
{
|
||||
class AvanceConstruccion extends Model {
|
||||
public static $_table = 'avance_construccion';
|
||||
|
||||
public function proyecto()
|
||||
{
|
||||
return $this->belongsTo(Proyecto::class, 'proyecto')->findOne();
|
||||
protected $proyecto_obj;
|
||||
public function proyecto() {
|
||||
if ($this->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)
|
||||
{
|
||||
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()
|
||||
{
|
||||
public function pagare() {
|
||||
if ($this->pagare == null) {
|
||||
$this->pagare = $this->hasMany(Pagare::class, 'estado_pago', 'numero')
|
||||
->where('proyecto', $this->proyecto)
|
||||
@ -40,8 +41,7 @@ class AvanceConstruccion extends Model
|
||||
return $this->pagare;
|
||||
}
|
||||
protected $pagares;
|
||||
public function pagares()
|
||||
{
|
||||
public function pagares() {
|
||||
if ($this->pagares == null) {
|
||||
$this->pagares = $this->hasMany(Pagare::class, 'estado_pago', 'numero')
|
||||
->where('proyecto', $this->proyecto)
|
||||
@ -49,8 +49,7 @@ class AvanceConstruccion extends Model
|
||||
}
|
||||
return $this->pagares;
|
||||
}
|
||||
public function uf()
|
||||
{
|
||||
public function uf() {
|
||||
if ($this->uf == 0) {
|
||||
$uf = $this->container->get('uf')($this->fecha());
|
||||
if ($uf->total > 0) {
|
||||
@ -60,22 +59,19 @@ class AvanceConstruccion extends Model
|
||||
}
|
||||
return $this->uf;
|
||||
}
|
||||
public function pagado($tipo = 'ufs')
|
||||
{
|
||||
public function pagado($tipo = 'ufs') {
|
||||
if ($tipo == 'ufs') {
|
||||
return $this->pagado / $this->uf();
|
||||
}
|
||||
return $this->pagado;
|
||||
}
|
||||
public function fechaPago(\DateTime $fecha = null)
|
||||
{
|
||||
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)
|
||||
{
|
||||
public function edit(array $data) {
|
||||
foreach ($data as $column => $value) {
|
||||
if (isset($this->$column) and $this->$column != $value) {
|
||||
$this->$column = $value;
|
||||
|
Reference in New Issue
Block a user