Skip to content
This repository has been archived by the owner on Oct 4, 2024. It is now read-only.

Commit

Permalink
- Correction de la date de la facture qui est maintenant egale à la d…
Browse files Browse the repository at this point in the history
…ate de paiement (le cas echeant celle de la commande)

- Correction compatibilité multi-entité
- Correction recherche sur l'id distant (requetes SQL)
  • Loading branch information
kamel committed Jul 27, 2022
1 parent bb7d677 commit 34c4c6e
Show file tree
Hide file tree
Showing 18 changed files with 91 additions and 151 deletions.
5 changes: 5 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# ChangeLog

## 4.1.11.0
- Correction de la date de la facture qui est maintenant egale à la date de paiement (le cas echeant celle de la commande)
- Correction compatibilité multi-entité
- Correction recherche sur l'id distant (requetes SQL)

## 4.1.10.0
- Correction synchronisation des commandes
- Correction ordre de synchronisation des webhook du plus recent au plus ancien
Expand Down
28 changes: 16 additions & 12 deletions class/business/eCommercePendingWebHook.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -570,10 +570,12 @@ public function cronProcessPendingWebHooks()
return -1;
}

$sql = "SELECT rowid, site_id, webhook_topic, webhook_resource, webhook_event, webhook_data";
$sql .= " FROM " . MAIN_DB_PREFIX . "ecommerce_pending_webhooks";
$sql .= " WHERE status IN (" . self::STATUS_NOT_PROCESSED . ")";
$sql .= " ORDER BY webhook_topic DESC, rowid DESC";
$sql = "SELECT epw.rowid, epw.site_id, epw.webhook_topic, epw.webhook_resource, epw.webhook_event, epw.webhook_data";
$sql .= " FROM " . MAIN_DB_PREFIX . "ecommerce_pending_webhooks AS epw";
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."ecommerce_site AS es ON es.rowid = epw.site_id";
$sql .= " WHERE epw.status IN (" . self::STATUS_NOT_PROCESSED . ")";
$sql .= " AND es.entity IN (" . getEntity('ecommerceng') . ")";
$sql .= " ORDER BY epw.webhook_topic DESC, epw.rowid DESC";

$resql = $this->db->query($sql);
if (!$resql) {
Expand Down Expand Up @@ -913,12 +915,14 @@ public function archive()
$period = !empty($conf->global->ECOMMERCE_PROCESSING_WEBHOOK_LOGS_BEFORE_X_DAYS) ? abs($conf->global->ECOMMERCE_PROCESSING_WEBHOOK_LOGS_BEFORE_X_DAYS) : 7;
$log_before_date = dol_time_plus_duree(dol_now(), -$period, 'd');

$sql = "SELECT rowid, datec, site_id, delivery_id, webhook_id, webhook_topic, webhook_resource" .
", webhook_event, webhook_data, webhook_signature, webhook_source, status, datep, error_msg" .
" FROM " . MAIN_DB_PREFIX . "ecommerce_pending_webhooks" .
" WHERE status IN (" . self::STATUS_PROCESSED . ")" .
" AND datep < '" . $this->db->idate($log_before_date) . "'" .
" ORDER BY datep ASC";
$sql = "SELECT epw.rowid, epw.datec, epw.site_id, epw.delivery_id, epw.webhook_id, epw.webhook_topic, epw.webhook_resource" .
", epw.webhook_event, epw.webhook_data, epw.webhook_signature, epw.webhook_source, epw.status, epw.datep, epw.error_msg" .
" FROM " . MAIN_DB_PREFIX . "ecommerce_pending_webhooks AS epw" .
" LEFT JOIN ".MAIN_DB_PREFIX."ecommerce_site AS es ON es.rowid = epw.site_id" .
" WHERE epw.status IN (" . self::STATUS_PROCESSED . ")" .
" AND es.entity IN (" . getEntity('ecommerceng') . ")" .
" AND epw.datep < '" . $this->db->idate($log_before_date) . "'" .
" ORDER BY epw.datep ASC";

$resql = $this->db->query($sql);
if (!$resql) {
Expand All @@ -927,8 +931,8 @@ public function archive()
$this->errors = array();
dol_syslog(__METHOD__ . " SQL: " . $sql . "; Error: " . $this->db->lasterror(), LOG_ERR);
} elseif ($this->db->num_rows($resql) > 0) {
if (empty($conf->global->SYSLOG_FILE)) $logfile = DOL_DATA_ROOT . '/woosync_webhooks.v2.log';
else $logfile = dirname(str_replace('DOL_DATA_ROOT', DOL_DATA_ROOT, $conf->global->SYSLOG_FILE)) . "/woosync_webhooks.v2.log";
if (empty($conf->global->SYSLOG_FILE)) $logfile = DOL_DATA_ROOT . '/woosync_webhooks_' . $conf->entity . '.v2.log';
else $logfile = dirname(str_replace('DOL_DATA_ROOT', DOL_DATA_ROOT, $conf->global->SYSLOG_FILE)) . "/woosync_webhooks_" . $conf->entity . ".v2.log";

// Open/create log file
$filefd = @fopen($logfile, 'a+');
Expand Down
8 changes: 3 additions & 5 deletions class/business/eCommerceSynchro.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -2447,7 +2447,6 @@ function getContactIdFromInfos($contact)
$zip = (empty($contact->zip) ? '' : $contact->zip);
$town = (empty($contact->town) ? '' : $contact->town);
$country_id = ($contact->country_id > 0 ? $contact->country_id : $contact->country_id);
$entity = ((isset($contact->entity) && is_numeric($contact->entity)) ? $contact->entity : $conf->entity);

$sql = 'SELECT rowid FROM ' . MAIN_DB_PREFIX . 'socpeople';
$sql .= ' WHERE lastname LIKE "' . $this->db->escape($lastname) . '"';
Expand All @@ -2461,7 +2460,7 @@ function getContactIdFromInfos($contact)
if (isset($contact->fax)) $sql .= ' AND fax LIKE "' . $this->db->escape($fax) . '"';
if ($socid > 0) $sql .= ' AND fk_soc = "' . $this->db->escape($socid) . '"';
else if ($socid == -1) $sql .= " AND fk_soc IS NULL";
$sql .= ' AND entity = ' . $entity;
$sql .= ' AND entity IN ('.getEntity('socpeople').')';

$resql = $this->db->query($sql);
if ($resql) {
Expand Down Expand Up @@ -5059,7 +5058,7 @@ public function synchronizeInvoiceFromOrder($order_data, $dont_synchronize_produ
// Set the invoice
$invoice->socid = $third_party_id;
$invoice->type = isset($this->eCommerceSite->parameters['create_invoice_type']) ? $this->eCommerceSite->parameters['create_invoice_type'] : Facture::TYPE_STANDARD;
$invoice->date = $order->id > 0 ? $order->date : strtotime($order_data['date_commande']);
$invoice->date = isset($order_data['date_payment']) && $order_data['date_payment'] !== '' ? strtotime($order_data['date_payment']) : ($order->id > 0 ? $order->date_commande : strtotime($order_data['date_commande']));
$invoice->ref_client = $order->id > 0 ? $order->ref_client : $order_data['ref_client'];
$invoice->ref_ext = $invoice_ref_ext;
$invoice->modelpdf = $conf->global->FACTURE_ADDON_PDF;
Expand Down Expand Up @@ -6512,7 +6511,6 @@ public function getContactInfosFromData($contact_data, $company_id = 0)
$email = trim($contact_data['email']);
$phone_pro = trim(dol_trunc($contact_data['phone'], 30, 'right', 'UTF-8', 1));
$fax = trim(dol_trunc($contact_data['fax'], 30, 'right', 'UTF-8', 1));
$entity = $conf->entity;

$sql = 'SELECT rowid, fk_soc FROM ' . MAIN_DB_PREFIX . 'socpeople';
$sql .= ' WHERE lastname LIKE "' . $this->db->escape($lastname) . '"';
Expand All @@ -6530,7 +6528,7 @@ public function getContactInfosFromData($contact_data, $company_id = 0)
if ($socid > 0) $sql .= ' AND fk_soc = ' . $this->db->escape($socid);
else if ($socid == -1) $sql .= " AND fk_soc IS NULL";
}
$sql .= ' AND entity = ' . $entity;
$sql .= ' AND entity IN ('.getEntity('socpeople').')';

$resql = $this->db->query($sql);
if ($resql) {
Expand Down
6 changes: 3 additions & 3 deletions class/data/eCommerceCategory.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ public function checkForUpdate($siteId, $toDate, $remoteCatToCheck)
$updateRequired = 0; // If any error occurs, category won't appears in update array

$sql = "SELECT t.last_update as lastdate, t.remote_parent_id as parentid, t.fk_category FROM " . MAIN_DB_PREFIX . $this->table_element . " as t";
$sql.= " WHERE t.remote_id=" . $remoteCatToCheck['category_id'] . " AND t.fk_site = " . $siteId;
$sql.= " WHERE t.remote_id='" . $this->db->escape($remoteCatToCheck['category_id']) . "' AND t.fk_site = " . $siteId;

$resql = $this->db->query($sql);
if ($resql)
Expand Down Expand Up @@ -445,7 +445,7 @@ public function fetchByRemoteId($remoteId, $siteId)
$sql.= "t.last_update";
$sql.= " FROM " . MAIN_DB_PREFIX . $this->table_element . " as t";
$sql.= " WHERE t.fk_site = " . $siteId;
$sql.= " AND t.remote_id = " . $remoteId;
$sql.= " AND t.remote_id = '" . $this->db->escape($remoteId) . "'";

dol_syslog(get_class($this) . "::fetchByRemoteId sql=" . $sql, LOG_DEBUG);
$resql = $this->db->query($sql);
Expand Down Expand Up @@ -603,7 +603,7 @@ public function getDolibarrCategoryFromRemoteIds($ids, $siteId)
foreach ($ids as $remoteId)
{
$ii++;
$sql .= $remoteId . ($ii == $idsCount ? ")" : ",");
$sql .= "'".$this->db->escape($remoteId)."'" . ($ii == $idsCount ? ")" : ",");
}

dol_syslog(get_class($this) . "::getDolibarrCategoryFromRemoteIds sql=" . $sql, LOG_DEBUG);
Expand Down
2 changes: 1 addition & 1 deletion class/data/eCommerceFacture.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ public function fetchByRemoteId($remoteId, $siteId)
$sql.= " t.last_update";
$sql.= " FROM ".MAIN_DB_PREFIX."ecommerce_facture as t";
$sql.= " WHERE t.fk_site = ".$siteId;
$sql.= " AND t.remote_id = ".$remoteId;
$sql.= " AND t.remote_id = '".$this->db->escape($remoteId)."'";
dol_syslog(get_class($this)."::fetchByRemoteId sql=".$sql, LOG_DEBUG);
$resql=$this->db->query($sql);
if ($resql)
Expand Down
75 changes: 44 additions & 31 deletions class/data/eCommerceSite.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,8 @@ function listSites($mode='array')
$sql.= " t.rowid,";
$sql.= " t.name,";
$sql.= " t.last_update";
$sql.= " FROM ".MAIN_DB_PREFIX."ecommerce_site as t";
$sql.= " FROM ".MAIN_DB_PREFIX."ecommerce_site as t";
$sql.= " WHERE t.entity IN (" . getEntity('ecommerceng') . ")";

$result = $this->db->query($sql);
if ($result)
Expand Down Expand Up @@ -655,6 +656,7 @@ function hasTypeSite($typeSite)
$sql.= " count(*) AS count";
$sql.= " FROM ".MAIN_DB_PREFIX."ecommerce_site as t";
$sql.= " WHERE t.type=".$typeSite;
$sql.= " AND t.entity IN (" . getEntity('ecommerceng') . ")";

$result = $this->db->query($sql);
if ($result) {
Expand Down Expand Up @@ -723,45 +725,56 @@ function setEntityValues($entity)
{
global $conf;

$result = 0;

if ($conf->entity != $entity) {
$conf->entity = $entity;
if (method_exists($conf, 'setEntityValues')) {
return $conf->setEntityValues($this->db, $entity);
} else {
if ($conf->entity != $entity) {
// If we ask to reload setup for a new entity
$conf->entity = $entity;

if (method_exists($conf, 'setEntityValues')) {
$result = $conf->setEntityValues($this->db, $entity);
} else {
// Unset all old modules values
if (!empty($conf->modules)) {
foreach ($conf->modules as $m) {
if (isset($conf->$m)) unset($conf->$m);
}
}

// Properly declare multi-modules objects.
$conf->global = new stdClass();
// Common objects that are not modules
$conf->mycompany = new stdClass();
$conf->admin = new stdClass();
$conf->medias = new stdClass();
$conf->global = new stdClass();
$conf->multicompany = new stdClass();

// Common objects that are not modules and set by the main and not into the this->setValues()
//$conf->browser = new stdClass(); // This is set by main and not into this setValues(), so we keep it intact.

// First level object
// TODO Remove this part.
$conf->expedition_bon = new stdClass();
$conf->livraison_bon = new stdClass();
$conf->fournisseur = new stdClass();
$conf->product = new stdClass();
$conf->service = new stdClass();
$conf->contrat = new stdClass();
$conf->actions = new stdClass();
$conf->commande = new stdClass();
$conf->propal = new stdClass();
$conf->facture = new stdClass();
$conf->contrat = new stdClass();
$conf->usergroup = new stdClass();
$conf->adherent = new stdClass();
$conf->bank = new stdClass();
$conf->notification = new stdClass();
$conf->mailing = new stdClass();
$conf->expensereport = new stdClass();
$conf->productbatch = new stdClass();
$conf->syslog = new stdClass();
$conf->expedition_bon = new stdClass();
$conf->delivery_note = new stdClass();
$conf->fournisseur = new stdClass();
$conf->product = new stdClass();
$conf->service = new stdClass();
$conf->contrat = new stdClass();
$conf->actions = new stdClass();
$conf->agenda = new stdClass();
$conf->commande = new stdClass();
$conf->propal = new stdClass();
$conf->facture = new stdClass();
$conf->contrat = new stdClass();
$conf->user = new stdClass();
$conf->usergroup = new stdClass();
$conf->adherent = new stdClass();
$conf->bank = new stdClass();
$conf->notification = new stdClass();
$conf->mailing = new stdClass();
$conf->expensereport = new stdClass();
$conf->productbatch = new stdClass();

// Common arrays
$conf->cache = array();
$conf->modules = array();;
$conf->modules_parts = array(
'css' => array(),
Expand All @@ -782,11 +795,11 @@ function setEntityValues($entity)
'syslog' => array(),
);

$result = $conf->setValues($this->db);
return $conf->setValues($this->db);
}
}

return $result;
return 0;
}
}
}

2 changes: 1 addition & 1 deletion class/data/eCommerceSociete.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ public function fetchByRemoteId($remoteId, $siteId)
$sql.= " t.last_update";
$sql.= " FROM ".MAIN_DB_PREFIX."ecommerce_societe as t";
$sql.= " WHERE t.fk_site = ".$siteId;
$sql.= " AND t.remote_id = ".$remoteId;
$sql.= " AND t.remote_id = '".$this->db->escape($remoteId)."'";
dol_syslog(get_class($this)."::fetchByRemoteId sql=".$sql, LOG_DEBUG);
$resql=$this->db->query($sql);
if ($resql)
Expand Down
2 changes: 1 addition & 1 deletion class/data/eCommerceSocpeople.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ public function fetchByRemoteId($remoteId, $typeId, $siteId)
$sql.= " FROM ".MAIN_DB_PREFIX."ecommerce_socpeople as t";
$sql.= " WHERE t.fk_site = ".$siteId;
$sql.= " AND t.type = ".$typeId;
$sql.= " AND t.remote_id = '".$remoteId."'";
$sql.= " AND t.remote_id = '".$this->db->escape($remoteId)."'";
dol_syslog(get_class($this)."::fetchByRemoteId sql=".$sql, LOG_DEBUG);
$resql=$this->db->query($sql);
if ($resql)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1746,6 +1746,7 @@ public function convertOrderDataIntoProcessedData($remote_data)
'remote_id_societe' => $remote_data->customer_id,
'ref_client' => $remote_data->number,
'date_commande' => $remote_data->date_created,
'date_payment' => $remote_data->date_paid,
'date_livraison' => $remote_data->date_completed,
'total_ht' => $remote_data->total - $remote_data->total_tax,
'total_tva' => $remote_data->total_tax,
Expand Down
10 changes: 6 additions & 4 deletions core/boxes/box_ecommerce_webhooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,12 @@ public function loadBox($max = 20)
$this->info_box_head = array('text' => $langs->trans("ECommerceBoxWebHooks"));

if ($user->rights->ecommerceng->read) {
$sql = "SELECT status, count(*) AS nb";
$sql .= " FROM " . MAIN_DB_PREFIX . "ecommerce_pending_webhooks";
$sql .= " GROUP BY status";
$sql .= " ORDER BY status";
$sql = "SELECT epw.status, count(*) AS nb";
$sql .= " FROM " . MAIN_DB_PREFIX . "ecommerce_pending_webhooks AS epw";
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "ecommerce_sites AS es ON es.rowid = epw.site_id";
$sql .= " WHERE es.entity IN (" . getEntity('ecommerceng') . ")";
$sql .= " GROUP BY epw.status";
$sql .= " ORDER BY epw.status";

dol_syslog(get_class($this) . "::loadBox", LOG_DEBUG);
$result = $this->db->query($sql);
Expand Down
2 changes: 1 addition & 1 deletion core/modules/modECommerceNg.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ function __construct($db)
$this->editor_url = 'http://www.open-dsi.fr';

// Possible values for version are: 'development', 'experimental', 'dolibarr' or version
$this->version = '4.1.10';
$this->version = '4.1.11';
// Key used in llx_const table to save module status enabled/disabled (where MYMODULE is value of property name of module in uppercase)
$this->const_name = 'MAIN_MODULE_' . strtoupper($this->name);
// Where to store the module in setup page (0=common,1=interface,2=others,3=very specific)
Expand Down
87 changes: 0 additions & 87 deletions lib/eCommerce.lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -738,90 +738,3 @@ function get_company_by_email($db, $email, $site=0)

return $result;
}

/**
* Load setup values into conf object (read llx_const) for a specified entity
* Note that this->db->xxx, this->file->xxx and this->multicompany have been already loaded when setEntityValues is called.
*
* @param DoliDB $db Database handler
* @param Conf $conf Conf handler
* @param int $entity Entity to get
* @return int < 0 if KO, >= 0 if OK
*/
function confSetEntityValues($db, &$conf, $entity)
{
if (method_exists($conf, 'setEntityValues')) {
return $conf->setEntityValues($db, $entity);
} else {
if ($conf->entity != $entity) {
// If we ask to reload setup for a new entity
$conf->entity = $entity;

// Unset all old modules values
if (!empty($conf->modules)) {
foreach ($conf->modules as $m) {
if (isset($conf->$m)) unset($conf->$m);
}
}

// Common objects that are not modules
$conf->mycompany = new stdClass();
$conf->admin = new stdClass();
$conf->medias = new stdClass();
$conf->global = new stdClass();

// Common objects that are not modules and set by the main and not into the this->setValues()
//$conf->browser = new stdClass(); // This is set by main and not into this setValues(), so we keep it intact.

// First level object
// TODO Remove this part.
$conf->syslog = new stdClass();
$conf->expedition_bon = new stdClass();
$conf->delivery_note = new stdClass();
$conf->fournisseur = new stdClass();
$conf->product = new stdClass();
$conf->service = new stdClass();
$conf->contrat = new stdClass();
$conf->actions = new stdClass();
$conf->agenda = new stdClass();
$conf->commande = new stdClass();
$conf->propal = new stdClass();
$conf->facture = new stdClass();
$conf->contrat = new stdClass();
$conf->user = new stdClass();
$conf->usergroup = new stdClass();
$conf->adherent = new stdClass();
$conf->bank = new stdClass();
$conf->notification = new stdClass();
$conf->mailing = new stdClass();
$conf->expensereport = new stdClass();
$conf->productbatch = new stdClass();

// Common arrays
$conf->cache = array();
$conf->modules = array();;
$conf->modules_parts = array(
'css' => array(),
'js' => array(),
'tabs' => array(),
'triggers' => array(),
'login' => array(),
'substitutions' => array(),
'menus' => array(),
'theme' => array(),
'sms' => array(),
'tpl' => array(),
'barcode' => array(),
'models' => array(),
'societe' => array(),
'hooks' => array(),
'dir' => array(),
'syslog' => array(),
);

return $conf->setValues($db);
}

return 0;
}
}
Loading

0 comments on commit 34c4c6e

Please sign in to comment.