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