29require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
40 public $element =
'subscription';
45 public $table_element =
'subscription';
50 public $picto =
'payment';
120 public $member_firstname;
125 public $member_lastname;
130 public $member_company;
145 public $fields = array(
146 'rowid' => array(
'type' =>
'integer',
'label' =>
'TechnicalID',
'enabled' => 1,
'visible' => -1,
'notnull' => 1,
'position' => 10),
147 'tms' => array(
'type' =>
'timestamp',
'label' =>
'DateModification',
'enabled' => 1,
'visible' => -1,
'notnull' => 1,
'position' => 15),
148 'datec' => array(
'type' =>
'datetime',
'label' =>
'DateCreation',
'enabled' => 1,
'visible' => -1,
'position' => 20),
149 'fk_adherent' => array(
'type' =>
'integer',
'label' =>
'Member',
'enabled' => 1,
'visible' => -1,
'position' => 25),
150 'dateadh' => array(
'type' =>
'datetime',
'label' =>
'DateSubscription',
'enabled' => 1,
'visible' => -1,
'position' => 30),
151 'datef' => array(
'type' =>
'datetime',
'label' =>
'DateEndSubscription',
'enabled' => 1,
'visible' => -1,
'position' => 35),
152 'subscription' => array(
'type' =>
'double(24,8)',
'label' =>
'Amount',
'enabled' => 1,
'visible' => -1,
'position' => 40,
'isameasure' => 1),
153 'fk_bank' => array(
'type' =>
'integer',
'label' =>
'BankId',
'enabled' => 1,
'visible' => -1,
'position' => 45),
154 'note' => array(
'type' =>
'html',
'label' =>
'Note',
'enabled' => 1,
'visible' => -1,
'position' => 50),
155 'fk_type' => array(
'type' =>
'integer',
'label' =>
'MemberType',
'enabled' => 1,
'visible' => -1,
'position' => 55),
156 'fk_user_creat' => array(
'type' =>
'integer:User:user/class/user.class.php',
'label' =>
'UserAuthor',
'enabled' => 1,
'visible' => -2,
'position' => 60),
157 'fk_user_valid' => array(
'type' =>
'integer:User:user/class/user.class.php',
'label' =>
'UserValidation',
'enabled' => 1,
'visible' => -1,
'position' => 65),
158 'import_key' => array(
'type' =>
'varchar(14)',
'label' =>
'ImportId',
'enabled' => 1,
'visible' => -2,
'position' => 805),
171 $this->ismultientitymanaged =
'fk_adherent@adherent';
182 public function create($user, $notrigger = 0)
192 if (isset($this->import_key)) {
193 $this->import_key = trim($this->import_key);
197 if ($this->datef <= $this->dateh) {
198 $this->error = $langs->trans(
"ErrorBadValueForDate");
201 if (empty($this->datec)) {
207 require_once DOL_DOCUMENT_ROOT.
'/adherents/class/adherent.class.php';
209 $result = $member->fetch($this->fk_adherent);
213 if ($allowedStatusesStr ===
'') {
216 $allowedStatuses = array_map(
'intval', explode(
',', $allowedStatusesStr));
217 if (!in_array((
int) $member->statut, $allowedStatuses,
true)) {
218 $this->error = $langs->trans(
'ErrorSubscriptionNotAllowed', $member->getLibStatut(1));
219 dol_syslog(get_class($this).
'::create User='.$user->id.
' tried to create subscription for member='.$member->id.
' with status='.$member->statut.
', allowed='.$allowedStatusesStr, LOG_WARNING);
220 $this->db->rollback();
224 if ($this->fk_type ==
null) {
225 $type = $member->typeid;
227 $type = $this->fk_type;
230 $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)";
231 $sql .=
" VALUES (".((int) $this->fk_adherent).
", '".$this->db->escape((
string) $type).
"', '".$this->db->idate($now).
"',";
232 $sql .=
" '".$this->db->idate($this->dateh).
"',";
233 $sql .=
" '".$this->db->idate($this->datef).
"',";
234 $sql .=
" ".((float) $this->
amount).
",";
235 $sql .=
" '".$this->db->escape($this->note_public ? $this->note_public : $this->note).
"',";
236 $sql .=
" '".$this->db->escape((
string) $this->note_private).
"',";
237 $sql .=
" ".(empty($this->ref_ext) ?
"null" :
"'".$this->db->escape($this->ref_ext).
"'").
",";
238 $sql .=
" ".((int) ($this->user_creation_id > 0 ? $this->user_creation_id : ((int) $user->id)));
239 $sql .=
", ".(!empty($this->import_key) ?
"'".$this->db->escape($this->import_key).
"'" :
"null");
242 $resql = $this->db->query($sql);
245 $this->errors[] = $this->db->lasterror();
249 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.$this->table_element);
250 $this->fk_type = $type;
255 $result = $member->update_end_date($user);
258 $this->error = $member->error;
259 $this->errors[] = $this->error;
265 $result = $member->validate($user);
268 $this->error = $langs->trans(
'ErrorValidationFailed', $member->error);
269 dol_syslog(get_class($this).
': ErrorValidationFailed for member='.$member->id, LOG_ERR);
271 dol_syslog(
'Auto-validated member '.$member->id.
' upon subscription creation', LOG_INFO);
275 if (!empty($this->linkedObjectsIds) && empty($this->linked_objects)) {
276 $this->linked_objects = $this->linkedObjectsIds;
280 if (!$error && $this->
id && !empty($this->linked_objects) && is_array($this->linked_objects)) {
281 foreach ($this->linked_objects as $origin => $tmp_origin_id) {
282 if (is_array($tmp_origin_id)) {
283 foreach ($tmp_origin_id as $origin_id) {
286 $this->error = $this->db->lasterror();
291 $origin_id = $tmp_origin_id;
294 $this->error = $this->db->lasterror();
301 if (!$error && !$notrigger) {
302 $this->context = array(
'member' => $member);
304 $result = $this->call_trigger(
'MEMBER_SUBSCRIPTION_CREATE', $user);
313 $this->db->rollback();
330 $sql =
"SELECT s.rowid, s.fk_type, s.fk_adherent, s.datec,";
332 $sql .=
" s.dateadh as dateh,";
334 $sql .=
" s.subscription, s.note as note_public, s.fk_bank,";
335 $sql .=
" a.firstname as member_firstname, a.lastname as member_lastname, a.societe as member_company";
336 $sql .=
" FROM ".MAIN_DB_PREFIX.
"subscription as s";
337 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"adherent as a ON a.rowid = s.fk_adherent";
338 $sql .=
" WHERE s.rowid = ".((int) $rowid);
340 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
341 $resql = $this->db->query($sql);
343 if ($this->db->num_rows($resql)) {
344 $obj = $this->db->fetch_object($resql);
346 $this->
id = $obj->rowid;
347 $this->
ref = $obj->rowid;
349 $this->fk_type = $obj->fk_type;
350 $this->fk_adherent = $obj->fk_adherent;
351 $this->member_firstname = $obj->member_firstname;
352 $this->member_lastname = $obj->member_lastname;
353 $this->member_company = $obj->member_company;
354 $this->datec = $this->db->jdate($obj->datec);
355 $this->datem = $this->db->jdate($obj->tms);
356 $this->dateh = $this->db->jdate($obj->dateh);
357 $this->datef = $this->db->jdate($obj->datef);
358 $this->
amount = $obj->subscription;
359 $this->note = $obj->note_public;
360 $this->note_public = $obj->note_public;
361 $this->fk_bank = $obj->fk_bank;
367 $this->error = $this->db->lasterror();
380 public function update($user, $notrigger = 0)
386 if (!is_numeric($this->
amount)) {
387 $this->error =
'BadValueForParameterAmount';
391 if (empty($this->note_public) && !empty($this->note)) {
392 $this->note_public = $this->note;
395 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"subscription SET ";
396 $sql .=
" fk_type = ".((int) $this->fk_type).
",";
397 $sql .=
" fk_adherent = ".((int) $this->fk_adherent).
",";
398 $sql .=
" note = ".($this->note_public ?
"'".$this->db->escape($this->note_public).
"'" :
'null').
",";
400 $sql .=
" dateadh = '".$this->db->idate($this->dateh).
"',";
401 $sql .=
" datef = '".$this->db->idate($this->datef).
"',";
402 $sql .=
" datec = '".$this->db->idate($this->datec).
"',";
403 $sql .=
" fk_bank = ".($this->fk_bank ? ((int) $this->fk_bank) :
'null');
404 $sql .=
" WHERE rowid = ".((int) $this->
id);
406 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
407 $resql = $this->db->query($sql);
409 require_once DOL_DOCUMENT_ROOT.
'/adherents/class/adherent.class.php';
411 $result = $member->fetch($this->fk_adherent);
412 $result = $member->update_end_date($user);
415 $this->context = array(
'member' => $member);
417 $result = $this->call_trigger(
'MEMBER_SUBSCRIPTION_MODIFY', $user);
425 $this->error = $this->db->lasterror();
430 $this->db->rollback();
445 public function delete($user, $notrigger = 0)
450 if ($this->fk_bank > 0) {
451 require_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/account.class.php';
453 $result = $accountline->fetch($this->fk_bank);
462 $result = $this->call_trigger(
'MEMBER_SUBSCRIPTION_DELETE', $user);
470 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"subscription WHERE rowid = ".((int) $this->
id);
471 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
472 $resql = $this->db->query($sql);
474 $num = $this->db->affected_rows($resql);
476 require_once DOL_DOCUMENT_ROOT.
'/adherents/class/adherent.class.php';
478 $result = $member->fetch($this->fk_adherent);
479 $result = $member->update_end_date($user);
481 if ($this->fk_bank > 0 && is_object($accountline) && $accountline->id > 0) {
482 $result = $accountline->delete($user);
494 $this->error = $this->db->lasterror();
500 $this->db->rollback();
519 public function getNomUrl($withpicto = 0, $notooltip = 0, $option =
'', $morecss =
'', $save_lastsearch_value = -1)
525 $langs->load(
"members");
526 $langs->load(
"main");
528 $label = img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"Subscription").
'</u>';
532 $label .=
'<br><b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
533 $label .=
'<br><b>'.$langs->trans(
'Label').
':</b> '.$this->note_public;
535 if (empty($memberName)) {
536 $memberName = $this->member_company;
538 if (!empty($memberName)) {
539 $label .=
'<br><b>'.$langs->trans(
'Member').
':</b> '.$memberName;
541 if (!empty($this->dateh)) {
542 $label .=
'<br><b>'.$langs->trans(
'DateStart').
':</b> '.
dol_print_date($this->dateh,
'day');
544 if (!empty($this->datef)) {
545 $label .=
'<br><b>'.$langs->trans(
'DateEnd').
':</b> '.
dol_print_date($this->datef,
'day');
547 $baseurl = DOL_URL_ROOT .
'/adherents/subscription/card.php';
548 $query = [
'rowid' => $this->id];
549 if ($option !=
'nolink') {
551 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
552 if ($save_lastsearch_value == -1 && isset($_SERVER[
"PHP_SELF"]) && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
553 $add_save_lastsearch_values = 1;
555 if ($add_save_lastsearch_values) {
556 $query = array_merge($query, [
'save_lastsearch_values' => 1]);
561 $linkstart =
'<a href="'.$url.
'" class="classfortooltip" title="'.
dol_escape_htmltag($label, 1).
'">';
564 $result .= $linkstart;
566 $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);
568 if ($withpicto != 2) {
569 $result .= $this->ref;
573 global $action, $hookmanager;
574 $hookmanager->initHooks(array($this->element .
'dao'));
575 $parameters = array(
'id' => $this->
id,
'getnomurl' => &$result);
576 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
578 $result = $hookmanager->resPrint;
580 $result .= $hookmanager->resPrint;
623 $sql =
"SELECT c.rowid, c.datec, c.tms as datem, c.fk_user_creat";
624 $sql .=
" FROM ".MAIN_DB_PREFIX.
"subscription as c";
625 $sql .=
" WHERE c.rowid = ".((int) $id);
627 $resql = $this->db->query($sql);
629 if ($this->db->num_rows($resql)) {
630 $obj = $this->db->fetch_object($resql);
631 $this->
id = $obj->rowid;
633 $this->date_creation = $this->db->jdate($obj->datec);
634 $this->date_modification = $this->db->jdate($obj->datem);
636 $this->user_creation_id = $obj->fk_user_creat;
639 $this->db->free($resql);
641 dol_print_error($this->db);
654 $selected = (empty($arraydata[
'selected']) ? 0 : $arraydata[
'selected']);
656 $return =
'<div class="box-flex-item box-flex-grow-zero">';
657 $return .=
'<div class="info-box info-box-sm">';
658 $return .=
'<span class="info-box-icon bg-infobox-action">';
659 $return .= img_picto(
'', $this->picto);
660 $return .=
'</span>';
662 $return .=
'<div class="info-box-content">';
663 $return .=
'<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">';
665 $return .=
'</span>';
666 if ($selected >= 0) {
667 $return .=
'<input id="cb'.$this->id.
'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->
id.
'"'.($selected ?
' checked="checked"' :
'').
'>';
669 if (!empty($this->dateh) || !empty($this->datef)) {
670 $return .=
'<br><span class="info-box-status opacitymedium small">'.dol_print_date($this->dateh,
'day').
' - '.
dol_print_date($this->datef,
'day').
'</span>';
673 if (!empty($arraydata[
'member']) && is_object($arraydata[
'member'])) {
674 $return .=
'<br><div class="inline-block tdoverflowmax150">'.$arraydata[
'member']->getNomUrl(-4).
'</div>';
677 $return .=
'<br><span class="amount inline-block">'.price($this->
amount).
'</span>';
678 if (!empty($arraydata[
'bank'])) {
679 $return .=
' <span class="info-box-label ">'.$arraydata[
'bank']->getNomUrl(-1).
'</span>';
Class to manage bank transaction lines.
Class to manage members of a foundation.
const STATUS_DRAFT
Draft status.
const STATUS_RESILIATED
Resiliated (membership end and was not renew)
const STATUS_VALIDATED
Validated status.
add_object_linked($origin=null, $origin_id=null, $f_user=null, $notrigger=0)
Add an object link into llx_element_element.
setErrorsFromObject($object)
setErrorsFromObject
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.
dol_now($mode='gmt')
Return date for now.
price2num($amount, $rounding='', $option=0, $currencycode='')
Function that return a number with universal decimal format (decimal separator is '.
dolBuildUrl($url, $params=[], $addtoken=false, $anchor='')
Return path of url.
dolGetFirstLastname($firstname, $lastname, $nameorder=-1)
Return firstname and lastname in correct order.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
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)
print $langs trans('Date')." left Ref Label right Qty right Price right TotalHT right TotalTTC right right right right right right right right right centpercent right TotalHT right n right VAT right n right TotalVAT right n No sujeto a RE IRPF right TotalLT1 right n right TotalLT2 right n right TotalTTC right n takeposcustomercurrency takeposcustomercurrency takeposcustomercurrency takeposcustomercurrency right TotalTTC takeposcustomercurrency right takeposcustomercurrency n right Paid right PaymentTypeShortLIQ right SELECT p pos_change as p datep as p p num_paiement as f pf amount as amount