mirror of
https://github.com/devcode-it/openstamanager.git
synced 2025-03-09 15:50:14 +01:00
Stile del codice
This commit is contained in:
parent
d0e384feb0
commit
f2f0e0e11f
4
.php_cs
4
.php_cs
@ -16,6 +16,10 @@ $config = PhpCsFixer\Config::create()
|
||||
'array_syntax' => ['syntax' => 'short'],
|
||||
'yoda_style' => false,
|
||||
'no_short_echo_tag' => true,
|
||||
'ordered_imports' => true,
|
||||
'no_alternative_syntax' => true,
|
||||
'ordered_class_elements' => true,
|
||||
'phpdoc_order' => true,
|
||||
])
|
||||
->setFinder($finder);
|
||||
|
||||
|
2
core.php
2
core.php
@ -73,9 +73,9 @@ $logger->pushProcessor(new Monolog\Processor\WebProcessor());
|
||||
// Registrazione globale del logger
|
||||
Monolog\Registry::addLogger($logger, 'logs');
|
||||
|
||||
use Monolog\Handler\StreamHandler;
|
||||
use Monolog\Handler\FilterHandler;
|
||||
use Monolog\Handler\RotatingFileHandler;
|
||||
use Monolog\Handler\StreamHandler;
|
||||
|
||||
$handlers = [];
|
||||
if (!API::isAPIRequest()) {
|
||||
|
@ -2,24 +2,15 @@
|
||||
|
||||
namespace Common\Components;
|
||||
|
||||
use Modules\Articoli\Articolo as Original;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use UnexpectedValueException;
|
||||
use Common\Document;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Modules\Articoli\Articolo as Original;
|
||||
use UnexpectedValueException;
|
||||
|
||||
abstract class Article extends Row
|
||||
{
|
||||
protected $serialRowID = 'documento';
|
||||
|
||||
protected static function boot()
|
||||
{
|
||||
parent::boot(true);
|
||||
|
||||
static::addGlobalScope('articles', function (Builder $builder) {
|
||||
$builder->whereNotNull('idarticolo')->where('idarticolo', '<>', 0);
|
||||
});
|
||||
}
|
||||
|
||||
public static function make(Document $document, Original $articolo)
|
||||
{
|
||||
$model = parent::make($document, true);
|
||||
@ -70,45 +61,6 @@ abstract class Article extends Row
|
||||
return array_column($results, 'serial');
|
||||
}
|
||||
|
||||
protected function usedSerials()
|
||||
{
|
||||
if ($this->getDirection() == 'uscita') {
|
||||
$results = database()->fetchArray("SELECT serial FROM mg_prodotti WHERE serial IN (SELECT DISTINCT serial FROM mg_prodotti WHERE dir = 'entrata') AND serial IS NOT NULL AND id_riga_".$this->serialRowID.' = '.prepare($this->id));
|
||||
|
||||
return array_column($results, 'serial');
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
protected function cleanupSerials($new_qta)
|
||||
{
|
||||
// Se la nuova quantità è minore della precedente
|
||||
if ($this->qta > $new_qta) {
|
||||
$seriali_usati = $this->usedSerials();
|
||||
$count_seriali_usati = count($seriali_usati);
|
||||
|
||||
// Controllo sulla possibilità di rimuovere i seriali (se non utilizzati da documenti di vendita)
|
||||
if ($this->getDirection() == 'uscita' && $new_qta < $count_seriali_usati) {
|
||||
return false;
|
||||
} else {
|
||||
// Controllo sul numero di seriali effettivi da rimuovere
|
||||
$seriali = $this->serials;
|
||||
|
||||
if ($new_qta < count($seriali)) {
|
||||
$rimovibili = array_diff($seriali, $seriali_usati);
|
||||
|
||||
// Rimozione dei seriali aggiuntivi
|
||||
$serials = array_slice($rimovibili, 0, $new_qta - $count_seriali_usati);
|
||||
|
||||
$this->serials = array_merge($seriali_usati, $serials);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Modifica la quantità dell'articolo e movimenta automaticamente il magazzino.
|
||||
*
|
||||
@ -169,4 +121,52 @@ abstract class Article extends Row
|
||||
|
||||
return $model;
|
||||
}
|
||||
|
||||
protected static function boot()
|
||||
{
|
||||
parent::boot(true);
|
||||
|
||||
static::addGlobalScope('articles', function (Builder $builder) {
|
||||
$builder->whereNotNull('idarticolo')->where('idarticolo', '<>', 0);
|
||||
});
|
||||
}
|
||||
|
||||
protected function usedSerials()
|
||||
{
|
||||
if ($this->getDirection() == 'uscita') {
|
||||
$results = database()->fetchArray("SELECT serial FROM mg_prodotti WHERE serial IN (SELECT DISTINCT serial FROM mg_prodotti WHERE dir = 'entrata') AND serial IS NOT NULL AND id_riga_".$this->serialRowID.' = '.prepare($this->id));
|
||||
|
||||
return array_column($results, 'serial');
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
protected function cleanupSerials($new_qta)
|
||||
{
|
||||
// Se la nuova quantità è minore della precedente
|
||||
if ($this->qta > $new_qta) {
|
||||
$seriali_usati = $this->usedSerials();
|
||||
$count_seriali_usati = count($seriali_usati);
|
||||
|
||||
// Controllo sulla possibilità di rimuovere i seriali (se non utilizzati da documenti di vendita)
|
||||
if ($this->getDirection() == 'uscita' && $new_qta < $count_seriali_usati) {
|
||||
return false;
|
||||
} else {
|
||||
// Controllo sul numero di seriali effettivi da rimuovere
|
||||
$seriali = $this->serials;
|
||||
|
||||
if ($new_qta < count($seriali)) {
|
||||
$rimovibili = array_diff($seriali, $seriali_usati);
|
||||
|
||||
// Rimozione dei seriali aggiuntivi
|
||||
$serials = array_slice($rimovibili, 0, $new_qta - $count_seriali_usati);
|
||||
|
||||
$this->serials = array_merge($seriali_usati, $serials);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -2,33 +2,14 @@
|
||||
|
||||
namespace Common\Components;
|
||||
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Common\Model;
|
||||
use Common\Document;
|
||||
use Common\Model;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
|
||||
abstract class Description extends Model
|
||||
{
|
||||
protected $guarded = [];
|
||||
|
||||
protected static function boot($bypass = false)
|
||||
{
|
||||
parent::boot();
|
||||
|
||||
if (!$bypass) {
|
||||
static::addGlobalScope('descriptions', function (Builder $builder) {
|
||||
$builder->where('is_descrizione', '=', 1);
|
||||
});
|
||||
} else {
|
||||
static::addGlobalScope('not_descriptions', function (Builder $builder) {
|
||||
$builder->where('is_descrizione', '=', 0);
|
||||
});
|
||||
}
|
||||
|
||||
static::addGlobalScope('not_discount', function (Builder $builder) {
|
||||
$builder->where('sconto_globale', '=', 0);
|
||||
});
|
||||
}
|
||||
|
||||
public static function make(Document $document, $bypass = false)
|
||||
{
|
||||
$model = parent::make();
|
||||
@ -83,4 +64,23 @@ abstract class Description extends Model
|
||||
abstract public function parent();
|
||||
|
||||
abstract public function getParentID();
|
||||
|
||||
protected static function boot($bypass = false)
|
||||
{
|
||||
parent::boot();
|
||||
|
||||
if (!$bypass) {
|
||||
static::addGlobalScope('descriptions', function (Builder $builder) {
|
||||
$builder->where('is_descrizione', '=', 1);
|
||||
});
|
||||
} else {
|
||||
static::addGlobalScope('not_descriptions', function (Builder $builder) {
|
||||
$builder->where('is_descrizione', '=', 0);
|
||||
});
|
||||
}
|
||||
|
||||
static::addGlobalScope('not_discount', function (Builder $builder) {
|
||||
$builder->where('sconto_globale', '=', 0);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -2,20 +2,11 @@
|
||||
|
||||
namespace Common\Components;
|
||||
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Common\Model;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
|
||||
abstract class Discount extends Model
|
||||
{
|
||||
protected static function boot()
|
||||
{
|
||||
parent::boot();
|
||||
|
||||
static::addGlobalScope('is_discount', function (Builder $builder) {
|
||||
$builder->where('sconto_globale', '=', 1);
|
||||
});
|
||||
}
|
||||
|
||||
public static function make()
|
||||
{
|
||||
$model = parent::make();
|
||||
@ -72,4 +63,13 @@ abstract class Discount extends Model
|
||||
{
|
||||
return $this->attributes['iva'];
|
||||
}
|
||||
|
||||
protected static function boot()
|
||||
{
|
||||
parent::boot();
|
||||
|
||||
static::addGlobalScope('is_discount', function (Builder $builder) {
|
||||
$builder->where('sconto_globale', '=', 1);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -9,17 +9,6 @@ abstract class Row extends Description
|
||||
{
|
||||
protected $prezzo_unitario_vendita_riga = null;
|
||||
|
||||
protected static function boot($bypass = false)
|
||||
{
|
||||
parent::boot(true);
|
||||
|
||||
if (!$bypass) {
|
||||
static::addGlobalScope('rows', function (Builder $builder) {
|
||||
$builder->whereNull('idarticolo')->orWhere('idarticolo', '=', 0);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public static function make(Document $document, $bypass = false)
|
||||
{
|
||||
return parent::make($document, true);
|
||||
@ -192,6 +181,37 @@ abstract class Row extends Description
|
||||
return $this->prezzo_unitario_vendita_riga;
|
||||
}
|
||||
|
||||
/**
|
||||
* Save the model to the database.
|
||||
*
|
||||
* @param array $options
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function save(array $options = [])
|
||||
{
|
||||
// Fix dei campi statici
|
||||
$this->fixSubtotale();
|
||||
$this->fixSconto();
|
||||
|
||||
$this->fixIva();
|
||||
$this->fixRitenutaAcconto();
|
||||
$this->fixRivalsaINPS();
|
||||
|
||||
return parent::save($options);
|
||||
}
|
||||
|
||||
protected static function boot($bypass = false)
|
||||
{
|
||||
parent::boot(true);
|
||||
|
||||
if (!$bypass) {
|
||||
static::addGlobalScope('rows', function (Builder $builder) {
|
||||
$builder->whereNull('idarticolo')->orWhere('idarticolo', '=', 0);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Effettua i conti per il subtotale della riga.
|
||||
*/
|
||||
@ -266,23 +286,4 @@ abstract class Row extends Description
|
||||
{
|
||||
$this->attributes['sconto'] = $this->sconto;
|
||||
}
|
||||
|
||||
/**
|
||||
* Save the model to the database.
|
||||
*
|
||||
* @param array $options
|
||||
* @return bool
|
||||
*/
|
||||
public function save(array $options = [])
|
||||
{
|
||||
// Fix dei campi statici
|
||||
$this->fixSubtotale();
|
||||
$this->fixSconto();
|
||||
|
||||
$this->fixIva();
|
||||
$this->fixRitenutaAcconto();
|
||||
$this->fixRivalsaINPS();
|
||||
|
||||
return parent::save($options);
|
||||
}
|
||||
}
|
||||
|
@ -26,32 +26,6 @@ abstract class Document extends Model
|
||||
|
||||
abstract public function scontoGlobale();
|
||||
|
||||
/**
|
||||
* Restituisce la collezione di righe e articoli con valori rilevanti per i conti.
|
||||
*
|
||||
* @return iterable
|
||||
*/
|
||||
protected function getRigheContabili()
|
||||
{
|
||||
$sconto = $this->scontoGlobale ? [$this->scontoGlobale] : [];
|
||||
|
||||
return $this->getRighe()->merge(collect($sconto));
|
||||
}
|
||||
|
||||
/**
|
||||
* Funzione per l'arrotondamento degli importi.
|
||||
*
|
||||
* @param float $value
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
protected function round($value)
|
||||
{
|
||||
$decimals = 2;
|
||||
|
||||
return round($value, $decimals);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calcola l'imponibile della fattura.
|
||||
*
|
||||
@ -151,4 +125,30 @@ abstract class Document extends Model
|
||||
{
|
||||
return $this->round($this->getRigheContabili()->sum('guadagno'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Restituisce la collezione di righe e articoli con valori rilevanti per i conti.
|
||||
*
|
||||
* @return iterable
|
||||
*/
|
||||
protected function getRigheContabili()
|
||||
{
|
||||
$sconto = $this->scontoGlobale ? [$this->scontoGlobale] : [];
|
||||
|
||||
return $this->getRighe()->merge(collect($sconto));
|
||||
}
|
||||
|
||||
/**
|
||||
* Funzione per l'arrotondamento degli importi.
|
||||
*
|
||||
* @param float $value
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
protected function round($value)
|
||||
{
|
||||
$decimals = 2;
|
||||
|
||||
return round($value, $decimals);
|
||||
}
|
||||
}
|
||||
|
@ -164,9 +164,6 @@ if (!function_exists('random_string')) {
|
||||
/**
|
||||
* Generates a string of random characters.
|
||||
*
|
||||
* @throws LengthException If $length is bigger than the available
|
||||
* character pool and $no_duplicate_chars is
|
||||
* enabled
|
||||
*
|
||||
* @param int $length The length of the string to
|
||||
* generate
|
||||
@ -182,6 +179,10 @@ if (!function_exists('random_string')) {
|
||||
* @param bool $no_duplicate_chars whether or not to only use
|
||||
* characters once in the string
|
||||
*
|
||||
* @throws LengthException If $length is bigger than the available
|
||||
* character pool and $no_duplicate_chars is
|
||||
* enabled
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function random_string($length = 16, $human_friendly = true, $include_symbols = false, $no_duplicate_chars = false)
|
||||
|
@ -268,9 +268,7 @@ if (!empty($google)) {
|
||||
echo Modules::link('Piano dei conti', null, null, null, 'class="pull-right"');
|
||||
} else {
|
||||
$piano_dei_conti_fornitore = tr('Nessuno');
|
||||
}
|
||||
|
||||
?>
|
||||
} ?>
|
||||
|
||||
{[ "type": "select", "label": "<?php echo tr('Piano dei conti fornitore'); ?>", "name": "piano_dei_conti_fornitore", "values": "list=\"\": \"<?php echo $piano_dei_conti_fornitore; ?>\"", "readonly": 1, "value": "", "extra": "" ]}
|
||||
|
||||
@ -347,9 +345,7 @@ if (!empty($google)) {
|
||||
echo Modules::link('Piano dei conti', null, null, null, 'class="pull-right"');
|
||||
} else {
|
||||
$piano_dei_conti_cliente = tr('Nessuno');
|
||||
}
|
||||
|
||||
?>
|
||||
} ?>
|
||||
|
||||
{[ "type": "select", "label": "<?php echo tr('Piano dei conti cliente'); ?>", "name": "piano_dei_conti_cliente", "values": "list=\"\": \"<?php echo $piano_dei_conti_cliente; ?>\"", "readonly": 1, "value": "", "extra": "" ]}
|
||||
|
||||
|
@ -4,9 +4,9 @@ namespace Modules\Anagrafiche;
|
||||
|
||||
use Common\Model;
|
||||
use Modules\Fatture\Fattura;
|
||||
use Settings;
|
||||
use Traits\RecordTrait;
|
||||
use Util\Generator;
|
||||
use Settings;
|
||||
|
||||
class Anagrafica extends Model
|
||||
{
|
||||
|
@ -2,9 +2,9 @@
|
||||
|
||||
include_once __DIR__.'/../../core.php';
|
||||
|
||||
use Modules\Anagrafiche\Anagrafica;
|
||||
use Modules\Fatture\Fattura;
|
||||
use Modules\Fatture\Tipo;
|
||||
use Modules\Anagrafiche\Anagrafica;
|
||||
|
||||
if ($module['name'] == 'Ddt di vendita') {
|
||||
$dir = 'entrata';
|
||||
|
@ -2,13 +2,13 @@
|
||||
|
||||
include_once __DIR__.'/../../core.php';
|
||||
|
||||
use Modules\Fatture\Tipo;
|
||||
use Modules\Fatture\Fattura;
|
||||
use Modules\Anagrafiche\Anagrafica;
|
||||
use Modules\Fatture\Components\Riga;
|
||||
use Modules\Articoli\Articolo as ArticoloOriginale;
|
||||
use Modules\Fatture\Components\Articolo;
|
||||
use Modules\Fatture\Components\Descrizione;
|
||||
use Modules\Articoli\Articolo as ArticoloOriginale;
|
||||
use Modules\Fatture\Components\Riga;
|
||||
use Modules\Fatture\Fattura;
|
||||
use Modules\Fatture\Tipo;
|
||||
|
||||
$module = Modules::get($id_module);
|
||||
|
||||
|
@ -108,12 +108,12 @@ if (empty($record['is_fiscale'])) {
|
||||
|
||||
<div class="col-md-3">
|
||||
<?php
|
||||
if ($dir == 'entrata') {
|
||||
?>
|
||||
if ($dir == 'entrata') {
|
||||
?>
|
||||
{[ "type": "select", "label": "<?php echo tr('Stato FE'); ?>", "name": "codice_stato_fe", "required": 0, "values": "query=SELECT codice as id, descrizione as text FROM fe_stati_documento", "value": "$codice_stato_fe$", "disabled": <?php echo intval(Plugins\ExportFE\Connection::isEnabled()); ?>, "class": "unblockable" ]}
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@ -175,7 +175,7 @@ if (empty($record['is_fiscale'])) {
|
||||
</div>
|
||||
|
||||
<div class="col-md-3">
|
||||
{[ "type": "select", "label": "<?php echo tr('Banca'); ?>", "name": "idbanca", "values": "query=SELECT id, CONCAT (nome, ' - ' , iban) AS descrizione FROM co_banche WHERE deleted_at IS NULL ORDER BY nome ASC", "value": "$idbanca$", "icon-after": "add|<?php echo Modules::get('Banche')['id']; ?>||", "extra": " <?php echo ($record['stato']=='Bozza') ? '' : 'disabled'; ?> " ]}
|
||||
{[ "type": "select", "label": "<?php echo tr('Banca'); ?>", "name": "idbanca", "values": "query=SELECT id, CONCAT (nome, ' - ' , iban) AS descrizione FROM co_banche WHERE deleted_at IS NULL ORDER BY nome ASC", "value": "$idbanca$", "icon-after": "add|<?php echo Modules::get('Banche')['id']; ?>||", "extra": " <?php echo ($record['stato'] == 'Bozza') ? '' : 'disabled'; ?> " ]}
|
||||
</div>
|
||||
|
||||
|
||||
|
@ -502,7 +502,7 @@ function get_netto_fattura($iddocumento)
|
||||
], null, 2);
|
||||
|
||||
if ($rs[0]['split_payment']) {
|
||||
$netto_a_pagare = sum($netto_a_pagare, - (get_ivadetraibile_fattura($iddocumento) + get_ivaindetraibile_fattura($iddocumento)), 2);
|
||||
$netto_a_pagare = sum($netto_a_pagare, -(get_ivadetraibile_fattura($iddocumento) + get_ivaindetraibile_fattura($iddocumento)), 2);
|
||||
}
|
||||
|
||||
return $netto_a_pagare;
|
||||
|
@ -2,8 +2,8 @@
|
||||
|
||||
include_once __DIR__.'/../../core.php';
|
||||
|
||||
use Modules\Fatture\Descrizione;
|
||||
use Modules\Fatture\Articolo;
|
||||
use Modules\Fatture\Descrizione;
|
||||
use Modules\Fatture\Riga;
|
||||
|
||||
// Righe fattura
|
||||
@ -323,12 +323,13 @@ if (!empty($iva)) {
|
||||
echo '
|
||||
<tr>
|
||||
<td colspan="5" class="text-right">';
|
||||
|
||||
if ($records[0]['split_payment'])
|
||||
echo '<b>'.tr('Iva a carico del destinatario', [], ['upper' => true]).':</b>';
|
||||
else
|
||||
echo '<b>'.tr('Iva', [], ['upper' => true]).':</b>';
|
||||
echo '
|
||||
|
||||
if ($records[0]['split_payment']) {
|
||||
echo '<b>'.tr('Iva a carico del destinatario', [], ['upper' => true]).':</b>';
|
||||
} else {
|
||||
echo '<b>'.tr('Iva', [], ['upper' => true]).':</b>';
|
||||
}
|
||||
echo '
|
||||
</td>
|
||||
<td align="right">
|
||||
'.Translator::numberToLocale($iva).' €
|
||||
|
@ -3,9 +3,9 @@
|
||||
namespace Modules\Fatture;
|
||||
|
||||
use Common\Document;
|
||||
use Util\Generator;
|
||||
use Traits\RecordTrait;
|
||||
use Modules\Anagrafiche\Anagrafica;
|
||||
use Traits\RecordTrait;
|
||||
use Util\Generator;
|
||||
|
||||
class Fattura extends Document
|
||||
{
|
||||
|
@ -2,9 +2,9 @@
|
||||
|
||||
include_once __DIR__.'/../../core.php';
|
||||
|
||||
use Modules\Interventi\Intervento;
|
||||
use Modules\Articoli\Articolo as ArticoloOriginale;
|
||||
use Modules\Interventi\Components\Articolo;
|
||||
use Modules\Interventi\Intervento;
|
||||
|
||||
switch (post('op')) {
|
||||
case 'update':
|
||||
|
@ -1,8 +1,8 @@
|
||||
<?php
|
||||
|
||||
use Modules\Articoli\Articolo as ArticoloOriginale;
|
||||
use Modules\Interventi\Articolo;
|
||||
use Modules\Interventi\Intervento;
|
||||
use Modules\Articoli\Articolo as ArticoloOriginale;
|
||||
|
||||
switch ($resource) {
|
||||
case 'intervento':
|
||||
|
@ -6,10 +6,10 @@ if (file_exists(__DIR__.'/../../../core.php')) {
|
||||
include_once __DIR__.'/../../core.php';
|
||||
}
|
||||
|
||||
use Util\Zip;
|
||||
use Modules\Anagrafiche\Anagrafica;
|
||||
use Modules\Fatture\Fattura;
|
||||
use Modules\Fatture\Tipo;
|
||||
use Modules\Anagrafiche\Anagrafica;
|
||||
use Util\Zip;
|
||||
|
||||
// Segmenti
|
||||
$id_fatture = Modules::get('Fatture di vendita')['id'];
|
||||
|
@ -3,8 +3,8 @@
|
||||
namespace Modules\Interventi\Components;
|
||||
|
||||
use Common\Components\Article;
|
||||
use Modules\Interventi\Intervento;
|
||||
use Modules\Articoli\Articolo as Original;
|
||||
use Modules\Interventi\Intervento;
|
||||
|
||||
class Articolo extends Article
|
||||
{
|
||||
@ -96,6 +96,11 @@ class Articolo extends Article
|
||||
{
|
||||
}
|
||||
|
||||
public function getSubtotaleAttribute()
|
||||
{
|
||||
return $this->prezzo_vendita * $this->qta;
|
||||
}
|
||||
|
||||
/**
|
||||
* Effettua i conti per il subtotale della riga.
|
||||
*/
|
||||
@ -105,9 +110,4 @@ class Articolo extends Article
|
||||
|
||||
$this->fixIva();
|
||||
}
|
||||
|
||||
public function getSubtotaleAttribute()
|
||||
{
|
||||
return $this->prezzo_vendita * $this->qta;
|
||||
}
|
||||
}
|
||||
|
@ -4,8 +4,8 @@ namespace Modules\Interventi;
|
||||
|
||||
use Common\Document;
|
||||
use Modules\Anagrafiche\Anagrafica;
|
||||
use Modules\Interventi\Components\Riga;
|
||||
use Modules\Interventi\Components\Articolo;
|
||||
use Modules\Interventi\Components\Riga;
|
||||
|
||||
class Intervento extends Document
|
||||
{
|
||||
|
@ -5,7 +5,7 @@ include_once __DIR__.'/../../../core.php';
|
||||
switch ($resource) {
|
||||
case 'iva':
|
||||
$query = 'SELECT id, IF(codice IS NULL, descrizione, CONCAT(codice, " - ", descrizione)) AS descrizione FROM co_iva |where| ORDER BY descrizione ASC';
|
||||
|
||||
|
||||
foreach ($elements as $element) {
|
||||
$filter[] = 'id='.prepare($element);
|
||||
}
|
||||
@ -16,11 +16,11 @@ switch ($resource) {
|
||||
|
||||
if (empty($filter)) {
|
||||
$where[] = 'deleted_at IS NULL';
|
||||
|
||||
//se sto valorizzando un documento con lo split payment impedisco la selezione delle aliquote iva con natura N6 (reverse charge)
|
||||
if (isset($superselect['split_payment']) and !empty($superselect['split_payment'])) {
|
||||
$where[] = '(codice_natura_fe IS NULL OR codice_natura_fe != "N6")';
|
||||
}
|
||||
|
||||
//se sto valorizzando un documento con lo split payment impedisco la selezione delle aliquote iva con natura N6 (reverse charge)
|
||||
if (isset($superselect['split_payment']) and !empty($superselect['split_payment'])) {
|
||||
$where[] = '(codice_natura_fe IS NULL OR codice_natura_fe != "N6")';
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
|
@ -125,11 +125,11 @@ $(document).ready(function() {
|
||||
if ($(this).parent().find("i").hasClass('fa-eye')) {
|
||||
$("#password").attr("type", "text");
|
||||
$(this).parent().find("i").removeClass('fa-eye').addClass('fa-eye-slash');
|
||||
$(this).parent().find("i").attr('title', '<?php echo tr ('Nascondi password'); ?>');
|
||||
$(this).parent().find("i").attr('title', '<?php echo tr('Nascondi password'); ?>');
|
||||
} else {
|
||||
$("#password").attr("type", "password");
|
||||
$(this).parent().find("i").removeClass('fa-eye-slash').addClass('fa-eye');
|
||||
$(this).parent().find("i").attr('title', '<?php echo tr ('Visualizza password'); ?>');
|
||||
$(this).parent().find("i").attr('title', '<?php echo tr('Visualizza password'); ?>');
|
||||
}
|
||||
});
|
||||
});
|
||||
|
@ -13,23 +13,6 @@ class Connection
|
||||
{
|
||||
protected static $client = null;
|
||||
|
||||
/**
|
||||
* Restituisce l'oggetto per la connessione all'API del progetto.
|
||||
*
|
||||
* @return Client
|
||||
*/
|
||||
protected static function getClient()
|
||||
{
|
||||
if (!isset(self::$client)) {
|
||||
self::$client = new Client([
|
||||
'base_uri' => 'https://services.osmcloud.it/v1/',
|
||||
'verify' => false,
|
||||
]);
|
||||
}
|
||||
|
||||
return self::$client;
|
||||
}
|
||||
|
||||
public static function isEnabled()
|
||||
{
|
||||
return !empty(setting('OSMCloud Services API Token'));
|
||||
@ -68,4 +51,21 @@ class Connection
|
||||
|
||||
return json_decode($body, true) ?: [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Restituisce l'oggetto per la connessione all'API del progetto.
|
||||
*
|
||||
* @return Client
|
||||
*/
|
||||
protected static function getClient()
|
||||
{
|
||||
if (!isset(self::$client)) {
|
||||
self::$client = new Client([
|
||||
'base_uri' => 'https://services.osmcloud.it/v1/',
|
||||
'verify' => false,
|
||||
]);
|
||||
}
|
||||
|
||||
return self::$client;
|
||||
}
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -2,19 +2,19 @@
|
||||
|
||||
namespace Plugins\ImportFE;
|
||||
|
||||
use Modules\Fatture\Fattura;
|
||||
use Modules\Fatture\Components\Riga;
|
||||
use Modules\Fatture\Components\Articolo;
|
||||
use Modules;
|
||||
use Modules\Anagrafiche\Anagrafica;
|
||||
use Modules\Anagrafiche\Nazione;
|
||||
use Modules\Anagrafiche\Tipo as TipoAnagrafica;
|
||||
use Modules\Articoli\Articolo as ArticoloOriginale;
|
||||
use Modules\Fatture\Components\Articolo;
|
||||
use Modules\Fatture\Components\Riga;
|
||||
use Modules\Fatture\Fattura;
|
||||
use Modules\Fatture\Stato as StatoFattura;
|
||||
use Modules\Fatture\Tipo as TipoFattura;
|
||||
use Modules\Anagrafiche\Anagrafica;
|
||||
use Modules\Anagrafiche\Tipo as TipoAnagrafica;
|
||||
use Modules\Anagrafiche\Nazione;
|
||||
use Util\XML;
|
||||
use Uploads;
|
||||
use Modules;
|
||||
use UnexpectedValueException;
|
||||
use Uploads;
|
||||
use Util\XML;
|
||||
|
||||
/**
|
||||
* Classe per la gestione della fatturazione elettronica in XML.
|
||||
|
@ -2,8 +2,8 @@
|
||||
|
||||
include_once __DIR__.'/../../core.php';
|
||||
|
||||
use Plugins\ReceiptFE\Ricevuta;
|
||||
use Plugins\ReceiptFE\Interaction;
|
||||
use Plugins\ReceiptFE\Ricevuta;
|
||||
|
||||
switch (filter('op')) {
|
||||
case 'save':
|
||||
|
@ -3,8 +3,8 @@
|
||||
namespace Plugins\ReceiptFE;
|
||||
|
||||
use Modules\Fatture\Fattura;
|
||||
use Util\XML;
|
||||
use UnexpectedValueException;
|
||||
use Util\XML;
|
||||
|
||||
/**
|
||||
* Classe per la gestione della fatturazione elettronica in XML.
|
||||
|
202
src/AJAX.php
202
src/AJAX.php
@ -17,55 +17,6 @@ class AJAX
|
||||
return \Whoops\Util\Misc::isAjaxRequest() && filter('ajax') !== null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Individua i file per cui l'utente possiede i permessi di accesso.
|
||||
*
|
||||
* @param string $file
|
||||
* @param bool $permissions
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected static function find($file, $permissions = true)
|
||||
{
|
||||
$dirname = substr($file, 0, strrpos($file, '/') + 1);
|
||||
|
||||
// Individuazione delle cartelle accessibili
|
||||
if (!empty($permissions)) {
|
||||
$modules = Modules::getAvailableModules();
|
||||
} else {
|
||||
$modules = Modules::getModules();
|
||||
}
|
||||
|
||||
$modules = $modules->toArray();
|
||||
|
||||
$dirs = array_unique(array_column($modules, 'directory'));
|
||||
$pieces = array_chunk($dirs, 5);
|
||||
|
||||
// Individuazione dei file esistenti
|
||||
$list = [];
|
||||
foreach ($pieces as $piece) {
|
||||
// File nativi
|
||||
$files = glob(DOCROOT.'/modules/{'.implode(',', $piece).'}/'.$file, GLOB_BRACE);
|
||||
|
||||
// File personalizzati
|
||||
$custom_files = glob(DOCROOT.'/modules/{'.implode(',', $piece).'}/custom/'.$file, GLOB_BRACE);
|
||||
|
||||
// Pulizia dei file nativi che sono stati personalizzati
|
||||
foreach ($custom_files as $key => $value) {
|
||||
$index = array_search(str_replace('custom/'.$dirname, $dirname, $value), $files);
|
||||
if ($index !== false) {
|
||||
unset($files[$index]);
|
||||
}
|
||||
}
|
||||
|
||||
$list = array_merge($list, $files, $custom_files);
|
||||
}
|
||||
|
||||
asort($list);
|
||||
|
||||
return $list;
|
||||
}
|
||||
|
||||
/**
|
||||
* Individua le opzioni di selezione a partire dalla risorsa richiesta.
|
||||
*
|
||||
@ -138,6 +89,107 @@ class AJAX
|
||||
return $results;
|
||||
}
|
||||
|
||||
/**
|
||||
* Effettua la ricerca di un termine all'intero delle risorse disponibili.
|
||||
*
|
||||
* @param string $term
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function search($term)
|
||||
{
|
||||
if (strlen($term) < 2) {
|
||||
return;
|
||||
}
|
||||
|
||||
$files = self::find('ajax/search.php');
|
||||
|
||||
// File di gestione predefinita
|
||||
array_unshift($files, DOCROOT.'/ajax_search.php');
|
||||
|
||||
$results = [];
|
||||
foreach ($files as $file) {
|
||||
$module_results = self::getSearchResults($file, $term);
|
||||
|
||||
$results = array_merge($results, $module_results);
|
||||
}
|
||||
|
||||
return $results;
|
||||
}
|
||||
|
||||
/**
|
||||
* Completa il codice HTML per la risorsa richiesta.
|
||||
*
|
||||
* @param string $resource
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function complete($resource)
|
||||
{
|
||||
$files = self::find('ajax/complete.php');
|
||||
|
||||
// File di gestione predefinita
|
||||
array_unshift($files, DOCROOT.'/ajax_complete.php');
|
||||
|
||||
foreach ($files as $file) {
|
||||
$result = self::getCompleteResults($file, $resource);
|
||||
if (!empty($result)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Individua i file per cui l'utente possiede i permessi di accesso.
|
||||
*
|
||||
* @param string $file
|
||||
* @param bool $permissions
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected static function find($file, $permissions = true)
|
||||
{
|
||||
$dirname = substr($file, 0, strrpos($file, '/') + 1);
|
||||
|
||||
// Individuazione delle cartelle accessibili
|
||||
if (!empty($permissions)) {
|
||||
$modules = Modules::getAvailableModules();
|
||||
} else {
|
||||
$modules = Modules::getModules();
|
||||
}
|
||||
|
||||
$modules = $modules->toArray();
|
||||
|
||||
$dirs = array_unique(array_column($modules, 'directory'));
|
||||
$pieces = array_chunk($dirs, 5);
|
||||
|
||||
// Individuazione dei file esistenti
|
||||
$list = [];
|
||||
foreach ($pieces as $piece) {
|
||||
// File nativi
|
||||
$files = glob(DOCROOT.'/modules/{'.implode(',', $piece).'}/'.$file, GLOB_BRACE);
|
||||
|
||||
// File personalizzati
|
||||
$custom_files = glob(DOCROOT.'/modules/{'.implode(',', $piece).'}/custom/'.$file, GLOB_BRACE);
|
||||
|
||||
// Pulizia dei file nativi che sono stati personalizzati
|
||||
foreach ($custom_files as $key => $value) {
|
||||
$index = array_search(str_replace('custom/'.$dirname, $dirname, $value), $files);
|
||||
if ($index !== false) {
|
||||
unset($files[$index]);
|
||||
}
|
||||
}
|
||||
|
||||
$list = array_merge($list, $files, $custom_files);
|
||||
}
|
||||
|
||||
asort($list);
|
||||
|
||||
return $list;
|
||||
}
|
||||
|
||||
/**
|
||||
* Ottiene i risultati del select all'interno di un file specifico (modulo).
|
||||
*
|
||||
@ -181,34 +233,6 @@ class AJAX
|
||||
return !empty($_SESSION['superselect']) ? $_SESSION['superselect'] : [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Effettua la ricerca di un termine all'intero delle risorse disponibili.
|
||||
*
|
||||
* @param string $term
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function search($term)
|
||||
{
|
||||
if (strlen($term) < 2) {
|
||||
return;
|
||||
}
|
||||
|
||||
$files = self::find('ajax/search.php');
|
||||
|
||||
// File di gestione predefinita
|
||||
array_unshift($files, DOCROOT.'/ajax_search.php');
|
||||
|
||||
$results = [];
|
||||
foreach ($files as $file) {
|
||||
$module_results = self::getSearchResults($file, $term);
|
||||
|
||||
$results = array_merge($results, $module_results);
|
||||
}
|
||||
|
||||
return $results;
|
||||
}
|
||||
|
||||
/**
|
||||
* Ottiene i risultati della ricerca all'interno di un file specifico (modulo).
|
||||
*
|
||||
@ -245,30 +269,6 @@ class AJAX
|
||||
return $results;
|
||||
}
|
||||
|
||||
/**
|
||||
* Completa il codice HTML per la risorsa richiesta.
|
||||
*
|
||||
* @param string $resource
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function complete($resource)
|
||||
{
|
||||
$files = self::find('ajax/complete.php');
|
||||
|
||||
// File di gestione predefinita
|
||||
array_unshift($files, DOCROOT.'/ajax_complete.php');
|
||||
|
||||
foreach ($files as $file) {
|
||||
$result = self::getCompleteResults($file, $resource);
|
||||
if (!empty($result)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Ottiene i risultati della richiesta di completamento all'interno di un file specifico (modulo).
|
||||
*
|
||||
|
80
src/API.php
80
src/API.php
@ -194,46 +194,6 @@ class API extends \Util\Singleton
|
||||
return $this->fileRequest($request, 'delete');
|
||||
}
|
||||
|
||||
/**
|
||||
* Gestisce le richieste in modo generalizzato, con il relativo richiamo ai file specifici responsabili dell'operazione.
|
||||
*
|
||||
* @param array $request
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function fileRequest($request, $kind)
|
||||
{
|
||||
$user = Auth::user();
|
||||
$response = [];
|
||||
|
||||
// Controllo sulla compatibilità dell'API
|
||||
if (!self::isCompatible()) {
|
||||
return self::response([
|
||||
'status' => self::$status['incompatible']['code'],
|
||||
]);
|
||||
}
|
||||
|
||||
$resources = self::getResources()[$kind];
|
||||
$resource = $request['resource'];
|
||||
|
||||
if (!in_array($resource, array_keys($resources))) {
|
||||
return self::error('notFound');
|
||||
}
|
||||
|
||||
// Database
|
||||
$dbo = $database = database();
|
||||
|
||||
$database->beginTransaction();
|
||||
|
||||
// Esecuzione delle operazioni
|
||||
$filename = DOCROOT.'/modules/'.$resources[$resource].'/api/'.$kind.'.php';
|
||||
include $filename;
|
||||
|
||||
$database->commitTransaction();
|
||||
|
||||
return self::response($response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Genera i contenuti di risposta nel caso si verifichi un errore.
|
||||
*
|
||||
@ -416,4 +376,44 @@ class API extends \Util\Singleton
|
||||
|
||||
return version_compare($database->getMySQLVersion(), '5.6.5') >= 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gestisce le richieste in modo generalizzato, con il relativo richiamo ai file specifici responsabili dell'operazione.
|
||||
*
|
||||
* @param array $request
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function fileRequest($request, $kind)
|
||||
{
|
||||
$user = Auth::user();
|
||||
$response = [];
|
||||
|
||||
// Controllo sulla compatibilità dell'API
|
||||
if (!self::isCompatible()) {
|
||||
return self::response([
|
||||
'status' => self::$status['incompatible']['code'],
|
||||
]);
|
||||
}
|
||||
|
||||
$resources = self::getResources()[$kind];
|
||||
$resource = $request['resource'];
|
||||
|
||||
if (!in_array($resource, array_keys($resources))) {
|
||||
return self::error('notFound');
|
||||
}
|
||||
|
||||
// Database
|
||||
$dbo = $database = database();
|
||||
|
||||
$database->beginTransaction();
|
||||
|
||||
// Esecuzione delle operazioni
|
||||
$filename = DOCROOT.'/modules/'.$resources[$resource].'/api/'.$kind.'.php';
|
||||
include $filename;
|
||||
|
||||
$database->commitTransaction();
|
||||
|
||||
return self::response($response);
|
||||
}
|
||||
}
|
||||
|
274
src/App.php
274
src/App.php
@ -43,26 +43,6 @@ class App
|
||||
],
|
||||
];
|
||||
|
||||
/**
|
||||
* Restituisce la configurazione di default del progetto.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected static function getDefaultConfig()
|
||||
{
|
||||
if (file_exists(DOCROOT.'/config.example.php')) {
|
||||
include DOCROOT.'/config.example.php';
|
||||
}
|
||||
|
||||
$db_host = '';
|
||||
$db_username = '';
|
||||
$db_password = '';
|
||||
$db_name = '';
|
||||
$port = '';
|
||||
|
||||
return get_defined_vars();
|
||||
}
|
||||
|
||||
/**
|
||||
* Restituisce la configurazione dell'installazione in utilizzo del progetto.
|
||||
*
|
||||
@ -236,6 +216,143 @@ class App
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sostituisce i valori previsti all'interno delle query di moduli/plugin.
|
||||
*
|
||||
* @param string $query
|
||||
* @param int $custom
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function replacePlaceholder($query)
|
||||
{
|
||||
$id_parent = filter('id_parent');
|
||||
|
||||
$id_module = Modules::getCurrent()['id'];
|
||||
$segment = $_SESSION['module_'.$id_module]['id_segment'];
|
||||
|
||||
$user = Auth::user();
|
||||
|
||||
// Elenco delle sostituzioni
|
||||
$replace = [
|
||||
// Identificatori
|
||||
'|id_anagrafica|' => prepare($user['idanagrafica']),
|
||||
'|id_utente|' => prepare($user['id']),
|
||||
'|id_parent|' => prepare($id_parent),
|
||||
|
||||
// Date
|
||||
'|period_start|' => $_SESSION['period_start'],
|
||||
'|period_end|' => $_SESSION['period_end'],
|
||||
|
||||
// Segmenti
|
||||
'|segment|' => !empty($segment) ? ' AND id_segment = '.prepare($segment) : '',
|
||||
];
|
||||
|
||||
// Sostituzione dei formati
|
||||
$patterns = formatter()->getSQLPatterns();
|
||||
|
||||
foreach ($patterns as $key => $value) {
|
||||
$replace['|'.$key.'_format|'] = "'".$value."'";
|
||||
}
|
||||
|
||||
// Sostituzione effettiva
|
||||
$query = replace($query, $replace);
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
/**
|
||||
* Restituisce il codice HTML per il form contenente il file indicato.
|
||||
*
|
||||
* @param string $path
|
||||
* @param array $result
|
||||
* @param array $options
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function load($file, $result, $options)
|
||||
{
|
||||
$form = self::internalLoad('form.php', $result, $options);
|
||||
|
||||
$response = self::internalLoad($file, $result, $options);
|
||||
|
||||
$form = str_replace('|response|', $response, $form);
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Restituisce il codice HTML generato del file indicato.
|
||||
*
|
||||
* @param string $path
|
||||
* @param array $result
|
||||
* @param array $options
|
||||
* @param string $directory
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function internalLoad($file, $result, $options, $directory = null)
|
||||
{
|
||||
$module = Modules::getCurrent();
|
||||
|
||||
$id_module = $module['id'];
|
||||
$id_record = filter('id_record');
|
||||
|
||||
$directory = empty($directory) ? 'include|custom|/common/' : $directory;
|
||||
|
||||
ob_start();
|
||||
include self::filepath($directory, $file);
|
||||
$response = ob_get_clean();
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Individua il percorso per il file da includere considerando gli eventuali custom.
|
||||
*
|
||||
* @param string $path
|
||||
* @param string $file
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public static function filepath($path, $file = null)
|
||||
{
|
||||
$path = str_contains($path, DOCROOT) ? $path : DOCROOT.'/'.ltrim($path, '/');
|
||||
$path = empty($file) ? $path : rtrim($path, '/').'/'.$file;
|
||||
|
||||
$original_file = str_replace('|custom|', '', $path);
|
||||
$custom_file = str_replace('|custom|', '/custom', $path);
|
||||
|
||||
$result = '';
|
||||
if (file_exists($custom_file)) {
|
||||
$result = $custom_file;
|
||||
} elseif (file_exists($original_file)) {
|
||||
$result = $original_file;
|
||||
}
|
||||
|
||||
return slashes($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Restituisce la configurazione di default del progetto.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected static function getDefaultConfig()
|
||||
{
|
||||
if (file_exists(DOCROOT.'/config.example.php')) {
|
||||
include DOCROOT.'/config.example.php';
|
||||
}
|
||||
|
||||
$db_host = '';
|
||||
$db_username = '';
|
||||
$db_password = '';
|
||||
$db_name = '';
|
||||
$port = '';
|
||||
|
||||
return get_defined_vars();
|
||||
}
|
||||
|
||||
/**
|
||||
* Interpreta lo standard modulare per l'individuazione delle query di un modulo/plugin del progetto.
|
||||
*
|
||||
@ -363,121 +480,4 @@ class App
|
||||
|
||||
return $views;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sostituisce i valori previsti all'interno delle query di moduli/plugin.
|
||||
*
|
||||
* @param string $query
|
||||
* @param int $custom
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function replacePlaceholder($query)
|
||||
{
|
||||
$id_parent = filter('id_parent');
|
||||
|
||||
$id_module = Modules::getCurrent()['id'];
|
||||
$segment = $_SESSION['module_'.$id_module]['id_segment'];
|
||||
|
||||
$user = Auth::user();
|
||||
|
||||
// Elenco delle sostituzioni
|
||||
$replace = [
|
||||
// Identificatori
|
||||
'|id_anagrafica|' => prepare($user['idanagrafica']),
|
||||
'|id_utente|' => prepare($user['id']),
|
||||
'|id_parent|' => prepare($id_parent),
|
||||
|
||||
// Date
|
||||
'|period_start|' => $_SESSION['period_start'],
|
||||
'|period_end|' => $_SESSION['period_end'],
|
||||
|
||||
// Segmenti
|
||||
'|segment|' => !empty($segment) ? ' AND id_segment = '.prepare($segment) : '',
|
||||
];
|
||||
|
||||
// Sostituzione dei formati
|
||||
$patterns = formatter()->getSQLPatterns();
|
||||
|
||||
foreach ($patterns as $key => $value) {
|
||||
$replace['|'.$key.'_format|'] = "'".$value."'";
|
||||
}
|
||||
|
||||
// Sostituzione effettiva
|
||||
$query = replace($query, $replace);
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
/**
|
||||
* Restituisce il codice HTML per il form contenente il file indicato.
|
||||
*
|
||||
* @param string $path
|
||||
* @param array $result
|
||||
* @param array $options
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function load($file, $result, $options)
|
||||
{
|
||||
$form = self::internalLoad('form.php', $result, $options);
|
||||
|
||||
$response = self::internalLoad($file, $result, $options);
|
||||
|
||||
$form = str_replace('|response|', $response, $form);
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Restituisce il codice HTML generato del file indicato.
|
||||
*
|
||||
* @param string $path
|
||||
* @param array $result
|
||||
* @param array $options
|
||||
* @param string $directory
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function internalLoad($file, $result, $options, $directory = null)
|
||||
{
|
||||
$module = Modules::getCurrent();
|
||||
|
||||
$id_module = $module['id'];
|
||||
$id_record = filter('id_record');
|
||||
|
||||
$directory = empty($directory) ? 'include|custom|/common/' : $directory;
|
||||
|
||||
ob_start();
|
||||
include self::filepath($directory, $file);
|
||||
$response = ob_get_clean();
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Individua il percorso per il file da includere considerando gli eventuali custom.
|
||||
*
|
||||
* @param string $path
|
||||
* @param string $file
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public static function filepath($path, $file = null)
|
||||
{
|
||||
$path = str_contains($path, DOCROOT) ? $path : DOCROOT.'/'.ltrim($path, '/');
|
||||
$path = empty($file) ? $path : rtrim($path, '/').'/'.$file;
|
||||
|
||||
$original_file = str_replace('|custom|', '', $path);
|
||||
$custom_file = str_replace('|custom|', '/custom', $path);
|
||||
|
||||
$result = '';
|
||||
if (file_exists($custom_file)) {
|
||||
$result = $custom_file;
|
||||
} elseif (file_exists($original_file)) {
|
||||
$result = $original_file;
|
||||
}
|
||||
|
||||
return slashes($result);
|
||||
}
|
||||
}
|
||||
|
154
src/Auth.php
154
src/Auth.php
@ -147,83 +147,6 @@ class Auth extends \Util\Singleton
|
||||
return $this->isAuthenticated();
|
||||
}
|
||||
|
||||
/**
|
||||
* Controlla la corrispondenza delle password ed eventualmente effettua un rehashing.
|
||||
*
|
||||
* @param string $password
|
||||
* @param string $hash
|
||||
* @param int $user_id
|
||||
*/
|
||||
protected function password_check($password, $hash, $user_id)
|
||||
{
|
||||
$result = false;
|
||||
$rehash = false;
|
||||
|
||||
// Retrocompatibilità
|
||||
if ($hash == md5($password)) {
|
||||
$rehash = true;
|
||||
|
||||
$result = true;
|
||||
}
|
||||
|
||||
// Nuova versione
|
||||
if (password_verify($password, $hash)) {
|
||||
$rehash = password_needs_rehash($hash, self::$password_options['algorithm'], self::$password_options['options']);
|
||||
|
||||
$result = true;
|
||||
}
|
||||
|
||||
// Controllo in automatico per futuri cambiamenti dell'algoritmo di password
|
||||
if ($rehash) {
|
||||
$database = database();
|
||||
$database->update('zz_users', ['password' => self::hashPassword($password)], ['id' => $user_id]);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Memorizza le informazioni riguardanti l'utente all'interno della sessione.
|
||||
*/
|
||||
protected function saveToSession()
|
||||
{
|
||||
if (session_status() == PHP_SESSION_ACTIVE && $this->isAuthenticated()) {
|
||||
// Retrocompatibilità
|
||||
foreach ($this->user as $key => $value) {
|
||||
$_SESSION[$key] = $value;
|
||||
}
|
||||
$_SESSION['id_utente'] = $this->user->id;
|
||||
|
||||
$identifier = md5($_SESSION['id_utente'].$_SERVER['HTTP_USER_AGENT']);
|
||||
if ((empty($_SESSION['last_active']) || time() < $_SESSION['last_active'] + (60 * 60)) && (empty($_SESSION['identifier']) || $_SESSION['identifier'] == $identifier)) {
|
||||
$_SESSION['last_active'] = time();
|
||||
$_SESSION['identifier'] = $identifier;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Identifica l'utente interessato dall'autenticazione.
|
||||
*
|
||||
* @param int $user_id
|
||||
*/
|
||||
protected function identifyUser($user_id)
|
||||
{
|
||||
$database = database();
|
||||
|
||||
try {
|
||||
$results = $database->fetchArray('SELECT id, idanagrafica, username, (SELECT nome FROM zz_groups WHERE zz_groups.id = zz_users.idgruppo) AS gruppo FROM zz_users WHERE id = :user_id AND enabled = 1 LIMIT 1', [
|
||||
':user_id' => $user_id,
|
||||
], false, ['session' => false]);
|
||||
|
||||
if (!empty($results)) {
|
||||
$this->user = User::with('group')->find($user_id);
|
||||
}
|
||||
} catch (PDOException $e) {
|
||||
$this->destory();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Controlla se l'utente è autenticato.
|
||||
*
|
||||
@ -469,4 +392,81 @@ class Auth extends \Util\Singleton
|
||||
|
||||
return intval($results[0]['diff']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Controlla la corrispondenza delle password ed eventualmente effettua un rehashing.
|
||||
*
|
||||
* @param string $password
|
||||
* @param string $hash
|
||||
* @param int $user_id
|
||||
*/
|
||||
protected function password_check($password, $hash, $user_id)
|
||||
{
|
||||
$result = false;
|
||||
$rehash = false;
|
||||
|
||||
// Retrocompatibilità
|
||||
if ($hash == md5($password)) {
|
||||
$rehash = true;
|
||||
|
||||
$result = true;
|
||||
}
|
||||
|
||||
// Nuova versione
|
||||
if (password_verify($password, $hash)) {
|
||||
$rehash = password_needs_rehash($hash, self::$password_options['algorithm'], self::$password_options['options']);
|
||||
|
||||
$result = true;
|
||||
}
|
||||
|
||||
// Controllo in automatico per futuri cambiamenti dell'algoritmo di password
|
||||
if ($rehash) {
|
||||
$database = database();
|
||||
$database->update('zz_users', ['password' => self::hashPassword($password)], ['id' => $user_id]);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Memorizza le informazioni riguardanti l'utente all'interno della sessione.
|
||||
*/
|
||||
protected function saveToSession()
|
||||
{
|
||||
if (session_status() == PHP_SESSION_ACTIVE && $this->isAuthenticated()) {
|
||||
// Retrocompatibilità
|
||||
foreach ($this->user as $key => $value) {
|
||||
$_SESSION[$key] = $value;
|
||||
}
|
||||
$_SESSION['id_utente'] = $this->user->id;
|
||||
|
||||
$identifier = md5($_SESSION['id_utente'].$_SERVER['HTTP_USER_AGENT']);
|
||||
if ((empty($_SESSION['last_active']) || time() < $_SESSION['last_active'] + (60 * 60)) && (empty($_SESSION['identifier']) || $_SESSION['identifier'] == $identifier)) {
|
||||
$_SESSION['last_active'] = time();
|
||||
$_SESSION['identifier'] = $identifier;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Identifica l'utente interessato dall'autenticazione.
|
||||
*
|
||||
* @param int $user_id
|
||||
*/
|
||||
protected function identifyUser($user_id)
|
||||
{
|
||||
$database = database();
|
||||
|
||||
try {
|
||||
$results = $database->fetchArray('SELECT id, idanagrafica, username, (SELECT nome FROM zz_groups WHERE zz_groups.id = zz_users.idgruppo) AS gruppo FROM zz_users WHERE id = :user_id AND enabled = 1 LIMIT 1', [
|
||||
':user_id' => $user_id,
|
||||
], false, ['session' => false]);
|
||||
|
||||
if (!empty($results)) {
|
||||
$this->user = User::with('group')->find($user_id);
|
||||
}
|
||||
} catch (PDOException $e) {
|
||||
$this->destory();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
<?php
|
||||
|
||||
use Util\Zip;
|
||||
use Ifsnop\Mysqldump\Mysqldump;
|
||||
use Util\Zip;
|
||||
|
||||
/**
|
||||
* Classe per la gestione dei backup.
|
||||
@ -36,22 +36,6 @@ class Backup
|
||||
return slashes($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Restituisce il percorso su cui salvare temporeneamente il dump del database.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected static function getDatabaseDirectory()
|
||||
{
|
||||
$result = self::getDirectory().'/database';
|
||||
|
||||
if (!directory($result)) {
|
||||
throw new UnexpectedValueException();
|
||||
}
|
||||
|
||||
return slashes($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Restituisce l'elenco dei backup disponibili.
|
||||
*
|
||||
@ -83,24 +67,6 @@ class Backup
|
||||
return $results;
|
||||
}
|
||||
|
||||
/**
|
||||
* Restituisce l'elenco delle variabili da sostituire normalizzato per l'utilizzo.
|
||||
*/
|
||||
protected static function getReplaces()
|
||||
{
|
||||
return Util\Generator::getReplaces();
|
||||
}
|
||||
|
||||
/**
|
||||
* Restituisce il nome previsto per il backup successivo.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected static function getNextName()
|
||||
{
|
||||
return Util\Generator::generate(self::PATTERN);
|
||||
}
|
||||
|
||||
/**
|
||||
* Restituisce i valori utilizzati sulle variabili sostituite.
|
||||
*
|
||||
@ -270,4 +236,38 @@ class Backup
|
||||
}
|
||||
delete(DOCROOT.'/database.sql');
|
||||
}
|
||||
|
||||
/**
|
||||
* Restituisce il percorso su cui salvare temporeneamente il dump del database.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected static function getDatabaseDirectory()
|
||||
{
|
||||
$result = self::getDirectory().'/database';
|
||||
|
||||
if (!directory($result)) {
|
||||
throw new UnexpectedValueException();
|
||||
}
|
||||
|
||||
return slashes($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Restituisce l'elenco delle variabili da sostituire normalizzato per l'utilizzo.
|
||||
*/
|
||||
protected static function getReplaces()
|
||||
{
|
||||
return Util\Generator::getReplaces();
|
||||
}
|
||||
|
||||
/**
|
||||
* Restituisce il nome previsto per il backup successivo.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected static function getNextName()
|
||||
{
|
||||
return Util\Generator::generate(self::PATTERN);
|
||||
}
|
||||
}
|
||||
|
108
src/Database.php
108
src/Database.php
@ -378,22 +378,6 @@ class Database extends Util\Singleton
|
||||
return $this->getPDO()->quote($parameter);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepara il campo per l'inserimento in uno statement SQL.
|
||||
*
|
||||
* @since 2.3
|
||||
*
|
||||
* @param string $value
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function quote($string)
|
||||
{
|
||||
$char = '`';
|
||||
|
||||
return $char.str_replace([$char, '#'], '', $string).$char;
|
||||
}
|
||||
|
||||
/**
|
||||
* Costruisce la query per l'INSERT definito dagli argomenti.
|
||||
*
|
||||
@ -652,6 +636,60 @@ class Database extends Util\Singleton
|
||||
}
|
||||
}
|
||||
|
||||
public function beginTransaction()
|
||||
{
|
||||
Capsule::beginTransaction();
|
||||
}
|
||||
|
||||
public function commitTransaction()
|
||||
{
|
||||
Capsule::commit();
|
||||
}
|
||||
|
||||
/**
|
||||
* Esegue le query interne ad un file .sql.
|
||||
*
|
||||
* @since 2.0
|
||||
*
|
||||
* @param string $filename Percorso per raggiungere il file delle query
|
||||
* @param string $delimiter Delimitatore delle query
|
||||
*/
|
||||
public function multiQuery($filename, $start = 0)
|
||||
{
|
||||
$queries = readSQLFile($filename, ';');
|
||||
$end = count($queries);
|
||||
|
||||
for ($i = $start; $i < $end; ++$i) {
|
||||
try {
|
||||
$this->getPDO()->exec($queries[$i]);
|
||||
} catch (PDOException $e) {
|
||||
$this->signal($e, $queries[$i], [
|
||||
'throw' => false,
|
||||
]);
|
||||
|
||||
return $i;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepara il campo per l'inserimento in uno statement SQL.
|
||||
*
|
||||
* @since 2.3
|
||||
*
|
||||
* @param string $value
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function quote($string)
|
||||
{
|
||||
$char = '`';
|
||||
|
||||
return $char.str_replace([$char, '#'], '', $string).$char;
|
||||
}
|
||||
|
||||
/**
|
||||
* Predispone una variabile per il relativo inserimento all'interno di uno statement SQL.
|
||||
*
|
||||
@ -736,44 +774,6 @@ class Database extends Util\Singleton
|
||||
return implode(' '.$cond.' ', $result);
|
||||
}
|
||||
|
||||
public function beginTransaction()
|
||||
{
|
||||
Capsule::beginTransaction();
|
||||
}
|
||||
|
||||
public function commitTransaction()
|
||||
{
|
||||
Capsule::commit();
|
||||
}
|
||||
|
||||
/**
|
||||
* Esegue le query interne ad un file .sql.
|
||||
*
|
||||
* @since 2.0
|
||||
*
|
||||
* @param string $filename Percorso per raggiungere il file delle query
|
||||
* @param string $delimiter Delimitatore delle query
|
||||
*/
|
||||
public function multiQuery($filename, $start = 0)
|
||||
{
|
||||
$queries = readSQLFile($filename, ';');
|
||||
$end = count($queries);
|
||||
|
||||
for ($i = $start; $i < $end; ++$i) {
|
||||
try {
|
||||
$this->getPDO()->exec($queries[$i]);
|
||||
} catch (PDOException $e) {
|
||||
$this->signal($e, $queries[$i], [
|
||||
'throw' => false,
|
||||
]);
|
||||
|
||||
return $i;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Aggiunge informazioni alla struttura di base dell'erroe o dell'eccezione intercettata.
|
||||
*
|
||||
|
@ -13,6 +13,29 @@ class EloquentCollector extends \DebugBar\DataCollector\PDO\PDOCollector
|
||||
$this->addConnection($this->getTraceablePdo(), 'Eloquent PDO');
|
||||
}
|
||||
|
||||
// Override
|
||||
public function getName()
|
||||
{
|
||||
return 'eloquent_pdo';
|
||||
}
|
||||
|
||||
// Override
|
||||
public function getWidgets()
|
||||
{
|
||||
return [
|
||||
'eloquent' => [
|
||||
'icon' => 'inbox',
|
||||
'widget' => 'PhpDebugBar.Widgets.SQLQueriesWidget',
|
||||
'map' => 'eloquent_pdo',
|
||||
'default' => '[]',
|
||||
],
|
||||
'eloquent:badge' => [
|
||||
'map' => 'eloquent_pdo.nb_statements',
|
||||
'default' => 0,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Illuminate\Database\Capsule\Manager;
|
||||
*/
|
||||
@ -36,27 +59,4 @@ class EloquentCollector extends \DebugBar\DataCollector\PDO\PDOCollector
|
||||
{
|
||||
return new \DebugBar\DataCollector\PDO\TraceablePDO($this->getEloquentPdo());
|
||||
}
|
||||
|
||||
// Override
|
||||
public function getName()
|
||||
{
|
||||
return 'eloquent_pdo';
|
||||
}
|
||||
|
||||
// Override
|
||||
public function getWidgets()
|
||||
{
|
||||
return [
|
||||
'eloquent' => [
|
||||
'icon' => 'inbox',
|
||||
'widget' => 'PhpDebugBar.Widgets.SQLQueriesWidget',
|
||||
'map' => 'eloquent_pdo',
|
||||
'default' => '[]',
|
||||
],
|
||||
'eloquent:badge' => [
|
||||
'map' => 'eloquent_pdo.nb_statements',
|
||||
'default' => 0,
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
@ -134,6 +134,139 @@ class HTMLBuilder
|
||||
return $html;
|
||||
}
|
||||
|
||||
/**
|
||||
* Restituisce il nome della classe resposabile per la gestione di una determinata tipologia di tag di input.
|
||||
*
|
||||
* @param string $input
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function getHandlerName($input)
|
||||
{
|
||||
$result = empty(self::$handlers['list'][$input]) ? self::$handlers['list']['default'] : self::$handlers['list'][$input];
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Restituisce l'istanza della classe resposabile per la gestione di una determinata tipologia di tag di input.
|
||||
*
|
||||
* @param string $input
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public static function getHandler($input)
|
||||
{
|
||||
$class = self::getHandlerName($input);
|
||||
if (empty(self::$handlers['instances'][$class])) {
|
||||
self::$handlers['instances'][$class] = new $class();
|
||||
}
|
||||
|
||||
return self::$handlers['instances'][$class];
|
||||
}
|
||||
|
||||
/**
|
||||
* Imposta una determinata classe come resposabile per la gestione di una determinata tipologia di tag di input.
|
||||
*
|
||||
* @param string $input
|
||||
* @param string|mixed $class
|
||||
*/
|
||||
public static function setHandler($input, $class)
|
||||
{
|
||||
$original = $class;
|
||||
|
||||
$class = is_object($class) ? $class : new $class();
|
||||
|
||||
if ($class instanceof Handler\HandlerInterface) {
|
||||
self::$handlers['list'][$input] = $original;
|
||||
self::$handlers['instances'][$original] = $class;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Restituisce l'oggetto responsabile per la costruzione del codice HTML contenente gli input effettivi.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public static function getWrapper()
|
||||
{
|
||||
if (empty(self::$wrapper['instance'])) {
|
||||
$class = self::$wrapper['class'];
|
||||
self::$wrapper['instance'] = new $class();
|
||||
}
|
||||
|
||||
return self::$wrapper['instance'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Imposta l'oggetto responsabile per la costruzione del codice HTML contenente gli input effettivi.
|
||||
*
|
||||
* @param string|mixed $class
|
||||
*/
|
||||
public static function setWrapper($class)
|
||||
{
|
||||
$original = $class;
|
||||
|
||||
$class = is_object($class) ? $class : new $class();
|
||||
|
||||
if ($class instanceof Wrapper\WrapperInterface) {
|
||||
self::$wrapper['class'] = $original;
|
||||
self::$wrapper['instance'] = $class;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Restituisce l'oggetto responsabile per la costruzione del codice HTML per il tag personalizzato.
|
||||
*
|
||||
* @param string $input
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public static function getManager($input)
|
||||
{
|
||||
$result = null;
|
||||
|
||||
$class = self::$managers['list'][$input];
|
||||
if (!empty($class)) {
|
||||
if (empty(self::$managers['instances'][$class])) {
|
||||
self::$managers['instances'][$class] = new $class();
|
||||
}
|
||||
|
||||
$result = self::$managers['instances'][$class];
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Imposta l'oggetto responsabile per la costruzione del codice HTML per il tag personalizzato.
|
||||
*
|
||||
* @param string $input
|
||||
* @param string|mixed $class
|
||||
*/
|
||||
public static function setManager($input, $class)
|
||||
{
|
||||
$original = $class;
|
||||
|
||||
$class = is_object($class) ? $class : new $class();
|
||||
|
||||
if ($class instanceof Handler\ManagerInterface) {
|
||||
self::$managers['list'][$input] = $original;
|
||||
self::$managers['instances'][$original] = $class;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Imposta l'oggetto responsabile per la costruzione del codice HTML per il tag personalizzato.
|
||||
*
|
||||
* @param string $input
|
||||
* @param string|mixed $class
|
||||
*/
|
||||
public static function setRecord($record)
|
||||
{
|
||||
self::$record = $record;
|
||||
}
|
||||
|
||||
/**
|
||||
* Genera il codice HTML per i singoli tag di input.
|
||||
*
|
||||
@ -300,137 +433,4 @@ class HTMLBuilder
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Restituisce il nome della classe resposabile per la gestione di una determinata tipologia di tag di input.
|
||||
*
|
||||
* @param string $input
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function getHandlerName($input)
|
||||
{
|
||||
$result = empty(self::$handlers['list'][$input]) ? self::$handlers['list']['default'] : self::$handlers['list'][$input];
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Restituisce l'istanza della classe resposabile per la gestione di una determinata tipologia di tag di input.
|
||||
*
|
||||
* @param string $input
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public static function getHandler($input)
|
||||
{
|
||||
$class = self::getHandlerName($input);
|
||||
if (empty(self::$handlers['instances'][$class])) {
|
||||
self::$handlers['instances'][$class] = new $class();
|
||||
}
|
||||
|
||||
return self::$handlers['instances'][$class];
|
||||
}
|
||||
|
||||
/**
|
||||
* Imposta una determinata classe come resposabile per la gestione di una determinata tipologia di tag di input.
|
||||
*
|
||||
* @param string $input
|
||||
* @param string|mixed $class
|
||||
*/
|
||||
public static function setHandler($input, $class)
|
||||
{
|
||||
$original = $class;
|
||||
|
||||
$class = is_object($class) ? $class : new $class();
|
||||
|
||||
if ($class instanceof Handler\HandlerInterface) {
|
||||
self::$handlers['list'][$input] = $original;
|
||||
self::$handlers['instances'][$original] = $class;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Restituisce l'oggetto responsabile per la costruzione del codice HTML contenente gli input effettivi.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public static function getWrapper()
|
||||
{
|
||||
if (empty(self::$wrapper['instance'])) {
|
||||
$class = self::$wrapper['class'];
|
||||
self::$wrapper['instance'] = new $class();
|
||||
}
|
||||
|
||||
return self::$wrapper['instance'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Imposta l'oggetto responsabile per la costruzione del codice HTML contenente gli input effettivi.
|
||||
*
|
||||
* @param string|mixed $class
|
||||
*/
|
||||
public static function setWrapper($class)
|
||||
{
|
||||
$original = $class;
|
||||
|
||||
$class = is_object($class) ? $class : new $class();
|
||||
|
||||
if ($class instanceof Wrapper\WrapperInterface) {
|
||||
self::$wrapper['class'] = $original;
|
||||
self::$wrapper['instance'] = $class;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Restituisce l'oggetto responsabile per la costruzione del codice HTML per il tag personalizzato.
|
||||
*
|
||||
* @param string $input
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public static function getManager($input)
|
||||
{
|
||||
$result = null;
|
||||
|
||||
$class = self::$managers['list'][$input];
|
||||
if (!empty($class)) {
|
||||
if (empty(self::$managers['instances'][$class])) {
|
||||
self::$managers['instances'][$class] = new $class();
|
||||
}
|
||||
|
||||
$result = self::$managers['instances'][$class];
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Imposta l'oggetto responsabile per la costruzione del codice HTML per il tag personalizzato.
|
||||
*
|
||||
* @param string $input
|
||||
* @param string|mixed $class
|
||||
*/
|
||||
public static function setManager($input, $class)
|
||||
{
|
||||
$original = $class;
|
||||
|
||||
$class = is_object($class) ? $class : new $class();
|
||||
|
||||
if ($class instanceof Handler\ManagerInterface) {
|
||||
self::$managers['list'][$input] = $original;
|
||||
self::$managers['instances'][$original] = $class;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Imposta l'oggetto responsabile per la costruzione del codice HTML per il tag personalizzato.
|
||||
*
|
||||
* @param string $input
|
||||
* @param string|mixed $class
|
||||
*/
|
||||
public static function setRecord($record)
|
||||
{
|
||||
self::$record = $record;
|
||||
}
|
||||
}
|
||||
|
@ -2,8 +2,8 @@
|
||||
|
||||
namespace HTMLBuilder\Manager;
|
||||
|
||||
use Translator;
|
||||
use Prints;
|
||||
use Translator;
|
||||
|
||||
/**
|
||||
* Gestione allegati.
|
||||
|
108
src/Mail.php
108
src/Mail.php
@ -20,6 +20,60 @@ class Mail extends PHPMailer\PHPMailer\PHPMailer
|
||||
|
||||
protected $infos = [];
|
||||
|
||||
public function __construct($account = null, $exceptions = null)
|
||||
{
|
||||
parent::__construct($exceptions);
|
||||
|
||||
$this->CharSet = 'UTF-8';
|
||||
|
||||
// Configurazione di base
|
||||
$config = self::get($account);
|
||||
|
||||
// Preparazione email
|
||||
$this->IsHTML(true);
|
||||
|
||||
if (!empty($config['server'])) {
|
||||
$this->IsSMTP(true);
|
||||
|
||||
// Impostazioni di debug
|
||||
$this->SMTPDebug = App::debug() ? 2 : 0;
|
||||
$this->Debugoutput = function ($str, $level) {
|
||||
$this->infos[] = $str;
|
||||
};
|
||||
|
||||
// Impostazioni dell'host
|
||||
$this->Host = $config['server'];
|
||||
$this->Port = $config['port'];
|
||||
|
||||
// Impostazioni di autenticazione
|
||||
if (!empty($config['username'])) {
|
||||
$this->SMTPAuth = true;
|
||||
$this->Username = $config['username'];
|
||||
$this->Password = $config['password'];
|
||||
}
|
||||
|
||||
// Impostazioni di sicurezza
|
||||
if (in_array(strtolower($config['encryption']), ['ssl', 'tls'])) {
|
||||
$this->SMTPSecure = strtolower($config['encryption']);
|
||||
}
|
||||
|
||||
if (!empty($config['ssl_no_verify'])) {
|
||||
$this->SMTPOptions = [
|
||||
'ssl' => [
|
||||
'verify_peer' => false,
|
||||
'verify_peer_name' => false,
|
||||
'allow_self_signed' => true,
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
$this->From = $config['from_address'];
|
||||
$this->FromName = $config['from_name'];
|
||||
|
||||
$this->WordWrap = 78;
|
||||
}
|
||||
|
||||
/**
|
||||
* Restituisce tutte le informazioni di tutti gli account email presenti.
|
||||
*
|
||||
@ -145,60 +199,6 @@ class Mail extends PHPMailer\PHPMailer\PHPMailer
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function __construct($account = null, $exceptions = null)
|
||||
{
|
||||
parent::__construct($exceptions);
|
||||
|
||||
$this->CharSet = 'UTF-8';
|
||||
|
||||
// Configurazione di base
|
||||
$config = self::get($account);
|
||||
|
||||
// Preparazione email
|
||||
$this->IsHTML(true);
|
||||
|
||||
if (!empty($config['server'])) {
|
||||
$this->IsSMTP(true);
|
||||
|
||||
// Impostazioni di debug
|
||||
$this->SMTPDebug = App::debug() ? 2 : 0;
|
||||
$this->Debugoutput = function ($str, $level) {
|
||||
$this->infos[] = $str;
|
||||
};
|
||||
|
||||
// Impostazioni dell'host
|
||||
$this->Host = $config['server'];
|
||||
$this->Port = $config['port'];
|
||||
|
||||
// Impostazioni di autenticazione
|
||||
if (!empty($config['username'])) {
|
||||
$this->SMTPAuth = true;
|
||||
$this->Username = $config['username'];
|
||||
$this->Password = $config['password'];
|
||||
}
|
||||
|
||||
// Impostazioni di sicurezza
|
||||
if (in_array(strtolower($config['encryption']), ['ssl', 'tls'])) {
|
||||
$this->SMTPSecure = strtolower($config['encryption']);
|
||||
}
|
||||
|
||||
if (!empty($config['ssl_no_verify'])) {
|
||||
$this->SMTPOptions = [
|
||||
'ssl' => [
|
||||
'verify_peer' => false,
|
||||
'verify_peer_name' => false,
|
||||
'allow_self_signed' => true,
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
$this->From = $config['from_address'];
|
||||
$this->FromName = $config['from_name'];
|
||||
|
||||
$this->WordWrap = 78;
|
||||
}
|
||||
|
||||
/**
|
||||
* Testa la connessione al server SMTP.
|
||||
*
|
||||
|
@ -2,8 +2,8 @@
|
||||
|
||||
namespace Models;
|
||||
|
||||
use Common\Model;
|
||||
use App;
|
||||
use Common\Model;
|
||||
|
||||
class Clause extends Model
|
||||
{
|
||||
|
@ -2,9 +2,9 @@
|
||||
|
||||
namespace Models;
|
||||
|
||||
use Traits\StoreTrait;
|
||||
use Common\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use Traits\StoreTrait;
|
||||
|
||||
class MailAccount extends Model
|
||||
{
|
||||
|
@ -2,9 +2,9 @@
|
||||
|
||||
namespace Models;
|
||||
|
||||
use Traits\StoreTrait;
|
||||
use Common\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use Traits\StoreTrait;
|
||||
|
||||
class MailTemplate extends Model
|
||||
{
|
||||
|
@ -3,11 +3,11 @@
|
||||
namespace Models;
|
||||
|
||||
use Auth;
|
||||
use Traits\ManagerTrait;
|
||||
use Traits\UploadTrait;
|
||||
use Traits\StoreTrait;
|
||||
use Common\Model;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Traits\ManagerTrait;
|
||||
use Traits\StoreTrait;
|
||||
use Traits\UploadTrait;
|
||||
|
||||
class Module extends Model
|
||||
{
|
||||
@ -27,19 +27,6 @@ class Module extends Model
|
||||
'options2',
|
||||
];
|
||||
|
||||
protected static function boot()
|
||||
{
|
||||
parent::boot();
|
||||
|
||||
static::addGlobalScope('enabled', function (Builder $builder) {
|
||||
$builder->where('enabled', true);
|
||||
});
|
||||
|
||||
static::addGlobalScope('permission', function (Builder $builder) {
|
||||
$builder->with('groups');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Restituisce i permessi relativi all'account in utilizzo.
|
||||
*
|
||||
@ -150,4 +137,17 @@ class Module extends Model
|
||||
->orderBy('order')
|
||||
->get();
|
||||
}
|
||||
|
||||
protected static function boot()
|
||||
{
|
||||
parent::boot();
|
||||
|
||||
static::addGlobalScope('enabled', function (Builder $builder) {
|
||||
$builder->where('enabled', true);
|
||||
});
|
||||
|
||||
static::addGlobalScope('permission', function (Builder $builder) {
|
||||
$builder->with('groups');
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -3,11 +3,11 @@
|
||||
namespace Models;
|
||||
|
||||
use App;
|
||||
use Traits\ManagerTrait;
|
||||
use Traits\UploadTrait;
|
||||
use Traits\StoreTrait;
|
||||
use Common\Model;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Traits\ManagerTrait;
|
||||
use Traits\StoreTrait;
|
||||
use Traits\UploadTrait;
|
||||
|
||||
class Plugin extends Model
|
||||
{
|
||||
@ -30,15 +30,6 @@ class Plugin extends Model
|
||||
'options2',
|
||||
];
|
||||
|
||||
protected static function boot()
|
||||
{
|
||||
parent::boot();
|
||||
|
||||
static::addGlobalScope('enabled', function (Builder $builder) {
|
||||
$builder->where('enabled', true);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Restituisce i permessi relativi all'account in utilizzo.
|
||||
*
|
||||
@ -111,4 +102,13 @@ class Plugin extends Model
|
||||
{
|
||||
return $this->belongsTo(Module::class, 'idmodule_to');
|
||||
}
|
||||
|
||||
protected static function boot()
|
||||
{
|
||||
parent::boot();
|
||||
|
||||
static::addGlobalScope('enabled', function (Builder $builder) {
|
||||
$builder->where('enabled', true);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -2,9 +2,9 @@
|
||||
|
||||
namespace Models;
|
||||
|
||||
use Common\Model;
|
||||
use Traits\PathTrait;
|
||||
use Traits\StoreTrait;
|
||||
use Common\Model;
|
||||
|
||||
class PrintTemplate extends Model
|
||||
{
|
||||
@ -13,6 +13,13 @@ class PrintTemplate extends Model
|
||||
protected $table = 'zz_prints';
|
||||
protected $main_folder = 'templates';
|
||||
|
||||
/* Relazioni Eloquent */
|
||||
|
||||
public function module()
|
||||
{
|
||||
return $this->belongsTo(Module::class, 'id_module');
|
||||
}
|
||||
|
||||
protected static function boot()
|
||||
{
|
||||
parent::boot();
|
||||
@ -21,11 +28,4 @@ class PrintTemplate extends Model
|
||||
$builder->where('enabled', true);
|
||||
});
|
||||
}
|
||||
|
||||
/* Relazioni Eloquent */
|
||||
|
||||
public function module()
|
||||
{
|
||||
return $this->belongsTo(Module::class, 'id_module');
|
||||
}
|
||||
}
|
||||
|
@ -2,8 +2,8 @@
|
||||
|
||||
namespace Models;
|
||||
|
||||
use Traits\StoreTrait;
|
||||
use Common\Model;
|
||||
use Traits\StoreTrait;
|
||||
|
||||
class Setting extends Model
|
||||
{
|
||||
|
@ -2,8 +2,8 @@
|
||||
|
||||
namespace Models;
|
||||
|
||||
use Common\Model;
|
||||
use App;
|
||||
use Common\Model;
|
||||
|
||||
class View extends Model
|
||||
{
|
||||
|
@ -242,6 +242,55 @@ class Modules
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Costruisce un link HTML per il modulo e il record indicati.
|
||||
*
|
||||
* @param string|int $modulo
|
||||
* @param int $id_record
|
||||
* @param string $testo
|
||||
* @param string $alternativo
|
||||
* @param string $extra
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function link($modulo, $id_record = null, $testo = null, $alternativo = true, $extra = null, $blank = true)
|
||||
{
|
||||
$testo = isset($testo) ? nl2br($testo) : tr('Visualizza scheda');
|
||||
$alternativo = is_bool($alternativo) && $alternativo ? $testo : $alternativo;
|
||||
|
||||
// Aggiunta automatica dell'icona di riferimento
|
||||
if (!str_contains($testo, '<i ')) {
|
||||
$testo = $testo.' <i class="fa fa-external-link"></i>';
|
||||
}
|
||||
|
||||
$module = self::get($modulo);
|
||||
|
||||
$extra .= !empty($blank) ? ' target="_blank"' : '';
|
||||
|
||||
if (!empty($module) && in_array($module->permission, ['r', 'rw'])) {
|
||||
$link = !empty($id_record) ? 'editor.php?id_module='.$module['id'].'&id_record='.$id_record : 'controller.php?id_module='.$module['id'];
|
||||
|
||||
return '<a href="'.ROOTDIR.'/'.$link.'" '.$extra.'>'.$testo.'</a>';
|
||||
} else {
|
||||
return $alternativo;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Individua il percorso per il file.
|
||||
*
|
||||
* @param string|int $element
|
||||
* @param string $file
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public static function filepath($element, $file)
|
||||
{
|
||||
$element = self::get($element);
|
||||
|
||||
return $element ? $element->filepath($file) : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Restituisce l'insieme dei menu derivato da un'array strutturato ad albero.
|
||||
*
|
||||
@ -307,53 +356,4 @@ class Modules
|
||||
|
||||
return [$result, $active, $show];
|
||||
}
|
||||
|
||||
/**
|
||||
* Costruisce un link HTML per il modulo e il record indicati.
|
||||
*
|
||||
* @param string|int $modulo
|
||||
* @param int $id_record
|
||||
* @param string $testo
|
||||
* @param string $alternativo
|
||||
* @param string $extra
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function link($modulo, $id_record = null, $testo = null, $alternativo = true, $extra = null, $blank = true)
|
||||
{
|
||||
$testo = isset($testo) ? nl2br($testo) : tr('Visualizza scheda');
|
||||
$alternativo = is_bool($alternativo) && $alternativo ? $testo : $alternativo;
|
||||
|
||||
// Aggiunta automatica dell'icona di riferimento
|
||||
if (!str_contains($testo, '<i ')) {
|
||||
$testo = $testo.' <i class="fa fa-external-link"></i>';
|
||||
}
|
||||
|
||||
$module = self::get($modulo);
|
||||
|
||||
$extra .= !empty($blank) ? ' target="_blank"' : '';
|
||||
|
||||
if (!empty($module) && in_array($module->permission, ['r', 'rw'])) {
|
||||
$link = !empty($id_record) ? 'editor.php?id_module='.$module['id'].'&id_record='.$id_record : 'controller.php?id_module='.$module['id'];
|
||||
|
||||
return '<a href="'.ROOTDIR.'/'.$link.'" '.$extra.'>'.$testo.'</a>';
|
||||
} else {
|
||||
return $alternativo;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Individua il percorso per il file.
|
||||
*
|
||||
* @param string|int $element
|
||||
* @param string $file
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public static function filepath($element, $file)
|
||||
{
|
||||
$element = self::get($element);
|
||||
|
||||
return $element ? $element->filepath($file) : null;
|
||||
}
|
||||
}
|
||||
|
@ -3,9 +3,9 @@
|
||||
namespace Notifications;
|
||||
|
||||
use Mail;
|
||||
use PHPMailer\PHPMailer\Exception as PHPMailerException;
|
||||
use Prints;
|
||||
use Uploads;
|
||||
use PHPMailer\PHPMailer\Exception as PHPMailerException;
|
||||
|
||||
class EmailNotification extends Notification
|
||||
{
|
||||
|
198
src/Prints.php
198
src/Prints.php
@ -155,6 +155,105 @@ class Prints
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Individua il link per la stampa.
|
||||
*
|
||||
* @param string|int $print
|
||||
* @param int $id_record
|
||||
* @param string $get
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function getHref($print, $id_record, $get = '')
|
||||
{
|
||||
$infos = self::get($print);
|
||||
|
||||
if (empty($infos)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$link = ROOTDIR.'/pdfgen.php?';
|
||||
|
||||
if (self::isOldStandard($infos['id'])) {
|
||||
$link .= 'ptype='.$infos['directory'];
|
||||
|
||||
$link .= !empty($infos['previous']) && !empty($id_record) ? '&'.$infos['previous'].'='.$id_record : '';
|
||||
} else {
|
||||
$link .= 'id_print='.$infos['id'];
|
||||
|
||||
$link .= !empty($id_record) ? '&id_record='.$id_record : '';
|
||||
}
|
||||
|
||||
$link .= !empty($get) ? '&'.$get : '';
|
||||
|
||||
return $link;
|
||||
}
|
||||
|
||||
/**
|
||||
* Restituisce il codice semplificato per il link alla stampa.
|
||||
*
|
||||
* @deprecated 2.4.1
|
||||
*
|
||||
* @param string|int $print
|
||||
* @param int $id_record
|
||||
* @param string $btn
|
||||
* @param string $title
|
||||
* @param string $icon
|
||||
* @param string $get
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function getLink($print, $id_record, $btn = null, $title = null, $icon = null, $get = '')
|
||||
{
|
||||
return '{( "name": "button", "type": "print", "id": "'.$print.'", "id_record": "'.$id_record.'", "label": "'.$title.'", "icon": "'.$icon.'", "parameters": "'.$get.'", "class": "'.$btn.'" )}';
|
||||
}
|
||||
|
||||
/**
|
||||
* Restituisce il link per la visualizzazione della stampa.
|
||||
*
|
||||
* @param string|int $print
|
||||
* @param int $id_record
|
||||
* @param string $filename
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function getPreviewLink($print, $id_record, $filename)
|
||||
{
|
||||
self::render($print, $id_record, $filename);
|
||||
|
||||
return self::getPDFLink($filename);
|
||||
}
|
||||
|
||||
/**
|
||||
* Restituisce il link per la visualizzazione del PDF.
|
||||
*
|
||||
* @param string|int $print
|
||||
* @param int $id_record
|
||||
* @param string $filename
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function getPDFLink($filename)
|
||||
{
|
||||
return ROOTDIR.'/assets/dist/pdfjs/web/viewer.html?file=../../../../'.ltrim(str_replace(DOCROOT, '', $filename), '/');
|
||||
}
|
||||
|
||||
/**
|
||||
* Individua il percorso per il file.
|
||||
*
|
||||
* @param string|int $template
|
||||
* @param string $file
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public static function filepath($template, $file)
|
||||
{
|
||||
$template = self::get($template);
|
||||
$directory = 'templates/'.$template['directory'].'|custom|';
|
||||
|
||||
return App::filepath($directory, $file);
|
||||
}
|
||||
|
||||
/**
|
||||
* Restituisce un array associativo dalla codifica JSON delle opzioni di stampa.
|
||||
*
|
||||
@ -383,103 +482,4 @@ class Prints
|
||||
// Creazione effettiva del PDF
|
||||
$mpdf->Output($filename, $mode);
|
||||
}
|
||||
|
||||
/**
|
||||
* Individua il link per la stampa.
|
||||
*
|
||||
* @param string|int $print
|
||||
* @param int $id_record
|
||||
* @param string $get
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function getHref($print, $id_record, $get = '')
|
||||
{
|
||||
$infos = self::get($print);
|
||||
|
||||
if (empty($infos)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$link = ROOTDIR.'/pdfgen.php?';
|
||||
|
||||
if (self::isOldStandard($infos['id'])) {
|
||||
$link .= 'ptype='.$infos['directory'];
|
||||
|
||||
$link .= !empty($infos['previous']) && !empty($id_record) ? '&'.$infos['previous'].'='.$id_record : '';
|
||||
} else {
|
||||
$link .= 'id_print='.$infos['id'];
|
||||
|
||||
$link .= !empty($id_record) ? '&id_record='.$id_record : '';
|
||||
}
|
||||
|
||||
$link .= !empty($get) ? '&'.$get : '';
|
||||
|
||||
return $link;
|
||||
}
|
||||
|
||||
/**
|
||||
* Restituisce il codice semplificato per il link alla stampa.
|
||||
*
|
||||
* @deprecated 2.4.1
|
||||
*
|
||||
* @param string|int $print
|
||||
* @param int $id_record
|
||||
* @param string $btn
|
||||
* @param string $title
|
||||
* @param string $icon
|
||||
* @param string $get
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function getLink($print, $id_record, $btn = null, $title = null, $icon = null, $get = '')
|
||||
{
|
||||
return '{( "name": "button", "type": "print", "id": "'.$print.'", "id_record": "'.$id_record.'", "label": "'.$title.'", "icon": "'.$icon.'", "parameters": "'.$get.'", "class": "'.$btn.'" )}';
|
||||
}
|
||||
|
||||
/**
|
||||
* Restituisce il link per la visualizzazione della stampa.
|
||||
*
|
||||
* @param string|int $print
|
||||
* @param int $id_record
|
||||
* @param string $filename
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function getPreviewLink($print, $id_record, $filename)
|
||||
{
|
||||
self::render($print, $id_record, $filename);
|
||||
|
||||
return self::getPDFLink($filename);
|
||||
}
|
||||
|
||||
/**
|
||||
* Restituisce il link per la visualizzazione del PDF.
|
||||
*
|
||||
* @param string|int $print
|
||||
* @param int $id_record
|
||||
* @param string $filename
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function getPDFLink($filename)
|
||||
{
|
||||
return ROOTDIR.'/assets/dist/pdfjs/web/viewer.html?file=../../../../'.ltrim(str_replace(DOCROOT, '', $filename), '/');
|
||||
}
|
||||
|
||||
/**
|
||||
* Individua il percorso per il file.
|
||||
*
|
||||
* @param string|int $template
|
||||
* @param string $file
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public static function filepath($template, $file)
|
||||
{
|
||||
$template = self::get($template);
|
||||
$directory = 'templates/'.$template['directory'].'|custom|';
|
||||
|
||||
return App::filepath($directory, $file);
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
<?php
|
||||
|
||||
use Respect\Validation\Validator as v;
|
||||
use Models\Setting;
|
||||
use Respect\Validation\Validator as v;
|
||||
|
||||
/**
|
||||
* Classe per la gestione dell impostazioni del progetto.
|
||||
|
@ -46,46 +46,6 @@ class Translator extends Util\Singleton
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Aggiunge i contenuti della cartella specificata alle traduzioni disponibili.
|
||||
*
|
||||
* @param string $path
|
||||
*/
|
||||
protected function addLocales($path)
|
||||
{
|
||||
// Individua i linguaggi disponibili
|
||||
$dirs = glob($path.DIRECTORY_SEPARATOR.'*', GLOB_ONLYDIR);
|
||||
foreach ($dirs as $dir) {
|
||||
$this->addLocale(basename($dir));
|
||||
}
|
||||
|
||||
// Aggiunge le singole traduzioni
|
||||
foreach ($this->locales as $lang) {
|
||||
$done = [];
|
||||
|
||||
$files = glob($path.DIRECTORY_SEPARATOR.$lang.DIRECTORY_SEPARATOR.'*.*');
|
||||
foreach ($files as $file) {
|
||||
if (!in_array(basename($file), $done)) {
|
||||
$this->translator->addResource('default', $file, $lang);
|
||||
|
||||
$done[] = basename($file);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Aggiunge il linguaggio indicato all'elenco di quelli disponibili.
|
||||
*
|
||||
* @param string $language
|
||||
*/
|
||||
protected function addLocale($language)
|
||||
{
|
||||
if (!$this->isLocaleAvailable($language)) {
|
||||
$this->locales[] = $language;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Restituisce l'elenco dei linguaggi disponibili.
|
||||
*
|
||||
@ -174,25 +134,6 @@ class Translator extends Util\Singleton
|
||||
return (string) $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Imposta l'oggetto responsabile della localizzazione di date e numeri.
|
||||
*/
|
||||
protected static function setFormatter($locale, $options)
|
||||
{
|
||||
self::$formatter = new Intl\Formatter(
|
||||
$locale,
|
||||
empty($options['timestamp']) ? 'd/m/Y H:i' : $options['timestamp'],
|
||||
empty($options['date']) ? 'd/m/Y' : $options['date'],
|
||||
empty($options['time']) ? 'H:i' : $options['time'],
|
||||
empty($options['number']) ? [
|
||||
'decimals' => ',',
|
||||
'thousands' => '.',
|
||||
] : $options['number']
|
||||
);
|
||||
|
||||
self::$formatter->setPrecision(auth()->check() ? setting('Cifre decimali per importi') : 2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Restituisce l'oggetto responsabile della localizzazione di date e numeri.
|
||||
*
|
||||
@ -308,4 +249,63 @@ class Translator extends Util\Singleton
|
||||
{
|
||||
return self::getFormatter()->formatTimestamp($string);
|
||||
}
|
||||
|
||||
/**
|
||||
* Aggiunge i contenuti della cartella specificata alle traduzioni disponibili.
|
||||
*
|
||||
* @param string $path
|
||||
*/
|
||||
protected function addLocales($path)
|
||||
{
|
||||
// Individua i linguaggi disponibili
|
||||
$dirs = glob($path.DIRECTORY_SEPARATOR.'*', GLOB_ONLYDIR);
|
||||
foreach ($dirs as $dir) {
|
||||
$this->addLocale(basename($dir));
|
||||
}
|
||||
|
||||
// Aggiunge le singole traduzioni
|
||||
foreach ($this->locales as $lang) {
|
||||
$done = [];
|
||||
|
||||
$files = glob($path.DIRECTORY_SEPARATOR.$lang.DIRECTORY_SEPARATOR.'*.*');
|
||||
foreach ($files as $file) {
|
||||
if (!in_array(basename($file), $done)) {
|
||||
$this->translator->addResource('default', $file, $lang);
|
||||
|
||||
$done[] = basename($file);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Aggiunge il linguaggio indicato all'elenco di quelli disponibili.
|
||||
*
|
||||
* @param string $language
|
||||
*/
|
||||
protected function addLocale($language)
|
||||
{
|
||||
if (!$this->isLocaleAvailable($language)) {
|
||||
$this->locales[] = $language;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Imposta l'oggetto responsabile della localizzazione di date e numeri.
|
||||
*/
|
||||
protected static function setFormatter($locale, $options)
|
||||
{
|
||||
self::$formatter = new Intl\Formatter(
|
||||
$locale,
|
||||
empty($options['timestamp']) ? 'd/m/Y H:i' : $options['timestamp'],
|
||||
empty($options['date']) ? 'd/m/Y' : $options['date'],
|
||||
empty($options['time']) ? 'H:i' : $options['time'],
|
||||
empty($options['number']) ? [
|
||||
'decimals' => ',',
|
||||
'thousands' => '.',
|
||||
] : $options['number']
|
||||
);
|
||||
|
||||
self::$formatter->setPrecision(auth()->check() ? setting('Cifre decimali per importi') : 2);
|
||||
}
|
||||
}
|
||||
|
340
src/Update.php
340
src/Update.php
@ -15,154 +15,6 @@ class Update
|
||||
'plugins',
|
||||
];
|
||||
|
||||
/**
|
||||
* Controlla la presenza di aggiornamenti e prepara il database per la procedura.
|
||||
*/
|
||||
protected static function prepareToUpdate()
|
||||
{
|
||||
$database = database();
|
||||
|
||||
$database_ready = $database->isConnected() && $database->tableExists('updates');
|
||||
|
||||
// Individuazione di tutti gli aggiornamenti presenti
|
||||
// Aggiornamenti del gestionale
|
||||
$core = self::getCoreUpdates();
|
||||
|
||||
// Aggiornamenti supportati
|
||||
$modules = self::getCustomUpdates();
|
||||
|
||||
$results = array_merge($core, $modules);
|
||||
$paths = array_column($results, 'path');
|
||||
|
||||
// Individuazione di tutti gli aggiornamenti inseriti nel database
|
||||
$updates = ($database_ready) ? $database->fetchArray('SELECT * FROM `updates`') : [];
|
||||
$versions = [];
|
||||
foreach ($updates as $update) {
|
||||
$versions[] = self::findUpdatePath($update);
|
||||
}
|
||||
|
||||
$reset = count(array_intersect($paths, $versions)) != count($results);
|
||||
|
||||
// Memorizzazione degli aggiornamenti
|
||||
if ($reset && $database->isConnected()) {
|
||||
// Reimpostazione della tabella degli aggiornamenti
|
||||
$create = DOCROOT.'/update/create_updates.sql';
|
||||
if (file_exists($create)) {
|
||||
$database->query('DROP TABLE IF EXISTS `updates`');
|
||||
$database->multiQuery($create);
|
||||
}
|
||||
|
||||
// Inserimento degli aggiornamenti individuati
|
||||
foreach ($results as $result) {
|
||||
// Individuazione di script e sql
|
||||
$sql = file_exists($result['path'].'.sql') ? 1 : 0;
|
||||
$script = file_exists($result['path'].'.php') ? 1 : 0;
|
||||
|
||||
// Reimpostazione degli stati per gli aggiornamenti precedentemente presenti
|
||||
$pos = array_search($result['path'], $versions);
|
||||
$done = ($pos !== false) ? $updates[$pos]['done'] : null;
|
||||
|
||||
$directory = explode('update/', $result['path'])[0];
|
||||
$database->insert('updates', [
|
||||
'directory' => rtrim($directory, '/'),
|
||||
'version' => $result['version'],
|
||||
'sql' => $sql,
|
||||
'script' => $script,
|
||||
'done' => $done,
|
||||
]);
|
||||
}
|
||||
|
||||
// Normalizzazione di charset e collation
|
||||
self::normalizeDatabase($database->getDatabaseName());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Restituisce l'elenco degli aggiornamento del gestionale presenti nella cartella <b>update<b>.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected static function getCoreUpdates()
|
||||
{
|
||||
return self::getUpdates(DOCROOT.'/update');
|
||||
}
|
||||
|
||||
/**
|
||||
* Restituisce l'elenco degli aggiornamento nel percorso indicato.
|
||||
*
|
||||
* @param string $directory
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected static function getUpdates($directory)
|
||||
{
|
||||
$results = [];
|
||||
$previous = [];
|
||||
|
||||
$files = glob($directory.'/*.{php,sql}', GLOB_BRACE);
|
||||
foreach ($files as $file) {
|
||||
$infos = pathinfo($file);
|
||||
$version = str_replace('_', '.', $infos['filename']);
|
||||
|
||||
if (array_search($version, $previous) === false && self::isVersion($version)) {
|
||||
$path = str_replace(DOCROOT, '', $infos['dirname'].'/'.$infos['filename']);
|
||||
$path = ltrim($path, '/');
|
||||
|
||||
$results[] = [
|
||||
'path' => $path,
|
||||
'version' => $version,
|
||||
];
|
||||
$previous[] = $version;
|
||||
}
|
||||
}
|
||||
|
||||
asort($results);
|
||||
|
||||
return $results;
|
||||
}
|
||||
|
||||
/**
|
||||
* Restituisce l'elenco degli aggiornamento delle strutture supportate, presenti nella cartella <b>update<b>.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected static function getCustomUpdates()
|
||||
{
|
||||
$results = [];
|
||||
|
||||
foreach (self::$directories as $dir) {
|
||||
$folders = glob(DOCROOT.'/'.$dir.'/*/update', GLOB_ONLYDIR);
|
||||
|
||||
foreach ($folders as $folder) {
|
||||
$results = array_merge($results, self::getUpdates($folder));
|
||||
}
|
||||
}
|
||||
|
||||
return $results;
|
||||
}
|
||||
|
||||
protected static function findUpdatePath($update)
|
||||
{
|
||||
$version = str_replace('.', '_', $update['version']);
|
||||
|
||||
$old_standard = str_contains($update['version'], '_');
|
||||
if (empty($update['directory']) && !$old_standard) {
|
||||
return 'update/'.$version;
|
||||
}
|
||||
|
||||
if ($old_standard) {
|
||||
$module = implode('_', explode('_', $update['version'], -1));
|
||||
$version = explode('_', $update['version']);
|
||||
$version = end($version);
|
||||
|
||||
$version = str_replace('.', '_', $version);
|
||||
|
||||
return 'modules/'.$module.'/update/'.$version;
|
||||
}
|
||||
|
||||
return $update['directory'].'/update/'.$version;
|
||||
}
|
||||
|
||||
/**
|
||||
* Restituisce l'elenco degli aggiornamento incompleti o non ancora effettuati.
|
||||
*
|
||||
@ -314,28 +166,6 @@ class Update
|
||||
return self::getFile('REVISION');
|
||||
}
|
||||
|
||||
/**
|
||||
* Ottiene i contenuti di un file.
|
||||
*
|
||||
* @param string $file
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected static function getFile($file)
|
||||
{
|
||||
$file = (str_contains($file, DOCROOT.DIRECTORY_SEPARATOR)) ? $file : DOCROOT.DIRECTORY_SEPARATOR.$file;
|
||||
|
||||
$result = '';
|
||||
|
||||
$filepath = realpath($file);
|
||||
if (!empty($filepath)) {
|
||||
$result = file_get_contents($filepath);
|
||||
$result = str_replace(["\r\n", "\n"], '', $result);
|
||||
}
|
||||
|
||||
return trim($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Effettua una pulizia del database a seguito del completamento dell'aggiornamento.
|
||||
*
|
||||
@ -458,6 +288,176 @@ class Update
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Controlla la presenza di aggiornamenti e prepara il database per la procedura.
|
||||
*/
|
||||
protected static function prepareToUpdate()
|
||||
{
|
||||
$database = database();
|
||||
|
||||
$database_ready = $database->isConnected() && $database->tableExists('updates');
|
||||
|
||||
// Individuazione di tutti gli aggiornamenti presenti
|
||||
// Aggiornamenti del gestionale
|
||||
$core = self::getCoreUpdates();
|
||||
|
||||
// Aggiornamenti supportati
|
||||
$modules = self::getCustomUpdates();
|
||||
|
||||
$results = array_merge($core, $modules);
|
||||
$paths = array_column($results, 'path');
|
||||
|
||||
// Individuazione di tutti gli aggiornamenti inseriti nel database
|
||||
$updates = ($database_ready) ? $database->fetchArray('SELECT * FROM `updates`') : [];
|
||||
$versions = [];
|
||||
foreach ($updates as $update) {
|
||||
$versions[] = self::findUpdatePath($update);
|
||||
}
|
||||
|
||||
$reset = count(array_intersect($paths, $versions)) != count($results);
|
||||
|
||||
// Memorizzazione degli aggiornamenti
|
||||
if ($reset && $database->isConnected()) {
|
||||
// Reimpostazione della tabella degli aggiornamenti
|
||||
$create = DOCROOT.'/update/create_updates.sql';
|
||||
if (file_exists($create)) {
|
||||
$database->query('DROP TABLE IF EXISTS `updates`');
|
||||
$database->multiQuery($create);
|
||||
}
|
||||
|
||||
// Inserimento degli aggiornamenti individuati
|
||||
foreach ($results as $result) {
|
||||
// Individuazione di script e sql
|
||||
$sql = file_exists($result['path'].'.sql') ? 1 : 0;
|
||||
$script = file_exists($result['path'].'.php') ? 1 : 0;
|
||||
|
||||
// Reimpostazione degli stati per gli aggiornamenti precedentemente presenti
|
||||
$pos = array_search($result['path'], $versions);
|
||||
$done = ($pos !== false) ? $updates[$pos]['done'] : null;
|
||||
|
||||
$directory = explode('update/', $result['path'])[0];
|
||||
$database->insert('updates', [
|
||||
'directory' => rtrim($directory, '/'),
|
||||
'version' => $result['version'],
|
||||
'sql' => $sql,
|
||||
'script' => $script,
|
||||
'done' => $done,
|
||||
]);
|
||||
}
|
||||
|
||||
// Normalizzazione di charset e collation
|
||||
self::normalizeDatabase($database->getDatabaseName());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Restituisce l'elenco degli aggiornamento del gestionale presenti nella cartella <b>update<b>.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected static function getCoreUpdates()
|
||||
{
|
||||
return self::getUpdates(DOCROOT.'/update');
|
||||
}
|
||||
|
||||
/**
|
||||
* Restituisce l'elenco degli aggiornamento nel percorso indicato.
|
||||
*
|
||||
* @param string $directory
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected static function getUpdates($directory)
|
||||
{
|
||||
$results = [];
|
||||
$previous = [];
|
||||
|
||||
$files = glob($directory.'/*.{php,sql}', GLOB_BRACE);
|
||||
foreach ($files as $file) {
|
||||
$infos = pathinfo($file);
|
||||
$version = str_replace('_', '.', $infos['filename']);
|
||||
|
||||
if (array_search($version, $previous) === false && self::isVersion($version)) {
|
||||
$path = str_replace(DOCROOT, '', $infos['dirname'].'/'.$infos['filename']);
|
||||
$path = ltrim($path, '/');
|
||||
|
||||
$results[] = [
|
||||
'path' => $path,
|
||||
'version' => $version,
|
||||
];
|
||||
$previous[] = $version;
|
||||
}
|
||||
}
|
||||
|
||||
asort($results);
|
||||
|
||||
return $results;
|
||||
}
|
||||
|
||||
/**
|
||||
* Restituisce l'elenco degli aggiornamento delle strutture supportate, presenti nella cartella <b>update<b>.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected static function getCustomUpdates()
|
||||
{
|
||||
$results = [];
|
||||
|
||||
foreach (self::$directories as $dir) {
|
||||
$folders = glob(DOCROOT.'/'.$dir.'/*/update', GLOB_ONLYDIR);
|
||||
|
||||
foreach ($folders as $folder) {
|
||||
$results = array_merge($results, self::getUpdates($folder));
|
||||
}
|
||||
}
|
||||
|
||||
return $results;
|
||||
}
|
||||
|
||||
protected static function findUpdatePath($update)
|
||||
{
|
||||
$version = str_replace('.', '_', $update['version']);
|
||||
|
||||
$old_standard = str_contains($update['version'], '_');
|
||||
if (empty($update['directory']) && !$old_standard) {
|
||||
return 'update/'.$version;
|
||||
}
|
||||
|
||||
if ($old_standard) {
|
||||
$module = implode('_', explode('_', $update['version'], -1));
|
||||
$version = explode('_', $update['version']);
|
||||
$version = end($version);
|
||||
|
||||
$version = str_replace('.', '_', $version);
|
||||
|
||||
return 'modules/'.$module.'/update/'.$version;
|
||||
}
|
||||
|
||||
return $update['directory'].'/update/'.$version;
|
||||
}
|
||||
|
||||
/**
|
||||
* Ottiene i contenuti di un file.
|
||||
*
|
||||
* @param string $file
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected static function getFile($file)
|
||||
{
|
||||
$file = (str_contains($file, DOCROOT.DIRECTORY_SEPARATOR)) ? $file : DOCROOT.DIRECTORY_SEPARATOR.$file;
|
||||
|
||||
$result = '';
|
||||
|
||||
$filepath = realpath($file);
|
||||
if (!empty($filepath)) {
|
||||
$result = file_get_contents($filepath);
|
||||
$result = str_replace(["\r\n", "\n"], '', $result);
|
||||
}
|
||||
|
||||
return trim($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Normalizza l'infrastruttura del database indicato, generalizzando charset e collation all'interno del database e delle tabelle ed effettuando una conversione delle tabelle all'engine InnoDB.
|
||||
* <b>Attenzione</b>: se l'engine InnoDB non è supportato, il server ignorerà la conversione dell'engine e le foreign key del gestionale non funzioneranno adeguatamente.
|
||||
|
332
src/Uploads.php
332
src/Uploads.php
@ -7,6 +7,120 @@
|
||||
*/
|
||||
class Uploads
|
||||
{
|
||||
/** @var array Elenco delle tipologie di file permesse */
|
||||
protected static $allowed_types = [
|
||||
// Image formats
|
||||
'jpg' => 'image/jpeg',
|
||||
'jpeg' => 'image/jpeg',
|
||||
'jpe' => 'image/jpeg',
|
||||
'gif' => 'image/gif',
|
||||
'png' => 'image/png',
|
||||
'bmp' => 'image/bmp',
|
||||
'tif' => 'image/tiff',
|
||||
'tiff' => 'image/tiff',
|
||||
'ico' => 'image/x-icon',
|
||||
// Video formats
|
||||
'asx' => 'video/asf',
|
||||
'asf' => 'video/asf',
|
||||
'wax' => 'video/asf',
|
||||
'wmv' => 'video/asf',
|
||||
'wmx' => 'video/asf',
|
||||
'avi' => 'video/avi',
|
||||
'divx' => 'video/divx',
|
||||
'flv' => 'video/x-flv',
|
||||
'mov' => 'video/quicktime',
|
||||
'qt' => 'video/quicktime',
|
||||
'mpg' => 'video/mpeg',
|
||||
'mpeg' => 'video/mpeg',
|
||||
'mpe' => 'video/mpeg',
|
||||
'mp4' => 'video/mp4',
|
||||
'm4v' => 'video/mp4',
|
||||
'ogv' => 'video/ogg',
|
||||
'mkv' => 'video/x-matroska',
|
||||
// Text formats
|
||||
'txt' => 'text/plain',
|
||||
'csv' => 'text/csv',
|
||||
'tsv' => 'text/tab-separated-values',
|
||||
'ics' => 'text/calendar',
|
||||
'rtx' => 'text/richtext',
|
||||
'css' => 'text/css',
|
||||
'htm' => 'text/html',
|
||||
'html' => 'text/html',
|
||||
// Audio formats
|
||||
'mp3' => 'audio/mpeg',
|
||||
'm4a' => 'audio/mpeg',
|
||||
'm4b' => 'audio/mpeg',
|
||||
'mp' => 'audio/mpeg',
|
||||
'm4b' => 'audio/mpeg',
|
||||
'ra' => 'audio/x-realaudio',
|
||||
'ram' => 'audio/x-realaudio',
|
||||
'wav' => 'audio/wav',
|
||||
'ogg' => 'audio/ogg',
|
||||
'oga' => 'audio/ogg',
|
||||
'mid' => 'audio/midi',
|
||||
'midi' => 'audio/midi',
|
||||
'wma' => 'audio/wma',
|
||||
'mka' => 'audio/x-matroska',
|
||||
// Misc application formats
|
||||
'rtf' => 'application/rtf',
|
||||
'js' => 'application/javascript',
|
||||
'pdf' => 'application/pdf',
|
||||
'swf' => 'application/x-shockwave-flash',
|
||||
'class' => 'application/java',
|
||||
'tar' => 'application/x-tar',
|
||||
'zip' => 'application/zip',
|
||||
'gz' => 'application/x-gzip',
|
||||
'gzip' => 'application/x-gzip',
|
||||
'rar' => 'application/rar',
|
||||
'7z' => 'application/x-7z-compressed',
|
||||
// MS Office formats
|
||||
'doc' => 'application/msword',
|
||||
'pot' => 'application/vnd.ms-powerpoint',
|
||||
'pps' => 'application/vnd.ms-powerpoint',
|
||||
'ppt' => 'application/vnd.ms-powerpoint',
|
||||
'wri' => 'application/vnd.ms-write',
|
||||
'xla' => 'application/vnd.ms-excel',
|
||||
'xls' => 'application/vnd.ms-excel',
|
||||
'xlt' => 'application/vnd.ms-excel',
|
||||
'xlw' => 'application/vnd.ms-excel',
|
||||
'mdb' => 'application/vnd.ms-access',
|
||||
'mpp' => 'application/vnd.ms-project',
|
||||
'docx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
|
||||
'docm' => 'application/vnd.ms-word.document.macroEnabled.12',
|
||||
'dotx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.template',
|
||||
'dotm' => 'application/vnd.ms-word.template.macroEnabled.12',
|
||||
'xlsx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
|
||||
'xlsm' => 'application/vnd.ms-excel.sheet.macroEnabled.12',
|
||||
'xlsb' => 'application/vnd.ms-excel.sheet.binary.macroEnabled.12',
|
||||
'xltx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.template',
|
||||
'xltm' => 'application/vnd.ms-excel.template.macroEnabled.12',
|
||||
'xlam' => 'application/vnd.ms-excel.addin.macroEnabled.12',
|
||||
'pptx' => 'application/vnd.openxmlformats-officedocument.presentationml.presentation',
|
||||
'pptm' => 'application/vnd.ms-powerpoint.presentation.macroEnabled.12',
|
||||
'ppsx' => 'application/vnd.openxmlformats-officedocument.presentationml.slideshow',
|
||||
'ppsm' => 'application/vnd.ms-powerpoint.slideshow.macroEnabled.12',
|
||||
'potx' => 'application/vnd.openxmlformats-officedocument.presentationml.template',
|
||||
'potm' => 'application/vnd.ms-powerpoint.template.macroEnabled.12',
|
||||
'ppam' => 'application/vnd.ms-powerpoint.addin.macroEnabled.12',
|
||||
'sldx' => 'application/vnd.openxmlformats-officedocument.presentationml.slide',
|
||||
'sldm' => 'application/vnd.ms-powerpoint.slide.macroEnabled.12',
|
||||
'onetoc' => 'application/onenote',
|
||||
'onetoc2' => 'application/onenote',
|
||||
'onetmp' => 'application/onenote',
|
||||
'onepkg' => 'application/onenote',
|
||||
// OpenOffice formats
|
||||
'odt' => 'application/vnd.oasis.opendocument.text',
|
||||
'odp' => 'application/vnd.oasis.opendocument.presentation',
|
||||
'ods' => 'application/vnd.oasis.opendocument.spreadsheet',
|
||||
'odg' => 'application/vnd.oasis.opendocument.graphics',
|
||||
'odc' => 'application/vnd.oasis.opendocument.chart',
|
||||
'odb' => 'application/vnd.oasis.opendocument.database',
|
||||
'odf' => 'application/vnd.oasis.opendocument.formula',
|
||||
// WordPerfect formats
|
||||
'wp' => 'application/wordperfect',
|
||||
'wpd' => 'application/wordperfect',
|
||||
];
|
||||
|
||||
/**
|
||||
* Restisuice l'elenco degli allegati registrati per un determinato modulo/plugin e record.
|
||||
*
|
||||
@ -111,15 +225,6 @@ class Uploads
|
||||
return $filename;
|
||||
}
|
||||
|
||||
protected static function processOptions($data, $options)
|
||||
{
|
||||
$directory = DOCROOT.'/'.self::getDirectory($data['id_module'], $data['id_plugin']);
|
||||
|
||||
if (!empty($options['thumbnails'])) {
|
||||
self::thumbnails($directory.'/'.$data['filename'], $directory);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Registra nel database il file caricato con i dati richiesti.
|
||||
*
|
||||
@ -140,50 +245,6 @@ class Uploads
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Controlla se l'estensione è supportata dal sistema di upload.
|
||||
*
|
||||
* @param string $extension
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected static function isSupportedType($extension)
|
||||
{
|
||||
return in_array(strtolower($extension), array_keys(self::$allowed_types));
|
||||
}
|
||||
|
||||
/**
|
||||
* Genera le thumbnails per le immagini.
|
||||
*
|
||||
* @param string $filepath
|
||||
* @param string $directory
|
||||
*/
|
||||
protected static function thumbnails($filepath, $directory = null)
|
||||
{
|
||||
$fileinfo = self::fileInfo($filepath);
|
||||
$directory = empty($directory) ? dirname($filepath) : $directory;
|
||||
|
||||
$driver = extension_loaded('gd') ? 'gd' : 'imagick';
|
||||
Intervention\Image\ImageManagerStatic::configure(['driver' => $driver]);
|
||||
|
||||
$img = Intervention\Image\ImageManagerStatic::make($filepath);
|
||||
|
||||
$img->resize(600, null, function ($constraint) {
|
||||
$constraint->aspectRatio();
|
||||
});
|
||||
$img->save(slashes($directory.'/'.$fileinfo['filename'].'_thumb600.'.$fileinfo['extension']));
|
||||
|
||||
$img->resize(250, null, function ($constraint) {
|
||||
$constraint->aspectRatio();
|
||||
});
|
||||
$img->save(slashes($directory.'/'.$fileinfo['filename'].'_thumb250.'.$fileinfo['extension']));
|
||||
|
||||
$img->resize(100, null, function ($constraint) {
|
||||
$constraint->aspectRatio();
|
||||
});
|
||||
$img->save(slashes($directory.'/'.$fileinfo['filename'].'_thumb100.'.$fileinfo['extension']));
|
||||
}
|
||||
|
||||
/**
|
||||
* Elimina l'allegato indicato.
|
||||
*
|
||||
@ -317,117 +378,56 @@ class Uploads
|
||||
return true;
|
||||
}
|
||||
|
||||
/** @var array Elenco delle tipologie di file permesse */
|
||||
protected static $allowed_types = [
|
||||
// Image formats
|
||||
'jpg' => 'image/jpeg',
|
||||
'jpeg' => 'image/jpeg',
|
||||
'jpe' => 'image/jpeg',
|
||||
'gif' => 'image/gif',
|
||||
'png' => 'image/png',
|
||||
'bmp' => 'image/bmp',
|
||||
'tif' => 'image/tiff',
|
||||
'tiff' => 'image/tiff',
|
||||
'ico' => 'image/x-icon',
|
||||
// Video formats
|
||||
'asx' => 'video/asf',
|
||||
'asf' => 'video/asf',
|
||||
'wax' => 'video/asf',
|
||||
'wmv' => 'video/asf',
|
||||
'wmx' => 'video/asf',
|
||||
'avi' => 'video/avi',
|
||||
'divx' => 'video/divx',
|
||||
'flv' => 'video/x-flv',
|
||||
'mov' => 'video/quicktime',
|
||||
'qt' => 'video/quicktime',
|
||||
'mpg' => 'video/mpeg',
|
||||
'mpeg' => 'video/mpeg',
|
||||
'mpe' => 'video/mpeg',
|
||||
'mp4' => 'video/mp4',
|
||||
'm4v' => 'video/mp4',
|
||||
'ogv' => 'video/ogg',
|
||||
'mkv' => 'video/x-matroska',
|
||||
// Text formats
|
||||
'txt' => 'text/plain',
|
||||
'csv' => 'text/csv',
|
||||
'tsv' => 'text/tab-separated-values',
|
||||
'ics' => 'text/calendar',
|
||||
'rtx' => 'text/richtext',
|
||||
'css' => 'text/css',
|
||||
'htm' => 'text/html',
|
||||
'html' => 'text/html',
|
||||
// Audio formats
|
||||
'mp3' => 'audio/mpeg',
|
||||
'm4a' => 'audio/mpeg',
|
||||
'm4b' => 'audio/mpeg',
|
||||
'mp' => 'audio/mpeg',
|
||||
'm4b' => 'audio/mpeg',
|
||||
'ra' => 'audio/x-realaudio',
|
||||
'ram' => 'audio/x-realaudio',
|
||||
'wav' => 'audio/wav',
|
||||
'ogg' => 'audio/ogg',
|
||||
'oga' => 'audio/ogg',
|
||||
'mid' => 'audio/midi',
|
||||
'midi' => 'audio/midi',
|
||||
'wma' => 'audio/wma',
|
||||
'mka' => 'audio/x-matroska',
|
||||
// Misc application formats
|
||||
'rtf' => 'application/rtf',
|
||||
'js' => 'application/javascript',
|
||||
'pdf' => 'application/pdf',
|
||||
'swf' => 'application/x-shockwave-flash',
|
||||
'class' => 'application/java',
|
||||
'tar' => 'application/x-tar',
|
||||
'zip' => 'application/zip',
|
||||
'gz' => 'application/x-gzip',
|
||||
'gzip' => 'application/x-gzip',
|
||||
'rar' => 'application/rar',
|
||||
'7z' => 'application/x-7z-compressed',
|
||||
// MS Office formats
|
||||
'doc' => 'application/msword',
|
||||
'pot' => 'application/vnd.ms-powerpoint',
|
||||
'pps' => 'application/vnd.ms-powerpoint',
|
||||
'ppt' => 'application/vnd.ms-powerpoint',
|
||||
'wri' => 'application/vnd.ms-write',
|
||||
'xla' => 'application/vnd.ms-excel',
|
||||
'xls' => 'application/vnd.ms-excel',
|
||||
'xlt' => 'application/vnd.ms-excel',
|
||||
'xlw' => 'application/vnd.ms-excel',
|
||||
'mdb' => 'application/vnd.ms-access',
|
||||
'mpp' => 'application/vnd.ms-project',
|
||||
'docx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
|
||||
'docm' => 'application/vnd.ms-word.document.macroEnabled.12',
|
||||
'dotx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.template',
|
||||
'dotm' => 'application/vnd.ms-word.template.macroEnabled.12',
|
||||
'xlsx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
|
||||
'xlsm' => 'application/vnd.ms-excel.sheet.macroEnabled.12',
|
||||
'xlsb' => 'application/vnd.ms-excel.sheet.binary.macroEnabled.12',
|
||||
'xltx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.template',
|
||||
'xltm' => 'application/vnd.ms-excel.template.macroEnabled.12',
|
||||
'xlam' => 'application/vnd.ms-excel.addin.macroEnabled.12',
|
||||
'pptx' => 'application/vnd.openxmlformats-officedocument.presentationml.presentation',
|
||||
'pptm' => 'application/vnd.ms-powerpoint.presentation.macroEnabled.12',
|
||||
'ppsx' => 'application/vnd.openxmlformats-officedocument.presentationml.slideshow',
|
||||
'ppsm' => 'application/vnd.ms-powerpoint.slideshow.macroEnabled.12',
|
||||
'potx' => 'application/vnd.openxmlformats-officedocument.presentationml.template',
|
||||
'potm' => 'application/vnd.ms-powerpoint.template.macroEnabled.12',
|
||||
'ppam' => 'application/vnd.ms-powerpoint.addin.macroEnabled.12',
|
||||
'sldx' => 'application/vnd.openxmlformats-officedocument.presentationml.slide',
|
||||
'sldm' => 'application/vnd.ms-powerpoint.slide.macroEnabled.12',
|
||||
'onetoc' => 'application/onenote',
|
||||
'onetoc2' => 'application/onenote',
|
||||
'onetmp' => 'application/onenote',
|
||||
'onepkg' => 'application/onenote',
|
||||
// OpenOffice formats
|
||||
'odt' => 'application/vnd.oasis.opendocument.text',
|
||||
'odp' => 'application/vnd.oasis.opendocument.presentation',
|
||||
'ods' => 'application/vnd.oasis.opendocument.spreadsheet',
|
||||
'odg' => 'application/vnd.oasis.opendocument.graphics',
|
||||
'odc' => 'application/vnd.oasis.opendocument.chart',
|
||||
'odb' => 'application/vnd.oasis.opendocument.database',
|
||||
'odf' => 'application/vnd.oasis.opendocument.formula',
|
||||
// WordPerfect formats
|
||||
'wp' => 'application/wordperfect',
|
||||
'wpd' => 'application/wordperfect',
|
||||
];
|
||||
protected static function processOptions($data, $options)
|
||||
{
|
||||
$directory = DOCROOT.'/'.self::getDirectory($data['id_module'], $data['id_plugin']);
|
||||
|
||||
if (!empty($options['thumbnails'])) {
|
||||
self::thumbnails($directory.'/'.$data['filename'], $directory);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Controlla se l'estensione è supportata dal sistema di upload.
|
||||
*
|
||||
* @param string $extension
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected static function isSupportedType($extension)
|
||||
{
|
||||
return in_array(strtolower($extension), array_keys(self::$allowed_types));
|
||||
}
|
||||
|
||||
/**
|
||||
* Genera le thumbnails per le immagini.
|
||||
*
|
||||
* @param string $filepath
|
||||
* @param string $directory
|
||||
*/
|
||||
protected static function thumbnails($filepath, $directory = null)
|
||||
{
|
||||
$fileinfo = self::fileInfo($filepath);
|
||||
$directory = empty($directory) ? dirname($filepath) : $directory;
|
||||
|
||||
$driver = extension_loaded('gd') ? 'gd' : 'imagick';
|
||||
Intervention\Image\ImageManagerStatic::configure(['driver' => $driver]);
|
||||
|
||||
$img = Intervention\Image\ImageManagerStatic::make($filepath);
|
||||
|
||||
$img->resize(600, null, function ($constraint) {
|
||||
$constraint->aspectRatio();
|
||||
});
|
||||
$img->save(slashes($directory.'/'.$fileinfo['filename'].'_thumb600.'.$fileinfo['extension']));
|
||||
|
||||
$img->resize(250, null, function ($constraint) {
|
||||
$constraint->aspectRatio();
|
||||
});
|
||||
$img->save(slashes($directory.'/'.$fileinfo['filename'].'_thumb250.'.$fileinfo['extension']));
|
||||
|
||||
$img->resize(100, null, function ($constraint) {
|
||||
$constraint->aspectRatio();
|
||||
});
|
||||
$img->save(slashes($directory.'/'.$fileinfo['filename'].'_thumb100.'.$fileinfo['extension']));
|
||||
}
|
||||
}
|
||||
|
@ -19,6 +19,20 @@ abstract class Singleton
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Private clone method to prevent cloning of the instance of the <b>Singleton</b> instance.
|
||||
*/
|
||||
private function __clone()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Private unserialize method to prevent unserializing of the <b>Singleton</b> instance.
|
||||
*/
|
||||
private function __wakeup()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Restituisce l'istanza della classe in oggetto.
|
||||
*
|
||||
@ -34,18 +48,4 @@ abstract class Singleton
|
||||
|
||||
return self::$instance[$class];
|
||||
}
|
||||
|
||||
/**
|
||||
* Private clone method to prevent cloning of the instance of the <b>Singleton</b> instance.
|
||||
*/
|
||||
private function __clone()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Private unserialize method to prevent unserializing of the <b>Singleton</b> instance.
|
||||
*/
|
||||
private function __wakeup()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
@ -2,8 +2,8 @@
|
||||
|
||||
namespace Util;
|
||||
|
||||
use ZipArchive;
|
||||
use Symfony\Component\Finder\Finder;
|
||||
use ZipArchive;
|
||||
|
||||
/**
|
||||
* Classe dedicata alla gestione dei contenuti ZIP.
|
||||
|
@ -1,7 +1,7 @@
|
||||
<?php
|
||||
|
||||
use Mpociot\VatCalculator\VatCalculator;
|
||||
use Mpociot\VatCalculator\Exceptions\VATCheckUnavailableException;
|
||||
use Mpociot\VatCalculator\VatCalculator;
|
||||
use Respect\Validation\Validator as v;
|
||||
|
||||
/**
|
||||
|
@ -248,20 +248,16 @@ if (!empty($record['ritenutaacconto']) or (!empty($record['spit_payment']))) {
|
||||
</th>';
|
||||
}
|
||||
|
||||
|
||||
|
||||
echo '
|
||||
echo '
|
||||
<th class="text-center small" colspan="'.$second_colspan.'">';
|
||||
if (empty($record['split_payment'])) {
|
||||
echo tr('Netto a pagare', [], ['upper' => true]);
|
||||
}else{
|
||||
echo tr('Totale', [], ['upper' => true]);
|
||||
}
|
||||
if (empty($record['split_payment'])) {
|
||||
echo tr('Netto a pagare', [], ['upper' => true]);
|
||||
} else {
|
||||
echo tr('Totale', [], ['upper' => true]);
|
||||
}
|
||||
echo '
|
||||
</th>';
|
||||
|
||||
|
||||
|
||||
echo'
|
||||
</tr>
|
||||
|
||||
@ -286,14 +282,12 @@ if (!empty($record['ritenutaacconto']) or (!empty($record['spit_payment']))) {
|
||||
</tr>';
|
||||
}
|
||||
|
||||
|
||||
// Split payment
|
||||
if (!empty($record['split_payment'])) {
|
||||
|
||||
$first_colspan = 1;
|
||||
$second_colspan = 2;
|
||||
|
||||
echo '
|
||||
$first_colspan = 1;
|
||||
$second_colspan = 2;
|
||||
|
||||
echo '
|
||||
<tr>
|
||||
<th class="text-center small" colspan="'.$first_colspan.'">
|
||||
'.tr('iva a carico del destinatario', [], ['upper' => true]).'
|
||||
@ -304,23 +298,18 @@ if (!empty($record['split_payment'])) {
|
||||
</th>
|
||||
</tr>';
|
||||
|
||||
echo '
|
||||
echo '
|
||||
<tr>
|
||||
<td class="cell-padded text-center" colspan="'.$first_colspan.'">
|
||||
'.Translator::numberToLocale($totale_iva).' €
|
||||
</td>
|
||||
|
||||
<td class="cell-padded text-center" colspan="'.$second_colspan.'">
|
||||
'.Translator::numberToLocale($totale - $totale_iva -$record['ritenutaacconto']).' €
|
||||
'.Translator::numberToLocale($totale - $totale_iva - $record['ritenutaacconto']).' €
|
||||
</td>
|
||||
</tr>';
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// Solo bollo
|
||||
if (empty($record['ritenutaacconto']) && empty($record['rivalsainps']) && empty($record['split_payment']) && abs($record['bollo']) > 0) {
|
||||
$first_colspan = 3;
|
||||
|
@ -37,15 +37,6 @@ class Acceptance extends \Codeception\Module
|
||||
$select2->selectOptionForSelect2($selector, $option, $timeout);
|
||||
}
|
||||
|
||||
protected function getAcceptanceModule()
|
||||
{
|
||||
if (!$this->hasModule('WebDriver')) {
|
||||
throw new \Exception('You must enable the WebDriver module', 1);
|
||||
}
|
||||
|
||||
return $this->getModule('WebDriver');
|
||||
}
|
||||
|
||||
public function seePageHasElement($element)
|
||||
{
|
||||
try {
|
||||
@ -66,4 +57,13 @@ class Acceptance extends \Codeception\Module
|
||||
$t->wait(1);
|
||||
}
|
||||
}
|
||||
|
||||
protected function getAcceptanceModule()
|
||||
{
|
||||
if (!$this->hasModule('WebDriver')) {
|
||||
throw new \Exception('You must enable the WebDriver module', 1);
|
||||
}
|
||||
|
||||
return $this->getModule('WebDriver');
|
||||
}
|
||||
}
|
||||
|
@ -10,47 +10,6 @@ class RowHelper extends \Codeception\Module
|
||||
protected $finalPattern = "//div[@class='panel-heading' and contains(string(), 'Righe')]/parent::*//table//tr[contains(string(), '|name|')]//td[2]";
|
||||
protected $dir;
|
||||
|
||||
/**
|
||||
* Completa le informazioni per la creazione di un nuovo elemento.
|
||||
*
|
||||
* @param AcceptanceTester $t
|
||||
* @param [type] $descrizione
|
||||
* @param [type] $qta
|
||||
* @param [type] $prezzo
|
||||
* @param int $sconto
|
||||
* @param string $tipo_sconto
|
||||
* @param [type] $id_iva
|
||||
* @param [type] $id_rivalsa_inps
|
||||
* @param [type] $id_ritenuta_acconto
|
||||
*/
|
||||
protected function fill(AcceptanceTester $t, $descrizione, $qta, $prezzo, $sconto = 0, $tipo_sconto = 'UNT', $id_iva = null, $id_rivalsa_inps = null, $id_ritenuta_acconto = null)
|
||||
{
|
||||
$t->fillField('#descrizione_riga', $descrizione);
|
||||
$t->fillField('Q.tà', $qta);
|
||||
|
||||
$label = ($this->dir == 'uscita') ? 'Prezzo unitario' : 'Prezzo unitario di vendita';
|
||||
$t->fillField($label, $prezzo);
|
||||
|
||||
if (!empty($sconto)) {
|
||||
$t->fillField('Sconto unitario', $sconto);
|
||||
|
||||
if (in_array($tipo_sconto, ['PRC', 'UNT'])) {
|
||||
$t->select2ajax('#tipo_sconto', $tipo_sconto);
|
||||
}
|
||||
}
|
||||
|
||||
if ($id_iva) {
|
||||
$t->select2('#idiva', $id_iva);
|
||||
}
|
||||
|
||||
if ($id_rivalsa_inps) {
|
||||
$t->select2('#id_rivalsa_inps', $id_rivalsa_inps);
|
||||
}
|
||||
if ($id_ritenuta_acconto) {
|
||||
$t->select2('#id_ritenuta_acconto', $id_ritenuta_acconto);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Aggiunge una nuova riga.
|
||||
*
|
||||
@ -106,26 +65,6 @@ class RowHelper extends \Codeception\Module
|
||||
$t->see('Articolo aggiunto');
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function.
|
||||
*
|
||||
* @param string $pattern
|
||||
*/
|
||||
protected function setFinalPattern($pattern)
|
||||
{
|
||||
$this->finalPattern = $pattern;
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function.
|
||||
*
|
||||
* @param string $type
|
||||
*/
|
||||
protected function getFinalValue($type)
|
||||
{
|
||||
return str_replace('|name|', strtoupper($type), $this->finalPattern);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function.
|
||||
*
|
||||
@ -179,4 +118,65 @@ class RowHelper extends \Codeception\Module
|
||||
$t->see('95,50', $this->getFinalValue('IVA'));
|
||||
$t->see('529,61', $this->getFinalValue('Totale'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Completa le informazioni per la creazione di un nuovo elemento.
|
||||
*
|
||||
* @param AcceptanceTester $t
|
||||
* @param [type] $descrizione
|
||||
* @param [type] $qta
|
||||
* @param [type] $prezzo
|
||||
* @param int $sconto
|
||||
* @param string $tipo_sconto
|
||||
* @param [type] $id_iva
|
||||
* @param [type] $id_rivalsa_inps
|
||||
* @param [type] $id_ritenuta_acconto
|
||||
*/
|
||||
protected function fill(AcceptanceTester $t, $descrizione, $qta, $prezzo, $sconto = 0, $tipo_sconto = 'UNT', $id_iva = null, $id_rivalsa_inps = null, $id_ritenuta_acconto = null)
|
||||
{
|
||||
$t->fillField('#descrizione_riga', $descrizione);
|
||||
$t->fillField('Q.tà', $qta);
|
||||
|
||||
$label = ($this->dir == 'uscita') ? 'Prezzo unitario' : 'Prezzo unitario di vendita';
|
||||
$t->fillField($label, $prezzo);
|
||||
|
||||
if (!empty($sconto)) {
|
||||
$t->fillField('Sconto unitario', $sconto);
|
||||
|
||||
if (in_array($tipo_sconto, ['PRC', 'UNT'])) {
|
||||
$t->select2ajax('#tipo_sconto', $tipo_sconto);
|
||||
}
|
||||
}
|
||||
|
||||
if ($id_iva) {
|
||||
$t->select2('#idiva', $id_iva);
|
||||
}
|
||||
|
||||
if ($id_rivalsa_inps) {
|
||||
$t->select2('#id_rivalsa_inps', $id_rivalsa_inps);
|
||||
}
|
||||
if ($id_ritenuta_acconto) {
|
||||
$t->select2('#id_ritenuta_acconto', $id_ritenuta_acconto);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function.
|
||||
*
|
||||
* @param string $pattern
|
||||
*/
|
||||
protected function setFinalPattern($pattern)
|
||||
{
|
||||
$this->finalPattern = $pattern;
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function.
|
||||
*
|
||||
* @param string $type
|
||||
*/
|
||||
protected function getFinalValue($type)
|
||||
{
|
||||
return str_replace('|name|', strtoupper($type), $this->finalPattern);
|
||||
}
|
||||
}
|
||||
|
@ -26,34 +26,6 @@ namespace Helper;
|
||||
|
||||
class Select2 extends \Codeception\Module
|
||||
{
|
||||
/**
|
||||
* @param $selector
|
||||
* @param $optionText
|
||||
* @param bool $expectedReturn Default to true
|
||||
*
|
||||
* @return string JavaScript
|
||||
*/
|
||||
protected function _optionIsSelectedForSelect2($selector, $optionText, $expectedReturn = true)
|
||||
{
|
||||
$returnFlag = $expectedReturn === true ? '' : '!';
|
||||
|
||||
return $script = <<<EOT
|
||||
return (function (\$) {
|
||||
var isSelected = false;
|
||||
var values = \$("$selector").val();
|
||||
values = \$.isArray(values ) ? values : [values];
|
||||
if (values && values.length > 0) {
|
||||
isSelected = values.some(function (data) {
|
||||
if (data && data.text && data.text === "$optionText") {
|
||||
return data;
|
||||
}
|
||||
});
|
||||
}
|
||||
return ${returnFlag}isSelected;
|
||||
}(jQuery));
|
||||
EOT;
|
||||
}
|
||||
|
||||
/**
|
||||
* Wait until the select2 component is loaded.
|
||||
*
|
||||
@ -215,6 +187,34 @@ EOT;
|
||||
$t->executeJS('jQuery("'.$selector.'").select2("close");');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $selector
|
||||
* @param $optionText
|
||||
* @param bool $expectedReturn Default to true
|
||||
*
|
||||
* @return string JavaScript
|
||||
*/
|
||||
protected function _optionIsSelectedForSelect2($selector, $optionText, $expectedReturn = true)
|
||||
{
|
||||
$returnFlag = $expectedReturn === true ? '' : '!';
|
||||
|
||||
return $script = <<<EOT
|
||||
return (function (\$) {
|
||||
var isSelected = false;
|
||||
var values = \$("$selector").val();
|
||||
values = \$.isArray(values ) ? values : [values];
|
||||
if (values && values.length > 0) {
|
||||
isSelected = values.some(function (data) {
|
||||
if (data && data.text && data.text === "$optionText") {
|
||||
return data;
|
||||
}
|
||||
});
|
||||
}
|
||||
return ${returnFlag}isSelected;
|
||||
}(jQuery));
|
||||
EOT;
|
||||
}
|
||||
|
||||
protected function getSelect2Selector($selector)
|
||||
{
|
||||
return $selector;
|
||||
|
@ -8,52 +8,6 @@ class AnagraficheCest
|
||||
$t->login('admin', 'admin');
|
||||
}
|
||||
|
||||
/**
|
||||
* Crea una nuova anagrafica.
|
||||
*
|
||||
* @param AcceptanceTester $t
|
||||
*/
|
||||
protected function addAnag(AcceptanceTester $t, $name = 'ANAGRAFICA DI PROVA', $tipo = 1, $partita_iva = '')
|
||||
{
|
||||
// Seleziona il modulo da aprire
|
||||
$t->navigateTo('Anagrafiche');
|
||||
|
||||
// Apre la schermata di nuovo elemento
|
||||
$t->clickAndWaitModal('.btn-primary', '#tabs');
|
||||
|
||||
// Completa i campi per il nuovo elemento
|
||||
$t->fillField('Ragione sociale', $name);
|
||||
$t->select2('#idtipoanagrafica', $tipo);
|
||||
$t->click('.btn-box-tool');
|
||||
$t->waitForElementVisible('#piva', 3);
|
||||
$t->fillField('Partita IVA', $partita_iva);
|
||||
|
||||
// Effettua il submit
|
||||
$t->clickAndWait('Aggiungi', '#add-form');
|
||||
|
||||
// Controlla il salvataggio finale
|
||||
$t->seeInField('Ragione sociale', $name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Crea una nuova anagrafica di tipo cliente e la elimina.
|
||||
*
|
||||
* @param AcceptanceTester $t
|
||||
*/
|
||||
protected function addAndDeleteAnag(AcceptanceTester $t, $name = 'ANAGRAFICA DI PROVA', $tipo = 1, $partita_iva = '')
|
||||
{
|
||||
$this->addAnag($t, $name, $tipo, $partita_iva);
|
||||
|
||||
// Seleziona l'azione di eliminazione
|
||||
$t->clickAndWaitSwal('Elimina', '#tab_0');
|
||||
|
||||
// Conferma l'eliminazione
|
||||
$t->clickSwalButton('Elimina');
|
||||
|
||||
// Controlla eliminazione
|
||||
$t->see('Anagrafica eliminata!', '.alert-success');
|
||||
}
|
||||
|
||||
/**
|
||||
* Crea una nuova anagrafica di tipo Cliente.
|
||||
*
|
||||
@ -103,4 +57,50 @@ class AnagraficheCest
|
||||
{
|
||||
$this->addAnag($t, 'Agente', 6, '05024030289');
|
||||
}
|
||||
|
||||
/**
|
||||
* Crea una nuova anagrafica.
|
||||
*
|
||||
* @param AcceptanceTester $t
|
||||
*/
|
||||
protected function addAnag(AcceptanceTester $t, $name = 'ANAGRAFICA DI PROVA', $tipo = 1, $partita_iva = '')
|
||||
{
|
||||
// Seleziona il modulo da aprire
|
||||
$t->navigateTo('Anagrafiche');
|
||||
|
||||
// Apre la schermata di nuovo elemento
|
||||
$t->clickAndWaitModal('.btn-primary', '#tabs');
|
||||
|
||||
// Completa i campi per il nuovo elemento
|
||||
$t->fillField('Ragione sociale', $name);
|
||||
$t->select2('#idtipoanagrafica', $tipo);
|
||||
$t->click('.btn-box-tool');
|
||||
$t->waitForElementVisible('#piva', 3);
|
||||
$t->fillField('Partita IVA', $partita_iva);
|
||||
|
||||
// Effettua il submit
|
||||
$t->clickAndWait('Aggiungi', '#add-form');
|
||||
|
||||
// Controlla il salvataggio finale
|
||||
$t->seeInField('Ragione sociale', $name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Crea una nuova anagrafica di tipo cliente e la elimina.
|
||||
*
|
||||
* @param AcceptanceTester $t
|
||||
*/
|
||||
protected function addAndDeleteAnag(AcceptanceTester $t, $name = 'ANAGRAFICA DI PROVA', $tipo = 1, $partita_iva = '')
|
||||
{
|
||||
$this->addAnag($t, $name, $tipo, $partita_iva);
|
||||
|
||||
// Seleziona l'azione di eliminazione
|
||||
$t->clickAndWaitSwal('Elimina', '#tab_0');
|
||||
|
||||
// Conferma l'eliminazione
|
||||
$t->clickSwalButton('Elimina');
|
||||
|
||||
// Controlla eliminazione
|
||||
$t->see('Anagrafica eliminata!', '.alert-success');
|
||||
}
|
||||
}
|
||||
|
@ -9,17 +9,31 @@ class ContrattiCest
|
||||
*/
|
||||
protected $rowHelper;
|
||||
|
||||
protected function _inject(RowHelper $rowHelper)
|
||||
{
|
||||
$this->rowHelper = $rowHelper;
|
||||
}
|
||||
|
||||
public function _before(\AcceptanceTester $t)
|
||||
{
|
||||
// Effettua l'accesso con le credenziali fornite
|
||||
$t->login('admin', 'admin');
|
||||
}
|
||||
|
||||
/**
|
||||
* Crea un nuovo contratto.
|
||||
*
|
||||
* @param AcceptanceTester $t
|
||||
*/
|
||||
public function testContratto(AcceptanceTester $t)
|
||||
{
|
||||
$this->addContratto($t, 'Contratto di test', 2);
|
||||
|
||||
$this->rowHelper->testImporti($t);
|
||||
|
||||
//$t->click('Stampa');
|
||||
}
|
||||
|
||||
protected function _inject(RowHelper $rowHelper)
|
||||
{
|
||||
$this->rowHelper = $rowHelper;
|
||||
}
|
||||
|
||||
/**
|
||||
* Crea un nuovo contratto.
|
||||
*
|
||||
@ -63,18 +77,4 @@ class ContrattiCest
|
||||
// Controlla eliminazione
|
||||
$t->see('Contratto eliminato!', '.alert-success');
|
||||
}
|
||||
|
||||
/**
|
||||
* Crea un nuovo contratto.
|
||||
*
|
||||
* @param AcceptanceTester $t
|
||||
*/
|
||||
public function testContratto(AcceptanceTester $t)
|
||||
{
|
||||
$this->addContratto($t, 'Contratto di test', 2);
|
||||
|
||||
$this->rowHelper->testImporti($t);
|
||||
|
||||
//$t->click('Stampa');
|
||||
}
|
||||
}
|
||||
|
@ -9,17 +9,43 @@ class DDTCest
|
||||
*/
|
||||
protected $rowHelper;
|
||||
|
||||
protected function _inject(RowHelper $rowHelper)
|
||||
{
|
||||
$this->rowHelper = $rowHelper;
|
||||
}
|
||||
|
||||
public function _before(\AcceptanceTester $t)
|
||||
{
|
||||
// Effettua l'accesso con le credenziali fornite
|
||||
$t->login('admin', 'admin');
|
||||
}
|
||||
|
||||
/**
|
||||
* Crea un nuovo ddt.
|
||||
*
|
||||
* @param AcceptanceTester $t
|
||||
*/
|
||||
public function testDdtDiVendita(AcceptanceTester $t)
|
||||
{
|
||||
$this->addDdt($t, true, 2, 2);
|
||||
|
||||
$this->rowHelper->testImporti($t);
|
||||
|
||||
//$t->click('Stampa');
|
||||
}
|
||||
|
||||
/**
|
||||
* Crea un nuovo ddt.
|
||||
*
|
||||
* @param AcceptanceTester $t
|
||||
*/
|
||||
public function testDdtDiAcquisto(AcceptanceTester $t)
|
||||
{
|
||||
$this->addDdt($t, false, 3, 1);
|
||||
|
||||
$this->rowHelper->testImporti($t, 'uscita');
|
||||
}
|
||||
|
||||
protected function _inject(RowHelper $rowHelper)
|
||||
{
|
||||
$this->rowHelper = $rowHelper;
|
||||
}
|
||||
|
||||
/**
|
||||
* Crea un nuovo ddt.
|
||||
*
|
||||
@ -63,30 +89,4 @@ class DDTCest
|
||||
// Controlla eliminazione
|
||||
$t->see('Ddt eliminato!', '.alert-success');
|
||||
}
|
||||
|
||||
/**
|
||||
* Crea un nuovo ddt.
|
||||
*
|
||||
* @param AcceptanceTester $t
|
||||
*/
|
||||
public function testDdtDiVendita(AcceptanceTester $t)
|
||||
{
|
||||
$this->addDdt($t, true, 2, 2);
|
||||
|
||||
$this->rowHelper->testImporti($t);
|
||||
|
||||
//$t->click('Stampa');
|
||||
}
|
||||
|
||||
/**
|
||||
* Crea un nuovo ddt.
|
||||
*
|
||||
* @param AcceptanceTester $t
|
||||
*/
|
||||
public function testDdtDiAcquisto(AcceptanceTester $t)
|
||||
{
|
||||
$this->addDdt($t, false, 3, 1);
|
||||
|
||||
$this->rowHelper->testImporti($t, 'uscita');
|
||||
}
|
||||
}
|
||||
|
@ -9,17 +9,45 @@ class FattureCest
|
||||
*/
|
||||
protected $rowHelper;
|
||||
|
||||
protected function _inject(RowHelper $rowHelper)
|
||||
{
|
||||
$this->rowHelper = $rowHelper;
|
||||
}
|
||||
|
||||
public function _before(\AcceptanceTester $t)
|
||||
{
|
||||
// Effettua l'accesso con le credenziali fornite
|
||||
$t->login('admin', 'admin');
|
||||
}
|
||||
|
||||
/**
|
||||
* Crea una nuova fattura di vendita.
|
||||
*
|
||||
* @param AcceptanceTester $t
|
||||
*/
|
||||
public function testFatturaDiVendita(AcceptanceTester $t)
|
||||
{
|
||||
$this->addFattura($t, true, 2, 2);
|
||||
|
||||
$this->rowHelper->testImporti($t);
|
||||
}
|
||||
|
||||
/**
|
||||
* Crea una nuova fattura di acquisto.
|
||||
*
|
||||
* @param AcceptanceTester $t
|
||||
*/
|
||||
public function testFatturaDiAcquisto(AcceptanceTester $t)
|
||||
{
|
||||
$this->addFattura($t, false, 1, 4);
|
||||
|
||||
// Fix pagamento vuoto
|
||||
$t->select2('#idpagamento', 109);
|
||||
$t->clickAndWait('Salva');
|
||||
|
||||
$this->rowHelper->testImporti($t, 'uscita');
|
||||
}
|
||||
|
||||
protected function _inject(RowHelper $rowHelper)
|
||||
{
|
||||
$this->rowHelper = $rowHelper;
|
||||
}
|
||||
|
||||
/**
|
||||
* Crea una nuova fattura.
|
||||
*
|
||||
@ -63,32 +91,4 @@ class FattureCest
|
||||
// Controlla eliminazione
|
||||
$t->see('Fattura eliminata!', '.alert-success');
|
||||
}
|
||||
|
||||
/**
|
||||
* Crea una nuova fattura di vendita.
|
||||
*
|
||||
* @param AcceptanceTester $t
|
||||
*/
|
||||
public function testFatturaDiVendita(AcceptanceTester $t)
|
||||
{
|
||||
$this->addFattura($t, true, 2, 2);
|
||||
|
||||
$this->rowHelper->testImporti($t);
|
||||
}
|
||||
|
||||
/**
|
||||
* Crea una nuova fattura di acquisto.
|
||||
*
|
||||
* @param AcceptanceTester $t
|
||||
*/
|
||||
public function testFatturaDiAcquisto(AcceptanceTester $t)
|
||||
{
|
||||
$this->addFattura($t, false, 1, 4);
|
||||
|
||||
// Fix pagamento vuoto
|
||||
$t->select2('#idpagamento', 109);
|
||||
$t->clickAndWait('Salva');
|
||||
|
||||
$this->rowHelper->testImporti($t, 'uscita');
|
||||
}
|
||||
}
|
||||
|
@ -9,17 +9,47 @@ class OrdiniCest
|
||||
*/
|
||||
protected $rowHelper;
|
||||
|
||||
protected function _inject(RowHelper $rowHelper)
|
||||
{
|
||||
$this->rowHelper = $rowHelper;
|
||||
}
|
||||
|
||||
public function _before(\AcceptanceTester $t)
|
||||
{
|
||||
// Effettua l'accesso con le credenziali fornite
|
||||
$t->login('admin', 'admin');
|
||||
}
|
||||
|
||||
/**
|
||||
* Crea un nuovo ordine.
|
||||
*
|
||||
* @param AcceptanceTester $t
|
||||
*/
|
||||
public function testOrdineCliente(AcceptanceTester $t)
|
||||
{
|
||||
$this->addOrdine($t, true, 2);
|
||||
|
||||
$this->rowHelper->testImporti($t);
|
||||
|
||||
//$t->click('Stampa');
|
||||
}
|
||||
|
||||
/**
|
||||
* Crea un nuovo ordine.
|
||||
*
|
||||
* @param AcceptanceTester $t
|
||||
*/
|
||||
public function testOrdineFornitore(AcceptanceTester $t)
|
||||
{
|
||||
$this->addOrdine($t, false, 4);
|
||||
|
||||
// Fix pagamento vuoto
|
||||
$t->select2('#idpagamento', 109);
|
||||
$t->clickAndWait('Salva');
|
||||
|
||||
$this->rowHelper->testImporti($t, 'uscita');
|
||||
}
|
||||
|
||||
protected function _inject(RowHelper $rowHelper)
|
||||
{
|
||||
$this->rowHelper = $rowHelper;
|
||||
}
|
||||
|
||||
/**
|
||||
* Crea un nuovo ordine.
|
||||
*
|
||||
@ -62,34 +92,4 @@ class OrdiniCest
|
||||
// Controlla eliminazione
|
||||
$t->see('Ordine eliminato!', '.alert-success');
|
||||
}
|
||||
|
||||
/**
|
||||
* Crea un nuovo ordine.
|
||||
*
|
||||
* @param AcceptanceTester $t
|
||||
*/
|
||||
public function testOrdineCliente(AcceptanceTester $t)
|
||||
{
|
||||
$this->addOrdine($t, true, 2);
|
||||
|
||||
$this->rowHelper->testImporti($t);
|
||||
|
||||
//$t->click('Stampa');
|
||||
}
|
||||
|
||||
/**
|
||||
* Crea un nuovo ordine.
|
||||
*
|
||||
* @param AcceptanceTester $t
|
||||
*/
|
||||
public function testOrdineFornitore(AcceptanceTester $t)
|
||||
{
|
||||
$this->addOrdine($t, false, 4);
|
||||
|
||||
// Fix pagamento vuoto
|
||||
$t->select2('#idpagamento', 109);
|
||||
$t->clickAndWait('Salva');
|
||||
|
||||
$this->rowHelper->testImporti($t, 'uscita');
|
||||
}
|
||||
}
|
||||
|
@ -9,17 +9,31 @@ class PreventiviCest
|
||||
*/
|
||||
protected $rowHelper;
|
||||
|
||||
protected function _inject(RowHelper $rowHelper)
|
||||
{
|
||||
$this->rowHelper = $rowHelper;
|
||||
}
|
||||
|
||||
public function _before(\AcceptanceTester $t)
|
||||
{
|
||||
// Effettua l'accesso con le credenziali fornite
|
||||
$t->login('admin', 'admin');
|
||||
}
|
||||
|
||||
/**
|
||||
* Crea un nuovo preventivo.
|
||||
*
|
||||
* @param AcceptanceTester $t
|
||||
*/
|
||||
public function testPreventivo(AcceptanceTester $t)
|
||||
{
|
||||
$this->addPreventivo($t, 'Preventivo di test', 2);
|
||||
|
||||
$this->rowHelper->testImporti($t);
|
||||
|
||||
//$t->click('Stampa');
|
||||
}
|
||||
|
||||
protected function _inject(RowHelper $rowHelper)
|
||||
{
|
||||
$this->rowHelper = $rowHelper;
|
||||
}
|
||||
|
||||
/**
|
||||
* Crea un nuovo preventivo.
|
||||
*
|
||||
@ -64,18 +78,4 @@ class PreventiviCest
|
||||
// Controlla eliminazione
|
||||
$t->see('Preventivo eliminato!', '.alert-success');
|
||||
}
|
||||
|
||||
/**
|
||||
* Crea un nuovo preventivo.
|
||||
*
|
||||
* @param AcceptanceTester $t
|
||||
*/
|
||||
public function testPreventivo(AcceptanceTester $t)
|
||||
{
|
||||
$this->addPreventivo($t, 'Preventivo di test', 2);
|
||||
|
||||
$this->rowHelper->testImporti($t);
|
||||
|
||||
//$t->click('Stampa');
|
||||
}
|
||||
}
|
||||
|
@ -1,8 +1,8 @@
|
||||
<?php
|
||||
|
||||
use Modules\Anagrafiche\Anagrafica;
|
||||
use Modules\Fatture\Fattura;
|
||||
use Modules\Fatture\Tipo;
|
||||
use Modules\Anagrafiche\Anagrafica;
|
||||
|
||||
class FatturaTest extends \Codeception\Test\Unit
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user