41 lines
1.2 KiB
PHP
Executable File
41 lines
1.2 KiB
PHP
Executable File
<?php
|
|
error_reporting(E_ALL);
|
|
ini_set('display_errors', 1);
|
|
|
|
// Vendors
|
|
require_once 'ripcord/ripcord.php';
|
|
require '../config/config.inc.php';
|
|
require 'ErpTools.php';
|
|
require 'config.php';
|
|
|
|
if (empty($_GET['token']) || $_GET['token'] !== ERP_SCRIPT_TOKEN) {
|
|
die;
|
|
}
|
|
|
|
$models = ripcord::client("$url/xmlrpc/2/object");
|
|
$d = Db::getInstance();
|
|
|
|
|
|
$orders = $d->ExecuteS('SELECT * FROM '._DB_PREFIX_.'orders o LEFT JOIN '._DB_PREFIX_.'orders_erp oe ON (o.id_order = oe.id_order) WHERE valid = 0');
|
|
|
|
foreach ($orders as $key => $order) {
|
|
|
|
$isPayed = (bool)$d->getValue('SELECT COUNT(*) as num FROM '._DB_PREFIX_.'order_history WHERE id_order = '.(int)$order['id_order'].' AND id_order_state = 2');
|
|
if ($isPayed) { continue; }
|
|
|
|
if (!empty($order['id_erp']) && $order['id_erp'] != 0) {
|
|
|
|
$odoo = $models->execute_kw($db, $uid, $password, 'sale.order', 'read', array(array((int)$order['id_erp'])));
|
|
foreach ($odoo as $key => $o) {
|
|
if (!empty($o) && $o['state'] == 'progress') {
|
|
$history = new OrderHistory();
|
|
$history->id_order = $order['id_order'];
|
|
$history->id_employee = 0;
|
|
$history->id_order_state = 2;
|
|
$history->add();
|
|
$history->changeIdOrderState($history->id_order_state, new Order($order['id_order']));
|
|
}
|
|
}
|
|
}
|
|
}
|