diff --git a/modules/EcmInvoiceOuts/BimIT-eCommerceInvoices/baselinkerInvoiceDetails.php b/modules/EcmInvoiceOuts/BimIT-eCommerceInvoices/baselinkerInvoiceDetails.php
new file mode 100644
index 00000000..e972a4d3
--- /dev/null
+++ b/modules/EcmInvoiceOuts/BimIT-eCommerceInvoices/baselinkerInvoiceDetails.php
@@ -0,0 +1,45 @@
+query("SELECT * FROM config WHERE category='baselinker'");
+ $config = [];
+ while ($row = $db->fetchByAssoc($dbRes)) {
+ $config[$row['name']] = $row['value'];
+ }
+ return $config;
+}
+function getOrder($token, $orderId)
+{
+ $methodParams = '{
+ "order_id": ' . $orderId . '
+ }';
+ $apiParams = [
+ "method" => "getOrders",
+ "parameters" => $methodParams
+ ];
+
+ $curl = curl_init("https://api.baselinker.com/connector.php");
+ curl_setopt($curl, CURLOPT_POST, 1);
+ curl_setopt($curl, CURLOPT_HTTPHEADER, ["X-BLToken: " . $token]);
+ curl_setopt($curl, CURLOPT_VERBOSE, 0);
+ curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
+ curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($apiParams));
+ $res = json_decode(curl_exec($curl));
+ if ($res->orders[0]->order_source != '') {
+ return $res->orders[0];
+ }
+}
+function brecho($msg)
+{
+echo '
';
+ var_dump($msg);
+ echo PHP_EOL;
+ echo '
';
+}
\ No newline at end of file
diff --git a/modules/EcmInvoiceOuts/BimIT-eCommerceInvoices/ecommerceInvoicesListView.js b/modules/EcmInvoiceOuts/BimIT-eCommerceInvoices/ecommerceInvoicesListView.js
index 8543d164..e71363c5 100644
--- a/modules/EcmInvoiceOuts/BimIT-eCommerceInvoices/ecommerceInvoicesListView.js
+++ b/modules/EcmInvoiceOuts/BimIT-eCommerceInvoices/ecommerceInvoicesListView.js
@@ -109,6 +109,12 @@ function blockUI($msg) {
function copyToClipboard(text) {
navigator.clipboard.writeText(text);
}
-function openDetails(id) {
- window.open("index.php?module=EcmInvoiceOuts&action=ecommerce&apilo_details="+id, "_blank");
+function openDetails(id, origin) {
+ window.console.log(origin);
+ if (origin.startsWith('apilo')) {
+ window.open("index.php?module=EcmInvoiceOuts&action=ecommerce&apilo_details="+id, "_blank");
+ } else {
+ window.open("index.php?module=EcmInvoiceOuts&action=ecommerce&baselinker_details="+id, "_blank");
+ }
+
}
\ No newline at end of file
diff --git a/modules/EcmInvoiceOuts/BimIT-eCommerceInvoices/ecommerceInvoicesListView.tpl b/modules/EcmInvoiceOuts/BimIT-eCommerceInvoices/ecommerceInvoicesListView.tpl
index a340d20e..faaef86a 100644
--- a/modules/EcmInvoiceOuts/BimIT-eCommerceInvoices/ecommerceInvoicesListView.tpl
+++ b/modules/EcmInvoiceOuts/BimIT-eCommerceInvoices/ecommerceInvoicesListView.tpl
@@ -153,7 +153,7 @@
{$ROW.sum_by_products}
{math equation="abs(x-y)" x=$ROW.total_netto y=$ROW.sum_by_products assign="price_difference"}
{if $price_difference > 0.02}
- !!!
+ !!!
{/if}
diff --git a/modules/EcmInvoiceOuts/BimIT-eCommerceInvoices/importApiloInvoices.php b/modules/EcmInvoiceOuts/BimIT-eCommerceInvoices/importApiloInvoices.php
index fdbd22de..e20c6dbb 100644
--- a/modules/EcmInvoiceOuts/BimIT-eCommerceInvoices/importApiloInvoices.php
+++ b/modules/EcmInvoiceOuts/BimIT-eCommerceInvoices/importApiloInvoices.php
@@ -1,6 +1,6 @@
fetchByAssoc($dbRes)['last_id']);
$invoices = loadApiloInvoices($apilo_config['token'], $offset);
-
if (isset($invoices->error)) {
- if (refreshApiloToken($apilo_config['refresh_token'], $apilo_config['client_id'], $apilo_config['client_secret']) == true) {
+ if (refreshApiloToken($apilo_config['refreshToken'], $apilo_config['clientId'], $apilo_config['clientSecret']) == true) {
$apilo_config = loadApiloConfiguration();
$invoices = loadApiloInvoices($apilo_config['token'], $offset);
} else {
@@ -72,41 +71,42 @@ function loadApiloInvoices($token, $offset)
}
function refreshApiloToken($refreshToken, $clientId, $clientSecret)
{
- $url = "https://api.apilo.com/oauth/token";
+ $url = "https://twinpol.apilo.com/rest/auth/token/";
$data = [
- 'grant_type' => 'refresh_token',
- 'refresh_token' => $refreshToken,
- 'client_id' => $clientId,
- 'client_secret' => $clientSecret
+ 'grantType' => 'refresh_token',
+ 'token' => $refreshToken,
];
$headers = [
- 'Content-Type: application/x-www-form-urlencoded',
+ 'Authorization: Basic ' . base64_encode($clientId . ':' . $clientSecret),
+ 'Content-Type: application/json',
'Accept: application/json'
];
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_POST, true);
- curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($data));
+ curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_TIMEOUT, 30);
$response = curl_exec($curl);
$httpCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
+ $err = curl_error($curl);
curl_close($curl);
+ brecho($response);
+ brecho($httpCode);
if ($httpCode !== 200) {
return false;
}
-
$tokenData = json_decode($response, true);
- if (isset($tokenData['access_token'])) {
+ brecho($tokenData);
+ if (isset($tokenData['accessToken'])) {
global $db;
$db->query("UPDATE config SET value='" . $tokenData['access_token'] . "' WHERE category='apilo' AND name='access_token'");
-
if (isset($tokenData['refresh_token'])) {
$db->query("UPDATE config SET value='" . $tokenData['refresh_token'] . "' WHERE category='apilo' AND name='refresh_token'");
}
diff --git a/modules/EcmInvoiceOuts/ecommerce.php b/modules/EcmInvoiceOuts/ecommerce.php
index 74cfb457..52c47525 100644
--- a/modules/EcmInvoiceOuts/ecommerce.php
+++ b/modules/EcmInvoiceOuts/ecommerce.php
@@ -21,6 +21,8 @@ if (isset($_REQUEST['import_baselinker'])) {
include_once(getcwd() . '/modules/EcmInvoiceOuts/BimIT-eCommerceInvoices/importApiloInvoices.php');
} else if (isset($_REQUEST['apilo_details'])) {
include_once(getcwd() . '/modules/EcmInvoiceOuts/BimIT-eCommerceInvoices/apiloInvoiceDetails.php');
+} else if (isset($_REQUEST['baselinker_details'])) {
+ include_once(getcwd() . '/modules/EcmInvoiceOuts/BimIT-eCommerceInvoices/baselinkerInvoiceDetails.php');
} else if (isset($_REQUEST['apilo_products'])) {
include_once(getcwd() . '/modules/EcmInvoiceOuts/BimIT-eCommerceInvoices/checkApiloProducts.php');
} else {
diff --git a/modules/Schedulers/_AddJobsHere.php b/modules/Schedulers/_AddJobsHere.php
index fa369024..6cc47ce1 100644
--- a/modules/Schedulers/_AddJobsHere.php
+++ b/modules/Schedulers/_AddJobsHere.php
@@ -86,6 +86,7 @@ function importBaselinkerInvoices()
require_once('modules/EcmInvoiceOuts/BimIT-eCommerceInvoices/importBaselinkerInvoices.php');
importFV('7688'); // FV Polska
//importFV('15356'); // FV Polska (stare)
+ importFV('53096'); // FV Temu
return true;
} catch (Exception $e) {
return false;
|