27require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
38 public $element =
'subscription';
43 public $table_element =
'subscription';
48 public $ismultientitymanaged =
'fk_adherent@adherent';
53 public $picto =
'payment';
106 public $fields = array(
107 'rowid' =>array(
'type'=>
'integer',
'label'=>
'TechnicalID',
'enabled'=>1,
'visible'=>-1,
'notnull'=>1,
'position'=>10),
108 'tms' =>array(
'type'=>
'timestamp',
'label'=>
'DateModification',
'enabled'=>1,
'visible'=>-1,
'notnull'=>1,
'position'=>15),
109 'datec' =>array(
'type'=>
'datetime',
'label'=>
'DateCreation',
'enabled'=>1,
'visible'=>-1,
'position'=>20),
110 'fk_adherent' =>array(
'type'=>
'integer',
'label'=>
'Member',
'enabled'=>1,
'visible'=>-1,
'position'=>25),
111 'dateadh' =>array(
'type'=>
'datetime',
'label'=>
'DateSubscription',
'enabled'=>1,
'visible'=>-1,
'position'=>30),
112 'datef' =>array(
'type'=>
'datetime',
'label'=>
'DateEndSubscription',
'enabled'=>1,
'visible'=>-1,
'position'=>35),
113 'subscription' =>array(
'type'=>
'double(24,8)',
'label'=>
'Amount',
'enabled'=>1,
'visible'=>-1,
'position'=>40,
'isameasure'=>1),
114 'fk_bank' =>array(
'type'=>
'integer',
'label'=>
'BankId',
'enabled'=>1,
'visible'=>-1,
'position'=>45),
115 'note' =>array(
'type'=>
'html',
'label'=>
'Note',
'enabled'=>1,
'visible'=>-1,
'position'=>50),
116 'fk_type' =>array(
'type'=>
'integer',
'label'=>
'MemberType',
'enabled'=>1,
'visible'=>-1,
'position'=>55),
117 'fk_user_creat' =>array(
'type'=>
'integer:User:user/class/user.class.php',
'label'=>
'UserAuthor',
'enabled'=>1,
'visible'=>-2,
'position'=>60),
118 'fk_user_valid' =>array(
'type'=>
'integer:User:user/class/user.class.php',
'label'=>
'UserValidation',
'enabled'=>1,
'visible'=>-1,
'position'=>65),
140 public function create($user, $notrigger =
false)
149 if ($this->datef <= $this->dateh) {
150 $this->error = $langs->trans(
"ErrorBadValueForDate");
153 if (empty($this->datec)) {
159 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"subscription (fk_adherent, fk_type, datec, dateadh, datef, subscription, note)";
161 require_once DOL_DOCUMENT_ROOT.
'/adherents/class/adherent.class.php';
163 $result = $member->fetch($this->fk_adherent);
165 if ($this->fk_type ==
null) {
166 $type = $member->typeid;
168 $type = $this->fk_type;
170 $sql .=
" VALUES (".((int) $this->fk_adherent).
", '".$this->db->escape($type).
"', '".$this->db->idate($now).
"',";
171 $sql .=
" '".$this->db->idate($this->dateh).
"',";
172 $sql .=
" '".$this->db->idate($this->datef).
"',";
173 $sql .=
" ".((float) $this->amount).
",";
174 $sql .=
" '".$this->db->escape($this->note_public ? $this->note_public :
$this->note).
"')";
176 $resql = $this->db->query($sql);
179 $this->errors[] = $this->db->lasterror();
183 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.$this->table_element);
184 $this->fk_type = $type;
187 if (!$error && !$notrigger) {
188 $this->context = array(
'member' => $member);
190 $result = $this->
call_trigger(
'MEMBER_SUBSCRIPTION_CREATE', $user);
199 $this->db->rollback();
216 $sql =
"SELECT rowid, fk_type, fk_adherent, datec,";
218 $sql .=
" dateadh as dateh,";
220 $sql .=
" subscription, note as note_public, fk_bank";
221 $sql .=
" FROM ".MAIN_DB_PREFIX.
"subscription";
222 $sql .=
" WHERE rowid = ".((int) $rowid);
224 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
225 $resql = $this->db->query($sql);
227 if ($this->db->num_rows($resql)) {
228 $obj = $this->db->fetch_object($resql);
230 $this->
id = $obj->rowid;
231 $this->
ref = $obj->rowid;
233 $this->fk_type = $obj->fk_type;
234 $this->fk_adherent = $obj->fk_adherent;
235 $this->datec = $this->db->jdate($obj->datec);
236 $this->datem = $this->db->jdate($obj->tms);
237 $this->dateh = $this->db->jdate($obj->dateh);
238 $this->datef = $this->db->jdate($obj->datef);
239 $this->amount = $obj->subscription;
240 $this->note = $obj->note_public;
241 $this->note_public = $obj->note_public;
242 $this->fk_bank = $obj->fk_bank;
248 $this->error = $this->db->lasterror();
261 public function update($user, $notrigger = 0)
267 if (!is_numeric($this->amount)) {
268 $this->error =
'BadValueForParameterAmount';
272 if (empty($this->note_public) && !empty($this->note)) {
276 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"subscription SET ";
277 $sql .=
" fk_type = ".((int) $this->fk_type).
",";
278 $sql .=
" fk_adherent = ".((int) $this->fk_adherent).
",";
279 $sql .=
" note = ".($this->note_public ?
"'".$this->db->escape($this->note_public).
"'" :
'null').
",";
280 $sql .=
" subscription = ".price2num($this->amount).
",";
281 $sql .=
" dateadh = '".$this->db->idate($this->dateh).
"',";
282 $sql .=
" datef = '".$this->db->idate($this->datef).
"',";
283 $sql .=
" datec = '".$this->db->idate($this->datec).
"',";
284 $sql .=
" fk_bank = ".($this->fk_bank ? ((int) $this->fk_bank) :
'null');
285 $sql .=
" WHERE rowid = ".((int) $this->
id);
287 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
288 $resql = $this->db->query($sql);
290 require_once DOL_DOCUMENT_ROOT.
'/adherents/class/adherent.class.php';
292 $result = $member->fetch($this->fk_adherent);
293 $result = $member->update_end_date($user);
295 if (!$error && !$notrigger) {
296 $this->context = array(
'member'=>$member);
298 $result = $this->
call_trigger(
'MEMBER_SUBSCRIPTION_MODIFY', $user);
306 $this->error = $this->db->lasterror();
311 $this->db->rollback();
326 public function delete($user, $notrigger =
false)
331 if ($this->fk_bank > 0) {
332 require_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/account.class.php';
334 $result = $accountline->fetch($this->fk_bank);
342 $result = $this->
call_trigger(
'MEMBER_SUBSCRIPTION_DELETE', $user);
351 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"subscription WHERE rowid = ".((int) $this->
id);
352 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
353 $resql = $this->db->query($sql);
355 $num = $this->db->affected_rows($resql);
357 require_once DOL_DOCUMENT_ROOT.
'/adherents/class/adherent.class.php';
359 $result = $member->fetch($this->fk_adherent);
360 $result = $member->update_end_date($user);
362 if ($this->fk_bank > 0 && is_object($accountline) && $accountline->id > 0) {
363 $result = $accountline->delete($user);
368 $this->error = $accountline->error;
369 $this->db->rollback();
382 $this->error = $this->db->lasterror();
388 $this->db->rollback();
407 public function getNomUrl($withpicto = 0, $notooltip = 0, $option =
'', $morecss =
'', $save_lastsearch_value = -1)
413 $langs->load(
"members");
415 $label =
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"Subscription").
'</u>';
419 $label .=
'<br><b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
420 if (!empty($this->dateh)) {
421 $label .=
'<br><b>'.$langs->trans(
'DateStart').
':</b> '.
dol_print_date($this->dateh,
'day');
423 if (!empty($this->datef)) {
424 $label .=
'<br><b>'.$langs->trans(
'DateEnd').
':</b> '.
dol_print_date($this->datef,
'day');
427 $url = DOL_URL_ROOT.
'/adherents/subscription/card.php?rowid='.((int) $this->
id);
429 if ($option !=
'nolink') {
431 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
432 if ($save_lastsearch_value == -1 && isset($_SERVER[
"PHP_SELF"]) && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
433 $add_save_lastsearch_values = 1;
435 if ($add_save_lastsearch_values) {
436 $url .=
'&save_lastsearch_values=1';
440 $linkstart =
'<a href="'.$url.
'" class="classfortooltip" title="'.
dol_escape_htmltag($label, 1).
'">';
443 $result .= $linkstart;
445 $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);
447 if ($withpicto != 2) {
448 $result .= $this->ref;
493 $sql =
'SELECT c.rowid, c.datec,';
494 $sql .=
' c.tms as datem';
495 $sql .=
' FROM '.MAIN_DB_PREFIX.
'subscription as c';
496 $sql .=
' WHERE c.rowid = '.((int) $id);
498 $resql = $this->db->query($sql);
500 if ($this->db->num_rows($resql)) {
501 $obj = $this->db->fetch_object($resql);
502 $this->
id = $obj->rowid;
504 $this->date_creation = $this->db->jdate($obj->datec);
505 $this->date_modification = $this->db->jdate($obj->datem);
508 $this->db->free($resql);
523 $selected = (empty($arraydata[
'selected']) ? 0 : $arraydata[
'selected']);
525 $return =
'<div class="box-flex-item box-flex-grow-zero">';
526 $return .=
'<div class="info-box info-box-sm">';
527 $return .=
'<span class="info-box-icon bg-infobox-action">';
529 $return .=
'</span>';
531 $return .=
'<div class="info-box-content">';
532 $return .=
'<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">';
534 $return .=
'</span>';
535 if ($selected >= 0) {
536 $return .=
'<input id="cb'.$this->id.
'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->
id.
'"'.($selected ?
' checked="checked"' :
'').
'>';
538 if (property_exists($this,
'dateh') || property_exists($this,
'datef')) {
539 $return .=
'<br><span class="info-box-status opacitymedium small">'.dol_print_date($this->dateh,
'day').
' - '.
dol_print_date($this->datef,
'day').
'</span>';
542 if (!empty($arraydata[
'member']) && is_object($arraydata[
'member'])) {
543 $return .=
'<br><span class="inline-block">'.$arraydata[
'member']->getNomUrl(-4).
'</span>';
546 if (property_exists($this,
'amount')) {
547 $return .=
'<br><span class="margintoponly amount inline-block">'.price($this->amount).
'</span>';
548 if (!empty($arraydata[
'bank'])) {
549 $return .=
' <span class="info-box-label ">'.$arraydata[
'bank']->getNomUrl(-1).
'</span>';
Class to manage bank transaction lines.
Class to manage members of a foundation.
Parent class of all other business classes (invoices, contracts, proposals, orders,...
call_trigger($triggerName, $user)
Call trigger based on this instance.
Class to manage subscriptions of foundation members.
fetch($rowid)
Method to load a subscription.
getLibStatut($mode=0)
Return the label of the status.
info($id)
Load information of the subscription object.
getKanbanView($option='', $arraydata=null)
Return clicable link of object (with eventually picto)
__construct($db)
Constructor.
getNomUrl($withpicto=0, $notooltip=0, $option='', $morecss='', $save_lastsearch_value=-1)
Return clicable name (with picto eventually)
LibStatut($status, $mode=0)
Return the label of a given status.
create($user, $notrigger=false)
Function who permitted creation of the subscription.
update($user, $notrigger=0)
Update subscription.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_now($mode='auto')
Return date for now.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...