Fix: pgql compatibility

This commit is contained in:
Laurent Destailleur 2011-07-04 10:30:00 +00:00
parent 573354f5d9
commit df8da8678b
13 changed files with 64 additions and 62 deletions

View File

@ -22,7 +22,7 @@
* \file htdocs/adherents/class/adherentstats.class.php * \file htdocs/adherents/class/adherentstats.class.php
* \ingroup member * \ingroup member
* \brief Fichier de la classe de gestion des stats des adhérents * \brief Fichier de la classe de gestion des stats des adhérents
* \version $Id$ * \version $Id: adherentstats.class.php,v 1.2 2011/07/04 10:30:01 eldy Exp $
*/ */
include_once DOL_DOCUMENT_ROOT . "/core/class/stats.class.php"; include_once DOL_DOCUMENT_ROOT . "/core/class/stats.class.php";
@ -90,7 +90,7 @@ class AdherentStats extends Stats
$sql = "SELECT date_format(p.dateadh,'%m') as dm, count(*)"; $sql = "SELECT date_format(p.dateadh,'%m') as dm, count(*)";
$sql.= " FROM ".$this->from; $sql.= " FROM ".$this->from;
//if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; //if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
$sql.= " WHERE date_format(p.dateadh,'%Y') = ".$year; $sql.= " WHERE date_format(p.dateadh,'%Y') = '".$year."'";
$sql.= " AND ".$this->where; $sql.= " AND ".$this->where;
$sql.= " GROUP BY dm"; $sql.= " GROUP BY dm";
$sql.= $this->db->order('dm','DESC'); $sql.= $this->db->order('dm','DESC');
@ -126,7 +126,7 @@ class AdherentStats extends Stats
$sql = "SELECT date_format(p.dateadh,'%m') as dm, sum(p.".$this->field.")"; $sql = "SELECT date_format(p.dateadh,'%m') as dm, sum(p.".$this->field.")";
$sql.= " FROM ".$this->from; $sql.= " FROM ".$this->from;
//if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; //if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
$sql.= " WHERE date_format(p.dateadh,'%Y') = ".$year; $sql.= " WHERE date_format(p.dateadh,'%Y') = '".$year."'";
$sql.= " AND ".$this->where; $sql.= " AND ".$this->where;
$sql.= " GROUP BY dm"; $sql.= " GROUP BY dm";
$sql.= $this->db->order('dm','DESC'); $sql.= $this->db->order('dm','DESC');
@ -144,7 +144,7 @@ class AdherentStats extends Stats
$sql = "SELECT date_format(p.dateadh,'%m') as dm, avg(p.".$this->field.")"; $sql = "SELECT date_format(p.dateadh,'%m') as dm, avg(p.".$this->field.")";
$sql.= " FROM ".$this->from; $sql.= " FROM ".$this->from;
//if (!$user->rights->societe->client->voir && !$this->socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; //if (!$user->rights->societe->client->voir && !$this->socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
$sql.= " WHERE date_format(p.dateadh,'%Y') = ".$year; $sql.= " WHERE date_format(p.dateadh,'%Y') = '".$year."'";
$sql.= " AND ".$this->where; $sql.= " AND ".$this->where;
$sql.= " GROUP BY dm"; $sql.= " GROUP BY dm";
$sql.= $this->db->order('dm','DESC'); $sql.= $this->db->order('dm','DESC');

View File

@ -27,7 +27,7 @@
* \file htdocs/comm/propal.php * \file htdocs/comm/propal.php
* \ingroup propale * \ingroup propale
* \brief Page of commercial proposals card and list * \brief Page of commercial proposals card and list
* \version $Id: propal.php,v 1.607 2011/07/02 16:48:32 eldy Exp $ * \version $Id: propal.php,v 1.608 2011/07/04 10:30:02 eldy Exp $
*/ */
require("../main.inc.php"); require("../main.inc.php");
@ -1805,13 +1805,13 @@ else
if ($month > 0) if ($month > 0)
{ {
if ($year > 0) if ($year > 0)
$sql.= " AND date_format(p.datep, '%Y-%m') = '$year-$month'"; $sql.= " AND date_format(p.datep, '%Y-%m') = '".$year."-".$month."'";
else else
$sql.= " AND date_format(p.datep, '%m') = '$month'"; $sql.= " AND date_format(p.datep, '%m') = '".$month."'";
} }
if ($year > 0) if ($year > 0)
{ {
$sql.= " AND date_format(p.datep, '%Y') = $year"; $sql.= " AND date_format(p.datep, '%Y') = '".$year."'";
} }
if (dol_strlen($_POST['sf_ref']) > 0) if (dol_strlen($_POST['sf_ref']) > 0)
{ {
@ -1975,6 +1975,6 @@ else
} }
$db->close(); $db->close();
llxFooter('$Date: 2011/07/02 16:48:32 $ - $Revision: 1.607 $'); llxFooter('$Date: 2011/07/04 10:30:02 $ - $Revision: 1.608 $');
?> ?>

View File

@ -22,7 +22,7 @@
* \file htdocs/comm/propal/class/propalestats.class.php * \file htdocs/comm/propal/class/propalestats.class.php
* \ingroup propales * \ingroup propales
* \brief Fichier de la classe de gestion des stats des propales * \brief Fichier de la classe de gestion des stats des propales
* \version $Id$ * \version $Id: propalestats.class.php,v 1.5 2011/07/04 10:30:03 eldy Exp $
*/ */
include_once DOL_DOCUMENT_ROOT . "/core/class/stats.class.php"; include_once DOL_DOCUMENT_ROOT . "/core/class/stats.class.php";
@ -91,7 +91,7 @@ class PropaleStats extends Stats
$sql = "SELECT date_format(p.datep,'%m') as dm, count(*)"; $sql = "SELECT date_format(p.datep,'%m') as dm, count(*)";
$sql.= " FROM ".$this->from; $sql.= " FROM ".$this->from;
if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
$sql.= " WHERE date_format(p.datep,'%Y') = ".$year; $sql.= " WHERE date_format(p.datep,'%Y') = '".$year."'";
$sql.= " AND ".$this->where; $sql.= " AND ".$this->where;
$sql.= " GROUP BY dm"; $sql.= " GROUP BY dm";
$sql.= $this->db->order('dm','DESC'); $sql.= $this->db->order('dm','DESC');
@ -127,7 +127,7 @@ class PropaleStats extends Stats
$sql = "SELECT date_format(p.datep,'%m') as dm, sum(p.".$this->field.")"; $sql = "SELECT date_format(p.datep,'%m') as dm, sum(p.".$this->field.")";
$sql.= " FROM ".$this->from; $sql.= " FROM ".$this->from;
if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
$sql.= " WHERE date_format(p.datep,'%Y') = ".$year; $sql.= " WHERE date_format(p.datep,'%Y') = '".$year."'";
$sql.= " AND ".$this->where; $sql.= " AND ".$this->where;
$sql.= " GROUP BY dm"; $sql.= " GROUP BY dm";
$sql.= $this->db->order('dm','DESC'); $sql.= $this->db->order('dm','DESC');
@ -145,7 +145,7 @@ class PropaleStats extends Stats
$sql = "SELECT date_format(p.datep,'%m') as dm, avg(p.".$this->field.")"; $sql = "SELECT date_format(p.datep,'%m') as dm, avg(p.".$this->field.")";
$sql.= " FROM ".$this->from; $sql.= " FROM ".$this->from;
if (!$user->rights->societe->client->voir && !$this->socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; if (!$user->rights->societe->client->voir && !$this->socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
$sql.= " WHERE date_format(p.datep,'%Y') = ".$year; $sql.= " WHERE date_format(p.datep,'%Y') = '".$year."'";
$sql.= " AND ".$this->where; $sql.= " AND ".$this->where;
$sql.= " GROUP BY dm"; $sql.= " GROUP BY dm";
$sql.= $this->db->order('dm','DESC'); $sql.= $this->db->order('dm','DESC');

View File

@ -22,7 +22,7 @@
* \file htdocs/commande/class/commandestats.class.php * \file htdocs/commande/class/commandestats.class.php
* \ingroup commandes * \ingroup commandes
* \brief Fichier de la classe de gestion des stats des commandes * \brief Fichier de la classe de gestion des stats des commandes
* \version $Id$ * \version $Id: commandestats.class.php,v 1.5 2011/07/04 10:30:01 eldy Exp $
*/ */
include_once DOL_DOCUMENT_ROOT . "/core/class/stats.class.php"; include_once DOL_DOCUMENT_ROOT . "/core/class/stats.class.php";
include_once DOL_DOCUMENT_ROOT . "/commande/class/commande.class.php"; include_once DOL_DOCUMENT_ROOT . "/commande/class/commande.class.php";
@ -102,7 +102,7 @@ class CommandeStats extends Stats
$sql = "SELECT date_format(c.date_valid,'%m') as dm, count(*) nb"; $sql = "SELECT date_format(c.date_valid,'%m') as dm, count(*) nb";
$sql.= " FROM ".$this->from; $sql.= " FROM ".$this->from;
if (!$user->rights->societe->client->voir && !$this->socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; if (!$user->rights->societe->client->voir && !$this->socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
$sql.= " WHERE date_format(c.date_valid,'%Y') = ".$year; $sql.= " WHERE date_format(c.date_valid,'%Y') = '".$year."'";
$sql.= " AND ".$this->where; $sql.= " AND ".$this->where;
$sql.= " GROUP BY dm"; $sql.= " GROUP BY dm";
$sql.= $this->db->order('dm','DESC'); $sql.= $this->db->order('dm','DESC');
@ -141,7 +141,7 @@ class CommandeStats extends Stats
$sql = "SELECT date_format(c.date_valid,'%m') as dm, sum(c.".$this->field.")"; $sql = "SELECT date_format(c.date_valid,'%m') as dm, sum(c.".$this->field.")";
$sql.= " FROM ".$this->from; $sql.= " FROM ".$this->from;
if (!$user->rights->societe->client->voir && !$this->socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; if (!$user->rights->societe->client->voir && !$this->socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
$sql.= " WHERE date_format(c.date_valid,'%Y') = ".$year; $sql.= " WHERE date_format(c.date_valid,'%Y') = '".$year."'";
$sql.= " AND ".$this->where; $sql.= " AND ".$this->where;
$sql.= " GROUP BY dm"; $sql.= " GROUP BY dm";
$sql.= $this->db->order('dm','DESC'); $sql.= $this->db->order('dm','DESC');
@ -161,7 +161,7 @@ class CommandeStats extends Stats
$sql = "SELECT date_format(c.date_valid,'%m') as dm, avg(c.".$this->field.")"; $sql = "SELECT date_format(c.date_valid,'%m') as dm, avg(c.".$this->field.")";
$sql.= " FROM ".$this->from; $sql.= " FROM ".$this->from;
if (!$user->rights->societe->client->voir && !$this->socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; if (!$user->rights->societe->client->voir && !$this->socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
$sql.= " WHERE date_format(c.date_valid,'%Y') = ".$year; $sql.= " WHERE date_format(c.date_valid,'%Y') = '".$year."'";
$sql.= " AND ".$this->where; $sql.= " AND ".$this->where;
$sql.= " GROUP BY dm"; $sql.= " GROUP BY dm";
$sql.= $this->db->order('dm','DESC'); $sql.= $this->db->order('dm','DESC');

View File

@ -23,7 +23,7 @@
* \file htdocs/commande/liste.php * \file htdocs/commande/liste.php
* \ingroup commande * \ingroup commande
* \brief Page to list orders * \brief Page to list orders
* \version $Id$ * \version $Id: liste.php,v 1.77 2011/07/04 10:30:02 eldy Exp $
*/ */
@ -115,19 +115,19 @@ if ($viewstatut <> '')
} }
if ($_GET['ordermonth'] > 0) if ($_GET['ordermonth'] > 0)
{ {
$sql.= " AND date_format(c.date_valid, '%Y-%m') = '$orderyear-$ordermonth'"; $sql.= " AND date_format(c.date_valid, '%Y-%m') = '".$orderyear."-".$ordermonth."'";
} }
if ($_GET['orderyear'] > 0) if ($_GET['orderyear'] > 0)
{ {
$sql.= " AND date_format(c.date_valid, '%Y') = $orderyear"; $sql.= " AND date_format(c.date_valid, '%Y') = '".$orderyear."'";
} }
if ($_GET['deliverymonth'] > 0) if ($_GET['deliverymonth'] > 0)
{ {
$sql.= " AND date_format(c.date_livraison, '%Y-%m') = '$deliveryyear-$deliverymonth'"; $sql.= " AND date_format(c.date_livraison, '%Y-%m') = '".$deliveryyear."-".$deliverymonth."'";
} }
if ($_GET['deliveryyear'] > 0) if ($_GET['deliveryyear'] > 0)
{ {
$sql.= " AND date_format(c.date_livraison, '%Y') = $deliveryyear"; $sql.= " AND date_format(c.date_livraison, '%Y') = '".$deliveryyear."'";
} }
if (!empty($snom)) if (!empty($snom))
{ {
@ -278,5 +278,5 @@ else
$db->close(); $db->close();
llxFooter('$Date$ - $Revision$'); llxFooter('$Date: 2011/07/04 10:30:02 $ - $Revision: 1.77 $');
?> ?>

View File

@ -22,7 +22,7 @@
* \file htdocs/compta/deplacement/class/deplacementstats.class.php * \file htdocs/compta/deplacement/class/deplacementstats.class.php
* \ingroup factures * \ingroup factures
* \brief Fichier de la classe de gestion des stats des deplacement et notes de frais * \brief Fichier de la classe de gestion des stats des deplacement et notes de frais
* \version $Id$ * \version $Id: deplacementstats.class.php,v 1.5 2011/07/04 10:30:02 eldy Exp $
*/ */
include_once DOL_DOCUMENT_ROOT . "/core/class/stats.class.php"; include_once DOL_DOCUMENT_ROOT . "/core/class/stats.class.php";
include_once DOL_DOCUMENT_ROOT . "/compta/deplacement/class/deplacement.class.php"; include_once DOL_DOCUMENT_ROOT . "/compta/deplacement/class/deplacement.class.php";
@ -117,7 +117,7 @@ class DeplacementStats extends Stats
{ {
$sql = "SELECT date_format(dated,'%m') as dm, sum(".$this->field.")"; $sql = "SELECT date_format(dated,'%m') as dm, sum(".$this->field.")";
$sql.= " FROM ".$this->from; $sql.= " FROM ".$this->from;
$sql.= " WHERE date_format(dated,'%Y') = ".$year; $sql.= " WHERE date_format(dated,'%Y') = '".$year."'";
$sql.= " AND ".$this->where; $sql.= " AND ".$this->where;
$sql.= " GROUP BY dm"; $sql.= " GROUP BY dm";
$sql.= $this->db->order('dm','DESC'); $sql.= $this->db->order('dm','DESC');
@ -136,7 +136,7 @@ class DeplacementStats extends Stats
{ {
$sql = "SELECT date_format(dated,'%m') as dm, avg(".$this->field.")"; $sql = "SELECT date_format(dated,'%m') as dm, avg(".$this->field.")";
$sql.= " FROM ".$this->from; $sql.= " FROM ".$this->from;
$sql.= " WHERE date_format(dated,'%Y') = ".$year; $sql.= " WHERE date_format(dated,'%Y') = '".$year."'";
$sql.= " AND ".$this->where; $sql.= " AND ".$this->where;
$sql.= " GROUP BY dm"; $sql.= " GROUP BY dm";
$sql.= $this->db->order('dm','DESC'); $sql.= $this->db->order('dm','DESC');

View File

@ -22,7 +22,7 @@
* \file htdocs/compta/facture/class/facturestats.class.php * \file htdocs/compta/facture/class/facturestats.class.php
* \ingroup factures * \ingroup factures
* \brief Fichier de la classe de gestion des stats des factures * \brief Fichier de la classe de gestion des stats des factures
* \version $Id$ * \version $Id: facturestats.class.php,v 1.6 2011/07/04 10:30:01 eldy Exp $
*/ */
include_once DOL_DOCUMENT_ROOT . "/core/class/stats.class.php"; include_once DOL_DOCUMENT_ROOT . "/core/class/stats.class.php";
include_once DOL_DOCUMENT_ROOT . "/compta/facture/class/facture.class.php"; include_once DOL_DOCUMENT_ROOT . "/compta/facture/class/facture.class.php";
@ -78,7 +78,7 @@ class FactureStats extends Stats
$this->where = " fk_statut > 0"; $this->where = " fk_statut > 0";
$this->where.= " AND entity = ".$conf->entity; $this->where.= " AND entity = ".$conf->entity;
if ($mode == 'customer') $this->where.=" AND (fk_statut != 3 OR close_code != 'replaced')"; // Exclude replaced invoices as they are duplicated (we count closed invoices for other reasons) if ($mode == 'customer') $this->where.=" AND (fk_statut <> 3 OR close_code <> 'replaced')"; // Exclude replaced invoices as they are duplicated (we count closed invoices for other reasons)
if ($this->socid) if ($this->socid)
{ {
$this->where.=" AND fk_soc = ".$this->socid; $this->where.=" AND fk_soc = ".$this->socid;
@ -132,7 +132,7 @@ class FactureStats extends Stats
{ {
$sql = "SELECT date_format(datef,'%m') as dm, SUM(".$this->field.")"; $sql = "SELECT date_format(datef,'%m') as dm, SUM(".$this->field.")";
$sql.= " FROM ".$this->from; $sql.= " FROM ".$this->from;
$sql.= " WHERE date_format(datef,'%Y') = ".$year; $sql.= " WHERE date_format(datef,'%Y') = '".$year."'";
$sql.= " AND ".$this->where; $sql.= " AND ".$this->where;
$sql.= " GROUP BY dm"; $sql.= " GROUP BY dm";
$sql.= $this->db->order('dm','DESC'); $sql.= $this->db->order('dm','DESC');

View File

@ -25,7 +25,7 @@
* \file htdocs/compta/propal.php * \file htdocs/compta/propal.php
* \ingroup propale * \ingroup propale
* \brief Page liste des propales (vision compta) * \brief Page liste des propales (vision compta)
* \version $Id$ * \version $Id: propal.php,v 1.193 2011/07/04 10:30:00 eldy Exp $
*/ */
require('../main.inc.php'); require('../main.inc.php');
@ -561,11 +561,11 @@ else
if ($month > 0) if ($month > 0)
{ {
if ($year > 0) if ($year > 0)
$sql.= " AND date_format(p.datep, '%Y-%m') = '$year-$month'"; $sql.= " AND date_format(p.datep, '%Y-%m') = '".$year."-".$month."'";
else else
$sql.= " AND date_format(p.datep, '%m') = '$month'"; $sql.= " AND date_format(p.datep, '%m') = '".$month."'";
} }
if ($year > 0) $sql .= " AND date_format(p.datep, '%Y') = $year"; if ($year > 0) $sql .= " AND date_format(p.datep, '%Y') = '".$year."'";
if (!empty($_GET['search_ref'])) if (!empty($_GET['search_ref']))
{ {
$sql.= " AND p.ref LIKE '%".$db->escape($_GET['search_ref'])."%'"; $sql.= " AND p.ref LIKE '%".$db->escape($_GET['search_ref'])."%'";
@ -702,6 +702,6 @@ else
$db->close(); $db->close();
llxFooter('$Date$ - $Revision$'); llxFooter('$Date: 2011/07/04 10:30:00 $ - $Revision: 1.193 $');
?> ?>

View File

@ -22,7 +22,7 @@
* \file htdocs/compta/sociales/index.php * \file htdocs/compta/sociales/index.php
* \ingroup tax * \ingroup tax
* \brief Page to list all social contributions * \brief Page to list all social contributions
* \version $Id$ * \version $Id: index.php,v 1.65 2011/07/04 10:30:01 eldy Exp $
*/ */
require('../../main.inc.php'); require('../../main.inc.php');
@ -86,8 +86,8 @@ if ($year > 0)
$sql .= " AND ("; $sql .= " AND (";
// Si period renseignee on l'utilise comme critere de date, sinon on prend date echeance, // Si period renseignee on l'utilise comme critere de date, sinon on prend date echeance,
// ceci afin d'etre compatible avec les cas ou la periode n'etait pas obligatoire // ceci afin d'etre compatible avec les cas ou la periode n'etait pas obligatoire
$sql .= " (s.periode is not null and date_format(s.periode, '%Y') = ".$year.") "; $sql .= " (s.periode is not null and date_format(s.periode, '%Y') = '".$year."') ";
$sql .= "or (s.periode is null and date_format(s.date_ech, '%Y') = ".$year.")"; $sql .= "or (s.periode is null and date_format(s.date_ech, '%Y') = '".$year."')";
$sql .= ")"; $sql .= ")";
} }
if ($filtre) { if ($filtre) {
@ -229,5 +229,5 @@ else
$db->close(); $db->close();
llxFooter('$Date$ - $Revision$'); llxFooter('$Date: 2011/07/04 10:30:01 $ - $Revision: 1.65 $');
?> ?>

View File

@ -21,7 +21,7 @@
/** /**
* \file htdocs/compta/stats/comp.php * \file htdocs/compta/stats/comp.php
* \ingroup commercial * \ingroup commercial
* \version $Id: comp.php,v 1.43 2011/06/29 11:22:36 eldy Exp $ * \version $Id: comp.php,v 1.44 2011/07/04 10:30:01 eldy Exp $
* TODO Remove or add page in menus * TODO Remove or add page in menus
*/ */
@ -47,8 +47,9 @@ function propals ($db, $year, $month)
$sql.= " WHERE p.fk_soc = s.rowid AND p.fk_statut = c.id"; $sql.= " WHERE p.fk_soc = s.rowid AND p.fk_statut = c.id";
$sql.= " AND p.entity = ".$conf->entity; $sql.= " AND p.entity = ".$conf->entity;
$sql.= " AND p.fk_statut in (1,2,4)"; $sql.= " AND p.fk_statut in (1,2,4)";
$sql.= " AND date_format(p.datep, '%Y') = ".$year; // TODO Use between instead of date_format
$sql.= " AND round(date_format(p.datep, '%m')) = ".$month; $sql.= " AND date_format(p.datep, '%Y') = '".$year."'";
$sql.= " AND round(date_format(p.datep, '%m')) = '".$month."'";
$sql.= " ORDER BY p.fk_statut"; $sql.= " ORDER BY p.fk_statut";
$result = $db->query($sql); $result = $db->query($sql);
@ -121,7 +122,7 @@ function factures ($db, $year, $month, $paye)
$sql.= " AND f.entity = ".$conf->entity; $sql.= " AND f.entity = ".$conf->entity;
if ($conf->compta->mode != 'CREANCES-DETTES') $sql.= " AND f.paye = ".$paye; if ($conf->compta->mode != 'CREANCES-DETTES') $sql.= " AND f.paye = ".$paye;
$sql.= " AND f.fk_soc = s.rowid"; $sql.= " AND f.fk_soc = s.rowid";
$sql.= " AND date_format(f.datef, '%Y') = ".$year; $sql.= " AND date_format(f.datef, '%Y') = '".$year."'";
$sql.= " AND round(date_format(f.datef, '%m')) = ".$month; $sql.= " AND round(date_format(f.datef, '%m')) = ".$month;
$sql.= " ORDER BY f.datef DESC "; $sql.= " ORDER BY f.datef DESC ";
@ -271,7 +272,7 @@ function ppt ($db, $year, $socid)
$sql.= " FROM ".MAIN_DB_PREFIX."propal as p"; $sql.= " FROM ".MAIN_DB_PREFIX."propal as p";
$sql.= " WHERE p.fk_statut in (1,2,4)"; $sql.= " WHERE p.fk_statut in (1,2,4)";
$sql.= " AND p.entity = ".$conf->entity; $sql.= " AND p.entity = ".$conf->entity;
$sql.= " AND date_format(p.datep,'%Y') = ".$year; $sql.= " AND date_format(p.datep,'%Y') = '".$year."'";
if ($socid) $sql.= " AND p.fk_soc = ".$socid; if ($socid) $sql.= " AND p.fk_soc = ".$socid;
$sql.= " GROUP BY dm"; $sql.= " GROUP BY dm";
@ -284,7 +285,7 @@ function ppt ($db, $year, $socid)
$sql.= " WHERE f.fk_statut in (1,2)"; $sql.= " WHERE f.fk_statut in (1,2)";
$sql.= " AND f.entity = ".$conf->entity; $sql.= " AND f.entity = ".$conf->entity;
if ($conf->compta->mode != 'CREANCES-DETTES') $sql.= " AND f.paye = 1"; if ($conf->compta->mode != 'CREANCES-DETTES') $sql.= " AND f.paye = 1";
$sql.= " AND date_format(f.datef,'%Y') = ".$year; $sql.= " AND date_format(f.datef,'%Y') = '".$year."'";
if ($socid) $sql.= " AND f.fk_soc = ".$socid; if ($socid) $sql.= " AND f.fk_soc = ".$socid;
$sql.= " GROUP BY dm"; $sql.= " GROUP BY dm";
@ -350,5 +351,5 @@ if ($details == 1)
$db->close(); $db->close();
llxFooter('$Date: 2011/06/29 11:22:36 $ - $Revision: 1.43 $'); llxFooter('$Date: 2011/07/04 10:30:01 $ - $Revision: 1.44 $');
?> ?>

View File

@ -24,7 +24,7 @@
\file htdocs/compta/tva/quadri.php \file htdocs/compta/tva/quadri.php
\ingroup tax \ingroup tax
\brief Trimestrial page \brief Trimestrial page
\version $Id: quadri.php,v 1.14 2011/07/04 09:01:38 eldy Exp $ \version $Id: quadri.php,v 1.15 2011/07/04 10:30:00 eldy Exp $
\todo Deal with recurrent invoices as well \todo Deal with recurrent invoices as well
*/ */
@ -70,9 +70,9 @@ function tva_coll($db,$y,$q)
$sql.= " AND s.entity = ".$conf->entity; $sql.= " AND s.entity = ".$conf->entity;
$sql.= " AND f.fk_statut in (1,2)"; $sql.= " AND f.fk_statut in (1,2)";
$sql.= " AND f.rowid = d.fk_facture "; $sql.= " AND f.rowid = d.fk_facture ";
$sql.= " AND date_format(f.datef,'%Y') = ".$y; $sql.= " AND date_format(f.datef,'%Y') = '".$y."'";
$sql.= " AND (date_format(f.datef,'%m') > ".(($q-1)*3); $sql.= " AND (round(date_format(f.datef,'%m') > ".(($q-1)*3);
$sql.= " AND date_format(f.datef,'%m') <= ".($q*3).")"; $sql.= " AND round(date_format(f.datef,'%m')) <= ".($q*3).")";
$sql.= " ORDER BY rate, facid"; $sql.= " ORDER BY rate, facid";
} }
@ -136,9 +136,9 @@ function tva_paye($db, $y,$q)
$sql.= " AND s.entity = ".$conf->entity; $sql.= " AND s.entity = ".$conf->entity;
$sql.= " AND f.fk_statut = 1 "; $sql.= " AND f.fk_statut = 1 ";
$sql.= " AND f.rowid = d.fk_facture_fourn "; $sql.= " AND f.rowid = d.fk_facture_fourn ";
$sql.= " AND date_format(f.datef,'%Y') = ".$y; $sql.= " AND date_format(f.datef,'%Y') = '".$y."'";
$sql.= " AND (date_format(f.datef,'%m') > ".(($q-1)*3); $sql.= " AND (round(date_format(f.datef,'%m')) > ".(($q-1)*3);
$sql.= " AND date_format(f.datef,'%m') <= ".($q*3).")"; $sql.= " AND round(date_format(f.datef,'%m')) <= ".($q*3).")";
$sql.= " ORDER BY rate, facid "; $sql.= " ORDER BY rate, facid ";
} }
else else
@ -315,5 +315,5 @@ echo '</table>';
$db->close(); $db->close();
llxFooter('$Date: 2011/07/04 09:01:38 $ - $Revision: 1.14 $'); llxFooter('$Date: 2011/07/04 10:30:00 $ - $Revision: 1.15 $');
?> ?>

View File

@ -21,7 +21,7 @@
* \file htdocs/expedition/class/expeditionstats.class.php * \file htdocs/expedition/class/expeditionstats.class.php
* \ingroup expedition * \ingroup expedition
* \brief Fichier des classes expedition * \brief Fichier des classes expedition
* \version $Id$ * \version $Id: expeditionstats.class.php,v 1.4 2011/07/04 10:30:01 eldy Exp $
*/ */
/** /**
@ -78,7 +78,7 @@ class ExpeditionStats
$result = array(); $result = array();
$sql = "SELECT count(*), date_format(date_expedition,'%m') as dm"; $sql = "SELECT count(*), date_format(date_expedition,'%m') as dm";
$sql.= " FROM ".MAIN_DB_PREFIX."expedition"; $sql.= " FROM ".MAIN_DB_PREFIX."expedition";
$sql.= " WHERE date_format(date_expedition,'%Y') = ".$year; $sql.= " WHERE date_format(date_expedition,'%Y') = '".$year."'";
$sql.= " AND fk_statut > 0"; $sql.= " AND fk_statut > 0";
$sql.= " AND entity = ".$conf->entity; $sql.= " AND entity = ".$conf->entity;
$sql.= " GROUP BY dm DESC"; $sql.= " GROUP BY dm DESC";

View File

@ -20,21 +20,23 @@
/** /**
* \file htdocs/lib/accountancy.lib.php * \file htdocs/lib/accountancy.lib.php
* \brief Library of accountancy functions * \brief Library of accountancy functions
* \version $Id$ * \version $Id: accountancy.lib.php,v 1.2 2011/07/04 10:30:01 eldy Exp $
*/ */
/**
* @param $db
* @param $year
* @param $socid
*/
function get_ca_propal ($db, $year, $socid) function get_ca_propal ($db, $year, $socid)
{ {
$sql = "SELECT sum(f.price - f.remise) as sum FROM ".MAIN_DB_PREFIX."propal as f WHERE fk_statut in (1,2,4) AND date_format(f.datep, '%Y') = '".$year."'";
$sql = "SELECT sum(f.price - f.remise) as sum FROM ".MAIN_DB_PREFIX."propal as f WHERE fk_statut in (1,2,4) AND date_format(f.datep, '%Y') = $year ";
if ($socid) if ($socid)
{ {
$sql .= " AND f.fk_soc = $socid"; $sql .= " AND f.fk_soc = $socid";
} }
$result = $db->query($sql); $result = $db->query($sql);
if ($result) if ($result)
{ {
$res = $db->fetch_object($result); $res = $db->fetch_object($result);
@ -56,14 +58,13 @@ function get_ca ($db, $year, $socid)
if ($conf->compta->mode != 'CREANCES-DETTES') { if ($conf->compta->mode != 'CREANCES-DETTES') {
$sql .= " AND f.paye = 1"; $sql .= " AND f.paye = 1";
} }
$sql .= " AND date_format(f.datef , '%Y') = $year "; $sql .= " AND date_format(f.datef , '%Y') = '".$year."'";
if ($socid) if ($socid)
{ {
$sql .= " AND f.fk_soc = $socid"; $sql .= " AND f.fk_soc = $socid";
} }
$result = $db->query($sql); $result = $db->query($sql);
if ($result) if ($result)
{ {
$res = $db->fetch_object($result); $res = $db->fetch_object($result);