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