openstamanager/plugins/importFE/src/InvoiceHook.php

72 lines
2.0 KiB
PHP
Raw Normal View History

2019-05-10 06:32:06 +02:00
<?php
2020-09-07 15:04:06 +02:00
/*
* OpenSTAManager: il software gestionale open source per l'assistenza tecnica e la fatturazione
2021-01-20 15:08:51 +01:00
* Copyright (C) DevCode s.r.l.
2020-09-07 15:04:06 +02:00
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
2019-05-10 06:32:06 +02:00
namespace Plugins\ImportFE;
2019-08-26 18:02:05 +02:00
use Hooks\CachedManager;
2019-05-10 17:14:34 +02:00
use Modules;
2019-05-10 06:32:06 +02:00
/**
* Hook dedicato all'importazione automatica delle Fatture Elettroniche di acquisto rilevate dal sistema automatico di gestione.
*/
2019-08-26 18:02:05 +02:00
class InvoiceHook extends CachedManager
2019-05-10 06:32:06 +02:00
{
2020-03-03 10:31:01 +01:00
public function getCacheName()
2019-05-10 06:32:06 +02:00
{
2020-03-03 10:31:01 +01:00
return 'Fatture Elettroniche';
}
2019-05-10 06:32:06 +02:00
2020-03-03 10:31:01 +01:00
public function cacheData()
{
return Interaction::getInvoiceList();
2019-05-10 06:32:06 +02:00
}
2019-08-29 11:25:13 +02:00
public function response()
2019-05-10 06:32:06 +02:00
{
2020-09-23 12:00:21 +02:00
$results = (array) $this->getCache()->content;
2019-08-29 11:25:13 +02:00
2019-05-10 06:32:06 +02:00
$count = count($results);
2019-06-29 11:12:43 +02:00
$notify = false;
2019-05-10 06:32:06 +02:00
2019-05-10 17:14:34 +02:00
$module = Modules::get('Fatture di acquisto');
2019-06-29 11:12:43 +02:00
$plugins = $module->plugins;
2019-05-10 17:14:34 +02:00
2019-06-29 11:12:43 +02:00
if (!empty($plugins)) {
$notify = !empty($count);
$plugin = $plugins->first(function ($value, $key) {
return $value->name == 'Fatturazione Elettronica';
});
$link = base_path().'/controller.php?id_module='.$module->id.'#tab_'.$plugin->id;
2019-06-29 11:12:43 +02:00
}
2019-05-24 20:15:05 +02:00
$message = tr('Ci sono _NUM_ fatture passive da importare', [
'_NUM_' => $count,
]);
2019-05-16 04:52:16 +02:00
2019-05-10 06:32:06 +02:00
return [
2019-05-24 20:15:05 +02:00
'icon' => 'fa fa-file-text-o text-yellow',
2019-05-10 17:14:34 +02:00
'link' => $link,
'message' => $message,
2019-08-27 15:42:13 +02:00
'show' => $notify,
2019-05-10 06:32:06 +02:00
];
}
}