Skip to content

Commit

Permalink
Fix a lot of request to use the IN getentity instead of =
Browse files Browse the repository at this point in the history
Fix a lot of request to use left join on type of payment table
  • Loading branch information
eldy committed Nov 23, 2017
1 parent 295b448 commit b93e35c
Show file tree
Hide file tree
Showing 50 changed files with 131 additions and 142 deletions.
12 changes: 6 additions & 6 deletions htdocs/admin/prelevement.php
Expand Up @@ -74,13 +74,13 @@

$res = dolibarr_set_const($db, "PRELEVEMENT_ICS", GETPOST("PRELEVEMENT_ICS"),'chaine',0,'',$conf->entity);
if (! $res > 0) $error++;

if (GETPOST("PRELEVEMENT_USER") > 0)
{
$res = dolibarr_set_const($db, "PRELEVEMENT_USER", GETPOST("PRELEVEMENT_USER"),'chaine',0,'',$conf->entity);
if (! $res > 0) $error++;
}

if (! $error)
{
$db->commit();
Expand Down Expand Up @@ -155,7 +155,7 @@
setEventMessages($langs->trans("ErrorModuleNotFound"), null, 'errors');
dol_syslog($langs->trans("ErrorModuleNotFound"), LOG_ERR);
}
}
}
// Set default model
else if ($action == 'setdoc')
Expand Down Expand Up @@ -411,7 +411,7 @@
$sql = "SELECT u.rowid, u.lastname, u.firstname, u.fk_soc, u.email";
$sql.= " FROM ".MAIN_DB_PREFIX."user as u";
$sql.= " WHERE entity IN (0,".$conf->entity.")";
$sql.= " WHERE entity IN (".getEntity('facture').")";

This comment has been minimized.

Copy link
@hregis

hregis Nov 23, 2017

Contributor

@eldy why "facture" ? this is "llx_user" table !

$resql=$db->query($sql);
if ($resql)
Expand All @@ -422,7 +422,7 @@
while ($i < $num)
{
$obj = $db->fetch_object($resql);
if (!$obj->fk_soc)
{
$username=dolGetFirstLastname($obj->firstname,$obj->lastname);
Expand Down Expand Up @@ -495,7 +495,7 @@
while ($i < $num)
{
$obj = $db->fetch_object($resql);
print '<tr class="oddeven">';
print '<td>'.dolGetFirstLastname($obj->firstname,$obj->lastname).'</td>';
Expand Down
6 changes: 3 additions & 3 deletions htdocs/comm/propal/class/propal.class.php
Expand Up @@ -1016,7 +1016,7 @@ function create($user, $notrigger=0)
{
if (! is_object($this->lines[$i])) // If this->lines is not array of objects, coming from REST API
{ // Convert into object this->lines[$i].
$line = (object) $this->lines[$i];
$line = (object) $this->lines[$i];
}
else
{
Expand Down Expand Up @@ -1331,8 +1331,8 @@ function fetch($rowid,$ref='')
$sql.= ", cr.code as cond_reglement_code, cr.libelle as cond_reglement, cr.libelle_facture as cond_reglement_libelle_doc";
$sql.= ", cp.code as mode_reglement_code, cp.libelle as mode_reglement";
$sql.= " FROM ".MAIN_DB_PREFIX."c_propalst as c, ".MAIN_DB_PREFIX."propal as p";
$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_paiement as cp ON p.fk_mode_reglement = cp.id AND cp.entity IN (' . getEntity('c_paiement').')';
$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_payment_term as cr ON p.fk_cond_reglement = cr.rowid AND cr.entity IN (' . getEntity('c_payment_term').')';
$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_paiement as cp ON p.fk_mode_reglement = cp.id AND cp.entity IN ('.getEntity('c_paiement').')';
$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_payment_term as cr ON p.fk_cond_reglement = cr.rowid AND cr.entity IN ('.getEntity('c_payment_term').')';
$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_availability as ca ON p.fk_availability = ca.rowid';
$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_input_reason as dr ON p.fk_input_reason = dr.rowid';
$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_incoterms as i ON p.fk_incoterms = i.rowid';
Expand Down
4 changes: 2 additions & 2 deletions htdocs/commande/class/commande.class.php
Expand Up @@ -1572,8 +1572,8 @@ function fetch($id, $ref='', $ref_ext='', $ref_int='')
$sql.= ', ca.code as availability_code, ca.label as availability_label';
$sql.= ', dr.code as demand_reason_code';
$sql.= ' FROM '.MAIN_DB_PREFIX.'commande as c';
$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_payment_term as cr ON c.fk_cond_reglement = cr.rowid AND cr.entity IN (' . getEntity('c_payment_term') . ')';
$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_paiement as p ON c.fk_mode_reglement = p.id AND p.entity IN (' . getEntity('c_paiement') . ')';
$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_payment_term as cr ON c.fk_cond_reglement = cr.rowid AND cr.entity IN ('.getEntity('c_payment_term').')';
$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_paiement as p ON c.fk_mode_reglement = p.id AND p.entity IN ('.getEntity('c_paiement').')';
$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_availability as ca ON c.fk_availability = ca.rowid';
$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_input_reason as dr ON c.fk_input_reason = ca.rowid';
$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_incoterms as i ON c.fk_incoterms = i.rowid';
Expand Down
4 changes: 2 additions & 2 deletions htdocs/compta/bank/class/account.class.php
Expand Up @@ -414,7 +414,7 @@ function addline($date, $oper, $label, $amount, $num_chq, $categorie, User $user
{
$sql = "SELECT code FROM ".MAIN_DB_PREFIX."c_paiement";
$sql.= " WHERE id=".$oper;
$sql.= " AND entity IN (" . getEntity('c_paiement') . ")";
$sql.= " AND entity IN (".getEntity('c_paiement').")";
$resql=$this->db->query($sql);
if ($resql)
{
Expand Down Expand Up @@ -857,7 +857,7 @@ function fetch($id, $ref='')
$sql.= " FROM ".MAIN_DB_PREFIX."bank_account as ba";
$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_country as c ON ba.fk_pays = c.rowid';
$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_departements as d ON ba.state_id = d.rowid';
$sql.= " WHERE entity IN (".getEntity($this->element, 1).")";
$sql.= " WHERE entity IN (".getEntity($this->element).")";
if ($id) $sql.= " AND ba.rowid = ".$id;
if ($ref) $sql.= " AND ba.ref = '".$this->db->escape($ref)."'";

Expand Down
4 changes: 2 additions & 2 deletions htdocs/compta/bank/various_payment/index.php
Expand Up @@ -96,10 +96,10 @@
$sql.= " ba.rowid as bid, ba.ref as bref, ba.number as bnumber, ba.account_number as bank_account_number, ba.fk_accountancy_journal as accountancy_journal, ba.label as blabel,";
$sql.= " pst.code as payment_code";
$sql.= " FROM ".MAIN_DB_PREFIX."payment_various as v";
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as pst ON v.fk_typepayment = pst.id AND pst.entity = " . getEntity('c_paiement');
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as pst ON v.fk_typepayment = pst.id AND pst.entity IN (" . getEntity('c_paiement').")";
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."bank as b ON v.fk_bank = b.rowid";
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."bank_account as ba ON b.fk_account = ba.rowid";
$sql.= " WHERE v.entity = ".$conf->entity;
$sql.= " WHERE v.entity IN (".getEntity('payment_various').")";

// Search criteria
if ($search_ref) $sql.=" AND v.rowid=".$search_ref;
Expand Down
10 changes: 5 additions & 5 deletions htdocs/compta/charges/index.php
Expand Up @@ -139,11 +139,11 @@
$sql.= " FROM ".MAIN_DB_PREFIX."c_chargesociales as c,";
$sql.= " ".MAIN_DB_PREFIX."chargesociales as cs";
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."paiementcharge as pc ON pc.fk_charge = cs.rowid";
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as pct ON pc.fk_typepaiement = pct.id AND pct.entity = " . getEntity('c_paiement');
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as pct ON pc.fk_typepaiement = pct.id AND pct.entity IN (".getEntity('c_paiement').")";
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."bank as b ON pc.fk_bank = b.rowid";
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."bank_account as ba ON b.fk_account = ba.rowid";
$sql.= " WHERE cs.fk_type = c.id";
$sql.= " AND cs.entity = ".$conf->entity;
$sql.= " AND cs.entity IN (".getEntity("tax").")";
if ($year > 0)
{
$sql .= " AND (";
Expand Down Expand Up @@ -260,8 +260,8 @@
$sql.= " FROM ".MAIN_DB_PREFIX."tva as pv";
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."bank as b ON pv.fk_bank = b.rowid";
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."bank_account as ba ON b.fk_account = ba.rowid";
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as pct ON pv.fk_typepayment = pct.id AND pct.entity = " . getEntity('c_paiement');
$sql.= " WHERE pv.entity = ".$conf->entity;
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as pct ON pv.fk_typepayment = pct.id AND pct.entity IN (".getEntity('c_paiement').")";
$sql.= " WHERE pv.entity IN (".getEntity("tax").")";
if ($year > 0)
{
// Si period renseignee on l'utilise comme critere de date, sinon on prend date echeance,
Expand Down Expand Up @@ -474,7 +474,7 @@
$sql.= " FROM ".MAIN_DB_PREFIX."payment_salary as s";
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."bank as b ON s.fk_bank = b.rowid";
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."bank_account as ba ON b.fk_account = ba.rowid";
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as pct ON s.fk_typepayment = pct.id AND pct.entity = " . getEntity('c_paiement');
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as pct ON s.fk_typepayment = pct.id AND pct.entity IN (".getEntity('c_paiement').")";
$sql.= " , ".MAIN_DB_PREFIX."user as u";
$sql.= " WHERE s.entity IN (".getEntity('user').")";
$sql.= " AND u.rowid = s.fk_user";
Expand Down
2 changes: 1 addition & 1 deletion htdocs/compta/deplacement/class/deplacement.class.php
Expand Up @@ -223,7 +223,7 @@ function fetch($id, $ref='')
{
$sql = "SELECT rowid, fk_user, type, fk_statut, km, fk_soc, dated, note_private, note_public, fk_projet, extraparams";
$sql.= " FROM ".MAIN_DB_PREFIX."deplacement";
$sql.= " WHERE entity IN (".getEntity('deplacement', 0).")";
$sql.= " WHERE entity IN (".getEntity('deplacement').")";
if ($ref) $sql.= " AND ref ='".$this->db->escape($ref)."'";
else $sql.= " AND rowid = ".$id;

Expand Down
14 changes: 8 additions & 6 deletions htdocs/compta/facture/card.php
Expand Up @@ -719,10 +719,11 @@
// If we're on a standard invoice, we have to get excess received to create a discount in TTC without VAT

$sql = 'SELECT SUM(pf.amount) as total_paiements';
$sql.= ' FROM '.MAIN_DB_PREFIX.'c_paiement as c, '.MAIN_DB_PREFIX.'paiement_facture as pf, '.MAIN_DB_PREFIX.'paiement as p';
$sql.= ' FROM '.MAIN_DB_PREFIX.'paiement_facture as pf, '.MAIN_DB_PREFIX.'paiement as p';
$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_paiement as c ON p.fk_paiement = c.id AND c.entity IN (' . getEntity('c_paiement') . ')';
$sql.= ' WHERE pf.fk_facture = '.$object->id;
$sql.= ' AND p.fk_paiement = c.id AND pf.fk_paiement = p.rowid';
$sql.= ' AND c.entity IN (' . getEntity('c_paiement').')';
$sql.= ' AND pf.fk_paiement = p.rowid';
$sql.= ' AND p.entity IN (' . getEntity('facture').')';
$sql.= ' ORDER BY p.datep, p.tms';

$resql = $db->query($sql);
Expand Down Expand Up @@ -3809,11 +3810,12 @@
$sql .= ' c.code as payment_code, c.libelle as payment_label,';
$sql .= ' pf.amount,';
$sql .= ' ba.rowid as baid, ba.ref as baref, ba.label, ba.number as banumber, ba.account_number, ba.fk_accountancy_journal';
$sql .= ' FROM ' . MAIN_DB_PREFIX . 'c_paiement as c, ' . MAIN_DB_PREFIX . 'paiement_facture as pf, ' . MAIN_DB_PREFIX . 'paiement as p';
$sql .= ' FROM ' . MAIN_DB_PREFIX . 'paiement_facture as pf, ' . MAIN_DB_PREFIX . 'paiement as p';
$sql .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'c_paiement as c ON p.fk_paiement = c.id' ;
$sql .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'bank as b ON p.fk_bank = b.rowid';
$sql .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'bank_account as ba ON b.fk_account = ba.rowid';
$sql .= ' WHERE pf.fk_facture = ' . $object->id . ' AND p.fk_paiement = c.id AND pf.fk_paiement = p.rowid';
$sql .= ' AND c.entity IN (' . getEntity('c_paiement').')';
$sql .= ' WHERE pf.fk_facture = ' . $object->id . ' AND pf.fk_paiement = p.rowid';
$sql .= ' AND p.entity IN (' . getEntity('facture').')';
$sql .= ' ORDER BY p.datep, p.tms';

$result = $db->query($sql);
Expand Down
9 changes: 5 additions & 4 deletions htdocs/compta/facture/class/facture-rec.class.php
Expand Up @@ -291,11 +291,12 @@ function fetch($rowid, $ref='', $ref_ext='', $ref_int='')
$sql.= ', c.code as cond_reglement_code, c.libelle as cond_reglement_libelle, c.libelle_facture as cond_reglement_libelle_doc';
//$sql.= ', el.fk_source';
$sql.= ' FROM '.MAIN_DB_PREFIX.'facture_rec as f';
$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_payment_term as c ON f.fk_cond_reglement = c.rowid AND c.entity IN (' . getEntity('c_payment_term').')';
$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_paiement as p ON f.fk_mode_reglement = p.id AND p.entity IN (' . getEntity('c_paiement').')';
$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_payment_term as c ON f.fk_cond_reglement = c.rowid AND c.entity IN ('.getEntity('c_payment_term').')';
$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_paiement as p ON f.fk_mode_reglement = p.id AND p.entity IN ('.getEntity('c_paiement').')';
//$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."element_element as el ON el.fk_target = f.rowid AND el.targettype = 'facture'";
if ($rowid) $sql.= ' WHERE f.rowid='.$rowid;
elseif ($ref) $sql.= " WHERE f.titre='".$this->db->escape($ref)."'";
$sql.= ' WHERE f.entity IN ('.getEntity('facture').')';
if ($rowid) $sql.= ' AND f.rowid='.$rowid;
elseif ($ref) $sql.= " AND f.titre='".$this->db->escape($ref)."'";
/* This field are not used for template invoice
if ($ref_ext) $sql.= " AND f.ref_ext='".$this->db->escape($ref_ext)."'";
if ($ref_int) $sql.= " AND f.ref_int='".$this->db->escape($ref_int)."'";
Expand Down
8 changes: 5 additions & 3 deletions htdocs/compta/facture/class/facture.class.php
Expand Up @@ -1225,9 +1225,9 @@ function fetch($rowid, $ref='', $ref_ext='', $ref_int='', $fetch_situation=false
$sql.= ", i.libelle as libelle_incoterms";
$sql.= ' FROM '.MAIN_DB_PREFIX.'facture as f';
$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_payment_term as c ON f.fk_cond_reglement = c.rowid AND c.entity IN (' . getEntity('c_payment_term').')';
$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_paiement as p ON f.fk_mode_reglement = p.id AND p.entity IN (' . getEntity('c_paiement').')';
$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_paiement as p ON f.fk_mode_reglement = p.id AND p.entity IN ('.getEntity('c_paiement').')';
$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_incoterms as i ON f.fk_incoterms = i.rowid';
$sql.= ' WHERE f.entity = '.$conf->entity;
$sql.= ' WHERE f.entity IN ('.getEntity('facture').')';
if ($rowid) $sql.= " AND f.rowid=".$rowid;
if ($ref) $sql.= " AND f.facnumber='".$this->db->escape($ref)."'";
if ($ref_ext) $sql.= " AND f.ref_ext='".$this->db->escape($ref_ext)."'";
Expand Down Expand Up @@ -3191,12 +3191,14 @@ function getListOfPayments($filtertype='')
$table2='paiement';
$field='fk_facture';
$field2='fk_paiement';
$sharedentity='facture';
if ($this->element == 'facture_fourn' || $this->element == 'invoice_supplier')
{
$table='paiementfourn_facturefourn';
$table2='paiementfourn';
$field='fk_facturefourn';
$field2='fk_paiementfourn';
$sharedentity='facture_fourn';
}

$sql = 'SELECT p.ref, pf.amount, pf.multicurrency_amount, p.fk_paiement, p.datep, p.num_paiement as num, t.code';
Expand All @@ -3205,7 +3207,7 @@ function getListOfPayments($filtertype='')
//$sql.= ' WHERE pf.'.$field.' = 1';
$sql.= ' AND pf.'.$field2.' = p.rowid';
$sql.= ' AND p.fk_paiement = t.id';
$sql.= ' AND t.entity IN (' . getEntity('c_paiement').')';
$sql.= ' AND p.entity IN (' . getEntity($sharedentity).')';
if ($filtertype) $sql.=" AND t.code='PRE'";

dol_syslog(get_class($this)."::getListOfPayments", LOG_DEBUG);
Expand Down
6 changes: 3 additions & 3 deletions htdocs/compta/paiement.php
Expand Up @@ -827,10 +827,10 @@ function callForResult(imgId)

$sql = 'SELECT p.datep as dp, p.amount, f.amount as fa_amount, f.facnumber';
$sql.=', f.rowid as facid, c.libelle as paiement_type, p.num_paiement';
$sql.= ' FROM '.MAIN_DB_PREFIX.'paiement as p, '.MAIN_DB_PREFIX.'facture as f, '.MAIN_DB_PREFIX.'c_paiement as c';
$sql.= ' WHERE p.fk_facture = f.rowid AND p.fk_paiement = c.id';
$sql.= ' FROM '.MAIN_DB_PREFIX.'paiement as p LEFT JOIN '.MAIN_DB_PREFIX.'c_paiement as c ON p.fk_paiement = c.id AND c.entity IN (' . getEntity('c_paiement').')';
$sql.= ', '.MAIN_DB_PREFIX.'facture as f';
$sql.= ' WHERE p.fk_facture = f.rowid';
$sql.= ' AND f.entity IN (' . getEntity('facture').')';
$sql.= ' AND c.entity IN (' . getEntity('c_paiement').')';
if ($socid)
{
$sql.= ' AND f.fk_soc = '.$socid;
Expand Down
6 changes: 2 additions & 4 deletions htdocs/compta/paiement/avalider.php
Expand Up @@ -64,15 +64,13 @@

$sql = "SELECT p.rowid, p.datep as dp, p.amount, p.statut";
$sql.=", c.libelle as paiement_type, p.num_paiement";
$sql.= " FROM ".MAIN_DB_PREFIX."paiement as p, ".MAIN_DB_PREFIX."c_paiement as c";
$sql.= " FROM ".MAIN_DB_PREFIX."paiement as p LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as c ON p.fk_paiement = c.id";
if ($socid)
{
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."paiement_facture as pf ON p.rowid = pf.fk_paiement";
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."facture as f ON pf.fk_facture = f.rowid";
}
$sql.= " WHERE p.fk_paiement = c.id";
$sql.= " AND p.entity = " . $conf->entity;
$sql.= " AND c.entity = " . getEntity('c_paiement');
$sql.= " WHERE p.entity IN (" . getEntity('facture') . ')';
if ($socid)
{
$sql.= " AND f.fk_soc = ".$socid;
Expand Down
7 changes: 3 additions & 4 deletions htdocs/compta/paiement/class/paiement.class.php
Expand Up @@ -90,10 +90,9 @@ function fetch($id, $ref='', $fk_bank='')
$sql.= ' c.code as type_code, c.libelle as type_libelle,';
$sql.= ' p.num_paiement, p.note,';
$sql.= ' b.fk_account';
$sql.= ' FROM '.MAIN_DB_PREFIX.'c_paiement as c, '.MAIN_DB_PREFIX.'paiement as p';
$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'bank as b ON p.fk_bank = b.rowid ';
$sql.= ' WHERE p.fk_paiement = c.id';
$sql.= ' AND c.entity IN (' . getEntity('c_paiement').')';
$sql.= ' FROM '.MAIN_DB_PREFIX.'paiement as p LEFT JOIN '.MAIN_DB_PREFIX.'c_paiement as c ON p.fk_paiement = c.id';
$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'bank as b ON p.fk_bank = b.rowid';
$sql.= ' WHERE p.entity IN (' . getEntity('facture').')';
if ($id > 0)
$sql.= ' AND p.rowid = '.$id;
else if ($ref)
Expand Down
15 changes: 6 additions & 9 deletions htdocs/compta/paiement/list.php
Expand Up @@ -115,12 +115,9 @@
$parameters=array();
$reshook=$hookmanager->executeHooks('printFieldListSelect',$parameters); // Note that $action and $object may have been modified by hook
$sql.=$hookmanager->resPrint;
$sql.= " FROM (".MAIN_DB_PREFIX."paiement as p,";
$sql.= " ".MAIN_DB_PREFIX."c_paiement as c)";
$sql.= " FROM ".MAIN_DB_PREFIX."paiement as p LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as c ON p.fk_paiement = c.id";
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."paiement_facture as pf ON p.rowid = pf.fk_paiement";
$sql.= " WHERE p.fk_paiement = c.id";
$sql.= " AND p.entity = " . $conf->entity;
$sql.= " AND c.entity = " . getEntity('c_paiement');
$sql.= " WHERE p.entity IN (" . getEntity('facture').")";
$sql.= " AND pf.fk_facture IS NULL";
// Add where from hooks
$parameters=array();
Expand All @@ -140,7 +137,8 @@
$parameters=array();
$reshook=$hookmanager->executeHooks('printFieldListSelect',$parameters); // Note that $action and $object may have been modified by hook
$sql.=$hookmanager->resPrint;
$sql.= " FROM (".MAIN_DB_PREFIX."c_paiement as c, ".MAIN_DB_PREFIX."paiement as p)";
$sql.= " FROM ".MAIN_DB_PREFIX."paiement as p";
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as c ON p.fk_paiement = c.id AND c.entity IN (" . getEntity('c_paiement') . ")";
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."bank as b ON p.fk_bank = b.rowid";
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."bank_account as ba ON b.fk_account = ba.rowid";
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."paiement_facture as pf ON p.rowid = pf.fk_paiement";
Expand All @@ -150,9 +148,8 @@
{
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON s.rowid = sc.fk_soc";
}
$sql.= " WHERE p.fk_paiement = c.id";
$sql.= " AND p.entity = " . $conf->entity;
$sql.= " AND c.entity = " . getEntity('c_paiement');
$sql.= " WHERE ";
$sql.= " AND p.entity IN (" . getEntity('facture') . ")";
if (! $user->rights->societe->client->voir && ! $socid)
{
$sql.= " AND sc.fk_user = " .$user->id;
Expand Down
4 changes: 2 additions & 2 deletions htdocs/compta/resultat/clientfourn.php
Expand Up @@ -822,7 +822,7 @@
$sql.= " FROM ".MAIN_DB_PREFIX."expensereport as p";
$sql.= " INNER JOIN ".MAIN_DB_PREFIX."user as u ON u.rowid=p.fk_user_author";
$sql.= " INNER JOIN ".MAIN_DB_PREFIX."payment_expensereport as pe ON pe.fk_expensereport = p.rowid";
$sql.= " INNER JOIN ".MAIN_DB_PREFIX."c_paiement as c ON pe.fk_typepayment = c.id AND c.entity = " . getEntity('c_paiement');
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as c ON pe.fk_typepayment = c.id AND c.entity IN (".getEntity('c_paiement').")";
$sql.= " WHERE p.entity = ".getEntity('expensereport');
$sql.= " AND p.fk_statut>=5";

Expand Down Expand Up @@ -906,7 +906,7 @@
$sql = "SELECT p.societe as nom, p.firstname, p.lastname, date_format(p.datedon,'%Y-%m') as dm, sum(p.amount) as amount";
$sql.= " FROM ".MAIN_DB_PREFIX."don as p";
$sql.= " INNER JOIN ".MAIN_DB_PREFIX."payment_donation as pe ON pe.fk_donation = p.rowid";
$sql.= " INNER JOIN ".MAIN_DB_PREFIX."c_paiement as c ON pe.fk_typepayment = c.id AND c.entity = " . getEntity('c_paiement');
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as c ON pe.fk_typepayment = c.id AND c.entity IN (".getEntity('c_paiement').")";
$sql.= " WHERE p.entity IN (".getEntity('donation').")";
$sql.= " AND fk_statut >= 2";
}
Expand Down

0 comments on commit b93e35c

Please sign in to comment.