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';
96 public $fields = array(
97 'rowid' =>array(
'type'=>
'integer',
'label'=>
'TechnicalID',
'enabled'=>1,
'visible'=>-1,
'notnull'=>1,
'position'=>10),
98 'tms' =>array(
'type'=>
'timestamp',
'label'=>
'DateModification',
'enabled'=>1,
'visible'=>-1,
'notnull'=>1,
'position'=>15),
99 'datec' =>array(
'type'=>
'datetime',
'label'=>
'DateCreation',
'enabled'=>1,
'visible'=>-1,
'position'=>20),
100 'fk_adherent' =>array(
'type'=>
'integer',
'label'=>
'Member',
'enabled'=>1,
'visible'=>-1,
'position'=>25),
101 'dateadh' =>array(
'type'=>
'datetime',
'label'=>
'DateSubscription',
'enabled'=>1,
'visible'=>-1,
'position'=>30),
102 'datef' =>array(
'type'=>
'datetime',
'label'=>
'DateEndSubscription',
'enabled'=>1,
'visible'=>-1,
'position'=>35),
103 'subscription' =>array(
'type'=>
'double(24,8)',
'label'=>
'Amount',
'enabled'=>1,
'visible'=>-1,
'position'=>40,
'isameasure'=>1),
104 'fk_bank' =>array(
'type'=>
'integer',
'label'=>
'BankId',
'enabled'=>1,
'visible'=>-1,
'position'=>45),
105 'note' =>array(
'type'=>
'text',
'label'=>
'Note',
'enabled'=>1,
'visible'=>-1,
'position'=>50),
106 'fk_type' =>array(
'type'=>
'integer',
'label'=>
'MemberType',
'enabled'=>1,
'visible'=>-1,
'position'=>55),
107 'fk_user_creat' =>array(
'type'=>
'integer:User:user/class/user.class.php',
'label'=>
'UserAuthor',
'enabled'=>1,
'visible'=>-2,
'position'=>60),
108 'fk_user_valid' =>array(
'type'=>
'integer:User:user/class/user.class.php',
'label'=>
'UserValidation',
'enabled'=>1,
'visible'=>-1,
'position'=>65),
130 public function create($user, $notrigger =
false)
139 if ($this->datef <= $this->dateh) {
140 $this->error = $langs->trans(
"ErrorBadValueForDate");
143 if (empty($this->datec)) $this->datec = $now;
148 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"subscription (fk_adherent, fk_type, datec, dateadh, datef, subscription, note)";
150 require_once DOL_DOCUMENT_ROOT.
'/adherents/class/adherent.class.php';
152 $result = $member->fetch($this->fk_adherent);
154 if ($this->fk_type == null) {
155 $type = $member->typeid;
157 $type = $this->fk_type;
159 $sql .=
" VALUES (".$this->fk_adherent.
", '".$this->
db->escape($type).
"', '".$this->
db->idate($now).
"',";
160 $sql .=
" '".$this->db->idate($this->dateh).
"',";
161 $sql .=
" '".$this->db->idate($this->datef).
"',";
162 $sql .=
" ".$this->amount.
",";
163 $sql .=
" '".$this->db->escape($this->note_public ? $this->note_public : $this->
note).
"')";
168 $this->errors[] = $this->
db->lasterror();
172 $this->
id = $this->
db->last_insert_id(MAIN_DB_PREFIX.$this->table_element);
173 $this->fk_type = $type;
176 if (!$error && !$notrigger) {
177 $this->context = array(
'member' => $member);
179 $result = $this->
call_trigger(
'MEMBER_SUBSCRIPTION_CREATE', $user);
180 if ($result < 0) { $error++; }
186 $this->
db->rollback();
203 $sql =
"SELECT rowid, fk_type, fk_adherent, datec,";
205 $sql .=
" dateadh as dateh,";
207 $sql .=
" subscription, note, fk_bank";
208 $sql .=
" FROM ".MAIN_DB_PREFIX.
"subscription";
209 $sql .=
" WHERE rowid=".$rowid;
211 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
215 $obj = $this->
db->fetch_object(
$resql);
217 $this->
id = $obj->rowid;
218 $this->ref = $obj->rowid;
220 $this->fk_type = $obj->fk_type;
221 $this->fk_adherent = $obj->fk_adherent;
222 $this->datec = $this->
db->jdate($obj->datec);
223 $this->datem = $this->
db->jdate($obj->tms);
224 $this->dateh = $this->
db->jdate($obj->dateh);
225 $this->datef = $this->
db->jdate($obj->datef);
226 $this->amount = $obj->subscription;
227 $this->
note = $obj->note;
228 $this->fk_bank = $obj->fk_bank;
234 $this->error = $this->
db->lasterror();
247 public function update($user, $notrigger = 0)
253 if (!is_numeric($this->amount)) {
254 $this->error =
'BadValueForParameterAmount';
258 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"subscription SET ";
259 $sql .=
" fk_type = ".$this->fk_type.
",";
260 $sql .=
" fk_adherent = ".$this->fk_adherent.
",";
261 $sql .=
" note=".($this->note ?
"'".$this->db->escape($this->
note).
"'" :
'null').
",";
262 $sql .=
" subscription = ".price2num($this->amount).
",";
263 $sql .=
" dateadh='".$this->db->idate($this->dateh).
"',";
264 $sql .=
" datef='".$this->db->idate($this->datef).
"',";
265 $sql .=
" datec='".$this->db->idate($this->datec).
"',";
266 $sql .=
" fk_bank = ".($this->fk_bank ? $this->fk_bank :
'null');
267 $sql .=
" WHERE rowid = ".$this->id;
269 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
272 require_once DOL_DOCUMENT_ROOT.
'/adherents/class/adherent.class.php';
274 $result = $member->fetch($this->fk_adherent);
275 $result = $member->update_end_date($user);
277 if (!$error && !$notrigger) {
278 $this->context = array(
'member'=>$member);
280 $result = $this->
call_trigger(
'MEMBER_SUBSCRIPTION_MODIFY', $user);
281 if ($result < 0) { $error++; }
286 $this->error = $this->
db->lasterror();
291 $this->
db->rollback();
306 public function delete($user, $notrigger =
false)
311 if ($this->fk_bank > 0) {
312 require_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/account.class.php';
314 $result = $accountline->fetch($this->fk_bank);
322 $result = $this->
call_trigger(
'MEMBER_SUBSCRIPTION_DELETE', $user);
323 if ($result < 0) { $error++; }
329 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"subscription WHERE rowid = ".$this->id;
330 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
333 $num = $this->
db->affected_rows(
$resql);
335 require_once DOL_DOCUMENT_ROOT.
'/adherents/class/adherent.class.php';
337 $result = $member->fetch($this->fk_adherent);
338 $result = $member->update_end_date($user);
340 if ($this->fk_bank > 0 && is_object($accountline) && $accountline->id > 0) {
341 $result = $accountline->delete($user);
346 $this->error = $accountline->error;
347 $this->
db->rollback();
360 $this->error = $this->
db->lasterror();
366 $this->
db->rollback();
385 public function getNomUrl($withpicto = 0, $notooltip = 0, $option =
'', $morecss =
'', $save_lastsearch_value = -1)
391 $langs->load(
"members");
393 $label =
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"Subscription").
'</u>';
397 $label .=
'<br><b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
398 if (!empty($this->dateh)) {
399 $label .=
'<br><b>'.$langs->trans(
'DateStart').
':</b> '.
dol_print_date($this->dateh,
'day');
401 if (!empty($this->datef)) {
402 $label .=
'<br><b>'.$langs->trans(
'DateEnd').
':</b> '.
dol_print_date($this->datef,
'day');
405 $url = DOL_URL_ROOT.
'/adherents/subscription/card.php?rowid='.$this->id;
407 if ($option !=
'nolink') {
409 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
410 if ($save_lastsearch_value == -1 && preg_match(
'/list\.php/',
$_SERVER[
"PHP_SELF"])) $add_save_lastsearch_values = 1;
411 if ($add_save_lastsearch_values) $url .=
'&save_lastsearch_values=1';
414 $linkstart =
'<a href="'.$url.
'" class="classfortooltip" title="'.
dol_escape_htmltag($label, 1).
'">';
417 $result .= $linkstart;
418 if ($withpicto) $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);
419 if ($withpicto != 2) $result .= $this->ref;
448 $langs->load(
"members");
460 $sql =
'SELECT c.rowid, c.datec,';
461 $sql .=
' c.tms as datem';
462 $sql .=
' FROM '.MAIN_DB_PREFIX.
'subscription as c';
463 $sql .=
' WHERE c.rowid = '.$id;
465 $result = $this->
db->query($sql);
467 if ($this->
db->num_rows($result)) {
468 $obj = $this->
db->fetch_object($result);
469 $this->
id = $obj->rowid;
471 $this->date_creation = $this->
db->jdate($obj->datec);
472 $this->date_modification = $this->
db->jdate($obj->datem);
475 $this->
db->free($result);
getLibStatut($mode=0)
Retourne le libelle du statut d'une adhesion.
info($id)
Load information of the subscription object.
fetch($rowid)
Method to load a subscription.
dol_now($mode= 'auto')
Return date for now.
Class to manage bank transaction lines.
$conf db
API class for accounts.
getNomUrl($withpicto=0, $notooltip=0, $option= '', $morecss= '', $save_lastsearch_value=-1)
Return clicable name (with picto eventually)
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.
Class to manage members of a foundation.
img_object($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
Class to manage subscriptions of foundation members.
LibStatut($status)
Renvoi le libelle d'un statut donne.
print $_SERVER["PHP_SELF"]
Edit parameters.
create($user, $notrigger=false)
Function who permitted cretaion of the subscription.
__construct($db)
Constructor.
dol_print_date($time, $format= '', $tzoutput= 'auto', $outputlangs= '', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
update($user, $notrigger=0)
Update subscription.
call_trigger($triggerName, $user)
Call trigger based on this instance.
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->don->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
Parent class of all other business classes (invoices, contracts, proposals, orders, ...)
if(!empty($search_group)) natural_search(array("g.nom"g note
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $keepmoretags= '', $escapeonlyhtmltags=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields...