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