2018-03-07 16:17:25 +01:00
< ? php
2021-11-02 04:51:18 +01:00
/* Copyright ( C ) 2002 - 2004 Rodolphe Quiedeville < rodolphe @ quiedeville . org >
* Copyright ( C ) 2003 Jean - Louis Bergamo < jlb @ j1b . org >
* Copyright ( C ) 2004 - 2018 Laurent Destailleur < eldy @ users . sourceforge . net >
* Copyright ( C ) 2005 - 2009 Regis Houssin < regis . houssin @ inodbox . com >
* Copyright ( C ) 2013 Peter Fontaine < contact @ peterfontaine . fr >
* Copyright ( C ) 2015 - 2016 Marcos García < marcosgdf @ gmail . com >
* Copyright ( C ) 2017 Ferran Marcet < fmarcet @ 2 byte . es >
* Copyright ( C ) 2018 - 2021 Thibault FOUCART < support @ ptibogxiv . net >
* Copyright ( C ) 2021 Alexandre Spangaro < aspangaro @ open - dsi . fr >
2018-03-07 16:17:25 +01:00
*
* This program is free software ; you can redistribute it and / or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation ; either version 3 of the License , or
* ( at your option ) any later version .
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
2019-09-23 21:55:30 +02:00
* along with this program . If not , see < https :// www . gnu . org / licenses />.
2018-03-07 16:17:25 +01:00
*/
/**
2018-03-08 22:26:42 +01:00
* \file htdocs / societe / paymentmodes . php
2018-03-07 16:17:25 +01:00
* \ingroup societe
2018-03-08 22:26:42 +01:00
* \brief Tab of payment modes for the customer
2018-03-07 16:17:25 +01:00
*/
require '../main.inc.php' ;
require_once DOL_DOCUMENT_ROOT . '/core/lib/company.lib.php' ;
require_once DOL_DOCUMENT_ROOT . '/core/lib/bank.lib.php' ;
require_once DOL_DOCUMENT_ROOT . '/core/class/html.formfile.class.php' ;
2018-03-14 11:51:13 +01:00
require_once DOL_DOCUMENT_ROOT . '/core/class/html.formother.class.php' ;
2018-03-07 16:17:25 +01:00
require_once DOL_DOCUMENT_ROOT . '/societe/class/companybankaccount.class.php' ;
2018-03-13 22:43:50 +01:00
require_once DOL_DOCUMENT_ROOT . '/societe/class/companypaymentmode.class.php' ;
2018-03-13 17:32:49 +01:00
require_once DOL_DOCUMENT_ROOT . '/societe/class/societeaccount.class.php' ;
2018-03-07 16:17:25 +01:00
require_once DOL_DOCUMENT_ROOT . '/compta/prelevement/class/bonprelevement.class.php' ;
require_once DOL_DOCUMENT_ROOT . '/stripe/class/stripe.class.php' ;
2019-11-13 18:32:11 +01:00
$langs -> loadLangs ( array ( " companies " , " commercial " , " banks " , " bills " , 'paypal' , 'stripe' , 'withdrawals' ));
2018-03-07 16:17:25 +01:00
// Security check
2019-01-27 11:55:16 +01:00
$socid = GETPOST ( " socid " , " int " );
2021-02-26 21:17:52 +01:00
if ( $user -> socid ) {
$socid = $user -> socid ;
}
2019-01-27 11:55:16 +01:00
$result = restrictedArea ( $user , 'societe' , '' , '' );
2018-03-07 16:17:25 +01:00
2019-11-13 18:32:11 +01:00
$id = GETPOST ( " id " , " int " );
$source = GETPOST ( " source " , " alpha " ); // source can be a source or a paymentmode
$ribid = GETPOST ( " ribid " , " int " );
$action = GETPOST ( " action " , 'alpha' , 3 );
$cancel = GETPOST ( 'cancel' , 'alpha' );
2018-03-07 16:17:25 +01:00
$object = new Societe ( $db );
$object -> fetch ( $socid );
2018-03-14 13:56:21 +01:00
$companybankaccount = new CompanyBankAccount ( $db );
$companypaymentmode = new CompanyPaymentMode ( $db );
2018-03-07 16:17:25 +01:00
$prelevement = new BonPrelevement ( $db );
$extrafields = new ExtraFields ( $db );
// fetch optionals attributes and labels
2019-10-06 14:41:52 +02:00
$extrafields -> fetch_name_optionals_label ( $object -> table_element );
2018-03-07 16:17:25 +01:00
// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
2019-11-13 18:32:11 +01:00
$hookmanager -> initHooks ( array ( 'thirdpartybancard' , 'globalcard' ));
2018-03-07 16:17:25 +01:00
2021-11-02 04:51:18 +01:00
$permissiontoread = $user -> rights -> societe -> lire ;
$permissiontoadd = $user -> rights -> societe -> creer ; // Used by the include of actions_addupdatedelete.inc.php and actions_builddoc.inc.php
$permissiontoaddupdatepaymentinformation = (( empty ( $conf -> global -> MAIN_USE_ADVANCED_PERMS ) && $permissiontoadd ) || ( ! empty ( $conf -> global -> MAIN_USE_ADVANCED_PERMS ) && ! empty ( $user -> rights -> societe -> addupdate_thirdparty_payment_information -> write )));
2018-03-07 16:17:25 +01:00
2021-02-26 21:17:52 +01:00
if ( ! empty ( $conf -> stripe -> enabled )) {
2018-03-13 15:19:31 +01:00
$service = 'StripeTest' ;
$servicestatus = 0 ;
2021-02-26 21:17:52 +01:00
if ( ! empty ( $conf -> global -> STRIPE_LIVE ) && ! GETPOST ( 'forcesandbox' , 'alpha' )) {
2018-03-13 15:19:31 +01:00
$service = 'StripeLive' ;
2018-03-14 12:01:15 +01:00
$servicestatus = 1 ;
2018-03-13 15:19:31 +01:00
}
2019-12-15 17:18:09 +01:00
// Force to use the correct API key
global $stripearrayofkeysbyenv ;
2019-12-15 17:32:45 +01:00
$site_account = $stripearrayofkeysbyenv [ $servicestatus ][ 'publishable_key' ];
2019-12-15 17:18:09 +01:00
2018-03-13 15:19:31 +01:00
$stripe = new Stripe ( $db );
2019-12-15 17:18:09 +01:00
$stripeacc = $stripe -> getStripeAccount ( $service ); // Get Stripe OAuth connect account (no remote access to Stripe here)
$stripecu = $stripe -> getStripeCustomerAccount ( $object -> id , $servicestatus , $site_account ); // Get remote Stripe customer 'cus_...' (no remote access to Stripe here)
2018-03-13 15:19:31 +01:00
}
2018-03-07 16:17:25 +01:00
/*
* Actions
*/
2021-02-26 21:17:52 +01:00
if ( $cancel ) {
2019-11-13 18:32:11 +01:00
$action = '' ;
2018-03-13 17:32:49 +01:00
}
2020-12-29 17:48:52 +01:00
$parameters = array ( 'id' => $socid );
2019-11-13 18:32:11 +01:00
$reshook = $hookmanager -> executeHooks ( 'doActions' , $parameters , $object , $action ); // Note that $action and $object may have been modified by some hooks
2021-02-26 21:17:52 +01:00
if ( $reshook < 0 ) {
setEventMessages ( $hookmanager -> error , $hookmanager -> errors , 'errors' );
}
2018-03-07 16:17:25 +01:00
2021-02-26 21:17:52 +01:00
if ( empty ( $reshook )) {
if ( $cancel ) {
2019-11-13 18:32:11 +01:00
$action = '' ;
2021-02-26 21:17:52 +01:00
if ( ! empty ( $backtopage )) {
2018-03-07 16:17:25 +01:00
header ( " Location: " . $backtopage );
exit ;
}
}
2021-02-26 21:17:52 +01:00
if ( $action == 'update' ) {
2018-03-07 16:17:25 +01:00
// Modification
2021-02-26 21:17:52 +01:00
if ( ! GETPOST ( 'label' , 'alpha' ) || ! GETPOST ( 'bank' , 'alpha' )) {
if ( ! GETPOST ( 'label' , 'alpha' )) {
setEventMessages ( $langs -> trans ( " ErrorFieldRequired " , $langs -> transnoentitiesnoconv ( " Label " )), null , 'errors' );
}
if ( ! GETPOST ( 'bank' , 'alpha' )) {
setEventMessages ( $langs -> trans ( " ErrorFieldRequired " , $langs -> transnoentitiesnoconv ( " BankName " )), null , 'errors' );
}
2019-11-13 18:32:11 +01:00
$action = 'edit' ;
2018-03-07 16:17:25 +01:00
$error ++ ;
}
2021-02-26 21:17:52 +01:00
if ( $companybankaccount -> needIBAN () == 1 ) {
if ( ! GETPOST ( 'iban' )) {
2018-03-07 16:17:25 +01:00
setEventMessages ( $langs -> trans ( " ErrorFieldRequired " , $langs -> transnoentitiesnoconv ( " IBAN " )), null , 'errors' );
2019-11-13 18:32:11 +01:00
$action = 'edit' ;
2018-03-07 16:17:25 +01:00
$error ++ ;
}
2021-02-26 21:17:52 +01:00
if ( ! GETPOST ( 'bic' )) {
2018-03-07 16:17:25 +01:00
setEventMessages ( $langs -> trans ( " ErrorFieldRequired " , $langs -> transnoentitiesnoconv ( " BIC " )), null , 'errors' );
2019-11-13 18:32:11 +01:00
$action = 'edit' ;
2018-03-07 16:17:25 +01:00
$error ++ ;
}
}
2018-03-14 13:56:21 +01:00
$companybankaccount -> fetch ( $id );
2021-02-26 21:17:52 +01:00
if ( ! $error ) {
2018-03-14 13:56:21 +01:00
$companybankaccount -> socid = $object -> id ;
2019-01-27 11:55:16 +01:00
$companybankaccount -> bank = GETPOST ( 'bank' , 'alpha' );
$companybankaccount -> label = GETPOST ( 'label' , 'alpha' );
$companybankaccount -> courant = GETPOST ( 'courant' , 'alpha' );
$companybankaccount -> clos = GETPOST ( 'clos' , 'alpha' );
$companybankaccount -> code_banque = GETPOST ( 'code_banque' , 'alpha' );
$companybankaccount -> code_guichet = GETPOST ( 'code_guichet' , 'alpha' );
$companybankaccount -> number = GETPOST ( 'number' , 'alpha' );
$companybankaccount -> cle_rib = GETPOST ( 'cle_rib' , 'alpha' );
$companybankaccount -> bic = GETPOST ( 'bic' , 'alpha' );
$companybankaccount -> iban = GETPOST ( 'iban' , 'alpha' );
$companybankaccount -> domiciliation = GETPOST ( 'domiciliation' , 'alpha' );
$companybankaccount -> proprio = GETPOST ( 'proprio' , 'alpha' );
$companybankaccount -> owner_address = GETPOST ( 'owner_address' , 'alpha' );
$companybankaccount -> frstrecur = GETPOST ( 'frstrecur' , 'alpha' );
$companybankaccount -> rum = GETPOST ( 'rum' , 'alpha' );
2019-07-28 19:07:44 +02:00
$companybankaccount -> date_rum = dol_mktime ( 0 , 0 , 0 , GETPOST ( 'date_rummonth' ), GETPOST ( 'date_rumday' ), GETPOST ( 'date_rumyear' ));
2021-02-26 21:17:52 +01:00
if ( empty ( $companybankaccount -> rum )) {
2018-03-14 13:56:21 +01:00
$companybankaccount -> rum = $prelevement -> buildRumNumber ( $object -> code_client , $companybankaccount -> datec , $companybankaccount -> id );
2019-07-28 17:10:37 +02:00
}
2018-03-07 16:17:25 +01:00
2018-03-14 13:56:21 +01:00
$result = $companybankaccount -> update ( $user );
2021-02-26 21:17:52 +01:00
if ( ! $result ) {
2018-03-14 13:56:21 +01:00
setEventMessages ( $companybankaccount -> error , $companybankaccount -> errors , 'errors' );
2020-05-21 15:05:19 +02:00
} else {
2018-03-07 16:17:25 +01:00
// If this account is the default bank account, we disable others
2021-02-26 21:17:52 +01:00
if ( $companybankaccount -> default_rib ) {
2019-11-13 18:32:11 +01:00
$companybankaccount -> setAsDefault ( $id ); // This will make sure there is only one default rib
2018-03-14 13:56:21 +01:00
}
2019-11-13 18:32:11 +01:00
$url = $_SERVER [ " PHP_SELF " ] . '?socid=' . $object -> id ;
2018-03-14 13:56:21 +01:00
header ( 'Location: ' . $url );
exit ;
}
}
}
2021-02-26 21:17:52 +01:00
if ( $action == 'updatecard' ) {
2018-03-14 13:56:21 +01:00
// Modification
2021-02-26 21:17:52 +01:00
if ( ! GETPOST ( 'label' , 'alpha' ) || ! GETPOST ( 'proprio' , 'alpha' ) || ! GETPOST ( 'exp_date_month' , 'alpha' ) || ! GETPOST ( 'exp_date_year' , 'alpha' )) {
if ( ! GETPOST ( 'label' , 'alpha' )) {
setEventMessages ( $langs -> trans ( " ErrorFieldRequired " , $langs -> transnoentitiesnoconv ( " Label " )), null , 'errors' );
}
if ( ! GETPOST ( 'proprio' , 'alpha' )) {
setEventMessages ( $langs -> trans ( " ErrorFieldRequired " , $langs -> transnoentitiesnoconv ( " NameOnCard " )), null , 'errors' );
}
2020-01-02 15:45:25 +01:00
//if (!GETPOST('cardnumber', 'alpha')) setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("CardNumber")), null, 'errors');
2021-02-26 21:17:52 +01:00
if ( ! ( GETPOST ( 'exp_date_month' , 'alpha' ) > 0 ) || ! ( GETPOST ( 'exp_date_year' , 'alpha' ) > 0 )) {
setEventMessages ( $langs -> trans ( " ErrorFieldRequired " , $langs -> transnoentitiesnoconv ( " ExpiryDate " )), null , 'errors' );
}
2020-01-02 15:45:25 +01:00
//if (!GETPOST('cvn', 'alpha')) setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("CVN")), null, 'errors');
2019-11-13 18:32:11 +01:00
$action = 'createcard' ;
2018-03-14 13:56:21 +01:00
$error ++ ;
}
$companypaymentmode -> fetch ( $id );
2021-02-26 21:17:52 +01:00
if ( ! $error ) {
2018-03-14 13:56:21 +01:00
$companypaymentmode -> fk_soc = $object -> id ;
2019-01-27 11:55:16 +01:00
$companypaymentmode -> bank = GETPOST ( 'bank' , 'alpha' );
$companypaymentmode -> label = GETPOST ( 'label' , 'alpha' );
$companypaymentmode -> number = GETPOST ( 'cardnumber' , 'alpha' );
$companypaymentmode -> last_four = substr ( GETPOST ( 'cardnumber' , 'alpha' ), - 4 );
$companypaymentmode -> proprio = GETPOST ( 'proprio' , 'alpha' );
$companypaymentmode -> exp_date_month = GETPOST ( 'exp_date_month' , 'int' );
$companypaymentmode -> exp_date_year = GETPOST ( 'exp_date_year' , 'int' );
$companypaymentmode -> cvn = GETPOST ( 'cvn' , 'alpha' );
2018-03-16 16:42:26 +01:00
$companypaymentmode -> country_code = $object -> country_code ;
2018-03-14 13:56:21 +01:00
2020-01-02 15:45:25 +01:00
if ( GETPOST ( 'stripe_card_ref' , 'alpha' ) && GETPOST ( 'stripe_card_ref' , 'alpha' ) != $companypaymentmode -> stripe_card_ref ) {
// If we set a stripe value that is different than previous one, we also set the stripe account
2020-01-22 16:02:28 +01:00
$companypaymentmode -> stripe_account = $stripecu . '@' . $site_account ;
2020-01-02 15:45:25 +01:00
}
2019-01-27 11:55:16 +01:00
$companypaymentmode -> stripe_card_ref = GETPOST ( 'stripe_card_ref' , 'alpha' );
2018-03-14 13:56:21 +01:00
$result = $companypaymentmode -> update ( $user );
2021-02-26 21:17:52 +01:00
if ( ! $result ) {
2018-03-14 13:56:21 +01:00
setEventMessages ( $companypaymentmode -> error , $companypaymentmode -> errors , 'errors' );
2020-05-21 15:05:19 +02:00
} else {
2018-03-14 13:56:21 +01:00
// If this account is the default bank account, we disable others
2021-02-26 21:17:52 +01:00
if ( $companypaymentmode -> default_rib ) {
2019-11-13 18:32:11 +01:00
$companypaymentmode -> setAsDefault ( $id ); // This will make sure there is only one default rib
2018-03-07 16:17:25 +01:00
}
2019-11-13 18:32:11 +01:00
$url = $_SERVER [ " PHP_SELF " ] . '?socid=' . $object -> id ;
2018-03-07 16:17:25 +01:00
header ( 'Location: ' . $url );
exit ;
}
}
}
2021-02-26 21:17:52 +01:00
if ( $action == 'add' ) {
2019-11-13 18:32:11 +01:00
$error = 0 ;
2018-03-07 16:17:25 +01:00
2021-02-26 21:17:52 +01:00
if ( ! GETPOST ( 'label' , 'alpha' ) || ! GETPOST ( 'bank' , 'alpha' )) {
if ( ! GETPOST ( 'label' , 'alpha' )) {
setEventMessages ( $langs -> trans ( " ErrorFieldRequired " , $langs -> transnoentitiesnoconv ( " Label " )), null , 'errors' );
}
if ( ! GETPOST ( 'bank' , 'alpha' )) {
setEventMessages ( $langs -> trans ( " ErrorFieldRequired " , $langs -> transnoentitiesnoconv ( " BankName " )), null , 'errors' );
}
2019-11-13 18:32:11 +01:00
$action = 'create' ;
2018-03-07 16:17:25 +01:00
$error ++ ;
}
2021-02-26 21:17:52 +01:00
if ( ! $error ) {
2018-03-07 16:17:25 +01:00
// Ajout
2018-03-14 13:56:21 +01:00
$companybankaccount = new CompanyBankAccount ( $db );
$companybankaccount -> socid = $object -> id ;
2019-01-27 11:55:16 +01:00
$companybankaccount -> bank = GETPOST ( 'bank' , 'alpha' );
$companybankaccount -> label = GETPOST ( 'label' , 'alpha' );
$companybankaccount -> courant = GETPOST ( 'courant' , 'alpha' );
$companybankaccount -> clos = GETPOST ( 'clos' , 'alpha' );
$companybankaccount -> code_banque = GETPOST ( 'code_banque' , 'alpha' );
$companybankaccount -> code_guichet = GETPOST ( 'code_guichet' , 'alpha' );
$companybankaccount -> number = GETPOST ( 'number' , 'alpha' );
$companybankaccount -> cle_rib = GETPOST ( 'cle_rib' , 'alpha' );
$companybankaccount -> bic = GETPOST ( 'bic' , 'alpha' );
$companybankaccount -> iban = GETPOST ( 'iban' , 'alpha' );
$companybankaccount -> domiciliation = GETPOST ( 'domiciliation' , 'alpha' );
$companybankaccount -> proprio = GETPOST ( 'proprio' , 'alpha' );
$companybankaccount -> owner_address = GETPOST ( 'owner_address' , 'alpha' );
2021-08-02 18:13:35 +02:00
$companybankaccount -> frstrecur = GETPOST ( 'frstrecur' , 'alpha' );
2019-01-27 11:55:16 +01:00
$companybankaccount -> rum = GETPOST ( 'rum' , 'alpha' );
2021-08-02 18:13:35 +02:00
$companybankaccount -> date_rum = dol_mktime ( 0 , 0 , 0 , GETPOST ( 'date_rummonth' , 'int' ), GETPOST ( 'date_rumday' , 'int' ), GETPOST ( 'date_rumyear' , 'int' ));
2019-11-13 18:32:11 +01:00
$companybankaccount -> datec = dol_now ();
2018-03-14 13:56:21 +01:00
$companybankaccount -> status = 1 ;
2018-03-07 16:17:25 +01:00
$db -> begin ();
// This test can be done only once properties were set
2021-02-26 21:17:52 +01:00
if ( $companybankaccount -> needIBAN () == 1 ) {
if ( ! GETPOST ( 'iban' )) {
2018-03-07 16:17:25 +01:00
setEventMessages ( $langs -> trans ( " ErrorFieldRequired " , $langs -> transnoentitiesnoconv ( " IBAN " )), null , 'errors' );
2019-11-13 18:32:11 +01:00
$action = 'create' ;
2018-03-07 16:17:25 +01:00
$error ++ ;
}
2021-02-26 21:17:52 +01:00
if ( ! GETPOST ( 'bic' )) {
2018-03-07 16:17:25 +01:00
setEventMessages ( $langs -> trans ( " ErrorFieldRequired " , $langs -> transnoentitiesnoconv ( " BIC " )), null , 'errors' );
2019-11-13 18:32:11 +01:00
$action = 'create' ;
2018-03-07 16:17:25 +01:00
$error ++ ;
}
}
2021-02-26 21:17:52 +01:00
if ( ! $error ) {
2018-03-14 13:56:21 +01:00
$result = $companybankaccount -> create ( $user );
2021-02-26 21:17:52 +01:00
if ( $result < 0 ) {
2018-03-07 16:17:25 +01:00
$error ++ ;
2018-03-14 13:56:21 +01:00
setEventMessages ( $companybankaccount -> error , $companybankaccount -> errors , 'errors' );
2019-11-13 18:32:11 +01:00
$action = 'create' ; // Force chargement page création
2018-03-07 16:17:25 +01:00
}
2021-02-26 21:17:52 +01:00
if ( empty ( $companybankaccount -> rum )) {
2018-03-14 13:56:21 +01:00
$companybankaccount -> rum = $prelevement -> buildRumNumber ( $object -> code_client , $companybankaccount -> datec , $companybankaccount -> id );
2018-03-07 16:17:25 +01:00
}
}
2021-02-26 21:17:52 +01:00
if ( ! $error ) {
2019-11-13 18:32:11 +01:00
$result = $companybankaccount -> update ( $user ); // This will set the UMR number.
2021-02-26 21:17:52 +01:00
if ( $result < 0 ) {
2018-03-07 16:17:25 +01:00
$error ++ ;
2018-03-14 13:56:21 +01:00
setEventMessages ( $companybankaccount -> error , $companybankaccount -> errors , 'errors' );
2019-11-13 18:32:11 +01:00
$action = 'create' ;
2018-03-07 16:17:25 +01:00
}
}
2021-02-26 21:17:52 +01:00
if ( ! $error ) {
2018-03-07 16:17:25 +01:00
$db -> commit ();
2019-11-13 18:32:11 +01:00
$url = $_SERVER [ " PHP_SELF " ] . '?socid=' . $object -> id ;
2018-03-07 16:17:25 +01:00
header ( 'Location: ' . $url );
exit ;
2020-05-21 15:05:19 +02:00
} else {
2018-03-07 16:17:25 +01:00
$db -> rollback ();
}
}
}
2021-02-26 21:17:52 +01:00
if ( $action == 'addcard' ) {
2019-11-13 18:32:11 +01:00
$error = 0 ;
2018-03-14 11:51:13 +01:00
2021-02-26 21:17:52 +01:00
if ( ! GETPOST ( 'label' , 'alpha' ) || ! GETPOST ( 'proprio' , 'alpha' ) || ! GETPOST ( 'exp_date_month' , 'alpha' ) || ! GETPOST ( 'exp_date_year' , 'alpha' )) {
if ( ! GETPOST ( 'label' , 'alpha' )) {
setEventMessages ( $langs -> trans ( " ErrorFieldRequired " , $langs -> transnoentitiesnoconv ( " Label " )), null , 'errors' );
}
if ( ! GETPOST ( 'proprio' , 'alpha' )) {
setEventMessages ( $langs -> trans ( " ErrorFieldRequired " , $langs -> transnoentitiesnoconv ( " NameOnCard " )), null , 'errors' );
}
2020-01-02 15:45:25 +01:00
//if (!GETPOST('cardnumber', 'alpha')) setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("CardNumber")), null, 'errors');
2021-02-26 21:17:52 +01:00
if ( ! ( GETPOST ( 'exp_date_month' , 'alpha' ) > 0 ) || ! ( GETPOST ( 'exp_date_year' , 'alpha' ) > 0 )) {
setEventMessages ( $langs -> trans ( " ErrorFieldRequired " , $langs -> transnoentitiesnoconv ( " ExpiryDate " )), null , 'errors' );
}
2020-01-02 15:45:25 +01:00
//if (!GETPOST('cvn', 'alpha')) setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("CVN")), null, 'errors');
2019-11-13 18:32:11 +01:00
$action = 'createcard' ;
2018-03-14 11:51:13 +01:00
$error ++ ;
}
2021-02-26 21:17:52 +01:00
if ( ! $error ) {
2018-03-14 11:51:13 +01:00
// Ajout
2018-03-14 13:56:21 +01:00
$companypaymentmode = new CompanyPaymentMode ( $db );
$companypaymentmode -> fk_soc = $object -> id ;
2019-01-27 11:55:16 +01:00
$companypaymentmode -> bank = GETPOST ( 'bank' , 'alpha' );
$companypaymentmode -> label = GETPOST ( 'label' , 'alpha' );
$companypaymentmode -> number = GETPOST ( 'cardnumber' , 'alpha' );
$companypaymentmode -> last_four = substr ( GETPOST ( 'cardnumber' , 'alpha' ), - 4 );
$companypaymentmode -> proprio = GETPOST ( 'proprio' , 'alpha' );
$companypaymentmode -> exp_date_month = GETPOST ( 'exp_date_month' , 'int' );
$companypaymentmode -> exp_date_year = GETPOST ( 'exp_date_year' , 'int' );
$companypaymentmode -> cvn = GETPOST ( 'cvn' , 'alpha' );
2018-03-14 13:56:21 +01:00
$companypaymentmode -> datec = dol_now ();
$companypaymentmode -> default_rib = 0 ;
$companypaymentmode -> type = 'card' ;
2018-03-16 16:10:04 +01:00
$companypaymentmode -> country_code = $object -> country_code ;
$companypaymentmode -> status = $servicestatus ;
2018-03-14 13:56:21 +01:00
2020-01-02 15:45:25 +01:00
if ( GETPOST ( 'stripe_card_ref' , 'alpha' )) {
// If we set a stripe value, we also set the stripe account
2020-01-22 16:02:28 +01:00
$companypaymentmode -> stripe_account = $stripecu . '@' . $site_account ;
2020-01-02 15:45:25 +01:00
}
2019-01-27 11:55:16 +01:00
$companypaymentmode -> stripe_card_ref = GETPOST ( 'stripe_card_ref' , 'alpha' );
2018-03-14 11:51:13 +01:00
$db -> begin ();
2021-02-26 21:17:52 +01:00
if ( ! $error ) {
2018-03-14 13:56:21 +01:00
$result = $companypaymentmode -> create ( $user );
2021-02-26 21:17:52 +01:00
if ( $result < 0 ) {
2018-03-14 11:51:13 +01:00
$error ++ ;
2018-03-14 13:56:21 +01:00
setEventMessages ( $companypaymentmode -> error , $companypaymentmode -> errors , 'errors' );
2019-11-13 18:32:11 +01:00
$action = 'createcard' ; // Force chargement page création
2018-03-14 11:51:13 +01:00
}
}
2021-02-26 21:17:52 +01:00
if ( ! $error ) {
2018-03-14 11:51:13 +01:00
$db -> commit ();
2019-11-13 18:32:11 +01:00
$url = $_SERVER [ " PHP_SELF " ] . '?socid=' . $object -> id ;
2018-03-14 11:51:13 +01:00
header ( 'Location: ' . $url );
exit ;
2020-05-21 15:05:19 +02:00
} else {
2018-03-14 11:51:13 +01:00
$db -> rollback ();
}
}
}
2021-02-26 21:17:52 +01:00
if ( $action == 'setasbankdefault' && GETPOST ( 'ribid' , 'int' ) > 0 ) {
2018-03-14 13:56:21 +01:00
$companybankaccount = new CompanyBankAccount ( $db );
2019-01-27 11:55:16 +01:00
$res = $companybankaccount -> setAsDefault ( GETPOST ( 'ribid' , 'int' ));
2021-02-26 21:17:52 +01:00
if ( $res ) {
2019-11-13 18:32:11 +01:00
$url = DOL_URL_ROOT . '/societe/paymentmodes.php?socid=' . $object -> id ;
2018-03-07 16:17:25 +01:00
header ( 'Location: ' . $url );
exit ;
2020-05-21 15:05:19 +02:00
} else {
2018-03-07 16:17:25 +01:00
setEventMessages ( $db -> lasterror , null , 'errors' );
}
}
2021-02-26 21:17:52 +01:00
if ( $action == 'confirm_deletecard' && GETPOST ( 'confirm' , 'alpha' ) == 'yes' ) {
2018-03-14 13:56:21 +01:00
$companypaymentmode = new CompanyPaymentMode ( $db );
2021-02-26 21:17:52 +01:00
if ( $companypaymentmode -> fetch ( $ribid ? $ribid : $id )) {
2019-06-14 15:03:37 +02:00
/* if ( $companypaymentmode -> stripe_card_ref && preg_match ( '/pm_/' , $companypaymentmode -> stripe_card_ref ))
{
$payment_method = \Stripe\PaymentMethod :: retrieve ( $companypaymentmode -> stripe_card_ref );
if ( $payment_method )
{
$payment_method -> detach ();
}
} */
2018-03-14 13:56:21 +01:00
$result = $companypaymentmode -> delete ( $user );
2021-02-26 21:17:52 +01:00
if ( $result > 0 ) {
2018-03-14 11:51:13 +01:00
$url = $_SERVER [ 'PHP_SELF' ] . " ?socid= " . $object -> id ;
header ( 'Location: ' . $url );
exit ;
2020-05-21 15:05:19 +02:00
} else {
2018-03-14 13:56:21 +01:00
setEventMessages ( $companypaymentmode -> error , $companypaymentmode -> errors , 'errors' );
2018-03-14 11:51:13 +01:00
}
2020-05-21 15:05:19 +02:00
} else {
2018-03-14 13:56:21 +01:00
setEventMessages ( $companypaymentmode -> error , $companypaymentmode -> errors , 'errors' );
2018-03-14 11:51:13 +01:00
}
}
2021-02-26 21:17:52 +01:00
if ( $action == 'confirm_delete' && GETPOST ( 'confirm' , 'alpha' ) == 'yes' ) {
2018-03-14 13:56:21 +01:00
$companybankaccount = new CompanyBankAccount ( $db );
2021-02-26 21:17:52 +01:00
if ( $companybankaccount -> fetch ( $ribid ? $ribid : $id )) {
2018-03-14 13:56:21 +01:00
$result = $companybankaccount -> delete ( $user );
2021-02-26 21:17:52 +01:00
if ( $result > 0 ) {
2018-03-07 16:17:25 +01:00
$url = $_SERVER [ 'PHP_SELF' ] . " ?socid= " . $object -> id ;
header ( 'Location: ' . $url );
exit ;
2020-05-21 15:05:19 +02:00
} else {
2018-03-14 13:56:21 +01:00
setEventMessages ( $companybankaccount -> error , $companybankaccount -> errors , 'errors' );
2018-03-07 16:17:25 +01:00
}
2020-05-21 15:05:19 +02:00
} else {
2018-03-14 13:56:21 +01:00
setEventMessages ( $companybankaccount -> error , $companybankaccount -> errors , 'errors' );
2018-03-07 16:17:25 +01:00
}
}
2019-11-13 18:32:11 +01:00
$savid = $id ;
2018-03-07 16:17:25 +01:00
// Actions to build doc
2021-02-26 21:17:52 +01:00
if ( $action == 'builddocrib' ) {
2018-03-07 16:17:25 +01:00
$action = 'builddoc' ;
$moreparams = array (
'use_companybankid' => GETPOST ( 'companybankid' ),
'force_dir_output' => $conf -> societe -> multidir_output [ $object -> entity ] . '/' . dol_sanitizeFileName ( $object -> id )
);
2019-01-27 11:55:16 +01:00
$_POST [ 'lang_id' ] = GETPOST ( 'lang_idrib' . GETPOST ( 'companybankid' , 'int' ), 'alpha' );
2019-11-13 18:32:11 +01:00
$_POST [ 'model' ] = GETPOST ( 'modelrib' . GETPOST ( 'companybankid' , 'int' ), 'alpha' );
2018-03-07 16:17:25 +01:00
}
2019-09-23 21:55:30 +02:00
2018-03-07 16:17:25 +01:00
$id = $socid ;
$upload_dir = $conf -> societe -> multidir_output [ $object -> entity ];
include DOL_DOCUMENT_ROOT . '/core/actions_builddoc.inc.php' ;
$id = $savid ;
2018-03-13 17:32:49 +01:00
// Action for stripe
2021-02-26 21:17:52 +01:00
if ( ! empty ( $conf -> stripe -> enabled ) && class_exists ( 'Stripe' )) {
if ( $action == 'synccustomertostripe' ) {
if ( $object -> client == 0 ) {
2018-03-14 16:53:16 +01:00
$error ++ ;
setEventMessages ( 'ThisThirdpartyIsNotACustomer' , null , 'errors' );
2020-05-21 15:05:19 +02:00
} else {
2018-03-14 16:53:16 +01:00
// Creation of Stripe customer + update of societe_account
$cu = $stripe -> customerStripe ( $object , $stripeacc , $servicestatus , 1 );
2021-02-26 21:17:52 +01:00
if ( ! $cu ) {
2018-03-14 16:53:16 +01:00
$error ++ ;
setEventMessages ( $stripe -> error , $stripe -> errors , 'errors' );
2020-05-21 15:05:19 +02:00
} else {
2018-03-14 16:53:16 +01:00
$stripecu = $cu -> id ;
}
}
}
2021-02-26 21:17:52 +01:00
if ( $action == 'synccardtostripe' ) {
2018-03-14 21:07:45 +01:00
$companypaymentmode = new CompanyPaymentMode ( $db );
$companypaymentmode -> fetch ( $id );
2021-02-26 21:17:52 +01:00
if ( $companypaymentmode -> type != 'card' ) {
2018-03-14 21:07:45 +01:00
$error ++ ;
setEventMessages ( 'ThisPaymentModeIsNotACard' , null , 'errors' );
2020-05-21 15:05:19 +02:00
} else {
2018-03-14 21:07:45 +01:00
// Get the Stripe customer
$cu = $stripe -> customerStripe ( $object , $stripeacc , $servicestatus );
2021-02-26 21:17:52 +01:00
if ( ! $cu ) {
2018-03-14 21:07:45 +01:00
$error ++ ;
setEventMessages ( $stripe -> error , $stripe -> errors , 'errors' );
}
2021-02-26 21:17:52 +01:00
if ( ! $error ) {
2018-03-14 21:07:45 +01:00
// Creation of Stripe card + update of societe_account
2020-02-03 14:54:35 +01:00
// Note that with the new Stripe API, option to create a card is no more available, instead an error message will be returned to
// ask to create the crdit card from Stripe backoffice.
2018-03-14 21:07:45 +01:00
$card = $stripe -> cardStripe ( $cu , $companypaymentmode , $stripeacc , $servicestatus , 1 );
2021-02-26 21:17:52 +01:00
if ( ! $card ) {
2018-03-14 21:07:45 +01:00
$error ++ ;
setEventMessages ( $stripe -> error , $stripe -> errors , 'errors' );
}
}
}
}
2018-03-14 16:53:16 +01:00
2021-02-26 21:17:52 +01:00
if ( $action == 'setkey_account' ) {
2018-03-13 17:32:49 +01:00
$error = 0 ;
2018-03-13 15:19:31 +01:00
2018-03-13 17:32:49 +01:00
$newcu = GETPOST ( 'key_account' , 'alpha' );
2018-03-08 22:26:42 +01:00
2018-03-13 17:32:49 +01:00
$db -> begin ();
2018-03-13 15:19:31 +01:00
2020-10-07 15:01:28 +02:00
if ( empty ( $newcu )) {
2021-03-30 19:12:07 +02:00
$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 ;
2020-10-07 15:01:28 +02:00
} else {
$sql = 'SELECT rowid FROM ' . MAIN_DB_PREFIX . " societe_account " ;
2021-08-23 17:41:11 +02:00
$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 ; // Keep = here for entity. Only 1 record must be modified !
2020-10-07 15:01:28 +02:00
}
2018-10-16 20:00:53 +02:00
2018-03-13 17:32:49 +01:00
$resql = $db -> query ( $sql );
2020-01-30 01:48:28 +01:00
$num = $db -> num_rows ( $resql ); // Note: $num is always 0 on an update and delete, it is defined for select only.
2020-01-27 12:40:20 +01:00
if ( ! empty ( $newcu )) {
2021-02-26 21:17:52 +01:00
if ( empty ( $num )) {
2020-01-27 12:40:20 +01:00
$societeaccount = new SocieteAccount ( $db );
$societeaccount -> fk_soc = $object -> id ;
$societeaccount -> login = '' ;
$societeaccount -> pass_encoding = '' ;
$societeaccount -> site = 'stripe' ;
$societeaccount -> status = $servicestatus ;
$societeaccount -> key_account = $newcu ;
$societeaccount -> site_account = $site_account ;
$result = $societeaccount -> create ( $user );
2021-02-26 21:17:52 +01:00
if ( $result < 0 ) {
2020-01-27 12:40:20 +01:00
$error ++ ;
}
} else {
$sql = 'UPDATE ' . MAIN_DB_PREFIX . " societe_account " ;
2020-09-20 03:32:43 +02:00
$sql .= " SET key_account = ' " . $db -> escape ( GETPOST ( 'key_account' , 'alpha' )) . " ', site_account = ' " . $db -> escape ( $site_account ) . " ' " ;
2021-08-23 17:41:11 +02:00
$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 ; // Keep = here for entity. Only 1 record must be modified !
2020-01-27 12:40:20 +01:00
$resql = $db -> query ( $sql );
2018-03-13 17:32:49 +01:00
}
}
2020-01-27 12:40:20 +01:00
//var_dump($sql); var_dump($newcu); var_dump($num); exit;
2018-03-13 17:32:49 +01:00
2021-02-26 21:17:52 +01:00
if ( ! $error ) {
2018-03-13 17:32:49 +01:00
$stripecu = $newcu ;
$db -> commit ();
2020-05-21 15:05:19 +02:00
} else {
2018-03-13 17:32:49 +01:00
$db -> rollback ();
}
}
2019-09-14 14:25:47 +02:00
2021-02-26 21:17:52 +01:00
if ( $action == 'setkey_account_supplier' ) {
2019-08-22 22:20:50 +02:00
$error = 0 ;
$newsup = GETPOST ( 'key_account_supplier' , 'alpha' );
$db -> begin ();
2020-10-07 15:01:28 +02:00
if ( empty ( $newsup )) {
$sql = " DELETE FROM " . MAIN_DB_PREFIX . " oauth_token WHERE fk_soc = " . $object -> id . " AND service = ' " . $db -> escape ( $service ) . " ' AND entity = " . $conf -> entity ;
// TODO Add site and site_account on oauth_token table
2021-08-23 17:41:11 +02:00
//$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;
2020-10-07 15:01:28 +02:00
} else {
try {
$stripesup = \Stripe\Account :: retrieve ( $db -> escape ( GETPOST ( 'key_account_supplier' , 'alpha' )));
$tokenstring [ 'stripe_user_id' ] = $stripesup -> id ;
$tokenstring [ 'type' ] = $stripesup -> type ;
$sql = " UPDATE " . MAIN_DB_PREFIX . " oauth_token " ;
2020-11-11 15:55:04 +01:00
$sql .= " SET tokenstring = ' " . $db -> escape ( json_encode ( $tokenstring )) . " ' " ;
2021-08-23 17:41:11 +02:00
$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 ; // Keep = here for entity. Only 1 record must be modified !
2020-10-07 15:01:28 +02:00
// TODO Add site and site_account on oauth_token table
$sql .= " WHERE fk_soc = " . $object -> id . " AND service = ' " . $db -> escape ( $service ) . " ' AND entity = " . $conf -> entity ; // Keep = here for entity. Only 1 record must be modified !
} catch ( Exception $e ) {
2019-10-27 17:01:23 +01:00
$error ++ ;
setEventMessages ( $e -> getMessage (), null , 'errors' );
2019-08-22 22:48:37 +02:00
}
2019-10-27 17:01:23 +01:00
}
2019-08-22 22:20:50 +02:00
$resql = $db -> query ( $sql );
$num = $db -> num_rows ( $resql );
2021-02-26 21:17:52 +01:00
if ( empty ( $num ) && ! empty ( $newsup )) {
2020-10-07 15:01:28 +02:00
try {
$stripesup = \Stripe\Account :: retrieve ( $db -> escape ( GETPOST ( 'key_account_supplier' , 'alpha' )));
$tokenstring [ 'stripe_user_id' ] = $stripesup -> id ;
$tokenstring [ 'type' ] = $stripesup -> type ;
$sql = " INSERT INTO " . MAIN_DB_PREFIX . " oauth_token (service, fk_soc, entity, tokenstring) " ;
2021-08-28 03:09:18 +02:00
$sql .= " VALUES (' " . $db -> escape ( $service ) . " ', " . (( int ) $object -> id ) . " , " . (( int ) $conf -> entity ) . " , ' " . $db -> escape ( json_encode ( $tokenstring )) . " ') " ;
2020-10-07 15:01:28 +02:00
// TODO Add site and site_account on oauth_token table
} catch ( Exception $e ) {
2019-08-22 22:48:37 +02:00
$error ++ ;
setEventMessages ( $e -> getMessage (), null , 'errors' );
}
$resql = $db -> query ( $sql );
2019-08-22 22:20:50 +02:00
}
2021-02-26 21:17:52 +01:00
if ( ! $error ) {
2019-08-22 22:20:50 +02:00
$stripesupplieracc = $newsup ;
$db -> commit ();
2020-05-21 15:05:19 +02:00
} else {
2019-08-22 22:20:50 +02:00
$db -> rollback ();
}
}
2021-02-26 21:17:52 +01:00
if ( $action == 'setlocalassourcedefault' ) { // Set as default when payment mode defined locally (and may be also remotely)
2018-03-14 11:51:13 +01:00
try {
2018-03-14 13:56:21 +01:00
$companypaymentmode -> setAsDefault ( $id );
2018-03-14 11:51:13 +01:00
2019-11-13 18:32:11 +01:00
$url = DOL_URL_ROOT . '/societe/paymentmodes.php?socid=' . $object -> id ;
2018-03-14 11:51:13 +01:00
header ( 'Location: ' . $url );
exit ;
2021-02-26 21:17:52 +01:00
} catch ( Exception $e ) {
2018-03-15 00:53:24 +01:00
$error ++ ;
setEventMessages ( $e -> getMessage (), null , 'errors' );
2018-03-14 11:51:13 +01:00
}
2021-02-26 21:17:52 +01:00
} elseif ( $action == 'setassourcedefault' ) { // Set as default when payment mode defined remotely only
2018-03-13 17:32:49 +01:00
try {
2019-11-13 18:32:11 +01:00
$cu = $stripe -> customerStripe ( $object , $stripeacc , $servicestatus );
2021-02-26 21:17:52 +01:00
if ( preg_match ( '/pm_/' , $source )) {
2019-11-13 18:32:11 +01:00
$cu -> invoice_settings -> default_payment_method = ( string ) $source ; // New
2020-05-21 15:05:19 +02:00
} else {
2019-11-13 18:32:11 +01:00
$cu -> default_source = ( string ) $source ; // Old
2019-06-16 17:17:07 +02:00
}
2018-03-13 17:32:49 +01:00
$result = $cu -> save ();
2019-11-13 18:32:11 +01:00
$url = DOL_URL_ROOT . '/societe/paymentmodes.php?socid=' . $object -> id ;
2018-03-13 17:32:49 +01:00
header ( 'Location: ' . $url );
exit ;
2021-02-26 21:17:52 +01:00
} catch ( Exception $e ) {
2018-03-15 00:53:24 +01:00
$error ++ ;
setEventMessages ( $e -> getMessage (), null , 'errors' );
2018-03-13 17:32:49 +01:00
}
2021-02-26 21:17:52 +01:00
} elseif ( $action == 'deletecard' && $source ) {
2018-03-13 17:32:49 +01:00
try {
2021-02-26 21:17:52 +01:00
if ( preg_match ( '/pm_/' , $source )) {
2020-10-07 15:01:28 +02:00
$payment_method = \Stripe\PaymentMethod :: retrieve ( $source , array ( " stripe_account " => $stripeacc ));
2021-02-26 21:17:52 +01:00
if ( $payment_method ) {
2020-10-07 15:01:28 +02:00
$payment_method -> detach ();
}
2020-05-21 15:05:19 +02:00
} else {
2020-10-07 15:01:28 +02:00
$cu = $stripe -> customerStripe ( $object , $stripeacc , $servicestatus );
$card = $cu -> sources -> retrieve ( " $source " );
if ( $card ) {
// $card->detach(); Does not work with card_, only with src_
if ( method_exists ( $card , 'detach' )) {
2019-10-27 17:01:23 +01:00
$card -> detach ();
} else {
$card -> delete ();
}
2020-10-07 15:01:28 +02:00
}
2019-07-02 21:46:00 +02:00
}
2018-03-13 17:32:49 +01:00
2019-11-13 18:32:11 +01:00
$url = DOL_URL_ROOT . '/societe/paymentmodes.php?socid=' . $object -> id ;
2018-03-13 17:32:49 +01:00
header ( 'Location: ' . $url );
exit ;
2021-02-26 21:17:52 +01:00
} catch ( Exception $e ) {
2018-03-15 00:53:24 +01:00
$error ++ ;
setEventMessages ( $e -> getMessage (), null , 'errors' );
2018-03-13 17:32:49 +01:00
}
}
2018-03-07 16:17:25 +01:00
}
}
2018-03-13 17:32:49 +01:00
2018-03-07 16:17:25 +01:00
/*
* View
*/
$form = new Form ( $db );
2018-03-14 11:51:13 +01:00
$formother = new FormOther ( $db );
2018-03-07 16:17:25 +01:00
$formfile = new FormFile ( $db );
2021-05-09 22:23:15 +02:00
$title = $langs -> trans ( " ThirdParty " );
if ( ! empty ( $conf -> global -> MAIN_HTML_TITLE ) && preg_match ( '/thirdpartynameonly/' , $conf -> global -> MAIN_HTML_TITLE ) && $object -> name ) {
$title = $object -> name . " - " . $langs -> trans ( 'PaymentInformation' );
}
2018-03-07 16:17:25 +01:00
llxHeader ();
2018-03-08 22:26:42 +01:00
2019-11-13 18:32:11 +01:00
$head = societe_prepare_head ( $object );
2018-03-08 02:08:14 +01:00
2018-03-14 21:07:45 +01:00
// Show sandbox warning
/* if ( ! empty ( $conf -> paypal -> enabled ) && ( ! empty ( $conf -> global -> PAYPAL_API_SANDBOX ) || GETPOST ( 'forcesandbox' , 'alpha' ))) // We can force sand box with param 'forcesandbox'
{
dol_htmloutput_mesg ( $langs -> trans ( 'YouAreCurrentlyInSandboxMode' , 'Paypal' ), '' , 'warning' );
} */
2021-02-26 21:17:52 +01:00
if ( ! empty ( $conf -> stripe -> enabled ) && ( empty ( $conf -> global -> STRIPE_LIVE ) || GETPOST ( 'forcesandbox' , 'alpha' ))) {
2019-01-27 11:55:16 +01:00
dol_htmloutput_mesg ( $langs -> trans ( 'YouAreCurrentlyInSandboxMode' , 'Stripe' ), '' , 'warning' );
2018-03-14 21:07:45 +01:00
}
2018-03-14 13:56:21 +01:00
// Load Bank account
2021-02-26 21:17:52 +01:00
if ( ! $id ) {
2018-03-14 13:56:21 +01:00
$companybankaccount -> fetch ( 0 , $object -> id );
$companypaymentmode -> fetch ( 0 , null , $object -> id , 'card' );
2020-05-21 15:05:19 +02:00
} else {
2018-03-14 13:56:21 +01:00
$companybankaccount -> fetch ( $id );
$companypaymentmode -> fetch ( $id );
2018-03-07 16:17:25 +01:00
}
2021-02-26 21:17:52 +01:00
if ( empty ( $companybankaccount -> socid )) {
$companybankaccount -> socid = $object -> id ;
}
2018-03-07 16:17:25 +01:00
2021-11-02 04:51:18 +01:00
if ( $socid && ( $action == 'edit' || $action == 'editcard' ) && $permissiontoadd ) {
2018-03-08 22:26:42 +01:00
print '<form action="' . $_SERVER [ " PHP_SELF " ] . '?socid=' . $object -> id . '" method="post">' ;
2019-12-18 23:12:31 +01:00
print '<input type="hidden" name="token" value="' . newToken () . '">' ;
2019-11-13 18:32:11 +01:00
$actionforadd = 'update' ;
2021-02-26 21:17:52 +01:00
if ( $action == 'editcard' ) {
$actionforadd = 'updatecard' ;
}
2018-03-14 13:56:21 +01:00
print '<input type="hidden" name="action" value="' . $actionforadd . '">' ;
2019-01-27 11:55:16 +01:00
print '<input type="hidden" name="id" value="' . GETPOST ( " id " , " int " ) . '">' ;
2018-03-07 16:17:25 +01:00
}
2021-11-02 04:51:18 +01:00
if ( $socid && ( $action == 'create' || $action == 'createcard' ) && $permissiontoadd ) {
2018-03-08 22:26:42 +01:00
print '<form action="' . $_SERVER [ " PHP_SELF " ] . '?socid=' . $object -> id . '" method="post">' ;
2019-12-18 23:12:31 +01:00
print '<input type="hidden" name="token" value="' . newToken () . '">' ;
2019-11-13 18:32:11 +01:00
$actionforadd = 'add' ;
2021-02-26 21:17:52 +01:00
if ( $action == 'createcard' ) {
$actionforadd = 'addcard' ;
}
2018-03-14 11:51:13 +01:00
print '<input type="hidden" name="action" value="' . $actionforadd . '">' ;
2018-03-07 16:17:25 +01:00
}
// View
2021-02-26 21:17:52 +01:00
if ( $socid && $action != 'edit' && $action != 'create' && $action != 'editcard' && $action != 'createcard' ) {
2020-10-22 22:50:03 +02:00
print dol_get_fiche_head ( $head , 'rib' , $langs -> trans ( " ThirdParty " ), - 1 , 'company' );
2018-03-07 16:17:25 +01:00
2018-03-14 11:51:13 +01:00
// Confirm delete ban
2021-02-26 21:17:52 +01:00
if ( $action == 'delete' ) {
2019-11-13 18:32:11 +01:00
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 );
2018-03-07 16:17:25 +01:00
}
2018-03-14 11:51:13 +01:00
// Confirm delete card
2021-02-26 21:17:52 +01:00
if ( $action == 'deletecard' ) {
2019-11-13 18:32:11 +01:00
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 );
2018-03-14 11:51:13 +01:00
}
2018-03-07 16:17:25 +01:00
$linkback = '<a href="' . DOL_URL_ROOT . '/societe/list.php?restore_lastsearch_values=1">' . $langs -> trans ( " BackToList " ) . '</a>' ;
2019-11-13 18:32:11 +01:00
dol_banner_tab ( $object , 'socid' , $linkback , ( $user -> socid ? 0 : 1 ), 'rowid' , 'nom' );
2018-03-07 16:17:25 +01:00
2018-03-12 16:04:23 +01:00
print '<div class="fichecenter">' ;
print '<div class="underbanner clearboth"></div>' ;
2019-09-14 14:25:47 +02:00
print '<table class="border tableforfield centpercent">' ;
2018-03-12 16:04:23 +01:00
2021-06-23 19:02:14 +02:00
// Type Prospect/Customer/Supplier
print '<tr><td class="titlefield">' . $langs -> trans ( 'NatureOfThirdParty' ) . '</td><td>' ;
print $object -> getTypeUrl ( 1 );
print '</td></tr>' ;
if ( ! empty ( $conf -> global -> SOCIETE_USEPREFIX )) { // Old not used prefix field
print '<tr><td class="titlefield">' . $langs -> trans ( 'Prefix' ) . '</td><td colspan="3">' . $object -> prefix_comm . '</td></tr>' ;
}
2021-02-26 21:17:52 +01:00
if ( $object -> client ) {
2018-03-12 16:04:23 +01:00
print '<tr><td class="titlefield">' ;
2018-03-14 16:53:16 +01:00
print $langs -> trans ( 'CustomerCode' ) . '</td><td colspan="2">' ;
2021-02-27 03:06:21 +01:00
print showValueWithClipboardCPButton ( dol_escape_htmltag ( $object -> code_client ));
2020-12-20 13:54:02 +01:00
$tmpcheck = $object -> check_codeclient ();
if ( $tmpcheck != 0 && $tmpcheck != - 5 ) {
2021-10-05 10:20:35 +02:00
print ' <span class="error">(' . $langs -> trans ( " WrongCustomerCode " ) . ')</span>' ;
2020-12-20 13:54:02 +01:00
}
2018-03-12 16:04:23 +01:00
print '</td></tr>' ;
2021-03-30 19:12:07 +02:00
$sql = " SELECT count(*) as nb from " . MAIN_DB_PREFIX . " facture where fk_soc = " . (( int ) $socid );
2019-11-13 18:32:11 +01:00
$resql = $db -> query ( $sql );
2021-02-26 21:17:52 +01:00
if ( ! $resql ) {
dol_print_error ( $db );
}
2018-03-12 16:04:23 +01:00
$obj = $db -> fetch_object ( $resql );
$nbFactsClient = $obj -> nb ;
2019-11-13 18:32:11 +01:00
$thirdTypeArray [ 'customer' ] = $langs -> trans ( " customer " );
2021-10-22 15:27:36 +02:00
if ( ! empty ( $conf -> propal -> enabled ) && $user -> rights -> propal -> lire ) {
2021-02-26 21:17:52 +01:00
$elementTypeArray [ 'propal' ] = $langs -> transnoentitiesnoconv ( 'Proposals' );
}
2021-10-22 15:27:36 +02:00
if ( ! empty ( $conf -> commande -> enabled ) && $user -> rights -> commande -> lire ) {
2021-02-26 21:17:52 +01:00
$elementTypeArray [ 'order' ] = $langs -> transnoentitiesnoconv ( 'Orders' );
}
2021-10-22 15:27:36 +02:00
if ( ! empty ( $conf -> facture -> enabled ) && $user -> rights -> facture -> lire ) {
2021-02-26 21:17:52 +01:00
$elementTypeArray [ 'invoice' ] = $langs -> transnoentitiesnoconv ( 'Invoices' );
}
2021-10-22 15:27:36 +02:00
if ( ! empty ( $conf -> contrat -> enabled ) && $user -> rights -> contrat -> lire ) {
2021-02-26 21:17:52 +01:00
$elementTypeArray [ 'contract' ] = $langs -> transnoentitiesnoconv ( 'Contracts' );
}
2018-03-12 16:04:23 +01:00
2021-02-26 21:17:52 +01:00
if ( ! empty ( $conf -> stripe -> enabled )) {
2019-07-20 16:08:31 +02:00
// Stripe customer key 'cu_....' stored into llx_societe_account
print '<tr><td class="titlefield">' ;
2021-11-02 04:51:18 +01:00
print $form -> editfieldkey ( " StripeCustomerId " , 'key_account' , $stripecu , $object , $permissiontoadd , 'string' , '' , 0 , 2 , 'socid' );
2019-07-20 16:08:31 +02:00
print '</td><td>' ;
2021-11-02 04:51:18 +01:00
print $form -> editfieldval ( " StripeCustomerId " , 'key_account' , $stripecu , $object , $permissiontoadd , 'string' , '' , null , null , '' , 2 , '' , 'socid' );
2021-02-26 21:17:52 +01:00
if ( ! empty ( $conf -> stripe -> enabled ) && $stripecu && $action != 'editkey_account' ) {
2020-10-07 15:01:28 +02:00
$connect = '' ;
2021-02-26 21:17:52 +01:00
if ( ! empty ( $stripeacc )) {
$connect = $stripeacc . '/' ;
}
2019-11-13 18:32:11 +01:00
$url = 'https://dashboard.stripe.com/' . $connect . 'test/customers/' . $stripecu ;
2021-02-26 21:17:52 +01:00
if ( $servicestatus ) {
2019-11-13 18:32:11 +01:00
$url = 'https://dashboard.stripe.com/' . $connect . 'customers/' . $stripecu ;
2019-07-20 16:08:31 +02:00
}
2020-01-22 16:02:28 +01:00
print ' <a href="' . $url . '" target="_stripe">' . img_picto ( $langs -> trans ( 'ShowInStripe' ) . ' - Publishable key = ' . $site_account , 'globe' ) . '</a>' ;
2018-03-15 00:40:29 +01:00
}
2019-07-20 16:08:31 +02:00
print '</td><td class="right">' ;
2021-02-26 21:17:52 +01:00
if ( empty ( $stripecu )) {
2019-07-20 16:08:31 +02:00
print '<form action="' . $_SERVER [ " PHP_SELF " ] . '" method="post">' ;
print '<input type="hidden" name="action" value="synccustomertostripe">' ;
2019-12-18 23:12:31 +01:00
print '<input type="hidden" name="token" value="' . newToken () . '">' ;
2019-07-20 16:08:31 +02:00
print '<input type="hidden" name="socid" value="' . $object -> id . '">' ;
2020-08-04 21:17:13 +02:00
print '<input type="submit" class="button buttongen" name="syncstripecustomer" value="' . $langs -> trans ( " CreateCustomerOnStripe " ) . '">' ;
2019-07-20 16:08:31 +02:00
print '</form>' ;
}
print '</td></tr>' ;
2018-03-14 16:53:16 +01:00
}
2020-10-07 15:01:28 +02:00
}
2019-09-14 14:25:47 +02:00
2021-02-26 21:17:52 +01:00
if ( $object -> fournisseur ) {
2019-08-05 23:34:28 +02:00
print '<tr><td class="titlefield">' ;
print $langs -> trans ( 'SupplierCode' ) . '</td><td colspan="2">' ;
2021-02-27 03:06:21 +01:00
print showValueWithClipboardCPButton ( dol_escape_htmltag ( $object -> code_fournisseur ));
2020-12-20 13:54:02 +01:00
$tmpcheck = $object -> check_codefournisseur ();
if ( $tmpcheck != 0 && $tmpcheck != - 5 ) {
2021-10-05 10:20:35 +02:00
print ' <span class="error">(' . $langs -> trans ( " WrongSupplierCode " ) . ')</span>' ;
2020-12-20 13:54:02 +01:00
}
2019-08-05 23:34:28 +02:00
print '</td></tr>' ;
2021-03-30 19:12:07 +02:00
$sql = " SELECT count(*) as nb from " . MAIN_DB_PREFIX . " facture where fk_soc = " . (( int ) $socid );
2019-11-13 18:32:11 +01:00
$resql = $db -> query ( $sql );
2021-02-26 21:17:52 +01:00
if ( ! $resql ) {
dol_print_error ( $db );
}
2019-08-05 23:34:28 +02:00
$obj = $db -> fetch_object ( $resql );
$nbFactsClient = $obj -> nb ;
2019-11-13 18:32:11 +01:00
$thirdTypeArray [ 'customer' ] = $langs -> trans ( " customer " );
2021-02-26 21:17:52 +01:00
if ( $conf -> propal -> enabled && $user -> rights -> propal -> lire ) {
$elementTypeArray [ 'propal' ] = $langs -> transnoentitiesnoconv ( 'Proposals' );
}
if ( $conf -> commande -> enabled && $user -> rights -> commande -> lire ) {
$elementTypeArray [ 'order' ] = $langs -> transnoentitiesnoconv ( 'Orders' );
}
if ( $conf -> facture -> enabled && $user -> rights -> facture -> lire ) {
$elementTypeArray [ 'invoice' ] = $langs -> transnoentitiesnoconv ( 'Invoices' );
}
if ( $conf -> contrat -> enabled && $user -> rights -> contrat -> lire ) {
$elementTypeArray [ 'contract' ] = $langs -> transnoentitiesnoconv ( 'Contracts' );
}
2019-08-06 13:08:34 +02:00
}
2019-09-14 14:25:47 +02:00
2021-02-26 21:17:52 +01:00
if ( ! empty ( $conf -> stripe -> enabled ) && ! empty ( $conf -> stripeconnect -> enabled ) && $conf -> global -> MAIN_FEATURES_LEVEL >= 2 ) {
2019-11-13 18:32:11 +01:00
$stripesupplieracc = $stripe -> getStripeAccount ( $service , $object -> id ); // Get Stripe OAuth connect account (no network access here)
2019-09-14 14:25:47 +02:00
2019-08-05 23:34:28 +02:00
// Stripe customer key 'cu_....' stored into llx_societe_account
print '<tr><td class="titlefield">' ;
2021-11-02 04:51:18 +01:00
print $form -> editfieldkey ( " StripeConnectAccount " , 'key_account_supplier' , $stripesupplieracc , $object , $permissiontoadd , 'string' , '' , 0 , 2 , 'socid' );
2019-08-05 23:34:28 +02:00
print '</td><td>' ;
2021-11-02 04:51:18 +01:00
print $form -> editfieldval ( " StripeConnectAccount " , 'key_account_supplier' , $stripesupplieracc , $object , $permissiontoadd , 'string' , '' , null , null , '' , 2 , '' , 'socid' );
2021-02-26 21:17:52 +01:00
if ( ! empty ( $conf -> stripe -> enabled ) && $stripesupplieracc && $action != 'editkey_account_supplier' ) {
2020-10-07 15:01:28 +02:00
$connect = '' ;
2019-09-14 14:25:47 +02:00
2019-11-13 18:32:11 +01:00
$url = 'https://dashboard.stripe.com/test/connect/accounts/' . $stripesupplieracc ;
2021-02-26 21:17:52 +01:00
if ( $servicestatus ) {
2019-11-13 18:32:11 +01:00
$url = 'https://dashboard.stripe.com/connect/accounts/' . $stripesupplieracc ;
2019-08-05 23:34:28 +02:00
}
2019-12-24 12:53:10 +01:00
print ' <a href="' . $url . '" target="_stripe">' . img_picto ( $langs -> trans ( 'ShowInStripe' ) . ' - Publishable key ' . $site_account , 'globe' ) . '</a>' ;
2019-08-05 23:34:28 +02:00
}
print '</td><td class="right">' ;
2021-02-26 21:17:52 +01:00
if ( empty ( $stripesupplieracc )) {
2019-08-05 23:34:28 +02:00
print '<form action="' . $_SERVER [ " PHP_SELF " ] . '" method="post">' ;
print '<input type="hidden" name="action" value="syncsuppliertostripe">' ;
2019-12-18 23:12:31 +01:00
print '<input type="hidden" name="token" value="' . newToken () . '">' ;
2019-08-05 23:34:28 +02:00
print '<input type="hidden" name="socid" value="' . $object -> id . '">' ;
print '<input type="hidden" name="companybankid" value="' . $rib -> id . '">' ;
2020-08-04 21:17:13 +02:00
//print '<input type="submit" class="button buttongen" name="syncstripecustomer" value="'.$langs->trans("CreateSupplierOnStripe").'">';
2019-08-05 23:34:28 +02:00
print '</form>' ;
}
print '</td></tr>' ;
}
2018-03-07 16:17:25 +01:00
2018-03-12 16:04:23 +01:00
print '</table>' ;
print '</div>' ;
2020-10-27 18:19:31 +01:00
print dol_get_fiche_end ();
2018-04-24 11:12:12 +02:00
2018-03-13 15:19:31 +01:00
print '<br>' ;
2018-03-14 13:56:21 +01:00
// List of Stripe payment modes
2021-02-26 21:17:52 +01:00
if ( ! ( empty ( $conf -> stripe -> enabled )) && $object -> client ) {
2019-11-13 18:32:11 +01:00
$morehtmlright = '' ;
2021-02-26 21:17:52 +01:00
if ( ! empty ( $conf -> global -> STRIPE_ALLOW_LOCAL_CARD )) {
2020-10-07 15:01:28 +02:00
$morehtmlright .= dolGetButtonTitle ( $langs -> trans ( 'Add' ), '' , 'fa fa-plus-circle' , $_SERVER [ " PHP_SELF " ] . '?socid=' . $object -> id . '&action=createcard' );
2018-03-13 22:43:50 +01:00
}
2020-05-27 00:26:04 +02:00
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' );
2018-03-08 22:26:42 +01:00
2018-03-13 15:19:31 +01:00
$listofsources = array ();
2021-02-26 21:17:52 +01:00
if ( is_object ( $stripe )) {
2018-03-13 17:32:49 +01:00
try {
2019-11-13 18:32:11 +01:00
$customerstripe = $stripe -> customerStripe ( $object , $stripeacc , $servicestatus );
2020-12-29 17:48:52 +01:00
if ( ! empty ( $customerstripe -> id )) {
2019-05-17 00:10:44 +02:00
// When using the Charge API architecture
2021-02-26 21:17:52 +01:00
if ( empty ( $conf -> global -> STRIPE_USE_INTENT_WITH_AUTOMATIC_CONFIRMATION )) {
2019-11-13 18:32:11 +01:00
$listofsources = $customerstripe -> sources -> data ;
2020-05-21 15:05:19 +02:00
} else {
2019-05-17 00:10:44 +02:00
$service = 'StripeTest' ;
$servicestatus = 0 ;
2021-02-26 21:17:52 +01:00
if ( ! empty ( $conf -> global -> STRIPE_LIVE ) && ! GETPOST ( 'forcesandbox' , 'alpha' )) {
2019-05-17 00:10:44 +02:00
$service = 'StripeLive' ;
$servicestatus = 1 ;
}
// Force to use the correct API key
global $stripearrayofkeysbyenv ;
\Stripe\Stripe :: setApiKey ( $stripearrayofkeysbyenv [ $servicestatus ][ 'secret_key' ]);
try {
if ( empty ( $stripeacc )) { // If the Stripe connect account not set, we use common API usage
2021-01-24 17:18:21 +01:00
$paymentmethodobjsA = \Stripe\PaymentMethod :: all ( array ( " customer " => $customerstripe -> id , " type " => " card " ));
2021-01-24 17:22:49 +01:00
$paymentmethodobjsB = \Stripe\PaymentMethod :: all ( array ( " customer " => $customerstripe -> id , " type " => " sepa_debit " ));
2019-05-17 00:10:44 +02:00
} else {
2021-01-24 17:18:21 +01:00
$paymentmethodobjsA = \Stripe\PaymentMethod :: all ( array ( " customer " => $customerstripe -> id , " type " => " card " ), array ( " stripe_account " => $stripeacc ));
2021-01-24 17:22:49 +01:00
$paymentmethodobjsB = \Stripe\PaymentMethod :: all ( array ( " customer " => $customerstripe -> id , " type " => " sepa_debit " ), array ( " stripe_account " => $stripeacc ));
2019-05-17 00:10:44 +02:00
}
2021-02-26 21:17:52 +01:00
if ( $paymentmethodobjsA -> data != null && $paymentmethodobjsB -> data != null ) {
$listofsources = array_merge (( array ) $paymentmethodobjsA -> data , ( array ) $paymentmethodobjsB -> data );
} elseif ( $paymentmethodobjsB -> data != null ) {
$listofsources = $paymentmethodobjsB -> data ;
} else {
$listofsources = $paymentmethodobjsA -> data ;
}
} catch ( Exception $e ) {
2019-05-17 00:10:44 +02:00
$error ++ ;
setEventMessages ( $e -> getMessage (), null , 'errors' );
2021-01-24 17:22:49 +01:00
}
2019-05-17 00:10:44 +02:00
}
2018-03-13 17:32:49 +01:00
}
2021-02-26 21:17:52 +01:00
} catch ( Exception $e ) {
2018-03-14 16:53:16 +01:00
dol_syslog ( " Error when searching/loading Stripe customer for thirdparty id = " . $object -> id );
2018-03-13 15:19:31 +01:00
}
2018-03-07 16:17:25 +01:00
}
2019-03-21 19:27:56 +01:00
print '<!-- List of stripe payments -->' . " \n " ;
2020-01-30 01:48:28 +01:00
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
2019-11-05 21:24:41 +01:00
print '<table class="liste centpercent">' . " \n " ;
2018-03-07 16:17:25 +01:00
print '<tr class="liste_titre">' ;
2021-02-26 21:17:52 +01:00
if ( ! empty ( $conf -> global -> STRIPE_ALLOW_LOCAL_CARD )) {
2018-03-13 22:43:50 +01:00
print '<td>' . $langs -> trans ( 'LocalID' ) . '</td>' ;
}
2020-01-02 17:19:42 +01:00
print '<td>' . $langs -> trans ( 'Label' ) . '</td>' ;
2018-03-13 22:43:50 +01:00
print '<td>' . $langs -> trans ( 'StripeID' ) . '</td>' ;
2018-03-13 17:32:49 +01:00
print '<td>' . $langs -> trans ( 'Type' ) . '</td>' ;
print '<td>' . $langs -> trans ( 'Informations' ) . '</td>' ;
print '<td></td>' ;
2019-02-23 21:02:39 +01:00
print '<td class="center">' . $langs -> trans ( 'Default' ) . '</td>' ;
2018-03-13 22:43:50 +01:00
print '<td>' . $langs -> trans ( 'Note' ) . '</td>' ;
2018-09-09 13:15:32 +02:00
print '<td>' . $langs -> trans ( 'DateModification' ) . '</td>' ;
2019-01-28 01:46:59 +01:00
// Hook fields
2019-11-13 18:32:11 +01:00
$parameters = array ( 'arrayfields' => array (), 'param' => '' , 'sortfield' => '' , 'sortorder' => '' , 'linetype' => 'stripetitle' );
$reshook = $hookmanager -> executeHooks ( 'printFieldListTitle' , $parameters , $object ); // Note that $action and $object may have been modified by hook
2019-01-28 01:46:59 +01:00
print $hookmanager -> resPrint ;
// Action column
2018-09-09 13:15:32 +02:00
print " <td></td> " ;
print " </tr> \n " ;
2018-03-07 16:17:25 +01:00
2018-03-13 22:43:50 +01:00
$nbremote = 0 ;
$nblocal = 0 ;
$arrayofstripecard = array ();
// Show local sources
2021-02-26 21:17:52 +01:00
if ( ! empty ( $conf -> global -> STRIPE_ALLOW_LOCAL_CARD )) {
2018-03-13 22:43:50 +01:00
//$societeaccount = new SocieteAccount($db);
$companypaymentmodetemp = new CompanyPaymentMode ( $db );
2019-11-13 18:32:11 +01:00
$sql = 'SELECT rowid FROM ' . MAIN_DB_PREFIX . " societe_rib " ;
$sql .= " WHERE type in ('card') " ;
2021-06-09 15:36:47 +02:00
$sql .= " AND fk_soc = " . (( int ) $object -> id );
$sql .= " AND status = " . (( int ) $servicestatus );
2018-03-13 22:43:50 +01:00
$resql = $db -> query ( $sql );
2021-02-26 21:17:52 +01:00
if ( $resql ) {
2018-03-13 22:43:50 +01:00
$num_rows = $db -> num_rows ( $resql );
2021-02-26 21:17:52 +01:00
if ( $num_rows ) {
2019-11-13 18:32:11 +01:00
$i = 0 ;
2021-02-26 21:17:52 +01:00
while ( $i < $num_rows ) {
2018-03-13 22:43:50 +01:00
$nblocal ++ ;
$obj = $db -> fetch_object ( $resql );
2021-02-26 21:17:52 +01:00
if ( $obj ) {
2018-03-13 22:43:50 +01:00
$companypaymentmodetemp -> fetch ( $obj -> rowid );
2019-11-13 18:32:11 +01:00
$arrayofstripecard [ $companypaymentmodetemp -> stripe_card_ref ] = $companypaymentmodetemp -> stripe_card_ref ;
2018-03-13 22:43:50 +01:00
2019-03-04 12:29:36 +01:00
print '<tr class="oddeven">' ;
2018-03-13 22:43:50 +01:00
print '<td>' ;
2018-03-14 13:56:21 +01:00
print $companypaymentmodetemp -> id ;
2018-03-13 22:43:50 +01:00
print '</td>' ;
print '<td>' ;
2020-01-02 17:19:42 +01:00
print $companypaymentmodetemp -> label ;
print '</td>' ;
print '<td>' ;
2018-03-14 13:56:21 +01:00
print $companypaymentmodetemp -> stripe_card_ref ;
2021-02-26 21:17:52 +01:00
if ( $companypaymentmodetemp -> stripe_card_ref ) {
2020-10-07 15:01:28 +02:00
$connect = '' ;
2021-02-26 21:17:52 +01:00
if ( ! empty ( $stripeacc )) {
$connect = $stripeacc . '/' ;
}
2020-10-07 15:01:28 +02:00
$url = 'https://dashboard.stripe.com/' . $connect . 'test/search?query=' . $companypaymentmodetemp -> stripe_card_ref ;
2021-02-26 21:17:52 +01:00
if ( $servicestatus ) {
2019-11-13 18:32:11 +01:00
$url = 'https://dashboard.stripe.com/' . $connect . 'search?query=' . $companypaymentmodetemp -> stripe_card_ref ;
2018-03-15 00:40:29 +01:00
}
2020-01-22 16:02:28 +01:00
print ' <a href="' . $url . '" target="_stripe">' . img_picto ( $langs -> trans ( 'ShowInStripe' ) . ' - Customer and Publishable key = ' . $companypaymentmodetemp -> stripe_account , 'globe' ) . '</a>' ;
2019-03-21 19:27:56 +01:00
}
2018-03-13 22:43:50 +01:00
print '</td>' ;
print '<td>' ;
print img_credit_card ( $companypaymentmodetemp -> type );
print '</td>' ;
print '<td>' ;
2021-02-26 21:17:52 +01:00
if ( $companypaymentmodetemp -> proprio ) {
print '<span class="opacitymedium">' . $companypaymentmodetemp -> proprio . '</span><br>' ;
}
if ( $companypaymentmodetemp -> last_four ) {
print '....' . $companypaymentmodetemp -> last_four ;
}
if ( $companypaymentmodetemp -> exp_date_month || $companypaymentmodetemp -> exp_date_year ) {
print ' - ' . sprintf ( " %02d " , $companypaymentmodetemp -> exp_date_month ) . '/' . $companypaymentmodetemp -> exp_date_year . '' ;
}
2018-03-13 22:43:50 +01:00
print '</td><td>' ;
2021-02-26 21:17:52 +01:00
if ( $companypaymentmodetemp -> country_code ) {
2019-11-13 18:32:11 +01:00
$img = picto_from_langcode ( $companypaymentmodetemp -> country_code );
print $img ? $img . ' ' : '' ;
2019-01-27 11:55:16 +01:00
print getCountry ( $companypaymentmodetemp -> country_code , 1 );
2021-02-26 21:17:52 +01:00
} else {
2021-10-05 10:20:35 +02:00
print img_warning () . ' <span class="error">' . $langs -> trans ( " ErrorFieldRequired " , $langs -> transnoentitiesnoconv ( " CompanyCountry " )) . '</span>' ;
2021-02-26 21:17:52 +01:00
}
2018-03-13 22:43:50 +01:00
print '</td>' ;
2018-03-13 22:54:28 +01:00
// Default
2019-02-23 21:02:39 +01:00
print '<td class="center">' ;
2021-02-26 21:17:52 +01:00
if ( empty ( $companypaymentmodetemp -> default_rib )) {
2020-09-30 15:13:28 +02:00
print '<a href="' . DOL_URL_ROOT . '/societe/paymentmodes.php?socid=' . $object -> id . '&id=' . $companypaymentmodetemp -> id . '&action=setlocalassourcedefault&token=' . newToken () . '">' ;
2019-01-27 11:55:16 +01:00
print img_picto ( $langs -> trans ( " Default " ), 'off' );
2018-03-14 11:51:13 +01:00
print '</a>' ;
2018-03-13 22:54:28 +01:00
} else {
2019-01-27 11:55:16 +01:00
print img_picto ( $langs -> trans ( " Default " ), 'on' );
2018-03-13 22:54:28 +01:00
}
2018-03-13 22:43:50 +01:00
print '</td>' ;
print '<td>' ;
2021-02-26 21:17:52 +01:00
if ( empty ( $companypaymentmodetemp -> stripe_card_ref )) {
print $langs -> trans ( " Local " );
} else {
print $langs -> trans ( " LocalAndRemote " );
}
2018-03-13 22:43:50 +01:00
print '</td>' ;
2018-09-09 13:15:32 +02:00
print '<td>' ;
print dol_print_date ( $companypaymentmodetemp -> tms , 'dayhour' );
print '</td>' ;
2019-01-28 01:46:59 +01:00
// Fields from hook
2019-11-13 18:32:11 +01:00
$parameters = array ( 'arrayfields' => array (), 'obj' => $obj , 'linetype' => 'stripecard' );
$reshook = $hookmanager -> executeHooks ( 'printFieldListValue' , $parameters , $object ); // Note that $action and $object may have been modified by hook
2019-01-28 01:46:59 +01:00
print $hookmanager -> resPrint ;
// Action column
2019-02-23 21:02:39 +01:00
print '<td class="right nowraponall">' ;
2021-11-02 04:51:18 +01:00
if ( $permissiontoadd ) {
2021-02-26 21:17:52 +01:00
if ( $stripecu && empty ( $companypaymentmodetemp -> stripe_card_ref )) {
2020-07-05 13:30:56 +02:00
print '<a href="' . $_SERVER [ 'PHP_SELF' ] . '?action=synccardtostripe&socid=' . $object -> id . '&id=' . $companypaymentmodetemp -> id . '" class="paddingrightonly marginrightonly">' . $langs -> trans ( " CreateCardOnStripe " ) . '</a>' ;
2018-03-14 21:07:45 +01:00
}
2020-10-01 10:50:54 +02:00
print '<a class="editfielda marginleftonly marginrightonly" href="' . DOL_URL_ROOT . '/societe/paymentmodes.php?socid=' . $object -> id . '&id=' . $companypaymentmodetemp -> id . '&action=editcard&token=' . newToken () . '">' ;
2019-01-27 11:55:16 +01:00
print img_picto ( $langs -> trans ( " Modify " ), 'edit' );
2018-03-13 22:43:50 +01:00
print '</a>' ;
print ' ' ;
2020-10-01 10:50:54 +02:00
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.'&
2018-03-14 20:08:44 +01:00
print img_picto ( $langs -> trans ( " Delete " ), 'delete' );
2018-03-13 22:43:50 +01:00
print '</a>' ;
}
print '</td>' ;
print '</tr>' ;
}
$i ++ ;
}
}
2021-01-20 22:40:40 +01:00
} else {
dol_print_error ( $db );
}
2018-03-13 22:43:50 +01:00
}
// Show remote sources (not already shown as local source)
2021-01-20 22:40:40 +01:00
if ( is_array ( $listofsources ) && count ( $listofsources )) {
foreach ( $listofsources as $src ) {
2021-02-26 21:17:52 +01:00
if ( ! empty ( $arrayofstripecard [ $src -> id ])) {
continue ; // Already in previous list
}
2018-03-13 22:43:50 +01:00
$nbremote ++ ;
2018-03-13 17:32:49 +01:00
print '<tr class="oddeven">' ;
2018-03-13 22:43:50 +01:00
// Local ID
2021-01-20 22:40:40 +01:00
if ( ! empty ( $conf -> global -> STRIPE_ALLOW_LOCAL_CARD )) {
2018-03-13 22:43:50 +01:00
print '<td>' ;
print '</td>' ;
}
2020-01-02 19:05:03 +01:00
print '<td>' ;
print '</td>' ;
2018-10-16 19:49:16 +02:00
// Src ID
2018-03-13 17:32:49 +01:00
print '<td>' ;
2019-11-13 18:32:11 +01:00
$connect = '' ;
2019-03-21 19:27:56 +01:00
print $src -> id ;
2021-02-26 21:17:52 +01:00
if ( ! empty ( $stripeacc )) {
$connect = $stripeacc . '/' ;
}
2019-03-21 19:27:56 +01:00
//$url='https://dashboard.stripe.com/'.$connect.'test/sources/'.$src->id;
2019-11-13 18:32:11 +01:00
$url = 'https://dashboard.stripe.com/' . $connect . 'test/search?query=' . $src -> id ;
2021-01-20 22:40:40 +01:00
if ( $servicestatus ) {
2020-10-07 15:01:28 +02:00
//$url='https://dashboard.stripe.com/'.$connect.'sources/'.$src->id;
$url = 'https://dashboard.stripe.com/' . $connect . 'search?query=' . $src -> id ;
2018-10-16 19:49:16 +02:00
}
2019-10-03 21:32:55 +02:00
print " <a href=' " . $url . " ' target='_stripe'> " . img_picto ( $langs -> trans ( 'ShowInStripe' ), 'globe' ) . " </a> " ;
2018-03-13 17:32:49 +01:00
print '</td>' ;
2018-10-16 19:49:16 +02:00
// Img of credit card
2018-03-07 16:17:25 +01:00
print '<td>' ;
2021-01-20 22:40:40 +01:00
if ( $src -> object == 'card' ) {
2018-03-13 22:43:50 +01:00
print img_credit_card ( $src -> brand );
2021-01-20 22:40:40 +01:00
} elseif ( $src -> object == 'source' && $src -> type == 'card' ) {
2018-03-13 22:43:50 +01:00
print img_credit_card ( $src -> card -> brand );
2021-01-20 22:40:40 +01:00
} elseif ( $src -> object == 'source' && $src -> type == 'sepa_debit' ) {
2018-03-13 17:32:49 +01:00
print '<span class="fa fa-university fa-2x fa-fw"></span>' ;
2021-01-20 22:40:40 +01:00
} elseif ( $src -> object == 'payment_method' && $src -> type == 'card' ) {
2019-05-17 00:10:44 +02:00
print img_credit_card ( $src -> card -> brand );
2021-01-20 22:40:40 +01:00
} elseif ( $src -> object == 'payment_method' && $src -> type == 'sepa_debit' ) {
2019-05-17 00:10:44 +02:00
print '<span class="fa fa-university fa-2x fa-fw"></span>' ;
}
2018-10-16 19:49:16 +02:00
print '</td>' ;
2020-03-16 15:49:58 +01:00
// Information
2018-10-16 19:49:16 +02:00
print '<td valign="middle">' ;
2021-01-20 22:40:40 +01:00
if ( $src -> object == 'card' ) {
2018-03-14 17:15:31 +01:00
print '....' . $src -> last4 . ' - ' . $src -> exp_month . '/' . $src -> exp_year . '' ;
2018-03-07 16:17:25 +01:00
print '</td><td>' ;
2021-01-20 22:40:40 +01:00
if ( $src -> country ) {
2019-11-13 18:32:11 +01:00
$img = picto_from_langcode ( $src -> country );
print $img ? $img . ' ' : '' ;
2019-01-27 11:55:16 +01:00
print getCountry ( $src -> country , 1 );
2021-02-26 21:17:52 +01:00
} else {
2021-10-05 10:20:35 +02:00
print img_warning () . ' <span class="error">' . $langs -> trans ( " ErrorFieldRequired " , $langs -> transnoentitiesnoconv ( " CompanyCountry " )) . '</span>' ;
2021-02-26 21:17:52 +01:00
}
2021-01-20 22:40:40 +01:00
} elseif ( $src -> object == 'source' && $src -> type == 'card' ) {
2020-03-16 15:49:58 +01:00
print '<span class="opacitymedium">' . $src -> owner -> name . '</span><br>....' . $src -> card -> last4 . ' - ' . $src -> card -> exp_month . '/' . $src -> card -> exp_year . '' ;
2018-03-07 16:17:25 +01:00
print '</td><td>' ;
2021-02-26 21:17:52 +01:00
if ( $src -> card -> country ) {
2019-11-13 18:32:11 +01:00
$img = picto_from_langcode ( $src -> card -> country );
print $img ? $img . ' ' : '' ;
2019-01-27 11:55:16 +01:00
print getCountry ( $src -> card -> country , 1 );
2021-02-26 21:17:52 +01:00
} else {
2021-10-05 10:20:35 +02:00
print img_warning () . ' <span class="error">' . $langs -> trans ( " ErrorFieldRequired " , $langs -> transnoentitiesnoconv ( " CompanyCountry " )) . '</span>' ;
2021-02-26 21:17:52 +01:00
}
2021-01-20 22:40:40 +01:00
} elseif ( $src -> object == 'source' && $src -> type == 'sepa_debit' ) {
2021-01-24 17:18:21 +01:00
print '<span class="opacitymedium">' . $src -> billing_details -> name . '</span><br>....' . $src -> sepa_debit -> last4 ;
2018-03-07 16:17:25 +01:00
print '</td><td>' ;
2021-01-20 22:40:40 +01:00
if ( $src -> sepa_debit -> country ) {
2019-11-13 18:32:11 +01:00
$img = picto_from_langcode ( $src -> sepa_debit -> country );
print $img ? $img . ' ' : '' ;
2019-01-27 11:55:16 +01:00
print getCountry ( $src -> sepa_debit -> country , 1 );
2021-02-26 21:17:52 +01:00
} else {
2021-10-05 10:20:35 +02:00
print img_warning () . ' <span class="error">' . $langs -> trans ( " ErrorFieldRequired " , $langs -> transnoentitiesnoconv ( " CompanyCountry " )) . '</span>' ;
2021-02-26 21:17:52 +01:00
}
2021-01-20 22:40:40 +01:00
} elseif ( $src -> object == 'payment_method' && $src -> type == 'card' ) {
2020-03-16 15:49:58 +01:00
print '<span class="opacitymedium">' . $src -> billing_details -> name . '</span><br>....' . $src -> card -> last4 . ' - ' . $src -> card -> exp_month . '/' . $src -> card -> exp_year . '' ;
2019-05-17 00:10:44 +02:00
print '</td><td>' ;
2021-01-20 22:40:40 +01:00
if ( $src -> card -> country ) {
2019-11-13 18:32:11 +01:00
$img = picto_from_langcode ( $src -> card -> country );
print $img ? $img . ' ' : '' ;
2019-05-17 00:10:44 +02:00
print getCountry ( $src -> card -> country , 1 );
2021-02-26 21:17:52 +01:00
} else {
2021-10-05 10:20:35 +02:00
print img_warning () . ' <span class="error">' . $langs -> trans ( " ErrorFieldRequired " , $langs -> transnoentitiesnoconv ( " CompanyCountry " )) . '</span>' ;
2021-02-26 21:17:52 +01:00
}
2021-01-20 22:40:40 +01:00
} elseif ( $src -> object == 'payment_method' && $src -> type == 'sepa_debit' ) {
2021-01-24 17:22:49 +01:00
print '<span class="opacitymedium">' . $src -> billing_details -> name . '</span><br>....' . $src -> sepa_debit -> last4 ;
2019-05-17 00:10:44 +02:00
print '</td><td>' ;
2021-01-20 22:40:40 +01:00
if ( $src -> sepa_debit -> country ) {
2019-11-13 18:32:11 +01:00
$img = picto_from_langcode ( $src -> sepa_debit -> country );
print $img ? $img . ' ' : '' ;
2019-05-17 00:10:44 +02:00
print getCountry ( $src -> sepa_debit -> country , 1 );
2021-02-26 21:17:52 +01:00
} else {
2021-10-05 10:20:35 +02:00
print img_warning () . ' <span class="error">' . $langs -> trans ( " ErrorFieldRequired " , $langs -> transnoentitiesnoconv ( " CompanyCountry " )) . '</span>' ;
2021-02-26 21:17:52 +01:00
}
2020-05-21 15:05:19 +02:00
} else {
2019-05-17 00:10:44 +02:00
print '</td><td>' ;
}
2018-03-07 16:17:25 +01:00
print '</td>' ;
// Default
2019-02-23 21:02:39 +01:00
print '<td class="center" width="50">' ;
2019-06-16 17:08:23 +02:00
if (( empty ( $customerstripe -> invoice_settings ) && $customerstripe -> default_source != $src -> id ) ||
2021-01-20 22:40:40 +01:00
( ! empty ( $customerstripe -> invoice_settings ) && $customerstripe -> invoice_settings -> default_payment_method != $src -> id )) {
2020-09-30 15:13:28 +02:00
print '<a href="' . DOL_URL_ROOT . '/societe/paymentmodes.php?socid=' . $object -> id . '&source=' . $src -> id . '&action=setassourcedefault&token=' . newToken () . '">' ;
2019-01-27 11:55:16 +01:00
print img_picto ( $langs -> trans ( " Default " ), 'off' );
2018-03-13 22:54:28 +01:00
print '</a>' ;
2018-03-07 16:17:25 +01:00
} else {
2019-01-27 11:55:16 +01:00
print img_picto ( $langs -> trans ( " Default " ), 'on' );
2018-03-07 16:17:25 +01:00
}
print '</td>' ;
2018-03-13 22:43:50 +01:00
print '<td>' ;
print $langs -> trans ( " Remote " );
2018-09-09 13:23:41 +02:00
//if ($src->cvc_check == 'fail') print ' - CVC check fail';
2018-03-13 22:43:50 +01:00
print '</td>' ;
2018-09-09 13:15:32 +02:00
print '<td>' ;
2018-09-09 13:23:41 +02:00
//var_dump($src);
2018-09-09 13:15:32 +02:00
print '' ;
print '</td>' ;
2019-01-28 03:00:28 +01:00
// Fields from hook
2019-11-13 18:32:11 +01:00
$parameters = array ( 'arrayfields' => array (), 'stripesource' => $src , 'linetype' => 'stripecardremoteonly' );
$reshook = $hookmanager -> executeHooks ( 'printFieldListValue' , $parameters , $object ); // Note that $action and $object may have been modified by hook
2019-01-28 03:00:28 +01:00
print $hookmanager -> resPrint ;
// Action column
2019-02-23 21:02:39 +01:00
print '<td class="right nowraponall">' ;
2021-11-02 04:51:18 +01:00
if ( $permissiontoadd ) {
2020-10-01 10:50:54 +02:00
print '<a href="' . DOL_URL_ROOT . '/societe/paymentmodes.php?socid=' . $object -> id . '&source=' . $src -> id . '&action=deletecard&token=' . newToken () . '">' ;
2018-03-14 20:08:44 +01:00
print img_picto ( $langs -> trans ( " Delete " ), 'delete' );
2018-03-13 22:43:50 +01:00
print '</a>' ;
2018-03-07 16:17:25 +01:00
}
2018-03-13 22:43:50 +01:00
print '</td>' ;
print '</tr>' ;
2018-03-07 16:17:25 +01:00
}
}
2018-03-13 22:43:50 +01:00
2021-01-20 22:40:40 +01:00
if ( $nbremote == 0 && $nblocal == 0 ) {
$colspan = ( ! empty ( $conf -> global -> STRIPE_ALLOW_LOCAL_CARD ) ? 10 : 9 );
2021-10-04 04:14:31 +02:00
print '<tr><td colspan="' . $colspan . '"<span class="opacitymedium">>' . $langs -> trans ( " None " ) . '</span></td></tr>' ;
2018-03-07 16:17:25 +01:00
}
print " </table> " ;
2018-03-13 15:19:31 +01:00
print " </div> " ;
2020-10-07 15:01:28 +02:00
print '<br>' ;
2018-03-07 16:17:25 +01:00
}
2019-09-14 14:25:47 +02:00
2021-02-26 21:17:52 +01:00
// List of Stripe payment modes
if ( ! empty ( $conf -> stripe -> enabled ) && ! empty ( $conf -> stripeconnect -> enabled ) && ! empty ( $stripesupplieracc )) {
2020-10-07 15:01:28 +02:00
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' );
$balance = \Stripe\Balance :: retrieve ( array ( " stripe_account " => $stripesupplieracc ));
2019-11-05 21:24:41 +01:00
print '<table class="liste centpercent">' . " \n " ;
2019-08-05 23:34:28 +02:00
print '<tr class="liste_titre">' ;
2019-08-06 00:12:49 +02:00
print '<td>' . $langs -> trans ( 'Currency' ) . '</td>' ;
2019-09-20 13:02:50 +02:00
print '<td>' . $langs -> trans ( 'Available' ) . '</td>' ;
print '<td>' . $langs -> trans ( 'Pending' ) . '</td>' ;
2020-10-07 15:01:28 +02:00
print '<td>' . $langs -> trans ( 'Total' ) . '</td>' ;
print '</tr>' ;
2019-09-14 14:25:47 +02:00
2020-10-07 15:01:28 +02:00
$currencybalance = array ();
2021-02-26 21:17:52 +01:00
if ( is_array ( $balance -> available ) && count ( $balance -> available )) {
foreach ( $balance -> available as $cpt ) {
2020-10-07 15:01:28 +02:00
$arrayzerounitcurrency = array ( 'BIF' , 'CLP' , 'DJF' , 'GNF' , 'JPY' , 'KMF' , 'KRW' , 'MGA' , 'PYG' , 'RWF' , 'VND' , 'VUV' , 'XAF' , 'XOF' , 'XPF' );
if ( ! in_array ( $cpt -> currency , $arrayzerounitcurrency )) {
$currencybalance [ $cpt -> currency ][ 'available' ] = $cpt -> amount / 100 ;
2019-11-13 19:15:19 +01:00
} else {
$currencybalance [ $cpt -> currency ][ 'available' ] = $cpt -> amount ;
}
$currencybalance [ $cpt -> currency ][ 'currency' ] = $cpt -> currency ;
2019-08-06 00:12:49 +02:00
}
}
2019-09-14 14:25:47 +02:00
2021-02-26 21:17:52 +01:00
if ( is_array ( $balance -> pending ) && count ( $balance -> pending )) {
foreach ( $balance -> pending as $cpt ) {
2020-01-30 01:48:28 +01:00
$arrayzerounitcurrency = array ( 'BIF' , 'CLP' , 'DJF' , 'GNF' , 'JPY' , 'KMF' , 'KRW' , 'MGA' , 'PYG' , 'RWF' , 'VND' , 'VUV' , 'XAF' , 'XOF' , 'XPF' );
2019-11-13 19:16:10 +01:00
if ( ! in_array ( $cpt -> currency , $arrayzerounitcurrency )) {
2020-01-30 01:48:28 +01:00
$currencybalance [ $cpt -> currency ][ 'pending' ] = $currencybalance [ $cpt -> currency ][ 'available' ] + $cpt -> amount / 100 ;
2019-10-27 17:01:23 +01:00
} else {
2020-01-30 01:48:28 +01:00
$currencybalance [ $cpt -> currency ][ 'pending' ] = $currencybalance [ $cpt -> currency ][ 'available' ] + $cpt -> amount ;
2019-10-27 17:01:23 +01:00
}
2019-08-06 00:12:49 +02:00
}
2020-10-07 15:01:28 +02:00
}
2019-10-06 14:41:52 +02:00
2021-02-26 21:17:52 +01:00
if ( is_array ( $currencybalance )) {
foreach ( $currencybalance as $cpt ) {
2020-01-30 01:48:28 +01:00
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>' ;
2019-09-20 13:02:50 +02:00
}
}
2019-10-06 14:41:52 +02:00
2020-10-07 15:01:28 +02:00
print '</table>' ;
print '<br>' ;
2019-08-06 00:12:49 +02:00
}
2018-03-07 16:17:25 +01:00
// List of bank accounts
2020-10-07 15:01:28 +02:00
$morehtmlright = dolGetButtonTitle ( $langs -> trans ( 'Add' ), '' , 'fa fa-plus-circle' , $_SERVER [ " PHP_SELF " ] . '?socid=' . $object -> id . '&action=create' );
2018-03-07 16:17:25 +01:00
2020-04-11 17:06:50 +02:00
print load_fiche_titre ( $langs -> trans ( " BankAccounts " ), $morehtmlright , 'bank' );
2018-03-07 16:17:25 +01:00
$rib_list = $object -> get_all_rib ();
2021-02-26 21:17:52 +01:00
if ( is_array ( $rib_list )) {
2021-11-02 04:51:18 +01:00
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
2019-11-05 21:24:41 +01:00
print '<table class="liste centpercent">' ;
2018-03-07 16:17:25 +01:00
print '<tr class="liste_titre">' ;
print_liste_field_titre ( " LabelRIB " );
print_liste_field_titre ( " Bank " );
print_liste_field_titre ( " RIB " );
print_liste_field_titre ( " IBAN " );
print_liste_field_titre ( " BIC " );
2021-02-26 21:17:52 +01:00
if ( ! empty ( $conf -> prelevement -> enabled )) {
2019-07-20 15:53:46 +02:00
print_liste_field_titre ( " RUM " );
2019-07-28 17:10:37 +02:00
print_liste_field_titre ( " DateRUM " );
2019-07-20 15:53:46 +02:00
print_liste_field_titre ( " WithdrawMode " );
2018-03-07 16:17:25 +01:00
}
2019-02-23 21:02:39 +01:00
print_liste_field_titre ( " DefaultRIB " , '' , '' , '' , '' , '' , '' , '' , 'center ' );
print_liste_field_titre ( '' , '' , '' , '' , '' , '' , '' , '' , 'center ' );
2021-10-22 15:27:36 +02:00
print_liste_field_titre ( '' , $_SERVER [ " PHP_SELF " ], " " , '' , '' , '' , '' , '' , 'maxwidthsearch ' );
2018-03-07 16:17:25 +01:00
print " </tr> \n " ;
2021-02-26 21:17:52 +01:00
foreach ( $rib_list as $rib ) {
2018-03-07 16:17:25 +01:00
print '<tr class="oddeven">' ;
// Label
print '<td>' . $rib -> label . '</td>' ;
// Bank name
print '<td>' . $rib -> bank . '</td>' ;
// Account number
print '<td>' ;
2019-11-13 18:32:11 +01:00
$string = '' ;
2018-03-07 16:17:25 +01:00
foreach ( $rib -> getFieldsToShow () as $val ) {
if ( $val == 'BankCode' ) {
$string .= $rib -> code_banque . ' ' ;
} elseif ( $val == 'BankAccountNumber' ) {
$string .= $rib -> number . ' ' ;
} elseif ( $val == 'DeskCode' ) {
$string .= $rib -> code_guichet . ' ' ;
} elseif ( $val == 'BankAccountNumberKey' ) {
$string .= $rib -> cle_rib . ' ' ;
}
2020-10-07 15:01:28 +02:00
// Already output after
// } elseif ($val == 'BIC') {
// $string .= $rib->bic.' ';
// } elseif ($val == 'IBAN') {
// $string .= $rib->iban.' ';*/
2019-10-27 17:01:23 +01:00
//}
2018-03-07 16:17:25 +01:00
}
2019-11-13 18:32:11 +01:00
if ( ! empty ( $rib -> label ) && $rib -> number ) {
if ( ! checkBanForAccount ( $rib )) {
$string .= ' ' . img_picto ( $langs -> trans ( " ValueIsNotValid " ), 'warning' );
2018-03-07 16:17:25 +01:00
} else {
2019-11-13 18:32:11 +01:00
$string .= ' ' . img_picto ( $langs -> trans ( " ValueIsValid " ), 'info' );
2018-03-07 16:17:25 +01:00
}
}
print $string ;
print '</td>' ;
// IBAN
print '<td>' . $rib -> iban ;
2021-02-26 21:17:52 +01:00
if ( ! empty ( $rib -> iban )) {
2019-11-13 18:32:11 +01:00
if ( ! checkIbanForAccount ( $rib )) {
2019-01-27 11:55:16 +01:00
print ' ' . img_picto ( $langs -> trans ( " IbanNotValid " ), 'warning' );
2018-03-07 16:17:25 +01:00
}
}
print '</td>' ;
// BIC
print '<td>' . $rib -> bic ;
2019-11-13 18:32:11 +01:00
if ( ! empty ( $rib -> bic )) {
if ( ! checkSwiftForAccount ( $rib )) {
2019-01-27 11:55:16 +01:00
print ' ' . img_picto ( $langs -> trans ( " SwiftNotValid " ), 'warning' );
2018-03-07 16:17:25 +01:00
}
}
print '</td>' ;
2021-02-26 21:17:52 +01:00
if ( ! empty ( $conf -> prelevement -> enabled )) {
2018-03-07 16:17:25 +01:00
// RUM
//print '<td>'.$prelevement->buildRumNumber($object->code_client, $rib->datec, $rib->id).'</td>';
print '<td>' . $rib -> rum . '</td>' ;
2019-07-28 17:10:37 +02:00
print '<td>' . dol_print_date ( $rib -> date_rum , 'day' ) . '</td>' ;
2018-03-07 16:17:25 +01:00
// FRSTRECUR
print '<td>' . $rib -> frstrecur . '</td>' ;
}
// Default
2019-02-23 21:02:39 +01:00
print '<td class="center" width="70">' ;
2018-03-07 16:17:25 +01:00
if ( ! $rib -> default_rib ) {
2020-09-30 15:13:28 +02:00
print '<a href="' . $_SERVER [ " PHP_SELF " ] . '?socid=' . $object -> id . '&ribid=' . $rib -> id . '&action=setasbankdefault&token=' . newToken () . '">' ;
2019-01-27 11:55:16 +01:00
print img_picto ( $langs -> trans ( " Disabled " ), 'off' );
2018-03-07 16:17:25 +01:00
print '</a>' ;
} else {
2019-01-27 11:55:16 +01:00
print img_picto ( $langs -> trans ( " Enabled " ), 'on' );
2018-03-07 16:17:25 +01:00
}
print '</td>' ;
// Generate doc
2019-02-23 21:02:39 +01:00
print '<td class="center">' ;
2018-03-07 16:17:25 +01:00
$buttonlabel = $langs -> trans ( " BuildDoc " );
2019-11-13 18:32:11 +01:00
$forname = 'builddocrib' . $rib -> id ;
2018-03-07 16:17:25 +01:00
include_once DOL_DOCUMENT_ROOT . '/core/modules/bank/modules_bank.php' ;
2019-11-13 18:32:11 +01:00
$modellist = ModeleBankAccountDoc :: liste_modeles ( $db );
2018-03-07 16:17:25 +01:00
$out = '' ;
2021-02-26 21:17:52 +01:00
if ( is_array ( $modellist ) && count ( $modellist )) {
2021-10-22 15:27:36 +02:00
$out .= '<form action="' . $_SERVER [ " PHP_SELF " ] . ( empty ( $conf -> global -> MAIN_JUMP_TAG ) ? '' : '#builddoc' ) . '" name="' . $forname . '" id="' . $forname . '_form" method="post">' ;
2019-11-13 18:32:11 +01:00
$out .= '<input type="hidden" name="action" value="builddocrib">' ;
2019-12-18 23:12:31 +01:00
$out .= '<input type="hidden" name="token" value="' . newToken () . '">' ;
2019-11-13 18:32:11 +01:00
$out .= '<input type="hidden" name="socid" value="' . $object -> id . '">' ;
$out .= '<input type="hidden" name="companybankid" value="' . $rib -> id . '">' ;
2018-03-07 16:17:25 +01:00
2021-02-26 21:17:52 +01:00
if ( is_array ( $modellist ) && count ( $modellist ) == 1 ) { // If there is only one element
2019-11-13 18:32:11 +01:00
$arraykeys = array_keys ( $modellist );
$modelselected = $arraykeys [ 0 ];
2018-03-07 16:17:25 +01:00
}
2021-02-26 21:17:52 +01:00
if ( ! empty ( $conf -> global -> BANKADDON_PDF )) {
$modelselected = $conf -> global -> BANKADDON_PDF ;
}
2018-03-07 16:17:25 +01:00
2021-10-22 15:27:36 +02:00
$out .= $form -> selectarray ( 'modelrib' . $rib -> id , $modellist , $modelselected , 1 , 0 , 0 , '' , 0 , 0 , 0 , '' , 'minwidth100' );
2019-11-13 18:32:11 +01:00
$out .= ajax_combobox ( 'modelrib' . $rib -> id );
2018-03-07 16:17:25 +01:00
2021-10-22 15:27:36 +02:00
$allowgenifempty = 0 ;
2018-03-07 16:17:25 +01:00
// Language code (if multilang)
2021-02-26 21:17:52 +01:00
if ( $conf -> global -> MAIN_MULTILANGS ) {
2018-03-07 16:17:25 +01:00
include_once DOL_DOCUMENT_ROOT . '/core/class/html.formadmin.class.php' ;
2019-11-13 18:32:11 +01:00
$formadmin = new FormAdmin ( $db );
2021-10-22 15:27:36 +02:00
$defaultlang = $langs -> getDefaultLang ();
2019-11-13 18:32:11 +01:00
$morecss = 'maxwidth150' ;
2021-02-26 21:17:52 +01:00
if ( $conf -> browser -> layout == 'phone' ) {
$morecss = 'maxwidth100' ;
}
2019-11-13 18:32:11 +01:00
$out .= $formadmin -> select_language ( $defaultlang , 'lang_idrib' . $rib -> id , 0 , 0 , 0 , 0 , 0 , $morecss );
2018-03-07 16:17:25 +01:00
}
// Button
$genbutton = '<input class="button buttongen" id="' . $forname . '_generatebutton" name="' . $forname . '_generatebutton"' ;
2019-11-13 18:32:11 +01:00
$genbutton .= ' type="submit" value="' . $buttonlabel . '"' ;
2021-02-26 21:17:52 +01:00
if ( ! $allowgenifempty && ! is_array ( $modellist ) && empty ( $modellist )) {
$genbutton .= ' disabled' ;
}
2019-11-13 18:32:11 +01:00
$genbutton .= '>' ;
2021-02-26 21:17:52 +01:00
if ( $allowgenifempty && ! is_array ( $modellist ) && empty ( $modellist ) && empty ( $conf -> dol_no_mouse_hover ) && $modulepart != 'unpaid' ) {
2018-03-07 16:17:25 +01:00
$langs -> load ( " errors " );
2019-11-13 18:32:11 +01:00
$genbutton .= ' ' . img_warning ( $langs -> transnoentitiesnoconv ( " WarningNoDocumentModelActivated " ));
2018-03-07 16:17:25 +01:00
}
2021-02-26 21:17:52 +01:00
if ( ! $allowgenifempty && ! is_array ( $modellist ) && empty ( $modellist ) && empty ( $conf -> dol_no_mouse_hover ) && $modulepart != 'unpaid' ) {
$genbutton = '' ;
}
if ( empty ( $modellist ) && ! $showempty && $modulepart != 'unpaid' ) {
$genbutton = '' ;
}
2019-11-13 18:32:11 +01:00
$out .= $genbutton ;
$out .= '</form>' ;
2018-03-07 16:17:25 +01:00
}
print $out ;
print '</td>' ;
// Edit/Delete
2019-02-23 21:02:39 +01:00
print '<td class="right nowraponall">' ;
2021-11-02 04:51:18 +01:00
if ( $permissiontoadd ) {
2020-04-26 14:12:51 +02:00
print '<a class="editfielda" href="' . $_SERVER [ " PHP_SELF " ] . '?socid=' . $object -> id . '&id=' . $rib -> id . '&action=edit">' ;
2019-01-27 11:55:16 +01:00
print img_picto ( $langs -> trans ( " Modify " ), 'edit' );
2018-03-07 16:17:25 +01:00
print '</a>' ;
2021-02-26 21:17:52 +01:00
print '<a class="marginleftonly" href="' . $_SERVER [ " PHP_SELF " ] . '?socid=' . $object -> id . '&id=' . $rib -> id . '&action=delete&token=' . newToken () . '">' ;
print img_picto ( $langs -> trans ( " Delete " ), 'delete' );
print '</a>' ;
2018-03-07 16:17:25 +01:00
}
print '</td>' ;
print '</tr>' ;
}
2021-02-26 21:17:52 +01:00
if ( count ( $rib_list ) == 0 ) {
2019-11-13 18:32:11 +01:00
$colspan = 9 ;
2021-02-26 21:17:52 +01:00
if ( ! empty ( $conf -> prelevement -> enabled )) {
$colspan += 2 ;
}
2018-03-14 17:12:32 +01:00
print '<tr><td colspan="' . $colspan . '" class="opacitymedium">' . $langs -> trans ( " NoBANRecord " ) . '</td></tr>' ;
2018-03-07 16:17:25 +01:00
}
print '</table>' ;
print '</div>' ;
} else {
dol_print_error ( $db );
}
2021-02-26 21:17:52 +01:00
if ( empty ( $conf -> global -> SOCIETE_DISABLE_BUILDDOC )) {
2018-04-24 11:12:12 +02:00
print '<br>' ;
2018-03-07 16:17:25 +01:00
print '<div class="fichecenter"><div class="fichehalfleft">' ;
print '<a name="builddoc"></a>' ; // ancre
/*
2021-03-16 04:04:18 +01:00
* Generated documents
2021-02-26 21:17:52 +01:00
*/
2019-11-13 18:32:11 +01:00
$filedir = $conf -> societe -> multidir_output [ $object -> entity ] . '/' . $object -> id ;
$urlsource = $_SERVER [ " PHP_SELF " ] . " ?socid= " . $object -> id ;
2018-03-07 16:17:25 +01:00
2021-11-02 04:51:18 +01:00
print $formfile -> showdocuments ( 'company' , $object -> id , $filedir , $urlsource , $permissiontoread , $permissiontoadd , $object -> model_pdf , 0 , 0 , 0 , 28 , 0 , 'entity=' . $object -> entity , 0 , '' , $object -> default_lang );
2018-03-07 16:17:25 +01:00
2018-04-20 14:50:11 +02:00
// Show direct download link
2021-02-26 21:17:52 +01:00
if ( ! empty ( $conf -> global -> BANK_ACCOUNT_ALLOW_EXTERNAL_DOWNLOAD )) {
2018-04-20 14:50:11 +02:00
$companybankaccounttemp = new CompanyBankAccount ( $db );
$companypaymentmodetemp = new CompanyPaymentMode ( $db );
$result = $companypaymentmodetemp -> fetch ( 0 , null , $object -> id , 'ban' );
include_once DOL_DOCUMENT_ROOT . '/ecm/class/ecmfiles.class.php' ;
$ecmfile = new EcmFiles ( $db );
$result = $ecmfile -> fetch ( 0 , '' , '' , '' , '' , $companybankaccounttemp -> table_element , $companypaymentmodetemp -> id );
2021-02-26 21:17:52 +01:00
if ( $result > 0 ) {
2018-04-20 14:50:11 +02:00
$companybankaccounttemp -> last_main_doc = $ecmfile -> filepath . '/' . $ecmfile -> filename ;
print '<br><!-- Link to download main doc -->' . " \n " ;
print showDirectDownloadLink ( $companybankaccounttemp ) . '<br>' ;
}
}
2021-10-23 17:18:35 +02:00
print '</div><div class="fichehalfright">' ;
2018-03-07 16:17:25 +01:00
2021-10-23 17:18:35 +02:00
print '</div></div>' ;
2018-03-07 16:17:25 +01:00
print '<br>' ;
}
/*
2021-02-26 21:17:52 +01:00
include_once DOL_DOCUMENT_ROOT . '/core/modules/bank/modules_bank.php' ;
$modellist = ModeleBankAccountDoc :: liste_modeles ( $db );
//print '<td>';
if ( is_array ( $modellist ) && count ( $modellist ) == 1 ) // If there is only one element
{
$arraykeys = array_keys ( $modellist );
$modelselected = $arraykeys [ 0 ];
}
$out .= $form -> selectarray ( 'model' , $modellist , $modelselected , 0 , 0 , 0 , '' , 0 , 0 , 0 , '' , 'minwidth100' );
$out .= ajax_combobox ( 'model' );
//print $out;
$buttonlabel = $langs -> trans ( " Generate " );
$genbutton = '<input class="button buttongen" id="' . $forname . '_generatebutton" name="' . $forname . '_generatebutton"' ;
$genbutton .= ' type="submit" value="' . $buttonlabel . '"' ;
$genbutton .= '>' ;
print $genbutton ;
//print '</td>'; // TODO Add link to generate doc
*/
2018-03-07 16:17:25 +01:00
}
2018-03-14 11:51:13 +01:00
// Edit BAN
2021-11-02 04:51:18 +01:00
if ( $socid && $action == 'edit' && $permissiontoadd ) {
2020-10-22 22:50:03 +02:00
print dol_get_fiche_head ( $head , 'rib' , $langs -> trans ( " ThirdParty " ), 0 , 'company' );
2018-03-07 16:17:25 +01:00
2019-12-05 15:22:06 +01:00
$linkback = '<a href="' . DOL_URL_ROOT . '/societe/list.php?restore_lastsearch_values=1">' . $langs -> trans ( " BackToList " ) . '</a>' ;
2018-03-07 16:17:25 +01:00
2019-11-13 18:32:11 +01:00
dol_banner_tab ( $object , 'socid' , $linkback , ( $user -> socid ? 0 : 1 ), 'rowid' , 'nom' );
2018-03-07 16:17:25 +01:00
print '<div class="underbanner clearboth"></div>' ;
2020-01-02 20:43:16 +01:00
print '<div class="div-table-responsive-no-min">' ;
2018-03-07 16:17:25 +01:00
print '<table class="border centpercent">' ;
print '<tr><td class="titlefield fieldrequired">' . $langs -> trans ( " LabelRIB " ) . '</td>' ;
2018-03-14 13:56:21 +01:00
print '<td><input class="minwidth300" type="text" name="label" value="' . $companybankaccount -> label . '"></td></tr>' ;
2018-03-07 16:17:25 +01:00
print '<tr><td class="fieldrequired">' . $langs -> trans ( " BankName " ) . '</td>' ;
2018-03-14 13:56:21 +01:00
print '<td><input class="minwidth200" type="text" name="bank" value="' . $companybankaccount -> bank . '"></td></tr>' ;
2018-03-07 16:17:25 +01:00
// Show fields of bank account
2018-03-14 13:56:21 +01:00
foreach ( $companybankaccount -> getFieldsToShow ( 1 ) as $val ) {
2019-11-13 18:32:11 +01:00
$require = false ;
2020-06-08 11:43:20 +02:00
$tooltip = '' ;
2018-03-07 16:17:25 +01:00
if ( $val == 'BankCode' ) {
$name = 'code_banque' ;
$size = 8 ;
2018-03-14 13:56:21 +01:00
$content = $companybankaccount -> code_banque ;
2018-03-07 16:17:25 +01:00
} elseif ( $val == 'DeskCode' ) {
$name = 'code_guichet' ;
$size = 8 ;
2018-03-14 13:56:21 +01:00
$content = $companybankaccount -> code_guichet ;
2018-03-07 16:17:25 +01:00
} elseif ( $val == 'BankAccountNumber' ) {
$name = 'number' ;
$size = 18 ;
2018-03-14 13:56:21 +01:00
$content = $companybankaccount -> number ;
2018-03-07 16:17:25 +01:00
} elseif ( $val == 'BankAccountNumberKey' ) {
$name = 'cle_rib' ;
$size = 3 ;
2018-03-14 13:56:21 +01:00
$content = $companybankaccount -> cle_rib ;
2018-03-07 16:17:25 +01:00
} elseif ( $val == 'IBAN' ) {
$name = 'iban' ;
$size = 30 ;
2018-03-14 13:56:21 +01:00
$content = $companybankaccount -> iban ;
2021-02-26 21:17:52 +01:00
if ( $companybankaccount -> needIBAN ()) {
$require = true ;
}
2020-06-08 11:43:20 +02:00
$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' ;
2018-03-07 16:17:25 +01:00
} elseif ( $val == 'BIC' ) {
$name = 'bic' ;
$size = 12 ;
2018-03-14 13:56:21 +01:00
$content = $companybankaccount -> bic ;
2021-02-26 21:17:52 +01:00
if ( $companybankaccount -> needIBAN ()) {
$require = true ;
}
2020-06-08 11:43:20 +02:00
$tooltip = $langs -> trans ( " Example " ) . ': LIABLT2XXXX' ;
2018-03-07 16:17:25 +01:00
}
2020-06-08 11:43:20 +02:00
print '<tr><td' . ( $require ? ' class="fieldrequired" ' : '' ) . '>' ;
if ( $tooltip ) {
print $form -> textwithpicto ( $langs -> trans ( $val ), $tooltip , 4 , 'help' , '' , 0 , 3 , $name );
} else {
print $langs -> trans ( $val );
}
print '</td>' ;
2018-03-07 16:17:25 +01:00
print '<td><input size="' . $size . '" type="text" class="flat" name="' . $name . '" value="' . $content . '"></td>' ;
print '</tr>' ;
}
print '<tr><td>' . $langs -> trans ( " BankAccountDomiciliation " ) . '</td><td>' ;
print '<textarea name="domiciliation" rows="4" cols="40" maxlength="255">' ;
2018-03-14 13:56:21 +01:00
print $companybankaccount -> domiciliation ;
2018-03-07 16:17:25 +01:00
print " </textarea></td></tr> " ;
print '<tr><td>' . $langs -> trans ( " BankAccountOwner " ) . '</td>' ;
2018-03-14 13:56:21 +01:00
print '<td><input class="minwidth300" type="text" name="proprio" value="' . $companybankaccount -> proprio . '"></td></tr>' ;
2018-03-07 16:17:25 +01:00
print " </td></tr> \n " ;
print '<tr><td>' . $langs -> trans ( " BankAccountOwnerAddress " ) . '</td><td>' ;
print '<textarea name="owner_address" rows="' . ROWS_4 . '" cols="40" maxlength="255">' ;
2018-03-14 13:56:21 +01:00
print $companybankaccount -> owner_address ;
2018-03-07 16:17:25 +01:00
print " </textarea></td></tr> " ;
print '</table>' ;
2020-01-02 20:43:16 +01:00
print '</div>' ;
2018-03-07 16:17:25 +01:00
2021-02-26 21:17:52 +01:00
if ( $conf -> prelevement -> enabled ) {
2018-03-07 16:17:25 +01:00
print '<br>' ;
2020-01-02 20:43:16 +01:00
print '<div class="div-table-responsive-no-min">' ;
2019-11-05 21:24:41 +01:00
print '<table class="border centpercent">' ;
2018-03-07 16:17:25 +01:00
2021-02-26 21:17:52 +01:00
if ( empty ( $companybankaccount -> rum )) {
$companybankaccount -> rum = $prelevement -> buildRumNumber ( $object -> code_client , $companybankaccount -> datec , $companybankaccount -> id );
}
2018-03-07 16:17:25 +01:00
// RUM
print '<tr><td class="titlefield">' . $langs -> trans ( " RUM " ) . '</td>' ;
2018-03-14 13:56:21 +01:00
print '<td><input class="minwidth300" type="text" name="rum" value="' . dol_escape_htmltag ( $companybankaccount -> rum ) . '"></td></tr>' ;
2018-03-07 16:17:25 +01:00
2021-08-02 18:13:35 +02:00
$date_rum = dol_mktime ( 0 , 0 , 0 , GETPOST ( 'date_rummonth' ), GETPOST ( 'date_rumday' ), GETPOST ( 'date_rumyear' ));
2019-07-28 17:10:37 +02:00
print '<tr><td class="titlefield">' . $langs -> trans ( " DateRUM " ) . '</td>' ;
2021-08-02 18:13:35 +02:00
print '<td>' . $form -> selectDate ( $date_rum ? $date_rum : $companybankaccount -> date_rum , 'date_rum' , 0 , 0 , 1 , 'date_rum' , 1 , 1 ) . '</td></tr>' ;
2019-07-28 17:10:37 +02:00
2018-03-07 16:17:25 +01:00
print '<tr><td>' . $langs -> trans ( " WithdrawMode " ) . '</td><td>' ;
$tblArraychoice = array ( " FRST " => $langs -> trans ( " FRST " ), " RECUR " => $langs -> trans ( " RECUR " ));
2019-11-13 18:32:11 +01:00
print $form -> selectarray ( " frstrecur " , $tblArraychoice , dol_escape_htmltag ( GETPOST ( 'frstrecur' , 'alpha' ) ? GETPOST ( 'frstrecur' , 'alpha' ) : $companybankaccount -> frstrecur ), 0 );
2018-03-07 16:17:25 +01:00
print '</td></tr>' ;
print '</table>' ;
2020-01-02 20:43:16 +01:00
print '</div>' ;
2018-03-07 16:17:25 +01:00
}
2020-10-27 18:19:31 +01:00
print dol_get_fiche_end ();
2018-03-07 16:17:25 +01:00
2021-08-20 14:41:30 +02:00
print $form -> buttonsSaveCancel ( " Modify " );
2018-03-07 16:17:25 +01:00
}
2018-03-14 13:56:21 +01:00
// Edit Card
2021-11-02 04:51:18 +01:00
if ( $socid && $action == 'editcard' && $permissiontoadd ) {
2020-10-22 22:50:03 +02:00
print dol_get_fiche_head ( $head , 'rib' , $langs -> trans ( " ThirdParty " ), 0 , 'company' );
2018-03-14 13:56:21 +01:00
2019-12-05 15:22:06 +01:00
$linkback = '<a href="' . DOL_URL_ROOT . '/societe/list.php?restore_lastsearch_values=1">' . $langs -> trans ( " BackToList " ) . '</a>' ;
2018-03-14 13:56:21 +01:00
2019-11-13 18:32:11 +01:00
dol_banner_tab ( $object , 'socid' , $linkback , ( $user -> socid ? 0 : 1 ), 'rowid' , 'nom' );
2018-03-14 13:56:21 +01:00
print '<div class="fichecenter">' ;
print '<div class="underbanner clearboth"></div>' ;
print '<table class="border centpercent">' ;
print '<tr><td class="titlefieldcreate fieldrequired">' . $langs -> trans ( " Label " ) . '</td>' ;
print '<td><input class="minwidth300" type="text" id="label" name="label" value="' . $companypaymentmode -> label . '"></td></tr>' ;
print '<tr><td class="fieldrequired">' . $langs -> trans ( " NameOnCard " ) . '</td>' ;
print '<td><input class="minwidth200" type="text" name="proprio" value="' . $companypaymentmode -> proprio . '"></td></tr>' ;
2020-01-02 15:45:25 +01:00
print '<tr><td>' . $langs -> trans ( " CardNumber " ) . '</td>' ;
2018-03-14 13:56:21 +01:00
print '<td><input class="minwidth200" type="text" name="cardnumber" value="' . $companypaymentmode -> number . '"></td></tr>' ;
print '<tr><td class="fieldrequired">' . $langs -> trans ( " ExpiryDate " ) . '</td>' ;
print '<td>' ;
print $formother -> select_month ( $companypaymentmode -> exp_date_month , 'exp_date_month' , 1 );
print $formother -> select_year ( $companypaymentmode -> exp_date_year , 'exp_date_year' , 1 , 5 , 10 , 0 , 0 , '' , 'marginleftonly' );
print '</td></tr>' ;
2020-01-02 15:45:25 +01:00
print '<tr><td>' . $langs -> trans ( " CVN " ) . '</td>' ;
2018-03-14 13:56:21 +01:00
print '<td><input size="8" type="text" name="cvn" value="' . $companypaymentmode -> cvn . '"></td></tr>' ;
print '<tr><td>' . $langs -> trans ( " StripeID " ) . " ('card_....')</td> " ;
print '<td><input class="minwidth300" type="text" name="stripe_card_ref" value="' . $companypaymentmode -> stripe_card_ref . '"></td></tr>' ;
print '</table>' ;
print '</div>' ;
2020-10-27 18:19:31 +01:00
print dol_get_fiche_end ();
2018-03-14 13:56:21 +01:00
2021-08-20 14:41:30 +02:00
print $form -> buttonsSaveCancel ( " Modify " );
2018-03-14 13:56:21 +01:00
}
2018-03-07 16:17:25 +01:00
2018-03-14 11:51:13 +01:00
// Create BAN
2021-11-02 04:51:18 +01:00
if ( $socid && $action == 'create' && $permissiontoadd ) {
2020-10-22 22:50:03 +02:00
print dol_get_fiche_head ( $head , 'rib' , $langs -> trans ( " ThirdParty " ), 0 , 'company' );
2018-03-07 16:17:25 +01:00
2019-12-05 15:22:06 +01:00
$linkback = '<a href="' . DOL_URL_ROOT . '/societe/list.php?restore_lastsearch_values=1">' . $langs -> trans ( " BackToList " ) . '</a>' ;
2018-03-07 16:17:25 +01:00
2019-11-13 18:32:11 +01:00
dol_banner_tab ( $object , 'socid' , $linkback , ( $user -> socid ? 0 : 1 ), 'rowid' , 'nom' );
2018-03-07 16:17:25 +01:00
print '<div class="nofichecenter">' ;
print '<div class="underbanner clearboth"></div>' ;
print '<table class="border centpercent">' ;
print '<tr><td class="titlefieldcreate fieldrequired">' . $langs -> trans ( " LabelRIB " ) . '</td>' ;
2018-03-14 13:56:21 +01:00
print '<td><input class="minwidth200" type="text" id="label" name="label" value="' . GETPOST ( 'label' ) . '"></td></tr>' ;
2018-03-07 16:17:25 +01:00
print '<tr><td class="fieldrequired">' . $langs -> trans ( " Bank " ) . '</td>' ;
2018-03-14 13:56:21 +01:00
print '<td><input class="minwidth200" type="text" name="bank" value="' . GETPOST ( 'bank' ) . '"></td></tr>' ;
2018-03-07 16:17:25 +01:00
// Show fields of bank account
2018-03-14 13:56:21 +01:00
foreach ( $companybankaccount -> getFieldsToShow ( 1 ) as $val ) {
2019-11-13 18:32:11 +01:00
$require = false ;
2020-07-01 19:42:28 +02:00
$tooltip = '' ;
2018-03-07 16:17:25 +01:00
if ( $val == 'BankCode' ) {
$name = 'code_banque' ;
$size = 8 ;
2020-07-01 19:42:28 +02:00
$content = $companybankaccount -> code_banque ;
2018-03-07 16:17:25 +01:00
} elseif ( $val == 'DeskCode' ) {
$name = 'code_guichet' ;
$size = 8 ;
2020-07-01 19:42:28 +02:00
$content = $companybankaccount -> code_guichet ;
2018-03-07 16:17:25 +01:00
} elseif ( $val == 'BankAccountNumber' ) {
$name = 'number' ;
$size = 18 ;
2020-07-01 19:42:28 +02:00
$content = $companybankaccount -> number ;
2018-03-07 16:17:25 +01:00
} elseif ( $val == 'BankAccountNumberKey' ) {
$name = 'cle_rib' ;
$size = 3 ;
2020-07-01 19:42:28 +02:00
$content = $companybankaccount -> cle_rib ;
2018-03-07 16:17:25 +01:00
} elseif ( $val == 'IBAN' ) {
$name = 'iban' ;
$size = 30 ;
2020-07-01 19:42:28 +02:00
$content = $companybankaccount -> iban ;
2021-02-26 21:17:52 +01:00
if ( $companybankaccount -> needIBAN ()) {
$require = true ;
}
2020-07-01 19:42:28 +02:00
$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' ;
2018-03-07 16:17:25 +01:00
} elseif ( $val == 'BIC' ) {
$name = 'bic' ;
$size = 12 ;
2020-07-01 19:42:28 +02:00
$content = $companybankaccount -> bic ;
2021-02-26 21:17:52 +01:00
if ( $companybankaccount -> needIBAN ()) {
$require = true ;
}
2020-07-01 19:42:28 +02:00
$tooltip = $langs -> trans ( " Example " ) . ': LIABLT2XXXX' ;
2018-03-07 16:17:25 +01:00
}
2020-07-01 19:42:28 +02:00
print '<tr><td' . ( $require ? ' class="fieldrequired" ' : '' ) . '>' ;
if ( $tooltip ) {
print $form -> textwithpicto ( $langs -> trans ( $val ), $tooltip , 4 , 'help' , '' , 0 , 3 , $name );
} else {
print $langs -> trans ( $val );
}
print '</td>' ;
2018-03-07 16:17:25 +01:00
print '<td><input size="' . $size . '" type="text" class="flat" name="' . $name . '" value="' . GETPOST ( $name ) . '"></td>' ;
print '</tr>' ;
}
print '<tr><td>' . $langs -> trans ( " BankAccountDomiciliation " ) . '</td><td>' ;
print '<textarea name="domiciliation" rows="' . ROWS_4 . '" class="quatrevingtpercent" maxlength="255">' ;
print GETPOST ( 'domiciliation' );
print " </textarea></td></tr> " ;
print '<tr><td>' . $langs -> trans ( " BankAccountOwner " ) . '</td>' ;
2018-03-14 13:56:21 +01:00
print '<td><input class="minwidth200" type="text" name="proprio" value="' . GETPOST ( 'proprio' ) . '"></td></tr>' ;
2018-03-07 16:17:25 +01:00
print " </td></tr> \n " ;
print '<tr><td>' . $langs -> trans ( " BankAccountOwnerAddress " ) . '</td><td>' ;
print '<textarea name="owner_address" rows="' . ROWS_4 . '" class="quatrevingtpercent" maxlength="255">' ;
print GETPOST ( 'owner_address' );
print " </textarea></td></tr> " ;
print '</table>' ;
2021-02-26 21:17:52 +01:00
if ( $conf -> prelevement -> enabled ) {
2018-03-07 16:17:25 +01:00
print '<br>' ;
2019-11-05 21:24:41 +01:00
print '<table class="border centpercent">' ;
2018-03-07 16:17:25 +01:00
// RUM
print '<tr><td class="titlefieldcreate">' . $langs -> trans ( " RUM " ) . '</td>' ;
2019-01-27 11:55:16 +01:00
print '<td colspan="4"><input type="text" class="minwidth300" name="rum" value="' . GETPOST ( 'rum' , 'alpha' ) . '"> <div class="opacitymedium">' . $langs -> trans ( " RUMWillBeGenerated " ) . '</div></td></tr>' ;
2018-03-07 16:17:25 +01:00
2021-08-02 18:13:35 +02:00
$date_rum = dol_mktime ( 0 , 0 , 0 , GETPOST ( 'date_rummonth' ), GETPOST ( 'date_rumday' ), GETPOST ( 'date_rumyear' ));
2019-07-28 17:10:37 +02:00
print '<tr><td class="titlefieldcreate">' . $langs -> trans ( " DateRUM " ) . '</td>' ;
2021-08-02 18:13:35 +02:00
print '<td colspan="4">' . $form -> selectDate ( $date_rum , 'date_rum' , 0 , 0 , 1 , 'date_rum' , 1 , 1 ) . '</td></tr>' ;
2019-07-28 17:10:37 +02:00
2018-03-07 16:17:25 +01:00
print '<tr><td>' . $langs -> trans ( " WithdrawMode " ) . '</td><td>' ;
$tblArraychoice = array ( " FRST " => $langs -> trans ( " FRST " ), " RECUR " => $langs -> trans ( " RECUR " ));
2020-02-16 19:33:58 +01:00
print $form -> selectarray ( " frstrecur " , $tblArraychoice , ( GETPOSTISSET ( 'frstrecur' ) ? GETPOST ( 'frstrecur' ) : 'FRST' ), 0 );
2018-03-07 16:17:25 +01:00
print '</td></tr>' ;
print '</table>' ;
}
print '</div>' ;
2020-10-27 18:19:31 +01:00
print dol_get_fiche_end ();
2018-03-07 16:17:25 +01:00
2018-03-14 11:51:13 +01:00
dol_set_focus ( '#label' );
2021-08-20 14:41:30 +02:00
print $form -> buttonsSaveCancel ( " Add " );
2018-03-14 11:51:13 +01:00
}
// Create Card
2021-11-02 04:51:18 +01:00
if ( $socid && $action == 'createcard' && $permissiontoadd ) {
2020-10-22 22:50:03 +02:00
print dol_get_fiche_head ( $head , 'rib' , $langs -> trans ( " ThirdParty " ), 0 , 'company' );
2018-03-14 11:51:13 +01:00
2019-12-05 15:22:06 +01:00
$linkback = '<a href="' . DOL_URL_ROOT . '/societe/list.php?restore_lastsearch_values=1">' . $langs -> trans ( " BackToList " ) . '</a>' ;
2018-03-14 11:51:13 +01:00
2019-11-13 18:32:11 +01:00
dol_banner_tab ( $object , 'socid' , $linkback , ( $user -> socid ? 0 : 1 ), 'rowid' , 'nom' );
2018-03-14 11:51:13 +01:00
print '<div class="nofichecenter">' ;
print '<div class="underbanner clearboth"></div>' ;
print '<table class="border centpercent">' ;
print '<tr><td class="titlefieldcreate fieldrequired">' . $langs -> trans ( " Label " ) . '</td>' ;
2019-01-27 11:55:16 +01:00
print '<td><input class="minwidth200" type="text" id="label" name="label" value="' . GETPOST ( 'label' , 'alpha' ) . '"></td></tr>' ;
2018-03-14 11:51:13 +01:00
print '<tr><td class="fieldrequired">' . $langs -> trans ( " NameOnCard " ) . '</td>' ;
2019-01-27 11:55:16 +01:00
print '<td><input class="minwidth200" type="text" name="proprio" value="' . GETPOST ( 'proprio' , 'alpha' ) . '"></td></tr>' ;
2018-03-14 11:51:13 +01:00
2020-01-02 15:45:25 +01:00
print '<tr><td>' . $langs -> trans ( " CardNumber " ) . '</td>' ;
2019-01-27 11:55:16 +01:00
print '<td><input class="minwidth200" type="text" name="cardnumber" value="' . GETPOST ( 'cardnumber' , 'alpha' ) . '"></td></tr>' ;
2018-03-14 11:51:13 +01:00
print '<tr><td class="fieldrequired">' . $langs -> trans ( " ExpiryDate " ) . '</td>' ;
print '<td>' ;
2019-01-27 11:55:16 +01:00
print $formother -> select_month ( GETPOST ( 'exp_date_month' , 'int' ), 'exp_date_month' , 1 );
print $formother -> select_year ( GETPOST ( 'exp_date_year' , 'int' ), 'exp_date_year' , 1 , 5 , 10 , 0 , 0 , '' , 'marginleftonly' );
2018-03-14 11:51:13 +01:00
print '</td></tr>' ;
2020-01-02 15:45:25 +01:00
print '<tr><td>' . $langs -> trans ( " CVN " ) . '</td>' ;
print '<td><input class="width50" type="text" name="cvn" value="' . GETPOST ( 'cvn' , 'alpha' ) . '"></td></tr>' ;
2018-03-14 11:51:13 +01:00
2018-03-14 13:56:21 +01:00
print '<tr><td>' . $langs -> trans ( " StripeID " ) . " ('card_....')</td> " ;
2019-01-27 11:55:16 +01:00
print '<td><input class="minwidth300" type="text" name="stripe_card_ref" value="' . GETPOST ( 'stripe_card_ref' , 'alpha' ) . '"></td></tr>' ;
2018-03-14 13:56:21 +01:00
2018-03-14 11:51:13 +01:00
print '</table>' ;
print '</div>' ;
2020-10-27 18:19:31 +01:00
print dol_get_fiche_end ();
2018-03-14 11:51:13 +01:00
dol_set_focus ( '#label' );
2021-08-20 14:41:30 +02:00
print $form -> buttonsSaveCancel ( " Add " );
2018-03-07 16:17:25 +01:00
}
2021-11-02 04:51:18 +01:00
if ( $socid && ( $action == 'edit' || $action == 'editcard' ) && $permissiontoadd ) {
2018-03-07 16:17:25 +01:00
print '</form>' ;
}
2021-11-02 04:51:18 +01:00
if ( $socid && ( $action == 'create' || $action == 'createcard' ) && $permissiontoadd ) {
2018-03-07 16:17:25 +01:00
print '</form>' ;
}
2018-08-05 17:21:59 +02:00
// End of page
2018-03-07 16:17:25 +01:00
llxFooter ();
$db -> close ();