* Copyright (C) 2003 Jean-Louis Bergamo * Copyright (C) 2004-2015 Laurent Destailleur * Copyright (C) 2005-2009 Regis Houssin * Copyright (C) 2013 Peter Fontaine * Copyright (C) 2015 Marcos García * * 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.'/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"); if ($user->societe_id) $socid=$user->societe_id; $result = restrictedArea($user, 'societe','',''); $soc = new Societe($db); $soc->id = $_GET["socid"]; $soc->fetch($_GET["socid"]); $id=GETPOST("id","int"); $ribid=GETPOST("ribid","int"); $action=GETPOST("action"); /* * Actions */ if ($action == 'update' && ! $_POST["cancel"]) { // Modification $account = new CompanyBankAccount($db); $account->fetch($id); $account->socid = $soc->id; $account->bank = $_POST["bank"]; $account->label = $_POST["label"]; $account->courant = $_POST["courant"]; $account->clos = $_POST["clos"]; $account->code_banque = $_POST["code_banque"]; $account->code_guichet = $_POST["code_guichet"]; $account->number = $_POST["number"]; $account->cle_rib = $_POST["cle_rib"]; $account->bic = $_POST["bic"]; $account->iban = $_POST["iban"]; $account->domiciliation = $_POST["domiciliation"]; $account->proprio = $_POST["proprio"]; $account->owner_address = $_POST["owner_address"]; $account->frstrecur = GETPOST('frstrecur'); $result = $account->update($user); if (! $result) { setEventMessage($account->error, 'errors'); $_GET["action"]='edit'; // Force chargement page edition } 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='.$soc->id; header('Location: '.$url); exit; } } if ($action == 'add' && ! $_POST["cancel"]) { $error=0; if (! GETPOST('label')) { setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv('Label')),'errors'); $action='create'; $error++; } if (! GETPOST('bank')) { setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv('BankName')),'errors'); $action='create'; $error++; } if (! $error) { // Ajout $account = new CompanyBankAccount($db); $account->socid = $soc->id; $account->bank = $_POST["bank"]; $account->label = $_POST["label"]; $account->courant = $_POST["courant"]; $account->clos = $_POST["clos"]; $account->code_banque = $_POST["code_banque"]; $account->code_guichet = $_POST["code_guichet"]; $account->number = $_POST["number"]; $account->cle_rib = $_POST["cle_rib"]; $account->bic = $_POST["bic"]; $account->iban = $_POST["iban"]; $account->domiciliation = $_POST["domiciliation"]; $account->proprio = $_POST["proprio"]; $account->owner_address = $_POST["owner_address"]; $account->frstrecur = GETPOST('frstrecur'); $result = $account->update($user); // TODO Use create and include update into create method if (! $result) { setEventMessages($account->error, $account->errors, 'errors'); $_GET["action"]='create'; // Force chargement page création } else { $url=DOL_URL_ROOT.'/societe/rib.php?socid='.$soc->id; header('Location: '.$url); exit; } } } if ($action == 'setasdefault') { $account = new CompanyBankAccount($db); $res = $account->setAsDefault(GETPOST('ribid','int')); if ($res) { $url=DOL_URL_ROOT.'/societe/rib.php?socid='.$soc->id; header('Location: '.$url); exit; } else { setEventMessage($db->lasterror, '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=".$soc->id; header('Location: '.$url); exit; } else { setEventMessage($account->error, 'errors'); } } else { setEventMessage($account->error, 'errors'); } } /* * View */ $form = new Form($db); $prelevement = new BonPrelevement($db); llxHeader(); $head=societe_prepare_head2($soc); $account = new CompanyBankAccount($db); if (! $id) $account->fetch(0,$soc->id); else $account->fetch($id); if (empty($account->socid)) $account->socid=$soc->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"),0,'company'); // Confirm delete third party if ($action == 'delete') { print $form->formconfirm($_SERVER["PHP_SELF"]."?socid=".$soc->id."&ribid=".($ribid?$ribid:$id), $langs->trans("DeleteARib"), $langs->trans("ConfirmDeleteRib", $account->getRibLabel()), "confirm_delete", '', 0, 1); } print_titre($langs->trans("DefaultRIB")); print ''; print ''; print ''; print ''; print ''; // Show fields of bank account $fieldlists='BankCode DeskCode AccountNumber BankAccountNumberKey'; if (! empty($conf->global->BANK_SHOW_ORDER_OPTION)) { if (is_numeric($conf->global->BANK_SHOW_ORDER_OPTION)) { if ($conf->global->BANK_SHOW_ORDER_OPTION == '1') $fieldlists='BankCode DeskCode BankAccountNumberKey AccountNumber'; } else $fieldlists=$conf->global->BANK_SHOW_ORDER_OPTION; } $fieldlistsarray=explode(' ',$fieldlists); foreach($fieldlistsarray as $val) { if ($val == 'BankCode') { if ($account->useDetailedBBAN() == 1) { print ''; print ''; print ''; } } if ($val == 'DeskCode') { if ($account->useDetailedBBAN() == 1) { print ''; print ''; print ''; } } if ($val == 'BankCode') { if ($account->useDetailedBBAN() == 2) { print ''; print ''; print ''; } } if ($val == 'AccountNumber') { print ''; print ''; print ''; } if ($val == 'BankAccountNumberKey') { if ($account->useDetailedBBAN() == 1) { print ''; print ''; print ''; } } } print ''; print ''; print ''; print ''; print '\n"; print '\n"; print '\n"; print '
'.$langs->trans("LabelRIB").''.$account->label.'
'.$langs->trans("BankName").''.$account->bank.'
'.$langs->trans("BankCode").''.$account->code_banque.'
'.$langs->trans("DeskCode").''.$account->code_guichet.'
'.$langs->trans("BankCode").''.$account->code_banque.'
'.$langs->trans("BankAccountNumber").''.$account->number.'
'.$langs->trans("BankAccountNumberKey").''.$account->cle_rib.'
'.$langs->trans("IBAN").''.$account->iban . ' '; if (! empty($account->iban)) { if (! checkIbanForAccount($account)) { print img_picto($langs->trans("IbanNotValid"),'warning'); } else { print img_picto($langs->trans("IbanValid"),'info'); } } print '
'.$langs->trans("BIC").''.$account->bic.' '; if (! empty($account->bic)) { if (! checkSwiftForAccount($account)) { print img_picto($langs->trans("SwiftNotValid"),'warning'); } else { print img_picto($langs->trans("SwiftValid"),'info'); } } print '
'.$langs->trans("BankAccountDomiciliation").''; print $account->domiciliation; print "
'.$langs->trans("BankAccountOwner").''; print $account->proprio; print "
'.$langs->trans("BankAccountOwnerAddress").''; print $account->owner_address; print "
'; // Check BBAN if ($account->label && ! checkBanForAccount($account)) { print '
'.$langs->trans("RIBControlError").'
'; } print "
"; /* * List of bank accounts */ print_titre($langs->trans("AllRIB")); $rib_list = $soc->get_all_rib(); $var = false; if (is_array($rib_list)) { print ''; print ''; print_liste_field_titre($langs->trans("LabelRIB")); print_liste_field_titre($langs->trans("Bank")); print_liste_field_titre($langs->trans("RIB")); print_liste_field_titre($langs->trans("IBAN")); print_liste_field_titre($langs->trans("BIC")); if (! empty($conf->prelevement->enabled)) { print ''; print ''; } print_liste_field_titre($langs->trans("DefaultRIB"), '', '', '', '', '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 ''; // FRSTRECUR print ''; } // Default print ''; // Edit/Delete print ''; print ''; } if (count($rib_list) == 0) { $colspan=7; if (! empty($conf->prelevement->enabled)) $colspan+=2; print ''; } print '
RUM'.$langs->trans("WithdrawMode").'
'.$rib->label.''.$rib->bank.''.$rib->getRibLabel(false).''.$rib->iban.''.$rib->bic.''.$prelevement->buildRumNumber($soc->code_client, $rib->datec, $rib->id).''.$rib->frstrecur.''; if (!$rib->default_rib) { print ''; print img_picto($langs->trans("Disabled"),'off'); print ''; } else { print img_picto($langs->trans("Enabled"),'on'); } 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").'
'; } else { dol_print_error($db); } dol_fiche_end(); } // Edit if ($socid && $action == 'edit' && $user->rights->societe->creer) { dol_fiche_head($head, 'rib', $langs->trans("ThirdParty"),0,'company'); print ''; print ''; print ''; print ''; print ''; // Show fields of bank account $fieldlists='BankCode DeskCode AccountNumber BankAccountNumberKey'; if (! empty($conf->global->BANK_SHOW_ORDER_OPTION)) { if (is_numeric($conf->global->BANK_SHOW_ORDER_OPTION)) { if ($conf->global->BANK_SHOW_ORDER_OPTION == '1') $fieldlists='BankCode DeskCode BankAccountNumberKey AccountNumber'; } else $fieldlists=$conf->global->BANK_SHOW_ORDER_OPTION; } $fieldlistsarray=explode(' ',$fieldlists); foreach($fieldlistsarray as $val) { if ($val == 'BankCode') { if ($account->useDetailedBBAN() == 1) { print ''; print ''; print ''; } } if ($val == 'DeskCode') { if ($account->useDetailedBBAN() == 1) { print ''; print ''; print ''; } } if ($val == 'BankCode') { if ($account->useDetailedBBAN() == 2) { print ''; print ''; print ''; } } if ($val == 'AccountNumber') { print ''; print ''; print ''; } if ($val == 'BankAccountNumberKey') { if ($account->useDetailedBBAN() == 1) { print ''; print ''; print ''; } } } // IBAN print ''; print ''; print ''; print ''; print '"; print ''; print ''; print "\n"; print '"; print '
'.$langs->trans("LabelRIB").'
'.$langs->trans("BankName").'
'.$langs->trans("BankCode").'
'.$langs->trans("DeskCode").'
'.$langs->trans("BankCode").'
'.$langs->trans("BankAccountNumber").'
'.$langs->trans("BankAccountNumberKey").'
'.$langs->trans("IBAN").'
'.$langs->trans("BIC").'
'.$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($soc->code_client, $account->datec, $account->id); // RUM print ''; print ''; // FRSTRECUR print ''; print ''; print '
'.$langs->trans("RUM").''.$account->rum.'
'.$langs->trans("WithdrawMode").'
'; } 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'); print ''; print ''; print ''; print ''; print ''; // BBAN if ($account->useDetailedBBAN() == 1) { print ''; print ''; print ''; print ''; print ''; print ''; } if ($account->useDetailedBBAN() == 2) { print ''; print ''; print ''; } print ''; print ''; print ''; if ($account->useDetailedBBAN() == 1) { print ''; print ''; print ''; } // IBAN print ''; print ''; print ''; print ''; print '"; print ''; print ''; print "\n"; print '"; print '
'.$langs->trans("LabelRIB").'
'.$langs->trans("Bank").'
'.$langs->trans("BankCode").'
'.$langs->trans("DeskCode").'
'.$langs->trans("BankCode").'
'.$langs->trans("BankAccountNumber").'
'.$langs->trans("BankAccountNumberKey").'
'.$langs->trans("IBAN").'
'.$langs->trans("BIC").'
'.$langs->trans("BankAccountDomiciliation").''; print '
'.$langs->trans("BankAccountOwner").'
'.$langs->trans("BankAccountOwnerAddress").''; print '
'; if ($conf->prelevement->enabled) { print '
'; print ''; // RUM print ''; print ''; // FRSTRECUR print ''; print ''; print '
'.$langs->trans("RUM").''.$langs->trans("RUMWillBeGenerated").'
'.$langs->trans("WithdrawMode").'
'; } 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 ''; } if ($socid && $action != 'edit' && $action != 'create') { /* * Barre d'actions */ print '
'; if ($user->rights->societe->creer) { print ''.$langs->trans("Add").''; } print '
'; } llxFooter(); $db->close();