dolibarr 23.0.4
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-2025 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 ?? $conf->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 ?? $conf->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">';
987 print $langs->trans('NatureOfThirdParty');
988 print '</td><td>';
989 print $object->getTypeUrl(1);
990 print '</td></tr>';
991
992 if ($object->client) {
993 print '<tr><td class="titlefield">';
994 print $langs->trans('CustomerCode');
995 print '</td><td>';
997 $tmpcheck = $object->check_codeclient();
998 if ($tmpcheck != 0 && $tmpcheck != -5) {
999 print ' <span class="error">('.$langs->trans("WrongCustomerCode").')</span>';
1000 }
1001 print '</td></tr>';
1002 $sql = "SELECT count(*) as nb from ".MAIN_DB_PREFIX."facture where fk_soc = ".((int) $socid);
1003 $resql = $db->query($sql);
1004 if (!$resql) {
1005 dol_print_error($db);
1006 }
1007
1008 $obj = $db->fetch_object($resql);
1009 $nbFactsClient = $obj->nb;
1010 $thirdTypeArray = array();
1011 $elementTypeArray = array();
1012 $thirdTypeArray['customer'] = $langs->trans("customer");
1013 if (isModEnabled("propal") && $user->hasRight('propal', 'lire')) {
1014 $elementTypeArray['propal'] = $langs->transnoentitiesnoconv('Proposals');
1015 }
1016 if (isModEnabled('order') && $user->hasRight('commande', 'lire')) {
1017 $elementTypeArray['order'] = $langs->transnoentitiesnoconv('Orders');
1018 }
1019 if (isModEnabled('invoice') && $user->hasRight('facture', 'lire')) {
1020 $elementTypeArray['invoice'] = $langs->transnoentitiesnoconv('Invoices');
1021 }
1022 if (isModEnabled('contract') && $user->hasRight('contrat', 'lire')) {
1023 $elementTypeArray['contract'] = $langs->transnoentitiesnoconv('Contracts');
1024 }
1025
1026 if (isModEnabled('stripe')) {
1027 // Force to use the correct API key
1028 global $stripearrayofkeysbyenv;
1029
1030 $tmpservice = 0;
1031 $tmpsite_account = $stripearrayofkeysbyenv[$tmpservice]['publishable_key'];
1032 $tmpstripeacc = $stripe->getStripeAccount((string) $tmpservice); // Get Stripe OAuth connect account (no remote access to Stripe here)
1033 $tmpstripecu = $stripe->getStripeCustomerAccount($object->id, $tmpservice, $tmpsite_account); // Get remote Stripe customer 'cus_...' (no remote access to Stripe here)
1034
1035 // Stripe customer key 'cu_....' stored into llx_societe_account
1036 print '<tr><td class="titlefield">';
1037 print $form->editfieldkey($langs->trans("StripeCustomerId").' (Test)', 'key_accounttest', $tmpstripecu, $object, (int) $permissiontoaddupdatepaymentinformation, 'string', '', 0, 2, 'socid');
1038 print '</td><td'.(empty($tmpstripecu) ? ' class="right"' : '').'>';
1039 print $form->editfieldval($langs->trans("StripeCustomerId").' (Test)', 'key_accounttest', $tmpstripecu, $object, $permissiontoaddupdatepaymentinformation, 'string', '', null, null, '', 2, '', 'socid');
1040 if ($tmpstripecu && $action != 'editkey_accounttest') {
1041 $connect = '';
1042 if (!empty($stripeacc)) {
1043 $connect = $stripeacc.'/';
1044 }
1045 $url = 'https://dashboard.stripe.com/'.$connect.'test/customers/'.$tmpstripecu;
1046 print ' <a href="'.$url.'" target="_stripe">'.img_picto($langs->trans('ShowInStripe').' - Publishable key = '.$tmpsite_account, 'globe').'</a>';
1047 }
1048 if (empty($tmpstripecu)) {
1049 print '<form action="'.$_SERVER["PHP_SELF"].'" method="post" class="nowraponall">';
1050 print '<input type="hidden" name="action" value="synccustomertostripetest">';
1051 print '<input type="hidden" name="token" value="'.newToken().'">';
1052 print '<input type="hidden" name="socid" value="'.$object->id.'">';
1053 print img_picto($langs->trans("CreateCustomerOnStripe"), 'stripe');
1054 print '<input type="submit" class="buttonlink nomargintop nomarginbottom noborderbottom nopaddingtopimp nopaddingbottomimp" name="syncstripecustomertest" value="'.$langs->trans("CreateCustomerOnStripe").'">';
1055 print '</form>';
1056 }
1057 print '</td></tr>';
1058
1059 $tmpservice = 1;
1060 $tmpsite_account = $stripearrayofkeysbyenv[$tmpservice]['publishable_key'];
1061 $tmpstripeacc = $stripe->getStripeAccount((string) $tmpservice); // Get Stripe OAuth connect account (no remote access to Stripe here)
1062 $tmpstripecu = $stripe->getStripeCustomerAccount($object->id, $tmpservice, $tmpsite_account); // Get remote Stripe customer 'cus_...' (no remote access to Stripe here)
1063
1064 // Stripe customer key 'cu_....' stored into llx_societe_account
1065 print '<tr><td class="titlefield">';
1066 print $form->editfieldkey($langs->trans("StripeCustomerId").' (Live)', 'key_account', $tmpstripecu, $object, (int) $permissiontoaddupdatepaymentinformation, 'string', '', 0, 2, 'socid');
1067 print '</td><td'.(empty($tmpstripecu) ? ' class="right"' : '').'>';
1068 print $form->editfieldval($langs->trans("StripeCustomerId").' (Live)', 'key_account', $tmpstripecu, $object, $permissiontoaddupdatepaymentinformation, 'string', '', null, null, '', 2, '', 'socid');
1069 if ($tmpstripecu && $action != 'editkey_account') {
1070 $connect = '';
1071 if (!empty($stripeacc)) {
1072 $connect = $stripeacc.'/';
1073 }
1074 $url = 'https://dashboard.stripe.com/'.$connect.'customers/'.$tmpstripecu;
1075 print ' <a href="'.$url.'" target="_stripe">'.img_picto($langs->trans('ShowInStripe').' - Publishable key = '.$tmpsite_account, 'globe').'</a>';
1076 }
1077 if (empty($tmpstripecu)) {
1078 print '<form action="'.$_SERVER["PHP_SELF"].'" method="post" class="nowraponall">';
1079 print '<input type="hidden" name="action" value="synccustomertostripe">';
1080 print '<input type="hidden" name="token" value="'.newToken().'">';
1081 print '<input type="hidden" name="socid" value="'.$object->id.'">';
1082 print img_picto($langs->trans("CreateCustomerOnStripe"), 'stripe');
1083 print '<input type="submit" class="buttonlink nomargintop nomarginbottom noborderbottom nopaddingtopimp nopaddingbottomimp" name="syncstripecustomer" value="'.$langs->trans("CreateCustomerOnStripe").'">';
1084 print '</form>';
1085 }
1086 print '</td></tr>';
1087 }
1088 }
1089
1090 if ($object->fournisseur) {
1091 print '<tr><td class="titlefield">';
1092 print $langs->trans('SupplierCode');
1093 print '</td><td>';
1095 $tmpcheck = $object->check_codefournisseur();
1096 if ($tmpcheck != 0 && $tmpcheck != -5) {
1097 print ' <span class="error">('.$langs->trans("WrongSupplierCode").')</span>';
1098 }
1099 print '</td></tr>';
1100 $sql = "SELECT count(*) as nb from ".MAIN_DB_PREFIX."facture where fk_soc = ".((int) $socid);
1101 $resql = $db->query($sql);
1102 if (!$resql) {
1103 dol_print_error($db);
1104 }
1105 $obj = $db->fetch_object($resql);
1106 $nbFactsClient = $obj->nb;
1107 $thirdTypeArray['customer'] = $langs->trans("customer");
1108 if (isModEnabled('propal') && $user->hasRight('propal', 'lire')) {
1109 $elementTypeArray['propal'] = $langs->transnoentitiesnoconv('Proposals');
1110 }
1111 if (isModEnabled('order') && $user->hasRight('commande', 'lire')) {
1112 $elementTypeArray['order'] = $langs->transnoentitiesnoconv('Orders');
1113 }
1114 if (isModEnabled('invoice') && $user->hasRight('facture', 'lire')) {
1115 $elementTypeArray['invoice'] = $langs->transnoentitiesnoconv('Invoices');
1116 }
1117 if (isModEnabled('contract') && $user->hasRight('contrat', 'lire')) {
1118 $elementTypeArray['contract'] = $langs->transnoentitiesnoconv('Contracts');
1119 }
1120 }
1121
1122 // Stripe connect
1123 if (isModEnabled('stripe') && !empty($conf->stripeconnect->enabled) && getDolGlobalInt('MAIN_FEATURES_LEVEL') >= 2 && $service !== null) {
1124 $stripesupplieracc = $stripe->getStripeAccount($service, $object->id); // Get Stripe OAuth connect account (no network access here)
1125
1126 // Stripe customer key 'cu_....' stored into llx_societe_account
1127 print '<tr><td class="titlefield">';
1128 print $form->editfieldkey("StripeConnectAccount", 'key_account_supplier', $stripesupplieracc, $object, (int) $permissiontoaddupdatepaymentinformation, 'string', '', 0, 2, 'socid');
1129 print '</td><td'.(empty($stripesupplieracc) ? ' class="right"' : '').'>';
1130 print $form->editfieldval("StripeConnectAccount", 'key_account_supplier', $stripesupplieracc, $object, $permissiontoaddupdatepaymentinformation, 'string', '', null, null, '', 2, '', 'socid');
1131 if ($stripesupplieracc && $action != 'editkey_account_supplier') {
1132 $connect = '';
1133
1134 $url = 'https://dashboard.stripe.com/test/connect/accounts/'.$stripesupplieracc;
1135 if ($servicestatus) {
1136 $url = 'https://dashboard.stripe.com/connect/accounts/'.$stripesupplieracc;
1137 }
1138 print ' <a href="'.$url.'" target="_stripe">'.img_picto($langs->trans('ShowInStripe').' - Publishable key '.$site_account, 'globe').'</a>';
1139 }
1140 if (empty($stripesupplieracc)) {
1141 print '<form action="'.$_SERVER["PHP_SELF"].'" method="post" class="nowraponall">';
1142 print '<input type="hidden" name="action" value="syncsuppliertostripe">';
1143 print '<input type="hidden" name="token" value="'.newToken().'">';
1144 print '<input type="hidden" name="socid" value="'.$object->id.'">';
1145 print '<input type="hidden" name="companybankid" value="'.$ribid.'">';
1146 //print '<input type="submit" class="button buttongen" name="syncstripecustomer" value="'.$langs->trans("CreateSupplierOnStripe").'">';
1147 print '</form>';
1148 }
1149 print '</td></tr>';
1150 }
1151
1152 print '</table>';
1153 print '</div>';
1154
1155 print dol_get_fiche_end();
1156
1157 print '<br>';
1158
1159 $showcardpaymentmode = 0;
1160 if (isModEnabled('stripe')) {
1161 $showcardpaymentmode++;
1162 }
1163
1164 // Get list of remote payment modes
1165 $listofsources = array();
1166
1167 $customerstripe = null;
1168 if (isset($stripe) && is_object($stripe) && $stripeacc !== null) {
1169 try {
1170 $customerstripe = $stripe->customerStripe($object, $stripeacc, $servicestatus);
1171 if (!empty($customerstripe->id)) {
1172 // When using the Charge API architecture
1173 if (!getDolGlobalString('STRIPE_USE_INTENT_WITH_AUTOMATIC_CONFIRMATION')) {
1174 $listofsources = $customerstripe->sources->data;
1175 } else {
1176 $service = 'StripeTest';
1177 $servicestatus = 0;
1178 if (getDolGlobalString('STRIPE_LIVE')/* && !GETPOST('forcesandbox', 'alpha') */) {
1179 $service = 'StripeLive';
1180 $servicestatus = 1;
1181 }
1182
1183 // Force to use the correct API key
1184 global $stripearrayofkeysbyenv;
1185 \Stripe\Stripe::setApiKey($stripearrayofkeysbyenv[$servicestatus]['secret_key']);
1186
1187 try {
1188 if (empty($stripeacc)) { // If the Stripe connect account not set, we use common API usage
1189 $paymentmethodobjsA = \Stripe\PaymentMethod::all(array("customer" => $customerstripe->id, "type" => "card"));
1190 $paymentmethodobjsB = \Stripe\PaymentMethod::all(array("customer" => $customerstripe->id, "type" => "sepa_debit"));
1191 } else {
1192 $paymentmethodobjsA = \Stripe\PaymentMethod::all(array("customer" => $customerstripe->id, "type" => "card"), array("stripe_account" => $stripeacc));
1193 $paymentmethodobjsB = \Stripe\PaymentMethod::all(array("customer" => $customerstripe->id, "type" => "sepa_debit"), array("stripe_account" => $stripeacc));
1194 }
1195
1196 if ($paymentmethodobjsA->data != null && $paymentmethodobjsB->data != null) {
1197 $listofsources = array_merge((array) $paymentmethodobjsA->data, (array) $paymentmethodobjsB->data);
1198 } elseif ($paymentmethodobjsB->data != null) {
1199 $listofsources = $paymentmethodobjsB->data;
1200 } else {
1201 $listofsources = $paymentmethodobjsA->data;
1202 }
1203 } catch (Exception $e) {
1204 $error++;
1205 setEventMessages($e->getMessage(), null, 'errors');
1206 }
1207 }
1208 }
1209 } catch (Exception $e) {
1210 dol_syslog("Error when searching/loading Stripe customer for thirdparty id =".$object->id);
1211 }
1212 }
1213
1214
1215 // List of Card payment modes
1216 if ($showcardpaymentmode && $object->client) {
1217 $morehtmlright = '';
1218 if (getDolGlobalString('STRIPE_ALLOW_LOCAL_CARD')) {
1219 $morehtmlright .= dolGetButtonTitle($langs->trans('Add'), '', 'fa fa-plus-circle', $_SERVER["PHP_SELF"].'?socid='.$object->id.'&action=createcard');
1220 }
1221 print load_fiche_titre($langs->trans('CreditCard'), $morehtmlright, 'fa-credit-card');
1222 //($stripeacc ? ' (Stripe connection with StripeConnect account '.$stripeacc.')' : ' (Stripe connection with keys from Stripe module setup)')
1223
1224 print '<!-- List of card payments -->'."\n";
1225 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
1226 print '<table class="liste centpercent noborder">'."\n";
1227 print '<tr class="liste_titre">';
1228 print '<td>'.$langs->trans('Label').'</td>';
1229 print '<td>'.$form->textwithpicto($langs->trans('ExternalSystemID'), $langs->trans("IDOfPaymentInAnExternalSystem")).'</td>'; // external system ID
1230 print '<td>'.$langs->trans('Type').'</td>';
1231 print '<td>'.$langs->trans('Informations').'</td>';
1232 print '<td></td>';
1233 print '<td class="center">'.$langs->trans('Default').'</td>';
1234 print '<td>'.$langs->trans('Note').'</td>';
1235 print '<td>'.$langs->trans('DateModification').'</td>';
1236 // Hook fields
1237 $parameters = array('arrayfields' => array(), 'param' => '', 'sortfield' => '', 'sortorder' => '', 'linetype' => 'stripetitle');
1238 $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters, $object); // Note that $action and $object may have been modified by hook
1239 print $hookmanager->resPrint;
1240 // Action column
1241 print "<td></td>";
1242 print "</tr>\n";
1243
1244 $nbremote = 0;
1245 $nblocal = 0;
1246 $arrayofremotecard = array();
1247
1248 // Show local sources
1249 if (getDolGlobalString('STRIPE_ALLOW_LOCAL_CARD')) {
1250 //$societeaccount = new SocieteAccount($db);
1251 $companypaymentmodetemp = new CompanyPaymentMode($db);
1252
1253 $sql = 'SELECT rowid FROM '.MAIN_DB_PREFIX."societe_rib";
1254 $sql .= " WHERE type in ('card')";
1255 $sql .= " AND fk_soc = ".((int) $object->id);
1256 $sql .= " AND status = ".((int) $servicestatus);
1257
1258 $resql = $db->query($sql);
1259 if ($resql) {
1260 $num_rows = $db->num_rows($resql);
1261 if ($num_rows) {
1262 $i = 0;
1263 while ($i < $num_rows) {
1264 $nblocal++;
1265
1266 $obj = $db->fetch_object($resql);
1267 if ($obj) {
1268 $companypaymentmodetemp->fetch($obj->rowid);
1269
1270 $arrayofremotecard[$companypaymentmodetemp->stripe_card_ref] = $companypaymentmodetemp->stripe_card_ref;
1271
1272 print '<tr class="oddeven" data-rowid="'.((int) $companypaymentmodetemp->id).'">';
1273 // Label
1274 print '<td class="tdoverflowmax150" title="'.dol_escape_htmltag($companypaymentmodetemp->label).'">';
1275 print dol_escape_htmltag($companypaymentmodetemp->label);
1276 print '</td>';
1277 // External system card ID
1278 print '<td class="tdoverflowmax150" title="'.dol_escape_htmltag($companypaymentmodetemp->stripe_card_ref.(empty($companypaymentmodetemp->stripe_account) ? '' : ' - '.$companypaymentmodetemp->stripe_account)).'">';
1279 if (!empty($companypaymentmodetemp->stripe_card_ref) && !empty($companypaymentmodetemp->ext_payment_site)) {
1280 if (isModEnabled('stripe') && in_array($companypaymentmodetemp->ext_payment_site, array('StripeTest', 'StripeLive'))) {
1281 $connect = '';
1282 if (!empty($stripeacc)) {
1283 $connect = $stripeacc.'/';
1284 }
1285 if ($companypaymentmodetemp->ext_payment_site == 'StripeLive') {
1286 $url = 'https://dashboard.stripe.com/'.$connect.'search?query='.$companypaymentmodetemp->stripe_card_ref;
1287 } else {
1288 $url = 'https://dashboard.stripe.com/'.$connect.'test/search?query='.$companypaymentmodetemp->stripe_card_ref;
1289 }
1290 print "<a href='".$url."' target='_stripe'>".img_picto($langs->trans('ShowInStripe').' - '.$companypaymentmodetemp->stripe_account, 'globe')."</a> ";
1291 }
1292 // TODO Add hook here for other payment services
1293 }
1294 print dol_escape_htmltag($companypaymentmodetemp->stripe_card_ref);
1295 print '</td>';
1296 // Type
1297 print '<td>';
1298 print img_credit_card($companypaymentmodetemp->type);
1299 print '</td>';
1300 // Information (Owner, ...)
1301 print '<td class="minwidth100">';
1302 if ($companypaymentmodetemp->owner_name) {
1303 print '<span class="opacitymedium">'.$companypaymentmodetemp->owner_name.'</span><br>';
1304 }
1305 if ($companypaymentmodetemp->last_four) {
1306 print '....'.$companypaymentmodetemp->last_four;
1307 }
1308 if ($companypaymentmodetemp->exp_date_month || $companypaymentmodetemp->exp_date_year) {
1309 print ' - '.sprintf("%02d", $companypaymentmodetemp->exp_date_month).'/'.$companypaymentmodetemp->exp_date_year;
1310 }
1311 print '</td>';
1312 // Country
1313 print '<td class="tdoverflowmax100">';
1314 if ($companypaymentmodetemp->country_code) {
1315 $img = picto_from_langcode($companypaymentmodetemp->country_code);
1316 print $img ? $img.' ' : '';
1317 print getCountry($companypaymentmodetemp->country_code, '1');
1318 } else {
1319 print img_warning().' <span class="error">'.$langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("CompanyCountry")).'</span>';
1320 }
1321 print '</td>';
1322 // Default
1323 print '<td class="center">';
1324 if (empty($companypaymentmodetemp->default_rib)) {
1325 print '<a href="'.DOL_URL_ROOT.'/societe/paymentmodes.php?socid='.$object->id.'&id='.$companypaymentmodetemp->id.'&action=setlocalassourcedefault&token='.newToken().'">';
1326 print img_picto($langs->trans("Default"), 'off');
1327 print '</a>';
1328 } else {
1329 print img_picto($langs->trans("Default"), 'on');
1330 }
1331 print '</td>';
1332 if (empty($companypaymentmodetemp->stripe_card_ref)) {
1333 $s = $langs->trans("Local");
1334 } else {
1335 $s = $langs->trans("LocalAndRemote");
1336 }
1337 print '<td class="tdoverflowmax100" title="'.dol_escape_htmltag($s).'">';
1338 print $s;
1339 print '</td>';
1340 print '<td>';
1341 print dol_print_date($companypaymentmodetemp->date_modification, 'dayhour', 'tzuserrel');
1342 print '</td>';
1343 // Fields from hook
1344 $parameters = array('arrayfields' => array(), 'obj' => $obj, 'linetype' => 'stripecard');
1345 $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters, $object); // Note that $action and $object may have been modified by hook
1346 print $hookmanager->resPrint;
1347 // Action column
1348 print '<td class="right minwidth50 nowraponall">';
1349 if ($permissiontoaddupdatepaymentinformation) {
1350 if ($stripecu && empty($companypaymentmodetemp->stripe_card_ref)) {
1351 print '<a href="'.$_SERVER['PHP_SELF'].'?action=synccardtostripe&socid='.$object->id.'&id='.$companypaymentmodetemp->id.'" class="paddingrightonly marginrightonly">'.$langs->trans("CreateCardOnStripe").'</a>';
1352 }
1353
1354 print '<a class="editfielda marginleftonly marginrightonly" href="'.DOL_URL_ROOT.'/societe/paymentmodes.php?socid='.$object->id.'&id='.$companypaymentmodetemp->id.'&action=editcard&token='.newToken().'">';
1355 print img_picto($langs->trans("Modify"), 'edit');
1356 print '</a>';
1357 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.'&
1358 print img_picto($langs->trans("Delete"), 'delete');
1359 print '</a>';
1360 }
1361 print '</td>';
1362 print '</tr>';
1363 }
1364 $i++;
1365 }
1366 }
1367 } else {
1368 dol_print_error($db);
1369 }
1370 }
1371
1372 // Show remote sources (not already shown as local source)
1373 if (is_array($listofsources) && count($listofsources)) {
1374 foreach ($listofsources as $src) {
1375 if (!empty($arrayofremotecard[$src->id])) {
1376 continue; // Already in previous list
1377 }
1378
1379 $nbremote++;
1380
1381 $imgline = '';
1382 if ($src->object == 'card') {
1383 $imgline = img_credit_card($src->brand);
1384 } elseif ($src->object == 'source' && $src->type == 'card') {
1385 $imgline = img_credit_card($src->card->brand);
1386 } elseif ($src->object == 'payment_method' && $src->type == 'card') {
1387 $imgline = img_credit_card($src->card->brand);
1388 } elseif ($src->object == 'source' && $src->type == 'sepa_debit') {
1389 continue;
1390 } elseif ($src->object == 'payment_method' && $src->type == 'sepa_debit') {
1391 continue;
1392 }
1393
1394 print '<tr class="oddeven">';
1395 print '<td>';
1396 print '</td>';
1397 // Src ID
1398 print '<td class="tdoverflowmax150">';
1399 $connect = '';
1400 if (!empty($stripeacc)) {
1401 $connect = $stripeacc.'/';
1402 }
1403 //$url='https://dashboard.stripe.com/'.$connect.'test/sources/'.$src->id;
1404 $url = 'https://dashboard.stripe.com/'.$connect.'test/search?query='.$src->id;
1405 if ($servicestatus) {
1406 //$url='https://dashboard.stripe.com/'.$connect.'sources/'.$src->id;
1407 $url = 'https://dashboard.stripe.com/'.$connect.'search?query='.$src->id;
1408 }
1409 print "<a href='".$url."' target='_stripe'>".img_picto($langs->trans('ShowInStripe'), 'globe')."</a> ";
1410 print $src->id;
1411 print '</td>';
1412 // Img
1413 print '<td>';
1414 print $imgline;
1415 print'</td>';
1416 // Information
1417 print '<td valign="middle">';
1418 if ($src->object == 'card') {
1419 print '....'.$src->last4.' - '.$src->exp_month.'/'.$src->exp_year;
1420 print '</td><td>';
1421 if ($src->country) {
1422 $img = picto_from_langcode($src->country);
1423 print $img ? $img.' ' : '';
1424 print getCountry($src->country, '1');
1425 } else {
1426 print img_warning().' <span class="error">'.$langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("CompanyCountry")).'</span>';
1427 }
1428 } elseif ($src->object == 'source' && $src->type == 'card') {
1429 print '<span class="opacitymedium">'.$src->owner->name.'</span><br>....'.$src->card->last4.' - '.$src->card->exp_month.'/'.$src->card->exp_year;
1430 print '</td><td>';
1431
1432 if ($src->card->country) {
1433 $img = picto_from_langcode($src->card->country);
1434 print $img ? $img.' ' : '';
1435 print getCountry($src->card->country, '1');
1436 } else {
1437 print img_warning().' <span class="error">'.$langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("CompanyCountry")).'</span>';
1438 }
1439 } elseif ($src->object == 'source' && $src->type == 'sepa_debit') {
1440 print '<span class="opacitymedium">'.$src->billing_details->name.'</span><br>....'.$src->sepa_debit->last4;
1441 print '</td><td>';
1442 if ($src->sepa_debit->country) {
1443 $img = picto_from_langcode($src->sepa_debit->country);
1444 print $img ? $img.' ' : '';
1445 print getCountry($src->sepa_debit->country, '1');
1446 } else {
1447 print img_warning().' <span class="error">'.$langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("CompanyCountry")).'</span>';
1448 }
1449 } elseif ($src->object == 'payment_method' && $src->type == 'card') {
1450 print '<span class="opacitymedium">'.$src->billing_details->name.'</span><br>....'.$src->card->last4.' - '.$src->card->exp_month.'/'.$src->card->exp_year;
1451 print '</td><td>';
1452
1453 if ($src->card->country) {
1454 $img = picto_from_langcode($src->card->country);
1455 print $img ? $img.' ' : '';
1456 print getCountry($src->card->country, '1');
1457 } else {
1458 print img_warning().' <span class="error">'.$langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("CompanyCountry")).'</span>';
1459 }
1460 } elseif ($src->object == 'payment_method' && $src->type == 'sepa_debit') {
1461 print '<span class="opacitymedium">'.$src->billing_details->name.'</span><br>....'.$src->sepa_debit->last4;
1462 print '</td><td>';
1463 if ($src->sepa_debit->country) {
1464 $img = picto_from_langcode($src->sepa_debit->country);
1465 print $img ? $img.' ' : '';
1466 print getCountry($src->sepa_debit->country, '1');
1467 } else {
1468 print img_warning().' <span class="error">'.$langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("CompanyCountry")).'</span>';
1469 }
1470 } else {
1471 print '</td><td>';
1472 }
1473 print '</td>';
1474 // Default
1475 print '<td class="center" width="50">';
1476 if ((empty($customerstripe->invoice_settings) && $customerstripe->default_source != $src->id) ||
1477 (!empty($customerstripe->invoice_settings) && $customerstripe->invoice_settings->default_payment_method != $src->id)) {
1478 print '<a href="'.DOL_URL_ROOT.'/societe/paymentmodes.php?socid='.$object->id.'&source='.$src->id.'&action=setassourcedefault&token='.newToken().'">';
1479 print img_picto($langs->trans("Default"), 'off');
1480 print '</a>';
1481 } else {
1482 print img_picto($langs->trans("Default"), 'on');
1483 }
1484 print '</td>';
1485 print '<td>';
1486 print $langs->trans("Remote");
1487 //if ($src->cvc_check == 'fail') print ' - CVC check fail';
1488 print '</td>';
1489
1490 print '<td>';
1491 //var_dump($src);
1492 print '</td>';
1493
1494 // Fields from hook
1495 $parameters = array('arrayfields' => array(), 'stripesource' => $src, 'linetype' => 'stripecardremoteonly');
1496 $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters, $object); // Note that $action and $object may have been modified by hook
1497 print $hookmanager->resPrint;
1498
1499 // Action column
1500 print '<td class="right nowraponall">';
1501 if ($permissiontoaddupdatepaymentinformation) {
1502 print '<a class="marginleftonly marginrightonly" href="'.DOL_URL_ROOT.'/societe/paymentmodes.php?socid='.$object->id.'&source='.$src->id.'&action=deletecard&token='.newToken().'">';
1503 print img_picto($langs->trans("Delete"), 'delete');
1504 print '</a>';
1505 }
1506 print '</td>';
1507
1508 print '</tr>';
1509 }
1510 }
1511
1512 if ($nbremote == 0 && $nblocal == 0) {
1513 $colspan = (getDolGlobalString('STRIPE_ALLOW_LOCAL_CARD') ? 10 : 9);
1514 print '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("None").'</span></td></tr>';
1515 }
1516 print "</table>";
1517 print "</div>";
1518 print '<br>';
1519 }
1520
1521 // List of Stripe connect accounts
1522 if (isModEnabled('stripe') && !empty($conf->stripeconnect->enabled) && !empty($stripesupplieracc)) {
1523 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');
1524 $balance = \Stripe\Balance::retrieve(array("stripe_account" => $stripesupplieracc));
1525 print '<!-- List of Stripe connected accounts -->'."\n";
1526 print '<table class="liste centpercent noborder">'."\n";
1527 print '<tr class="liste_titre">';
1528 print '<td>'.$langs->trans('Currency').'</td>';
1529 print '<td>'.$langs->trans('Available').'</td>';
1530 print '<td>'.$langs->trans('Pending').'</td>';
1531 print '<td>'.$langs->trans('Total').'</td>';
1532 print '</tr>';
1533
1534 $currencybalance = array();
1535 if (is_array($balance->available) && count($balance->available)) {
1536 foreach ($balance->available as $cpt) {
1537 $arrayzerounitcurrency = array('BIF', 'CLP', 'DJF', 'GNF', 'JPY', 'KMF', 'KRW', 'MGA', 'PYG', 'RWF', 'VND', 'VUV', 'XAF', 'XOF', 'XPF');
1538 if (!in_array($cpt->currency, $arrayzerounitcurrency)) {
1539 $currencybalance[$cpt->currency]['available'] = $cpt->amount / 100;
1540 } else {
1541 $currencybalance[$cpt->currency]['available'] = $cpt->amount;
1542 }
1543 $currencybalance[$cpt->currency]['currency'] = $cpt->currency;
1544 }
1545 }
1546
1547 if (is_array($balance->pending) && count($balance->pending)) {
1548 foreach ($balance->pending as $cpt) {
1549 $arrayzerounitcurrency = array('BIF', 'CLP', 'DJF', 'GNF', 'JPY', 'KMF', 'KRW', 'MGA', 'PYG', 'RWF', 'VND', 'VUV', 'XAF', 'XOF', 'XPF');
1550 if (!in_array($cpt->currency, $arrayzerounitcurrency)) {
1551 $currencybalance[$cpt->currency]['pending'] = $currencybalance[$cpt->currency]['available'] + $cpt->amount / 100;
1552 } else {
1553 $currencybalance[$cpt->currency]['pending'] = $currencybalance[$cpt->currency]['available'] + $cpt->amount;
1554 }
1555 }
1556 }
1557
1558 if (is_array($currencybalance)) {
1559 foreach ($currencybalance as $cpt_arr) {
1560 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>';
1561 }
1562 }
1563
1564 print '</table>';
1565 print '<br>';
1566 }
1567
1568
1569 // List of bank accounts
1570 if ($permissiontoaddupdatepaymentinformation) {
1571 $morehtmlright = dolGetButtonTitle($langs->trans('Add'), '', 'fa fa-plus-circle', $_SERVER["PHP_SELF"] . '?socid=' . $object->id . '&action=create');
1572 }
1573
1574 print load_fiche_titre($langs->trans("BankAccounts"), $morehtmlright, 'bank');
1575
1576 $nblocal = 0;
1577 $nbremote = 0;
1578 $arrayofremoteban = array();
1579
1580 $rib_list = $object->get_all_rib();
1581
1582 if (is_array($rib_list)) {
1583 print '<!-- List of bank accounts -->'."\n";
1584 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
1585 print '<table class="liste centpercent noborder">';
1586
1587 print '<tr class="liste_titre">';
1588 print_liste_field_titre("Label");
1589 print_liste_field_titre($form->textwithpicto($langs->trans('ExternalSystemID'), $langs->trans("IDOfPaymentInAnExternalSystem"))); // external system ID
1590 //print_liste_field_titre("Bank");
1594 if (isModEnabled('prelevement')) {
1596 print_liste_field_titre("DateRUM");
1597 }
1598 print_liste_field_titre("Default", '', '', '', '', '', '', '', 'center ');
1599 if (!getDolGlobalInt('SOCIETE_DISABLE_BANKACCOUNT') && getDolGlobalInt("SOCIETE_RIB_ALLOW_ONLINESIGN")) {
1600 print_liste_field_titre('', '', '', '', '', '', '', '', 'center ');
1601 }
1602 print_liste_field_titre('', '', '', '', '', '', '', '', 'center ');
1603 // Fields from hook
1604 $parameters = array('arrayfields' => array(), 'linetype' => 'stripebantitle');
1605 $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters, $object); // Note that $action and $object may have been modified by hook
1606 print $hookmanager->resPrint;
1607 print_liste_field_titre('', $_SERVER["PHP_SELF"], "", '', '', '', '', '', 'maxwidthsearch ');
1608 print "</tr>\n";
1609
1610 // List of local BAN
1611 foreach ($rib_list as $rib) {
1612 $arrayofremoteban[$rib->stripe_card_ref] = $rib->stripe_card_ref;
1613
1614 $nblocal++;
1615
1616 print '<tr class="oddeven">';
1617 // Label
1618 print '<td class="tdoverflowmax150" title="'.dolPrintHTMLForAttribute($rib->label).'">'.dolPrintHTML($rib->label);
1619 print '<br><span class="opacitymedium">'.dolPrintHTML($rib->bank).'</span>';
1620 print '</td>';
1621
1622 // External system ID
1623 print '<td class="tdoverflowmax150" title="'.dol_escape_htmltag($rib->stripe_card_ref.(empty($rib->stripe_account) ? '' : ' - '.$rib->stripe_account)).'">';
1624 if (!empty($rib->stripe_card_ref) && !empty($rib->ext_payment_site)) {
1625 if (isModEnabled('stripe') && in_array($rib->ext_payment_site, array('StripeTest', 'StripeLive'))) {
1626 $connect = '';
1627 if (!empty($stripeacc)) {
1628 $connect = $stripeacc.'/';
1629 }
1630 if ($rib->ext_payment_site == 'StripeLive') {
1631 $url = 'https://dashboard.stripe.com/'.$connect.'search?query='.$rib->stripe_card_ref;
1632 } else {
1633 $url = 'https://dashboard.stripe.com/'.$connect.'test/search?query='.$rib->stripe_card_ref;
1634 }
1635 print "<a href='".$url."' target='_stripe'>".img_picto($langs->trans('ShowInStripe'), 'globe')."</a> ";
1636 }
1637 // TODO Add hook here for other payment services
1638 }
1639 print dol_escape_htmltag($rib->stripe_card_ref);
1640 print '</td>';
1641
1642 // Bank name
1643 //print '<td class="tdoverflowmax100" title="'.dol_escape_htmltag($rib->bank).'">'.dol_escape_htmltag($rib->bank).'</td>';
1644
1645 // Account number
1646 $string = '';
1647 foreach ($rib->getFieldsToShow() as $val) {
1648 if ($val == 'BankCode') {
1649 $string .= $rib->code_banque.' ';
1650 } elseif ($val == 'BankAccountNumber') {
1651 $string .= $rib->number.' ';
1652 } elseif ($val == 'DeskCode') {
1653 $string .= $rib->code_guichet.' ';
1654 } elseif ($val == 'BankAccountNumberKey') {
1655 $string .= $rib->cle_rib.' ';
1656 }
1657 // Already output after
1658 // } elseif ($val == 'BIC') {
1659 // $string .= $rib->bic.' ';
1660 // } elseif ($val == 'IBAN') {
1661 // $string .= $rib->iban.' ';*/
1662 //}
1663 if (!empty($rib->label) && $rib->number) {
1664 if (!checkBanForAccount($rib)) {
1665 $string .= img_picto($langs->trans("ValueIsNotValid"), 'warning', 'class="pictofixedwidth"').$string;
1666 } else {
1667 $string .= img_picto($langs->trans("ValueIsValid"), 'info', 'class="pictofixedwidth"').$string;
1668 }
1669 }
1670 } // EndFor $rib_list as $rib
1671 print '<td class="tdoverflowmax150" title="'.dol_escape_htmltag($string).'">';
1672 print $string;
1673 print '</td>';
1674
1675 // IBAN
1676 print '<td class="tdoverflowmax100" title="'.dol_escape_htmltag($rib->iban).'">';
1677 if (!empty($rib->iban)) {
1678 if (!checkIbanForAccount($rib)) {
1679 print img_picto($langs->trans("IbanNotValid"), 'warning').' ';
1680 }
1681 }
1682 print dol_escape_htmltag($rib->iban);
1683 print '</td>';
1684 // BIC
1685 print '<td>';
1686 if (!empty($rib->bic)) {
1687 if (!checkSwiftForAccount($rib)) {
1688 print img_picto($langs->trans("SwiftNotValid"), 'warning').' ';
1689 }
1690 }
1691 print dol_escape_htmltag($rib->bic);
1692 print '</td>';
1693
1694 if (isModEnabled('prelevement')) {
1695 // RUM
1696 print '<td class="tdoverflowmax100 small" title="'.dolPrintHTMLForAttribute($rib->rum).'">'.dolPrintHTML($rib->rum);
1697 print '<br><span class="opacitymedium">'.dolPrintHTML($rib->frstrecur).'</span>'; // FRST or RCUR
1698 print '</td>';
1699
1700 // Date
1701 print '<td>'.dol_print_date($rib->date_rum, 'day').'</td>';
1702 }
1703
1704 // Default
1705 print '<td class="center" width="70">';
1706 if (!$rib->default_rib) {
1707 print '<a href="'.$_SERVER["PHP_SELF"].'?socid='.((int) $object->id).'&ribid='.((int) $rib->id).'&action=setasbankdefault&token='.newToken().'">';
1708 print img_picto($langs->trans("Disabled"), 'off');
1709 print '</a>';
1710 } else {
1711 print img_picto($langs->trans("Enabled"), 'on');
1712 }
1713 print '</td>';
1714
1715 // Generate doc
1716 print '<td class="center">';
1717
1718 $buttonlabel = $langs->trans("BuildDoc");
1719 $forname = 'builddocrib'.$rib->id;
1720
1721 include_once DOL_DOCUMENT_ROOT.'/core/modules/bank/modules_bank.php';
1722 $modellist = ModeleBankAccountDoc::liste_modeles($db);
1723
1724 $out = '';
1725 if (is_array($modellist) && count($modellist)) {
1726 $out .= '<form action="'.$_SERVER["PHP_SELF"].(!getDolGlobalString('MAIN_JUMP_TAG') ? '' : '#builddoc').'" name="'.$forname.'" id="'.$forname.'_form" method="post">';
1727 $out .= '<input type="hidden" name="action" value="builddocrib">';
1728 $out .= '<input type="hidden" name="token" value="'.newToken().'">';
1729 $out .= '<input type="hidden" name="socid" value="'.$object->id.'">';
1730 $out .= '<input type="hidden" name="companybankid" value="'.$rib->id.'">';
1731
1732 $modelselected = '';
1733 if (count($modellist) == 1) { // If there is only one element
1734 $arraykeys = array_keys($modellist);
1735 $modelselected = $arraykeys[0];
1736 }
1737 if (getDolGlobalString('BANKADDON_PDF')) {
1738 $modelselected = getDolGlobalString('BANKADDON_PDF');
1739 }
1740
1741 $morecss = 'maxwidth125';
1742 if ($conf->browser->layout == 'phone') {
1743 $morecss = 'maxwidth100';
1744 }
1745
1746 $out .= $form->selectarray('modelrib'.$rib->id, $modellist, $modelselected, 1, 0, 0, '', 0, 0, 0, '', 'minwidth100 '.$morecss);
1747 $out .= ajax_combobox('modelrib'.$rib->id);
1748
1749 // Language code (if multilang)
1750 if (getDolGlobalInt('MAIN_MULTILANGS')) {
1751 include_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php';
1752 $formadmin = new FormAdmin($db);
1753 $defaultlang = $langs->getDefaultLang();
1754 $out .= $formadmin->select_language($defaultlang, 'lang_idrib'.$rib->id, 0, array(), 0, 0, 0, $morecss);
1755 }
1756 // Button
1757 $out .= '<input class="button buttongen reposition nomargintop nomarginbottom small '.$morecss.'" id="'.$forname.'_generatebutton" name="'.$forname.'_generatebutton"';
1758 $out .= ' type="submit" value="'.$buttonlabel.'"';
1759 $out .= '>';
1760 $out .= '</form>';
1761 }
1762 print $out;
1763 print '</td>';
1764
1765 // Fields from hook
1766 $parameters = array('arrayfields' => array(), 'stripe_card_ref' => $rib->stripe_card_ref, 'stripe_account' => $rib->stripe_account, 'linetype' => 'stripeban');
1767 $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters, $object); // Note that $action and $object may have been modified by hook
1768 print $hookmanager->resPrint;
1769
1770 // Show online signature link
1771 if (!getDolGlobalInt('SOCIETE_DISABLE_BANKACCOUNT') && getDolGlobalInt("SOCIETE_RIB_ALLOW_ONLINESIGN")) {
1772 print '<td class="minwidth200 width200">';
1773 $useonlinesignature = 1;
1774 if ($useonlinesignature) {
1775 $rib->entity = $object->entity; //Assign $rib->entity necessary for a valid multicompany hash
1776 require_once DOL_DOCUMENT_ROOT . '/core/lib/signature.lib.php';
1777 print showOnlineSignatureUrl($companybankaccount->element, (string) $rib->id, $rib, 'short');
1778 }
1779 print '</td>';
1780 }
1781
1782 // Edit/Delete
1783 print '<td class="right nowraponall">';
1784 if ($permissiontoaddupdatepaymentinformation) {
1785 if (isModEnabled('stripe')) {
1786 if (empty($rib->stripe_card_ref)) {
1787 if ($object->client) {
1788 // Add link to create BAN on Stripe
1789 print '<a class="editfielda marginrightonly marginleftonly" href="'.$_SERVER["PHP_SELF"].'?socid='.$object->id.'&id='.$rib->id.'&action=syncsepatostripe&token='.newToken().'">';
1790 print img_picto($langs->trans("CreateBANOnStripe"), 'stripe');
1791 print '</a>';
1792 } else {
1793 print '<span class="opacitymedium marginrightonly marginleftonly">';
1794 print img_picto($langs->trans("ThirdPartyMustBeACustomerToCreateBANOnStripe"), 'stripe');
1795 print '</span>';
1796 }
1797 }
1798 }
1799
1800 print '<a class="editfielda marginrightonly marginleftonly" href="'.$_SERVER["PHP_SELF"].'?socid='.$object->id.'&id='.$rib->id.'&action=edit">';
1801 print img_picto($langs->trans("Modify"), 'edit');
1802 print '</a>';
1803
1804 print '<a class="marginrightonly marginleftonly reposition" href="'.$_SERVER["PHP_SELF"].'?socid='.$object->id.'&id='.$rib->id.'&action=deletebank&token='.newToken().'">';
1805 print img_picto($langs->trans("Delete"), 'delete');
1806 print '</a>';
1807 }
1808 print '</td>';
1809
1810 print '</tr>';
1811 }
1812
1813
1814 // List of remote BAN (if not already added as local)
1815 foreach ($listofsources as $src) {
1816 if (!empty($arrayofremoteban[$src->id])) {
1817 continue; // Already in previous list
1818 }
1819
1820 $imgline = '';
1821 if ($src->object == 'source' && $src->type == 'sepa_debit') {
1822 $imgline = '<span class="fa fa-university fa-2x fa-fw"></span>';
1823 } elseif ($src->object == 'payment_method' && $src->type == 'sepa_debit') {
1824 $imgline = '<span class="fa fa-university fa-2x fa-fw"></span>';
1825 } else {
1826 continue;
1827 }
1828
1829 $nbremote++;
1830
1831 print '<tr class="oddeven">';
1832 // Label
1833 print '<td>';
1834 print '</td>';
1835 // External ID
1836 print '<td class="tdoverflowmax150">';
1837 $connect = '';
1838 if (!empty($stripeacc)) {
1839 $connect = $stripeacc.'/';
1840 }
1841 //$url='https://dashboard.stripe.com/'.$connect.'test/sources/'.$src->id;
1842 $url = 'https://dashboard.stripe.com/'.$connect.'test/search?query='.$src->id;
1843 if ($servicestatus) {
1844 //$url='https://dashboard.stripe.com/'.$connect.'sources/'.$src->id;
1845 $url = 'https://dashboard.stripe.com/'.$connect.'search?query='.$src->id;
1846 }
1847 print "<a href='".$url."' target='_stripe'>".img_picto($langs->trans('ShowInStripe'), 'globe')."</a> ";
1848 print $src->id;
1849 print '</td>';
1850 // Bank
1851 /*
1852 print '<td>';
1853 print '</td>';
1854 */
1855 // Account number
1856 print '<td>';
1857 print '</td>';
1858 // IBAN
1859 print '<td>';
1860 //var_dump($src);
1861 print '</td>';
1862 // BIC
1863 print '<td>';
1864 //var_dump($src);
1865 print '</td>';
1866
1867 if (isModEnabled('prelevement')) {
1868 // RUM
1869 print '<td>';
1870 print '</td>';
1871
1872 // Date
1873 print '<td>';
1874 print '</td>';
1875 }
1876
1877 // Default
1878 print '<td class="center" width="50">';
1879 if ((empty($customerstripe->invoice_settings) && $customerstripe->default_source != $src->id) ||
1880 (!empty($customerstripe->invoice_settings) && $customerstripe->invoice_settings->default_payment_method != $src->id)) {
1881 print '<a href="'.DOL_URL_ROOT.'/societe/paymentmodes.php?socid='.$object->id.'&source='.$src->id.'&action=setassourcedefault&token='.newToken().'">';
1882 print img_picto($langs->trans("Default"), 'off');
1883 print '</a>';
1884 } else {
1885 print img_picto($langs->trans("Default"), 'on');
1886 }
1887 print '</td>';
1888
1889 // Doc gen
1890 print '<td>';
1891 print '</td>';
1892
1893 // Online sign
1894 if (!getDolGlobalInt('SOCIETE_DISABLE_BANKACCOUNT') && getDolGlobalInt("SOCIETE_RIB_ALLOW_ONLINESIGN")) {
1895 print '<td>';
1896 print '</td>';
1897 }
1898
1899 // Fields from hook
1900 // TODO: No longer in foreach -> using last rib of for each which may be undeclared!
1901 $parameters = array('arrayfields' => array(), 'stripe_card_ref' => $rib->stripe_card_ref, 'stripe_account' => $rib->stripe_account, 'linetype' => 'stripebanremoteonly');
1902 $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters, $object); // Note that $action and $object may have been modified by hook
1903 print $hookmanager->resPrint;
1904
1905 // Action column
1906 print '<td class="right nowraponall">';
1907 if ($permissiontoaddupdatepaymentinformation) {
1908 print '<a class="marginleftonly marginrightonly reposition" href="'.DOL_URL_ROOT.'/societe/paymentmodes.php?socid='.$object->id.'&source='.$src->id.'&action=deletebank&token='.newToken().'">';
1909 print img_picto($langs->trans("Delete"), 'delete');
1910 print '</a>';
1911 }
1912 print '</td>';
1913
1914 print '</tr>';
1915 }
1916
1917 if ($nbremote == 0 && $nblocal == 0) {
1918 $colspan = 10;
1919 if (isModEnabled('prelevement')) {
1920 $colspan += 2;
1921 }
1922 if (!getDolGlobalInt('SOCIETE_DISABLE_BANKACCOUNT') && getDolGlobalInt("SOCIETE_RIB_ALLOW_ONLINESIGN")) {
1923 $colspan++;
1924 }
1925 print '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("NoBANRecord").'</span></td></tr>';
1926 }
1927
1928 print '</table>';
1929 print '</div>';
1930 } else {
1931 dol_print_error($db);
1932 }
1933
1934 //Hook to display your print listing (list of CB card from Stancer Plugin for example)
1935 $parameters = array('arrayfields' => array(), 'param' => '', 'sortfield' => '', 'sortorder' => '', 'linetype' => '');
1936 $reshook = $hookmanager->executeHooks('printNewTable', $parameters, $object);
1937 print $hookmanager->resPrint;
1938
1939 if (!getDolGlobalString('SOCIETE_DISABLE_BUILDDOC')) {
1940 print '<br>';
1941
1942 print '<div class="fichecenter"><div class="fichehalfleft">';
1943 print '<a name="builddoc"></a>'; // ancre
1944
1945 /*
1946 * Generated documents
1947 */
1948 $filedir = $conf->societe->multidir_output[$object->entity ?? $conf->entity].'/'.$object->id;
1949 $urlsource = $_SERVER["PHP_SELF"]."?socid=".$object->id;
1950
1951 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);
1952
1953 // Show direct download link
1954 if (getDolGlobalString('BANK_ACCOUNT_ALLOW_EXTERNAL_DOWNLOAD')) {
1955 $companybankaccounttemp = new CompanyBankAccount($db);
1956 $companypaymentmodetemp = new CompanyPaymentMode($db);
1957 // @phan-suppress-next-line PhanPluginSuspiciousParamPosition
1958 $result = $companypaymentmodetemp->fetch(0, '', $object->id, 'ban');
1959
1960 include_once DOL_DOCUMENT_ROOT.'/ecm/class/ecmfiles.class.php';
1961 $ecmfile = new EcmFiles($db);
1962 // @phan-suppress-next-line PhanPluginSuspiciousParamPosition
1963 $result = $ecmfile->fetch(0, '', '', '', '', $companybankaccounttemp->table_element, $companypaymentmodetemp->id);
1964 if ($result > 0) {
1965 $companybankaccounttemp->last_main_doc = $ecmfile->filepath.'/'.$ecmfile->filename;
1966 print '<br><!-- Link to download main doc -->'."\n";
1967 print showDirectDownloadLink($companybankaccounttemp).'<br>';
1968 }
1969 }
1970
1971 print '</div><div class="fichehalfright">';
1972
1973
1974 print '</div></div>';
1975
1976 print '<br>';
1977 }
1978 /*
1979 include_once DOL_DOCUMENT_ROOT.'/core/modules/bank/modules_bank.php';
1980 $modellist=ModeleBankAccountDoc::liste_modeles($db);
1981 //print '<td>';
1982 if (is_array($modellist) && count($modellist) == 1) // If there is only one element
1983 {
1984 $arraykeys=array_keys($modellist);
1985 $modelselected=$arraykeys[0];
1986 }
1987 $out.= $form->selectarray('model', $modellist, $modelselected, 0, 0, 0, '', 0, 0, 0, '', 'minwidth100');
1988 $out.= ajax_combobox('model');
1989 //print $out;
1990 $buttonlabel=$langs->trans("Generate");
1991 $genbutton = '<input class="button buttongen reposition nomargintop nomarginbottom" id="'.$forname.'_generatebutton" name="'.$forname.'_generatebutton"';
1992 $genbutton.= ' type="submit" value="'.$buttonlabel.'"';
1993 $genbutton.= '>';
1994 print $genbutton;
1995 //print '</td>'; // TODO Add link to generate doc
1996 */
1997}
1998
1999// Edit BAN
2000if ($socid && $action == 'edit' && $permissiontoaddupdatepaymentinformation) {
2001 print dol_get_fiche_head($head, 'rib', $langs->trans("ThirdParty"), 0, 'company');
2002
2003 $linkback = '<a href="'.DOL_URL_ROOT.'/societe/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
2004
2005 dol_banner_tab($object, 'socid', $linkback, ($user->socid ? 0 : 1), 'rowid', 'nom');
2006
2007 print '<div class="underbanner clearboth"></div>';
2008
2009 print '<br>';
2010
2011 print '<div class="div-table-responsive-no-min">';
2012 print '<table class="border tableforfield centpercent">';
2013
2014 print '<tr><td class="titlefield fieldrequired">'.$langs->trans("Label").'</td>';
2015 print '<td><input class="minwidth300" type="text" name="label" value="'.$companybankaccount->label.'"></td></tr>';
2016
2017 $required = (getDolGlobalInt('WITHDRAWAL_WITHOUT_BIC') == 0) ? "fieldrequired" : "";
2018 print '<tr><td class="'.$required.'">'.$langs->trans("BankName").'</td>';
2019 print '<td><input class="minwidth200" type="text" name="bank" value="'.$companybankaccount->bank.'"></td></tr>';
2020
2021 // Show fields of bank account
2022 $bankaccount = $companybankaccount;
2023 // Code here is similar as in bank.php for users
2024 foreach ($bankaccount->getFieldsToShow(1) as $val) {
2025 $require = false;
2026 $tooltip = '';
2027 $name = 'Unset';
2028 $size = 8;
2029 $content = 'NoContent';
2030 if ($val == 'BankCode') {
2031 $name = 'code_banque';
2032 $size = 8;
2033 $content = $bankaccount->code_banque;
2034 } elseif ($val == 'DeskCode') {
2035 $name = 'code_guichet';
2036 $size = 8;
2037 $content = $bankaccount->code_guichet;
2038 } elseif ($val == 'BankAccountNumber') {
2039 $name = 'number';
2040 $size = 18;
2041 $content = $bankaccount->number;
2042 } elseif ($val == 'BankAccountNumberKey') {
2043 $name = 'cle_rib';
2044 $size = 3;
2045 $content = $bankaccount->cle_rib;
2046 } elseif ($val == 'IBAN') {
2047 $name = 'iban';
2048 $size = 30;
2049 $content = $bankaccount->iban;
2050 if ($bankaccount->needIBAN()) {
2051 $require = true;
2052 }
2053 $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';
2054 } elseif ($val == 'BIC') {
2055 $name = 'bic';
2056 $size = 12;
2057 $content = $bankaccount->bic;
2058 if ($bankaccount->needBIC() && (getDolGlobalInt('WITHDRAWAL_WITHOUT_BIC') == 0)) {
2059 $require = true;
2060 }
2061 $tooltip = $langs->trans("Example").': LIABLT2XXXX';
2062 }
2063
2064 print '<tr>';
2065 print '<td'.($require ? ' class="fieldrequired" ' : '').'>';
2066 if ($tooltip) {
2067 // $tooltip looks like $tooltiptrigger so: @phan-suppress-next-line PhanPluginSuspiciousParamOrder
2068 print $form->textwithpicto($langs->trans($val), $tooltip, 4, 'help', '', 0, 3, $name);
2069 } else {
2070 print $langs->trans($val);
2071 }
2072 print '</td>';
2073 print '<td><input size="'.$size.'" type="text" class="flat" name="'.$name.'" value="'.$content.'"></td>';
2074 print '</tr>';
2075 }
2076
2077 print '<tr><td class="tdtop">'.$langs->trans("BankAccountDomiciliation").'</td><td>';
2078 print '<textarea name="address" rows="'.ROWS_4.'" cols="40" maxlength="255" spellcheck="false">';
2079 print $companybankaccount->address;
2080 print "</textarea></td></tr>";
2081
2082 print '<tr><td>'.$langs->trans("BankAccountOwner").'</td>';
2083 print '<td><input class="minwidth300" type="text" name="proprio" value="'.$companybankaccount->owner_name.'"></td></tr>';
2084 print "</td></tr>\n";
2085
2086 print '<tr><td class="tdtop">'.$langs->trans("BankAccountOwnerAddress").'</td><td>';
2087 print '<textarea name="owner_address" rows="'.ROWS_4.'" cols="40" maxlength="255" spellcheck="false">';
2088 print $companybankaccount->owner_address;
2089 print "</textarea></td></tr>";
2090
2091 print '</table>';
2092 print '</div>';
2093
2094 if (isModEnabled('prelevement')) {
2095 print '<hr>';
2096
2097 print '<div class="div-table-responsive-no-min">';
2098 print '<table class="border tableforfield centpercent">';
2099
2100 if (empty($companybankaccount->rum)) {
2101 $companybankaccount->rum = $prelevement->buildRumNumber($object->code_client, $companybankaccount->datec, (string) $companybankaccount->id);
2102 }
2103
2104 // Title
2105 print '<tr><td class="titlefieldcreate" colspan="5">'.$langs->trans("WithdrawalsSetup").'</td></tr>';
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 tableforfield 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 '<hr>';
2277
2278 print '<div class="div-table-responsive-no-min">';
2279 print '<table class="border tableforfield centpercent">';
2280
2281 // Title
2282 print '<tr><td class="titlefieldcreate" colspan="5">'.$langs->trans("WithdrawalsSetup").'</td></tr>';
2283
2284 // RUM
2285 print '<tr><td class="titlefieldcreate">'.$form->textwithpicto($langs->trans("RUM"), $langs->trans("RUMLong").'<br>'.$langs->trans("RUMWillBeGenerated")).'</td>';
2286 print '<td colspan="4"><input type="text" class="minwidth300" name="rum" value="'.GETPOST('rum', 'alpha').'"></td></tr>';
2287
2288 $date_rum = GETPOSTDATE('date_rum', '00:00:00');
2289
2290 print '<tr><td class="titlefieldcreate">'.$langs->trans("DateRUM").'</td>';
2291 print '<td colspan="4">'.$form->selectDate($date_rum, 'date_rum', 0, 0, 1, 'date_rum', 1, 1).'</td></tr>';
2292
2293 print '<tr><td>'.$langs->trans("WithdrawMode").'</td><td>';
2294 $tblArraychoice = array("FRST" => $langs->trans("FRST"), "RCUR" => $langs->trans("RECUR"));
2295 print $form->selectarray("frstrecur", $tblArraychoice, (GETPOSTISSET('frstrecur') ? GETPOST('frstrecur') : 'FRST'), 0);
2296 print '</td></tr>';
2297
2298 print '<tr><td>'.$langs->trans("ExternalSystemID")." ('src_....')</td>";
2299 print '<td><input class="minwidth300" type="text" name="stripe_card_ref" value="'.GETPOST('stripe_card_ref', 'alpha').'"></td></tr>';
2300
2301 print '</table>';
2302 print '</div>';
2303 }
2304
2305 print '</div>';
2306
2307 print dol_get_fiche_end();
2308
2309 dol_set_focus('#bank');
2310
2311 print $form->buttonsSaveCancel("Add");
2312}
2313
2314// Create Card
2315if ($socid && $action == 'createcard' && $permissiontoaddupdatepaymentinformation) {
2316 print dol_get_fiche_head($head, 'rib', $langs->trans("ThirdParty"), 0, 'company');
2317
2318 $linkback = '<a href="'.DOL_URL_ROOT.'/societe/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
2319
2320 dol_banner_tab($object, 'socid', $linkback, ($user->socid ? 0 : 1), 'rowid', 'nom');
2321
2322 print '<div class="nofichecenter">';
2323
2324 print '<div class="underbanner clearboth"></div>';
2325
2326 print '<br>';
2327
2328 print '<div class="div-table-responsive-no-min">';
2329 print '<table class="border centpercent">';
2330
2331 print '<tr><td class="titlefieldcreate fieldrequired">'.$langs->trans("Label").'</td>';
2332 print '<td><input class="minwidth200" type="text" id="label" name="label" value="'.GETPOST('label', 'alpha').'"></td></tr>';
2333
2334 print '<tr><td class="fieldrequired">'.$langs->trans("NameOnCard").'</td>';
2335 print '<td><input class="minwidth200" type="text" name="proprio" value="'.GETPOST('proprio', 'alpha').'"></td></tr>';
2336
2337 print '<tr><td>'.$langs->trans("CardNumber").'</td>';
2338 print '<td><input class="minwidth200" type="text" name="cardnumber" value="'.GETPOST('cardnumber', 'alpha').'"></td></tr>';
2339
2340 print '<tr><td class="fieldrequired">'.$langs->trans("ExpiryDate").'</td>';
2341 print '<td>';
2342 print $formother->select_month((string) GETPOSTINT('exp_date_month'), 'exp_date_month', 1);
2343 print $formother->selectyear((string) GETPOSTINT('exp_date_year'), 'exp_date_year', 1, 5, 10, 0, 0, '', 'marginleftonly');
2344 print '</td></tr>';
2345
2346 print '<tr><td>'.$langs->trans("CVN").'</td>';
2347 print '<td><input class="width50" type="text" name="cvn" value="'.GETPOST('cvn', 'alpha').'"></td></tr>';
2348
2349 print '<tr><td>'.$langs->trans("ExternalSystemID")." ('card_....')</td>";
2350 print '<td><input class="minwidth300" type="text" name="stripe_card_ref" value="'.GETPOST('stripe_card_ref', 'alpha').'"></td></tr>';
2351
2352 print '</table>';
2353 print '</div>';
2354
2355 print '</div>';
2356
2357 print dol_get_fiche_end();
2358
2359 dol_set_focus('#label');
2360
2361 print $form->buttonsSaveCancel("Add");
2362}
2363
2364if ($socid && ($action == 'edit' || $action == 'editcard') && $permissiontoaddupdatepaymentinformation) {
2365 print '</form>';
2366}
2367if ($socid && ($action == 'create' || $action == 'createcard') && $permissiontoaddupdatepaymentinformation) {
2368 print '</form>';
2369}
2370
2371// End of page
2372llxFooter();
2373$db->close();
$id
Support class for third parties, contacts, members, users or resources.
Definition account.php:47
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
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:380
checkBanForAccount($account)
Check account number information for a bank account.
Definition bank.lib.php:423
checkSwiftForAccount($account=null, $swift=null)
Check SWIFT information for a bank account.
Definition bank.lib.php:359
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.
dol_now($mode='gmt')
Return date for now.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
img_credit_card($brand, $morecss='fa-2x inline-block valignmiddle')
Return image of a credit card according to its brand name.
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.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0, $allowdash=0)
Clean a string to use it as a file name.
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.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
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.
dol_clone($srcobject, $native=2)
Create a clone of instance of object (new instance with same value for each properties) With native =...
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
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_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition repair.php:135
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.