diff --git a/build/rpm/dolibarr_fedora.spec b/build/rpm/dolibarr_fedora.spec index 1a6371b1bf8..c34cd4e9d61 100755 --- a/build/rpm/dolibarr_fedora.spec +++ b/build/rpm/dolibarr_fedora.spec @@ -172,6 +172,7 @@ done >>%{name}.lang %_datadir/dolibarr/htdocs/contrat %_datadir/dolibarr/htdocs/core %_datadir/dolibarr/htdocs/cron +%_datadir/dolibarr/htdocs/don %_datadir/dolibarr/htdocs/ecm %_datadir/dolibarr/htdocs/expedition %_datadir/dolibarr/htdocs/expensereport diff --git a/build/rpm/dolibarr_generic.spec b/build/rpm/dolibarr_generic.spec index 59569c2c9fd..c3c3b2a7939 100755 --- a/build/rpm/dolibarr_generic.spec +++ b/build/rpm/dolibarr_generic.spec @@ -252,6 +252,7 @@ done >>%{name}.lang %_datadir/dolibarr/htdocs/contrat %_datadir/dolibarr/htdocs/core %_datadir/dolibarr/htdocs/cron +%_datadir/dolibarr/htdocs/don %_datadir/dolibarr/htdocs/ecm %_datadir/dolibarr/htdocs/expedition %_datadir/dolibarr/htdocs/expensereport diff --git a/build/rpm/dolibarr_mandriva.spec b/build/rpm/dolibarr_mandriva.spec index 0c7050ef049..efe55e2aa7a 100755 --- a/build/rpm/dolibarr_mandriva.spec +++ b/build/rpm/dolibarr_mandriva.spec @@ -169,6 +169,7 @@ done >>%{name}.lang %_datadir/dolibarr/htdocs/contrat %_datadir/dolibarr/htdocs/core %_datadir/dolibarr/htdocs/cron +%_datadir/dolibarr/htdocs/don %_datadir/dolibarr/htdocs/ecm %_datadir/dolibarr/htdocs/expedition %_datadir/dolibarr/htdocs/expensereport diff --git a/build/rpm/dolibarr_opensuse.spec b/build/rpm/dolibarr_opensuse.spec index 34833025e81..6a86f9e3ffa 100755 --- a/build/rpm/dolibarr_opensuse.spec +++ b/build/rpm/dolibarr_opensuse.spec @@ -180,6 +180,7 @@ done >>%{name}.lang %_datadir/dolibarr/htdocs/contrat %_datadir/dolibarr/htdocs/core %_datadir/dolibarr/htdocs/cron +%_datadir/dolibarr/htdocs/don %_datadir/dolibarr/htdocs/ecm %_datadir/dolibarr/htdocs/expedition %_datadir/dolibarr/htdocs/expensereport diff --git a/htdocs/compta/bank/account.php b/htdocs/compta/bank/account.php index c84909cb216..20ef8bcc3cc 100644 --- a/htdocs/compta/bank/account.php +++ b/htdocs/compta/bank/account.php @@ -6,7 +6,7 @@ * Copyright (C) 2005-2012 Regis Houssin * Copyright (C) 2010-2011 Juanjo Menent * Copyright (C) 2012-2014 Marcos GarcĂ­a - * Copyright (C) 2011-2014 Alexandre Spangaro + * Copyright (C) 2011-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 @@ -37,6 +37,7 @@ require_once DOL_DOCUMENT_ROOT.'/compta/sociales/class/chargesociales.class.php' require_once DOL_DOCUMENT_ROOT.'/compta/paiement/class/paiement.class.php'; require_once DOL_DOCUMENT_ROOT.'/compta/tva/class/tva.class.php'; require_once DOL_DOCUMENT_ROOT.'/compta/salaries/class/paymentsalary.class.php'; +require_once DOL_DOCUMENT_ROOT.'/don/class/don.class.php'; require_once DOL_DOCUMENT_ROOT.'/loan/class/loan.class.php'; require_once DOL_DOCUMENT_ROOT.'/fourn/class/paiementfourn.class.php'; require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php'; @@ -46,6 +47,7 @@ $langs->load("categories"); $langs->load("bills"); $langs->load("companies"); $langs->load("loan"); +$langs->load("donations"); $id = (GETPOST('id','int') ? GETPOST('id','int') : GETPOST('account','int')); $ref = GETPOST('ref','alpha'); @@ -156,6 +158,7 @@ $paymentstatic=new Paiement($db); $paymentsupplierstatic=new PaiementFourn($db); $paymentvatstatic=new TVA($db); $paymentsalstatic=new PaymentSalary($db); +$donstatic=new Don($db); $bankstatic=new Account($db); $banklinestatic=new AccountLine($db); @@ -615,6 +618,12 @@ if ($id > 0 || ! empty($ref)) print ' '.img_object($langs->trans('ShowPayment'),'payment').' '; print ''; } + elseif ($links[$key]['type']=='payment_donation') + { + print ''; + print ' '.img_object($langs->trans('ShowPayment'),'payment').' '; + print ''; + } elseif ($links[$key]['type']=='banktransfert') { // Do not show link to transfer since there is no transfer card (avoid confusion). Can already be accessed from transaction detail. diff --git a/htdocs/compta/dons/card.php b/htdocs/compta/dons/card.php deleted file mode 100644 index 71e96f60f49..00000000000 --- a/htdocs/compta/dons/card.php +++ /dev/null @@ -1,593 +0,0 @@ - - * Copyright (C) 2004-2011 Laurent Destailleur - * Copyright (C) 2005-2012 Regis Houssin - * Copyright (C) 2013 Florian Henry - * - * 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/card.php - * \ingroup don - * \brief Page of donation card - */ - -require '../../main.inc.php'; -require_once DOL_DOCUMENT_ROOT.'/core/modules/dons/modules_don.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'; -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'; -} - -$langs->load("companies"); -$langs->load("donations"); -$langs->load("bills"); - -$id=GETPOST('rowid')?GETPOST('rowid','int'):GETPOST('id','int'); -$action=GETPOST('action','alpha'); -$cancel=GETPOST('cancel'); -$amount=GETPOST('amount'); - -$don = new Don($db); -$donation_date=dol_mktime(12, 0, 0, GETPOST('remonth'), GETPOST('reday'), GETPOST('reyear')); - -// Security check -$result = restrictedArea($user, 'don', $id); - -// Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array -$hookmanager->initHooks(array('doncard','globalcard')); - - -/* - * Actions - */ - -if ($action == 'update') -{ - if (! empty($cancel)) - { - header("Location: ".$_SERVER['PHP_SELF']."?id=".$id); - exit; - } - - $error=0; - - if (empty($donation_date)) - { - setEventMessage($langs->trans("ErrorFieldRequired",$langs->trans("Date")), 'errors'); - $action = "create"; - $error++; - } - - if (empty($amount)) - { - setEventMessage($langs->trans("ErrorFieldRequired",$langs->trans("Amount")), 'errors'); - $action = "create"; - $error++; - } - - if (! $error) - { - $don->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"]; - - if ($don->update($user) > 0) - { - header("Location: ".$_SERVER['PHP_SELF']."?id=".$don->id); - exit; - } - } -} - -if ($action == 'add') -{ - if (! empty($cancel)) - { - header("Location: index.php"); - exit; - } - - $error=0; - - if (empty($donation_date)) - { - setEventMessage($langs->trans("ErrorFieldRequired",$langs->trans("Date")), 'errors'); - $action = "create"; - $error++; - } - - if (empty($amount)) - { - setEventMessage($langs->trans("ErrorFieldRequired",$langs->trans("Amount")), 'errors'); - $action = "create"; - $error++; - } - - 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"]; - - if ($don->create($user) > 0) - { - header("Location: index.php"); - exit; - } - } -} - -if ($action == 'delete') -{ - $don->delete($id); - header("Location: list.php"); - exit; -} -if ($action == 'commentaire') -{ - $don->fetch($id); - $don->update_note($_POST["commentaire"]); -} -if ($action == 'valid_promesse') -{ - if ($don->valid_promesse($id, $user->id) >= 0) - { - header("Location: ".$_SERVER['PHP_SELF']."?id=".$id); - exit; - } - else { - setEventMessage($don->error, 'errors'); - } -} -if ($action == 'set_cancel') -{ - if ($don->set_cancel($id) >= 0) - { - header("Location: ".$_SERVER['PHP_SELF']."?id=".$id); - exit; - } - else { - setEventMessage($don->error, 'errors'); - } -} -if ($action == 'set_paid') -{ - if ($don->set_paye($id, $modepaiement) >= 0) - { - header("Location: ".$_SERVER['PHP_SELF']."?id=".$id); - exit; - } - else { - setEventMessage($don->error, 'errors'); - } -} -if ($action == 'set_encaisse') -{ - if ($don->set_encaisse($id) >= 0) - { - header("Location: ".$_SERVER['PHP_SELF']."?id=".$id); - exit; - } - else { - setEventMessage($don->error, 'errors'); - } -} - -/* - * Build doc - */ -if ($action == 'builddoc') -{ - $object = new Don($db); - $object->fetch($id); - - // Save last template used to generate document - if (GETPOST('model')) $object->setDocModel($user, GETPOST('model','alpha')); - - // Define output language - $outputlangs = $langs; - $newlang=''; - if ($conf->global->MAIN_MULTILANGS && empty($newlang) && ! empty($_REQUEST['lang_id'])) $newlang=$_REQUEST['lang_id']; - if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->client->default_lang; - if (! empty($newlang)) - { - $outputlangs = new Translate("",$conf); - $outputlangs->setDefaultLang($newlang); - } - $result=don_create($db, $object->id, '', $object->modelpdf, $outputlangs); - if ($result <= 0) - { - dol_print_error($db,$result); - exit; - } -} - - -/* - * View - */ - -llxHeader('',$langs->trans("Donations"),'EN:Module_Donations|FR:Module_Dons|ES:Módulo_Donaciones'); - -$form=new Form($db); -$formfile = new FormFile($db); -$formcompany = new FormCompany($db); - - -/* ************************************************************************** */ -/* */ -/* Creation */ -/* */ -/* ************************************************************************** */ - -if ($action == 'create') -{ - print_fiche_titre($langs->trans("AddDonation")); - - print '
'; - print ''; - print ''; - - print ''; - - $nbrows=11; - if (! empty($conf->projet->enabled)) $nbrows++; - - // Date - print ''; - - print '"; - print ""; - - // Amount - print "".''; - - print '\n"; - - print "".''; - print "".''; - print "".''; - print "".''; - - // Zip / Town - print ''; - - print "".''; - print "".''; - - print "\n"; - - if (! empty($conf->projet->enabled)) - { - - $formproject=new FormProjets($db); - - // 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 - - 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("PublicDonation").""; - print $form->selectyesno("public",isset($_POST["public"])?$_POST["public"]:1,1); - print "
'.$langs->trans("Company").'
'.$langs->trans("Firstname").'
'.$langs->trans("Lastname").'
'.$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 ' '; - print $formcompany->select_ziptown((isset($_POST["town"])?$_POST["town"]:$don->town),'town',array('zipcode','selectcountry_id','state_id')); - print '
'.$langs->trans("Country").'
'.$langs->trans("EMail").'
".$langs->trans("PaymentMode")."\n"; - $form->select_types_paiements('', 'modepaiement', 'CRDT', 0, 1); - print "
".$langs->trans("Project").""; - $formproject->select_projects('',$_POST["projectid"],"projectid"); - print "
\n"; - print '
   
'; - print "
\n"; -} - - -/* ************************************************************ */ -/* */ -/* Fiche don en mode edition */ -/* */ -/* ************************************************************ */ - -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++; - - dol_fiche_head($head, $hselected, $langs->trans("Donation"), 0, 'generic'); - - print '
'; - print ''; - print ''; - - print ''; - print ''; - - // Ref - print "".''; - print ''; - - $nbrows=12; - if (! empty($conf->projet->enabled)) $nbrows++; - - // Date - print "".''; - - print '"; - print ""; - - // Amount - print "".''; - - print '"; - print "\n"; - - $langs->load("companies"); - print "".''; - print "".''; - print "".''; - print "".''; - - // Zip / Town - print ''; - - print "".''; - print "".''; - - print "\n"; - - print "".''; - - // Project - if (! empty($conf->projet->enabled)) - { - $formproject=new FormProjets($db); - - $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 - - print "
'.$langs->trans("Ref").''; - print $don->getNomUrl(); - print '
'.$langs->trans("Date").''; - $form->select_date($don->date,'','','','',"update"); - print ''.$langs->trans("Comments").' :
'; - print "
'.$langs->trans("Amount").' '.$langs->trans("Currency".$conf->currency).'
'.$langs->trans("PublicDonation").""; - print $form->selectyesno("public",1,1); - print "
'.$langs->trans("Company").'
'.$langs->trans("Firstname").'
'.$langs->trans("Lastname").'
'.$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 ' '; - print $formcompany->select_ziptown((isset($_POST["town"])?$_POST["town"]:$don->town),'town',array('zipcode','selectcountry_id','state_id')); - print '
'.$langs->trans("Country").'
'.$langs->trans("EMail").'
".$langs->trans("PaymentMode")."\n"; - - if ($don->modepaiementid) $selected = $don->modepaiementid; - else $selected = ''; - - $form->select_types_paiements($selected, 'modepaiement', 'CRDT', 0, 1); - print "
'.$langs->trans("Status").''.$don->getLibStatut(4).'
'.$langs->trans('Project').''; - $formproject->select_projects(-1, (isset($_POST["projectid"])?$_POST["projectid"]:$don->fk_project), 'projectid'); - print '
\n"; - - print '
   
'; - - print "
\n"; - - print "\n"; -} - - - -/* ************************************************************ */ -/* */ -/* Fiche don en mode visu */ -/* */ -/* ************************************************************ */ -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++; - - dol_fiche_head($head, $hselected, $langs->trans("Donation"), 0, 'generic'); - - print "
"; - print ''; - print ''; - - $linkback = ''.$langs->trans("BackToList").''; - - $nbrows=12; - if (! empty($conf->projet->enabled)) $nbrows++; - - // Ref - print "".''; - print ''; - - // Date - print '"; - - print ''; - - print "".''; - - print "\n"; - - print "".''; - print "".''; - print "".''; - print "".''; - - // Zip / Town - print "".''; - - // Country - print "".''; - - // EMail - print "".''; - - // Payment mode - print "\n"; - - print "".''; - - // Project - if (! empty($conf->projet->enabled)) - { - 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 - - print "
'.$langs->trans("Ref").''; - print $form->showrefnav($don, 'rowid', $linkback, 1, 'rowid', 'ref', ''); - print '
'.$langs->trans("Date").''; - print dol_print_date($don->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("PublicDonation").""; - print yn($don->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("Zip").' / '.$langs->trans("Town").''.$don->zip.($don->zip && $don->town?' / ':'').$don->town.'
'.$langs->trans("Country").''.$don->country.'
'.$langs->trans("EMail").''.dol_print_email($don->email).'
".$langs->trans("PaymentMode").""; - $form->form_modes_reglement(null, $don->modepaiementid,'none'); - print "
'.$langs->trans("Status").''.$don->getLibStatut(4).'
'.$langs->trans("Project").''.$don->projet.'
\n"; - print "
\n"; - - print ""; - - // TODO Gerer action emettre paiement - $resteapayer = 0; - - - /** - * Barre d'actions - */ - print '
'; - - print ''; - - if ($don->statut == 0) - { - print ''; - } - - if (($don->statut == 0 || $don->statut == 1) && $resteapayer == 0 && $don->paye == 0) - { - print '"; - } - - // TODO Gerer action emettre paiement - if ($don->statut == 1 && $resteapayer > 0) - { - print '"; - } - - if ($don->statut == 1 && $resteapayer == 0 && $don->paye == 0) - { - print '"; - } - - if ($user->rights->don->supprimer) - { - print '"; - } - else - { - print '"; - } - - print "
"; - - - print ''; - - print '
'; - - /* - * Documents generes - */ - $filename=dol_sanitizeFileName($don->id); - $filedir=$conf->don->dir_output . '/' . get_exdir($filename,2); - $urlsource=$_SERVER['PHP_SELF'].'?rowid='.$don->id; - // $genallowed=($fac->statut == 1 && ($fac->paye == 0 || $user->admin) && $user->rights->facture->creer); - // $delallowed=$user->rights->facture->supprimer; - $genallowed=1; - $delallowed=0; - - $var=true; - - print '
'; - $formfile->show_documents('donation',$filename,$filedir,$urlsource,$genallowed,$delallowed); - - print '
 
'; - -} - - -llxFooter(); -$db->close(); diff --git a/htdocs/compta/dons/stats.php b/htdocs/compta/dons/stats.php deleted file mode 100644 index 1fbde7c0ce7..00000000000 --- a/htdocs/compta/dons/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/compta/dons/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 ''; - - $var=!$var; - print ""; - print ''; - $var=!$var; - print "".''; - $var=!$var; - print "".''; - print ""; - - print "
'.$langs->trans("Parameter").''.$langs->trans("Value").'
'.$langs->trans("DonationsNumber").''.$num.'
'.$langs->trans("AmountTotal").''.price($total).'
'.$langs->trans("Average").''.price($total / ($num?$num:1)).'
"; -} -else -{ - dol_print_error($db); -} - - -llxFooter(); - -$db->close(); diff --git a/htdocs/compta/index.php b/htdocs/compta/index.php index b1d32083a8a..698676829d1 100644 --- a/htdocs/compta/index.php +++ b/htdocs/compta/index.php @@ -127,7 +127,7 @@ if (! empty($conf->fournisseur->enabled) && $user->rights->fournisseur->lire) if (! empty($conf->don->enabled) && $user->rights->don->lire) { $langs->load("donations"); - print '
'; + print ''; print ''; print ''; print ''; @@ -497,7 +497,7 @@ if (! empty($conf->fournisseur->enabled) && $user->rights->fournisseur->facture- // Last donations if (! empty($conf->don->enabled) && $user->rights->societe->lire) { - include_once DOL_DOCUMENT_ROOT.'/compta/dons/class/don.class.php'; + include_once DOL_DOCUMENT_ROOT.'/don/class/don.class.php'; $langs->load("boxes"); $donationstatic=new Don($db); diff --git a/htdocs/compta/resultat/clientfourn.php b/htdocs/compta/resultat/clientfourn.php index 09469329069..a9e14030388 100644 --- a/htdocs/compta/resultat/clientfourn.php +++ b/htdocs/compta/resultat/clientfourn.php @@ -651,7 +651,7 @@ if ($conf->donation->enabled) $var = !$var; print ""; - print "\n"; + print "\n"; if ($modecompta == 'CREANCES-DETTES') print ''; print ''; diff --git a/htdocs/core/lib/donation.lib.php b/htdocs/core/lib/donation.lib.php new file mode 100644 index 00000000000..ed6407b1e84 --- /dev/null +++ b/htdocs/core/lib/donation.lib.php @@ -0,0 +1,90 @@ + + * + * 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 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 . '/don/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 . '/don/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 + * + * @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 . '/don/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 . '/don/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/core/menus/init_menu_auguria.sql b/htdocs/core/menus/init_menu_auguria.sql index c385eaab4bf..ffb33138bcc 100644 --- a/htdocs/core/menus/init_menu_auguria.sql +++ b/htdocs/core/menus/init_menu_auguria.sql @@ -172,10 +172,10 @@ insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, left -- Accountancy - Orders to bill insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->commande->enabled', __HANDLER__, 'left', 1900__+MAX_llx_menu__, 'accountancy', 'orders', 6__+MAX_llx_menu__, '/commande/list.php?leftmenu=orders&viewstatut=3', 'MenuOrdersToBill', 0, 'orders', '$user->rights->commande->lire', '', 0, 3, __ENTITY__); -- Donations -insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->don->enabled', __HANDLER__, 'left', 2000__+MAX_llx_menu__, 'accountancy', 'donations', 6__+MAX_llx_menu__, '/compta/dons/index.php?leftmenu=donations&mainmenu=accountancy', 'Donations', 0, 'donations', '$user->rights->don->lire', '', 2, 4, __ENTITY__); -insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->don->enabled && $leftmenu=="donations"', __HANDLER__, 'left', 2001__+MAX_llx_menu__, 'accountancy', '', 2000__+MAX_llx_menu__, '/compta/dons/card.php?leftmenu=donations&mainmenu=accountancy&action=create', 'NewDonation', 1, 'donations', '$user->rights->don->creer', '', 2, 0, __ENTITY__); -insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->don->enabled && $leftmenu=="donations"', __HANDLER__, 'left', 2002__+MAX_llx_menu__, 'accountancy', '', 2000__+MAX_llx_menu__, '/compta/dons/list.php?leftmenu=donations&mainmenu=accountancy', 'List', 1, 'donations', '$user->rights->don->lire', '', 2, 1, __ENTITY__); ---insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->don->enabled && $leftmenu=="donations"', __HANDLER__, 'left', 2003__+MAX_llx_menu__, 'accountancy', '', 2000__+MAX_llx_menu__, '/compta/dons/stats.php?leftmenu=donations&mainmenu=accountancy', 'Statistics', 1, 'donations', '$user->rights->don->lire', '', 2, 2, __ENTITY__); +insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->don->enabled', __HANDLER__, 'left', 2000__+MAX_llx_menu__, 'accountancy', 'donations', 6__+MAX_llx_menu__, '/don/index.php?leftmenu=donations&mainmenu=accountancy', 'Donations', 0, 'donations', '$user->rights->don->lire', '', 2, 4, __ENTITY__); +insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->don->enabled && $leftmenu=="donations"', __HANDLER__, 'left', 2001__+MAX_llx_menu__, 'accountancy', '', 2000__+MAX_llx_menu__, '/don/card.php?leftmenu=donations&mainmenu=accountancy&action=create', 'NewDonation', 1, 'donations', '$user->rights->don->creer', '', 2, 0, __ENTITY__); +insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->don->enabled && $leftmenu=="donations"', __HANDLER__, 'left', 2002__+MAX_llx_menu__, 'accountancy', '', 2000__+MAX_llx_menu__, '/don/list.php?leftmenu=donations&mainmenu=accountancy', 'List', 1, 'donations', '$user->rights->don->lire', '', 2, 1, __ENTITY__); +-- insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->don->enabled && $leftmenu=="donations"', __HANDLER__, 'left', 2003__+MAX_llx_menu__, 'accountancy', '', 2000__+MAX_llx_menu__, '/don/stats/index.php?leftmenu=donations&mainmenu=accountancy', 'Statistics', 1, 'donations', '$user->rights->don->lire', '', 2, 2, __ENTITY__); -- Special expenses insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->tax->enabled || $conf->salaries->enabled', __HANDLER__, 'left', 2200__+MAX_llx_menu__, 'accountancy', 'tax', 6__+MAX_llx_menu__, '/compta/charges/index.php?leftmenu=tax&mainmenu=accountancy', 'MenuSpecialExpenses', 0, 'compta', '(! empty($conf->tax->enabled) && $user->rights->tax->charges->lire) || (! empty($conf->salaries->enabled) && $user->rights->salaries->read)', '', 0, 6, __ENTITY__); insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->salaries->enabled', __HANDLER__, 'left', 2210__+MAX_llx_menu__, 'accountancy', 'tax_sal', 2200__+MAX_llx_menu__, '/compta/salaries/index.php?leftmenu=tax_salary&mainmenu=accountancy', 'Salaries', 1, 'salaries', '$user->rights->salaries->read', '', 0, 1, __ENTITY__); diff --git a/htdocs/core/menus/standard/eldy.lib.php b/htdocs/core/menus/standard/eldy.lib.php index 32fc9a07aed..9eba6b79dd6 100644 --- a/htdocs/core/menus/standard/eldy.lib.php +++ b/htdocs/core/menus/standard/eldy.lib.php @@ -807,10 +807,10 @@ function print_left_eldy_menu($db,$menu_array_before,$menu_array_after,&$tabMenu if (! empty($conf->don->enabled)) { $langs->load("donations"); - $newmenu->add("/compta/dons/index.php?leftmenu=donations&mainmenu=accountancy",$langs->trans("Donations"), 0, $user->rights->don->lire, '', $mainmenu, 'donations'); - if (empty($leftmenu) || $leftmenu=="donations") $newmenu->add("/compta/dons/card.php?action=create",$langs->trans("NewDonation"), 1, $user->rights->don->creer); - if (empty($leftmenu) || $leftmenu=="donations") $newmenu->add("/compta/dons/list.php",$langs->trans("List"), 1, $user->rights->don->lire); - //if ($leftmenu=="donations") $newmenu->add("/compta/dons/stats.php",$langs->trans("Statistics"), 1, $user->rights->don->lire); + $newmenu->add("/don/index.php?leftmenu=donations&mainmenu=accountancy",$langs->trans("Donations"), 0, $user->rights->don->lire, '', $mainmenu, 'donations'); + if (empty($leftmenu) || $leftmenu=="donations") $newmenu->add("/don/card.php?action=create",$langs->trans("NewDonation"), 1, $user->rights->don->creer); + if (empty($leftmenu) || $leftmenu=="donations") $newmenu->add("/don/list.php",$langs->trans("List"), 1, $user->rights->don->lire); + // if ($leftmenu=="donations") $newmenu->add("/don/stats/index.php",$langs->trans("Statistics"), 1, $user->rights->don->lire); } // Taxes and social contributions diff --git a/htdocs/core/modules/dons/html_cerfafr.modules.php b/htdocs/core/modules/dons/html_cerfafr.modules.php index b4cc2795c1a..8730b1041de 100644 --- a/htdocs/core/modules/dons/html_cerfafr.modules.php +++ b/htdocs/core/modules/dons/html_cerfafr.modules.php @@ -25,7 +25,7 @@ * \brief Form of donation */ require_once DOL_DOCUMENT_ROOT.'/core/modules/dons/modules_don.php'; -require_once DOL_DOCUMENT_ROOT.'/compta/dons/class/don.class.php'; +require_once DOL_DOCUMENT_ROOT.'/don/class/don.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php'; diff --git a/htdocs/core/modules/dons/modules_don.php b/htdocs/core/modules/dons/modules_don.php index 8c894e7fa1f..14045f20d11 100644 --- a/htdocs/core/modules/dons/modules_don.php +++ b/htdocs/core/modules/dons/modules_don.php @@ -21,11 +21,11 @@ /** * \file htdocs/core/modules/dons/modules_don.php - * \ingroup don + * \ingroup donations * \brief File of class to manage donation document generation */ require_once DOL_DOCUMENT_ROOT.'/core/class/commondocgenerator.class.php'; -require_once DOL_DOCUMENT_ROOT.'/compta/dons/class/don.class.php'; +require_once DOL_DOCUMENT_ROOT.'/don/class/don.class.php'; diff --git a/htdocs/core/modules/modDon.class.php b/htdocs/core/modules/modDon.class.php index b1b265146a4..8c7425ceed2 100644 --- a/htdocs/core/modules/modDon.class.php +++ b/htdocs/core/modules/modDon.class.php @@ -2,7 +2,7 @@ /* Copyright (C) 2003-2005 Rodolphe Quiedeville * Copyright (C) 2004-2010 Laurent Destailleur * Copyright (C) 2005-2011 Regis Houssin - * Copyright (C) 2014 Alexandre Spangaro + * 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 @@ -19,10 +19,10 @@ */ /** - * \defgroup don Module donation + * \defgroup don Module donations * \brief Module to manage the follow-up of the donations * \file htdocs/core/modules/modDon.class.php - * \ingroup don + * \ingroup donations * \brief Description and activation file for module Donation */ @@ -64,7 +64,7 @@ class modDon extends DolibarrModules $this->requiredby = array(); // Config pages - $this->config_page_url = array("dons.php"); + $this->config_page_url = array("donation.php@don"); // Constants $this->const = array (); @@ -146,8 +146,8 @@ class modDon extends DolibarrModules global $conf; $sql = array( - "DELETE FROM ".MAIN_DB_PREFIX."document_model WHERE nom = '".$this->const[0][2]."' AND entity = ".$conf->entity, - "INSERT INTO ".MAIN_DB_PREFIX."document_model (nom, type, entity) VALUES('".$this->const[0][2]."','donation',".$conf->entity.")", + "DELETE FROM ".MAIN_DB_PREFIX."document_model WHERE nom = '".$this->const[0][4]."' AND entity = ".$conf->entity, + "INSERT INTO ".MAIN_DB_PREFIX."document_model (nom, type, entity) VALUES('".$this->const[0][4]."','donation',".$conf->entity.")", ); return $this->_init($sql,$options); @@ -168,4 +168,4 @@ class modDon extends DolibarrModules return $this->_remove($sql,$options); } -} +} \ No newline at end of file diff --git a/htdocs/admin/dons.php b/htdocs/don/admin/donation.php similarity index 94% rename from htdocs/admin/dons.php rename to htdocs/don/admin/donation.php index dcac1079422..af00f2dbbcc 100644 --- a/htdocs/admin/dons.php +++ b/htdocs/don/admin/donation.php @@ -2,7 +2,7 @@ /* Copyright (C) 2005-2010 Laurent Destailleur * Copyright (C) 2012-2013 Juanjo Menent * Copyright (C) 2013 Philippe Grand - * Copyright (C) 2014 Alexandre Spangaro + * 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 @@ -19,13 +19,15 @@ */ /** - * \file htdocs/admin/dons.php - * \ingroup dons - * \brief Page d'administration/configuration du module Dons + * \file htdocs/don/admin/dons.php + * \ingroup donations + * \brief Page to setup the donation module */ -require '../main.inc.php'; +require '../../main.inc.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php'; -require_once DOL_DOCUMENT_ROOT.'/compta/dons/class/don.class.php'; +require_once DOL_DOCUMENT_ROOT.'/core/lib/donation.lib.php'; +require_once DOL_DOCUMENT_ROOT.'/don/class/don.class.php'; +require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php'; $langs->load("admin"); $langs->load("donations"); @@ -173,14 +175,17 @@ else if ($action == 'setart885') { * View */ -$dir = "../core/modules/dons/"; +$dir = "../../core/modules/dons/"; $form=new Form($db); llxHeader('',$langs->trans("DonationsSetup"),'DonConfiguration'); - $linkback=''.$langs->trans("BackToModuleList").''; print_fiche_titre($langs->trans("DonationsSetup"),$linkback,'setup'); +$head = donation_admin_prepare_head(); + +dol_fiche_head($head, 'general', $langs->trans("Donations"), 0, 'payment'); + /* * Params */ @@ -191,7 +196,7 @@ print ''; print ''; print '
'.$langs->trans("SearchADonation").'
 ".$langs->trans("Donation")." name."&search_name=".$obj->firstname." ".$obj->lastname."\">".$obj->name. " ".$obj->firstname." ".$obj->lastname."".$langs->trans("Donation")." name."&search_name=".$obj->firstname." ".$obj->lastname."\">".$obj->name. " ".$obj->firstname." ".$obj->lastname."'.price($obj->amount).''.price($obj->amount).'
'; print ''; -print ''; +print ''; print ''; print "\n"; $var=true; @@ -210,7 +215,7 @@ print ''; /* * French params */ -if ($conf->global->MAIN_LANG_DEFAULT == "fr_FR") +if (preg_match('/fr/i',$conf->global->MAIN_INFO_SOCIETE_COUNTRY)) { print '
'; print_titre($langs->trans("FrenchOptions")); diff --git a/htdocs/don/admin/donation_extrafields.php b/htdocs/don/admin/donation_extrafields.php new file mode 100644 index 00000000000..2d08c36873f --- /dev/null +++ b/htdocs/don/admin/donation_extrafields.php @@ -0,0 +1,114 @@ + + * + * 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/don/admin/donation_extrafields.php + * \ingroup donations + * \brief Page to setup extra fields of donations + */ + +require '../../main.inc.php'; +require_once DOL_DOCUMENT_ROOT.'/core/lib/donation.lib.php'; +require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; + +$langs->load("companies"); +$langs->load("admin"); +$langs->load('donations'); + +$extrafields = new ExtraFields($db); +$form = new Form($db); + +// List of supported format +$tmptype2label=ExtraFields::$type2label; +$type2label=array(''); +foreach ($tmptype2label as $key => $val) $type2label[$key]=$langs->trans($val); + +$action=GETPOST('action', 'alpha'); +$attrname=GETPOST('attrname', 'alpha'); +$elementtype='don'; //Must be the $table_element of the class that manage extrafield + +if (!$user->admin) accessforbidden(); + + +/* + * Actions + */ + +require DOL_DOCUMENT_ROOT.'/core/actions_extrafields.inc.php'; + + + +/* + * View + */ + +$textobject=$langs->transnoentitiesnoconv("Donations"); + +llxHeader('',$langs->trans("DonationsSetup")); + +$linkback=''.$langs->trans("BackToModuleList").''; +print_fiche_titre($langs->trans("DonationsSetup"),$linkback,'setup'); + + +$head = donation_admin_prepare_head(); + +dol_fiche_head($head, 'attributes', $langs->trans("Donations"), 0, 'payment'); + +require DOL_DOCUMENT_ROOT.'/core/tpl/admin_extrafields_view.tpl.php'; + +dol_fiche_end(); + + +// Buttons +if ($action != 'create' && $action != 'edit') +{ + print '
'; + print ''; + print "
"; +} + + +/* ************************************************************************** */ +/* */ +/* 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/compta/dons/class/index.html b/htdocs/don/admin/index.html similarity index 100% rename from htdocs/compta/dons/class/index.html rename to htdocs/don/admin/index.html diff --git a/htdocs/don/card.php b/htdocs/don/card.php new file mode 100644 index 00000000000..d3ce60a5381 --- /dev/null +++ b/htdocs/don/card.php @@ -0,0 +1,740 @@ + + * 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 + * 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/don/card.php + * \ingroup donations + * \brief Page of donation card + */ + +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.'/don/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'; +} +require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php'; + +$langs->load("companies"); +$langs->load("donations"); +$langs->load("bills"); + +$id=GETPOST('rowid')?GETPOST('rowid','int'):GETPOST('id','int'); +$action=GETPOST('action','alpha'); +$cancel=GETPOST('cancel'); +$amount=GETPOST('amount'); +$donation_date=dol_mktime(12, 0, 0, GETPOST('remonth'), GETPOST('reday'), GETPOST('reyear')); + +$object = new Don($db); +$extrafields = new ExtraFields($db); + +// Security check +$result = restrictedArea($user, 'don', $id); + +// fetch optionals attributes and labels +$extralabels=$extrafields->fetch_name_optionals_label($object->table_element); + +// Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array +$hookmanager->initHooks(array('doncard','globalcard')); + +/* + * Actions + */ +$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some +if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); + +if ($action == 'update') +{ + if (! empty($cancel)) + { + header("Location: ".$_SERVER['PHP_SELF']."?id=".$id); + exit; + } + + $error=0; + + if (empty($donation_date)) + { + setEventMessage($langs->trans("ErrorFieldRequired",$langs->trans("Date")), 'errors'); + $action = "create"; + $error++; + } + + if (empty($amount)) + { + setEventMessage($langs->trans("ErrorFieldRequired",$langs->trans("Amount")), 'errors'); + $action = "create"; + $error++; + } + + if (! $error) + { + $object->fetch($id); + + $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("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) + { + header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id); + exit; + } + } +} + +if ($action == 'add') +{ + if (! empty($cancel)) + { + header("Location: index.php"); + exit; + } + + $error=0; + + if (empty($donation_date)) + { + setEventMessage($langs->trans("ErrorFieldRequired",$langs->trans("Date")), 'errors'); + $action = "create"; + $error++; + } + + if (empty($amount)) + { + setEventMessage($langs->trans("ErrorFieldRequired",$langs->trans("Amount")), 'errors'); + $action = "create"; + $error++; + } + + if (! $error) + { + $object->firstname = GETPOST("firstname"); + $object->lastname = GETPOST("lastname"); + $object->societe = GETPOST("societe"); + $object->address = GETPOST("address"); + $object->amount = price2num(GETPOST("amount")); + $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("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) + { + header("Location: index.php"); + exit; + } + } +} +if ($action == 'confirm_delete' && GETPOST("confirm") == "yes" && $user->rights->don->supprimer) +{ + $object->fetch($id); + $result=$object->delete($user); + if ($result > 0) + { + header("Location: index.php"); + exit; + } + else + { + dol_syslog($object->error,LOG_DEBUG); + setEventMessage($object->error,'errors'); + setEventMessage($object->errors,'errors'); + } +} +if ($action == 'valid_promesse') +{ + if ($object->valid_promesse($id, $user->id) >= 0) + { + header("Location: ".$_SERVER['PHP_SELF']."?id=".$id); + exit; + } + else { + setEventMessage($object->error, 'errors'); + } +} +if ($action == 'set_cancel') +{ + if ($object->set_cancel($id) >= 0) + { + header("Location: ".$_SERVER['PHP_SELF']."?id=".$id); + exit; + } + else { + setEventMessage($object->error, 'errors'); + } +} +if ($action == 'set_paid') +{ + if ($object->set_paid($id, $modepayment) >= 0) + { + header("Location: ".$_SERVER['PHP_SELF']."?id=".$id); + exit; + } + else { + setEventMessage($object->error, 'errors'); + } +} + +/* + * Build doc + */ +if ($action == 'builddoc') +{ + $object = new Don($db); + $object->fetch($id); + + // Save last template used to generate document + if (GETPOST('model')) $object->setDocModel($user, GETPOST('model','alpha')); + + // Define output language + $outputlangs = $langs; + $newlang=''; + if ($conf->global->MAIN_MULTILANGS && empty($newlang) && ! empty($_REQUEST['lang_id'])) $newlang=$_REQUEST['lang_id']; + if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->client->default_lang; + if (! empty($newlang)) + { + $outputlangs = new Translate("",$conf); + $outputlangs->setDefaultLang($newlang); + } + $result=don_create($db, $object->id, '', $object->modelpdf, $outputlangs); + if ($result <= 0) + { + dol_print_error($db,$result); + exit; + } +} + + +/* + * View + */ + +llxHeader('',$langs->trans("Donations"),'EN:Module_Donations|FR:Module_Dons|ES:Módulo_Donaciones'); + +$form=new Form($db); +$formfile = new FormFile($db); +$formcompany = new FormCompany($db); + + +/* ************************************************************************** */ +/* */ +/* Donation card in create mode */ +/* */ +/* ************************************************************************** */ + +if ($action == 'create') +{ + print_fiche_titre($langs->trans("AddDonation")); + + print '
'; + print ''; + print '
'.$langs->trans("Parameter").''.$langs->trans("Parameters").' 
'; + + print ''; + + $nbrows=11; + if (! empty($conf->projet->enabled)) $nbrows++; + + // Date + print ''; + + // Amount + print "".''; + + print '\n"; + + print "".''; + print "".''; + print "".''; + print "".''; + + // Zip / Town + print ''; + + // Country + print ''; + + print "".''; + + // Public note + print ''; + print ''; + print ''; + + // Private note + if (empty($user->societe_id)) { + print ''; + print ''; + print ''; + } + + if (! empty($conf->projet->enabled)) + { + + $formproject=new FormProjets($db); + + print "\n"; + } + + // Other attributes + $parameters=array('colspan' => 3); + $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',$parameters); + } + + print "
'.$langs->trans("Date").''; + $form->select_date($donation_date?$donation_date:-1,'','','','',"add",1,1); + print '
'.$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("Lastname").'
'.$langs->trans("Firstname").'
'.$langs->trans("Address").''; + print '
'.$langs->trans("Zip").' / '.$langs->trans("Town").''; + 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"]:$object->town),'town',array('zipcode','selectcountry_id','state_id')); + print '
'; + 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('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(-1, GETPOST("fk_project"),'fk_project', 0, 1, 0, 1); + print "
\n"; + print '
   
'; + print "\n"; +} + + +/* ************************************************************ */ +/* */ +/* Donation card in edit mode */ +/* */ +/* ************************************************************ */ + +if (! empty($id) && $action == 'edit') +{ + $result=$object->fetch($id); + if ($result < 0) { + dol_print_error($db,$object->error); exit; + } + $result=$object->fetch_optionals($object->id,$extralabels); + if ($result < 0) { + dol_print_error($db); exit; + } + + $head = donation_prepare_head($object); + dol_fiche_head($head, $hselected, $langs->trans("Donation"), 0, 'generic'); + + print '
'; + print ''; + print ''; + + print ''; + print ''; + print ''; + + // Ref + print "".''; + print ''; + + $nbrows=12; + if (! empty($conf->projet->enabled)) $nbrows++; + + // Date + print "".''; + + // Amount + if ($object->statut == 0) + { + print "".''; + } + else + { + print ''; + } + + print '"; + print "\n"; + + $langs->load("companies"); + print "".''; + print "".''; + print "".''; + print "".''; + + // Zip / Town + print ''; + + // Country + print ''; + + print "".''; + + print "\n"; + + print "".''; + + // Project + if (! empty($conf->projet->enabled)) + { + $formproject=new FormProjets($db); + + $langs->load('projects'); + print ''; + } + + // Other attributes + $parameters=array('colspan' => ' colspan="2"'); + $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 "
'.$langs->trans("Ref").''; + print $object->getNomUrl(); + print '
'.$langs->trans("Date").''; + $form->select_date($object->date,'','','','',"update"); + print '
'.$langs->trans("Amount").' '.$langs->trans("Currency".$conf->currency).'
'.$langs->trans("Amount").''; + print price($object->amount,0,$langs,0,0,-1,$conf->currency); + print '
'.$langs->trans("PublicDonation").""; + print $form->selectyesno("public",1,1); + print "
'.$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"]:$object->zip),'zipcode',array('town','selectcountry_id','state_id'),6); + print ' '; + print $formcompany->select_ziptown((isset($_POST["town"])?$_POST["town"]:$object->town),'town',array('zipcode','selectcountry_id','state_id')); + print '
'.$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 ($object->modepaymentid) $selected = $object->modepaymentid; + else $selected = ''; + + $form->select_types_paiements($selected, 'modepayment', 'CRDT', 0, 1); + print "
'.$langs->trans("Status").''.$object->getLibStatut(4).'
'.$langs->trans('Project').''; + $formproject->select_projects(-1, $object->fk_project,'fk_project', 0, 1, 0, 1); + print '
\n"; + + print '
   
'; + + print "
\n"; + + print "\n"; +} + + + +/* ************************************************************ */ +/* */ +/* Donation card in view mode */ +/* */ +/* ************************************************************ */ +if (! empty($id) && $action != 'edit') +{ + // Confirmation delete + if ($action == 'delete') + { + $text=$langs->trans("ConfirmDeleteADonation"); + print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id,$langs->trans("DeleteADonation"),$text,"confirm_delete",'','',1); + } + + $result=$object->fetch($id); + if ($result < 0) { + dol_print_error($db,$object->error); exit; + } + $result=$object->fetch_optionals($object->id,$extralabels); + if ($result < 0) { + dol_print_error($db); exit; + } + + $head = donation_prepare_head($object); + dol_fiche_head($head, $hselected, $langs->trans("Donation"), 0, 'generic'); + + print '
'; + print ''; + print ''; + + $linkback = ''.$langs->trans("BackToList").''; + + $nbrows=12; + if (! empty($conf->projet->enabled)) $nbrows++; + + // Ref + print "".''; + print ''; + + // Date + print '"; + + print ''; + + print ''; + + print ''; + print ''; + print ''; + print ''; + + $rowspan=6; + if (! empty($conf->projet->enabled)) $rowspan++; + print '"; + + print ""; + + // Zip / Town + print ''; + + // Country + print ''; + + // EMail + print "".''; + + // Payment mode + print "\n"; + + print "".''; + + // Project + if (! empty($conf->projet->enabled)) + { + print ''; + print ''; + print ''; + print ''; + } + + // Other attributes + $parameters=array('colspan' => ' colspan="2"'); + $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); + } + + print "
'.$langs->trans("Ref").''; + print $form->showrefnav($object, 'rowid', $linkback, 1, 'rowid', 'ref', ''); + print '
'.$langs->trans("Date").''; + print dol_print_date($object->date,"day"); + print "
'.$langs->trans("Amount").''; + print price($object->amount,0,$langs,0,0,-1,$conf->currency); + print '
'.$langs->trans("PublicDonation").''; + print yn($object->public); + print '
'.$langs->trans("Company").''.$object->societe.'
'.$langs->trans("Lastname").''.$object->lastname.'
'.$langs->trans("Firstname").''.$object->firstname.'
'.$langs->trans("Address").''.dol_nl2br($object->address).''; + + /* + * Payments + */ + $sql = "SELECT p.rowid, p.num_payment, p.datep as dp, p.amount,"; + $sql.= "c.code as type_code,c.libelle as paiement_type"; + $sql.= " FROM ".MAIN_DB_PREFIX."payment_donation as p"; + $sql.= ", ".MAIN_DB_PREFIX."c_paiement as c "; + $sql.= ", ".MAIN_DB_PREFIX."don as d"; + $sql.= " WHERE d.rowid = '".$id."'"; + $sql.= " AND p.fk_donation = d.rowid"; + $sql.= " AND d.entity = ".$conf->entity; + $sql.= " AND p.fk_typepayment = c.id"; + $sql.= " ORDER BY dp"; + + //print $sql; + $resql = $db->query($sql); + if ($resql) + { + $num = $db->num_rows($resql); + $i = 0; $total = 0; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + + $var=True; + while ($i < $num) + { + $objp = $db->fetch_object($resql); + $var=!$var; + print "'; + print '\n"; + $labeltype=$langs->trans("PaymentType".$object->type_code)!=("PaymentType".$object->type_code)?$langs->trans("PaymentType".$object->type_code):$object->paiement_type; + print "\n"; + print '\n"; + print ""; + $totalpaid += $objp->amount; + $i++; + } + + if ($object->paid == 0) + { + print "\n"; + print "\n"; + + $remaintopay = $object->amount - $totalpaid; + + print ""; + print "\n"; + } + print "
'.$langs->trans("RefPayment").''.$langs->trans("Date").''.$langs->trans("Type").''.$langs->trans("Amount").' 
"; + print ''.img_object($langs->trans("Payment"),"payment").' '.$objp->rowid.''.dol_print_date($db->jdate($objp->dp),'day')."".$labeltype.' '.$object->num_paiement."'.price($objp->amount)." ".$langs->trans("Currency".$conf->currency)."
".$langs->trans("AlreadyPaid")." :".price($totalpaid)." ".$langs->trans("Currency".$conf->currency)."
".$langs->trans("AmountExpected")." :".price($object->amount)." ".$langs->trans("Currency".$conf->currency)."
".$langs->trans("RemainderToPay")." :".price($remaintopay)." ".$langs->trans("Currency".$conf->currency)."
"; + $db->free($resql); + } + else + { + dol_print_error($db); + } + print "
'.$langs->trans("Zip").' / '.$langs->trans("Town").''; + print $object->zip.($object->zip && $object->town?' / ':'').$object->town.'
'.$langs->trans('Country').''; + if (! empty($object->country_code)) + { + $img=picto_from_langcode($object->country_code); + print ($img?$img.' ':''); + print $object->country; + } + else + { + print $object->country_olddata; + } + print '
'.$langs->trans("EMail").''.dol_print_email($object->email).'
".$langs->trans("PaymentMode").""; + $form->form_modes_reglement(null, $object->modepaymentid,'none'); + print "
'.$langs->trans("Status").''.$object->getLibStatut(4).'
'.$langs->trans("Project").''.$object->projet.'
\n"; + print "
\n"; + + print ""; + + $remaintopay = $object->amount - $totalpaid; + + /** + * Actions buttons + */ + print '
'; + + print ''; + + if ($object->statut == 0) + { + print ''; + } + + if (($object->statut == 0 || $object->statut == 1) && $remaintopay == 0 && $object->paye == 0) + { + print '"; + } + + // Create payment + if ($object->statut == 1 && $object->paid == 0 && $user->rights->don->creer) + { + if ($remaintopay == 0) + { + print '
' . $langs->trans('DoPayment') . '
'; + } + else + { + print ''; + } + } + + // Classify 'paid' + if ($object->statut == 1 && round($remaintopay) == 0 && $object->paid == 0 && $user->rights->don->creer) + { + print '"; + } + + // Delete + if ($user->rights->don->supprimer) + { + print '"; + } + else + { + print '"; + } + + print "
"; + + + print ''; + + print '
'; + + /* + * Documents generes + */ + $filename=dol_sanitizeFileName($object->id); + $filedir=$conf->don->dir_output . '/' . get_exdir($filename,2); + $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; + $delallowed=0; + + $var=true; + + print '
'; + $formfile->show_documents('donation',$filename,$filedir,$urlsource,$genallowed,$delallowed); + + print '
 
'; + +} + +llxFooter(); +$db->close(); \ No newline at end of file diff --git a/htdocs/compta/dons/class/don.class.php b/htdocs/don/class/don.class.php similarity index 70% rename from htdocs/compta/dons/class/don.class.php rename to htdocs/don/class/don.class.php index c018570a3b0..ce041351eed 100644 --- a/htdocs/compta/dons/class/don.class.php +++ b/htdocs/don/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 @@ -19,9 +20,9 @@ */ /** - * \file htdocs/compta/dons/class/don.class.php - * \ingroup don - * \brief Fichier de la classe des dons + * \file htdocs/don/class/don.class.php + * \ingroup Donation + * \brief File of class to manage donations */ require_once DOL_DOCUMENT_ROOT .'/core/class/commonobject.class.php'; @@ -33,8 +34,10 @@ require_once DOL_DOCUMENT_ROOT .'/core/class/commonobject.class.php'; */ class Don extends CommonObject { - public $element='don'; - public $table_element='don'; + public $element='don'; // Id that identify managed objects + public $table_element='don'; // Name of table without prefix where object is stored + public $fk_element = 'fk_donation'; + protected $ismultientitymanaged = 1; // 0=No test on entity, 1=Test with field entity, 2=Test with link by societe var $id; var $ref; @@ -46,6 +49,8 @@ class Don extends CommonObject var $address; var $zip; var $town; + var $country_id; + var $country_code; var $country; var $email; var $public; @@ -296,14 +301,19 @@ class Don extends CommonObject /** * Create donation record into database * - * @param User $user Objet utilisateur qui cree le don - * @return int Id don cree si ok, <0 si ko + * @param User $user User who created the donation + * @param int $notrigger Disable triggers + * @return int <0 if KO, id of created donation if OK * TODO add numbering module for Ref */ function create($user) { - global $conf; - + global $conf, $langs; + + $error = 0; + $ret = 0; + $now=dol_now(); + // Clean parameters $this->address=($this->address>0?$this->address:$this->address); $this->zip=($this->zip>0?$this->zip:$this->zip); @@ -311,24 +321,23 @@ class Don extends CommonObject $this->country_id=($this->country_id>0?$this->country_id:$this->country_id); $this->country=($this->country?$this->country:$this->country); - $now=dol_now(); - $this->db->begin(); $sql = "INSERT INTO ".MAIN_DB_PREFIX."don ("; $sql.= "datec"; $sql.= ", entity"; $sql.= ", amount"; - $sql.= ", fk_paiement"; + $sql.= ", fk_payment"; $sql.= ", firstname"; $sql.= ", lastname"; $sql.= ", societe"; $sql.= ", address"; $sql.= ", zip"; $sql.= ", town"; - $sql.= ", country"; + // $sql.= ", country"; -- Deprecated + $sql.= ", fk_country"; $sql.= ", public"; - $sql.= ", fk_don_projet"; + $sql.= ", fk_project"; $sql.= ", note_private"; $sql.= ", note_public"; $sql.= ", fk_user_author"; @@ -348,7 +357,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"); @@ -361,24 +370,54 @@ class Don extends CommonObject $sql.= ", '".$this->db->escape($this->phone_mobile)."'"; $sql.= ")"; - dol_syslog("Don::create", LOG_DEBUG); - $result = $this->db->query($sql); - if ($result) + dol_syslog(get_class($this)."::create", LOG_DEBUG); + $resql = $this->db->query($sql); + if ($resql) { - $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."don"); + $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."don"); + $ret = $this->id; - // Call trigger - $result=$this->call_trigger('DON_CREATE',$user); - if ($result < 0) { $error++; $this->db->rollback(); return -1; } - // End call triggers + if (!$notrigger) + { + // Call trigger + $result=$this->call_trigger('DON_CREATE',$user); + if ($result < 0) { $error++; } + // End call triggers + } + } + else + { + $this->error = $this->db->lasterror(); + $this->errno = $this->db->lasterrno(); + $error++; + } + + // Update extrafield + if (!$error) { + if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used + { + $result=$this->insertExtraFields(); + if ($result < 0) + { + $error++; + } + } + } + + if (!$error && !empty($conf->global->MAIN_DISABLEDRAFTSTATUS)) + { + $res = $this->setValid($user); + if ($res < 0) $error++; + } + if (!$error) + { $this->db->commit(); - return $this->id; + return $ret; } else { $this->db->rollback(); - dol_print_error($this->db); return -1; } } @@ -389,8 +428,12 @@ class Don extends CommonObject * @param User $user Objet utilisateur qui met a jour le don * @return int >0 if OK, <0 if KO */ - function update($user) + function update($user, $notrigger=0) { + global $langs, $conf; + + $error=0; + // Clean parameters $this->address=($this->address>0?$this->address:$this->address); $this->zip=($this->zip>0?$this->zip:$this->zip); @@ -402,16 +445,16 @@ class Don extends CommonObject $sql = "UPDATE ".MAIN_DB_PREFIX."don SET "; $sql .= "amount = " . price2num($this->amount); - $sql .= ",fk_paiement = ".($this->modepaiementid?$this->modepaiementid:"null"); + $sql .= ",fk_payment = ".($this->modepaymentid?$this->modepaymentid:"null"); $sql .= ",firstname = '".$this->db->escape($this->firstname)."'"; $sql .= ",lastname='".$this->db->escape($this->lastname)."'"; $sql .= ",societe='".$this->db->escape($this->societe)."'"; $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_country = ".$this->country_id; $sql .= ",public=".$this->public; - $sql .= ",fk_don_projet=".($this->fk_project>0?$this->fk_project:'null'); + $sql .= ",fk_project=".($this->fk_project>0?$this->fk_project:'null'); $sql .= ",note_private=".(!empty($this->note_private)?("'".$this->db->escape($this->note_private)."'"):"NULL"); $sql .= ",note_public=".(!empty($this->note_public)?("'".$this->db->escape($this->note_public)."'"):"NULL"); $sql .= ",datedon='".$this->db->idate($this->date)."'"; @@ -419,63 +462,126 @@ class Don extends CommonObject $sql .= ",phone='".$this->phone."'"; $sql .= ",phone_mobile='".$this->phone_mobile."'"; $sql .= ",fk_statut=".$this->statut; - $sql .= " WHERE rowid = $this->id"; - - dol_syslog("Don::update", LOG_DEBUG); - $result = $this->db->query($sql); - if ($result) - { - // Call trigger - $result=$this->call_trigger('DON_UPDATE',$user); - if ($result < 0) { $error++; $this->db->rollback(); return -1; } - // End call triggers - - $this->db->commit(); - return 1; - } - else - { - $this->db->rollback(); - dol_print_error($this->db); - return -1; - } - } - - /** - * Delete a donation - * - * @param int $rowid Id of donation to delete - * @return int <0 if KO, >0 if OK - */ - function delete($rowid) - { - - $this->db->begin(); - - $sql = "DELETE FROM ".MAIN_DB_PREFIX."don WHERE rowid = $rowid AND fk_statut = 0;"; + $sql .= " WHERE rowid = '".$this->id."'"; + dol_syslog(get_class($this)."::Update", LOG_DEBUG); $resql=$this->db->query($sql); if ($resql) { - if ( $this->db->affected_rows($resql) ) + if (!$notrigger) { - // Call trigger - $result=$this->call_trigger('DON_DELETE',$user); - if ($result < 0) { $error++; $this->db->rollback(); return -1; } + // Call trigger + $result=$this->call_trigger('DON_MODIFY',$user); + if ($result < 0) { $error++; } // End call triggers + } + // Update extrafield + if (!$error) + { + if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used + { + $result=$this->insertExtraFields(); + if ($result < 0) + { + $error++; + } + } + } + + if (! $error ) + { $this->db->commit(); - return 1; + $result = 1; } else { $this->db->rollback(); - return -1; + $result = -1; } } else + { + $this->error = $this->db->lasterror(); + $this->errors[] = $this->error; + $this->db->rollback(); + dol_syslog(get_class($this)."::Update error -2 " . $this->error, LOG_ERR); + $result = -2; + } + return $result; + } + + /** + * Delete a donation from database + * + * @param User $user User + * @param int $notrigger Disable triggers + * @return int <0 if KO, 0 if not possible, >0 if OK + */ + function delete($user, $notrigger=0) + { + global $conf, $langs; + require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php'; + + $error = 0; + + $this->db->begin(); + + // Delete donation + if (! $error) { - dol_print_error($this->db); + $sql = "DELETE FROM " . MAIN_DB_PREFIX . "don"; + $sql.= " WHERE rowid=" . $this->id; + + $resql = $this->db->query($sql); + if (!$resql) + { + $this->errors[] = $this->db->lasterror(); + $error++; + } + } + + if (! $error) + { + $sql = "DELETE FROM " . MAIN_DB_PREFIX . "don_extrafields"; + $sql.= " WHERE fk_object=" . $this->id; + + $resql = $this->db->query($sql); + if (! $resql) + { + $this->errors[] = $this->db->lasterror(); + $error++; + } + } + + if (! $error) + { + if (!$notrigger) + { + // Call trigger + $result=$this->call_trigger('DON_DELETE',$user); + + if ($result < 0) { + $error++; + } + // End call triggers + } + } + + if (! $error) + { + $this->db->commit(); + return 1; + } + else + { + foreach ( $this->errors as $errmsg ) + { + dol_syslog(get_class($this) . "::delete " . $errmsg, LOG_ERR); + $this->error .= ($this->error ? ', ' . $errmsg : $errmsg); + } + dol_syslog(get_class($this) . "::delete " . $this->error, LOG_ERR); + $this->db->rollback(); return -1; } } @@ -487,19 +593,29 @@ class Don extends CommonObject * @param string $ref Ref of donation to load * @return int <0 if KO, >0 if OK */ - function fetch($rowid,$ref='') + function fetch($id,$ref='') { global $conf; $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_country, d.country as country_olddata, d.public, d.amount, d.fk_payment, d.paid, d.note_private, d.note_public, cp.libelle, d.email, d.phone, "; + $sql.= " d.phone_mobile, d.fk_project,"; + $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.= " WHERE d.rowid = ".$rowid." AND d.entity = ".$conf->entity; + $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."projet as p ON p.rowid = d.fk_project"; + $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as cp ON cp.id = d.fk_payment"; + $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as c ON d.fk_country = c.rowid"; + if (! empty($id)) + { + $sql.= " WHERE d.rowid=".$id; + } + else if (! empty($ref)) + { + $sql.= " WHERE ref='".$this->db->escape($ref)."'"; + } + $sql.= " AND d.entity = ".$conf->entity; dol_syslog(get_class($this)."::fetch", LOG_DEBUG); $resql=$this->db->query($sql); @@ -522,19 +638,30 @@ class Don extends CommonObject $this->town = $obj->town; $this->zip = $obj->zip; $this->town = $obj->town; + $this->country_id = $obj->country_id; + $this->country_code = $obj->country_code; $this->country = $obj->country; - $this->email = $obj->email; + $this->country_olddata= $obj->country_olddata; // deprecated + $this->email = $obj->email; $this->phone = $obj->phone; $this->phone_mobile = $obj->phone_mobile; - $this->projet = $obj->project_label; - $this->fk_project = $obj->fk_don_projet; + $this->project = $obj->project_label; + $this->fk_project = $obj->fk_project; $this->public = $obj->public; - $this->modepaiementid = $obj->fk_paiement; - $this->modepaiement = $obj->libelle; + $this->modepaymentid = $obj->fk_payment; + $this->modepayment = $obj->libelle; + $this->paid = $obj->paid; $this->amount = $obj->amount; $this->note_private = $obj->note_private; $this->note_public = $obj->note_public; $this->commentaire = $obj->note; // deprecated + + // Retrieve all extrafield for thirdparty + // fetch optionals attributes and labels + require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; + $extrafields=new ExtraFields($this->db); + $extralabels=$extrafields->fetch_name_optionals_label($this->table_element,true); + $this->fetch_optionals($this->id,$extralabels); } return 1; } @@ -547,16 +674,16 @@ 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) + function valid_promesse($id, $userid) { - $sql = "UPDATE ".MAIN_DB_PREFIX."don SET fk_statut = 1, fk_user_valid = $userid WHERE rowid = $rowid AND fk_statut = 0"; + $sql = "UPDATE ".MAIN_DB_PREFIX."don SET fk_statut = 1, fk_user_valid = ".$userid." WHERE rowid = ".$id." AND fk_statut = 0"; $resql=$this->db->query($sql); if ($resql) @@ -584,14 +711,14 @@ class Don extends CommonObject * @param int $modepaiement mode de paiement * @return int <0 if KO, >0 if OK */ - function set_paye($rowid, $modepaiement='') + function set_paid($id, $modepaiement='') { $sql = "UPDATE ".MAIN_DB_PREFIX."don SET fk_statut = 2"; if ($modepaiement) { - $sql .= ", fk_paiement=$modepaiement"; + $sql .= ", fk_payment=$modepayment"; } - $sql .= " WHERE rowid = $rowid AND fk_statut = 1"; + $sql .= " WHERE rowid = $id AND fk_statut = 1"; $resql=$this->db->query($sql); if ($resql) @@ -612,17 +739,15 @@ class Don extends CommonObject } } - /** - * Classe le don comme encaisse + * 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_encaisse($rowid) + function set_cancel($id) { - - $sql = "UPDATE ".MAIN_DB_PREFIX."don SET fk_statut = 3 WHERE rowid = $rowid AND fk_statut = 2"; + $sql = "UPDATE ".MAIN_DB_PREFIX."don SET fk_statut = -1 WHERE rowid = ".$id; $resql=$this->db->query($sql); if ($resql) @@ -644,36 +769,7 @@ class Don extends CommonObject } /** - * Set donation sto status canceled - * - * @param int $rowid id du don a modifier - * @return int <0 if KO, >0 if OK - */ - function set_cancel($rowid) - { - $sql = "UPDATE ".MAIN_DB_PREFIX."don SET fk_statut = -1 WHERE rowid = ".$rowid; - - $resql=$this->db->query($sql); - if ($resql) - { - if ( $this->db->affected_rows($resql) ) - { - return 1; - } - else - { - return 0; - } - } - else - { - dol_print_error($this->db); - return -1; - } - } - - /** - * Somme des dons + * Sum of donations * * @param string $param 1=promesses de dons validees , 2=xxx, 3=encaisses * @return int Summ of donations @@ -713,7 +809,7 @@ class Don extends CommonObject $result=''; $label=$langs->trans("ShowDonation").': '.$this->id; - $link = ''; + $link = ''; $linkend=''; $picto='generic'; @@ -724,5 +820,50 @@ class Don extends CommonObject if ($withpicto != 2) $result.=$link.$this->id.$linkend; 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/don/class/donstats.class.php b/htdocs/don/class/donstats.class.php new file mode 100644 index 00000000000..63105da07d2 --- /dev/null +++ b/htdocs/don/class/donstats.class.php @@ -0,0 +1,133 @@ + + * 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/don/class/dontats.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 . '/don/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 d"; + //$this->from.= ", ".MAIN_DB_PREFIX."societe as s"; + //$this->field='weight'; // Warning, unit of weight is NOT USED AND MUST BE + $this->where.= " d.fk_statut > 0"; // Not draft and not cancelled + + //$this->where.= " AND c.fk_soc = s.rowid AND c.entity = ".$conf->entity; + $this->where.= " AND d.entity = ".$conf->entity; + if ($this->userid > 0) $this->where.=' WHERE 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(d.datedon,'%m') as dm, COUNT(*) as nb"; + $sql.= " FROM ".$this->from; + $sql.= " WHERE d.datedon 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(d.datedon,'%Y') as dm, COUNT(*) as nb, SUM(d.".$this->field.")"; + $sql.= " FROM ".$this->from; + $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(d.datedon,'%Y') as year, COUNT(*) as nb, SUM(d.".$this->field.") as total, AVG(".$this->field.") as avg"; + $sql.= " FROM ".$this->from; + $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/don/class/index.html b/htdocs/don/class/index.html new file mode 100644 index 00000000000..e69de29bb2d diff --git a/htdocs/don/class/paymentdonation.class.php b/htdocs/don/class/paymentdonation.class.php new file mode 100644 index 00000000000..a6c56f9f235 --- /dev/null +++ b/htdocs/don/class/paymentdonation.class.php @@ -0,0 +1,593 @@ + + * + * 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/don/class/paymentdonation.class.php + * \ingroup Donation + * \brief File of class to manage payment of donations + */ + +require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php'; + + +/** \class PaymentDonation + * \brief Class to manage payments of donations + */ +class PaymentDonation extends CommonObject +{ + public $element='payment_donation'; //!< Id that identify managed objects + public $table_element='payment_donation'; //!< Name of table without prefix where object is stored + + var $id; + var $rowid; + var $ref; + + var $fk_donation; + var $datec=''; + var $tms=''; + var $datep=''; + var $amount; // Total amount of payment + var $amounts=array(); // Array of amounts + var $fk_typepayment; + var $num_payment; + var $note; + var $fk_bank; + var $fk_user_creat; + var $fk_user_modif; + + /** + * Constructor + * + * @param DoliDB $db Database handler + */ + function __construct($db) + { + $this->db = $db; + } + + /** + * Create payment of donation into database. + * Use this->amounts to have list of lines for the payment + * + * @param User $user User making payment + * @return int <0 if KO, id of payment if OK + */ + function create($user) + { + global $conf, $langs; + + $error=0; + + $now=dol_now(); + + // Validate parameters + if (! $this->datepaid) + { + $this->error='ErrorBadValueForParameterCreatePaymentDonation'; + return -1; + } + + // Clean parameters + if (isset($this->fk_donation)) $this->fk_donation=trim($this->fk_donation); + if (isset($this->amount)) $this->amount=trim($this->amount); + if (isset($this->fk_typepayment)) $this->fk_typepayment=trim($this->fk_typepayment); + if (isset($this->num_payment)) $this->num_payment=trim($this->num_payment); + if (isset($this->note)) $this->note=trim($this->note); + if (isset($this->fk_bank)) $this->fk_bank=trim($this->fk_bank); + if (isset($this->fk_user_creat)) $this->fk_user_creat=trim($this->fk_user_creat); + if (isset($this->fk_user_modif)) $this->fk_user_modif=trim($this->fk_user_modif); + + $totalamount = 0; + foreach ($this->amounts as $key => $value) // How payment is dispatch + { + $newvalue = price2num($value,'MT'); + $this->amounts[$key] = $newvalue; + $totalamount += $newvalue; + } + $totalamount = price2num($totalamount); + + // Check parameters + if ($totalamount == 0) return -1; // On accepte les montants negatifs pour les rejets de prelevement mais pas null + + + $this->db->begin(); + + if ($totalamount != 0) + { + $sql = "INSERT INTO ".MAIN_DB_PREFIX."payment_donation (fk_donation, datec, datep, amount,"; + $sql.= " fk_typepayment, num_payment, note, fk_user_creat, fk_bank)"; + $sql.= " VALUES ($this->chid, '".$this->db->idate($now)."',"; + $sql.= " '".$this->db->idate($this->datepaid)."',"; + $sql.= " ".$totalamount.","; + $sql.= " ".$this->paymenttype.", '".$this->db->escape($this->num_payment)."', '".$this->db->escape($this->note)."', ".$user->id.","; + $sql.= " 0)"; + + dol_syslog(get_class($this)."::create", LOG_DEBUG); + $resql=$this->db->query($sql); + if ($resql) + { + $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."payment_donation"); + } + else + { + $error++; + } + + } + + if ($totalamount != 0 && ! $error) + { + $this->amount=$totalamount; + $this->total=$totalamount; // deprecated + $this->db->commit(); + return $this->id; + } + else + { + $this->error=$this->db->error(); + $this->db->rollback(); + return -1; + } + } + + /** + * Load object in memory from database + * + * @param int $id Id object + * @return int <0 if KO, >0 if OK + */ + function fetch($id) + { + global $langs; + $sql = "SELECT"; + $sql.= " t.rowid,"; + $sql.= " t.fk_donation,"; + $sql.= " t.datec,"; + $sql.= " t.tms,"; + $sql.= " t.datep,"; + $sql.= " t.amount,"; + $sql.= " t.fk_typepayment,"; + $sql.= " t.num_payment,"; + $sql.= " t.note,"; + $sql.= " t.fk_bank,"; + $sql.= " t.fk_user_creat,"; + $sql.= " t.fk_user_modif,"; + $sql.= " pt.code as type_code, pt.libelle as type_libelle,"; + $sql.= ' b.fk_account'; + $sql.= " FROM (".MAIN_DB_PREFIX."c_paiement as pt, ".MAIN_DB_PREFIX."payment_donation as t)"; + $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'bank as b ON t.fk_bank = b.rowid'; + $sql.= " WHERE t.rowid = ".$id." AND t.fk_typepayment = pt.id"; + + dol_syslog(get_class($this)."::fetch", LOG_DEBUG); + $resql=$this->db->query($sql); + if ($resql) + { + if ($this->db->num_rows($resql)) + { + $obj = $this->db->fetch_object($resql); + + $this->id = $obj->rowid; + $this->ref = $obj->rowid; + + $this->fk_donation = $obj->fk_donation; + $this->datec = $this->db->jdate($obj->datec); + $this->tms = $this->db->jdate($obj->tms); + $this->datep = $this->db->jdate($obj->datep); + $this->amount = $obj->amount; + $this->fk_typepayment = $obj->fk_typepayment; + $this->num_payment = $obj->num_payment; + $this->note = $obj->note; + $this->fk_bank = $obj->fk_bank; + $this->fk_user_creat = $obj->fk_user_creat; + $this->fk_user_modif = $obj->fk_user_modif; + + $this->type_code = $obj->type_code; + $this->type_libelle = $obj->type_libelle; + + $this->bank_account = $obj->fk_account; + $this->bank_line = $obj->fk_bank; + } + $this->db->free($resql); + + return 1; + } + else + { + $this->error="Error ".$this->db->lasterror(); + return -1; + } + } + + + /** + * Update database + * + * @param User $user User that modify + * @param int $notrigger 0=launch triggers after, 1=disable triggers + * @return int <0 if KO, >0 if OK + */ + function update($user=null, $notrigger=0) + { + global $conf, $langs; + $error=0; + + // Clean parameters + + if (isset($this->fk_donation)) $this->fk_donation=trim($this->fk_donation); + if (isset($this->amount)) $this->amount=trim($this->amount); + if (isset($this->fk_typepayment)) $this->fk_typepayment=trim($this->fk_typepayment); + if (isset($this->num_payment)) $this->num_payment=trim($this->num_payment); + if (isset($this->note)) $this->note=trim($this->note); + if (isset($this->fk_bank)) $this->fk_bank=trim($this->fk_bank); + if (isset($this->fk_user_creat)) $this->fk_user_creat=trim($this->fk_user_creat); + if (isset($this->fk_user_modif)) $this->fk_user_modif=trim($this->fk_user_modif); + + + + // Check parameters + // Put here code to add control on parameters values + + // Update request + $sql = "UPDATE ".MAIN_DB_PREFIX."payment_donation SET"; + + $sql.= " fk_donation=".(isset($this->fk_donation)?$this->fk_donation:"null").","; + $sql.= " datec=".(dol_strlen($this->datec)!=0 ? "'".$this->db->idate($this->datec)."'" : 'null').","; + $sql.= " tms=".(dol_strlen($this->tms)!=0 ? "'".$this->db->idate($this->tms)."'" : 'null').","; + $sql.= " datep=".(dol_strlen($this->datep)!=0 ? "'".$this->db->idate($this->datep)."'" : 'null').","; + $sql.= " amount=".(isset($this->amount)?$this->amount:"null").","; + $sql.= " fk_typepayment=".(isset($this->fk_typepayment)?$this->fk_typepayment:"null").","; + $sql.= " num_payment=".(isset($this->num_payment)?"'".$this->db->escape($this->num_payment)."'":"null").","; + $sql.= " note=".(isset($this->note)?"'".$this->db->escape($this->note)."'":"null").","; + $sql.= " fk_bank=".(isset($this->fk_bank)?$this->fk_bank:"null").","; + $sql.= " fk_user_creat=".(isset($this->fk_user_creat)?$this->fk_user_creat:"null").","; + $sql.= " fk_user_modif=".(isset($this->fk_user_modif)?$this->fk_user_modif:"null").""; + + + $sql.= " WHERE rowid=".$this->id; + + $this->db->begin(); + + dol_syslog(get_class($this)."::update", LOG_DEBUG); + $resql = $this->db->query($sql); + if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); } + + if (! $error) + { + if (! $notrigger) + { + // Uncomment this and change MYOBJECT to your own tag if you + // want this action call a trigger. + + //// Call triggers + //include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; + //$interface=new Interfaces($this->db); + //$result=$interface->run_triggers('MYOBJECT_MODIFY',$this,$user,$langs,$conf); + //if ($result < 0) { $error++; $this->errors=$interface->errors; } + //// End call triggers + } + } + + // Commit or rollback + if ($error) + { + foreach($this->errors as $errmsg) + { + dol_syslog(get_class($this)."::update ".$errmsg, LOG_ERR); + $this->error.=($this->error?', '.$errmsg:$errmsg); + } + $this->db->rollback(); + return -1*$error; + } + else + { + $this->db->commit(); + return 1; + } + } + + + /** + * Delete object in database + * + * @param User $user User that delete + * @param int $notrigger 0=launch triggers after, 1=disable triggers + * @return int <0 if KO, >0 if OK + */ + function delete($user, $notrigger=0) + { + global $conf, $langs; + $error=0; + + $this->db->begin(); + + if (! $error) + { + $sql = "DELETE FROM ".MAIN_DB_PREFIX."bank_url"; + $sql.= " WHERE type='payment_donation' AND url_id=".$this->id; + + dol_syslog(get_class($this)."::delete", LOG_DEBUG); + $resql = $this->db->query($sql); + if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); } + } + + if (! $error) + { + $sql = "DELETE FROM ".MAIN_DB_PREFIX."payment_donation"; + $sql.= " WHERE rowid=".$this->id; + + dol_syslog(get_class($this)."::delete", LOG_DEBUG); + $resql = $this->db->query($sql); + if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); } + } + + if (! $error) + { + if (! $notrigger) + { + // Uncomment this and change MYOBJECT to your own tag if you + // want this action call a trigger. + + //// Call triggers + //include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; + //$interface=new Interfaces($this->db); + //$result=$interface->run_triggers('MYOBJECT_DELETE',$this,$user,$langs,$conf); + //if ($result < 0) { $error++; $this->errors=$interface->errors; } + //// End call triggers + } + } + + // Commit or rollback + if ($error) + { + foreach($this->errors as $errmsg) + { + dol_syslog(get_class($this)."::delete ".$errmsg, LOG_ERR); + $this->error.=($this->error?', '.$errmsg:$errmsg); + } + $this->db->rollback(); + return -1*$error; + } + else + { + $this->db->commit(); + return 1; + } + } + + + + /** + * Load an object from its id and create a new one in database + * + * @param int $fromid Id of object to clone + * @return int New id of clone + */ + function createFromClone($fromid) + { + global $user,$langs; + + $error=0; + + $object=new PaymentDonation($this->db); + + $object->context['createfromclone'] = 'createfromclone'; + + $this->db->begin(); + + // Load source object + $object->fetch($fromid); + $object->id=0; + $object->statut=0; + + // Clear fields + // ... + + // Create clone + $result=$object->create($user); + + // Other options + if ($result < 0) + { + $this->error=$object->error; + $error++; + } + + if (! $error) + { + + + + } + + unset($this->context['createfromclone']); + + // End + if (! $error) + { + $this->db->commit(); + return $object->id; + } + else + { + $this->db->rollback(); + return -1; + } + } + + + /** + * Initialise an instance with random values. + * Used to build previews or test instances. + * id must be 0 if object instance is a specimen. + * + * @return void + */ + function initAsSpecimen() + { + $this->id=0; + + $this->fk_donation=''; + $this->datec=''; + $this->tms=''; + $this->datep=''; + $this->amount=''; + $this->fk_typepayment=''; + $this->num_payment=''; + $this->note=''; + $this->fk_bank=''; + $this->fk_user_creat=''; + $this->fk_user_modif=''; + + + } + + + /** + * Add record into bank for payment with links between this bank record and invoices of payment. + * All payment properties must have been set first like after a call to create(). + * + * @param User $user Object of user making payment + * @param string $mode 'payment_donation' + * @param string $label Label to use in bank record + * @param int $accountid Id of bank account to do link with + * @param string $emetteur_nom Name of transmitter + * @param string $emetteur_banque Name of bank + * @return int <0 if KO, >0 if OK + */ + function addPaymentToBank($user,$mode,$label,$accountid,$emetteur_nom,$emetteur_banque) + { + global $conf; + + $error=0; + + if (! empty($conf->banque->enabled)) + { + require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php'; + + $acc = new Account($this->db); + $acc->fetch($accountid); + + $total=$this->total; + if ($mode == 'payment_donation') $amount=$total; + + // Insert payment into llx_bank + $bank_line_id = $acc->addline( + $this->datepaid, + $this->paymenttype, // Payment mode id or code ("CHQ or VIR for example") + $label, + $amount, + $this->num_payment, + '', + $user, + $emetteur_nom, + $emetteur_banque + ); + + // Update fk_bank in llx_paiement. + // On connait ainsi le paiement qui a genere l'ecriture bancaire + if ($bank_line_id > 0) + { + $result=$this->update_fk_bank($bank_line_id); + if ($result <= 0) + { + $error++; + dol_print_error($this->db); + } + + // Add link 'payment', 'payment_supplier', 'payment_donation' in bank_url between payment and bank transaction + $url=''; + if ($mode == 'payment_donation') $url=DOL_URL_ROOT.'/don/payment/card.php?rowid='; + if ($url) + { + $result=$acc->add_url_line($bank_line_id, $this->id, $url, '(paiement)', $mode); + if ($result <= 0) + { + $error++; + dol_print_error($this->db); + } + } + } + else + { + $this->error=$acc->error; + $error++; + } + } + + if (! $error) + { + return 1; + } + else + { + return -1; + } + } + + + /** + * Update link between the donation payment and the generated line in llx_bank + * + * @param int $id_bank Id if bank + * @return int >0 if OK, <=0 if KO + */ + function update_fk_bank($id_bank) + { + $sql = "UPDATE ".MAIN_DB_PREFIX."payment_donation SET fk_bank = ".$id_bank." WHERE rowid = ".$this->id; + + dol_syslog(get_class($this)."::update_fk_bank", LOG_DEBUG); + $result = $this->db->query($sql); + if ($result) + { + return 1; + } + else + { + $this->error=$this->db->error(); + return 0; + } + } + + /** + * Return clicable name (with picto eventually) + * + * @param int $withpicto 0=No picto, 1=Include picto into link, 2=Only picto + * @param int $maxlen Longueur max libelle + * @return string Chaine avec URL + */ + function getNomUrl($withpicto=0,$maxlen=0) + { + global $langs; + + $result=''; + + if (empty($this->ref)) $this->ref=$this->lib; + $label = $langs->trans("ShowPayment").': '.$this->ref; + + if (!empty($this->id)) + { + $link = ''; + $linkend=''; + + if ($withpicto) $result.=($link.img_object($label, 'payment', 'class="classfortooltip"').$linkend.' '); + if ($withpicto && $withpicto != 2) $result.=' '; + if ($withpicto != 2) $result.=$link.($maxlen?dol_trunc($this->ref,$maxlen):$this->ref).$linkend; + } + + return $result; + } +} \ No newline at end of file diff --git a/htdocs/don/index.html b/htdocs/don/index.html new file mode 100644 index 00000000000..e69de29bb2d diff --git a/htdocs/compta/dons/index.php b/htdocs/don/index.php similarity index 96% rename from htdocs/compta/dons/index.php rename to htdocs/don/index.php index 100380bc128..b276e21dc50 100644 --- a/htdocs/compta/dons/index.php +++ b/htdocs/don/index.php @@ -18,13 +18,13 @@ */ /** - * \file htdocs/compta/dons/index.php - * \ingroup don - * \brief Home page of donation module + * \file htdocs/don/index.php + * \ingroup donations + * \brief Home page of donation module */ -require '../../main.inc.php'; -require_once DOL_DOCUMENT_ROOT.'/compta/dons/class/don.class.php'; +require '../main.inc.php'; +require_once DOL_DOCUMENT_ROOT.'/don/class/don.class.php'; $langs->load("donations"); diff --git a/htdocs/don/info.php b/htdocs/don/info.php new file mode 100644 index 00000000000..04cbae7a587 --- /dev/null +++ b/htdocs/don/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/don/info.php + * \ingroup donations + * \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.'/don/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/compta/dons/list.php b/htdocs/don/list.php similarity index 95% rename from htdocs/compta/dons/list.php rename to htdocs/don/list.php index 95011ca0b74..ee7a6f5e6f9 100644 --- a/htdocs/compta/dons/list.php +++ b/htdocs/don/list.php @@ -19,13 +19,13 @@ */ /** - * \file htdocs/compta/dons/list.php - * \ingroup don - * \brief Page de liste des dons + * \file htdocs/don/list.php + * \ingroup donations + * \brief List of donations */ -require '../../main.inc.php'; -require_once DOL_DOCUMENT_ROOT.'/compta/dons/class/don.class.php'; +require '../main.inc.php'; +require_once DOL_DOCUMENT_ROOT.'/don/class/don.class.php'; if (! empty($conf->projet->enabled)) require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php'; $langs->load("companies"); @@ -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/don/payment/card.php b/htdocs/don/payment/card.php new file mode 100644 index 00000000000..4c59f566ba5 --- /dev/null +++ b/htdocs/don/payment/card.php @@ -0,0 +1,303 @@ + + * + * 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/don/payment/card.php + * \ingroup donations + * \brief Tab payment of a donation + */ + +require '../../main.inc.php'; +require_once DOL_DOCUMENT_ROOT.'/don/class/don.class.php'; +require_once DOL_DOCUMENT_ROOT.'/don/class/paymentdonation.class.php'; +require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php'; +require_once DOL_DOCUMENT_ROOT.'/core/modules/facture/modules_facture.php'; +if (! empty($conf->banque->enabled)) require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php'; + +$langs->load('bills'); +$langs->load('banks'); +$langs->load('companies'); + +// Security check +$id=GETPOST("id"); +$action=GETPOST("action"); +$confirm=GETPOST('confirm'); +if ($user->societe_id) $socid=$user->societe_id; +// TODO Add rule to restrict access payment +//$result = restrictedArea($user, 'facture', $id,''); + +$payment = new PaymentDonation($db); +if ($id > 0) +{ + $result=$payment->fetch($id); + if (! $result) dol_print_error($db,'Failed to get payment id '.$id); +} + + +/* + * Actions + */ + +// Delete payment +if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->don->supprimer) +{ + $db->begin(); + + $result = $payment->delete($user); + if ($result > 0) + { + $db->commit(); + header("Location: ".DOL_URL_ROOT."/don/index.php"); + exit; + } + else + { + setEventMessage($payment->error, 'errors'); + $db->rollback(); + } +} + +// Create payment +if ($action == 'confirm_valide' && $confirm == 'yes' && $user->rights->don->creer) +{ + $db->begin(); + + $result=$payment->valide(); + + if ($result > 0) + { + $db->commit(); + + $factures=array(); // TODO Get all id of invoices linked to this payment + foreach($factures as $id) + { + $fac = new Facture($db); + $fac->fetch($id); + + $outputlangs = $langs; + if (! empty($_REQUEST['lang_id'])) + { + $outputlangs = new Translate("",$conf); + $outputlangs->setDefaultLang($_REQUEST['lang_id']); + } + if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) { + $fac->generateDocument($fac->modelpdf, $outputlangs); + } + } + + header('Location: card.php?id='.$payment->id); + exit; + } + else + { + setEventMessage($payment->error); + $db->rollback(); + } +} + + +/* + * View + */ + +llxHeader(); + +$don = new Don($db); +$form = new Form($db); + +$h=0; + +$head[$h][0] = DOL_URL_ROOT.'/don/payment/card.php?id='.$id; +$head[$h][1] = $langs->trans("Card"); +$hselected = $h; +$h++; + +dol_fiche_head($head, $hselected, $langs->trans("DonationPayment"), 0, 'payment'); + +/* + * Confirmation de la suppression du paiement + */ +if ($action == 'delete') +{ + print $form->formconfirm('card.php?id='.$payment->id, $langs->trans("DeletePayment"), $langs->trans("ConfirmDeletePayment"), 'confirm_delete','',0,2); + +} + +/* + * Confirmation de la validation du paiement + */ +if ($action == 'valide') +{ + $facid = $_GET['facid']; + print $form->formconfirm('card.php?id='.$payment->id.'&facid='.$facid, $langs->trans("ValidatePayment"), $langs->trans("ConfirmValidatePayment"), 'confirm_valide','',0,2); + +} + + +print ''; + +// Ref +print ''; +print ''; + +// Date +print ''; + +// Mode +print ''; + +// Number +print ''; + +// Amount +print ''; + +// Note +print ''; + +// Bank account +if (! empty($conf->banque->enabled)) +{ + if ($payment->bank_account) + { + $bankline=new AccountLine($db); + $bankline->fetch($payment->bank_line); + + print ''; + print ''; + print ''; + print ''; + } +} + +print '
'.$langs->trans('Ref').''; +print $form->showrefnav($payment,'id','',1,'rowid','id'); +print '
'.$langs->trans('Date').''.dol_print_date($payment->datep,'day').'
'.$langs->trans('Mode').''.$langs->trans("PaymentType".$payment->type_code).'
'.$langs->trans('Number').''.$payment->num_payment.'
'.$langs->trans('Amount').''.price($payment->amount, 0, $outputlangs, 1, -1, -1, $conf->currency).'
'.$langs->trans('Note').''.nl2br($payment->note).'
'.$langs->trans('BankTransactionLine').''; + print $bankline->getNomUrl(1,0,'showall'); + print '
'; + + +/* + * List of donations payed + */ + +$disable_delete = 0; +$sql = 'SELECT d.rowid as did, d.paid, d.amount as d_amount, pd.amount'; +$sql.= ' FROM '.MAIN_DB_PREFIX.'payment_donation as pd,'.MAIN_DB_PREFIX.'don as d'; +$sql.= ' WHERE pd.fk_donation = d.rowid'; +$sql.= ' AND d.entity = '.$conf->entity; +$sql.= ' AND pd.rowid = '.$id; + +dol_syslog("donations/payment/card.php", LOG_DEBUG); +$resql=$db->query($sql); +if ($resql) +{ + $num = $db->num_rows($resql); + + $i = 0; + $total = 0; + print '
'; + print ''; + print ''; + print ''; + print ''; + print ''; + print "\n"; + + if ($num > 0) + { + $var=True; + + while ($i < $num) + { + $objp = $db->fetch_object($resql); + + $var=!$var; + print ''; + // Ref + print '\n"; + // Expected to pay + print ''; + // Status + print ''; + // Amount payed + print ''; + print "\n"; + if ($objp->paid == 1) // If at least one invoice is paid, disable delete + { + $disable_delete = 1; + } + $total = $total + $objp->amount; + $i++; + } + } + $var=!$var; + + print "
'.$langs->trans('Donation').''.$langs->trans('ExpectedToPay').''.$langs->trans('Status').''.$langs->trans('PayedByThisPayment').'
'; + $don->fetch($objp->did); + print $don->getNomUrl(1); + print "'.price($objp->d_amount).''.$don->getLibStatut(4,$objp->amount).''.price($objp->amount).'
\n"; + $db->free($resql); +} +else +{ + dol_print_error($db); +} + +print ''; + + +/* + * Boutons Actions + */ +print '
'; + +/* +if (! empty($conf->global->BILL_ADD_PAYMENT_VALIDATION)) +{ + if ($user->societe_id == 0 && $payment->statut == 0 && $_GET['action'] == '') + { + if ($user->rights->facture->paiement) + { + print ''.$langs->trans('Valid').''; + } + } +} +*/ + +if ($_GET['action'] == '') +{ + if ($user->rights->don->supprimer) + { + if (! $disable_delete) + { + print ''.$langs->trans('Delete').''; + } + else + { + print ''.$langs->trans('Delete').''; + } + } +} + +print '
'; + + + +llxFooter(); + +$db->close(); diff --git a/htdocs/don/payment/index.html b/htdocs/don/payment/index.html new file mode 100644 index 00000000000..e69de29bb2d diff --git a/htdocs/don/payment/payment.php b/htdocs/don/payment/payment.php new file mode 100644 index 00000000000..52cf8f38a12 --- /dev/null +++ b/htdocs/don/payment/payment.php @@ -0,0 +1,313 @@ + + * + * 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/don/payment.php + * \ingroup donations + * \brief Page to add payment of a donation + */ + +require '../../main.inc.php'; +require_once DOL_DOCUMENT_ROOT.'/don/class/don.class.php'; +require_once DOL_DOCUMENT_ROOT.'/don/class/paymentdonation.class.php'; +require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php'; + +$langs->load("bills"); + +$chid=GETPOST("rowid"); +$action=GETPOST('action'); +$amounts = array(); + +// Security check +$socid=0; +if ($user->societe_id > 0) +{ + $socid = $user->societe_id; +} + + +/* + * Actions + */ + +if ($action == 'add_payment') +{ + $error=0; + + if ($_POST["cancel"]) + { + $loc = DOL_URL_ROOT.'/don/card.php?rowid='.$chid; + header("Location: ".$loc); + exit; + } + + $datepaid = dol_mktime(12, 0, 0, $_POST["remonth"], $_POST["reday"], $_POST["reyear"]); + + if (! $_POST["paymenttype"] > 0) + { + $mesg = $langs->trans("ErrorFieldRequired",$langs->transnoentities("PaymentMode")); + $error++; + } + if ($datepaid == '') + { + $mesg = $langs->trans("ErrorFieldRequired",$langs->transnoentities("Date")); + $error++; + } + if (! empty($conf->banque->enabled) && ! $_POST["accountid"] > 0) + { + $mesg = $langs->trans("ErrorFieldRequired",$langs->transnoentities("AccountToCredit")); + $error++; + } + + if (! $error) + { + $paymentid = 0; + + // Read possible payments + foreach ($_POST as $key => $value) + { + if (substr($key,0,7) == 'amount_') + { + $other_chid = substr($key,7); + $amounts[$other_chid] = price2num($_POST[$key]); + } + } + + if (count($amounts) <= 0) + { + $error++; + $errmsg='ErrorNoPaymentDefined'; + } + + if (! $error) + { + $db->begin(); + + // Create a line of payments + $payment = new PaymentDonation($db); + $payment->chid = $chid; + $payment->datepaid = $datepaid; + $payment->amounts = $amounts; // Tableau de montant + $payment->paymenttype = $_POST["paymenttype"]; + $payment->num_payment = $_POST["num_payment"]; + $payment->note = $_POST["note"]; + + if (! $error) + { + $paymentid = $payment->create($user); + if ($paymentid < 0) + { + $errmsg=$payment->error; + $error++; + } + } + + if (! $error) + { + $result=$payment->addPaymentToBank($user,'payment_donation','(DonationPayment)',$_POST['accountid'],'',''); + if (! $result > 0) + { + $errmsg=$payment->error; + $error++; + } + } + + if (! $error) + { + $db->commit(); + $loc = DOL_URL_ROOT.'/don/card.php?rowid='.$chid; + header('Location: '.$loc); + exit; + } + else + { + $db->rollback(); + } + } + } + + $_GET["action"]='create'; +} + + +/* + * View + */ + +llxHeader(); + +$form=new Form($db); + + +// Form to create donation payment +if (GETPOST("action") == 'create') +{ + + $don = new Don($db); + $don->fetch($chid); + + $total = $don->amount; + + print_fiche_titre($langs->trans("DoPayment")); + print "
\n"; + + if ($mesg) + { + print "
$mesg
"; + } + + print '
'; + print ''; + print ''; + print ''; + print ''; + + print ''; + + print ''; + + print ''; + print '\n"; + print ''; + + $sql = "SELECT sum(p.amount) as total"; + $sql.= " FROM ".MAIN_DB_PREFIX."payment_donation as p"; + $sql.= " WHERE p.fk_donation = ".$chid; + $resql = $db->query($sql); + if ($resql) + { + $obj=$db->fetch_object($resql); + $sumpaid = $obj->total; + $db->free(); + } + print ''; + print ''; + + print ''; + print "'; + print ''; + + print '"; + print ''; + + print '\n"; + print ''; + + print ''; + print ''; + print ''; + + // Number + print ''; + print ''."\n"; + + print ''; + print ''; + print ''; + print ''; + + print '
'.$langs->trans("Donation").'
'.$langs->trans("Ref").''.$chid.'
'.$langs->trans("Date")."".dol_print_date($don->date,'day')."
'.$langs->trans("Amount")."".price($don->amount,0,$outputlangs,1,-1,-1,$conf->currency).'
'.$langs->trans("AlreadyPaid").''.price($sumpaid,0,$outputlangs,1,-1,-1,$conf->currency).'
'.$langs->trans("RemainderToPay").''.price($total-$sumpaid,0,$outputlangs,1,-1,-1,$conf->currency).'
".$langs->trans("Payment").'
'.$langs->trans("Date").''; + $datepaid = dol_mktime(12, 0, 0, $_POST["remonth"], $_POST["reday"], $_POST["reyear"]); + $datepayment=empty($conf->global->MAIN_AUTOFILL_DATE)?(empty($_POST["remonth"])?-1:$datepaid):0; + $form->select_date($datepayment,'','','','',"add_payment",1,1); + print "
'.$langs->trans("PaymentMode").''; + $form->select_types_paiements(isset($_POST["paymenttype"])?$_POST["paymenttype"]:$don->paymenttype, "paymenttype"); + print "
'.$langs->trans('AccountToCredit').''; + $form->select_comptes(isset($_POST["accountid"])?$_POST["accountid"]:$don->accountid, "accountid", 0, '',1); // Show open bank account list + print '
'.$langs->trans('Numero'); + print ' ('.$langs->trans("ChequeOrTransferNumber").')'; + print '
'.$langs->trans("Comments").'
'; + + print '
'; + + /* + * Autres charges impayees + */ + $num = 1; + $i = 0; + + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print "\n"; + + $var=true; + $total=0; + $totalrecu=0; + + while ($i < $num) + { + $objp = $don; + + $var=!$var; + + print ""; + + print '"; + + print '"; + + print '"; + + print '"; + + print "\n"; + $total+=$objp->total; + $total_ttc+=$objp->total_ttc; + $totalrecu+=$objp->am; + $i++; + } + if ($i > 1) + { + // Print total + print ""; + print ''; + print ""; + print ""; + print ""; + print ''; + print "\n"; + } + + print "
'.$langs->trans("Amount").''.$langs->trans("AlreadyPaid").''.$langs->trans("RemainderToPay").''.$langs->trans("Amount").'
'.price($objp->amount)."'.price($sumpaid)."'.price($objp->amount - $sumpaid)."'; + if ($sumpaid < $objp->amount) + { + $namef = "amount_".$objp->id; + print ''; + } + else + { + print '-'; + } + print "
'.$langs->trans("Total").':".price($total_ttc)."".price($totalrecu)."".price($total_ttc - $totalrecu)." 
"; + + print '
'; + print ''; + print '     '; + print ''; + print '
'; + + print "
\n"; +} + + +$db->close(); + +llxFooter(); diff --git a/htdocs/don/stats/index.php b/htdocs/don/stats/index.php new file mode 100644 index 00000000000..91f4465f376 --- /dev/null +++ b/htdocs/don/stats/index.php @@ -0,0 +1,358 @@ + + * Copyright (C) 2004-2013 Laurent Destailleur + * Copyright (C) 2005-2009 Regis Houssin + * 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 . + */ + +/** + * \file htdocs/don/stats/index.php + * \ingroup donations + * \brief Page with donations statistics + */ + +require '../../main.inc.php'; +require_once DOL_DOCUMENT_ROOT.'/don/class/don.class.php'; +require_once DOL_DOCUMENT_ROOT.'/don/class/donstats.class.php'; +require_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php'; + +$WIDTH=DolGraph::getDefaultGraphSizeForStats('width'); +$HEIGHT=DolGraph::getDefaultGraphSizeForStats('height'); + +$userid=GETPOST('userid','int'); +$socid=GETPOST('socid','int'); +// Security check +if ($user->societe_id > 0) +{ + $action = ''; + $socid = $user->societe_id; +} + +$nowyear=strftime("%Y", dol_now()); +$year = GETPOST('year')>0?GETPOST('year'):$nowyear; +//$startyear=$year-2; +$startyear=$year-1; +$endyear=$year; + +$langs->load("sendings"); +$langs->load("other"); + + +/* + * View + */ + +$form=new Form($db); + +llxHeader(); + +print_fiche_titre($langs->trans("StatisticsOfSendings"), $mesg); + + +dol_mkdir($dir); + +$stats = new DonationStats($db, $socid, $mode, ($userid>0?$userid:0)); + +// Build graphic number of object +$data = $stats->getNbByMonthWithPrevYear($endyear,$startyear); +//var_dump($data);exit; +// $data = array(array('Lib',val1,val2,val3),...) + + +if (!$user->rights->societe->client->voir || $user->societe_id) +{ + $filenamenb = $dir.'/shipmentsnbinyear-'.$user->id.'-'.$year.'.png'; + if ($mode == 'customer') $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=shipmentstats&file=shipmentsnbinyear-'.$user->id.'-'.$year.'.png'; + if ($mode == 'supplier') $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=shipmentstatssupplier&file=shipmentsnbinyear-'.$user->id.'-'.$year.'.png'; +} +else +{ + $filenamenb = $dir.'/shipmentsnbinyear-'.$year.'.png'; + if ($mode == 'customer') $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=shipmentstats&file=shipmentsnbinyear-'.$year.'.png'; + if ($mode == 'supplier') $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=shipmentstatssupplier&file=shipmentsnbinyear-'.$year.'.png'; +} + +$px1 = new DolGraph(); +$mesg = $px1->isGraphKo(); +if (! $mesg) +{ + $px1->SetData($data); + $px1->SetPrecisionY(0); + $i=$startyear;$legend=array(); + while ($i <= $endyear) + { + $legend[]=$i; + $i++; + } + $px1->SetLegend($legend); + $px1->SetMaxValue($px1->GetCeilMaxValue()); + $px1->SetMinValue(min(0,$px1->GetFloorMinValue())); + $px1->SetWidth($WIDTH); + $px1->SetHeight($HEIGHT); + $px1->SetYLabel($langs->trans("NbOfSendings")); + $px1->SetShading(3); + $px1->SetHorizTickIncrement(1); + $px1->SetPrecisionY(0); + $px1->mode='depth'; + $px1->SetTitle($langs->trans("NumberOfShipmentsByMonth")); + + $px1->draw($filenamenb,$fileurlnb); +} + +// Build graphic amount of object +/* +$data = $stats->getAmountByMonthWithPrevYear($endyear,$startyear); +//var_dump($data); +// $data = array(array('Lib',val1,val2,val3),...) + +if (!$user->rights->societe->client->voir || $user->societe_id) +{ + $filenameamount = $dir.'/shipmentsamountinyear-'.$user->id.'-'.$year.'.png'; + if ($mode == 'customer') $fileurlamount = DOL_URL_ROOT.'/viewimage.php?modulepart=shipmentstats&file=shipmentsamountinyear-'.$user->id.'-'.$year.'.png'; + if ($mode == 'supplier') $fileurlamount = DOL_URL_ROOT.'/viewimage.php?modulepart=shipmentstatssupplier&file=shipmentsamountinyear-'.$user->id.'-'.$year.'.png'; +} +else +{ + $filenameamount = $dir.'/shipmentsamountinyear-'.$year.'.png'; + if ($mode == 'customer') $fileurlamount = DOL_URL_ROOT.'/viewimage.php?modulepart=shipmentstats&file=shipmentsamountinyear-'.$year.'.png'; + if ($mode == 'supplier') $fileurlamount = DOL_URL_ROOT.'/viewimage.php?modulepart=shipmentstatssupplier&file=shipmentsamountinyear-'.$year.'.png'; +} + +$px2 = new DolGraph(); +$mesg = $px2->isGraphKo(); +if (! $mesg) +{ + $px2->SetData($data); + $i=$startyear;$legend=array(); + while ($i <= $endyear) + { + $legend[]=$i; + $i++; + } + $px2->SetLegend($legend); + $px2->SetMaxValue($px2->GetCeilMaxValue()); + $px2->SetMinValue(min(0,$px2->GetFloorMinValue())); + $px2->SetWidth($WIDTH); + $px2->SetHeight($HEIGHT); + $px2->SetYLabel($langs->trans("AmountOfShipments")); + $px2->SetShading(3); + $px2->SetHorizTickIncrement(1); + $px2->SetPrecisionY(0); + $px2->mode='depth'; + $px2->SetTitle($langs->trans("AmountOfShipmentsByMonthHT")); + + $px2->draw($filenameamount,$fileurlamount); +} +*/ + +/* +$data = $stats->getAverageByMonthWithPrevYear($endyear, $startyear); + +if (!$user->rights->societe->client->voir || $user->societe_id) +{ + $filename_avg = $dir.'/shipmentsaverage-'.$user->id.'-'.$year.'.png'; + if ($mode == 'customer') $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=shipmentstats&file=shipmentsaverage-'.$user->id.'-'.$year.'.png'; + if ($mode == 'supplier') $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=shipmentstatssupplier&file=shipmentsaverage-'.$user->id.'-'.$year.'.png'; +} +else +{ + $filename_avg = $dir.'/shipmentsaverage-'.$year.'.png'; + if ($mode == 'customer') $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=shipmentstats&file=shipmentsaverage-'.$year.'.png'; + if ($mode == 'supplier') $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=shipmentstatssupplier&file=shipmentsaverage-'.$year.'.png'; +} + +$px3 = new DolGraph(); +$mesg = $px3->isGraphKo(); +if (! $mesg) +{ + $px3->SetData($data); + $i=$startyear;$legend=array(); + while ($i <= $endyear) + { + $legend[]=$i; + $i++; + } + $px3->SetLegend($legend); + $px3->SetYLabel($langs->trans("AmountAverage")); + $px3->SetMaxValue($px3->GetCeilMaxValue()); + $px3->SetMinValue($px3->GetFloorMinValue()); + $px3->SetWidth($WIDTH); + $px3->SetHeight($HEIGHT); + $px3->SetShading(3); + $px3->SetHorizTickIncrement(1); + $px3->SetPrecisionY(0); + $px3->mode='depth'; + $px3->SetTitle($langs->trans("AmountAverage")); + + $px3->draw($filename_avg,$fileurl_avg); +} +*/ + + +// Show array +$data = $stats->getAllByYear(); +$arrayyears=array(); +foreach($data as $val) { + if (! empty($val['year'])) { + $arrayyears[$val['year']]=$val['year']; + } +} +if (! count($arrayyears)) $arrayyears[$nowyear]=$nowyear; + +$h=0; +$head = array(); +$head[$h][0] = DOL_URL_ROOT . '/don/stats/index.php?mode='.$mode; +$head[$h][1] = $langs->trans("ByMonthYear"); +$head[$h][2] = 'byyear'; +$h++; + +$type='donation_stats'; + +complete_head_from_modules($conf,$langs,null,$head,$h,$type); + +dol_fiche_head($head,'byyear',$langs->trans("Statistics")); + + +print '
'; + + +//if (empty($socid)) +//{ + // Show filter box + print '
'; + print ''; + print ''; + print ''; + // Company + print ''; + // User + print ''; + // Year + print ''; + print ''; + print '
'.$langs->trans("Filter").'
'.$langs->trans("ThirdParty").''; + if ($mode == 'customer') $filter='s.client in (1,2,3)'; + if ($mode == 'supplier') $filter='s.fournisseur = 1'; + print $form->select_company($socid,'socid',$filter,1); + print '
'.$langs->trans("CreatedBy").''; + print $form->select_users($userid,'userid',1); + print '
'.$langs->trans("Year").''; + if (! in_array($year,$arrayyears)) $arrayyears[$year]=$year; + if (! in_array($nowyear,$arrayyears)) $arrayyears[$nowyear]=$nowyear; + arsort($arrayyears); + print $form->selectarray('year',$arrayyears,$year,0); + print '
'; + print '
'; + print '

'; +//} + +print ''; +print ''; +print ''; +print ''; +/*print ''; +print '';*/ +print ''; + +$oldyear=0; +foreach ($data as $val) +{ + $year = $val['year']; + while (! empty($year) && $oldyear > $year+1) + { // If we have empty year + $oldyear--; + print ''; + print ''; + + print ''; + /*print ''; + print '';*/ + print ''; + } + + print ''; + print ''; + print ''; + /*print ''; + print '';*/ + print ''; + $oldyear=$year; +} + +print '
'.$langs->trans("Year").''.$langs->trans("NbOfSendings").''.$langs->trans("AmountTotal").''.$langs->trans("AmountAverage").'
'.$oldyear.'000
'.$year.''.$val['nb'].''.price(price2num($val['total'],'MT'),1).''.price(price2num($val['avg'],'MT'),1).'
'; + + +print '
'; + + +// Show graphs +print '
'; +if ($mesg) { print $mesg; } +else { + print $px1->show(); + print "
\n"; + /*print $px2->show(); + print "
\n"; + print $px3->show();*/ +} +print '
'; + + +print '
'; +print '
'; + +dol_fiche_end(); + + + +// TODO USe code similar to commande/stats/index.php instead of this one. +/* +print ''; +print ''; +print ''; + +$sql = "SELECT count(*) as nb, date_format(date_expedition,'%Y') as dm"; +$sql.= " FROM ".MAIN_DB_PREFIX."expedition"; +$sql.= " WHERE fk_statut > 0"; +$sql.= " AND entity = ".$conf->entity; +$sql.= " GROUP BY dm DESC"; + +$resql=$db->query($sql); +if ($resql) +{ + $num = $db->num_rows($resql); + $i = 0; + while ($i < $num) + { + $row = $db->fetch_row($resql); + $nbproduct = $row[0]; + $year = $row[1]; + print ""; + print ''; + $i++; + } +} +$db->free($resql); + +print '
'.$langs->trans("Year").''.$langs->trans("NbOfSendings").'
'.$year.''.$nbproduct.'
'; +*/ + +print '
'; +print ''.$langs->trans("StatsOnShipmentsOnlyValidated").''; + +llxFooter(); + +$db->close(); diff --git a/htdocs/install/filelist.xml b/htdocs/install/filelist.xml index e9ae4ec5dd1..7b7ed9c36ef 100644 --- a/htdocs/install/filelist.xml +++ b/htdocs/install/filelist.xml @@ -5893,7 +5893,7 @@ d41d8cd98f00b204e9800998ecf8427e 8ea20800d43bbdfdb20363355521c20c - + 9029f09e1592da49626e9fb5b6399e1e d71afb404b4f1946d241bc44ab27df8b 823e0c612e7de62db2d41adf37214bea 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 bf0fb5dcdbd..9475719732d 100644 --- a/htdocs/install/mysql/migration/3.7.0-3.8.0.sql +++ b/htdocs/install/mysql/migration/3.7.0-3.8.0.sql @@ -419,6 +419,37 @@ INSERT INTO llx_c_incoterms (code, libelle, active) VALUES ('DDP', 'Delivered Du 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_country integer NOT NULL after country; +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, + fk_donation integer, + datec datetime, -- date de creation + tms timestamp, + datep datetime, -- payment date + amount real DEFAULT 0, + fk_typepayment integer NOT NULL, + num_payment varchar(50), + note text, + fk_bank integer NOT NULL, + fk_user_creat integer, -- creation user + fk_user_modif integer -- last modification user +)ENGINE=innodb; insert into llx_c_action_trigger (code,label,description,elementtype,rang) values ('BILL_VALIDATE','Customer invoice validated','Executed when a customer invoice is approved','facture',6); insert into llx_c_action_trigger (code,label,description,elementtype,rang) values ('ORDER_SUPPLIER_APPROVE','Supplier order request approved','Executed when a supplier order is approved','order_supplier',12); @@ -460,7 +491,6 @@ insert into llx_c_action_trigger (code,label,description,elementtype,rang) value insert into llx_c_action_trigger (code,label,description,elementtype,rang) values ('TASK_MODIFY','Task modified','Executed when a project task is modified','project',36); insert into llx_c_action_trigger (code,label,description,elementtype,rang) values ('TASK_DELETE','Task deleted','Executed when a project task is deleted','project',37); - create table llx_c_price_global_variable ( rowid integer AUTO_INCREMENT PRIMARY KEY, diff --git a/htdocs/install/mysql/tables/llx_don.sql b/htdocs/install/mysql/tables/llx_don.sql index 259cac22966..d33467f9a7b 100644 --- a/htdocs/install/mysql/tables/llx_don.sql +++ b/htdocs/install/mysql/tables/llx_don.sql @@ -2,6 +2,7 @@ -- Copyright (C) 2001-2002 Rodolphe Quiedeville -- Copyright (C) 2009 Regis Houssin -- Copyright (C) 2011 Laurent Destailleur +-- 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 @@ -25,23 +26,25 @@ create table llx_don ref varchar(30) DEFAULT NULL, -- Ref donation (TODO change to NOT NULL) entity integer DEFAULT 1 NOT NULL, -- multi company id tms timestamp, - fk_statut smallint NOT NULL DEFAULT 0, -- etat du don promesse/valid + fk_statut smallint NOT NULL DEFAULT 0, -- Status of donation promise or validate datec datetime, -- date de creation de l'enregistrement datedon datetime, -- date du don/promesse amount real DEFAULT 0, - fk_paiement integer, + fk_payment integer, + paid smallint default 0 NOT NULL, firstname varchar(50), lastname varchar(50), societe varchar(50), address text, zip varchar(30), town varchar(50), - country varchar(50), + country varchar(50), -- Deprecated - Replace with fk_country + fk_country integer NOT NULL, email varchar(255), phone varchar(24), phone_mobile varchar(24), - public smallint DEFAULT 1 NOT NULL, -- le don est-il public (0,1) - fk_don_projet integer NULL, -- projet auquel est fait le don + public smallint DEFAULT 1 NOT NULL, -- Donation is public ? (0,1) + fk_project integer NULL, -- Donation is given for a project ? fk_user_author integer NOT NULL, fk_user_valid integer NULL, note_private text, 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; + diff --git a/htdocs/install/mysql/tables/llx_payment_donation.sql b/htdocs/install/mysql/tables/llx_payment_donation.sql new file mode 100644 index 00000000000..0389a59e06e --- /dev/null +++ b/htdocs/install/mysql/tables/llx_payment_donation.sql @@ -0,0 +1,33 @@ +-- =================================================================== +-- 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_payment_donation +( + rowid integer AUTO_INCREMENT PRIMARY KEY, + fk_donation integer, + datec datetime, -- date de creation + tms timestamp, + datep datetime, -- payment date + amount real DEFAULT 0, + fk_typepayment integer NOT NULL, + num_payment varchar(50), + note text, + fk_bank integer NOT NULL, + fk_user_creat integer, -- creation user + fk_user_modif integer -- last modification user +)ENGINE=innodb; diff --git a/htdocs/langs/en_US/donations.lang b/htdocs/langs/en_US/donations.lang index 77d91ad801d..8b4c2ca8756 100644 --- a/htdocs/langs/en_US/donations.lang +++ b/htdocs/langs/en_US/donations.lang @@ -6,6 +6,8 @@ Donor=Donor Donors=Donors AddDonation=Create a donation NewDonation=New donation +DeleteADonation=Delete a donation +ConfirmDeleteADonation=Are you sure you want to delete this donation ? ShowDonation=Show donation DonationPromise=Gift promise PromisesNotValid=Not validated promises @@ -21,6 +23,8 @@ DonationStatusPaid=Donation received DonationStatusPromiseNotValidatedShort=Draft DonationStatusPromiseValidatedShort=Validated DonationStatusPaidShort=Received +DonationTitle=Donation receipt +DonationDatePayment=Payment date ValidPromess=Validate promise DonationReceipt=Donation receipt BuildDonationReceipt=Build receipt @@ -36,3 +40,4 @@ FrenchOptions=Options for France DONATION_ART200=Show article 200 from CGI if you are concerned DONATION_ART238=Show article 238 from CGI if you are concerned DONATION_ART885=Show article 885 from CGI if you are concerned +DonationPayment=Donation payment diff --git a/htdocs/langs/en_US/projects.lang b/htdocs/langs/en_US/projects.lang index ef270909120..40b1c2e308d 100644 --- a/htdocs/langs/en_US/projects.lang +++ b/htdocs/langs/en_US/projects.lang @@ -72,6 +72,7 @@ ListSupplierInvoicesAssociatedProject=List of supplier's invoices associated wit ListContractAssociatedProject=List of contracts associated with the project ListFichinterAssociatedProject=List of interventions associated with the project ListExpenseReportsAssociatedProject=List of expense reports associated with the project +ListDonationsAssociatedProject=List of donations associated with the project ListActionsAssociatedProject=List of events associated with the project ActivityOnProjectThisWeek=Activity on project this week ActivityOnProjectThisMonth=Activity on project this month diff --git a/htdocs/product/class/product.class.php b/htdocs/product/class/product.class.php index f66a007e93a..d08ed699b7f 100755 --- a/htdocs/product/class/product.class.php +++ b/htdocs/product/class/product.class.php @@ -1563,7 +1563,7 @@ class Product extends CommonObject $this->db->free($resql); - // Retreive all extrafield for thirdparty + // Retrieve all extrafield for thirdparty // fetch optionals attributes and labels require_once(DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'); $extrafields=new ExtraFields($this->db); diff --git a/htdocs/projet/class/project.class.php b/htdocs/projet/class/project.class.php index 681abb411ce..e78e9de0c63 100644 --- a/htdocs/projet/class/project.class.php +++ b/htdocs/projet/class/project.class.php @@ -506,7 +506,7 @@ class Project extends CommonObject // Set fk_projet into elements to null $listoftables=array( 'facture'=>'fk_projet','propal'=>'fk_projet','commande'=>'fk_projet','facture_fourn'=>'fk_projet','commande_fournisseur'=>'fk_projet', - 'expensereport_det'=>'fk_projet','contrat'=>'fk_projet','fichinter'=>'fk_projet' + 'expensereport_det'=>'fk_projet','contrat'=>'fk_projet','fichinter'=>'fk_projet','don'=>'fk_project' ); foreach($listoftables as $key => $value) { diff --git a/htdocs/projet/element.php b/htdocs/projet/element.php index b688f365e38..23c3cc6f8b1 100644 --- a/htdocs/projet/element.php +++ b/htdocs/projet/element.php @@ -3,6 +3,7 @@ * Copyright (C) 2004-2015 Laurent Destailleur * Copyright (C) 2005-2010 Regis Houssin * Copyright (C) 2012 Juanjo Menent + * 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 @@ -41,16 +42,18 @@ if (! empty($conf->ficheinter->enabled)) require_once DOL_DOCUMENT_ROOT.'/fichi if (! empty($conf->deplacement->enabled)) require_once DOL_DOCUMENT_ROOT.'/compta/deplacement/class/deplacement.class.php'; if (! empty($conf->expensereport->enabled)) require_once DOL_DOCUMENT_ROOT.'/expensereport/class/expensereport.class.php'; if (! empty($conf->agenda->enabled)) require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php'; +if (! empty($conf->don->enabled)) require_once DOL_DOCUMENT_ROOT.'/donations/class/don.class.php'; $langs->load("projects"); $langs->load("companies"); $langs->load("suppliers"); -if (! empty($conf->facture->enabled)) $langs->load("bills"); -if (! empty($conf->commande->enabled)) $langs->load("orders"); -if (! empty($conf->propal->enabled)) $langs->load("propal"); -if (! empty($conf->ficheinter->enabled)) $langs->load("interventions"); -if (! empty($conf->deplacement->enabled)) $langs->load("trips"); +if (! empty($conf->facture->enabled)) $langs->load("bills"); +if (! empty($conf->commande->enabled)) $langs->load("orders"); +if (! empty($conf->propal->enabled)) $langs->load("propal"); +if (! empty($conf->ficheinter->enabled)) $langs->load("interventions"); +if (! empty($conf->deplacement->enabled)) $langs->load("trips"); if (! empty($conf->expensereport->enabled)) $langs->load("trips"); +if (! empty($conf->don->enabled)) $langs->load("donations"); $id=GETPOST('id','int'); $ref=GETPOST('ref','alpha'); @@ -246,7 +249,15 @@ $listofreferent=array( 'table'=>'actioncomm', 'datefieldname'=>'datep', 'disableamount'=>1, - 'test'=>$conf->agenda->enabled && $user->rights->agenda->allactions->lire) + 'test'=>$conf->agenda->enabled && $user->rights->agenda->allactions->lire), +'donation'=>array( + 'name'=>"Donation", + 'title'=>"ListDonationsAssociatedProject", + 'class'=>'Don', + 'table'=>'don', + 'datefieldname'=>'date', + 'disableamount'=>1, + 'test'=>$conf->don->enabled && $user->rights->don->lire), ); if ($action=="addelement") diff --git a/htdocs/public/donations/donateurs_code.php b/htdocs/public/donations/donateurs_code.php index d2435f9f20f..0fef24df949 100644 --- a/htdocs/public/donations/donateurs_code.php +++ b/htdocs/public/donations/donateurs_code.php @@ -39,7 +39,7 @@ function llxHeaderVierge() { print 'Export agenda cal function llxFooterVierge() { print ''; } require '../../main.inc.php'; -require_once DOL_DOCUMENT_ROOT .'/compta/dons/class/class/don.class.php'; +require_once DOL_DOCUMENT_ROOT .'/don/class/don.class.php'; // Security check if (empty($conf->don->enabled)) accessforbidden('',1,1,1); diff --git a/htdocs/public/donations/therm.php b/htdocs/public/donations/therm.php index 1e111567c17..7c24253dd71 100644 --- a/htdocs/public/donations/therm.php +++ b/htdocs/public/donations/therm.php @@ -27,7 +27,7 @@ define("NOCSRFCHECK",1); // We accept to go on this page from external web site. require '../../main.inc.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php'; -require_once DOL_DOCUMENT_ROOT.'/compta/dons/class/don.class.php'; +require_once DOL_DOCUMENT_ROOT.'/don/class/don.class.php'; // Security check if (empty($conf->don->enabled)) accessforbidden('',1,1,1);