Import Precios
This commit is contained in:
@ -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);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user