Completamento importazione ricevute fatture elettroniche

This commit is contained in:
Fabio Lovato 2019-01-25 15:54:56 +01:00
parent fafa068cca
commit 32eeb76e58
7 changed files with 75 additions and 26 deletions

View File

@ -31,6 +31,8 @@ switch (filter('op')) {
if ($result) {
database()->update('co_documenti', [
'codice_stato_fe' => 'WAIT',
'descrizione_stato_fe' => 'Fattura in elaborazione...',
'data_stato_fe' => date('Y-m-d H:i:s'),
], ['id' => $id_record]);
}

View File

@ -151,7 +151,8 @@ echo '
<i class="fa fa-eye"></i> '.tr('Visualizza').'
</a>';
$send = Interaction::isEnabled() && $generated && $record['codice_stato_fe'] == 'GEN';
// Scelgo quando posso inviarla
$send = Interaction::isEnabled() && $generated && in_array( $record['codice_stato_fe'], array('GEN', 'ERVAL') );
echo '
@ -159,8 +160,34 @@ echo '
<button onclick="if( confirm(\''.tr('Inviare la fattura al SDI?').'\') ){ send(this); }" class="btn btn-success btn-lg '.($send ? '' : 'disabled').'" target="_blank" '.($send ? '' : 'disabled').'>
<i class="fa fa-paper-plane"></i> '.tr('Invia').'
</button>
</button><br><br>';
// Messaggio esito invio
if ($record['codice_stato_fe'] == '') {
} elseif ($record['codice_stato_fe'] == 'GEN') {
echo '
<div class="alert alert-warning">'.tr('La fattura è stata generata ed è pronta per l\'invio.').'</div>
';
} else {
$stato_fe = database()->fetchOne('SELECT codice, descrizione, icon FROM fe_stati_documento WHERE codice='.prepare($record['codice_stato_fe']));
if (in_array($stato_fe['codice'], array('EC01', 'RC'))) {
$class = 'success';
} elseif (in_array($stato_fe['codice'], array('ERVAL', 'GEN', 'MC', 'WAIT'))) {
$class = 'warning';
} else {
$class = 'danger';
}
echo '
<div class="alert text-left alert-'.$class.'"><big><i class="'.$stato_fe['icon'].'" style="color:#fff;"></i> <b>'.$record['codice_stato_fe'].'</b> - '.$record['descrizione_stato_fe'].'</big> <div class="pull-right"><i class="fa fa-clock-o"></i> '.date('d/m/Y H:i', strtotime($record['data_stato_fe'])).'</small></div>
';
}
echo '
<script>
function send(btn) {
var restore = buttonLoading(btn);

View File

@ -32,7 +32,7 @@ switch (filter('op')) {
$result = [];
if (!empty($file)) {
try {
$receipt = new Ricevuta($file['content']);
$receipt = new Ricevuta($name, $file['content']);
$result = [
'fattura' => $receipt->getFattura()->numero_esterno,

View File

@ -45,20 +45,27 @@ echo '
count = data.length;
buttonRestore(btn, restore);
swal({
title: "'.tr('Ricevute da importare: _COUNT_', [
'_COUNT_' => '" + count + "',
]).'",
html: "'.tr('Sono state individuate _COUNT_ ricevute da importare', [
'_COUNT_' => '" + count + "',
]).'.",
showCancelButton: true,
confirmButtonText: "'.tr('Procedi').'",
type: "info",
}).then(function (result) {
importAll(btn);
});
if( count == 0 ){
swal({
title: "'.tr('Non ci sono ricevute da importare').'",
showCancelButton: false,
confirmButtonText: "'.tr('OK').'",
type: "info",
});
} else {
swal({
title: "'.tr('Ricevute da importare: _COUNT_', [
'_COUNT_' => '" + count + "',
]).'",
html: "'.tr('Importando le ricevute, verranno aggiornati gli stati di invio fatture elettroniche. Continuare?').'",
showCancelButton: true,
confirmButtonText: "'.tr('Procedi').'",
type: "info",
}).then(function (result) {
importAll(btn);
});
}
},
error: function(data) {
alert("'.tr('Errore').': " + data);

View File

@ -26,10 +26,6 @@ class Interaction extends Connection
]);
$body = static::responseBody($response);
if ($body['code'] != '200') {
return false;
}
return $body;
}
}

View File

@ -19,14 +19,15 @@ class Ricevuta
/** @var array XML della fattura */
protected $fattura = null;
public function __construct($content)
public function __construct($name, $content)
{
$this->xml = XML::read($content);
$nome = $this->xml['NomeFile'];
$pieces = explode('_', $nome);
$filename = explode('.', $nome)[0];
$pieces = explode('_', $filename);
$progressivo_invio = explode('.', $pieces[1])[0];
$progressivo_invio = $pieces[1];
$this->fattura = Fattura::where([
'progressivo_invio' => $progressivo_invio,
@ -34,6 +35,20 @@ class Ricevuta
if (empty($this->fattura)) {
throw new UnexpectedValueException();
} else {
// Processo la ricevuta e salvo il codice e messaggio di errore
$filename = explode('.', $name)[0];
$pieces = explode('_', $filename);
$codice = $pieces[2];
$descrizione = $this->xml['Destinatario']['Descrizione'];
$data = $this->xml['DataOraRicezione'];
$this->fattura->codice_stato_fe = $codice;
$this->fattura->descrizione_stato_fe = $descrizione;
$this->fattura->data_stato_fe = date('Y-m-d H:i:s', strtotime($data));
$this->fattura->save();
return true;
}
}

View File

@ -48,5 +48,7 @@ UPDATE `zz_settings` SET `tipo` = 'query=SELECT codice AS id, CONCAT_WS(\' - \',
UPDATE `fe_stati_documento` SET `descrizione`='In elaborazione' WHERE `codice`='WAIT';
INSERT INTO `fe_stati_documento`( `codice`, `descrizione`, `icon` ) VALUES
( 'ERVAL', 'Errore di validazione', 'fa fa-edit text-danger' );
INSERT INTO `fe_stati_documento`( `codice`, `descrizione`, `icon` ) VALUES( 'ERVAL', 'Errore di validazione', 'fa fa-edit text-danger' );
ALTER TABLE `co_documenti` ADD `descrizione_stato_fe` TEXT NOT NULL AFTER `codice_stato_fe`;
ALTER TABLE `co_documenti` ADD `data_stato_fe` TIMESTAMP NOT NULL AFTER `descrizione_stato_fe`;