Files
modelos/src/old/Proyecto/AvanceConstruccion.php

83 lines
2.3 KiB
PHP
Raw Normal View History

2019-12-23 18:01:23 -03:00
<?php
namespace Incoviba\old\Proyecto;
use Carbon\Carbon;
use Incoviba\Common\Alias\OldModel as Model;
/**
* @property int $id
* @property int $proyecto
* @property \DateTime $fecha
* @property double $avance
* @property double $estado_pago
* @property int $pagado
* @property double $uf
* @property \DateTime $fecha_pagado
*/
2020-02-18 11:42:49 -03:00
class AvanceConstruccion extends Model {
2019-12-23 18:01:23 -03:00
public static $_table = 'avance_construccion';
2020-02-18 11:42:49 -03:00
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();
2019-12-23 18:01:23 -03:00
}
2020-02-18 11:42:49 -03:00
public function fecha(\DateTime $fecha = null) {
2019-12-23 18:01:23 -03:00
if ($fecha == null) {
2020-01-07 12:25:52 -03:00
return Carbon::parse($this->fecha, $this->container->get('settings')->app->timezone);
2019-12-23 18:01:23 -03:00
}
$this->fecha = $fecha->format('Y-m-d');
}
protected $pagare;
2020-02-18 11:42:49 -03:00
public function pagare() {
2019-12-23 18:01:23 -03:00
if ($this->pagare == null) {
$this->pagare = $this->hasMany(Pagare::class, 'estado_pago', 'numero')
->where('proyecto', $this->proyecto)
->findOne();
}
return $this->pagare;
}
protected $pagares;
2020-02-18 11:42:49 -03:00
public function pagares() {
2019-12-23 18:01:23 -03:00
if ($this->pagares == null) {
$this->pagares = $this->hasMany(Pagare::class, 'estado_pago', 'numero')
->where('proyecto', $this->proyecto)
->findMany();
}
return $this->pagares;
}
2020-02-18 11:42:49 -03:00
public function uf() {
2019-12-23 18:01:23 -03:00
if ($this->uf == 0) {
2020-01-07 12:25:52 -03:00
$uf = $this->container->get('uf')($this->fecha());
2019-12-23 18:01:23 -03:00
if ($uf->total > 0) {
$this->uf = $uf->uf->value;
$this->save();
}
}
return $this->uf;
}
2020-02-18 11:42:49 -03:00
public function pagado($tipo = 'ufs') {
2019-12-23 18:01:23 -03:00
if ($tipo == 'ufs') {
return $this->pagado / $this->uf();
}
return $this->pagado;
}
2020-02-18 11:42:49 -03:00
public function fechaPago(\DateTime $fecha = null) {
2019-12-23 18:01:23 -03:00
if ($fecha == null) {
2020-01-07 12:25:52 -03:00
return Carbon::parse($this->fecha_pagado, $this->container->get('settings')->app->timezone);
2019-12-23 18:01:23 -03:00
}
$this->fecha_pagado = $fecha->format('Y-m-d');
}
2020-02-18 11:42:49 -03:00
public function edit(array $data) {
2019-12-23 18:01:23 -03:00
foreach ($data as $column => $value) {
if (isset($this->$column) and $this->$column != $value) {
$this->$column = $value;
}
}
$this->save();
}
}