76 lines
2.3 KiB
PHP
76 lines
2.3 KiB
PHP
<?php
|
|
ini_set('display_errors', 0);
|
|
ini_set('display_startup_errors', 0);
|
|
//error_reporting(E_ALL & ~E_NOTICE & ~E_STRICT);
|
|
|
|
chdir(dirname(__DIR__));
|
|
|
|
require_once('./REST/config.php');
|
|
require_once('./REST/functions.php');
|
|
if ($_GET['key'] != $restConfig['e5Key']) {
|
|
echo 'Unauthorized';
|
|
exit;
|
|
}
|
|
// Enable SugarCRM features
|
|
if (!defined('sugarEntry')) define('sugarEntry', true);
|
|
require_once('./include/entryPoint.php');
|
|
// Make action
|
|
switch ($_GET["action"]) {
|
|
case 'getInvoice':
|
|
sendInvoice($_GET['record']);
|
|
break;
|
|
case 'getProduct':
|
|
sendProduct($_GET['record']);
|
|
break;
|
|
case 'copySaleFromTwinpol':
|
|
copySaleFromTwinpol($_GET['record']);
|
|
break;
|
|
case 'export.products.list':
|
|
if ($_GET['since'] == null) {
|
|
echo 'No since date';
|
|
exit;
|
|
}
|
|
$products = [];
|
|
$db = $GLOBALS['db'];
|
|
$sixMonthsAgo = (new DateTime())->modify('-6 months')->format('Y-m-d H:i:s');
|
|
$sinceDate = date('Y-m-d H:i:s', intval($_GET['since']));;
|
|
$query = "
|
|
SELECT
|
|
p.id,
|
|
p.name,
|
|
p.code,
|
|
p.ean,
|
|
GROUP_CONCAT(s.stock_address SEPARATOR ', ') AS stock_addresses
|
|
FROM ecmproducts p
|
|
LEFT JOIN ecmproducts_stock_addresses s ON p.id = s.ecmproduct_id
|
|
WHERE p.active = 1
|
|
AND p.deleted = 0
|
|
AND p.date_modified > '$sixMonthsAgo'
|
|
AND (p.exportedAt IS NULL OR p.exportedAt < '$sinceDate')
|
|
GROUP BY p.id, p.name, p.code
|
|
";
|
|
$r = $db->query($query);
|
|
while ($row = $db->fetchByAssoc($r)) {
|
|
$p = [];
|
|
$p['id'] = $row['id'];
|
|
$p['ean'] = $row['ean'];
|
|
$p['name'] = $row['name'];
|
|
$p['code'] = $row['code'];
|
|
$p['stock_addresses'] = $row['stock_addresses'];
|
|
array_push($products, $p);
|
|
}
|
|
echo json_encode($products);
|
|
break;
|
|
case 'export.products.setExportedAt':
|
|
{
|
|
if ($_GET['exportedAt'] == null || $_GET['id'] == null) {
|
|
echo 'Wrong parameters';
|
|
exit;
|
|
}
|
|
$db = $GLOBALS['db'];
|
|
$exportedAt = date('Y-m-d H:i:s', intval($_GET['exportedAt']));;
|
|
$id = $_GET['id'];
|
|
$db->query("UPDATE ecmproducts SET exportedAt='$exportedAt' WHERE id='$id'");
|
|
break;
|
|
}
|
|
} |