openstamanager/plugins/receiptFE/actions.php

50 lines
1.1 KiB
PHP
Raw Normal View History

2018-12-14 12:50:44 +01:00
<?php
include_once __DIR__.'/../../core.php';
use Plugins\ReceiptFE\Interaction;
2019-07-05 09:53:53 +02:00
use Plugins\ReceiptFE\ReceiptHook;
2018-12-29 12:03:22 +01:00
use Plugins\ReceiptFE\Ricevuta;
2018-12-14 12:50:44 +01:00
switch (filter('op')) {
case 'import':
$list = Interaction::getReceiptList();
2019-07-05 09:53:53 +02:00
// Aggiornamento cache hook
ReceiptHook::update($list);
2018-12-14 12:50:44 +01:00
$results = [];
foreach ($list as $name) {
2019-02-20 16:07:42 +01:00
Interaction::getReceipt($name);
2019-02-20 12:39:28 +01:00
$fattura = null;
try {
$receipt = new Ricevuta($name, $content);
2019-02-20 16:07:42 +01:00
$receipt->save();
2019-02-20 12:39:28 +01:00
$fattura = $receipt->getFattura()->numero_esterno;
2019-02-20 16:07:42 +01:00
$receipt->delete();
2019-02-20 12:39:28 +01:00
Interaction::processReceipt($name);
2019-02-20 16:07:42 +01:00
} catch (UnexpectedValueException $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;
}