Files
oficial/app/src/Controller/API/Ventas/Facturas.php

39 lines
1.2 KiB
PHP
Raw Normal View History

2024-06-18 22:41:03 -04:00
<?php
namespace Incoviba\Controller\API\Ventas;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Message\ResponseInterface;
use Incoviba\Controller\API\withJson;
use Incoviba\Common\Ideal\Controller;
use Incoviba\Common\Implement;
use Incoviba\Service;
class Facturas extends Controller
{
use withJson;
public function add(ServerRequestInterface $request, ResponseInterface $response, Service\Venta\Factura $facturaService): ResponseInterface
{
$data = $request->getParsedBody();
$output = [
'input' => $data,
'factura' => null,
2025-01-17 00:04:34 -03:00
'success' => false
2024-06-18 22:41:03 -04:00
];
try {
2025-01-17 16:56:03 -03:00
foreach (['cliente', 'unidades', 'detalle', 'total', 'uf'] as $key) {
if (!isset($data[$key]) or empty($data[$key])) {
continue;
}
$data[$key] = json_decode($data[$key], true);
}
2024-06-18 22:41:03 -04:00
$output['factura'] = $facturaService->add($data);
2025-01-17 00:04:34 -03:00
$output['success'] = true;
2024-06-18 22:41:03 -04:00
} catch (Implement\Exception\EmptyResult) {
$output['error'] = 'No se pudo agregar la factura';
return $this->withJson($response, $output, 400);
}
return $this->withJson($response, $output);
}
}