1
0
mirror of https://github.com/devcode-it/openstamanager.git synced 2024-12-25 23:33:02 +01:00
openstamanager/plugins/receiptFE/actions.php
2019-07-10 15:02:09 +02:00

99 lines
2.2 KiB
PHP

<?php
include_once __DIR__.'/../../core.php';
use Plugins\ReceiptFE\Interaction;
use Plugins\ReceiptFE\ReceiptHook;
use Plugins\ReceiptFE\Ricevuta;
switch (filter('op')) {
case 'import':
$list = Interaction::getReceiptList();
// Aggiornamento cache hook
ReceiptHook::update($list);
$results = [];
foreach ($list as $name) {
Interaction::getReceipt($name);
$fattura = null;
try {
$receipt = new Ricevuta($name, $content);
$receipt->save();
$fattura = $receipt->getFattura()->numero_esterno;
$receipt->delete();
Interaction::processReceipt($name);
} catch (UnexpectedValueException $e) {
}
$results[] = [
'file' => $name,
'fattura' => $fattura,
];
}
echo json_encode($results);
break;
case 'save':
$content = file_get_contents($_FILES['blob']['tmp_name']);
$file = Ricevuta::store($_FILES['blob']['name'], $content);
$name = $file;
// no break
case 'prepare':
$name = $name ?: get('name');
Interaction::getReceipt($name);
$fattura = null;
try {
$receipt = new Ricevuta($name, $content);
$receipt->save();
$fattura = $receipt->getFattura()->numero_esterno;
$receipt->delete();
Interaction::processReceipt($name);
} catch (UnexpectedValueException $e) {
}
echo json_encode([
'file' => $name,
'fattura' => $fattura,
]);
break;
case 'list':
include __DIR__.'/rows.php';
break;
case 'delete':
$directory = Ricevuta::getImportDirectory();
delete($directory.'/'.get('name'));
break;
case 'process':
$name = get('name');
// Processo il file ricevuto
if (Interaction::isEnabled()) {
$process_result = Interaction::processReceipt($name);
if (!empty($process_result)) {
flash()->error($process_result);
}
}
break;
}