";
+}
+
+
+/* ************************************************************************** */
+/* */
+/* Create optional field */
+/* */
+/* ************************************************************************** */
+
+if ($action == 'create')
+{
+ print " ";
+ print_titre($langs->trans('NewAttribute'));
+
+ require DOL_DOCUMENT_ROOT.'/core/tpl/admin_extrafields_add.tpl.php';
+}
+
+/* ************************************************************************** */
+/* */
+/* Edit optional field */
+/* */
+/* ************************************************************************** */
+if ($action == 'edit' && ! empty($attrname))
+{
+ print " ";
+ print_titre($langs->trans("FieldEdition", $attrname));
+
+ require DOL_DOCUMENT_ROOT.'/core/tpl/admin_extrafields_edit.tpl.php';
+}
+
+llxFooter();
+
+$db->close();
diff --git a/htdocs/donations/card.php b/htdocs/donations/card.php
index 0d1cea0d4f1..d5aeaedb56d 100644
--- a/htdocs/donations/card.php
+++ b/htdocs/donations/card.php
@@ -32,6 +32,7 @@ require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
require_once DOL_DOCUMENT_ROOT.'/donations/class/don.class.php';
require_once DOL_DOCUMENT_ROOT.'/compta/paiement/class/paiement.class.php';
+require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
if (! empty($conf->projet->enabled))
{
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
@@ -48,6 +49,11 @@ $cancel=GETPOST('cancel');
$amount=GETPOST('amount');
$object = new Don($db);
+$extrafields = new ExtraFields($db);
+
+// fetch optionals attributes and labels
+$extralabels=$extrafields->fetch_name_optionals_label($object->table_element);
+
$donation_date=dol_mktime(12, 0, 0, GETPOST('remonth'), GETPOST('reday'), GETPOST('reyear'));
// Security check
@@ -103,6 +109,10 @@ if ($action == 'update')
$object->fk_project = GETPOST("fk_project");
$object->note_private= GETPOST("note_private");
$object->note_public = GETPOST("note_public");
+
+ // Fill array 'array_options' with data from add form
+ $ret = $extrafields->setOptionalsFromPost($extralabels,$object);
+ if ($ret < 0) $error++;
if ($object->update($user) > 0)
{
@@ -151,7 +161,11 @@ if ($action == 'add')
$object->note_private= GETPOST("note_private");
$object->note_public = GETPOST("note_public");
$object->public = GETPOST("public");
- $object->fk_project = GETPOST("projectid");
+ $object->fk_project = GETPOST("fk_project");
+
+ // Fill array 'array_options' with data from add form
+ $ret = $extrafields->setOptionalsFromPost($extralabels,$object);
+ if ($ret < 0) $error++;
if ($object->create($user) > 0)
{
@@ -341,9 +355,13 @@ if ($action == 'create')
}
// Other attributes
- $parameters=array('colspan' => ' colspan="1"');
- $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
-
+ $parameters=array();
+ $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
+ if (empty($reshook) && ! empty($extrafields->attribute_label))
+ {
+ print $object->showOptionals($extrafields,'edit');
+ }
+
print "\n";
print '
';
print "\n";
diff --git a/htdocs/donations/class/donationstats.class.php b/htdocs/donations/class/donationstats.class.php
new file mode 100644
index 00000000000..74fd4d3d6f1
--- /dev/null
+++ b/htdocs/donations/class/donationstats.class.php
@@ -0,0 +1,141 @@
+
+ * Copyright (c) 2005-2013 Laurent Destailleur
+ * Copyright (C) 2005-2009 Regis Houssin
+ * Copyright (C) 2011 Juanjo Menent
+ *
+ * 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 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+/**
+ * \file htdocs/donations/class/donationstats.class.php
+ * \ingroup donations
+ * \brief File of class to manage donations statistics
+ */
+
+include_once DOL_DOCUMENT_ROOT . '/core/class/stats.class.php';
+include_once DOL_DOCUMENT_ROOT . '/donations/class/don.class.php';
+include_once DOL_DOCUMENT_ROOT . '/core/lib/date.lib.php';
+
+
+/**
+ * Class to manage donations statistics
+ */
+class DonationStats extends Stats
+{
+ public $table_element;
+
+ var $socid;
+ var $userid;
+
+ var $from;
+ var $field;
+ var $where;
+
+
+ /**
+ * Constructor
+ *
+ * @param DoliDB $db Database handler
+ * @param int $socid Id third party for filter
+ * @param string $mode Option (not used)
+ * @param int $userid Id user for filter (creation user)
+ */
+ function __construct($db, $socid, $mode, $userid=0)
+ {
+ global $user, $conf;
+
+ $this->db = $db;
+
+ $this->socid = ($socid > 0 ? $socid : 0);
+ $this->userid = $userid;
+ $this->cachefilesuffix = $mode;
+
+ $object=new Don($this->db);
+ $this->from = MAIN_DB_PREFIX.$object->table_element." as c";
+ //$this->from.= ", ".MAIN_DB_PREFIX."societe as s";
+ //$this->field='weight'; // Warning, unit of weight is NOT USED AND MUST BE
+ $this->where.= " c.fk_statut > 0"; // Not draft and not cancelled
+
+ //$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)
+ {
+ $this->where.=" AND c.fk_soc = ".$this->socid;
+ }
+ if ($this->userid > 0) $this->where.=' AND c.fk_user_author = '.$this->userid;
+ }
+
+ /**
+ * Return shipment number by month for a year
+ *
+ * @param int $year Year to scan
+ * @return array Array with number by month
+ */
+ function getNbByMonth($year)
+ {
+ global $user;
+
+ $sql = "SELECT date_format(c.date_valid,'%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_valid 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');
+
+ $res=$this->_getNbByMonth($year, $sql);
+ return $res;
+ }
+
+ /**
+ * Return shipments number per year
+ *
+ * @return array Array with number by year
+ *
+ */
+ function getNbByYear()
+ {
+ global $user;
+
+ $sql = "SELECT date_format(c.date_valid,'%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;
+ $sql.= " GROUP BY dm";
+ $sql.= $this->db->order('dm','DESC');
+
+ return $this->_getNbByYear($sql);
+ }
+
+ /**
+ * Return nb, total and average
+ *
+ * @return array Array of values
+ */
+ function getAllByYear()
+ {
+ global $user;
+
+ $sql = "SELECT date_format(c.date_valid,'%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;
+ $sql.= " GROUP BY year";
+ $sql.= $this->db->order('year','DESC');
+
+ return $this->_getAllByYear($sql);
+ }
+}
\ No newline at end of file
diff --git a/htdocs/donations/core/lib/donation.lib.php b/htdocs/donations/core/lib/donation.lib.php
index c274811bca1..93cbe889e4d 100644
--- a/htdocs/donations/core/lib/donation.lib.php
+++ b/htdocs/donations/core/lib/donation.lib.php
@@ -21,6 +21,40 @@
* \brief Library of donation functions
*/
+/**
+ * Prepare array with list of admin tabs
+ *
+ * @param Donation $object Donation
+ * @return array Array of tabs to show
+ */
+function donation_admin_prepare_head()
+{
+ global $langs, $conf;
+
+ $h = 0;
+ $head = array ();
+
+ $head[$h][0] = DOL_URL_ROOT . '/donations/admin/donation.php';
+ $head[$h][1] = $langs->trans("Miscellaneous");
+ $head[$h][2] = 'general';
+ $h ++;
+
+ // Show more tabs from modules
+ // Entries must be declared in modules descriptor with line
+ // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
+ // $this->tabs = array('entity:-tabname); to remove a tab
+ complete_head_from_modules($conf, $langs, $object, $head, $h, 'donation_admin');
+
+ $head[$h][0] = DOL_URL_ROOT . '/donations/admin/donation_extrafields.php';
+ $head[$h][1] = $langs->trans("ExtraFields");
+ $head[$h][2] = 'attributes';
+ $h++;
+
+ complete_head_from_modules($conf, $langs, $object, $head, $h, 'donation_admin', 'remove');
+
+ return $head;
+}
+
/**
* Prepare array with list of tabs
*
diff --git a/htdocs/donations/core/modules/modDon.class.php b/htdocs/donations/core/modules/modDon.class.php
index d602d867e1c..a4a825d8343 100644
--- a/htdocs/donations/core/modules/modDon.class.php
+++ b/htdocs/donations/core/modules/modDon.class.php
@@ -64,7 +64,7 @@ class modDon extends DolibarrModules
$this->requiredby = array();
// Config pages
- $this->config_page_url = array("dons.php@donations");
+ $this->config_page_url = array("donation.php@donations");
// Constants
$this->const = array ();
diff --git a/htdocs/donations/list.php b/htdocs/donations/list.php
index 4f49c28fb59..f277dc0b671 100644
--- a/htdocs/donations/list.php
+++ b/htdocs/donations/list.php
@@ -73,7 +73,7 @@ $sql = "SELECT d.rowid, d.datedon, d.firstname, d.lastname, d.societe,";
$sql.= " d.amount, d.fk_statut as statut, ";
$sql.= " p.rowid as pid, p.ref, p.title, p.public";
$sql.= " FROM ".MAIN_DB_PREFIX."don as d LEFT JOIN ".MAIN_DB_PREFIX."projet AS p";
-$sql.= " ON p.rowid = d.fk_don_projet WHERE 1 = 1";
+$sql.= " ON p.rowid = d.fk_project WHERE 1 = 1";
if ($statut >= 0)
{
$sql .= " AND d.fk_statut = ".$statut;
@@ -125,7 +125,7 @@ if ($resql)
if (! empty($conf->projet->enabled))
{
$langs->load("projects");
- print_liste_field_titre($langs->trans("Project"),$_SERVER["PHP_SELF"],"fk_don_projet","&page=$page&statut=$statut","","",$sortfield,$sortorder);
+ print_liste_field_titre($langs->trans("Project"),$_SERVER["PHP_SELF"],"fk_project","&page=$page&statut=$statut","","",$sortfield,$sortorder);
}
print_liste_field_titre($langs->trans("Amount"),$_SERVER["PHP_SELF"],"d.amount","&page=$page&statut=$statut","",'align="right"',$sortfield,$sortorder);
print_liste_field_titre($langs->trans("Status"),$_SERVER["PHP_SELF"],"d.fk_statut","&page=$page&statut=$statut","",'align="right"',$sortfield,$sortorder);
diff --git a/htdocs/donations/stats.php b/htdocs/donations/stats.php
deleted file mode 100644
index 2dacd9e093f..00000000000
--- a/htdocs/donations/stats.php
+++ /dev/null
@@ -1,84 +0,0 @@
-
- * Copyright (C) 2004-2009 Laurent Destailleur
- *
- * 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 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- */
-
-/**
- * \file htdocs/donations/stats.php
- * \ingroup don
- * \brief Page des statistiques de dons
- */
-
-require '../main.inc.php';
-
-$langs->load("donations");
-
-if (!$user->rights->don->lire) accessforbidden();
-
-
-/*
- * View
- */
-
-llxHeader('',$langs->trans("Donations"),'EN:Module_Donations|FR:Module_Dons|ES:Módulo_Donaciones');
-
-
-print_fiche_titre($langs->trans("Statistics"));
-
-
-$sql = "SELECT d.amount";
-$sql .= " FROM ".MAIN_DB_PREFIX."don as d LEFT JOIN ".MAIN_DB_PREFIX."projet as p";
-$sql .= " ON p.rowid = d.fk_don_projet";
-
-$result = $db->query($sql);
-if ($result)
-{
- $num = $db->num_rows($result);
-
- $var=true;
- $i=0;
- $total=0;
- while ($i < $num)
- {
- $objp = $db->fetch_object($result);
- $total += $objp->amount;
- $i++;
- }
-
- print '
';
-
- print '
'.$langs->trans("Parameter").'
'.$langs->trans("Value").'
';
-
- $var=!$var;
- print "
";
- print '
'.$langs->trans("DonationsNumber").'
'.$num.'
';
- $var=!$var;
- print "
".'
'.$langs->trans("AmountTotal").'
'.price($total).'
';
- $var=!$var;
- print "
".'
'.$langs->trans("Average").'
'.price($total / ($num?$num:1)).'
';
- print "
";
-
- print "
";
-}
-else
-{
- dol_print_error($db);
-}
-
-
-llxFooter();
-
-$db->close();
diff --git a/htdocs/install/mysql/migration/3.7.0-3.8.0.sql b/htdocs/install/mysql/migration/3.7.0-3.8.0.sql
index caf7a474543..c1b999fa052 100755
--- a/htdocs/install/mysql/migration/3.7.0-3.8.0.sql
+++ b/htdocs/install/mysql/migration/3.7.0-3.8.0.sql
@@ -380,6 +380,16 @@ ALTER TABLE llx_don CHANGE COLUMN fk_paiement fk_payment integer;
ALTER TABLE llx_don ADD COLUMN paid smallint default 0 NOT NULL after fk_payment;
ALTER TABLE llx_don CHANGE COLUMN fk_don_projet fk_project integer NULL;
+create table llx_don_extrafields
+(
+ rowid integer AUTO_INCREMENT PRIMARY KEY,
+ tms timestamp,
+ fk_object integer NOT NULL,
+ import_key varchar(14) -- import key
+) ENGINE=innodb;
+
+ALTER TABLE llx_don_extrafields ADD INDEX idx_don_extrafields (fk_object);
+
create table llx_payment_donation
(
rowid integer AUTO_INCREMENT PRIMARY KEY,
diff --git a/htdocs/install/mysql/tables/llx_don_extrafields.key.sql b/htdocs/install/mysql/tables/llx_don_extrafields.key.sql
new file mode 100644
index 00000000000..592df29f8f9
--- /dev/null
+++ b/htdocs/install/mysql/tables/llx_don_extrafields.key.sql
@@ -0,0 +1,20 @@
+-- ===================================================================
+-- Copyright (C) 2015 Alexandre Spangaro
+--
+-- 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 3 of the License, or
+-- (at your option) any later version.
+--
+-- This program is distributed in the hope that it will be useful,
+-- but WITHOUT ANY WARRANTY; without even the implied warranty of
+-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+-- GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License
+-- along with this program. If not, see .
+--
+-- ===================================================================
+
+
+ALTER TABLE llx_don_extrafields ADD INDEX idx_don_extrafields (fk_object);
diff --git a/htdocs/install/mysql/tables/llx_don_extrafields.sql b/htdocs/install/mysql/tables/llx_don_extrafields.sql
new file mode 100644
index 00000000000..b81f31f0c65
--- /dev/null
+++ b/htdocs/install/mysql/tables/llx_don_extrafields.sql
@@ -0,0 +1,26 @@
+-- ========================================================================
+-- Copyright (C) 2015 Alexandre Spangaro
+--
+-- 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 3 of the License, or
+-- (at your option) any later version.
+--
+-- This program is distributed in the hope that it will be useful,
+-- but WITHOUT ANY WARRANTY; without even the implied warranty of
+-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+-- GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License
+-- along with this program. If not, see .
+--
+-- ========================================================================
+
+create table llx_don_extrafields
+(
+ rowid integer AUTO_INCREMENT PRIMARY KEY,
+ tms timestamp,
+ fk_object integer NOT NULL,
+ import_key varchar(14) -- import key
+) ENGINE=innodb;
+