<?php
namespace Incoviba\Controller\Ventas;

use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Incoviba\Common\Alias\View;
use Incoviba\Exception\ServiceAction\Read;
use Incoviba\Repository;
use Incoviba\Service;

class Pies
{
    public function cuotas(ServerRequestInterface $request, ResponseInterface $response, Service\Venta\Pie $pieService,
                           Repository\Venta $ventaRepository, Repository\Contabilidad\Banco $bancoRepository,
                           Repository\Venta\TipoEstadoPago $tipoEstadoPagoRepository,
                           View $view, int $pie_id): ResponseInterface
    {
        $pie = $pieService->getById($pie_id);
        $venta = $ventaRepository->fetchByPie($pie_id);
        $bancos = $bancoRepository->fetchAll('nombre');
        $estados = $tipoEstadoPagoRepository->fetchAll('descripcion');
        return $view->render($response, 'ventas.pies.cuotas', compact('pie', 'venta', 'bancos', 'estados', 'ventaRepository'));
    }
    public function add(ServerRequestInterface $request, ResponseInterface $response, Service\Venta $ventaService,
                        View $view, int $venta_id): ResponseInterface
    {
        $venta = null;
        try {
            $venta = $ventaService->getById($venta_id);
        } catch (Read) {}
        return $view->render($response, 'ventas.pies.add', compact('venta'));
    }
}
