2016-09-16 16:36:16 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
require_once(dirname(__FILE__).'../../../config/config.inc.php');
|
|
|
|
require_once(dirname(__FILE__).'../../../init.php');
|
|
|
|
|
|
|
|
header('Content-Type: application/json');
|
|
|
|
if(Tools::getValue('action') != 'getReport') {
|
|
|
|
http_response_code(418);
|
|
|
|
die('I\'m a teapot');
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (Tools::getValue('type')) {
|
|
|
|
case 'ART':
|
|
|
|
die(getReport('ART'));
|
|
|
|
break;
|
|
|
|
case 'CDC':
|
|
|
|
die(getReport('CDC'));
|
|
|
|
break;
|
2016-09-29 18:08:23 +02:00
|
|
|
case 'CRP':
|
|
|
|
die(getReport('CRP'));
|
|
|
|
break;
|
2016-09-16 16:36:16 +02:00
|
|
|
default:
|
|
|
|
http_response_code(418);
|
|
|
|
die(json_encode('I\'m a teapot'));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
function getReport($type) {
|
|
|
|
//global $cookie;
|
|
|
|
$id_sale = (int)Tools::getValue('id_sale', false);
|
|
|
|
|
|
|
|
if (!$id_sale) {
|
|
|
|
http_response_code(500);
|
|
|
|
return json_encode(array(
|
|
|
|
'error'=> 'true',
|
|
|
|
'message'=> Tools::displayError('Vente non trouvée')
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
$report = Db::getInstance()->getRow('
|
2016-09-19 11:58:14 +02:00
|
|
|
SELECT `report_data`, `report_date`, `id_sale`
|
2016-09-16 16:36:16 +02:00
|
|
|
FROM `'._DB_PREFIX_.'philea_syncreport`
|
|
|
|
WHERE `id_sale` = '.$id_sale.'
|
|
|
|
AND `filename` LIKE "'.$type.'%"
|
|
|
|
');
|
2016-09-16 17:17:41 +02:00
|
|
|
if(empty($report['report_data'])){
|
2016-09-19 11:58:14 +02:00
|
|
|
$report['report_data'] = Tools::displayError('Pas encore de rapport '.$type.' disponible');
|
2016-09-16 17:17:41 +02:00
|
|
|
}
|
2016-09-16 16:36:16 +02:00
|
|
|
if(isset($report) && $report != false) {
|
|
|
|
return json_encode(array(
|
|
|
|
'error' => 'false',
|
|
|
|
'report' => $report
|
|
|
|
));
|
|
|
|
} else {
|
|
|
|
return json_encode(array(
|
|
|
|
'error'=> 'true',
|
2016-09-19 11:58:14 +02:00
|
|
|
'message' => Tools::displayError('Pas encore de rapport '.$type.' disponible')
|
2016-09-16 16:36:16 +02:00
|
|
|
));
|
|
|
|
}
|
|
|
|
}
|