diff --git a/htdocs/compta/bank/fiche.php b/htdocs/compta/bank/fiche.php index 1547c6a94f1..6bd460ac4a6 100644 --- a/htdocs/compta/bank/fiche.php +++ b/htdocs/compta/bank/fiche.php @@ -1,7 +1,7 @@ * Copyright (C) 2003 Jean-Louis Bergamo - * Copyright (C) 2004-2010 Laurent Destailleur + * Copyright (C) 2004-2011 Laurent Destailleur * Copytight (C) 2005-2009 Regis Houssin * * This program is free software; you can redistribute it and/or modify @@ -34,6 +34,8 @@ require_once(DOL_DOCUMENT_ROOT."/core/class/html.formcompany.class.php"); $langs->load("banks"); $langs->load("companies"); +$action=GETPOST("action"); + // Security check if (isset($_GET["id"]) || isset($_GET["ref"])) { @@ -49,7 +51,9 @@ $result=restrictedArea($user,'banque',$id,'bank_account','','',$fieldid); */ if ($_POST["action"] == 'add') { - // Creation compte + $error=0; + + // Create account $account = new Account($db,0); $account->ref = dol_sanitizeFileName(trim($_POST["ref"])); @@ -73,7 +77,21 @@ if ($_POST["action"] == 'add') $account->min_desired = $_POST["account_min_desired"]; $account->comment = trim($_POST["account_comment"]); - if ($account->label) + if ($conf->global->MAIN_BANCK_ACCOUNTANCY_CODE_ALWAYS_REQUIRED && empty($account->account_number)) + { + $message='
'.$langs->trans("ErrorFieldRequired",$langs->transnoentities("AccountancyCode")).'
'; + $action='create'; // Force chargement page en mode creation + $error++; + } + + if (empty($account->label)) + { + $message='
'.$langs->trans("ErrorFieldRequired",$langs->transnoentities("LabelBankCashAccount")).'
'; + $action='create'; // Force chargement page en mode creation + $error++; + } + + if (! $error) { $id = $account->create($user->id); if ($id > 0) @@ -82,17 +100,16 @@ if ($_POST["action"] == 'add') } else { $message='
'.$account->error().'
'; - $_REQUEST["action"]='create'; // Force chargement page en mode creation + $action='create'; // Force chargement page en mode creation } - } else { - $message='
'.$langs->trans("ErrorFieldRequired",$langs->transnoentities("LabelBankCashAccount")).'
'; - $_REQUEST["action"]='create'; // Force chargement page en mode creation } } if ($_POST["action"] == 'update' && ! $_POST["cancel"]) { - // Modification + $error=0; + + // Update account $account = new Account($db, $_POST["id"]); $account->fetch($_POST["id"]); @@ -127,7 +144,21 @@ if ($_POST["action"] == 'update' && ! $_POST["cancel"]) $account->min_desired = $_POST["account_min_desired"]; $account->comment = trim($_POST["account_comment"]); - if ($account->label) + if ($conf->global->MAIN_BANCK_ACCOUNTANCY_CODE_ALWAYS_REQUIRED && empty($account->account_number)) + { + $message='
'.$langs->trans("ErrorFieldRequired",$langs->transnoentities("AccountancyCode")).'
'; + $action='edit'; // Force chargement page en mode creation + $error++; + } + + if (empty($account->label)) + { + $message='
'.$langs->trans("ErrorFieldRequired",$langs->transnoentities("LabelBankCashAccount")).'
'; + $action='edit'; // Force chargement page en mode creation + $error++; + } + + if (! $error) { $result = $account->update($user); if ($result >= 0) @@ -137,11 +168,8 @@ if ($_POST["action"] == 'update' && ! $_POST["cancel"]) else { $message='
'.$account->error().'
'; - $_REQUEST["action"]='edit'; // Force chargement page edition + $action='edit'; // Force chargement page edition } - } else { - $message='
'.$langs->trans("ErrorFieldRequired",$langs->transnoentities("LabelBankCashAccount")).'
'; - $_REQUEST["action"]='create'; // Force chargement page en mode creation } } @@ -173,7 +201,7 @@ $htmlcompany = new FormCompany($db); /* */ /* ************************************************************************** */ -if ($_REQUEST["action"] == 'create') +if ($action == 'create') { $account=new Account($db); @@ -214,17 +242,6 @@ if ($_REQUEST["action"] == 'create') print $form->select_type_comptes_financiers(isset($_POST["type"])?$_POST["type"]:1,"type"); print ''; - // Code compta - if ($conf->global->MAIN_BANCK_ACCOUNTANCY_CODE_ALWAYS_REQUIRED) - { - print ''.$langs->trans("AccountancyCode").''; - print ''; - } - else - { - print ''; - } - // Currency print ''.$langs->trans("Currency").''; print ''; @@ -266,6 +283,26 @@ if ($_REQUEST["action"] == 'create') } print ''; + // Conciliable + /*print ''.$langs->trans("Conciliable").''; + print ''; + if ($account->type == 0 || $account->type == 1) print 'rappro?'':'checked="true"').'"> '.$langs->trans("DisableConciliation"); + if ($account->type == 2) print $langs->trans("No").' ('.$langs->trans("CashAccount").')'; + print ''; + */ + + // Accountancy code + if ($conf->global->MAIN_BANCK_ACCOUNTANCY_CODE_ALWAYS_REQUIRED) + { + print ''.$langs->trans("AccountancyCode").''; + print ''; + } + else + { + print ''.$langs->trans("AccountancyCode").''; + print ''; + } + // Web print ''.$langs->trans("Web").''; print ''; @@ -307,7 +344,7 @@ if ($_REQUEST["action"] == 'create') /* ************************************************************************** */ else { - if (($_GET["id"] || $_GET["ref"]) && $_REQUEST["action"] != 'edit') + if (($_GET["id"] || $_GET["ref"]) && $action != 'edit') { $account = new Account($db); if ($_GET["id"]) @@ -331,7 +368,7 @@ else /* * Confirmation to delete */ - if ($_REQUEST["action"] == 'delete') + if ($action == 'delete') { $ret=$form->form_confirm($_SERVER["PHP_SELF"].'?id='.$account->id,$langs->trans("DeleteAccount"),$langs->trans("ConfirmDeleteAccount"),"confirm_delete"); if ($ret == 'html') print '
'; @@ -387,12 +424,9 @@ else if ($account->type == 2) print $langs->trans("No").' ('.$langs->trans("CashAccount").')'; print ''; - // Code compta - if ($conf->accounting->enabled) - { + // Accountancy code print ''.$langs->trans("AccountancyCode").''; print ''.$account->account_number.''; - } print ''.$langs->trans("BalanceMinimalAllowed").''; print ''.$account->min_allowed.''; @@ -416,7 +450,6 @@ else /* * Barre d'actions - * */ print '
'; @@ -441,10 +474,10 @@ else /* */ /* ************************************************************************** */ - if ($_REQUEST["id"] && $_REQUEST["action"] == 'edit' && $user->rights->banque->configurer) + if (GETPOST("id") && $action == 'edit' && $user->rights->banque->configurer) { - $account = new Account($db, $_REQUEST["id"]); - $account->fetch($_REQUEST["id"]); + $account = new Account($db); + $account->fetch(GETPOST("id")); print_fiche_titre($langs->trans("EditFinancialAccount")); print "
"; @@ -525,21 +558,23 @@ else } print ''; + // Conciliable print ''.$langs->trans("Conciliable").''; print ''; if ($account->type == 0 || $account->type == 1) print 'rappro?'':'checked="true"').'"> '.$langs->trans("DisableConciliation"); if ($account->type == 2) print $langs->trans("No").' ('.$langs->trans("CashAccount").')'; print ''; - // Code compta - if ($conf->accounting->enabled) + // Accountancy code + if ($conf->global->MAIN_BANCK_ACCOUNTANCY_CODE_ALWAYS_REQUIRED) { - print ''.$langs->trans("AccountancyCode").''; + print ''.$langs->trans("AccountancyCode").''; print 'account_number).'">'; } else { - print 'account_number).'">'; + print ''.$langs->trans("AccountancyCode").''; + print 'account_number).'">'; } // Balance