From 39749a0a2ce890022277b725b46b2fa9eba9e3af Mon Sep 17 00:00:00 2001 From: ptibogxiv Date: Wed, 7 Mar 2018 16:13:49 +0100 Subject: [PATCH 01/10] NEW function and update comment --- htdocs/stripe/admin/stripe.php | 61 +++++++++++++++++----------------- 1 file changed, 30 insertions(+), 31 deletions(-) diff --git a/htdocs/stripe/admin/stripe.php b/htdocs/stripe/admin/stripe.php index 544764b4c11..7a418a695dc 100644 --- a/htdocs/stripe/admin/stripe.php +++ b/htdocs/stripe/admin/stripe.php @@ -49,26 +49,26 @@ if ($action == 'setvalue' && $user->admin) $result=dolibarr_set_const($db, "STRIPE_LIVE",GETPOST('STRIPE_LIVE','alpha'),'chaine',0,'',$conf->entity); if (! $result > 0) $error++; -if (empty($conf->stripeconnect->enabled)) { +if (empty($conf->stripeconnect->enabled)) { $result=dolibarr_set_const($db, "STRIPE_TEST_PUBLISHABLE_KEY",GETPOST('STRIPE_TEST_PUBLISHABLE_KEY','alpha'),'chaine',0,'',$conf->entity); if (! $result > 0) $error++; $result=dolibarr_set_const($db, "STRIPE_TEST_SECRET_KEY",GETPOST('STRIPE_TEST_SECRET_KEY','alpha'),'chaine',0,'',$conf->entity); if (! $result > 0) $error++; $result=dolibarr_set_const($db, "STRIPE_TEST_WEBHOOK_KEY",GETPOST('STRIPE_TEST_WEBHOOK_KEY','alpha'),'chaine',0,'',$conf->entity); - if (! $result > 0) $error++; + if (! $result > 0) $error++; $result=dolibarr_set_const($db, "STRIPE_LIVE_PUBLISHABLE_KEY",GETPOST('STRIPE_LIVE_PUBLISHABLE_KEY','alpha'),'chaine',0,'',$conf->entity); if (! $result > 0) $error++; $result=dolibarr_set_const($db, "STRIPE_LIVE_SECRET_KEY",GETPOST('STRIPE_LIVE_SECRET_KEY','alpha'),'chaine',0,'',$conf->entity); if (! $result > 0) $error++; $result=dolibarr_set_const($db, "STRIPE_LIVE_WEBHOOK_KEY",GETPOST('STRIPE_LIVE_WEBHOOK_KEY','alpha'),'chaine',0,'',$conf->entity); - if (! $result > 0) $error++; -} + if (! $result > 0) $error++; +} $result=dolibarr_set_const($db, "ONLINE_PAYMENT_CREDITOR",GETPOST('ONLINE_PAYMENT_CREDITOR','alpha'),'chaine',0,'',$conf->entity); if (! $result > 0) $error++; $result=dolibarr_set_const($db, "STRIPE_BANK_ACCOUNT_FOR_PAYMENTS",GETPOST('STRIPE_BANK_ACCOUNT_FOR_PAYMENTS','int'),'chaine',0,'',$conf->entity); if (! $result > 0) $error++; $result=dolibarr_set_const($db, "STRIPE_BANK_ACCOUNT_FOR_BANKTRANSFERS",GETPOST('STRIPE_BANK_ACCOUNT_FOR_BANKTRANSFERS','int'),'chaine',0,'',$conf->entity); - if (! $result > 0) $error++; + if (! $result > 0) $error++; $result=dolibarr_set_const($db, "ONLINE_PAYMENT_CSS_URL",GETPOST('ONLINE_PAYMENT_CSS_URL','alpha'),'chaine',0,'',$conf->entity); if (! $result > 0) $error++; $result=dolibarr_set_const($db, "ONLINE_PAYMENT_MESSAGE_FORM",GETPOST('ONLINE_PAYMENT_MESSAGE_FORM','alpha'),'chaine',0,'',$conf->entity); @@ -114,7 +114,7 @@ if ($action=="setlive") setEventMessages($langs->trans("Error"), null, 'errors'); } } - +//TODO: import script for stripe account saving in alone or connect mode for stripe.class.php /* * View @@ -180,10 +180,10 @@ print ''; print ''.$langs->trans("STRIPE_TEST_SECRET_KEY").''; print ''; print '   '.$langs->trans("Example").': sk_test_xxxxxxxxxxxxxxxxxxxxxxxx'; -print ''; +print ''; print ''; -print ''.$langs->trans("STRIPE_TEST_WEBHOOK_KEY").''; +print ''.$langs->trans("STRIPE_TEST_WEBHOOK_KEY").''; print ''; print '   '.$langs->trans("Example").': whsec_xxxxxxxxxxxxxxxxxxxxxxxx'; print ''; @@ -201,32 +201,36 @@ print '   '.$langs->trans("Example").': sk_live_xxxxxxxxxxxxxxxxxxxxxxxx'; print ''; print ''; -print ''.$langs->trans("STRIPE_LIVE_WEBHOOK_KEY").''; +print ''.$langs->trans("STRIPE_LIVE_WEBHOOK_KEY").''; print ''; print '   '.$langs->trans("Example").': whsec_xxxxxxxxxxxxxxxxxxxxxxxx'; print ''; } else { -print ''.$langs->trans("STRIPECONNECT").''; -print 'Ce module est configuré en mode marketplace'; +print ''.$langs->trans("StripeConnect").''; +print ''.$langs->trans("StripeConnect_Mode").''; } -if (! empty($conf->banque->enabled)) +if (! empty($conf->banque->enabled)) //deplace here for separate stripe setting of general and common online payment settings { -print ''; -print $langs->trans("BankAccount").''; -print $form->select_comptes($conf->global->STRIPE_BANK_ACCOUNT_FOR_PAYMENTS, 'STRIPE_BANK_ACCOUNT_FOR_PAYMENTS', 0, '', 1); -print ''; - -print ''; -print $langs->trans("BankAccount").''; -print $form->select_comptes($conf->global->STRIPE_BANK_ACCOUNT_FOR_BANKTRANSFERS, 'STRIPE_BANK_ACCOUNT_FOR_BANKTRANSFERS', 0, '', 1); -print ''; + print ''; + print $langs->trans("BankAccount").''; + print $form->select_comptes($conf->global->STRIPE_BANK_ACCOUNT_FOR_PAYMENTS, 'STRIPE_BANK_ACCOUNT_FOR_PAYMENTS', 0, '', 1); + print ''; + + if ($conf->global->MAIN_FEATURES_LEVEL >= 2) // real bank account : automatic banktransfert with stripe webhook from stripe account (receiving funds, payment, debit fee/application fee, payment dispute) to real bank account + { + print ''; + print $langs->trans("BankAccountForBankTransfer").''; + print $form->select_comptes($conf->global->STRIPE_BANK_ACCOUNT_FOR_BANKTRANSFERS, 'STRIPE_BANK_ACCOUNT_FOR_BANKTRANSFERS', 0, '', 1); + print ''; + } } print ''; print '
'; + print ''; print ''; print ''; @@ -239,11 +243,12 @@ print 'name; print ''; -if (! empty($conf->banque->enabled)) +if ($conf->global->MAIN_FEATURES_LEVEL >= 2) // autodecrement selected web stock when generate invoice or paid an order->generate linked invoice as in a POS module for a full automatic functionality (useful when there is a lot of payment) { + // Stock for automatic decrement print ''; } @@ -275,13 +280,7 @@ print ''; - -// stock for automatic decrement -print ''; +print ''; // Payment token for URL print '\n"; -$list=\Stripe\Charge::all(array("limit" => $limit),array("stripe_account" => $stripeconnect->GetStripeAccount($conf->entity))); +$list=\Stripe\Charge::all(array("limit" => $limit),array("stripe_account" => $stripe->GetStripeAccount($conf->entity))); //print $list; foreach ($list->data as $charge) { print ''; @@ -131,7 +131,10 @@ $label.="Statut: ".$langs->trans("".$charge->outcome->seller_message.""); print "\n"; // Type print '\n"; -$txn=\Stripe\BalanceTransaction::all(array("limit" => $limit), array("stripe_account" => $stripeconnect->GetStripeAccount($conf->entity))); +$txn=\Stripe\BalanceTransaction::all(array("limit" => $limit), array("stripe_account" => $stripe->GetStripeAccount($conf->entity))); foreach ($txn->data as $txn) { print ''; $societestatic->fetch($charge->metadata->idcustomer); @@ -119,16 +119,7 @@ $object->fetch($txn->metadata->idsource); print '\n"; // Label payment print "\n"; // Type print ''; From a0b587acc0766502a53031e3d83c916bcc3a1c26 Mon Sep 17 00:00:00 2001 From: ptibogxiv Date: Wed, 7 Mar 2018 20:04:13 +0100 Subject: [PATCH 05/10] NEW introduce stripe.class.php TODO: more powerful saving infos ? --- htdocs/stripe/class/stripe.class.php | 320 +++++++++++++++++++++++++++ 1 file changed, 320 insertions(+) create mode 100644 htdocs/stripe/class/stripe.class.php diff --git a/htdocs/stripe/class/stripe.class.php b/htdocs/stripe/class/stripe.class.php new file mode 100644 index 00000000000..c3fded06264 --- /dev/null +++ b/htdocs/stripe/class/stripe.class.php @@ -0,0 +1,320 @@ + + * + * 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 . + */ + +// Put here all includes required by your class file +require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php'; +require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php'; +require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php'; +require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php'; +require_once DOL_DOCUMENT_ROOT.'/stripe/config.php'; +/** + * \class Rewards + * \brief Class for Rewards + */ +class Stripe extends CommonObject +{ + public $rowid; + public $fk_soc; + public $fk_key; + public $id; + public $mode; + public $entity; + public $statut; + public $type; + public $code; + public $message; + + /** + * Constructor + * + * @param DoliDB $db Database handler + */ + public function __construct($db) + { + $this->db = $db; + + } + + +public function GetStripeAccount($id) // TODO: move /transforme optimize function/data + { + global $conf; + + $sql = "SELECT key_account"; + $sql.= " FROM ".MAIN_DB_PREFIX."stripe_entity"; + $sql.= " WHERE entity = ".$id.""; + + dol_syslog(get_class($this) . "::fetch", LOG_DEBUG); + $result = $this->db->query($sql); + if ($result) + { + if ($this->db->num_rows($result)) + { + $obj = $this->db->fetch_object($result); + $key=$obj->key_account; + } + else {$key=0;} + } + else {$key=0;} + +return $key; + } + +public function GetStripeCustomerAccount($id) + { + global $conf; + + $sql = "SELECT s.key_account as key_account, s.entity, e.fk_object"; + $sql.= " FROM ".MAIN_DB_PREFIX."stripe_entity as s"; + $sql.= " JOIN ".MAIN_DB_PREFIX."entity_extrafields as e ON s.entity=e.fk_object"; + $sql.= " WHERE e.fk_soc=".$id." "; + + dol_syslog(get_class($this) . "::fetch", LOG_DEBUG); + $result = $this->db->query($sql); + if ($result) + { + if ($this->db->num_rows($result)) + { + $obj = $this->db->fetch_object($result); + $key=$obj->key_account; + } + else {$key=NULL;} + } + else {$key=NULL;} + +return $key; + } + +public function CustomerStripe($id,$key) + { +global $conf; +if (empty($conf->global->STRIPECONNECT_LIVE)) +{ +$mode=0; +} +else +{ +if (empty($conf->global->STRIPE_LIVE)) +{ +$mode=0; +} +else +{ +$mode=$conf->global->STRIPE_LIVE; +} +} + $sql = "SELECT rowid,fk_soc,fk_key,mode,entity"; + $sql.= " FROM ".MAIN_DB_PREFIX."societe_stripe"; + $sql.= " WHERE fk_soc = ".$id." "; + $sql.= " AND mode=".$mode." AND entity IN (" . getEntity('stripe') . ")"; + + dol_syslog(get_class($this) . "::fetch", LOG_DEBUG); + $resql = $this->db->query($sql); + if ($resql) { + $soc = new Societe($this->db); + $soc->fetch($id); + $num=$this->db->num_rows($resql); + if ($num) { + $obj = $this->db->fetch_object($resql); + $tiers = $obj->fk_key; + if ($conf->entity==1){ + $customer = \Stripe\Customer::retrieve("$tiers"); + }else{ + $customer = \Stripe\Customer::retrieve("$tiers",array("stripe_account" => $key)); + }} + else { + if ($conf->entity==1){ + $customer = \Stripe\Customer::create(array( + "email" => $soc->email, + "description" => $soc->name + )); + }else{ + $customer = \Stripe\Customer::create(array( + "email" => $soc->email, + "description" => $soc->name + ), array("stripe_account" => $key)); + } + $customer_id = "".$customer->id.""; + $sql = "INSERT INTO ".MAIN_DB_PREFIX."societe_stripe (fk_soc,fk_key,mode,entity)"; + $sql .= " VALUES ($id,'$customer_id',".$mode.",".$conf->entity.")"; + dol_syslog(get_class($this) . "::create sql=" . $sql, LOG_DEBUG); + $resql = $this->db->query($sql); + }} +return $customer; + } + +public function CreatePaymentStripe($amount,$currency,$origin,$item,$source,$customer,$account) +{ +global $conf; +if (empty($conf->global->STRIPECONNECT_LIVE)) +{ +$mode=0; +} +else +{ +if (empty($conf->global->STRIPE_LIVE)) +{ +$mode=0; +} +else +{ +$mode=$conf->global->STRIPE_LIVE; +} +} + $sql = "SELECT fk_soc,fk_key,mode,entity"; + $sql.= " FROM ".MAIN_DB_PREFIX."societe_stripe"; + $sql.= " WHERE fk_key = '$customer' "; + $sql.= " AND mode=".$mode." "; + + dol_syslog(get_class($this) . "::fetch", LOG_DEBUG); + $result = $this->db->query($sql); + if ($result) + { + if ($this->db->num_rows($result)) + { + $obj = $this->db->fetch_object($result); + $entite=$obj->entity; + $fksoc=$obj->fk_soc; + } + } +$stripeamount=round($amount*100); +$societe = new Societe($this->db); +$societe->fetch($fksoc); + +if ($origin==order){ +$order=new Commande($this->db); +$order->fetch($item); +$ref=$order->ref; +$description="ORD=".$ref.".CUS=".$societe->code_client; +} +elseif ($origin==invoice) { +$invoice=new Facture($this->db); +$invoice->fetch($item); +$ref=$invoice->ref; +$description="INV=".$ref.".CUS=".$societe->code_client; +} + +$metadata = array( + "source" => "".$origin."", + "idsource" => "".$item."", + "idcustomer" => "".$societe->id."" + ); +$return = new StripeConnexion($this->db); +try { +if ($stripeamount>=100) { +if ($entite=='1' or empty($conf->stripeconnect->enabled)){ +if (preg_match('/acct_/i',$source)){ + $charge = \Stripe\Charge::create(array( + "amount" => "$stripeamount", + "currency" => "$currency", +// "statement_descriptor" => " ", + "metadata" => $metadata, + "source" => "$source" +) +); +} else { +$charge = \Stripe\Charge::create(array( + "amount" => "$stripeamount", + "currency" => "$currency", +// "statement_descriptor" => " ", + "description" => "$description", + "metadata" => $metadata, + "receipt_email" => $societe->email, + "source" => "$source", + "customer" => "$customer") + ,array("idempotency_key" => "$ref") +); +}}else{ +$fee=round(($amount*($conf->global->STRIPE_APPLICATION_FEE_PERCENT/100)+$conf->global->STRIPE_APPLICATION_FEE)*100); +if ($fee<($conf->global->STRIPE_APPLICATION_FEE_MINIMAL*100)){ +$fee=round($conf->global->STRIPE_APPLICATION_FEE_MINIMAL*100); +} +$charge = \Stripe\Charge::create(array( + "amount" => "$stripeamount", + "currency" => "$currency", +// "statement_descriptor" => " ", + "description" => "$description", + "metadata" => $metadata, + "source" => "$source", + "customer" => "$customer", + "application_fee" => "$fee" +), array("idempotency_key" => "$ref","stripe_account" => "$account")); +} +if (isset($charge->id)){ + +} +} + +$return->statut = 'success'; +$return->id = $charge->id; +if ($charge->source->type=='card'){ +$return->message = $charge->source->card->brand." ****".$charge->source->card->last4; +}elseif ($charge->source->type=='three_d_secure'){ +$stripeconnect=new StripeConnexion($this->db); +$src = \Stripe\Source::retrieve("".$charge->source->three_d_secure->card."",array("stripe_account" => $stripeconnect->GetStripeAccount($conf->entity))); +$return->message = $src->card->brand." ****".$src->card->last4; +}else { +$return->message = $charge->id; +} + +} catch(\Stripe\Error\Card $e) { + // Since it's a decline, \Stripe\Error\Card will be caught + $body = $e->getJsonBody(); + $err = $body['error']; + +$return->statut = 'error'; +$return->id = $err['charge']; +$return->type = $err['type']; +$return->code = $err['code']; +$return->message = $err['message']; +$body = "Une erreur de paiement est survenue. Voici le code d'erreur:
".$return->id." ".$return->message." "; +$subject = '[NOTIFICATION] Erreur de paiement'; +$headers = 'From: "ptibogxiv.net" <'.$conf->global->MAIN_INFO_SOCIETE_MAIL.'>'; +mail(''.$conf->global->MAIN_INFO_SOCIETE_MAIL.'', $subject, $body, $headers); + $error++; + dol_syslog($e->getMessage(), LOG_WARNING, 0, '_stripe'); + } catch (\Stripe\Error\RateLimit $e) { + // Too many requests made to the API too quickly + $error++; + dol_syslog($e->getMessage(), LOG_WARNING, 0, '_stripe'); + } catch (\Stripe\Error\InvalidRequest $e) { + // Invalid parameters were supplied to Stripe's API + $error++; + dol_syslog($e->getMessage(), LOG_WARNING, 0, '_stripe'); + } catch (\Stripe\Error\Authentication $e) { + // Authentication with Stripe's API failed + // (maybe you changed API keys recently) + $error++; + dol_syslog($e->getMessage(), LOG_WARNING, 0, '_stripe'); + } catch (\Stripe\Error\ApiConnection $e) { + // Network communication with Stripe failed + $error++; + dol_syslog($e->getMessage(), LOG_WARNING, 0, '_stripe'); + } catch (\Stripe\Error\Base $e) { + // Display a very generic error to the user, and maybe send + // yourself an email + $error++; + dol_syslog($e->getMessage(), LOG_WARNING, 0, '_stripe'); + } catch (Exception $e) { + // Something else happened, completely unrelated to Stripe + $error++; + dol_syslog($e->getMessage(), LOG_WARNING, 0, '_stripe'); + } + return $return; +} + +} From 197ce2fc3d3b240a6d1e7da82e25f874a125cd51 Mon Sep 17 00:00:00 2001 From: ptibogxiv Date: Thu, 8 Mar 2018 02:08:14 +0100 Subject: [PATCH 06/10] Fix set default --- htdocs/societe/paymentmodes.php | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/htdocs/societe/paymentmodes.php b/htdocs/societe/paymentmodes.php index 7f969f64e56..cbafeb68a09 100644 --- a/htdocs/societe/paymentmodes.php +++ b/htdocs/societe/paymentmodes.php @@ -272,13 +272,13 @@ if (empty($reshook)) } } - if ($action == 'setasdefault') + if ($action == 'setasbankdefault') { $account = new CompanyBankAccount($db); $res = $account->setAsDefault(GETPOST('ribid','int')); if ($res) { - $url=DOL_URL_ROOT.'/societe/gateway.php?socid='.$object->id; + $url=DOL_URL_ROOT.'/societe/paymentmodes.php?socid='.$object->id; header('Location: '.$url); exit; } @@ -337,19 +337,20 @@ if (class_exists('Stripe')) $stripe=new Stripe($db); $customerstripe=$stripe->CustomerStripe($socid,$stripe->GetStripeAccount($conf->entity)); if ($customerstripe->id) { - $cu = \Stripe\Customer::retrieve("".$customerstripe->id."",array("stripe_account" => $stripe->GetStripeAccount($conf->entity)));} + $cu = \Stripe\Customer::retrieve("".$customerstripe->id."");} + $url=DOL_URL_ROOT.'/societe/paymentmodes.php?socid='.$object->id; - if ($action == 'setasdefault') + if ($action == 'setassourcedefault') { $cu->default_source = "$source"; // obtained with Stripe.js $cu->save(); - - header('Location: '.$url); - exit; + + //header('Location: '.$url); + //exit; } elseif ($action == 'delete') { - $cu->sources->retrieve("$source")->delete(); + $cu->sources->retrieve("$source")->detach(); header('Location: '.$url); exit; @@ -365,8 +366,9 @@ $form = new Form($db); $formfile = new FormFile($db); llxHeader(); - + $head=societe_prepare_head($object); + if (! $id) { $account->fetch(0,$object->id); @@ -505,7 +507,7 @@ if ($socid && $action != 'edit' && $action != "create") print '
'.$langs->trans("UsageParameter").'
'; - print $langs->trans("BankAccount").''; - print $form->select_comptes($conf->global->STRIPE_BANK_ACCOUNT_FOR_PAYMENTS, 'STRIPE_BANK_ACCOUNT_FOR_PAYMENTS', 0, '', 1); + print $langs->trans("ONLINE_PAYMENT_WAREHOUSE").''; + print $formproduct->selectWarehouses($conf->global->ONLINE_PAYMENT_WAREHOUSE,'ONLINE_PAYMENT_WAREHOUSE','',1,$disabled); print '
'; print $langs->trans("ONLINE_PAYMENT_SENDEMAIL").''; print ''; print '   '.$langs->trans("Example").': myemail@myserver.com'; -print '
'; -print $langs->trans("ONLINE_PAYMENT_WAREHOUSE").''; -print $formproduct->selectWarehouses($conf->global->ONLINE_PAYMENT_WAREHOUSE,'ONLINE_PAYMENT_WAREHOUSE','',1,$disabled); -print '
'; From d791b014a5089833400f2c3eb2da390a6064ca03 Mon Sep 17 00:00:00 2001 From: ptibogxiv Date: Wed, 7 Mar 2018 16:17:25 +0100 Subject: [PATCH 02/10] update comment and class --- htdocs/societe/paymentmodes.php | 1006 +++++++++++++++++++++++++++++++ 1 file changed, 1006 insertions(+) create mode 100644 htdocs/societe/paymentmodes.php diff --git a/htdocs/societe/paymentmodes.php b/htdocs/societe/paymentmodes.php new file mode 100644 index 00000000000..7f969f64e56 --- /dev/null +++ b/htdocs/societe/paymentmodes.php @@ -0,0 +1,1006 @@ + + * Copyright (C) 2003 Jean-Louis Bergamo + * Copyright (C) 2004-2016 Laurent Destailleur + * Copyright (C) 2005-2009 Regis Houssin + * Copyright (C) 2013 Peter Fontaine + * Copyright (C) 2015-2016 Marcos García + * Copyright (C) 2017 Ferran Marcet + * Copyright (C) 2018 ptibogxiv + * + * 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 . + */ + +/** + * \file htdocs/societe/rib.php + * \ingroup societe + * \brief BAN tab for companies + */ + +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'; +require_once DOL_DOCUMENT_ROOT.'/societe/class/companybankaccount.class.php'; +require_once DOL_DOCUMENT_ROOT.'/compta/prelevement/class/bonprelevement.class.php'; +require_once DOL_DOCUMENT_ROOT.'/stripe/class/stripe.class.php'; + +$langs->load("companies"); +$langs->load("commercial"); +$langs->load("banks"); +$langs->load("bills"); + +// 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); + +$object = new Societe($db); +$object->fetch($socid); + +$account = new CompanyBankAccount($db); +$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')); + + +// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context +$hookmanager->initHooks(array('thirdpartybancard')); + + + +/* + * Actions + */ + +$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; + } + } + + + if ($action == 'update' && ! $_POST["cancel"]) + { + // Modification + if (! GETPOST('label')) + { + setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Label")), null, 'errors'); + $action='edit'; + $error++; + } + if (! GETPOST('bank')) + { + setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("BankName")), null, 'errors'); + $action='edit'; + $error++; + } + if ($account->needIBAN() == 1) + { + 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++; + } + } + + $account->fetch($id); + if (! $error) + { + $account->socid = $object->id; + + $account->bank = GETPOST('bank','alpha'); + $account->label = GETPOST('label','alpha'); + $account->courant = GETPOST('courant','alpha'); + $account->clos = GETPOST('clos','alpha'); + $account->code_banque = GETPOST('code_banque','alpha'); + $account->code_guichet = GETPOST('code_guichet','alpha'); + $account->number = GETPOST('number','alpha'); + $account->cle_rib = GETPOST('cle_rib','alpha'); + $account->bic = GETPOST('bic','alpha'); + $account->iban = GETPOST('iban','alpha'); + $account->domiciliation = GETPOST('domiciliation','alpha'); + $account->proprio = GETPOST('proprio','alpha'); + $account->owner_address = GETPOST('owner_address','alpha'); + $account->frstrecur = GETPOST('frstrecur','alpha'); + $account->rum = GETPOST('rum','alpha'); + if (empty($account->rum)) + { + $account->rum = $prelevement->buildRumNumber($object->code_client, $account->datec, $account->id); + $account->date_rum = dol_now(); + } + + $result = $account->update($user); + if (! $result) + { + setEventMessages($account->error, $account->errors, 'errors'); + } + else + { + // If this account is the default bank account, we disable others + if ($account->default_rib) + { + $account->setAsDefault($id); // This will make sure there is only one default rib + } + + $url=DOL_URL_ROOT.'/societe/rib.php?socid='.$object->id; + header('Location: '.$url); + exit; + } + } + } + + if ($action == 'add' && ! $_POST["cancel"]) + { + $error=0; + + if (! GETPOST('label')) + { + setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Label")), null, 'errors'); + $action='create'; + $error++; + } + if (! GETPOST('bank')) + { + setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("BankName")), null, 'errors'); + $action='create'; + $error++; + } + + if (! $error) + { + // Ajout + $account = new CompanyBankAccount($db); + + $account->socid = $object->id; + + $account->bank = GETPOST('bank','alpha'); + $account->label = GETPOST('label','alpha'); + $account->courant = GETPOST('courant','alpha'); + $account->clos = GETPOST('clos','alpha'); + $account->code_banque = GETPOST('code_banque','alpha'); + $account->code_guichet = GETPOST('code_guichet','alpha'); + $account->number = GETPOST('number','alpha'); + $account->cle_rib = GETPOST('cle_rib','alpha'); + $account->bic = GETPOST('bic','alpha'); + $account->iban = GETPOST('iban','alpha'); + $account->domiciliation = GETPOST('domiciliation','alpha'); + $account->proprio = GETPOST('proprio','alpha'); + $account->owner_address = GETPOST('owner_address','alpha'); + $account->frstrecur = GETPOST('frstrecur'); + $account->rum = GETPOST('rum','alpha'); + $account->datec = dol_now(); + + $db->begin(); + + // This test can be done only once properties were set + if ($account->needIBAN() == 1) + { + 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) + { + $result = $account->create($user); + if ($result < 0) + { + $error++; + setEventMessages($account->error, $account->errors, 'errors'); + $action='create'; // Force chargement page création + } + + if (empty($account->rum)) + { + $account->rum = $prelevement->buildRumNumber($object->code_client, $account->datec, $account->id); + $account->date_rum = dol_now(); + } + } + + if (! $error) + { + $result = $account->update($user); // This will set the UMR number. + if ($result < 0) + { + $error++; + setEventMessages($account->error, $account->errors, 'errors'); + $action='create'; + } + } + + if (! $error) + { + $db->commit(); + + $url=DOL_URL_ROOT.'/societe/rib.php?socid='.$object->id; + header('Location: '.$url); + exit; + } + else + { + $db->rollback(); + } + } + } + + if ($action == 'setasdefault') + { + $account = new CompanyBankAccount($db); + $res = $account->setAsDefault(GETPOST('ribid','int')); + if ($res) + { + $url=DOL_URL_ROOT.'/societe/gateway.php?socid='.$object->id; + header('Location: '.$url); + exit; + } + else + { + setEventMessages($db->lasterror, null, 'errors'); + } + } + + if ($action == 'confirm_delete' && $_GET['confirm'] == 'yes') + { + $account = new CompanyBankAccount($db); + if ($account->fetch($ribid?$ribid:$id)) + { + $result = $account->delete($user); + if ($result > 0) + { + $url = $_SERVER['PHP_SELF']."?socid=".$object->id; + header('Location: '.$url); + exit; + } + else + { + setEventMessages($account->error, $account->errors, 'errors'); + } + } + else + { + setEventMessages($account->error, $account->errors, 'errors'); + } + } + + $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) + ); + $_POST['lang_id'] = GETPOST('lang_idrib'.GETPOST('companybankid')); + $_POST['model'] = GETPOST('modelrib'.GETPOST('companybankid')); + } + $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; +} + +if (class_exists('Stripe')) +{ + $stripe=new Stripe($db); + $customerstripe=$stripe->CustomerStripe($socid,$stripe->GetStripeAccount($conf->entity)); + if ($customerstripe->id) { + $cu = \Stripe\Customer::retrieve("".$customerstripe->id."",array("stripe_account" => $stripe->GetStripeAccount($conf->entity)));} + $url=DOL_URL_ROOT.'/societe/paymentmodes.php?socid='.$object->id; + if ($action == 'setasdefault') + { + $cu->default_source = "$source"; // obtained with Stripe.js + $cu->save(); + + header('Location: '.$url); + exit; + } + elseif ($action == 'delete') + { + $cu->sources->retrieve("$source")->delete(); + + header('Location: '.$url); + exit; + } +} + + +/* + * View + */ + +$form = new Form($db); +$formfile = new FormFile($db); + +llxHeader(); + +$head=societe_prepare_head($object); +if (! $id) +{ + $account->fetch(0,$object->id); +} +else +{ + $account->fetch($id); +} +if (empty($account->socid)) $account->socid=$object->id; + +if ($socid && $action == 'edit' && $user->rights->societe->creer) +{ + print '
'; + print ''; + print ''; + print ''; +} +if ($socid && $action == 'create' && $user->rights->societe->creer) +{ + print ''; + print ''; + print ''; +} + + +// View +if ($socid && $action != 'edit' && $action != "create") +{ + dol_fiche_head($head, 'rib', $langs->trans("ThirdParty"), -1, 'company'); + + // Confirm delete third party + if ($action == 'delete') + { + print $form->formconfirm($_SERVER["PHP_SELF"]."?socid=".$object->id."&ribid=".($ribid?$ribid:$id), $langs->trans("DeleteARib"), $langs->trans("ConfirmDeleteRib", $account->getRibLabel()), "confirm_delete", '', 0, 1); + } + + $linkback = ''.$langs->trans("BackToList").''; + + dol_banner_tab($object, 'socid', $linkback, ($user->societe_id?0:1), 'rowid', 'nom'); + + + if (! (empty($conf->stripe->enabled))) + { + print load_fiche_titre($langs->trans('StripeGateways'), '', ''); + + if (is_object($stripe) && $stripe->GetStripeAccount($conf->entity)) + { + $customerstripe=$stripe->CustomerStripe($object->id,$stripe->GetStripeAccount($conf->entity)); + } + + if ($customerstripe->id) { + $input=$customerstripe->sources->data; + } + + print ''."\n"; + print ''; + print ''; + print ''; + print ''; + print ''; + print "\n"; + + if (is_array($input)) + { + foreach ($input as $src) + { + print ''; + print ''; + // Default + print ''; + print ''; + } + } + if (empty($input)) + { + print ''; + } + print "
'.$langs->trans('Type').''.$langs->trans('Informations').''.$langs->trans('Default').'
'; + if ($src->object=='card') + { + if ($src->brand == 'Visa') {$brand='cc-visa';} + elseif ($src->brand == 'MasterCard') {$brand='cc-mastercard';} + elseif ($src->brand == 'American Express') {$brand='cc-amex';} + elseif ($src->brand == 'Discover') {$brand='cc-discover';} + elseif ($src->brand == 'JCB') {$brand='cc-jcb';} + elseif ($src->brand == 'Diners Club') {$brand='cc-diners-club';} + else {$brand='credit-card';} + print ''; + } + elseif ($src->object=='source' && $src->type=='card') + { + if ($src->card->brand == 'Visa') {$brand='cc-visa';} + elseif ($src->card->brand == 'MasterCard') {$brand='cc-mastercard';} + elseif ($src->card->brand == 'American Express') {$brand='cc-amex';} + elseif ($src->card->brand == 'Discover') {$brand='cc-discover';} + elseif ($src->card->brand == 'JCB') {$brand='cc-jcb';} + elseif ($src->card->brand == 'Diners Club') {$brand='cc-diners-club';} + else {$brand='credit-card';} + print ''; + } + elseif ($src->object=='source' && $src->type=='sepa_debit') + { + print ''; + } + + print''; + if ($src->object=='card') + { + print '**** '.$src->last4.' - '.$src->exp_month.'/'.$src->exp_year.''; + print ''; + if ($src->country) + { + $img=picto_from_langcode($src->country); + print $img?$img.' ':''; + print getCountry($src->country,1); + } + else print img_warning().' '.$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("CompanyCountry")).''; + } + elseif ($src->object=='source' && $src->type=='card') + { + print $src->owner->name.'
**** '.$src->card->last4.' - '.$src->card->exp_month.'/'.$src->card->exp_year.''; + print '
'; + + if ($src->card->country) + { + $img=picto_from_langcode($src->card->country); + print $img?$img.' ':''; + print getCountry($src->card->country,1); + } + else print img_warning().' '.$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("CompanyCountry")).''; + } + elseif ($src->object=='source' && $src->type=='sepa_debit') + { + print 'info sepa'; + print ''; + 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().' '.$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("CompanyCountry")).''; + } + print ''; + if (($cu->default_source!=$src->id)) + { + print ''; + print ""; + print ''; + } else { + print ""; + } + print ''; + if ($user->rights->societe->creer) + { + // print ''; + // print img_picto($langs->trans("Modify"),'edit'); + // print ''; + // print ' '; + print ''; + print ""; + print ''; + } + print '
'.$langs->trans("NoSource").'
"; + } + + + // List of bank accounts + + $morehtmlright=''.$langs->trans("Add").''; + + print load_fiche_titre($langs->trans("AllRIB"), $morehtmlright, ''); + + $rib_list = $object->get_all_rib(); + $var = false; + if (is_array($rib_list)) + { + print '
'; // You can use div-table-responsive-no-min if you dont need reserved height for your table + print ''; + + print ''; + 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 "\n"; + + foreach ($rib_list as $rib) + { + print ''; + // Label + print ''; + // Bank name + print ''; + // Account number + print ''; + // IBAN + print ''; + // BIC + print ''; + + if (! empty($conf->prelevement->enabled)) + { + // RUM + //print ''; + print ''; + + // FRSTRECUR + print ''; + } + + // Default + print ''; + + // Generate doc + print ''; + + // Edit/Delete + print ''; + + print ''; + } + + if (count($rib_list) == 0) + { + $colspan=8; + if (! empty($conf->prelevement->enabled)) $colspan+=2; + print ''; + } + + print '
'.$rib->label.''.$rib->bank.''; + $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 ''.$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 ''.$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 ''.$prelevement->buildRumNumber($object->code_client, $rib->datec, $rib->id).''.$rib->rum.''.$rib->frstrecur.''; + if (!$rib->default_rib) { + print ''; + print img_picto($langs->trans("Disabled"),'off'); + print ''; + } else { + print img_picto($langs->trans("Enabled"),'on'); + } + print ''; + + $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.= ''; + $out.= ''; + $out.= ''; + $out.= ''; + $out.= ''; + + 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'; + if (! empty($conf->browser->phone)) $morecss='maxwidth100'; + $out.= $formadmin->select_language($defaultlang, 'lang_idrib'.$rib->id, 0, 0, 0, 0, 0, $morecss); + } + // Button + $genbutton = '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.= ''; + } + print $out; + print ''; + if ($user->rights->societe->creer) + { + print ''; + print img_picto($langs->trans("Modify"),'edit'); + print ''; + + print ' '; + + print ''; + print img_picto($langs->trans("Delete"),'delete'); + print ''; + } + print '
'.$langs->trans("NoBANRecord").'
'; + print '
'; + } else { + dol_print_error($db); + } + + dol_fiche_end(); +/* + if ($socid && $action != 'edit' && $action != 'create') + { + // Barre d'actions + print '
'; + + if ($user->rights->societe->creer) + { + print ''.$langs->trans("Add").''; + } + + print '
'; + } +*/ + if (empty($conf->global->SOCIETE_DISABLE_BUILDDOC)) + { + print '
'; + print ''; // 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; + + $var=true; + + print $formfile->showdocuments('company', $object->id, $filedir, $urlsource, $genallowed, $delallowed, $object->modelpdf, 0, 0, 0, 28, 0, 'entity='.$object->entity, 0, '', $object->default_lang); + + print '
'; + + + print '
'; + + print '
'; + } + /* + include_once DOL_DOCUMENT_ROOT.'/core/modules/bank/modules_bank.php'; + $modellist=ModeleBankAccountDoc::liste_modeles($db); + //print '
'; + 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 = ''; // TODO Add link to generate doc + */ +} + +// Edit +if ($socid && $action == 'edit' && $user->rights->societe->creer) +{ + dol_fiche_head($head, 'rib', $langs->trans("ThirdParty"),0,'company'); + + $linkback = ''.$langs->trans("BackToList").''; + + dol_banner_tab($object, 'socid', $linkback, ($user->societe_id?0:1), 'rowid', 'nom'); + + print '
'; + + print '
'; + print ''; + + print ''; + print ''; + + print ''; + print ''; + + // Show fields of bank account + foreach ($account->getFieldsToShow(1) as $val) { + + $require=false; + if ($val == 'BankCode') { + $name = 'code_banque'; + $size = 8; + $content = $account->code_banque; + } elseif ($val == 'DeskCode') { + $name = 'code_guichet'; + $size = 8; + $content = $account->code_guichet; + } elseif ($val == 'BankAccountNumber') { + $name = 'number'; + $size = 18; + $content = $account->number; + } elseif ($val == 'BankAccountNumberKey') { + $name = 'cle_rib'; + $size = 3; + $content = $account->cle_rib; + } elseif ($val == 'IBAN') { + $name = 'iban'; + $size = 30; + $content = $account->iban; + if ($account->needIBAN()) $require=true; + } elseif ($val == 'BIC') { + $name = 'bic'; + $size = 12; + $content = $account->bic; + if ($account->needIBAN()) $require=true; + } + + print ''.$langs->trans($val).''; + print ''; + print ''; + } + + print '"; + + print ''; + print ''; + print "\n"; + + print '"; + + print '
'.$langs->trans("LabelRIB").'
'.$langs->trans("BankName").'
'.$langs->trans("BankAccountDomiciliation").''; + print '
'.$langs->trans("BankAccountOwner").'
'.$langs->trans("BankAccountOwnerAddress").''; + print '
'; + + if ($conf->prelevement->enabled) + { + print '
'; + + print ''; + + if (empty($account->rum)) $account->rum = $prelevement->buildRumNumber($object->code_client, $account->datec, $account->id); + + // RUM + print ''; + print ''; + + print ''; + + print '
'.$langs->trans("RUM").'
'.$langs->trans("WithdrawMode").''; + $tblArraychoice = array("FRST" => $langs->trans("FRST"), "RECUR" => $langs->trans("RECUR")); + print $form->selectarray("frstrecur", $tblArraychoice, dol_escape_htmltag(GETPOST('frstrecur')?GETPOST('frstrecur'):$account->frstrecur), 0); + print '
'; + } + + print '
'; + + dol_fiche_end(); + + print '
'; + print ''; + print '     '; + print ''; + print '
'; +} + + +// Create +if ($socid && $action == 'create' && $user->rights->societe->creer) +{ + dol_fiche_head($head, 'rib', $langs->trans("ThirdParty"),0,'company'); + + $linkback = ''.$langs->trans("BackToList").''; + + dol_banner_tab($object, 'socid', $linkback, ($user->societe_id?0:1), 'rowid', 'nom'); + + print '
'; + + print '
'; + print ''; + + print ''; + print ''; + + print ''; + print ''; + + // Show fields of bank account + foreach ($account->getFieldsToShow(1) as $val) { + + $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; + if ($account->needIBAN()) $require=true; + } elseif ($val == 'BIC') { + $name = 'bic'; + $size = 12; + if ($account->needIBAN()) $require=true; + } + + print ''.$langs->trans($val).''; + print ''; + print ''; + } + + print '"; + + print ''; + print ''; + print "\n"; + + print '"; + + print '
'.$langs->trans("LabelRIB").'
'.$langs->trans("Bank").'
'.$langs->trans("BankAccountDomiciliation").''; + print '
'.$langs->trans("BankAccountOwner").'
'.$langs->trans("BankAccountOwnerAddress").''; + print '
'; + + if ($conf->prelevement->enabled) + { + print '
'; + + print ''; + + // RUM + print ''; + print ''; + + print ''; + + print '
'.$langs->trans("RUM").'
'.$langs->trans("RUMWillBeGenerated").'
'.$langs->trans("WithdrawMode").''; + $tblArraychoice = array("FRST" => $langs->trans("FRST"), "RECUR" => $langs->trans("RECUR")); + print $form->selectarray("frstrecur", $tblArraychoice, (isset($_POST['frstrecur'])?GETPOST('frstrecur'):'FRST'), 0); + print '
'; + } + + print '
'; + + dol_fiche_end(); + + print '
'; + print ''; + print '     '; + print ''; + print '
'; +} + +if ($socid && $action == 'edit' && $user->rights->societe->creer) +{ + print ''; +} +if ($socid && $action == 'create' && $user->rights->societe->creer) +{ + print ''; +} + + +llxFooter(); + +$db->close(); From 1ba6de7ec7b5cda981578ee26ed1d4d5ad157a8f Mon Sep 17 00:00:00 2001 From: ptibogxiv Date: Wed, 7 Mar 2018 17:26:49 +0100 Subject: [PATCH 03/10] FIX call stripe.class.php --- htdocs/stripe/charge | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/htdocs/stripe/charge b/htdocs/stripe/charge index 28b990fe811..aaa0b0475f8 100644 --- a/htdocs/stripe/charge +++ b/htdocs/stripe/charge @@ -1,5 +1,5 @@ +/* Copyright (C) 2018 PtibogXIV * * 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 @@ -53,7 +53,7 @@ llxHeader('', $langs->trans("StripeChargeList")); $form = new Form($db); $societestatic = new societe($db); $acc = new Account($db); -$stripeconnect=new StripeConnexion($db); +$stripe=new Stripe($db); if (! empty($conf->stripe->enabled) && (empty($conf->global->STRIPE_LIVE) || empty($conf->global->STRIPECONNECT_LIVE) || GETPOST('forcesandbox','alpha'))) { dol_htmloutput_mesg($langs->trans('YouAreCurrentlyInSandboxMode','Stripe'),'','warning'); @@ -86,7 +86,7 @@ if (!$rowid){ print "
'; -if ($charge->source->type=='card'){ +if ($charge->source->object=='card'){ + print $langs->trans("card"); +} +elseif ($charge->source->type=='card'){ print $langs->trans("card"); } elseif ($charge->source->type=='three_d_secure'){ print $langs->trans("card3DS"); From 7edec37b286b4c10050a34ff2e2fc16acb7817e0 Mon Sep 17 00:00:00 2001 From: ptibogxiv Date: Wed, 7 Mar 2018 17:27:45 +0100 Subject: [PATCH 04/10] FIx call stripe.class.php --- htdocs/stripe/transaction.php | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/htdocs/stripe/transaction.php b/htdocs/stripe/transaction.php index b350154bee9..2a37b5a55a5 100644 --- a/htdocs/stripe/transaction.php +++ b/htdocs/stripe/transaction.php @@ -1,5 +1,5 @@ +/* Copyright (C) 2018 PtibogXIV * * 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 @@ -53,7 +53,7 @@ llxHeader('', $langs->trans("StripeTransactionList")); $form = new Form($db); $societestatic = new societe($db); $acc = new Account($db); -$stripeconnect=new StripeConnexion($db); +$stripe=new Stripe($db); if (! empty($conf->stripe->enabled) && (empty($conf->global->STRIPE_LIVE) || empty($conf->global->STRIPECONNECT_LIVE) || GETPOST('forcesandbox','alpha'))) { dol_htmloutput_mesg($langs->trans('YouAreCurrentlyInSandboxMode','Stripe'),'','warning'); @@ -87,7 +87,7 @@ if (!$rowid){ print "
'.dol_print_date($txn->created,'%d/%m/%Y %H:%M').""; -if ($charge->refunded=='1'){ - print $langs->trans("refunded"); -} elseif ($charge->paid=='1'){ - print $langs->trans("".$charge->status.""); -} else { -$label="Message: ".$charge->failure_message."
"; -$label.="Réseau: ".$charge->outcome->network_status."
"; -$label.="Statut: ".$langs->trans("".$charge->outcome->seller_message.""); - print $form->textwithpicto($langs->trans("".$charge->status.""),$label,1); -} + print "
'.$txn->type.''; if (($cu->default_source!=$src->id)) { - print ''; + print ''; print ""; print ''; } else { @@ -515,7 +517,7 @@ if ($socid && $action != 'edit' && $action != "create") print ''; if ($user->rights->societe->creer) { - // print ''; + // print ''; // print img_picto($langs->trans("Modify"),'edit'); // print ''; // print ' '; @@ -634,7 +636,7 @@ if ($socid && $action != 'edit' && $action != "create") // Default print ''; if (!$rib->default_rib) { - print ''; + print ''; print img_picto($langs->trans("Disabled"),'off'); print ''; } else { From c3e211f3f78d2ff2e4ea7185fc0871c402c1d788 Mon Sep 17 00:00:00 2001 From: ptibogxiv Date: Thu, 8 Mar 2018 02:08:43 +0100 Subject: [PATCH 07/10] Delete gateway.php --- htdocs/societe/gateway.php | 985 ------------------------------------- 1 file changed, 985 deletions(-) delete mode 100644 htdocs/societe/gateway.php diff --git a/htdocs/societe/gateway.php b/htdocs/societe/gateway.php deleted file mode 100644 index 79a9a60bb96..00000000000 --- a/htdocs/societe/gateway.php +++ /dev/null @@ -1,985 +0,0 @@ - - * Copyright (C) 2003 Jean-Louis Bergamo - * Copyright (C) 2004-2016 Laurent Destailleur - * Copyright (C) 2005-2009 Regis Houssin - * Copyright (C) 2013 Peter Fontaine - * Copyright (C) 2015-2016 Marcos García - * Copyright (C) 2017 Ferran Marcet - * - * 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 . - */ - -/** - * \file htdocs/societe/rib.php - * \ingroup societe - * \brief BAN tab for companies - */ - -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'; -require_once DOL_DOCUMENT_ROOT.'/societe/class/companybankaccount.class.php'; -require_once DOL_DOCUMENT_ROOT.'/compta/prelevement/class/bonprelevement.class.php'; -require_once DOL_DOCUMENT_ROOT.'/stripe/class/stripe.class.php'; - -$langs->load("companies"); -$langs->load("commercial"); -$langs->load("banks"); -$langs->load("bills"); - -// 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); - -$object = new Societe($db); -$object->fetch($socid); - -$account = new CompanyBankAccount($db); -$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')); - - -// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context -$hookmanager->initHooks(array('thirdpartybancard')); - - - -/* - * Actions - */ - -$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; - } - } - - - if ($action == 'update' && ! $_POST["cancel"]) - { - // Modification - if (! GETPOST('label')) - { - setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Label")), null, 'errors'); - $action='edit'; - $error++; - } - if (! GETPOST('bank')) - { - setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("BankName")), null, 'errors'); - $action='edit'; - $error++; - } - if ($account->needIBAN() == 1) - { - 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++; - } - } - - $account->fetch($id); - if (! $error) - { - $account->socid = $object->id; - - $account->bank = GETPOST('bank','alpha'); - $account->label = GETPOST('label','alpha'); - $account->courant = GETPOST('courant','alpha'); - $account->clos = GETPOST('clos','alpha'); - $account->code_banque = GETPOST('code_banque','alpha'); - $account->code_guichet = GETPOST('code_guichet','alpha'); - $account->number = GETPOST('number','alpha'); - $account->cle_rib = GETPOST('cle_rib','alpha'); - $account->bic = GETPOST('bic','alpha'); - $account->iban = GETPOST('iban','alpha'); - $account->domiciliation = GETPOST('domiciliation','alpha'); - $account->proprio = GETPOST('proprio','alpha'); - $account->owner_address = GETPOST('owner_address','alpha'); - $account->frstrecur = GETPOST('frstrecur','alpha'); - $account->rum = GETPOST('rum','alpha'); - if (empty($account->rum)) - { - $account->rum = $prelevement->buildRumNumber($object->code_client, $account->datec, $account->id); - $account->date_rum = dol_now(); - } - - $result = $account->update($user); - if (! $result) - { - setEventMessages($account->error, $account->errors, 'errors'); - } - else - { - // If this account is the default bank account, we disable others - if ($account->default_rib) - { - $account->setAsDefault($id); // This will make sure there is only one default rib - } - - $url=DOL_URL_ROOT.'/societe/rib.php?socid='.$object->id; - header('Location: '.$url); - exit; - } - } - } - - if ($action == 'add' && ! $_POST["cancel"]) - { - $error=0; - - if (! GETPOST('label')) - { - setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Label")), null, 'errors'); - $action='create'; - $error++; - } - if (! GETPOST('bank')) - { - setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("BankName")), null, 'errors'); - $action='create'; - $error++; - } - - if (! $error) - { - // Ajout - $account = new CompanyBankAccount($db); - - $account->socid = $object->id; - - $account->bank = GETPOST('bank','alpha'); - $account->label = GETPOST('label','alpha'); - $account->courant = GETPOST('courant','alpha'); - $account->clos = GETPOST('clos','alpha'); - $account->code_banque = GETPOST('code_banque','alpha'); - $account->code_guichet = GETPOST('code_guichet','alpha'); - $account->number = GETPOST('number','alpha'); - $account->cle_rib = GETPOST('cle_rib','alpha'); - $account->bic = GETPOST('bic','alpha'); - $account->iban = GETPOST('iban','alpha'); - $account->domiciliation = GETPOST('domiciliation','alpha'); - $account->proprio = GETPOST('proprio','alpha'); - $account->owner_address = GETPOST('owner_address','alpha'); - $account->frstrecur = GETPOST('frstrecur'); - $account->rum = GETPOST('rum','alpha'); - $account->datec = dol_now(); - - $db->begin(); - - // This test can be done only once properties were set - if ($account->needIBAN() == 1) - { - 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) - { - $result = $account->create($user); - if ($result < 0) - { - $error++; - setEventMessages($account->error, $account->errors, 'errors'); - $action='create'; // Force chargement page création - } - - if (empty($account->rum)) - { - $account->rum = $prelevement->buildRumNumber($object->code_client, $account->datec, $account->id); - $account->date_rum = dol_now(); - } - } - - if (! $error) - { - $result = $account->update($user); // This will set the UMR number. - if ($result < 0) - { - $error++; - setEventMessages($account->error, $account->errors, 'errors'); - $action='create'; - } - } - - if (! $error) - { - $db->commit(); - - $url=DOL_URL_ROOT.'/societe/rib.php?socid='.$object->id; - header('Location: '.$url); - exit; - } - else - { - $db->rollback(); - } - } - } - - if ($action == 'setasdefault') - { - $account = new CompanyBankAccount($db); - $res = $account->setAsDefault(GETPOST('ribid','int')); - if ($res) - { - $url=DOL_URL_ROOT.'/societe/gateway.php?socid='.$object->id; - header('Location: '.$url); - exit; - } - else - { - setEventMessages($db->lasterror, null, 'errors'); - } - } - - if ($action == 'confirm_delete' && $_GET['confirm'] == 'yes') - { - $account = new CompanyBankAccount($db); - if ($account->fetch($ribid?$ribid:$id)) - { - $result = $account->delete($user); - if ($result > 0) - { - $url = $_SERVER['PHP_SELF']."?socid=".$object->id; - header('Location: '.$url); - exit; - } - else - { - setEventMessages($account->error, $account->errors, 'errors'); - } - } - else - { - setEventMessages($account->error, $account->errors, 'errors'); - } - } - - $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) - ); - $_POST['lang_id'] = GETPOST('lang_idrib'.GETPOST('companybankid')); - $_POST['model'] = GETPOST('modelrib'.GETPOST('companybankid')); - } - $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; -} - -$stripeconnect=new StripeConnexion($db); -$customer=$stripeconnect->CustomerStripe($socid,$stripeconnect->GetStripeAccount($conf->entity)); -if ($customer->id) { -$cu = \Stripe\Customer::retrieve("".$customer->id."",array("stripe_account" => $stripeconnect->GetStripeAccount($conf->entity)));} -$url=DOL_URL_ROOT.'/societe/gateway.php?socid='.$object->id; -if ($action == 'setasdefault') -{ -$cu->default_source = "$source"; // obtained with Stripe.js -$cu->save(); - -header('Location: '.$url); -exit; -} -elseif ($action == 'delete') -{ -$cu->sources->retrieve("$source")->delete(); - -header('Location: '.$url); -exit; -} - - -/* - * View - */ - -$form = new Form($db); -$formfile = new FormFile($db); - -llxHeader(); - -$head=societe_prepare_head($object); -if (! $id) -{ - $account->fetch(0,$object->id); -} -else -{ - $account->fetch($id); -} -if (empty($account->socid)) $account->socid=$object->id; - -if ($socid && $action == 'edit' && $user->rights->societe->creer) -{ - print '
'; - print ''; - print ''; - print ''; -} -if ($socid && $action == 'create' && $user->rights->societe->creer) -{ - print ''; - print ''; - print ''; -} - - -// View -if ($socid && $action != 'edit' && $action != "create") -{ - dol_fiche_head($head, 'rib', $langs->trans("ThirdParty"), -1, 'company'); - - // Confirm delete third party - if ($action == 'delete') - { - print $form->formconfirm($_SERVER["PHP_SELF"]."?socid=".$object->id."&ribid=".($ribid?$ribid:$id), $langs->trans("DeleteARib"), $langs->trans("ConfirmDeleteRib", $account->getRibLabel()), "confirm_delete", '', 0, 1); - } - - $linkback = ''.$langs->trans("BackToList").''; - - dol_banner_tab($object, 'socid', $linkback, ($user->societe_id?0:1), 'rowid', 'nom'); - -if (! (empty($conf->stripe->enabled))){ -print '
'; -print $langs->trans('StripeGateways').''; -if ($stripeconnect->GetStripeAccount($conf->entity)) { -$customer=$stripeconnect->CustomerStripe($object->id,$stripeconnect->GetStripeAccount($conf->entity)); -} - -if ($customer->id) { -$input=$customer->sources->data; -} -print ''."\n"; -print ''; -print ''; -print ''; -print ''; -print ''; -print "\n"; - -foreach ($input as $src) { -print ''; -print ''; - // Default - print ''; -print ''; -} -if (empty($input)) -{ -print ''; -} -print "
'.$langs->trans('Type').''.$langs->trans('Informations').''.$langs->trans('Default').'
'; -if ($src->object=='card'){ -if ($src->brand == 'Visa') {$brand='cc-visa';} -elseif ($src->brand == 'MasterCard') {$brand='cc-mastercard';} -elseif ($src->brand == 'American Express') {$brand='cc-amex';} -elseif ($src->brand == 'Discover') {$brand='cc-discover';} -elseif ($src->brand == 'JCB') {$brand='cc-jcb';} -elseif ($src->brand == 'Diners Club') {$brand='cc-diners-club';} -else {$brand='credit-card';} -print ''; -} -elseif ($src->object=='source' && $src->type=='card'){ -if ($src->card->brand == 'Visa') {$brand='cc-visa';} -elseif ($src->card->brand == 'MasterCard') {$brand='cc-mastercard';} -elseif ($src->card->brand == 'American Express') {$brand='cc-amex';} -elseif ($src->card->brand == 'Discover') {$brand='cc-discover';} -elseif ($src->card->brand == 'JCB') {$brand='cc-jcb';} -elseif ($src->card->brand == 'Diners Club') {$brand='cc-diners-club';} -else {$brand='credit-card';} - -print ''; -} -elseif ($src->object=='source' && $src->type=='sepa_debit'){ -print ''; -} -print''; -if ($src->object=='card'){ -print '**** '.$src->last4.' - '.$src->exp_month.'/'.$src->exp_year.''; -print ''; - if ($src->country) - { - $img=picto_from_langcode($src->country); - print $img?$img.' ':''; - print getCountry($src->country,1); - } - else print img_warning().' '.$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("CompanyCountry")).''; -} -elseif ($src->object=='source' && $src->type=='card'){ -print $src->owner->name.'
**** '.$src->card->last4.' - '.$src->card->exp_month.'/'.$src->card->exp_year.''; -print '
'; - if ($src->card->country) - { - $img=picto_from_langcode($src->card->country); - print $img?$img.' ':''; - print getCountry($src->card->country,1); - } - else print img_warning().' '.$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("CompanyCountry")).''; -} -elseif ($src->object=='source' && $src->type=='sepa_debit'){ -print 'info sepa'; -print ''; - 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().' '.$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("CompanyCountry")).''; -} -print ''; - if (($cu->default_source!=$src->id)) { - print ''; - print ""; - print ''; - } else { - print ""; - } - print ''; - if ($user->rights->societe->creer) - { -// print ''; -// print img_picto($langs->trans("Modify"),'edit'); -// print ''; -// print ' '; - print ''; - print ""; - print ''; - } -print '
'.$langs->trans("NoSource").'
"; -} - - // List of bank accounts - - $morehtmlright=''.$langs->trans("Add").''; - - print load_fiche_titre($langs->trans("AllRIB"), $morehtmlright, ''); - - $rib_list = $object->get_all_rib(); - $var = false; - if (is_array($rib_list)) - { - print '
'; // You can use div-table-responsive-no-min if you dont need reserved height for your table - print ''; - - print ''; - 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 "\n"; - - foreach ($rib_list as $rib) - { - print ''; - // Label - print ''; - // Bank name - print ''; - // Account number - print ''; - // IBAN - print ''; - // BIC - print ''; - - if (! empty($conf->prelevement->enabled)) - { - // RUM - //print ''; - print ''; - - // FRSTRECUR - print ''; - } - - // Default - print ''; - - // Generate doc - print ''; - - // Edit/Delete - print ''; - - print ''; - } - - if (count($rib_list) == 0) - { - $colspan=8; - if (! empty($conf->prelevement->enabled)) $colspan+=2; - print ''; - } - - print '
'.$rib->label.''.$rib->bank.''; - $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 ''.$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 ''.$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 ''.$prelevement->buildRumNumber($object->code_client, $rib->datec, $rib->id).''.$rib->rum.''.$rib->frstrecur.''; - if (!$rib->default_rib) { - print ''; - print img_picto($langs->trans("Disabled"),'off'); - print ''; - } else { - print img_picto($langs->trans("Enabled"),'on'); - } - print ''; - - $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.= ''; - $out.= ''; - $out.= ''; - $out.= ''; - $out.= ''; - - 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'; - if (! empty($conf->browser->phone)) $morecss='maxwidth100'; - $out.= $formadmin->select_language($defaultlang, 'lang_idrib'.$rib->id, 0, 0, 0, 0, 0, $morecss); - } - // Button - $genbutton = '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.= ''; - } - print $out; - print ''; - if ($user->rights->societe->creer) - { - print ''; - print img_picto($langs->trans("Modify"),'edit'); - print ''; - - print ' '; - - print ''; - print img_picto($langs->trans("Delete"),'delete'); - print ''; - } - print '
'.$langs->trans("NoBANRecord").'
'; - print '
'; - } else { - dol_print_error($db); - } - - dol_fiche_end(); -/* - if ($socid && $action != 'edit' && $action != 'create') - { - // Barre d'actions - print '
'; - - if ($user->rights->societe->creer) - { - print ''.$langs->trans("Add").''; - } - - print '
'; - } -*/ - if (empty($conf->global->SOCIETE_DISABLE_BUILDDOC)) - { - print '
'; - print ''; // 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; - - $var=true; - - print $formfile->showdocuments('company', $object->id, $filedir, $urlsource, $genallowed, $delallowed, $object->modelpdf, 0, 0, 0, 28, 0, 'entity='.$object->entity, 0, '', $object->default_lang); - - print '
'; - - - print '
'; - - print '
'; - } - /* - include_once DOL_DOCUMENT_ROOT.'/core/modules/bank/modules_bank.php'; - $modellist=ModeleBankAccountDoc::liste_modeles($db); - //print '
'; - 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 = ''; // TODO Add link to generate doc - */ -} - -// Edit -if ($socid && $action == 'edit' && $user->rights->societe->creer) -{ - dol_fiche_head($head, 'rib', $langs->trans("ThirdParty"),0,'company'); - - $linkback = ''.$langs->trans("BackToList").''; - - dol_banner_tab($object, 'socid', $linkback, ($user->societe_id?0:1), 'rowid', 'nom'); - - print '
'; - - print '
'; - print ''; - - print ''; - print ''; - - print ''; - print ''; - - // Show fields of bank account - foreach ($account->getFieldsToShow(1) as $val) { - - $require=false; - if ($val == 'BankCode') { - $name = 'code_banque'; - $size = 8; - $content = $account->code_banque; - } elseif ($val == 'DeskCode') { - $name = 'code_guichet'; - $size = 8; - $content = $account->code_guichet; - } elseif ($val == 'BankAccountNumber') { - $name = 'number'; - $size = 18; - $content = $account->number; - } elseif ($val == 'BankAccountNumberKey') { - $name = 'cle_rib'; - $size = 3; - $content = $account->cle_rib; - } elseif ($val == 'IBAN') { - $name = 'iban'; - $size = 30; - $content = $account->iban; - if ($account->needIBAN()) $require=true; - } elseif ($val == 'BIC') { - $name = 'bic'; - $size = 12; - $content = $account->bic; - if ($account->needIBAN()) $require=true; - } - - print ''.$langs->trans($val).''; - print ''; - print ''; - } - - print '"; - - print ''; - print ''; - print "\n"; - - print '"; - - print '
'.$langs->trans("LabelRIB").'
'.$langs->trans("BankName").'
'.$langs->trans("BankAccountDomiciliation").''; - print '
'.$langs->trans("BankAccountOwner").'
'.$langs->trans("BankAccountOwnerAddress").''; - print '
'; - - if ($conf->prelevement->enabled) - { - print '
'; - - print ''; - - if (empty($account->rum)) $account->rum = $prelevement->buildRumNumber($object->code_client, $account->datec, $account->id); - - // RUM - print ''; - print ''; - - print ''; - - print '
'.$langs->trans("RUM").'
'.$langs->trans("WithdrawMode").''; - $tblArraychoice = array("FRST" => $langs->trans("FRST"), "RECUR" => $langs->trans("RECUR")); - print $form->selectarray("frstrecur", $tblArraychoice, dol_escape_htmltag(GETPOST('frstrecur')?GETPOST('frstrecur'):$account->frstrecur), 0); - print '
'; - } - - print '
'; - - dol_fiche_end(); - - print '
'; - print ''; - print '     '; - print ''; - print '
'; -} - - -// Create -if ($socid && $action == 'create' && $user->rights->societe->creer) -{ - dol_fiche_head($head, 'rib', $langs->trans("ThirdParty"),0,'company'); - - $linkback = ''.$langs->trans("BackToList").''; - - dol_banner_tab($object, 'socid', $linkback, ($user->societe_id?0:1), 'rowid', 'nom'); - - print '
'; - - print '
'; - print ''; - - print ''; - print ''; - - print ''; - print ''; - - // Show fields of bank account - foreach ($account->getFieldsToShow(1) as $val) { - - $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; - if ($account->needIBAN()) $require=true; - } elseif ($val == 'BIC') { - $name = 'bic'; - $size = 12; - if ($account->needIBAN()) $require=true; - } - - print ''.$langs->trans($val).''; - print ''; - print ''; - } - - print '"; - - print ''; - print ''; - print "\n"; - - print '"; - - print '
'.$langs->trans("LabelRIB").'
'.$langs->trans("Bank").'
'.$langs->trans("BankAccountDomiciliation").''; - print '
'.$langs->trans("BankAccountOwner").'
'.$langs->trans("BankAccountOwnerAddress").''; - print '
'; - - if ($conf->prelevement->enabled) - { - print '
'; - - print ''; - - // RUM - print ''; - print ''; - - print ''; - - print '
'.$langs->trans("RUM").'
'.$langs->trans("RUMWillBeGenerated").'
'.$langs->trans("WithdrawMode").''; - $tblArraychoice = array("FRST" => $langs->trans("FRST"), "RECUR" => $langs->trans("RECUR")); - print $form->selectarray("frstrecur", $tblArraychoice, (isset($_POST['frstrecur'])?GETPOST('frstrecur'):'FRST'), 0); - print '
'; - } - - print '
'; - - dol_fiche_end(); - - print '
'; - print ''; - print '     '; - print ''; - print '
'; -} - -if ($socid && $action == 'edit' && $user->rights->societe->creer) -{ - print ''; -} -if ($socid && $action == 'create' && $user->rights->societe->creer) -{ - print ''; -} - - -llxFooter(); - -$db->close(); From 5c04c2886ca681cd08d3089569e45e51b9d1412d Mon Sep 17 00:00:00 2001 From: ptibogxiv Date: Thu, 8 Mar 2018 02:09:27 +0100 Subject: [PATCH 08/10] Delete because replace by paymentmodes.php --- htdocs/societe/rib.php | 932 ----------------------------------------- 1 file changed, 932 deletions(-) delete mode 100644 htdocs/societe/rib.php diff --git a/htdocs/societe/rib.php b/htdocs/societe/rib.php deleted file mode 100644 index d4263cc0b21..00000000000 --- a/htdocs/societe/rib.php +++ /dev/null @@ -1,932 +0,0 @@ - - * Copyright (C) 2003 Jean-Louis Bergamo - * Copyright (C) 2004-2016 Laurent Destailleur - * Copyright (C) 2005-2009 Regis Houssin - * Copyright (C) 2013 Peter Fontaine - * Copyright (C) 2015-2016 Marcos García - * Copyright (C) 2017 Ferran Marcet - * - * 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 . - */ - -/** - * \file htdocs/societe/rib.php - * \ingroup societe - * \brief BAN tab for companies - */ - -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'; -require_once DOL_DOCUMENT_ROOT.'/societe/class/companybankaccount.class.php'; -require_once DOL_DOCUMENT_ROOT.'/compta/prelevement/class/bonprelevement.class.php'; - -$langs->load("companies"); -$langs->load("commercial"); -$langs->load("banks"); -$langs->load("bills"); - -// Security check -$socid = GETPOST("socid","int"); -if ($user->societe_id) $socid=$user->societe_id; -$result = restrictedArea($user, 'societe','',''); - -$id=GETPOST("id","int"); -$ribid=GETPOST("ribid","int"); -$action=GETPOST("action", 'alpha', 3); - -$object = new Societe($db); -$object->fetch($socid); - -$account = new CompanyBankAccount($db); -$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')); - - -// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context -$hookmanager->initHooks(array('thirdpartybancard')); - - - -/* - * Actions - */ - -$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; - } - } - - - if ($action == 'update' && ! $_POST["cancel"]) - { - // Modification - if (! GETPOST('label')) - { - setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Label")), null, 'errors'); - $action='edit'; - $error++; - } - if (! GETPOST('bank')) - { - setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("BankName")), null, 'errors'); - $action='edit'; - $error++; - } - if ($account->needIBAN() == 1) - { - 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++; - } - } - - $account->fetch($id); - if (! $error) - { - $account->socid = $object->id; - - $account->bank = GETPOST('bank','alpha'); - $account->label = GETPOST('label','alpha'); - $account->courant = GETPOST('courant','alpha'); - $account->clos = GETPOST('clos','alpha'); - $account->code_banque = GETPOST('code_banque','alpha'); - $account->code_guichet = GETPOST('code_guichet','alpha'); - $account->number = GETPOST('number','alpha'); - $account->cle_rib = GETPOST('cle_rib','alpha'); - $account->bic = GETPOST('bic','alpha'); - $account->iban = GETPOST('iban','alpha'); - $account->domiciliation = GETPOST('domiciliation','alpha'); - $account->proprio = GETPOST('proprio','alpha'); - $account->owner_address = GETPOST('owner_address','alpha'); - $account->frstrecur = GETPOST('frstrecur','alpha'); - $account->rum = GETPOST('rum','alpha'); - if (empty($account->rum)) - { - $account->rum = $prelevement->buildRumNumber($object->code_client, $account->datec, $account->id); - $account->date_rum = dol_now(); - } - - $result = $account->update($user); - if (! $result) - { - setEventMessages($account->error, $account->errors, 'errors'); - } - else - { - // If this account is the default bank account, we disable others - if ($account->default_rib) - { - $account->setAsDefault($id); // This will make sure there is only one default rib - } - - $url=DOL_URL_ROOT.'/societe/rib.php?socid='.$object->id; - header('Location: '.$url); - exit; - } - } - } - - if ($action == 'add' && ! $_POST["cancel"]) - { - $error=0; - - if (! GETPOST('label')) - { - setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Label")), null, 'errors'); - $action='create'; - $error++; - } - if (! GETPOST('bank')) - { - setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("BankName")), null, 'errors'); - $action='create'; - $error++; - } - - if (! $error) - { - // Ajout - $account = new CompanyBankAccount($db); - - $account->socid = $object->id; - - $account->bank = GETPOST('bank','alpha'); - $account->label = GETPOST('label','alpha'); - $account->courant = GETPOST('courant','alpha'); - $account->clos = GETPOST('clos','alpha'); - $account->code_banque = GETPOST('code_banque','alpha'); - $account->code_guichet = GETPOST('code_guichet','alpha'); - $account->number = GETPOST('number','alpha'); - $account->cle_rib = GETPOST('cle_rib','alpha'); - $account->bic = GETPOST('bic','alpha'); - $account->iban = GETPOST('iban','alpha'); - $account->domiciliation = GETPOST('domiciliation','alpha'); - $account->proprio = GETPOST('proprio','alpha'); - $account->owner_address = GETPOST('owner_address','alpha'); - $account->frstrecur = GETPOST('frstrecur'); - $account->rum = GETPOST('rum','alpha'); - $account->datec = dol_now(); - - $db->begin(); - - // This test can be done only once properties were set - if ($account->needIBAN() == 1) - { - 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) - { - $result = $account->create($user); - if ($result < 0) - { - $error++; - setEventMessages($account->error, $account->errors, 'errors'); - $action='create'; // Force chargement page création - } - - if (empty($account->rum)) - { - $account->rum = $prelevement->buildRumNumber($object->code_client, $account->datec, $account->id); - $account->date_rum = dol_now(); - } - } - - if (! $error) - { - $result = $account->update($user); // This will set the UMR number. - if ($result < 0) - { - $error++; - setEventMessages($account->error, $account->errors, 'errors'); - $action='create'; - } - } - - if (! $error) - { - $db->commit(); - - $url=DOL_URL_ROOT.'/societe/rib.php?socid='.$object->id; - header('Location: '.$url); - exit; - } - else - { - $db->rollback(); - } - } - } - - if ($action == 'setasdefault') - { - $account = new CompanyBankAccount($db); - $res = $account->setAsDefault(GETPOST('ribid','int')); - if ($res) - { - $url=DOL_URL_ROOT.'/societe/rib.php?socid='.$object->id; - header('Location: '.$url); - exit; - } - else - { - setEventMessages($db->lasterror, null, 'errors'); - } - } - - if ($action == 'confirm_delete' && $_GET['confirm'] == 'yes') - { - $account = new CompanyBankAccount($db); - if ($account->fetch($ribid?$ribid:$id)) - { - $result = $account->delete($user); - if ($result > 0) - { - $url = $_SERVER['PHP_SELF']."?socid=".$object->id; - header('Location: '.$url); - exit; - } - else - { - setEventMessages($account->error, $account->errors, 'errors'); - } - } - else - { - setEventMessages($account->error, $account->errors, 'errors'); - } - } - - $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) - ); - $_POST['lang_id'] = GETPOST('lang_idrib'.GETPOST('companybankid')); - $_POST['model'] = GETPOST('modelrib'.GETPOST('companybankid')); - } - $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; -} - - - -/* - * View - */ - -$form = new Form($db); -$formfile = new FormFile($db); - -llxHeader(); - -$head=societe_prepare_head($object); -if (! $id) -{ - $account->fetch(0,$object->id); -} -else -{ - $account->fetch($id); -} -if (empty($account->socid)) $account->socid=$object->id; - -if ($socid && $action == 'edit' && $user->rights->societe->creer) -{ - print '
'; - print ''; - print ''; - print ''; -} -if ($socid && $action == 'create' && $user->rights->societe->creer) -{ - print ''; - print ''; - print ''; -} - - -// View -if ($socid && $action != 'edit' && $action != "create") -{ - dol_fiche_head($head, 'rib', $langs->trans("ThirdParty"), -1, 'company'); - - // Confirm delete third party - if ($action == 'delete') - { - print $form->formconfirm($_SERVER["PHP_SELF"]."?socid=".$object->id."&ribid=".($ribid?$ribid:$id), $langs->trans("DeleteARib"), $langs->trans("ConfirmDeleteRib", $account->getRibLabel()), "confirm_delete", '', 0, 1); - } - - $linkback = ''.$langs->trans("BackToList").''; - - dol_banner_tab($object, 'socid', $linkback, ($user->societe_id?0:1), 'rowid', 'nom'); - - - print load_fiche_titre($langs->trans("DefaultRIB"), '', ''); - - print '
'; - print '
'; - - print ''; - - print ''; - print ''; - - print ''; - print ''; - - // Show fields of bank account - foreach($account->getFieldsToShow(1) as $val) - { - if ($val == 'BankCode') { - $content = $account->code_banque; - } elseif ($val == 'DeskCode') { - $content = $account->code_guichet; - } elseif ($val == 'BankAccountNumber') { - $content = $account->number; - if (! empty($account->label) && $account->number) { - if (! checkBanForAccount($account)) { - $content.= ' '.img_picto($langs->trans("ValueIsNotValid"),'warning'); - } else { - $content.= ' '.img_picto($langs->trans("ValueIsValid"),'info'); - } - } - } elseif ($val == 'BankAccountNumberKey') { - $content = $account->cle_rib; - } elseif ($val == 'IBAN') { - $content = $account->iban; - if (! empty($account->iban)) { - if (! checkIbanForAccount($account)) { - $content.= ' '.img_picto($langs->trans("ValueIsNotValid"),'warning'); - } else { - $content.= ' '.img_picto($langs->trans("ValueIsValid"),'info'); - } - } - } elseif ($val == 'BIC') { - $content = $account->bic; - if (! empty($account->bic)) { - if (! checkSwiftForAccount($account)) { - $content.= ' '.img_picto($langs->trans("ValueIsNotValid"),'warning'); - } else { - $content.= ' '.img_picto($langs->trans("ValueIsValid"),'info'); - } - } - } - - print ''; - print ''; - print ''; - } - - print '\n"; - - print '\n"; - - print '\n"; - - print '
'.$langs->trans("LabelRIB").''.$account->label.'
'.$langs->trans("BankName").''.$account->bank.'
'.$langs->trans($val).''.$content.'
'.$langs->trans("BankAccountDomiciliation").''; - print $account->domiciliation; - print "
'.$langs->trans("BankAccountOwner").''; - print $account->proprio; - print "
'.$langs->trans("BankAccountOwnerAddress").''; - print $account->owner_address; - print "
'; - print '
'; - - print '
'; - - // List of bank accounts - - $morehtmlright=''.$langs->trans("Add").''; - - print load_fiche_titre($langs->trans("AllRIB"), $morehtmlright, ''); - - $rib_list = $object->get_all_rib(); - $var = false; - if (is_array($rib_list)) - { - print '
'; // You can use div-table-responsive-no-min if you dont need reserved height for your table - print ''; - - print ''; - 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 "\n"; - - foreach ($rib_list as $rib) - { - print ''; - // Label - print ''; - // Bank name - print ''; - // Account number - print ''; - // IBAN - print ''; - // BIC - print ''; - - if (! empty($conf->prelevement->enabled)) - { - // RUM - //print ''; - print ''; - - // FRSTRECUR - print ''; - } - - // Default - print ''; - - // Generate doc - print ''; - - // Edit/Delete - print ''; - - print ''; - } - - if (count($rib_list) == 0) - { - $colspan=8; - if (! empty($conf->prelevement->enabled)) $colspan+=2; - print ''; - } - - print '
'.$rib->label.''.$rib->bank.''; - $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 ''.$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 ''.$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 ''.$prelevement->buildRumNumber($object->code_client, $rib->datec, $rib->id).''.$rib->rum.''.$rib->frstrecur.''; - if (!$rib->default_rib) { - print ''; - print img_picto($langs->trans("Disabled"),'off'); - print ''; - } else { - print img_picto($langs->trans("Enabled"),'on'); - } - print ''; - - $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.= ''; - $out.= ''; - $out.= ''; - $out.= ''; - $out.= ''; - - 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'; - if (! empty($conf->browser->phone)) $morecss='maxwidth100'; - $out.= $formadmin->select_language($defaultlang, 'lang_idrib'.$rib->id, 0, 0, 0, 0, 0, $morecss); - } - // Button - $genbutton = '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.= ''; - } - print $out; - print ''; - if ($user->rights->societe->creer) - { - print ''; - print img_picto($langs->trans("Modify"),'edit'); - print ''; - - print ' '; - - print ''; - print img_picto($langs->trans("Delete"),'delete'); - print ''; - } - print '
'.$langs->trans("NoBANRecord").'
'; - print '
'; - } else { - dol_print_error($db); - } - - dol_fiche_end(); - - - /* - if ($socid && $action != 'edit' && $action != 'create') - { - // Barre d'actions - print '
'; - - if ($user->rights->societe->creer) - { - print ''.$langs->trans("Add").''; - } - - print '
'; - } - */ - - - - if (empty($conf->global->SOCIETE_DISABLE_BUILDDOC)) - { - print '
'; - print ''; // 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; - - $var=true; - - print $formfile->showdocuments('company', $object->id, $filedir, $urlsource, $genallowed, $delallowed, $object->modelpdf, 0, 0, 0, 28, 0, 'entity='.$object->entity, 0, '', $object->default_lang); - - print '
'; - - - print '
'; - - print '
'; - } - /* - include_once DOL_DOCUMENT_ROOT.'/core/modules/bank/modules_bank.php'; - $modellist=ModeleBankAccountDoc::liste_modeles($db); - //print '
'; - 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 = ''; // TODO Add link to generate doc - */ -} - -// Edit -if ($socid && $action == 'edit' && $user->rights->societe->creer) -{ - dol_fiche_head($head, 'rib', $langs->trans("ThirdParty"),0,'company'); - - $linkback = ''.$langs->trans("BackToList").''; - - dol_banner_tab($object, 'socid', $linkback, ($user->societe_id?0:1), 'rowid', 'nom'); - - print '
'; - - print '
'; - print ''; - - print ''; - print ''; - - print ''; - print ''; - - // Show fields of bank account - foreach ($account->getFieldsToShow(1) as $val) { - - $require=false; - if ($val == 'BankCode') { - $name = 'code_banque'; - $size = 8; - $content = $account->code_banque; - } elseif ($val == 'DeskCode') { - $name = 'code_guichet'; - $size = 8; - $content = $account->code_guichet; - } elseif ($val == 'BankAccountNumber') { - $name = 'number'; - $size = 18; - $content = $account->number; - } elseif ($val == 'BankAccountNumberKey') { - $name = 'cle_rib'; - $size = 3; - $content = $account->cle_rib; - } elseif ($val == 'IBAN') { - $name = 'iban'; - $size = 30; - $content = $account->iban; - if ($account->needIBAN()) $require=true; - } elseif ($val == 'BIC') { - $name = 'bic'; - $size = 12; - $content = $account->bic; - if ($account->needIBAN()) $require=true; - } - - print ''.$langs->trans($val).''; - print ''; - print ''; - } - - print '"; - - print ''; - print ''; - print "\n"; - - print '"; - - print '
'.$langs->trans("LabelRIB").'
'.$langs->trans("BankName").'
'.$langs->trans("BankAccountDomiciliation").''; - print '
'.$langs->trans("BankAccountOwner").'
'.$langs->trans("BankAccountOwnerAddress").''; - print '
'; - - if ($conf->prelevement->enabled) - { - print '
'; - - print ''; - - if (empty($account->rum)) $account->rum = $prelevement->buildRumNumber($object->code_client, $account->datec, $account->id); - - // RUM - print ''; - print ''; - - print ''; - - print '
'.$langs->trans("RUM").'
'.$langs->trans("WithdrawMode").''; - $tblArraychoice = array("FRST" => $langs->trans("FRST"), "RECUR" => $langs->trans("RECUR")); - print $form->selectarray("frstrecur", $tblArraychoice, dol_escape_htmltag(GETPOST('frstrecur')?GETPOST('frstrecur'):$account->frstrecur), 0); - print '
'; - } - - print '
'; - - dol_fiche_end(); - - print '
'; - print ''; - print '     '; - print ''; - print '
'; -} - - -// Create -if ($socid && $action == 'create' && $user->rights->societe->creer) -{ - dol_fiche_head($head, 'rib', $langs->trans("ThirdParty"),0,'company'); - - $linkback = ''.$langs->trans("BackToList").''; - - dol_banner_tab($object, 'socid', $linkback, ($user->societe_id?0:1), 'rowid', 'nom'); - - print '
'; - - print '
'; - print ''; - - print ''; - print ''; - - print ''; - print ''; - - // Show fields of bank account - foreach ($account->getFieldsToShow(1) as $val) { - - $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; - if ($account->needIBAN()) $require=true; - } elseif ($val == 'BIC') { - $name = 'bic'; - $size = 12; - if ($account->needIBAN()) $require=true; - } - - print ''.$langs->trans($val).''; - print ''; - print ''; - } - - print '"; - - print ''; - print ''; - print "\n"; - - print '"; - - print '
'.$langs->trans("LabelRIB").'
'.$langs->trans("Bank").'
'.$langs->trans("BankAccountDomiciliation").''; - print '
'.$langs->trans("BankAccountOwner").'
'.$langs->trans("BankAccountOwnerAddress").''; - print '
'; - - if ($conf->prelevement->enabled) - { - print '
'; - - print ''; - - // RUM - print ''; - print ''; - - print ''; - - print '
'.$langs->trans("RUM").'
'.$langs->trans("RUMWillBeGenerated").'
'.$langs->trans("WithdrawMode").''; - $tblArraychoice = array("FRST" => $langs->trans("FRST"), "RECUR" => $langs->trans("RECUR")); - print $form->selectarray("frstrecur", $tblArraychoice, (isset($_POST['frstrecur'])?GETPOST('frstrecur'):'FRST'), 0); - print '
'; - } - - print '
'; - - dol_fiche_end(); - - print '
'; - print ''; - print '     '; - print ''; - print '
'; -} - -if ($socid && $action == 'edit' && $user->rights->societe->creer) -{ - print ''; -} -if ($socid && $action == 'create' && $user->rights->societe->creer) -{ - print ''; -} - - -llxFooter(); - -$db->close(); From e2bd0198d1bcfec9f0b1cceae41e6e36246b7cc8 Mon Sep 17 00:00:00 2001 From: ptibogxiv Date: Thu, 8 Mar 2018 02:26:57 +0100 Subject: [PATCH 09/10] Fix class call --- htdocs/stripe/class/stripe.class.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/htdocs/stripe/class/stripe.class.php b/htdocs/stripe/class/stripe.class.php index c3fded06264..a1eefd6ecb7 100644 --- a/htdocs/stripe/class/stripe.class.php +++ b/htdocs/stripe/class/stripe.class.php @@ -1,5 +1,5 @@ +/* Copyright (C) 2018 PtibogXIV * * 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 @@ -213,7 +213,7 @@ $metadata = array( "idsource" => "".$item."", "idcustomer" => "".$societe->id."" ); -$return = new StripeConnexion($this->db); +$return = new Stripe($this->db); try { if ($stripeamount>=100) { if ($entite=='1' or empty($conf->stripeconnect->enabled)){ @@ -264,8 +264,8 @@ $return->id = $charge->id; if ($charge->source->type=='card'){ $return->message = $charge->source->card->brand." ****".$charge->source->card->last4; }elseif ($charge->source->type=='three_d_secure'){ -$stripeconnect=new StripeConnexion($this->db); -$src = \Stripe\Source::retrieve("".$charge->source->three_d_secure->card."",array("stripe_account" => $stripeconnect->GetStripeAccount($conf->entity))); +$stripe=new Stripe($this->db); +$src = \Stripe\Source::retrieve("".$charge->source->three_d_secure->card."",array("stripe_account" => $stripe->GetStripeAccount($conf->entity))); $return->message = $src->card->brand." ****".$src->card->last4; }else { $return->message = $charge->id; From 7774b49beb6afe22087fd4c41db2addb339e7609 Mon Sep 17 00:00:00 2001 From: ptibogxiv Date: Thu, 8 Mar 2018 10:03:36 +0100 Subject: [PATCH 10/10] Fix paymentmodes.php --- htdocs/societe/paymentmodes.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/societe/paymentmodes.php b/htdocs/societe/paymentmodes.php index cbafeb68a09..4bd19295e7a 100644 --- a/htdocs/societe/paymentmodes.php +++ b/htdocs/societe/paymentmodes.php @@ -345,8 +345,8 @@ if (class_exists('Stripe')) $cu->default_source = "$source"; // obtained with Stripe.js $cu->save(); - //header('Location: '.$url); - //exit; + header('Location: '.$url); + exit; } elseif ($action == 'delete') {