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