* Copyright (C) 2002-2003 Jean-Louis Bergamo * Copyright (C) 2004-2007 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, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * $Id$ */ /** \file htdocs/adherents/card_subscriptions.php \ingroup adherent \brief Onglet d'ajout, edition, suppression des adh�sions d'un adh�rent \version $Revision$ */ require("./pre.inc.php"); require_once(DOL_DOCUMENT_ROOT."/lib/member.lib.php"); require_once(DOL_DOCUMENT_ROOT."/adherents/adherent.class.php"); require_once(DOL_DOCUMENT_ROOT."/adherents/adherent_type.class.php"); require_once(DOL_DOCUMENT_ROOT."/adherents/adherent_options.class.php"); require_once(DOL_DOCUMENT_ROOT."/adherents/cotisation.class.php"); require_once(DOL_DOCUMENT_ROOT."/compta/bank/account.class.php"); $langs->load("companies"); $langs->load("bills"); $langs->load("members"); $langs->load("users"); $langs->load("mails"); $adh = new Adherent($db); $adho = new AdherentOptions($db); $adht = new AdherentType($db); $errmsg=''; $defaultdelay=1; $defaultdelayunit='y'; $action=isset($_GET["action"])?$_GET["action"]:$_POST["action"]; $rowid=isset($_GET["rowid"])?$_GET["rowid"]:$_POST["rowid"]; $typeid=isset($_GET["typeid"])?$_GET["typeid"]:$_POST["typeid"]; if (! $user->rights->adherent->cotisation->lire) accessforbidden(); /* * Actions */ if ($user->rights->adherent->cotisation->creer && $_POST["action"] == 'cotisation' && ! $_POST["cancel"]) { $langs->load("banks"); $adh->id = $rowid; $result=$adh->fetch($rowid); $adht->fetch($adh->typeid); $datecotisation=0; $datesubend=0; if ($_POST["reyear"] && $_POST["remonth"] && $_POST["reday"]) { $datecotisation=dolibarr_mktime(0, 0, 0, $_POST["remonth"], $_POST["reday"], $_POST["reyear"]); } if ($_POST["endyear"] && $_POST["endmonth"] && $_POST["endday"]) { $datesubend=dolibarr_mktime(0, 0, 0, $_POST["endmonth"], $_POST["endday"], $_POST["endyear"]); } $cotisation=$_POST["cotisation"]; $accountid=$_POST["accountid"]; $operation=$_POST["operation"]; $label=$_POST["label"]; $num_chq=$_POST["num_chq"]; $emetteur_nom=$_POST["chqemetteur"]; $emetteur_banque=$_POST["chqbank"]; if (! $datecotisation) { $errmsg=$langs->trans("BadDateFormat"); $action='addsubscription'; } if (! $datesubend) { $datesubend=dolibarr_time_plus_duree(dolibarr_time_plus_duree($datecotisation,$defaultdelay,$defaultdelayunit),-1,'d'); } if ($adht->cotisation) // Type adherent soumis a cotisation { if (! is_numeric($_POST["cotisation"])) { // If field is '' or not a numeric value $errmsg=$langs->trans("ErrorFieldRequired",$langs->transnoentities("Amount")); $action='addsubscription'; } else { if ($conf->banque->enabled && $conf->global->ADHERENT_BANK_USE) { if ($_POST["cotisation"]) { if (! $_POST["label"]) $errmsg=$langs->trans("ErrorFieldRequired",$langs->transnoentities("Label")); if (! $_POST["operation"]) $errmsg=$langs->trans("ErrorFieldRequired",$langs->transnoentities("PaymentMode")); if (! $_POST["accountid"]) $errmsg=$langs->trans("ErrorFieldRequired",$langs->transnoentities("FinancialAccount")); } else { if ($_POST["accountid"]) $errmsg=$langs->trans("ErrorDoNotProvideAccountsIfNullAmount"); } if ($errmsg) $action='addsubscription'; } } } if ($action=='cotisation') { $db->begin(); $crowid=$adh->cotisation($datecotisation, $cotisation, $accountid, $operation, $label, $num_chq, $emetteur_nom, $emetteur_banque, $datesubend); if ($crowid > 0) { $db->commit(); // Envoi mail if ($_POST["sendmail"]) { $result=$adh->send_an_email($conf->global->ADHERENT_MAIL_COTIS,$conf->global->ADHERENT_MAIL_COTIS_SUBJECT,array(),array(),array(),"","",0,-1); if ($result < 0) $errmsg=$adh->error; } $_POST["cotisation"]=''; $_POST["accountid"]=''; $_POST["operation"]=''; $_POST["label"]=''; $_POST["num_chq"]=''; } else { $db->rollback(); $errmsg=$adh->error; $action = 'addsubscription'; } } } /* ************************************************************************** */ /* */ /* Mode affichage */ /* */ /* ************************************************************************** */ llxHeader(); $html = new Form($db); $adh->id = $rowid; $result=$adh->fetch($rowid); $result=$adh->fetch_optionals($rowid); $adht->fetch($adh->typeid); // fetch optionals attributes and labels $adho->fetch_optionals(); /* * Affichage onglets */ $head = member_prepare_head($adh); dolibarr_fiche_head($head, 'subscription', $langs->trans("Member")); print '
'; print ''; // Ref print ''; print ''; // Nom print ''; print ''; // Prenom print ''; print ''; // Login print ''; // Type print '\n"; // Status print ''; print "
'.$langs->trans("Ref").''; print $html->showrefnav($adh,'rowid'); print '
'.$langs->trans("Lastname").''.$adh->nom.' 
'.$langs->trans("Firstname").''.$adh->prenom.' 
'.$langs->trans("Login").''.$adh->login.' 
'.$langs->trans("Type").''.$adht->getNomUrl(1)."
'.$langs->trans("Status").''.$adh->getLibStatut(4).'
\n"; print '
'; print "\n"; if ($errmsg) { if (eregi('^Error',$errmsg)) { $langs->load("errors"); $errmsg=$langs->trans($errmsg); } print '
'.$errmsg.'
'; print "\n"; } /* * Barre d'actions * */ print '
'; // Lien nouvelle cotisation si non brouillon et non r�sili� if ($user->rights->adherent->cotisation->creer) { if ($action != 'addsubscription' && $adh->statut > 0) { print "".$langs->trans("NewSubscription").""; } } print '
'; print "
\n"; /* * Bandeau des cotisations * */ print ''; print ''; print ''; print '
'; /* * Liste des cotisations * */ $sql = "SELECT d.rowid, d.prenom, d.nom, d.societe,"; $sql.= " c.rowid as crowid, c.cotisation,"; $sql.= " ".$db->pdate("c.dateadh")." as dateadh,"; $sql.= " ".$db->pdate("c.datef")." as datef,"; $sql.= " c.fk_bank,"; $sql.= " b.rowid as bid,"; $sql.= " ba.rowid as baid, ba.label, ba.bank"; $sql.= " FROM ".MAIN_DB_PREFIX."adherent as d, ".MAIN_DB_PREFIX."cotisation as c"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."bank as b ON c.fk_bank = b.rowid"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."bank_account as ba ON b.fk_account = ba.rowid"; $sql.= " WHERE d.rowid = c.fk_adherent AND d.rowid=".$rowid; $result = $db->query($sql); if ($result) { $cotisationstatic=new Cotisation($db); $accountstatic=new Account($db); $num = $db->num_rows($result); $i = 0; print "\n"; print ''; print ''; print ''; print ''; print ''; if ($conf->banque->enabled && $conf->global->ADHERENT_BANK_USE) { print ''; } print "\n"; $var=True; while ($i < $num) { $objp = $db->fetch_object($result); $var=!$var; print ""; $cotisationstatic->ref=$objp->crowid; $cotisationstatic->id=$objp->crowid; print ''; print '\n"; print '\n"; print ''; if ($conf->banque->enabled && $conf->global->ADHERENT_BANK_USE) { print ''; } print ""; $i++; } print "
'.$langs->trans("Ref").''.$langs->trans("DateSubscription").''.$langs->trans("DateEnd").''.$langs->trans("Amount").''.$langs->trans("Account").'
'.$cotisationstatic->getNomUrl(1).''.dolibarr_print_date($objp->dateadh,'day')."'.dolibarr_print_date($objp->datef,'day')."'.price($objp->cotisation).''; if ($objp->bid) { $accountstatic->label=$objp->label; $accountstatic->id=$objp->baid; print $accountstatic->getNomUrl(1); } else { print ' '; } print '
"; } else { dolibarr_print_error($db); } print '
'; // Date fin cotisation print "\n"; print ''; print ''; print ''; print '
'.$langs->trans("SubscriptionEndDate"); print ''; if ($adh->datefin) { if ($adh->datefin < time()) { print dolibarr_print_date($adh->datefin,'day'); if ($adh->statut > 0) print " ".img_warning($langs->trans("Late")); // Affiche picto retard uniquement si non brouillon et non resilie } else { print dolibarr_print_date($adh->datefin,'day'); } } else { print $langs->trans("SubscriptionNotReceived"); if ($adh->statut > 0) print " ".img_warning($langs->trans("Late")); // Affiche picto retard uniquement si non brouillon et non resilie } print '
'; /* * Ajout d'une nouvelle cotisation */ if ($action == 'addsubscription' && $user->rights->adherent->cotisation->creer) { print '
'; print "\n\n\n"; print '
'; print ''; print ''; print "\n"; print ''; $today=mktime(); $datefrom=0; $dateto=0; // Date start subscription print '"; // Date end subscription if ($_POST["endday"]) { $dateto=dolibarr_mktime(0,0,0,$_POST["endmonth"],$_POST["endday"],$_POST["endyear"]); } if (! $dateto) { //$dateto=dolibarr_time_plus_duree(dolibarr_time_plus_duree($datefrom,$defaultdelay,$defaultdelayunit),-1,'d'); $dateto=-1; // By default, no date is suggested } print '"; if ($adht->cotisation) { print ''; if ($conf->banque->enabled && $conf->global->ADHERENT_BANK_USE) { print '\n"; } print '\n"; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; } print ''; print ''; print ''; print '
'.$langs->trans("NewCotisation").'
'.$langs->trans("DateSubscription").''; if ($_POST["reday"]) { $datefrom=dolibarr_mktime(0,0,0,$_POST["remonth"],$_POST["reday"],$_POST["reyear"]); } if (! $datefrom) { if ($adh->datefin > 0) { $datefrom=dolibarr_time_plus_duree($adh->datefin,1,'d'); } else { $datefrom=mktime(); } } $html->select_date($datefrom,'','','','',"cotisation"); print "
'.$langs->trans("DateEndSubscription").''; $html->select_date($dateto,'end','','','',"cotisation"); print "
'.$langs->trans("Amount").' '.$langs->trans("Currency".$conf->monnaie).'
'.$langs->trans("FinancialAccount").''; $html->select_comptes($_POST["accountid"],'accountid',0,'',1); print "
'.$langs->trans("PaymentMode").''; $html->select_types_paiements($_POST["operation"],'operation'); print "
'.$langs->trans('Numero'); print ' ('.$langs->trans("ChequeOrTransferNumber").')'; // \todo a traduire print '
'.$langs->trans('CheckTransmitter'); print ' ('.$langs->trans("ChequeMaker").')'; // \todo a traduire print '
'.$langs->trans('Bank'); print ' ('.$langs->trans("ChequeBank").')'; // \todo a traduire print '
'.$langs->trans("Label").'
'.$langs->trans("SendAcknowledgementByMail").''; if (! $adh->email) { print $langs->trans("NoEMail"); } else { $s1='global->ADHERENT_MAIL_COTIS?' checked="true"':'').'>'; $s2=$langs->trans("MailFrom").': '.$conf->global->ADHERENT_MAIL_FROM.'
'; $s2.=$langs->trans("MailRecipient").': '.$adh->email.''; //$s2.='
'.$langs->trans("Content").': '.nl2br($conf->global->ADHERENT_MAIL_COTIS); print $html->textwithhelp($s1,$s2,1); } print '
'; print ''; print '     '; print ''; print '
'; print '
'; print "\n\n\n"; } print '
'; $db->close(); llxFooter('$Date$ - $Revision$'); ?>