mirror of
https://github.com/devcode-it/openstamanager.git
synced 2025-06-05 22:09:38 +02:00
Fix generali
This commit is contained in:
@@ -37,18 +37,17 @@ if ($dir == 'entrata') {
|
|||||||
if ($dir == 'entrata') {
|
if ($dir == 'entrata') {
|
||||||
$rs2 = $dbo->fetchArray('SELECT piva, codice_fiscale, citta, indirizzo, cap, provincia, id_nazione, tipo FROM an_anagrafiche WHERE idanagrafica='.prepare($record['idanagrafica']));
|
$rs2 = $dbo->fetchArray('SELECT piva, codice_fiscale, citta, indirizzo, cap, provincia, id_nazione, tipo FROM an_anagrafiche WHERE idanagrafica='.prepare($record['idanagrafica']));
|
||||||
$campi_mancanti = [];
|
$campi_mancanti = [];
|
||||||
|
|
||||||
|
//di default è un azienda e chiedo la partita iva
|
||||||
//di default è un azienda e chiedo la partita iva
|
if (empty($rs2[0]['piva']) and (empty($rs2[0]['tipo']) or $rs2[0]['tipo'] == 'Azienda')) {
|
||||||
if (empty($rs2[0]['piva']) and (empty($rs2[0]['tipo']) or $rs2[0]['tipo'] == 'Azienda')) {
|
|
||||||
array_push($campi_mancanti, 'Partita IVA');
|
array_push($campi_mancanti, 'Partita IVA');
|
||||||
}
|
}
|
||||||
|
|
||||||
//se è un privato o un ente pubblico controllo il codice fiscale
|
//se è un privato o un ente pubblico controllo il codice fiscale
|
||||||
if (($rs2[0]['tipo'] == 'Privato' or $rs2[0]['tipo'] == 'Ente pubblico') and empty($rs2[0]['codice_fiscale'])) {
|
if (($rs2[0]['tipo'] == 'Privato' or $rs2[0]['tipo'] == 'Ente pubblico') and empty($rs2[0]['codice_fiscale'])) {
|
||||||
array_push($campi_mancanti, 'Codice fiscale');
|
array_push($campi_mancanti, 'Codice fiscale');
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($rs2[0]['citta'] == '') {
|
if ($rs2[0]['citta'] == '') {
|
||||||
array_push($campi_mancanti, 'Città');
|
array_push($campi_mancanti, 'Città');
|
||||||
}
|
}
|
||||||
@@ -263,7 +262,7 @@ if ($dir == 'uscita') {
|
|||||||
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-md-12">
|
<div class="col-md-12">
|
||||||
{[ "type": "textarea", "label": "<?php echo tr('Note aggiuntive'); ?>", "name": "note_aggiuntive", "help": "<?php echo tr('Note interne.'); ?>", "value": "$note_aggiuntive$" ]}
|
{[ "type": "textarea", "label": "<?php echo tr('Note aggiuntive'); ?>", "name": "note_aggiuntive", "help": "<?php echo tr('Note interne.'); ?>", "value": "$note_aggiuntive$", "class": "unblockable" ]}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@@ -109,11 +109,12 @@ function aggiungi_scadenza($iddocumento, $pagamento = '', $pagato = 0)
|
|||||||
{
|
{
|
||||||
$dbo = database();
|
$dbo = database();
|
||||||
|
|
||||||
$totale_da_pagare = 0.00;
|
$fattura = Fattura::find($iddocumento);
|
||||||
$totale_fattura = get_totale_fattura($iddocumento);
|
|
||||||
$netto_fattura = get_netto_fattura($iddocumento);
|
$ricalcola = true;
|
||||||
$imponibile_fattura = get_imponibile_fattura($iddocumento);
|
if ($fattura->isFE()) {
|
||||||
$totale_iva = sum(abs($totale_fattura), -abs($imponibile_fattura));
|
$ricalcola = $fattura->registraScadenzeFE($pagato);
|
||||||
|
}
|
||||||
|
|
||||||
// Lettura data di emissione fattura
|
// Lettura data di emissione fattura
|
||||||
$query3 = 'SELECT ritenutaacconto, data FROM co_documenti WHERE id='.prepare($iddocumento);
|
$query3 = 'SELECT ritenutaacconto, data FROM co_documenti WHERE id='.prepare($iddocumento);
|
||||||
@@ -121,77 +122,86 @@ function aggiungi_scadenza($iddocumento, $pagamento = '', $pagato = 0)
|
|||||||
$data = $rs[0]['data'];
|
$data = $rs[0]['data'];
|
||||||
$ritenutaacconto = $rs[0]['ritenutaacconto'];
|
$ritenutaacconto = $rs[0]['ritenutaacconto'];
|
||||||
|
|
||||||
// Verifico se la fattura è di acquisto o di vendita per scegliere che segno mettere nel totale
|
if ($ricalcola) {
|
||||||
$query2 = 'SELECT dir FROM co_documenti INNER JOIN co_tipidocumento ON co_documenti.idtipodocumento=co_tipidocumento.id WHERE co_documenti.id='.prepare($iddocumento);
|
$totale_da_pagare = 0.00;
|
||||||
$rs2 = $dbo->fetchArray($query2);
|
|
||||||
$dir = $rs2[0]['dir'];
|
|
||||||
|
|
||||||
/*
|
$totale_fattura = get_totale_fattura($iddocumento);
|
||||||
Inserisco la nuova scadenza (anche più di una riga per pagamenti multipli
|
$netto_fattura = get_netto_fattura($iddocumento);
|
||||||
*/
|
$imponibile_fattura = get_imponibile_fattura($iddocumento);
|
||||||
// Se il pagamento non è specificato lo leggo dal documento
|
$totale_iva = sum(abs($totale_fattura), -abs($imponibile_fattura));
|
||||||
if ($pagamento == '') {
|
|
||||||
$query = 'SELECT descrizione FROM co_pagamenti WHERE id=(SELECT idpagamento FROM co_documenti WHERE id='.prepare($iddocumento).')';
|
|
||||||
$rs = $dbo->fetchArray($query);
|
|
||||||
$pagamento = $rs[0]['descrizione'];
|
|
||||||
}
|
|
||||||
|
|
||||||
$query4 = 'SELECT * FROM co_pagamenti WHERE descrizione='.prepare($pagamento);
|
// Verifico se la fattura è di acquisto o di vendita per scegliere che segno mettere nel totale
|
||||||
$rs = $dbo->fetchArray($query4);
|
$query2 = 'SELECT dir FROM co_documenti INNER JOIN co_tipidocumento ON co_documenti.idtipodocumento=co_tipidocumento.id WHERE co_documenti.id='.prepare($iddocumento);
|
||||||
for ($i = 0; $i < sizeof($rs); ++$i) {
|
$rs2 = $dbo->fetchArray($query2);
|
||||||
// X giorni esatti
|
$dir = $rs2[0]['dir'];
|
||||||
if ($rs[$i]['giorno'] == 0) {
|
|
||||||
$scadenza = date('Y-m-d', strtotime($data.' +'.$rs[$i]['num_giorni'].' day'));
|
/*
|
||||||
|
Inserisco la nuova scadenza (anche più di una riga per pagamenti multipli
|
||||||
|
*/
|
||||||
|
// Se il pagamento non è specificato lo leggo dal documento
|
||||||
|
if ($pagamento == '') {
|
||||||
|
$query = 'SELECT descrizione FROM co_pagamenti WHERE id=(SELECT idpagamento FROM co_documenti WHERE id='.prepare($iddocumento).')';
|
||||||
|
$rs = $dbo->fetchArray($query);
|
||||||
|
$pagamento = $rs[0]['descrizione'];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ultimo del mese
|
$query4 = 'SELECT * FROM co_pagamenti WHERE descrizione='.prepare($pagamento);
|
||||||
elseif ($rs[$i]['giorno'] < 0) {
|
$rs = $dbo->fetchArray($query4);
|
||||||
$date = new DateTime($data);
|
for ($i = 0; $i < sizeof($rs); ++$i) {
|
||||||
|
// X giorni esatti
|
||||||
$add = floor($rs[$i]['num_giorni'] / 30);
|
if ($rs[$i]['giorno'] == 0) {
|
||||||
for ($c = 0; $c < $add; ++$c) {
|
$scadenza = date('Y-m-d', strtotime($data.' +'.$rs[$i]['num_giorni'].' day'));
|
||||||
$date->modify('last day of next month');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ultimo del mese più X giorni
|
// Ultimo del mese
|
||||||
$giorni = -$rs[$i]['giorno'] - 1;
|
elseif ($rs[$i]['giorno'] < 0) {
|
||||||
if ($giorni > 0) {
|
$date = new DateTime($data);
|
||||||
$date->modify('+'.($giorni).' day');
|
|
||||||
} else {
|
$add = floor($rs[$i]['num_giorni'] / 30);
|
||||||
$date->modify('last day of this month');
|
for ($c = 0; $c < $add; ++$c) {
|
||||||
|
$date->modify('last day of next month');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ultimo del mese più X giorni
|
||||||
|
$giorni = -$rs[$i]['giorno'] - 1;
|
||||||
|
if ($giorni > 0) {
|
||||||
|
$date->modify('+'.($giorni).' day');
|
||||||
|
} else {
|
||||||
|
$date->modify('last day of this month');
|
||||||
|
}
|
||||||
|
|
||||||
|
$scadenza = $date->format('Y-m-d');
|
||||||
}
|
}
|
||||||
|
|
||||||
$scadenza = $date->format('Y-m-d');
|
// Giorno preciso del mese
|
||||||
}
|
else {
|
||||||
|
$scadenza = date('Y-m-'.$rs[$i]['giorno'], strtotime($data.' +'.$rs[$i]['num_giorni'].' day'));
|
||||||
|
}
|
||||||
|
|
||||||
// Giorno preciso del mese
|
// All'ultimo ciclo imposto come cifra da pagare il totale della fattura meno gli importi già inseriti in scadenziario per evitare di inserire cifre arrotondate "male"
|
||||||
else {
|
if ($i == (sizeof($rs) - 1)) {
|
||||||
$scadenza = date('Y-m-'.$rs[$i]['giorno'], strtotime($data.' +'.$rs[$i]['num_giorni'].' day'));
|
$da_pagare = sum($netto_fattura, -$totale_da_pagare, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
// All'ultimo ciclo imposto come cifra da pagare il totale della fattura meno gli importi già inseriti in scadenziario per evitare di inserire cifre arrotondate "male"
|
// Totale da pagare (totale x percentuale di pagamento nei casi pagamenti multipli)
|
||||||
if ($i == (sizeof($rs) - 1)) {
|
else {
|
||||||
$da_pagare = sum($netto_fattura, -$totale_da_pagare, 2);
|
$da_pagare = sum($netto_fattura / 100 * $rs[$i]['prc'], 0, 2);
|
||||||
}
|
}
|
||||||
|
$totale_da_pagare = sum($da_pagare, $totale_da_pagare, 2);
|
||||||
|
|
||||||
// Totale da pagare (totale x percentuale di pagamento nei casi pagamenti multipli)
|
if ($dir == 'uscita') {
|
||||||
else {
|
$da_pagare = -$da_pagare;
|
||||||
$da_pagare = sum($netto_fattura / 100 * $rs[$i]['prc'], 0, 2);
|
}
|
||||||
}
|
|
||||||
$totale_da_pagare = sum($da_pagare, $totale_da_pagare, 2);
|
|
||||||
|
|
||||||
if ($dir == 'uscita') {
|
$dbo->query('INSERT INTO co_scadenziario(iddocumento, data_emissione, scadenza, da_pagare, pagato, tipo) VALUES('.prepare($iddocumento).', '.prepare($data).', '.prepare($scadenza).', '.prepare($da_pagare).", 0, 'fattura')");
|
||||||
$da_pagare = -$da_pagare;
|
|
||||||
}
|
|
||||||
|
|
||||||
$dbo->query('INSERT INTO co_scadenziario(iddocumento, data_emissione, scadenza, da_pagare, pagato, tipo) VALUES('.prepare($iddocumento).', '.prepare($data).', '.prepare($scadenza).', '.prepare($da_pagare).", 0, 'fattura')");
|
if ($pagato) {
|
||||||
|
$id_scadenza = $dbo->lastInsertedID();
|
||||||
if ($pagato) {
|
$dbo->update('co_scadenziario', [
|
||||||
$id_scadenza = $dbo->lastInsertedID();
|
|
||||||
$dbo->update('co_scadenziario', [
|
|
||||||
'pagato' => $da_pagare,
|
'pagato' => $da_pagare,
|
||||||
'data_pagamento' => $data,
|
'data_pagamento' => $data,
|
||||||
], ['id' => $id_scadenza]);
|
], ['id' => $id_scadenza]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -4,6 +4,7 @@ namespace Modules\Fatture;
|
|||||||
|
|
||||||
use Common\Document;
|
use Common\Document;
|
||||||
use Modules\Anagrafiche\Anagrafica;
|
use Modules\Anagrafiche\Anagrafica;
|
||||||
|
use Plugins\ExportFE\FatturaElettronica;
|
||||||
use Traits\RecordTrait;
|
use Traits\RecordTrait;
|
||||||
use Util\Generator;
|
use Util\Generator;
|
||||||
|
|
||||||
@@ -226,6 +227,51 @@ class Fattura extends Document
|
|||||||
return $this->hasOne(Components\Sconto::class, 'iddocumento');
|
return $this->hasOne(Components\Sconto::class, 'iddocumento');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getXML()
|
||||||
|
{
|
||||||
|
if (empty($this->progressivo_invio)) {
|
||||||
|
$fe = new FatturaElettronica($this->id);
|
||||||
|
|
||||||
|
return $fe->toXML();
|
||||||
|
}
|
||||||
|
|
||||||
|
$file = $this->uploads()->where('name', 'Fattura Elettronica')->first();
|
||||||
|
|
||||||
|
return file_get_contents($file->filepath);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function isFE()
|
||||||
|
{
|
||||||
|
return !empty($this->progressivo_invio) && $this->module == 'Fatture di acquisto';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function registraScadenzeFE($is_pagato = false)
|
||||||
|
{
|
||||||
|
$database = $dbo = database();
|
||||||
|
|
||||||
|
$xml = \Util\XML::read($this->getXML());
|
||||||
|
|
||||||
|
$scadenze = $xml['FatturaElettronicaBody']['DatiPagamento']['DettaglioPagamento'];
|
||||||
|
$scadenze = isset($scadenze[0]) ? $scadenze : [$scadenze];
|
||||||
|
|
||||||
|
foreach ($scadenze as $scadenza) {
|
||||||
|
$data = $scadenza['DataScadenzaPagamento'];
|
||||||
|
$importo = $scadenza['ImportoPagamento'];
|
||||||
|
|
||||||
|
$dbo->insert('co_scadenziario', [
|
||||||
|
'iddocumento' => $this->id,
|
||||||
|
'data_emissione' => $this->data,
|
||||||
|
'scadenza' => $data,
|
||||||
|
'da_pagare' => $importo,
|
||||||
|
'tipo' => 'fattura',
|
||||||
|
'pagato' => $is_pagato ? $importo : 0,
|
||||||
|
'data_pagamento' => $is_pagato ? $data : '',
|
||||||
|
], ['id' => $id_scadenza]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return !empty($scadenze);
|
||||||
|
}
|
||||||
|
|
||||||
// Metodi statici
|
// Metodi statici
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -20,9 +20,8 @@ if (!empty($fattura_pa)) {
|
|||||||
$generated = false;
|
$generated = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Natura obbligatoria per iva con esenzione
|
// Natura obbligatoria per iva con esenzione
|
||||||
$iva = $database->fetchOne('SELECT * FROM `co_iva` WHERE `id` IN (SELECT idiva FROM co_righe_documenti WHERE iddocumento = '.prepare($id_record).') AND esente = 1' );
|
$iva = $database->fetchOne('SELECT * FROM `co_iva` WHERE `id` IN (SELECT idiva FROM co_righe_documenti WHERE iddocumento = '.prepare($id_record).') AND esente = 1');
|
||||||
$fields = [
|
$fields = [
|
||||||
'codice_natura_fe' => 'Natura IVA',
|
'codice_natura_fe' => 'Natura IVA',
|
||||||
];
|
];
|
||||||
@@ -45,8 +44,6 @@ if (!empty($missing) && !$generated) {
|
|||||||
//$disabled = true;
|
//$disabled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Campi obbligatori per il pagamento
|
// Campi obbligatori per il pagamento
|
||||||
$pagamento = $database->fetchOne('SELECT * FROM `co_pagamenti` WHERE `id` = '.prepare($record['idpagamento']));
|
$pagamento = $database->fetchOne('SELECT * FROM `co_pagamenti` WHERE `id` = '.prepare($record['idpagamento']));
|
||||||
$fields = [
|
$fields = [
|
||||||
@@ -164,7 +161,7 @@ echo '
|
|||||||
echo '
|
echo '
|
||||||
<i class="fa fa-arrow-right fa-fw text-muted"></i>
|
<i class="fa fa-arrow-right fa-fw text-muted"></i>
|
||||||
|
|
||||||
<a href="'.ROOTDIR.'/plugins/exportFE/download.php?id_record='.$id_record.'" class="btn btn-success btn-lg '.($generated ? '' : 'disabled').'" target="_blank" '.($generated ? '' : 'disabled').'>
|
<a href="'.$structure->fileurl('download.php').'?id_record='.$id_record.'" class="btn btn-success btn-lg '.($generated ? '' : 'disabled').'" target="_blank" '.($generated ? '' : 'disabled').'>
|
||||||
<i class="fa fa-download"></i> '.tr('Scarica').'
|
<i class="fa fa-download"></i> '.tr('Scarica').'
|
||||||
</a>';
|
</a>';
|
||||||
|
|
||||||
@@ -209,7 +206,7 @@ if (!empty($record['codice_stato_fe'])) {
|
|||||||
echo '
|
echo '
|
||||||
<div class="alert text-left alert-'.$class.'">
|
<div class="alert text-left alert-'.$class.'">
|
||||||
<big><i class="'.$stato_fe['icon'].'" style="color:#fff;"></i>
|
<big><i class="'.$stato_fe['icon'].'" style="color:#fff;"></i>
|
||||||
<b>'.$stato_fe['codice'].'</b> - '.$stato_fe['descrizione'].'</big> '.( !empty($record['descrizione_ricevuta_fe']) ? '<br><b>NOTE:</b><br>'.$record['descrizione_ricevuta_fe'] : '' ).'
|
<b>'.$stato_fe['codice'].'</b> - '.$stato_fe['descrizione'].'</big> '.(!empty($record['descrizione_ricevuta_fe']) ? '<br><b>NOTE:</b><br>'.$record['descrizione_ricevuta_fe'] : '').'
|
||||||
<div class="pull-right">
|
<div class="pull-right">
|
||||||
<i class="fa fa-clock-o"></i> '.Translator::timestampToLocale($record['data_stato_fe']).'
|
<i class="fa fa-clock-o"></i> '.Translator::timestampToLocale($record['data_stato_fe']).'
|
||||||
</div>
|
</div>
|
||||||
|
@@ -5,8 +5,6 @@ include_once __DIR__.'/../../core.php';
|
|||||||
use Plugins\ImportFE\FatturaElettronica;
|
use Plugins\ImportFE\FatturaElettronica;
|
||||||
use Plugins\ImportFE\Interaction;
|
use Plugins\ImportFE\Interaction;
|
||||||
|
|
||||||
$directory = Uploads::getDirectory($id_module);
|
|
||||||
|
|
||||||
switch (filter('op')) {
|
switch (filter('op')) {
|
||||||
case 'save':
|
case 'save':
|
||||||
$content = file_get_contents($_FILES['blob']['tmp_name']);
|
$content = file_get_contents($_FILES['blob']['tmp_name']);
|
||||||
@@ -40,6 +38,13 @@ switch (filter('op')) {
|
|||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 'delete':
|
||||||
|
$directory = Plugins\ImportFE\FatturaElettronica::getImportDirectory();
|
||||||
|
|
||||||
|
delete($directory.'/'.get('filename'));
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
case 'generate':
|
case 'generate':
|
||||||
$filename = post('filename');
|
$filename = post('filename');
|
||||||
|
|
||||||
|
@@ -81,16 +81,22 @@ echo '
|
|||||||
</div>
|
</div>
|
||||||
</div>';
|
</div>';
|
||||||
|
|
||||||
if (Interaction::isEnabled()) {
|
echo '
|
||||||
echo '
|
|
||||||
<div class="box box-info">
|
<div class="box box-info">
|
||||||
<div class="box-header with-border">
|
<div class="box-header with-border">
|
||||||
<h3 class="box-title">
|
<h3 class="box-title">
|
||||||
'.tr('Importazione automatica').'</span>
|
'.tr('Fatture da importare').'</span>
|
||||||
</h3>
|
</h3>';
|
||||||
|
|
||||||
|
// Ricerca automatica
|
||||||
|
if (Interaction::isEnabled()) {
|
||||||
|
echo '
|
||||||
<button type="button" class="btn btn-primary pull-right" onclick="search(this)">
|
<button type="button" class="btn btn-primary pull-right" onclick="search(this)">
|
||||||
<i class="fa fa-refresh"></i> '.tr('Ricerca fatture di acquisto').'
|
<i class="fa fa-refresh"></i> '.tr('Ricerca fatture di acquisto').'
|
||||||
</button>
|
</button>';
|
||||||
|
}
|
||||||
|
|
||||||
|
echo '
|
||||||
</div>
|
</div>
|
||||||
<div class="box-body" id="list">';
|
<div class="box-body" id="list">';
|
||||||
|
|
||||||
@@ -110,4 +116,3 @@ function search(button) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
</script>';
|
</script>';
|
||||||
}
|
|
||||||
|
@@ -5,6 +5,7 @@ include_once __DIR__.'/../../core.php';
|
|||||||
use Plugins\ImportFE\Interaction;
|
use Plugins\ImportFE\Interaction;
|
||||||
|
|
||||||
$list = Interaction::listToImport();
|
$list = Interaction::listToImport();
|
||||||
|
$directory = Plugins\ImportFE\FatturaElettronica::getImportDirectory();
|
||||||
|
|
||||||
if (!empty($list)) {
|
if (!empty($list)) {
|
||||||
echo '
|
echo '
|
||||||
@@ -12,7 +13,7 @@ if (!empty($list)) {
|
|||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th>'.tr('Nome').'</th>
|
<th>'.tr('Nome').'</th>
|
||||||
<th width="60" class="text-center">#</th>
|
<th width="10%" class="text-center">#</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>';
|
<tbody>';
|
||||||
@@ -21,9 +22,18 @@ if (!empty($list)) {
|
|||||||
echo '
|
echo '
|
||||||
<tr>
|
<tr>
|
||||||
<td>'.$element.'</td>
|
<td>'.$element.'</td>
|
||||||
<td>
|
<td class="text-center">';
|
||||||
|
|
||||||
|
if (file_exists($directory.'/'.$element)) {
|
||||||
|
echo '
|
||||||
|
<button type="button" class="btn btn-danger" onclick="delete_fe(this, \''.$element.'\')">
|
||||||
|
<i class="fa fa-trash"></i>
|
||||||
|
</button>';
|
||||||
|
}
|
||||||
|
|
||||||
|
echo '
|
||||||
<button type="button" class="btn btn-warning" onclick="download(this, \''.$element.'\')">
|
<button type="button" class="btn btn-warning" onclick="download(this, \''.$element.'\')">
|
||||||
<i class="fa fa-download"></i> '.tr('Importa fattura di acquisto').'
|
<i class="fa fa-download"></i> '.tr('Importa').'
|
||||||
</button>
|
</button>
|
||||||
</td>
|
</td>
|
||||||
</tr>';
|
</tr>';
|
||||||
@@ -70,4 +80,24 @@ function download(button, file) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function delete_fe(button, file) {
|
||||||
|
var restore = buttonLoading(button);
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
url: globals.rootdir + "/actions.php",
|
||||||
|
type: "get",
|
||||||
|
data: {
|
||||||
|
id_module: globals.id_module,
|
||||||
|
id_plugin: '.$id_plugin.',
|
||||||
|
op: "delete",
|
||||||
|
name: file,
|
||||||
|
},
|
||||||
|
success: function(data) {
|
||||||
|
$("#list").load("'.$structure->fileurl('list.php').'?id_module='.$id_module.'&id_plugin='.$id_plugin.'", function() {
|
||||||
|
buttonRestore(button, restore);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
</script>';
|
</script>';
|
||||||
|
@@ -45,8 +45,8 @@ echo '
|
|||||||
|
|
||||||
<div class="col-md-6">
|
<div class="col-md-6">
|
||||||
<h4>'.$dati_generali['Numero'];
|
<h4>'.$dati_generali['Numero'];
|
||||||
echo '
|
echo '
|
||||||
<a href="'.ROOTDIR.'/view.php?file_id='.get('id').'" class="btn btn-info btn-xs" target="_blank" >
|
<a href="'.$structure->fileurl('view.php').'?filename='.get('filename').'" class="btn btn-info btn-xs" target="_blank" >
|
||||||
<i class="fa fa-eye"></i> '.tr('Visualizza').'
|
<i class="fa fa-eye"></i> '.tr('Visualizza').'
|
||||||
</a><br>
|
</a><br>
|
||||||
<small>
|
<small>
|
||||||
|
@@ -221,7 +221,7 @@ class FatturaElettronica
|
|||||||
}
|
}
|
||||||
|
|
||||||
$sconti = $riga['ScontoMaggiorazione'];
|
$sconti = $riga['ScontoMaggiorazione'];
|
||||||
|
|
||||||
if (!empty($sconti)) {
|
if (!empty($sconti)) {
|
||||||
if ($sconti['Percentuale'] || $sconti['Importo']) {
|
if ($sconti['Percentuale'] || $sconti['Importo']) {
|
||||||
$tipo = !empty($sconti['Percentuale']) ? 'PRC' : 'EUR';
|
$tipo = !empty($sconti['Percentuale']) ? 'PRC' : 'EUR';
|
||||||
@@ -235,7 +235,7 @@ class FatturaElettronica
|
|||||||
$obj->tipo_sconto = $tipo;
|
$obj->tipo_sconto = $tipo;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sconti multipli
|
// Sconti multipli
|
||||||
else {
|
else {
|
||||||
$sconto = $sconti[0]['Percentuale'] ? $sconti[0]['Percentuale'] : $sconti['Percentuale'];
|
$sconto = $sconti[0]['Percentuale'] ? $sconti[0]['Percentuale'] : $sconti['Percentuale'];
|
||||||
@@ -244,28 +244,26 @@ class FatturaElettronica
|
|||||||
$sconto_totale = 0;
|
$sconto_totale = 0;
|
||||||
if ($tipo == 'PRC') {
|
if ($tipo == 'PRC') {
|
||||||
/**
|
/**
|
||||||
* Trasformo un eventuale sconto percentuale combinato in più
|
* Trasformo un eventuale sconto percentuale combinato in più
|
||||||
* sconti:
|
* sconti:
|
||||||
* Esempio:
|
* Esempio:
|
||||||
* 40% + 30% è uno sconto del 42%
|
* 40% + 30% è uno sconto del 42%.
|
||||||
*/
|
*/
|
||||||
$prezzo_intero = $riga['PrezzoUnitario'] * $riga['Quantita'];
|
$prezzo_intero = $riga['PrezzoUnitario'] * $riga['Quantita'];
|
||||||
$prezzo_scontato = $prezzo_intero;
|
$prezzo_scontato = $prezzo_intero;
|
||||||
|
|
||||||
foreach ($sconti as $scontor) {
|
foreach ($sconti as $scontor) {
|
||||||
$prezzo_scontato -= $prezzo_scontato / 100 * $scontor['Percentuale'];
|
$prezzo_scontato -= $prezzo_scontato / 100 * $scontor['Percentuale'];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ricavo la percentuale finale di sconto con una proporzione
|
// Ricavo la percentuale finale di sconto con una proporzione
|
||||||
$percentuale_totale = ( 1 - ($prezzo_scontato / $prezzo_intero) ) * 100;
|
$percentuale_totale = (1 - ($prezzo_scontato / $prezzo_intero)) * 100;
|
||||||
|
|
||||||
if (!empty($percentuale_totale)) {
|
if (!empty($percentuale_totale)) {
|
||||||
$obj->sconto_unitario = $percentuale_totale;
|
$obj->sconto_unitario = $percentuale_totale;
|
||||||
$obj->tipo_sconto = $tipo;
|
$obj->tipo_sconto = $tipo;
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
|
|
||||||
else {
|
|
||||||
// Combino gli sconti tra loro
|
// Combino gli sconti tra loro
|
||||||
foreach ($sconti as $sconto) {
|
foreach ($sconti as $sconto) {
|
||||||
$unitario = $sconto['Percentuale'] ?: $sconto['Importo'];
|
$unitario = $sconto['Percentuale'] ?: $sconto['Importo'];
|
||||||
@@ -275,7 +273,7 @@ class FatturaElettronica
|
|||||||
|
|
||||||
$sconto_totale += $unitario;
|
$sconto_totale += $unitario;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($unitario)) {
|
if (!empty($unitario)) {
|
||||||
$obj->sconto_unitario = $sconto_totale;
|
$obj->sconto_unitario = $sconto_totale;
|
||||||
$obj->tipo_sconto = $tipo;
|
$obj->tipo_sconto = $tipo;
|
||||||
|
@@ -15,33 +15,42 @@ class Interaction extends Connection
|
|||||||
{
|
{
|
||||||
$directory = FatturaElettronica::getImportDirectory();
|
$directory = FatturaElettronica::getImportDirectory();
|
||||||
|
|
||||||
$response = static::request('POST', 'get_fatture_da_importare');
|
$list = [];
|
||||||
$body = static::responseBody($response);
|
|
||||||
|
|
||||||
$code = $body['code'];
|
$files = glob($directory.'/*.xml');
|
||||||
|
foreach ($files as $file) {
|
||||||
|
$list[] = basename($file);
|
||||||
|
}
|
||||||
|
|
||||||
if ($code == '200') {
|
// Ricerca da remoto
|
||||||
$files = $body['results'];
|
if (self::isEnabled()) {
|
||||||
|
$response = static::request('POST', 'get_fatture_da_importare');
|
||||||
|
$body = static::responseBody($response);
|
||||||
|
|
||||||
foreach ($files as $file) {
|
$code = $body['code'];
|
||||||
/*
|
|
||||||
* Verifico che l'XML (fattura di acquisto) non sia già stato importato nel db, controllo p.iva del fornitore e progressivo invio
|
|
||||||
* TODO: caricare contenuto xml e verificare anche la data (e magari numero) della fattura. Potrebbe essere che il fornitore l'anno successivo mi genera FE con stesso progressivo invio.
|
|
||||||
*/
|
|
||||||
|
|
||||||
if (preg_match("/^([A-Z]{2})(.+?)_([^\.]+)\.xml/i", $file, $m)) {
|
if ($code == '200') {
|
||||||
$partita_iva = $m[2];
|
$files = $body['results'];
|
||||||
$progressivo_invio = $m[3];
|
|
||||||
$fattura = database()->fetchOne('SELECT co_documenti.id FROM (co_documenti INNER JOIN co_tipidocumento ON co_documenti.idtipodocumento=co_tipidocumento.id) INNER JOIN an_anagrafiche ON co_documenti.idanagrafica=an_anagrafiche.idanagrafica WHERE co_tipidocumento.dir="uscita" AND an_anagrafiche.piva='.prepare($partita_iva).' AND co_documenti.progressivo_invio='.prepare($progressivo_invio));
|
|
||||||
|
|
||||||
if (!$fattura) {
|
foreach ($files as $file) {
|
||||||
$list[] = basename($file);
|
/*
|
||||||
|
* Verifico che l'XML (fattura di acquisto) non sia già stato importato nel db, controllo p.iva del fornitore e progressivo invio
|
||||||
|
* TODO: caricare contenuto xml e verificare anche la data (e magari numero) della fattura. Potrebbe essere che il fornitore l'anno successivo mi genera FE con stesso progressivo invio.
|
||||||
|
*/
|
||||||
|
if (preg_match("/^([A-Z]{2})(.+?)_([^\.]+)\.xml/i", $file, $m)) {
|
||||||
|
$partita_iva = $m[2];
|
||||||
|
$progressivo_invio = $m[3];
|
||||||
|
$fattura = database()->fetchOne('SELECT co_documenti.id FROM (co_documenti INNER JOIN co_tipidocumento ON co_documenti.idtipodocumento=co_tipidocumento.id) INNER JOIN an_anagrafiche ON co_documenti.idanagrafica=an_anagrafiche.idanagrafica WHERE co_tipidocumento.dir="uscita" AND an_anagrafiche.piva='.prepare($partita_iva).' AND co_documenti.progressivo_invio='.prepare($progressivo_invio));
|
||||||
|
|
||||||
|
if (!$fattura) {
|
||||||
|
$list[] = basename($file);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return array_clean($list);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return array_clean($list);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getImportXML($name)
|
public static function getImportXML($name)
|
||||||
|
22
plugins/importFE/view.php
Normal file
22
plugins/importFE/view.php
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
include_once __DIR__.'/../../core.php';
|
||||||
|
|
||||||
|
$directory = Plugins\ImportFE\FatturaElettronica::getImportDirectory();
|
||||||
|
$filename = get('filename');
|
||||||
|
|
||||||
|
$content = file_get_contents($directory.'/'.$filename);
|
||||||
|
|
||||||
|
// XML
|
||||||
|
$xml = new DOMDocument();
|
||||||
|
$xml->loadXML($content);
|
||||||
|
|
||||||
|
// XSL
|
||||||
|
$xsl = new DOMDocument();
|
||||||
|
$xsl->load(DOCROOT.'/assets/src/xml/fe-stylesheet-1.2.1.xsl');
|
||||||
|
|
||||||
|
// XSLT
|
||||||
|
$xslt = new XSLTProcessor();
|
||||||
|
$xslt->importStylesheet($xsl);
|
||||||
|
|
||||||
|
echo $xslt->transformToXML($xml);
|
@@ -22,6 +22,6 @@ trait UploadTrait
|
|||||||
|
|
||||||
public function uploads($id_record)
|
public function uploads($id_record)
|
||||||
{
|
{
|
||||||
return $this->hasMany(Upload::class, $this->upload_identifier)->where('id_record', $id_record)->get()->groupBy('category');
|
return $this->hasMany(Upload::class, $this->upload_identifier)->where('id_record', $id_record)->get();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -190,16 +190,15 @@ class Uploads
|
|||||||
/**
|
/**
|
||||||
* Effettua l'upload di un file nella cartella indicata.
|
* Effettua l'upload di un file nella cartella indicata.
|
||||||
*
|
*
|
||||||
* @param array $source
|
* @param array $source
|
||||||
* @param string $directory
|
* @param array $data
|
||||||
* @param array $data
|
* @param array $options
|
||||||
* @param array $options
|
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public static function upload($source, $data, $options = [])
|
public static function upload($source, $data, $options = [])
|
||||||
{
|
{
|
||||||
$original = isset($source['name']) ? $source['name'] : $source;
|
$original = isset($source['name']) ? $source['name'] : basename($source);
|
||||||
|
|
||||||
$filename = self::getName($original, $data);
|
$filename = self::getName($original, $data);
|
||||||
$directory = DOCROOT.'/'.self::getDirectory($data['id_module'], $data['id_plugin']);
|
$directory = DOCROOT.'/'.self::getDirectory($data['id_module'], $data['id_plugin']);
|
||||||
|
2
view.php
2
view.php
@@ -21,7 +21,7 @@ if ($file->isFatturaElettronica()) {
|
|||||||
|
|
||||||
// XSL
|
// XSL
|
||||||
$xsl = new DOMDocument();
|
$xsl = new DOMDocument();
|
||||||
$xsl->load(__DIR__.'/assets/src/xml/fe-stylesheet-1.2.1.xsl');
|
$xsl->load(DOCROOT.'/assets/src/xml/fe-stylesheet-1.2.1.xsl');
|
||||||
|
|
||||||
// XSLT
|
// XSLT
|
||||||
$xslt = new XSLTProcessor();
|
$xslt = new XSLTProcessor();
|
||||||
|
Reference in New Issue
Block a user