* Copyright (C) 2004-2011 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 2 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."/includes/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 ($conf->projet->enabled) require_once(DOL_DOCUMENT_ROOT.'/lib/project.lib.php'); $langs->load("companies"); $langs->load("donations"); $langs->load("bills"); $mesg=""; $mesgs=array(); $don = new Don($db); $donation_date=dol_mktime(12, 0, 0, $_POST["remonth"], $_POST["reday"], $_POST["reyear"]); /* * Actions */ if ($_POST["action"] == 'update') { if (! empty($_POST['cancel'])) { Header("Location: fiche.php?rowid=".$_POST["rowid"]); exit; } $error=0; if (empty($donation_date)) { $mesgs[]=$langs->trans("ErrorFieldRequired",$langs->trans("Date")); $_GET["action"] = "create"; $error++; } if (! $_POST["amount"] > 0) { $mesgs[]=$langs->trans("ErrorFieldRequired",$langs->trans("Amount")); $_GET["action"] = "create"; $error++; } if (! $error) { $don->id = $_POST["rowid"]; $don->fetch($_POST["rowid"]); $don->prenom = $_POST["prenom"]; $don->nom = $_POST["nom"]; $don->societe = $_POST["societe"]; $don->adresse = $_POST["adresse"]; $don->amount = price2num($_POST["amount"]); $don->cp = $_POST["zipcode"]; $don->ville = $_POST["town"]; $don->zip = $_POST["zipcode"]; $don->town = $_POST["town"]; $don->email = $_POST["email"]; $don->date = $donation_date; $don->note = $_POST["note"]; $don->pays = $_POST["pays"]; $don->public = $_POST["public"]; $don->fk_project = $_POST["projectid"]; $don->note = $_POST["comment"]; $don->modepaiementid = $_POST["modepaiement"]; if ($don->update($user) > 0) { Header("Location: fiche.php?rowid=".$don->id); exit; } } } if ($_POST["action"] == 'add') { if (! empty($_POST['cancel'])) { Header("Location: index.php"); exit; } $error=0; if (empty($donation_date)) { $mesgs[]=$langs->trans("ErrorFieldRequired",$langs->trans("Date")); $_GET["action"] = "create"; $error++; } if (! $_POST["amount"] > 0) { $mesgs[]=$langs->trans("ErrorFieldRequired",$langs->trans("Amount")); $_GET["action"] = "create"; $error++; } if (! $error) { $don->prenom = $_POST["prenom"]; $don->nom = $_POST["nom"]; $don->societe = $_POST["societe"]; $don->adresse = $_POST["adresse"]; $don->amount = price2num($_POST["amount"]); $don->cp = $_POST["zipcode"]; $don->ville = $_POST["town"]; $don->zip = $_POST["zipcode"]; $don->town = $_POST["town"]; $don->email = $_POST["email"]; $don->date = $donation_date; $don->note = $_POST["note"]; $don->pays = $_POST["pays"]; $don->public = $_POST["public"]; $don->fk_project = $_POST["projectid"]; $don->note = $_POST["comment"]; $don->modepaiementid = $_POST["modepaiement"]; if ($don->create($user) > 0) { Header("Location: index.php"); exit; } } } if ($_GET["action"] == 'delete') { $don->delete($_GET["rowid"]); Header("Location: liste.php"); exit; } if ($_POST["action"] == 'commentaire') { $don->fetch($_POST["rowid"]); $don->update_note($_POST["commentaire"]); $_GET["rowid"] = $_POST["rowid"]; } if ($_GET["action"] == 'valid_promesse') { if ($don->valid_promesse($_GET["rowid"], $user->id) >= 0) { Header("Location: fiche.php?rowid=".$_GET["rowid"]); exit; } else $mesg=$don->error; } if ($_GET["action"] == 'set_cancel') { if ($don->set_cancel($_GET["rowid"]) >= 0) { Header("Location: fiche.php?rowid=".$_GET["rowid"]); exit; } else $mesg=$don->error; } if ($_GET["action"] == 'set_paid') { if ($don->set_paye($_GET["rowid"], $modepaiement) >= 0) { Header("Location: fiche.php?rowid=".$_GET["rowid"]); exit; } else $mesg=$don->error; } if ($_GET["action"] == 'set_encaisse') { if ($don->set_encaisse($_GET["rowid"]) >= 0) { Header("Location: fiche.php?rowid=".$_GET["rowid"]); exit; } else $mesg=$don->error; } /* * Build doc */ if ($_REQUEST['action'] == 'builddoc') { $donation = new Don($db); $donation->fetch($_GET['rowid']); if ($_REQUEST['model']) { $donation->setDocModel($user, $_REQUEST['model']); } // 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=$donation->client->default_lang; if (! empty($newlang)) { $outputlangs = new Translate("",$conf); $outputlangs->setDefaultLang($newlang); } $result=don_create($db, $donation->id, '', $donation->modelpdf, $outputlangs); if ($result <= 0) { dol_print_error($db,$result); exit; } else { Header('Location: '.$_SERVER["PHP_SELF"].'?rowid='.$donation->id.(empty($conf->global->MAIN_JUMP_TAG)?'':'#builddoc')); exit; } } /* * View */ llxHeader('',$langs->trans("Donations"),'EN:Module_Donations|FR:Module_Dons|ES:Módulo_Subvenciones'); $html=new Form($db); $formfile = new FormFile($db); $htmlcompany = new FormCompany($db); /* ************************************************************************** */ /* */ /* Creation */ /* */ /* ************************************************************************** */ if ($_GET["action"] == 'create') { print_fiche_titre($langs->trans("AddDonation")); dol_htmloutput_errors($mesg,$mesgs); print '
'; print ''; print ''; print ''; $nbrows=11; if ($conf->projet->enabled) $nbrows++; // Date print ''; print '"; print ""; // Amount print "".''; print '\n"; print "".''; print "".''; print "".''; print "".''; // Zip / Town print ''; print "".''; print "".''; print "\n"; if ($conf->projet->enabled) { // Si module projet actif print "\n"; } print "
'.$langs->trans("Date").''; $html->select_date($donation_date?$donation_date:-1,'','','','',"add",1,1); print ''.$langs->trans("Comments").' :
'; print "
'.$langs->trans("Amount").' '.$langs->trans("Currency".$conf->monnaie).'
'.$langs->trans("PublicDonation").""; print $html->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 $htmlcompany->select_ziptown((isset($_POST["zipcode"])?$_POST["zipcode"]:$don->zip),'zipcode',array('town','selectpays_id','departement_id'),6); print ' '; print $htmlcompany->select_ziptown((isset($_POST["town"])?$_POST["town"]:$don->town),'town',array('zipcode','selectpays_id','departement_id')); print '
'.$langs->trans("Country").'
'.$langs->trans("EMail").'
".$langs->trans("PaymentMode")."\n"; $html->select_types_paiements('', 'modepaiement', 'CRDT', 0, 1); print "
".$langs->trans("Project").""; select_projects('',$_POST["projectid"],"projectid"); print "
\n"; print '
   
'; print "
\n"; } /* ************************************************************ */ /* */ /* Fiche don en mode edition */ /* */ /* ************************************************************ */ if ($_GET["rowid"] && $_GET["action"] == 'edit') { $don->id = $_GET["rowid"]; $don->fetch($_GET["rowid"]); $h=0; $head[$h][0] = DOL_URL_ROOT."/compta/dons/fiche.php?rowid=".$_GET["rowid"]; $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 ($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 ($conf->projet->enabled) { $langs->load('projects'); print ''; } print "
'.$langs->trans("Ref").''; print $don->getNomUrl(); print '
'.$langs->trans("Date").''; $html->select_date($don->date,'','','','',"update"); print ''.$langs->trans("Comments").' :
'; print "
'.$langs->trans("Amount").' '.$langs->trans("Currency".$conf->monnaie).'
'.$langs->trans("PublicDonation").""; print $html->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 $htmlcompany->select_ziptown((isset($_POST["zipcode"])?$_POST["zipcode"]:$don->zip),'zipcode',array('town','selectpays_id','departement_id'),6); print ' '; print $htmlcompany->select_ziptown((isset($_POST["town"])?$_POST["town"]:$don->town),'town',array('zipcode','selectpays_id','departement_id')); print '
'.$langs->trans("Country").'
'.$langs->trans("EMail").'
".$langs->trans("PaymentMode")."\n"; $html->select_types_paiements('', 'modepaiement', 'CRDT', 0, 1); print "
'.$langs->trans("Status").''.$don->getLibStatut(4).'
'.$langs->trans('Project').''; select_projects($soc->id, isset($_POST["projectid"])?$_POST["projectid"]:$don->fk_project, 'projectid'); print '
\n"; print '
   
'; print "
\n"; print "\n"; } /* ************************************************************ */ /* */ /* Fiche don en mode visu */ /* */ /* ************************************************************ */ if ($_GET["rowid"] && $_GET["action"] != 'edit') { $don->id = $_GET["rowid"]; $result=$don->fetch($_GET["rowid"]); $h=0; $head[$h][0] = DOL_URL_ROOT."/compta/dons/fiche.php?rowid=".$_GET["rowid"]; $head[$h][1] = $langs->trans("Card"); $hselected=$h; $h++; dol_fiche_head($head, $hselected, $langs->trans("Donation"), 0, 'generic'); print "
"; print ''; print ''; $nbrows=12; if ($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 ($conf->projet->enabled) { print "".''; } print "
'.$langs->trans("Ref").''; print $html->showrefnav($don,'rowid','',1,'rowid','ref',''); print '
'.$langs->trans("Date").''; print dol_print_date($don->date,"day"); print "'.$langs->trans("Comments").' :
'; print nl2br($don->note).'
'.$langs->trans("Amount").''.price($don->amount).' '.$langs->trans("Currency".$conf->monnaie).'
".$langs->trans("PublicDonation").""; print yn($don->public); print "
'.$langs->trans("Company").''.$don->societe.'
'.$langs->trans("Firstname").''.$don->prenom.'
'.$langs->trans("Lastname").''.$don->nom.'
'.$langs->trans("Address").''.dol_nl2br($don->adresse).'
'.$langs->trans("Zip").' / '.$langs->trans("Town").''.$don->cp.($don->cp && $don->ville?' / ':'').$don->ville.'
'.$langs->trans("Country").''.$don->pays.'
'.$langs->trans("EMail").''.dol_print_email($don->email).'
".$langs->trans("PaymentMode").""; print $don->modepaiement; 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 ''.$langs->trans('Modify').''; if ($don->statut == 0) { print ''.$langs->trans("ValidPromess").''; } if (($don->statut == 0 || $don->statut == 1) && $resteapayer == 0 && $don->paye == 0) { print "id&action=set_cancel\">".$langs->trans("ClassifyCanceled").""; } // TODO Gerer action emettre paiement if ($don->statut == 1 && $resteapayer > 0) { print "".$langs->trans("DoPayment").""; } if ($don->statut == 1 && $resteapayer == 0 && $don->paye == 0) { print "id&action=set_paid\">".$langs->trans("ClassifyPaid").""; } if ($user->rights->don->supprimer) { print "id&action=delete\">".$langs->trans("Delete").""; } else { print "".$langs->trans("Delete").""; } 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 '
 
'; } $db->close(); llxFooter(); ?>