From 3302a86f0c4c559cac5d3a1844024a6047389a53 Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Wed, 1 Feb 2012 18:29:06 +0100 Subject: [PATCH] Fix: add entity field in llx_paiement --- htdocs/compta/paiement.php | 13 +- htdocs/compta/paiement/avalider.php | 13 +- .../compta/paiement/class/paiement.class.php | 19 +- htdocs/compta/paiement/liste.php | 1 + htdocs/compta/recap-compta.php | 311 +++++++++--------- .../modules/facture/doc/pdf_crabe.modules.php | 2 +- .../facture/doc/pdf_oursin.modules.php | 2 +- .../modules/rapport/pdf_paiement.class.php | 21 +- 8 files changed, 193 insertions(+), 189 deletions(-) diff --git a/htdocs/compta/paiement.php b/htdocs/compta/paiement.php index 358e73d4f85..aa427f491ce 100644 --- a/htdocs/compta/paiement.php +++ b/htdocs/compta/paiement.php @@ -637,16 +637,17 @@ if (! GETPOST('action')) if (! $sortfield) $sortfield='p.datep'; $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.=', 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.= ' AND f.entity = '.$conf->entity; if ($socid) { - $sql .= ' AND f.fk_soc = '.$socid; + $sql.= ' AND f.fk_soc = '.$socid; } - $sql .= ' ORDER BY '.$sortfield.' '.$sortorder; - $sql .= $db->plimit($limit+1, $offset); + $sql.= ' ORDER BY '.$sortfield.' '.$sortorder; + $sql.= $db->plimit($limit+1, $offset); $resql = $db->query($sql); if ($resql) diff --git a/htdocs/compta/paiement/avalider.php b/htdocs/compta/paiement/avalider.php index 2cb5efb1ce3..1fde3bd1a19 100644 --- a/htdocs/compta/paiement/avalider.php +++ b/htdocs/compta/paiement/avalider.php @@ -56,21 +56,22 @@ if (! $sortfield) $sortfield="p.rowid"; $limit = $conf->liste_limit; $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.=", c.libelle as paiement_type, p.num_paiement"; +$sql.= " FROM ".MAIN_DB_PREFIX."paiement as p, ".MAIN_DB_PREFIX."c_paiement as c"; 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.= " WHERE p.fk_paiement = c.id"; +$sql.= " AND p.entity = ".$conf->entity; if ($socid) { $sql.= " AND f.fk_soc = ".$socid; } -$sql .= " AND p.statut = 0"; -$sql .= " ORDER BY $sortfield $sortorder"; -$sql .= $db->plimit($limit +1 ,$offset); +$sql.= " AND p.statut = 0"; +$sql.= " ORDER BY $sortfield $sortorder"; +$sql.= $db->plimit($limit +1 ,$offset); $resql = $db->query($sql); if ($resql) diff --git a/htdocs/compta/paiement/class/paiement.class.php b/htdocs/compta/paiement/class/paiement.class.php index 7754a370ecd..d5cc2ce4e3f 100644 --- a/htdocs/compta/paiement/class/paiement.class.php +++ b/htdocs/compta/paiement/class/paiement.class.php @@ -56,11 +56,11 @@ class Paiement extends CommonObject /** * Constructor * - * @param DoliDB $DB Database handler + * @param DoliDB $db Database handler */ - function Paiement($DB) + function Paiement($db) { - $this->db = $DB ; + $this->db = $db ; } /** @@ -129,7 +129,7 @@ class Paiement extends CommonObject */ function create($user,$closepaidinvoices=0) { - global $langs,$conf; + global $conf, $langs; $error = 0; @@ -151,8 +151,8 @@ class Paiement extends CommonObject $this->db->begin(); - $sql = "INSERT INTO ".MAIN_DB_PREFIX."paiement (datec, datep, amount, fk_paiement, num_paiement, note, fk_user_creat)"; - $sql.= " VALUES ('".$this->db->idate($now)."', '".$this->db->idate($this->datepaye)."', '".$totalamount."', ".$this->paiementid.", '".$this->num_paiement."', '".$this->db->escape($this->note)."', ".$user->id.")"; + $sql = "INSERT INTO ".MAIN_DB_PREFIX."paiement (entity, datec, datep, amount, fk_paiement, num_paiement, note, fk_user_creat)"; + $sql.= " VALUES (".$conf->entity.", '".$this->db->idate($now)."', '".$this->db->idate($this->datepaye)."', '".$totalamount."', ".$this->paiementid.", '".$this->num_paiement."', '".$this->db->escape($this->note)."', ".$user->id.")"; dol_syslog(get_class($this)."::Create insert paiement sql=".$sql); $resql = $this->db->query($sql); @@ -619,10 +619,9 @@ class Paiement extends CommonObject */ function info($id) { - $sql = 'SELECT c.rowid, c.datec, c.fk_user_creat, c.fk_user_modif,'; - $sql.= ' c.tms'; - $sql.= ' FROM '.MAIN_DB_PREFIX.'paiement as c'; - $sql.= ' WHERE c.rowid = '.$id; + $sql = 'SELECT p.rowid, p.datec, p.fk_user_creat, p.fk_user_modif, p.tms'; + $sql.= ' FROM '.MAIN_DB_PREFIX.'paiement as p'; + $sql.= ' WHERE p.rowid = '.$id; dol_syslog(get_class($this).'::info sql='.$sql); $result = $this->db->query($sql); diff --git a/htdocs/compta/paiement/liste.php b/htdocs/compta/paiement/liste.php index 8c930856137..ddc95aa5642 100644 --- a/htdocs/compta/paiement/liste.php +++ b/htdocs/compta/paiement/liste.php @@ -73,6 +73,7 @@ if (GETPOST("orphelins")) $sql.= " ".MAIN_DB_PREFIX."c_paiement as c)"; $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 pf.fk_facture IS NULL"; } else diff --git a/htdocs/compta/recap-compta.php b/htdocs/compta/recap-compta.php index 72771a20c8b..f5e3b3ca01a 100644 --- a/htdocs/compta/recap-compta.php +++ b/htdocs/compta/recap-compta.php @@ -47,170 +47,171 @@ llxHeader(); if ($socid > 0) { - $societe = new Societe($db); - $societe->fetch($socid); - - /* - * Affichage onglets - */ + $societe = new Societe($db); + $societe->fetch($socid); + + /* + * Affichage onglets + */ $head = societe_prepare_head($societe); - - dol_fiche_head($head, 'customer', $langs->trans("ThirdParty"), 0, 'company'); - - print "\n"; - print '
'; - - print ''; - - // Nom - print ''; - - // Prefix - if (! empty($conf->global->SOCIETE_USEPREFIX)) // Old not used prefix field - { - print ''; - } - - print "
'.$langs->trans("Name").''.$societe->nom.'
'.$langs->trans("Prefix").''; - print ($societe->prefix_comm?$societe->prefix_comm:' '); - print '
"; - - print "
\n"; - - print ''; - - - if ($conf->facture->enabled && $user->rights->facture->lire) - { - // Factures - print_fiche_titre($langs->trans("CustomerPreview")); - - print ''; - - $sql = "SELECT s.nom, s.rowid as socid, f.facnumber, f.amount, f.datef as df,"; - $sql.= " f.paye as paye, f.fk_statut as statut, f.rowid as facid,"; - $sql.= " u.login, u.rowid as userid"; - $sql.= " FROM ".MAIN_DB_PREFIX."societe as s,".MAIN_DB_PREFIX."facture as f,".MAIN_DB_PREFIX."user as u"; - $sql.= " WHERE f.fk_soc = s.rowid AND s.rowid = ".$societe->id; - $sql.= " AND f.fk_user_valid = u.rowid"; - $sql.= " ORDER BY f.datef DESC"; - - $resql=$db->query($sql); - if ($resql) - { - $var=true; - $num = $db->num_rows($resql); - - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - + + dol_fiche_head($head, 'customer', $langs->trans("ThirdParty"), 0, 'company'); + + print "
'.$langs->trans("Date").' '.$langs->trans("Status").''.$langs->trans("Debit").''.$langs->trans("Credit").''.$langs->trans("Balance").' 
\n"; + print '
'; + + print ''; + + // Nom + print ''; + + // Prefix + if (! empty($conf->global->SOCIETE_USEPREFIX)) // Old not used prefix field + { + print ''; + } + + print "
'.$langs->trans("Name").''.$societe->nom.'
'.$langs->trans("Prefix").''; + print ($societe->prefix_comm?$societe->prefix_comm:' '); + print '
"; + + print "
\n"; + + print ''; + + if ($conf->facture->enabled && $user->rights->facture->lire) + { + // Factures + print_fiche_titre($langs->trans("CustomerPreview")); + + print ''; + + $sql = "SELECT s.nom, s.rowid as socid, f.facnumber, f.amount, f.datef as df,"; + $sql.= " f.paye as paye, f.fk_statut as statut, f.rowid as facid,"; + $sql.= " u.login, u.rowid as userid"; + $sql.= " FROM ".MAIN_DB_PREFIX."societe as s,".MAIN_DB_PREFIX."facture as f,".MAIN_DB_PREFIX."user as u"; + $sql.= " WHERE f.fk_soc = s.rowid AND s.rowid = ".$societe->id; + $sql.= " AND f.entity = ".$conf->entity; + $sql.= " AND f.fk_user_valid = u.rowid"; + $sql.= " ORDER BY f.datef DESC"; + + $resql=$db->query($sql); + if ($resql) + { + $var=true; + $num = $db->num_rows($resql); + + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + if (! $num > 0) - { - print ''; - } - - $solde = 0; - - // Boucle sur chaque facture - for ($i = 0 ; $i < $num ; $i++) - { - $objf = $db->fetch_object($resql); - - $fac = new Facture($db); - $ret=$fac->fetch($objf->facid); - if ($ret < 0) - { - print $fac->error."
"; - continue; - } - $totalpaye = $fac->getSommePaiement(); - - $var=!$var; - print ""; - - print "\n"; - print "\n"; - - print ''; - print '\n"; - $solde = $solde + $fac->total_ttc; - - print ''; - print '\n"; - - // Auteur - print ''; - - print "\n"; - - // Paiements - $sql = "SELECT p.rowid, p.datep as dp, pf.amount, p.statut,"; - $sql.= " p.fk_user_creat, u.login, u.rowid as userid"; - $sql.= " FROM ".MAIN_DB_PREFIX."paiement_facture as pf,"; - $sql.= " ".MAIN_DB_PREFIX."paiement as p"; - $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."user as u ON p.fk_user_creat = u.rowid"; - $sql.= " WHERE pf.fk_paiement = p.rowid"; - $sql.= " AND pf.fk_facture = ".$fac->id; - - $resqlp = $db->query($sql); - if ($resqlp) - { - $nump = $db->num_rows($resqlp); - $j = 0; - - while ($j < $nump) - { - $objp = $db->fetch_object($resqlp); - //$var=!$var; - print ""; - print '\n"; - print ''; - print "\n"; - print "\n"; - print ''; - $solde = $solde - $objp->amount; - print '\n"; - + { + print ''; + } + + $solde = 0; + + // Boucle sur chaque facture + for ($i = 0 ; $i < $num ; $i++) + { + $objf = $db->fetch_object($resql); + + $fac = new Facture($db); + $ret=$fac->fetch($objf->facid); + if ($ret < 0) + { + print $fac->error."
"; + continue; + } + $totalpaye = $fac->getSommePaiement(); + + $var=!$var; + print ""; + + print "\n"; + print "\n"; + + print ''; + print '\n"; + $solde = $solde + $fac->total_ttc; + + print ''; + print '\n"; + + // Auteur + print ''; + + print "\n"; + + // Paiements + $sql = "SELECT p.rowid, p.datep as dp, pf.amount, p.statut,"; + $sql.= " p.fk_user_creat, u.login, u.rowid as userid"; + $sql.= " FROM ".MAIN_DB_PREFIX."paiement_facture as pf,"; + $sql.= " ".MAIN_DB_PREFIX."paiement as p"; + $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."user as u ON p.fk_user_creat = u.rowid"; + $sql.= " WHERE pf.fk_paiement = p.rowid"; + $sql.= " AND p.entity = ".$conf->entity; + $sql.= " AND pf.fk_facture = ".$fac->id; + + $resqlp = $db->query($sql); + if ($resqlp) + { + $nump = $db->num_rows($resqlp); + $j = 0; + + while ($j < $nump) + { + $objp = $db->fetch_object($resqlp); + //$var=!$var; + print ""; + print '\n"; + print ''; + print "\n"; + print "\n"; + print ''; + $solde = $solde - $objp->amount; + print '\n"; + // Auteur - print ''; - - print ''; - - $j++; - } - - $db->free($resqlp); - } - else - { - dol_print_error($db); - } - } - } - else - { - dol_print_error($db); - } - print "
'.$langs->trans("Date").' '.$langs->trans("Status").''.$langs->trans("Debit").''.$langs->trans("Credit").''.$langs->trans("Balance").' 
'.$langs->trans("NoInvoice").'
".dol_print_date($fac->date)."id\">".img_object($langs->trans("ShowBill"),"bill")." ".$fac->ref."'.$fac->getLibStatut(2,$totalpaye).''.price($fac->total_ttc)." '.price($solde)."'.img_object($langs->trans("ShowUser"),'user').' '.$objf->login.'
'.dol_print_date($db->jdate($objp->dp))."'; - print '      '; // Decalage - print ''.img_object($langs->trans("ShowPayment"),"payment").' '.$langs->trans("Payment").' '.$objp->rowid.'  '.price($objp->amount).''.price($solde)."
'.$langs->trans("NoInvoice").'
".dol_print_date($fac->date)."id\">".img_object($langs->trans("ShowBill"),"bill")." ".$fac->ref."'.$fac->getLibStatut(2,$totalpaye).''.price($fac->total_ttc)." '.price($solde)."'.img_object($langs->trans("ShowUser"),'user').' '.$objf->login.'
'.dol_print_date($db->jdate($objp->dp))."'; + print '      '; // Decalage + print ''.img_object($langs->trans("ShowPayment"),"payment").' '.$langs->trans("Payment").' '.$objp->rowid.'  '.price($objp->amount).''.price($solde)."'.img_object($langs->trans("ShowUser"),'user').' '.$objp->login.'
"; - print "
"; - } + print ''.img_object($langs->trans("ShowUser"),'user').' '.$objp->login.''; + + print ''; + + $j++; + } + + $db->free($resqlp); + } + else + { + dol_print_error($db); + } + } + } + else + { + dol_print_error($db); + } + print ""; + print "
"; + } } else { - dol_print_error($db); + dol_print_error($db); } +llxFooter(); $db->close(); -llxFooter(); ?> diff --git a/htdocs/core/modules/facture/doc/pdf_crabe.modules.php b/htdocs/core/modules/facture/doc/pdf_crabe.modules.php index 760b175a42f..5a5882c2454 100755 --- a/htdocs/core/modules/facture/doc/pdf_crabe.modules.php +++ b/htdocs/core/modules/facture/doc/pdf_crabe.modules.php @@ -521,7 +521,7 @@ class pdf_crabe extends ModelePDFFactures $sql.= " cp.code"; $sql.= " FROM ".MAIN_DB_PREFIX."paiement_facture as pf, ".MAIN_DB_PREFIX."paiement as p"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as cp ON p.fk_paiement = cp.id"; - $sql.= " WHERE pf.fk_paiement = p.rowid and pf.fk_facture = ".$object->id; + $sql.= " WHERE pf.fk_paiement = p.rowid AND pf.fk_facture = ".$object->id; $sql.= " ORDER BY p.datep"; $resql=$this->db->query($sql); if ($resql) diff --git a/htdocs/core/modules/facture/doc/pdf_oursin.modules.php b/htdocs/core/modules/facture/doc/pdf_oursin.modules.php index 26ae580d4d3..0c43cb2e5e2 100755 --- a/htdocs/core/modules/facture/doc/pdf_oursin.modules.php +++ b/htdocs/core/modules/facture/doc/pdf_oursin.modules.php @@ -406,7 +406,7 @@ class pdf_oursin extends ModelePDFFactures $sql.= " cp.code"; $sql.= " FROM ".MAIN_DB_PREFIX."paiement_facture as pf, ".MAIN_DB_PREFIX."paiement as p"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as cp ON p.fk_paiement = cp.id"; - $sql.= " WHERE pf.fk_paiement = p.rowid and pf.fk_facture = ".$object->id; + $sql.= " WHERE pf.fk_paiement = p.rowid AND pf.fk_facture = ".$object->id; $sql.= " ORDER BY p.datep"; $resql=$this->db->query($sql); if ($resql) diff --git a/htdocs/core/modules/rapport/pdf_paiement.class.php b/htdocs/core/modules/rapport/pdf_paiement.class.php index ff1522267de..c6c083c7efd 100644 --- a/htdocs/core/modules/rapport/pdf_paiement.class.php +++ b/htdocs/core/modules/rapport/pdf_paiement.class.php @@ -115,16 +115,17 @@ class pdf_paiement $sql = "SELECT p.datep as dp, f.facnumber"; //$sql .= ", c.libelle as paiement_type, p.num_paiement"; - $sql .= ", c.code as paiement_code, p.num_paiement"; - $sql .= ", p.amount as paiement_amount, f.total_ttc as facture_amount "; - $sql .= ", pf.amount as pf_amount "; - $sql .= ", p.rowid as prowid"; - $sql .= " FROM ".MAIN_DB_PREFIX."paiement as p, ".MAIN_DB_PREFIX."facture as f,"; - $sql .= " ".MAIN_DB_PREFIX."c_paiement as c, ".MAIN_DB_PREFIX."paiement_facture as pf"; - $sql .= " WHERE pf.fk_facture = f.rowid AND pf.fk_paiement = p.rowid"; - $sql .= " AND p.fk_paiement = c.id "; - $sql .= " AND p.datep BETWEEN '".$this->db->idate(dol_get_first_day($year,$month))."' AND '".$this->db->idate(dol_get_last_day($year,$month))."'"; - $sql .= " ORDER BY p.datep ASC, pf.fk_paiement ASC"; + $sql.= ", c.code as paiement_code, p.num_paiement"; + $sql.= ", p.amount as paiement_amount, f.total_ttc as facture_amount "; + $sql.= ", pf.amount as pf_amount "; + $sql.= ", p.rowid as prowid"; + $sql.= " FROM ".MAIN_DB_PREFIX."paiement as p, ".MAIN_DB_PREFIX."facture as f,"; + $sql.= " ".MAIN_DB_PREFIX."c_paiement as c, ".MAIN_DB_PREFIX."paiement_facture as pf"; + $sql.= " WHERE pf.fk_facture = f.rowid AND pf.fk_paiement = p.rowid"; + $sql.= " AND f.entity = ".$conf->entity; + $sql.= " AND p.fk_paiement = c.id "; + $sql.= " AND p.datep BETWEEN '".$this->db->idate(dol_get_first_day($year,$month))."' AND '".$this->db->idate(dol_get_last_day($year,$month))."'"; + $sql.= " ORDER BY p.datep ASC, pf.fk_paiement ASC"; dol_syslog("pdf_paiement::write_file sql=".$sql); $result = $this->db->query($sql);