WIP: schedulers..
This commit is contained in:
@@ -2,8 +2,10 @@
|
||||
$id = $_REQUEST['apilo_details'];
|
||||
|
||||
$apilo_config = loadApiloConfiguration();
|
||||
brecho('halo');
|
||||
brecho(loadApiloOrder($apilo_config['token'], $id));
|
||||
function loadApiloOrder($token, $orderId) {
|
||||
brecho($token);
|
||||
$url = "https://twinpol.apilo.com/rest/api/orders/".$orderId."/";
|
||||
$headers = [
|
||||
'Authorization: Bearer ' . $token,
|
||||
@@ -17,6 +19,7 @@ function loadApiloOrder($token, $orderId) {
|
||||
$response = curl_exec($curl);
|
||||
$httpCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
|
||||
curl_close($curl);
|
||||
brecho($response);
|
||||
if ($httpCode !== 200) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ function getOrder($token, $orderId)
|
||||
function brecho($msg)
|
||||
{
|
||||
echo '<br><pre>';
|
||||
var_dump($msg);
|
||||
print_r($msg);
|
||||
echo PHP_EOL;
|
||||
echo '</pre><br>';
|
||||
}
|
||||
@@ -111,7 +111,7 @@ function copyToClipboard(text) {
|
||||
}
|
||||
function openDetails(id, origin) {
|
||||
window.console.log(origin);
|
||||
if (origin.startsWith('apilo')) {
|
||||
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");
|
||||
|
||||
@@ -109,12 +109,17 @@
|
||||
{$ROW.document_no}
|
||||
{if $ROW.origin == 'amazon'}
|
||||
<img src="modules/EcmSales/images/pdf.gif" onclick="copyToClipboard('{$ROW.url}')"
|
||||
style="cursor:pointer;"></a>
|
||||
style="cursor:pointer;"/>
|
||||
{/if}
|
||||
{if $ROW.origin == 'allegro'}
|
||||
<img src="modules/EcmSales/images/pdf.gif"
|
||||
onclick="window.open('https://panel-g.baselinker.com/printouts/printout_invoices.php?id={$ROW.id}')"
|
||||
style="cursor:pointer;" {/if} </td>
|
||||
style="cursor:pointer;"/>
|
||||
{/if}
|
||||
<img src="modules/EcmSales/images/convert.gif"
|
||||
onclick="openDetails('{$ROW.order_no}', '{$ROW.origin}')"
|
||||
style="cursor:pointer;"/>
|
||||
</td>
|
||||
<td>
|
||||
<a target="_blank"
|
||||
href="index.php?module=EcmStockDocOuts&action=DetailView&record={$ROW.wz_id}">{$ROW.wz_document_no}</a>
|
||||
|
||||
@@ -1,36 +1,31 @@
|
||||
<?php
|
||||
// enable error reporting
|
||||
error_reporting(LC_ALL);
|
||||
ini_set('display_errors', 1);
|
||||
//error_reporting(LC_ALL);
|
||||
//ini_set('display_errors', 1);
|
||||
// ?XDEBUG_SESSION_START=PHPSTORM
|
||||
importInvoices();
|
||||
function importInvoices()
|
||||
//importInvoices();
|
||||
function apilo_importInvoices()
|
||||
{
|
||||
$apilo_config = loadApiloConfiguration();
|
||||
$apilo_config = apilo_loadConfiguration();
|
||||
$db = $GLOBALS['db'];
|
||||
|
||||
$GLOBALS['log']->info('----- Importing invoices from Apilo, config', $apilo_config);
|
||||
|
||||
$dbRes = $db->query("SELECT COUNT(id) as last_id FROM ecommerce_invoices WHERE origin LIKE 'apilo%'");
|
||||
$offset = intval($db->fetchByAssoc($dbRes)['last_id']);
|
||||
|
||||
$GLOBALS['log']->info('----- Importing invoices from Apilo, offset', $offset);
|
||||
|
||||
$invoices = loadApiloInvoices($apilo_config['token'], $offset);
|
||||
$invoices = apilo_loadInvoices($apilo_config['token'], $offset);
|
||||
if (isset($invoices->error)) {
|
||||
if (refreshApiloToken($apilo_config['refreshToken'], $apilo_config['clientId'], $apilo_config['clientSecret']) == true) {
|
||||
$apilo_config = loadApiloConfiguration();
|
||||
$invoices = loadApiloInvoices($apilo_config['token'], $offset);
|
||||
if (apilo_refreshToken($apilo_config['refreshToken'], $apilo_config['clientId'], $apilo_config['clientSecret']) == true) {
|
||||
//$apilo_config = apilo_loadConfiguration();
|
||||
//$invoices = apilo_loadInvoices($apilo_config['token'], $offset);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
brecho(count($invoices->documents));
|
||||
$GLOBALS['log']->bimit('----- Importing invoices from Apilo, documents count', count($invoices->documents));
|
||||
|
||||
$GLOBALS['log']->info('----- Importing invoices from Apilo, documents count', count($invoices->documents));
|
||||
|
||||
$platforms = loadApiloPlatformsList($apilo_config['token']);
|
||||
$platforms = apilo_loadPlatformsList($apilo_config['token']);
|
||||
|
||||
if (!$platforms) {
|
||||
return false;
|
||||
@@ -38,15 +33,15 @@ function importInvoices()
|
||||
|
||||
if (isset($invoices->documents) && count($invoices->documents) > 0) {
|
||||
foreach ($invoices->documents as $invoice) {
|
||||
addapiloInvoice($invoice, $platforms, $apilo_config['token']);
|
||||
apilo_addInvoice($invoice, $platforms, $apilo_config['token']);
|
||||
}
|
||||
}
|
||||
$GLOBALS['log']->info('----- Importing invoices from Apilo, all processed, return TRUE');
|
||||
$GLOBALS['log']->bimit('----- Importing invoices from Apilo, all processed, return TRUE');
|
||||
return true;
|
||||
}
|
||||
function loadApiloConfiguration()
|
||||
function apilo_loadConfiguration()
|
||||
{
|
||||
global $db;
|
||||
$db = $GLOBALS['db'];
|
||||
$dbRes = $db->query("SELECT * FROM config WHERE category='apilo'");
|
||||
$config = [];
|
||||
while ($row = $db->fetchByAssoc($dbRes)) {
|
||||
@@ -54,7 +49,7 @@ function loadApiloConfiguration()
|
||||
}
|
||||
return $config;
|
||||
}
|
||||
function loadApiloInvoices($token, $offset)
|
||||
function apilo_loadInvoices($token, $offset)
|
||||
{
|
||||
$url = "https://twinpol.apilo.com/rest/api/finance/documents/";
|
||||
$params = [
|
||||
@@ -81,7 +76,7 @@ function loadApiloInvoices($token, $offset)
|
||||
}
|
||||
return json_decode($response);
|
||||
}
|
||||
function refreshApiloToken($refreshToken, $clientId, $clientSecret)
|
||||
function apilo_refreshToken($refreshToken, $clientId, $clientSecret)
|
||||
{
|
||||
$url = "https://twinpol.apilo.com/rest/auth/token/";
|
||||
|
||||
@@ -126,11 +121,11 @@ function refreshApiloToken($refreshToken, $clientId, $clientSecret)
|
||||
}
|
||||
return false;
|
||||
}
|
||||
function addApiloInvoice($invoice, $platforms, $token)
|
||||
function apilo_addInvoice($invoice, $platforms, $token)
|
||||
{
|
||||
$db = $GLOBALS['db'];
|
||||
|
||||
$platformId = loadApiloOrderPlatformId($token, $invoice->orderId);
|
||||
$platformId = apilo_loadOrderPlatformId($token, $invoice->orderId);
|
||||
if (!$platformId) {
|
||||
return false;
|
||||
}
|
||||
@@ -231,12 +226,12 @@ function addApiloInvoice($invoice, $platforms, $token)
|
||||
if (isset($invoice->documentItems) && is_array($invoice->documentItems)) {
|
||||
$db->query(sprintf("DELETE FROM ecommerce_invoices_products WHERE invoice_id='%s'", $db->quote($invoice->id)));
|
||||
foreach ($invoice->documentItems as $item) {
|
||||
addApiloInvoiceProduct($invoice->id, $item);
|
||||
apilo_addInvoiceProduct($invoice->id, $item);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
function addApiloInvoiceProduct($invoiceId, $item)
|
||||
function apilo_addInvoiceProduct($invoiceId, $item)
|
||||
{
|
||||
$db = $GLOBALS['db'];
|
||||
|
||||
@@ -290,7 +285,7 @@ function addApiloInvoiceProduct($invoiceId, $item)
|
||||
return false;
|
||||
}
|
||||
}
|
||||
function loadApiloPlatformsList($token) {
|
||||
function apilo_loadPlatformsList($token) {
|
||||
$url = "https://twinpol.apilo.com/rest/api/orders/platform/map/";
|
||||
$headers = [
|
||||
'Authorization: Bearer ' . $token,
|
||||
@@ -309,7 +304,7 @@ function loadApiloPlatformsList($token) {
|
||||
}
|
||||
return json_decode($response);
|
||||
}
|
||||
function loadApiloOrderPlatformId($token, $orderId) {
|
||||
function apilo_loadOrderPlatformId($token, $orderId) {
|
||||
$url = "https://twinpol.apilo.com/rest/api/orders/".$orderId."/";
|
||||
$headers = [
|
||||
'Authorization: Bearer ' . $token,
|
||||
|
||||
Reference in New Issue
Block a user