2018-03-07 16:17:25 +01:00
< ? php
/* Copyright ( C ) 2002 - 2004 Rodolphe Quiedeville < rodolphe @ quiedeville . org >
* Copyright ( C ) 2003 Jean - Louis Bergamo < jlb @ j1b . org >
2018-03-14 20:08:44 +01:00
* Copyright ( C ) 2004 - 2018 Laurent Destailleur < eldy @ users . sourceforge . net >
2018-10-27 14:43:12 +02:00
* Copyright ( C ) 2005 - 2009 Regis Houssin < regis . houssin @ inodbox . com >
2018-03-07 16:17:25 +01:00
* 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 >
2018-03-14 20:08:44 +01:00
* Copyright ( C ) 2018 ptibogxiv < support @ ptibogxiv . net >
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
* along with this program . If not , see < http :// www . gnu . org / licenses />.
*/
/**
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' ;
2018-07-24 19:12:35 +02:00
$langs -> loadLangs ( array ( " companies " , " commercial " , " banks " , " bills " , 'paypal' , 'stripe' , 'withdrawals' ));
2018-03-07 16:17:25 +01:00
2018-03-14 16:53:16 +01:00
2018-03-07 16:17:25 +01:00
// Security check
$socid = GETPOST ( " socid " , " int " );
if ( $user -> societe_id ) $socid = $user -> societe_id ;
$result = restrictedArea ( $user , 'societe' , '' , '' );
$id = GETPOST ( " id " , " int " );
$source = GETPOST ( " source " , " alpha " );
$ribid = GETPOST ( " ribid " , " int " );
$action = GETPOST ( " action " , 'alpha' , 3 );
2018-03-13 17:32:49 +01:00
$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
$extralabels = $extrafields -> fetch_name_optionals_label ( $object -> table_element );
// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
$hookmanager -> initHooks ( array ( 'thirdpartybancard' , 'globalcard' ));
2018-03-13 15:19:31 +01:00
if ( ! empty ( $conf -> stripe -> enabled ))
{
$service = 'StripeTest' ;
$servicestatus = 0 ;
if ( ! empty ( $conf -> global -> STRIPE_LIVE ) && ! GETPOST ( 'forcesandbox' , 'alpha' ))
{
$service = 'StripeLive' ;
2018-03-14 12:01:15 +01:00
$servicestatus = 1 ;
2018-03-13 15:19:31 +01:00
}
$stripe = new Stripe ( $db );
2018-03-14 16:53:16 +01:00
$stripeacc = $stripe -> getStripeAccount ( $service ); // Get Stripe OAuth connect account (no network access here)
$stripecu = $stripe -> getStripeCustomerAccount ( $object -> id , $servicestatus ); // Get remote Stripe customer 'cus_...' (no network access here)
2018-03-13 15:19:31 +01:00
}
2018-03-07 16:17:25 +01:00
/*
* Actions
*/
2018-03-13 17:32:49 +01:00
if ( $cancel )
{
$action = '' ;
}
2018-03-07 16:17:25 +01:00
$parameters = array ( 'id' => $socid , 'objcanvas' => $objcanvas );
$reshook = $hookmanager -> executeHooks ( 'doActions' , $parameters , $object , $action ); // Note that $action and $object may have been modified by some hooks
if ( $reshook < 0 ) setEventMessages ( $hookmanager -> error , $hookmanager -> errors , 'errors' );
if ( empty ( $reshook ))
{
if ( $cancel )
{
$action = '' ;
if ( ! empty ( $backtopage ))
{
header ( " Location: " . $backtopage );
exit ;
}
}
2018-03-14 11:51:13 +01:00
if ( $action == 'update' )
2018-03-07 16:17:25 +01:00
{
// Modification
2018-03-14 13:56:21 +01:00
if ( ! GETPOST ( 'label' , 'alpha' ) || ! GETPOST ( 'bank' , 'alpha' ))
2018-03-07 16:17:25 +01:00
{
2018-03-14 13:56:21 +01:00
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' );
2018-03-07 16:17:25 +01:00
$action = 'edit' ;
$error ++ ;
}
2018-03-14 13:56:21 +01:00
if ( $companybankaccount -> needIBAN () == 1 )
2018-03-07 16:17:25 +01:00
{
if ( ! GETPOST ( 'iban' ))
{
setEventMessages ( $langs -> trans ( " ErrorFieldRequired " , $langs -> transnoentitiesnoconv ( " IBAN " )), null , 'errors' );
$action = 'edit' ;
$error ++ ;
}
if ( ! GETPOST ( 'bic' ))
{
setEventMessages ( $langs -> trans ( " ErrorFieldRequired " , $langs -> transnoentitiesnoconv ( " BIC " )), null , 'errors' );
$action = 'edit' ;
$error ++ ;
}
}
2018-03-14 13:56:21 +01:00
$companybankaccount -> fetch ( $id );
2018-03-07 16:17:25 +01:00
if ( ! $error )
{
2018-03-14 13:56:21 +01:00
$companybankaccount -> socid = $object -> id ;
$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' );
if ( empty ( $companybankaccount -> rum ))
2018-03-07 16:17:25 +01:00
{
2018-03-14 13:56:21 +01:00
$companybankaccount -> rum = $prelevement -> buildRumNumber ( $object -> code_client , $companybankaccount -> datec , $companybankaccount -> id );
$companybankaccount -> date_rum = dol_now ();
2018-03-07 16:17:25 +01:00
}
2018-03-14 13:56:21 +01:00
$result = $companybankaccount -> update ( $user );
2018-03-07 16:17:25 +01:00
if ( ! $result )
{
2018-03-14 13:56:21 +01:00
setEventMessages ( $companybankaccount -> error , $companybankaccount -> errors , 'errors' );
2018-03-07 16:17:25 +01:00
}
else
{
// If this account is the default bank account, we disable others
2018-03-14 13:56:21 +01:00
if ( $companybankaccount -> default_rib )
2018-03-07 16:17:25 +01:00
{
2018-03-14 13:56:21 +01:00
$companybankaccount -> setAsDefault ( $id ); // This will make sure there is only one default rib
}
$url = $_SERVER [ " PHP_SELF " ] . '?socid=' . $object -> id ;
header ( 'Location: ' . $url );
exit ;
}
}
}
if ( $action == 'updatecard' )
{
// Modification
if ( ! GETPOST ( 'label' , 'alpha' ) || ! GETPOST ( 'proprio' , 'alpha' ) || ! GETPOST ( 'cardnumber' , 'alpha' ) || ! GETPOST ( 'exp_date_month' , 'alpha' ) || ! GETPOST ( 'exp_date_year' , 'alpha' ) || ! GETPOST ( 'cvn' , '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' );
if ( ! GETPOST ( 'cardnumber' , 'alpha' )) setEventMessages ( $langs -> trans ( " ErrorFieldRequired " , $langs -> transnoentitiesnoconv ( " CardNumber " )), null , 'errors' );
if ( ! ( GETPOST ( 'exp_date_month' , 'alpha' ) > 0 ) || ! ( GETPOST ( 'exp_date_year' , 'alpha' ) > 0 )) setEventMessages ( $langs -> trans ( " ErrorFieldRequired " , $langs -> transnoentitiesnoconv ( " ExpiryDate " )), null , 'errors' );
if ( ! GETPOST ( 'cvn' , 'alpha' )) setEventMessages ( $langs -> trans ( " ErrorFieldRequired " , $langs -> transnoentitiesnoconv ( " CVN " )), null , 'errors' );
$action = 'createcard' ;
$error ++ ;
}
$companypaymentmode -> fetch ( $id );
if ( ! $error )
{
$companypaymentmode -> fk_soc = $object -> id ;
$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
$companypaymentmode -> stripe_card_ref = GETPOST ( 'stripe_card_ref' , 'alpha' );
$result = $companypaymentmode -> update ( $user );
if ( ! $result )
{
setEventMessages ( $companypaymentmode -> error , $companypaymentmode -> errors , 'errors' );
}
else
{
// If this account is the default bank account, we disable others
if ( $companypaymentmode -> default_rib )
{
$companypaymentmode -> setAsDefault ( $id ); // This will make sure there is only one default rib
2018-03-07 16:17:25 +01:00
}
2018-03-08 22:26:42 +01:00
$url = $_SERVER [ " PHP_SELF " ] . '?socid=' . $object -> id ;
2018-03-07 16:17:25 +01:00
header ( 'Location: ' . $url );
exit ;
}
}
}
2018-03-14 11:51:13 +01:00
if ( $action == 'add' )
2018-03-07 16:17:25 +01:00
{
$error = 0 ;
2018-03-14 11:51:13 +01:00
if ( ! GETPOST ( 'label' , 'alpha' ) || ! GETPOST ( 'bank' , 'alpha' ))
2018-03-07 16:17:25 +01:00
{
2018-03-14 11:51:13 +01:00
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' );
2018-03-07 16:17:25 +01:00
$action = 'create' ;
$error ++ ;
}
if ( ! $error )
{
// Ajout
2018-03-14 13:56:21 +01:00
$companybankaccount = new CompanyBankAccount ( $db );
$companybankaccount -> socid = $object -> id ;
$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' );
$companybankaccount -> rum = GETPOST ( 'rum' , 'alpha' );
$companybankaccount -> datec = dol_now ();
$companybankaccount -> status = 1 ;
2018-03-07 16:17:25 +01:00
$db -> begin ();
// This test can be done only once properties were set
2018-03-14 13:56:21 +01:00
if ( $companybankaccount -> needIBAN () == 1 )
2018-03-07 16:17:25 +01:00
{
if ( ! GETPOST ( 'iban' ))
{
setEventMessages ( $langs -> trans ( " ErrorFieldRequired " , $langs -> transnoentitiesnoconv ( " IBAN " )), null , 'errors' );
$action = 'create' ;
$error ++ ;
}
if ( ! GETPOST ( 'bic' ))
{
setEventMessages ( $langs -> trans ( " ErrorFieldRequired " , $langs -> transnoentitiesnoconv ( " BIC " )), null , 'errors' );
$action = 'create' ;
$error ++ ;
}
}
if ( ! $error )
{
2018-03-14 13:56:21 +01:00
$result = $companybankaccount -> create ( $user );
2018-03-07 16:17:25 +01:00
if ( $result < 0 )
{
$error ++ ;
2018-03-14 13:56:21 +01:00
setEventMessages ( $companybankaccount -> error , $companybankaccount -> errors , 'errors' );
2018-03-07 16:17:25 +01:00
$action = 'create' ; // Force chargement page création
}
2018-03-14 13:56:21 +01:00
if ( empty ( $companybankaccount -> rum ))
2018-03-07 16:17:25 +01:00
{
2018-03-14 13:56:21 +01:00
$companybankaccount -> rum = $prelevement -> buildRumNumber ( $object -> code_client , $companybankaccount -> datec , $companybankaccount -> id );
$companybankaccount -> date_rum = dol_now ();
2018-03-07 16:17:25 +01:00
}
}
if ( ! $error )
{
2018-03-14 13:56:21 +01:00
$result = $companybankaccount -> update ( $user ); // This will set the UMR number.
2018-03-07 16:17:25 +01:00
if ( $result < 0 )
{
$error ++ ;
2018-03-14 13:56:21 +01:00
setEventMessages ( $companybankaccount -> error , $companybankaccount -> errors , 'errors' );
2018-03-07 16:17:25 +01:00
$action = 'create' ;
}
}
if ( ! $error )
{
$db -> commit ();
2018-03-08 22:26:42 +01:00
$url = $_SERVER [ " PHP_SELF " ] . '?socid=' . $object -> id ;
2018-03-07 16:17:25 +01:00
header ( 'Location: ' . $url );
exit ;
}
else
{
$db -> rollback ();
}
}
}
2018-03-14 11:51:13 +01:00
if ( $action == 'addcard' )
{
$error = 0 ;
if ( ! GETPOST ( 'label' , 'alpha' ) || ! GETPOST ( 'proprio' , 'alpha' ) || ! GETPOST ( 'cardnumber' , 'alpha' ) || ! GETPOST ( 'exp_date_month' , 'alpha' ) || ! GETPOST ( 'exp_date_year' , 'alpha' ) || ! GETPOST ( 'cvn' , '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' );
if ( ! GETPOST ( 'cardnumber' , 'alpha' )) setEventMessages ( $langs -> trans ( " ErrorFieldRequired " , $langs -> transnoentitiesnoconv ( " CardNumber " )), null , 'errors' );
if ( ! ( GETPOST ( 'exp_date_month' , 'alpha' ) > 0 ) || ! ( GETPOST ( 'exp_date_year' , 'alpha' ) > 0 )) setEventMessages ( $langs -> trans ( " ErrorFieldRequired " , $langs -> transnoentitiesnoconv ( " ExpiryDate " )), null , 'errors' );
if ( ! GETPOST ( 'cvn' , 'alpha' )) setEventMessages ( $langs -> trans ( " ErrorFieldRequired " , $langs -> transnoentitiesnoconv ( " CVN " )), null , 'errors' );
$action = 'createcard' ;
$error ++ ;
}
if ( ! $error )
{
// Ajout
2018-03-14 13:56:21 +01:00
$companypaymentmode = new CompanyPaymentMode ( $db );
$companypaymentmode -> fk_soc = $object -> id ;
$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' );
$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
$companypaymentmode -> stripe_card_ref = GETPOST ( 'stripe_card_ref' , 'alpha' );
2018-03-14 11:51:13 +01:00
$db -> begin ();
if ( ! $error )
{
2018-03-14 13:56:21 +01:00
$result = $companypaymentmode -> create ( $user );
2018-03-14 11:51:13 +01:00
if ( $result < 0 )
{
$error ++ ;
2018-03-14 13:56:21 +01:00
setEventMessages ( $companypaymentmode -> error , $companypaymentmode -> errors , 'errors' );
2018-03-14 11:51:13 +01:00
$action = 'createcard' ; // Force chargement page création
}
}
if ( ! $error )
{
$db -> commit ();
$url = $_SERVER [ " PHP_SELF " ] . '?socid=' . $object -> id ;
header ( 'Location: ' . $url );
exit ;
}
else
{
$db -> rollback ();
}
}
}
2018-03-14 13:56:21 +01:00
if ( $action == 'setasbankdefault' && GETPOST ( 'ribid' , 'int' ) > 0 )
2018-03-07 16:17:25 +01:00
{
2018-03-14 13:56:21 +01:00
$companybankaccount = new CompanyBankAccount ( $db );
$res = $companybankaccount -> setAsDefault ( GETPOST ( 'ribid' , 'int' ));
2018-03-07 16:17:25 +01:00
if ( $res )
{
2018-03-08 02:08:14 +01:00
$url = DOL_URL_ROOT . '/societe/paymentmodes.php?socid=' . $object -> id ;
2018-03-07 16:17:25 +01:00
header ( 'Location: ' . $url );
exit ;
}
else
{
setEventMessages ( $db -> lasterror , null , 'errors' );
}
}
2018-03-14 11:51:13 +01:00
if ( $action == 'confirm_deletecard' && GETPOST ( 'confirm' , 'alpha' ) == 'yes' )
{
2018-03-14 13:56:21 +01:00
$companypaymentmode = new CompanyPaymentMode ( $db );
if ( $companypaymentmode -> fetch ( $ribid ? $ribid : $id ))
2018-03-14 11:51:13 +01:00
{
2018-03-14 13:56:21 +01:00
$result = $companypaymentmode -> delete ( $user );
2018-03-14 11:51:13 +01:00
if ( $result > 0 )
{
$url = $_SERVER [ 'PHP_SELF' ] . " ?socid= " . $object -> id ;
header ( 'Location: ' . $url );
exit ;
}
else
{
2018-03-14 13:56:21 +01:00
setEventMessages ( $companypaymentmode -> error , $companypaymentmode -> errors , 'errors' );
2018-03-14 11:51:13 +01:00
}
}
else
{
2018-03-14 13:56:21 +01:00
setEventMessages ( $companypaymentmode -> error , $companypaymentmode -> errors , 'errors' );
2018-03-14 11:51:13 +01:00
}
}
if ( $action == 'confirm_delete' && GETPOST ( 'confirm' , 'alpha' ) == 'yes' )
2018-03-07 16:17:25 +01:00
{
2018-03-14 13:56:21 +01:00
$companybankaccount = new CompanyBankAccount ( $db );
if ( $companybankaccount -> fetch ( $ribid ? $ribid : $id ))
2018-03-07 16:17:25 +01:00
{
2018-03-14 13:56:21 +01:00
$result = $companybankaccount -> delete ( $user );
2018-03-07 16:17:25 +01:00
if ( $result > 0 )
{
$url = $_SERVER [ 'PHP_SELF' ] . " ?socid= " . $object -> id ;
header ( 'Location: ' . $url );
exit ;
}
else
{
2018-03-14 13:56:21 +01:00
setEventMessages ( $companybankaccount -> error , $companybankaccount -> errors , 'errors' );
2018-03-07 16:17:25 +01:00
}
}
else
{
2018-03-14 13:56:21 +01:00
setEventMessages ( $companybankaccount -> error , $companybankaccount -> errors , 'errors' );
2018-03-07 16:17:25 +01:00
}
}
$savid = $id ;
// Actions to build doc
if ( $action == 'builddocrib' )
{
$action = 'builddoc' ;
$moreparams = array (
'use_companybankid' => GETPOST ( 'companybankid' ),
'force_dir_output' => $conf -> societe -> multidir_output [ $object -> entity ] . '/' . dol_sanitizeFileName ( $object -> id )
);
2018-04-20 14:50:11 +02:00
$_POST [ 'lang_id' ] = GETPOST ( 'lang_idrib' . GETPOST ( 'companybankid' , 'int' ), 'alpha' );
$_POST [ 'model' ] = GETPOST ( 'modelrib' . GETPOST ( 'companybankid' , 'int' ), 'alpha' );
2018-03-07 16:17:25 +01:00
}
2018-03-14 16:53:16 +01:00
2018-03-07 16:17:25 +01:00
$id = $socid ;
$upload_dir = $conf -> societe -> multidir_output [ $object -> entity ];
$permissioncreate = $user -> rights -> societe -> creer ;
include DOL_DOCUMENT_ROOT . '/core/actions_builddoc.inc.php' ;
$id = $savid ;
2018-03-13 17:32:49 +01:00
// Action for stripe
if ( ! empty ( $conf -> stripe -> enabled ) && class_exists ( 'Stripe' ))
2018-03-07 16:17:25 +01:00
{
2018-03-14 16:53:16 +01:00
if ( $action == 'synccustomertostripe' )
{
if ( $object -> client == 0 )
{
$error ++ ;
setEventMessages ( 'ThisThirdpartyIsNotACustomer' , null , 'errors' );
}
else
{
// Creation of Stripe customer + update of societe_account
$cu = $stripe -> customerStripe ( $object , $stripeacc , $servicestatus , 1 );
if ( ! $cu )
{
$error ++ ;
setEventMessages ( $stripe -> error , $stripe -> errors , 'errors' );
}
else
{
$stripecu = $cu -> id ;
}
}
}
2018-03-14 21:07:45 +01:00
if ( $action == 'synccardtostripe' )
{
$companypaymentmode = new CompanyPaymentMode ( $db );
$companypaymentmode -> fetch ( $id );
if ( $companypaymentmode -> type != 'card' )
{
$error ++ ;
setEventMessages ( 'ThisPaymentModeIsNotACard' , null , 'errors' );
}
else
{
// Get the Stripe customer
$cu = $stripe -> customerStripe ( $object , $stripeacc , $servicestatus );
if ( ! $cu )
{
$error ++ ;
setEventMessages ( $stripe -> error , $stripe -> errors , 'errors' );
}
if ( ! $error )
{
// Creation of Stripe card + update of societe_account
$card = $stripe -> cardStripe ( $cu , $companypaymentmode , $stripeacc , $servicestatus , 1 );
if ( ! $card )
{
$error ++ ;
setEventMessages ( $stripe -> error , $stripe -> errors , 'errors' );
}
else
{
$stripecard = $card -> id ;
}
}
}
}
2018-03-14 16:53:16 +01:00
2018-03-13 17:32:49 +01:00
if ( $action == 'setkey_account' )
{
$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
2018-09-06 11:35:19 +02:00
if ( empty ( $newcu )) {
$sql = " DELETE FROM " . MAIN_DB_PREFIX . " societe_account WHERE site = 'stripe' AND fk_soc = " . $object -> id . " AND status = " . $servicestatus . " AND entity = " . $conf -> entity ;
} else {
2018-03-13 17:32:49 +01:00
$sql = 'UPDATE ' . MAIN_DB_PREFIX . " societe_account " ;
$sql .= " SET key_account = ' " . $db -> escape ( GETPOST ( 'key_account' , 'alpha' )) . " ' " ;
$sql .= " WHERE site = 'stripe' AND fk_soc = " . $object -> id . " AND status = " . $servicestatus . " AND entity = " . $conf -> entity ; // Keep = here for entity. Only 1 record must be modified !
2018-09-06 11:35:19 +02:00
}
2018-10-16 20:00:53 +02:00
2018-03-13 17:32:49 +01:00
$resql = $db -> query ( $sql );
$num = $db -> num_rows ( $resql );
2018-09-06 11:35:19 +02:00
if ( empty ( $num ) && ! empty ( $newcu ))
2018-03-13 17:32:49 +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 ;
$result = $societeaccount -> create ( $user );
if ( $result < 0 )
{
$error ++ ;
}
}
if ( ! $error )
{
$stripecu = $newcu ;
$db -> commit ();
}
else
{
$db -> rollback ();
}
}
2018-03-14 11:51:13 +01:00
if ( $action == 'setlocalassourcedefault' )
{
try {
2018-03-14 13:56:21 +01:00
$companypaymentmode -> setAsDefault ( $id );
2018-03-14 11:51:13 +01:00
$url = DOL_URL_ROOT . '/societe/paymentmodes.php?socid=' . $object -> id ;
header ( 'Location: ' . $url );
exit ;
}
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
}
}
elseif ( $action == 'setassourcedefault' )
2018-03-13 17:32:49 +01:00
{
try {
2018-03-15 00:53:24 +01:00
$cu = $stripe -> customerStripe ( $object , $stripeacc , $servicestatus );
2018-03-13 17:32:49 +01:00
$cu -> default_source = ( string ) $source ;
$result = $cu -> save ();
$url = DOL_URL_ROOT . '/societe/paymentmodes.php?socid=' . $object -> id ;
header ( 'Location: ' . $url );
exit ;
}
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-05-16 20:41:01 +02:00
elseif ( $action == 'deletecard' && $source )
2018-03-13 17:32:49 +01:00
{
try {
2018-03-15 00:53:24 +01:00
$cu = $stripe -> customerStripe ( $object , $stripeacc , $servicestatus );
$card = $cu -> sources -> retrieve ( " $source " );
if ( $card )
{
// $card->detach(); Does not work with card_, only with src_
2018-03-16 00:16:32 +01:00
if ( method_exists ( $card , 'detach' )) $card -> detach ();
else $card -> delete ();
2018-03-15 00:53:24 +01:00
}
2018-03-13 17:32:49 +01:00
$url = DOL_URL_ROOT . '/societe/paymentmodes.php?socid=' . $object -> id ;
header ( 'Location: ' . $url );
exit ;
}
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 );
llxHeader ();
2018-03-08 22:26:42 +01:00
2018-03-07 16:17:25 +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' );
} */
if ( ! empty ( $conf -> stripe -> enabled ) && ( empty ( $conf -> global -> STRIPE_LIVE ) || GETPOST ( 'forcesandbox' , 'alpha' )))
{
dol_htmloutput_mesg ( $langs -> trans ( 'YouAreCurrentlyInSandboxMode' , 'Stripe' ), '' , 'warning' );
}
2018-03-14 13:56:21 +01:00
// Load Bank account
2018-03-07 16:17:25 +01:00
if ( ! $id )
{
2018-03-14 13:56:21 +01:00
$companybankaccount -> fetch ( 0 , $object -> id );
$companypaymentmode -> fetch ( 0 , null , $object -> id , 'card' );
2018-03-07 16:17:25 +01:00
}
else
{
2018-03-14 13:56:21 +01:00
$companybankaccount -> fetch ( $id );
$companypaymentmode -> fetch ( $id );
2018-03-07 16:17:25 +01:00
}
2018-03-14 13:56:21 +01:00
if ( empty ( $companybankaccount -> socid )) $companybankaccount -> socid = $object -> id ;
2018-03-07 16:17:25 +01:00
2018-03-14 11:51:13 +01:00
if ( $socid && ( $action == 'edit' || $action == 'editcard' ) && $user -> rights -> societe -> creer )
2018-03-07 16:17:25 +01:00
{
2018-03-08 22:26:42 +01:00
print '<form action="' . $_SERVER [ " PHP_SELF " ] . '?socid=' . $object -> id . '" method="post">' ;
2018-03-07 16:17:25 +01:00
print '<input type="hidden" name="token" value="' . $_SESSION [ 'newtoken' ] . '">' ;
2018-03-14 13:56:21 +01:00
$actionforadd = 'update' ;
if ( $action == 'editcard' ) $actionforadd = 'updatecard' ;
print '<input type="hidden" name="action" value="' . $actionforadd . '">' ;
2018-03-07 16:17:25 +01:00
print '<input type="hidden" name="id" value="' . GETPOST ( " id " , " int " ) . '">' ;
}
2018-03-14 11:51:13 +01:00
if ( $socid && ( $action == 'create' || $action == 'createcard' ) && $user -> rights -> societe -> creer )
2018-03-07 16:17:25 +01:00
{
2018-03-08 22:26:42 +01:00
print '<form action="' . $_SERVER [ " PHP_SELF " ] . '?socid=' . $object -> id . '" method="post">' ;
2018-03-07 16:17:25 +01:00
print '<input type="hidden" name="token" value="' . $_SESSION [ 'newtoken' ] . '">' ;
2018-03-14 11:51:13 +01:00
$actionforadd = 'add' ;
if ( $action == 'createcard' ) $actionforadd = 'addcard' ;
print '<input type="hidden" name="action" value="' . $actionforadd . '">' ;
2018-03-07 16:17:25 +01:00
}
// View
2018-03-14 11:51:13 +01:00
if ( $socid && $action != 'edit' && $action != 'create' && $action != 'editcard' && $action != 'createcard' )
2018-03-07 16:17:25 +01:00
{
dol_fiche_head ( $head , 'rib' , $langs -> trans ( " ThirdParty " ), - 1 , 'company' );
2018-03-14 11:51:13 +01:00
// Confirm delete ban
2018-03-07 16:17:25 +01:00
if ( $action == 'delete' )
{
2018-03-14 13:56:21 +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
if ( $action == 'deletecard' )
{
2018-03-14 13:56:21 +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>' ;
dol_banner_tab ( $object , 'socid' , $linkback , ( $user -> societe_id ? 0 : 1 ), 'rowid' , 'nom' );
2018-03-12 16:04:23 +01:00
if ( ! empty ( $conf -> global -> SOCIETE_USEPREFIX )) // Old not used prefix field
2018-03-12 15:59:03 +01:00
{
2018-03-12 16:04:23 +01:00
print '<tr><td class="titlefield">' . $langs -> trans ( 'Prefix' ) . '</td><td colspan="3">' . $object -> prefix_comm . '</td></tr>' ;
}
//if ($conf->agenda->enabled && $user->rights->agenda->myactions->read) $elementTypeArray['action']=$langs->transnoentitiesnoconv('Events');
2018-03-12 15:59:03 +01:00
2018-03-12 16:04:23 +01:00
print '<div class="fichecenter">' ;
print '<div class="underbanner clearboth"></div>' ;
print '<table class="border tableforfield" width="100%">' ;
if ( $object -> client )
{
print '<tr><td class="titlefield">' ;
2018-03-14 16:53:16 +01:00
print $langs -> trans ( 'CustomerCode' ) . '</td><td colspan="2">' ;
2018-03-12 16:04:23 +01:00
print $object -> code_client ;
if ( $object -> check_codeclient () <> 0 ) print ' <font class="error">(' . $langs -> trans ( " WrongCustomerCode " ) . ')</font>' ;
print '</td></tr>' ;
$sql = " SELECT count(*) as nb from " . MAIN_DB_PREFIX . " facture where fk_soc = " . $socid ;
$resql = $db -> query ( $sql );
if ( ! $resql ) dol_print_error ( $db );
$obj = $db -> fetch_object ( $resql );
$nbFactsClient = $obj -> nb ;
$thirdTypeArray [ 'customer' ] = $langs -> trans ( " customer " );
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' );
}
2018-03-13 15:19:31 +01:00
if ( ! empty ( $conf -> stripe -> enabled ))
2018-03-12 16:04:23 +01:00
{
2018-03-13 17:32:49 +01:00
$permissiontowrite = $user -> rights -> societe -> creer ;
2018-03-13 15:19:31 +01:00
// Stripe customer key 'cu_....' stored into llx_societe_account
2018-03-13 17:32:49 +01:00
print '<tr><td class="titlefield">' ;
//print $langs->trans('StripeCustomerId');
2018-03-14 20:08:44 +01:00
print $form -> editfieldkey ( " StripeCustomerId " , 'key_account' , $stripecu , $object , $permissiontowrite , 'string' , '' , 0 , 2 , 'socid' );
2018-03-13 17:32:49 +01:00
print '</td><td>' ;
//print $stripecu;
2018-03-14 20:08:44 +01:00
print $form -> editfieldval ( " StripeCustomerId " , 'key_account' , $stripecu , $object , $permissiontowrite , 'string' , '' , null , null , '' , 2 , '' , 'socid' );
2018-05-17 09:45:31 +02:00
if ( $stripecu && $action != 'editkey_account' )
2018-03-15 00:40:29 +01:00
{
2018-09-14 15:38:38 +02:00
if ( ! empty ( $conf -> stripe -> enabled ) && ! empty ( $stripeacc )) $connect = $stripeacc . '/' ;
$url = 'https://dashboard.stripe.com/' . $connect . 'test/customers/' . $stripecu ;
2018-03-15 00:40:29 +01:00
if ( $servicestatus )
{
2018-09-14 15:38:38 +02:00
$url = 'https://dashboard.stripe.com/' . $connect . 'customers/' . $stripecu ;
2018-03-15 00:40:29 +01:00
}
print ' <a href="' . $url . '" target="_stripe">' . img_picto ( $langs -> trans ( 'ShowInStripe' ), 'object_globe' ) . '</a>' ;
}
2018-03-14 16:53:16 +01:00
print '</td><td align="right">' ;
if ( empty ( $stripecu ))
{
print '<form action="' . $_SERVER [ " PHP_SELF " ] . '" method="post">' ;
print '<input type="hidden" name="action" value="synccustomertostripe">' ;
print '<input type="hidden" name="token" value="' . $_SESSION [ 'newtoken' ] . '">' ;
print '<input type="hidden" name="socid" value="' . $object -> id . '">' ;
print '<input type="hidden" name="companybankid" value="' . $rib -> id . '">' ;
print '<input type="submit" class="button" name="syncstripecustomer" value="' . $langs -> trans ( " CreateCustomerOnStripe " ) . '">' ;
print '</form>' ;
}
2018-03-12 15:59:03 +01:00
print '</td></tr>' ;
}
2018-03-07 16:17:25 +01:00
2018-03-12 16:04:23 +01:00
print '</table>' ;
print '</div>' ;
2018-04-24 11:12:12 +02:00
dol_fiche_end ();
2018-03-13 15:19:31 +01:00
print '<br>' ;
2018-03-14 13:56:21 +01:00
// List of Stripe payment modes
2018-03-07 16:17:25 +01:00
if ( ! ( empty ( $conf -> stripe -> enabled )))
{
2018-03-13 22:43:50 +01:00
$morehtmlright = '' ;
if ( ! empty ( $conf -> global -> STRIPE_ALLOW_LOCAL_CARD ))
{
2018-04-24 11:12:12 +02:00
$morehtmlright = '<a class="butActionNew" href="' . $_SERVER [ " PHP_SELF " ] . '?socid=' . $object -> id . '&action=createcard">' . $langs -> trans ( " Add " ) . ' <span class="fa fa-plus-circle valignmiddle"></span></a>' ;
2018-03-13 22:43:50 +01:00
}
2018-03-16 10:07:47 +01:00
print load_fiche_titre ( $langs -> trans ( 'StripePaymentModes' ) . ( $stripeacc ? ' (Stripe connection with StripeConnect account ' . $stripeacc . ')' : ' (Stripe connection with keys from Stripe module setup)' ), $morehtmlright , '' );
2018-03-08 22:26:42 +01:00
2018-03-13 15:19:31 +01:00
$listofsources = array ();
2018-03-14 16:53:16 +01:00
if ( is_object ( $stripe ))
2018-03-07 16:17:25 +01:00
{
2018-03-13 17:32:49 +01:00
try {
2018-03-14 16:53:16 +01:00
$customerstripe = $stripe -> customerStripe ( $object , $stripeacc , $servicestatus );
2018-03-13 17:32:49 +01:00
if ( $customerstripe -> id ) {
$listofsources = $customerstripe -> sources -> data ;
}
}
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
}
2018-03-13 15:19:31 +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
2018-03-07 16:17:25 +01:00
print '<table class="liste" width="100%">' . " \n " ;
print '<tr class="liste_titre">' ;
2018-03-13 22:43:50 +01:00
if ( ! empty ( $conf -> global -> STRIPE_ALLOW_LOCAL_CARD ))
{
print '<td>' . $langs -> trans ( 'LocalID' ) . '</td>' ;
}
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>' ;
2018-03-07 16:17:25 +01:00
print '<td align="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>' ;
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
if ( ! empty ( $conf -> global -> STRIPE_ALLOW_LOCAL_CARD ))
{
//$societeaccount = new SocieteAccount($db);
$companypaymentmodetemp = new CompanyPaymentMode ( $db );
$sql = 'SELECT rowid FROM ' . MAIN_DB_PREFIX . " societe_rib " ;
$sql .= " WHERE type in ('card', 'paypal') " ;
$sql .= " AND fk_soc = " . $object -> id ;
2018-05-17 15:13:16 +02:00
$sql .= " AND status = " . $servicestatus ;
2018-03-13 22:43:50 +01:00
$resql = $db -> query ( $sql );
if ( $resql )
{
$num_rows = $db -> num_rows ( $resql );
if ( $num_rows )
{
$i = 0 ;
while ( $i < $num_rows )
{
$nblocal ++ ;
$obj = $db -> fetch_object ( $resql );
if ( $obj )
{
$companypaymentmodetemp -> fetch ( $obj -> rowid );
2018-03-14 13:56:21 +01:00
$arrayofstripecard [ $companypaymentmodetemp -> stripe_card_ref ] = $companypaymentmodetemp -> stripe_card_ref ;
2018-03-13 22:43:50 +01:00
print '<tr>' ;
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>' ;
2018-03-14 13:56:21 +01:00
print $companypaymentmodetemp -> stripe_card_ref ;
2018-03-15 00:40:29 +01:00
/* if ( $companypaymentmodetemp -> stripe_card_ref )
{
$url = 'https://dashboard.stripe.com/test/card/' . $companypaymentmodetemp -> stripe_card_ref ;
if ( $servicestatus )
{
$url = 'https://dashboard.stripe.com/card/' . $companypaymentmodetemp -> stripe_card_ref ;
}
print ' <a href="' . $url . '" target="_stripe">' . img_picto ( $langs -> trans ( 'ShowInStripe' ), 'object_globe' ) . '</a>' ;
} */
2018-03-13 22:43:50 +01:00
print '</td>' ;
print '<td>' ;
print img_credit_card ( $companypaymentmodetemp -> type );
print '</td>' ;
print '<td>' ;
2018-03-14 17:15:31 +01:00
if ( $companypaymentmodetemp -> last_four ) print '....' . $companypaymentmodetemp -> last_four ;
2018-03-14 21:07:45 +01:00
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>' ;
if ( $companypaymentmodetemp -> country_code )
{
$img = picto_from_langcode ( $companypaymentmodetemp -> country_code );
print $img ? $img . ' ' : '' ;
print getCountry ( $companypaymentmodetemp -> country_code , 1 );
}
else print img_warning () . ' <font class="error">' . $langs -> trans ( " ErrorFieldRequired " , $langs -> transnoentitiesnoconv ( " CompanyCountry " )) . '</font>' ;
print '</td>' ;
2018-03-13 22:54:28 +01:00
// Default
2018-03-13 22:43:50 +01:00
print '<td align="center">' ;
2018-03-14 11:51:13 +01:00
if ( empty ( $companypaymentmodetemp -> default_rib ))
2018-03-13 22:54:28 +01:00
{
2018-03-14 11:51:13 +01:00
print '<a href="' . DOL_URL_ROOT . '/societe/paymentmodes.php?socid=' . $object -> id . '&id=' . $companypaymentmodetemp -> id . '&action=setlocalassourcedefault">' ;
2018-03-13 22:54:28 +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 {
print img_picto ( $langs -> trans ( " Default " ), 'on' );
}
2018-03-13 22:43:50 +01:00
print '</td>' ;
print '<td>' ;
2018-03-14 11:51:13 +01:00
if ( empty ( $companypaymentmodetemp -> stripe_card_ref )) print $langs -> trans ( " Local " );
2018-03-13 22:43:50 +01:00
else print $langs -> trans ( " LocalAndRemote " );
print '</td>' ;
2018-09-09 13:15:32 +02:00
print '<td>' ;
print dol_print_date ( $companypaymentmodetemp -> tms , 'dayhour' );
print '</td>' ;
2018-03-14 20:08:44 +01:00
print '<td align="right" class="nowraponall">' ;
2018-03-13 22:43:50 +01:00
if ( $user -> rights -> societe -> creer )
{
2018-03-14 21:07:45 +01:00
if ( $stripecu && empty ( $companypaymentmodetemp -> stripe_card_ref ))
{
print '<a href="' . $_SERVER [ 'PHP_SELF' ] . '?action=synccardtostripe&socid=' . $object -> id . '&id=' . $companypaymentmodetemp -> id . '" class="button">' . $langs -> trans ( " CreateCardOnStripe " ) . '</a>' ;
}
2018-03-13 22:43:50 +01:00
print '<a href="' . DOL_URL_ROOT . '/societe/paymentmodes.php?socid=' . $object -> id . '&id=' . $companypaymentmodetemp -> id . '&action=editcard">' ;
print img_picto ( $langs -> trans ( " Modify " ), 'edit' );
print '</a>' ;
print ' ' ;
2018-05-16 20:41:01 +02:00
print '<a href="' . DOL_URL_ROOT . '/societe/paymentmodes.php?socid=' . $object -> id . '&id=' . $companypaymentmodetemp -> id . '&action=deletecard">' ; // 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 ++ ;
}
}
}
else dol_print_error ( $db );
}
// Show remote sources (not already shown as local source)
if ( is_array ( $listofsources ) && count ( $listofsources ))
2018-03-07 16:17:25 +01:00
{
2018-03-13 15:19:31 +01:00
foreach ( $listofsources as $src )
2018-03-07 16:17:25 +01:00
{
2018-03-13 22:43:50 +01:00
if ( ! empty ( $arrayofstripecard [ $src -> id ])) continue ; // Already in previous list
$nbremote ++ ;
2018-03-13 17:32:49 +01:00
print '<tr class="oddeven">' ;
2018-03-13 22:43:50 +01:00
// Local ID
if ( ! empty ( $conf -> global -> STRIPE_ALLOW_LOCAL_CARD ))
{
print '<td>' ;
print '</td>' ;
}
2018-10-16 19:49:16 +02:00
// Src ID
2018-03-13 17:32:49 +01:00
print '<td>' ;
2018-10-16 19:49:16 +02:00
if ( ! empty ( $stripeacc )) $connect = $stripeacc . '/' ;
$url = 'https://dashboard.stripe.com/' . $connect . 'test/sources/' . $src -> id ;
if ( $servicestatus )
{
$url = 'https://dashboard.stripe.com/' . $connect . 'sources/' . $src -> id ;
}
2018-10-16 20:00:53 +02:00
print $src -> id . " <a href=' " . $url . " ' target='_stripe'> " . img_picto ( $langs -> trans ( 'ShowInStripe' ), 'object_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>' ;
if ( $src -> object == 'card' )
{
2018-03-13 22:43:50 +01:00
print img_credit_card ( $src -> brand );
2018-03-07 16:17:25 +01:00
}
elseif ( $src -> object == 'source' && $src -> type == 'card' )
{
2018-03-13 22:43:50 +01:00
print img_credit_card ( $src -> card -> brand );
2018-03-07 16:17:25 +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>' ;
2018-03-07 16:17:25 +01:00
}
2018-10-16 19:49:16 +02:00
print '</td>' ;
print '<td valign="middle">' ;
2018-03-07 16:17:25 +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>' ;
if ( $src -> country )
{
$img = picto_from_langcode ( $src -> country );
print $img ? $img . ' ' : '' ;
print getCountry ( $src -> country , 1 );
}
else print img_warning () . ' <font class="error">' . $langs -> trans ( " ErrorFieldRequired " , $langs -> transnoentitiesnoconv ( " CompanyCountry " )) . '</font>' ;
}
elseif ( $src -> object == 'source' && $src -> type == 'card' )
{
2018-03-14 17:15:31 +01:00
print $src -> owner -> name . '<br>....' . $src -> card -> last4 . ' - ' . $src -> card -> exp_month . '/' . $src -> card -> exp_year . '' ;
2018-03-07 16:17:25 +01:00
print '</td><td>' ;
if ( $src -> card -> country )
{
$img = picto_from_langcode ( $src -> card -> country );
print $img ? $img . ' ' : '' ;
print getCountry ( $src -> card -> country , 1 );
}
else print img_warning () . ' <font class="error">' . $langs -> trans ( " ErrorFieldRequired " , $langs -> transnoentitiesnoconv ( " CompanyCountry " )) . '</font>' ;
}
elseif ( $src -> object == 'source' && $src -> type == 'sepa_debit' )
{
print 'info sepa' ;
print '</td><td>' ;
if ( $src -> sepa_debit -> country )
{
$img = picto_from_langcode ( $src -> sepa_debit -> country );
print $img ? $img . ' ' : '' ;
print getCountry ( $src -> sepa_debit -> country , 1 );
}
else print img_warning () . ' <font class="error">' . $langs -> trans ( " ErrorFieldRequired " , $langs -> transnoentitiesnoconv ( " CompanyCountry " )) . '</font>' ;
}
print '</td>' ;
// Default
print '<td align="center" width="50">' ;
2018-03-13 17:32:49 +01:00
if (( $customerstripe -> default_source != $src -> id ))
2018-03-07 16:17:25 +01:00
{
2018-03-13 22:54:28 +01:00
print '<a href="' . DOL_URL_ROOT . '/societe/paymentmodes.php?socid=' . $object -> id . '&source=' . $src -> id . '&action=setassourcedefault">' ;
print img_picto ( $langs -> trans ( " Default " ), 'off' );
print '</a>' ;
2018-03-07 16:17:25 +01:00
} else {
2018-03-13 17:32:49 +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>' ;
2018-03-14 20:08:44 +01:00
print '<td align="right" class="nowraponall">' ;
2018-03-07 16:17:25 +01:00
if ( $user -> rights -> societe -> creer )
{
2018-03-13 22:43:50 +01:00
print '<a href="' . DOL_URL_ROOT . '/societe/paymentmodes.php?socid=' . $object -> id . '&source=' . $src -> id . '&action=deletecard">' ;
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
if ( $nbremote == 0 && $nblocal == 0 )
2018-03-07 16:17:25 +01:00
{
2018-03-13 22:43:50 +01:00
print '<tr><td class="opacitymedium" colspan="7">' . $langs -> trans ( " None " ) . '</td></tr>' ;
2018-03-07 16:17:25 +01:00
}
print " </table> " ;
2018-03-13 15:19:31 +01:00
print " </div> " ;
2018-03-07 16:17:25 +01:00
}
// List of bank accounts
2018-03-13 17:32:49 +01:00
print '<br>' ;
2018-03-07 16:17:25 +01:00
2018-04-24 11:12:12 +02:00
$morehtmlright = '<a class="butActionNew" href="' . $_SERVER [ " PHP_SELF " ] . '?socid=' . $object -> id . '&action=create">' . $langs -> trans ( " Add " ) . ' <span class="fa fa-plus-circle valignmiddle"></span></a>' ;
2018-03-07 16:17:25 +01:00
2018-03-13 17:52:15 +01:00
print load_fiche_titre ( $langs -> trans ( " BankAccounts " ), $morehtmlright , '' );
2018-03-07 16:17:25 +01:00
$rib_list = $object -> get_all_rib ();
if ( is_array ( $rib_list ))
{
2018-03-13 15:19:31 +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
2018-03-07 16:17:25 +01:00
print '<table class="liste" width="100%">' ;
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 " );
if ( ! empty ( $conf -> prelevement -> enabled ))
{
print print_liste_field_titre ( " RUM " );
print print_liste_field_titre ( " WithdrawMode " );
}
print_liste_field_titre ( " DefaultRIB " , '' , '' , '' , '' , 'align="center"' );
print_liste_field_titre ( '' , '' , '' , '' , '' , 'align="center"' );
print_liste_field_titre ( '' , $_SERVER [ " PHP_SELF " ], " " , '' , '' , '' , $sortfield , $sortorder , 'maxwidthsearch ' );
print " </tr> \n " ;
foreach ( $rib_list as $rib )
{
print '<tr class="oddeven">' ;
// Label
print '<td>' . $rib -> label . '</td>' ;
// Bank name
print '<td>' . $rib -> bank . '</td>' ;
// Account number
print '<td>' ;
$string = '' ;
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 . ' ' ;
/* Already output after
} elseif ( $val == 'BIC' ) {
$string .= $rib -> bic . ' ' ;
} elseif ( $val == 'IBAN' ) {
$string .= $rib -> iban . ' ' ; */
}
}
if ( ! empty ( $rib -> label ) && $rib -> number ) {
if ( ! checkBanForAccount ( $rib )) {
$string .= ' ' . img_picto ( $langs -> trans ( " ValueIsNotValid " ), 'warning' );
} else {
$string .= ' ' . img_picto ( $langs -> trans ( " ValueIsValid " ), 'info' );
}
}
print $string ;
print '</td>' ;
// IBAN
print '<td>' . $rib -> iban ;
if ( ! empty ( $rib -> iban )) {
if ( ! checkIbanForAccount ( $rib )) {
print ' ' . img_picto ( $langs -> trans ( " IbanNotValid " ), 'warning' );
} else {
print ' ' . img_picto ( $langs -> trans ( " IbanValid " ), 'info' );
}
}
print '</td>' ;
// BIC
print '<td>' . $rib -> bic ;
if ( ! empty ( $rib -> bic )) {
if ( ! checkSwiftForAccount ( $rib )) {
print ' ' . img_picto ( $langs -> trans ( " SwiftNotValid " ), 'warning' );
} else {
print ' ' . img_picto ( $langs -> trans ( " SwiftValid " ), 'info' );
}
}
print '</td>' ;
if ( ! empty ( $conf -> prelevement -> enabled ))
{
// RUM
//print '<td>'.$prelevement->buildRumNumber($object->code_client, $rib->datec, $rib->id).'</td>';
print '<td>' . $rib -> rum . '</td>' ;
// FRSTRECUR
print '<td>' . $rib -> frstrecur . '</td>' ;
}
// Default
print '<td align="center" width="70">' ;
if ( ! $rib -> default_rib ) {
2018-03-08 22:26:42 +01:00
print '<a href="' . $_SERVER [ " PHP_SELF " ] . '?socid=' . $object -> id . '&ribid=' . $rib -> id . '&action=setasbankdefault">' ;
2018-03-07 16:17:25 +01:00
print img_picto ( $langs -> trans ( " Disabled " ), 'off' );
print '</a>' ;
} else {
print img_picto ( $langs -> trans ( " Enabled " ), 'on' );
}
print '</td>' ;
// Generate doc
print '<td align="center">' ;
$buttonlabel = $langs -> trans ( " BuildDoc " );
$forname = 'builddocrib' . $rib -> id ;
include_once DOL_DOCUMENT_ROOT . '/core/modules/bank/modules_bank.php' ;
$modellist = ModeleBankAccountDoc :: liste_modeles ( $db );
$out = '' ;
if ( is_array ( $modellist ) && count ( $modellist ))
{
$out .= '<form action="' . $urlsource . ( empty ( $conf -> global -> MAIN_JUMP_TAG ) ? '' : '#builddoc' ) . '" name="' . $forname . '" id="' . $forname . '_form" method="post">' ;
$out .= '<input type="hidden" name="action" value="builddocrib">' ;
$out .= '<input type="hidden" name="token" value="' . $_SESSION [ 'newtoken' ] . '">' ;
$out .= '<input type="hidden" name="socid" value="' . $object -> id . '">' ;
$out .= '<input type="hidden" name="companybankid" value="' . $rib -> id . '">' ;
if ( is_array ( $modellist ) && count ( $modellist ) == 1 ) // If there is only one element
{
$arraykeys = array_keys ( $modellist );
$modelselected = $arraykeys [ 0 ];
}
if ( ! empty ( $conf -> global -> BANKADDON_PDF )) $modelselected = $conf -> global -> BANKADDON_PDF ;
$out .= $form -> selectarray ( 'modelrib' . $rib -> id , $modellist , $modelselected , $showempty , 0 , 0 , '' , 0 , 0 , 0 , '' , 'minwidth100' );
$out .= ajax_combobox ( 'modelrib' . $rib -> id );
// Language code (if multilang)
if ( $conf -> global -> MAIN_MULTILANGS )
{
include_once DOL_DOCUMENT_ROOT . '/core/class/html.formadmin.class.php' ;
$formadmin = new FormAdmin ( $db );
$defaultlang = $codelang ? $codelang : $langs -> getDefaultLang ();
$morecss = 'maxwidth150' ;
2018-09-02 16:45:03 +02:00
if ( $conf -> browser -> layout == 'phone' ) $morecss = 'maxwidth100' ;
2018-03-07 16:17:25 +01:00
$out .= $formadmin -> select_language ( $defaultlang , 'lang_idrib' . $rib -> id , 0 , 0 , 0 , 0 , 0 , $morecss );
}
// Button
$genbutton = '<input class="button buttongen" id="' . $forname . '_generatebutton" name="' . $forname . '_generatebutton"' ;
$genbutton .= ' type="submit" value="' . $buttonlabel . '"' ;
if ( ! $allowgenifempty && ! is_array ( $modellist ) && empty ( $modellist )) $genbutton .= ' disabled' ;
$genbutton .= '>' ;
if ( $allowgenifempty && ! is_array ( $modellist ) && empty ( $modellist ) && empty ( $conf -> dol_no_mouse_hover ) && $modulepart != 'unpaid' )
{
$langs -> load ( " errors " );
$genbutton .= ' ' . img_warning ( $langs -> transnoentitiesnoconv ( " WarningNoDocumentModelActivated " ));
}
if ( ! $allowgenifempty && ! is_array ( $modellist ) && empty ( $modellist ) && empty ( $conf -> dol_no_mouse_hover ) && $modulepart != 'unpaid' ) $genbutton = '' ;
if ( empty ( $modellist ) && ! $showempty && $modulepart != 'unpaid' ) $genbutton = '' ;
$out .= $genbutton ;
$out .= '</form>' ;
}
print $out ;
print '</td>' ;
// Edit/Delete
2018-03-14 20:08:44 +01:00
print '<td align="right" class="nowraponall">' ;
2018-03-07 16:17:25 +01:00
if ( $user -> rights -> societe -> creer )
{
2018-03-08 22:26:42 +01:00
print '<a href="' . $_SERVER [ " PHP_SELF " ] . '?socid=' . $object -> id . '&id=' . $rib -> id . '&action=edit">' ;
2018-03-07 16:17:25 +01:00
print img_picto ( $langs -> trans ( " Modify " ), 'edit' );
print '</a>' ;
print ' ' ;
2018-03-08 22:26:42 +01:00
print '<a href="' . $_SERVER [ " PHP_SELF " ] . '?socid=' . $object -> id . '&id=' . $rib -> id . '&action=delete">' ;
2018-03-07 16:17:25 +01:00
print img_picto ( $langs -> trans ( " Delete " ), 'delete' );
print '</a>' ;
}
print '</td>' ;
print '</tr>' ;
}
if ( count ( $rib_list ) == 0 )
{
$colspan = 8 ;
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 );
}
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
/*
* Documents generes
*/
$filedir = $conf -> societe -> multidir_output [ $object -> entity ] . '/' . $object -> id ;
$urlsource = $_SERVER [ " PHP_SELF " ] . " ?socid= " . $object -> id ;
$genallowed = $user -> rights -> societe -> lire ;
$delallowed = $user -> rights -> societe -> creer ;
print $formfile -> showdocuments ( 'company' , $object -> id , $filedir , $urlsource , $genallowed , $delallowed , $object -> modelpdf , 0 , 0 , 0 , 28 , 0 , 'entity=' . $object -> entity , 0 , '' , $object -> default_lang );
2018-04-20 14:50:11 +02:00
// Show direct download link
if ( ! empty ( $conf -> global -> BANK_ACCOUNT_ALLOW_EXTERNAL_DOWNLOAD ))
{
$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 );
if ( $result > 0 )
{
$companybankaccounttemp -> last_main_doc = $ecmfile -> filepath . '/' . $ecmfile -> filename ;
print '<br><!-- Link to download main doc -->' . " \n " ;
print showDirectDownloadLink ( $companybankaccounttemp ) . '<br>' ;
}
}
2018-03-07 16:17:25 +01:00
print '</div><div class="fichehalfright"><div class="ficheaddleft">' ;
print '</div></div></div>' ;
print '<br>' ;
}
/*
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-14 11:51:13 +01:00
// Edit BAN
2018-03-07 16:17:25 +01:00
if ( $socid && $action == 'edit' && $user -> rights -> societe -> creer )
{
dol_fiche_head ( $head , 'rib' , $langs -> trans ( " ThirdParty " ), 0 , 'company' );
$linkback = '<a href="' . DOL_URL_ROOT . '/societe/list.php">' . $langs -> trans ( " BackToList " ) . '</a>' ;
dol_banner_tab ( $object , 'socid' , $linkback , ( $user -> societe_id ? 0 : 1 ), 'rowid' , 'nom' );
print '<div class="fichecenter">' ;
print '<div class="underbanner clearboth"></div>' ;
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 ) {
2018-03-07 16:17:25 +01:00
$require = false ;
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 ;
if ( $companybankaccount -> needIBAN ()) $require = true ;
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 ;
if ( $companybankaccount -> needIBAN ()) $require = true ;
2018-03-07 16:17:25 +01:00
}
print '<tr><td' . ( $require ? ' class="fieldrequired" ' : '' ) . '>' . $langs -> trans ( $val ) . '</td>' ;
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>' ;
if ( $conf -> prelevement -> enabled )
{
print '<br>' ;
print '<table class="border" width="100%">' ;
2018-03-14 13:56:21 +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
print '<tr><td>' . $langs -> trans ( " WithdrawMode " ) . '</td><td>' ;
$tblArraychoice = array ( " FRST " => $langs -> trans ( " FRST " ), " RECUR " => $langs -> trans ( " RECUR " ));
2018-03-14 13:56:21 +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>' ;
}
print '</div>' ;
dol_fiche_end ();
print '<div align="center">' ;
print '<input class="button" value="' . $langs -> trans ( " Modify " ) . '" type="submit">' ;
print ' ' ;
print '<input class="button" name="cancel" value="' . $langs -> trans ( " Cancel " ) . '" type="submit">' ;
print '</div>' ;
}
2018-03-14 13:56:21 +01:00
// Edit Card
if ( $socid && $action == 'editcard' && $user -> rights -> societe -> creer )
{
dol_fiche_head ( $head , 'rib' , $langs -> trans ( " ThirdParty " ), 0 , 'company' );
$linkback = '<a href="' . DOL_URL_ROOT . '/societe/list.php">' . $langs -> trans ( " BackToList " ) . '</a>' ;
dol_banner_tab ( $object , 'socid' , $linkback , ( $user -> societe_id ? 0 : 1 ), 'rowid' , 'nom' );
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>' ;
print '<tr><td class="fieldrequired">' . $langs -> trans ( " CardNumber " ) . '</td>' ;
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>' ;
print '<tr><td class="fieldrequired">' . $langs -> trans ( " CVN " ) . '</td>' ;
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>' ;
dol_fiche_end ();
print '<div align="center">' ;
print '<input class="button" value="' . $langs -> trans ( " Modify " ) . '" type="submit">' ;
print ' ' ;
print '<input class="button" name="cancel" value="' . $langs -> trans ( " Cancel " ) . '" type="submit">' ;
print '</div>' ;
}
2018-03-07 16:17:25 +01:00
2018-03-14 11:51:13 +01:00
// Create BAN
2018-03-07 16:17:25 +01:00
if ( $socid && $action == 'create' && $user -> rights -> societe -> creer )
{
dol_fiche_head ( $head , 'rib' , $langs -> trans ( " ThirdParty " ), 0 , 'company' );
$linkback = '<a href="' . DOL_URL_ROOT . '/societe/list.php">' . $langs -> trans ( " BackToList " ) . '</a>' ;
dol_banner_tab ( $object , 'socid' , $linkback , ( $user -> societe_id ? 0 : 1 ), 'rowid' , 'nom' );
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 ) {
2018-03-07 16:17:25 +01:00
$require = false ;
if ( $val == 'BankCode' ) {
$name = 'code_banque' ;
$size = 8 ;
} elseif ( $val == 'DeskCode' ) {
$name = 'code_guichet' ;
$size = 8 ;
} elseif ( $val == 'BankAccountNumber' ) {
$name = 'number' ;
$size = 18 ;
} elseif ( $val == 'BankAccountNumberKey' ) {
$name = 'cle_rib' ;
$size = 3 ;
} elseif ( $val == 'IBAN' ) {
$name = 'iban' ;
$size = 30 ;
2018-03-14 13:56:21 +01:00
if ( $companybankaccount -> needIBAN ()) $require = true ;
2018-03-07 16:17:25 +01:00
} elseif ( $val == 'BIC' ) {
$name = 'bic' ;
$size = 12 ;
2018-03-14 13:56:21 +01:00
if ( $companybankaccount -> needIBAN ()) $require = true ;
2018-03-07 16:17:25 +01:00
}
print '<tr><td' . ( $require ? ' class="fieldrequired" ' : '' ) . '>' . $langs -> trans ( $val ) . '</td>' ;
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>' ;
if ( $conf -> prelevement -> enabled )
{
print '<br>' ;
print '<table class="border" width="100%">' ;
// RUM
print '<tr><td class="titlefieldcreate">' . $langs -> trans ( " RUM " ) . '</td>' ;
2018-03-12 15:59:03 +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
print '<tr><td>' . $langs -> trans ( " WithdrawMode " ) . '</td><td>' ;
$tblArraychoice = array ( " FRST " => $langs -> trans ( " FRST " ), " RECUR " => $langs -> trans ( " RECUR " ));
print $form -> selectarray ( " frstrecur " , $tblArraychoice , ( isset ( $_POST [ 'frstrecur' ]) ? GETPOST ( 'frstrecur' ) : 'FRST' ), 0 );
print '</td></tr>' ;
print '</table>' ;
}
print '</div>' ;
dol_fiche_end ();
2018-03-14 11:51:13 +01:00
dol_set_focus ( '#label' );
print '<div class="center">' ;
print '<input class="button" value="' . $langs -> trans ( " Add " ) . '" type="submit">' ;
print ' ' ;
print '<input name="cancel" class="button" value="' . $langs -> trans ( " Cancel " ) . '" type="submit">' ;
print '</div>' ;
}
// Create Card
if ( $socid && $action == 'createcard' && $user -> rights -> societe -> creer )
{
dol_fiche_head ( $head , 'rib' , $langs -> trans ( " ThirdParty " ), 0 , 'company' );
$linkback = '<a href="' . DOL_URL_ROOT . '/societe/list.php">' . $langs -> trans ( " BackToList " ) . '</a>' ;
dol_banner_tab ( $object , 'socid' , $linkback , ( $user -> societe_id ? 0 : 1 ), 'rowid' , 'nom' );
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>' ;
2018-03-14 13:56:21 +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>' ;
2018-03-14 13:56:21 +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
print '<tr><td class="fieldrequired">' . $langs -> trans ( " CardNumber " ) . '</td>' ;
2018-03-14 13:56:21 +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>' ;
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' );
print '</td></tr>' ;
print '<tr><td class="fieldrequired">' . $langs -> trans ( " CVN " ) . '</td>' ;
print '<td><input size="8" type="text" name="cvn" value="' . GETPOST ( 'cvn' , 'alpha' ) . '"></td></tr>' ;
2018-03-14 13:56:21 +01:00
print '<tr><td>' . $langs -> trans ( " StripeID " ) . " ('card_....')</td> " ;
print '<td><input class="minwidth300" type="text" name="stripe_card_ref" value="' . GETPOST ( 'stripe_card_ref' , 'alpha' ) . '"></td></tr>' ;
2018-03-14 11:51:13 +01:00
print '</table>' ;
print '</div>' ;
dol_fiche_end ();
dol_set_focus ( '#label' );
2018-03-07 16:17:25 +01:00
print '<div class="center">' ;
print '<input class="button" value="' . $langs -> trans ( " Add " ) . '" type="submit">' ;
print ' ' ;
print '<input name="cancel" class="button" value="' . $langs -> trans ( " Cancel " ) . '" type="submit">' ;
print '</div>' ;
}
2018-03-14 13:56:21 +01:00
if ( $socid && ( $action == 'edit' || $action == 'editcard' ) && $user -> rights -> societe -> creer )
2018-03-07 16:17:25 +01:00
{
print '</form>' ;
}
2018-03-14 11:51:13 +01:00
if ( $socid && ( $action == 'create' || $action == 'createcard' ) && $user -> rights -> societe -> creer )
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 ();