* Copyright (C) 2003 Jean-Louis Bergamo * Copyright (C) 2004-2012 Laurent Destailleur * Copytight (C) 2005-2009 Regis Houssin * * 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/compta/bank/fiche.php * \ingroup banque * \brief Page to create/view a bank account */ require('../../main.inc.php'); require_once DOL_DOCUMENT_ROOT.'/core/lib/bank.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/html.formbank.class.php'; require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php'; $langs->load("banks"); $langs->load("categories"); $langs->load("companies"); $action=GETPOST("action"); // Security check if (isset($_GET["id"]) || isset($_GET["ref"])) { $id = isset($_GET["id"])?$_GET["id"]:(isset($_GET["ref"])?$_GET["ref"]:''); } $fieldid = isset($_GET["ref"])?'ref':'rowid'; if ($user->societe_id) $socid=$user->societe_id; $result=restrictedArea($user,'banque',$id,'bank_account&bank_account','','',$fieldid); /* * Actions */ if ($_POST["action"] == 'add') { $error=0; // Create account $account = new Account($db,0); $account->ref = dol_sanitizeFileName(trim($_POST["ref"])); $account->label = trim($_POST["label"]); $account->courant = $_POST["type"]; $account->clos = $_POST["clos"]; $account->rappro = (isset($_POST["norappro"]) && $_POST["norappro"])?0:1; $account->url = $_POST["url"]; $account->account_number = trim($_POST["account_number"]); $account->solde = $_POST["solde"]; $account->date_solde = dol_mktime(12,0,0,$_POST["remonth"],$_POST["reday"],$_POST["reyear"]); $account->currency_code = trim($_POST["account_currency_code"]); $account->state_id = $_POST["account_state_id"]; $account->country_id = $_POST["account_country_id"]; $account->min_allowed = $_POST["account_min_allowed"]; $account->min_desired = $_POST["account_min_desired"]; $account->comment = trim($_POST["account_comment"]); if ($conf->global->MAIN_BANK_ACCOUNTANCY_CODE_ALWAYS_REQUIRED && empty($account->account_number)) { setEventMessage($langs->transnoentitiesnoconv("ErrorFieldRequired",$langs->transnoentitiesnoconv("AccountancyCode")), 'error'); $action='create'; // Force chargement page en mode creation $error++; } if (empty($account->ref)) { setEventMessage($langs->transnoentitiesnoconv("ErrorFieldRequired",$langs->transnoentitiesnoconv("Ref")), 'errors'); $action='create'; // Force chargement page en mode creation $error++; } if (empty($account->label)) { setEventMessage($langs->transnoentitiesnoconv("ErrorFieldRequired",$langs->transnoentitiesnoconv("LabelBankCashAccount")), 'errors'); $action='create'; // Force chargement page en mode creation $error++; } if (! $error) { $id = $account->create($user->id); if ($id > 0) { $_GET["id"]=$id; // Force chargement page en mode visu } else { setEventMessage($account->error,'errors'); $action='create'; // Force chargement page en mode creation } } } if ($_POST["action"] == 'update' && ! $_POST["cancel"]) { $error=0; // Update account $account = new Account($db, $_POST["id"]); $account->fetch($_POST["id"]); $account->ref = dol_string_nospecial(trim($_POST["ref"])); $account->label = trim($_POST["label"]); $account->courant = $_POST["type"]; $account->clos = $_POST["clos"]; $account->rappro = (isset($_POST["norappro"]) && $_POST["norappro"])?0:1; $account->url = trim($_POST["url"]); $account->bank = trim($_POST["bank"]); $account->code_banque = trim($_POST["code_banque"]); $account->code_guichet = trim($_POST["code_guichet"]); $account->number = trim($_POST["number"]); $account->cle_rib = trim($_POST["cle_rib"]); $account->bic = trim($_POST["bic"]); $account->iban_prefix = trim($_POST["iban_prefix"]); $account->domiciliation = trim($_POST["domiciliation"]); $account->proprio = trim($_POST["proprio"]); $account->owner_address = trim($_POST["owner_address"]); $account->account_number = trim($_POST["account_number"]); $account->currency_code = trim($_POST["account_currency_code"]); $account->state_id = $_POST["account_state_id"]; $account->country_id = $_POST["account_country_id"]; $account->min_allowed = $_POST["account_min_allowed"]; $account->min_desired = $_POST["account_min_desired"]; $account->comment = trim($_POST["account_comment"]); if ($conf->global->MAIN_BANK_ACCOUNTANCY_CODE_ALWAYS_REQUIRED && empty($account->account_number)) { setEventMessage($langs->transnoentitiesnoconv("ErrorFieldRequired",$langs->transnoentitiesnoconv("AccountancyCode")), 'error'); $action='edit'; // Force chargement page en mode creation $error++; } if (empty($account->ref)) { setEventMessage($langs->transnoentitiesnoconv("ErrorFieldRequired",$langs->transnoentitiesnoconv("Ref")), 'errors'); $action='edit'; // Force chargement page en mode creation $error++; } if (empty($account->label)) { setEventMessage($langs->transnoentitiesnoconv("ErrorFieldRequired",$langs->transnoentitiesnoconv("LabelBankCashAccount")), 'errors'); $action='edit'; // Force chargement page en mode creation $error++; } if (! $error) { $result = $account->update($user); if ($result >= 0) { $_GET["id"]=$_POST["id"]; // Force chargement page en mode visu } else { $message='
'.$account->error.'
'; $action='edit'; // Force chargement page edition } } } if ($_POST["action"] == 'confirm_delete' && $_POST["confirm"] == "yes" && $user->rights->banque->configurer) { // Delete $account = new Account($db); $account->fetch($_GET["id"]); $account->delete(); header("Location: ".DOL_URL_ROOT."/compta/bank/index.php"); exit; } /* * View */ $form = new Form($db); $formbank = new FormBank($db); $formcompany = new FormCompany($db); $countrynotdefined=$langs->trans("ErrorSetACountryFirst").' ('.$langs->trans("SeeAbove").')'; llxHeader(); // Creation if ($action == 'create') { $account=new Account($db); print_fiche_titre($langs->trans("NewFinancialAccount")); dol_htmloutput_mesg($message); if ($conf->use_javascript_ajax) { print "\n".''."\n"; } print '
'; print ''; print ''; print ''; print ''; // Ref print ''; print ''; // Label print ''; print ''; // Type print ''; print ''; // Currency print ''; print ''; // Status print ''; print ''; // Country print ''; print ''; // State print ''; // Accountancy code if (! empty($conf->global->MAIN_BANK_ACCOUNTANCY_CODE_ALWAYS_REQUIRED)) { print ''; print ''; } else { print ''; print ''; } // Web print ''; print ''; // Comment print ''; print ''; // Sold print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print '
'.$langs->trans("Ref").'ref).'" maxlength="12">
'.$langs->trans("LabelBankCashAccount").'
'.$langs->trans("AccountType").''; print $formbank->select_type_comptes_financiers(isset($_POST["type"])?$_POST["type"]:1,"type"); print '
'.$langs->trans("Currency").''; $selectedcode=$account->account_currency_code; if (! $selectedcode) $selectedcode=$conf->currency; print $form->selectCurrency((isset($_POST["account_currency_code"])?$_POST["account_currency_code"]:$selectedcode), 'account_currency_code'); //print $langs->trans("Currency".$conf->currency); //print ''; print '
'.$langs->trans("Status").''; print $form->selectarray("clos",array(0=>$account->status[0],1=>$account->status[1]),(isset($_POST["clos"])?$_POST["clos"]:$account->clos)); print '
'.$langs->trans("BankAccountCountry").''; $selectedcode=''; if (isset($_POST["account_country_id"])) { $selectedcode=$_POST["account_country_id"]?$_POST["account_country_id"]:$account->country_code; } else if (empty($selectedcode)) $selectedcode=$mysoc->country_code; print $form->select_country($selectedcode,'account_country_id'); if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1); print '
'.$langs->trans('State').''; if ($selectedcode) { $formcompany->select_departement(isset($_POST["account_state_id"])?$_POST["account_state_id"]:'',$selectedcode,'account_state_id'); } else { print $countrynotdefined; } print '
'.$langs->trans("AccountancyCode").'
'.$langs->trans("AccountancyCode").'
'.$langs->trans("Web").'
'.$langs->trans("Comment").''; // Editor wysiwyg require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php'; $doleditor=new DolEditor('account_comment',$account->comment,'',200,'dolibarr_notes','',false,true,$conf->global->FCKEDITOR_ENABLE_SOCIETE,10,70); $doleditor->Create(); print '
'.$langs->trans("InitialBankBalance").'...
'.$langs->trans("InitialBankBalance").'solde)).'">
'.$langs->trans("Date").''; $form->select_date('', 're', 0, 0, 0, 'formsoc'); print '
'.$langs->trans("BalanceMinimalAllowed").'account_min_allowed).'">
'.$langs->trans("BalanceMinimalDesired").'account_min_desired).'">
'; print '

'; print '
'; } /* ************************************************************************** */ /* */ /* Visu et edition */ /* */ /* ************************************************************************** */ else { if (($_GET["id"] || $_GET["ref"]) && $action != 'edit') { $account = new Account($db); if ($_GET["id"]) { $account->fetch($_GET["id"]); } if ($_GET["ref"]) { $account->fetch(0,$_GET["ref"]); $_GET["id"]=$account->id; } /* * Affichage onglets */ // Onglets $head=bank_prepare_head($account); dol_fiche_head($head, 'bankname', $langs->trans("FinancialAccount"),0,'account'); /* * Confirmation to delete */ if ($action == 'delete') { print $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$account->id,$langs->trans("DeleteAccount"),$langs->trans("ConfirmDeleteAccount"),"confirm_delete"); } print ''; $linkback = ''.$langs->trans("BackToList").''; // Ref print ''; print ''; // Label print ''; print ''; // Type print ''; print ''; // Currency print ''; print ''; // Status print ''; print ''; // Country print ''; // State print ''; // Conciliate print ''; print ''; // Accountancy code print ''; print ''; print ''; print ''; print ''; print ''; print '\n"; print ''; print ''; print '
'.$langs->trans("Ref").''; print $form->showrefnav($account, 'ref', $linkback, 1, 'ref'); print '
'.$langs->trans("Label").''.$account->label.'
'.$langs->trans("AccountType").''.$account->type_lib[$account->type].'
'.$langs->trans("Currency").''; $selectedcode=$account->account_currency_code; if (! $selectedcode) $selectedcode=$conf->currency; print $langs->trans("Currency".$selectedcode); print '
'.$langs->trans("Status").''.$account->getLibStatut(4).'
'.$langs->trans("BankAccountCountry").''; if ($account->country_id > 0) { $img=picto_from_langcode($account->country_code); print $img?$img.' ':''; print getCountry($account->getCountryCode(),0,$db); } print '
'.$langs->trans('State').''; if ($account->fk_departement > 0) print getState($account->fk_departement); print '
'.$langs->trans("Conciliable").''; $conciliate=$account->canBeConciliated(); if ($conciliate == -2) print $langs->trans("No").' ('.$langs->trans("CashAccount").')'; else if ($conciliate == -3) print $langs->trans("No").' ('.$langs->trans("Closed").')'; else print ($account->rappro==1 ? $langs->trans("Yes") : ($langs->trans("No").' ('.$langs->trans("ConciliationDisabled").')')); print '
'.$langs->trans("AccountancyCode").''.$account->account_number.'
'.$langs->trans("BalanceMinimalAllowed").''.$account->min_allowed.'
'.$langs->trans("BalanceMinimalDesired").''.$account->min_desired.'
'.$langs->trans("Web").''; if ($account->url) print ''; print $account->url; if ($account->url) print ''; print "
'.$langs->trans("Comment").''.$account->comment.'
'; print ''; /* * Barre d'actions */ print '
'; if ($user->rights->banque->configurer) { print 'id.'">'.$langs->trans("Modify").''; } $canbedeleted=$account->can_be_deleted(); // Renvoi vrai si compte sans mouvements if ($user->rights->banque->configurer && $canbedeleted) { print 'id.'">'.$langs->trans("Delete").''; } print '
'; } /* ************************************************************************** */ /* */ /* Edition */ /* */ /* ************************************************************************** */ if (GETPOST('id','int') && $action == 'edit' && $user->rights->banque->configurer) { $account = new Account($db); $account->fetch(GETPOST('id','int')); print_fiche_titre($langs->trans("EditFinancialAccount")); print "
"; if ($message) { print "$message
\n"; } if ($conf->use_javascript_ajax) { print "\n".''."\n"; } print '
'; print ''; print ''; print ''."\n\n"; print ''; // Ref print ''; print ''; // Label print ''; print ''; // Type print ''; print ''; // Currency print ''; print ''; // Status print ''; print ''; // Country $account->country_id=$account->country_id?$account->country_id:$mysoc->country_id; print ''; print ''; // State print ''; // Conciliable print ''; print ''; // Accountancy code if (! empty($conf->global->MAIN_BANK_ACCOUNTANCY_CODE_ALWAYS_REQUIRED)) { print ''; print ''; } else { print ''; print ''; } // Balance print ''; print ''; print ''; print ''; // Web print ''; print ''; // Comment print ''; print ''; print ''; print '
'.$langs->trans("Ref").'ref).'">
'.$langs->trans("Label").'label).'">
'.$langs->trans("AccountType").''; print $formbank->select_type_comptes_financiers((isset($_POST["type"])?$_POST["type"]:$account->type),"type"); print '
'.$langs->trans("Currency"); print ''; print ''; $selectedcode=$account->account_currency_code; if (! $selectedcode) $selectedcode=$conf->currency; print $form->selectCurrency((isset($_POST["account_currency_code"])?$_POST["account_currency_code"]:$selectedcode), 'account_currency_code'); //print $langs->trans("Currency".$conf->currency); //print ''; print '
'.$langs->trans("Status").''; print $form->selectarray("clos",array(0=>$account->status[0],1=>$account->status[1]),(isset($_POST["clos"])?$_POST["clos"]:$account->clos)); print '
'.$langs->trans("Country").''; $selectedcode=$account->country_code; if (isset($_POST["account_country_id"])) $selectedcode=$_POST["account_country_id"]; else if (empty($selectedcode)) $selectedcode=$mysoc->country_code; print $form->select_country($selectedcode,'account_country_id'); if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1); print '
'.$langs->trans('State').''; if ($selectedcode) { print $formcompany->select_state(isset($_POST["account_state_id"])?$_POST["account_state_id"]:$account->state_id,$selectedcode,'account_state_id'); } else { print $countrynotdefined; } print '
'.$langs->trans("Conciliable").''; $conciliate=$account->canBeConciliated(); if ($conciliate == -2) print $langs->trans("No").' ('.$langs->trans("CashAccount").')'; else if ($conciliate == -3) print $langs->trans("No").' ('.$langs->trans("Closed").')'; else print 'rappro?'':' checked="checked"').'"> '.$langs->trans("DisableConciliation"); print '
'.$langs->trans("AccountancyCode").'account_number).'">
'.$langs->trans("AccountancyCode").'account_number).'">
'.$langs->trans("BalanceMinimalAllowed").'min_allowed).'">
'.$langs->trans("BalanceMinimalDesired").'min_desired).'">
'.$langs->trans("Web").'url).'">'; print '
'.$langs->trans("Comment").''; // Editor wysiwyg require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php'; $doleditor=new DolEditor('account_comment',(isset($_POST["account_comment"])?$_POST["account_comment"]:$account->comment),'',200,'dolibarr_notes','',false,true,$conf->global->FCKEDITOR_ENABLE_SOCIETE,10,70); $doleditor->Create(); print '
'; print '   '; print '
'; print '
'; } } $db->close(); llxFooter();