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");
if ($conf->facture->enabled) $langs->load("bills");
// Sécurité accés client
// Security check
$socid = $_GET["socid"];
if ($user->societe_id > 0)
{
@ -42,9 +42,7 @@ if ($user->societe_id > 0)
/*
*
* Mode fiche
*
* View
*/
llxHeader();
@ -52,7 +50,7 @@ llxHeader();
if ($socid > 0)
{
$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

View File

@ -18,11 +18,11 @@
*/
/**
\file htdocs/comm/recap-client.php
\ingroup societe
\brief Page de fiche recap client
\version $Id$
*/
* \file htdocs/comm/recap-client.php
* \ingroup societe
* \brief Page de fiche recap client
* \version $Id$
*/
require("./pre.inc.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");
if ($conf->facture->enabled) $langs->load("bills");
// Sécurité accés client
// Security check
$socid = $_GET["socid"];
if ($user->societe_id > 0)
{
@ -42,9 +42,7 @@ if ($user->societe_id > 0)
/*
*
* Mode fiche
*
* View
*/
llxHeader();
@ -52,18 +50,18 @@ llxHeader();
if ($socid > 0)
{
$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
*/
$head = societe_prepare_head($societe);
dol_fiche_head($head, 'customer', $langs->trans("ThirdParty"));
print "<table width=\"100%\">\n";
print '<tr><td valign="top" width="50%">';
print '<tr><td valign="top" width="50%">';
print '<table class="border" width="100%">';
@ -74,7 +72,7 @@ if ($socid > 0)
print '<tr><td>'.$langs->trans("Prefix").'</td><td colspan="3">';
print ($societe->prefix_comm?$societe->prefix_comm:'&nbsp;');
print '</td></tr>';
print "</table>";
print "</td></tr></table>\n";

View File

@ -1,7 +1,7 @@
<?PHP
/* Copyright (C) 2004-2006 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2006 Laurent Destailleur <eldy@users.sourceforge.net>
*
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
@ -21,215 +21,215 @@
*/
/**
\file htdocs/compta/export/modules/compta.export.class.php
\ingroup compta
\brief Fichier de la classe d'export compta
\version $Revision$
*/
\file htdocs/compta/export/modules/compta.export.class.php
\ingroup compta
\brief Fichier de la classe d'export compta
\version $Revision$
*/
/**
\class ComptaExport
\brief Classe permettant les exports comptables
*/
\class ComptaExport
\brief Classe permettant les exports comptables
*/
class ComptaExport
{
/**
\brief Constructeur de la class
\param DB Object de base de données
\param USER Object utilisateur
\param classe Nom de la classe utilisée pour formater les rapports
*/
function ComptaExport ($DB, $USER, $classe)
{
$this->db = $DB;
$this->user = $USER;
$this->classe_export = $classe;
$this->error_message = '';
}
/**
\brief Lecture des factures dans la base
\param id Id ligne
*/
function ReadLines($id=0)
{
global $langs;
dol_syslog("ComptaExport::ReadLines id=".$id);
$error = 0;
$sql = "SELECT f.rowid as facid, f.facnumber, ".$this->db->pdate("f.datef")." as datef";
$sql .= " , f.total_ttc, f.tva ";
$sql .= " ,s.nom, s.rowid as socid, s.code_compta";
$sql .= " , l.price, l.tva_taux";
$sql .= " , c.numero, f.increment";
$sql .= " , l.rowid as lrowid";
$sql .= " FROM ".MAIN_DB_PREFIX."facturedet as l";
$sql .= " , ".MAIN_DB_PREFIX."facture as f";
$sql .= " , ".MAIN_DB_PREFIX."societe as s";
$sql .= " , ".MAIN_DB_PREFIX."compta_compte_generaux as c";
$sql .= " WHERE f.rowid = l.fk_facture ";
$sql .= " AND s.rowid = f.fk_soc";
$sql .= " AND f.fk_statut = 1 ";
$sql .= " AND l.fk_code_ventilation <> 0 ";
$sql .= " AND l.fk_export_compta = ".$id;
$sql .= " AND c.rowid = l.fk_code_ventilation";
$sql .= " ORDER BY f.rowid ASC, l.fk_code_ventilation ASC";
$resql = $this->db->query($sql);
if ($resql)
{
$num = $this->db->num_rows($resql);
$i = 0;
$this->linec = array();
while ($i < $num)
/**
\brief Constructeur de la class
\param DB Object de base de donn<EFBFBD>es
\param USER Object utilisateur
\param classe Nom de la classe utilis<EFBFBD>e pour formater les rapports
*/
function ComptaExport ($DB, $USER, $classe)
{
$this->db = $DB;
$this->user = $USER;
$this->classe_export = $classe;
$this->error_message = '';
}
/**
\brief Lecture des factures dans la base
\param id Id ligne
*/
function ReadLines($id=0)
{
global $langs;
dol_syslog("ComptaExport::ReadLines id=".$id);
$error = 0;
$sql = "SELECT f.rowid as facid, f.facnumber, ".$this->db->pdate("f.datef")." as datef";
$sql .= " , f.total_ttc, f.tva ";
$sql .= " ,s.nom, s.rowid as socid, s.code_compta";
$sql .= " , l.price, l.tva_taux";
$sql .= " , c.numero, f.increment";
$sql .= " , l.rowid as lrowid";
$sql .= " FROM ".MAIN_DB_PREFIX."facturedet as l";
$sql .= " , ".MAIN_DB_PREFIX."facture as f";
$sql .= " , ".MAIN_DB_PREFIX."societe as s";
$sql .= " , ".MAIN_DB_PREFIX."compta_compte_generaux as c";
$sql .= " WHERE f.rowid = l.fk_facture ";
$sql .= " AND s.rowid = f.fk_soc";
$sql .= " AND f.fk_statut = 1 ";
$sql .= " AND l.fk_code_ventilation <> 0 ";
$sql .= " AND l.fk_export_compta = ".$id;
$sql .= " AND c.rowid = l.fk_code_ventilation";
$sql .= " ORDER BY f.rowid ASC, l.fk_code_ventilation ASC";
$resql = $this->db->query($sql);
if ($resql)
{
$num = $this->db->num_rows($resql);
$i = 0;
$this->linec = array();
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);
$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";
$obj = $this->db->fetch_object($resql);
$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 ";
$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;
$sql .= " ORDER BY f.rowid ASC, p.rowid ASC";
if (strlen(trim( $obj->increment)) > 0)
{
$this->linep[$i][7] = $obj->increment;
}
else
{
$this->linep[$i][7] = $obj->facnumber;
}
$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++;
$i++;
}
$this->db->free($resql);
$this->db->free($resql);
}
else
{
$error++;
}
return $error;
}
}
else
{
$error++;
}
/**
\brief Créé le fichier d'export
*/
return $error;
}
function Export($id=0, $dir)
{
$error = 0;
/**
\brief Cr<EFBFBD><EFBFBD> le fichier d'export
*/
dol_syslog("ComptaExport::Export");
function Export($id=0, $dir)
{
$error = 0;
$error += $this->ReadLines($id);
$error += $this->ReadLinesPayment($id);
dol_syslog("ComptaExport::Export");
dol_syslog("ComptaExport::Export Lignes de factures : ".sizeof($this->linec));
dol_syslog("ComptaExport::Export Lignes de paiements : ".sizeof($this->linep));
$error += $this->ReadLines($id);
$error += $this->ReadLinesPayment($id);
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';
dol_syslog("ComptaExport::Export Lignes de factures : ".sizeof($this->linec));
dol_syslog("ComptaExport::Export Lignes de paiements : ".sizeof($this->linep));
$objexport_name = "ComptaExport".$this->classe_export;
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';
$objexport = new $objexport_name($this->db, $this->user);
$objexport_name = "ComptaExport".$this->classe_export;
$objexport->Export($dir, $this->linec, $this->linep, $id);
$objexport = new $objexport_name($this->db, $this->user);
$this->id = $objexport->id;
$this->ref = $objexport->ref;
}
}
$objexport->Export($dir, $this->linec, $this->linep, $id);
$this->id = $objexport->id;
$this->ref = $objexport->ref;
}
}
}

View File

@ -83,7 +83,7 @@ $form = new Form($db);
if ($socid > 0)
{
$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)
{
dol_print_error($db,$societe->error);

View File

@ -31,7 +31,7 @@ require_once(DOL_DOCUMENT_ROOT."/facture.class.php");
$langs->load("companies");
if ($conf->facture->enabled) $langs->load("bills");
// Sécurité accés client
// Security check
$socid = $_GET["socid"];
if ($user->societe_id > 0)
{
@ -39,10 +39,9 @@ if ($user->societe_id > 0)
$socid = $user->societe_id;
}
/*
*
* Mode fiche
*
* View
*/
llxHeader();
@ -50,7 +49,7 @@ llxHeader();
if ($socid > 0)
{
$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
@ -171,7 +170,7 @@ if ($socid > 0)
print "<tr $bc[$var]>";
print '<td align="center">'.dol_print_date($objp->dp)."</td>\n";
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 "<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%">';
// Ref
print '<tr><td width="18%">'.$langs->trans("Ref")."</td>";
print '<td colspan="2">'.$fichinter->ref.'</td>';
// Ref
print '<tr><td width="18%">'.$langs->trans("Ref")."</td>";
print '<td colspan="2">'.$fichinter->ref.'</td>';
$nbrow=4;
$nbrow=4;
print '<td rowspan="'.$nbrow.'" valign="top" width="50%">';
/*
* Documents
* Documents
*/
$fichinterref = dol_sanitizeFileName($fichinter->ref);
$dir_output = $conf->ficheinter->dir_output . "/";
@ -104,7 +104,7 @@ if ($_GET["id"] > 0) {
$relativepath = "${fichinterref}/${fichinterref}.pdf";
$relativepathdetail = "${fichinterref}/${fichinterref}-detail.pdf";
// Chemin vers png aper<65>us
// Chemin vers png apercus
$relativepathimage = "${fichinterref}/${fichinterref}.pdf.png";
$fileimage = $file.".png"; // Si PDF 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");
if ($conf->facture->enabled) $langs->load("bills");
// Sécurité accés client
// Security check
$socid = $_GET["socid"];
if ($user->societe_id > 0)
{
@ -42,9 +42,7 @@ if ($user->societe_id > 0)
/*
*
* Mode fiche
*
* View
*/
llxHeader();
@ -52,7 +50,7 @@ llxHeader();
if ($socid > 0)
{
$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

View File

@ -479,11 +479,11 @@ class Societe extends CommonObject
/**
* \brief Load a third party from database into memory
* \param socid Id third party to load
* \param user User object
* \return int >0 if OK, <0 if KO
* \param socid Id third party to load
* \param ref Name of third party (Warning, this can return several records)
* \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 $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_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 .= ' 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);
dol_syslog("Societe::fetch ".$sql);
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);
@ -624,8 +632,8 @@ class Societe extends CommonObject
}
else
{
dol_syslog('Erreur Societe::Fetch aucune societe avec id='.$this->id.' - '.$sql);
$this->error='Erreur Societe::Fetch aucune societe avec id='.$this->id.' - '.$sql;
$this->error='Societe::Fetch no third party found for id='.$this->id;
dol_syslog($this->error, LOG_ERR);
$result = -2;
}

View File

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