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;
|
|
|
|
|
2019-07-22 15:45:36 +02:00
|
|
|
$file = null;
|
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-04 17:26:29 +01:00
|
|
|
$file = FatturaElettronica::store($_FILES['blob']['name'], $content);
|
2018-09-25 11:55:52 +02:00
|
|
|
|
2019-07-10 15:02:09 +02:00
|
|
|
// no break
|
2018-11-30 15:33:25 +01:00
|
|
|
case 'prepare':
|
2019-07-22 12:52:48 +02:00
|
|
|
if (!isset($file)) {
|
2019-07-22 15:45:36 +02:00
|
|
|
$name = filter('name');
|
2019-07-22 11:35:44 +02:00
|
|
|
$file = Interaction::getImportXML($name);
|
|
|
|
}
|
2018-09-24 18:10:16 +02:00
|
|
|
|
2018-11-30 15:33:25 +01:00
|
|
|
if (FatturaElettronica::isValid($file)) {
|
2019-07-22 18:35:13 +02:00
|
|
|
// Individuazione ID fisico
|
|
|
|
$files = Interaction::fileToImport();
|
|
|
|
foreach ($files as $key => $value) {
|
|
|
|
if ($value['name'] == $file) {
|
|
|
|
$index = $key;
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-30 15:33:25 +01:00
|
|
|
echo json_encode([
|
2019-07-22 18:35:13 +02:00
|
|
|
'id' => $index + 1,
|
2018-11-30 15:33:25 +01:00
|
|
|
]);
|
|
|
|
} else {
|
|
|
|
echo json_encode([
|
|
|
|
'already' => 1,
|
|
|
|
]);
|
|
|
|
}
|
2018-09-24 18:10:16 +02:00
|
|
|
|
2018-11-30 15:33:25 +01:00
|
|
|
break;
|
|
|
|
|
2019-02-12 11:42:48 +01:00
|
|
|
case 'delete':
|
2019-04-19 03:18:05 +02:00
|
|
|
$directory = FatturaElettronica::getImportDirectory();
|
2019-02-12 11:42:48 +01:00
|
|
|
|
2019-02-12 15:00:08 +01:00
|
|
|
delete($directory.'/'.get('name'));
|
2019-02-12 11:42:48 +01:00
|
|
|
|
|
|
|
break;
|
|
|
|
|
2018-11-30 15:33:25 +01:00
|
|
|
case 'generate':
|
2019-01-25 10:44:03 +01:00
|
|
|
$filename = post('filename');
|
|
|
|
|
2019-04-19 03:18:05 +02:00
|
|
|
$info = [
|
|
|
|
'id_pagamento' => post('pagamento'),
|
|
|
|
'id_segment' => post('id_segment'),
|
|
|
|
'id_tipo' => post('id_tipo'),
|
2019-07-22 11:35:44 +02:00
|
|
|
'ref_fattura' => post('ref_fattura'),
|
2019-05-17 05:56:10 +02:00
|
|
|
'data_registrazione' => post('data_registrazione'),
|
2019-04-19 03:18:05 +02:00
|
|
|
'articoli' => post('articoli'),
|
|
|
|
'iva' => post('iva'),
|
|
|
|
'conto' => post('conto'),
|
|
|
|
'movimentazione' => post('movimentazione'),
|
|
|
|
];
|
|
|
|
|
|
|
|
$fattura_pa = FatturaElettronica::manage($filename);
|
|
|
|
$id_record = $fattura_pa->save($info);
|
2018-09-24 18:10:16 +02:00
|
|
|
|
2019-04-19 20:47:55 +02:00
|
|
|
ricalcola_costiagg_fattura($id_record);
|
2018-10-29 22:23:29 +01:00
|
|
|
elimina_scadenza($id_record);
|
|
|
|
elimina_movimento($id_record, 0);
|
2019-02-13 10:53:29 +01:00
|
|
|
aggiungi_scadenza($id_record);
|
2018-10-29 22:23:29 +01:00
|
|
|
aggiungi_movimento($id_record, 'uscita');
|
|
|
|
|
2018-11-30 15:33:25 +01:00
|
|
|
$fattura_pa->delete();
|
|
|
|
|
2019-02-14 10:58:43 +01:00
|
|
|
// Processo il file ricevuto
|
|
|
|
if (Interaction::isEnabled()) {
|
|
|
|
$process_result = Interaction::processXML($filename);
|
|
|
|
if ($process_result != '') {
|
|
|
|
flash()->error($process_result);
|
|
|
|
redirect(ROOTDIR.'/controller.php?id_module='.$id_module);
|
2019-07-22 11:35:44 +02:00
|
|
|
|
|
|
|
return;
|
2019-02-14 10:58:43 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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;
|
2019-04-19 18:50:16 +02:00
|
|
|
|
|
|
|
case 'process':
|
|
|
|
$name = get('name');
|
|
|
|
|
|
|
|
// Processo il file ricevuto
|
|
|
|
if (Interaction::isEnabled()) {
|
|
|
|
$process_result = Interaction::processXML($name);
|
2019-07-10 15:02:09 +02:00
|
|
|
if (!empty($process_result)) {
|
2019-04-19 18:50:16 +02:00
|
|
|
flash()->error($process_result);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
2018-09-24 18:10:16 +02:00
|
|
|
}
|