mirror of
https://github.com/devcode-it/openstamanager.git
synced 2025-06-05 22:09:38 +02:00
Aggiunto invio FE tramite hook
This commit is contained in:
@@ -26,8 +26,8 @@ class BackupHook extends Manager
|
|||||||
|
|
||||||
public function response()
|
public function response()
|
||||||
{
|
{
|
||||||
$show = boolval(setting('Backup automatico'));
|
$show = boolval(setting('Backup automatico')) && !Backup::isDailyComplete();
|
||||||
$message = $show && !Backup::isDailyComplete() ? tr('Backup in corso...') : tr('Backup automatico completato!');
|
$message = $show ? tr('Backup in corso...') : tr('Backup automatico completato!');
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'icon' => 'fa fa-file-o text-success',
|
'icon' => 'fa fa-file-o text-success',
|
||||||
|
@@ -80,8 +80,10 @@ class EmailHook extends Manager
|
|||||||
$current = Mail::whereDate('sent_at', '>', $yesterday)
|
$current = Mail::whereDate('sent_at', '>', $yesterday)
|
||||||
->where('created_by', $user->id)
|
->where('created_by', $user->id)
|
||||||
->count();
|
->count();
|
||||||
$total = Mail::whereDate('sent_at', '>', $yesterday)
|
$total = Mail::where(function ($query) use ($yesterday) {
|
||||||
->orWhereNull('sent_at')
|
$query->whereDate('sent_at', '>', $yesterday)
|
||||||
|
->orWhereNull('sent_at');
|
||||||
|
})
|
||||||
->where('created_by', $user->id)
|
->where('created_by', $user->id)
|
||||||
->count();
|
->count();
|
||||||
|
|
||||||
@@ -91,7 +93,7 @@ class EmailHook extends Manager
|
|||||||
return [
|
return [
|
||||||
'icon' => 'fa fa-envelope text-info',
|
'icon' => 'fa fa-envelope text-info',
|
||||||
'message' => $message,
|
'message' => $message,
|
||||||
'show' => true,
|
'show' => ($total != $current),
|
||||||
'progress' => [
|
'progress' => [
|
||||||
'current' => $current,
|
'current' => $current,
|
||||||
'total' => $total,
|
'total' => $total,
|
||||||
|
@@ -4,6 +4,7 @@ include_once __DIR__.'/../../core.php';
|
|||||||
|
|
||||||
use Modules\Fatture\Fattura;
|
use Modules\Fatture\Fattura;
|
||||||
use Plugins\ExportFE\FatturaElettronica;
|
use Plugins\ExportFE\FatturaElettronica;
|
||||||
|
use Plugins\ExportFE\Interaction;
|
||||||
use Util\Zip;
|
use Util\Zip;
|
||||||
|
|
||||||
switch (post('op')) {
|
switch (post('op')) {
|
||||||
@@ -89,6 +90,23 @@ switch (post('op')) {
|
|||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 'hook-send':
|
||||||
|
foreach ($id_records as $id) {
|
||||||
|
$fattura = Fattura::find($id);
|
||||||
|
|
||||||
|
$fe = new \Plugins\ExportFE\FatturaElettronica($fattura->id);
|
||||||
|
if ($fe->isGenerated() && $fattura->codice_stato_fe == 'GEN') {
|
||||||
|
$fattura->codice_stato_fe = 'QUEUE';
|
||||||
|
$fattura->data_stato_fe = date('Y-m-d H:i:s');
|
||||||
|
$fattura->hook_send = true;
|
||||||
|
$fattura->save();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
flash()->info(tr('Le fatture elettroniche sono state aggiunte alla coda di invio'));
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
case 'export-xml-bulk':
|
case 'export-xml-bulk':
|
||||||
$dir = DOCROOT.'/files/export_fatture/';
|
$dir = DOCROOT.'/files/export_fatture/';
|
||||||
directory($dir.'tmp/');
|
directory($dir.'tmp/');
|
||||||
@@ -219,4 +237,16 @@ $operations['export-xml-bulk'] = [
|
|||||||
],
|
],
|
||||||
];
|
];
|
||||||
|
|
||||||
|
if (Interaction::isEnabled()) {
|
||||||
|
$operations['hook-send'] = [
|
||||||
|
'text' => '<span><i class="fa fa-paper-plane"></i> '.tr('Coda di invio FE').'</span>',
|
||||||
|
'data' => [
|
||||||
|
'title' => '',
|
||||||
|
'msg' => tr('Vuoi davvero aggiungere queste fatture alla coda di invio per le fatture elettroniche?'),
|
||||||
|
'button' => tr('Procedi'),
|
||||||
|
'class' => 'btn btn-lg btn-warning',
|
||||||
|
],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
return $operations;
|
return $operations;
|
||||||
|
@@ -27,14 +27,6 @@ switch (filter('op')) {
|
|||||||
case 'send':
|
case 'send':
|
||||||
$result = Interaction::sendInvoice($id_record);
|
$result = Interaction::sendInvoice($id_record);
|
||||||
|
|
||||||
// Aggiornamento dello stato
|
|
||||||
if ($result['code'] == 200) {
|
|
||||||
database()->update('co_documenti', [
|
|
||||||
'codice_stato_fe' => 'WAIT',
|
|
||||||
'data_stato_fe' => date('Y-m-d H:i:s'),
|
|
||||||
], ['id' => $id_record]);
|
|
||||||
}
|
|
||||||
|
|
||||||
echo json_encode($result);
|
echo json_encode($result);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
@@ -23,6 +23,19 @@ class Interaction extends Services
|
|||||||
]);
|
]);
|
||||||
$body = static::responseBody($response);
|
$body = static::responseBody($response);
|
||||||
|
|
||||||
|
// Aggiornamento dello stato
|
||||||
|
if ($body['status'] == 200) {
|
||||||
|
database()->update('co_documenti', [
|
||||||
|
'codice_stato_fe' => 'WAIT',
|
||||||
|
'data_stato_fe' => date('Y-m-d H:i:s'),
|
||||||
|
], ['id' => $id_record]);
|
||||||
|
} elseif ($body['status'] == 405) {
|
||||||
|
database()->update('co_documenti', [
|
||||||
|
'codice_stato_fe' => 'ERR',
|
||||||
|
'data_stato_fe' => date('Y-m-d H:i:s'),
|
||||||
|
], ['id' => $id_record]);
|
||||||
|
}
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'code' => $body['status'],
|
'code' => $body['status'],
|
||||||
'message' => $body['message'],
|
'message' => $body['message'],
|
||||||
|
69
plugins/exportFE/src/InvoiceHook.php
Normal file
69
plugins/exportFE/src/InvoiceHook.php
Normal file
@@ -0,0 +1,69 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Plugins\ExportFE;
|
||||||
|
|
||||||
|
use Hooks\Manager;
|
||||||
|
use Modules\Fatture\Fattura;
|
||||||
|
|
||||||
|
class InvoiceHook extends Manager
|
||||||
|
{
|
||||||
|
public function isSingleton()
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function needsExecution()
|
||||||
|
{
|
||||||
|
if (!Interaction::isEnabled()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$remaining = Fattura::where('hook_send', 1)
|
||||||
|
->where('codice_stato_fe', 'ERR')
|
||||||
|
->count();
|
||||||
|
|
||||||
|
return !empty($remaining);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function execute()
|
||||||
|
{
|
||||||
|
$fattura = Fattura::where('hook_send', 1)
|
||||||
|
->where('codice_stato_fe', 'ERR')
|
||||||
|
->first();
|
||||||
|
|
||||||
|
$result = Interaction::sendInvoice($fattura->id);
|
||||||
|
|
||||||
|
if ($result['code'] == 200) {
|
||||||
|
$fattura->hook_send = false;
|
||||||
|
$fattura->save();
|
||||||
|
}
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function response()
|
||||||
|
{
|
||||||
|
$completed = !$this->needsExecution();
|
||||||
|
$message = tr('Invio fatture elettroniche in corso...');
|
||||||
|
$icon = 'text-info';
|
||||||
|
|
||||||
|
$errors = Fattura::where('hook_send', 1)
|
||||||
|
->where('codice_stato_fe', 'ERR')
|
||||||
|
->count();
|
||||||
|
|
||||||
|
if ($completed) {
|
||||||
|
if (empty($errors)) {
|
||||||
|
$message = tr('Invio fatture elettroniche completato!');
|
||||||
|
} else {
|
||||||
|
$message = tr('Invio fatture elettroniche completato con errori');
|
||||||
|
$icon = 'text-danger';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return [
|
||||||
|
'icon' => 'fa fa-envelope '.$icon,
|
||||||
|
'message' => $message,
|
||||||
|
'show' => !$completed || !empty($errors),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
@@ -434,3 +434,11 @@ ALTER TABLE `em_templates` CHANGE `id_smtp` `id_account` INT(11) NOT NULL;
|
|||||||
ALTER TABLE `em_print_template` CHANGE `id_email` `id_template` INT(11) NOT NULL;
|
ALTER TABLE `em_print_template` CHANGE `id_email` `id_template` INT(11) NOT NULL;
|
||||||
ALTER TABLE `em_accounts` ADD `timeout` INT(11) NOT NULL DEFAULT 1000;
|
ALTER TABLE `em_accounts` ADD `timeout` INT(11) NOT NULL DEFAULT 1000;
|
||||||
ALTER TABLE `an_anagrafiche` ADD `enable_newsletter` BOOLEAN DEFAULT TRUE;
|
ALTER TABLE `an_anagrafiche` ADD `enable_newsletter` BOOLEAN DEFAULT TRUE;
|
||||||
|
|
||||||
|
-- Aggiunta coda di invio per le Fatture Elettroniche
|
||||||
|
ALTER TABLE `co_documenti` ADD `hook_send` BOOLEAN DEFAULT FALSE;
|
||||||
|
INSERT INTO `zz_hooks` (`id`, `name`, `class`, `frequency`, `id_module`) VALUES (NULL, 'Fatture Elettroniche', 'Plugins\\ExportFE\\InvoiceHook', '1 minute', NULL);
|
||||||
|
|
||||||
|
INSERT INTO `fe_stati_documento` (`codice`, `descrizione`, `icon`) VALUES
|
||||||
|
('ERR', 'Trasmissione non riuscita', 'fa fa-close'),
|
||||||
|
('QUEUE', 'In coda di elaborazione', 'fa fa-spinner');
|
||||||
|
Reference in New Issue
Block a user