Miglioramento strutturale

This commit is contained in:
Thomas Zilio 2018-12-14 09:46:35 +01:00
parent f5aafd1ef4
commit 3ea579c827
4 changed files with 119 additions and 88 deletions

111
include/src/Document.php Normal file
View File

@ -0,0 +1,111 @@
<?php
namespace Common;
use Illuminate\Database\Eloquent\Builder;
abstract class Document extends Model
{
/**
* Restituisce la collezione di righe e articoli con valori rilevanti per i conti.
*
* @return iterable
*/
protected function getRighe()
{
return $this->righe->merge($this->articoli);
}
/**
* 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.
*
* @return float
*/
public function getImponibileAttribute()
{
return $this->round($this->getRighe()->sum('imponibile'));
}
/**
* Calcola lo sconto totale della fattura.
*
* @return float
*/
public function getScontoAttribute()
{
return $this->round($this->getRighe()->sum('sconto'));
}
/**
* Calcola l'imponibile scontato della fattura.
*
* @return float
*/
public function getImponibileScontatoAttribute()
{
return $this->round($this->getRighe()->sum('imponibile_scontato'));
}
/**
* Calcola l'IVA totale della fattura.
*
* @return float
*/
public function getIvaAttribute()
{
return $this->round($this->getRighe()->sum('iva'));
}
/**
* Calcola la rivalsa INPS totale della fattura.
*
* @return float
*/
public function getRivalsaINPSAttribute()
{
return $this->round($this->getRighe()->sum('rivalsa_inps'));
}
/**
* Calcola la ritenuta d'acconto totale della fattura.
*
* @return float
*/
public function getRitenutaAccontoAttribute()
{
return $this->round($this->getRighe()->sum('ritenuta_acconto'));
}
/**
* Calcola il totale della fattura.
*
* @return float
*/
public function getTotaleAttribute()
{
return $this->round($this->getRighe()->sum('totale'));
}
/**
* Calcola il netto a pagare della fattura.
*
* @return float
*/
public function getNettoAttribute()
{
return $this->round($this->getRighe()->sum('netto'));
}
}

View File

@ -2,12 +2,12 @@
namespace Modules\Fatture;
use Common\Model;
use Common\Document;
use Util\Generator;
use Traits\RecordTrait;
use Modules\Anagrafiche\Anagrafica;
class Fattura extends Model
class Fattura extends Document
{
use RecordTrait;
@ -175,94 +175,14 @@ class Fattura extends Model
return $numero_esterno;
}
/**
* Restituisce la collezione di righe e articoli con valori rilevanti per i conti.
*
* @return iterable
*/
protected function getRighe()
{
return $this->righe->merge($this->articoli);
}
/**
* Calcola l'imponibile della fattura.
*
* @return float
*/
public function getImponibile()
{
return $this->getRighe()->sum('imponibile');
}
/**
* Calcola lo sconto totale della fattura.
*
* @return float
*/
public function getSconto()
{
return $this->getRighe()->sum('sconto');
}
/**
* Calcola l'imponibile scontato della fattura.
*
* @return float
*/
public function getImponibileScontato()
{
return $this->getRighe()->sum('imponibile_scontato');
}
/**
* Calcola l'IVA totale della fattura.
*
* @return float
*/
public function getIva()
{
return $this->getRighe()->sum('iva');
}
/**
* Calcola la rivalsa INPS totale della fattura.
*
* @return float
*/
public function getRivalsaINPS()
{
return $this->getRighe()->sum('rivalsa_inps');
}
/**
* Calcola la ritenuta d'acconto totale della fattura.
*
* @return float
*/
public function getRitenutaAcconto()
{
return $this->getRighe()->sum('ritenuta_acconto');
}
/**
* Calcola il totale della fattura.
*
* @return float
*/
public function getTotale()
{
return $this->getRighe()->sum('totale');
}
/**
* Calcola il netto a pagare della fattura.
*
* @return float
*/
public function getNetto()
public function getNettoAttribute()
{
return $this->getRighe()->sum('netto') + $this->bollo;
return parent::getNettoAttribute() + $this->bollo;
}
/**

View File

@ -2,10 +2,10 @@
namespace Modules\Interventi;
use Common\Model;
use Common\Document;
use Modules\Anagrafiche\Anagrafica;
class Intervento extends Model
class Intervento extends Document
{
protected $table = 'in_interventi';

View File

@ -246,9 +246,9 @@ class Backup
if (file_exists($database_file)) {
$database->query('SET foreign_key_checks = 0');
foreach ($tables as $tables) {
$database->query('DROP TABLE `'.$tables.'`');
$database->query('DROP TABLE IF EXISTS `'.$tables.'`');
}
$database->query('DROP TABLE `updates`');
$database->query('DROP TABLE IF EXISTS `updates`');
// Ripristino del database
$database->multiQuery($database_file);