Files
contabilidad/api/src/Transaccion.php

51 lines
1.4 KiB
PHP
Raw Normal View History

2021-07-30 16:38:09 -04:00
<?php
namespace Contabilidad;
2021-12-06 22:10:41 -03:00
use DateTime;
2021-07-30 16:38:09 -04:00
use Carbon\Carbon;
use ProVM\Common\Alias\Model;
/**
* @property int $id
2021-11-01 11:00:59 -03:00
* @property Cuenta $debito_id
* @property Cuenta $credito_id
2021-12-06 22:10:41 -03:00
* @property DateTime $fecha
2021-07-30 16:38:09 -04:00
* @property string $glosa
* @property string $detalle
* @property double $valor
*/
class Transaccion extends Model {
public static $_table = 'transacciones';
2021-11-01 11:00:59 -03:00
protected static $fields = ['debito_id', 'credito_id', 'fecha', 'glosa', 'detalle', 'valor'];
2021-07-30 16:38:09 -04:00
2021-11-01 11:00:59 -03:00
protected $debito;
public function debito() {
if ($this->debito === null) {
$this->debito = $this->childOf(Cuenta::class, [Model::SELF_KEY => 'debito_id']);
2021-07-30 16:38:09 -04:00
}
2021-11-01 11:00:59 -03:00
return $this->debito;
2021-07-30 16:38:09 -04:00
}
2021-11-01 11:00:59 -03:00
protected $credito;
public function credito() {
if ($this->credito === null) {
$this->credito = $this->childOf(Cuenta::class, [Model::SELF_KEY => 'credito_id']);
2021-07-30 16:38:09 -04:00
}
2021-11-01 11:00:59 -03:00
return $this->credito;
2021-07-30 16:38:09 -04:00
}
2021-12-06 22:10:41 -03:00
public function fecha(DateTime $fecha = null) {
2021-07-30 16:38:09 -04:00
if ($fecha === null) {
return Carbon::parse($this->fecha);
}
$this->fecha = $fecha->format('Y-m-d');
}
public function toArray(): array {
$arr = parent::toArray();
2021-11-01 11:00:59 -03:00
$arr['debito'] = $this->debito()->toArray();
$arr['credito'] = $this->credito()->toArray();
2021-07-30 16:38:09 -04:00
$arr['fechaFormateada'] = $this->fecha()->format('d-m-Y');
2021-12-06 22:10:41 -03:00
$arr['valorFormateado'] = $this->debito()->moneda()->format($this->valor);
2021-07-30 16:38:09 -04:00
return $arr;
}
}