From 1cd81f0e81c2dc779b30c58baed8d824386d93a7 Mon Sep 17 00:00:00 2001 From: aspangaro Date: Mon, 16 Mar 2015 06:29:15 +0100 Subject: [PATCH] Work on module donations --- htdocs/compta/dons/card.php | 282 +++++++++--------- htdocs/compta/dons/class/don.class.php | 85 +++++- htdocs/compta/dons/document.php | 125 ++++++++ htdocs/compta/dons/info.php | 62 ++++ htdocs/core/lib/donation.lib.php | 61 ++++ .../install/mysql/migration/3.7.0-3.8.0.sql | 3 + htdocs/install/mysql/tables/llx_don.sql | 3 +- 7 files changed, 469 insertions(+), 152 deletions(-) create mode 100644 htdocs/compta/dons/document.php create mode 100644 htdocs/compta/dons/info.php create mode 100644 htdocs/core/lib/donation.lib.php diff --git a/htdocs/compta/dons/card.php b/htdocs/compta/dons/card.php index 71e96f60f49..a4e68fbc4de 100644 --- a/htdocs/compta/dons/card.php +++ b/htdocs/compta/dons/card.php @@ -3,6 +3,7 @@ * Copyright (C) 2004-2011 Laurent Destailleur * Copyright (C) 2005-2012 Regis Houssin * Copyright (C) 2013 Florian Henry + * 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 @@ -26,6 +27,7 @@ require '../../main.inc.php'; require_once DOL_DOCUMENT_ROOT.'/core/modules/dons/modules_don.php'; +require_once DOL_DOCUMENT_ROOT.'/core/lib/donation.lib.php'; 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.'/compta/dons/class/don.class.php'; @@ -33,6 +35,7 @@ require_once DOL_DOCUMENT_ROOT.'/compta/paiement/class/paiement.class.php'; if (! empty($conf->projet->enabled)) { require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php'; } +require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php'; $langs->load("companies"); $langs->load("donations"); @@ -43,7 +46,7 @@ $action=GETPOST('action','alpha'); $cancel=GETPOST('cancel'); $amount=GETPOST('amount'); -$don = new Don($db); +$object = new Don($db); $donation_date=dol_mktime(12, 0, 0, GETPOST('remonth'), GETPOST('reday'), GETPOST('reyear')); // Security check @@ -83,28 +86,26 @@ if ($action == 'update') if (! $error) { - $don->fetch($id); + $object->fetch($id); - $don->firstname = $_POST["firstname"]; - $don->lastname = $_POST["lastname"]; - $don->societe = $_POST["societe"]; - $don->address = $_POST["address"]; - $don->amount = price2num($_POST["amount"]); - $don->town = $_POST["town"]; - $don->zip = $_POST["zipcode"]; - $don->country = $_POST["country"]; - $don->email = $_POST["email"]; - $don->date = $donation_date; - $don->note = $_POST["note"]; - $don->public = $_POST["public"]; - $don->fk_project = $_POST["projectid"]; - $don->note_private= GETPOST("note_private"); - $don->note_public = GETPOST("note_public"); - $don->modepaiementid = $_POST["modepaiement"]; + $object->firstname = GETPOST("firstname"); + $object->lastname = GETPOST("lastname"); + $object->societe = GETPOST("societe"); + $object->address = GETPOST("address"); + $object->amount = price2num(GETPOST("amount")); + $object->town = GETPOST("town"); + $object->zip = GETPOST("zipcode"); + $object->country_id = GETPOST('country_id', 'int'); + $object->email = GETPOST("email"); + $object->date = $donation_date; + $object->public = GETPOST("public"); + $object->fk_project = GETPOST("projectid"); + $object->note_private= GETPOST("note_private"); + $object->note_public = GETPOST("note_public"); - if ($don->update($user) > 0) + if ($object->update($user) > 0) { - header("Location: ".$_SERVER['PHP_SELF']."?id=".$don->id); + header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id); exit; } } @@ -136,24 +137,23 @@ if ($action == 'add') if (! $error) { - $don->firstname = $_POST["firstname"]; - $don->lastname = $_POST["lastname"]; - $don->societe = $_POST["societe"]; - $don->address = $_POST["address"]; - $don->amount = price2num($_POST["amount"]); - $don->town = $_POST["town"]; - $don->zip = $_POST["zipcode"]; - $don->town = $_POST["town"]; - $don->country = $_POST["country"]; - $don->email = $_POST["email"]; - $don->date = $donation_date; - $don->note_private= GETPOST("note_private"); - $don->note_public = GETPOST("note_public"); - $don->public = $_POST["public"]; - $don->fk_project = $_POST["projectid"]; - $don->modepaiementid = $_POST["modepaiement"]; + $object->firstname = GETPOST("firstname"); + $object->lastname = GETPOST("lastname"); + $object->societe = GETPOST("societe"); + $object->address = GETPOST("address"); + $object->amount = price2num(GETPOST("amount")); + $object->town = GETPOST("town"); + $object->zip = GETPOST("zipcode"); + $object->town = GETPOST("town"); + $object->country_id = GETPOST('country_id', 'int'); + $object->email = GETPOST("email"); + $object->date = $donation_date; + $object->note_private= GETPOST("note_private"); + $object->note_public = GETPOST("note_public"); + $object->public = GETPOST("public"); + $object->fk_project = GETPOST("projectid"); - if ($don->create($user) > 0) + if ($object->create($user) > 0) { header("Location: index.php"); exit; @@ -163,57 +163,57 @@ if ($action == 'add') if ($action == 'delete') { - $don->delete($id); + $object->delete($id); header("Location: list.php"); exit; } if ($action == 'commentaire') { - $don->fetch($id); - $don->update_note($_POST["commentaire"]); + $object->fetch($id); + $object->update_note(GETPOST("commentaire")); } if ($action == 'valid_promesse') { - if ($don->valid_promesse($id, $user->id) >= 0) + if ($object->valid_promesse($id, $user->id) >= 0) { header("Location: ".$_SERVER['PHP_SELF']."?id=".$id); exit; } else { - setEventMessage($don->error, 'errors'); + setEventMessage($object->error, 'errors'); } } if ($action == 'set_cancel') { - if ($don->set_cancel($id) >= 0) + if ($object->set_cancel($id) >= 0) { header("Location: ".$_SERVER['PHP_SELF']."?id=".$id); exit; } else { - setEventMessage($don->error, 'errors'); + setEventMessage($object->error, 'errors'); } } if ($action == 'set_paid') { - if ($don->set_paye($id, $modepaiement) >= 0) + if ($object->set_paye($id, $modepaiement) >= 0) { header("Location: ".$_SERVER['PHP_SELF']."?id=".$id); exit; } else { - setEventMessage($don->error, 'errors'); + setEventMessage($object->error, 'errors'); } } if ($action == 'set_encaisse') { - if ($don->set_encaisse($id) >= 0) + if ($object->set_encaisse($id) >= 0) { header("Location: ".$_SERVER['PHP_SELF']."?id=".$id); exit; } else { - setEventMessage($don->error, 'errors'); + setEventMessage($object->error, 'errors'); } } @@ -268,7 +268,7 @@ if ($action == 'create') { print_fiche_titre($langs->trans("AddDonation")); - print '
'; + print ''; print ''; print ''; @@ -278,40 +278,57 @@ if ($action == 'create') if (! empty($conf->projet->enabled)) $nbrows++; // Date - print ''; - print '"; - print ""; - // Amount - print "".''; + print "".''; print '\n"; - print "".''; - print "".''; - print "".''; + print "".''; + print "".''; + print "".''; print "".''; + print ''; // Zip / Town print ''; - print "".''; - print "".''; + // Country + print ''; + + print "".''; - print "\n"; + // Public note + print ''; + print ''; + print ''; + + // Private note + if (empty($user->societe_id)) { + print ''; + print ''; + print ''; + } if (! empty($conf->projet->enabled)) { @@ -320,13 +337,13 @@ if ($action == 'create') // Si module projet actif print "\n"; } // Other attributes $parameters=array('colspan' => ' colspan="1"'); - $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$don,$action); // Note that $action and $object may have been modified by hook + $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook print "
'.$langs->trans("Date").''; + print '
'.$langs->trans("Date").''; $form->select_date($donation_date?$donation_date:-1,'','','','',"add",1,1); print ''.$langs->trans("Comments").' :
'; - print "
'.$langs->trans("Amount").' '.$langs->trans("Currency".$conf->currency).'
'.$langs->trans("Amount").' '.$langs->trans("Currency".$conf->currency).'
'.$langs->trans("PublicDonation").""; print $form->selectyesno("public",isset($_POST["public"])?$_POST["public"]:1,1); print "
'.$langs->trans("Company").'
'.$langs->trans("Firstname").'
'.$langs->trans("Lastname").'
'.$langs->trans("Company").'
'.$langs->trans("Lastname").'
'.$langs->trans("Firstname").'
'.$langs->trans("Address").''; - print '
'.$langs->trans("Zip").' / '.$langs->trans("Town").''; - print $formcompany->select_ziptown((isset($_POST["zipcode"])?$_POST["zipcode"]:$don->zip),'zipcode',array('town','selectcountry_id','state_id'),6); + print $formcompany->select_ziptown((isset($_POST["zipcode"])?$_POST["zipcode"]:$object->zip),'zipcode',array('town','selectcountry_id','state_id'),6); print ' '; - print $formcompany->select_ziptown((isset($_POST["town"])?$_POST["town"]:$don->town),'town',array('zipcode','selectcountry_id','state_id')); + print $formcompany->select_ziptown((isset($_POST["town"])?$_POST["town"]:$object->town),'town',array('zipcode','selectcountry_id','state_id')); print '
'.$langs->trans("Country").'
'.$langs->trans("EMail").'
'; + print $form->select_country(GETPOST('country_id')!=''?GETPOST('country_id'):$object->country_id); + if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1); + print '
'.$langs->trans("EMail").'
".$langs->trans("PaymentMode")."\n"; - $form->select_types_paiements('', 'modepaiement', 'CRDT', 0, 1); - print "
' . $langs->trans('NotePublic') . ''; + + $doleditor = new DolEditor('note_public', $note_public, '', 80, 'dolibarr_notes', 'In', 0, false, true, ROWS_3, 70); + print $doleditor->Create(1); + print '
' . $langs->trans('NotePrivate') . ''; + + $doleditor = new DolEditor('note_private', $note_private, '', 80, 'dolibarr_notes', 'In', 0, false, true, ROWS_3, 70); + print $doleditor->Create(1); + print '
".$langs->trans("Project").""; - $formproject->select_projects('',$_POST["projectid"],"projectid"); + $formproject->select_projects('',GETPOST("projectid"),"projectid"); print "
\n"; print '
   
'; @@ -342,26 +359,21 @@ if ($action == 'create') if (! empty($id) && $action == 'edit') { - $don->fetch($id); - - $h=0; - $head[$h][0] = $_SERVER['PHP_SELF']."?id=".$don->id; - $head[$h][1] = $langs->trans("Card"); - $hselected=$h; - $h++; + $object->fetch($id); + $head = donation_prepare_head($object); dol_fiche_head($head, $hselected, $langs->trans("Donation"), 0, 'generic'); - print ''; + print ''; print ''; print ''; print ''; - print ''; + print ''; // Ref print "".''; print ''; @@ -370,15 +382,11 @@ if (! empty($id) && $action == 'edit') // Date print "".''; - print '"; - print ""; - // Amount - print "".''; + print "".''; print '\n"; $langs->load("companies"); - print "".''; - print "".''; - print "".''; + print "".''; + print "".''; + print "".''; print "".''; + print ''; // Zip / Town print ''; - print "".''; - print "".''; + // Country + print ''; + + print "".''; print "\n"; - print "".''; + print "".''; // Project if (! empty($conf->projet->enabled)) @@ -419,13 +432,13 @@ if (! empty($id) && $action == 'edit') $langs->load('projects'); print ''; } // Other attributes $parameters=array('colspan' => ' colspan="1"'); - $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$don,$action); // Note that $action and $object may have been modified by hook + $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook print "
'.$langs->trans("Ref").''; - print $don->getNomUrl(); + print $object->getNomUrl(); print '
'.$langs->trans("Date").''; - $form->select_date($don->date,'','','','',"update"); + $form->select_date($object->date,'','','','',"update"); print ''.$langs->trans("Comments").' :
'; - print "
'.$langs->trans("Amount").' '.$langs->trans("Currency".$conf->currency).'
'.$langs->trans("Amount").' '.$langs->trans("Currency".$conf->currency).'
'.$langs->trans("PublicDonation").""; print $form->selectyesno("public",1,1); @@ -386,31 +394,36 @@ if (! empty($id) && $action == 'edit') print "
'.$langs->trans("Company").'
'.$langs->trans("Firstname").'
'.$langs->trans("Lastname").'
'.$langs->trans("Company").'
'.$langs->trans("Lastname").'
'.$langs->trans("Firstname").'
'.$langs->trans("Address").''; - print '
'.$langs->trans("Zip").' / '.$langs->trans("Town").''; - print $formcompany->select_ziptown((isset($_POST["zipcode"])?$_POST["zipcode"]:$don->zip),'zipcode',array('town','selectcountry_id','state_id'),6); + print $formcompany->select_ziptown((isset($_POST["zipcode"])?$_POST["zipcode"]:$object->zip),'zipcode',array('town','selectcountry_id','state_id'),6); print ' '; - print $formcompany->select_ziptown((isset($_POST["town"])?$_POST["town"]:$don->town),'town',array('zipcode','selectcountry_id','state_id')); + print $formcompany->select_ziptown((isset($_POST["town"])?$_POST["town"]:$object->town),'town',array('zipcode','selectcountry_id','state_id')); print '
'.$langs->trans("Country").'
'.$langs->trans("EMail").'
'.$langs->trans('Country').''; + print $form->select_country((!empty($object->country_id)?$object->country_id:$mysoc->country_code),'country_id'); + if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1); + print '
'.$langs->trans("EMail").'
".$langs->trans("PaymentMode")."\n"; - if ($don->modepaiementid) $selected = $don->modepaiementid; + if ($object->modepaiementid) $selected = $object->modepaiementid; else $selected = ''; $form->select_types_paiements($selected, 'modepaiement', 'CRDT', 0, 1); print "
'.$langs->trans("Status").''.$don->getLibStatut(4).'
'.$langs->trans("Status").''.$object->getLibStatut(4).'
'.$langs->trans('Project').''; - $formproject->select_projects(-1, (isset($_POST["projectid"])?$_POST["projectid"]:$don->fk_project), 'projectid'); + $formproject->select_projects(-1, (isset($_POST["projectid"])?$_POST["projectid"]:$don->fk_project), 'projectid'); print '
\n"; @@ -445,17 +458,12 @@ if (! empty($id) && $action == 'edit') /* ************************************************************ */ if (! empty($id) && $action != 'edit') { - $result=$don->fetch($id); - - $h=0; - $head[$h][0] = $_SERVER['PHP_SELF']."?id=".$don->id; - $head[$h][1] = $langs->trans("Card"); - $hselected=$h; - $h++; - + $result=$object->fetch($id); + + $head = donation_prepare_head($object); dol_fiche_head($head, $hselected, $langs->trans("Donation"), 0, 'generic'); - print ""; + print ''; print ''; print ''; @@ -466,54 +474,58 @@ if (! empty($id) && $action != 'edit') // Ref print "".''; print ''; // Date print '"; - print ''; - - print "".''; + print "".''; print "\n"; - print "".''; - print "".''; - print "".''; - print "".''; + print "".''; + print "".''; + print "".''; + print "".''; // Zip / Town - print "".''; + print "".''; // Country - print "".''; + print ''; // EMail - print "".''; + print "".''; // Payment mode print "\n"; - print "".''; + print "".''; // Project if (! empty($conf->projet->enabled)) { - print "".''; + print "".''; } // Other attributes $parameters=array('colspan' => ' colspan="1"'); - $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$don,$action); // Note that $action and $object may have been modified by hook + $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook print "
'.$langs->trans("Ref").''; - print $form->showrefnav($don, 'rowid', $linkback, 1, 'rowid', 'ref', ''); + print $form->showrefnav($object, 'rowid', $linkback, 1, 'rowid', 'ref', ''); print '
'.$langs->trans("Date").''; - print dol_print_date($don->date,"day"); + print dol_print_date($object->date,"day"); print "'.$langs->trans("Comments").' :
'; - print nl2br($don->note_private).'
'.$langs->trans("Amount").''.price($don->amount,0,$langs,0,0,-1,$conf->currency).'
'.$langs->trans("Amount").''.price($object->amount,0,$langs,0,0,-1,$conf->currency).'
".$langs->trans("PublicDonation").""; - print yn($don->public); + print yn($object->public); print "
'.$langs->trans("Company").''.$don->societe.'
'.$langs->trans("Firstname").''.$don->firstname.'
'.$langs->trans("Lastname").''.$don->lastname.'
'.$langs->trans("Address").''.dol_nl2br($don->address).'
'.$langs->trans("Company").''.$object->societe.'
'.$langs->trans("Lastname").''.$object->lastname.'
'.$langs->trans("Firstname").''.$object->firstname.'
'.$langs->trans("Address").''.dol_nl2br($object->address).'
'.$langs->trans("Zip").' / '.$langs->trans("Town").''.$don->zip.($don->zip && $don->town?' / ':'').$don->town.'
'.$langs->trans("Zip").' / '.$langs->trans("Town").''.$object->zip.($object->zip && $object->town?' / ':'').$object->town.'
'.$langs->trans("Country").''.$don->country.'
'.$langs->trans('Country').''; + if (! empty($object->country_code)) + { + $img=picto_from_langcode($object->country_code); + print ($img?$img.' ':''); + } + print $object->country; + print '
'.$langs->trans("EMail").''.dol_print_email($don->email).'
'.$langs->trans("EMail").''.dol_print_email($object->email).'
".$langs->trans("PaymentMode").""; - $form->form_modes_reglement(null, $don->modepaiementid,'none'); + $form->form_modes_reglement(null, $object->modepaiementid,'none'); print "
'.$langs->trans("Status").''.$don->getLibStatut(4).'
'.$langs->trans("Status").''.$object->getLibStatut(4).'
'.$langs->trans("Project").''.$don->projet.'
'.$langs->trans("Project").''.$object->projet.'
\n"; print "
\n"; @@ -529,32 +541,32 @@ if (! empty($id) && $action != 'edit') */ print '
'; - print ''; + print ''; - if ($don->statut == 0) + if ($object->statut == 0) { - print ''; + print ''; } - if (($don->statut == 0 || $don->statut == 1) && $resteapayer == 0 && $don->paye == 0) + if (($object->statut == 0 || $object->statut == 1) && $resteapayer == 0 && $object->paye == 0) { - print '"; + print '"; } // TODO Gerer action emettre paiement - if ($don->statut == 1 && $resteapayer > 0) + if ($object->statut == 1 && $resteapayer > 0) { - print '"; + print '"; } - if ($don->statut == 1 && $resteapayer == 0 && $don->paye == 0) + if ($object->statut == 1 && $resteapayer == 0 && $object->paye == 0) { - print '"; + print '"; } if ($user->rights->don->supprimer) { - print '"; + print '"; } else { @@ -569,9 +581,9 @@ if (! empty($id) && $action != 'edit') /* * Documents generes */ - $filename=dol_sanitizeFileName($don->id); + $filename=dol_sanitizeFileName($object->id); $filedir=$conf->don->dir_output . '/' . get_exdir($filename,2); - $urlsource=$_SERVER['PHP_SELF'].'?rowid='.$don->id; + $urlsource=$_SERVER['PHP_SELF'].'?rowid='.$object->id; // $genallowed=($fac->statut == 1 && ($fac->paye == 0 || $user->admin) && $user->rights->facture->creer); // $delallowed=$user->rights->facture->supprimer; $genallowed=1; diff --git a/htdocs/compta/dons/class/don.class.php b/htdocs/compta/dons/class/don.class.php index e5d64eb0d9d..6435e82ed8c 100644 --- a/htdocs/compta/dons/class/don.class.php +++ b/htdocs/compta/dons/class/don.class.php @@ -2,7 +2,8 @@ /* Copyright (C) 2002 Rodolphe Quiedeville * Copyright (C) 2004-2008 Laurent Destailleur * Copyright (C) 2009 Regis Houssin - * Copyright (C) 2014 Florian Henry + * Copyright (C) 2014 Florian Henry + * 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 @@ -20,8 +21,8 @@ /** * \file htdocs/compta/dons/class/don.class.php - * \ingroup don - * \brief Fichier de la classe des dons + * \ingroup Donation + * \brief File of class to manage donations */ require_once DOL_DOCUMENT_ROOT .'/core/class/commonobject.class.php'; @@ -46,6 +47,8 @@ class Don extends CommonObject var $address; var $zip; var $town; + var $country_id; + var $country_code; var $country; var $email; var $public; @@ -326,7 +329,8 @@ class Don extends CommonObject $sql.= ", address"; $sql.= ", zip"; $sql.= ", town"; - $sql.= ", country"; + // $sql.= ", country"; -- Deprecated + $sql.= ", fk_pays"; $sql.= ", public"; $sql.= ", fk_don_projet"; $sql.= ", note_private"; @@ -348,7 +352,7 @@ class Don extends CommonObject $sql.= ", '".$this->db->escape($this->address)."'"; $sql.= ", '".$this->db->escape($this->zip)."'"; $sql.= ", '".$this->db->escape($this->town)."'"; - $sql.= ", '".$this->db->escape($this->country)."'"; // TODO use country_id + $sql.= ", ".$this->country_id; $sql.= ", ".$this->public; $sql.= ", ".($this->fk_project > 0?$this->fk_project:"null"); $sql.= ", ".(!empty($this->note_private)?("'".$this->db->escape($this->note_private)."'"):"NULL"); @@ -409,7 +413,7 @@ class Don extends CommonObject $sql .= ",address='".$this->db->escape($this->address)."'"; $sql .= ",zip='".$this->db->escape($this->zip)."'"; $sql .= ",town='".$this->db->escape($this->town)."'"; - $sql .= ",country='".$this->db->escape($this->country)."'"; // TODO use country_id + $sql .= ",fk_pays = ".$this->country_id; $sql .= ",public=".$this->public; $sql .= ",fk_don_projet=".($this->fk_project>0?$this->fk_project:'null'); $sql .= ",note_private=".(!empty($this->note_private)?("'".$this->db->escape($this->note_private)."'"):"NULL"); @@ -493,12 +497,14 @@ class Don extends CommonObject $sql = "SELECT d.rowid, d.datec, d.tms as datem, d.datedon,"; $sql.= " d.firstname, d.lastname, d.societe, d.amount, d.fk_statut, d.address, d.zip, d.town, "; - $sql.= " d.country, d.public, d.amount, d.fk_paiement, d.note_private, d.note_public, cp.libelle, d.email, d.phone, "; - $sql.= " d.phone_mobile, d.fk_don_projet,"; - $sql.= " p.title as project_label"; + $sql.= " d.fk_pays, d.public, d.amount, d.fk_paiement, d.note_private, d.note_public, cp.libelle, d.email, d.phone, "; + $sql.= " d.phone_mobile, d.fk_don_projet,"; + $sql.= " p.title as project_label,"; + $sql.= " c.code as country_code, c.label as country"; $sql.= " FROM ".MAIN_DB_PREFIX."don as d"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."projet as p ON p.rowid = d.fk_don_projet"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as cp ON cp.id = d.fk_paiement"; + $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as c ON d.fk_pays = c.rowid"; $sql.= " WHERE d.rowid = ".$rowid." AND d.entity = ".$conf->entity; dol_syslog(get_class($this)."::fetch", LOG_DEBUG); @@ -522,7 +528,9 @@ class Don extends CommonObject $this->town = $obj->town; $this->zip = $obj->zip; $this->town = $obj->town; - $this->country = $obj->country; + $this->country_id = $obj->country_id; + $this->country_code = $obj->country_code; + $this->country = $obj->country; $this->email = $obj->email; $this->phone = $obj->phone; $this->phone_mobile = $obj->phone_mobile; @@ -547,10 +555,10 @@ class Don extends CommonObject } /** - * Valide une promesse de don + * Validate a promise of donation * - * @param int $rowid id du don a modifier - * @param int $userid utilisateur qui valide la promesse + * @param int $rowid id of donation + * @param int $userid User who validate the promise * @return int <0 if KO, >0 if OK */ function valid_promesse($rowid, $userid) @@ -644,9 +652,9 @@ class Don extends CommonObject } /** - * Set donation sto status canceled + * Set donation to status canceled * - * @param int $rowid id du don a modifier + * @param int $rowid id of donation * @return int <0 if KO, >0 if OK */ function set_cancel($rowid) @@ -673,7 +681,7 @@ class Don extends CommonObject } /** - * Somme des dons + * Sum of donations * * @param string $param 1=promesses de dons validees , 2=xxx, 3=encaisses * @return int Summ of donations @@ -724,5 +732,50 @@ class Don extends CommonObject if ($withpicto != 2) $result.=$lien.$this->id.$lienfin; return $result; } + + /** + * Information on record + * + * @param int $id Id of record + * @return void + */ + function info($id) + { + $sql = 'SELECT d.rowid, d.datec, d.fk_user_author, d.fk_user_valid,'; + $sql.= ' d.tms'; + $sql.= ' FROM '.MAIN_DB_PREFIX.'don as d'; + $sql.= ' WHERE d.rowid = '.$id; + + dol_syslog(get_class($this).'::info', LOG_DEBUG); + $result = $this->db->query($sql); + + if ($result) + { + if ($this->db->num_rows($result)) + { + $obj = $this->db->fetch_object($result); + $this->id = $obj->rowid; + if ($obj->fk_user_author) + { + $cuser = new User($this->db); + $cuser->fetch($obj->fk_user_author); + $this->user_creation = $cuser; + } + if ($obj->fk_user_valid) + { + $vuser = new User($this->db); + $vuser->fetch($obj->fk_user_valid); + $this->user_modification = $vuser; + } + $this->date_creation = $this->db->jdate($obj->datec); + $this->date_modification = $this->db->jdate($obj->tms); + } + $this->db->free($result); + } + else + { + dol_print_error($this->db); + } + } } diff --git a/htdocs/compta/dons/document.php b/htdocs/compta/dons/document.php new file mode 100644 index 00000000000..d4671097fad --- /dev/null +++ b/htdocs/compta/dons/document.php @@ -0,0 +1,125 @@ + + * + * 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/compta/dons/document.php + * \ingroup Donation + * \brief Page of linked files into donations + */ + +require '../../main.inc.php'; +require_once DOL_DOCUMENT_ROOT.'/compta/dons/class/don.class.php'; +require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; +require_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php'; +require_once DOL_DOCUMENT_ROOT.'/core/lib/donation.lib.php'; +require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php'; + +$langs->load("other"); +$langs->load("donations"); +$langs->load("companies"); +$langs->load("interventions"); + +$id = GETPOST('id','int'); +$ref = GETPOST('ref', 'alpha'); +$action = GETPOST('action','alpha'); +$confirm = GETPOST('confirm','alpha'); + +// Security check +if ($user->societe_id) $socid=$user->societe_id; +$result = restrictedArea($user, 'don', $id, ''); + +// Get parameters +$sortfield = GETPOST('sortfield','alpha'); +$sortorder = GETPOST('sortorder','alpha'); +$page = GETPOST('page','int'); +if ($page == -1) { $page = 0; } +$offset = $conf->liste_limit * $page; +$pageprev = $page - 1; +$pagenext = $page + 1; +if (! $sortorder) $sortorder="ASC"; +if (! $sortfield) $sortfield="name"; + +$object = new Don($db); +$object->fetch($id, $ref); + +$upload_dir = $conf->dons->dir_output.'/'.dol_sanitizeFileName($object->ref); +$modulepart='don'; + + +/* + * Actions + */ + +include_once DOL_DOCUMENT_ROOT . '/core/tpl/document_actions_pre_headers.tpl.php'; + + +/* + * View + */ + +$form = new Form($db); + +llxHeader("","",$langs->trans("Don")); + + +if ($object->id) +{ + $object->fetch_thirdparty(); + + $head=donation_prepare_head($object); + + dol_fiche_head($head, 'documents', $langs->trans("Don"), 0, 'bill'); + + + // Built files list + $filearray=dol_dir_list($upload_dir,"files",0,'','(\.meta|_preview\.png)$',$sortfield,(strtolower($sortorder)=='desc'?SORT_DESC:SORT_ASC),1); + $totalsize=0; + foreach($filearray as $key => $file) + { + $totalsize+=$file['size']; + } + + + print ''; + + $linkback = ''.$langs->trans("BackToList").''; + + // Ref + print ''; + + print ''; + print ''; + print '
'.$langs->trans("Ref").''; + print $form->showrefnav($object, 'id', $linkback, 1, 'rowid', 'ref', ''); + print '
'.$langs->trans("NbOfAttachedFiles").''.count($filearray).'
'.$langs->trans("TotalSizeOfAttachedFiles").''.$totalsize.' '.$langs->trans("bytes").'
'; + + print '
'; + + $modulepart = 'don'; + $permission = $user->rights->don->creer; + $param = '&id=' . $object->id; + include_once DOL_DOCUMENT_ROOT . '/core/tpl/document_actions_post_headers.tpl.php'; + +} +else +{ + print $langs->trans("ErrorUnknown"); +} + +llxFooter(); + +$db->close(); diff --git a/htdocs/compta/dons/info.php b/htdocs/compta/dons/info.php new file mode 100644 index 00000000000..ca2c03878d6 --- /dev/null +++ b/htdocs/compta/dons/info.php @@ -0,0 +1,62 @@ + + * + * 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/compta/dons/info.php + * \ingroup Donation + * \brief Page to show a donation information + */ + +require '../../main.inc.php'; +require_once DOL_DOCUMENT_ROOT.'/core/lib/donation.lib.php'; +require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php'; +require_once DOL_DOCUMENT_ROOT.'/compta/dons/class/don.class.php'; + +$langs->load("donations"); + +// Security check +$id = GETPOST('id','int'); +if ($user->societe_id) $socid=$user->societe_id; +$result = restrictedArea($user, 'don', $id, ''); + + +/* + * View + */ + +llxHeader(); + +if ($id) +{ + $object = new Don($db); + $object->fetch($id); + $object->info($id); + + $head = donation_prepare_head($object); + + dol_fiche_head($head, 'info', $langs->trans("Donation"), 0, 'bill'); + + print '
'; + dol_print_object_info($object); + print '
'; + + print ''; +} + +$db->close(); + +llxFooter(); diff --git a/htdocs/core/lib/donation.lib.php b/htdocs/core/lib/donation.lib.php new file mode 100644 index 00000000000..dcbe2d30e84 --- /dev/null +++ b/htdocs/core/lib/donation.lib.php @@ -0,0 +1,61 @@ + + * + * 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/core/lib/donation.lib.php + * \ingroup Donation + * \brief Library of donation functions + */ + +/** + * Prepare array with list of tabs + * + * @param Donation $object Donation + * @return array Array of tabs to show + */ +function donation_prepare_head($object) +{ + global $langs, $conf; + + $h = 0; + $head = array (); + + $head[$h][0] = DOL_URL_ROOT . '/compta/dons/card.php?id=' . $object->id; + $head[$h][1] = $langs->trans("Card"); + $head[$h][2] = 'card'; + $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'); + + $head[$h][0] = DOL_URL_ROOT . '/compta/dons/document.php?id='.$object->id; + $head[$h][1] = $langs->trans("Documents"); + $head[$h][2] = 'documents'; + $h++; + + $head[$h][0] = DOL_URL_ROOT . '/compta/dons/info.php?id=' . $object->id; + $head[$h][1] = $langs->trans("Info"); + $head[$h][2] = 'info'; + $h++; + + complete_head_from_modules($conf, $langs, $object, $head, $h, 'donation', 'remove'); + + return $head; +} 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 b7475d88f91..d2520973275 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 @@ -370,3 +370,6 @@ INSERT INTO llx_c_incoterms (code, libelle, active) VALUES ('DDP', 'Delivered Du -- Extrafields fk_object must be unique (1-1 relation) ALTER TABLE llx_societe_extrafields DROP INDEX idx_societe_extrafields; ALTER TABLE llx_societe_extrafields ADD UNIQUE INDEX uk_societe_extrafields (fk_object); + +-- Module Donation +ALTER TABLE llx_don ADD COLUMN fk_pays integer NOT NULL after country; diff --git a/htdocs/install/mysql/tables/llx_don.sql b/htdocs/install/mysql/tables/llx_don.sql index 259cac22966..bf434e11518 100644 --- a/htdocs/install/mysql/tables/llx_don.sql +++ b/htdocs/install/mysql/tables/llx_don.sql @@ -36,7 +36,8 @@ create table llx_don address text, zip varchar(30), town varchar(50), - country varchar(50), + country varchar(50), -- Deprecated - Replace with fk_pays + fk_pays integer NOT NULL, email varchar(255), phone varchar(24), phone_mobile varchar(24),