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