* 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/fiche.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'); $mesg=""; $mesgs=array(); $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')); /* * Actions */ if ($action == 'update') { if (! empty($cancel)) { header("Location: ".$_SERVER['PHP_SELF']."?id=".$id); exit; } $error=0; if (empty($donation_date)) { $mesgs[]=$langs->trans("ErrorFieldRequired",$langs->trans("Date")); $action = "create"; $error++; } if (empty($amount)) { $mesgs[]=$langs->trans("ErrorFieldRequired",$langs->trans("Amount")); $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)) { $mesgs[]=$langs->trans("ErrorFieldRequired",$langs->trans("Date")); $action = "create"; $error++; } if (empty($amount)) { $mesgs[]=$langs->trans("ErrorFieldRequired",$langs->trans("Amount")); $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: liste.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 $mesg=$don->error; } if ($action == 'set_cancel') { if ($don->set_cancel($id) >= 0) { header("Location: ".$_SERVER['PHP_SELF']."?id=".$id); exit; } else $mesg=$don->error; } if ($action == 'set_paid') { if ($don->set_paye($id, $modepaiement) >= 0) { header("Location: ".$_SERVER['PHP_SELF']."?id=".$id); exit; } else $mesg=$don->error; } if ($action == 'set_encaisse') { if ($don->set_encaisse($id) >= 0) { header("Location: ".$_SERVER['PHP_SELF']."?id=".$id); exit; } else $mesg=$don->error; } /* * 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")); dol_htmloutput_errors($mesg,$mesgs); 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").""; print $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();