openstamanager/plugins/receiptFE/actions.php

59 lines
1.3 KiB
PHP
Raw Normal View History

2018-12-14 12:50:44 +01:00
<?php
include_once __DIR__.'/../../core.php';
use Plugins\ReceiptFE\Interaction;
2018-12-29 12:03:22 +01:00
use Plugins\ReceiptFE\Ricevuta;
2018-12-14 12:50:44 +01:00
switch (filter('op')) {
case 'save':
$content = file_get_contents($_FILES['blob']['tmp_name']);
$file = FatturaElettronica::store($_FILES['blob']['name'], $content);
if (FatturaElettronica::isValid($file)) {
echo json_encode([
'filename' => $file,
]);
} else {
echo json_encode([
'already' => 1,
]);
}
break;
case 'import':
$list = Interaction::getReceiptList();
$results = [];
foreach ($list as $name) {
2019-02-20 12:39:28 +01:00
$content = Interaction::getReceipt($name);
$fattura = null;
try {
$receipt = new Ricevuta($name, $content);
$fattura = $receipt->getFattura()->numero_esterno;
Interaction::processReceipt($name);
} catch (Exception $e) {
2018-12-14 12:50:44 +01:00
}
2019-02-20 12:39:28 +01:00
$results[] = [
2018-12-14 12:50:44 +01:00
'file' => $name,
2019-02-20 12:39:28 +01:00
'fattura' => $fattura,
];
2018-12-14 12:50:44 +01:00
}
echo json_encode($results);
break;
case 'list':
$list = Interaction::getReceiptList();
echo json_encode($list);
break;
}