dolibarr 21.0.0-alpha
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) 2024 Frédéric France <frederic.france@free.fr>
4 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
26// Put here all includes required by your class file
27require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
28//require_once DOL_DOCUMENT_ROOT . '/societe/class/societe.class.php';
29//require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php';
30
35{
39 public $element = 'companypaymentmode';
40
44 public $table_element = 'societe_rib';
45
49 public $picto = 'generic';
50
51
52 const STATUS_ENABLED = 1;
53 const STATUS_CANCELED = 0;
54
55
73 // BEGIN MODULEBUILDER PROPERTIES
77 public $fields = array(
78 'rowid' => array('type' => 'integer', 'label' => 'Rowid', 'enabled' => 1, 'visible' => -2, 'notnull' => 1, 'position' => 10),
79 'fk_soc' => array('type' => 'integer', 'label' => 'Fk soc', 'enabled' => 1, 'visible' => -2, 'notnull' => 1, 'position' => 15),
80 'label' => array('type' => 'varchar(30)', 'label' => 'Label', 'enabled' => 1, 'visible' => -2, 'position' => 30),
81 'bank' => array('type' => 'varchar(255)', 'label' => 'Bank', 'enabled' => 1, 'visible' => -2, 'position' => 35),
82 'code_banque' => array('type' => 'varchar(128)', 'label' => 'Code banque', 'enabled' => 1, 'visible' => -2, 'position' => 40),
83 'code_guichet' => array('type' => 'varchar(6)', 'label' => 'Code guichet', 'enabled' => 1, 'visible' => -2, 'position' => 45),
84 'number' => array('type' => 'varchar(255)', 'label' => 'Number', 'enabled' => 1, 'visible' => -2, 'position' => 50),
85 'cle_rib' => array('type' => 'varchar(5)', 'label' => 'Cle rib', 'enabled' => 1, 'visible' => -2, 'position' => 55),
86 'bic' => array('type' => 'varchar(20)', 'label' => 'Bic', 'enabled' => 1, 'visible' => -2, 'position' => 60),
87 'iban_prefix' => array('type' => 'varchar(34)', 'label' => 'Iban prefix', 'enabled' => 1, 'visible' => -2, 'position' => 65),
88 'domiciliation' => array('type' => 'varchar(255)', 'label' => 'Domiciliation', 'enabled' => 1, 'visible' => -2, 'position' => 70),
89 'proprio' => array('type' => 'varchar(60)', 'label' => 'Proprio', 'enabled' => 1, 'visible' => -2, 'position' => 75),
90 'owner_address' => array('type' => 'text', 'label' => 'Owner address', 'enabled' => 1, 'visible' => -2, 'position' => 80),
91 'default_rib' => array('type' => 'tinyint(4)', 'label' => 'Default rib', 'enabled' => 1, 'visible' => -2, 'notnull' => 1, 'position' => 85),
92 'rum' => array('type' => 'varchar(32)', 'label' => 'Rum', 'enabled' => 1, 'visible' => -2, 'position' => 90),
93 'date_rum' => array('type' => 'date', 'label' => 'Date rum', 'enabled' => 1, 'visible' => -2, 'position' => 95),
94 'frstrecur' => array('type' => 'varchar(16)', 'label' => 'Frstrecur', 'enabled' => 1, 'visible' => -2, 'position' => 100),
95 'type' => array('type' => 'varchar(32)', 'label' => 'Type', 'enabled' => 1, 'visible' => -2, 'position' => 110),
96 'last_four' => array('type' => 'varchar(4)', 'label' => 'Last four', 'enabled' => 1, 'visible' => -2, 'position' => 115),
97 'card_type' => array('type' => 'varchar(255)', 'label' => 'Card type', 'enabled' => 1, 'visible' => -2, 'position' => 120),
98 'cvn' => array('type' => 'varchar(255)', 'label' => 'Cvn', 'enabled' => 1, 'visible' => -2, 'position' => 125),
99 'exp_date_month' => array('type' => 'integer', 'label' => 'Exp date month', 'enabled' => 1, 'visible' => -2, 'position' => 130),
100 'exp_date_year' => array('type' => 'integer', 'label' => 'Exp date year', 'enabled' => 1, 'visible' => -2, 'position' => 135),
101 'country_code' => array('type' => 'varchar(10)', 'label' => 'Country code', 'enabled' => 1, 'visible' => -2, 'position' => 140),
102 'approved' => array('type' => 'integer', 'label' => 'Approved', 'enabled' => 1, 'visible' => -2, 'position' => 145),
103 'email' => array('type' => 'varchar(255)', 'label' => 'Email', 'enabled' => 1, 'visible' => -2, 'position' => 150),
104 'max_total_amount_of_all_payments' => array('type' => 'double(24,8)', 'label' => 'Max total amount of all payments', 'enabled' => 1, 'visible' => -2, 'position' => 155),
105 'preapproval_key' => array('type' => 'varchar(255)', 'label' => 'Preapproval key', 'enabled' => 1, 'visible' => -2, 'position' => 160),
106 'total_amount_of_all_payments' => array('type' => 'double(24,8)', 'label' => 'Total amount of all payments', 'enabled' => 1, 'visible' => -2, 'position' => 165),
107 'stripe_card_ref' => array('type' => 'varchar(128)', 'label' => 'ExternalSystemID', 'enabled' => 1, 'visible' => -2, 'position' => 170, 'help' => 'IDOfPaymentInAnExternalSystem'),
108 'stripe_account' => array('type' => 'varchar(128)', 'label' => 'ExternalSystemCustomerAccount', 'enabled' => 1, 'visible' => -2, 'position' => 171, 'help' => 'IDOfCustomerInAnExternalSystem'),
109 'ext_payment_site' => array('type' => 'varchar(128)', 'label' => 'ExternalSystem', 'enabled' => 1, 'visible' => -2, 'position' => 172, 'help' => 'NameOfExternalSystem'),
110 'status' => array('type' => 'integer', 'label' => 'Status', 'enabled' => 1, 'visible' => -2, 'notnull' => 1, 'position' => 175),
111 'starting_date' => array('type' => 'date', 'label' => 'Starting date', 'enabled' => 1, 'visible' => -2, 'position' => 180),
112 'ending_date' => array('type' => 'date', 'label' => 'Ending date', 'enabled' => 1, 'visible' => -2, 'position' => 185),
113 'datec' => array('type' => 'datetime', 'label' => 'DateCreation', 'enabled' => 1, 'visible' => -2, 'position' => 20),
114 'tms' => array('type' => 'timestamp', 'label' => 'Tms', 'enabled' => 1, 'visible' => -2, 'notnull' => 1, 'position' => 25),
115 'import_key' => array('type' => 'varchar(14)', 'label' => 'Import key', 'enabled' => 1, 'visible' => -2, 'position' => 105),
116 //'aaa' =>array('type'=>'date', 'label'=>'Ending date', 'enabled'=>0, 'visible'=>-2, 'position'=>185),
117 );
118
122 public $rowid;
123
127 public $fk_soc;
128
132 public $label;
133
134 public $bank;
135 public $code_banque;
136 public $code_guichet;
137 public $number;
138 public $cle_rib;
139 public $bic;
140
146 public $iban;
147
152 public $iban_prefix;
153 public $domiciliation;
154 public $proprio;
155 public $owner_address;
156 public $default_rib;
157 public $rum;
158 public $date_rum;
159 public $frstrecur;
160 public $type;
161 public $last_four;
162 public $card_type;
163 public $cvn;
164 public $exp_date_month;
165 public $exp_date_year;
166 public $country_code;
167 public $approved;
168 public $email;
169 public $max_total_amount_of_all_payments;
170 public $preapproval_key;
171 public $total_amount_of_all_payments;
172 public $stripe_card_ref; // External system payment mode ID
173 public $stripe_account; // External system customer ID
174 public $ext_payment_site; // External system 'StripeLive', 'StripeTest', 'StancerLive', 'StancerTest', ...
175
179 public $status;
180
181 public $starting_date;
182 public $ending_date;
183
189 public $datec;
190
191 public $import_key;
192 // END MODULEBUILDER PROPERTIES
193
194
200 public function __construct(DoliDB $db)
201 {
202 global $conf;
203
204 $this->db = $db;
205
206 $this->ismultientitymanaged = 'fk_soc@societe';
207 $this->isextrafieldmanaged = 0;
208
209 if (!getDolGlobalString('MAIN_SHOW_TECHNICAL_ID') && isset($this->fields['rowid'])) {
210 $this->fields['rowid']['visible'] = 0;
211 }
212 if (!isModEnabled('multicompany') && isset($this->fields['entity'])) {
213 $this->fields['entity']['enabled'] = 0;
214 }
215 }
216
224 public function create(User $user, $notrigger = 0)
225 {
226 $idpayment = $this->createCommon($user, $notrigger);
227
228 return $idpayment;
229 }
230
238 public function createFromClone(User $user, $fromid)
239 {
240 global $hookmanager, $langs;
241 $error = 0;
242
243 dol_syslog(__METHOD__, LOG_DEBUG);
244
245 $object = new self($this->db);
246
247 $this->db->begin();
248
249 // Load source object
250 $object->fetchCommon($fromid);
251 // Reset some properties
252 unset($object->id);
253 unset($object->fk_user_creat);
254 unset($object->import_key);
255
256 // Clear fields
257 $object->ref = "copy_of_".$object->ref;
258 // $object->title = $langs->trans("CopyOf")." ".$object->title;
259
260 // Create clone
261 $object->context['createfromclone'] = 'createfromclone';
262 $result = $object->createCommon($user);
263 if ($result < 0) {
264 $error++;
265 $this->error = $object->error;
266 $this->errors = $object->errors;
267 }
268
269 unset($object->context['createfromclone']);
270
271 // End
272 if (!$error) {
273 $this->db->commit();
274 return $object;
275 } else {
276 $this->db->rollback();
277 return -1;
278 }
279 }
280
291 public function fetch($id, $ref = null, $socid = 0, $type = '', $morewhere = '')
292 {
293 if ($socid) {
294 $morewhere .= " AND fk_soc = ".((int) $socid)." AND default_rib = 1";
295 }
296 if ($type) {
297 $morewhere .= " AND type = '".$this->db->escape($type)."'";
298 }
299
300 $result = $this->fetchCommon($id, $ref, $morewhere);
301
302 // For backward compatibility
303 $this->iban = $this->iban_prefix;
304 $this->date_modification = $this->tms;
305
306 //if ($result > 0 && !empty($this->table_element_line)) $this->fetchLines();
307 return $result;
308 }
309
315 /*public function fetchLines()
316 {
317 $this->lines=array();
318
319 // Load lines with object CompanyPaymentModeLine
320
321 return count($this->lines)?1:0;
322 }*/
323
331 public function update(User $user, $notrigger = 0)
332 {
333 return $this->updateCommon($user, $notrigger);
334 }
335
343 public function delete(User $user, $notrigger = 0)
344 {
345 return $this->deleteCommon($user, $notrigger);
346 }
347
358 public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
359 {
360 global $db, $conf, $langs;
361 global $dolibarr_main_authentication, $dolibarr_main_demo;
362 global $menumanager;
363
364 if (!empty($conf->dol_no_mouse_hover)) {
365 $notooltip = 1; // Force disable tooltips
366 }
367
368 $result = '';
369 $companylink = '';
370
371 $label = '<u>'.$langs->trans("CompanyPaymentMode").'</u>';
372 $label .= '<br>';
373 $label .= '<b>'.$langs->trans('Ref').':</b> '.$this->ref;
374
375 $url = '';
376
377 if ($option != 'nolink') {
378 // Add param to save lastsearch_values or not
379 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
380 if ($save_lastsearch_value == -1 && isset($_SERVER["PHP_SELF"]) && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
381 $add_save_lastsearch_values = 1;
382 }
383 if ($add_save_lastsearch_values) {
384 $url .= '&save_lastsearch_values=1';
385 }
386 }
387
388 $linkclose = '';
389 if (empty($notooltip)) {
390 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
391 $label = $langs->trans("ShowCompanyPaymentMode");
392 $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
393 }
394 $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"';
395 $linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"';
396 } else {
397 $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
398 }
399
400 $linkstart = '<a href="'.$url.'"';
401 $linkstart .= $linkclose.'>';
402 $linkend = '</a>';
403
404 $result .= $linkstart;
405 if ($withpicto) {
406 $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);
407 }
408 if ($withpicto != 2) {
409 $result .= $this->ref;
410 }
411 $result .= $linkend;
412 //if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : '');
413
414 return $result;
415 }
416
424 public function setAsDefault($id = 0, $alltypes = 0)
425 {
426 $sql1 = "SELECT rowid as id, fk_soc, type FROM ".MAIN_DB_PREFIX."societe_rib";
427 $sql1 .= " WHERE rowid = ".($id ? $id : $this->id);
428
429 dol_syslog(get_class($this).'::setAsDefault', LOG_DEBUG);
430 $result1 = $this->db->query($sql1);
431 if ($result1) {
432 if ($this->db->num_rows($result1) == 0) {
433 return 0;
434 } else {
435 $obj = $this->db->fetch_object($result1);
436
437 $type = '';
438 if (empty($alltypes)) {
439 $type = $obj->type;
440 }
441
442 $this->db->begin();
443
444 $sql2 = "UPDATE ".MAIN_DB_PREFIX."societe_rib SET default_rib = 0, tms = tms";
445 $sql2 .= " WHERE default_rib <> 0 AND fk_soc = ".((int) $obj->fk_soc);
446 if ($type) {
447 $sql2 .= " AND type = '".$this->db->escape($type)."'";
448 }
449 dol_syslog(get_class($this).'::setAsDefault', LOG_DEBUG);
450 $result2 = $this->db->query($sql2);
451
452 $sql3 = "UPDATE ".MAIN_DB_PREFIX."societe_rib SET default_rib = 1";
453 $sql3 .= " WHERE rowid = ".((int) $obj->id);
454 if ($type) {
455 $sql3 .= " AND type = '".$this->db->escape($type)."'";
456 }
457 dol_syslog(get_class($this).'::setAsDefault', LOG_DEBUG);
458 $result3 = $this->db->query($sql3);
459
460 if (!$result2 || !$result3) {
461 dol_print_error($this->db);
462 $this->db->rollback();
463 return -1;
464 } else {
465 $this->db->commit();
466 return 1;
467 }
468 }
469 } else {
470 dol_print_error($this->db);
471 return -1;
472 }
473 }
474
481 public function getLibStatut($mode = 0)
482 {
483 return $this->LibStatut($this->status, $mode);
484 }
485
486 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
494 public function LibStatut($status, $mode = 0)
495 {
496 // phpcs:enable
497 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
498 global $langs;
499 //$langs->load("mymodule");
500 $this->labelStatus[self::STATUS_ENABLED] = $langs->transnoentitiesnoconv('Enabled');
501 $this->labelStatus[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv('Disabled');
502 $this->labelStatusShort[self::STATUS_ENABLED] = $langs->transnoentitiesnoconv('Enabled');
503 $this->labelStatusShort[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv('Disabled');
504 }
505
506 $statusType = 'status5';
507 if ($status == self::STATUS_ENABLED) {
508 $statusType = 'status4';
509 }
510
511 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode);
512 }
513
520 public function info($id)
521 {
522 $sql = 'SELECT rowid, date_creation as datec, tms as datem,';
523 $sql .= ' fk_user_creat, fk_user_modif';
524 $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
525 $sql .= ' WHERE t.rowid = '.((int) $id);
526 $result = $this->db->query($sql);
527 if ($result) {
528 if ($this->db->num_rows($result)) {
529 $obj = $this->db->fetch_object($result);
530
531 $this->id = $obj->rowid;
532
533 $this->user_creation_id = $obj->fk_user_creat;
534 $this->user_modification_id = $obj->fk_user_modif;
535 $this->date_creation = $this->db->jdate($obj->datec);
536 $this->date_modification = empty($obj->datem) ? '' : $this->db->jdate($obj->datem);
537 }
538
539 $this->db->free($result);
540 } else {
541 dol_print_error($this->db);
542 }
543 }
544
551 public function initAsSpecimen()
552 {
553 return $this->initAsSpecimenCommon();
554 }
555}
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:58
print $langs trans("AuditedSecurityEvents").'</strong >< span class="opacitymedium"></span >< br > status
Or an array listing all the potential status of the object: array: int of the status => translated la...
Definition security.php:640
Parent class of all other business classes (invoices, contracts, proposals, orders,...
createCommon(User $user, $notrigger=0)
Create object in the database.
updateCommon(User $user, $notrigger=0)
Update object into database.
initAsSpecimenCommon()
Initialise object with example values Id must be 0 if object instance is a specimen.
fetchCommon($id, $ref=null, $morewhere='', $noextrafields=0)
Load object in memory from the database.
deleteCommon(User $user, $notrigger=0, $forcechilddeletion=0)
Delete object in database.
Class for CompanyPaymentMode.
create(User $user, $notrigger=0)
Create object into database.
update(User $user, $notrigger=0)
Load object lines in memory from the database.
info($id)
Load the info information in the object.
setAsDefault($id=0, $alltypes=0)
Set a Payment mode as Default.
getLibStatut($mode=0)
Return label of the status.
__construct(DoliDB $db)
Constructor.
getNomUrl($withpicto=0, $option='', $notooltip=0, $morecss='', $save_lastsearch_value=-1)
Return a link to the object card (with optionally the picto)
initAsSpecimen()
Initialise object with example values Id must be 0 if object instance is a specimen.
fetch($id, $ref=null, $socid=0, $type='', $morewhere='')
Load object in memory from the database.
LibStatut($status, $mode=0)
Return the status.
createFromClone(User $user, $fromid)
Clone and object into another one.
Class to manage Dolibarr database access.
Class to manage Dolibarr users.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.