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