old models
This commit is contained in:
86
src/old/Proyecto/AvanceConstruccion.php
Normal file
86
src/old/Proyecto/AvanceConstruccion.php
Normal file
@ -0,0 +1,86 @@
|
||||
<?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';
|
||||
|
||||
public function proyecto()
|
||||
{
|
||||
return $this->belongsTo(Proyecto::class, 'proyecto')->findOne();
|
||||
}
|
||||
public function fecha(\DateTime $fecha = null)
|
||||
{
|
||||
if ($fecha == null) {
|
||||
return Carbon::parse($this->fecha, config('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 = 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, config('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();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user