Import Precios

This commit is contained in:
Juan Pablo Vial
2025-08-27 19:27:18 -04:00
parent 4e4c0b7648
commit ad64ffa436
19 changed files with 1049 additions and 21 deletions

View File

@ -1,13 +1,16 @@
<?php
namespace Incoviba\Controller\API\Ventas;
use DateTime;
use Exception;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Incoviba\Common\Implement\Exception\EmptyRedis;
use Incoviba\Common\Implement\Exception\EmptyResult;
use Incoviba\Common\Implement\Exception\{EmptyRedis,EmptyResult};
use Psr\Log\LoggerInterface;
use Incoviba\Controller\API\{withJson,emptyBody};
use Incoviba\Service;
use Incoviba\Controller\withRedis;
use Incoviba\Exception\ServiceAction\Create;
use Incoviba\Service;
class Precios
{
@ -51,4 +54,29 @@ class Precios
}
}
}
public function import(ServerRequestInterface $request, ResponseInterface $response,
LoggerInterface $logger,
Service\Venta\Precio $precioService): ResponseInterface
{
$body = $request->getParsedBody();
$projectId = $body['project_id'];
$date = $body['date'];
$file = $request->getUploadedFiles()['file'];
$output = [
'input' => $body,
'total' => 0,
'precios' => [],
'status' => false
];
$date = DateTime::createFromFormat('Y-m-d', $date);
try {
$output['precios'] = $precioService->import($projectId, $date, $file);
$output['total'] = count($output['precios']);
$output['status'] = true;
} catch (Create | Exception $exception) {
$logger->warning($exception);
}
return $this->withJson($response, $output);
}
}