mirror of
https://github.com/devcode-it/openstamanager.git
synced 2025-02-18 04:20:50 +01:00
Miglioramento gestione Services
This commit is contained in:
parent
be86c40a6f
commit
07c098deb3
@ -23,6 +23,7 @@ use Modules\Anagrafiche\Nazione;
|
|||||||
use Modules\Fatture\Gestori\Bollo;
|
use Modules\Fatture\Gestori\Bollo;
|
||||||
use Modules\Interventi\Intervento;
|
use Modules\Interventi\Intervento;
|
||||||
use Modules\Iva\Aliquota;
|
use Modules\Iva\Aliquota;
|
||||||
|
use Plugins\ExportFE\Interaction;
|
||||||
|
|
||||||
include_once __DIR__.'/../../core.php';
|
include_once __DIR__.'/../../core.php';
|
||||||
|
|
||||||
@ -228,7 +229,7 @@ elseif ($record['stato'] == 'Bozza') {
|
|||||||
?>
|
?>
|
||||||
|
|
||||||
<div class="col-md-2" <?php echo ($is_fiscale) ? '' : 'hidden'; ?> >
|
<div class="col-md-2" <?php echo ($is_fiscale) ? '' : 'hidden'; ?> >
|
||||||
{[ "type": "select", "label": "<?php echo tr('Stato FE'); ?>", "name": "codice_stato_fe", "values": "query=SELECT codice as id, CONCAT_WS(' - ',codice,descrizione) as text FROM fe_stati_documento", "value": "$codice_stato_fe$", "disabled": <?php echo intval(API\Services::isEnabled() || ($record['stato'] == 'Bozza' && $abilita_genera)); ?>, "class": "unblockable", "help": "<?php echo (!empty($record['data_stato_fe'])) ? Translator::timestampToLocale($record['data_stato_fe']) : ''; ?>" ]}
|
{[ "type": "select", "label": "<?php echo tr('Stato FE'); ?>", "name": "codice_stato_fe", "values": "query=SELECT codice as id, CONCAT_WS(' - ',codice,descrizione) as text FROM fe_stati_documento", "value": "$codice_stato_fe$", "disabled": <?php echo intval(Interaction::isEnabled() || ($record['stato'] == 'Bozza' && $abilita_genera)); ?>, "class": "unblockable", "help": "<?php echo (!empty($record['data_stato_fe'])) ? Translator::timestampToLocale($record['data_stato_fe']) : ''; ?>" ]}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<?php
|
<?php
|
||||||
|
@ -19,8 +19,6 @@
|
|||||||
|
|
||||||
use API\Services;
|
use API\Services;
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use Models\Cache;
|
|
||||||
use Modules\StatoServizi\ServicesHook;
|
|
||||||
|
|
||||||
include_once __DIR__.'/../../core.php';
|
include_once __DIR__.'/../../core.php';
|
||||||
|
|
||||||
@ -28,12 +26,6 @@ include_once __DIR__.'/../../core.php';
|
|||||||
echo '
|
echo '
|
||||||
<div class="row">';
|
<div class="row">';
|
||||||
|
|
||||||
/**
|
|
||||||
* Contenuto aggiornato e gestito dall'Hook ServicesHook.
|
|
||||||
*
|
|
||||||
* @var array
|
|
||||||
*/
|
|
||||||
$response = Cache::pool('Informazioni su Services')->content;
|
|
||||||
$limite_scadenze = (new Carbon())->addDays(60);
|
$limite_scadenze = (new Carbon())->addDays(60);
|
||||||
if (Services::isEnabled()) {
|
if (Services::isEnabled()) {
|
||||||
echo '
|
echo '
|
||||||
@ -48,7 +40,7 @@ if (Services::isEnabled()) {
|
|||||||
|
|
||||||
<div class="box-body">';
|
<div class="box-body">';
|
||||||
|
|
||||||
$servizi = collect($response['servizi'])->flatten(1);
|
$servizi = Services::getServiziAttivi()->flatten(1);
|
||||||
if (!$servizi->isEmpty()) {
|
if (!$servizi->isEmpty()) {
|
||||||
echo '
|
echo '
|
||||||
<table class="table table-striped table-hover">
|
<table class="table table-striped table-hover">
|
||||||
@ -99,8 +91,9 @@ if (Services::isEnabled()) {
|
|||||||
<div class="box-body">';
|
<div class="box-body">';
|
||||||
|
|
||||||
// Elaborazione delle risorse API in scadenza
|
// Elaborazione delle risorse API in scadenza
|
||||||
if (!empty($response['risorse-api'])) {
|
$risorse_attive = Services::getRisorseAttive();
|
||||||
$risorse_in_scadenza = ServicesHook::getRisorseInScadenza($response['risorse-api'], $limite_scadenze);
|
if (!$risorse_attive->isEmpty()) {
|
||||||
|
$risorse_in_scadenza = Services::getRisorseInScadenza($limite_scadenze);
|
||||||
if (!$risorse_in_scadenza->isEmpty()) {
|
if (!$risorse_in_scadenza->isEmpty()) {
|
||||||
echo '
|
echo '
|
||||||
<p>'.tr('Le seguenti risorse sono in scadenza:').'</p>
|
<p>'.tr('Le seguenti risorse sono in scadenza:').'</p>
|
||||||
@ -115,11 +108,12 @@ if (Services::isEnabled()) {
|
|||||||
|
|
||||||
<tbody>';
|
<tbody>';
|
||||||
foreach ($risorse_in_scadenza as $servizio) {
|
foreach ($risorse_in_scadenza as $servizio) {
|
||||||
$scadenza = Carbon::parse($servizio['data_scadenza']);
|
$scadenza = Carbon::parse($servizio['expiration_at']);
|
||||||
|
|
||||||
echo '
|
echo '
|
||||||
<tr>
|
<tr>
|
||||||
<td>'.$servizio['nome'].'</td>
|
<td>'.$servizio['name'].'</td>
|
||||||
<td>'.$servizio['crediti'].'</td>
|
<td>'.$servizio['credits'].'</td>
|
||||||
<td>'.dateFormat($scadenza).' ('.$scadenza->diffForHumans().')</td>
|
<td>'.dateFormat($scadenza).' ('.$scadenza->diffForHumans().')</td>
|
||||||
</tr>';
|
</tr>';
|
||||||
}
|
}
|
||||||
|
@ -21,29 +21,15 @@ namespace Modules\StatoServizi;
|
|||||||
|
|
||||||
use API\Services;
|
use API\Services;
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use Hooks\CachedManager;
|
use Hooks\Manager;
|
||||||
|
|
||||||
class ServicesHook extends CachedManager
|
class ServicesHook extends Manager
|
||||||
{
|
{
|
||||||
public function getCacheName()
|
|
||||||
{
|
|
||||||
return 'Informazioni su Services';
|
|
||||||
}
|
|
||||||
|
|
||||||
public function cacheData()
|
|
||||||
{
|
|
||||||
$response = Services::request('GET', 'info');
|
|
||||||
|
|
||||||
return Services::responseBody($response);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function response()
|
public function response()
|
||||||
{
|
{
|
||||||
$servizi = $this->getCache()->content;
|
|
||||||
$limite_scadenze = (new Carbon())->addDays(60);
|
|
||||||
|
|
||||||
// Elaborazione dei servizi in scadenza
|
// Elaborazione dei servizi in scadenza
|
||||||
$risorse_in_scadenza = self::getRisorseInScadenza($servizi['risorse-api'], $limite_scadenze);
|
$limite_scadenze = (new Carbon())->addDays(60);
|
||||||
|
$risorse_in_scadenza = Services::getRisorseInScadenza($limite_scadenze);
|
||||||
|
|
||||||
$message = tr('I seguenti servizi sono in scadenza: _LIST_', [
|
$message = tr('I seguenti servizi sono in scadenza: _LIST_', [
|
||||||
'_LIST_' => implode(', ', $risorse_in_scadenza->pluck('nome')->all()),
|
'_LIST_' => implode(', ', $risorse_in_scadenza->pluck('nome')->all()),
|
||||||
@ -56,26 +42,13 @@ class ServicesHook extends CachedManager
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function execute()
|
||||||
* Restituisce l'elenco delle risorse API in scadenza, causa data oppure crediti.
|
|
||||||
*
|
|
||||||
* @param $servizi
|
|
||||||
*/
|
|
||||||
public static function getRisorseInScadenza($risorse, $limite_scadenze)
|
|
||||||
{
|
{
|
||||||
// Elaborazione dei servizi in scadenza
|
return false;
|
||||||
$risorse_in_scadenza = collect($risorse)
|
}
|
||||||
->filter(function ($item) use ($limite_scadenze) {
|
|
||||||
return (isset($item['expiration_at']) && Carbon::parse($item['expiration_at'])->lessThan($limite_scadenze))
|
|
||||||
|| (isset($item['credits']) && $item['credits'] < 100);
|
|
||||||
});
|
|
||||||
|
|
||||||
return $risorse_in_scadenza->transform(function ($item, $key) {
|
public function needsExecution()
|
||||||
return [
|
{
|
||||||
'nome' => $item['name'],
|
return false;
|
||||||
'data_scadenza' => $item['expiration_at'],
|
|
||||||
'crediti' => $item['credits'],
|
|
||||||
];
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -30,6 +30,11 @@ use UnexpectedValueException;
|
|||||||
*/
|
*/
|
||||||
class Interaction extends Services
|
class Interaction extends Services
|
||||||
{
|
{
|
||||||
|
public static function isEnabled()
|
||||||
|
{
|
||||||
|
return parent::isEnabled() && self::verificaRisorsaAttiva('Fatturazione Elettronica');
|
||||||
|
}
|
||||||
|
|
||||||
public static function sendInvoice($id_record)
|
public static function sendInvoice($id_record)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
|
@ -29,6 +29,11 @@ use Models\Cache;
|
|||||||
*/
|
*/
|
||||||
class Interaction extends Services
|
class Interaction extends Services
|
||||||
{
|
{
|
||||||
|
public static function isEnabled()
|
||||||
|
{
|
||||||
|
return parent::isEnabled() && self::verificaRisorsaAttiva('Fatturazione Elettronica');
|
||||||
|
}
|
||||||
|
|
||||||
public static function getInvoiceList()
|
public static function getInvoiceList()
|
||||||
{
|
{
|
||||||
$list = self::getRemoteList();
|
$list = self::getRemoteList();
|
||||||
|
@ -29,6 +29,11 @@ use Models\Cache;
|
|||||||
*/
|
*/
|
||||||
class Interaction extends Services
|
class Interaction extends Services
|
||||||
{
|
{
|
||||||
|
public static function isEnabled()
|
||||||
|
{
|
||||||
|
return parent::isEnabled() && self::verificaRisorsaAttiva('Fatturazione Elettronica');
|
||||||
|
}
|
||||||
|
|
||||||
public static function getReceiptList()
|
public static function getReceiptList()
|
||||||
{
|
{
|
||||||
$list = self::getRemoteList();
|
$list = self::getRemoteList();
|
||||||
|
@ -19,7 +19,9 @@
|
|||||||
|
|
||||||
namespace API;
|
namespace API;
|
||||||
|
|
||||||
|
use Carbon\Carbon;
|
||||||
use GuzzleHttp\Client;
|
use GuzzleHttp\Client;
|
||||||
|
use Models\Cache;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Classe per l'interazione con API esterne.
|
* Classe per l'interazione con API esterne.
|
||||||
@ -30,11 +32,98 @@ class Services
|
|||||||
{
|
{
|
||||||
protected static $client = null;
|
protected static $client = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Controlla se il gestionale ha accesso a Services.
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
public static function isEnabled()
|
public static function isEnabled()
|
||||||
{
|
{
|
||||||
return !empty(setting('OSMCloud Services API Token'));
|
return !empty(setting('OSMCloud Services API Token'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Restituisce le informazioni disponibili su Services.
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public static function getInformazioni($force = false)
|
||||||
|
{
|
||||||
|
$cache = Cache::pool('Informazioni su Services');
|
||||||
|
|
||||||
|
// Aggiornamento dei contenuti della cache
|
||||||
|
if (!$cache->isValid() || $force) {
|
||||||
|
$response = self::request('GET', 'info');
|
||||||
|
$content = self::responseBody($response);
|
||||||
|
|
||||||
|
$cache->set($content);
|
||||||
|
|
||||||
|
return $content;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $cache->content;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Restituisce i servizi attivi attraverso Services.
|
||||||
|
*
|
||||||
|
* @return \Illuminate\Support\Collection
|
||||||
|
*/
|
||||||
|
public static function getServiziAttivi()
|
||||||
|
{
|
||||||
|
return collect(self::getInformazioni()['servizi']);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Restituisce le risorse attive in Services.
|
||||||
|
*
|
||||||
|
* @return \Illuminate\Support\Collection
|
||||||
|
*/
|
||||||
|
public static function getRisorseAttive()
|
||||||
|
{
|
||||||
|
return collect(self::getInformazioni()['risorse-api']);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Controlla se il gestionale ha accesso a una specifica risorsa di Services.
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public static function verificaRisorsaAttiva($servizio)
|
||||||
|
{
|
||||||
|
return self::isEnabled() && self::getRisorseAttive()->search(function ($item) use ($servizio) {
|
||||||
|
return $item['name'] == $servizio;
|
||||||
|
}) !== false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Restituisce le risorse in scadenza per assenza di crediti oppure per data di fine prossima.
|
||||||
|
*
|
||||||
|
* @param Carbon $limite_scadenze
|
||||||
|
*
|
||||||
|
* @return \Illuminate\Support\Collection
|
||||||
|
*/
|
||||||
|
public static function getRisorseInScadenza($limite_scadenze)
|
||||||
|
{
|
||||||
|
return self::getRisorseAttive()
|
||||||
|
->filter(function ($item) use ($limite_scadenze) {
|
||||||
|
return (isset($item['expiration_at']) && Carbon::parse($item['expiration_at'])->lessThan($limite_scadenze))
|
||||||
|
|| (isset($item['credits']) && $item['credits'] < 100);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Effettua una richiesta a Services.
|
||||||
|
*
|
||||||
|
* @param $type
|
||||||
|
* @param $resource
|
||||||
|
* @param array $data
|
||||||
|
* @param array $options
|
||||||
|
*
|
||||||
|
* @throws \GuzzleHttp\Exception\GuzzleException
|
||||||
|
*
|
||||||
|
* @return \Psr\Http\Message\ResponseInterface
|
||||||
|
*/
|
||||||
public static function request($type, $resource, $data = [], $options = [])
|
public static function request($type, $resource, $data = [], $options = [])
|
||||||
{
|
{
|
||||||
$client = static::getClient();
|
$client = static::getClient();
|
||||||
@ -53,6 +142,13 @@ class Services
|
|||||||
return $client->request($type, '', $options);
|
return $client->request($type, '', $options);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Restituisce il corpo JSON della risposta in array.
|
||||||
|
*
|
||||||
|
* @param $response
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
public static function responseBody($response)
|
public static function responseBody($response)
|
||||||
{
|
{
|
||||||
$body = $response->getBody();
|
$body = $response->getBody();
|
||||||
|
@ -98,7 +98,7 @@ class Validate
|
|||||||
} */
|
} */
|
||||||
|
|
||||||
// Controllo attraverso apilayer
|
// Controllo attraverso apilayer
|
||||||
if (Services::isEnabled()) {
|
if (Services::verificaRisorsaAttiva('Verifica Partita IVA')) {
|
||||||
$response = Services::request('post', 'check_iva', [
|
$response = Services::request('post', 'check_iva', [
|
||||||
'partita_iva' => $vat_number,
|
'partita_iva' => $vat_number,
|
||||||
]);
|
]);
|
||||||
@ -151,7 +151,7 @@ class Validate
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Controllo attraverso apilayer
|
// Controllo attraverso apilayer
|
||||||
if (Services::isEnabled()) {
|
if (Services::verificaRisorsaAttiva('Verifica Email')) {
|
||||||
$response = Services::request('post', 'check_email', [
|
$response = Services::request('post', 'check_email', [
|
||||||
'email' => $email,
|
'email' => $email,
|
||||||
]);
|
]);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user