<?php

class AnfianzadoraProveedorCuentaContable
{
    public static function get($id)
    {
        $cuenta = Yii::app()->getDb()->createCommand('
            SELECT a.descripcion, p.id_cuenta
            FROM prestamos.afianzadora a
            LEFT JOIN proveedor p ON p.id=a.id_proveedor
            WHERE a.id=:id;
        ')->bindValue('id', $id)->queryRow();

        if (is_null($cuenta['id_cuenta'])) {
            throw new Exception("La afianzadora {$cuenta['descripcion']} no tiene cuenta auxiliar definida.");
        }

        return $cuenta['id_cuenta'];
    }
}
