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