Migliorata importazione fattura elettronica

This commit is contained in:
loviuz 2018-10-29 22:23:29 +01:00
parent 6b677920d7
commit 182098a846
4 changed files with 35 additions and 16 deletions

View File

@ -57,6 +57,7 @@ switch (post('op')) {
if ($dir == 'uscita') {
$data = [
'numero' => post('numero'),
'numero_esterno' => post('numero_esterno'),
'idrivalsainps' => post('id_rivalsa_inps'),
'idritenutaacconto' => post('id_ritenuta_acconto'),
];

View File

@ -2,6 +2,8 @@
include_once __DIR__.'/../../core.php';
include_once Modules::filepath('Fatture di vendita', 'modutil.php');
$directory = Uploads::getDirectory($id_module);
switch (filter('op')) {
@ -39,14 +41,23 @@ switch (filter('op')) {
$fattura_pa = new Plugins\ImportPA\FatturaElettronica($xml, post('id_segment'));
$id_record = $fattura_pa->saveFattura(post('pagamento'));
$idrivalsainps = 0;
$idritenutaacconto = 0;
$bollo = 0;
$fattura_pa->saveRighe(post('articoli'), post('iva'));
$fattura_pa->saveRighe(post('articoli'), post('iva'), post('conto'));
$fattura_pa->getFattura()->updateSconto();
$fattura_pa->saveAllegati($directory);
Uploads::updateFake($id, $id_record);
ricalcola_costiagg_fattura($id_record, $idrivalsainps, $idritenutaacconto, $bollo);
elimina_scadenza($id_record);
elimina_movimento($id_record, 0);
aggiungi_scadenza($id_record, post('pagamento'));
aggiungi_movimento($id_record, 'uscita');
redirect(ROOTDIR.'/editor.php?id_module='.$id_module.'&id_record='.$id_record);
break;

View File

@ -70,15 +70,16 @@ if (!empty($righe)) {
echo '
<h4>'.tr('Righe').'</h4>
<table class="table table-hover table-striped">
<tr>
<th width="10%">'.tr('Riga').'</th>
<th width="40%">'.tr('Descrizione').'</th>
<th width="10%">'.tr('Quantità').'</th>
<th width="10%">'.tr('Prezzo unitario').'</th>
<th width="10%">'.tr('Iva associata').'*</th>
<th width="20%">'.tr('Articolo associato').'</th>
</tr>';
<div class="table-responsive">
<table class="table table-hover table-striped table-condensed">
<tr>
<th>'.tr('Descrizione').'</th>
<th width="10%">'.tr('Q.').'</th>
<th width="15%">'.tr('Prezzo unitario').'</th>
<th width="15%">'.tr('Iva associata').'*</th>
<th width="15%">'.tr('Conto').'</th>
<th width="15%">'.tr('Articolo associato').'</th>
</tr>';
foreach ($righe as $key => $riga) {
$query = 'SELECT id, IF(codice IS NULL, descrizione, CONCAT(codice, " - ", descrizione)) AS descrizione FROM co_iva WHERE percentuale = '.prepare($riga['AliquotaIVA']);
@ -91,13 +92,15 @@ if (!empty($righe)) {
echo '
<tr>
<td>'.$key.'</td>
<td>'.$riga['Descrizione'].'</td>
<td>'.$riga['Quantita'].' '.$riga['UnitaMisura'].'</td>
<td>'.$riga['PrezzoUnitario'].'</td>
<td>'.Translator::numberToLocale( $riga['Quantita'] ).' '.$riga['UnitaMisura'].'</td>
<td>'.Translator::numberToLocale( $riga['PrezzoUnitario'] ).'&nbsp;&euro;</td>
<td>
{[ "type": "select", "name": "iva['.$key.']", "values": "query='.str_replace('"', '\"', $query).'", "required": 1 ]}
</td>
<td>
{[ "type": "select", "name": "conto['.$key.']", "ajax-source": "conti-acquisti" ]}
</td>
<td>
{[ "type": "select", "name": "articoli['.$key.']", "ajax-source": "articoli" ]}
</td>
@ -105,7 +108,8 @@ if (!empty($righe)) {
}
echo '
</table>';
</table>
</div>';
} else {
echo '
<p>Non ci sono righe nella fattura.</p>';

View File

@ -153,7 +153,7 @@ class FatturaElettronica
return $result;
}
public function saveRighe($articoli, $iva)
public function saveRighe($articoli, $iva, $conto)
{
$righe = $this->getRighe();
@ -168,6 +168,7 @@ class FatturaElettronica
$obj->descrizione = $riga['Descrizione'];
$obj->id_iva = $iva[$key];
$obj->idconto = $conto[$key];
$obj->costo_unitario = $riga['PrezzoUnitario'];
$obj->qta = $riga['Quantita'] ?: 1;
@ -240,7 +241,8 @@ class FatturaElettronica
$dati_generali = $this->getBody()['DatiGenerali']['DatiGeneraliDocumento'];
$data = $dati_generali['Data'];
$numero = $dati_generali['Numero'];
$numero = Fattura::getNumero($data, 'uscita', $this->id_sezionale);
$numero_esterno = $dati_generali['Numero'];
$descrizione_tipo = empty($this->getBody()['DatiGenerali']['DatiTrasporto']) ? 'Fattura immediata di acquisto' : 'Fattura accompagnatoria di acquisto';
$tipo = TipoFattura::where('descrizione', $descrizione_tipo)->first();
@ -249,6 +251,7 @@ class FatturaElettronica
$this->fattura = $fattura;
$fattura->numero = $numero;
$fattura->numero_esterno = $numero_esterno;
$fattura->idpagamento = $id_pagamento;
$stato_documento = StatoFattura::where('descrizione', 'Emessa')->first();