<?php
namespace Incoviba\old\Venta;

use Incoviba\Common\Alias\OldModel as Model;

/**
 *
 * @property int id
 * @property Pago pago
 * @property null|Pago subsidio
 *
 */
class Subsidio extends Model
{
	public function pago()
	{
		return $this->belongs_to(Pago::class, 'pago')->findOne();
	}
	public function subsidio()
	{
		$pago = $this->belongs_to(Pago::class, 'subsidio');
		if ($pago) {
			return $pago->findOne();
		}
		return null;
	}
	public function total($tipo = 'pesos')
	{
		$sum = 0;
		if ($tipo == 'pesos') {
			$sum = $this->pago()->valor;
			if ($this->subsidio != 0) {
				$sum += $this->subsidio()->valor;
			}
		} else {
			$sum = $this->pago()->valor('ufs');
			if ($this->subsidio != 0) {
				$sum += $this->subsidio()->valor('ufs');
			}
		}
		return $sum;
	}
}
?>
