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