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