2004-10-19 18:58:50 +00:00
< ? php
2025-09-17 16:18:16 +00:00
/* Copyright ( C ) 2002 - 2004 Rodolphe Quiedeville < rodolphe @ quiedeville . org >
* Copyright ( C ) 2006 - 2015 Laurent Destailleur < eldy @ users . sourceforge . net >
2026-04-19 14:10:54 +00:00
* Copyright ( C ) 2024 - 2026 MDW < mdeweerd @ users . noreply . github . com >
2025-09-17 16:18:16 +00:00
* Copyright ( C ) 2024 - 2025 Frédéric France < frederic . france @ free . fr >
2003-08-31 22:05:54 +00: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 14:36:08 +00:00
* the Free Software Foundation ; either version 3 of the License , or
2003-08-31 22:05:54 +00: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 19:55:30 +00:00
* along with this program . If not , see < https :// www . gnu . org / licenses />.
2003-08-31 22:05:54 +00:00
*/
2007-05-28 13:14:50 +00:00
/**
2016-09-24 04:48:40 +00:00
* \file htdocs / adherents / class / subscription . class . php
* \ingroup member
* \brief File of class to manage subscriptions of foundation members
2009-10-10 16:00:35 +00:00
*/
2004-07-27 22:46:33 +00:00
2017-11-15 10:39:11 +00:00
//namespace DolibarrMember;
2012-08-22 21:11:24 +00:00
require_once DOL_DOCUMENT_ROOT . '/core/class/commonobject.class.php' ;
2010-04-17 14:49:27 +00:00
2004-07-27 22:46:33 +00:00
2007-05-28 13:14:50 +00:00
/**
2012-11-15 13:52:19 +00:00
* Class to manage subscriptions of foundation members
2009-10-10 16:00:35 +00:00
*/
2016-09-24 04:48:40 +00:00
class Subscription extends CommonObject
2003-08-31 22:05:54 +00:00
{
2020-10-31 13:32:18 +00:00
/**
* @ var string ID to identify managed object
*/
public $element = 'subscription' ;
/**
* @ var string Name of table without prefix where object is stored
*/
public $table_element = 'subscription' ;
/**
* @ var string String with name of icon for myobject . Must be the part after the 'object_' into object_myobject . png
*/
public $picto = 'payment' ;
/**
* Date creation record ( datec )
*
* @ var integer
*/
public $datec ;
/**
* Date modification record ( tms )
*
* @ var integer
*/
public $datem ;
/**
* Subscription start date ( date subscription )
*
* @ var integer
*/
public $dateh ;
/**
* Subscription end date
*
* @ var integer
*/
public $datef ;
Fix #38279 expose Subscription dates and note under documented names in API (#38674)
GET /api/index.php/members/{id}/subscriptions returned the raw
Subscription object fields (dateh, datef, note_public, amount) while
POST /api/index.php/members/{id}/subscriptions takes start_date,
end_date, amount, label. A client that fetches existing subscriptions
to push them back has to translate the field names by hand.
Per @eldy review on PR #38556, address this with the renaming that
fits the rest of the codebase:
- Add date_start / date_end aliases on the Subscription class. The
date_start / date_end naming convention is already used by other
objects (task, expense, holiday), so the alias matches the existing
contract instead of inventing a new pair of names.
- Do not introduce a 'label' alias. note_public is already the
documented field on v24; declare it as a real property so phpstan
stops flagging the dynamic-property write.
- _cleanObjectDatas on the Subscription branch now sets only
date_start and date_end. note_public is left as the existing
property name. dateh / datef stay populated for backward
compatibility with existing consumers.
Develop-branch version of PR #38556 (closed).
Signed-off-by: Dolicraft <contact@dolicraft.com>
Co-authored-by: Dolicraft <contact@dolicraft.com>
2026-06-10 19:16:27 +00:00
/**
* Alias of $dateh exposed by the REST API GET response so the same payload
* can be sent back to POST / members / { id } / subscriptions without renaming
* client - side . Matches the date_start / date_end naming convention used by
* other Dolibarr objects . Not persisted ( see issue #38279).
*
* @ var integer
*/
public $date_start ;
/**
* Alias of $datef exposed by the REST API GET response ( see issue #38279).
* Not persisted .
*
* @ var integer
*/
public $date_end ;
/**
* Public note exposed under the documented field name . Already populated by
* fetch () but not declared as a real property ; declared here so phpstan and
* phan stop flagging the API setter as touching a dynamic property .
*
* @ var string
*/
public $note_public ;
2020-10-31 13:32:18 +00:00
/**
* @ var int ID
*/
public $fk_type ;
2020-12-30 20:41:44 +00:00
/**
* @ var int Member ID
*/
2020-10-31 13:32:18 +00:00
public $fk_adherent ;
2020-12-30 20:41:44 +00:00
/**
* @ var double amount subscription
*/
2020-10-31 13:32:18 +00:00
public $amount ;
/**
2023-06-08 07:55:08 +00:00
* @ var int ID of bank in llx_bank
2020-10-31 13:32:18 +00:00
*/
public $fk_bank ;
2023-06-08 07:55:08 +00:00
/**
2026-04-19 14:10:54 +00:00
* @ var array < string , array { type : string , label : string , enabled : int < 0 , 2 >| string , position : int , visible : int <- 6 , 6 >| string , langfile ? : string , notnull ? : int <- 1 , 1 > , noteditable ? : int < 0 , 1 > , alwayseditable ? : int < 0 , 1 >| string , default ? : string | int , index ? : int < 0 , 1 > , foreignkey ? : string , searchall ? : int < 0 , 1 > , isameasure ? : int < 0 , 1 > , css ? : string , cssview ? : string , csslist ? : string , help ? : string , helplist ? : string , showoncombobox ? : int < 0 , 4 >| string , disabled ? : int < 0 , 1 >| string , arrayofkeyval ? : array < int | string , string > , autofocusoncreate ? : int < 0 , 1 > , comment ? : string , copytoclipboard ? : int < 1 , 2 > , validate ? : int < 0 , 1 >| string , showonheader ? : int < 0 , 1 > , searchmulti ? : int < 0 , 1 > , picto ? : string , required ? : int < 0 , 1 > , placeholder ? : string } > Array with all fields and their property . Do not use it as a static var . It may be modified by constructor .
2023-06-08 07:55:08 +00:00
*/
2020-10-31 13:32:18 +00:00
public $fields = array (
2024-03-11 16:38:38 +00:00
'rowid' => array ( 'type' => 'integer' , 'label' => 'TechnicalID' , 'enabled' => 1 , 'visible' => - 1 , 'notnull' => 1 , 'position' => 10 ),
'tms' => array ( 'type' => 'timestamp' , 'label' => 'DateModification' , 'enabled' => 1 , 'visible' => - 1 , 'notnull' => 1 , 'position' => 15 ),
'datec' => array ( 'type' => 'datetime' , 'label' => 'DateCreation' , 'enabled' => 1 , 'visible' => - 1 , 'position' => 20 ),
'fk_adherent' => array ( 'type' => 'integer' , 'label' => 'Member' , 'enabled' => 1 , 'visible' => - 1 , 'position' => 25 ),
'dateadh' => array ( 'type' => 'datetime' , 'label' => 'DateSubscription' , 'enabled' => 1 , 'visible' => - 1 , 'position' => 30 ),
'datef' => array ( 'type' => 'datetime' , 'label' => 'DateEndSubscription' , 'enabled' => 1 , 'visible' => - 1 , 'position' => 35 ),
'subscription' => array ( 'type' => 'double(24,8)' , 'label' => 'Amount' , 'enabled' => 1 , 'visible' => - 1 , 'position' => 40 , 'isameasure' => 1 ),
'fk_bank' => array ( 'type' => 'integer' , 'label' => 'BankId' , 'enabled' => 1 , 'visible' => - 1 , 'position' => 45 ),
'note' => array ( 'type' => 'html' , 'label' => 'Note' , 'enabled' => 1 , 'visible' => - 1 , 'position' => 50 ),
'fk_type' => array ( 'type' => 'integer' , 'label' => 'MemberType' , 'enabled' => 1 , 'visible' => - 1 , 'position' => 55 ),
'fk_user_creat' => array ( 'type' => 'integer:User:user/class/user.class.php' , 'label' => 'UserAuthor' , 'enabled' => 1 , 'visible' => - 2 , 'position' => 60 ),
'fk_user_valid' => array ( 'type' => 'integer:User:user/class/user.class.php' , 'label' => 'UserValidation' , 'enabled' => 1 , 'visible' => - 1 , 'position' => 65 ),
2025-10-17 16:24:40 +00:00
'import_key' => array ( 'type' => 'varchar(14)' , 'label' => 'ImportId' , 'enabled' => 1 , 'visible' => - 2 , 'position' => 805 ),
2020-10-31 13:32:18 +00:00
);
/**
* Constructor
*
* @ param DoliDB $db Database handler
*/
public function __construct ( $db )
{
$this -> db = $db ;
2024-05-04 22:34:19 +00:00
$this -> ismultientitymanaged = 'fk_adherent@adherent' ;
2020-10-31 13:32:18 +00:00
}
/**
2023-06-08 07:55:08 +00:00
* Function who permitted creation of the subscription
2020-10-31 13:32:18 +00:00
*
* @ param User $user User that create
2024-01-12 17:07:53 +00:00
* @ param int $notrigger 0 = launch triggers after , 1 = disable triggers
2023-12-06 14:46:39 +00:00
* @ return int Return integer < 0 if KO , Id subscription created if OK
2020-10-31 13:32:18 +00:00
*/
2024-01-12 17:07:53 +00:00
public function create ( $user , $notrigger = 0 )
2020-10-31 13:32:18 +00:00
{
global $langs ;
$error = 0 ;
$now = dol_now ();
2025-10-17 16:24:40 +00:00
// Clean parameters
if ( isset ( $this -> import_key )) {
$this -> import_key = trim ( $this -> import_key );
}
2020-10-31 13:32:18 +00:00
// Check parameters
if ( $this -> datef <= $this -> dateh ) {
$this -> error = $langs -> trans ( " ErrorBadValueForDate " );
return - 1 ;
}
2020-12-30 20:41:44 +00:00
if ( empty ( $this -> datec )) {
$this -> datec = $now ;
}
2020-10-31 13:32:18 +00:00
$this -> db -> begin ();
require_once DOL_DOCUMENT_ROOT . '/adherents/class/adherent.class.php' ;
$member = new Adherent ( $this -> db );
$result = $member -> fetch ( $this -> fk_adherent );
if ( $this -> fk_type == null ) { // If type not defined, we use the type of member
$type = $member -> typeid ;
} else {
$type = $this -> fk_type ;
}
2025-01-23 13:20:47 +00:00
2025-10-17 16:24:40 +00:00
$sql = " INSERT INTO " . MAIN_DB_PREFIX . " subscription (fk_adherent, fk_type, datec, dateadh, datef, subscription, note, note_private, ref_ext, fk_user_creat, import_key) " ;
2025-02-03 10:24:16 +00:00
$sql .= " VALUES ( " . (( int ) $this -> fk_adherent ) . " , ' " . $this -> db -> escape (( string ) $type ) . " ', ' " . $this -> db -> idate ( $now ) . " ', " ;
2020-10-31 13:32:18 +00:00
$sql .= " ' " . $this -> db -> idate ( $this -> dateh ) . " ', " ;
$sql .= " ' " . $this -> db -> idate ( $this -> datef ) . " ', " ;
2021-06-14 11:51:09 +00:00
$sql .= " " . (( float ) $this -> amount ) . " , " ;
2025-01-23 13:20:47 +00:00
$sql .= " ' " . $this -> db -> escape ( $this -> note_public ? $this -> note_public : $this -> note ) . " ', " ;
2025-10-09 04:18:45 +00:00
$sql .= " ' " . $this -> db -> escape ( $this -> note_private ) . " ', " ;
$sql .= " " . ( empty ( $this -> ref_ext ) ? " null " : " ' " . $this -> db -> escape ( $this -> ref_ext ) . " ' " ) . " , " ;
2026-07-20 00:51:42 +00:00
$sql .= " " . (( int ) ( $this -> user_creation_id > 0 ? $this -> user_creation_id : (( int ) $user -> id )));
2025-10-17 16:24:40 +00:00
$sql .= " , " . ( ! empty ( $this -> import_key ) ? " ' " . $this -> db -> escape ( $this -> import_key ) . " ' " : " null " );
2025-01-23 13:20:47 +00:00
$sql .= " ) " ;
2020-10-31 13:32:18 +00:00
$resql = $this -> db -> query ( $sql );
if ( ! $resql ) {
$error ++ ;
$this -> errors [] = $this -> db -> lasterror ();
}
if ( ! $error ) {
$this -> id = $this -> db -> last_insert_id ( MAIN_DB_PREFIX . $this -> table_element );
$this -> fk_type = $type ;
}
2024-03-17 22:06:11 +00:00
if ( ! empty ( $this -> linkedObjectsIds ) && empty ( $this -> linked_objects )) { // To use new linkedObjectsIds instead of old linked_objects
$this -> linked_objects = $this -> linkedObjectsIds ; // TODO Replace linked_objects with linkedObjectsIds
}
// Add object linked
if ( ! $error && $this -> id && ! empty ( $this -> linked_objects ) && is_array ( $this -> linked_objects )) {
foreach ( $this -> linked_objects as $origin => $tmp_origin_id ) {
if ( is_array ( $tmp_origin_id )) { // New behaviour, if linked_object can have several links per type, so is something like array('contract'=>array(id1, id2, ...))
foreach ( $tmp_origin_id as $origin_id ) {
$ret = $this -> add_object_linked ( $origin , $origin_id );
if ( ! $ret ) {
$this -> error = $this -> db -> lasterror ();
$error ++ ;
}
}
} else { // Old behaviour, if linked_object has only one link per type, so is something like array('contract'=>id1))
$origin_id = $tmp_origin_id ;
$ret = $this -> add_object_linked ( $origin , $origin_id );
if ( ! $ret ) {
$this -> error = $this -> db -> lasterror ();
$error ++ ;
}
}
}
}
2020-10-31 13:32:18 +00:00
if ( ! $error && ! $notrigger ) {
2020-11-08 17:52:26 +00:00
$this -> context = array ( 'member' => $member );
2020-10-31 13:32:18 +00:00
// Call triggers
$result = $this -> call_trigger ( 'MEMBER_SUBSCRIPTION_CREATE' , $user );
2020-12-30 20:41:44 +00:00
if ( $result < 0 ) {
$error ++ ;
}
2020-10-31 13:32:18 +00:00
// End call triggers
}
// Commit or rollback
if ( $error ) {
$this -> db -> rollback ();
return - 1 ;
} else {
$this -> db -> commit ();
return $this -> id ;
}
}
/**
* Method to load a subscription
*
* @ param int $rowid Id subscription
2023-12-06 14:46:39 +00:00
* @ return int Return integer < 0 if KO , = 0 if not found , > 0 if OK
2020-10-31 13:32:18 +00:00
*/
public function fetch ( $rowid )
{
$sql = " SELECT rowid, fk_type, fk_adherent, datec, " ;
$sql .= " tms, " ;
$sql .= " dateadh as dateh, " ;
$sql .= " datef, " ;
2022-01-23 18:20:13 +00:00
$sql .= " subscription, note as note_public, fk_bank " ;
2020-10-31 13:32:18 +00:00
$sql .= " FROM " . MAIN_DB_PREFIX . " subscription " ;
2023-06-08 07:55:08 +00:00
$sql .= " WHERE rowid = " . (( int ) $rowid );
2020-10-31 13:32:18 +00:00
dol_syslog ( get_class ( $this ) . " ::fetch " , LOG_DEBUG );
$resql = $this -> db -> query ( $sql );
if ( $resql ) {
if ( $this -> db -> num_rows ( $resql )) {
$obj = $this -> db -> fetch_object ( $resql );
$this -> id = $obj -> rowid ;
$this -> ref = $obj -> rowid ;
$this -> fk_type = $obj -> fk_type ;
$this -> fk_adherent = $obj -> fk_adherent ;
$this -> datec = $this -> db -> jdate ( $obj -> datec );
$this -> datem = $this -> db -> jdate ( $obj -> tms );
$this -> dateh = $this -> db -> jdate ( $obj -> dateh );
$this -> datef = $this -> db -> jdate ( $obj -> datef );
$this -> amount = $obj -> subscription ;
2022-01-23 18:20:13 +00:00
$this -> note = $obj -> note_public ; // deprecated
$this -> note_public = $obj -> note_public ;
2020-10-31 13:32:18 +00:00
$this -> fk_bank = $obj -> fk_bank ;
return 1 ;
} else {
return 0 ;
}
} else {
$this -> error = $this -> db -> lasterror ();
return - 1 ;
}
}
/**
* Update subscription
*
* @ param User $user User who updated
* @ param int $notrigger 0 = Disable triggers
2023-12-01 18:51:32 +00:00
* @ return int Return integer < 0 if KO , > 0 if OK
2020-10-31 13:32:18 +00:00
*/
public function update ( $user , $notrigger = 0 )
{
$error = 0 ;
$this -> db -> begin ();
2020-12-01 01:41:19 +00:00
if ( ! is_numeric ( $this -> amount )) {
$this -> error = 'BadValueForParameterAmount' ;
return - 1 ;
}
2020-11-27 13:24:15 +00:00
2022-01-23 18:20:13 +00:00
if ( empty ( $this -> note_public ) && ! empty ( $this -> note )) { // For backward compatibility
$this -> note_public = $this -> note ;
}
2020-10-31 13:32:18 +00:00
$sql = " UPDATE " . MAIN_DB_PREFIX . " subscription SET " ;
2021-06-09 13:36:47 +00:00
$sql .= " fk_type = " . (( int ) $this -> fk_type ) . " , " ;
$sql .= " fk_adherent = " . (( int ) $this -> fk_adherent ) . " , " ;
2023-06-08 07:55:08 +00:00
$sql .= " note = " . ( $this -> note_public ? " ' " . $this -> db -> escape ( $this -> note_public ) . " ' " : 'null' ) . " , " ;
2024-03-04 23:15:33 +00:00
$sql .= " subscription = " . ( float ) price2num ( $this -> amount ) . " , " ;
2023-06-08 07:55:08 +00:00
$sql .= " dateadh = ' " . $this -> db -> idate ( $this -> dateh ) . " ', " ;
$sql .= " datef = ' " . $this -> db -> idate ( $this -> datef ) . " ', " ;
$sql .= " datec = ' " . $this -> db -> idate ( $this -> datec ) . " ', " ;
2021-06-09 13:36:47 +00:00
$sql .= " fk_bank = " . ( $this -> fk_bank ? (( int ) $this -> fk_bank ) : 'null' );
2021-08-27 14:33:03 +00:00
$sql .= " WHERE rowid = " . (( int ) $this -> id );
2020-10-31 13:32:18 +00:00
dol_syslog ( get_class ( $this ) . " ::update " , LOG_DEBUG );
$resql = $this -> db -> query ( $sql );
if ( $resql ) {
require_once DOL_DOCUMENT_ROOT . '/adherents/class/adherent.class.php' ;
$member = new Adherent ( $this -> db );
$result = $member -> fetch ( $this -> fk_adherent );
$result = $member -> update_end_date ( $user );
2025-09-17 16:18:16 +00:00
if ( ! $notrigger ) {
2024-03-11 16:38:38 +00:00
$this -> context = array ( 'member' => $member );
2020-10-31 13:32:18 +00:00
// Call triggers
$result = $this -> call_trigger ( 'MEMBER_SUBSCRIPTION_MODIFY' , $user );
2020-12-30 20:41:44 +00:00
if ( $result < 0 ) {
$error ++ ;
} //Do also here what you must do to rollback action if trigger fail
2020-10-31 13:32:18 +00:00
// End call triggers
}
} else {
$error ++ ;
$this -> error = $this -> db -> lasterror ();
}
// Commit or rollback
if ( $error ) {
$this -> db -> rollback ();
return - 1 ;
} else {
$this -> db -> commit ();
return $this -> id ;
}
}
/**
* Delete a subscription
*
2024-09-12 19:16:42 +00:00
* @ param User $user User that delete
* @ param int < 0 , 1 > $notrigger 0 = launch triggers after , 1 = disable triggers
* @ return int Return integer < 0 if KO , 0 if not found , > 0 if OK
2020-10-31 13:32:18 +00:00
*/
2024-01-12 16:47:54 +00:00
public function delete ( $user , $notrigger = 0 )
2020-10-31 13:32:18 +00:00
{
$error = 0 ;
// It subscription is linked to a bank transaction, we get it
if ( $this -> fk_bank > 0 ) {
require_once DOL_DOCUMENT_ROOT . '/compta/bank/class/account.class.php' ;
$accountline = new AccountLine ( $this -> db );
$result = $accountline -> fetch ( $this -> fk_bank );
2024-09-12 19:16:42 +00:00
} else {
$accountline = null ;
2020-10-31 13:32:18 +00:00
}
$this -> db -> begin ();
2025-09-17 16:18:16 +00:00
if ( ! $notrigger ) {
// Call triggers
$result = $this -> call_trigger ( 'MEMBER_SUBSCRIPTION_DELETE' , $user );
if ( $result < 0 ) {
$error ++ ;
} // Do also here what you must do to rollback action if trigger fail
// End call triggers
2020-10-31 13:32:18 +00:00
}
if ( ! $error ) {
2021-06-09 13:36:47 +00:00
$sql = " DELETE FROM " . MAIN_DB_PREFIX . " subscription WHERE rowid = " . (( int ) $this -> id );
2020-10-31 13:32:18 +00:00
dol_syslog ( get_class ( $this ) . " ::delete " , LOG_DEBUG );
$resql = $this -> db -> query ( $sql );
if ( $resql ) {
$num = $this -> db -> affected_rows ( $resql );
if ( $num ) {
require_once DOL_DOCUMENT_ROOT . '/adherents/class/adherent.class.php' ;
$member = new Adherent ( $this -> db );
$result = $member -> fetch ( $this -> fk_adherent );
$result = $member -> update_end_date ( $user );
if ( $this -> fk_bank > 0 && is_object ( $accountline ) && $accountline -> id > 0 ) { // If we found bank account line (this means this->fk_bank defined)
2022-03-25 13:43:48 +00:00
$result = $accountline -> delete ( $user ); // Return false if refused because line is reconciled
2025-09-17 16:18:16 +00:00
if ( $result <= 0 ) {
$this -> setErrorsFromObject ( $accountline );
$error ++ ;
2020-10-31 13:32:18 +00:00
}
}
} else {
$this -> db -> commit ();
return 0 ;
}
} else {
$error ++ ;
$this -> error = $this -> db -> lasterror ();
}
}
// Commit or rollback
if ( $error ) {
$this -> db -> rollback ();
return - 1 ;
} else {
$this -> db -> commit ();
return 1 ;
}
}
/**
2024-08-06 23:20:43 +00:00
* Return clickable name ( with picto eventually )
2020-10-31 13:32:18 +00:00
*
* @ param int $withpicto 0 = No picto , 1 = Include picto into link , 2 = Only picto
* @ param int $notooltip 1 = Disable tooltip
* @ param string $option Page for link ( '' , 'nolink' , ... )
* @ param string $morecss Add more css on link
* @ param int $save_lastsearch_value - 1 = Auto , 0 = No save of lastsearch_values when clicking , 1 = Save lastsearch_values whenclicking
2026-01-15 15:05:06 +00:00
* @ return string String with URL
2020-10-31 13:32:18 +00:00
*/
public function getNomUrl ( $withpicto = 0 , $notooltip = 0 , $option = '' , $morecss = '' , $save_lastsearch_value = - 1 )
{
global $langs ;
$result = '' ;
$langs -> load ( " members " );
2026-05-17 23:19:29 +00:00
$langs -> load ( " main " );
2020-11-23 11:29:38 +00:00
$label = img_picto ( '' , $this -> picto ) . ' <u class="paddingrightonly">' . $langs -> trans ( " Subscription " ) . '</u>' ;
/* if ( isset ( $this -> statut )) {
$label .= ' ' . $this -> getLibStatut ( 5 );
} */
$label .= '<br><b>' . $langs -> trans ( 'Ref' ) . ':</b> ' . $this -> ref ;
2026-05-17 23:19:29 +00:00
$label .= '<br><b>' . $langs -> trans ( 'Label' ) . ':</b> ' . $this -> note_public ;
2020-11-23 11:29:38 +00:00
if ( ! empty ( $this -> dateh )) {
$label .= '<br><b>' . $langs -> trans ( 'DateStart' ) . ':</b> ' . dol_print_date ( $this -> dateh , 'day' );
}
if ( ! empty ( $this -> datef )) {
$label .= '<br><b>' . $langs -> trans ( 'DateEnd' ) . ':</b> ' . dol_print_date ( $this -> datef , 'day' );
}
2025-10-06 16:17:02 +00:00
$baseurl = DOL_URL_ROOT . '/adherents/subscription/card.php' ;
$query = [ 'rowid' => $this -> id ];
2020-10-31 13:32:18 +00:00
if ( $option != 'nolink' ) {
// Add param to save lastsearch_values or not
$add_save_lastsearch_values = ( $save_lastsearch_value == 1 ? 1 : 0 );
2023-09-10 15:41:22 +00:00
if ( $save_lastsearch_value == - 1 && isset ( $_SERVER [ " PHP_SELF " ]) && preg_match ( '/list\.php/' , $_SERVER [ " PHP_SELF " ])) {
2020-12-30 20:41:44 +00:00
$add_save_lastsearch_values = 1 ;
}
if ( $add_save_lastsearch_values ) {
2025-10-06 16:17:02 +00:00
$query = array_merge ( $query , [ 'save_lastsearch_values' => 1 ]);
2020-12-30 20:41:44 +00:00
}
2020-10-31 13:32:18 +00:00
}
2025-10-06 16:17:02 +00:00
$url = dolBuildUrl ( $baseurl , $query );
2020-10-31 13:32:18 +00:00
$linkstart = '<a href="' . $url . '" class="classfortooltip" title="' . dol_escape_htmltag ( $label , 1 ) . '">' ;
$linkend = '</a>' ;
$result .= $linkstart ;
2020-12-30 20:41:44 +00:00
if ( $withpicto ) {
$result .= img_object (( $notooltip ? '' : $label ), ( $this -> picto ? $this -> picto : 'generic' ), ( $notooltip ? (( $withpicto != 2 ) ? 'class="paddingright"' : '' ) : 'class="' . (( $withpicto != 2 ) ? 'paddingright ' : '' ) . 'classfortooltip"' ), 0 , 0 , $notooltip ? 0 : 1 );
}
if ( $withpicto != 2 ) {
$result .= $this -> ref ;
}
2020-10-31 13:32:18 +00:00
$result .= $linkend ;
return $result ;
}
/**
2023-04-08 13:08:55 +00:00
* Return the label of the status
2020-10-31 13:32:18 +00:00
*
2023-04-08 13:08:55 +00:00
* @ param int $mode 0 = long label , 1 = short label , 2 = Picto + short label , 3 = Picto , 4 = Picto + long label , 5 = Short label + Picto , 6 = Long label + Picto
* @ return string Label of status
2020-10-31 13:32:18 +00:00
*/
public function getLibStatut ( $mode = 0 )
{
return '' ;
}
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
/**
2023-04-08 13:08:55 +00:00
* Return the label of a given status
2020-10-31 13:32:18 +00:00
*
2023-04-08 13:08:55 +00:00
* @ param int $status Id status
* @ param int $mode 0 = long label , 1 = short label , 2 = Picto + short label , 3 = Picto , 4 = Picto + long label , 5 = Short label + Picto , 6 = Long label + Picto
* @ return string Label of status
2020-10-31 13:32:18 +00:00
*/
2023-04-08 13:08:55 +00:00
public function LibStatut ( $status , $mode = 0 )
2020-10-31 13:32:18 +00:00
{
// phpcs:enable
2023-04-08 13:08:55 +00:00
//$langs->load("members");
2020-10-31 13:32:18 +00:00
return '' ;
}
/**
* Load information of the subscription object
*
* @ param int $id Id subscription
* @ return void
*/
public function info ( $id )
{
2026-07-18 00:49:05 +00:00
$sql = " SELECT c.rowid, c.datec, c.tms as datem, c.fk_user_creat " ;
$sql .= " FROM " . MAIN_DB_PREFIX . " subscription as c " ;
$sql .= " WHERE c.rowid = " . (( int ) $id );
2020-10-31 13:32:18 +00:00
2022-05-15 20:29:19 +00:00
$resql = $this -> db -> query ( $sql );
if ( $resql ) {
if ( $this -> db -> num_rows ( $resql )) {
$obj = $this -> db -> fetch_object ( $resql );
2020-10-31 13:32:18 +00:00
$this -> id = $obj -> rowid ;
$this -> date_creation = $this -> db -> jdate ( $obj -> datec );
$this -> date_modification = $this -> db -> jdate ( $obj -> datem );
2025-01-23 13:20:47 +00:00
$this -> user_creation_id = $obj -> fk_user_creat ;
2020-10-31 13:32:18 +00:00
}
2022-05-15 20:29:19 +00:00
$this -> db -> free ( $resql );
2020-10-31 13:32:18 +00:00
} else {
dol_print_error ( $this -> db );
}
}
2022-12-19 14:19:12 +00:00
/**
2024-08-06 23:20:43 +00:00
* Return clickable link of object ( with eventually picto )
2022-12-19 14:19:12 +00:00
*
2025-02-03 10:24:16 +00:00
* @ param string $option Where point the link ( 0 => main card , 1 , 2 => shipment , 'nolink' => No link )
* @ param ? array { selected ? : int | bool , adherent_type ? : AdherentType , member ? : Adherent , bank ? : Account } $arraydata Array of data
* @ return string HTML Code for Kanban thumb .
2022-12-19 14:19:12 +00:00
*/
2023-01-18 21:27:52 +00:00
public function getKanbanView ( $option = '' , $arraydata = null )
2022-12-19 14:19:12 +00:00
{
2023-03-07 21:04:40 +00:00
$selected = ( empty ( $arraydata [ 'selected' ]) ? 0 : $arraydata [ 'selected' ]);
2022-12-19 14:19:12 +00:00
$return = '<div class="box-flex-item box-flex-grow-zero">' ;
$return .= '<div class="info-box info-box-sm">' ;
$return .= '<span class="info-box-icon bg-infobox-action">' ;
$return .= img_picto ( '' , $this -> picto );
$return .= '</span>' ;
$return .= '<div class="info-box-content">' ;
2023-07-02 18:01:37 +00:00
$return .= '<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">' ;
2024-05-29 20:19:52 +00:00
$return .= $this -> getNomUrl ( 0 );
2023-10-01 18:15:01 +00:00
$return .= '</span>' ;
2023-10-17 13:43:56 +00:00
if ( $selected >= 0 ) {
$return .= '<input id="cb' . $this -> id . '" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="' . $this -> id . '"' . ( $selected ? ' checked="checked"' : '' ) . '>' ;
}
2025-09-17 16:18:16 +00:00
if ( ! empty ( $this -> dateh ) || ! empty ( $this -> datef )) {
2023-07-02 18:01:37 +00:00
$return .= '<br><span class="info-box-status opacitymedium small">' . dol_print_date ( $this -> dateh , 'day' ) . ' - ' . dol_print_date ( $this -> datef , 'day' ) . '</span>' ;
2022-12-19 14:19:12 +00:00
}
2022-12-19 14:19:18 +00:00
2023-07-02 18:01:37 +00:00
if ( ! empty ( $arraydata [ 'member' ]) && is_object ( $arraydata [ 'member' ])) {
2024-05-29 20:19:52 +00:00
$return .= '<br><div class="inline-block tdoverflowmax150">' . $arraydata [ 'member' ] -> getNomUrl ( - 4 ) . '</div>' ;
2022-12-19 14:19:12 +00:00
}
2023-07-02 18:01:37 +00:00
2025-09-17 16:18:16 +00:00
$return .= '<br><span class="amount inline-block">' . price ( $this -> amount ) . '</span>' ;
if ( ! empty ( $arraydata [ 'bank' ])) {
$return .= ' <span class="info-box-label ">' . $arraydata [ 'bank' ] -> getNomUrl ( - 1 ) . '</span>' ;
2022-12-19 14:19:12 +00:00
}
$return .= '</div>' ;
$return .= '</div>' ;
$return .= '</div>' ;
2025-09-17 16:18:16 +00:00
2022-12-19 14:19:12 +00:00
return $return ;
}
2003-08-31 22:05:54 +00:00
}