29require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
40 public $element =
'subscription';
45 public $table_element =
'subscription';
50 public $picto =
'payment';
130 public $fields = array(
131 'rowid' => array(
'type' =>
'integer',
'label' =>
'TechnicalID',
'enabled' => 1,
'visible' => -1,
'notnull' => 1,
'position' => 10),
132 'tms' => array(
'type' =>
'timestamp',
'label' =>
'DateModification',
'enabled' => 1,
'visible' => -1,
'notnull' => 1,
'position' => 15),
133 'datec' => array(
'type' =>
'datetime',
'label' =>
'DateCreation',
'enabled' => 1,
'visible' => -1,
'position' => 20),
134 'fk_adherent' => array(
'type' =>
'integer',
'label' =>
'Member',
'enabled' => 1,
'visible' => -1,
'position' => 25),
135 'dateadh' => array(
'type' =>
'datetime',
'label' =>
'DateSubscription',
'enabled' => 1,
'visible' => -1,
'position' => 30),
136 'datef' => array(
'type' =>
'datetime',
'label' =>
'DateEndSubscription',
'enabled' => 1,
'visible' => -1,
'position' => 35),
137 'subscription' => array(
'type' =>
'double(24,8)',
'label' =>
'Amount',
'enabled' => 1,
'visible' => -1,
'position' => 40,
'isameasure' => 1),
138 'fk_bank' => array(
'type' =>
'integer',
'label' =>
'BankId',
'enabled' => 1,
'visible' => -1,
'position' => 45),
139 'note' => array(
'type' =>
'html',
'label' =>
'Note',
'enabled' => 1,
'visible' => -1,
'position' => 50),
140 'fk_type' => array(
'type' =>
'integer',
'label' =>
'MemberType',
'enabled' => 1,
'visible' => -1,
'position' => 55),
141 'fk_user_creat' => array(
'type' =>
'integer:User:user/class/user.class.php',
'label' =>
'UserAuthor',
'enabled' => 1,
'visible' => -2,
'position' => 60),
142 'fk_user_valid' => array(
'type' =>
'integer:User:user/class/user.class.php',
'label' =>
'UserValidation',
'enabled' => 1,
'visible' => -1,
'position' => 65),
143 'import_key' => array(
'type' =>
'varchar(14)',
'label' =>
'ImportId',
'enabled' => 1,
'visible' => -2,
'position' => 805),
156 $this->ismultientitymanaged =
'fk_adherent@adherent';
167 public function create($user, $notrigger = 0)
176 if (isset($this->import_key)) {
177 $this->import_key = trim($this->import_key);
181 if ($this->datef <= $this->dateh) {
182 $this->error = $langs->trans(
"ErrorBadValueForDate");
185 if (empty($this->datec)) {
191 require_once DOL_DOCUMENT_ROOT.
'/adherents/class/adherent.class.php';
193 $result = $member->fetch($this->fk_adherent);
195 if ($this->fk_type ==
null) {
196 $type = $member->typeid;
198 $type = $this->fk_type;
201 $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)";
202 $sql .=
" VALUES (".((int) $this->fk_adherent).
", '".$this->db->escape((
string) $type).
"', '".$this->db->idate($now).
"',";
203 $sql .=
" '".$this->db->idate($this->dateh).
"',";
204 $sql .=
" '".$this->db->idate($this->datef).
"',";
205 $sql .=
" ".((float) $this->
amount).
",";
206 $sql .=
" '".$this->db->escape($this->note_public ? $this->note_public : $this->note).
"',";
207 $sql .=
" '".$this->db->escape($this->note_private).
"',";
208 $sql .=
" ".(empty($this->ref_ext) ?
"null" :
"'".$this->db->escape($this->ref_ext).
"'").
",";
209 $sql .=
" ".((int) ($this->user_creation_id > 0 ? $this->user_creation_id : ((int) $user->id)));
210 $sql .=
", ".(!empty($this->import_key) ?
"'".$this->db->escape($this->import_key).
"'" :
"null");
213 $resql = $this->db->query($sql);
216 $this->errors[] = $this->db->lasterror();
220 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.$this->table_element);
221 $this->fk_type = $type;
226 $result = $member->update_end_date($user);
229 $this->error = $member->error;
230 $this->errors[] = $this->error;
234 if (!empty($this->linkedObjectsIds) && empty($this->linked_objects)) {
235 $this->linked_objects = $this->linkedObjectsIds;
239 if (!$error && $this->
id && !empty($this->linked_objects) && is_array($this->linked_objects)) {
240 foreach ($this->linked_objects as $origin => $tmp_origin_id) {
241 if (is_array($tmp_origin_id)) {
242 foreach ($tmp_origin_id as $origin_id) {
245 $this->error = $this->db->lasterror();
250 $origin_id = $tmp_origin_id;
253 $this->error = $this->db->lasterror();
260 if (!$error && !$notrigger) {
261 $this->context = array(
'member' => $member);
263 $result = $this->call_trigger(
'MEMBER_SUBSCRIPTION_CREATE', $user);
272 $this->db->rollback();
289 $sql =
"SELECT rowid, fk_type, fk_adherent, datec,";
291 $sql .=
" dateadh as dateh,";
293 $sql .=
" subscription, note as note_public, fk_bank";
294 $sql .=
" FROM ".MAIN_DB_PREFIX.
"subscription";
295 $sql .=
" WHERE rowid = ".((int) $rowid);
297 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
298 $resql = $this->db->query($sql);
300 if ($this->db->num_rows($resql)) {
301 $obj = $this->db->fetch_object($resql);
303 $this->
id = $obj->rowid;
304 $this->
ref = $obj->rowid;
306 $this->fk_type = $obj->fk_type;
307 $this->fk_adherent = $obj->fk_adherent;
308 $this->datec = $this->db->jdate($obj->datec);
309 $this->datem = $this->db->jdate($obj->tms);
310 $this->dateh = $this->db->jdate($obj->dateh);
311 $this->datef = $this->db->jdate($obj->datef);
312 $this->
amount = $obj->subscription;
313 $this->note = $obj->note_public;
314 $this->note_public = $obj->note_public;
315 $this->fk_bank = $obj->fk_bank;
321 $this->error = $this->db->lasterror();
334 public function update($user, $notrigger = 0)
340 if (!is_numeric($this->
amount)) {
341 $this->error =
'BadValueForParameterAmount';
345 if (empty($this->note_public) && !empty($this->note)) {
346 $this->note_public = $this->note;
349 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"subscription SET ";
350 $sql .=
" fk_type = ".((int) $this->fk_type).
",";
351 $sql .=
" fk_adherent = ".((int) $this->fk_adherent).
",";
352 $sql .=
" note = ".($this->note_public ?
"'".$this->db->escape($this->note_public).
"'" :
'null').
",";
354 $sql .=
" dateadh = '".$this->db->idate($this->dateh).
"',";
355 $sql .=
" datef = '".$this->db->idate($this->datef).
"',";
356 $sql .=
" datec = '".$this->db->idate($this->datec).
"',";
357 $sql .=
" fk_bank = ".($this->fk_bank ? ((int) $this->fk_bank) :
'null');
358 $sql .=
" WHERE rowid = ".((int) $this->
id);
360 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
361 $resql = $this->db->query($sql);
363 require_once DOL_DOCUMENT_ROOT.
'/adherents/class/adherent.class.php';
365 $result = $member->fetch($this->fk_adherent);
366 $result = $member->update_end_date($user);
369 $this->context = array(
'member' => $member);
371 $result = $this->call_trigger(
'MEMBER_SUBSCRIPTION_MODIFY', $user);
379 $this->error = $this->db->lasterror();
384 $this->db->rollback();
399 public function delete($user, $notrigger = 0)
404 if ($this->fk_bank > 0) {
405 require_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/account.class.php';
407 $result = $accountline->fetch($this->fk_bank);
416 $result = $this->call_trigger(
'MEMBER_SUBSCRIPTION_DELETE', $user);
424 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"subscription WHERE rowid = ".((int) $this->
id);
425 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
426 $resql = $this->db->query($sql);
428 $num = $this->db->affected_rows($resql);
430 require_once DOL_DOCUMENT_ROOT.
'/adherents/class/adherent.class.php';
432 $result = $member->fetch($this->fk_adherent);
433 $result = $member->update_end_date($user);
435 if ($this->fk_bank > 0 && is_object($accountline) && $accountline->id > 0) {
436 $result = $accountline->delete($user);
448 $this->error = $this->db->lasterror();
454 $this->db->rollback();
473 public function getNomUrl($withpicto = 0, $notooltip = 0, $option =
'', $morecss =
'', $save_lastsearch_value = -1)
479 $langs->load(
"members");
480 $langs->load(
"main");
482 $label =
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"Subscription").
'</u>';
486 $label .=
'<br><b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
487 $label .=
'<br><b>'.$langs->trans(
'Label').
':</b> '.$this->note_public;
488 if (!empty($this->dateh)) {
489 $label .=
'<br><b>'.$langs->trans(
'DateStart').
':</b> '.
dol_print_date($this->dateh,
'day');
491 if (!empty($this->datef)) {
492 $label .=
'<br><b>'.$langs->trans(
'DateEnd').
':</b> '.
dol_print_date($this->datef,
'day');
494 $baseurl = DOL_URL_ROOT .
'/adherents/subscription/card.php';
495 $query = [
'rowid' => $this->id];
496 if ($option !=
'nolink') {
498 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
499 if ($save_lastsearch_value == -1 && isset($_SERVER[
"PHP_SELF"]) && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
500 $add_save_lastsearch_values = 1;
502 if ($add_save_lastsearch_values) {
503 $query = array_merge($query, [
'save_lastsearch_values' => 1]);
508 $linkstart =
'<a href="'.$url.
'" class="classfortooltip" title="'.
dol_escape_htmltag($label, 1).
'">';
511 $result .= $linkstart;
513 $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);
515 if ($withpicto != 2) {
516 $result .= $this->ref;
560 $sql =
"SELECT c.rowid, c.datec, c.tms as datem, c.fk_user_creat";
561 $sql .=
" FROM ".MAIN_DB_PREFIX.
"subscription as c";
562 $sql .=
" WHERE c.rowid = ".((int) $id);
564 $resql = $this->db->query($sql);
566 if ($this->db->num_rows($resql)) {
567 $obj = $this->db->fetch_object($resql);
568 $this->
id = $obj->rowid;
570 $this->date_creation = $this->db->jdate($obj->datec);
571 $this->date_modification = $this->db->jdate($obj->datem);
573 $this->user_creation_id = $obj->fk_user_creat;
576 $this->db->free($resql);
591 $selected = (empty($arraydata[
'selected']) ? 0 : $arraydata[
'selected']);
593 $return =
'<div class="box-flex-item box-flex-grow-zero">';
594 $return .=
'<div class="info-box info-box-sm">';
595 $return .=
'<span class="info-box-icon bg-infobox-action">';
597 $return .=
'</span>';
599 $return .=
'<div class="info-box-content">';
600 $return .=
'<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">';
602 $return .=
'</span>';
603 if ($selected >= 0) {
604 $return .=
'<input id="cb'.$this->id.
'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->
id.
'"'.($selected ?
' checked="checked"' :
'').
'>';
606 if (!empty($this->dateh) || !empty($this->datef)) {
607 $return .=
'<br><span class="info-box-status opacitymedium small">'.dol_print_date($this->dateh,
'day').
' - '.
dol_print_date($this->datef,
'day').
'</span>';
610 if (!empty($arraydata[
'member']) && is_object($arraydata[
'member'])) {
611 $return .=
'<br><div class="inline-block tdoverflowmax150">'.$arraydata[
'member']->getNomUrl(-4).
'</div>';
614 $return .=
'<br><span class="amount inline-block">'.price($this->
amount).
'</span>';
615 if (!empty($arraydata[
'bank'])) {
616 $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.
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.
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 '.
dolBuildUrl($url, $params=[], $addtoken=false, $anchor='')
Return path of url.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $allowothertags=array())
Show a picto called object_picto (generic function)
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).
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...
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