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