29require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
40 public $element =
'subscription';
45 public $table_element =
'subscription';
50 public $picto =
'payment';
103 public $fields = array(
104 'rowid' => array(
'type' =>
'integer',
'label' =>
'TechnicalID',
'enabled' => 1,
'visible' => -1,
'notnull' => 1,
'position' => 10),
105 'tms' => array(
'type' =>
'timestamp',
'label' =>
'DateModification',
'enabled' => 1,
'visible' => -1,
'notnull' => 1,
'position' => 15),
106 'datec' => array(
'type' =>
'datetime',
'label' =>
'DateCreation',
'enabled' => 1,
'visible' => -1,
'position' => 20),
107 'fk_adherent' => array(
'type' =>
'integer',
'label' =>
'Member',
'enabled' => 1,
'visible' => -1,
'position' => 25),
108 'dateadh' => array(
'type' =>
'datetime',
'label' =>
'DateSubscription',
'enabled' => 1,
'visible' => -1,
'position' => 30),
109 'datef' => array(
'type' =>
'datetime',
'label' =>
'DateEndSubscription',
'enabled' => 1,
'visible' => -1,
'position' => 35),
110 'subscription' => array(
'type' =>
'double(24,8)',
'label' =>
'Amount',
'enabled' => 1,
'visible' => -1,
'position' => 40,
'isameasure' => 1),
111 'fk_bank' => array(
'type' =>
'integer',
'label' =>
'BankId',
'enabled' => 1,
'visible' => -1,
'position' => 45),
112 'note' => array(
'type' =>
'html',
'label' =>
'Note',
'enabled' => 1,
'visible' => -1,
'position' => 50),
113 'fk_type' => array(
'type' =>
'integer',
'label' =>
'MemberType',
'enabled' => 1,
'visible' => -1,
'position' => 55),
114 'fk_user_creat' => array(
'type' =>
'integer:User:user/class/user.class.php',
'label' =>
'UserAuthor',
'enabled' => 1,
'visible' => -2,
'position' => 60),
115 'fk_user_valid' => array(
'type' =>
'integer:User:user/class/user.class.php',
'label' =>
'UserValidation',
'enabled' => 1,
'visible' => -1,
'position' => 65),
128 $this->ismultientitymanaged =
'fk_adherent@adherent';
139 public function create($user, $notrigger = 0)
148 if ($this->datef <= $this->dateh) {
149 $this->error = $langs->trans(
"ErrorBadValueForDate");
152 if (empty($this->datec)) {
158 require_once DOL_DOCUMENT_ROOT.
'/adherents/class/adherent.class.php';
160 $result = $member->fetch($this->fk_adherent);
162 if ($this->fk_type ==
null) {
163 $type = $member->typeid;
165 $type = $this->fk_type;
168 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"subscription (fk_adherent, fk_type, datec, dateadh, datef, subscription, note, fk_user_creat)";
169 $sql .=
" VALUES (".((int) $this->fk_adherent).
", '".$this->db->escape((
string) $type).
"', '".$this->db->idate($now).
"',";
170 $sql .=
" '".$this->db->idate($this->dateh).
"',";
171 $sql .=
" '".$this->db->idate($this->datef).
"',";
172 $sql .=
" ".((float) $this->amount).
",";
173 $sql .=
" '".$this->db->escape($this->note_public ? $this->note_public : $this->note).
"',";
174 $sql .=
" ".((int) ($this->user_creation_id > 0 ? $this->user_creation_id : $user->id));
177 $resql = $this->db->query($sql);
180 $this->errors[] = $this->db->lasterror();
184 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.$this->table_element);
185 $this->fk_type = $type;
190 $result = $member->update_end_date($user);
193 $this->error = $member->error;
194 $this->errors[] = $this->error;
198 if (!empty($this->linkedObjectsIds) && empty($this->linked_objects)) {
199 $this->linked_objects = $this->linkedObjectsIds;
203 if (!$error && $this->
id && !empty($this->linked_objects) && is_array($this->linked_objects)) {
204 foreach ($this->linked_objects as $origin => $tmp_origin_id) {
205 if (is_array($tmp_origin_id)) {
206 foreach ($tmp_origin_id as $origin_id) {
209 $this->error = $this->db->lasterror();
214 $origin_id = $tmp_origin_id;
217 $this->error = $this->db->lasterror();
224 if (!$error && !$notrigger) {
225 $this->context = array(
'member' => $member);
227 $result = $this->
call_trigger(
'MEMBER_SUBSCRIPTION_CREATE', $user);
236 $this->db->rollback();
253 $sql =
"SELECT rowid, fk_type, fk_adherent, datec,";
255 $sql .=
" dateadh as dateh,";
257 $sql .=
" subscription, note as note_public, fk_bank";
258 $sql .=
" FROM ".MAIN_DB_PREFIX.
"subscription";
259 $sql .=
" WHERE rowid = ".((int) $rowid);
261 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
262 $resql = $this->db->query($sql);
264 if ($this->db->num_rows($resql)) {
265 $obj = $this->db->fetch_object($resql);
267 $this->
id = $obj->rowid;
268 $this->
ref = $obj->rowid;
270 $this->fk_type = $obj->fk_type;
271 $this->fk_adherent = $obj->fk_adherent;
272 $this->datec = $this->db->jdate($obj->datec);
273 $this->datem = $this->db->jdate($obj->tms);
274 $this->dateh = $this->db->jdate($obj->dateh);
275 $this->datef = $this->db->jdate($obj->datef);
276 $this->amount = $obj->subscription;
277 $this->note = $obj->note_public;
278 $this->note_public = $obj->note_public;
279 $this->fk_bank = $obj->fk_bank;
285 $this->error = $this->db->lasterror();
298 public function update($user, $notrigger = 0)
304 if (!is_numeric($this->amount)) {
305 $this->error =
'BadValueForParameterAmount';
309 if (empty($this->note_public) && !empty($this->note)) {
310 $this->note_public = $this->note;
313 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"subscription SET ";
314 $sql .=
" fk_type = ".((int) $this->fk_type).
",";
315 $sql .=
" fk_adherent = ".((int) $this->fk_adherent).
",";
316 $sql .=
" note = ".($this->note_public ?
"'".$this->db->escape($this->note_public).
"'" :
'null').
",";
317 $sql .=
" subscription = ".(float)
price2num($this->amount).
",";
318 $sql .=
" dateadh = '".$this->db->idate($this->dateh).
"',";
319 $sql .=
" datef = '".$this->db->idate($this->datef).
"',";
320 $sql .=
" datec = '".$this->db->idate($this->datec).
"',";
321 $sql .=
" fk_bank = ".($this->fk_bank ? ((int) $this->fk_bank) :
'null');
322 $sql .=
" WHERE rowid = ".((int) $this->
id);
324 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
325 $resql = $this->db->query($sql);
327 require_once DOL_DOCUMENT_ROOT.
'/adherents/class/adherent.class.php';
329 $result = $member->fetch($this->fk_adherent);
330 $result = $member->update_end_date($user);
332 if (!$error && !$notrigger) {
333 $this->context = array(
'member' => $member);
335 $result = $this->
call_trigger(
'MEMBER_SUBSCRIPTION_MODIFY', $user);
343 $this->error = $this->db->lasterror();
348 $this->db->rollback();
363 public function delete($user, $notrigger = 0)
368 if ($this->fk_bank > 0) {
369 require_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/account.class.php';
371 $result = $accountline->fetch($this->fk_bank);
381 $result = $this->
call_trigger(
'MEMBER_SUBSCRIPTION_DELETE', $user);
390 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"subscription WHERE rowid = ".((int) $this->
id);
391 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
392 $resql = $this->db->query($sql);
394 $num = $this->db->affected_rows($resql);
396 require_once DOL_DOCUMENT_ROOT.
'/adherents/class/adherent.class.php';
398 $result = $member->fetch($this->fk_adherent);
399 $result = $member->update_end_date($user);
401 if ($this->fk_bank > 0 && is_object($accountline) && $accountline->id > 0) {
402 $result = $accountline->delete($user);
407 $this->error = $accountline->error;
408 $this->db->rollback();
421 $this->error = $this->db->lasterror();
427 $this->db->rollback();
446 public function getNomUrl($withpicto = 0, $notooltip = 0, $option =
'', $morecss =
'', $save_lastsearch_value = -1)
452 $langs->load(
"members");
454 $label =
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"Subscription").
'</u>';
458 $label .=
'<br><b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
459 if (!empty($this->dateh)) {
460 $label .=
'<br><b>'.$langs->trans(
'DateStart').
':</b> '.
dol_print_date($this->dateh,
'day');
462 if (!empty($this->datef)) {
463 $label .=
'<br><b>'.$langs->trans(
'DateEnd').
':</b> '.
dol_print_date($this->datef,
'day');
466 $url = DOL_URL_ROOT.
'/adherents/subscription/card.php?rowid='.((int) $this->
id);
468 if ($option !=
'nolink') {
470 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
471 if ($save_lastsearch_value == -1 && isset($_SERVER[
"PHP_SELF"]) && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
472 $add_save_lastsearch_values = 1;
474 if ($add_save_lastsearch_values) {
475 $url .=
'&save_lastsearch_values=1';
479 $linkstart =
'<a href="'.$url.
'" class="classfortooltip" title="'.
dol_escape_htmltag($label, 1).
'">';
482 $result .= $linkstart;
484 $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);
486 if ($withpicto != 2) {
487 $result .= $this->ref;
531 $sql =
"SELECT c.rowid, c.datec, c.tms as datem, c.fk_user_creat";
532 $sql .=
" FROM ".MAIN_DB_PREFIX.
"subscription as c";
533 $sql .=
" WHERE c.rowid = ".((int) $id);
535 $resql = $this->db->query($sql);
537 if ($this->db->num_rows($resql)) {
538 $obj = $this->db->fetch_object($resql);
539 $this->
id = $obj->rowid;
541 $this->date_creation = $this->db->jdate($obj->datec);
542 $this->date_modification = $this->db->jdate($obj->datem);
544 $this->user_creation_id = $obj->fk_user_creat;
547 $this->db->free($resql);
562 $selected = (empty($arraydata[
'selected']) ? 0 : $arraydata[
'selected']);
564 $return =
'<div class="box-flex-item box-flex-grow-zero">';
565 $return .=
'<div class="info-box info-box-sm">';
566 $return .=
'<span class="info-box-icon bg-infobox-action">';
568 $return .=
'</span>';
570 $return .=
'<div class="info-box-content">';
571 $return .=
'<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">';
573 $return .=
'</span>';
574 if ($selected >= 0) {
575 $return .=
'<input id="cb'.$this->id.
'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->
id.
'"'.($selected ?
' checked="checked"' :
'').
'>';
577 if (property_exists($this,
'dateh') || property_exists($this,
'datef')) {
578 $return .=
'<br><span class="info-box-status opacitymedium small">'.dol_print_date($this->dateh,
'day').
' - '.
dol_print_date($this->datef,
'day').
'</span>';
581 if (!empty($arraydata[
'member']) && is_object($arraydata[
'member'])) {
582 $return .=
'<br><div class="inline-block tdoverflowmax150">'.$arraydata[
'member']->getNomUrl(-4).
'</div>';
585 if (property_exists($this,
'amount')) {
586 $return .=
'<br><span class="amount inline-block">'.price($this->amount).
'</span>';
587 if (!empty($arraydata[
'bank'])) {
588 $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,...
add_object_linked($origin=null, $origin_id=null, $f_user=null, $notrigger=0)
Add an object link into llx_element_element.
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.
create($user, $notrigger=0)
Function who permitted creation of the subscription.
info($id)
Load information of the subscription object.
getKanbanView($option='', $arraydata=null)
Return clickable link of object (with eventually picto)
__construct($db)
Constructor.
getNomUrl($withpicto=0, $notooltip=0, $option='', $morecss='', $save_lastsearch_value=-1)
Return clickable name (with picto eventually)
LibStatut($status, $mode=0)
Return the label of a given status.
update($user, $notrigger=0)
Update subscription.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $allowothertags=array())
Show a picto called object_picto (generic function)
dol_now($mode='auto')
Return date for now.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
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...