dolibarr  13.0.2
paymentmodes.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2002-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3  * Copyright (C) 2003 Jean-Louis Bergamo <jlb@j1b.org>
4  * Copyright (C) 2004-2018 Laurent Destailleur <eldy@users.sourceforge.net>
5  * Copyright (C) 2005-2009 Regis Houssin <regis.houssin@inodbox.com>
6  * Copyright (C) 2013 Peter Fontaine <contact@peterfontaine.fr>
7  * Copyright (C) 2015-2016 Marcos García <marcosgdf@gmail.com>
8  * Copyright (C) 2017 Ferran Marcet <fmarcet@2byte.es>
9  * Copyright (C) 2018 ptibogxiv <support@ptibogxiv.net>
10  *
11  * This program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation; either version 3 of the License, or
14  * (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program. If not, see <https://www.gnu.org/licenses/>.
23  */
24 
31 require '../main.inc.php';
32 require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
33 require_once DOL_DOCUMENT_ROOT.'/core/lib/bank.lib.php';
34 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
35 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
36 require_once DOL_DOCUMENT_ROOT.'/societe/class/companybankaccount.class.php';
37 require_once DOL_DOCUMENT_ROOT.'/societe/class/companypaymentmode.class.php';
38 require_once DOL_DOCUMENT_ROOT.'/societe/class/societeaccount.class.php';
39 require_once DOL_DOCUMENT_ROOT.'/compta/prelevement/class/bonprelevement.class.php';
40 require_once DOL_DOCUMENT_ROOT.'/stripe/class/stripe.class.php';
41 
42 $langs->loadLangs(array("companies", "commercial", "banks", "bills", 'paypal', 'stripe', 'withdrawals'));
43 
44 
45 // Security check
46 $socid = GETPOST("socid", "int");
47 if ($user->socid) $socid = $user->socid;
48 $result = restrictedArea($user, 'societe', '', '');
49 
50 $id = GETPOST("id", "int");
51 $source = GETPOST("source", "alpha"); // source can be a source or a paymentmode
52 $ribid = GETPOST("ribid", "int");
53 $action = GETPOST("action", 'alpha', 3);
54 $cancel = GETPOST('cancel', 'alpha');
55 
56 $object = new Societe($db);
57 $object->fetch($socid);
58 
59 $companybankaccount = new CompanyBankAccount($db);
60 $companypaymentmode = new CompanyPaymentMode($db);
61 $prelevement = new BonPrelevement($db);
62 
63 $extrafields = new ExtraFields($db);
64 
65 // fetch optionals attributes and labels
66 $extrafields->fetch_name_optionals_label($object->table_element);
67 
68 // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
69 $hookmanager->initHooks(array('thirdpartybancard', 'globalcard'));
70 
71 
72 if (!empty($conf->stripe->enabled))
73 {
74  $service = 'StripeTest';
75  $servicestatus = 0;
76  if (!empty($conf->global->STRIPE_LIVE) && !GETPOST('forcesandbox', 'alpha'))
77  {
78  $service = 'StripeLive';
79  $servicestatus = 1;
80  }
81 
82  // Force to use the correct API key
83  global $stripearrayofkeysbyenv;
84  $site_account = $stripearrayofkeysbyenv[$servicestatus]['publishable_key'];
85 
86  $stripe = new Stripe($db);
87  $stripeacc = $stripe->getStripeAccount($service); // Get Stripe OAuth connect account (no remote access to Stripe here)
88  $stripecu = $stripe->getStripeCustomerAccount($object->id, $servicestatus, $site_account); // Get remote Stripe customer 'cus_...' (no remote access to Stripe here)
89 }
90 
91 
92 
93 /*
94  * Actions
95  */
96 
97 if ($cancel)
98 {
99  $action = '';
100 }
101 
102 $parameters = array('id'=>$socid, 'objcanvas'=>$objcanvas);
103 $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
104 if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
105 
106 if (empty($reshook))
107 {
108  if ($cancel)
109  {
110  $action = '';
111  if (!empty($backtopage))
112  {
113  header("Location: ".$backtopage);
114  exit;
115  }
116  }
117 
118  if ($action == 'update')
119  {
120  // Modification
121  if (!GETPOST('label', 'alpha') || !GETPOST('bank', 'alpha'))
122  {
123  if (!GETPOST('label', 'alpha')) setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Label")), null, 'errors');
124  if (!GETPOST('bank', 'alpha')) setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("BankName")), null, 'errors');
125  $action = 'edit';
126  $error++;
127  }
128  if ($companybankaccount->needIBAN() == 1)
129  {
130  if (!GETPOST('iban'))
131  {
132  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("IBAN")), null, 'errors');
133  $action = 'edit';
134  $error++;
135  }
136  if (!GETPOST('bic'))
137  {
138  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("BIC")), null, 'errors');
139  $action = 'edit';
140  $error++;
141  }
142  }
143 
144  $companybankaccount->fetch($id);
145  if (!$error)
146  {
147  $companybankaccount->socid = $object->id;
148 
149  $companybankaccount->bank = GETPOST('bank', 'alpha');
150  $companybankaccount->label = GETPOST('label', 'alpha');
151  $companybankaccount->courant = GETPOST('courant', 'alpha');
152  $companybankaccount->clos = GETPOST('clos', 'alpha');
153  $companybankaccount->code_banque = GETPOST('code_banque', 'alpha');
154  $companybankaccount->code_guichet = GETPOST('code_guichet', 'alpha');
155  $companybankaccount->number = GETPOST('number', 'alpha');
156  $companybankaccount->cle_rib = GETPOST('cle_rib', 'alpha');
157  $companybankaccount->bic = GETPOST('bic', 'alpha');
158  $companybankaccount->iban = GETPOST('iban', 'alpha');
159  $companybankaccount->domiciliation = GETPOST('domiciliation', 'alpha');
160  $companybankaccount->proprio = GETPOST('proprio', 'alpha');
161  $companybankaccount->owner_address = GETPOST('owner_address', 'alpha');
162  $companybankaccount->frstrecur = GETPOST('frstrecur', 'alpha');
163  $companybankaccount->rum = GETPOST('rum', 'alpha');
164  $companybankaccount->date_rum = dol_mktime(0, 0, 0, GETPOST('date_rummonth'), GETPOST('date_rumday'), GETPOST('date_rumyear'));
165  if (empty($companybankaccount->rum))
166  {
167  $companybankaccount->rum = $prelevement->buildRumNumber($object->code_client, $companybankaccount->datec, $companybankaccount->id);
168  }
169  if (empty($companybankaccount->date_rum))
170  {
171  $companybankaccount->date_rum = dol_now();
172  }
173 
174  $result = $companybankaccount->update($user);
175  if (!$result)
176  {
177  setEventMessages($companybankaccount->error, $companybankaccount->errors, 'errors');
178  } else {
179  // If this account is the default bank account, we disable others
180  if ($companybankaccount->default_rib)
181  {
182  $companybankaccount->setAsDefault($id); // This will make sure there is only one default rib
183  }
184 
185  $url = $_SERVER["PHP_SELF"].'?socid='.$object->id;
186  header('Location: '.$url);
187  exit;
188  }
189  }
190  }
191 
192  if ($action == 'updatecard')
193  {
194  // Modification
195  if (!GETPOST('label', 'alpha') || !GETPOST('proprio', 'alpha') || !GETPOST('exp_date_month', 'alpha') || !GETPOST('exp_date_year', 'alpha'))
196  {
197  if (!GETPOST('label', 'alpha')) setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Label")), null, 'errors');
198  if (!GETPOST('proprio', 'alpha')) setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("NameOnCard")), null, 'errors');
199  //if (!GETPOST('cardnumber', 'alpha')) setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("CardNumber")), null, 'errors');
200  if (!(GETPOST('exp_date_month', 'alpha') > 0) || !(GETPOST('exp_date_year', 'alpha') > 0)) setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("ExpiryDate")), null, 'errors');
201  //if (!GETPOST('cvn', 'alpha')) setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("CVN")), null, 'errors');
202  $action = 'createcard';
203  $error++;
204  }
205 
206  $companypaymentmode->fetch($id);
207  if (!$error)
208  {
209  $companypaymentmode->fk_soc = $object->id;
210 
211  $companypaymentmode->bank = GETPOST('bank', 'alpha');
212  $companypaymentmode->label = GETPOST('label', 'alpha');
213  $companypaymentmode->number = GETPOST('cardnumber', 'alpha');
214  $companypaymentmode->last_four = substr(GETPOST('cardnumber', 'alpha'), -4);
215  $companypaymentmode->proprio = GETPOST('proprio', 'alpha');
216  $companypaymentmode->exp_date_month = GETPOST('exp_date_month', 'int');
217  $companypaymentmode->exp_date_year = GETPOST('exp_date_year', 'int');
218  $companypaymentmode->cvn = GETPOST('cvn', 'alpha');
219  $companypaymentmode->country_code = $object->country_code;
220 
221  if (GETPOST('stripe_card_ref', 'alpha') && GETPOST('stripe_card_ref', 'alpha') != $companypaymentmode->stripe_card_ref) {
222  // If we set a stripe value that is different than previous one, we also set the stripe account
223  $companypaymentmode->stripe_account = $stripecu.'@'.$site_account;
224  }
225  $companypaymentmode->stripe_card_ref = GETPOST('stripe_card_ref', 'alpha');
226 
227  $result = $companypaymentmode->update($user);
228  if (!$result)
229  {
230  setEventMessages($companypaymentmode->error, $companypaymentmode->errors, 'errors');
231  } else {
232  // If this account is the default bank account, we disable others
233  if ($companypaymentmode->default_rib)
234  {
235  $companypaymentmode->setAsDefault($id); // This will make sure there is only one default rib
236  }
237 
238  $url = $_SERVER["PHP_SELF"].'?socid='.$object->id;
239  header('Location: '.$url);
240  exit;
241  }
242  }
243  }
244 
245  if ($action == 'add')
246  {
247  $error = 0;
248 
249  if (!GETPOST('label', 'alpha') || !GETPOST('bank', 'alpha'))
250  {
251  if (!GETPOST('label', 'alpha')) setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Label")), null, 'errors');
252  if (!GETPOST('bank', 'alpha')) setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("BankName")), null, 'errors');
253  $action = 'create';
254  $error++;
255  }
256 
257  if (!$error)
258  {
259  // Ajout
260  $companybankaccount = new CompanyBankAccount($db);
261 
262  $companybankaccount->socid = $object->id;
263 
264  $companybankaccount->bank = GETPOST('bank', 'alpha');
265  $companybankaccount->label = GETPOST('label', 'alpha');
266  $companybankaccount->courant = GETPOST('courant', 'alpha');
267  $companybankaccount->clos = GETPOST('clos', 'alpha');
268  $companybankaccount->code_banque = GETPOST('code_banque', 'alpha');
269  $companybankaccount->code_guichet = GETPOST('code_guichet', 'alpha');
270  $companybankaccount->number = GETPOST('number', 'alpha');
271  $companybankaccount->cle_rib = GETPOST('cle_rib', 'alpha');
272  $companybankaccount->bic = GETPOST('bic', 'alpha');
273  $companybankaccount->iban = GETPOST('iban', 'alpha');
274  $companybankaccount->domiciliation = GETPOST('domiciliation', 'alpha');
275  $companybankaccount->proprio = GETPOST('proprio', 'alpha');
276  $companybankaccount->owner_address = GETPOST('owner_address', 'alpha');
277  $companybankaccount->frstrecur = GETPOST('frstrecur');
278  $companybankaccount->rum = GETPOST('rum', 'alpha');
279  $companybankaccount->date_rum = dol_mktime(0, 0, 0, GETPOST('date_rummonth'), GETPOST('date_rumday'), GETPOST('date_rumyear'));
280  $companybankaccount->datec = dol_now();
281  $companybankaccount->status = 1;
282 
283  $db->begin();
284 
285  // This test can be done only once properties were set
286  if ($companybankaccount->needIBAN() == 1)
287  {
288  if (!GETPOST('iban'))
289  {
290  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("IBAN")), null, 'errors');
291  $action = 'create';
292  $error++;
293  }
294  if (!GETPOST('bic'))
295  {
296  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("BIC")), null, 'errors');
297  $action = 'create';
298  $error++;
299  }
300  }
301 
302  if (!$error)
303  {
304  $result = $companybankaccount->create($user);
305  if ($result < 0)
306  {
307  $error++;
308  setEventMessages($companybankaccount->error, $companybankaccount->errors, 'errors');
309  $action = 'create'; // Force chargement page création
310  }
311 
312  if (empty($companybankaccount->rum))
313  {
314  $companybankaccount->rum = $prelevement->buildRumNumber($object->code_client, $companybankaccount->datec, $companybankaccount->id);
315  $companybankaccount->date_rum = dol_now();
316  }
317  }
318 
319  if (!$error)
320  {
321  $result = $companybankaccount->update($user); // This will set the UMR number.
322  if ($result < 0)
323  {
324  $error++;
325  setEventMessages($companybankaccount->error, $companybankaccount->errors, 'errors');
326  $action = 'create';
327  }
328  }
329 
330  if (!$error)
331  {
332  $db->commit();
333 
334  $url = $_SERVER["PHP_SELF"].'?socid='.$object->id;
335  header('Location: '.$url);
336  exit;
337  } else {
338  $db->rollback();
339  }
340  }
341  }
342 
343  if ($action == 'addcard')
344  {
345  $error = 0;
346 
347  if (!GETPOST('label', 'alpha') || !GETPOST('proprio', 'alpha') || !GETPOST('exp_date_month', 'alpha') || !GETPOST('exp_date_year', 'alpha'))
348  {
349  if (!GETPOST('label', 'alpha')) setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Label")), null, 'errors');
350  if (!GETPOST('proprio', 'alpha')) setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("NameOnCard")), null, 'errors');
351  //if (!GETPOST('cardnumber', 'alpha')) setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("CardNumber")), null, 'errors');
352  if (!(GETPOST('exp_date_month', 'alpha') > 0) || !(GETPOST('exp_date_year', 'alpha') > 0)) setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("ExpiryDate")), null, 'errors');
353  //if (!GETPOST('cvn', 'alpha')) setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("CVN")), null, 'errors');
354  $action = 'createcard';
355  $error++;
356  }
357 
358  if (!$error)
359  {
360  // Ajout
361  $companypaymentmode = new CompanyPaymentMode($db);
362 
363  $companypaymentmode->fk_soc = $object->id;
364  $companypaymentmode->bank = GETPOST('bank', 'alpha');
365  $companypaymentmode->label = GETPOST('label', 'alpha');
366  $companypaymentmode->number = GETPOST('cardnumber', 'alpha');
367  $companypaymentmode->last_four = substr(GETPOST('cardnumber', 'alpha'), -4);
368  $companypaymentmode->proprio = GETPOST('proprio', 'alpha');
369  $companypaymentmode->exp_date_month = GETPOST('exp_date_month', 'int');
370  $companypaymentmode->exp_date_year = GETPOST('exp_date_year', 'int');
371  $companypaymentmode->cvn = GETPOST('cvn', 'alpha');
372  $companypaymentmode->datec = dol_now();
373  $companypaymentmode->default_rib = 0;
374  $companypaymentmode->type = 'card';
375  $companypaymentmode->country_code = $object->country_code;
376  $companypaymentmode->status = $servicestatus;
377 
378  if (GETPOST('stripe_card_ref', 'alpha')) {
379  // If we set a stripe value, we also set the stripe account
380  $companypaymentmode->stripe_account = $stripecu.'@'.$site_account;
381  }
382  $companypaymentmode->stripe_card_ref = GETPOST('stripe_card_ref', 'alpha');
383 
384  $db->begin();
385 
386  if (!$error)
387  {
388  $result = $companypaymentmode->create($user);
389  if ($result < 0)
390  {
391  $error++;
392  setEventMessages($companypaymentmode->error, $companypaymentmode->errors, 'errors');
393  $action = 'createcard'; // Force chargement page création
394  }
395  }
396 
397  if (!$error)
398  {
399  $db->commit();
400 
401  $url = $_SERVER["PHP_SELF"].'?socid='.$object->id;
402  header('Location: '.$url);
403  exit;
404  } else {
405  $db->rollback();
406  }
407  }
408  }
409 
410  if ($action == 'setasbankdefault' && GETPOST('ribid', 'int') > 0)
411  {
412  $companybankaccount = new CompanyBankAccount($db);
413  $res = $companybankaccount->setAsDefault(GETPOST('ribid', 'int'));
414  if ($res)
415  {
416  $url = DOL_URL_ROOT.'/societe/paymentmodes.php?socid='.$object->id;
417  header('Location: '.$url);
418  exit;
419  } else {
420  setEventMessages($db->lasterror, null, 'errors');
421  }
422  }
423 
424  if ($action == 'confirm_deletecard' && GETPOST('confirm', 'alpha') == 'yes')
425  {
426  $companypaymentmode = new CompanyPaymentMode($db);
427  if ($companypaymentmode->fetch($ribid ? $ribid : $id))
428  {
429  /*if ($companypaymentmode->stripe_card_ref && preg_match('/pm_/', $companypaymentmode->stripe_card_ref))
430  {
431  $payment_method = \Stripe\PaymentMethod::retrieve($companypaymentmode->stripe_card_ref);
432  if ($payment_method)
433  {
434  $payment_method->detach();
435  }
436  }*/
437 
438  $result = $companypaymentmode->delete($user);
439  if ($result > 0)
440  {
441  $url = $_SERVER['PHP_SELF']."?socid=".$object->id;
442  header('Location: '.$url);
443  exit;
444  } else {
445  setEventMessages($companypaymentmode->error, $companypaymentmode->errors, 'errors');
446  }
447  } else {
448  setEventMessages($companypaymentmode->error, $companypaymentmode->errors, 'errors');
449  }
450  }
451  if ($action == 'confirm_delete' && GETPOST('confirm', 'alpha') == 'yes')
452  {
453  $companybankaccount = new CompanyBankAccount($db);
454  if ($companybankaccount->fetch($ribid ? $ribid : $id))
455  {
456  $result = $companybankaccount->delete($user);
457  if ($result > 0)
458  {
459  $url = $_SERVER['PHP_SELF']."?socid=".$object->id;
460  header('Location: '.$url);
461  exit;
462  } else {
463  setEventMessages($companybankaccount->error, $companybankaccount->errors, 'errors');
464  }
465  } else {
466  setEventMessages($companybankaccount->error, $companybankaccount->errors, 'errors');
467  }
468  }
469 
470  $savid = $id;
471 
472  // Actions to build doc
473  if ($action == 'builddocrib')
474  {
475  $action = 'builddoc';
476  $moreparams = array(
477  'use_companybankid'=>GETPOST('companybankid'),
478  'force_dir_output'=>$conf->societe->multidir_output[$object->entity].'/'.dol_sanitizeFileName($object->id)
479  );
480  $_POST['lang_id'] = GETPOST('lang_idrib'.GETPOST('companybankid', 'int'), 'alpha');
481  $_POST['model'] = GETPOST('modelrib'.GETPOST('companybankid', 'int'), 'alpha');
482  }
483 
484  $id = $socid;
485  $upload_dir = $conf->societe->multidir_output[$object->entity];
486  $permissiontoadd = $user->rights->societe->creer;
487  include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php';
488 
489  $id = $savid;
490 
491  // Action for stripe
492  if (!empty($conf->stripe->enabled) && class_exists('Stripe'))
493  {
494  if ($action == 'synccustomertostripe')
495  {
496  if ($object->client == 0)
497  {
498  $error++;
499  setEventMessages('ThisThirdpartyIsNotACustomer', null, 'errors');
500  } else {
501  // Creation of Stripe customer + update of societe_account
502  $cu = $stripe->customerStripe($object, $stripeacc, $servicestatus, 1);
503  if (!$cu)
504  {
505  $error++;
506  setEventMessages($stripe->error, $stripe->errors, 'errors');
507  } else {
508  $stripecu = $cu->id;
509  }
510  }
511  }
512  if ($action == 'synccardtostripe')
513  {
514  $companypaymentmode = new CompanyPaymentMode($db);
515  $companypaymentmode->fetch($id);
516 
517  if ($companypaymentmode->type != 'card')
518  {
519  $error++;
520  setEventMessages('ThisPaymentModeIsNotACard', null, 'errors');
521  } else {
522  // Get the Stripe customer
523  $cu = $stripe->customerStripe($object, $stripeacc, $servicestatus);
524  if (!$cu)
525  {
526  $error++;
527  setEventMessages($stripe->error, $stripe->errors, 'errors');
528  }
529 
530  if (!$error)
531  {
532  // Creation of Stripe card + update of societe_account
533  // Note that with the new Stripe API, option to create a card is no more available, instead an error message will be returned to
534  // ask to create the crdit card from Stripe backoffice.
535  $card = $stripe->cardStripe($cu, $companypaymentmode, $stripeacc, $servicestatus, 1);
536  if (!$card)
537  {
538  $error++;
539  setEventMessages($stripe->error, $stripe->errors, 'errors');
540  }
541  }
542  }
543  }
544 
545  if ($action == 'setkey_account')
546  {
547  $error = 0;
548 
549  $newcu = GETPOST('key_account', 'alpha');
550 
551  $db->begin();
552 
553  if (empty($newcu)) {
554  $sql = "DELETE FROM ".MAIN_DB_PREFIX."societe_account WHERE site = 'stripe' AND (site_account IS NULL or site_account = '' or site_account = '".$db->escape($site_account)."') AND fk_soc = ".$object->id." AND status = ".$servicestatus." AND entity = ".$conf->entity;
555  } else {
556  $sql = 'SELECT rowid FROM '.MAIN_DB_PREFIX."societe_account";
557  $sql .= " WHERE site = 'stripe' AND (site_account IS NULL or site_account = '' or site_account = '".$db->escape($site_account)."') AND fk_soc = ".$object->id." AND status = ".$servicestatus." AND entity = ".$conf->entity; // Keep = here for entity. Only 1 record must be modified !
558  }
559 
560  $resql = $db->query($sql);
561  $num = $db->num_rows($resql); // Note: $num is always 0 on an update and delete, it is defined for select only.
562  if (!empty($newcu)) {
563  if (empty($num))
564  {
565  $societeaccount = new SocieteAccount($db);
566  $societeaccount->fk_soc = $object->id;
567  $societeaccount->login = '';
568  $societeaccount->pass_encoding = '';
569  $societeaccount->site = 'stripe';
570  $societeaccount->status = $servicestatus;
571  $societeaccount->key_account = $newcu;
572  $societeaccount->site_account = $site_account;
573  $result = $societeaccount->create($user);
574  if ($result < 0)
575  {
576  $error++;
577  }
578  } else {
579  $sql = 'UPDATE '.MAIN_DB_PREFIX."societe_account";
580  $sql .= " SET key_account = '".$db->escape(GETPOST('key_account', 'alpha'))."', site_account = '".$db->escape($site_account)."'";
581  $sql .= " WHERE site = 'stripe' AND (site_account IS NULL or site_account = '' or site_account = '".$db->escape($site_account)."') AND fk_soc = ".$object->id." AND status = ".$servicestatus." AND entity = ".$conf->entity; // Keep = here for entity. Only 1 record must be modified !
582  $resql = $db->query($sql);
583  }
584  }
585  //var_dump($sql); var_dump($newcu); var_dump($num); exit;
586 
587  if (!$error)
588  {
589  $stripecu = $newcu;
590  $db->commit();
591  } else {
592  $db->rollback();
593  }
594  }
595 
596  if ($action == 'setkey_account_supplier')
597  {
598  $error = 0;
599 
600  $newsup = GETPOST('key_account_supplier', 'alpha');
601 
602  $db->begin();
603 
604  if (empty($newsup)) {
605  $sql = "DELETE FROM ".MAIN_DB_PREFIX."oauth_token WHERE fk_soc = ".$object->id." AND service = '".$db->escape($service)."' AND entity = ".$conf->entity;
606  // TODO Add site and site_account on oauth_token table
607  //$sql = "DELETE FROM ".MAIN_DB_PREFIX."oauth_token WHERE site = 'stripe' AND (site_account IS NULL or site_account = '".$db->escape($site_account)."') AND fk_soc = ".$object->id." AND service = '".$db->escape($service)."' AND entity = ".$conf->entity;
608  } else {
609  try {
610  $stripesup = \Stripe\Account::retrieve($db->escape(GETPOST('key_account_supplier', 'alpha')));
611  $tokenstring['stripe_user_id'] = $stripesup->id;
612  $tokenstring['type'] = $stripesup->type;
613  $sql = "UPDATE ".MAIN_DB_PREFIX."oauth_token";
614  $sql .= " SET tokenstring = '".$db->escape(json_encode($tokenstring))."'";
615  $sql .= " WHERE site = 'stripe' AND (site_account IS NULL or site_account = '".$db->escape($site_account)."') AND fk_soc = ".$object->id." AND service = '".$db->escape($service)."' AND entity = ".$conf->entity; // Keep = here for entity. Only 1 record must be modified !
616  // TODO Add site and site_account on oauth_token table
617  $sql .= " WHERE fk_soc = ".$object->id." AND service = '".$db->escape($service)."' AND entity = ".$conf->entity; // Keep = here for entity. Only 1 record must be modified !
618  } catch (Exception $e) {
619  $error++;
620  setEventMessages($e->getMessage(), null, 'errors');
621  }
622  }
623 
624  $resql = $db->query($sql);
625  $num = $db->num_rows($resql);
626  if (empty($num) && !empty($newsup))
627  {
628  try {
629  $stripesup = \Stripe\Account::retrieve($db->escape(GETPOST('key_account_supplier', 'alpha')));
630  $tokenstring['stripe_user_id'] = $stripesup->id;
631  $tokenstring['type'] = $stripesup->type;
632  $sql = "INSERT INTO ".MAIN_DB_PREFIX."oauth_token (service, fk_soc, entity, tokenstring)";
633  $sql .= " VALUES ('".$db->escape($service)."', ".$object->id.", ".$conf->entity.", '".$db->escape(json_encode($tokenstring))."')";
634  // TODO Add site and site_account on oauth_token table
635  } catch (Exception $e) {
636  $error++;
637  setEventMessages($e->getMessage(), null, 'errors');
638  }
639  $resql = $db->query($sql);
640  }
641 
642  if (!$error)
643  {
644  $stripesupplieracc = $newsup;
645  $db->commit();
646  } else {
647  $db->rollback();
648  }
649  }
650 
651  if ($action == 'setlocalassourcedefault') // Set as default when payment mode defined locally (and may be also remotely)
652  {
653  try {
654  $companypaymentmode->setAsDefault($id);
655 
656  $url = DOL_URL_ROOT.'/societe/paymentmodes.php?socid='.$object->id;
657  header('Location: '.$url);
658  exit;
659  } catch (Exception $e)
660  {
661  $error++;
662  setEventMessages($e->getMessage(), null, 'errors');
663  }
664  } elseif ($action == 'setassourcedefault') // Set as default when payment mode defined remotely only
665  {
666  try {
667  $cu = $stripe->customerStripe($object, $stripeacc, $servicestatus);
668  if (preg_match('/pm_/', $source))
669  {
670  $cu->invoice_settings->default_payment_method = (string) $source; // New
671  } else {
672  $cu->default_source = (string) $source; // Old
673  }
674  $result = $cu->save();
675 
676  $url = DOL_URL_ROOT.'/societe/paymentmodes.php?socid='.$object->id;
677  header('Location: '.$url);
678  exit;
679  } catch (Exception $e)
680  {
681  $error++;
682  setEventMessages($e->getMessage(), null, 'errors');
683  }
684  } elseif ($action == 'deletecard' && $source)
685  {
686  try {
687  if (preg_match('/pm_/', $source))
688  {
689  $payment_method = \Stripe\PaymentMethod::retrieve($source, array("stripe_account" => $stripeacc));
690  if ($payment_method)
691  {
692  $payment_method->detach();
693  }
694  } else {
695  $cu = $stripe->customerStripe($object, $stripeacc, $servicestatus);
696  $card = $cu->sources->retrieve("$source");
697  if ($card) {
698  // $card->detach(); Does not work with card_, only with src_
699  if (method_exists($card, 'detach')) {
700  $card->detach();
701  } else {
702  $card->delete();
703  }
704  }
705  }
706 
707  $url = DOL_URL_ROOT.'/societe/paymentmodes.php?socid='.$object->id;
708  header('Location: '.$url);
709  exit;
710  } catch (Exception $e)
711  {
712  $error++;
713  setEventMessages($e->getMessage(), null, 'errors');
714  }
715  }
716  }
717 }
718 
719 
720 
721 /*
722  * View
723  */
724 
725 $form = new Form($db);
726 $formother = new FormOther($db);
727 $formfile = new FormFile($db);
728 
729 llxHeader();
730 
731 $head = societe_prepare_head($object);
732 
733 // Show sandbox warning
734 /*if (! empty($conf->paypal->enabled) && (! empty($conf->global->PAYPAL_API_SANDBOX) || GETPOST('forcesandbox','alpha'))) // We can force sand box with param 'forcesandbox'
735 {
736  dol_htmloutput_mesg($langs->trans('YouAreCurrentlyInSandboxMode','Paypal'),'','warning');
737 }*/
738 if (!empty($conf->stripe->enabled) && (empty($conf->global->STRIPE_LIVE) || GETPOST('forcesandbox', 'alpha')))
739 {
740  dol_htmloutput_mesg($langs->trans('YouAreCurrentlyInSandboxMode', 'Stripe'), '', 'warning');
741 }
742 
743 // Load Bank account
744 if (!$id)
745 {
746  $companybankaccount->fetch(0, $object->id);
747  $companypaymentmode->fetch(0, null, $object->id, 'card');
748 } else {
749  $companybankaccount->fetch($id);
750  $companypaymentmode->fetch($id);
751 }
752 if (empty($companybankaccount->socid)) $companybankaccount->socid = $object->id;
753 
754 if ($socid && ($action == 'edit' || $action == 'editcard') && $user->rights->societe->creer)
755 {
756  print '<form action="'.$_SERVER["PHP_SELF"].'?socid='.$object->id.'" method="post">';
757  print '<input type="hidden" name="token" value="'.newToken().'">';
758  $actionforadd = 'update';
759  if ($action == 'editcard') $actionforadd = 'updatecard';
760  print '<input type="hidden" name="action" value="'.$actionforadd.'">';
761  print '<input type="hidden" name="id" value="'.GETPOST("id", "int").'">';
762 }
763 if ($socid && ($action == 'create' || $action == 'createcard') && $user->rights->societe->creer)
764 {
765  print '<form action="'.$_SERVER["PHP_SELF"].'?socid='.$object->id.'" method="post">';
766  print '<input type="hidden" name="token" value="'.newToken().'">';
767  $actionforadd = 'add';
768  if ($action == 'createcard') $actionforadd = 'addcard';
769  print '<input type="hidden" name="action" value="'.$actionforadd.'">';
770 }
771 
772 
773 // View
774 if ($socid && $action != 'edit' && $action != 'create' && $action != 'editcard' && $action != 'createcard')
775 {
776  print dol_get_fiche_head($head, 'rib', $langs->trans("ThirdParty"), -1, 'company');
777 
778  // Confirm delete ban
779  if ($action == 'delete')
780  {
781  print $form->formconfirm($_SERVER["PHP_SELF"]."?socid=".$object->id."&ribid=".($ribid ? $ribid : $id), $langs->trans("DeleteARib"), $langs->trans("ConfirmDeleteRib", $companybankaccount->getRibLabel()), "confirm_delete", '', 0, 1);
782  }
783  // Confirm delete card
784  if ($action == 'deletecard')
785  {
786  print $form->formconfirm($_SERVER["PHP_SELF"]."?socid=".$object->id."&ribid=".($ribid ? $ribid : $id), $langs->trans("DeleteACard"), $langs->trans("ConfirmDeleteCard", $companybankaccount->getRibLabel()), "confirm_deletecard", '', 0, 1);
787  }
788 
789  $linkback = '<a href="'.DOL_URL_ROOT.'/societe/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
790 
791  dol_banner_tab($object, 'socid', $linkback, ($user->socid ? 0 : 1), 'rowid', 'nom');
792 
793 
794  if (!empty($conf->global->SOCIETE_USEPREFIX)) // Old not used prefix field
795  {
796  print '<tr><td class="titlefield">'.$langs->trans('Prefix').'</td><td colspan="3">'.$object->prefix_comm.'</td></tr>';
797  }
798 
799  //if ($conf->agenda->enabled && $user->rights->agenda->myactions->read) $elementTypeArray['action']=$langs->transnoentitiesnoconv('Events');
800 
801  print '<div class="fichecenter">';
802 
803  print '<div class="underbanner clearboth"></div>';
804  print '<table class="border tableforfield centpercent">';
805 
806  if ($object->client)
807  {
808  print '<tr><td class="titlefield">';
809  print $langs->trans('CustomerCode').'</td><td colspan="2">';
810  print $object->code_client;
811  $tmpcheck = $object->check_codeclient();
812  if ($tmpcheck != 0 && $tmpcheck != -5) {
813  print ' <font class="error">('.$langs->trans("WrongCustomerCode").')</font>';
814  }
815  print '</td></tr>';
816  $sql = "SELECT count(*) as nb from ".MAIN_DB_PREFIX."facture where fk_soc = ".$socid;
817  $resql = $db->query($sql);
818  if (!$resql) dol_print_error($db);
819 
820  $obj = $db->fetch_object($resql);
821  $nbFactsClient = $obj->nb;
822  $thirdTypeArray['customer'] = $langs->trans("customer");
823  if ($conf->propal->enabled && $user->rights->propal->lire) $elementTypeArray['propal'] = $langs->transnoentitiesnoconv('Proposals');
824  if ($conf->commande->enabled && $user->rights->commande->lire) $elementTypeArray['order'] = $langs->transnoentitiesnoconv('Orders');
825  if ($conf->facture->enabled && $user->rights->facture->lire) $elementTypeArray['invoice'] = $langs->transnoentitiesnoconv('Invoices');
826  if ($conf->contrat->enabled && $user->rights->contrat->lire) $elementTypeArray['contract'] = $langs->transnoentitiesnoconv('Contracts');
827 
828  if (!empty($conf->stripe->enabled))
829  {
830  $permissiontowrite = $user->rights->societe->creer;
831  // Stripe customer key 'cu_....' stored into llx_societe_account
832  print '<tr><td class="titlefield">';
833  print $form->editfieldkey("StripeCustomerId", 'key_account', $stripecu, $object, $permissiontowrite, 'string', '', 0, 2, 'socid');
834  print '</td><td>';
835  print $form->editfieldval("StripeCustomerId", 'key_account', $stripecu, $object, $permissiontowrite, 'string', '', null, null, '', 2, '', 'socid');
836  if (!empty($conf->stripe->enabled) && $stripecu && $action != 'editkey_account')
837  {
838  $connect = '';
839  if (!empty($stripeacc)) $connect = $stripeacc.'/';
840  $url = 'https://dashboard.stripe.com/'.$connect.'test/customers/'.$stripecu;
841  if ($servicestatus)
842  {
843  $url = 'https://dashboard.stripe.com/'.$connect.'customers/'.$stripecu;
844  }
845  print ' <a href="'.$url.'" target="_stripe">'.img_picto($langs->trans('ShowInStripe').' - Publishable key = '.$site_account, 'globe').'</a>';
846  }
847  print '</td><td class="right">';
848  if (empty($stripecu))
849  {
850  print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">';
851  print '<input type="hidden" name="action" value="synccustomertostripe">';
852  print '<input type="hidden" name="token" value="'.newToken().'">';
853  print '<input type="hidden" name="socid" value="'.$object->id.'">';
854  print '<input type="submit" class="button buttongen" name="syncstripecustomer" value="'.$langs->trans("CreateCustomerOnStripe").'">';
855  print '</form>';
856  }
857  print '</td></tr>';
858  }
859  }
860 
861  if ($object->fournisseur)
862  {
863  print '<tr><td class="titlefield">';
864  print $langs->trans('SupplierCode').'</td><td colspan="2">';
865  print $object->code_fournisseur;
866  $tmpcheck = $object->check_codefournisseur();
867  if ($tmpcheck != 0 && $tmpcheck != -5) {
868  print ' <font class="error">('.$langs->trans("WrongSupplierCode").')</font>';
869  }
870  print '</td></tr>';
871  $sql = "SELECT count(*) as nb from ".MAIN_DB_PREFIX."facture where fk_soc = ".$socid;
872  $resql = $db->query($sql);
873  if (!$resql) dol_print_error($db);
874  $obj = $db->fetch_object($resql);
875  $nbFactsClient = $obj->nb;
876  $thirdTypeArray['customer'] = $langs->trans("customer");
877  if ($conf->propal->enabled && $user->rights->propal->lire) $elementTypeArray['propal'] = $langs->transnoentitiesnoconv('Proposals');
878  if ($conf->commande->enabled && $user->rights->commande->lire) $elementTypeArray['order'] = $langs->transnoentitiesnoconv('Orders');
879  if ($conf->facture->enabled && $user->rights->facture->lire) $elementTypeArray['invoice'] = $langs->transnoentitiesnoconv('Invoices');
880  if ($conf->contrat->enabled && $user->rights->contrat->lire) $elementTypeArray['contract'] = $langs->transnoentitiesnoconv('Contracts');
881  }
882 
883  if (!empty($conf->stripe->enabled) && !empty($conf->stripeconnect->enabled) && $conf->global->MAIN_FEATURES_LEVEL >= 2)
884  {
885  $permissiontowrite = $user->rights->societe->creer;
886  $stripesupplieracc = $stripe->getStripeAccount($service, $object->id); // Get Stripe OAuth connect account (no network access here)
887 
888  // Stripe customer key 'cu_....' stored into llx_societe_account
889  print '<tr><td class="titlefield">';
890  print $form->editfieldkey("StripeConnectAccount", 'key_account_supplier', $stripesupplieracc, $object, $permissiontowrite, 'string', '', 0, 2, 'socid');
891  print '</td><td>';
892  print $form->editfieldval("StripeConnectAccount", 'key_account_supplier', $stripesupplieracc, $object, $permissiontowrite, 'string', '', null, null, '', 2, '', 'socid');
893  if (!empty($conf->stripe->enabled) && $stripesupplieracc && $action != 'editkey_account_supplier')
894  {
895  $connect = '';
896 
897  $url = 'https://dashboard.stripe.com/test/connect/accounts/'.$stripesupplieracc;
898  if ($servicestatus)
899  {
900  $url = 'https://dashboard.stripe.com/connect/accounts/'.$stripesupplieracc;
901  }
902  print ' <a href="'.$url.'" target="_stripe">'.img_picto($langs->trans('ShowInStripe').' - Publishable key '.$site_account, 'globe').'</a>';
903  }
904  print '</td><td class="right">';
905  if (empty($stripesupplieracc))
906  {
907  print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">';
908  print '<input type="hidden" name="action" value="syncsuppliertostripe">';
909  print '<input type="hidden" name="token" value="'.newToken().'">';
910  print '<input type="hidden" name="socid" value="'.$object->id.'">';
911  print '<input type="hidden" name="companybankid" value="'.$rib->id.'">';
912  //print '<input type="submit" class="button buttongen" name="syncstripecustomer" value="'.$langs->trans("CreateSupplierOnStripe").'">';
913  print '</form>';
914  }
915  print '</td></tr>';
916  }
917 
918  print '</table>';
919  print '</div>';
920 
922 
923  print '<br>';
924 
925  // List of Stripe payment modes
926  if (!(empty($conf->stripe->enabled)) && $object->client)
927  {
928  $morehtmlright = '';
929  if (!empty($conf->global->STRIPE_ALLOW_LOCAL_CARD))
930  {
931  $morehtmlright .= dolGetButtonTitle($langs->trans('Add'), '', 'fa fa-plus-circle', $_SERVER["PHP_SELF"].'?socid='.$object->id.'&amp;action=createcard');
932  }
933  print load_fiche_titre($langs->trans('StripePaymentModes').($stripeacc ? ' (Stripe connection with StripeConnect account '.$stripeacc.')' : ' (Stripe connection with keys from Stripe module setup)'), $morehtmlright, 'stripe-s');
934 
935  $listofsources = array();
936  if (is_object($stripe))
937  {
938  try {
939  $customerstripe = $stripe->customerStripe($object, $stripeacc, $servicestatus);
940  if ($customerstripe->id) {
941  // When using the Charge API architecture
942  if (empty($conf->global->STRIPE_USE_INTENT_WITH_AUTOMATIC_CONFIRMATION))
943  {
944  $listofsources = $customerstripe->sources->data;
945  } else {
946  $service = 'StripeTest';
947  $servicestatus = 0;
948  if (!empty($conf->global->STRIPE_LIVE) && !GETPOST('forcesandbox', 'alpha'))
949  {
950  $service = 'StripeLive';
951  $servicestatus = 1;
952  }
953 
954  // Force to use the correct API key
955  global $stripearrayofkeysbyenv;
956  \Stripe\Stripe::setApiKey($stripearrayofkeysbyenv[$servicestatus]['secret_key']);
957 
958  try {
959  if (empty($stripeacc)) { // If the Stripe connect account not set, we use common API usage
960  $paymentmethodobjs = \Stripe\PaymentMethod::all(array("customer" => $customerstripe->id, "type" => "card"));
961  } else {
962  $paymentmethodobjs = \Stripe\PaymentMethod::all(array("customer" => $customerstripe->id, "type" => "card"), array("stripe_account" => $stripeacc));
963  }
964 
965  $listofsources = $paymentmethodobjs->data;
966  } catch (Exception $e)
967  {
968  $error++;
969  setEventMessages($e->getMessage(), null, 'errors');
970  }
971  }
972  }
973  } catch (Exception $e)
974  {
975  dol_syslog("Error when searching/loading Stripe customer for thirdparty id =".$object->id);
976  }
977  }
978 
979  print '<!-- List of stripe payments -->'."\n";
980  print '<div class="div-table-responsive-no-min">'; // You can use div-table-responsive-no-min if you dont need reserved height for your table
981  print '<table class="liste centpercent">'."\n";
982  print '<tr class="liste_titre">';
983  if (!empty($conf->global->STRIPE_ALLOW_LOCAL_CARD))
984  {
985  print '<td>'.$langs->trans('LocalID').'</td>';
986  }
987  print '<td>'.$langs->trans('Label').'</td>';
988  print '<td>'.$langs->trans('StripeID').'</td>';
989  print '<td>'.$langs->trans('Type').'</td>';
990  print '<td>'.$langs->trans('Informations').'</td>';
991  print '<td></td>';
992  print '<td class="center">'.$langs->trans('Default').'</td>';
993  print '<td>'.$langs->trans('Note').'</td>';
994  print '<td>'.$langs->trans('DateModification').'</td>';
995  // Hook fields
996  $parameters = array('arrayfields'=>array(), 'param'=>'', 'sortfield'=>'', 'sortorder'=>'', 'linetype'=>'stripetitle');
997  $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters, $object); // Note that $action and $object may have been modified by hook
998  print $hookmanager->resPrint;
999  // Action column
1000  print "<td></td>";
1001  print "</tr>\n";
1002 
1003  $nbremote = 0;
1004  $nblocal = 0;
1005  $arrayofstripecard = array();
1006 
1007  // Show local sources
1008  if (!empty($conf->global->STRIPE_ALLOW_LOCAL_CARD))
1009  {
1010  //$societeaccount = new SocieteAccount($db);
1011  $companypaymentmodetemp = new CompanyPaymentMode($db);
1012 
1013  $sql = 'SELECT rowid FROM '.MAIN_DB_PREFIX."societe_rib";
1014  $sql .= " WHERE type in ('card')";
1015  $sql .= " AND fk_soc = ".$object->id;
1016  $sql .= " AND status = ".$servicestatus;
1017 
1018  $resql = $db->query($sql);
1019  if ($resql)
1020  {
1021  $num_rows = $db->num_rows($resql);
1022  if ($num_rows)
1023  {
1024  $i = 0;
1025  while ($i < $num_rows)
1026  {
1027  $nblocal++;
1028 
1029  $obj = $db->fetch_object($resql);
1030  if ($obj)
1031  {
1032  $companypaymentmodetemp->fetch($obj->rowid);
1033 
1034  $arrayofstripecard[$companypaymentmodetemp->stripe_card_ref] = $companypaymentmodetemp->stripe_card_ref;
1035 
1036  print '<tr class="oddeven">';
1037  print '<td>';
1038  print $companypaymentmodetemp->id;
1039  print '</td>';
1040  print '<td>';
1041  print $companypaymentmodetemp->label;
1042  print '</td>';
1043  print '<td>';
1044  print $companypaymentmodetemp->stripe_card_ref;
1045  if ($companypaymentmodetemp->stripe_card_ref)
1046  {
1047  $connect = '';
1048  if (!empty($stripeacc)) $connect = $stripeacc.'/';
1049  $url = 'https://dashboard.stripe.com/'.$connect.'test/search?query='.$companypaymentmodetemp->stripe_card_ref;
1050  if ($servicestatus)
1051  {
1052  $url = 'https://dashboard.stripe.com/'.$connect.'search?query='.$companypaymentmodetemp->stripe_card_ref;
1053  }
1054  print ' <a href="'.$url.'" target="_stripe">'.img_picto($langs->trans('ShowInStripe').' - Customer and Publishable key = '.$companypaymentmodetemp->stripe_account, 'globe').'</a>';
1055  }
1056  print '</td>';
1057  print '<td>';
1058  print img_credit_card($companypaymentmodetemp->type);
1059  print '</td>';
1060  print '<td>';
1061  if ($companypaymentmodetemp->proprio) print '<span class="opacitymedium">'.$companypaymentmodetemp->proprio.'</span><br>';
1062  if ($companypaymentmodetemp->last_four) print '....'.$companypaymentmodetemp->last_four;
1063  if ($companypaymentmodetemp->exp_date_month || $companypaymentmodetemp->exp_date_year) print ' - '.sprintf("%02d", $companypaymentmodetemp->exp_date_month).'/'.$companypaymentmodetemp->exp_date_year.'';
1064  print '</td><td>';
1065  if ($companypaymentmodetemp->country_code)
1066  {
1067  $img = picto_from_langcode($companypaymentmodetemp->country_code);
1068  print $img ? $img.' ' : '';
1069  print getCountry($companypaymentmodetemp->country_code, 1);
1070  } else print img_warning().' <font class="error">'.$langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("CompanyCountry")).'</font>';
1071  print '</td>';
1072  // Default
1073  print '<td class="center">';
1074  if (empty($companypaymentmodetemp->default_rib))
1075  {
1076  print '<a href="'.DOL_URL_ROOT.'/societe/paymentmodes.php?socid='.$object->id.'&id='.$companypaymentmodetemp->id.'&action=setlocalassourcedefault&token='.newToken().'">';
1077  print img_picto($langs->trans("Default"), 'off');
1078  print '</a>';
1079  } else {
1080  print img_picto($langs->trans("Default"), 'on');
1081  }
1082  print '</td>';
1083  print '<td>';
1084  if (empty($companypaymentmodetemp->stripe_card_ref)) print $langs->trans("Local");
1085  else print $langs->trans("LocalAndRemote");
1086  print '</td>';
1087  print '<td>';
1088  print dol_print_date($companypaymentmodetemp->tms, 'dayhour');
1089  print '</td>';
1090  // Fields from hook
1091  $parameters = array('arrayfields'=>array(), 'obj'=>$obj, 'linetype'=>'stripecard');
1092  $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters, $object); // Note that $action and $object may have been modified by hook
1093  print $hookmanager->resPrint;
1094  // Action column
1095  print '<td class="right nowraponall">';
1096  if ($user->rights->societe->creer)
1097  {
1098  if ($stripecu && empty($companypaymentmodetemp->stripe_card_ref))
1099  {
1100  print '<a href="'.$_SERVER['PHP_SELF'].'?action=synccardtostripe&socid='.$object->id.'&id='.$companypaymentmodetemp->id.'" class="paddingrightonly marginrightonly">'.$langs->trans("CreateCardOnStripe").'</a>';
1101  }
1102 
1103  print '<a class="editfielda marginleftonly marginrightonly" href="'.DOL_URL_ROOT.'/societe/paymentmodes.php?socid='.$object->id.'&id='.$companypaymentmodetemp->id.'&action=editcard&token='.newToken().'">';
1104  print img_picto($langs->trans("Modify"), 'edit');
1105  print '</a>';
1106  print '&nbsp;';
1107  print '<a class="marginleftonly marginrightonly" href="'.DOL_URL_ROOT.'/societe/paymentmodes.php?socid='.$object->id.'&id='.$companypaymentmodetemp->id.'&action=deletecard&token='.newToken().'">'; // source='.$companypaymentmodetemp->stripe_card_ref.'&
1108  print img_picto($langs->trans("Delete"), 'delete');
1109  print '</a>';
1110  }
1111  print '</td>';
1112  print '</tr>';
1113  }
1114  $i++;
1115  }
1116  }
1117  } else dol_print_error($db);
1118  }
1119 
1120  // Show remote sources (not already shown as local source)
1121  if (is_array($listofsources) && count($listofsources))
1122  {
1123  foreach ($listofsources as $src)
1124  {
1125  if (!empty($arrayofstripecard[$src->id])) continue; // Already in previous list
1126 
1127  $nbremote++;
1128 
1129  print '<tr class="oddeven">';
1130  // Local ID
1131  if (!empty($conf->global->STRIPE_ALLOW_LOCAL_CARD))
1132  {
1133  print '<td>';
1134  print '</td>';
1135  }
1136  print '<td>';
1137  print '</td>';
1138  // Src ID
1139  print '<td>';
1140  $connect = '';
1141  print $src->id;
1142  if (!empty($stripeacc)) $connect = $stripeacc.'/';
1143  //$url='https://dashboard.stripe.com/'.$connect.'test/sources/'.$src->id;
1144  $url = 'https://dashboard.stripe.com/'.$connect.'test/search?query='.$src->id;
1145  if ($servicestatus)
1146  {
1147  //$url='https://dashboard.stripe.com/'.$connect.'sources/'.$src->id;
1148  $url = 'https://dashboard.stripe.com/'.$connect.'search?query='.$src->id;
1149  }
1150  print " <a href='".$url."' target='_stripe'>".img_picto($langs->trans('ShowInStripe'), 'globe')."</a>";
1151  print '</td>';
1152  // Img of credit card
1153  print '<td>';
1154  if ($src->object == 'card')
1155  {
1156  print img_credit_card($src->brand);
1157  } elseif ($src->object == 'source' && $src->type == 'card')
1158  {
1159  print img_credit_card($src->card->brand);
1160  } elseif ($src->object == 'source' && $src->type == 'sepa_debit')
1161  {
1162  print '<span class="fa fa-university fa-2x fa-fw"></span>';
1163  } elseif ($src->object == 'payment_method' && $src->type == 'card')
1164  {
1165  print img_credit_card($src->card->brand);
1166  } elseif ($src->object == 'payment_method' && $src->type == 'sepa_debit')
1167  {
1168  print '<span class="fa fa-university fa-2x fa-fw"></span>';
1169  }
1170  print'</td>';
1171  // Information
1172  print '<td valign="middle">';
1173  if ($src->object == 'card')
1174  {
1175  print '....'.$src->last4.' - '.$src->exp_month.'/'.$src->exp_year.'';
1176  print '</td><td>';
1177  if ($src->country)
1178  {
1179  $img = picto_from_langcode($src->country);
1180  print $img ? $img.' ' : '';
1181  print getCountry($src->country, 1);
1182  } else print img_warning().' <font class="error">'.$langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("CompanyCountry")).'</font>';
1183  } elseif ($src->object == 'source' && $src->type == 'card')
1184  {
1185  print '<span class="opacitymedium">'.$src->owner->name.'</span><br>....'.$src->card->last4.' - '.$src->card->exp_month.'/'.$src->card->exp_year.'';
1186  print '</td><td>';
1187 
1188  if ($src->card->country)
1189  {
1190  $img = picto_from_langcode($src->card->country);
1191  print $img ? $img.' ' : '';
1192  print getCountry($src->card->country, 1);
1193  } else print img_warning().' <font class="error">'.$langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("CompanyCountry")).'</font>';
1194  } elseif ($src->object == 'source' && $src->type == 'sepa_debit')
1195  {
1196  print 'SEPA debit';
1197  print '</td><td>';
1198  if ($src->sepa_debit->country)
1199  {
1200  $img = picto_from_langcode($src->sepa_debit->country);
1201  print $img ? $img.' ' : '';
1202  print getCountry($src->sepa_debit->country, 1);
1203  } else print img_warning().' <font class="error">'.$langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("CompanyCountry")).'</font>';
1204  } elseif ($src->object == 'payment_method' && $src->type == 'card')
1205  {
1206  print '<span class="opacitymedium">'.$src->billing_details->name.'</span><br>....'.$src->card->last4.' - '.$src->card->exp_month.'/'.$src->card->exp_year.'';
1207  print '</td><td>';
1208 
1209  if ($src->card->country)
1210  {
1211  $img = picto_from_langcode($src->card->country);
1212  print $img ? $img.' ' : '';
1213  print getCountry($src->card->country, 1);
1214  } else print img_warning().' <font class="error">'.$langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("CompanyCountry")).'</font>';
1215  } elseif ($src->object == 'payment_method' && $src->type == 'sepa_debit')
1216  {
1217  print 'SEPA debit';
1218  print '</td><td>';
1219  if ($src->sepa_debit->country)
1220  {
1221  $img = picto_from_langcode($src->sepa_debit->country);
1222  print $img ? $img.' ' : '';
1223  print getCountry($src->sepa_debit->country, 1);
1224  } else print img_warning().' <font class="error">'.$langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("CompanyCountry")).'</font>';
1225  } else {
1226  print '</td><td>';
1227  }
1228  print '</td>';
1229  // Default
1230  print '<td class="center" width="50">';
1231  if ((empty($customerstripe->invoice_settings) && $customerstripe->default_source != $src->id) ||
1232  (!empty($customerstripe->invoice_settings) && $customerstripe->invoice_settings->default_payment_method != $src->id))
1233  {
1234  print '<a href="'.DOL_URL_ROOT.'/societe/paymentmodes.php?socid='.$object->id.'&source='.$src->id.'&action=setassourcedefault&token='.newToken().'">';
1235  print img_picto($langs->trans("Default"), 'off');
1236  print '</a>';
1237  } else {
1238  print img_picto($langs->trans("Default"), 'on');
1239  }
1240  print '</td>';
1241  print '<td>';
1242  print $langs->trans("Remote");
1243  //if ($src->cvc_check == 'fail') print ' - CVC check fail';
1244  print '</td>';
1245  print '<td>';
1246  //var_dump($src);
1247  print '';
1248  print '</td>';
1249  // Fields from hook
1250  $parameters = array('arrayfields'=>array(), 'stripesource'=>$src, 'linetype'=>'stripecardremoteonly');
1251  $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters, $object); // Note that $action and $object may have been modified by hook
1252  print $hookmanager->resPrint;
1253  // Action column
1254  print '<td class="right nowraponall">';
1255  if ($user->rights->societe->creer)
1256  {
1257  print '<a href="'.DOL_URL_ROOT.'/societe/paymentmodes.php?socid='.$object->id.'&source='.$src->id.'&action=deletecard&token='.newToken().'">';
1258  print img_picto($langs->trans("Delete"), 'delete');
1259  print '</a>';
1260  }
1261  print '</td>';
1262 
1263  print '</tr>';
1264  }
1265  }
1266 
1267  if ($nbremote == 0 && $nblocal == 0)
1268  {
1269  $colspan = 8;
1270  if (!empty($conf->global->STRIPE_ALLOW_LOCAL_CARD)) $colspan++;
1271  print '<tr><td class="opacitymedium" colspan="'.$colspan.'">'.$langs->trans("None").'</td></tr>';
1272  }
1273  print "</table>";
1274  print "</div>";
1275  print '<br>';
1276  }
1277 
1278  // List of Stripe payment modes
1279  if (!empty($conf->stripe->enabled) && !empty($conf->stripeconnect->enabled) && !empty($stripesupplieracc))
1280  {
1281  print load_fiche_titre($langs->trans('StripeBalance').($stripesupplieracc ? ' (Stripe connection with StripeConnect account '.$stripesupplieracc.')' : ' (Stripe connection with keys from Stripe module setup)'), $morehtmlright, 'stripe-s');
1282  $balance = \Stripe\Balance::retrieve(array("stripe_account" => $stripesupplieracc));
1283  print '<table class="liste centpercent">'."\n";
1284  print '<tr class="liste_titre">';
1285  print '<td>'.$langs->trans('Currency').'</td>';
1286  print '<td>'.$langs->trans('Available').'</td>';
1287  print '<td>'.$langs->trans('Pending').'</td>';
1288  print '<td>'.$langs->trans('Total').'</td>';
1289  print '</tr>';
1290 
1291  $currencybalance = array();
1292  if (is_array($balance->available) && count($balance->available))
1293  {
1294  foreach ($balance->available as $cpt)
1295  {
1296  $arrayzerounitcurrency = array('BIF', 'CLP', 'DJF', 'GNF', 'JPY', 'KMF', 'KRW', 'MGA', 'PYG', 'RWF', 'VND', 'VUV', 'XAF', 'XOF', 'XPF');
1297  if (!in_array($cpt->currency, $arrayzerounitcurrency)) {
1298  $currencybalance[$cpt->currency]['available'] = $cpt->amount / 100;
1299  } else {
1300  $currencybalance[$cpt->currency]['available'] = $cpt->amount;
1301  }
1302  $currencybalance[$cpt->currency]['currency'] = $cpt->currency;
1303  }
1304  }
1305 
1306  if (is_array($balance->pending) && count($balance->pending))
1307  {
1308  foreach ($balance->pending as $cpt)
1309  {
1310  $arrayzerounitcurrency = array('BIF', 'CLP', 'DJF', 'GNF', 'JPY', 'KMF', 'KRW', 'MGA', 'PYG', 'RWF', 'VND', 'VUV', 'XAF', 'XOF', 'XPF');
1311  if (!in_array($cpt->currency, $arrayzerounitcurrency)) {
1312  $currencybalance[$cpt->currency]['pending'] = $currencybalance[$cpt->currency]['available'] + $cpt->amount / 100;
1313  } else {
1314  $currencybalance[$cpt->currency]['pending'] = $currencybalance[$cpt->currency]['available'] + $cpt->amount;
1315  }
1316  }
1317  }
1318 
1319  if (is_array($currencybalance))
1320  {
1321  foreach ($currencybalance as $cpt)
1322  {
1323  print '<tr><td>'.$langs->trans("Currency".strtoupper($cpt['currency'])).'</td><td>'.price($cpt['available'], 0, '', 1, - 1, - 1, strtoupper($cpt['currency'])).'</td><td>'.price($cpt->pending, 0, '', 1, - 1, - 1, strtoupper($cpt['currency'])).'</td><td>'.price($cpt['available'] + $cpt->pending, 0, '', 1, - 1, - 1, strtoupper($cpt['currency'])).'</td></tr>';
1324  }
1325  }
1326 
1327  print '</table>';
1328  print '<br>';
1329  }
1330 
1331  // List of bank accounts
1332 
1333  $morehtmlright = dolGetButtonTitle($langs->trans('Add'), '', 'fa fa-plus-circle', $_SERVER["PHP_SELF"].'?socid='.$object->id.'&amp;action=create');
1334 
1335  print load_fiche_titre($langs->trans("BankAccounts"), $morehtmlright, 'bank');
1336 
1337  $rib_list = $object->get_all_rib();
1338  if (is_array($rib_list))
1339  {
1340  print '<div class="div-table-responsive-no-min">'; // You can use div-table-responsive-no-min if you dont need reserved height for your table
1341  print '<table class="liste centpercent">';
1342 
1343  print '<tr class="liste_titre">';
1344  print_liste_field_titre("LabelRIB");
1345  print_liste_field_titre("Bank");
1346  print_liste_field_titre("RIB");
1347  print_liste_field_titre("IBAN");
1348  print_liste_field_titre("BIC");
1349  if (!empty($conf->prelevement->enabled))
1350  {
1351  print_liste_field_titre("RUM");
1352  print_liste_field_titre("DateRUM");
1353  print_liste_field_titre("WithdrawMode");
1354  }
1355  print_liste_field_titre("DefaultRIB", '', '', '', '', '', '', '', 'center ');
1356  print_liste_field_titre('', '', '', '', '', '', '', '', 'center ');
1357  print_liste_field_titre('', $_SERVER["PHP_SELF"], "", '', '', '', $sortfield, $sortorder, 'maxwidthsearch ');
1358  print "</tr>\n";
1359 
1360  foreach ($rib_list as $rib)
1361  {
1362  print '<tr class="oddeven">';
1363  // Label
1364  print '<td>'.$rib->label.'</td>';
1365  // Bank name
1366  print '<td>'.$rib->bank.'</td>';
1367  // Account number
1368  print '<td>';
1369  $string = '';
1370  foreach ($rib->getFieldsToShow() as $val) {
1371  if ($val == 'BankCode') {
1372  $string .= $rib->code_banque.' ';
1373  } elseif ($val == 'BankAccountNumber') {
1374  $string .= $rib->number.' ';
1375  } elseif ($val == 'DeskCode') {
1376  $string .= $rib->code_guichet.' ';
1377  } elseif ($val == 'BankAccountNumberKey') {
1378  $string .= $rib->cle_rib.' ';
1379  }
1380  // Already output after
1381  // } elseif ($val == 'BIC') {
1382  // $string .= $rib->bic.' ';
1383  // } elseif ($val == 'IBAN') {
1384  // $string .= $rib->iban.' ';*/
1385  //}
1386  }
1387  if (!empty($rib->label) && $rib->number) {
1388  if (!checkBanForAccount($rib)) {
1389  $string .= ' '.img_picto($langs->trans("ValueIsNotValid"), 'warning');
1390  } else {
1391  $string .= ' '.img_picto($langs->trans("ValueIsValid"), 'info');
1392  }
1393  }
1394 
1395  print $string;
1396  print '</td>';
1397  // IBAN
1398  print '<td>'.$rib->iban;
1399  if (!empty($rib->iban)) {
1400  if (!checkIbanForAccount($rib)) {
1401  print ' '.img_picto($langs->trans("IbanNotValid"), 'warning');
1402  }
1403  }
1404  print '</td>';
1405  // BIC
1406  print '<td>'.$rib->bic;
1407  if (!empty($rib->bic)) {
1408  if (!checkSwiftForAccount($rib)) {
1409  print ' '.img_picto($langs->trans("SwiftNotValid"), 'warning');
1410  }
1411  }
1412  print '</td>';
1413 
1414  if (!empty($conf->prelevement->enabled))
1415  {
1416  // RUM
1417  //print '<td>'.$prelevement->buildRumNumber($object->code_client, $rib->datec, $rib->id).'</td>';
1418  print '<td>'.$rib->rum.'</td>';
1419 
1420  print '<td>'.dol_print_date($rib->date_rum, 'day').'</td>';
1421 
1422  // FRSTRECUR
1423  print '<td>'.$rib->frstrecur.'</td>';
1424  }
1425 
1426  // Default
1427  print '<td class="center" width="70">';
1428  if (!$rib->default_rib) {
1429  print '<a href="'.$_SERVER["PHP_SELF"].'?socid='.$object->id.'&ribid='.$rib->id.'&action=setasbankdefault&token='.newToken().'">';
1430  print img_picto($langs->trans("Disabled"), 'off');
1431  print '</a>';
1432  } else {
1433  print img_picto($langs->trans("Enabled"), 'on');
1434  }
1435  print '</td>';
1436 
1437  // Generate doc
1438  print '<td class="center">';
1439 
1440  $buttonlabel = $langs->trans("BuildDoc");
1441  $forname = 'builddocrib'.$rib->id;
1442 
1443  include_once DOL_DOCUMENT_ROOT.'/core/modules/bank/modules_bank.php';
1444  $modellist = ModeleBankAccountDoc::liste_modeles($db);
1445 
1446  $out = '';
1447  if (is_array($modellist) && count($modellist))
1448  {
1449  $out .= '<form action="'.$urlsource.(empty($conf->global->MAIN_JUMP_TAG) ? '' : '#builddoc').'" name="'.$forname.'" id="'.$forname.'_form" method="post">';
1450  $out .= '<input type="hidden" name="action" value="builddocrib">';
1451  $out .= '<input type="hidden" name="token" value="'.newToken().'">';
1452  $out .= '<input type="hidden" name="socid" value="'.$object->id.'">';
1453  $out .= '<input type="hidden" name="companybankid" value="'.$rib->id.'">';
1454 
1455  if (is_array($modellist) && count($modellist) == 1) // If there is only one element
1456  {
1457  $arraykeys = array_keys($modellist);
1458  $modelselected = $arraykeys[0];
1459  }
1460  if (!empty($conf->global->BANKADDON_PDF)) $modelselected = $conf->global->BANKADDON_PDF;
1461 
1462  $out .= $form->selectarray('modelrib'.$rib->id, $modellist, $modelselected, $showempty, 0, 0, '', 0, 0, 0, '', 'minwidth100');
1463  $out .= ajax_combobox('modelrib'.$rib->id);
1464 
1465  // Language code (if multilang)
1466  if ($conf->global->MAIN_MULTILANGS)
1467  {
1468  include_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php';
1469  $formadmin = new FormAdmin($db);
1470  $defaultlang = $codelang ? $codelang : $langs->getDefaultLang();
1471  $morecss = 'maxwidth150';
1472  if ($conf->browser->layout == 'phone') $morecss = 'maxwidth100';
1473  $out .= $formadmin->select_language($defaultlang, 'lang_idrib'.$rib->id, 0, 0, 0, 0, 0, $morecss);
1474  }
1475  // Button
1476  $genbutton = '<input class="button buttongen" id="'.$forname.'_generatebutton" name="'.$forname.'_generatebutton"';
1477  $genbutton .= ' type="submit" value="'.$buttonlabel.'"';
1478  if (!$allowgenifempty && !is_array($modellist) && empty($modellist)) $genbutton .= ' disabled';
1479  $genbutton .= '>';
1480  if ($allowgenifempty && !is_array($modellist) && empty($modellist) && empty($conf->dol_no_mouse_hover) && $modulepart != 'unpaid')
1481  {
1482  $langs->load("errors");
1483  $genbutton .= ' '.img_warning($langs->transnoentitiesnoconv("WarningNoDocumentModelActivated"));
1484  }
1485  if (!$allowgenifempty && !is_array($modellist) && empty($modellist) && empty($conf->dol_no_mouse_hover) && $modulepart != 'unpaid') $genbutton = '';
1486  if (empty($modellist) && !$showempty && $modulepart != 'unpaid') $genbutton = '';
1487  $out .= $genbutton;
1488  $out .= '</form>';
1489  }
1490  print $out;
1491  print '</td>';
1492 
1493  // Edit/Delete
1494  print '<td class="right nowraponall">';
1495  if ($user->rights->societe->creer)
1496  {
1497  print '<a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?socid='.$object->id.'&id='.$rib->id.'&action=edit">';
1498  print img_picto($langs->trans("Modify"), 'edit');
1499  print '</a>';
1500 
1501  print '<a class="marginleftonly" href="'.$_SERVER["PHP_SELF"].'?socid='.$object->id.'&id='.$rib->id.'&action=delete&token='.newToken().'">';
1502  print img_picto($langs->trans("Delete"), 'delete');
1503  print '</a>';
1504  }
1505  print '</td>';
1506 
1507  print '</tr>';
1508  }
1509 
1510  if (count($rib_list) == 0)
1511  {
1512  $colspan = 9;
1513  if (!empty($conf->prelevement->enabled)) $colspan += 2;
1514  print '<tr><td colspan="'.$colspan.'" class="opacitymedium">'.$langs->trans("NoBANRecord").'</td></tr>';
1515  }
1516 
1517  print '</table>';
1518  print '</div>';
1519  } else {
1520  dol_print_error($db);
1521  }
1522 
1523 
1524  if (empty($conf->global->SOCIETE_DISABLE_BUILDDOC))
1525  {
1526  print '<br>';
1527 
1528  print '<div class="fichecenter"><div class="fichehalfleft">';
1529  print '<a name="builddoc"></a>'; // ancre
1530 
1531  /*
1532  * Documents generes
1533  */
1534  $filedir = $conf->societe->multidir_output[$object->entity].'/'.$object->id;
1535  $urlsource = $_SERVER["PHP_SELF"]."?socid=".$object->id;
1536  $genallowed = $user->rights->societe->lire;
1537  $delallowed = $user->rights->societe->creer;
1538 
1539  print $formfile->showdocuments('company', $object->id, $filedir, $urlsource, $genallowed, $delallowed, $object->model_pdf, 0, 0, 0, 28, 0, 'entity='.$object->entity, 0, '', $object->default_lang);
1540 
1541  // Show direct download link
1542  if (!empty($conf->global->BANK_ACCOUNT_ALLOW_EXTERNAL_DOWNLOAD))
1543  {
1544  $companybankaccounttemp = new CompanyBankAccount($db);
1545  $companypaymentmodetemp = new CompanyPaymentMode($db);
1546  $result = $companypaymentmodetemp->fetch(0, null, $object->id, 'ban');
1547 
1548  include_once DOL_DOCUMENT_ROOT.'/ecm/class/ecmfiles.class.php';
1549  $ecmfile = new EcmFiles($db);
1550  $result = $ecmfile->fetch(0, '', '', '', '', $companybankaccounttemp->table_element, $companypaymentmodetemp->id);
1551  if ($result > 0)
1552  {
1553  $companybankaccounttemp->last_main_doc = $ecmfile->filepath.'/'.$ecmfile->filename;
1554  print '<br><!-- Link to download main doc -->'."\n";
1555  print showDirectDownloadLink($companybankaccounttemp).'<br>';
1556  }
1557  }
1558 
1559  print '</div><div class="fichehalfright"><div class="ficheaddleft">';
1560 
1561 
1562  print '</div></div></div>';
1563 
1564  print '<br>';
1565  }
1566  /*
1567  include_once DOL_DOCUMENT_ROOT.'/core/modules/bank/modules_bank.php';
1568  $modellist=ModeleBankAccountDoc::liste_modeles($db);
1569  //print '<td>';
1570  if (is_array($modellist) && count($modellist) == 1) // If there is only one element
1571  {
1572  $arraykeys=array_keys($modellist);
1573  $modelselected=$arraykeys[0];
1574  }
1575  $out.= $form->selectarray('model', $modellist, $modelselected, 0, 0, 0, '', 0, 0, 0, '', 'minwidth100');
1576  $out.= ajax_combobox('model');
1577  //print $out;
1578  $buttonlabel=$langs->trans("Generate");
1579  $genbutton = '<input class="button buttongen" id="'.$forname.'_generatebutton" name="'.$forname.'_generatebutton"';
1580  $genbutton.= ' type="submit" value="'.$buttonlabel.'"';
1581  $genbutton.= '>';
1582  print $genbutton;
1583  //print '</td>'; // TODO Add link to generate doc
1584  */
1585 }
1586 
1587 // Edit BAN
1588 if ($socid && $action == 'edit' && $user->rights->societe->creer)
1589 {
1590  print dol_get_fiche_head($head, 'rib', $langs->trans("ThirdParty"), 0, 'company');
1591 
1592  $linkback = '<a href="'.DOL_URL_ROOT.'/societe/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
1593 
1594  dol_banner_tab($object, 'socid', $linkback, ($user->socid ? 0 : 1), 'rowid', 'nom');
1595 
1596  print '<div class="underbanner clearboth"></div>';
1597 
1598  print '<div class="div-table-responsive-no-min">';
1599  print '<table class="border centpercent">';
1600 
1601  print '<tr><td class="titlefield fieldrequired">'.$langs->trans("LabelRIB").'</td>';
1602  print '<td><input class="minwidth300" type="text" name="label" value="'.$companybankaccount->label.'"></td></tr>';
1603 
1604  print '<tr><td class="fieldrequired">'.$langs->trans("BankName").'</td>';
1605  print '<td><input class="minwidth200" type="text" name="bank" value="'.$companybankaccount->bank.'"></td></tr>';
1606 
1607  // Show fields of bank account
1608  foreach ($companybankaccount->getFieldsToShow(1) as $val) {
1609  $require = false;
1610  $tooltip = '';
1611  if ($val == 'BankCode') {
1612  $name = 'code_banque';
1613  $size = 8;
1614  $content = $companybankaccount->code_banque;
1615  } elseif ($val == 'DeskCode') {
1616  $name = 'code_guichet';
1617  $size = 8;
1618  $content = $companybankaccount->code_guichet;
1619  } elseif ($val == 'BankAccountNumber') {
1620  $name = 'number';
1621  $size = 18;
1622  $content = $companybankaccount->number;
1623  } elseif ($val == 'BankAccountNumberKey') {
1624  $name = 'cle_rib';
1625  $size = 3;
1626  $content = $companybankaccount->cle_rib;
1627  } elseif ($val == 'IBAN') {
1628  $name = 'iban';
1629  $size = 30;
1630  $content = $companybankaccount->iban;
1631  if ($companybankaccount->needIBAN()) $require = true;
1632  $tooltip = $langs->trans("Example").':<br>LT12 1000 0111 0100 1000<br>FR14 2004 1010 0505 0001 3M02 606<br>LU28 0019 4006 4475 0000<br>DE89 3704 0044 0532 0130 00';
1633  } elseif ($val == 'BIC') {
1634  $name = 'bic';
1635  $size = 12;
1636  $content = $companybankaccount->bic;
1637  if ($companybankaccount->needIBAN()) $require = true;
1638  $tooltip = $langs->trans("Example").': LIABLT2XXXX';
1639  }
1640 
1641  print '<tr><td'.($require ? ' class="fieldrequired" ' : '').'>';
1642  if ($tooltip) {
1643  print $form->textwithpicto($langs->trans($val), $tooltip, 4, 'help', '', 0, 3, $name);
1644  } else {
1645  print $langs->trans($val);
1646  }
1647  print '</td>';
1648  print '<td><input size="'.$size.'" type="text" class="flat" name="'.$name.'" value="'.$content.'"></td>';
1649  print '</tr>';
1650  }
1651 
1652  print '<tr><td>'.$langs->trans("BankAccountDomiciliation").'</td><td>';
1653  print '<textarea name="domiciliation" rows="4" cols="40" maxlength="255">';
1654  print $companybankaccount->domiciliation;
1655  print "</textarea></td></tr>";
1656 
1657  print '<tr><td>'.$langs->trans("BankAccountOwner").'</td>';
1658  print '<td><input class="minwidth300" type="text" name="proprio" value="'.$companybankaccount->proprio.'"></td></tr>';
1659  print "</td></tr>\n";
1660 
1661  print '<tr><td>'.$langs->trans("BankAccountOwnerAddress").'</td><td>';
1662  print '<textarea name="owner_address" rows="'.ROWS_4.'" cols="40" maxlength="255">';
1663  print $companybankaccount->owner_address;
1664  print "</textarea></td></tr>";
1665 
1666  print '</table>';
1667  print '</div>';
1668 
1669  if ($conf->prelevement->enabled)
1670  {
1671  print '<br>';
1672 
1673  print '<div class="div-table-responsive-no-min">';
1674  print '<table class="border centpercent">';
1675 
1676  if (empty($companybankaccount->rum)) $companybankaccount->rum = $prelevement->buildRumNumber($object->code_client, $companybankaccount->datec, $companybankaccount->id);
1677 
1678  // RUM
1679  print '<tr><td class="titlefield">'.$langs->trans("RUM").'</td>';
1680  print '<td><input class="minwidth300" type="text" name="rum" value="'.dol_escape_htmltag($companybankaccount->rum).'"></td></tr>';
1681 
1682  print '<tr><td class="titlefield">'.$langs->trans("DateRUM").'</td>';
1683  print '<td>'.$form->selectDate(GETPOST('date_rum') ?GETPOST('date_rum') : $companybankaccount->date_rum, 'date_rum', 0, 0, 1, 'date_rum').'</td></tr>';
1684 
1685  print '<tr><td>'.$langs->trans("WithdrawMode").'</td><td>';
1686  $tblArraychoice = array("FRST" => $langs->trans("FRST"), "RECUR" => $langs->trans("RECUR"));
1687  print $form->selectarray("frstrecur", $tblArraychoice, dol_escape_htmltag(GETPOST('frstrecur', 'alpha') ?GETPOST('frstrecur', 'alpha') : $companybankaccount->frstrecur), 0);
1688  print '</td></tr>';
1689 
1690  print '</table>';
1691  print '</div>';
1692  }
1693 
1694 
1695  print dol_get_fiche_end();
1696 
1697  print '<div class="center">';
1698  print '<input class="button" value="'.$langs->trans("Modify").'" type="submit">';
1699  print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
1700  print '<input class="button button-cancel" name="cancel" value="'.$langs->trans("Cancel").'" type="submit">';
1701  print '</div>';
1702 }
1703 
1704 // Edit Card
1705 if ($socid && $action == 'editcard' && $user->rights->societe->creer)
1706 {
1707  print dol_get_fiche_head($head, 'rib', $langs->trans("ThirdParty"), 0, 'company');
1708 
1709  $linkback = '<a href="'.DOL_URL_ROOT.'/societe/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
1710 
1711  dol_banner_tab($object, 'socid', $linkback, ($user->socid ? 0 : 1), 'rowid', 'nom');
1712 
1713  print '<div class="fichecenter">';
1714 
1715  print '<div class="underbanner clearboth"></div>';
1716  print '<table class="border centpercent">';
1717 
1718  print '<tr><td class="titlefieldcreate fieldrequired">'.$langs->trans("Label").'</td>';
1719  print '<td><input class="minwidth300" type="text" id="label" name="label" value="'.$companypaymentmode->label.'"></td></tr>';
1720 
1721  print '<tr><td class="fieldrequired">'.$langs->trans("NameOnCard").'</td>';
1722  print '<td><input class="minwidth200" type="text" name="proprio" value="'.$companypaymentmode->proprio.'"></td></tr>';
1723 
1724  print '<tr><td>'.$langs->trans("CardNumber").'</td>';
1725  print '<td><input class="minwidth200" type="text" name="cardnumber" value="'.$companypaymentmode->number.'"></td></tr>';
1726 
1727  print '<tr><td class="fieldrequired">'.$langs->trans("ExpiryDate").'</td>';
1728  print '<td>';
1729  print $formother->select_month($companypaymentmode->exp_date_month, 'exp_date_month', 1);
1730  print $formother->select_year($companypaymentmode->exp_date_year, 'exp_date_year', 1, 5, 10, 0, 0, '', 'marginleftonly');
1731  print '</td></tr>';
1732 
1733  print '<tr><td>'.$langs->trans("CVN").'</td>';
1734  print '<td><input size="8" type="text" name="cvn" value="'.$companypaymentmode->cvn.'"></td></tr>';
1735 
1736  print '<tr><td>'.$langs->trans("StripeID")." ('card_....')</td>";
1737  print '<td><input class="minwidth300" type="text" name="stripe_card_ref" value="'.$companypaymentmode->stripe_card_ref.'"></td></tr>';
1738 
1739  print '</table>';
1740  print '</div>';
1741 
1742  print dol_get_fiche_end();
1743 
1744  print '<div class="center">';
1745  print '<input class="button" value="'.$langs->trans("Modify").'" type="submit">';
1746  print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
1747  print '<input class="button button-cancel" name="cancel" value="'.$langs->trans("Cancel").'" type="submit">';
1748  print '</div>';
1749 }
1750 
1751 
1752 // Create BAN
1753 if ($socid && $action == 'create' && $user->rights->societe->creer)
1754 {
1755  print dol_get_fiche_head($head, 'rib', $langs->trans("ThirdParty"), 0, 'company');
1756 
1757  $linkback = '<a href="'.DOL_URL_ROOT.'/societe/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
1758 
1759  dol_banner_tab($object, 'socid', $linkback, ($user->socid ? 0 : 1), 'rowid', 'nom');
1760 
1761  print '<div class="nofichecenter">';
1762 
1763  print '<div class="underbanner clearboth"></div>';
1764  print '<table class="border centpercent">';
1765 
1766  print '<tr><td class="titlefieldcreate fieldrequired">'.$langs->trans("LabelRIB").'</td>';
1767  print '<td><input class="minwidth200" type="text" id="label" name="label" value="'.GETPOST('label').'"></td></tr>';
1768 
1769  print '<tr><td class="fieldrequired">'.$langs->trans("Bank").'</td>';
1770  print '<td><input class="minwidth200" type="text" name="bank" value="'.GETPOST('bank').'"></td></tr>';
1771 
1772  // Show fields of bank account
1773  foreach ($companybankaccount->getFieldsToShow(1) as $val) {
1774  $require = false;
1775  $tooltip = '';
1776  if ($val == 'BankCode') {
1777  $name = 'code_banque';
1778  $size = 8;
1779  $content = $companybankaccount->code_banque;
1780  } elseif ($val == 'DeskCode') {
1781  $name = 'code_guichet';
1782  $size = 8;
1783  $content = $companybankaccount->code_guichet;
1784  } elseif ($val == 'BankAccountNumber') {
1785  $name = 'number';
1786  $size = 18;
1787  $content = $companybankaccount->number;
1788  } elseif ($val == 'BankAccountNumberKey') {
1789  $name = 'cle_rib';
1790  $size = 3;
1791  $content = $companybankaccount->cle_rib;
1792  } elseif ($val == 'IBAN') {
1793  $name = 'iban';
1794  $size = 30;
1795  $content = $companybankaccount->iban;
1796  if ($companybankaccount->needIBAN()) $require = true;
1797  $tooltip = $langs->trans("Example").':<br>LT12 1000 0111 0100 1000<br>FR14 2004 1010 0505 0001 3M02 606<br>LU28 0019 4006 4475 0000<br>DE89 3704 0044 0532 0130 00';
1798  } elseif ($val == 'BIC') {
1799  $name = 'bic';
1800  $size = 12;
1801  $content = $companybankaccount->bic;
1802  if ($companybankaccount->needIBAN()) $require = true;
1803  $tooltip = $langs->trans("Example").': LIABLT2XXXX';
1804  }
1805 
1806  print '<tr><td'.($require ? ' class="fieldrequired" ' : '').'>';
1807  if ($tooltip) {
1808  print $form->textwithpicto($langs->trans($val), $tooltip, 4, 'help', '', 0, 3, $name);
1809  } else {
1810  print $langs->trans($val);
1811  }
1812  print '</td>';
1813  print '<td><input size="'.$size.'" type="text" class="flat" name="'.$name.'" value="'.GETPOST($name).'"></td>';
1814  print '</tr>';
1815  }
1816 
1817  print '<tr><td>'.$langs->trans("BankAccountDomiciliation").'</td><td>';
1818  print '<textarea name="domiciliation" rows="'.ROWS_4.'" class="quatrevingtpercent" maxlength="255">';
1819  print GETPOST('domiciliation');
1820  print "</textarea></td></tr>";
1821 
1822  print '<tr><td>'.$langs->trans("BankAccountOwner").'</td>';
1823  print '<td><input class="minwidth200" type="text" name="proprio" value="'.GETPOST('proprio').'"></td></tr>';
1824  print "</td></tr>\n";
1825 
1826  print '<tr><td>'.$langs->trans("BankAccountOwnerAddress").'</td><td>';
1827  print '<textarea name="owner_address" rows="'.ROWS_4.'" class="quatrevingtpercent" maxlength="255">';
1828  print GETPOST('owner_address');
1829  print "</textarea></td></tr>";
1830 
1831  print '</table>';
1832 
1833  if ($conf->prelevement->enabled)
1834  {
1835  print '<br>';
1836 
1837  print '<table class="border centpercent">';
1838 
1839  // RUM
1840  print '<tr><td class="titlefieldcreate">'.$langs->trans("RUM").'</td>';
1841  print '<td colspan="4"><input type="text" class="minwidth300" name="rum" value="'.GETPOST('rum', 'alpha').'"> <div class="opacitymedium">'.$langs->trans("RUMWillBeGenerated").'</div></td></tr>';
1842 
1843  print '<tr><td class="titlefieldcreate">'.$langs->trans("DateRUM").'</td>';
1844  print '<td colspan="4">'.$form->selectDate(GETPOST('date_rum'), 'date_rum', 0, 0, 1, 'date_rum').'</td></tr>';
1845 
1846  print '<tr><td>'.$langs->trans("WithdrawMode").'</td><td>';
1847  $tblArraychoice = array("FRST" => $langs->trans("FRST"), "RECUR" => $langs->trans("RECUR"));
1848  print $form->selectarray("frstrecur", $tblArraychoice, (GETPOSTISSET('frstrecur') ? GETPOST('frstrecur') : 'FRST'), 0);
1849  print '</td></tr>';
1850 
1851  print '</table>';
1852  }
1853 
1854  print '</div>';
1855 
1856  print dol_get_fiche_end();
1857 
1858  dol_set_focus('#label');
1859 
1860  print '<div class="center">';
1861  print '<input class="button" value="'.$langs->trans("Add").'" type="submit">';
1862  print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
1863  print '<input name="cancel" class="button button-cancel" value="'.$langs->trans("Cancel").'" type="submit">';
1864  print '</div>';
1865 }
1866 
1867 // Create Card
1868 if ($socid && $action == 'createcard' && $user->rights->societe->creer)
1869 {
1870  print dol_get_fiche_head($head, 'rib', $langs->trans("ThirdParty"), 0, 'company');
1871 
1872  $linkback = '<a href="'.DOL_URL_ROOT.'/societe/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
1873 
1874  dol_banner_tab($object, 'socid', $linkback, ($user->socid ? 0 : 1), 'rowid', 'nom');
1875 
1876  print '<div class="nofichecenter">';
1877 
1878  print '<div class="underbanner clearboth"></div>';
1879  print '<table class="border centpercent">';
1880 
1881  print '<tr><td class="titlefieldcreate fieldrequired">'.$langs->trans("Label").'</td>';
1882  print '<td><input class="minwidth200" type="text" id="label" name="label" value="'.GETPOST('label', 'alpha').'"></td></tr>';
1883 
1884  print '<tr><td class="fieldrequired">'.$langs->trans("NameOnCard").'</td>';
1885  print '<td><input class="minwidth200" type="text" name="proprio" value="'.GETPOST('proprio', 'alpha').'"></td></tr>';
1886 
1887  print '<tr><td>'.$langs->trans("CardNumber").'</td>';
1888  print '<td><input class="minwidth200" type="text" name="cardnumber" value="'.GETPOST('cardnumber', 'alpha').'"></td></tr>';
1889 
1890  print '<tr><td class="fieldrequired">'.$langs->trans("ExpiryDate").'</td>';
1891  print '<td>';
1892  print $formother->select_month(GETPOST('exp_date_month', 'int'), 'exp_date_month', 1);
1893  print $formother->select_year(GETPOST('exp_date_year', 'int'), 'exp_date_year', 1, 5, 10, 0, 0, '', 'marginleftonly');
1894  print '</td></tr>';
1895 
1896  print '<tr><td>'.$langs->trans("CVN").'</td>';
1897  print '<td><input class="width50" type="text" name="cvn" value="'.GETPOST('cvn', 'alpha').'"></td></tr>';
1898 
1899  print '<tr><td>'.$langs->trans("StripeID")." ('card_....')</td>";
1900  print '<td><input class="minwidth300" type="text" name="stripe_card_ref" value="'.GETPOST('stripe_card_ref', 'alpha').'"></td></tr>';
1901 
1902  print '</table>';
1903 
1904  print '</div>';
1905 
1906  print dol_get_fiche_end();
1907 
1908  dol_set_focus('#label');
1909 
1910  print '<div class="center">';
1911  print '<input class="button" value="'.$langs->trans("Add").'" type="submit">';
1912  print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
1913  print '<input name="cancel" class="button button-cancel" value="'.$langs->trans("Cancel").'" type="submit">';
1914  print '</div>';
1915 }
1916 
1917 if ($socid && ($action == 'edit' || $action == 'editcard') && $user->rights->societe->creer)
1918 {
1919  print '</form>';
1920 }
1921 if ($socid && ($action == 'create' || $action == 'createcard') && $user->rights->societe->creer)
1922 {
1923  print '</form>';
1924 }
1925 
1926 // End of page
1927 llxFooter();
1928 $db->close();
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm= 'auto', $check=1)
Return a timestamp date built from detailed informations (by default a local PHP server timestamp) Re...
dolGetButtonTitle($label, $helpText= '', $iconClass= 'fa fa-file', $url= '', $id= '', $status=1, $params=array())
Function dolGetButtonTitle : this kind of buttons are used in title in list.
img_credit_card($brand, $morecss=null)
Return image of a credit card according to its brand name.
dol_now($mode= 'auto')
Return date for now.
static liste_modeles($db, $maxfilenamelength=0)
Return list of active generation modules.
Class to manage bank accounts description of third parties.
ajax_combobox($htmlname, $events=array(), $minLengthToAutocomplete=0, $forcefocus=0, $widthTypeOfAutocomplete= 'resolve')
Convert a html select field into an ajax combobox.
Definition: ajax.lib.php:391
Class for SocieteAccount.
checkSwiftForAccount($account)
Check SWIFT informations for a bank account.
Definition: bank.lib.php:251
Stripe class.
img_warning($titlealt= 'default', $moreatt= '', $morecss= 'pictowarning')
Show warning logo.
price($amount, $form=0, $outlangs= '', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code= '')
Function to format a value into an amount for visual output Function used into PDF and HTML pages...
Class to generate html code for admin pages.
llxHeader()
Empty header.
Definition: wrapper.php:45
Class to manage standard extra fields.
setEventMessages($mesg, $mesgs, $style= 'mesgs', $messagekey= '')
Set event messages in dol_events session object.
showDirectDownloadLink($object)
Return string with full Url.
Class to manage generation of HTML components Only common components must be here.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname.
Class to manage third parties objects (customers, suppliers, prospects...)
print_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
load_fiche_titre($titre, $morehtmlright= '', $picto= 'generic', $pictoisfullpath=0, $id= '', $morecssontable= '', $morehtmlcenter= '')
Load a title with picto.
Class to manage withdrawal receipts.
img_picto($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt= '', $morecss= '', $marginleftonlyshort=2)
Show picto whatever it&#39;s its name (generic function)
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
Classe permettant la generation de composants html autre Only common components are here...
restrictedArea($user, $features, $objectid=0, $tableandshare= '', $feature2= '', $dbt_keyfield= 'fk_soc', $dbt_select= 'rowid', $isdraft=0)
Check permissions of a user to show a page and an object.
dol_sanitizeFileName($str, $newstr= '_', $unaccent=1)
Clean a string to use it as a file name.
societe_prepare_head(Societe $object)
Return array of tabs to used on pages for third parties cards.
Definition: company.lib.php:42
Class to offer components to list and upload files.
print $_SERVER["PHP_SELF"]
Edit parameters.
Class for CompanyPaymentMode.
checkBanForAccount($account)
Check account number informations for a bank account.
Definition: bank.lib.php:284
dol_get_fiche_head($links=array(), $active= '', $title= '', $notab=0, $picto= '', $pictoisfullpath=0, $morehtmlright= '', $morecss= '', $limittoshow=0, $moretabssuffix= '')
Show tabs of a record.
dol_htmloutput_mesg($mesgstring= '', $mesgarray=array(), $style= 'ok', $keepembedded=0)
Print formated messages to output (Used to show messages on html output).
print
Draft customers invoices.
Definition: index.php:89
dol_print_date($time, $format= '', $tzoutput= 'auto', $outputlangs= '', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
checkIbanForAccount($account)
Check IBAN number informations for a bank account.
Definition: bank.lib.php:267
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.
Definition: index.php:1232
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
newToken()
Return the value of token currently saved into session with name &#39;newtoken&#39;.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
dol_banner_tab($object, $paramid, $morehtml= '', $shownav=1, $fieldid= 'rowid', $fieldref= 'ref', $morehtmlref= '', $moreparam= '', $nodbprefix=0, $morehtmlleft= '', $morehtmlstatus= '', $onlybanner=0, $morehtmlright= '')
Show tab footer of a card.
llxFooter()
Empty footer.
Definition: wrapper.php:59
Class to manage ECM files.
dol_set_focus($selector)
Set focus onto field with selector (similar behaviour of &#39;autofocus&#39; HTML5 tag)
getCountry($searchkey, $withcode= '', $dbtouse=0, $outputlangs= '', $entconv=1, $searchlabel= '')
Return country label, code or id from an id, code or label.
picto_from_langcode($codelang, $moreatt= '')
Return img flag of country for a language code or country code.
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...