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'=>
'text',
'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).
"')";
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);
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);
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);
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);
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);
517 $return =
'<div class="box-flex-item box-flex-grow-zero">';
518 $return .=
'<div class="info-box info-box-sm">';
519 $return .=
'<span class="info-box-icon bg-infobox-action">';
521 $return .=
'</span>';
523 $return .=
'<div class="info-box-content">';
524 $return .=
'<span class="info-box-ref">'.(property_exists($this,
'fk_adherent')? $this->fk_adherent: $this->ref ).
'</span>';
525 if (property_exists($this,
'dateh') || property_exists($this,
'datef')) {
526 $return .=
'<br><span class="info-box-status opacitymedium">'.dol_print_date($this->dateh,
'day').
' - '.
dol_print_date($this->datef,
'day').
'</span>';
529 if (property_exists($this,
'fk_bank')) {
530 $return .=
'<br><span class="info-box-label ">'.$this->fk_bank.
'</span>';
532 if (property_exists($this,
'amount')) {
533 $return .=
'<br><div class="info-box-label margintoponly amount">'.price($this->amount).
'</div>';
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)
Retourne le libelle du statut d'une adhesion.
info($id)
Load information of the subscription object.
__construct($db)
Constructor.
getKanbanView($option='')
Return clicable link of object (with eventually picto)
getNomUrl($withpicto=0, $notooltip=0, $option='', $morecss='', $save_lastsearch_value=-1)
Return clicable name (with picto eventually)
create($user, $notrigger=false)
Function who permitted cretaion of the subscription.
LibStatut($status)
Renvoi le libelle d'un statut donne.
update($user, $notrigger=0)
Update subscription.
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields.
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.
$conf db
API class for accounts.