<?php
declare(strict_types=1);
namespace App\Controller\Admin;
use App\DTO\CancelOperacionDTO;
use App\DTO\FinishOperacionDTO;
use App\DTO\SettleOperacionDTO;
use App\Entity\AccionEstado;
use App\Entity\Operacion;
use App\Entity\PlantillaContrato;
use App\Enum\EstadoRelojEnum;
use App\Exception\AsentadaOperacionException;
use App\Exception\BorradoOperacionException;
use App\Exception\CanceladaOperacionException;
use App\Exception\ConfirmadaOperacionException;
use App\Exception\ContractOperacionException;
use App\Exception\DeliveryOperacionException;
use App\Exception\EmptyOperacionException;
use App\Exception\EnTramitacionOperacionException;
use App\Exception\FinalizadaOperacionException;
use App\Exception\RenderWrapperException;
use App\Exception\TramitadaOperacionException;
use App\Service\NumberToWords\NumberToWordsService;
use App\Service\Renders\RenderWrapperService;
use App\UseCase\Operacion\AsentadaUseCase;
use App\UseCase\Operacion\BorradoUseCase;
use App\UseCase\Operacion\CanceladaUseCase;
use App\UseCase\Operacion\CancelarRelojUseCase;
use App\UseCase\Operacion\ConfirmarOperacionUseCase;
use App\UseCase\Operacion\EnTramitacionUseCase;
use App\UseCase\Operacion\FinalizadaUseCase;
use App\UseCase\Operacion\TramitarOperacionUseCase;
use Doctrine\Persistence\ManagerRegistry;
use Exception;
use InvalidArgumentException;
use Sonata\AdminBundle\Controller\CRUDController;
use Symfony\Component\HttpFoundation\File\UploadedFile;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\HttpKernel\KernelInterface;
use Symfony\Component\Routing\Generator\UrlGenerator;
use Vich\UploaderBundle\Storage\StorageInterface;
final class OperacionAdminController extends CRUDController
{
protected $om;
private $cacheDir;
private $tmpDir;
private $locale;
public function __construct(
KernelInterface $kernel,
ManagerRegistry $mr,
private EnTramitacionUseCase $useCaseEnTramitacionOperacion,
private TramitarOperacionUseCase $useCaseTramitarOperacion,
private ConfirmarOperacionUseCase $useCaseConfirmarOperacion,
private AsentadaUseCase $useCaseAsentadaOperacion,
private FinalizadaUseCase $useCaseFinalizadaOperacion,
private CanceladaUseCase $useCaseCanceladaOperacion,
private CancelarRelojUseCase $useCaseCancelarReloj,
private BorradoUseCase $useCaseBorradoOperacion,
private RenderWrapperService $renderWrapper,
private NumberToWordsService $numberToWords,
private StorageInterface $storage,
private RequestStack $requestStack
)
{
$this->om = $mr->getManager();
$this->cacheDir = $kernel->getCacheDir();
$this->tmpDir = $kernel->getCacheDir().DIRECTORY_SEPARATOR."tmp"; //$kernel->getProjectDir()."\\var\\tmp";
$this->locale = $this->requestStack->getCurrentRequest()->getLocale()??$_ENV['LOCALE'];
}
public function editAction(Request $request): Response
{
$responseEdit = parent::editAction($request);
try {
switch ($request->query->get('action'))
{
case 'processed':
return $this->processedAction($request);
case 'contract':
return $this->contractAction($request);
case 'confirmed':
return $this->confirmedAction($request);
case 'settle':
return $this->settleAction($request);
case 'finish':
return $this->finishAction($request);
case 'cancel':
return $this->cancelAction($request);
default:
return $responseEdit;
}
}
catch (EmptyOperacionException $e)
{
$this->addFlash('error', $this->trans($e->getMessage(), [], 'exception'));
}
return $this->redirect($_SERVER['HTTP_REFERER']);
}
public function contractAction(Request $request)
{
try {
$content = '';
$existingObject = $this->assertObjectExists($request, true);
if(!$existingObject) throw new NotFoundHttpException('OPERACION_NOT_EXISTS');
$idioma = mb_strtolower($existingObject->getIdioma()??$this->locale);
$tipo = mb_strtolower($existingObject->getTipo());
$empresa = mb_strtolower($existingObject->getUnidadNegocio()?->getEmpresa()?->getCod());
$templateName = $empresa ? "plantilla_contrato.$empresa.$tipo.$idioma.all.html.twig" : "plantilla_contrato.$tipo.$idioma.all.html.twig";
$template = $this->om->getRepository(PlantillaContrato::class)->findOneByFilename($templateName);
if(!$template) throw new ContractOperacionException("la plantilla [$templateName] no existe");
switch ($request->get('format'))
{
case 'word':
$filename = date('ymd')."-Contrato-$tipo.doc";
$mime = 'application/msword';
$templateName .= 'w';
break;
case 'pdf':
$filename = date('ymd')."-Contrato-$tipo.pdf";
$mime = 'application/pdf';
break;
default:
throw new ContractOperacionException('formato solicitado incorrecto ['.$request->get('format').']');
break;
}
if($template->getTemplate())
{
$filenamePath = $this->storage->resolvePath($template, 'templateFile');
$templateFile = ($filenamePath && file_exists($filenamePath)) ? new UploadedFile($filenamePath, $template->getTemplate(), 'image', null, true) : null;
if(!$templateFile) throw new ContractOperacionException("No se ha podido acceder a la plantilla $filenamePath");
$precioPagarStr = is_null($existingObject?->getPrecioPagar()) ? null : $this->numberToWords->converter(abs($existingObject->getPrecioPagar()), $existingObject->getIdioma());
$content = ($this->renderWrapper)($template->getTemplate(), [
'operacion' => $existingObject,
'operacion.precioPagarStr' => $precioPagarStr,
'firma' => $existingObject?->getFirmante() ,
'segments' => [
'DetalleVenta' => $existingObject->getVenta()?->getDetalle(),
'DetalleCompra' => $existingObject->getCompra()?->getDetalle(),
],
'templateFile' => $templateFile,
'format' => $request->get('format')
]);
$mime = 'application/vnd.oasis.opendocument.text';
}
else if($template->getSource()) {
$content = ($this->renderWrapper)($templateName, [
'operacion' => $existingObject,
'plantilla' => $template,
'source' => $template->getSource(),
'header' => $template->getHeader(),
'footer' => $template->getfooter(),
'format' => $request->get('format')
]);
}
$response = new Response($content);
$response->headers->set('Content-Type', $mime);
$response->headers->set('Content-Disposition', 'attachment; filename="'.$filename.'"');
$response->headers->set('Content-Length', strlen($content??''));
$response->headers->set('Pragma', 'no-cache');
$response->headers->set('Cache-Control', 'no-store, no-cache, must-revalidate, post-check=0, pre-check=0');
$response->headers->set('Expires', '0');
return $response;
}
catch (NotFoundHttpException $e)
{
$this->addFlash('sonata_flash_error', $e->getMessage());
}
catch (ContractOperacionException $e)
{
$this->addFlash('sonata_flash_error', $e->getMessage());
}
catch(RenderWrapperException $e)
{
$this->addFlash('sonata_flash_error', $e->getMessage());
}
catch(Exception $e)
{
$this->addFlash('sonata_flash_error', $e->getMessage());
}
return $this->redirect($_SERVER['HTTP_REFERER']);
}
public function deliveryAction(Request $request)
{
try {
$content = '';
$existingObject = $this->assertObjectExists($request, true);
if(!$existingObject) throw new NotFoundHttpException('OPERACION_NOT_EXISTS');
$detalleVentaReloj = $existingObject->getVenta()->getDetalle()->filter(fn($dv) => $dv->getReloj()->getId() == $request->get('reloj'))->first();
if (!$detalleVentaReloj) throw new DeliveryOperacionException('Detalle de venta no encontrado para el reloj indicado.');
$reloj = $detalleVentaReloj->getReloj();
$idioma = mb_strtolower($existingObject->getIdioma()??$this->locale);
$empresa = mb_strtolower($existingObject->getUnidadNegocio()?->getEmpresa()?->getCod());
$templateName = $empresa ? "plantilla_delivery.$empresa.$idioma.all.html.twig" : "plantilla_delivery.$idioma.all.html.twig";
$template = $this->om->getRepository(PlantillaContrato::class)->findOneByFilename($templateName);
if(!$template) throw new DeliveryOperacionException("la plantilla [$templateName] no existe");
$filename = date('ymd').'-Delivery-'.$reloj->getCodigo().'.docx';
//$mime = 'application/msword';
$mime = 'application/vnd.openxmlformats-officedocument.wordprocessingml.document';
if($template->getTemplate())
{
$filenamePath = $this->storage->resolvePath($template, 'templateFile');
$templateFile = $this->cacheDir. DIRECTORY_SEPARATOR . uniqid('delivery_', true) . '.odt';
if (!is_readable($filenamePath)) {
throw new DeliveryOperacionException("No se puede leer el archivo $filenamePath");
}
if (!is_writable(dirname($templateFile))) {
throw new DeliveryOperacionException("No se puede escribir en el directorio " . dirname($templateFile));
}
if(!copy($filenamePath, $templateFile)) throw new DeliveryOperacionException("No se ha podido cpiar la plantilla $filenamePath a $templateFile");
//$templateFile = ($filenamePath && file_exists($filenamePath)) ? new UploadedFile($filenamePath, $template->getTemplate(), $mime, null, true) : null;
if(!file_exists($templateFile)) throw new DeliveryOperacionException("No se ha podido acceder a la plantilla $filenamePath");
$content = ($this->renderWrapper)($template->getTemplate(), [
'operacion' => $existingObject,
'detallereloj' => $detalleVentaReloj,
'destinatarioEnvio' => $detalleVentaReloj->getVenta()->getDestinatarioEnvio(),
'direccionEnvio' => $detalleVentaReloj->getVenta()->getDireccionEnvio(),
'relojFechaEnvio' => $detalleVentaReloj->getFechaEnvio()?->format('d/m/Y'),
'relojMarca' => $reloj->getMarca(),
'relojFecha' => $reloj->getFecha()?->format('d/m/Y'),
'relojCaja' => $reloj->getCaja() ? 'SI': 'NO',
'relojPapeles' => $reloj->getPapeles() ? 'SI' : 'NO',
'relojGarantia' => $detalleVentaReloj->getGarantiaStr(),
'relojGarantiaFecha' => $detalleVentaReloj->getGarantiaFecha()?->format('d/m/Y'),
'relojRecompra' => $detalleVentaReloj->getRecompraStr(),
'relojRecompraIndice' => $detalleVentaReloj->getRecompraIndice(),
'relojRecompraFechaStr' => $detalleVentaReloj->getRecompraFechaStr(),
'relojRecompraFecha' => $detalleVentaReloj->getRecompraFecha()?->format('d/m/Y'),
'templateFile' => $templateFile,
'format' => 'docx'
]);
//$mime = 'application/vnd.oasis.opendocument.text';
}
else if($template->getSource()) {
$content = ($this->renderWrapper)($templateName, [
'operacion' => $existingObject,
'plantilla' => $template,
'source' => $template->getSource(),
'header' => $template->getHeader(),
'footer' => $template->getfooter(),
'format' => $request->get('format')
]);
}
$response = new Response($content);
$response->headers->set('Content-Type', $mime);
$response->headers->set('Content-Disposition', 'attachment; filename="'.$filename.'"');
$response->headers->set('Content-Length', strlen($content??''));
$response->headers->set('Pragma', 'no-cache');
$response->headers->set('Cache-Control', 'no-store, no-cache, must-revalidate, post-check=0, pre-check=0');
$response->headers->set('Expires', '0');
if (file_exists($templateFile)) {
unlink($templateFile);
}
return $response;
}
catch (NotFoundHttpException $e)
{
$this->addFlash('sonata_flash_error', $e->getMessage());
}
catch (DeliveryOperacionException $e)
{
$this->addFlash('sonata_flash_error', $e->getMessage());
}
catch(RenderWrapperException $e)
{
$this->addFlash('sonata_flash_error', $e->getMessage());
}
catch(Exception $e)
{
$this->addFlash('sonata_flash_error', $e->getMessage());
}
return $this->redirect($_SERVER['HTTP_REFERER']);
}
public function proformaAction(Request $request)
{
try {
$content = '';
$existingObject = $this->assertObjectExists($request, true);
if(!$existingObject) throw new NotFoundHttpException('OPERACION_NOT_EXISTS');
$detalleVentaReloj = $existingObject->getVenta()->getDetalle()->filter(fn($dv) => $dv->getReloj()->getId() == $request->get('reloj'))->first();
$reloj = $detalleVentaReloj->getReloj();
$idioma = mb_strtolower($existingObject->getIdioma()??$this->locale);
$empresa = mb_strtolower($existingObject->getUnidadNegocio()?->getEmpresa()?->getCod());
$templateName = $empresa ? "plantilla_proforma.$empresa.$idioma.all.html.twig" : "plantilla_proforma.$idioma.all.html.twig";
$template = $this->om->getRepository(PlantillaContrato::class)->findOneByFilename($templateName);
if(!$template) throw new DeliveryOperacionException("la plantilla [$templateName] no existe");
$filename = date('ymd').'-Proforma-'.$reloj->getCodigo().'.xls';
$mime = 'application/vnd.ms-excel';
if($template->getTemplate())
{
$filenamePath = $this->storage->resolvePath($template, 'templateFile');
$templateFile = ($filenamePath && file_exists($filenamePath)) ? new UploadedFile($filenamePath, $template->getTemplate(), 'image', null, true) : null;
if(!$templateFile) throw new DeliveryOperacionException("No se ha podido acceder a la plantilla $filenamePath");
//fecha es la del estado en tramitación
//En la descripción, concatena: Marca + espacio + Modelo 1 + espacio + Modelo 2 + coma y espacio + “Ref.” + Referencia 1 + Referencia 2 (sin espacio en medio)
$content = ($this->renderWrapper)($template->getTemplate(), [
'operacion' => $existingObject,
'reloj' => $reloj,
'templateFile' => $templateFile,
'format' => 'excel'
]);
$mime = 'application/vnd.oasis.opendocument.spreadsheet';
}
else if($template->getSource()) {
$content = ($this->renderWrapper)($templateName, [
'operacion' => $existingObject,
'plantilla' => $template,
'source' => $template->getSource(),
'header' => $template->getHeader(),
'footer' => $template->getfooter(),
'format' => $request->get('format')
]);
}
$response = new Response($content);
$response->headers->set('Content-Type', $mime);
$response->headers->set('Content-Disposition', 'attachment; filename="'.$filename.'"');
$response->headers->set('Content-Length', strlen($content??''));
$response->headers->set('Pragma', 'no-cache');
$response->headers->set('Cache-Control', 'no-store, no-cache, must-revalidate, post-check=0, pre-check=0');
$response->headers->set('Expires', '0');
return $response;
}
catch (NotFoundHttpException $e)
{
$this->addFlash('sonata_flash_error', $e->getMessage());
}
catch (DeliveryOperacionException $e)
{
$this->addFlash('sonata_flash_error', $e->getMessage());
}
catch(RenderWrapperException $e)
{
$this->addFlash('sonata_flash_error', $e->getMessage());
}
catch(Exception $e)
{
$this->addFlash('sonata_flash_error', $e->getMessage());
}
return $this->redirect($_SERVER['HTTP_REFERER']);
}
public function uploadContractAction(Request $request = null) : Response
{
try
{
$existingObject = $this->assertObjectExists($request, true);
if(!$existingObject) throw new NotFoundHttpException('OPERACION_NOT_EXISTS');
if(!count($_FILES)) throw new InvalidArgumentException('ko.upload_contract.not_found_file');
$filePath = @$_FILES['UPLOAD_CONTRACT']['tmp_name'];//$this->kernel->getProjectDir().DIRECTORY_SEPARATOR."templates/report/$fileName";
$contractSigned = @$_FILES['UPLOAD_CONTRACT']['name'];
if(!$filePath) throw new InvalidArgumentException('ko.upload_contract.incorrect_file');
if(!$this->isValidFileContract(@$_FILES['UPLOAD_CONTRACT']['type'])) throw new InvalidArgumentException('ko.upload_contract.incorrect_file_type');
$contractSignedFile = new UploadedFile($filePath, $contractSigned, 'application/pdf', null, true);
$existingObject->setContractSignedFile($contractSignedFile);
$this->om->persist($existingObject);
$this->om->flush();
$this->addFlash('sonata_flash_success', $this->trans('ok.upload_contract', [], 'flash'));
}
catch (NotFoundHttpException $e)
{
$this->addFlash('sonata_flash_error', $e->getMessage());
}
catch (InvalidArgumentException $e)
{
$this->addFlash('sonata_flash_error', $this->trans($e->getMessage(), [], 'flash'));
}
catch (Exception $e)
{
$this->addFlash('sonata_flash_error', $this->trans('ko.upload_contract', ['%error%' => $e->getMessage()], 'flash'));
}
catch (Throwable $e)
{
$this->addFlash('sonata_flash_error', $this->trans('ko.upload_contract', ['%error%' => $e->getMessage()], 'flash'));
}
finally
{
return $this->redirect($_SERVER['HTTP_REFERER']);
}
}
public function cardAction()
{
}
public function sendAction()
{
}
public function inProcessAction(Request $request)
{
try
{
$id = $request->get($this->admin->getIdParameter());
$object = $this->admin->getObject($id);
if (!$object) throw new NotFoundHttpException('OPERACION_NOT_EXISTS');
$this->useCaseEnTramitacionOperacion->tramitacion($object);
$this->addFlash('sonata_flash_success', $this->trans('operacion.in_processed.ok', [], 'flash'));
return $this->redirect($this->generateUrl('admin_app_operacion_edit', ['id' => $object->getId()], UrlGenerator::ABSOLUTE_URL));
}
catch (NotFoundHttpException $e)
{
$this->addFlash('sonata_flash_error', $e->getMessage());
}
catch (EnTramitacionOperacionException $e)
{
$this->addFlash('sonata_flash_error', $this->trans($e->getMessage(), [], 'flash'));
}
return $this->redirect($_SERVER['HTTP_REFERER']);
}
public function processedAction(Request $request)
{
try
{
$id = $request->get($this->admin->getIdParameter());
$object = $this->admin->getObject($id);
if (!$object instanceof Operacion) throw new NotFoundHttpException('OPERACION_NOT_EXISTS');
// 🔐 Control de autorización
// $this->denyAccessUnlessGranted(OperacionVoter::OPERACION_TRAMITAR, $object);
$this->useCaseTramitarOperacion->execute($object, $request->query->has('deleteSold'));
$this->addFlash('sonata_flash_success', $this->trans('operacion.processed.ok', [], 'flash'));
return $this->redirectToRoute('admin_app_operacion_edit', ['id' => $object->getId()]);
}
catch (NotFoundHttpException | TramitadaOperacionException $e)
{
$this->addFlash('sonata_flash_error', $this->trans($e->getMessage(), [], 'flash'));
}
return $this->redirect($_SERVER['HTTP_REFERER']);
}
public function confirmedAction(Request $request)
{
try
{
$id = $request->get($this->admin->getIdParameter());
$object = $this->admin->getObject($id);
if (!$object instanceof Operacion) throw new NotFoundHttpException('OPERACION_NOT_EXISTS');
// // 🔒 Verificación de permisos (voter)
// $this->denyAccessUnlessGranted('OPERACION_CONFIRMAR', $object);
$this->useCaseConfirmarOperacion->execute($object);
$this->addFlash('sonata_flash_success', $this->trans('operacion.confirmed.ok', [], 'flash'));
return $this->redirectToRoute('admin_app_operacion_edit', ['id' => $object->getId()]);
}
catch (NotFoundHttpException | ConfirmadaOperacionException $e)
{
$this->addFlash('sonata_flash_error', $this->trans($e->getMessage(), [], 'flash'));
}
return $this->redirect($_SERVER['HTTP_REFERER']);
}
// controlar que sea el admin
public function settleAction(Request $request)
{
try
{
$id = $request->get($this->admin->getIdParameter());
$object = $this->admin->getObject($id);
$dto = SettleOperacionDTO::fromRequest($request);
if (!$object) throw new NotFoundHttpException('OPERACION_NOT_EXISTS');
$this->useCaseAsentadaOperacion->execute($object, $dto);
$this->addFlash('sonata_flash_success', $this->trans('operacion.settled.ok', [], 'flash'));
return $this->redirectToRoute('admin_app_operacion_edit', ['id' => $object->getId()]);
}
catch (NotFoundHttpException $e)
{
$this->addFlash('sonata_flash_error', $e->getMessage());
}
catch (AsentadaOperacionException $e)
{
$this->addFlash('sonata_flash_error', $this->trans($e->getMessage(), [], 'flash'));
}
return $this->redirect($_SERVER['HTTP_REFERER']);
}
public function finishAction(Request $request)
{
try
{
$id = $request->get($this->admin->getIdParameter());
$object = $this->admin->getObject($id);
$dto = FinishOperacionDTO::fromRequest($request);
if (!$object) throw new NotFoundHttpException('OPERACION_NOT_EXISTS');
$this->useCaseFinalizadaOperacion->finalizada($object, $dto);
$this->addFlash('sonata_flash_success', $this->trans('operacion.finish.ok', [], 'flash'));
return $this->redirect($this->generateUrl('admin_app_operacion_edit', ['id' => $object->getId()], UrlGenerator::ABSOLUTE_URL));
}
catch (NotFoundHttpException $e)
{
$this->addFlash('sonata_flash_error', $e->getMessage());
}
catch (FinalizadaOperacionException $e)
{
$this->addFlash('sonata_flash_error', $this->trans($e->getMessage(), [], 'flash'));
}
return $this->redirect($_SERVER['HTTP_REFERER']);
}
public function cancelRelojAction(Request $request)
{
$error = [];
try {
$existingObject = $this->assertObjectExists($request, true);
if(!$existingObject) throw new NotFoundHttpException('OPERACION_NOT_EXISTS');
if(!$request->get("fechaCancelacion")) throw new InvalidArgumentException('ko.operacion.cancel_reloj.not_found_date_cancel');
$fechaCancelacion = date_create_from_format('d-m-Y', $request->get("fechaCancelacion"));
$detalleCompraReloj = $existingObject->getCompra()->getDetalle()->filter(fn($dv) => $dv->getReloj()?->getId() == $request->get('reloj'))->first();
$this->useCaseCancelarReloj->__invoke($detalleCompraReloj, $fechaCancelacion);
if($this->isXmlHttpRequest($request))
{
return $this->handleXmlHttpRequestSuccessResponse($request, $existingObject);
}
$this->addFlash('sonata_flash_success', $this->trans('operacion.cancelar_reloj.ok', [ '%reloj%' => $detalleCompraReloj->getReloj() ], 'flash'));
return $this->redirect($this->generateUrl('admin_app_operacion_edit', ['id' => $existingObject->getId()], UrlGenerator::ABSOLUTE_URL));
}
catch (CanceladaOperacionException | InvalidArgumentException | NotFoundHttpException $e)
{
$errorTrans = $this->trans($e->getMessage(), [], 'flash');
$this->addFlash('sonata_flash_error', $errorTrans);
$error = ['error' => $errorTrans];
}
if($this->isXmlHttpRequest($request))
{
return $this->json( $error, Response::HTTP_BAD_REQUEST);
}
return $this->redirect($_SERVER['HTTP_REFERER']);
}
// controlar que sea el admin
public function cancelAction(Request $request)
{
try
{
$id = $request->get($this->admin->getIdParameter());
$object = $this->admin->getObject($id);
$dto = CancelOperacionDTO::fromRequest($request);
if (!$object) throw new NotFoundHttpException('OPERACION_NOT_EXISTS');
$this->useCaseCanceladaOperacion->execute($object, $dto);
$this->addFlash('sonata_flash_success', $this->trans('operacion.canceled.ok', [], 'flash'));
return $this->redirect($this->generateUrl('admin_app_operacion_edit', ['id' => $object->getId()], UrlGenerator::ABSOLUTE_URL));
}
catch (NotFoundHttpException $e)
{
$this->addFlash('sonata_flash_error', $e->getMessage());
}
catch (CanceladaOperacionException $e)
{
$this->addFlash('sonata_flash_error', $this->trans($e->getMessage(), [], 'flash'));
}
return $this->redirect($_SERVER['HTTP_REFERER']);
}
public function deleteAction(Request $request): Response
{
try
{
$id = $request->get($this->admin->getIdParameter());
$object = $this->admin->getObject($id);
if (!$object) throw new NotFoundHttpException('OPERACION_NOT_EXISTS');
$valoracion = $object->getValoracion();
$this->useCaseBorradoOperacion->borrado($object);
$this->addFlash('sonata_flash_success', $this->trans('operacion.borrada.ok', [], 'flash'));
return $this->redirect($this->generateUrl('admin_app_valoracion_edit', ['id' => $valoracion->getId()], UrlGenerator::ABSOLUTE_URL));
}
catch (NotFoundHttpException $e)
{
$this->addFlash('sonata_flash_error', $e->getMessage());
}
catch (BorradoOperacionException $e)
{
$this->addFlash('sonata_flash_error', $this->trans($e->getMessage(), [], 'flash'));
}
return $this->redirect($_SERVER['HTTP_REFERER']);
}
public function switchOperacionAction()
{
}
public function controlUnconfirmedAction(Request $request)
{
$relojesVendidos = [];
$existingObject = $this->assertObjectExists($request, true);
foreach ($existingObject->getVenta()->getDetalle() as $detalle)
{
if(($reloj = $detalle->getReloj())->getPromociones()->getAcciones()->filter(fn($accion) => $accion instanceof AccionEstado && $accion->getEstado()->getKey() === EstadoRelojEnum::ESTADO_VENDIDO)->count())
{
$relojesVendidos[] = $reloj->getIDPerseo() . ' ' . $reloj->getMarca() . ' ' . $reloj->getModelo1();
}
}
return $this->renderJson([
'relojesVendidos' => count($relojesVendidos),
'relojes' => $relojesVendidos
]);
}
private function normalizePath($path) {
$parts = explode(DIRECTORY_SEPARATOR, $path);
$absolutes = [];
foreach ($parts as $part) {
if ('.' == $part) {
continue;
}
if ('..' == $part) {
array_pop($absolutes);
} else {
$absolutes[] = $part;
}
}
return implode(DIRECTORY_SEPARATOR, $absolutes);
}
private function isValidFileContract(string $type) : bool
{
$valid = false;
switch ($type)
{
case 'application/pdf':
$valid = true;
break;
default:
break;
}
return $valid;
}
}