Aggiunto invio FE tramite hook
This commit is contained in:
parent
f320cb97d4
commit
52631632e4
|
@ -26,8 +26,8 @@ class BackupHook extends Manager
|
|||
|
||||
public function response()
|
||||
{
|
||||
$show = boolval(setting('Backup automatico'));
|
||||
$message = $show && !Backup::isDailyComplete() ? tr('Backup in corso...') : tr('Backup automatico completato!');
|
||||
$show = boolval(setting('Backup automatico')) && !Backup::isDailyComplete();
|
||||
$message = $show ? tr('Backup in corso...') : tr('Backup automatico completato!');
|
||||
|
||||
return [
|
||||
'icon' => 'fa fa-file-o text-success',
|
||||
|
|
|
@ -80,8 +80,10 @@ class EmailHook extends Manager
|
|||
$current = Mail::whereDate('sent_at', '>', $yesterday)
|
||||
->where('created_by', $user->id)
|
||||
->count();
|
||||
$total = Mail::whereDate('sent_at', '>', $yesterday)
|
||||
->orWhereNull('sent_at')
|
||||
$total = Mail::where(function ($query) use ($yesterday) {
|
||||
$query->whereDate('sent_at', '>', $yesterday)
|
||||
->orWhereNull('sent_at');
|
||||
})
|
||||
->where('created_by', $user->id)
|
||||
->count();
|
||||
|
||||
|
@ -91,7 +93,7 @@ class EmailHook extends Manager
|
|||
return [
|
||||
'icon' => 'fa fa-envelope text-info',
|
||||
'message' => $message,
|
||||
'show' => true,
|
||||
'show' => ($total != $current),
|
||||
'progress' => [
|
||||
'current' => $current,
|
||||
'total' => $total,
|
||||
|
|
|
@ -4,6 +4,7 @@ include_once __DIR__.'/../../core.php';
|
|||
|
||||
use Modules\Fatture\Fattura;
|
||||
use Plugins\ExportFE\FatturaElettronica;
|
||||
use Plugins\ExportFE\Interaction;
|
||||
use Util\Zip;
|
||||
|
||||
switch (post('op')) {
|
||||
|
@ -89,6 +90,23 @@ switch (post('op')) {
|
|||
|
||||
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':
|
||||
$dir = DOCROOT.'/files/export_fatture/';
|
||||
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;
|
||||
|
|
|
@ -27,14 +27,6 @@ switch (filter('op')) {
|
|||
case 'send':
|
||||
$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);
|
||||
|
||||
break;
|
||||
|
|
|
@ -23,6 +23,19 @@ class Interaction extends Services
|
|||
]);
|
||||
$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 [
|
||||
'code' => $body['status'],
|
||||
'message' => $body['message'],
|
||||
|
|
|
@ -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_accounts` ADD `timeout` INT(11) NOT NULL DEFAULT 1000;
|
||||
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');
|
||||
|
|
Loading…
Reference in New Issue