Fix: The call of fetch method for societe.class with a second argument (ref) was wrong.

This commit is contained in:
Laurent Destailleur 2009-11-09 18:28:17 +00:00
parent 52dc19bc9f
commit 314b2e9509
9 changed files with 233 additions and 233 deletions

View File

@ -31,7 +31,7 @@ require_once(DOL_DOCUMENT_ROOT."/facture.class.php");
$langs->load("companies"); $langs->load("companies");
if ($conf->facture->enabled) $langs->load("bills"); if ($conf->facture->enabled) $langs->load("bills");
// Sécurité accés client // Security check
$socid = $_GET["socid"]; $socid = $_GET["socid"];
if ($user->societe_id > 0) if ($user->societe_id > 0)
{ {
@ -42,9 +42,7 @@ if ($user->societe_id > 0)
/* /*
* * View
* Mode fiche
*
*/ */
llxHeader(); llxHeader();
@ -52,7 +50,7 @@ llxHeader();
if ($socid > 0) if ($socid > 0)
{ {
$societe = new Societe($db); $societe = new Societe($db);
$societe->fetch($socid, $to); // si $to='next' ajouter " AND s.rowid > $socid ORDER BY idp ASC LIMIT 1"; $societe->fetch($socid);
/* /*
* Affichage onglets * Affichage onglets

View File

@ -18,11 +18,11 @@
*/ */
/** /**
\file htdocs/comm/recap-client.php * \file htdocs/comm/recap-client.php
\ingroup societe * \ingroup societe
\brief Page de fiche recap client * \brief Page de fiche recap client
\version $Id$ * \version $Id$
*/ */
require("./pre.inc.php"); require("./pre.inc.php");
require_once(DOL_DOCUMENT_ROOT."/lib/company.lib.php"); require_once(DOL_DOCUMENT_ROOT."/lib/company.lib.php");
@ -31,7 +31,7 @@ require_once(DOL_DOCUMENT_ROOT."/facture.class.php");
$langs->load("companies"); $langs->load("companies");
if ($conf->facture->enabled) $langs->load("bills"); if ($conf->facture->enabled) $langs->load("bills");
// Sécurité accés client // Security check
$socid = $_GET["socid"]; $socid = $_GET["socid"];
if ($user->societe_id > 0) if ($user->societe_id > 0)
{ {
@ -42,9 +42,7 @@ if ($user->societe_id > 0)
/* /*
* * View
* Mode fiche
*
*/ */
llxHeader(); llxHeader();
@ -52,7 +50,7 @@ llxHeader();
if ($socid > 0) if ($socid > 0)
{ {
$societe = new Societe($db); $societe = new Societe($db);
$societe->fetch($socid, $to); // si $to='next' ajouter " AND s.rowid > $socid ORDER BY idp ASC LIMIT 1"; $societe->fetch($socid);
/* /*
* Affichage onglets * Affichage onglets

View File

@ -21,215 +21,215 @@
*/ */
/** /**
\file htdocs/compta/export/modules/compta.export.class.php \file htdocs/compta/export/modules/compta.export.class.php
\ingroup compta \ingroup compta
\brief Fichier de la classe d'export compta \brief Fichier de la classe d'export compta
\version $Revision$ \version $Revision$
*/ */
/** /**
\class ComptaExport \class ComptaExport
\brief Classe permettant les exports comptables \brief Classe permettant les exports comptables
*/ */
class ComptaExport class ComptaExport
{ {
/** /**
\brief Constructeur de la class \brief Constructeur de la class
\param DB Object de base de données \param DB Object de base de donn<EFBFBD>es
\param USER Object utilisateur \param USER Object utilisateur
\param classe Nom de la classe utilisée pour formater les rapports \param classe Nom de la classe utilis<EFBFBD>e pour formater les rapports
*/ */
function ComptaExport ($DB, $USER, $classe) function ComptaExport ($DB, $USER, $classe)
{ {
$this->db = $DB; $this->db = $DB;
$this->user = $USER; $this->user = $USER;
$this->classe_export = $classe; $this->classe_export = $classe;
$this->error_message = ''; $this->error_message = '';
} }
/** /**
\brief Lecture des factures dans la base \brief Lecture des factures dans la base
\param id Id ligne \param id Id ligne
*/ */
function ReadLines($id=0) function ReadLines($id=0)
{ {
global $langs; global $langs;
dol_syslog("ComptaExport::ReadLines id=".$id); dol_syslog("ComptaExport::ReadLines id=".$id);
$error = 0; $error = 0;
$sql = "SELECT f.rowid as facid, f.facnumber, ".$this->db->pdate("f.datef")." as datef"; $sql = "SELECT f.rowid as facid, f.facnumber, ".$this->db->pdate("f.datef")." as datef";
$sql .= " , f.total_ttc, f.tva "; $sql .= " , f.total_ttc, f.tva ";
$sql .= " ,s.nom, s.rowid as socid, s.code_compta"; $sql .= " ,s.nom, s.rowid as socid, s.code_compta";
$sql .= " , l.price, l.tva_taux"; $sql .= " , l.price, l.tva_taux";
$sql .= " , c.numero, f.increment"; $sql .= " , c.numero, f.increment";
$sql .= " , l.rowid as lrowid"; $sql .= " , l.rowid as lrowid";
$sql .= " FROM ".MAIN_DB_PREFIX."facturedet as l"; $sql .= " FROM ".MAIN_DB_PREFIX."facturedet as l";
$sql .= " , ".MAIN_DB_PREFIX."facture as f"; $sql .= " , ".MAIN_DB_PREFIX."facture as f";
$sql .= " , ".MAIN_DB_PREFIX."societe as s"; $sql .= " , ".MAIN_DB_PREFIX."societe as s";
$sql .= " , ".MAIN_DB_PREFIX."compta_compte_generaux as c"; $sql .= " , ".MAIN_DB_PREFIX."compta_compte_generaux as c";
$sql .= " WHERE f.rowid = l.fk_facture "; $sql .= " WHERE f.rowid = l.fk_facture ";
$sql .= " AND s.rowid = f.fk_soc"; $sql .= " AND s.rowid = f.fk_soc";
$sql .= " AND f.fk_statut = 1 "; $sql .= " AND f.fk_statut = 1 ";
$sql .= " AND l.fk_code_ventilation <> 0 "; $sql .= " AND l.fk_code_ventilation <> 0 ";
$sql .= " AND l.fk_export_compta = ".$id; $sql .= " AND l.fk_export_compta = ".$id;
$sql .= " AND c.rowid = l.fk_code_ventilation"; $sql .= " AND c.rowid = l.fk_code_ventilation";
$sql .= " ORDER BY f.rowid ASC, l.fk_code_ventilation ASC"; $sql .= " ORDER BY f.rowid ASC, l.fk_code_ventilation ASC";
$resql = $this->db->query($sql); $resql = $this->db->query($sql);
if ($resql) if ($resql)
{ {
$num = $this->db->num_rows($resql); $num = $this->db->num_rows($resql);
$i = 0; $i = 0;
$this->linec = array(); $this->linec = array();
while ($i < $num) while ($i < $num)
{
$obj = $this->db->fetch_object($resql);
$this->linec[$i][0] = $obj->datef;
$this->linec[$i][1] = $obj->facid;
$this->linec[$i][2] = $obj->code_compta;
$this->linec[$i][3] = $obj->nom;
$this->linec[$i][4] = $obj->numero;
$this->linec[$i][5] = $obj->facnumber;
$this->linec[$i][6] = $obj->tva;
$this->linec[$i][7] = $obj->total_ttc;
$this->linec[$i][8] = $obj->price;
$this->linec[$i][9] = $obj->increment;
$this->linec[$i][10] = $obj->lrowid;
if ($obj->code_compta == '')
{
$societe=new Societe($this->db);
$societe->fetch($obj->socid);
$this->error_message.= $langs->transnoentities("ErrorWrongAccountancyCodeForCompany",$societe->getNomUrl(1))."<br>";
$error++;
}
$i++;
}
$this->db->free($resql);
}
return $error;
}
/**
\brief Lecture des paiements dans la base
\param id Id ligne
*/
function ReadLinesPayment($id=0)
{
dol_syslog("ComptaExport::ReadLinesPayment id=".$id);
$error = 0;
$sql = "SELECT p.rowid as paymentid, f.facnumber";
$sql .= " ,".$this->db->pdate("p.datep")." as datep";
$sql .= " , pf.amount";
$sql .= " , s.nom, s.code_compta";
$sql .= " , cp.libelle, f.increment";
$sql .= " FROM ".MAIN_DB_PREFIX."paiement as p";
$sql .= " , ".MAIN_DB_PREFIX."paiement_facture as pf";
$sql .= " , ".MAIN_DB_PREFIX."c_paiement as cp";
$sql .= " , ".MAIN_DB_PREFIX."facture as f";
$sql .= " , ".MAIN_DB_PREFIX."societe as s";
$sql .= " WHERE p.fk_export_compta = ".$id;
$sql .= " AND p.rowid = pf.fk_paiement";
$sql .= " AND cp.id = p.fk_paiement";
$sql .= " AND f.rowid = pf.fk_facture";
$sql .= " AND f.fk_soc = s.rowid";
$sql .= " AND p.statut = 1 ";
$sql .= " ORDER BY f.rowid ASC, p.rowid ASC";
$resql = $this->db->query($sql);
if ($resql)
{
$num = $this->db->num_rows($resql);
$i = 0;
$this->linep = array();
while ($i < $num)
{ {
$obj = $this->db->fetch_object($resql); $obj = $this->db->fetch_object($resql);
$this->linec[$i][0] = $obj->datef; $this->linep[$i][0] = $obj->datep;
$this->linec[$i][1] = $obj->facid; $this->linep[$i][1] = $obj->paymentid;
$this->linec[$i][2] = $obj->code_compta; $this->linep[$i][2] = $obj->code_compta;
$this->linec[$i][3] = $obj->nom; $this->linep[$i][3] = $obj->nom;
$this->linec[$i][4] = $obj->numero; $this->linep[$i][4] = $obj->facnumber;
$this->linec[$i][5] = $obj->facnumber; $this->linep[$i][5] = $obj->amount;
$this->linec[$i][6] = $obj->tva; $this->linep[$i][6] = $obj->libelle;
$this->linec[$i][7] = $obj->total_ttc;
$this->linec[$i][8] = $obj->price;
$this->linec[$i][9] = $obj->increment;
$this->linec[$i][10] = $obj->lrowid;
if ($obj->code_compta == '') if (strlen(trim( $obj->increment)) > 0)
{ {
$societe=new Societe($this->db); $this->linep[$i][7] = $obj->increment;
$societe->fetch($obj->socid); }
$this->error_message.= $langs->transnoentities("ErrorWrongAccountancyCodeForCompany",$societe->getNomUrl(1))."<br>"; else
$error++; {
} $this->linep[$i][7] = $obj->facnumber;
}
$i++; $i++;
}
$this->db->free($resql);
}
return $error;
}
/**
\brief Lecture des paiements dans la base
\param id Id ligne
*/
function ReadLinesPayment($id=0)
{
dol_syslog("ComptaExport::ReadLinesPayment id=".$id);
$error = 0;
$sql = "SELECT p.rowid as paymentid, f.facnumber";
$sql .= " ,".$this->db->pdate("p.datep")." as datep";
$sql .= " , pf.amount";
$sql .= " , s.nom, s.code_compta";
$sql .= " , cp.libelle, f.increment";
$sql .= " FROM ".MAIN_DB_PREFIX."paiement as p";
$sql .= " , ".MAIN_DB_PREFIX."paiement_facture as pf";
$sql .= " , ".MAIN_DB_PREFIX."c_paiement as cp";
$sql .= " , ".MAIN_DB_PREFIX."facture as f";
$sql .= " , ".MAIN_DB_PREFIX."societe as s";
$sql .= " WHERE p.fk_export_compta = ".$id;
$sql .= " AND p.rowid = pf.fk_paiement";
$sql .= " AND cp.id = p.fk_paiement";
$sql .= " AND f.rowid = pf.fk_facture";
$sql .= " AND f.fk_soc = s.rowid";
$sql .= " AND p.statut = 1 ";
$sql .= " ORDER BY f.rowid ASC, p.rowid ASC";
$resql = $this->db->query($sql);
if ($resql)
{
$num = $this->db->num_rows($resql);
$i = 0;
$this->linep = array();
while ($i < $num)
{
$obj = $this->db->fetch_object($resql);
$this->linep[$i][0] = $obj->datep;
$this->linep[$i][1] = $obj->paymentid;
$this->linep[$i][2] = $obj->code_compta;
$this->linep[$i][3] = $obj->nom;
$this->linep[$i][4] = $obj->facnumber;
$this->linep[$i][5] = $obj->amount;
$this->linep[$i][6] = $obj->libelle;
if (strlen(trim( $obj->increment)) > 0)
{
$this->linep[$i][7] = $obj->increment;
}
else
{
$this->linep[$i][7] = $obj->facnumber;
}
$i++;
} }
$this->db->free($resql); $this->db->free($resql);
} }
else else
{ {
$error++; $error++;
} }
return $error; return $error;
} }
/** /**
\brief Créé le fichier d'export \brief Cr<EFBFBD><EFBFBD> le fichier d'export
*/ */
function Export($id=0, $dir) function Export($id=0, $dir)
{ {
$error = 0; $error = 0;
dol_syslog("ComptaExport::Export"); dol_syslog("ComptaExport::Export");
$error += $this->ReadLines($id); $error += $this->ReadLines($id);
$error += $this->ReadLinesPayment($id); $error += $this->ReadLinesPayment($id);
dol_syslog("ComptaExport::Export Lignes de factures : ".sizeof($this->linec)); dol_syslog("ComptaExport::Export Lignes de factures : ".sizeof($this->linec));
dol_syslog("ComptaExport::Export Lignes de paiements : ".sizeof($this->linep)); dol_syslog("ComptaExport::Export Lignes de paiements : ".sizeof($this->linep));
if (!$error && (sizeof($this->linec) > 0 || sizeof($this->linep) > 0)) if (!$error && (sizeof($this->linec) > 0 || sizeof($this->linep) > 0))
{ {
include_once DOL_DOCUMENT_ROOT.'/compta/export/modules/compta.export.'.strtolower($this->classe_export).'.class.php'; include_once DOL_DOCUMENT_ROOT.'/compta/export/modules/compta.export.'.strtolower($this->classe_export).'.class.php';
$objexport_name = "ComptaExport".$this->classe_export; $objexport_name = "ComptaExport".$this->classe_export;
$objexport = new $objexport_name($this->db, $this->user); $objexport = new $objexport_name($this->db, $this->user);
$objexport->Export($dir, $this->linec, $this->linep, $id); $objexport->Export($dir, $this->linec, $this->linep, $id);
$this->id = $objexport->id; $this->id = $objexport->id;
$this->ref = $objexport->ref; $this->ref = $objexport->ref;
} }
} }
} }

View File

@ -83,7 +83,7 @@ $form = new Form($db);
if ($socid > 0) if ($socid > 0)
{ {
$societe = new Societe($db); $societe = new Societe($db);
$societe->fetch($socid, $to); // si $to='next' ajouter " AND s.rowid > $socid ORDER BY idp ASC LIMIT 1"; $societe->fetch($socid);
if ($societe->id <= 0) if ($societe->id <= 0)
{ {
dol_print_error($db,$societe->error); dol_print_error($db,$societe->error);

View File

@ -31,7 +31,7 @@ require_once(DOL_DOCUMENT_ROOT."/facture.class.php");
$langs->load("companies"); $langs->load("companies");
if ($conf->facture->enabled) $langs->load("bills"); if ($conf->facture->enabled) $langs->load("bills");
// Sécurité accés client // Security check
$socid = $_GET["socid"]; $socid = $_GET["socid"];
if ($user->societe_id > 0) if ($user->societe_id > 0)
{ {
@ -39,10 +39,9 @@ if ($user->societe_id > 0)
$socid = $user->societe_id; $socid = $user->societe_id;
} }
/* /*
* * View
* Mode fiche
*
*/ */
llxHeader(); llxHeader();
@ -50,7 +49,7 @@ llxHeader();
if ($socid > 0) if ($socid > 0)
{ {
$societe = new Societe($db); $societe = new Societe($db);
$societe->fetch($socid, $to); // si $to='next' ajouter " AND s.rowid > $socid ORDER BY idp ASC LIMIT 1"; $societe->fetch($socid);
/* /*
* Affichage onglets * Affichage onglets
@ -171,7 +170,7 @@ if ($socid > 0)
print "<tr $bc[$var]>"; print "<tr $bc[$var]>";
print '<td align="center">'.dol_print_date($objp->dp)."</td>\n"; print '<td align="center">'.dol_print_date($objp->dp)."</td>\n";
print '<td>'; print '<td>';
print '&nbsp; &nbsp; &nbsp; '; // Décalage print '&nbsp; &nbsp; &nbsp; '; // D<EFBFBD>calage
print '<a href="paiement/fiche.php?id='.$objp->rowid.'">'.img_object($langs->trans("ShowPayment"),"payment").' '.$langs->trans("Payment").' '.$objp->rowid.'</td>'; print '<a href="paiement/fiche.php?id='.$objp->rowid.'">'.img_object($langs->trans("ShowPayment"),"payment").' '.$langs->trans("Payment").' '.$objp->rowid.'</td>';
print "<td>&nbsp;</td>\n"; print "<td>&nbsp;</td>\n";
print "<td>&nbsp;</td>\n"; print "<td>&nbsp;</td>\n";

View File

@ -86,15 +86,15 @@ if ($_GET["id"] > 0) {
print '<table class="border" width="100%">'; print '<table class="border" width="100%">';
// Ref // Ref
print '<tr><td width="18%">'.$langs->trans("Ref")."</td>"; print '<tr><td width="18%">'.$langs->trans("Ref")."</td>";
print '<td colspan="2">'.$fichinter->ref.'</td>'; print '<td colspan="2">'.$fichinter->ref.'</td>';
$nbrow=4; $nbrow=4;
print '<td rowspan="'.$nbrow.'" valign="top" width="50%">'; print '<td rowspan="'.$nbrow.'" valign="top" width="50%">';
/* /*
* Documents * Documents
*/ */
$fichinterref = dol_sanitizeFileName($fichinter->ref); $fichinterref = dol_sanitizeFileName($fichinter->ref);
$dir_output = $conf->ficheinter->dir_output . "/"; $dir_output = $conf->ficheinter->dir_output . "/";
@ -104,7 +104,7 @@ if ($_GET["id"] > 0) {
$relativepath = "${fichinterref}/${fichinterref}.pdf"; $relativepath = "${fichinterref}/${fichinterref}.pdf";
$relativepathdetail = "${fichinterref}/${fichinterref}-detail.pdf"; $relativepathdetail = "${fichinterref}/${fichinterref}-detail.pdf";
// Chemin vers png aper<65>us // Chemin vers png apercus
$relativepathimage = "${fichinterref}/${fichinterref}.pdf.png"; $relativepathimage = "${fichinterref}/${fichinterref}.pdf.png";
$fileimage = $file.".png"; // Si PDF d'1 page $fileimage = $file.".png"; // Si PDF d'1 page
$fileimagebis = $file.".png.0"; // Si PDF de plus d'1 page $fileimagebis = $file.".png.0"; // Si PDF de plus d'1 page

View File

@ -31,7 +31,7 @@ require_once(DOL_DOCUMENT_ROOT."/facture.class.php");
$langs->load("companies"); $langs->load("companies");
if ($conf->facture->enabled) $langs->load("bills"); if ($conf->facture->enabled) $langs->load("bills");
// Sécurité accés client // Security check
$socid = $_GET["socid"]; $socid = $_GET["socid"];
if ($user->societe_id > 0) if ($user->societe_id > 0)
{ {
@ -42,9 +42,7 @@ if ($user->societe_id > 0)
/* /*
* * View
* Mode fiche
*
*/ */
llxHeader(); llxHeader();
@ -52,7 +50,7 @@ llxHeader();
if ($socid > 0) if ($socid > 0)
{ {
$societe = new Societe($db); $societe = new Societe($db);
$societe->fetch($socid, $to); // si $to='next' ajouter " AND s.rowid > $socid ORDER BY idp ASC LIMIT 1"; $societe->fetch($socid);
/* /*
* Affichage onglets * Affichage onglets

View File

@ -479,11 +479,11 @@ class Societe extends CommonObject
/** /**
* \brief Load a third party from database into memory * \brief Load a third party from database into memory
* \param socid Id third party to load * \param socid Id third party to load
* \param user User object * \param ref Name of third party (Warning, this can return several records)
* \return int >0 if OK, <0 if KO * \return int >0 if OK, <0 if KO or if two records found for same ref.
*/ */
function fetch($socid, $user=0) function fetch($socid, $ref='')
{ {
global $langs; global $langs;
global $conf; global $conf;
@ -534,13 +534,21 @@ class Societe extends CommonObject
$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_forme_juridique as fj ON s.fk_forme_juridique = fj.code'; $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_forme_juridique as fj ON s.fk_forme_juridique = fj.code';
$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_departements as d ON s.fk_departement = d.rowid'; $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_departements as d ON s.fk_departement = d.rowid';
$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_typent as te ON s.fk_typent = te.id'; $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_typent as te ON s.fk_typent = te.id';
$sql .= ' WHERE s.rowid = '.$socid; if ($socid) $sql .= ' WHERE s.rowid = '.$socid;
if ($ref) $sql .= " WHERE s.nom = '".addslashes($ref)."' AND s.entity = ".$conf->entity;
$resql=$this->db->query($sql); $resql=$this->db->query($sql);
dol_syslog("Societe::fetch ".$sql); dol_syslog("Societe::fetch ".$sql);
if ($resql) if ($resql)
{ {
if ($this->db->num_rows($resql)) $num=$this->db->num_rows($resql);
if ($num > 1)
{
$this->error='Societe::Fetch several records found for ref='.$ref;
dol_syslog($this->error, LOG_ERR);
$result = -1;
}
if ($num)
{ {
$obj = $this->db->fetch_object($resql); $obj = $this->db->fetch_object($resql);
@ -624,8 +632,8 @@ class Societe extends CommonObject
} }
else else
{ {
dol_syslog('Erreur Societe::Fetch aucune societe avec id='.$this->id.' - '.$sql); $this->error='Societe::Fetch no third party found for id='.$this->id;
$this->error='Erreur Societe::Fetch aucune societe avec id='.$this->id.' - '.$sql; dol_syslog($this->error, LOG_ERR);
$result = -2; $result = -2;
} }

View File

@ -60,7 +60,6 @@ $pagenext = $page + 1;
/* /*
* Actions * Actions
*
*/ */
// Recherche // Recherche