diff --git a/REST/bimai.php b/REST/bimai.php new file mode 100644 index 00000000..8cc01824 --- /dev/null +++ b/REST/bimai.php @@ -0,0 +1,64 @@ + 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; +} \ No newline at end of file diff --git a/REST/index.php b/REST/index.php index 16931b6d..35ffc998 100644 --- a/REST/index.php +++ b/REST/index.php @@ -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 -?> \ No newline at end of file + // https://crm.twinpol.com/REST/index.php?key=d68dac4c-f784-4e1b-8267-9ffcfa0eda4c&action=createCostDocumentFromInvoice&record=c3f6eaa6-0cbd-8c89-1a8c-683ff19a36db \ No newline at end of file