dolibarr  13.0.2
companypaymentmode.class.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2017 Laurent Destailleur <eldy@users.sourceforge.net>
3  * Copyright (C) ---Put here your own copyright and developer email---
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <https://www.gnu.org/licenses/>.
17  */
18 
25 // Put here all includes required by your class file
26 require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
27 //require_once DOL_DOCUMENT_ROOT . '/societe/class/societe.class.php';
28 //require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php';
29 
34 {
38  public $element = 'companypaymentmode';
39 
43  public $table_element = 'societe_rib';
44 
49  public $ismultientitymanaged = 'fk_soc@societe';
50 
54  public $isextrafieldmanaged = 0;
55 
59  public $picto = 'generic';
60 
61 
62  const STATUS_ENABLED = 1;
63  const STATUS_CANCELED = 0;
64 
65 
83  // BEGIN MODULEBUILDER PROPERTIES
87  public $fields = array(
88  'rowid' =>array('type'=>'integer', 'label'=>'Rowid', 'enabled'=>1, 'visible'=>-2, 'notnull'=>1, 'position'=>10),
89  'fk_soc' =>array('type'=>'integer', 'label'=>'Fk soc', 'enabled'=>1, 'visible'=>-2, 'notnull'=>1, 'position'=>15),
90  'label' =>array('type'=>'varchar(30)', 'label'=>'Label', 'enabled'=>1, 'visible'=>-2, 'position'=>30),
91  'bank' =>array('type'=>'varchar(255)', 'label'=>'Bank', 'enabled'=>1, 'visible'=>-2, 'position'=>35),
92  'code_banque' =>array('type'=>'varchar(128)', 'label'=>'Code banque', 'enabled'=>1, 'visible'=>-2, 'position'=>40),
93  'code_guichet' =>array('type'=>'varchar(6)', 'label'=>'Code guichet', 'enabled'=>1, 'visible'=>-2, 'position'=>45),
94  'number' =>array('type'=>'varchar(255)', 'label'=>'Number', 'enabled'=>1, 'visible'=>-2, 'position'=>50),
95  'cle_rib' =>array('type'=>'varchar(5)', 'label'=>'Cle rib', 'enabled'=>1, 'visible'=>-2, 'position'=>55),
96  'bic' =>array('type'=>'varchar(20)', 'label'=>'Bic', 'enabled'=>1, 'visible'=>-2, 'position'=>60),
97  'iban_prefix' =>array('type'=>'varchar(34)', 'label'=>'Iban prefix', 'enabled'=>1, 'visible'=>-2, 'position'=>65),
98  'domiciliation' =>array('type'=>'varchar(255)', 'label'=>'Domiciliation', 'enabled'=>1, 'visible'=>-2, 'position'=>70),
99  'proprio' =>array('type'=>'varchar(60)', 'label'=>'Proprio', 'enabled'=>1, 'visible'=>-2, 'position'=>75),
100  'owner_address' =>array('type'=>'text', 'label'=>'Owner address', 'enabled'=>1, 'visible'=>-2, 'position'=>80),
101  'default_rib' =>array('type'=>'tinyint(4)', 'label'=>'Default rib', 'enabled'=>1, 'visible'=>-2, 'notnull'=>1, 'position'=>85),
102  'rum' =>array('type'=>'varchar(32)', 'label'=>'Rum', 'enabled'=>1, 'visible'=>-2, 'position'=>90),
103  'date_rum' =>array('type'=>'date', 'label'=>'Date rum', 'enabled'=>1, 'visible'=>-2, 'position'=>95),
104  'frstrecur' =>array('type'=>'varchar(16)', 'label'=>'Frstrecur', 'enabled'=>1, 'visible'=>-2, 'position'=>100),
105  'type' =>array('type'=>'varchar(32)', 'label'=>'Type', 'enabled'=>1, 'visible'=>-2, 'position'=>110),
106  'last_four' =>array('type'=>'varchar(4)', 'label'=>'Last four', 'enabled'=>1, 'visible'=>-2, 'position'=>115),
107  'card_type' =>array('type'=>'varchar(255)', 'label'=>'Card type', 'enabled'=>1, 'visible'=>-2, 'position'=>120),
108  'cvn' =>array('type'=>'varchar(255)', 'label'=>'Cvn', 'enabled'=>1, 'visible'=>-2, 'position'=>125),
109  'exp_date_month' =>array('type'=>'integer', 'label'=>'Exp date month', 'enabled'=>1, 'visible'=>-2, 'position'=>130),
110  'exp_date_year' =>array('type'=>'integer', 'label'=>'Exp date year', 'enabled'=>1, 'visible'=>-2, 'position'=>135),
111  'country_code' =>array('type'=>'varchar(10)', 'label'=>'Country code', 'enabled'=>1, 'visible'=>-2, 'position'=>140),
112  'approved' =>array('type'=>'integer', 'label'=>'Approved', 'enabled'=>1, 'visible'=>-2, 'position'=>145),
113  'email' =>array('type'=>'varchar(255)', 'label'=>'Email', 'enabled'=>1, 'visible'=>-2, 'position'=>150),
114  'max_total_amount_of_all_payments' =>array('type'=>'double(24,8)', 'label'=>'Max total amount of all payments', 'enabled'=>1, 'visible'=>-2, 'position'=>155),
115  'preapproval_key' =>array('type'=>'varchar(255)', 'label'=>'Preapproval key', 'enabled'=>1, 'visible'=>-2, 'position'=>160),
116  'total_amount_of_all_payments' =>array('type'=>'double(24,8)', 'label'=>'Total amount of all payments', 'enabled'=>1, 'visible'=>-2, 'position'=>165),
117  'stripe_card_ref' =>array('type'=>'varchar(128)', 'label'=>'Stripe card ref', 'enabled'=>1, 'visible'=>-2, 'position'=>170),
118  'stripe_account' =>array('type'=>'varchar(128)', 'label'=>'Stripe account', 'enabled'=>1, 'visible'=>-2, 'position'=>171),
119  'status' =>array('type'=>'integer', 'label'=>'Status', 'enabled'=>1, 'visible'=>-2, 'notnull'=>1, 'position'=>175),
120  'starting_date' =>array('type'=>'date', 'label'=>'Starting date', 'enabled'=>1, 'visible'=>-2, 'position'=>180),
121  'ending_date' =>array('type'=>'date', 'label'=>'Ending date', 'enabled'=>1, 'visible'=>-2, 'position'=>185),
122  'datec' =>array('type'=>'datetime', 'label'=>'DateCreation', 'enabled'=>1, 'visible'=>-2, 'position'=>20),
123  'tms' =>array('type'=>'timestamp', 'label'=>'Tms', 'enabled'=>1, 'visible'=>-2, 'notnull'=>1, 'position'=>25),
124  'import_key' =>array('type'=>'varchar(14)', 'label'=>'Import key', 'enabled'=>1, 'visible'=>-2, 'position'=>105),
125  //'aaa' =>array('type'=>'date', 'label'=>'Ending date', 'enabled'=>0, 'visible'=>-2, 'position'=>185),
126  );
127 
131  public $rowid;
132 
136  public $fk_soc;
137 
141  public $label;
142 
143  public $bank;
144  public $code_banque;
145  public $code_guichet;
146  public $number;
147  public $cle_rib;
148  public $bic;
149  public $iban_prefix;
150  public $domiciliation;
151  public $proprio;
152  public $owner_address;
153  public $default_rib;
154  public $rum;
155  public $date_rum;
156  public $frstrecur;
157  public $type;
158  public $last_four;
159  public $card_type;
160  public $cvn;
161  public $exp_date_month;
162  public $exp_date_year;
163  public $country_code;
164  public $approved;
165  public $email;
166  public $max_total_amount_of_all_payments;
167  public $preapproval_key;
168  public $total_amount_of_all_payments;
169  public $stripe_card_ref;
170  public $stripe_account;
171 
175  public $status;
176 
177  public $starting_date;
178  public $ending_date;
179 
185  public $datec;
186 
192  public $tms;
193 
194  public $import_key;
195  // END MODULEBUILDER PROPERTIES
196 
197 
198 
199  // If this object has a subtable with lines
200 
204  //public $table_element_line = 'companypaymentmodedet';
208  //public $fk_element = 'fk_companypaymentmode';
212  //public $class_element_line = 'CompanyPaymentModeline';
216  //protected $childtables=array();
220  //public $lines = array();
221 
222 
223 
229  public function __construct(DoliDB $db)
230  {
231  global $conf;
232 
233  $this->db = $db;
234 
235  if (empty($conf->global->MAIN_SHOW_TECHNICAL_ID) && isset($this->fields['rowid'])) $this->fields['rowid']['visible'] = 0;
236  if (empty($conf->multicompany->enabled) && isset($this->fields['entity'])) $this->fields['entity']['enabled'] = 0;
237  }
238 
246  public function create(User $user, $notrigger = false)
247  {
248  $idpayment = $this->createCommon($user, $notrigger);
249 
250  return $idpayment;
251  }
252 
260  public function createFromClone(User $user, $fromid)
261  {
262  global $hookmanager, $langs;
263  $error = 0;
264 
265  dol_syslog(__METHOD__, LOG_DEBUG);
266 
267  $object = new self($this->db);
268 
269  $this->db->begin();
270 
271  // Load source object
272  $object->fetchCommon($fromid);
273  // Reset some properties
274  unset($object->id);
275  unset($object->fk_user_creat);
276  unset($object->import_key);
277 
278  // Clear fields
279  $object->ref = "copy_of_".$object->ref;
280  $object->title = $langs->trans("CopyOf")." ".$object->title;
281  // ...
282 
283  // Create clone
284  $object->context['createfromclone'] = 'createfromclone';
285  $result = $object->createCommon($user);
286  if ($result < 0) {
287  $error++;
288  $this->error = $object->error;
289  $this->errors = $object->errors;
290  }
291 
292  unset($object->context['createfromclone']);
293 
294  // End
295  if (!$error) {
296  $this->db->commit();
297  return $object;
298  } else {
299  $this->db->rollback();
300  return -1;
301  }
302  }
303 
314  public function fetch($id, $ref = null, $socid = 0, $type = '', $morewhere = '')
315  {
316  if ($socid) $morewhere .= " AND fk_soc = ".$this->db->escape($socid)." AND default_rib = 1";
317  if ($type) $morewhere .= " AND type = '".$this->db->escape($type)."'";
318 
319  $result = $this->fetchCommon($id, $ref, $morewhere);
320  //if ($result > 0 && ! empty($this->table_element_line)) $this->fetchLines();
321  return $result;
322  }
323 
329  /*public function fetchLines()
330  {
331  $this->lines=array();
332 
333  // Load lines with object CompanyPaymentModeLine
334 
335  return count($this->lines)?1:0;
336  }*/
337 
345  public function update(User $user, $notrigger = false)
346  {
347  return $this->updateCommon($user, $notrigger);
348  }
349 
357  public function delete(User $user, $notrigger = false)
358  {
359  return $this->deleteCommon($user, $notrigger);
360  }
361 
372  public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
373  {
374  global $db, $conf, $langs;
375  global $dolibarr_main_authentication, $dolibarr_main_demo;
376  global $menumanager;
377 
378  if (!empty($conf->dol_no_mouse_hover)) $notooltip = 1; // Force disable tooltips
379 
380  $result = '';
381  $companylink = '';
382 
383  $label = '<u>'.$langs->trans("CompanyPaymentMode").'</u>';
384  $label .= '<br>';
385  $label .= '<b>'.$langs->trans('Ref').':</b> '.$this->ref;
386 
387  $url = dol_buildpath('/monmodule/companypaymentmode_card.php', 1).'?id='.$this->id;
388 
389  if ($option != 'nolink')
390  {
391  // Add param to save lastsearch_values or not
392  $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
393  if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) $add_save_lastsearch_values = 1;
394  if ($add_save_lastsearch_values) $url .= '&save_lastsearch_values=1';
395  }
396 
397  $linkclose = '';
398  if (empty($notooltip))
399  {
400  if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER))
401  {
402  $label = $langs->trans("ShowCompanyPaymentMode");
403  $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
404  }
405  $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"';
406  $linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"';
407  } else $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
408 
409  $linkstart = '<a href="'.$url.'"';
410  $linkstart .= $linkclose.'>';
411  $linkend = '</a>';
412 
413  $result .= $linkstart;
414  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);
415  if ($withpicto != 2) $result .= $this->ref;
416  $result .= $linkend;
417  //if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : '');
418 
419  return $result;
420  }
421 
429  public function setAsDefault($id = 0, $alltypes = 0)
430  {
431  $sql1 = "SELECT rowid as id, fk_soc, type FROM ".MAIN_DB_PREFIX."societe_rib";
432  $sql1 .= " WHERE rowid = ".($id ? $id : $this->id);
433 
434  dol_syslog(get_class($this).'::setAsDefault', LOG_DEBUG);
435  $result1 = $this->db->query($sql1);
436  if ($result1)
437  {
438  if ($this->db->num_rows($result1) == 0)
439  {
440  return 0;
441  } else {
442  $obj = $this->db->fetch_object($result1);
443 
444  $type = '';
445  if (empty($alltypes)) $type = $obj->type;
446 
447  $this->db->begin();
448 
449  $sql2 = "UPDATE ".MAIN_DB_PREFIX."societe_rib SET default_rib = 0, tms = tms";
450  $sql2 .= " WHERE default_rib <> 0 AND fk_soc = ".$obj->fk_soc;
451  if ($type) $sql2 .= " AND type = '".$this->db->escape($type)."'";
452  dol_syslog(get_class($this).'::setAsDefault', LOG_DEBUG);
453  $result2 = $this->db->query($sql2);
454 
455  $sql3 = "UPDATE ".MAIN_DB_PREFIX."societe_rib SET default_rib = 1";
456  $sql3 .= " WHERE rowid = ".$obj->id;
457  if ($type) $sql3 .= " AND type = '".$this->db->escape($type)."'";
458  dol_syslog(get_class($this).'::setAsDefault', LOG_DEBUG);
459  $result3 = $this->db->query($sql3);
460 
461  if (!$result2 || !$result3)
462  {
463  dol_print_error($this->db);
464  $this->db->rollback();
465  return -1;
466  } else {
467  $this->db->commit();
468  return 1;
469  }
470  }
471  } else {
472  dol_print_error($this->db);
473  return -1;
474  }
475  }
476 
483  public function getLibStatut($mode = 0)
484  {
485  return $this->LibStatut($this->status, $mode);
486  }
487 
488  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
496  public function LibStatut($status, $mode = 0)
497  {
498  // phpcs:enable
499  if (empty($this->labelStatus) || empty($this->labelStatusShort))
500  {
501  global $langs;
502  //$langs->load("mymodule");
503  $this->labelStatus[self::STATUS_ENABLED] = $langs->trans('Enabled');
504  $this->labelStatus[self::STATUS_CANCELED] = $langs->trans('Disabled');
505  $this->labelStatusShort[self::STATUS_ENABLED] = $langs->trans('Enabled');
506  $this->labelStatusShort[self::STATUS_CANCELED] = $langs->trans('Disabled');
507  }
508 
509  $statusType = 'status5';
510  if ($status == self::STATUS_ENABLED) $statusType = 'status4';
511 
512  return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode);
513  }
514 
521  public function info($id)
522  {
523  $sql = 'SELECT rowid, date_creation as datec, tms as datem,';
524  $sql .= ' fk_user_creat, fk_user_modif';
525  $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
526  $sql .= ' WHERE t.rowid = '.$id;
527  $result = $this->db->query($sql);
528  if ($result)
529  {
530  if ($this->db->num_rows($result))
531  {
532  $obj = $this->db->fetch_object($result);
533  $this->id = $obj->rowid;
534  if ($obj->fk_user_author)
535  {
536  $cuser = new User($this->db);
537  $cuser->fetch($obj->fk_user_author);
538  $this->user_creation = $cuser;
539  }
540 
541  if ($obj->fk_user_valid)
542  {
543  $vuser = new User($this->db);
544  $vuser->fetch($obj->fk_user_valid);
545  $this->user_validation = $vuser;
546  }
547 
548  if ($obj->fk_user_cloture)
549  {
550  $cluser = new User($this->db);
551  $cluser->fetch($obj->fk_user_cloture);
552  $this->user_cloture = $cluser;
553  }
554 
555  $this->date_creation = $this->db->jdate($obj->datec);
556  $this->date_modification = $this->db->jdate($obj->datem);
557  $this->date_validation = $this->db->jdate($obj->datev);
558  }
559 
560  $this->db->free($result);
561  } else {
562  dol_print_error($this->db);
563  }
564  }
565 
572  public function initAsSpecimen()
573  {
574  $this->initAsSpecimenCommon();
575  }
576 }
deleteCommon(User $user, $notrigger=false, $forcechilddeletion=0)
Delete object in database.
foreach($object->fields as $key=> $val) if(is_array($extrafields->attributes[$object->table_element]['label'])&&count($extrafields->attributes[$object->table_element]['label']) > 0) $object fields
Class to manage Dolibarr users.
Definition: user.class.php:44
Class to manage Dolibarr database access.
initAsSpecimenCommon()
Initialise object with example values Id must be 0 if object instance is a specimen.
createCommon(User $user, $notrigger=false)
Create object into database.
createFromClone(User $user, $fromid)
Clone and object into another one.
create(User $user, $notrigger=false)
Create object into database.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
fetch($id, $ref=null, $socid=0, $type= '', $morewhere= '')
Load object in memory from the database.
$conf db
API class for accounts.
Definition: inc.php:54
__construct(DoliDB $db)
Constructor.
getNomUrl($withpicto=0, $option= '', $notooltip=0, $morecss= '', $save_lastsearch_value=-1)
Return a link to the object card (with optionaly the picto)
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
img_object($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
updateCommon(User $user, $notrigger=false)
Update object into database.
info($id)
Load the info information in the object.
update(User $user, $notrigger=false)
Load object lines in memory from the database.
print $_SERVER["PHP_SELF"]
Edit parameters.
Class for CompanyPaymentMode.
initAsSpecimen()
Initialise object with example values Id must be 0 if object instance is a specimen.
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dolGetStatus($statusLabel= '', $statusLabelShort= '', $html= '', $statusType= 'status0', $displayMode=0, $url= '', $params=array())
Output the badge of a status.
setAsDefault($id=0, $alltypes=0)
Set a Payment mode as Default.
getLibStatut($mode=0)
Return label of the status.
LibStatut($status, $mode=0)
Return the status.
Parent class of all other business classes (invoices, contracts, proposals, orders, ...)
fetchCommon($id, $ref=null, $morewhere= '')
Load object in memory from the database.