27 require_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';
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),
137 public function create($user, $notrigger =
false)
146 if ($this->datef <= $this->dateh) {
147 $this->error = $langs->trans(
"ErrorBadValueForDate");
150 if (empty($this->datec)) {
157 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"subscription (fk_adherent, fk_type, datec, dateadh, datef, subscription, note)";
159 require_once DOL_DOCUMENT_ROOT.
'/adherents/class/adherent.class.php';
161 $result = $member->fetch($this->fk_adherent);
163 if ($this->fk_type ==
null) {
164 $type = $member->typeid;
166 $type = $this->fk_type;
168 $sql .=
" VALUES (".((int) $this->fk_adherent).
", '".$this->
db->escape($type).
"', '".$this->
db->idate($now).
"',";
169 $sql .=
" '".$this->db->idate($this->dateh).
"',";
170 $sql .=
" '".$this->db->idate($this->datef).
"',";
171 $sql .=
" ".((float) $this->amount).
",";
172 $sql .=
" '".$this->db->escape($this->note_public ? $this->note_public : $this->note).
"')";
174 $resql = $this->
db->query(
$sql);
177 $this->errors[] = $this->
db->lasterror();
181 $this->
id = $this->
db->last_insert_id(MAIN_DB_PREFIX.$this->table_element);
182 $this->fk_type = $type;
185 if (!$error && !$notrigger) {
186 $this->context = array(
'member' => $member);
188 $result = $this->
call_trigger(
'MEMBER_SUBSCRIPTION_CREATE', $user);
197 $this->
db->rollback();
214 $sql =
"SELECT rowid, fk_type, fk_adherent, datec,";
216 $sql .=
" dateadh as dateh,";
218 $sql .=
" subscription, note as note_public, fk_bank";
219 $sql .=
" FROM ".MAIN_DB_PREFIX.
"subscription";
220 $sql .=
" WHERE rowid=".((int) $rowid);
222 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
223 $resql = $this->
db->query(
$sql);
225 if ($this->
db->num_rows($resql)) {
226 $obj = $this->
db->fetch_object($resql);
228 $this->
id = $obj->rowid;
229 $this->
ref = $obj->rowid;
231 $this->fk_type = $obj->fk_type;
232 $this->fk_adherent = $obj->fk_adherent;
233 $this->datec = $this->
db->jdate($obj->datec);
234 $this->datem = $this->
db->jdate($obj->tms);
235 $this->dateh = $this->
db->jdate($obj->dateh);
236 $this->datef = $this->
db->jdate($obj->datef);
237 $this->amount = $obj->subscription;
238 $this->note = $obj->note_public;
239 $this->note_public = $obj->note_public;
240 $this->fk_bank = $obj->fk_bank;
246 $this->error = $this->
db->lasterror();
259 public function update($user, $notrigger = 0)
265 if (!is_numeric($this->amount)) {
266 $this->error =
'BadValueForParameterAmount';
270 if (empty($this->note_public) && !empty($this->note)) {
274 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"subscription SET ";
275 $sql .=
" fk_type = ".((int) $this->fk_type).
",";
276 $sql .=
" fk_adherent = ".((int) $this->fk_adherent).
",";
277 $sql .=
" note=".($this->note_public ?
"'".$this->db->escape($this->note_public).
"'" :
'null').
",";
278 $sql .=
" subscription = ".price2num($this->amount).
",";
279 $sql .=
" dateadh='".$this->db->idate($this->dateh).
"',";
280 $sql .=
" datef='".$this->db->idate($this->datef).
"',";
281 $sql .=
" datec='".$this->db->idate($this->datec).
"',";
282 $sql .=
" fk_bank = ".($this->fk_bank ? ((int) $this->fk_bank) :
'null');
283 $sql .=
" WHERE rowid = ".((int) $this->
id);
285 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
286 $resql = $this->
db->query(
$sql);
288 require_once DOL_DOCUMENT_ROOT.
'/adherents/class/adherent.class.php';
290 $result = $member->fetch($this->fk_adherent);
291 $result = $member->update_end_date($user);
293 if (!$error && !$notrigger) {
294 $this->context = array(
'member'=>$member);
296 $result = $this->
call_trigger(
'MEMBER_SUBSCRIPTION_MODIFY', $user);
304 $this->error = $this->
db->lasterror();
309 $this->
db->rollback();
324 public function delete($user, $notrigger =
false)
329 if ($this->fk_bank > 0) {
330 require_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/account.class.php';
332 $result = $accountline->fetch($this->fk_bank);
340 $result = $this->
call_trigger(
'MEMBER_SUBSCRIPTION_DELETE', $user);
349 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"subscription WHERE rowid = ".((int) $this->
id);
350 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
351 $resql = $this->
db->query(
$sql);
353 $num = $this->
db->affected_rows($resql);
355 require_once DOL_DOCUMENT_ROOT.
'/adherents/class/adherent.class.php';
357 $result = $member->fetch($this->fk_adherent);
358 $result = $member->update_end_date($user);
360 if ($this->fk_bank > 0 && is_object($accountline) && $accountline->id > 0) {
361 $result = $accountline->delete($user);
366 $this->error = $accountline->error;
367 $this->
db->rollback();
380 $this->error = $this->
db->lasterror();
386 $this->
db->rollback();
405 public function getNomUrl($withpicto = 0, $notooltip = 0, $option =
'', $morecss =
'', $save_lastsearch_value = -1)
411 $langs->load(
"members");
413 $label =
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"Subscription").
'</u>';
417 $label .=
'<br><b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
418 if (!empty($this->dateh)) {
419 $label .=
'<br><b>'.$langs->trans(
'DateStart').
':</b> '.
dol_print_date($this->dateh,
'day');
421 if (!empty($this->datef)) {
422 $label .=
'<br><b>'.$langs->trans(
'DateEnd').
':</b> '.
dol_print_date($this->datef,
'day');
425 $url = DOL_URL_ROOT.
'/adherents/subscription/card.php?rowid='.((int) $this->
id);
427 if ($option !=
'nolink') {
429 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
430 if ($save_lastsearch_value == -1 && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
431 $add_save_lastsearch_values = 1;
433 if ($add_save_lastsearch_values) {
434 $url .=
'&save_lastsearch_values=1';
438 $linkstart =
'<a href="'.$url.
'" class="classfortooltip" title="'.
dol_escape_htmltag($label, 1).
'">';
441 $result .= $linkstart;
443 $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);
445 if ($withpicto != 2) {
446 $result .= $this->ref;
476 $langs->load(
"members");
488 $sql =
'SELECT c.rowid, c.datec,';
489 $sql .=
' c.tms as datem';
490 $sql .=
' FROM '.MAIN_DB_PREFIX.
'subscription as c';
491 $sql .=
' WHERE c.rowid = '.((int) $id);
493 $resql = $this->
db->query(
$sql);
495 if ($this->
db->num_rows($resql)) {
496 $obj = $this->
db->fetch_object($resql);
497 $this->
id = $obj->rowid;
499 $this->date_creation = $this->
db->jdate($obj->datec);
500 $this->date_modification = $this->
db->jdate($obj->datem);
503 $this->
db->free($resql);
518 $return =
'<div class="box-flex-item box-flex-grow-zero">';
519 $return .=
'<div class="info-box info-box-sm">';
520 $return .=
'<span class="info-box-icon bg-infobox-action">';
522 $return .=
'</span>';
524 $return .=
'<div class="info-box-content">';
525 $return .=
'<span class="info-box-ref">'.(property_exists($this,
'fk_adherent')? $this->fk_adherent: $this->ref ).
'</span>';
526 if (property_exists($this,
'dateh') || property_exists($this,
'datef')) {
527 $return .=
'<br><span class="info-box-status opacitymedium">'.dol_print_date($this->dateh,
'day').
' - '.
dol_print_date($this->datef,
'day').
'</span>';
530 if (property_exists($this,
'fk_bank')) {
531 $return .=
'<br><span class="info-box-label ">'.$this->fk_bank.
'</span>';
533 if (property_exists($this,
'amount')) {
534 $return .=
'<br><div class="info-box-label margintoponly amount">'.price($this->amount).
'</div>';