dolibarr  18.0.0
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 
155  public $iban;
156 
161  public $iban_prefix;
162  public $domiciliation;
163  public $proprio;
164  public $owner_address;
165  public $default_rib;
166  public $rum;
167  public $date_rum;
168  public $frstrecur;
169  public $type;
170  public $last_four;
171  public $card_type;
172  public $cvn;
173  public $exp_date_month;
174  public $exp_date_year;
175  public $country_code;
176  public $approved;
177  public $email;
178  public $max_total_amount_of_all_payments;
179  public $preapproval_key;
180  public $total_amount_of_all_payments;
181  public $stripe_card_ref;
182  public $stripe_account;
183 
187  public $status;
188 
189  public $starting_date;
190  public $ending_date;
191 
197  public $datec;
198 
204  public $tms;
205 
206  public $import_key;
207  // END MODULEBUILDER PROPERTIES
208 
209 
215  public function __construct(DoliDB $db)
216  {
217  global $conf;
218 
219  $this->db = $db;
220 
221  if (empty($conf->global->MAIN_SHOW_TECHNICAL_ID) && isset($this->fields['rowid'])) {
222  $this->fields['rowid']['visible'] = 0;
223  }
224  if (!isModEnabled('multicompany') && isset($this->fields['entity'])) {
225  $this->fields['entity']['enabled'] = 0;
226  }
227  }
228 
236  public function create(User $user, $notrigger = false)
237  {
238  $idpayment = $this->createCommon($user, $notrigger);
239 
240  return $idpayment;
241  }
242 
250  public function createFromClone(User $user, $fromid)
251  {
252  global $hookmanager, $langs;
253  $error = 0;
254 
255  dol_syslog(__METHOD__, LOG_DEBUG);
256 
257  $object = new self($this->db);
258 
259  $this->db->begin();
260 
261  // Load source object
262  $object->fetchCommon($fromid);
263  // Reset some properties
264  unset($object->id);
265  unset($object->fk_user_creat);
266  unset($object->import_key);
267 
268  // Clear fields
269  $object->ref = "copy_of_".$object->ref;
270  // $object->title = $langs->trans("CopyOf")." ".$object->title;
271 
272  // Create clone
273  $object->context['createfromclone'] = 'createfromclone';
274  $result = $object->createCommon($user);
275  if ($result < 0) {
276  $error++;
277  $this->error = $object->error;
278  $this->errors = $object->errors;
279  }
280 
281  unset($object->context['createfromclone']);
282 
283  // End
284  if (!$error) {
285  $this->db->commit();
286  return $object;
287  } else {
288  $this->db->rollback();
289  return -1;
290  }
291  }
292 
303  public function fetch($id, $ref = null, $socid = 0, $type = '', $morewhere = '')
304  {
305  if ($socid) {
306  $morewhere .= " AND fk_soc = ".((int) $socid)." AND default_rib = 1";
307  }
308  if ($type) {
309  $morewhere .= " AND type = '".$this->db->escape($type)."'";
310  }
311 
312  $result = $this->fetchCommon($id, $ref, $morewhere);
313 
314  // For backward compatibility
315  $this->iban = $this->iban_prefix;
316 
317  //if ($result > 0 && !empty($this->table_element_line)) $this->fetchLines();
318  return $result;
319  }
320 
326  /*public function fetchLines()
327  {
328  $this->lines=array();
329 
330  // Load lines with object CompanyPaymentModeLine
331 
332  return count($this->lines)?1:0;
333  }*/
334 
342  public function update(User $user, $notrigger = false)
343  {
344  return $this->updateCommon($user, $notrigger);
345  }
346 
354  public function delete(User $user, $notrigger = false)
355  {
356  return $this->deleteCommon($user, $notrigger);
357  }
358 
369  public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
370  {
371  global $db, $conf, $langs;
372  global $dolibarr_main_authentication, $dolibarr_main_demo;
373  global $menumanager;
374 
375  if (!empty($conf->dol_no_mouse_hover)) {
376  $notooltip = 1; // Force disable tooltips
377  }
378 
379  $result = '';
380  $companylink = '';
381 
382  $label = '<u>'.$langs->trans("CompanyPaymentMode").'</u>';
383  $label .= '<br>';
384  $label .= '<b>'.$langs->trans('Ref').':</b> '.$this->ref;
385 
386  $url = '';
387 
388  if ($option != 'nolink') {
389  // Add param to save lastsearch_values or not
390  $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
391  if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
392  $add_save_lastsearch_values = 1;
393  }
394  if ($add_save_lastsearch_values) {
395  $url .= '&save_lastsearch_values=1';
396  }
397  }
398 
399  $linkclose = '';
400  if (empty($notooltip)) {
401  if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
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 {
408  $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
409  }
410 
411  $linkstart = '<a href="'.$url.'"';
412  $linkstart .= $linkclose.'>';
413  $linkend = '</a>';
414 
415  $result .= $linkstart;
416  if ($withpicto) {
417  $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);
418  }
419  if ($withpicto != 2) {
420  $result .= $this->ref;
421  }
422  $result .= $linkend;
423  //if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : '');
424 
425  return $result;
426  }
427 
435  public function setAsDefault($id = 0, $alltypes = 0)
436  {
437  $sql1 = "SELECT rowid as id, fk_soc, type FROM ".MAIN_DB_PREFIX."societe_rib";
438  $sql1 .= " WHERE rowid = ".($id ? $id : $this->id);
439 
440  dol_syslog(get_class($this).'::setAsDefault', LOG_DEBUG);
441  $result1 = $this->db->query($sql1);
442  if ($result1) {
443  if ($this->db->num_rows($result1) == 0) {
444  return 0;
445  } else {
446  $obj = $this->db->fetch_object($result1);
447 
448  $type = '';
449  if (empty($alltypes)) {
450  $type = $obj->type;
451  }
452 
453  $this->db->begin();
454 
455  $sql2 = "UPDATE ".MAIN_DB_PREFIX."societe_rib SET default_rib = 0, tms = tms";
456  $sql2 .= " WHERE default_rib <> 0 AND fk_soc = ".((int) $obj->fk_soc);
457  if ($type) {
458  $sql2 .= " AND type = '".$this->db->escape($type)."'";
459  }
460  dol_syslog(get_class($this).'::setAsDefault', LOG_DEBUG);
461  $result2 = $this->db->query($sql2);
462 
463  $sql3 = "UPDATE ".MAIN_DB_PREFIX."societe_rib SET default_rib = 1";
464  $sql3 .= " WHERE rowid = ".((int) $obj->id);
465  if ($type) {
466  $sql3 .= " AND type = '".$this->db->escape($type)."'";
467  }
468  dol_syslog(get_class($this).'::setAsDefault', LOG_DEBUG);
469  $result3 = $this->db->query($sql3);
470 
471  if (!$result2 || !$result3) {
472  dol_print_error($this->db);
473  $this->db->rollback();
474  return -1;
475  } else {
476  $this->db->commit();
477  return 1;
478  }
479  }
480  } else {
481  dol_print_error($this->db);
482  return -1;
483  }
484  }
485 
492  public function getLibStatut($mode = 0)
493  {
494  return $this->LibStatut($this->status, $mode);
495  }
496 
497  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
505  public function LibStatut($status, $mode = 0)
506  {
507  // phpcs:enable
508  if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
509  global $langs;
510  //$langs->load("mymodule");
511  $this->labelStatus[self::STATUS_ENABLED] = $langs->transnoentitiesnoconv('Enabled');
512  $this->labelStatus[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv('Disabled');
513  $this->labelStatusShort[self::STATUS_ENABLED] = $langs->transnoentitiesnoconv('Enabled');
514  $this->labelStatusShort[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv('Disabled');
515  }
516 
517  $statusType = 'status5';
518  if ($status == self::STATUS_ENABLED) {
519  $statusType = 'status4';
520  }
521 
522  return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode);
523  }
524 
531  public function info($id)
532  {
533  $sql = 'SELECT rowid, date_creation as datec, tms as datem,';
534  $sql .= ' fk_user_creat, fk_user_modif';
535  $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
536  $sql .= ' WHERE t.rowid = '.((int) $id);
537  $result = $this->db->query($sql);
538  if ($result) {
539  if ($this->db->num_rows($result)) {
540  $obj = $this->db->fetch_object($result);
541  $this->id = $obj->rowid;
542 
543  $this->user_creation_id = $obj->fk_user_creat;
544  $this->user_modification_id = $obj->fk_user_modif;
545  $this->date_creation = $this->db->jdate($obj->datec);
546  $this->date_modification = empty($obj->datem) ? '' : $this->db->jdate($obj->datem);
547  }
548 
549  $this->db->free($result);
550  } else {
551  dol_print_error($this->db);
552  }
553  }
554 
561  public function initAsSpecimen()
562  {
563  $this->initAsSpecimenCommon();
564  }
565 }
CommonObject\deleteCommon
deleteCommon(User $user, $notrigger=false, $forcechilddeletion=0)
Delete object in database.
Definition: commonobject.class.php:9574
CommonObject\fetchCommon
fetchCommon($id, $ref=null, $morewhere='')
Load object in memory from the database.
Definition: commonobject.class.php:9364
CompanyPaymentMode\createFromClone
createFromClone(User $user, $fromid)
Clone and object into another one.
Definition: companypaymentmode.class.php:250
DoliDB
Class to manage Dolibarr database access.
Definition: DoliDB.class.php:30
dol_print_error
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
Definition: functions.lib.php:5107
CompanyPaymentMode\initAsSpecimen
initAsSpecimen()
Initialise object with example values Id must be 0 if object instance is a specimen.
Definition: companypaymentmode.class.php:561
CompanyPaymentMode\fetch
fetch($id, $ref=null, $socid=0, $type='', $morewhere='')
Load object in memory from the database.
Definition: companypaymentmode.class.php:303
CompanyPaymentMode\getNomUrl
getNomUrl($withpicto=0, $option='', $notooltip=0, $morecss='', $save_lastsearch_value=-1)
Return a link to the object card (with optionaly the picto)
Definition: companypaymentmode.class.php:369
CommonObject\initAsSpecimenCommon
initAsSpecimenCommon()
Initialise object with example values Id must be 0 if object instance is a specimen.
Definition: commonobject.class.php:9902
CommonObject
Parent class of all other business classes (invoices, contracts, proposals, orders,...
Definition: commonobject.class.php:45
CompanyPaymentMode\LibStatut
LibStatut($status, $mode=0)
Return the status.
Definition: companypaymentmode.class.php:505
CompanyPaymentMode\create
create(User $user, $notrigger=false)
Create object into database.
Definition: companypaymentmode.class.php:236
CompanyPaymentMode\getLibStatut
getLibStatut($mode=0)
Return label of the status.
Definition: companypaymentmode.class.php:492
CommonObject\createCommon
createCommon(User $user, $notrigger=false)
Create object into database.
Definition: commonobject.class.php:9197
CompanyPaymentMode\info
info($id)
Load the info information in the object.
Definition: companypaymentmode.class.php:531
dol_syslog
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
Definition: functions.lib.php:1741
CommonObject\updateCommon
updateCommon(User $user, $notrigger=false)
Update object into database.
Definition: commonobject.class.php:9470
$sql
if(isModEnabled('facture') && $user->hasRight('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') && $user->hasRight('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)) $sql
Social contributions to pay.
Definition: index.php:746
isModEnabled
isModEnabled($module)
Is Dolibarr module enabled.
Definition: functions.lib.php:207
User
Class to manage Dolibarr users.
Definition: user.class.php:47
dolGetStatus
dolGetStatus($statusLabel='', $statusLabelShort='', $html='', $statusType='status0', $displayMode=0, $url='', $params=array())
Output the badge of a status.
Definition: functions.lib.php:10967
img_object
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
Definition: functions.lib.php:4473
CompanyPaymentMode\update
update(User $user, $notrigger=false)
Load object lines in memory from the database.
Definition: companypaymentmode.class.php:342
CompanyPaymentMode\setAsDefault
setAsDefault($id=0, $alltypes=0)
Set a Payment mode as Default.
Definition: companypaymentmode.class.php:435
CompanyPaymentMode
Class for CompanyPaymentMode.
Definition: companypaymentmode.class.php:33
CompanyPaymentMode\__construct
__construct(DoliDB $db)
Constructor.
Definition: companypaymentmode.class.php:215