2018-09-24 18:10:16 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
include_once __DIR__.'/../../core.php';
|
|
|
|
|
2018-11-30 15:33:25 +01:00
|
|
|
use Plugins\ImportFE\FatturaElettronica;
|
|
|
|
use Plugins\ImportFE\Interaction;
|
|
|
|
|
2018-09-25 11:55:52 +02:00
|
|
|
$directory = Uploads::getDirectory($id_module);
|
|
|
|
|
2018-09-24 18:10:16 +02:00
|
|
|
switch (filter('op')) {
|
|
|
|
case 'save':
|
2018-11-30 15:33:25 +01:00
|
|
|
$content = file_get_contents($_FILES['blob']['tmp_name']);
|
2019-02-02 13:11:20 +01:00
|
|
|
$filename = FatturaElettronica::store($_FILES['blob']['name'], $content);
|
2018-09-25 11:55:52 +02:00
|
|
|
|
2018-11-30 15:33:25 +01:00
|
|
|
if (FatturaElettronica::isValid($file)) {
|
2018-09-25 11:55:52 +02:00
|
|
|
echo json_encode([
|
2019-02-02 13:11:20 +01:00
|
|
|
'filename' => $filename,
|
2018-09-25 11:55:52 +02:00
|
|
|
]);
|
2018-11-30 15:33:25 +01:00
|
|
|
} else {
|
2018-09-25 11:55:52 +02:00
|
|
|
echo json_encode([
|
2018-09-25 16:47:44 +02:00
|
|
|
'already' => 1,
|
2018-09-25 11:55:52 +02:00
|
|
|
]);
|
|
|
|
}
|
2018-09-24 18:10:16 +02:00
|
|
|
|
|
|
|
break;
|
|
|
|
|
2018-11-30 15:33:25 +01:00
|
|
|
case 'prepare':
|
|
|
|
$name = get('name');
|
|
|
|
$file = Interaction::getImportXML($name);
|
2018-09-24 18:10:16 +02:00
|
|
|
|
2018-11-30 15:33:25 +01:00
|
|
|
if (FatturaElettronica::isValid($file)) {
|
|
|
|
echo json_encode([
|
|
|
|
'filename' => $file,
|
|
|
|
]);
|
|
|
|
} else {
|
|
|
|
echo json_encode([
|
|
|
|
'already' => 1,
|
|
|
|
]);
|
|
|
|
}
|
2018-09-24 18:10:16 +02:00
|
|
|
|
2018-11-30 15:33:25 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'generate':
|
2019-01-25 10:44:03 +01:00
|
|
|
$filename = post('filename');
|
|
|
|
|
|
|
|
//Processo il file ricevuto
|
|
|
|
$process_result = Interaction::processXML($filename);
|
2019-01-25 11:02:36 +01:00
|
|
|
if ($process_result != '') {
|
2019-01-25 10:44:03 +01:00
|
|
|
flash()->error($process_result);
|
|
|
|
redirect(ROOTDIR.'/controller.php?id_module='.$id_module);
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
$fattura_pa = new FatturaElettronica($filename);
|
2018-09-24 18:10:16 +02:00
|
|
|
|
2019-01-10 18:41:25 +01:00
|
|
|
$id_record = $fattura_pa->saveFattura(post('pagamento'), post('id_segment'), post('id_tipo'));
|
2018-10-29 22:23:29 +01:00
|
|
|
$fattura_pa->saveRighe(post('articoli'), post('iva'), post('conto'));
|
2018-09-25 11:55:52 +02:00
|
|
|
$fattura_pa->getFattura()->updateSconto();
|
2018-09-24 18:10:16 +02:00
|
|
|
|
2018-11-30 15:33:25 +01:00
|
|
|
$fattura_pa->saveAllegati();
|
2018-09-24 18:10:16 +02:00
|
|
|
|
2018-11-30 15:33:25 +01:00
|
|
|
$idrivalsainps = 0;
|
|
|
|
$idritenutaacconto = 0;
|
|
|
|
$bollo = 0;
|
2018-09-24 18:10:16 +02:00
|
|
|
|
2018-10-29 22:23:29 +01:00
|
|
|
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');
|
|
|
|
|
2018-11-30 15:33:25 +01:00
|
|
|
$fattura_pa->delete();
|
|
|
|
|
2018-09-24 18:10:16 +02:00
|
|
|
redirect(ROOTDIR.'/editor.php?id_module='.$id_module.'&id_record='.$id_record);
|
|
|
|
break;
|
2018-09-26 12:06:24 +02:00
|
|
|
|
|
|
|
case 'list':
|
|
|
|
include __DIR__.'/rows.php';
|
|
|
|
|
|
|
|
break;
|
2018-09-24 18:10:16 +02:00
|
|
|
}
|