* Copyright (C) 2002-2003 Jean-Louis Bergamo * Copyright (C) 2004-2010 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. */ /** * \file htdocs/adherents/card_subscriptions.php * \ingroup member * \brief Onglet d'ajout, edition, suppression des adhesions d'un adherent * \version $Id$ */ require("../main.inc.php"); require_once(DOL_DOCUMENT_ROOT."/lib/member.lib.php"); require_once(DOL_DOCUMENT_ROOT."/adherents/class/adherent.class.php"); require_once(DOL_DOCUMENT_ROOT."/adherents/class/adherent_type.class.php"); require_once(DOL_DOCUMENT_ROOT."/adherents/class/adherent_options.class.php"); require_once(DOL_DOCUMENT_ROOT."/adherents/class/cotisation.class.php"); require_once(DOL_DOCUMENT_ROOT."/compta/bank/class/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=GETPOST('action'); $rowid=GETPOST('rowid'); $typeid=GETPOST('typeid'); if (! $user->rights->adherent->cotisation->lire) accessforbidden(); /* * Actions */ if ($user->rights->adherent->cotisation->creer && $_POST["action"] == 'cotisation' && ! $_POST["cancel"]) { $error=0; $langs->load("banks"); $result=$adh->fetch($rowid); $result=$adht->fetch($adh->typeid); // Subscription informations $datecotisation=0; $datesubend=0; if ($_POST["reyear"] && $_POST["remonth"] && $_POST["reday"]) { $datecotisation=dol_mktime(0, 0, 0, $_POST["remonth"], $_POST["reday"], $_POST["reyear"]); } if ($_POST["endyear"] && $_POST["endmonth"] && $_POST["endday"]) { $datesubend=dol_mktime(0, 0, 0, $_POST["endmonth"], $_POST["endday"], $_POST["endyear"]); } $cotisation=$_POST["cotisation"]; // Amount of subscription $label=$_POST["label"]; if (! $datecotisation) { $error++; $errmsg=$langs->trans("BadDateFormat"); $action='addsubscription'; } if (! $datesubend) { $datesubend=dol_time_plus_duree(dol_time_plus_duree($datecotisation,$defaultdelay,$defaultdelayunit),-1,'d'); } // Payment informations $accountid=$_POST["accountid"]; $operation=$_POST["operation"]; // Payment mode $num_chq=$_POST["num_chq"]; $emetteur_nom=$_POST["chqemetteur"]; $emetteur_banque=$_POST["chqbank"]; $option=$_POST["paymentsave"]; if (empty($option)) $option='none'; // Check if a payment is mandatory or not if (! $error && $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")); $error++; $action='addsubscription'; } else { if ($conf->banque->enabled && $_POST["paymentsave"] != 'none') { 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 (! $error && $action=='cotisation') { $db->begin(); $crowid=$adh->cotisation($datecotisation, $cotisation, $accountid, $operation, $label, $num_chq, $emetteur_nom, $emetteur_banque, $datesubend, $option); if ($crowid <= 0) { $error++; $errmsg=$adh->error; } if (! $error) { if ($option == 'bankviainvoice' || $option == 'invoiceonly') { // If option choosed, we create invoice require_once(DOL_DOCUMENT_ROOT."/compta/facture/class/facture.class.php"); require_once(DOL_DOCUMENT_ROOT."/compta/facture/class/paymentterm.class.php"); $invoice=new Facture($db); $customer=new Societe($db); $result=$customer->fetch($adh->fk_soc); if ($result <= 0) { $errmsg=$customer->error; $error++; } // Create draft invoice $invoice->type=0; $invoice->cond_reglement_id=$customer->cond_reglement_id; if (empty($invoice->cond_reglement_id)) { $paymenttermstatic=new PaymentTerm($db); $invoice->cond_reglement_id=$paymenttermstatic->getDefaultId(); if (empty($invoice->cond_reglement_id)) { $error++; $errmsg='ErrorNoPaymentTermRECEPFound'; } } $invoice->socid=$adh->fk_soc; $result=$invoice->create($user); if ($result <= 0) { $errmsg=$invoice->error; $error++; } // Add line to draft invoice $idprodsubscription=0; $vattouse=get_default_tva($mysoc, $customer, $idprodsubscription); //print xx".$vattouse." - ".$mysoc." - ".$customer;exit; $result=$invoice->addline($invoice->id,$label,0,1,$vattouse,0,0,$idprodsubscription,0,$datecotisation,$datesubend,0,0,'','TTC',$cotisation,1); if ($result <= 0) { $errmsg=$invoice->error; $error++; } } } if (! $error) { $db->commit(); } else { $db->rollback(); $errmsg=$adh->error; $action = 'addsubscription'; } // Send email if (! $error) { // Send confirmation Email if ($adh->email && $_POST["sendmail"]) { $subjecttosend=$adh->makeSubstitution($conf->global->ADHERENT_MAIL_COTIS_SUBJECT); $texttosend=$adh->makeSubstitution($adht->getMailOnSubscription()); $result=$adh->send_an_email($texttosend,$subjecttosend,array(),array(),array(),"","",0,-1); if ($result < 0) $errmsg=$adh->error; } $_POST["cotisation"]=''; $_POST["accountid"]=''; $_POST["operation"]=''; $_POST["label"]=''; $_POST["num_chq"]=''; } } } /* * View */ $html = new Form($db); llxHeader('',$langs->trans("Subscriptions"),'EN:Module_Foundations|FR:Module_Adhérents|ES:Módulo_Miembros'); if ($rowid) { $adh->id = $rowid; $result=$adh->fetch($rowid); $result=$adh->fetch_optionals($rowid); $adht->fetch($adh->typeid); // fetch optionals attributes and labels $adho->fetch_optionals(); $head = member_prepare_head($adh); dol_fiche_head($head, 'subscription', $langs->trans("Member"), 0, 'user'); print '
'; 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 '
'; dol_fiche_end(); if ($errmsg) { if (preg_match('/^Error/i',$errmsg)) { $langs->load("errors"); $errmsg=$langs->trans($errmsg); } print '
'.$errmsg.'
'."\n"; } /* * Barre d'actions */ print '
'; // Lien nouvelle cotisation si non brouillon et non resilie if ($user->rights->adherent->cotisation->creer) { if ($action != 'addsubscription') { if ($adh->statut > 0) print "".$langs->trans("AddSubscription").""; else print ''.$langs->trans("AddSubscription").''; print "
\n"; } } print '
'; // Date fin cotisation print "\n"; print ''; print ''; print ''; print '
'.$langs->trans("SubscriptionEndDate"); print ''; if ($adh->datefin) { if ($adh->datefin < time()) { print dol_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 dol_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 '
'; print '
'; /* * List of subscriptions */ if ($action != 'addsubscription') { $sql = "SELECT d.rowid, d.prenom, d.nom, d.societe,"; $sql.= " c.rowid as crowid, c.cotisation,"; $sql.= " c.dateadh,"; $sql.= " c.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) { 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) { print ''; } print ""; $i++; } print "
'.$langs->trans("Ref").''.$langs->trans("DateSubscription").''.$langs->trans("DateEnd").''.$langs->trans("Amount").''.$langs->trans("Account").'
'.$cotisationstatic->getNomUrl(1).''.dol_print_date($db->jdate($objp->dateadh),'day')."'.dol_print_date($db->jdate($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 { dol_print_error($db); } } /* * Add new subscription form */ if ($action == 'addsubscription' && $user->rights->adherent->cotisation->creer) { print '
'; print_fiche_titre($langs->trans("NewCotisation")); $bankdirect=0; // Option to write to bank is on by default $bankviainvoice=0; // Option to write via invoice is on by default $invoiceonly=0; if ($conf->banque->enabled && $conf->global->ADHERENT_BANK_USE && (empty($_POST['paymentsave']) || $_POST["paymentsave"] == 'bankdirect')) $bankdirect=1; if ($conf->banque->enabled && $conf->societe->enabled && $conf->facture->enabled && $adh->fk_soc) $bankviainvoice=1; // TODO A virer //$bankviainvoice=0; print "\n\n\n"; if ($conf->use_javascript_ajax) { print "\n".''."\n"; } print '
'; print ''; print ''; print ''; print "\n"; $today=mktime(); $datefrom=0; $dateto=0; // Date start subscription print '"; // Date end subscription if ($_POST["endday"]) { $dateto=dol_mktime(0,0,0,$_POST["endmonth"],$_POST["endday"],$_POST["endyear"]); } if (! $dateto) { //$dateto=dol_time_plus_duree(dol_time_plus_duree($datefrom,$defaultdelay,$defaultdelayunit),-1,'d'); $dateto=-1; // By default, no date is suggested } print '"; if ($adht->cotisation) { // Amount print ''; // Label print ''; print ''; // Bank account transaction if ($conf->banque->enabled || $conf->facture->enabled) { $company=new Societe($db); if ($adh->fk_soc) { $result=$company->fetch($adh->fk_soc); } // Title payments //print ''; // Define a way to write payment print ''; print ''; // Bank account print '\n"; // Payment mode print '\n"; print ''; print ''; print ''; print ''; print ''; print ''; } } print ''; print ''; print ''; print '
'.$langs->trans("DateSubscription").''; if ($_POST["reday"]) { $datefrom=dol_mktime(0,0,0,$_POST["remonth"],$_POST["reday"],$_POST["reyear"]); } if (! $datefrom) { if ($adh->datefin > 0) { $datefrom=dol_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("Label").'
'.$langs->trans("Payment").'
'.$langs->trans('MoreActions'); print ''; print ' '.$langs->trans("None").'
'; if ($conf->banque->enabled) { print ' '.$langs->trans("MoreActionBankDirect").'
'; } if ($conf->banque->enabled && $conf->societe->enabled && $conf->facture->enabled) { print 'fk_soc) || empty($bankviainvoice)) print ' disabled="true"'; print '> '.$langs->trans("MoreActionBankViaInvoice"); if ($adh->fk_soc) print ' ('.$langs->trans("ThirdParty").': '.$company->getNomUrl(1).')'; else print ' ('.$langs->trans("NoThirdPartyAssociatedToMember").')'; print '
'; } if ($conf->societe->enabled && $conf->facture->enabled) { print 'fk_soc) || empty($bankviainvoice)) print ' disabled="true"'; print '> '.$langs->trans("MoreActionInvoiceOnly"); if ($adh->fk_soc) print ' ('.$langs->trans("ThirdParty").': '.$company->getNomUrl(1).')'; else print ' ('.$langs->trans("NoThirdPartyAssociatedToMember").')'; print '
'; } print '
'.$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").')'; print '
'.$langs->trans('CheckTransmitter'); print ' ('.$langs->trans("ChequeMaker").')'; print '
'.$langs->trans('Bank'); print ' ('.$langs->trans("ChequeBank").')'; print '
 
'.$langs->trans("SendAcknowledgementByMail").''; if (! $adh->email) { print $langs->trans("NoEMail"); } else { $adht = new AdherentType($db); $adht->fetch($adh->typeid); $subjecttosend=$adh->makeSubstitution($conf->global->ADHERENT_MAIL_COTIS_SUBJECT); $texttosend=$adh->makeSubstitution($adht->getMailOnSubscription()); $tmp='global->ADHERENT_DEFAULT_SENDINFOBYMAIL?' checked="true"':'').'>'; $helpcontent=''; $helpcontent.=''.$langs->trans("MailFrom").': '.$conf->global->ADHERENT_MAIL_FROM.'
'."\n"; $helpcontent.=''.$langs->trans("MailRecipient").': '.$adh->email.'
'."\n"; $helpcontent.=''.$langs->trans("Subject").':
'."\n"; $helpcontent.=$subjecttosend."\n"; $helpcontent.="
"; $helpcontent.=''.$langs->trans("Content").':
'; $helpcontent.=dol_htmlentitiesbr($texttosend)."\n"; print $html->textwithpicto($tmp,$helpcontent,1,'help'); } print '
'; print '
'; print '
'; print ''; print '     '; print ''; print '
'; print '
'; print "\n\n\n"; } //print ''; //print ''; } else { $langs->load("errors"); print $langs->trans("ErrorRecordNotFound"); } $db->close(); llxFooter('$Date$ - $Revision$'); ?>