old models
This commit is contained in:
72
src/old/Venta/Cuota.php
Normal file
72
src/old/Venta/Cuota.php
Normal file
@ -0,0 +1,72 @@
|
||||
<?php
|
||||
namespace Incoviba\old\Venta;
|
||||
|
||||
use Incoviba\Common\Alias\OldModel as Model;
|
||||
|
||||
/**
|
||||
*
|
||||
* @property int id
|
||||
* @property int pie
|
||||
* @property date fecha
|
||||
* @property int valor_$
|
||||
* @property int estado
|
||||
* @property string banco
|
||||
* @property date fecha_pago
|
||||
* @property int abonado
|
||||
* @property date fecha_abono
|
||||
* @property float uf
|
||||
* @property Pago pago
|
||||
* @property int numero
|
||||
*
|
||||
*/
|
||||
class Cuota extends Model
|
||||
{
|
||||
public function pago()
|
||||
{
|
||||
return $this->belongs_to(Pago::class, 'pago')->findOne();
|
||||
}
|
||||
public function pie()
|
||||
{
|
||||
return $this->belongs_to(Pie::class, 'pie')->findOne();
|
||||
}
|
||||
public function uf()
|
||||
{
|
||||
if ($this->uf == 0) {
|
||||
$uf = $this->pago()->uf();
|
||||
if ($uf == 1) {
|
||||
$uf = $this->pie()->uf();
|
||||
}
|
||||
$this->uf = $uf;
|
||||
}
|
||||
return $this->uf;
|
||||
}
|
||||
public function valor($tipo = 'pesos')
|
||||
{
|
||||
$valor = $this->pago()->valor;
|
||||
if ($tipo == 'pesos') {
|
||||
return $valor;
|
||||
}
|
||||
$uf = $this->uf();
|
||||
if ($uf == 0) {
|
||||
return 0;
|
||||
}
|
||||
return $valor / $uf;
|
||||
}
|
||||
public function numero()
|
||||
{
|
||||
if ($this->numero == '') {
|
||||
$cuotas = $this->pie()->cuotas('fecha');
|
||||
$n = 0;
|
||||
foreach ($cuotas as $cuota) {
|
||||
$n ++;
|
||||
if ($cuota->id == $this->id) {
|
||||
$this->numero = $n;
|
||||
$this->save();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $this->numero;
|
||||
}
|
||||
}
|
||||
?>
|
||||
Reference in New Issue
Block a user