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