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