Miglioramenti struttura documenti
@lucasalva87 Ho aggiornato il totale documento della fattura elettronica per funzionare con i nuovi oggetti.
This commit is contained in:
parent
e812025848
commit
0e81099c4b
|
@ -26,6 +26,23 @@ abstract class Document extends Model
|
|||
|
||||
abstract public function scontoGlobale();
|
||||
|
||||
/**
|
||||
* Calcola la somma degli attributi indicati come parametri.
|
||||
*
|
||||
* @param mixed ...$args
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
public function calcola(...$args)
|
||||
{
|
||||
$result = 0;
|
||||
foreach ($args as $arg) {
|
||||
$result += $this->getRigheContabili()->sum($arg);
|
||||
}
|
||||
|
||||
return $this->round($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calcola l'imponibile della fattura.
|
||||
*
|
||||
|
@ -33,7 +50,7 @@ abstract class Document extends Model
|
|||
*/
|
||||
public function getImponibileAttribute()
|
||||
{
|
||||
return $this->round($this->getRigheContabili()->sum('imponibile'));
|
||||
return $this->calcola('imponibile');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -43,7 +60,7 @@ abstract class Document extends Model
|
|||
*/
|
||||
public function getScontoAttribute()
|
||||
{
|
||||
return $this->round($this->getRigheContabili()->sum('sconto'));
|
||||
return $this->calcola('sconto');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -53,7 +70,7 @@ abstract class Document extends Model
|
|||
*/
|
||||
public function getImponibileScontatoAttribute()
|
||||
{
|
||||
return $this->round($this->getRigheContabili()->sum('imponibile_scontato'));
|
||||
return $this->calcola('imponibile_scontato');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -63,7 +80,7 @@ abstract class Document extends Model
|
|||
*/
|
||||
public function getIvaAttribute()
|
||||
{
|
||||
return $this->round($this->getRigheContabili()->sum('iva'));
|
||||
return $this->calcola('iva');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -73,7 +90,7 @@ abstract class Document extends Model
|
|||
*/
|
||||
public function getRivalsaINPSAttribute()
|
||||
{
|
||||
return $this->round($this->getRigheContabili()->sum('rivalsa_inps'));
|
||||
return $this->calcola('rivalsa_inps');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -83,7 +100,7 @@ abstract class Document extends Model
|
|||
*/
|
||||
public function getRitenutaAccontoAttribute()
|
||||
{
|
||||
return $this->round($this->getRigheContabili()->sum('ritenuta_acconto'));
|
||||
return $this->calcola('ritenuta_acconto');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -93,7 +110,7 @@ abstract class Document extends Model
|
|||
*/
|
||||
public function getTotaleAttribute()
|
||||
{
|
||||
return $this->round($this->getRigheContabili()->sum('totale'));
|
||||
return $this->calcola('totale');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -103,7 +120,7 @@ abstract class Document extends Model
|
|||
*/
|
||||
public function getNettoAttribute()
|
||||
{
|
||||
return $this->round($this->getRigheContabili()->sum('netto'));
|
||||
return $this->calcola('netto');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -113,7 +130,7 @@ abstract class Document extends Model
|
|||
*/
|
||||
public function getSpesaAttribute()
|
||||
{
|
||||
return $this->round($this->getRigheContabili()->sum('spesa'));
|
||||
return $this->calcola('spesa');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -123,7 +140,7 @@ abstract class Document extends Model
|
|||
*/
|
||||
public function getGuadagnoAttribute()
|
||||
{
|
||||
return $this->round($this->getRigheContabili()->sum('guadagno'));
|
||||
return $this->calcola('guadagno');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -102,19 +102,19 @@ $(document).ready(function () {
|
|||
});
|
||||
}
|
||||
);
|
||||
|
||||
// Pulsante per visualizzare/ nascondere la password
|
||||
$(".input-group-addon").on('click', 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', 'Nascondi password');
|
||||
} else if ($(this).parent().find("i").hasClass('fa-eye-slash')) {
|
||||
$("#password").attr("type", "password");
|
||||
$(this).parent().find("i").removeClass('fa-eye-slash').addClass('fa-eye');
|
||||
$(this).parent().find("i").attr('title', 'Visualizza password');
|
||||
}
|
||||
});
|
||||
|
||||
// Pulsante per visualizzare/ nascondere la password
|
||||
$(".input-group-addon").on('click', 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', 'Nascondi password');
|
||||
} else if ($(this).parent().find("i").hasClass('fa-eye-slash')) {
|
||||
$("#password").attr("type", "password");
|
||||
$(this).parent().find("i").removeClass('fa-eye-slash').addClass('fa-eye');
|
||||
$(this).parent().find("i").attr('title', 'Visualizza password');
|
||||
}
|
||||
});
|
||||
|
||||
// Messaggi automatici di eliminazione
|
||||
$(document).on('click', '.ask', function () {
|
||||
|
@ -444,7 +444,8 @@ function start_widgets($widgets) {
|
|||
// Modal
|
||||
function launch_modal(title, href, init_modal, id) {
|
||||
// Fix - Select2 does not function properly when I use it inside a Bootstrap modal.
|
||||
$.fn.modal.Constructor.prototype.enforceFocus = function () {};
|
||||
$.fn.modal.Constructor.prototype.enforceFocus = function () {
|
||||
};
|
||||
|
||||
if (id == null) {
|
||||
id = '#bs-popup';
|
||||
|
@ -599,14 +600,14 @@ function start_datatables() {
|
|||
selector: 'td:first-child'
|
||||
},
|
||||
buttons: [{
|
||||
extend: 'csv',
|
||||
fieldSeparator: ";",
|
||||
exportOptions: {
|
||||
modifier: {
|
||||
selected: true
|
||||
}
|
||||
extend: 'csv',
|
||||
fieldSeparator: ";",
|
||||
exportOptions: {
|
||||
modifier: {
|
||||
selected: true
|
||||
}
|
||||
},
|
||||
}
|
||||
},
|
||||
{
|
||||
extend: 'copy',
|
||||
exportOptions: {
|
||||
|
@ -767,8 +768,8 @@ function start_datatables() {
|
|||
var container = $(document).find('[data-target=' + $this.attr('id') + ']');
|
||||
|
||||
if (api.rows({
|
||||
selected: true
|
||||
}).count() > 0) {
|
||||
selected: true
|
||||
}).count() > 0) {
|
||||
container.find('.table-btn').removeClass('disabled').attr('disabled', false);
|
||||
} else {
|
||||
container.find('.table-btn').addClass('disabled').attr('disabled', true);
|
||||
|
@ -781,8 +782,8 @@ function start_datatables() {
|
|||
}).select();
|
||||
|
||||
if (this.fnSettings().fnRecordsDisplay() == api.rows({
|
||||
selected: true
|
||||
}).count()) {
|
||||
selected: true
|
||||
}).count()) {
|
||||
$("#main_loading").fadeOut();
|
||||
}
|
||||
}
|
||||
|
@ -842,8 +843,8 @@ function start_datatables() {
|
|||
}
|
||||
|
||||
if (table.rows({
|
||||
selected: true
|
||||
}).count() > 0) {
|
||||
selected: true
|
||||
}).count() > 0) {
|
||||
container.find('.table-btn').removeClass('disabled').attr('disabled', false);
|
||||
} else {
|
||||
container.find('.table-btn').addClass('disabled').attr('disabled', true);
|
||||
|
@ -1211,6 +1212,7 @@ function session_set(session_array, value, clear, reload) {
|
|||
function session_keep_alive() {
|
||||
$.get(globals.rootdir + '/core.php');
|
||||
}
|
||||
|
||||
/**
|
||||
* Funzione per gestire i contatori testuali nel formato x/total.
|
||||
* Viene dato un id del campo da verificare come input, viene letto il testo nella forma [0-9]/[0-9] e viene fatto
|
||||
|
@ -1384,7 +1386,8 @@ function message(element) {
|
|||
redirect(href, data, method, blank);
|
||||
}
|
||||
},
|
||||
function (dismiss) {}
|
||||
function (dismiss) {
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -3,16 +3,13 @@
|
|||
namespace Plugins\ExportFE;
|
||||
|
||||
use DateTime;
|
||||
use DOMDocument;
|
||||
use FluidXml\FluidXml;
|
||||
use GuzzleHttp\Client;
|
||||
use Modules;
|
||||
use Plugins;
|
||||
use Prints;
|
||||
use Respect\Validation\Validator as v;
|
||||
use Stringy\Stringy as S;
|
||||
use Uploads;
|
||||
use XSLTProcessor;
|
||||
|
||||
/**
|
||||
* Classe per la gestione della fatturazione elettronica in XML.
|
||||
|
@ -575,7 +572,7 @@ class FatturaElettronica
|
|||
|
||||
public function __toString()
|
||||
{
|
||||
return $this->toHTML();
|
||||
return $this->toXML();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -744,6 +741,15 @@ class FatturaElettronica
|
|||
return $this->errors;
|
||||
}
|
||||
|
||||
/**
|
||||
* Ottiene il codice destinatario a partire dal database ufficiale indicepa www.indicepa.gov.it.
|
||||
*
|
||||
* @param $codice_fiscale
|
||||
*
|
||||
* @throws \GuzzleHttp\Exception\GuzzleException
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public static function PA($codice_fiscale)
|
||||
{
|
||||
$id = setting('Authorization ID Indice PA');
|
||||
|
@ -752,7 +758,7 @@ class FatturaElettronica
|
|||
return null;
|
||||
}
|
||||
|
||||
// Localhost:
|
||||
// Configurazione per localhost: CURLOPT_SSL_VERIFYPEER
|
||||
$client = new Client(['curl' => [CURLOPT_SSL_VERIFYPEER => false]]);
|
||||
|
||||
$response = $client->request('POST', 'https://www.indicepa.gov.it/public-ws/WS01_SFE_CF.php', [
|
||||
|
@ -877,28 +883,6 @@ class FatturaElettronica
|
|||
return $this->xml;
|
||||
}
|
||||
|
||||
/**
|
||||
* Restituisce il codice XML formattato della fattura elettronica.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function toHTML()
|
||||
{
|
||||
// XML
|
||||
$xml = new DOMDocument();
|
||||
$xml->loadXML($this->toXML());
|
||||
|
||||
// XSL
|
||||
$xsl = new DOMDocument();
|
||||
$xsl->load(__DIR__.'/stylesheet-1.2.1.xsl');
|
||||
|
||||
// XSLT
|
||||
$xslt = new XSLTProcessor();
|
||||
$xslt->importStylesheet($xsl);
|
||||
|
||||
return $xslt->transformToXML($xml);
|
||||
}
|
||||
|
||||
/**
|
||||
* Restituisce l'array responsabile per la generazione del tag DatiTrasmission.
|
||||
*
|
||||
|
@ -1164,45 +1148,11 @@ class FatturaElettronica
|
|||
|
||||
$result['ScontoMaggiorazione'] = $sconto;
|
||||
}
|
||||
|
||||
// Importo Totale Documento (2.1.1.9)
|
||||
//Importo totale del documento al netto dell'eventuale sconto e comprensivo di imposta a debito del cessionario / committente
|
||||
|
||||
// Calcoli
|
||||
$imponibile = sum(array_column($righe, 'subtotale'));
|
||||
//$sconto = sum(array_column($righe, 'sconto'));
|
||||
$iva = sum(array_column($righe, 'iva'));
|
||||
|
||||
//$imponibile_scontato = sum($imponibile, -$sconto);
|
||||
|
||||
$totale_iva = sum($iva, $record['iva_rivalsainps']);
|
||||
|
||||
/*$totale = sum([
|
||||
$imponibile_scontato,
|
||||
$record['rivalsainps'],
|
||||
$totale_iva,
|
||||
]);
|
||||
|
||||
$netto_a_pagare = sum([
|
||||
$totale,
|
||||
$record['bollo'],
|
||||
-$record['ritenutaacconto'],
|
||||
]);
|
||||
|
||||
$imponibile = abs($imponibile);
|
||||
$sconto = abs($sconto);
|
||||
$iva = abs($iva);
|
||||
$imponibile_scontato = abs($imponibile_scontato);
|
||||
$totale_iva = abs($totale_iva);
|
||||
$totale = abs($totale);
|
||||
$netto_a_pagare = abs($netto_a_pagare);*/
|
||||
|
||||
|
||||
|
||||
if (!empty($imponibile)) {
|
||||
|
||||
$result['ImportoTotaleDocumento'] = $imponibile+$totale_iva;
|
||||
}
|
||||
// Importo Totale Documento (2.1.1.9)
|
||||
// Importo totale del documento al netto dell'eventuale sconto e comprensivo di imposta a debito del cessionario / committente
|
||||
$fattura = Modules\Fatture\Fattura::find($documento['id']);
|
||||
$result['ImportoTotaleDocumento'] = $fattura->calcola('imponibile', 'iva');
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
@ -1406,23 +1356,21 @@ class FatturaElettronica
|
|||
$dettaglio = [
|
||||
'NumeroLinea' => $numero + 1,
|
||||
];
|
||||
|
||||
// 2.2.1.2
|
||||
|
||||
// 2.2.1.2
|
||||
if (!empty($riga['tipo_cessione_prestazione'])) {
|
||||
$dettaglio['TipoCessionePrestazione'] = $riga['tipo_cessione_prestazione'];
|
||||
}
|
||||
|
||||
//2.2.1.3
|
||||
if (!empty($riga['idarticolo'])) {
|
||||
|
||||
$codice_articolo = [
|
||||
|
||||
//2.2.1.3
|
||||
if (!empty($riga['idarticolo'])) {
|
||||
$codice_articolo = [
|
||||
'CodiceTipo' => 'OSM',
|
||||
'CodiceValore' => $database->fetchOne('SELECT `codice` FROM `mg_articoli` WHERE `id` = '.prepare($riga['idarticolo']))['codice']
|
||||
'CodiceValore' => $database->fetchOne('SELECT `codice` FROM `mg_articoli` WHERE `id` = '.prepare($riga['idarticolo']))['codice'],
|
||||
];
|
||||
|
||||
$dettaglio['CodiceArticolo'] = $codice_articolo;
|
||||
}
|
||||
|
||||
|
||||
$dettaglio['CodiceArticolo'] = $codice_articolo;
|
||||
}
|
||||
|
||||
$dettaglio['Descrizione'] = $riga['descrizione'];
|
||||
$dettaglio['Quantita'] = $riga['qta'];
|
||||
|
@ -1714,11 +1662,13 @@ class FatturaElettronica
|
|||
$size = isset($info['size']) ? $info['size'] : null;
|
||||
|
||||
$output = $input;
|
||||
|
||||
// Operazioni di normalizzazione
|
||||
// Formattazione decimali
|
||||
if ($info['type'] == 'decimal') {
|
||||
$output = number_format($output, 2, '.', '');
|
||||
}
|
||||
|
||||
// Formattazione date
|
||||
elseif ($info['type'] == 'date') {
|
||||
$object = DateTime::createFromFormat('Y-m-d H:i:s', $output);
|
||||
|
@ -1726,6 +1676,7 @@ class FatturaElettronica
|
|||
$output = $object->format('Y-m-d');
|
||||
}
|
||||
}
|
||||
|
||||
// Formattazione testo
|
||||
elseif ($info['type'] == 'string') {
|
||||
}
|
||||
|
|
|
@ -2,4 +2,16 @@
|
|||
|
||||
include_once __DIR__.'/init.php';
|
||||
|
||||
echo $fattura_pa;
|
||||
// XML
|
||||
$xml = new DOMDocument();
|
||||
$xml->loadXML($fattura_pa->toXML());
|
||||
|
||||
// XSL
|
||||
$xsl = new DOMDocument();
|
||||
$xsl->load(__DIR__.'/src/stylesheet-1.2.1.xsl');
|
||||
|
||||
// XSLT
|
||||
$xslt = new XSLTProcessor();
|
||||
$xslt->importStylesheet($xsl);
|
||||
|
||||
echo $xslt->transformToXML($xml);
|
||||
|
|
Loading…
Reference in New Issue