2007-02-03 23:40:04 +01:00
< ? php
2018-09-09 09:36:12 +02:00
/* Copyright ( C ) 2001 - 2004 Rodolphe Quiedeville < rodolphe @ quiedeville . org >
* Copyright ( C ) 2002 - 2003 Jean - Louis Bergamo < jlb @ j1b . org >
* Copyright ( C ) 2004 - 2018 Laurent Destailleur < eldy @ users . sourceforge . net >
2018-10-27 14:43:12 +02:00
* Copyright ( C ) 2012 - 2017 Regis Houssin < regis . houssin @ inodbox . com >
2019-01-28 21:39:22 +01:00
* Copyright ( C ) 2015 - 2016 Alexandre Spangaro < aspangaro @ open - dsi . fr >
2018-09-09 09:36:12 +02:00
* Copyright ( C ) 2018 Frédéric France < frederic . france @ netlogic . fr >
2019-04-25 13:12:33 +02:00
* Copyright ( C ) 2019 Thibault FOUCART < support @ ptibogxiv . net >
2007-02-03 23:40:04 +01:00
*
* 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
2013-01-16 15:36:08 +01:00
* the Free Software Foundation ; either version 3 of the License , or
2007-02-03 23:40:04 +01:00
* ( 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
2019-09-23 21:55:30 +02:00
* along with this program . If not , see < https :// www . gnu . org / licenses />.
2007-02-03 23:40:04 +01:00
*/
/**
2016-09-24 06:48:40 +02:00
* \file htdocs / adherents / subscription . php
2009-10-10 18:00:35 +02:00
* \ingroup member
2019-11-09 16:11:37 +01:00
* \brief tab for Adding , editing , deleting a member ' s memberships
2008-11-15 01:10:42 +01:00
*/
2007-02-03 23:40:04 +01:00
2012-08-22 23:24:21 +02:00
require '../main.inc.php' ;
2012-08-22 23:11:24 +02:00
require_once DOL_DOCUMENT_ROOT . '/core/lib/member.lib.php' ;
require_once DOL_DOCUMENT_ROOT . '/core/lib/date.lib.php' ;
require_once DOL_DOCUMENT_ROOT . '/adherents/class/adherent.class.php' ;
require_once DOL_DOCUMENT_ROOT . '/adherents/class/adherent_type.class.php' ;
2016-09-24 06:48:40 +02:00
require_once DOL_DOCUMENT_ROOT . '/adherents/class/subscription.class.php' ;
2012-08-22 23:11:24 +02:00
require_once DOL_DOCUMENT_ROOT . '/core/class/extrafields.class.php' ;
2017-10-11 11:42:39 +02:00
require_once DOL_DOCUMENT_ROOT . '/compta/bank/class/account.class.php' ;
require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php' ;
require_once DOL_DOCUMENT_ROOT . '/accountancy/class/accountingjournal.class.php' ;
2007-02-03 23:40:04 +01:00
2019-11-13 19:35:39 +01:00
$langs -> loadLangs ( array ( " companies " , " bills " , " members " , " users " , " mails " , 'other' ));
2010-09-07 03:32:20 +02:00
2020-09-16 19:39:50 +02:00
$action = GETPOST ( 'action' , 'aZ09' );
2019-11-13 19:35:39 +01:00
$confirm = GETPOST ( 'confirm' , 'alpha' );
$rowid = GETPOST ( 'rowid' , 'int' ) ? GETPOST ( 'rowid' , 'int' ) : GETPOST ( 'id' , 'int' );
$typeid = GETPOST ( 'typeid' , 'int' );
2012-04-15 11:28:21 +02:00
2018-01-10 13:02:05 +01:00
// Load variable for pagination
2019-11-13 19:35:39 +01:00
$limit = GETPOST ( 'limit' , 'int' ) ? GETPOST ( 'limit' , 'int' ) : $conf -> liste_limit ;
2020-09-18 17:13:01 +02:00
$sortfield = GETPOST ( 'sortfield' , 'aZ09comma' );
2020-09-17 14:31:25 +02:00
$sortorder = GETPOST ( 'sortorder' , 'aZ09comma' );
2020-03-13 13:07:11 +01:00
$page = GETPOSTISSET ( 'pageplusone' ) ? ( GETPOST ( 'pageplusone' ) - 1 ) : GETPOST ( " page " , 'int' );
2018-01-10 13:02:05 +01:00
if ( empty ( $page ) || $page == - 1 ) { $page = 0 ; } // If $page is not defined, or '' or -1
$offset = $limit * $page ;
$pageprev = $page - 1 ;
$pagenext = $page + 1 ;
// Default sort order (if not yet defined by previous GETPOST)
2019-11-13 19:35:39 +01:00
if ( ! $sortfield ) $sortfield = " c.rowid " ;
if ( ! $sortorder ) $sortorder = " DESC " ;
2018-01-10 13:02:05 +01:00
2010-09-07 03:32:20 +02:00
// Security check
2019-11-13 19:35:39 +01:00
$result = restrictedArea ( $user , 'adherent' , $rowid , '' , 'cotisation' );
2010-09-07 03:32:20 +02:00
2012-03-04 01:09:39 +01:00
$object = new Adherent ( $db );
$extrafields = new ExtraFields ( $db );
2007-02-28 00:06:18 +01:00
$adht = new AdherentType ( $db );
2016-06-24 00:45:35 +02:00
// fetch optionals attributes and labels
2019-10-06 14:41:52 +02:00
$extrafields -> fetch_name_optionals_label ( $object -> table_element );
2016-06-24 00:45:35 +02:00
2019-11-13 19:35:39 +01:00
$errmsg = '' ;
2007-02-03 23:40:04 +01:00
2019-11-13 19:35:39 +01:00
$defaultdelay = 1 ;
$defaultdelayunit = 'y' ;
2007-09-05 09:43:43 +02:00
2020-05-21 09:12:18 +02:00
if ( $rowid ) {
2020-10-27 19:46:07 +01:00
// Load member
$result = $object -> fetch ( $rowid );
// Define variables to know what current user can do on users
$canadduser = ( $user -> admin || $user -> rights -> user -> user -> creer );
// Define variables to know what current user can do on properties of user linked to edited member
if ( $object -> user_id ) {
// $user is the user editing, $object->user_id is the user's id linked to the edited member
$caneditfielduser = ((( $user -> id == $object -> user_id ) && $user -> rights -> user -> self -> creer )
|| (( $user -> id != $object -> user_id ) && $user -> rights -> user -> user -> creer ));
$caneditpassworduser = ((( $user -> id == $object -> user_id ) && $user -> rights -> user -> self -> password )
|| (( $user -> id != $object -> user_id ) && $user -> rights -> user -> user -> password ));
}
2010-09-07 03:32:20 +02:00
}
// Define variables to know what current user can do on members
2020-04-10 10:59:32 +02:00
$canaddmember = $user -> rights -> adherent -> creer ;
2010-09-07 03:32:20 +02:00
// Define variables to know what current user can do on properties of a member
2020-05-21 09:12:18 +02:00
if ( $rowid ) {
2020-10-27 19:46:07 +01:00
$caneditfieldmember = $user -> rights -> adherent -> creer ;
2010-09-07 03:32:20 +02:00
}
2017-06-10 12:56:28 +02:00
// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
2017-04-15 08:35:23 +02:00
$hookmanager -> initHooks ( array ( 'subscription' ));
2014-05-07 10:33:10 +02:00
// PDF
2020-04-10 10:59:32 +02:00
$hidedetails = ( GETPOST ( 'hidedetails' , 'int' ) ? GETPOST ( 'hidedetails' , 'int' ) : ( ! empty ( $conf -> global -> MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS ) ? 1 : 0 ));
$hidedesc = ( GETPOST ( 'hidedesc' , 'int' ) ? GETPOST ( 'hidedesc' , 'int' ) : ( ! empty ( $conf -> global -> MAIN_GENERATE_DOCUMENTS_HIDE_DESC ) ? 1 : 0 ));
$hideref = ( GETPOST ( 'hideref' , 'int' ) ? GETPOST ( 'hideref' , 'int' ) : ( ! empty ( $conf -> global -> MAIN_GENERATE_DOCUMENTS_HIDE_REF ) ? 1 : 0 ));
2014-05-07 10:33:10 +02:00
2018-01-10 13:02:05 +01:00
2007-02-03 23:40:04 +01:00
/*
* Actions
*/
2011-02-26 10:51:53 +01:00
// Create third party from a member
2020-05-21 09:12:18 +02:00
if ( $action == 'confirm_create_thirdparty' && $confirm == 'yes' && $user -> rights -> societe -> creer ) {
if ( $result > 0 ) {
2018-03-05 21:46:24 +01:00
// Creation of thirdparty
2011-02-26 10:51:53 +01:00
$company = new Societe ( $db );
2019-11-13 19:35:39 +01:00
$result = $company -> create_from_member ( $object , GETPOST ( 'companyname' , 'alpha' ), GETPOST ( 'companyalias' , 'alpha' ), GETPOST ( 'customercode' , 'alpha' ));
2011-03-06 14:55:47 +01:00
2020-05-21 09:12:18 +02:00
if ( $result < 0 ) {
2011-02-26 10:51:53 +01:00
$langs -> load ( " errors " );
2015-10-23 12:58:30 +02:00
setEventMessages ( $company -> error , $company -> errors , 'errors' );
2020-05-21 09:21:30 +02:00
} else {
2019-11-13 19:35:39 +01:00
$action = 'addsubscription' ;
2011-02-26 10:51:53 +01:00
}
2020-05-21 09:21:30 +02:00
} else {
2017-08-23 16:53:29 +02:00
setEventMessages ( $object -> error , $object -> errors , 'errors' );
2011-02-26 10:51:53 +01:00
}
}
2010-09-07 03:32:20 +02:00
2020-05-21 09:12:18 +02:00
if ( $action == 'setuserid' && ( $user -> rights -> user -> self -> creer || $user -> rights -> user -> user -> creer )) {
2020-10-27 19:46:07 +01:00
$error = 0 ;
if ( empty ( $user -> rights -> user -> user -> creer )) { // If can edit only itself user, we can link to itself only
2020-05-21 09:12:18 +02:00
if ( $_POST [ " userid " ] != $user -> id && $_POST [ " userid " ] != $object -> user_id ) {
2020-10-27 19:46:07 +01:00
$error ++ ;
setEventMessages ( $langs -> trans ( " ErrorUserPermissionAllowsToLinksToItselfOnly " ), null , 'errors' );
2020-05-21 09:12:18 +02:00
}
2020-10-27 19:46:07 +01:00
}
2010-09-07 03:32:20 +02:00
2020-10-27 19:46:07 +01:00
if ( ! $error ) {
if ( $_POST [ " userid " ] != $object -> user_id ) { // If link differs from currently in database
2020-05-21 09:12:18 +02:00
$result = $object -> setUserId ( $_POST [ " userid " ]);
2020-10-27 19:46:07 +01:00
if ( $result < 0 ) dol_print_error ( '' , $object -> error );
$_POST [ 'action' ] = '' ;
$action = '' ;
}
}
2010-09-07 03:32:20 +02:00
}
2020-05-21 09:12:18 +02:00
if ( $action == 'setsocid' ) {
2020-10-27 19:46:07 +01:00
$error = 0 ;
if ( ! $error ) {
if ( GETPOST ( 'socid' , 'int' ) != $object -> fk_soc ) { // If link differs from currently in database
2020-05-21 09:12:18 +02:00
$sql = " SELECT rowid FROM " . MAIN_DB_PREFIX . " adherent " ;
2020-10-27 19:46:07 +01:00
$sql .= " WHERE fk_soc = ' " . GETPOST ( 'socid' , 'int' ) . " ' " ;
$resql = $db -> query ( $sql );
if ( $resql ) {
$obj = $db -> fetch_object ( $resql );
if ( $obj && $obj -> rowid > 0 ) {
$othermember = new Adherent ( $db );
$othermember -> fetch ( $obj -> rowid );
$thirdparty = new Societe ( $db );
$thirdparty -> fetch ( GETPOST ( 'socid' , 'int' ));
$error ++ ;
setEventMessages ( $langs -> trans ( " ErrorMemberIsAlreadyLinkedToThisThirdParty " , $othermember -> getFullName ( $langs ), $othermember -> login , $thirdparty -> name ), null , 'errors' );
}
}
2010-09-07 03:32:20 +02:00
2020-10-27 19:46:07 +01:00
if ( ! $error ) {
$result = $object -> setThirdPartyId ( GETPOST ( 'socid' , 'int' ));
if ( $result < 0 ) dol_print_error ( '' , $object -> error );
$_POST [ 'action' ] = '' ;
$action = '' ;
}
}
}
2010-09-07 03:32:20 +02:00
}
2020-05-21 09:12:18 +02:00
if ( $user -> rights -> adherent -> cotisation -> creer && $action == 'subscription' && ! $_POST [ " cancel " ]) {
2020-10-27 19:46:07 +01:00
$error = 0 ;
2010-09-05 21:22:00 +02:00
2020-10-27 19:46:07 +01:00
$langs -> load ( " banks " );
2007-05-28 13:11:46 +02:00
2020-10-27 19:46:07 +01:00
$result = $object -> fetch ( $rowid );
$result = $adht -> fetch ( $object -> typeid );
2010-09-09 01:50:52 +02:00
2020-10-27 19:46:07 +01:00
// Subscription informations
$datesubscription = 0 ;
$datesubend = 0 ;
$paymentdate = 0 ;
if ( $_POST [ " reyear " ] && $_POST [ " remonth " ] && $_POST [ " reday " ]) {
$datesubscription = 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 " ]);
}
if ( $_POST [ " paymentyear " ] && $_POST [ " paymentmonth " ] && $_POST [ " paymentday " ]) {
$paymentdate = dol_mktime ( 0 , 0 , 0 , $_POST [ " paymentmonth " ], $_POST [ " paymentday " ], $_POST [ " paymentyear " ]);
}
$amount = price2num ( GETPOST ( " subscription " , 'alpha' )); // Amount of subscription
$label = $_POST [ " label " ];
// Payment informations
$accountid = $_POST [ " accountid " ];
$operation = $_POST [ " operation " ]; // Payment mode
$num_chq = GETPOST ( " num_chq " , " alphanohtml " );
$emetteur_nom = $_POST [ " chqemetteur " ];
$emetteur_banque = $_POST [ " chqbank " ];
$option = $_POST [ " paymentsave " ];
if ( empty ( $option )) $option = 'none' ;
$sendalsoemail = GETPOST ( " sendmail " , 'alpha' );
// Check parameters
if ( ! $datesubscription ) {
$error ++ ;
$langs -> load ( " errors " );
$errmsg = $langs -> trans ( " ErrorBadDateFormat " , $langs -> transnoentitiesnoconv ( " DateSubscription " ));
setEventMessages ( $errmsg , null , 'errors' );
$action = 'addsubscription' ;
}
if ( GETPOST ( 'end' ) && ! $datesubend ) {
$error ++ ;
$langs -> load ( " errors " );
$errmsg = $langs -> trans ( " ErrorBadDateFormat " , $langs -> transnoentitiesnoconv ( " DateEndSubscription " ));
setEventMessages ( $errmsg , null , 'errors' );
$action = 'addsubscription' ;
}
if ( ! $datesubend ) {
$datesubend = dol_time_plus_duree ( dol_time_plus_duree ( $datesubscription , $defaultdelay , $defaultdelayunit ), - 1 , 'd' );
}
if (( $option == 'bankviainvoice' || $option == 'bankdirect' ) && ! $paymentdate ) {
$error ++ ;
$errmsg = $langs -> trans ( " ErrorFieldRequired " , $langs -> transnoentitiesnoconv ( " DatePayment " ));
setEventMessages ( $errmsg , null , 'errors' );
$action = 'addsubscription' ;
}
2008-11-15 01:10:42 +01:00
2020-10-27 19:46:07 +01:00
// Check if a payment is mandatory or not
if ( ! $error && $adht -> subscription ) { // Member type need subscriptions
2020-05-21 09:12:18 +02:00
if ( ! is_numeric ( $amount )) {
2020-10-27 19:46:07 +01:00
// If field is '' or not a numeric value
$errmsg = $langs -> trans ( " ErrorFieldRequired " , $langs -> transnoentities ( " Amount " ));
setEventMessages ( $errmsg , null , 'errors' );
$error ++ ;
$action = 'addsubscription' ;
2020-05-21 09:21:30 +02:00
} else {
2020-10-27 19:46:07 +01:00
if ( ! empty ( $conf -> banque -> enabled ) && $_POST [ " paymentsave " ] != 'none' ) {
if ( $_POST [ " subscription " ]) {
if ( ! $_POST [ " label " ]) $errmsg = $langs -> trans ( " ErrorFieldRequired " , $langs -> transnoentities ( " Label " ));
if ( $_POST [ " paymentsave " ] != 'invoiceonly' && ! $_POST [ " operation " ]) $errmsg = $langs -> trans ( " ErrorFieldRequired " , $langs -> transnoentities ( " PaymentMode " ));
if ( $_POST [ " paymentsave " ] != 'invoiceonly' && ! ( $_POST [ " accountid " ] > 0 )) $errmsg = $langs -> trans ( " ErrorFieldRequired " , $langs -> transnoentities ( " FinancialAccount " ));
} else {
if ( $_POST [ " accountid " ]) $errmsg = $langs -> trans ( " ErrorDoNotProvideAccountsIfNullAmount " );
}
if ( $errmsg ) {
$error ++ ;
setEventMessages ( $errmsg , null , 'errors' );
$error ++ ;
$action = 'addsubscription' ;
}
}
}
}
2010-09-09 01:50:52 +02:00
2020-10-27 19:46:07 +01:00
// Record the subscription then complementary actions
if ( ! $error && $action == 'subscription' ) {
$db -> begin ();
2010-09-09 01:50:52 +02:00
2020-10-27 19:46:07 +01:00
// Create subscription
$crowid = $object -> subscription ( $datesubscription , $amount , $accountid , $operation , $label , $num_chq , $emetteur_nom , $emetteur_banque , $datesubend );
if ( $crowid <= 0 ) {
$error ++ ;
$errmsg = $object -> error ;
setEventMessages ( $object -> error , $object -> errors , 'errors' );
}
2010-09-09 01:50:52 +02:00
2020-10-27 19:46:07 +01:00
if ( ! $error ) {
$result = $object -> subscriptionComplementaryActions ( $crowid , $option , $accountid , $datesubscription , $paymentdate , $operation , $label , $amount , $num_chq , $emetteur_nom , $emetteur_banque );
2020-05-21 09:12:18 +02:00
if ( $result < 0 ) {
2018-03-05 21:46:24 +01:00
$error ++ ;
setEventMessages ( $object -> error , $object -> errors , 'errors' );
2020-05-21 09:21:30 +02:00
} else {
2018-03-08 15:01:34 +01:00
// If an invoice was created, it is into $object->invoice
}
2020-10-27 19:46:07 +01:00
}
2010-09-09 01:50:52 +02:00
2020-10-27 19:46:07 +01:00
if ( ! $error ) {
$db -> commit ();
} else {
$db -> rollback ();
$action = 'addsubscription' ;
}
2010-09-09 01:50:52 +02:00
2020-10-27 19:46:07 +01:00
if ( ! $error ) {
setEventMessages ( " SubscriptionRecorded " , null , 'mesgs' );
}
2018-03-08 15:01:34 +01:00
2020-10-27 19:46:07 +01:00
// Send email
if ( ! $error ) {
// Send confirmation Email
if ( $object -> email && $sendalsoemail ) { // $object is 'Adherent'
2020-12-16 10:47:28 +01:00
$parameters = array (
'datesubscription' => $datesubscription ,
'amount' => $amount ,
'ccountid' => $accountid ,
'operation' => $operation ,
'label' => $label ,
'num_chq' => $num_chq ,
'emetteur_nom' => $emetteur_nom ,
'emetteur_banque' => $emetteur_banque ,
'datesubend' => $datesubend
);
$reshook = $hookmanager -> executeHooks ( 'sendMail' , $parameters , $object , $action ); // Note that $action and $object may have been modified by some hooks
if ( $reshook < 0 ) {
setEventMessages ( $hookmanager -> error , $hookmanager -> errors , 'errors' );
2020-10-27 19:46:07 +01:00
}
2020-12-16 10:47:28 +01:00
if ( empty ( $reshook )) {
$subject = '' ;
$msg = '' ;
// Send subscription email
include_once DOL_DOCUMENT_ROOT . '/core/class/html.formmail.class.php' ;
$formmail = new FormMail ( $db );
// Set output language
$outputlangs = new Translate ( '' , $conf );
$outputlangs -> setDefaultLang ( empty ( $object -> thirdparty -> default_lang ) ? $mysoc -> default_lang : $object -> thirdparty -> default_lang );
// Load traductions files required by page
$outputlangs -> loadLangs ( array ( " main " , " members " ));
// Get email content from template
$arraydefaultmessage = null ;
$labeltouse = $conf -> global -> ADHERENT_EMAIL_TEMPLATE_SUBSCRIPTION ;
if ( ! empty ( $labeltouse )) $arraydefaultmessage = $formmail -> getEMailTemplate ( $db , 'member' , $user , $outputlangs , 0 , 1 , $labeltouse );
if ( ! empty ( $labeltouse ) && is_object ( $arraydefaultmessage ) && $arraydefaultmessage -> id > 0 ) {
$subject = $arraydefaultmessage -> topic ;
$msg = $arraydefaultmessage -> content ;
}
$substitutionarray = getCommonSubstitutionArray ( $outputlangs , 0 , null , $object );
complete_substitutions_array ( $substitutionarray , $outputlangs , $object );
$subjecttosend = make_substitutions ( $subject , $substitutionarray , $outputlangs );
$texttosend = make_substitutions ( dol_concatdesc ( $msg , $adht -> getMailOnSubscription ()), $substitutionarray , $outputlangs );
// Attach a file ?
$file = '' ;
$listofpaths = array ();
$listofnames = array ();
$listofmimes = array ();
if ( is_object ( $object -> invoice ) && ( ! is_object ( $arraydefaultmessage ) || intval ( $arraydefaultmessage -> joinfiles ))) {
$invoicediroutput = $conf -> facture -> dir_output ;
$fileparams = dol_most_recent_file ( $invoicediroutput . '/' . $object -> invoice -> ref , preg_quote ( $object -> invoice -> ref , '/' ) . '[^\-]+' );
$file = $fileparams [ 'fullname' ];
$listofpaths = array ( $file );
$listofnames = array ( basename ( $file ));
$listofmimes = array ( dol_mimetype ( $file ));
}
$moreinheader = 'X-Dolibarr-Info: send_an_email by adherents/subscription.php' . " \r \n " ;
$result = $object -> send_an_email ( $texttosend , $subjecttosend , $listofpaths , $listofmimes , $listofnames , " " , " " , 0 , - 1 , '' , $moreinheader );
if ( $result < 0 ) {
$errmsg = $object -> error ;
setEventMessages ( $object -> error , $object -> errors , 'errors' );
} else {
setEventMessages ( $langs -> trans ( " EmailSentToMember " , $object -> email ), null , 'mesgs' );
}
2020-10-27 19:46:07 +01:00
}
} else {
setEventMessages ( $langs -> trans ( " NoEmailSentToMember " ), null , 'mesgs' );
}
}
2010-09-05 21:22:00 +02:00
2020-10-27 19:46:07 +01:00
// Clean some POST vars
if ( ! $error ) {
$_POST [ " subscription " ] = '' ;
$_POST [ " accountid " ] = '' ;
$_POST [ " operation " ] = '' ;
$_POST [ " label " ] = '' ;
$_POST [ " num_chq " ] = '' ;
}
}
2007-02-03 23:40:04 +01:00
}
2010-09-07 03:32:20 +02:00
2009-08-12 14:59:14 +02:00
/*
* View
*/
2007-02-03 23:40:04 +01:00
2011-11-08 10:18:45 +01:00
$form = new Form ( $db );
2007-02-03 23:40:04 +01:00
2019-11-13 19:35:39 +01:00
$now = dol_now ();
2011-01-15 03:39:31 +01:00
2019-11-13 19:35:39 +01:00
$title = $langs -> trans ( " Member " ) . " - " . $langs -> trans ( " Subscriptions " );
$helpurl = " EN:Module_Foundations|FR:Module_Adhérents|ES:Módulo_Miembros " ;
2019-01-27 11:55:16 +01:00
llxHeader ( " " , $title , $helpurl );
2007-02-03 23:40:04 +01:00
2018-01-10 13:02:05 +01:00
2019-11-13 19:35:39 +01:00
$param = '' ;
if ( ! empty ( $contextpage ) && $contextpage != $_SERVER [ " PHP_SELF " ]) $param .= '&contextpage=' . urlencode ( $contextpage );
if ( $limit > 0 && $limit != $conf -> liste_limit ) $param .= '&limit=' . urlencode ( $limit );
$param .= '&id=' . $rowid ;
if ( $optioncss != '' ) $param .= '&optioncss=' . urlencode ( $optioncss );
2018-01-10 13:02:05 +01:00
// Add $param from extra fields
//include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
2020-05-21 09:12:18 +02:00
if ( $rowid > 0 ) {
2020-10-27 19:46:07 +01:00
$res = $object -> fetch ( $rowid );
if ( $res < 0 ) { dol_print_error ( $db , $object -> error ); exit ; }
2007-02-03 23:40:04 +01:00
2020-10-27 19:46:07 +01:00
$adht -> fetch ( $object -> typeid );
2007-02-03 23:40:04 +01:00
2020-10-27 19:46:07 +01:00
$head = member_prepare_head ( $object );
2007-02-03 23:40:04 +01:00
2020-10-27 19:46:07 +01:00
$rowspan = 10 ;
if ( empty ( $conf -> global -> ADHERENT_LOGIN_NOT_REQUIRED )) $rowspan ++ ;
if ( ! empty ( $conf -> societe -> enabled )) $rowspan ++ ;
2011-03-06 14:55:47 +01:00
2020-10-27 19:46:07 +01:00
print '<form action="' . $_SERVER [ " PHP_SELF " ] . '" method="POST">' ;
print '<input type="hidden" name="token" value="' . newToken () . '">' ;
print '<input type="hidden" name="rowid" value="' . $object -> id . '">' ;
2015-05-14 20:49:22 +02:00
2020-10-27 19:46:07 +01:00
print dol_get_fiche_head ( $head , 'subscription' , $langs -> trans ( " Member " ), - 1 , 'user' );
2015-05-14 20:49:22 +02:00
2020-10-27 19:46:07 +01:00
$linkback = '<a href="' . DOL_URL_ROOT . '/adherents/list.php?restore_lastsearch_values=1">' . $langs -> trans ( " BackToList " ) . '</a>' ;
2017-06-07 16:44:04 +02:00
2020-10-27 19:46:07 +01:00
dol_banner_tab ( $object , 'rowid' , $linkback );
2017-06-07 16:44:04 +02:00
2020-10-27 19:46:07 +01:00
print '<div class="fichecenter">' ;
print '<div class="fichehalfleft">' ;
2017-06-07 16:44:04 +02:00
2020-10-27 19:46:07 +01:00
print '<div class="underbanner clearboth"></div>' ;
print '<table class="border centpercent tableforfield">' ;
2011-06-16 23:15:45 +02:00
2015-10-16 20:16:28 +02:00
// Login
2020-05-21 09:12:18 +02:00
if ( empty ( $conf -> global -> ADHERENT_LOGIN_NOT_REQUIRED )) {
2016-07-27 07:24:36 +02:00
print '<tr><td class="titlefield">' . $langs -> trans ( " Login " ) . ' / ' . $langs -> trans ( " Id " ) . '</td><td class="valeur">' . $object -> login . ' </td></tr>' ;
2015-10-16 20:16:28 +02:00
}
2011-03-06 14:55:47 +01:00
2015-10-16 20:16:28 +02:00
// Type
2016-07-27 07:24:36 +02:00
print '<tr><td class="titlefield">' . $langs -> trans ( " Type " ) . '</td><td class="valeur">' . $adht -> getNomUrl ( 1 ) . " </td></tr> \n " ;
2015-10-16 16:14:33 +02:00
2015-10-16 20:16:28 +02:00
// Morphy
2019-06-24 17:59:00 +02:00
print '<tr><td>' . $langs -> trans ( " MemberNature " ) . '</td><td class="valeur" >' . $object -> getmorphylib () . '</td>' ;
2015-10-16 20:16:28 +02:00
print '</tr>' ;
2011-03-06 14:55:47 +01:00
2015-10-16 20:16:28 +02:00
// Company
2019-09-01 22:21:48 +02:00
print '<tr><td>' . $langs -> trans ( " Company " ) . '</td><td class="valeur">' . $object -> company . '</td></tr>' ;
2011-03-06 14:55:47 +01:00
2015-10-16 20:16:28 +02:00
// Civility
print '<tr><td>' . $langs -> trans ( " UserTitle " ) . '</td><td class="valeur">' . $object -> getCivilityLabel () . ' </td>' ;
print '</tr>' ;
// Password
2020-05-21 09:12:18 +02:00
if ( empty ( $conf -> global -> ADHERENT_LOGIN_NOT_REQUIRED )) {
2019-01-27 11:55:16 +01:00
print '<tr><td>' . $langs -> trans ( " Password " ) . '</td><td>' . preg_replace ( '/./i' , '*' , $object -> pass );
2020-05-21 09:12:18 +02:00
if (( ! empty ( $object -> pass ) || ! empty ( $object -> pass_crypted )) && empty ( $object -> user_id )) {
2020-10-27 19:46:07 +01:00
$langs -> load ( " errors " );
$htmltext = $langs -> trans ( " WarningPasswordSetWithNoAccount " );
print ' ' . $form -> textwithpicto ( '' , $htmltext , 1 , 'warning' );
2015-10-16 20:16:28 +02:00
}
print '</td></tr>' ;
}
2011-03-06 14:55:47 +01:00
2020-10-27 19:46:07 +01:00
print '</table>' ;
2017-06-07 16:44:04 +02:00
2020-10-27 19:46:07 +01:00
print '</div>' ;
print '<div class="fichehalfright"><div class="ficheaddleft">' ;
2017-06-07 16:44:04 +02:00
2020-10-27 19:46:07 +01:00
print '<div class="underbanner clearboth"></div>' ;
print '<table class="border tableforfield" width="100%">' ;
2017-06-07 16:44:04 +02:00
2015-10-16 20:16:28 +02:00
// Birthday
2019-01-27 11:55:16 +01:00
print '<tr><td class="titlefield">' . $langs -> trans ( " Birthday " ) . '</td><td class="valeur">' . dol_print_date ( $object -> birth , 'day' ) . '</td></tr>' ;
2007-02-03 23:40:04 +01:00
2015-10-16 20:16:28 +02:00
// Public
print '<tr><td>' . $langs -> trans ( " Public " ) . '</td><td class="valeur">' . yn ( $object -> public ) . '</td></tr>' ;
2013-07-10 17:29:54 +02:00
2015-10-16 20:16:28 +02:00
// Categories
2020-05-21 09:12:18 +02:00
if ( ! empty ( $conf -> categorie -> enabled ) && ! empty ( $user -> rights -> categorie -> lire )) {
2019-11-13 19:35:39 +01:00
print '<tr><td>' . $langs -> trans ( " Categories " ) . '</td>' ;
2015-10-16 20:16:28 +02:00
print '<td colspan="2">' ;
2019-11-14 08:07:16 +01:00
print $form -> showCategories ( $object -> id , Categorie :: TYPE_MEMBER , 1 );
2015-10-16 20:16:28 +02:00
print '</td></tr>' ;
}
2020-10-27 19:46:07 +01:00
// Other attributes
$cols = 2 ;
include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_view.tpl.php' ;
2015-10-16 20:16:28 +02:00
2016-06-26 12:07:24 +02:00
// Date end subscription
print '<tr><td>' . $langs -> trans ( " SubscriptionEndDate " ) . '</td><td class="valeur">' ;
2020-05-21 09:12:18 +02:00
if ( $object -> datefin ) {
2020-10-27 19:46:07 +01:00
print dol_print_date ( $object -> datefin , 'day' );
if ( $object -> hasDelay ()) {
print " " . img_warning ( $langs -> trans ( " Late " ));
}
2020-05-21 09:21:30 +02:00
} else {
2020-10-27 19:46:07 +01:00
if ( ! $adht -> subscription ) {
print $langs -> trans ( " SubscriptionNotRecorded " );
if ( $object -> statut > 0 ) print " " . img_warning ( $langs -> trans ( " Late " )); // Display a delay picto only if it is not a draft and is not canceled
} else {
print $langs -> trans ( " SubscriptionNotReceived " );
if ( $object -> statut > 0 ) print " " . img_warning ( $langs -> trans ( " Late " )); // Display a delay picto only if it is not a draft and is not canceled
}
2016-06-26 12:07:24 +02:00
}
print '</td></tr>' ;
2017-06-07 16:44:04 +02:00
2015-10-16 20:16:28 +02:00
// Third party Dolibarr
2020-05-21 09:12:18 +02:00
if ( ! empty ( $conf -> societe -> enabled )) {
2015-10-16 20:16:28 +02:00
print '<tr><td>' ;
print '<table class="nobordernopadding" width="100%"><tr><td>' ;
print $langs -> trans ( " LinkedToDolibarrThirdParty " );
print '</td>' ;
2019-10-06 15:34:22 +02:00
if ( $action != 'editthirdparty' && $user -> rights -> adherent -> creer ) print '<td class="right"><a class="editfielda" href="' . $_SERVER [ " PHP_SELF " ] . '?action=editthirdparty&rowid=' . $object -> id . '">' . img_edit ( $langs -> trans ( 'SetLinkToThirdParty' ), 1 ) . '</a></td>' ;
2015-10-16 20:16:28 +02:00
print '</tr></table>' ;
print '</td><td colspan="2" class="valeur">' ;
2020-05-21 09:12:18 +02:00
if ( $action == 'editthirdparty' ) {
2019-11-13 19:35:39 +01:00
$htmlname = 'socid' ;
2015-10-16 20:16:28 +02:00
print '<form method="POST" action="' . $_SERVER [ 'PHP_SELF' ] . '" name="form' . $htmlname . '">' ;
print '<input type="hidden" name="rowid" value="' . $object -> id . '">' ;
print '<input type="hidden" name="action" value="set' . $htmlname . '">' ;
2019-12-18 23:12:31 +01:00
print '<input type="hidden" name="token" value="' . newToken () . '">' ;
2015-10-16 20:16:28 +02:00
print '<table class="nobordernopadding" cellpadding="0" cellspacing="0">' ;
print '<tr><td>' ;
2019-01-27 11:55:16 +01:00
print $form -> select_company ( $object -> fk_soc , 'socid' , '' , 1 );
2015-10-16 20:16:28 +02:00
print '</td>' ;
2019-01-17 14:04:16 +01:00
print '<td class="left"><input type="submit" class="button" value="' . $langs -> trans ( " Modify " ) . '"></td>' ;
2015-10-16 20:16:28 +02:00
print '</tr></table></form>' ;
2020-05-21 09:21:30 +02:00
} else {
2020-05-21 09:12:18 +02:00
if ( $object -> fk_soc ) {
2019-11-13 19:35:39 +01:00
$company = new Societe ( $db );
$result = $company -> fetch ( $object -> fk_soc );
2015-10-16 20:16:28 +02:00
print $company -> getNomUrl ( 1 );
2020-05-21 09:21:30 +02:00
} else {
2015-10-16 20:16:28 +02:00
print $langs -> trans ( " NoThirdPartyAssociatedToMember " );
}
}
print '</td></tr>' ;
}
// Login Dolibarr
print '<tr><td>' ;
print '<table class="nobordernopadding" width="100%"><tr><td>' ;
print $langs -> trans ( " LinkedToDolibarrUser " );
print '</td>' ;
2020-05-21 09:12:18 +02:00
if ( $action != 'editlogin' && $user -> rights -> adherent -> creer ) {
2019-01-21 22:04:42 +01:00
print '<td class="right">' ;
2020-05-21 09:12:18 +02:00
if ( $user -> rights -> user -> user -> creer ) {
2019-10-06 15:34:22 +02:00
print '<a class="editfielda" href="' . $_SERVER [ " PHP_SELF " ] . '?action=editlogin&rowid=' . $object -> id . '">' . img_edit ( $langs -> trans ( 'SetLinkToUser' ), 1 ) . '</a>' ;
2015-10-16 20:16:28 +02:00
}
print '</td>' ;
}
print '</tr></table>' ;
print '</td><td colspan="2" class="valeur">' ;
2020-05-21 09:12:18 +02:00
if ( $action == 'editlogin' ) {
2019-01-27 11:55:16 +01:00
$form -> form_users ( $_SERVER [ 'PHP_SELF' ] . '?rowid=' . $object -> id , $object -> user_id , 'userid' , '' );
2020-05-21 09:21:30 +02:00
} else {
2020-05-21 09:12:18 +02:00
if ( $object -> user_id ) {
2019-01-27 11:55:16 +01:00
$form -> form_users ( $_SERVER [ 'PHP_SELF' ] . '?rowid=' . $object -> id , $object -> user_id , 'none' );
2020-05-21 09:21:30 +02:00
} else print $langs -> trans ( " NoDolibarrAccess " );
2015-10-16 20:16:28 +02:00
}
print '</td></tr>' ;
2007-02-03 23:40:04 +01:00
2020-10-31 14:32:18 +01:00
print " </table> \n " ;
2007-02-03 23:40:04 +01:00
2015-10-16 20:16:28 +02:00
print " </div></div></div> \n " ;
2020-10-31 14:32:18 +01:00
print '<div style="clear:both"></div>' ;
2017-06-07 16:44:04 +02:00
2020-10-31 14:32:18 +01:00
print dol_get_fiche_end ();
2007-02-03 23:40:04 +01:00
2020-10-31 14:32:18 +01:00
print '</form>' ;
2015-05-14 20:49:22 +02:00
2007-09-05 09:43:43 +02:00
2020-10-31 14:32:18 +01:00
/*
2018-01-10 13:02:05 +01:00
* Action buttons
2010-09-06 20:56:13 +02:00
*/
2007-02-03 23:40:04 +01:00
2020-10-31 14:32:18 +01:00
// Button to create a new subscription if member no draft neither resiliated
if ( $user -> rights -> adherent -> cotisation -> creer ) {
if ( $action != 'addsubscription' && $action != 'create_thirdparty' ) {
print '<div class="tabsAction">' ;
2010-09-07 02:38:03 +02:00
2020-10-31 14:32:18 +01:00
if ( $object -> statut > 0 ) print '<div class="inline-block divButAction"><a class="butAction" href="' . $_SERVER [ " PHP_SELF " ] . '?rowid=' . $rowid . '&action=addsubscription">' . $langs -> trans ( " AddSubscription " ) . " </a></div> " ;
else print '<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" href="#" title="' . dol_escape_htmltag ( $langs -> trans ( " ValidateBefore " )) . '">' . $langs -> trans ( " AddSubscription " ) . '</a></div>' ;
2007-02-03 23:40:04 +01:00
2020-10-31 14:32:18 +01:00
print '</div>' ;
}
}
2007-02-03 23:40:04 +01:00
2020-10-31 14:32:18 +01:00
/*
2010-09-06 20:56:13 +02:00
* List of subscriptions
*/
2020-10-31 14:32:18 +01:00
if ( $action != 'addsubscription' && $action != 'create_thirdparty' ) {
$sql = " SELECT d.rowid, d.firstname, d.lastname, d.societe, d.fk_adherent_type as type, " ;
$sql .= " c.rowid as crowid, c.subscription, " ;
$sql .= " c.datec, c.fk_type as cfk_type, " ;
$sql .= " c.dateadh as dateh, " ;
$sql .= " c.datef, " ;
$sql .= " c.fk_bank, " ;
$sql .= " b.rowid as bid, " ;
$sql .= " ba.rowid as baid, ba.label, ba.bank, ba.ref, ba.account_number, ba.fk_accountancy_journal, ba.number, ba.currency_code " ;
$sql .= " FROM " . MAIN_DB_PREFIX . " adherent as d, " . MAIN_DB_PREFIX . " subscription 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 ;
2019-11-13 19:35:39 +01:00
$sql .= $db -> order ( $sortfield , $sortorder );
2010-09-06 20:56:13 +02:00
2020-10-31 14:32:18 +01:00
$result = $db -> query ( $sql );
if ( $result ) {
$subscriptionstatic = new Subscription ( $db );
$num = $db -> num_rows ( $result );
print '<table class="noborder centpercent">' . " \n " ;
print '<tr class="liste_titre">' ;
print_liste_field_titre ( 'Ref' , $_SERVER [ " PHP_SELF " ], 'c.rowid' , '' , $param , '' , $sortfield , $sortorder );
print_liste_field_titre ( 'DateCreation' , $_SERVER [ " PHP_SELF " ], '' , '' , $param , '' , $sortfield , $sortorder , 'center ' );
print_liste_field_titre ( 'Type' , $_SERVER [ " PHP_SELF " ], '' , '' , $param , '' , $sortfield , $sortorder , 'center ' );
print_liste_field_titre ( 'DateStart' , $_SERVER [ " PHP_SELF " ], '' , '' , $param , '' , $sortfield , $sortorder , 'center ' );
print_liste_field_titre ( 'DateEnd' , $_SERVER [ " PHP_SELF " ], '' , '' , $param , '' , $sortfield , $sortorder , 'center ' );
print_liste_field_titre ( 'Amount' , $_SERVER [ " PHP_SELF " ], '' , '' , $param , '' , $sortfield , $sortorder , 'right ' );
if ( ! empty ( $conf -> banque -> enabled )) {
print_liste_field_titre ( 'Account' , $_SERVER [ " PHP_SELF " ], '' , '' , $param , '' , $sortfield , $sortorder , 'right ' );
}
print " </tr> \n " ;
$accountstatic = new Account ( $db );
$adh = new Adherent ( $db );
$adht = new AdherentType ( $db );
$i = 0 ;
while ( $i < $num ) {
$objp = $db -> fetch_object ( $result );
$adh -> id = $objp -> rowid ;
$adh -> typeid = $objp -> type ;
$subscriptionstatic -> ref = $objp -> crowid ;
$subscriptionstatic -> id = $objp -> crowid ;
$typeid = $objp -> cfk_type ;
if ( $typeid > 0 ) {
$adht -> fetch ( $typeid );
}
print '<tr class="oddeven">' ;
print '<td>' . $subscriptionstatic -> getNomUrl ( 1 ) . '</td>' ;
print '<td class="center">' . dol_print_date ( $db -> jdate ( $objp -> datec ), 'dayhour' ) . " </td> \n " ;
print '<td class="center">' ;
if ( $typeid > 0 ) {
print $adht -> getNomUrl ( 1 );
}
print '</td>' ;
print '<td class="center">' . dol_print_date ( $db -> jdate ( $objp -> dateh ), 'day' ) . " </td> \n " ;
print '<td class="center">' . dol_print_date ( $db -> jdate ( $objp -> datef ), 'day' ) . " </td> \n " ;
print '<td class="right">' . price ( $objp -> subscription ) . '</td>' ;
2020-05-21 09:12:18 +02:00
if ( ! empty ( $conf -> banque -> enabled )) {
2019-01-21 22:04:42 +01:00
print '<td class="right">' ;
2020-05-21 09:12:18 +02:00
if ( $objp -> bid ) {
2019-11-13 19:35:39 +01:00
$accountstatic -> label = $objp -> label ;
$accountstatic -> id = $objp -> baid ;
$accountstatic -> number = $objp -> number ;
$accountstatic -> account_number = $objp -> account_number ;
$accountstatic -> currency_code = $objp -> currency_code ;
2017-07-17 05:58:27 +02:00
2020-05-21 09:12:18 +02:00
if ( ! empty ( $conf -> accounting -> enabled ) && $objp -> fk_accountancy_journal > 0 ) {
2017-10-10 07:37:39 +02:00
$accountingjournal = new AccountingJournal ( $db );
$accountingjournal -> fetch ( $objp -> fk_accountancy_journal );
2017-07-17 05:58:27 +02:00
2019-01-27 11:55:16 +01:00
$accountstatic -> accountancy_journal = $accountingjournal -> getNomUrl ( 0 , 1 , 1 , '' , 1 );
2017-10-10 07:37:39 +02:00
}
2017-07-17 05:58:27 +02:00
2020-10-27 19:46:07 +01:00
$accountstatic -> ref = $objp -> ref ;
print $accountstatic -> getNomUrl ( 1 );
} else {
print ' ' ;
}
print '</td>' ;
}
print " </tr> " ;
$i ++ ;
}
2019-12-06 09:20:45 +01:00
2020-10-27 19:46:07 +01:00
if ( empty ( $num )) {
$colspan = 6 ;
if ( ! empty ( $conf -> banque -> enabled )) $colspan ++ ;
print '<tr><td colspan="' . $colspan . '"><span class="opacitymedium">' . $langs -> trans ( " None " ) . '</span></td></tr>' ;
}
2019-12-06 09:20:45 +01:00
2020-10-27 19:46:07 +01:00
print " </table> " ;
} else {
dol_print_error ( $db );
}
}
2010-09-06 20:56:13 +02:00
2010-08-29 17:25:39 +02:00
2020-10-27 19:46:07 +01:00
if (( $action != 'addsubscription' && $action != 'create_thirdparty' )) {
// Shon online payment link
$useonlinepayment = ( ! empty ( $conf -> paypal -> enabled ) || ! empty ( $conf -> stripe -> enabled ) || ! empty ( $conf -> paybox -> enabled ));
2017-02-22 06:33:52 +01:00
2020-10-27 19:46:07 +01:00
if ( $useonlinepayment ) {
print '<br>' ;
2010-08-29 17:25:39 +02:00
2020-10-27 19:46:07 +01:00
require_once DOL_DOCUMENT_ROOT . '/core/lib/payments.lib.php' ;
print showOnlinePaymentUrl ( 'membersubscription' , $object -> ref );
print '<br>' ;
}
}
2017-09-12 12:18:26 +02:00
2020-10-27 19:46:07 +01:00
/*
2010-09-06 20:56:13 +02:00
* Add new subscription form
*/
2020-10-27 19:46:07 +01:00
if (( $action == 'addsubscription' || $action == 'create_thirdparty' ) && $user -> rights -> adherent -> cotisation -> creer ) {
print '<br>' ;
print load_fiche_titre ( $langs -> trans ( " NewCotisation " ));
// Define default choice for complementary actions
$bankdirect = 0 ; // 1 means option by default is write to bank direct with no invoice
$invoiceonly = 0 ; // 1 means option by default is invoice only
$bankviainvoice = 0 ; // 1 means option by default is write to bank via invoice
if ( GETPOST ( 'paymentsave' )) {
if ( GETPOST ( 'paymentsave' ) == 'bankdirect' ) $bankdirect = 1 ;
if ( GETPOST ( 'paymentsave' ) == 'invoiceonly' ) $invoiceonly = 1 ;
if ( GETPOST ( 'paymentsave' ) == 'bankviainvoice' ) $bankviainvoice = 1 ;
} else {
if ( ! empty ( $conf -> global -> ADHERENT_BANK_USE ) && $conf -> global -> ADHERENT_BANK_USE == 'bankviainvoice' && ! empty ( $conf -> banque -> enabled ) && ! empty ( $conf -> societe -> enabled ) && ! empty ( $conf -> facture -> enabled )) $bankviainvoice = 1 ;
elseif ( ! empty ( $conf -> global -> ADHERENT_BANK_USE ) && $conf -> global -> ADHERENT_BANK_USE == 'bankdirect' && ! empty ( $conf -> banque -> enabled )) $bankdirect = 1 ;
elseif ( ! empty ( $conf -> global -> ADHERENT_BANK_USE ) && $conf -> global -> ADHERENT_BANK_USE == 'invoiceonly' && ! empty ( $conf -> banque -> enabled ) && ! empty ( $conf -> societe -> enabled ) && ! empty ( $conf -> facture -> enabled )) $invoiceonly = 1 ;
}
2010-09-06 20:56:13 +02:00
2020-10-27 19:46:07 +01:00
print " \n \n <!-- Form add subscription --> \n " ;
2010-09-06 20:56:13 +02:00
2020-10-27 19:46:07 +01:00
if ( $conf -> use_javascript_ajax ) {
//var_dump($bankdirect.'-'.$bankviainvoice.'-'.$invoiceonly.'-'.empty($conf->global->ADHERENT_BANK_USE));
print " \n " . '<script type="text/javascript" language="javascript">' ;
print ' $ ( document ) . ready ( function () {
2019-11-13 19:35:39 +01:00
$ ( " .bankswitchclass, .bankswitchclass2 " ) . '.(($bankdirect || $bankviainvoice) ? ' show () ' : ' hide () ').' ;
2012-09-29 12:07:07 +02:00
$ ( " #none, #invoiceonly " ) . click ( function () {
$ ( " .bankswitchclass " ) . hide ();
$ ( " .bankswitchclass2 " ) . hide ();
2010-09-06 20:56:13 +02:00
});
2012-09-29 12:07:07 +02:00
$ ( " #bankdirect, #bankviainvoice " ) . click ( function () {
$ ( " .bankswitchclass " ) . show ();
$ ( " .bankswitchclass2 " ) . show ();
2010-09-06 20:56:13 +02:00
});
2012-09-29 12:07:07 +02:00
$ ( " #selectoperation " ) . change ( function () {
var code = $ ( this ) . val ();
if ( code == " CHQ " )
2011-02-26 03:17:29 +01:00
{
2012-09-29 12:07:07 +02:00
$ ( " .fieldrequireddyn " ) . addClass ( " fieldrequired " );
if ( $ ( " #fieldchqemetteur " ) . val () == " " )
2011-02-26 11:18:29 +01:00
{
2012-09-29 12:07:07 +02:00
$ ( " #fieldchqemetteur " ) . val ( $ ( " #memberlabel " ) . val ());
2011-02-26 11:18:29 +01:00
}
2011-02-26 03:23:01 +01:00
}
else
{
2012-09-29 12:07:07 +02:00
$ ( " .fieldrequireddyn " ) . removeClass ( " fieldrequired " );
2011-02-26 03:17:29 +01:00
}
});
2010-09-10 00:45:05 +02:00
' ;
2020-10-27 19:46:07 +01:00
if ( GETPOST ( 'paymentsave' )) print '$("#' . GETPOST ( 'paymentsave' ) . '").prop("checked",true);' ;
print '});' ;
print '</script>' . " \n " ;
}
2010-09-09 01:50:52 +02:00
2011-02-26 10:51:53 +01:00
// Confirm create third party
2020-05-21 09:12:18 +02:00
if ( $action == 'create_thirdparty' ) {
2019-11-13 19:35:39 +01:00
$companyalias = '' ;
2017-10-09 12:38:44 +02:00
$fullname = $object -> getFullName ( $langs );
2020-05-21 09:12:18 +02:00
if ( $object -> morphy == 'mor' ) {
2019-11-13 19:35:39 +01:00
$companyname = $object -> company ;
if ( ! empty ( $fullname )) $companyalias = $fullname ;
2020-05-21 00:47:16 +02:00
} else {
2019-11-13 19:35:39 +01:00
$companyname = $fullname ;
if ( ! empty ( $object -> company )) $companyalias = $object -> company ;
2011-02-26 10:51:53 +01:00
}
2011-03-06 14:55:47 +01:00
2011-02-26 10:51:53 +01:00
// Create a form array
2019-11-13 19:35:39 +01:00
$formquestion = array (
2017-10-09 15:49:10 +02:00
array ( 'label' => $langs -> trans ( " NameToCreate " ), 'type' => 'text' , 'name' => 'companyname' , 'value' => $companyname , 'morecss' => 'minwidth300' , 'moreattr' => 'maxlength="128"' ),
array ( 'label' => $langs -> trans ( " AliasNames " ), 'type' => 'text' , 'name' => 'companyalias' , 'value' => $companyalias , 'morecss' => 'minwidth300' , 'moreattr' => 'maxlength="128"' )
2017-10-09 12:38:44 +02:00
);
2018-12-18 21:00:06 +01:00
// If customer code was forced to "required", we ask it at creation to avoid error later
2020-05-21 09:12:18 +02:00
if ( ! empty ( $conf -> global -> MAIN_COMPANY_CODE_ALWAYS_REQUIRED )) {
2018-12-18 21:00:06 +01:00
$tmpcompany = new Societe ( $db );
2019-11-13 19:35:39 +01:00
$tmpcompany -> name = $companyname ;
2020-10-27 19:46:07 +01:00
$tmpcompany -> get_codeclient ( $tmpcompany , 0 );
2019-01-20 15:23:48 +01:00
$customercode = $tmpcompany -> code_client ;
2019-11-13 19:35:39 +01:00
$formquestion [] = array (
2020-10-27 19:46:07 +01:00
'label' => $langs -> trans ( " CustomerCode " ),
'type' => 'text' ,
'name' => 'customercode' ,
'value' => $customercode ,
'morecss' => 'minwidth300' ,
'moreattr' => 'maxlength="128"' ,
);
2018-12-18 21:00:06 +01:00
}
2019-12-11 19:11:13 +01:00
// @todo Add other extrafields mandatory for thirdparty creation
2011-03-06 14:55:47 +01:00
2019-01-27 11:55:16 +01:00
print $form -> formconfirm ( $_SERVER [ " PHP_SELF " ] . " ?rowid= " . $object -> id , $langs -> trans ( " CreateDolibarrThirdParty " ), $langs -> trans ( " ConfirmCreateThirdParty " ), " confirm_create_thirdparty " , $formquestion , 1 );
2011-02-26 10:51:53 +01:00
}
2011-03-06 14:55:47 +01:00
2020-10-27 19:46:07 +01:00
print '<form name="subscription" method="POST" action="' . $_SERVER [ " PHP_SELF " ] . '">' ;
print '<input type="hidden" name="token" value="' . newToken () . '">' ;
print '<input type="hidden" name="action" value="subscription">' ;
print '<input type="hidden" name="rowid" value="' . $rowid . '">' ;
print '<input type="hidden" name="memberlabel" id="memberlabel" value="' . dol_escape_htmltag ( $object -> getFullName ( $langs )) . '">' ;
print '<input type="hidden" name="thirdpartylabel" id="thirdpartylabel" value="' . dol_escape_htmltag ( $object -> company ) . '">' ;
2010-09-09 01:50:52 +02:00
2020-10-22 22:50:03 +02:00
print dol_get_fiche_head ( '' );
2015-05-20 06:25:43 +02:00
print " <table class= \" border \" width= \" 100% \" > \n " ;
2020-10-27 19:46:07 +01:00
print '<tbody>' ;
2015-05-20 06:25:43 +02:00
2019-11-13 19:35:39 +01:00
$today = dol_now ();
2020-10-27 19:46:07 +01:00
$datefrom = 0 ;
$dateto = 0 ;
$paymentdate = - 1 ;
2010-09-09 01:50:52 +02:00
2020-10-27 19:46:07 +01:00
// Date payment
if ( GETPOST ( 'paymentyear' ) && GETPOST ( 'paymentmonth' ) && GETPOST ( 'paymentday' )) {
$paymentdate = dol_mktime ( 0 , 0 , 0 , GETPOST ( 'paymentmonth' ), GETPOST ( 'paymentday' ), GETPOST ( 'paymentyear' ));
}
2007-02-03 23:40:04 +01:00
2020-10-27 19:46:07 +01:00
print '<tr>' ;
// Date start subscription
print '<td class="fieldrequired">' . $langs -> trans ( " DateSubscription " ) . '</td><td>' ;
if ( GETPOST ( 'reday' )) {
$datefrom = dol_mktime ( 0 , 0 , 0 , GETPOST ( 'remonth' ), GETPOST ( 'reday' ), GETPOST ( 'reyear' ));
}
if ( ! $datefrom ) {
$datefrom = $object -> datevalid ;
if ( $object -> datefin > 0 ) {
$datefrom = dol_time_plus_duree ( $object -> datefin , 1 , 'd' );
}
}
print $form -> selectDate ( $datefrom , '' , '' , '' , '' , " subscription " , 1 , 1 );
print " </td></tr> " ;
2007-09-04 19:53:11 +02:00
2020-10-27 19:46:07 +01:00
// Date end subscription
if ( GETPOST ( 'endday' )) {
$dateto = dol_mktime ( 0 , 0 , 0 , GETPOST ( 'endmonth' ), GETPOST ( 'endday' ), GETPOST ( 'endyear' ));
}
if ( ! $dateto ) {
$dateto = - 1 ; // By default, no date is suggested
}
print '<tr><td>' . $langs -> trans ( " DateEndSubscription " ) . '</td><td>' ;
print $form -> selectDate ( $dateto , 'end' , '' , '' , '' , " subscription " , 1 , 0 );
print " </td></tr> " ;
if ( $adht -> subscription ) {
// Amount
print '<tr><td class="fieldrequired">' . $langs -> trans ( " Amount " ) . '</td><td><input type="text" name="subscription" size="6" value="' . GETPOST ( 'subscription' ) . '"> ' . $langs -> trans ( " Currency " . $conf -> currency ) . '</td></tr>' ;
// Label
print '<tr><td>' . $langs -> trans ( " Label " ) . '</td>' ;
print '<td><input name="label" type="text" size="32" value="' ;
if ( empty ( $conf -> global -> MEMBER_NO_DEFAULT_LABEL )) print $langs -> trans ( " Subscription " ) . ' ' . dol_print_date (( $datefrom ? $datefrom : time ()), " %Y " );
print '"></td></tr>' ;
// Complementary action
if (( ! empty ( $conf -> banque -> enabled ) || ! empty ( $conf -> facture -> enabled )) && empty ( $conf -> global -> ADHERENT_SUBSCRIPTION_HIDECOMPLEMENTARYACTIONS )) {
$company = new Societe ( $db );
if ( $object -> fk_soc ) {
$result = $company -> fetch ( $object -> fk_soc );
}
// Title payments
//print '<tr><td colspan="2"><b>'.$langs->trans("Payment").'</b></td></tr>';
// No more action
print '<tr><td class="tdtop fieldrequired">' . $langs -> trans ( 'MoreActions' );
print '</td>' ;
print '<td>' ;
print '<input type="radio" class="moreaction" id="none" name="paymentsave" value="none"' . ( empty ( $bankdirect ) && empty ( $invoiceonly ) && empty ( $bankviainvoice ) ? ' checked' : '' ) . '> ' . $langs -> trans ( " None " ) . '<br>' ;
// Add entry into bank accoun
if ( ! empty ( $conf -> banque -> enabled )) {
print '<input type="radio" class="moreaction" id="bankdirect" name="paymentsave" value="bankdirect"' . ( ! empty ( $bankdirect ) ? ' checked' : '' );
print '> ' . $langs -> trans ( " MoreActionBankDirect " ) . '<br>' ;
}
// Add invoice with no payments
if ( ! empty ( $conf -> societe -> enabled ) && ! empty ( $conf -> facture -> enabled )) {
print '<input type="radio" class="moreaction" id="invoiceonly" name="paymentsave" value="invoiceonly"' . ( ! empty ( $invoiceonly ) ? ' checked' : '' );
//if (empty($object->fk_soc)) print ' disabled';
print '> ' . $langs -> trans ( " MoreActionInvoiceOnly " );
if ( $object -> fk_soc ) print ' (' . $langs -> trans ( " ThirdParty " ) . ': ' . $company -> getNomUrl ( 1 ) . ')' ;
else {
print ' (' ;
if ( empty ( $object -> fk_soc )) print img_warning ( $langs -> trans ( " NoThirdPartyAssociatedToMember " ));
print $langs -> trans ( " NoThirdPartyAssociatedToMember " );
print ' - <a href="' . $_SERVER [ " PHP_SELF " ] . '?rowid=' . $object -> id . '&action=create_thirdparty">' ;
print $langs -> trans ( " CreateDolibarrThirdParty " );
print '</a>)' ;
}
if ( empty ( $conf -> global -> ADHERENT_VAT_FOR_SUBSCRIPTIONS ) || $conf -> global -> ADHERENT_VAT_FOR_SUBSCRIPTIONS != 'defaultforfoundationcountry' ) print '. <span class="opacitymedium">' . $langs -> trans ( " NoVatOnSubscription " , 0 ) . '</span>' ;
2020-05-21 00:47:16 +02:00
if ( ! empty ( $conf -> global -> ADHERENT_PRODUCT_ID_FOR_SUBSCRIPTIONS ) && ( ! empty ( $conf -> product -> enabled ) || ! empty ( $conf -> service -> enabled ))) {
2019-11-13 19:35:39 +01:00
$prodtmp = new Product ( $db );
2020-07-31 16:09:38 +02:00
$result = $prodtmp -> fetch ( $conf -> global -> ADHERENT_PRODUCT_ID_FOR_SUBSCRIPTIONS );
if ( $result < 0 ) {
setEventMessage ( $prodtmp -> error , 'errors' );
}
2019-11-13 19:35:39 +01:00
print '. ' . $langs -> transnoentitiesnoconv ( " ADHERENT_PRODUCT_ID_FOR_SUBSCRIPTIONS " , $prodtmp -> getNomUrl ( 1 )); // must use noentitiesnoconv to avoid to encode html into getNomUrl of product
2017-10-10 07:37:39 +02:00
}
2020-10-27 19:46:07 +01:00
print '<br>' ;
}
// Add invoice with payments
if ( ! empty ( $conf -> banque -> enabled ) && ! empty ( $conf -> societe -> enabled ) && ! empty ( $conf -> facture -> enabled )) {
print '<input type="radio" class="moreaction" id="bankviainvoice" name="paymentsave" value="bankviainvoice"' . ( ! empty ( $bankviainvoice ) ? ' checked' : '' );
//if (empty($object->fk_soc)) print ' disabled';
print '> ' . $langs -> trans ( " MoreActionBankViaInvoice " );
if ( $object -> fk_soc ) print ' (' . $langs -> trans ( " ThirdParty " ) . ': ' . $company -> getNomUrl ( 1 ) . ')' ;
else {
print ' (' ;
if ( empty ( $object -> fk_soc )) print img_warning ( $langs -> trans ( " NoThirdPartyAssociatedToMember " ));
print $langs -> trans ( " NoThirdPartyAssociatedToMember " );
print ' - <a href="' . $_SERVER [ " PHP_SELF " ] . '?rowid=' . $object -> id . '&action=create_thirdparty">' ;
print $langs -> trans ( " CreateDolibarrThirdParty " );
print '</a>)' ;
}
if ( empty ( $conf -> global -> ADHERENT_VAT_FOR_SUBSCRIPTIONS ) || $conf -> global -> ADHERENT_VAT_FOR_SUBSCRIPTIONS != 'defaultforfoundationcountry' ) print '. <span class="opacitymedium">' . $langs -> trans ( " NoVatOnSubscription " , 0 ) . '</span>' ;
2020-05-21 09:12:18 +02:00
if ( ! empty ( $conf -> global -> ADHERENT_PRODUCT_ID_FOR_SUBSCRIPTIONS ) && ( ! empty ( $conf -> product -> enabled ) || ! empty ( $conf -> service -> enabled ))) {
2019-11-13 19:35:39 +01:00
$prodtmp = new Product ( $db );
2020-07-31 16:09:38 +02:00
$result = $prodtmp -> fetch ( $conf -> global -> ADHERENT_PRODUCT_ID_FOR_SUBSCRIPTIONS );
if ( $result < 0 ) {
setEventMessage ( $prodtmp -> error , 'errors' );
}
2019-11-13 19:35:39 +01:00
print '. ' . $langs -> transnoentitiesnoconv ( " ADHERENT_PRODUCT_ID_FOR_SUBSCRIPTIONS " , $prodtmp -> getNomUrl ( 1 )); // must use noentitiesnoconv to avoid to encode html into getNomUrl of product
2017-10-10 07:37:39 +02:00
}
2020-10-31 14:32:18 +01:00
print '<br>' ;
}
print '</td></tr>' ;
// Bank account
print '<tr class="bankswitchclass"><td class="fieldrequired">' . $langs -> trans ( " FinancialAccount " ) . '</td><td>' ;
$form -> select_comptes ( GETPOST ( 'accountid' ), 'accountid' , 0 , '' , 2 );
print " </td></tr> \n " ;
// Payment mode
print '<tr class="bankswitchclass"><td class="fieldrequired">' . $langs -> trans ( " PaymentMode " ) . '</td><td>' ;
$form -> select_types_paiements ( GETPOST ( 'operation' ), 'operation' , '' , 2 );
print " </td></tr> \n " ;
// Date of payment
print '<tr class="bankswitchclass"><td class="fieldrequired">' . $langs -> trans ( " DatePayment " ) . '</td><td>' ;
print $form -> selectDate ( isset ( $paymentdate ) ? $paymentdate : - 1 , 'payment' , 0 , 0 , 1 , 'subscription' , 1 , 1 );
print " </td></tr> \n " ;
print '<tr class="bankswitchclass2"><td>' . $langs -> trans ( 'Numero' );
print ' <em>(' . $langs -> trans ( " ChequeOrTransferNumber " ) . ')</em>' ;
print '</td>' ;
print '<td><input id="fieldnum_chq" name="num_chq" type="text" size="8" value="' . ( ! GETPOST ( 'num_chq' ) ? '' : GETPOST ( 'num_chq' )) . '"></td></tr>' ;
print '<tr class="bankswitchclass2 fieldrequireddyn"><td>' . $langs -> trans ( 'CheckTransmitter' );
print ' <em>(' . $langs -> trans ( " ChequeMaker " ) . ')</em>' ;
print '</td>' ;
print '<td><input id="fieldchqemetteur" name="chqemetteur" size="32" type="text" value="' . ( ! GETPOST ( 'chqemetteur' ) ? '' : GETPOST ( 'chqemetteur' )) . '"></td></tr>' ;
print '<tr class="bankswitchclass2"><td>' . $langs -> trans ( 'Bank' );
print ' <em>(' . $langs -> trans ( " ChequeBank " ) . ')</em>' ;
print '</td>' ;
print '<td><input id="chqbank" name="chqbank" size="32" type="text" value="' . ( ! GETPOST ( 'chqbank' ) ? '' : GETPOST ( 'chqbank' )) . '"></td></tr>' ;
}
}
print '<tr><td></td><td></td></tr>' ;
print '<tr><td>' . $langs -> trans ( " SendAcknowledgementByMail " ) . '</td>' ;
print '<td>' ;
if ( ! $object -> email ) {
print $langs -> trans ( " NoEMail " );
} else {
$adht = new AdherentType ( $db );
$adht -> fetch ( $object -> typeid );
// Send subscription email
$subject = '' ;
$msg = '' ;
// Send subscription email
include_once DOL_DOCUMENT_ROOT . '/core/class/html.formmail.class.php' ;
$formmail = new FormMail ( $db );
// Set output language
$outputlangs = new Translate ( '' , $conf );
$outputlangs -> setDefaultLang ( empty ( $object -> thirdparty -> default_lang ) ? $mysoc -> default_lang : $object -> thirdparty -> default_lang );
// Load traductions files required by page
$outputlangs -> loadLangs ( array ( " main " , " members " ));
// Get email content from template
$arraydefaultmessage = null ;
$labeltouse = $conf -> global -> ADHERENT_EMAIL_TEMPLATE_SUBSCRIPTION ;
if ( ! empty ( $labeltouse )) $arraydefaultmessage = $formmail -> getEMailTemplate ( $db , 'member' , $user , $outputlangs , 0 , 1 , $labeltouse );
if ( ! empty ( $labeltouse ) && is_object ( $arraydefaultmessage ) && $arraydefaultmessage -> id > 0 ) {
$subject = $arraydefaultmessage -> topic ;
$msg = $arraydefaultmessage -> content ;
}
$substitutionarray = getCommonSubstitutionArray ( $outputlangs , 0 , null , $object );
complete_substitutions_array ( $substitutionarray , $outputlangs , $object );
$subjecttosend = make_substitutions ( $subject , $substitutionarray , $outputlangs );
$texttosend = make_substitutions ( dol_concatdesc ( $msg , $adht -> getMailOnSubscription ()), $substitutionarray , $outputlangs );
$tmp = '<input name="sendmail" type="checkbox"' . ( GETPOST ( 'sendmail' , 'alpha' ) ? ' checked' : ( ! empty ( $conf -> global -> ADHERENT_DEFAULT_SENDINFOBYMAIL ) ? ' checked' : '' )) . '>' ;
$helpcontent = '' ;
$helpcontent .= '<b>' . $langs -> trans ( " MailFrom " ) . '</b>: ' . $conf -> global -> ADHERENT_MAIL_FROM . '<br>' . " \n " ;
$helpcontent .= '<b>' . $langs -> trans ( " MailRecipient " ) . '</b>: ' . $object -> email . '<br>' . " \n " ;
$helpcontent .= '<b>' . $langs -> trans ( " MailTopic " ) . '</b>:<br>' . " \n " ;
if ( $subjecttosend ) {
$helpcontent .= $subjecttosend . " \n " ;
} else {
$langs -> load ( " errors " );
$helpcontent .= '<span class="error">' . $langs -> trans ( " ErrorModuleSetupNotComplete " , $langs -> transnoentitiesnoconv ( " Module310Name " )) . '</span>' . " \n " ;
}
$helpcontent .= " <br> " ;
$helpcontent .= '<b>' . $langs -> trans ( " MailText " ) . '</b>:<br>' ;
if ( $texttosend ) {
$helpcontent .= dol_htmlentitiesbr ( $texttosend ) . " \n " ;
} else {
$langs -> load ( " errors " );
$helpcontent .= '<span class="error">' . $langs -> trans ( " ErrorModuleSetupNotComplete " , $langs -> transnoentitiesnoconv ( " Module310Name " )) . '</span>' . " \n " ;
}
print $form -> textwithpicto ( $tmp , $helpcontent , 1 , 'help' , '' , 0 , 2 , 'helpemailtosend' );
}
print '</td></tr>' ;
print '</tbody>' ;
print '</table>' ;
print dol_get_fiche_end ();
print '<div class="center">' ;
print '<input type="submit" class="button" name="add" value="' . $langs -> trans ( " AddSubscription " ) . '">' ;
print ' ' ;
2020-11-23 15:12:52 +01:00
print '<input type="submit" class="button button-cancel" name="cancel" value="' . $langs -> trans ( " Cancel " ) . '">' ;
2020-10-31 14:32:18 +01:00
print '</div>' ;
print '</form>' ;
print " \n <!-- End form subscription --> \n \n " ;
}
//print '</td></tr>';
//print '</table>';
2020-05-21 00:47:16 +02:00
} else {
2020-10-31 14:32:18 +01:00
$langs -> load ( " errors " );
print $langs -> trans ( " ErrorRecordNotFound " );
2007-02-03 23:40:04 +01:00
}
2018-07-28 14:29:28 +02:00
// End of page
2011-08-27 16:24:16 +02:00
llxFooter ();
2012-03-04 01:09:39 +01:00
$db -> close ();