Compare commits

...

2 Commits

Author SHA1 Message Date
Michał Zieliński
dc48841d9b Merge remote-tracking branch 'origin/main' 2025-10-21 17:04:25 +02:00
Michał Zieliński
28d637ecc1 BIMAI: REST get ecommerceinvoices 2025-10-21 17:04:15 +02:00
2 changed files with 69 additions and 2 deletions

64
REST/bimai.php Normal file
View File

@@ -0,0 +1,64 @@
<?php
function bimai_exportEcommerceDate($since)
{
if (!isset($since)) {
echo json_encode(array('ok' => false, 'error' => 'Missing since parameter'));
return false;
}
$sinceDate = date('Y-m-d H:i:s', intval($_GET['since']));
$query = "
SELECT
i.id,
i .document_no,
i.type,
i.register_date,
i.sell_date,
i.parent_name,
i.parent_nip,
i.parent_address_street,
i.parent_address_postalcode,
i.parent_address_city,
i.parent_address_country,
i.currency,
i.total_netto,
i.total_brutto,
i.total_vat,
i.origin
FROM ecommerce_invoices i
WHERE
i.origin = 'allegro'
AND YEAR(i.register_date) = 2024
AND i.register_date > '$sinceDate'
ORDER BY i.register_date
LIMIT 0,5;
";
$db = $GLOBALS['db'];
$query = $db->query($query);
if ($db->last_error != '') {
echo json_encode(array('ok' => false, 'error' => $db->last_error));
return false;
}
$data = array();
while ($row = $db->fetchByAssoc($query)) {
$d = array();
$d['e5Id'] = $row['id'];
$d['documentNo'] = $row['document_no'];
$d['type'] = $row['type'];
$d['registerDate'] = $row['register_date'];
$d['sellDate'] = $row['sell_date'];
$d['clientName'] = $row['parent_name'];
$d['clientId'] = $row['parent_id'] ?: '';
$d['clientNip'] = $row['parent_nip'] ?: '';
$d['clientAddress'] = $row['parent_address_street'] . ", " . $row['parent_address_postalcode'] . " " . $row['parent_address_city'] . " " . $row['parent_address_country'];;
$d['currency'] = $row['currency'];
$d['totalNetto'] = $row['total_netto'];
$d['totalBrutto'] = $row['total_brutto'];
$d['totalVat'] = $row['total_vat'];
$d['source'] = $row['origin'];
$data[] = $d;
}
echo json_encode(array('ok' => true, 'data' => $data));
return true;
}

View File

@@ -14,6 +14,7 @@
}
require_once('./REST/functions.php');
require_once('./REST/bimai.php');
// Enable SugarCRM features
if(!defined('sugarEntry'))define('sugarEntry', true);
require_once('./include/entryPoint.php');
@@ -41,6 +42,8 @@
case 'createCSVReports':
createCSVReports();
break;
case 'bimai.export.ecommerce':
bimai_exportEcommerceDate($_GET['since']);
break;
}
// https://crm.twinpol.com/REST/index.php?key=d68dac4c-f784-4e1b-8267-9ffcfa0eda4c&action=createCostDocumentFromInvoice&record=c3f6eaa6-0cbd-8c89-1a8c-683ff19a36db
?>