32 require
'../main.inc.php';
33 require_once DOL_DOCUMENT_ROOT.
'/core/lib/company.lib.php';
34 require_once DOL_DOCUMENT_ROOT.
'/core/lib/bank.lib.php';
35 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formfile.class.php';
36 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formother.class.php';
37 require_once DOL_DOCUMENT_ROOT.
'/societe/class/companybankaccount.class.php';
38 require_once DOL_DOCUMENT_ROOT.
'/societe/class/companypaymentmode.class.php';
39 require_once DOL_DOCUMENT_ROOT.
'/societe/class/societeaccount.class.php';
40 require_once DOL_DOCUMENT_ROOT.
'/compta/prelevement/class/bonprelevement.class.php';
41 require_once DOL_DOCUMENT_ROOT.
'/stripe/class/stripe.class.php';
43 $langs->loadLangs(array(
"companies",
"commercial",
"banks",
"bills",
'paypal',
'stripe',
'withdrawals'));
46 $socid =
GETPOST(
"socid",
"int");
48 $socid = $user->socid;
53 $source =
GETPOST(
"source",
"alpha");
54 $ribid =
GETPOST(
"ribid",
"int");
55 $action =
GETPOST(
"action",
'alpha', 3);
56 $cancel =
GETPOST(
'cancel',
'alpha');
59 $object->fetch($socid);
68 $extrafields->fetch_name_optionals_label($object->table_element);
71 $hookmanager->initHooks(array(
'thirdpartybancard',
'globalcard'));
73 $permissiontoread = $user->rights->societe->lire;
74 $permissiontoadd = $user->rights->societe->creer;
76 $permissiontoaddupdatepaymentinformation = ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && $permissiontoadd) || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->societe->thirdparty_paymentinformation_advance->write)));
78 if (!empty($conf->stripe->enabled)) {
79 $service =
'StripeTest';
81 if (!empty($conf->global->STRIPE_LIVE) && !
GETPOST(
'forcesandbox',
'alpha')) {
82 $service =
'StripeLive';
87 global $stripearrayofkeysbyenv;
88 $site_account = $stripearrayofkeysbyenv[$servicestatus][
'publishable_key'];
91 $stripeacc = $stripe->getStripeAccount($service);
92 $stripecu = $stripe->getStripeCustomerAccount($object->id, $servicestatus, $site_account);
105 $parameters = array(
'id'=>$socid);
106 $reshook = $hookmanager->executeHooks(
'doActions', $parameters, $object, $action);
111 if (empty($reshook)) {
114 if (!empty($backtopage)) {
115 header(
"Location: ".$backtopage);
120 if ($action ==
'update') {
123 if (!
GETPOST(
'label',
'alpha')) {
124 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Label")),
null,
'errors');
126 if (!
GETPOST(
'bank',
'alpha')) {
127 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"BankName")),
null,
'errors');
132 $companybankaccount->fetch($id);
133 if ($companybankaccount->needIBAN() == 1) {
135 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"IBAN")),
null,
'errors');
140 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"BIC")),
null,
'errors');
147 $companybankaccount->socid = $object->id;
149 $companybankaccount->bank =
GETPOST(
'bank',
'alpha');
150 $companybankaccount->label =
GETPOST(
'label',
'alpha');
151 $companybankaccount->courant =
GETPOST(
'courant',
'alpha');
152 $companybankaccount->clos =
GETPOST(
'clos',
'alpha');
153 $companybankaccount->code_banque =
GETPOST(
'code_banque',
'alpha');
154 $companybankaccount->code_guichet =
GETPOST(
'code_guichet',
'alpha');
155 $companybankaccount->number =
GETPOST(
'number',
'alpha');
156 $companybankaccount->cle_rib =
GETPOST(
'cle_rib',
'alpha');
157 $companybankaccount->bic =
GETPOST(
'bic',
'alpha');
158 $companybankaccount->iban =
GETPOST(
'iban',
'alpha');
159 $companybankaccount->domiciliation =
GETPOST(
'domiciliation',
'alpha');
160 $companybankaccount->proprio =
GETPOST(
'proprio',
'alpha');
161 $companybankaccount->owner_address =
GETPOST(
'owner_address',
'alpha');
162 $companybankaccount->frstrecur =
GETPOST(
'frstrecur',
'alpha');
163 $companybankaccount->rum =
GETPOST(
'rum',
'alpha');
165 if (empty($companybankaccount->rum)) {
166 $companybankaccount->rum = $prelevement->buildRumNumber($object->code_client, $companybankaccount->datec, $companybankaccount->id);
169 $result = $companybankaccount->update($user);
171 setEventMessages($companybankaccount->error, $companybankaccount->errors,
'errors');
174 if ($companybankaccount->default_rib) {
175 $companybankaccount->setAsDefault($id);
178 $url = $_SERVER[
"PHP_SELF"].
'?socid='.$object->id;
179 header(
'Location: '.$url);
185 if ($action ==
'updatecard') {
187 if (!
GETPOST(
'label',
'alpha') || !
GETPOST(
'proprio',
'alpha') || !
GETPOST(
'exp_date_month',
'alpha') || !
GETPOST(
'exp_date_year',
'alpha')) {
188 if (!
GETPOST(
'label',
'alpha')) {
189 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Label")),
null,
'errors');
191 if (!
GETPOST(
'proprio',
'alpha')) {
192 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"NameOnCard")),
null,
'errors');
195 if (!(
GETPOST(
'exp_date_month',
'alpha') > 0) || !(
GETPOST(
'exp_date_year',
'alpha') > 0)) {
196 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"ExpiryDate")),
null,
'errors');
199 $action =
'createcard';
203 $companypaymentmode->fetch($id);
205 $companypaymentmode->fk_soc = $object->id;
207 $companypaymentmode->bank =
GETPOST(
'bank',
'alpha');
208 $companypaymentmode->label =
GETPOST(
'label',
'alpha');
209 $companypaymentmode->number =
GETPOST(
'cardnumber',
'alpha');
210 $companypaymentmode->last_four = substr(
GETPOST(
'cardnumber',
'alpha'), -4);
211 $companypaymentmode->proprio =
GETPOST(
'proprio',
'alpha');
212 $companypaymentmode->exp_date_month =
GETPOST(
'exp_date_month',
'int');
213 $companypaymentmode->exp_date_year =
GETPOST(
'exp_date_year',
'int');
214 $companypaymentmode->cvn =
GETPOST(
'cvn',
'alpha');
215 $companypaymentmode->country_code = $object->country_code;
217 if (
GETPOST(
'stripe_card_ref',
'alpha') &&
GETPOST(
'stripe_card_ref',
'alpha') != $companypaymentmode->stripe_card_ref) {
219 $companypaymentmode->stripe_account = $stripecu.
'@'.$site_account;
221 $companypaymentmode->stripe_card_ref =
GETPOST(
'stripe_card_ref',
'alpha');
223 $result = $companypaymentmode->update($user);
225 setEventMessages($companypaymentmode->error, $companypaymentmode->errors,
'errors');
228 if ($companypaymentmode->default_rib) {
229 $companypaymentmode->setAsDefault($id);
232 $url = $_SERVER[
"PHP_SELF"].
'?socid='.$object->id;
233 header(
'Location: '.$url);
239 if ($action ==
'add') {
243 if (!
GETPOST(
'label',
'alpha')) {
244 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Label")),
null,
'errors');
246 if (!
GETPOST(
'bank',
'alpha')) {
247 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"BankName")),
null,
'errors');
257 $companybankaccount->socid = $object->id;
259 $companybankaccount->bank =
GETPOST(
'bank',
'alpha');
260 $companybankaccount->label =
GETPOST(
'label',
'alpha');
261 $companybankaccount->courant =
GETPOST(
'courant',
'alpha');
262 $companybankaccount->clos =
GETPOST(
'clos',
'alpha');
263 $companybankaccount->code_banque =
GETPOST(
'code_banque',
'alpha');
264 $companybankaccount->code_guichet =
GETPOST(
'code_guichet',
'alpha');
265 $companybankaccount->number =
GETPOST(
'number',
'alpha');
266 $companybankaccount->cle_rib =
GETPOST(
'cle_rib',
'alpha');
267 $companybankaccount->bic =
GETPOST(
'bic',
'alpha');
268 $companybankaccount->iban =
GETPOST(
'iban',
'alpha');
269 $companybankaccount->domiciliation =
GETPOST(
'domiciliation',
'alpha');
270 $companybankaccount->proprio =
GETPOST(
'proprio',
'alpha');
271 $companybankaccount->owner_address =
GETPOST(
'owner_address',
'alpha');
272 $companybankaccount->frstrecur =
GETPOST(
'frstrecur',
'alpha');
273 $companybankaccount->rum =
GETPOST(
'rum',
'alpha');
275 $companybankaccount->datec =
dol_now();
276 $companybankaccount->status = 1;
281 if ($companybankaccount->needIBAN() == 1) {
283 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"IBAN")),
null,
'errors');
288 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"BIC")),
null,
'errors');
295 $result = $companybankaccount->create($user);
298 setEventMessages($companybankaccount->error, $companybankaccount->errors,
'errors');
302 if (empty($companybankaccount->rum)) {
303 $companybankaccount->rum = $prelevement->buildRumNumber($object->code_client, $companybankaccount->datec, $companybankaccount->id);
308 $result = $companybankaccount->update($user);
311 setEventMessages($companybankaccount->error, $companybankaccount->errors,
'errors');
319 $url = $_SERVER[
"PHP_SELF"].
'?socid='.$object->id;
320 header(
'Location: '.$url);
328 if ($action ==
'addcard') {
331 if (!
GETPOST(
'label',
'alpha') || !
GETPOST(
'proprio',
'alpha') || !
GETPOST(
'exp_date_month',
'alpha') || !
GETPOST(
'exp_date_year',
'alpha')) {
332 if (!
GETPOST(
'label',
'alpha')) {
333 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Label")),
null,
'errors');
335 if (!
GETPOST(
'proprio',
'alpha')) {
336 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"NameOnCard")),
null,
'errors');
339 if (!(
GETPOST(
'exp_date_month',
'alpha') > 0) || !(
GETPOST(
'exp_date_year',
'alpha') > 0)) {
340 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"ExpiryDate")),
null,
'errors');
343 $action =
'createcard';
351 $companypaymentmode->fk_soc = $object->id;
352 $companypaymentmode->bank =
GETPOST(
'bank',
'alpha');
353 $companypaymentmode->label =
GETPOST(
'label',
'alpha');
354 $companypaymentmode->number =
GETPOST(
'cardnumber',
'alpha');
355 $companypaymentmode->last_four = substr(
GETPOST(
'cardnumber',
'alpha'), -4);
356 $companypaymentmode->proprio =
GETPOST(
'proprio',
'alpha');
357 $companypaymentmode->exp_date_month =
GETPOST(
'exp_date_month',
'int');
358 $companypaymentmode->exp_date_year =
GETPOST(
'exp_date_year',
'int');
359 $companypaymentmode->cvn =
GETPOST(
'cvn',
'alpha');
360 $companypaymentmode->datec =
dol_now();
361 $companypaymentmode->default_rib = 0;
362 $companypaymentmode->type =
'card';
363 $companypaymentmode->country_code = $object->country_code;
364 $companypaymentmode->status = $servicestatus;
366 if (
GETPOST(
'stripe_card_ref',
'alpha')) {
368 $companypaymentmode->stripe_account = $stripecu.
'@'.$site_account;
370 $companypaymentmode->stripe_card_ref =
GETPOST(
'stripe_card_ref',
'alpha');
375 $result = $companypaymentmode->create($user);
378 setEventMessages($companypaymentmode->error, $companypaymentmode->errors,
'errors');
379 $action =
'createcard';
386 $url = $_SERVER[
"PHP_SELF"].
'?socid='.$object->id;
387 header(
'Location: '.$url);
395 if ($action ==
'setasbankdefault' &&
GETPOST(
'ribid',
'int') > 0) {
397 $res = $companybankaccount->setAsDefault(
GETPOST(
'ribid',
'int'));
399 $url = DOL_URL_ROOT.
'/societe/paymentmodes.php?socid='.$object->id;
400 header(
'Location: '.$url);
407 if ($action ==
'confirm_deletecard' &&
GETPOST(
'confirm',
'alpha') ==
'yes') {
409 if ($companypaymentmode->fetch($ribid ? $ribid : $id)) {
419 $result = $companypaymentmode->delete($user);
421 $url = $_SERVER[
'PHP_SELF'].
"?socid=".$object->id;
422 header(
'Location: '.$url);
425 setEventMessages($companypaymentmode->error, $companypaymentmode->errors,
'errors');
428 setEventMessages($companypaymentmode->error, $companypaymentmode->errors,
'errors');
431 if ($action ==
'confirm_delete' &&
GETPOST(
'confirm',
'alpha') ==
'yes') {
433 if ($companybankaccount->fetch($ribid ? $ribid : $id)) {
434 $result = $companybankaccount->delete($user);
436 $url = $_SERVER[
'PHP_SELF'].
"?socid=".$object->id;
437 header(
'Location: '.$url);
440 setEventMessages($companybankaccount->error, $companybankaccount->errors,
'errors');
443 setEventMessages($companybankaccount->error, $companybankaccount->errors,
'errors');
450 if ($action ==
'builddocrib') {
451 $action =
'builddoc';
453 'use_companybankid'=>
GETPOST(
'companybankid'),
454 'force_dir_output'=>$conf->societe->multidir_output[$object->entity].
'/'.
dol_sanitizeFileName($object->id)
456 $_POST[
'lang_id'] =
GETPOST(
'lang_idrib'.
GETPOST(
'companybankid',
'int'),
'alpha');
457 $_POST[
'model'] =
GETPOST(
'modelrib'.
GETPOST(
'companybankid',
'int'),
'alpha');
461 $upload_dir = $conf->societe->multidir_output[$object->entity];
462 include DOL_DOCUMENT_ROOT.
'/core/actions_builddoc.inc.php';
467 if (!empty($conf->stripe->enabled) && class_exists(
'Stripe')) {
468 if ($action ==
'synccustomertostripe') {
469 if ($object->client == 0) {
474 $cu = $stripe->customerStripe($object, $stripeacc, $servicestatus, 1);
483 if ($action ==
'synccardtostripe') {
485 $companypaymentmode->fetch($id);
487 if ($companypaymentmode->type !=
'card') {
492 $cu = $stripe->customerStripe($object, $stripeacc, $servicestatus);
502 $card = $stripe->cardStripe($cu, $companypaymentmode, $stripeacc, $servicestatus, 1);
511 if ($action ==
'setkey_account') {
514 $newcu =
GETPOST(
'key_account',
'alpha');
519 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"societe_account WHERE site = 'stripe' AND (site_account IS NULL or site_account = '' or site_account = '".$db->escape($site_account).
"') AND fk_soc = ".$object->id.
" AND status = ".((int) $servicestatus).
" AND entity = ".$conf->entity;
521 $sql =
'SELECT rowid FROM '.MAIN_DB_PREFIX.
"societe_account";
522 $sql .=
" WHERE site = 'stripe' AND (site_account IS NULL or site_account = '' or site_account = '".$db->escape($site_account).
"') AND fk_soc = ".((int) $object->id).
" AND status = ".((int) $servicestatus).
" AND entity = ".$conf->entity;
525 $resql = $db->query($sql);
526 $num = $db->num_rows(
$resql);
527 if (!empty($newcu)) {
530 $societeaccount->fk_soc = $object->id;
531 $societeaccount->login =
'';
532 $societeaccount->pass_encoding =
'';
533 $societeaccount->site =
'stripe';
534 $societeaccount->status = $servicestatus;
535 $societeaccount->key_account = $newcu;
536 $societeaccount->site_account = $site_account;
537 $result = $societeaccount->create($user);
542 $sql =
'UPDATE '.MAIN_DB_PREFIX.
"societe_account";
543 $sql .=
" SET key_account = '".$db->escape(
GETPOST(
'key_account',
'alpha')).
"', site_account = '".$db->escape($site_account).
"'";
544 $sql .=
" WHERE site = 'stripe' AND (site_account IS NULL or site_account = '' or site_account = '".$db->escape($site_account).
"') AND fk_soc = ".((int) $object->id).
" AND status = ".((int) $servicestatus).
" AND entity = ".$conf->entity;
545 $resql = $db->query($sql);
560 if ($action ==
'setkey_account_supplier') {
563 $newsup =
GETPOST(
'key_account_supplier',
'alpha');
567 if (empty($newsup)) {
568 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"oauth_token WHERE fk_soc = ".$object->id.
" AND service = '".$db->escape($service).
"' AND entity = ".$conf->entity;
573 $stripesup = \Stripe\Account::retrieve($db->escape(
GETPOST(
'key_account_supplier',
'alpha')));
574 $tokenstring[
'stripe_user_id'] = $stripesup->id;
575 $tokenstring[
'type'] = $stripesup->type;
576 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"oauth_token";
577 $sql .=
" SET tokenstring = '".$db->escape(json_encode($tokenstring)).
"'";
578 $sql .=
" 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;
580 $sql .=
" WHERE fk_soc = ".$object->id.
" AND service = '".$db->escape($service).
"' AND entity = ".$conf->entity;
587 $resql = $db->query($sql);
588 $num = $db->num_rows(
$resql);
589 if (empty($num) && !empty($newsup)) {
591 $stripesup = \Stripe\Account::retrieve($db->escape(
GETPOST(
'key_account_supplier',
'alpha')));
592 $tokenstring[
'stripe_user_id'] = $stripesup->id;
593 $tokenstring[
'type'] = $stripesup->type;
594 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"oauth_token (service, fk_soc, entity, tokenstring)";
595 $sql .=
" VALUES ('".$db->escape($service).
"', ".((int) $object->id).
", ".((int) $conf->entity).
", '".$db->escape(json_encode($tokenstring)).
"')";
601 $resql = $db->query($sql);
605 $stripesupplieracc = $newsup;
612 if ($action ==
'setlocalassourcedefault') {
614 $companypaymentmode->setAsDefault($id);
616 $url = DOL_URL_ROOT.
'/societe/paymentmodes.php?socid='.$object->id;
617 header(
'Location: '.$url);
623 } elseif ($action ==
'setassourcedefault') {
625 $cu = $stripe->customerStripe($object, $stripeacc, $servicestatus);
626 if (preg_match(
'/pm_/', $source)) {
627 $cu->invoice_settings->default_payment_method = (string) $source;
629 $cu->default_source = (string) $source;
631 $result = $cu->save();
633 $url = DOL_URL_ROOT.
'/societe/paymentmodes.php?socid='.$object->id;
634 header(
'Location: '.$url);
640 } elseif ($action ==
'deletecard' && $source) {
642 if (preg_match(
'/pm_/', $source)) {
643 $payment_method = \Stripe\PaymentMethod::retrieve($source, array(
"stripe_account" => $stripeacc));
644 if ($payment_method) {
645 $payment_method->detach();
648 $cu = $stripe->customerStripe($object, $stripeacc, $servicestatus);
649 $card = $cu->sources->retrieve(
"$source");
652 if (method_exists($card,
'detach')) {
660 $url = DOL_URL_ROOT.
'/societe/paymentmodes.php?socid='.$object->id;
661 header(
'Location: '.$url);
681 $title = $langs->trans(
"ThirdParty");
682 if (!empty($conf->global->MAIN_HTML_TITLE) && preg_match(
'/thirdpartynameonly/', $conf->global->MAIN_HTML_TITLE) && $object->name) {
683 $title = $object->name.
" - ".$langs->trans(
'PaymentInformation');
695 if (!empty($conf->stripe->enabled) && (empty($conf->global->STRIPE_LIVE) ||
GETPOST(
'forcesandbox',
'alpha'))) {
696 dol_htmloutput_mesg($langs->trans(
'YouAreCurrentlyInSandboxMode',
'Stripe'),
'',
'warning');
701 $companybankaccount->fetch(0, $object->id);
702 $companypaymentmode->fetch(0,
null, $object->id,
'card');
704 $companybankaccount->fetch($id);
705 $companypaymentmode->fetch($id);
707 if (empty($companybankaccount->socid)) {
708 $companybankaccount->socid = $object->id;
711 if ($socid && ($action ==
'edit' || $action ==
'editcard') && $permissiontoaddupdatepaymentinformation) {
712 print
'<form action="'.$_SERVER[
"PHP_SELF"].
'?socid='.$object->id.
'" method="post">';
713 print
'<input type="hidden" name="token" value="'.newToken().
'">';
714 $actionforadd =
'update';
715 if ($action ==
'editcard') {
716 $actionforadd =
'updatecard';
718 print
'<input type="hidden" name="action" value="'.$actionforadd.
'">';
719 print
'<input type="hidden" name="id" value="'.GETPOST(
"id",
"int").
'">';
721 if ($socid && ($action ==
'create' || $action ==
'createcard') && $permissiontoaddupdatepaymentinformation) {
722 print
'<form action="'.$_SERVER[
"PHP_SELF"].
'?socid='.$object->id.
'" method="post">';
723 print
'<input type="hidden" name="token" value="'.newToken().
'">';
724 $actionforadd =
'add';
725 if ($action ==
'createcard') {
726 $actionforadd =
'addcard';
728 print
'<input type="hidden" name="action" value="'.$actionforadd.
'">';
733 if ($socid && $action !=
'edit' && $action !=
'create' && $action !=
'editcard' && $action !=
'createcard') {
737 if ($action ==
'delete') {
738 print
$form->formconfirm($_SERVER[
"PHP_SELF"].
"?socid=".$object->id.
"&ribid=".($ribid ? $ribid : $id), $langs->trans(
"DeleteARib"), $langs->trans(
"ConfirmDeleteRib", $companybankaccount->getRibLabel()),
"confirm_delete",
'', 0, 1);
741 if ($action ==
'deletecard') {
742 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);
745 $linkback =
'<a href="'.DOL_URL_ROOT.
'/societe/list.php?restore_lastsearch_values=1">'.$langs->trans(
"BackToList").
'</a>';
747 dol_banner_tab($object,
'socid', $linkback, ($user->socid ? 0 : 1),
'rowid',
'nom');
749 print
'<div class="fichecenter">';
751 print
'<div class="underbanner clearboth"></div>';
752 print
'<table class="border tableforfield centpercent">';
755 print
'<tr><td class="titlefield">'.$langs->trans(
'NatureOfThirdParty').
'</td><td colspan="2">';
756 print $object->getTypeUrl(1);
759 if (!empty($conf->global->SOCIETE_USEPREFIX)) {
760 print
'<tr><td class="titlefield">'.$langs->trans(
'Prefix').
'</td><td colspan="2">'.$object->prefix_comm.
'</td></tr>';
763 if ($object->client) {
764 print
'<tr><td class="titlefield">';
765 print $langs->trans(
'CustomerCode').
'</td><td colspan="2">';
767 $tmpcheck = $object->check_codeclient();
768 if ($tmpcheck != 0 && $tmpcheck != -5) {
769 print
' <span class="error">('.$langs->trans(
"WrongCustomerCode").
')</span>';
772 $sql =
"SELECT count(*) as nb from ".MAIN_DB_PREFIX.
"facture where fk_soc = ".((int) $socid);
773 $resql = $db->query($sql);
778 $obj = $db->fetch_object(
$resql);
779 $nbFactsClient = $obj->nb;
780 $thirdTypeArray[
'customer'] = $langs->trans(
"customer");
781 if (!empty($conf->propal->enabled) && $user->rights->propal->lire) {
782 $elementTypeArray[
'propal'] = $langs->transnoentitiesnoconv(
'Proposals');
784 if (!empty($conf->commande->enabled) && $user->rights->commande->lire) {
785 $elementTypeArray[
'order'] = $langs->transnoentitiesnoconv(
'Orders');
787 if (
isModEnabled(
'facture') && $user->rights->facture->lire) {
788 $elementTypeArray[
'invoice'] = $langs->transnoentitiesnoconv(
'Invoices');
790 if (!empty($conf->contrat->enabled) && $user->rights->contrat->lire) {
791 $elementTypeArray[
'contract'] = $langs->transnoentitiesnoconv(
'Contracts');
794 if (!empty($conf->stripe->enabled)) {
796 print
'<tr><td class="titlefield">';
797 print
$form->editfieldkey(
"StripeCustomerId",
'key_account', $stripecu, $object, $permissiontoaddupdatepaymentinformation,
'string',
'', 0, 2,
'socid');
799 print
$form->editfieldval(
"StripeCustomerId",
'key_account', $stripecu, $object, $permissiontoaddupdatepaymentinformation,
'string',
'',
null,
null,
'', 2,
'',
'socid');
800 if (!empty($conf->stripe->enabled) && $stripecu && $action !=
'editkey_account') {
802 if (!empty($stripeacc)) {
803 $connect = $stripeacc.
'/';
805 $url =
'https://dashboard.stripe.com/'.$connect.
'test/customers/'.$stripecu;
806 if ($servicestatus) {
807 $url =
'https://dashboard.stripe.com/'.$connect.
'customers/'.$stripecu;
809 print
' <a href="'.$url.
'" target="_stripe">'.
img_picto($langs->trans(
'ShowInStripe').
' - Publishable key = '.$site_account,
'globe').
'</a>';
811 print
'</td><td class="right">';
812 if (empty($stripecu)) {
813 print
'<form action="'.$_SERVER[
"PHP_SELF"].
'" method="post">';
814 print
'<input type="hidden" name="action" value="synccustomertostripe">';
815 print
'<input type="hidden" name="token" value="'.newToken().
'">';
816 print
'<input type="hidden" name="socid" value="'.$object->id.
'">';
817 print
'<input type="submit" class="button buttongen" name="syncstripecustomer" value="'.$langs->trans(
"CreateCustomerOnStripe").
'">';
824 if ($object->fournisseur) {
825 print
'<tr><td class="titlefield">';
826 print $langs->trans(
'SupplierCode').
'</td><td colspan="2">';
828 $tmpcheck = $object->check_codefournisseur();
829 if ($tmpcheck != 0 && $tmpcheck != -5) {
830 print
' <span class="error">('.$langs->trans(
"WrongSupplierCode").
')</span>';
833 $sql =
"SELECT count(*) as nb from ".MAIN_DB_PREFIX.
"facture where fk_soc = ".((int) $socid);
834 $resql = $db->query($sql);
838 $obj = $db->fetch_object(
$resql);
839 $nbFactsClient = $obj->nb;
840 $thirdTypeArray[
'customer'] = $langs->trans(
"customer");
841 if (
isModEnabled(
'propal') && $user->rights->propal->lire) {
842 $elementTypeArray[
'propal'] = $langs->transnoentitiesnoconv(
'Proposals');
844 if (
isModEnabled(
'commande') && $user->rights->commande->lire) {
845 $elementTypeArray[
'order'] = $langs->transnoentitiesnoconv(
'Orders');
847 if (
isModEnabled(
'facture') && $user->rights->facture->lire) {
848 $elementTypeArray[
'invoice'] = $langs->transnoentitiesnoconv(
'Invoices');
850 if (
isModEnabled(
'contrat') && $user->rights->contrat->lire) {
851 $elementTypeArray[
'contract'] = $langs->transnoentitiesnoconv(
'Contracts');
855 if (!empty($conf->stripe->enabled) && !empty($conf->stripeconnect->enabled) &&
getDolGlobalInt(
'MAIN_FEATURES_LEVEL') >= 2) {
856 $stripesupplieracc = $stripe->getStripeAccount($service, $object->id);
859 print
'<tr><td class="titlefield">';
860 print
$form->editfieldkey(
"StripeConnectAccount",
'key_account_supplier', $stripesupplieracc, $object, $permissiontoaddupdatepaymentinformation,
'string',
'', 0, 2,
'socid');
862 print
$form->editfieldval(
"StripeConnectAccount",
'key_account_supplier', $stripesupplieracc, $object, $permissiontoaddupdatepaymentinformation,
'string',
'',
null,
null,
'', 2,
'',
'socid');
863 if (!empty($conf->stripe->enabled) && $stripesupplieracc && $action !=
'editkey_account_supplier') {
866 $url =
'https://dashboard.stripe.com/test/connect/accounts/'.$stripesupplieracc;
867 if ($servicestatus) {
868 $url =
'https://dashboard.stripe.com/connect/accounts/'.$stripesupplieracc;
870 print
' <a href="'.$url.
'" target="_stripe">'.
img_picto($langs->trans(
'ShowInStripe').
' - Publishable key '.$site_account,
'globe').
'</a>';
872 print
'</td><td class="right">';
873 if (empty($stripesupplieracc)) {
874 print
'<form action="'.$_SERVER[
"PHP_SELF"].
'" method="post">';
875 print
'<input type="hidden" name="action" value="syncsuppliertostripe">';
876 print
'<input type="hidden" name="token" value="'.newToken().
'">';
877 print
'<input type="hidden" name="socid" value="'.$object->id.
'">';
878 print
'<input type="hidden" name="companybankid" value="'.$rib->id.
'">';
893 if (!(empty($conf->stripe->enabled)) && $object->client) {
895 if (!empty($conf->global->STRIPE_ALLOW_LOCAL_CARD)) {
896 $morehtmlright .=
dolGetButtonTitle($langs->trans(
'Add'),
'',
'fa fa-plus-circle', $_SERVER[
"PHP_SELF"].
'?socid='.$object->id.
'&action=createcard');
898 print
load_fiche_titre($langs->trans(
'StripePaymentModes').($stripeacc ?
' (Stripe connection with StripeConnect account '.$stripeacc.
')' :
' (Stripe connection with keys from Stripe module setup)'), $morehtmlright,
'stripe-s');
900 $listofsources = array();
901 if (is_object($stripe)) {
903 $customerstripe = $stripe->customerStripe($object, $stripeacc, $servicestatus);
904 if (!empty($customerstripe->id)) {
906 if (empty($conf->global->STRIPE_USE_INTENT_WITH_AUTOMATIC_CONFIRMATION)) {
907 $listofsources = $customerstripe->sources->data;
909 $service =
'StripeTest';
911 if (!empty($conf->global->STRIPE_LIVE) && !
GETPOST(
'forcesandbox',
'alpha')) {
912 $service =
'StripeLive';
917 global $stripearrayofkeysbyenv;
918 \Stripe\Stripe::setApiKey($stripearrayofkeysbyenv[$servicestatus][
'secret_key']);
921 if (empty($stripeacc)) {
922 $paymentmethodobjsA = \Stripe\PaymentMethod::all(array(
"customer" => $customerstripe->id,
"type" =>
"card"));
923 $paymentmethodobjsB = \Stripe\PaymentMethod::all(array(
"customer" => $customerstripe->id,
"type" =>
"sepa_debit"));
925 $paymentmethodobjsA = \Stripe\PaymentMethod::all(array(
"customer" => $customerstripe->id,
"type" =>
"card"), array(
"stripe_account" => $stripeacc));
926 $paymentmethodobjsB = \Stripe\PaymentMethod::all(array(
"customer" => $customerstripe->id,
"type" =>
"sepa_debit"), array(
"stripe_account" => $stripeacc));
929 if ($paymentmethodobjsA->data !=
null && $paymentmethodobjsB->data !=
null) {
930 $listofsources = array_merge((array) $paymentmethodobjsA->data, (array) $paymentmethodobjsB->data);
931 } elseif ($paymentmethodobjsB->data !=
null) {
932 $listofsources = $paymentmethodobjsB->data;
934 $listofsources = $paymentmethodobjsA->data;
943 dol_syslog(
"Error when searching/loading Stripe customer for thirdparty id =".$object->id);
947 print
'<!-- List of stripe payments -->'.
"\n";
948 print
'<div class="div-table-responsive-no-min">';
949 print
'<table class="liste centpercent">'.
"\n";
950 print
'<tr class="liste_titre">';
951 if (!empty($conf->global->STRIPE_ALLOW_LOCAL_CARD)) {
952 print
'<td>'.$langs->trans(
'LocalID').
'</td>';
954 print
'<td>'.$langs->trans(
'Label').
'</td>';
955 print
'<td>'.$langs->trans(
'StripeID').
'</td>';
956 print
'<td>'.$langs->trans(
'Type').
'</td>';
957 print
'<td>'.$langs->trans(
'Informations').
'</td>';
959 print
'<td class="center">'.$langs->trans(
'Default').
'</td>';
960 print
'<td>'.$langs->trans(
'Note').
'</td>';
961 print
'<td>'.$langs->trans(
'DateModification').
'</td>';
963 $parameters = array(
'arrayfields'=>array(),
'param'=>
'',
'sortfield'=>
'',
'sortorder'=>
'',
'linetype'=>
'stripetitle');
964 $reshook = $hookmanager->executeHooks(
'printFieldListTitle', $parameters, $object);
965 print $hookmanager->resPrint;
972 $arrayofstripecard = array();
975 if (!empty($conf->global->STRIPE_ALLOW_LOCAL_CARD)) {
979 $sql =
'SELECT rowid FROM '.MAIN_DB_PREFIX.
"societe_rib";
980 $sql .=
" WHERE type in ('card')";
981 $sql .=
" AND fk_soc = ".((int) $object->id);
982 $sql .=
" AND status = ".((int) $servicestatus);
984 $resql = $db->query($sql);
986 $num_rows = $db->num_rows(
$resql);
989 while ($i < $num_rows) {
992 $obj = $db->fetch_object(
$resql);
994 $companypaymentmodetemp->fetch($obj->rowid);
996 $arrayofstripecard[$companypaymentmodetemp->stripe_card_ref] = $companypaymentmodetemp->stripe_card_ref;
998 print
'<tr class="oddeven">';
1000 print $companypaymentmodetemp->id;
1002 print
'<td class="tdoverflowmax150" title="'.dol_escape_htmltag($companypaymentmodetemp->label).
'">';
1006 print $companypaymentmodetemp->stripe_card_ref;
1007 if ($companypaymentmodetemp->stripe_card_ref) {
1009 if (!empty($stripeacc)) {
1010 $connect = $stripeacc.
'/';
1012 $url =
'https://dashboard.stripe.com/'.$connect.
'test/search?query='.$companypaymentmodetemp->stripe_card_ref;
1013 if ($servicestatus) {
1014 $url =
'https://dashboard.stripe.com/'.$connect.
'search?query='.$companypaymentmodetemp->stripe_card_ref;
1016 print
' <a href="'.$url.
'" target="_stripe">'.
img_picto($langs->trans(
'ShowInStripe').
' - Customer and Publishable key = '.$companypaymentmodetemp->stripe_account,
'globe').
'</a>';
1023 if ($companypaymentmodetemp->proprio) {
1024 print
'<span class="opacitymedium">'.$companypaymentmodetemp->proprio.
'</span><br>';
1026 if ($companypaymentmodetemp->last_four) {
1027 print
'....'.$companypaymentmodetemp->last_four;
1029 if ($companypaymentmodetemp->exp_date_month || $companypaymentmodetemp->exp_date_year) {
1030 print
' - '.sprintf(
"%02d", $companypaymentmodetemp->exp_date_month).
'/'.$companypaymentmodetemp->exp_date_year.
'';
1033 if ($companypaymentmodetemp->country_code) {
1035 print $img ? $img.
' ' :
'';
1036 print
getCountry($companypaymentmodetemp->country_code, 1);
1038 print
img_warning().
' <span class="error">'.$langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"CompanyCountry")).
'</span>';
1042 print
'<td class="center">';
1043 if (empty($companypaymentmodetemp->default_rib)) {
1044 print
'<a href="'.DOL_URL_ROOT.
'/societe/paymentmodes.php?socid='.$object->id.
'&id='.$companypaymentmodetemp->id.
'&action=setlocalassourcedefault&token='.
newToken().
'">';
1045 print
img_picto($langs->trans(
"Default"),
'off');
1048 print
img_picto($langs->trans(
"Default"),
'on');
1052 if (empty($companypaymentmodetemp->stripe_card_ref)) {
1053 print $langs->trans(
"Local");
1055 print $langs->trans(
"LocalAndRemote");
1062 $parameters = array(
'arrayfields'=>array(),
'obj'=>$obj,
'linetype'=>
'stripecard');
1063 $reshook = $hookmanager->executeHooks(
'printFieldListValue', $parameters, $object);
1064 print $hookmanager->resPrint;
1066 print
'<td class="right nowraponall">';
1067 if ($permissiontoaddupdatepaymentinformation) {
1068 if ($stripecu && empty($companypaymentmodetemp->stripe_card_ref)) {
1069 print
'<a href="'.$_SERVER[
'PHP_SELF'].
'?action=synccardtostripe&socid='.$object->id.
'&id='.$companypaymentmodetemp->id.
'" class="paddingrightonly marginrightonly">'.$langs->trans(
"CreateCardOnStripe").
'</a>';
1072 print
'<a class="editfielda marginleftonly marginrightonly" href="'.DOL_URL_ROOT.
'/societe/paymentmodes.php?socid='.$object->id.
'&id='.$companypaymentmodetemp->id.
'&action=editcard&token='.
newToken().
'">';
1073 print
img_picto($langs->trans(
"Modify"),
'edit');
1076 print
'<a class="marginleftonly marginrightonly" href="'.DOL_URL_ROOT.
'/societe/paymentmodes.php?socid='.$object->id.
'&id='.$companypaymentmodetemp->id.
'&action=deletecard&token='.
newToken().
'">';
1077 print
img_picto($langs->trans(
"Delete"),
'delete');
1092 if (is_array($listofsources) && count($listofsources)) {
1093 foreach ($listofsources as $src) {
1094 if (!empty($arrayofstripecard[$src->id])) {
1100 print
'<tr class="oddeven">';
1102 if (!empty($conf->global->STRIPE_ALLOW_LOCAL_CARD)) {
1112 if (!empty($stripeacc)) {
1113 $connect = $stripeacc.
'/';
1116 $url =
'https://dashboard.stripe.com/'.$connect.
'test/search?query='.$src->id;
1117 if ($servicestatus) {
1119 $url =
'https://dashboard.stripe.com/'.$connect.
'search?query='.$src->id;
1121 print
" <a href='".$url.
"' target='_stripe'>".
img_picto($langs->trans(
'ShowInStripe'),
'globe').
"</a>";
1125 if ($src->object ==
'card') {
1127 } elseif ($src->object ==
'source' && $src->type ==
'card') {
1129 } elseif ($src->object ==
'source' && $src->type ==
'sepa_debit') {
1130 print
'<span class="fa fa-university fa-2x fa-fw"></span>';
1131 } elseif ($src->object ==
'payment_method' && $src->type ==
'card') {
1133 } elseif ($src->object ==
'payment_method' && $src->type ==
'sepa_debit') {
1134 print
'<span class="fa fa-university fa-2x fa-fw"></span>';
1138 print
'<td valign="middle">';
1139 if ($src->object ==
'card') {
1140 print
'....'.$src->last4.
' - '.$src->exp_month.
'/'.$src->exp_year.
'';
1142 if ($src->country) {
1144 print $img ? $img.
' ' :
'';
1147 print
img_warning().
' <span class="error">'.$langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"CompanyCountry")).
'</span>';
1149 } elseif ($src->object ==
'source' && $src->type ==
'card') {
1150 print
'<span class="opacitymedium">'.$src->owner->name.
'</span><br>....'.$src->card->last4.
' - '.$src->card->exp_month.
'/'.$src->card->exp_year.
'';
1153 if ($src->card->country) {
1155 print $img ? $img.
' ' :
'';
1158 print
img_warning().
' <span class="error">'.$langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"CompanyCountry")).
'</span>';
1160 } elseif ($src->object ==
'source' && $src->type ==
'sepa_debit') {
1161 print
'<span class="opacitymedium">'.$src->billing_details->name.
'</span><br>....'.$src->sepa_debit->last4;
1163 if ($src->sepa_debit->country) {
1165 print $img ? $img.
' ' :
'';
1166 print
getCountry($src->sepa_debit->country, 1);
1168 print
img_warning().
' <span class="error">'.$langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"CompanyCountry")).
'</span>';
1170 } elseif ($src->object ==
'payment_method' && $src->type ==
'card') {
1171 print
'<span class="opacitymedium">'.$src->billing_details->name.
'</span><br>....'.$src->card->last4.
' - '.$src->card->exp_month.
'/'.$src->card->exp_year.
'';
1174 if ($src->card->country) {
1176 print $img ? $img.
' ' :
'';
1179 print
img_warning().
' <span class="error">'.$langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"CompanyCountry")).
'</span>';
1181 } elseif ($src->object ==
'payment_method' && $src->type ==
'sepa_debit') {
1182 print
'<span class="opacitymedium">'.$src->billing_details->name.
'</span><br>....'.$src->sepa_debit->last4;
1184 if ($src->sepa_debit->country) {
1186 print $img ? $img.
' ' :
'';
1187 print
getCountry($src->sepa_debit->country, 1);
1189 print
img_warning().
' <span class="error">'.$langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"CompanyCountry")).
'</span>';
1196 print
'<td class="center" width="50">';
1197 if ((empty($customerstripe->invoice_settings) && $customerstripe->default_source != $src->id) ||
1198 (!empty($customerstripe->invoice_settings) && $customerstripe->invoice_settings->default_payment_method != $src->id)) {
1199 print
'<a href="'.DOL_URL_ROOT.
'/societe/paymentmodes.php?socid='.$object->id.
'&source='.$src->id.
'&action=setassourcedefault&token='.
newToken().
'">';
1200 print
img_picto($langs->trans(
"Default"),
'off');
1203 print
img_picto($langs->trans(
"Default"),
'on');
1207 print $langs->trans(
"Remote");
1215 $parameters = array(
'arrayfields'=>array(),
'stripesource'=>$src,
'linetype'=>
'stripecardremoteonly');
1216 $reshook = $hookmanager->executeHooks(
'printFieldListValue', $parameters, $object);
1217 print $hookmanager->resPrint;
1219 print
'<td class="right nowraponall">';
1220 if ($permissiontoaddupdatepaymentinformation) {
1221 print
'<a href="'.DOL_URL_ROOT.
'/societe/paymentmodes.php?socid='.$object->id.
'&source='.$src->id.
'&action=deletecard&token='.
newToken().
'">';
1222 print
img_picto($langs->trans(
"Delete"),
'delete');
1231 if ($nbremote == 0 && $nblocal == 0) {
1232 $colspan = (!empty($conf->global->STRIPE_ALLOW_LOCAL_CARD) ? 10 : 9);
1233 print
'<tr><td colspan="'.$colspan.
'"<span class="opacitymedium">'.$langs->trans(
"None").
'</span></td></tr>';
1241 if (!empty($conf->stripe->enabled) && !empty($conf->stripeconnect->enabled) && !empty($stripesupplieracc)) {
1242 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');
1243 $balance = \Stripe\Balance::retrieve(array(
"stripe_account" => $stripesupplieracc));
1244 print
'<table class="liste centpercent">'.
"\n";
1245 print
'<tr class="liste_titre">';
1246 print
'<td>'.$langs->trans(
'Currency').
'</td>';
1247 print
'<td>'.$langs->trans(
'Available').
'</td>';
1248 print
'<td>'.$langs->trans(
'Pending').
'</td>';
1249 print
'<td>'.$langs->trans(
'Total').
'</td>';
1252 $currencybalance = array();
1253 if (is_array($balance->available) && count($balance->available)) {
1254 foreach ($balance->available as $cpt) {
1255 $arrayzerounitcurrency = array(
'BIF',
'CLP',
'DJF',
'GNF',
'JPY',
'KMF',
'KRW',
'MGA',
'PYG',
'RWF',
'VND',
'VUV',
'XAF',
'XOF',
'XPF');
1256 if (!in_array($cpt->currency, $arrayzerounitcurrency)) {
1257 $currencybalance[$cpt->currency][
'available'] = $cpt->amount / 100;
1259 $currencybalance[$cpt->currency][
'available'] = $cpt->amount;
1261 $currencybalance[$cpt->currency][
'currency'] = $cpt->currency;
1265 if (is_array($balance->pending) && count($balance->pending)) {
1266 foreach ($balance->pending as $cpt) {
1267 $arrayzerounitcurrency = array(
'BIF',
'CLP',
'DJF',
'GNF',
'JPY',
'KMF',
'KRW',
'MGA',
'PYG',
'RWF',
'VND',
'VUV',
'XAF',
'XOF',
'XPF');
1268 if (!in_array($cpt->currency, $arrayzerounitcurrency)) {
1269 $currencybalance[$cpt->currency][
'pending'] = $currencybalance[$cpt->currency][
'available'] + $cpt->amount / 100;
1271 $currencybalance[$cpt->currency][
'pending'] = $currencybalance[$cpt->currency][
'available'] + $cpt->amount;
1276 if (is_array($currencybalance)) {
1277 foreach ($currencybalance as $cpt) {
1278 print
'<tr><td>'.$langs->trans(
"Currency".strtoupper($cpt[
'currency'])).
'</td><td>'.
price($cpt[
'available'], 0,
'', 1, - 1, - 1, strtoupper($cpt[
'currency'])).
'</td><td>'.
price($cpt->pending, 0,
'', 1, - 1, - 1, strtoupper($cpt[
'currency'])).
'</td><td>'.
price($cpt[
'available'] + $cpt->pending, 0,
'', 1, - 1, - 1, strtoupper($cpt[
'currency'])).
'</td></tr>';
1287 if ($permissiontoaddupdatepaymentinformation) {
1288 $morehtmlright =
dolGetButtonTitle($langs->trans(
'Add'),
'',
'fa fa-plus-circle', $_SERVER[
"PHP_SELF"] .
'?socid=' . $object->id .
'&action=create');
1291 print
load_fiche_titre($langs->trans(
"BankAccounts"), $morehtmlright,
'bank');
1293 $rib_list = $object->get_all_rib();
1294 if (is_array($rib_list)) {
1295 print
'<div class="div-table-responsive-no-min">';
1296 print
'<table class="liste centpercent">';
1298 print
'<tr class="liste_titre">';
1304 if (!empty($conf->prelevement->enabled)) {
1314 foreach ($rib_list as $rib) {
1315 print
'<tr class="oddeven">';
1317 print
'<td>'.$rib->label.
'</td>';
1319 print
'<td>'.$rib->bank.
'</td>';
1323 foreach ($rib->getFieldsToShow() as $val) {
1324 if ($val ==
'BankCode') {
1325 $string .= $rib->code_banque.
' ';
1326 } elseif ($val ==
'BankAccountNumber') {
1327 $string .= $rib->number.
' ';
1328 } elseif ($val ==
'DeskCode') {
1329 $string .= $rib->code_guichet.
' ';
1330 } elseif ($val ==
'BankAccountNumberKey') {
1331 $string .= $rib->cle_rib.
' ';
1340 if (!empty($rib->label) && $rib->number) {
1342 $string .=
' '.img_picto($langs->trans(
"ValueIsNotValid"),
'warning');
1344 $string .=
' '.img_picto($langs->trans(
"ValueIsValid"),
'info');
1351 print
'<td>'.$rib->iban;
1352 if (!empty($rib->iban)) {
1354 print
' '.img_picto($langs->trans(
"IbanNotValid"),
'warning');
1359 print
'<td>'.$rib->bic;
1360 if (!empty($rib->bic)) {
1362 print
' '.img_picto($langs->trans(
"SwiftNotValid"),
'warning');
1367 if (!empty($conf->prelevement->enabled)) {
1370 print
'<td>'.$rib->rum.
'</td>';
1372 print
'<td>'.dol_print_date($rib->date_rum,
'day').
'</td>';
1375 print
'<td>'.$rib->frstrecur.
'</td>';
1379 print
'<td class="center" width="70">';
1380 if (!$rib->default_rib) {
1381 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?socid='.$object->id.
'&ribid='.$rib->id.
'&action=setasbankdefault&token='.
newToken().
'">';
1382 print
img_picto($langs->trans(
"Disabled"),
'off');
1385 print
img_picto($langs->trans(
"Enabled"),
'on');
1390 print
'<td class="center">';
1392 $buttonlabel = $langs->trans(
"BuildDoc");
1393 $forname =
'builddocrib'.$rib->id;
1395 include_once DOL_DOCUMENT_ROOT.
'/core/modules/bank/modules_bank.php';
1399 if (is_array($modellist) && count($modellist)) {
1400 $out .=
'<form action="'.$_SERVER[
"PHP_SELF"].(empty($conf->global->MAIN_JUMP_TAG) ?
'' :
'#builddoc').
'" name="'.$forname.
'" id="'.$forname.
'_form" method="post">';
1401 $out .=
'<input type="hidden" name="action" value="builddocrib">';
1402 $out .=
'<input type="hidden" name="token" value="'.newToken().
'">';
1403 $out .=
'<input type="hidden" name="socid" value="'.$object->id.
'">';
1404 $out .=
'<input type="hidden" name="companybankid" value="'.$rib->id.
'">';
1406 if (is_array($modellist) && count($modellist) == 1) {
1407 $arraykeys = array_keys($modellist);
1408 $modelselected = $arraykeys[0];
1410 if (!empty($conf->global->BANKADDON_PDF)) {
1411 $modelselected = $conf->global->BANKADDON_PDF;
1414 $out .=
$form->selectarray(
'modelrib'.$rib->id, $modellist, $modelselected, 1, 0, 0,
'', 0, 0, 0,
'',
'minwidth100');
1417 $allowgenifempty = 0;
1420 if ($conf->global->MAIN_MULTILANGS) {
1421 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formadmin.class.php';
1423 $defaultlang = $langs->getDefaultLang();
1424 $morecss =
'maxwidth150';
1425 if ($conf->browser->layout ==
'phone') {
1426 $morecss =
'maxwidth100';
1428 $out .= $formadmin->select_language($defaultlang,
'lang_idrib'.$rib->id, 0, 0, 0, 0, 0, $morecss);
1431 $genbutton =
'<input class="button buttongen reposition nomargintop nomarginbottom" id="'.$forname.
'_generatebutton" name="'.$forname.
'_generatebutton"';
1432 $genbutton .=
' type="submit" value="'.$buttonlabel.
'"';
1433 if (!$allowgenifempty && !is_array($modellist) && empty($modellist)) {
1434 $genbutton .=
' disabled';
1437 if ($allowgenifempty && !is_array($modellist) && empty($modellist) && empty($conf->dol_no_mouse_hover) && $modulepart !=
'unpaid') {
1438 $langs->load(
"errors");
1439 $genbutton .=
' '.img_warning($langs->transnoentitiesnoconv(
"WarningNoDocumentModelActivated"));
1441 if (!$allowgenifempty && !is_array($modellist) && empty($modellist) && empty($conf->dol_no_mouse_hover) && $modulepart !=
'unpaid') {
1444 if (empty($modellist) && !$showempty && $modulepart !=
'unpaid') {
1454 print
'<td class="right nowraponall">';
1455 if ($permissiontoaddupdatepaymentinformation) {
1456 print
'<a class="editfielda" href="'.$_SERVER[
"PHP_SELF"].
'?socid='.$object->id.
'&id='.$rib->id.
'&action=edit">';
1457 print
img_picto($langs->trans(
"Modify"),
'edit');
1460 print
'<a class="marginleftonly" href="'.$_SERVER[
"PHP_SELF"].
'?socid='.$object->id.
'&id='.$rib->id.
'&action=delete&token='.
newToken().
'">';
1461 print
img_picto($langs->trans(
"Delete"),
'delete');
1469 if (count($rib_list) == 0) {
1471 if (!empty($conf->prelevement->enabled)) {
1474 print
'<tr><td colspan="'.$colspan.
'"><span class="opacitymedium">'.$langs->trans(
"NoBANRecord").
'</span></td></tr>';
1484 if (empty($conf->global->SOCIETE_DISABLE_BUILDDOC)) {
1487 print
'<div class="fichecenter"><div class="fichehalfleft">';
1488 print
'<a name="builddoc"></a>';
1493 $filedir = $conf->societe->multidir_output[$object->entity].
'/'.$object->id;
1494 $urlsource = $_SERVER[
"PHP_SELF"].
"?socid=".$object->id;
1496 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);
1499 if (!empty($conf->global->BANK_ACCOUNT_ALLOW_EXTERNAL_DOWNLOAD)) {
1502 $result = $companypaymentmodetemp->fetch(0,
null, $object->id,
'ban');
1504 include_once DOL_DOCUMENT_ROOT.
'/ecm/class/ecmfiles.class.php';
1506 $result = $ecmfile->fetch(0,
'',
'',
'',
'', $companybankaccounttemp->table_element, $companypaymentmodetemp->id);
1508 $companybankaccounttemp->last_main_doc = $ecmfile->filepath.
'/'.$ecmfile->filename;
1509 print
'<br><!-- Link to download main doc -->'.
"\n";
1514 print
'</div><div class="fichehalfright">';
1517 print
'</div></div>';
1543 if ($socid && $action ==
'edit' && $permissiontoaddupdatepaymentinformation) {
1546 $linkback =
'<a href="'.DOL_URL_ROOT.
'/societe/list.php?restore_lastsearch_values=1">'.$langs->trans(
"BackToList").
'</a>';
1548 dol_banner_tab($object,
'socid', $linkback, ($user->socid ? 0 : 1),
'rowid',
'nom');
1550 print
'<div class="underbanner clearboth"></div>';
1552 print
'<div class="div-table-responsive-no-min">';
1553 print
'<table class="border centpercent">';
1555 print
'<tr><td class="titlefield fieldrequired">'.$langs->trans(
"LabelRIB").
'</td>';
1556 print
'<td><input class="minwidth300" type="text" name="label" value="'.$companybankaccount->label.
'"></td></tr>';
1558 print
'<tr><td class="fieldrequired">'.$langs->trans(
"BankName").
'</td>';
1559 print
'<td><input class="minwidth200" type="text" name="bank" value="'.$companybankaccount->bank.
'"></td></tr>';
1562 foreach ($companybankaccount->getFieldsToShow(1) as $val) {
1565 if ($val ==
'BankCode') {
1566 $name =
'code_banque';
1568 $content = $companybankaccount->code_banque;
1569 } elseif ($val ==
'DeskCode') {
1570 $name =
'code_guichet';
1572 $content = $companybankaccount->code_guichet;
1573 } elseif ($val ==
'BankAccountNumber') {
1576 $content = $companybankaccount->number;
1577 } elseif ($val ==
'BankAccountNumberKey') {
1580 $content = $companybankaccount->cle_rib;
1581 } elseif ($val ==
'IBAN') {
1584 $content = $companybankaccount->iban;
1585 if ($companybankaccount->needIBAN()) {
1588 $tooltip = $langs->trans(
"Example").
':<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';
1589 } elseif ($val ==
'BIC') {
1592 $content = $companybankaccount->bic;
1593 if ($companybankaccount->needIBAN()) {
1596 $tooltip = $langs->trans(
"Example").
': LIABLT2XXXX';
1599 print
'<tr><td'.($require ?
' class="fieldrequired" ' :
'').
'>';
1601 print
$form->textwithpicto($langs->trans($val), $tooltip, 4,
'help',
'', 0, 3, $name);
1603 print $langs->trans($val);
1606 print
'<td><input size="'.$size.
'" type="text" class="flat" name="'.$name.
'" value="'.$content.
'"></td>';
1610 print
'<tr><td>'.$langs->trans(
"BankAccountDomiciliation").
'</td><td>';
1611 print
'<textarea name="domiciliation" rows="4" cols="40" maxlength="255">';
1612 print $companybankaccount->domiciliation;
1613 print
"</textarea></td></tr>";
1615 print
'<tr><td>'.$langs->trans(
"BankAccountOwner").
'</td>';
1616 print
'<td><input class="minwidth300" type="text" name="proprio" value="'.$companybankaccount->proprio.
'"></td></tr>';
1617 print
"</td></tr>\n";
1619 print
'<tr><td>'.$langs->trans(
"BankAccountOwnerAddress").
'</td><td>';
1620 print
'<textarea name="owner_address" rows="'.ROWS_4.
'" cols="40" maxlength="255">';
1621 print $companybankaccount->owner_address;
1622 print
"</textarea></td></tr>";
1630 print
'<div class="div-table-responsive-no-min">';
1631 print
'<table class="border centpercent">';
1633 if (empty($companybankaccount->rum)) {
1634 $companybankaccount->rum = $prelevement->buildRumNumber($object->code_client, $companybankaccount->datec, $companybankaccount->id);
1638 print
'<tr><td class="titlefield">'.$langs->trans(
"RUM").
'</td>';
1639 print
'<td><input class="minwidth300" type="text" name="rum" value="'.dol_escape_htmltag($companybankaccount->rum).
'"></td></tr>';
1643 print
'<tr><td class="titlefield">'.$langs->trans(
"DateRUM").
'</td>';
1644 print
'<td>'.$form->selectDate($date_rum ? $date_rum : $companybankaccount->date_rum,
'date_rum', 0, 0, 1,
'date_rum', 1, 1).
'</td></tr>';
1646 print
'<tr><td>'.$langs->trans(
"WithdrawMode").
'</td><td>';
1647 $tblArraychoice = array(
"FRST" => $langs->trans(
"FRST"),
"RECUR" => $langs->trans(
"RECUR"));
1658 print
$form->buttonsSaveCancel(
"Modify");
1662 if ($socid && $action ==
'editcard' && $permissiontoaddupdatepaymentinformation) {
1665 $linkback =
'<a href="'.DOL_URL_ROOT.
'/societe/list.php?restore_lastsearch_values=1">'.$langs->trans(
"BackToList").
'</a>';
1667 dol_banner_tab($object,
'socid', $linkback, ($user->socid ? 0 : 1),
'rowid',
'nom');
1669 print
'<div class="fichecenter">';
1671 print
'<div class="underbanner clearboth"></div>';
1672 print
'<table class="border centpercent">';
1674 print
'<tr><td class="titlefieldcreate fieldrequired">'.$langs->trans(
"Label").
'</td>';
1675 print
'<td><input class="minwidth300" type="text" id="label" name="label" value="'.$companypaymentmode->label.
'"></td></tr>';
1677 print
'<tr><td class="fieldrequired">'.$langs->trans(
"NameOnCard").
'</td>';
1678 print
'<td><input class="minwidth200" type="text" name="proprio" value="'.$companypaymentmode->proprio.
'"></td></tr>';
1680 print
'<tr><td>'.$langs->trans(
"CardNumber").
'</td>';
1681 print
'<td><input class="minwidth200" type="text" name="cardnumber" value="'.$companypaymentmode->number.
'"></td></tr>';
1683 print
'<tr><td class="fieldrequired">'.$langs->trans(
"ExpiryDate").
'</td>';
1685 print $formother->select_month($companypaymentmode->exp_date_month,
'exp_date_month', 1);
1686 print $formother->selectyear($companypaymentmode->exp_date_year,
'exp_date_year', 1, 5, 10, 0, 0,
'',
'marginleftonly');
1689 print
'<tr><td>'.$langs->trans(
"CVN").
'</td>';
1690 print
'<td><input size="8" type="text" name="cvn" value="'.$companypaymentmode->cvn.
'"></td></tr>';
1692 print
'<tr><td>'.$langs->trans(
"StripeID").
" ('card_....')</td>";
1693 print
'<td><input class="minwidth300" type="text" name="stripe_card_ref" value="'.$companypaymentmode->stripe_card_ref.
'"></td></tr>';
1700 print
$form->buttonsSaveCancel(
"Modify");
1705 if ($socid && $action ==
'create' && $permissiontoaddupdatepaymentinformation) {
1708 $linkback =
'<a href="'.DOL_URL_ROOT.
'/societe/list.php?restore_lastsearch_values=1">'.$langs->trans(
"BackToList").
'</a>';
1710 dol_banner_tab($object,
'socid', $linkback, ($user->socid ? 0 : 1),
'rowid',
'nom');
1712 print
'<div class="nofichecenter">';
1714 print
'<div class="underbanner clearboth"></div>';
1715 print
'<table class="border centpercent">';
1717 print
'<tr><td class="titlefieldcreate fieldrequired">'.$langs->trans(
"LabelRIB").
'</td>';
1718 print
'<td><input class="minwidth200" type="text" id="label" name="label" value="'.GETPOST(
'label').
'"></td></tr>';
1720 print
'<tr><td class="fieldrequired">'.$langs->trans(
"Bank").
'</td>';
1721 print
'<td><input class="minwidth200" type="text" name="bank" value="'.GETPOST(
'bank').
'"></td></tr>';
1724 foreach ($companybankaccount->getFieldsToShow(1) as $val) {
1727 if ($val ==
'BankCode') {
1728 $name =
'code_banque';
1730 $content = $companybankaccount->code_banque;
1731 } elseif ($val ==
'DeskCode') {
1732 $name =
'code_guichet';
1734 $content = $companybankaccount->code_guichet;
1735 } elseif ($val ==
'BankAccountNumber') {
1738 $content = $companybankaccount->number;
1739 } elseif ($val ==
'BankAccountNumberKey') {
1742 $content = $companybankaccount->cle_rib;
1743 } elseif ($val ==
'IBAN') {
1746 $content = $companybankaccount->iban;
1747 if ($companybankaccount->needIBAN()) {
1750 $tooltip = $langs->trans(
"Example").
':<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';
1751 } elseif ($val ==
'BIC') {
1754 $content = $companybankaccount->bic;
1755 if ($companybankaccount->needIBAN()) {
1758 $tooltip = $langs->trans(
"Example").
': LIABLT2XXXX';
1761 print
'<tr><td'.($require ?
' class="fieldrequired" ' :
'').
'>';
1763 print
$form->textwithpicto($langs->trans($val), $tooltip, 4,
'help',
'', 0, 3, $name);
1765 print $langs->trans($val);
1768 print
'<td><input size="'.$size.
'" type="text" class="flat" name="'.$name.
'" value="'.
GETPOST($name).
'"></td>';
1772 print
'<tr><td>'.$langs->trans(
"BankAccountDomiciliation").
'</td><td>';
1773 print
'<textarea name="domiciliation" rows="'.ROWS_4.
'" class="quatrevingtpercent" maxlength="255">';
1774 print
GETPOST(
'domiciliation');
1775 print
"</textarea></td></tr>";
1777 print
'<tr><td>'.$langs->trans(
"BankAccountOwner").
'</td>';
1778 print
'<td><input class="minwidth200" type="text" name="proprio" value="'.GETPOST(
'proprio').
'"></td></tr>';
1779 print
"</td></tr>\n";
1781 print
'<tr><td>'.$langs->trans(
"BankAccountOwnerAddress").
'</td><td>';
1782 print
'<textarea name="owner_address" rows="'.ROWS_4.
'" class="quatrevingtpercent" maxlength="255">';
1783 print
GETPOST(
'owner_address');
1784 print
"</textarea></td></tr>";
1791 print
'<table class="border centpercent">';
1794 print
'<tr><td class="titlefieldcreate">'.$langs->trans(
"RUM").
'</td>';
1795 print
'<td colspan="4"><input type="text" class="minwidth300" name="rum" value="'.GETPOST(
'rum',
'alpha').
'"> <div class="opacitymedium">'.$langs->trans(
"RUMWillBeGenerated").
'</div></td></tr>';
1799 print
'<tr><td class="titlefieldcreate">'.$langs->trans(
"DateRUM").
'</td>';
1800 print
'<td colspan="4">'.$form->selectDate($date_rum,
'date_rum', 0, 0, 1,
'date_rum', 1, 1).
'</td></tr>';
1802 print
'<tr><td>'.$langs->trans(
"WithdrawMode").
'</td><td>';
1803 $tblArraychoice = array(
"FRST" => $langs->trans(
"FRST"),
"RECUR" => $langs->trans(
"RECUR"));
1804 print
$form->selectarray(
"frstrecur", $tblArraychoice, (
GETPOSTISSET(
'frstrecur') ?
GETPOST(
'frstrecur') :
'FRST'), 0);
1816 print
$form->buttonsSaveCancel(
"Add");
1820 if ($socid && $action ==
'createcard' && $permissiontoaddupdatepaymentinformation) {
1823 $linkback =
'<a href="'.DOL_URL_ROOT.
'/societe/list.php?restore_lastsearch_values=1">'.$langs->trans(
"BackToList").
'</a>';
1825 dol_banner_tab($object,
'socid', $linkback, ($user->socid ? 0 : 1),
'rowid',
'nom');
1827 print
'<div class="nofichecenter">';
1829 print
'<div class="underbanner clearboth"></div>';
1830 print
'<table class="border centpercent">';
1832 print
'<tr><td class="titlefieldcreate fieldrequired">'.$langs->trans(
"Label").
'</td>';
1833 print
'<td><input class="minwidth200" type="text" id="label" name="label" value="'.GETPOST(
'label',
'alpha').
'"></td></tr>';
1835 print
'<tr><td class="fieldrequired">'.$langs->trans(
"NameOnCard").
'</td>';
1836 print
'<td><input class="minwidth200" type="text" name="proprio" value="'.GETPOST(
'proprio',
'alpha').
'"></td></tr>';
1838 print
'<tr><td>'.$langs->trans(
"CardNumber").
'</td>';
1839 print
'<td><input class="minwidth200" type="text" name="cardnumber" value="'.GETPOST(
'cardnumber',
'alpha').
'"></td></tr>';
1841 print
'<tr><td class="fieldrequired">'.$langs->trans(
"ExpiryDate").
'</td>';
1843 print $formother->select_month(
GETPOST(
'exp_date_month',
'int'),
'exp_date_month', 1);
1844 print $formother->selectyear(
GETPOST(
'exp_date_year',
'int'),
'exp_date_year', 1, 5, 10, 0, 0,
'',
'marginleftonly');
1847 print
'<tr><td>'.$langs->trans(
"CVN").
'</td>';
1848 print
'<td><input class="width50" type="text" name="cvn" value="'.GETPOST(
'cvn',
'alpha').
'"></td></tr>';
1850 print
'<tr><td>'.$langs->trans(
"StripeID").
" ('card_....')</td>";
1851 print
'<td><input class="minwidth300" type="text" name="stripe_card_ref" value="'.GETPOST(
'stripe_card_ref',
'alpha').
'"></td></tr>';
1861 print
$form->buttonsSaveCancel(
"Add");
1864 if ($socid && ($action ==
'edit' || $action ==
'editcard') && $permissiontoaddupdatepaymentinformation) {
1867 if ($socid && ($action ==
'create' || $action ==
'createcard') && $permissiontoaddupdatepaymentinformation) {