2018-09-24 18:10:16 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
include_once __DIR__.'/../../core.php';
|
|
|
|
|
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':
|
|
|
|
$id = Uploads::getFakeID();
|
|
|
|
$filename = $upload = Uploads::upload($_FILES['blob'], [
|
|
|
|
'name' => tr('Fattura Elettronica'),
|
|
|
|
'category' => tr('Fattura Elettronica'),
|
|
|
|
'id_module' => $id_module,
|
|
|
|
'id_record' => $id,
|
|
|
|
]);
|
|
|
|
|
2018-09-25 11:55:52 +02:00
|
|
|
try {
|
|
|
|
$xml = file_get_contents(DOCROOT.'/'.$directory.'/'.$filename);
|
|
|
|
$fattura_pa = new Plugins\ImportPA\FatturaElettronica($xml, post('id_segment'));
|
|
|
|
|
|
|
|
echo json_encode([
|
|
|
|
'id' => $id,
|
|
|
|
'filename' => $filename,
|
|
|
|
'id_segment' => post('id_segment'),
|
|
|
|
]);
|
|
|
|
} catch (UnexpectedValueException $e) {
|
|
|
|
echo json_encode([
|
|
|
|
'already' => 1
|
|
|
|
]);
|
|
|
|
}
|
2018-09-24 18:10:16 +02:00
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'generate':
|
|
|
|
$id = post('id');
|
|
|
|
$filename = post('filename');
|
|
|
|
|
|
|
|
$xml = file_get_contents(DOCROOT.'/'.$directory.'/'.$filename);
|
2018-09-25 11:55:52 +02:00
|
|
|
$fattura_pa = new Plugins\ImportPA\FatturaElettronica($xml, post('id_segment'));
|
2018-09-24 18:10:16 +02:00
|
|
|
|
2018-09-25 11:55:52 +02:00
|
|
|
$id_record = $fattura_pa->saveFattura();
|
2018-09-24 18:10:16 +02:00
|
|
|
|
2018-09-25 11:55:52 +02:00
|
|
|
$fattura_pa->saveRighe(post('articoli'), post('iva'));
|
|
|
|
$fattura_pa->getFattura()->updateSconto();
|
2018-09-24 18:10:16 +02:00
|
|
|
|
|
|
|
$fattura_pa->saveAllegati($directory);
|
|
|
|
|
|
|
|
Uploads::updateFake($id, $id_record);
|
|
|
|
|
|
|
|
redirect(ROOTDIR.'/editor.php?id_module='.$id_module.'&id_record='.$id_record);
|
|
|
|
break;
|
|
|
|
}
|