diff --git a/Controller/Modelo347.php b/Controller/Modelo347.php index 5f3cea4..c921e2b 100644 --- a/Controller/Modelo347.php +++ b/Controller/Modelo347.php @@ -24,6 +24,7 @@ use FacturaScripts\Core\DataSrc\Empresas; use FacturaScripts\Core\Tools; use FacturaScripts\Core\Where; +use FacturaScripts\Core\WorkQueue; use FacturaScripts\Dinamic\Lib\Export\XLSExport; use FacturaScripts\Dinamic\Model\Cliente; use FacturaScripts\Dinamic\Model\Cuenta; @@ -131,7 +132,76 @@ public function privateCore(&$response, $user, $permissions) case 'download-txt': $this->downloadTxtAction(); break; + + case 'send-emails': + $this->sendEmailsAction(); + break; + } + } + + protected function sendEmailsAction(): void + { + $sendtype = $this->request->request->get('sendtype', 'both'); + + if (in_array($sendtype, ['customers', 'both']) && false === empty($this->customersData)) { + $data = []; + $sentEmails = []; + foreach ($this->customersData as $codcliente => $row) { + $cliente = new Cliente(); + if (false === $cliente->load($codcliente)) { + continue; + } + $email = $cliente->email; + if (empty($email) || isset($sentEmails[$email])) { + continue; + } + $sentEmails[$email] = true; + $data[] = [ + 'email' => $email, + 'name' => $row['cliente'], + 'cifnif' => $row['cifnif'], + 't1' => $row['t1'], + 't2' => $row['t2'], + 't3' => $row['t3'], + 't4' => $row['t4'], + 'total' => $row['total'], + ]; + } + if (false === empty($data)) { + WorkQueue::send('Modelo347.SendCustomersEmails', $this->codejercicio, ['data' => $data, 'amount' => $this->amount]); + } } + + if (in_array($sendtype, ['suppliers', 'both']) && false === empty($this->suppliersData)) { + $data = []; + $sentEmails = []; + foreach ($this->suppliersData as $codproveedor => $row) { + $proveedor = new Proveedor(); + if (false === $proveedor->load($codproveedor)) { + continue; + } + $email = $proveedor->email; + if (empty($email) || isset($sentEmails[$email])) { + continue; + } + $sentEmails[$email] = true; + $data[] = [ + 'email' => $email, + 'name' => $row['proveedor'], + 'cifnif' => $row['cifnif'], + 't1' => $row['t1'], + 't2' => $row['t2'], + 't3' => $row['t3'], + 't4' => $row['t4'], + 'total' => $row['total'], + ]; + } + if (false === empty($data)) { + WorkQueue::send('Modelo347.SendSuppliersEmails', $this->codejercicio, ['data' => $data, 'amount' => $this->amount]); + } + } + + Tools::log()->info('347-emails-queued'); } protected function checkAddress(array $data, string $type): void diff --git a/Init.php b/Init.php index aa4353e..ea747c4 100644 --- a/Init.php +++ b/Init.php @@ -1,7 +1,7 @@ + * Copyright (C) 2017-2026 Carlos Garcia Gomez * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as @@ -22,6 +22,7 @@ use FacturaScripts\Core\Lib\AjaxForms\PurchasesHeaderHTML; use FacturaScripts\Core\Lib\AjaxForms\SalesHeaderHTML; use FacturaScripts\Core\Template\InitClass; +use FacturaScripts\Core\WorkQueue; use FacturaScripts\Dinamic\Model\FacturaCliente; use FacturaScripts\Dinamic\Model\FacturaProveedor; @@ -43,6 +44,10 @@ public function init(): void // mods PurchasesHeaderHTML::addMod(new Mod\PurchasesHeaderHTMLMod()); SalesHeaderHTML::addMod(new Mod\SalesHeaderHTMLMod()); + + // workers + WorkQueue::addWorker('Modelo347CustomersEmailWorker', 'Modelo347.SendCustomersEmails'); + WorkQueue::addWorker('Modelo347SuppliersEmailWorker', 'Modelo347.SendSuppliersEmails'); } public function uninstall(): void diff --git a/Translation/es_ES.json b/Translation/es_ES.json index d36dfea..6501573 100644 --- a/Translation/es_ES.json +++ b/Translation/es_ES.json @@ -1,6 +1,21 @@ { + "347-confirm-send": "Enviar emails del Modelo 347", + "347-confirm-send-body": "Se enviarán emails a los destinatarios del Modelo 347 con el resumen de operaciones del ejercicio.", + "347-email-amounts-title": "IMPORTE TRIMESTRAL OPERACIONES", + "347-email-cifnif-line": "DNI\/NIF: %cifnif%<\/strong>", + "347-email-footer": "De no recibir disconformidad por su parte antes del 20 de febrero<\/strong>, consideraremos que nuestra cifra es correcta.\n\nSin otro particular, les saludamos cordialmente.", + "347-email-greeting": "Muy Sres. Nuestros:", + "347-email-included": "Hallándose Vds. incluidos en la relación que hacemos referencia, les informamos que el importe a declarar por este concepto es:", + "347-email-intro": "El próximo mes de febrero presentaremos relación de todos nuestros clientes cuya facturación haya superado la cantidad de %amount%<\/strong> durante el año %year%<\/strong>.", + "347-email-name-line": "NOMBRE\/RAZÓN SOCIAL: %name%<\/strong>", + "347-email-subject": "Modelo 347 - Ejercicio %year%", + "347-email-title": "DECLARACIÓN ANUAL DE OPERACIONES CON TERCERAS PERSONAS.", + "347-send-email": "Enviar Email", + "347-emails-queued": "Los emails del Modelo 347 han sido encolados para su envío.", + "347-emails-sent": "Modelo 347: enviados %sent% emails, sin email: %noEmail%.", "347-no-country": "El %type% %name% con cif\/nif %cifnif% no tiene país y es obligatorio", "347-no-data": "Sin resultados", + "347-no-email": "El destinatario %name% con cif\/nif %cifnif% no tiene email y no se le puede notificar.", "347-no-province": "El %type% %name% con cif\/nif %cifnif% no tiene provincia y es obligatorio", "company-admin-no-data": "La empresa %company% no tiene administrador y es obligatorio", "company-phone-no-data": "La empresa %company% no tiene teléfono y es obligatorio", diff --git a/View/Modelo347.html.twig b/View/Modelo347.html.twig index 605b575..04b9f21 100644 --- a/View/Modelo347.html.twig +++ b/View/Modelo347.html.twig @@ -9,6 +9,22 @@ document.forms['modelo347'].submit(); } + function confirmSendEmails() { + const sendtype = document.getElementById('emailSendType').value; + const form = document.forms['modelo347']; + const actionInput = document.createElement('input'); + actionInput.type = 'hidden'; + actionInput.name = 'action'; + actionInput.value = 'send-emails'; + form.appendChild(actionInput); + const sendtypeInput = document.createElement('input'); + sendtypeInput.type = 'hidden'; + sendtypeInput.name = 'sendtype'; + sendtypeInput.value = sendtype; + form.appendChild(sendtypeInput); + form.submit(); + } + function toggleDeclarationType() { const type = document.getElementById('declarationtype').value; const prevGroup = document.getElementById('justificante-anterior-group'); @@ -135,6 +151,10 @@ {# Buttons #}
+
+ +