From 460778818cb5ce7ef6c2a3b8c88624a543211b8e Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 14 Jul 2013 00:09:42 +0200 Subject: [PATCH 01/11] Fix: automatic ecm for supplier invoices --- htdocs/core/class/html.formfile.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/core/class/html.formfile.class.php b/htdocs/core/class/html.formfile.class.php index b79b3ef22c6..127323ecc97 100644 --- a/htdocs/core/class/html.formfile.class.php +++ b/htdocs/core/class/html.formfile.class.php @@ -836,7 +836,7 @@ class FormFile // To show ref or specific information according to view to show (defined by $module) if ($modulepart == 'company') { preg_match('/(\d+)\/[^\/]+$/',$relativefile,$reg); $id=(isset($reg[1])?$reg[1]:''); } if ($modulepart == 'invoice') { preg_match('/(.*)\/[^\/]+$/',$relativefile,$reg); $ref=(isset($reg[1])?$reg[1]:''); } - if ($modulepart == 'invoice_supplier') { preg_match('/(\d+)\/[^\/]+$/',$relativefile,$reg); $id=(isset($reg[1])?$reg[1]:''); } + if ($modulepart == 'invoice_supplier') { preg_match('/([^\/]+)\/[^\/]+$/',$relativefile,$reg); $ref=(isset($reg[1])?$reg[1]:''); if (is_numeric($ref)) { $id=$ref; $ref=''; } } // $ref may be also id with old supplier invoices if ($modulepart == 'propal') { preg_match('/(.*)\/[^\/]+$/',$relativefile,$reg); $ref=(isset($reg[1])?$reg[1]:''); } if ($modulepart == 'order') { preg_match('/(.*)\/[^\/]+$/',$relativefile,$reg); $ref=(isset($reg[1])?$reg[1]:''); } if ($modulepart == 'order_supplier') { preg_match('/(.*)\/[^\/]+$/',$relativefile,$reg); $ref=(isset($reg[1])?$reg[1]:''); } From 154cd1fcf9956120c8a94f89c038dd7576e12a26 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 14 Jul 2013 00:40:22 +0200 Subject: [PATCH 02/11] Fix: Sort on ref for supplier invoice into ged --- htdocs/core/class/html.formfile.class.php | 2 +- htdocs/core/lib/files.lib.php | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/htdocs/core/class/html.formfile.class.php b/htdocs/core/class/html.formfile.class.php index 127323ecc97..b4103974a03 100644 --- a/htdocs/core/class/html.formfile.class.php +++ b/htdocs/core/class/html.formfile.class.php @@ -758,7 +758,7 @@ class FormFile print ''; print ''; $sortref="fullname"; - if ($modulepart == 'invoice_supplier') $sortref=''; // No sort for supplier invoices as path name is not + if ($modulepart == 'invoice_supplier') $sortref='level1name'; print_liste_field_titre($langs->trans("Ref"),$url,$sortref,"",$param,'align="left"',$sortfield,$sortorder); print_liste_field_titre($langs->trans("Documents2"),$url,"name","",$param,'align="left"',$sortfield,$sortorder); print_liste_field_titre($langs->trans("Size"),$url,"size","",$param,'align="right"',$sortfield,$sortorder); diff --git a/htdocs/core/lib/files.lib.php b/htdocs/core/lib/files.lib.php index 8ff9e6bbc47..8946ed14654 100644 --- a/htdocs/core/lib/files.lib.php +++ b/htdocs/core/lib/files.lib.php @@ -135,8 +135,11 @@ function dol_dir_list($path, $types="all", $recursive=0, $filter="", $excludefil if (! $filter || preg_match('/'.$filter.'/i',$file)) // We do not search key $filter into $path, only into $file { + preg_match('/([^\/]+)\/[^\/]+$/',$path.'/'.$file,$reg); + $level1name=(isset($reg[1])?$reg[1]:''); $file_list[] = array( "name" => $file, + "level1name" => $level1name, "fullname" => $path.'/'.$file, "date" => $filedate, "size" => $filesize, @@ -159,8 +162,11 @@ function dol_dir_list($path, $types="all", $recursive=0, $filter="", $excludefil if (! $filter || preg_match('/'.$filter.'/i',$file)) // We do not search key $filter into $path, only into $file { + preg_match('/([^\/]+)\/[^\/]+$/',$path.'/'.$file,$reg); + $level1name=(isset($reg[1])?$reg[1]:''); $file_list[] = array( "name" => $file, + "level1name" => $level1name, "fullname" => $path.'/'.$file, "date" => $filedate, "size" => $filesize, From 57ab24bacaa50ffb8a04c79ccdcdedfdd9674592 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 14 Jul 2013 01:08:53 +0200 Subject: [PATCH 03/11] Fix: bad sort order into ecm module --- htdocs/ecm/index.php | 1 + 1 file changed, 1 insertion(+) diff --git a/htdocs/ecm/index.php b/htdocs/ecm/index.php index c671fa2e29b..3ca6ccb2221 100644 --- a/htdocs/ecm/index.php +++ b/htdocs/ecm/index.php @@ -63,6 +63,7 @@ $pageprev = $page - 1; $pagenext = $page + 1; if (! $sortorder) $sortorder="ASC"; if (! $sortfield) $sortfield="fullname"; +if ($module == 'invoice_supplier' && $sortfield == "fullname") $sortfield="level1name"; $ecmdir = new EcmDirectory($db); if ($section) From 0a3bd586459146b12d102ffd1e106f265043c37a Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 14 Jul 2013 03:28:19 +0200 Subject: [PATCH 04/11] Fix: Duplicate button --- htdocs/compta/paiement/cheque/fiche.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/htdocs/compta/paiement/cheque/fiche.php b/htdocs/compta/paiement/cheque/fiche.php index 3251b4a1ab6..ae0469d581c 100644 --- a/htdocs/compta/paiement/cheque/fiche.php +++ b/htdocs/compta/paiement/cheque/fiche.php @@ -344,8 +344,8 @@ if ($action == 'new') $sql.= " AND ba.entity = ".$conf->entity; $sql.= " AND b.fk_bordereau = 0"; $sql.= " AND b.amount > 0"; - if ($filterdate) $sql.=" AND b.dateo = '".$db->idate($filterdate)."'"; - if ($filteraccountid) $sql.=" AND ba.rowid= '".$filteraccountid."'"; + if ($filterdate) $sql.=" AND b.dateo = '".$db->idate($filterdate)."'"; + if ($filteraccountid > 0) $sql.=" AND ba.rowid= '".$filteraccountid."'"; $sql.= $db->order("b.dateo,b.rowid","ASC"); $resql = $db->query($sql); @@ -602,10 +602,10 @@ else print '
'; -if ($user->societe_id == 0 && count($accounts) == 1 && $action == 'new' && $user->rights->banque->cheque) +/*if ($user->societe_id == 0 && count($accounts) == 1 && $action == 'new' && $user->rights->banque->cheque) { print ''.$langs->trans('NewCheckReceipt').''; -} +}*/ if ($user->societe_id == 0 && ! empty($object->id) && $object->statut == 0 && $user->rights->banque->cheque) { From cc124e03c1c7fa964f316ee140eafc1e7a74f82c Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 14 Jul 2013 03:38:07 +0200 Subject: [PATCH 05/11] Fix: Missing comma --- build/debian/control | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/debian/control b/build/debian/control index 8810a7d189c..3fb705087a8 100755 --- a/build/debian/control +++ b/build/debian/control @@ -13,7 +13,7 @@ Depends: libapache2-mod-php5 | libapache2-mod-php5filter | php5-cgi | php5-fpm | libphp-adodb, libnusoap-php, libphp-pclzip, - libfpdi-php, libfpdf-tpl-php, php-fpdf + libfpdi-php, libfpdf-tpl-php, php-fpdf, libjs-jquery, libjs-jquery-ui, libjs-flot, ckeditor, ttf-dejavu-core, xdg-utils, From f4dfac045a2f39b267c19de3ae22b9bd53da819f Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 14 Jul 2013 20:20:52 +0200 Subject: [PATCH 06/11] Fix: Bad default mysql driver --- htdocs/install/inc.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/htdocs/install/inc.php b/htdocs/install/inc.php index 7d4a22fffa2..fe7dd58cabc 100644 --- a/htdocs/install/inc.php +++ b/htdocs/install/inc.php @@ -82,7 +82,7 @@ if (! defined('DONOTLOADCONF') && file_exists($conffile)) $result=include_once $conffile; // Load conf file if ($result) { - if (empty($dolibarr_main_db_type)) $dolibarr_main_db_type='mysql'; // For backward compatibility + if (empty($dolibarr_main_db_type)) $dolibarr_main_db_type='mysqli'; // For backward compatibility // Clean parameters $dolibarr_main_data_root =isset($dolibarr_main_data_root)?trim($dolibarr_main_data_root):''; @@ -323,7 +323,7 @@ function conf($dolibarr_main_document_root) { throw new Exception('Missing log handler file '.$handler.'.php'); } - + require_once $file; $loghandlerinstance = new $handler(); if (!$loghandlerinstance instanceof LogHandlerInterface) @@ -333,7 +333,7 @@ function conf($dolibarr_main_document_root) if (empty($conf->loghandlers[$handler])) $conf->loghandlers[$handler]=$loghandlerinstance; } - + return 1; } From dc5ad1a0f3ce4d4acfcbe281e23c5ca188dfd480 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 14 Jul 2013 20:29:07 +0200 Subject: [PATCH 07/11] Fix: Total missing --- htdocs/compta/facture/impayees.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/compta/facture/impayees.php b/htdocs/compta/facture/impayees.php index 48c0f5c1e9e..975211b11bf 100644 --- a/htdocs/compta/facture/impayees.php +++ b/htdocs/compta/facture/impayees.php @@ -400,7 +400,7 @@ if ($resql) print '
'; print ''; print ''; - print ''; + print ''; print ''; print ''; print "\n"; From 5fb707f918fbdaaa108c9915509585c651a2bc32 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 14 Jul 2013 21:02:00 +0200 Subject: [PATCH 08/11] Fix: Restore disappeared feature --- htdocs/compta/facture/impayees.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/htdocs/compta/facture/impayees.php b/htdocs/compta/facture/impayees.php index bd207b7dbfc..79838cbe86b 100644 --- a/htdocs/compta/facture/impayees.php +++ b/htdocs/compta/facture/impayees.php @@ -283,7 +283,7 @@ if ($resql) print_liste_field_titre($langs->trans("Taxes"),$_SERVER["PHP_SELF"],"f.tva","",$param,'align="right"',$sortfield,$sortorder); print_liste_field_titre($langs->trans("AmountTTC"),$_SERVER["PHP_SELF"],"f.total_ttc","",$param,'align="right"',$sortfield,$sortorder); print_liste_field_titre($langs->trans("Received"),$_SERVER["PHP_SELF"],"am","",$param,'align="right"',$sortfield,$sortorder); - //print_liste_field_titre($langs->trans("Remain"),$_SERVER["PHP_SELF"],"am","",$param,'align="right"',$sortfield,$sortorder); + print_liste_field_titre($langs->trans("Rest"),$_SERVER["PHP_SELF"],"am","",$param,'align="right"',$sortfield,$sortorder); print_liste_field_titre($langs->trans("Status"),$_SERVER["PHP_SELF"],"fk_statut,paye,am","",$param,'align="right"',$sortfield,$sortorder); print_liste_field_titre($langs->trans("Merge"),$_SERVER["PHP_SELF"],"","",$param,'align="center"',$sortfield,$sortorder); print "\n"; @@ -300,7 +300,9 @@ if ($resql) print ''; print ''; print ''; - print ''; + print ''; + print ''; print ''; // Remain to receive - //print ''; + print ''; // Status of invoice print '
'.price($total_tva).' '.getCurrencySymbol($conf->currency).''.price($total_ttc).' '.getCurrencySymbol($conf->currency).''.price($total_paid).' '.getCurrencySymbol($conf->currency).' '.price($total_ttc - $total_paid).' '.getCurrencySymbol($conf->currency).'  
 '; + print '  '; print ''; print ''; @@ -382,7 +384,7 @@ if ($resql) print ''.((! empty($objp->am) || ! empty($cn))?price($objp->total_ttc-$objp->am-$cn):' ').''.((! empty($objp->am) || ! empty($cn))?price($objp->total_ttc-$objp->am-$cn):' ').''; From 2ae1e787c94a8de8b059b352a5e5a262d2e9e23e Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 15 Jul 2013 21:49:54 +0200 Subject: [PATCH 09/11] Fix: Bad date ranges Conflicts: scripts/invoices/rebuild_merge_pdf.php --- htdocs/core/lib/invoice2.lib.php | 6 +++--- scripts/invoices/rebuild_merge_pdf.php | 13 +++++++++---- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/htdocs/core/lib/invoice2.lib.php b/htdocs/core/lib/invoice2.lib.php index d4373fcd204..9c6ccc1268f 100644 --- a/htdocs/core/lib/invoice2.lib.php +++ b/htdocs/core/lib/invoice2.lib.php @@ -37,8 +37,8 @@ require_once(DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php'); * @param array $filter Array with filters * @param date $dateafterdate Invoice after date * @param date $datebeforedate Invoice before date - * @param date $paymentdateafter Payment after date - * @param date $paymentdatebefore Payment before date + * @param date $paymentdateafter Payment after date (must includes hour) + * @param date $paymentdatebefore Payment before date (must includes hour) * @param int $usestdout Add information onto standard output * @param int $regenerate ''=Use existing PDF files, 'nameofpdf'=Regenerate all PDF files using the template * @param string $option Suffix to add into file name of generated PDF @@ -264,4 +264,4 @@ function rebuild_merge_pdf($db, $langs, $conf, $diroutputpdf, $newlangid, $filte else return $result; } -?> \ No newline at end of file +?> diff --git a/scripts/invoices/rebuild_merge_pdf.php b/scripts/invoices/rebuild_merge_pdf.php index 6360735ab67..1e5d137dff5 100755 --- a/scripts/invoices/rebuild_merge_pdf.php +++ b/scripts/invoices/rebuild_merge_pdf.php @@ -107,7 +107,7 @@ foreach ($argv as $key => $value) $dateafterdate=dol_stringtotime($argv[$key+1]); $datebeforedate=dol_stringtotime($argv[$key+2]); - print 'Rebuild PDF for invoices validated between '.dol_print_date($dateafterdate,'day')." and ".dol_print_date($datebeforedate,'day').".\n"; + print 'Rebuild PDF for invoices validated between '.dol_print_date($dateafterdate,'day','gmt')." and ".dol_print_date($datebeforedate,'day','gmt').".\n"; } if ($value == 'filter=payments') @@ -116,9 +116,14 @@ foreach ($argv as $key => $value) $option.=(empty($option)?'':'_').'payments_'.$argv[$key+1].'_'.$argv[$key+2]; $filter[]='payments'; - $paymentdateafter=dol_stringtotime($argv[$key+1]); - $paymentdatebefore=dol_stringtotime($argv[$key+2]); - print 'Rebuild PDF for invoices with at least one payment between '.dol_print_date($paymentdateafter,'day')." and ".dol_print_date($paymentdatebefore,'day').".\n"; + $paymentdateafter=dol_stringtotime($argv[$key+1].'000000'); + $paymentdatebefore=dol_stringtotime($argv[$key+2].'235959'); + if (empty($paymentdateafter) || empty($paymentdatebefore)) + { + print 'Error: Bad date format or value'."\n"; + exit(-1); + } + print 'Rebuild PDF for invoices with at least one payment between '.dol_print_date($paymentdateafter,'day','gmt')." and ".dol_print_date($paymentdatebefore,'day','gmt').".\n"; } if ($value == 'filter=nopayment') From 4fee61beb02f8e1d178e3461df0cd0adc9018ceb Mon Sep 17 00:00:00 2001 From: Florian Henry Date: Tue, 16 Jul 2013 21:34:24 +0200 Subject: [PATCH 10/11] Fix adding email into mailing module source_id is already added --- htdocs/core/modules/mailings/modules_mailings.php | 1 - 1 file changed, 1 deletion(-) diff --git a/htdocs/core/modules/mailings/modules_mailings.php b/htdocs/core/modules/mailings/modules_mailings.php index 9d84058fa87..74d79547e2f 100644 --- a/htdocs/core/modules/mailings/modules_mailings.php +++ b/htdocs/core/modules/mailings/modules_mailings.php @@ -169,7 +169,6 @@ class MailingTargets // This can't be abstract as it is used for some method $sql .= "'".$this->db->escape($targetarray['email'])."',"; $sql .= "'".$this->db->escape($targetarray['other'])."',"; $sql .= "'".$this->db->escape($targetarray['source_url'])."',"; - $sql .= "'".$this->db->escape($targetarray['source_id'])."',"; $sql .= (empty($targetarray['source_id']) ? 'null' : "'".$this->db->escape($targetarray['source_id'])."'").","; if (! empty($conf->global->MAILING_EMAIL_UNSUBSCRIBE)) { $sql .= "'".$this->db->escape(md5($targetarray['email'].';'.$targetarray['name'].';'.$mailing_id.';'.$conf->global->MAILING_EMAIL_UNSUBSCRIBE_KEY))."',"; From d5ca2f9f4057607847340b050e5a740cc764b3a5 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 18 Jul 2013 15:37:14 +0200 Subject: [PATCH 11/11] Fix: forged select for stats where wrong when filtering on a thirdparty Conflicts: htdocs/compta/facture/class/facturestats.class.php --- .../comm/propal/class/propalestats.class.php | 48 ++++++++--------- htdocs/commande/class/commandestats.class.php | 51 ++++++++++--------- .../facture/class/facturestats.class.php | 25 +++++---- 3 files changed, 64 insertions(+), 60 deletions(-) diff --git a/htdocs/comm/propal/class/propalestats.class.php b/htdocs/comm/propal/class/propalestats.class.php index 34584c7f99e..5b5b0dd7279 100644 --- a/htdocs/comm/propal/class/propalestats.class.php +++ b/htdocs/comm/propal/class/propalestats.class.php @@ -1,6 +1,6 @@ - * Copyright (c) 2005 Laurent Destailleur + * Copyright (c) 2005-2013 Laurent Destailleur * Copyright (C) 2005-2009 Regis Houssin * Copyright (c) 2011 Juanjo Menent * @@ -30,8 +30,7 @@ include_once DOL_DOCUMENT_ROOT . '/core/lib/date.lib.php'; /** - * \class PropaleStats - * \brief Classe permettant la gestion des stats des propales + * Class to manage proposal statistics */ class PropaleStats extends Stats { @@ -49,7 +48,7 @@ class PropaleStats extends Stats * Constructor * * @param DoliDB $db Database handler - * @param int $socid Id third party + * @param int $socid Id third party for filter * @param int $userid Id user for filter (creation user) */ function __construct($db, $socid=0, $userid=0) @@ -63,16 +62,17 @@ class PropaleStats extends Stats $object=new Propal($this->db); $this->from = MAIN_DB_PREFIX.$object->table_element." as p"; - $this->from.= ", ".MAIN_DB_PREFIX."societe as s"; + //$this->from.= ", ".MAIN_DB_PREFIX."societe as s"; $this->field='total_ht'; $this->where.= " p.fk_statut > 0"; - $this->where.= " AND p.fk_soc = s.rowid AND p.entity = ".$conf->entity; - if (!$user->rights->societe->client->voir && !$user->societe_id) $this->where .= " AND p.fk_soc = sc.fk_soc AND sc.fk_user = " .$user->id; + //$this->where.= " AND p.fk_soc = s.rowid AND p.entity = ".$conf->entity; + $this->where.= " AND p.entity = ".$conf->entity; + if (!$user->rights->societe->client->voir && !$this->socid) $this->where .= " AND p.fk_soc = sc.fk_soc AND sc.fk_user = " .$user->id; if($this->socid) { - $this->where .= " AND p.fk_soc = ".$this->socid; + $this->where.=" AND p.fk_soc = ".$this->socid; } if ($this->userid > 0) $this->where.=' AND fk_user_author = '.$this->userid; } @@ -81,14 +81,14 @@ class PropaleStats extends Stats /** * Return propals number by month for a year * - * @param int $year year for stats - * @return array array with number by month + * @param int $year Year to scan + * @return array Array with number by month */ function getNbByMonth($year) { global $user; - $sql = "SELECT date_format(p.datep,'%m') as dm, count(*)"; + $sql = "SELECT date_format(p.datep,'%m') as dm, COUNT(*) as nb"; $sql.= " FROM ".$this->from; if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; $sql.= " WHERE p.datep BETWEEN '".$this->db->idate(dol_get_first_day($year))."' AND '".$this->db->idate(dol_get_last_day($year))."'"; @@ -96,22 +96,23 @@ class PropaleStats extends Stats $sql.= " GROUP BY dm"; $sql.= $this->db->order('dm','DESC'); - return $this->_getNbByMonth($year, $sql); + $res=$this->_getNbByMonth($year, $sql); + return $res; } /** - * Return propals number by year + * Return propals number per year * - * @return array array with number by year + * @return array Array with number by year * */ function getNbByYear() { global $user; - $sql = "SELECT date_format(p.datep,'%Y') as dm, count(*)"; + $sql = "SELECT date_format(p.datep,'%Y') as dm, COUNT(*) as nb, SUM(c.".$this->field.")"; $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 && !$this->socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; $sql.= " WHERE ".$this->where; $sql.= " GROUP BY dm"; $sql.= $this->db->order('dm','DESC'); @@ -122,22 +123,23 @@ class PropaleStats extends Stats /** * Return the propals amount by month for a year * - * @param int $year year for stats - * @return array array with number by month + * @param int $year Year to scan + * @return array Array with amount by month */ function getAmountByMonth($year) { global $user; - $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; - if (!$user->rights->societe->client->voir && !$user->societe_id) $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 p.datep BETWEEN '".$this->db->idate(dol_get_first_day($year))."' AND '".$this->db->idate(dol_get_last_day($year))."'"; $sql.= " AND ".$this->where; $sql.= " GROUP BY dm"; $sql.= $this->db->order('dm','DESC'); - return $this->_getAmountByMonth($year, $sql); + $res=$this->_getAmountByMonth($year, $sql); + return $res; } /** @@ -150,7 +152,7 @@ class PropaleStats extends Stats { global $user; - $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; if (!$user->rights->societe->client->voir && !$this->socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; $sql.= " WHERE p.datep BETWEEN '".$this->db->idate(dol_get_first_day($year))."' AND '".$this->db->idate(dol_get_last_day($year))."'"; @@ -170,7 +172,7 @@ class PropaleStats extends Stats { global $user; - $sql = "SELECT date_format(p.datep,'%Y') as year, count(*) as nb, sum(".$this->field.") as total, avg(".$this->field.") as avg"; + $sql = "SELECT date_format(p.datep,'%Y') as year, COUNT(*) as nb, SUM(".$this->field.") as total, AVG(".$this->field.") as avg"; $sql.= " FROM ".$this->from; if (!$user->rights->societe->client->voir && !$this->socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; $sql.= " WHERE ".$this->where; diff --git a/htdocs/commande/class/commandestats.class.php b/htdocs/commande/class/commandestats.class.php index 6de20836f35..c5923edbb55 100644 --- a/htdocs/commande/class/commandestats.class.php +++ b/htdocs/commande/class/commandestats.class.php @@ -1,6 +1,6 @@ - * Copyright (c) 2005 Laurent Destailleur + * Copyright (c) 2005-2013 Laurent Destailleur * Copyright (C) 2005-2012 Regis Houssin * Copyright (C) 2012 Marcos GarcĂ­a * @@ -30,7 +30,7 @@ include_once DOL_DOCUMENT_ROOT . '/core/lib/date.lib.php'; /** - * Class to manage order statistics + * Class to manage order statistics (customer and supplier) */ class CommandeStats extends Stats { @@ -49,7 +49,7 @@ class CommandeStats extends Stats * * @param DoliDB $db Database handler * @param int $socid Id third party for filter - * @param string $mode Option + * @param string $mode Option ('customer', 'supplier') * @param int $userid Id user for filter (creation user) */ function __construct($db, $socid, $mode, $userid=0) @@ -60,12 +60,13 @@ class CommandeStats extends Stats $this->socid = ($socid > 0 ? $socid : 0); $this->userid = $userid; - + $this->cachefilesuffix = $mode; + if ($mode == 'customer') { $object=new Commande($this->db); $this->from = MAIN_DB_PREFIX.$object->table_element." as c"; - $this->from.= ", ".MAIN_DB_PREFIX."societe as s"; + //$this->from.= ", ".MAIN_DB_PREFIX."societe as s"; $this->field='total_ht'; $this->where.= " c.fk_statut > 0"; // Not draft and not cancelled } @@ -73,16 +74,16 @@ class CommandeStats extends Stats { $object=new CommandeFournisseur($this->db); $this->from = MAIN_DB_PREFIX.$object->table_element." as c"; - $this->from.= ", ".MAIN_DB_PREFIX."societe as s"; + //$this->from.= ", ".MAIN_DB_PREFIX."societe as s"; $this->field='total_ht'; $this->where.= " c.fk_statut > 2"; // Only approved & ordered } - $this->where.= " AND c.fk_soc = s.rowid AND c.entity = ".$conf->entity; - + //$this->where.= " AND c.fk_soc = s.rowid AND c.entity = ".$conf->entity; + $this->where.= " AND c.entity = ".$conf->entity; if (!$user->rights->societe->client->voir && !$this->socid) $this->where .= " AND c.fk_soc = sc.fk_soc AND sc.fk_user = " .$user->id; - if($this->socid) + if ($this->socid) { - $this->where .= " AND c.fk_soc = ".$this->socid; + $this->where.=" AND c.fk_soc = ".$this->socid; } if ($this->userid > 0) $this->where.=' AND c.fk_user_author = '.$this->userid; } @@ -90,14 +91,14 @@ class CommandeStats extends Stats /** * Return orders number by month for a year * - * @param int $year year for stats - * @return array array with number by month + * @param int $year Year to scan + * @return array Array with number by month */ function getNbByMonth($year) { global $user; - $sql = "SELECT date_format(c.date_commande,'%m') as dm, count(*) nb"; + $sql = "SELECT date_format(c.date_commande,'%m') as dm, COUNT(*) as nb"; $sql.= " FROM ".$this->from; if (!$user->rights->societe->client->voir && !$this->socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; $sql.= " WHERE c.date_commande BETWEEN '".$this->db->idate(dol_get_first_day($year))."' AND '".$this->db->idate(dol_get_last_day($year))."'"; @@ -105,20 +106,21 @@ class CommandeStats extends Stats $sql.= " GROUP BY dm"; $sql.= $this->db->order('dm','DESC'); - return $this->_getNbByMonth($year, $sql); + $res=$this->_getNbByMonth($year, $sql); + return $res; } /** - * Return orders number by year + * Return orders number per year * - * @return array array with number by year + * @return array Array with number by year * */ function getNbByYear() { global $user; - $sql = "SELECT date_format(c.date_commande,'%Y') as dm, count(*), sum(c.".$this->field.")"; + $sql = "SELECT date_format(c.date_commande,'%Y') as dm, COUNT(*) as nb, SUM(c.".$this->field.")"; $sql.= " FROM ".$this->from; if (!$user->rights->societe->client->voir && !$this->socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; $sql.= " WHERE ".$this->where; @@ -131,14 +133,14 @@ class CommandeStats extends Stats /** * Return the orders amount by month for a year * - * @param int $year year for stats - * @return array array with number by month + * @param int $year Year to scan + * @return array Array with amount by month */ function getAmountByMonth($year) { global $user; - $sql = "SELECT date_format(c.date_commande,'%m') as dm, sum(c.".$this->field.")"; + $sql = "SELECT date_format(c.date_commande,'%m') as dm, SUM(c.".$this->field.")"; $sql.= " FROM ".$this->from; if (!$user->rights->societe->client->voir && !$this->socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; $sql.= " WHERE c.date_commande BETWEEN '".$this->db->idate(dol_get_first_day($year))."' AND '".$this->db->idate(dol_get_last_day($year))."'"; @@ -146,7 +148,8 @@ class CommandeStats extends Stats $sql.= " GROUP BY dm"; $sql.= $this->db->order('dm','DESC'); - return $this->_getAmountByMonth($year, $sql); + $res=$this->_getAmountByMonth($year, $sql); + return $res; } /** @@ -159,7 +162,7 @@ class CommandeStats extends Stats { global $user; - $sql = "SELECT date_format(c.date_commande,'%m') as dm, avg(c.".$this->field.")"; + $sql = "SELECT date_format(c.date_commande,'%m') as dm, AVG(c.".$this->field.")"; $sql.= " FROM ".$this->from; if (!$user->rights->societe->client->voir && !$this->socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; $sql.= " WHERE c.date_commande BETWEEN '".$this->db->idate(dol_get_first_day($year))."' AND '".$this->db->idate(dol_get_last_day($year))."'"; @@ -179,7 +182,7 @@ class CommandeStats extends Stats { global $user; - $sql = "SELECT date_format(c.date_commande,'%Y') as year, count(*) as nb, sum(c.".$this->field.") as total, avg(".$this->field.") as avg"; + $sql = "SELECT date_format(c.date_commande,'%Y') as year, COUNT(*) as nb, SUM(c.".$this->field.") as total, AVG(".$this->field.") as avg"; $sql.= " FROM ".$this->from; if (!$user->rights->societe->client->voir && !$this->socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; $sql.= " WHERE ".$this->where; @@ -190,4 +193,4 @@ class CommandeStats extends Stats } } -?> +?> \ No newline at end of file diff --git a/htdocs/compta/facture/class/facturestats.class.php b/htdocs/compta/facture/class/facturestats.class.php index c2e42addbb5..a168e483d7c 100644 --- a/htdocs/compta/facture/class/facturestats.class.php +++ b/htdocs/compta/facture/class/facturestats.class.php @@ -1,6 +1,6 @@ - * Copyright (c) 2005-2012 Laurent Destailleur + * Copyright (c) 2005-2013 Laurent Destailleur * Copyright (C) 2005-2009 Regis Houssin * * This program is free software; you can redistribute it and/or modify @@ -46,10 +46,9 @@ class FactureStats extends Stats * Constructor * * @param DoliDB $db Database handler - * @param int $socid Id third party - * @param string $mode Option + * @param int $socid Id third party for filter + * @param string $mode Option ('customer', 'supplier') * @param int $userid Id user for filter (creation user) - * @return FactureStats */ function __construct($db, $socid, $mode, $userid=0) { @@ -74,7 +73,7 @@ class FactureStats extends Stats $this->where = " f.fk_statut > 0"; $this->where.= " AND f.entity = ".$conf->entity; - if (!$user->rights->societe->client->voir && !$user->societe_id) $this->where .= " AND f.fk_soc = sc.fk_soc AND sc.fk_user = " .$user->id; + if (!$user->rights->societe->client->voir && !$this->socid) $this->where .= " AND f.fk_soc = sc.fk_soc AND sc.fk_user = " .$user->id; if ($mode == 'customer') $this->where.=" AND (f.fk_statut <> 3 OR f.close_code <> 'replaced')"; // Exclude replaced invoices as they are duplicated (we count closed invoices for other reasons) if ($this->socid) { @@ -85,7 +84,7 @@ class FactureStats extends Stats /** - * Renvoie le nombre de facture par mois pour une annee donnee + * Return orders number by month for a year * * @param int $year Year to scan * @return array Array of values @@ -94,7 +93,7 @@ class FactureStats extends Stats { global $user; - $sql = "SELECT MONTH(f.datef) as dm, COUNT(*)"; + $sql = "SELECT date_format(f.datef,'%m') as dm, COUNT(*) as nb"; $sql.= " FROM ".$this->from; if (!$user->rights->societe->client->voir && !$this->socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; $sql.= " WHERE f.datef BETWEEN '".$this->db->idate(dol_get_first_day($year))."' AND '".$this->db->idate(dol_get_last_day($year))."'"; @@ -109,15 +108,15 @@ class FactureStats extends Stats /** - * Renvoie le nombre de facture par annee + * Return invoices number per year * - * @return array Array of values + * @return array Array with number by year */ function getNbByYear() { global $user; - $sql = "SELECT YEAR(f.datef) as dm, COUNT(*)"; + $sql = "SELECT date_format(f.datef,'%Y') as dm, COUNT(*), SUM(c.".$this->field.")"; $sql.= " FROM ".$this->from; if (!$user->rights->societe->client->voir && !$this->socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; $sql.= " WHERE ".$this->where; @@ -129,10 +128,10 @@ class FactureStats extends Stats /** - * Renvoie le montant de facture par mois pour une annee donnee + * Return the invoices amount by month for a year * * @param int $year Year to scan - * @return array Array of values + * @return array Array with amount by month */ function getAmountByMonth($year) { @@ -140,7 +139,7 @@ class FactureStats extends Stats $sql = "SELECT date_format(datef,'%m') as dm, SUM(f.".$this->field.")"; $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 && !$this->socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; $sql.= " WHERE f.datef BETWEEN '".$this->db->idate(dol_get_first_day($year))."' AND '".$this->db->idate(dol_get_last_day($year))."'"; $sql.= " AND ".$this->where; $sql.= " GROUP BY dm";