Files
modelos/src/old/Proyecto/AvanceConstruccion.php
2020-02-18 11:42:49 -03:00

83 lines
2.3 KiB
PHP

<?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
*/
class AvanceConstruccion extends Model {
public static $_table = 'avance_construccion';
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) {
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();
}
}