<?php
namespace Incoviba\Controller\API\Contabilidad;

use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Log\LoggerInterface;
use Incoviba\Controller\API\withJson;
use Incoviba\Service;

class Tesoreria
{
    use withJson;

    public function import(ServerRequestInterface $request, ResponseInterface $response, LoggerInterface $logger,
                           Service\Contabilidad\Informe\Tesoreria $tesoreriaService): ResponseInterface
    {
        $files = $request->getUploadedFiles();
        $output = [];
        foreach ($files['file'] as $file) {
            if ($file->getError() !== UPLOAD_ERR_OK) {
                continue;
            }
            $data = $tesoreriaService->getInput()->loadFromExcel($file);
            $tesoreriaService->getInput()->load($data);
            $output['informes'] []= $data;
        }
        return $this->withJson($response, $output);
    }
}
