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