1
0
mirror of https://github.com/devcode-it/openstamanager.git synced 2025-02-16 19:40:44 +01:00

Aggiornamento hook Ricevute per l'importazione

This commit is contained in:
Thomas Zilio 2020-03-09 15:53:07 +01:00
parent 997085a195
commit 8ca6af2539
3 changed files with 80 additions and 29 deletions

View File

@ -16,7 +16,7 @@ switch (filter('op')) {
$fattura = null; $fattura = null;
try { try {
$receipt = new Ricevuta($name, $content); $receipt = new Ricevuta($name);
$receipt->save(); $receipt->save();
$fattura = $receipt->getFattura()->numero_esterno; $fattura = $receipt->getFattura()->numero_esterno;
@ -50,7 +50,7 @@ switch (filter('op')) {
$fattura = null; $fattura = null;
try { try {
$receipt = new Ricevuta($name, $content); $receipt = new Ricevuta($name);
$receipt->save(); $receipt->save();
$fattura = $receipt->getFattura()->numero_esterno; $fattura = $receipt->getFattura()->numero_esterno;

View File

@ -2,48 +2,97 @@
namespace Plugins\ReceiptFE; namespace Plugins\ReceiptFE;
use Hooks\CachedManager; use Hooks\Manager;
use Modules; use Models\Cache;
class ReceiptHook extends CachedManager class ReceiptHook extends Manager
{ {
public function getCacheName() public function isSingleton()
{ {
return 'Ricevute Elettroniche'; return true;
} }
public function cacheData() public function needsExecution()
{ {
return Interaction::getReceiptList(); // Lettura cache
$todo_cache = Cache::get('Ricevute Elettroniche');
return !$todo_cache->isValid() || !empty($todo_cache->content);
}
public function execute()
{
// Lettura cache
$todo_cache = Cache::get('Ricevute Elettroniche');
$completed_cache = Cache::get('Ricevute Elettroniche importate');
// Refresh cache
if (!$todo_cache->isValid()) {
$list = Interaction::getRemoteList();
$todo_cache->set($list);
$completed_cache->set([]);
return;
}
// Caricamento elenco di importazione
$todo = $todo_cache->content;
if (empty($todo)) {
return;
}
// Caricamento elenco di ricevute imporate
$completed = $completed_cache->content;
$count = count($todo);
// Esecuzione di 10 imporazioni
for ($i = 0; $i < 10 && $i < $count; ++$i) {
$element = $todo[$i];
// Importazione ricevuta
$name = $element['name'];
Interaction::getReceiptList($name);
try {
$receipt = new Ricevuta($name);
$receipt->save();
$receipt->delete();
Interaction::processReceipt($name);
$completed[] = $element;
unset($todo[$i]);
} catch (UnexpectedValueException $e) {
}
}
// Aggiornamento cache
$todo_cache->set($todo);
$completed_cache->set($completed);
} }
public function response() public function response()
{ {
$results = $this->getCache()->content; // Lettura cache
$todo_cache = Cache::get('Ricevute Elettroniche');
$completed_cache = Cache::get('Ricevute Elettroniche importate');
$count = count($results); $completed_number = count($completed_cache->content);
$notify = false; $total_number = $completed_number + count($todo_cache->content);
$module = Modules::get('Fatture di vendita'); // Messaggio di importazione
$plugins = $module->plugins; $message = tr('Sono state importate _NUM_ ricevute su _TOT_', [
'_NUM_' => $completed_number,
if (!empty($plugins)) { '_TOT_' => $total_number,
$notify = !empty($count);
$plugin = $plugins->first(function ($value, $key) {
return $value->name == 'Ricevute FE';
});
$link = ROOTDIR.'/controller.php?id_module='.$module->id.'#tab_'.$plugin->id;
}
$message = tr('Ci sono _NUM_ ricevute da importare', [
'_NUM_' => $count,
]); ]);
// Notifica sullo stato dell'importazione
$notify = $total_number != 0;
$color = $total_number == $completed_number ? 'success' : 'yellow';
return [ return [
'icon' => 'fa fa-ticket text-yellow', 'icon' => 'fa fa-ticket text-'.$color,
'link' => $link,
'message' => $message, 'message' => $message,
'show' => $notify, 'show' => $notify,
]; ];

View File

@ -436,10 +436,12 @@ CREATE TABLE IF NOT EXISTS `zz_cache` (
INSERT INTO `zz_cache` (`id`, `name`, `content`, `valid_time`, `expire_at`) VALUES INSERT INTO `zz_cache` (`id`, `name`, `content`, `valid_time`, `expire_at`) VALUES
(NULL, 'Ricevute Elettroniche', '', '1 day', NULL), (NULL, 'Ricevute Elettroniche', '', '1 day', NULL),
(NULL, 'Ricevute Elettroniche importate', '', '1 day', NULL),
(NULL, 'Fatture Elettroniche', '', '1 day', NULL), (NULL, 'Fatture Elettroniche', '', '1 day', NULL),
(NULL, 'Ultima versione di OpenSTAManager disponibile', '', '7 day', NULL); (NULL, 'Ultima versione di OpenSTAManager disponibile', '', '7 day', NULL);
DROP TABLE IF EXISTS `zz_hook_cache`; DROP TABLE IF EXISTS `zz_hook_cache`;
ALTER TABLE `zz_hooks` DROP `frequency`;
-- Fix nome hook Aggiornamenti -- Fix nome hook Aggiornamenti
UPDATE `zz_hooks` SET `name` = 'Aggiornamenti' WHERE `class` = 'Modules\\Aggiornamenti\\UpdateHook'; UPDATE `zz_hooks` SET `name` = 'Aggiornamenti' WHERE `class` = 'Modules\\Aggiornamenti\\UpdateHook';