diff --git a/htdocs/compta/bank/account.class.php b/htdocs/compta/bank/account.class.php index 0cfb880702f..4a11dcd8a7a 100644 --- a/htdocs/compta/bank/account.class.php +++ b/htdocs/compta/bank/account.class.php @@ -1,7 +1,7 @@ * Copyright (C) 2003 Jean-Louis Bergamo - * Copyright (C) 2004-2005 Laurent Destailleur + * Copyright (C) 2004-2006 Laurent Destailleur * Copyright (C) 2004 Christophe Combelles * * This program is free software; you can redistribute it and/or modify @@ -39,6 +39,7 @@ class Account { var $rowid; + var $ref; var $label; var $type; var $bank; @@ -55,6 +56,9 @@ class Account var $adresse_proprio; var $type_lib=array(); + var $account_number; + + /** * Constructeur */ @@ -264,9 +268,13 @@ class Account return 0; } - if (! $pcgnumber) $pcgnumber="51"; + if (! $this->ref) + { + $this->error=$langs->trans("ErrorFieldRequired",$langs->trans("Ref")); + return -1; + } - $sql = "INSERT INTO ".MAIN_DB_PREFIX."bank_account (datec, label, account_number) values (now(),'" . addslashes($this->label) . "','$pcgnumber');"; + $sql = "INSERT INTO ".MAIN_DB_PREFIX."bank_account (datec, ref, label, account_number) values (now(),'" . addslashes($this->ref) . "', '" . addslashes($this->label) . "','" . addslashes($this->account_number) . "');"; $resql=$this->db->query($sql); if ($resql) { @@ -296,24 +304,36 @@ class Account } /* - * \brief Mise a jour compte - * \param user Object utilisateur qui modifie + * \brief Mise a jour compte + * \param user Object utilisateur qui modifie + * \return int <0 si ko, >0 si ok */ function update($user='') { + global $langs; + // Chargement librairie pour acces fonction controle RIB - require_once DOL_DOCUMENT_ROOT . '/compta/bank/bank.lib.php'; + require_once(DOL_DOCUMENT_ROOT . '/compta/bank/bank.lib.php'); + // Verification parametres if (! verif_rib($this->code_banque,$this->code_guichet,$this->number,$this->cle_rib,$this->iban_prefix)) { $this->error="Le contrôle de la clé indique que les informations de votre compte bancaire sont incorrectes."; return 0; } + if (! $this->ref) + { + $this->error=$langs->trans("ErrorFieldRequired",$langs->trans("Ref")); + return -1; + } if (! $this->label) $this->label = "???"; + $this->account_number=trim($this->account_number); + $sql = "UPDATE ".MAIN_DB_PREFIX."bank_account SET "; - $sql .= " bank = '" .addslashes($this->bank)."'"; + $sql .= " bank = '".addslashes($this->bank)."'"; + $sql .= ",ref = '".addslashes($this->ref)."'"; $sql .= ",label = '".addslashes($this->label)."'"; $sql .= ",code_banque='".$this->code_banque."'"; @@ -328,6 +348,7 @@ class Account $sql .= ",courant = ".$this->courant; $sql .= ",clos = ".$this->clos; $sql .= ",rappro = ".$this->rappro; + $sql .= ",account_number = '".$this->account_number."'"; $sql .= " WHERE rowid = ".$this->id; @@ -351,8 +372,11 @@ class Account function fetch($id) { $this->id = $id; - $sql = "SELECT rowid, label, bank, number, courant, clos, rappro,"; - $sql.= " code_banque, code_guichet, cle_rib, bic, iban_prefix, domiciliation, proprio, adresse_proprio FROM ".MAIN_DB_PREFIX."bank_account"; + $sql = "SELECT rowid, ref, label, bank, number, courant, clos, rappro,"; + $sql.= " code_banque, code_guichet, cle_rib, bic, iban_prefix,"; + $sql.= " domiciliation, proprio, adresse_proprio,"; + $sql.= " account_number"; + $sql.= " FROM ".MAIN_DB_PREFIX."bank_account"; $sql.= " WHERE rowid = ".$id; $result = $this->db->query($sql); @@ -363,6 +387,7 @@ class Account { $obj = $this->db->fetch_object($result); + $this->ref = $obj->ref; $this->label = $obj->label; $this->type = $obj->courant; $this->courant = $obj->courant; @@ -379,6 +404,8 @@ class Account $this->domiciliation = $obj->domiciliation; $this->proprio = $obj->proprio; $this->adresse_proprio = $obj->adresse_proprio; + + $this->account_number = $obj->account_number; } $this->db->free($result); } @@ -407,7 +434,61 @@ class Account } - /* + /** + * \brief Retourne le libellé du statut d'une facture (brouillon, validée, abandonnée, payée) + * \param mode 0=libellé long, 1=libellé court, 2=Picto + Libellé court, 3=Picto, 4=Picto + Libellé long + * \return string Libelle + */ + function getLibStatut($mode=0) + { + return $this->LibStatut($this->clos,$mode); + } + + /** + * \brief Renvoi le libellé d'un statut donné + * \param statut Id statut + * \param mode 0=libellé long, 1=libellé court, 2=Picto + Libellé court, 3=Picto, 4=Picto + Libellé long, 5=Libellé court + Picto + * \return string Libellé du statut + */ + function LibStatut($statut,$mode=0) + { + global $langs; + $langs->load('banks'); + + if ($mode == 0) + { + if ($statut==0) return $langs->trans("StatusAccountOpened"); + if ($statut==1) return $langs->trans("StatusAccountClosed"); + } + if ($mode == 1) + { + if ($statut==0) return $langs->trans("StatusAccountOpened"); + if ($statut==1) return $langs->trans("StatusAccountClosed"); + } + if ($mode == 2) + { + if ($statut==0) return img_picto($langs->trans("StatusAccountOpened"),'statut4').' '.$langs->trans("StatusAccountOpened"); + if ($statut==1) return img_picto($langs->trans("StatusAccountClosed"),'statut5').' '.$langs->trans("StatusAccountClosed"); + } + if ($mode == 3) + { + if ($statut==0) return img_picto($langs->trans("StatusAccountOpened"),'statut4'); + if ($statut==1) return img_picto($langs->trans("StatusAccountClosed"),'statut5'); + } + if ($mode == 4) + { + if ($statut==0) return img_picto($langs->trans("StatusAccountOpened"),'statut4').' '.$langs->trans("StatusAccountOpened"); + if ($statut==1) return img_picto($langs->trans("StatusAccountClosed"),'statut5').' '.$langs->trans("StatusAccountClosed"); + } + if ($mode == 5) + { + if ($statut==0) return $langs->trans("StatusAccountOpened").' '.img_picto($langs->trans("StatusAccountOpened"),'statut4'); + if ($statut==1) return $langs->trans("StatusAccountClosed").' '.img_picto($langs->trans("StatusAccountClosed"),'statut5'); + } + } + + + /* * \brief Renvoi si un compte peut etre supprimer ou non (sans mouvements) * \return boolean vrai si peut etre supprimé, faux sinon */ @@ -443,7 +524,8 @@ class Account */ function solde() { - $sql = "SELECT sum(amount) FROM ".MAIN_DB_PREFIX."bank WHERE fk_account=$this->id AND dateo <=" . $this->db->idate(time() ); + $sql = "SELECT sum(amount) FROM ".MAIN_DB_PREFIX."bank"; + $sql.= " WHERE fk_account=$this->id AND dateo <=" . $this->db->idate(time() ); $result = $this->db->query($sql); diff --git a/htdocs/compta/bank/fiche.php b/htdocs/compta/bank/fiche.php index 1bd7a8759fa..25ec476e723 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-2005 Laurent Destailleur + * Copyright (C) 2004-2006 Laurent Destailleur * * 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 @@ -46,6 +46,7 @@ if ($_POST["action"] == 'add') // Creation compte $account = new Account($db,0); + $account->ref = ereg_replace(' ','',trim($_POST["ref"])); $account->label = trim($_POST["label"]); $account->courant = $_POST["type"]; $account->clos = $_POST["clos"]; @@ -58,10 +59,12 @@ if ($_POST["action"] == 'add') $account->cle_rib = $_POST["cle_rib"]; $account->bic = $_POST["bic"]; $account->iban_prefix = $_POST["iban_prefix"]; - $account->domiciliation = $_POST["domiciliation"]; + $account->domiciliation = trim($_POST["domiciliation"]); - $account->proprio = $_POST["proprio"]; - $account->adresse_proprio = $_POST["adresse_proprio"]; + $account->proprio = trim($_POST["proprio"]); + $account->adresse_proprio = trim($_POST["adresse_proprio"]); + + $account->account_number = trim($_POST["account_number"]); $account->solde = $_POST["solde"]; $account->date_solde = mktime(12,0,0,$_POST["remonth"],$_POST["reday"],$_POST["reyear"]); @@ -87,12 +90,13 @@ if ($_POST["action"] == 'update' && ! $_POST["cancel"]) $account = new Account($db, $_POST["id"]); $account->fetch($_POST["id"]); + $account->ref = ereg_replace(' ','',trim($_POST["ref"])); $account->label = trim($_POST["label"]); $account->courant = $_POST["type"]; $account->clos = $_POST["clos"]; $account->rappro = (isset($_POST["norappro"]) && $_POST["norappro"]=='on')?0:1; - $account->bank = $_POST["bank"]; + $account->bank = trim($_POST["bank"]); $account->code_banque = $_POST["code_banque"]; $account->code_guichet = $_POST["code_guichet"]; $account->number = $_POST["number"]; @@ -100,9 +104,12 @@ if ($_POST["action"] == 'update' && ! $_POST["cancel"]) $account->bic = $_POST["bic"]; $account->iban_prefix = $_POST["iban_prefix"]; $account->domiciliation = $_POST["domiciliation"]; + $account->proprio = $_POST["proprio"]; $account->adresse_proprio = $_POST["adresse_proprio"]; + $account->account_number = trim($_POST["account_number"]); + if ($account->label) { $result = $account->update($user); @@ -144,70 +151,81 @@ $form = new Form($db); if ($_GET["action"] == 'create') { - print_titre($langs->trans("NewFinancialAccount")); - print '
'; - - if ($message) { print "$message
\n"; } + print_titre($langs->trans("NewFinancialAccount")); + print '
'; - print '
'; - print ''; - print ''; + if ($message) { print "$message
\n"; } - print ''; + print ''; + print ''; + print ''; - print ''; - print ''; + print '
'.$langs->trans("LabelBankCashAccount").'
'; - print ''; - print ''; + print ''; + print ''; - print ''; - print ''; + print ''; + print ''; - print ''; - print ''; - - print ''; + // Code compta + if ($conf->comptaexpert->enabled) + { + print ''; + print ''; + } + else + { + print ''; + } - print ''; - print ''; + print ''; + print ''; - print ''; - print ''; + print ''; + print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - - print ''; - print ''; + print ''; - print ''; - print ''; + print ''; + print ''; - print '"; + print ''; + print ''; - print ''; - print ''; + print ''; + print ''; + print ''; + print ''; + print ''; - print '"; + print ''; + print ''; - print ''; - print ''; - print '
'.$langs->trans("AccountType").''; - $form=new Form($db); - print $form->select_type_comptes_financiers(isset($_POST["type"])?$_POST["type"]:1,"type"); - print '
'.$langs->trans("LabelBankCashAccount").'
'.$langs->trans("InitialBankBalance").'
'.$langs->trans("AccountType").''; + $form=new Form($db); + print $form->select_type_comptes_financiers(isset($_POST["type"])?$_POST["type"]:1,"type"); + print '
'.$langs->trans("Date").''; $now=time(); - print '/'; - print '/'; - print ''; - print '
'.$langs->trans("IfBankAccount").'...
'.$langs->trans("AccountancyCode").'
'.$langs->trans("Conciliation").' '.$langs->trans("DisableConciliation").'
'.$langs->trans("InitialBankBalance").'
'.$langs->trans("Bank").'
'.$langs->trans("Date").''; $now=time(); + print '/'; + print '/'; + print ''; + print '
Code BanqueCode GuichetNuméroClé RIB
'.$langs->trans("IBAN").'
'.$langs->trans("IfBankAccount").'...
'.$langs->trans("BIC").'
'.$langs->trans("Conciliation").' '.$langs->trans("DisableConciliation").'
'.$langs->trans("BankAccountDomiciliation").''; - print "
'.$langs->trans("Bank").'
'.$langs->trans("BankAccountOwner").'
Code BanqueCode GuichetNuméroClé RIB
'.$langs->trans("BankAccountOwnerAddress").''; - print "
'.$langs->trans("IBAN").'
'; + print ''.$langs->trans("BIC").''; + print ''; + + print ''.$langs->trans("BankAccountDomiciliation").''; + print ""; + + print ''.$langs->trans("BankAccountOwner").''; + print ''; + + print ''.$langs->trans("BankAccountOwnerAddress").''; + print ""; + + print ''; + print ''; + print ''; } /* ************************************************************************** */ /* */ @@ -217,103 +235,114 @@ if ($_GET["action"] == 'create') else { if ($_GET["id"] && $_GET["action"] != 'edit') - { - $account = new Account($db, $_GET["id"]); - $account->fetch($_GET["id"]); - - /* - * Affichage onglets - */ - $h = 0; - - $head[$h][0] = "fiche.php?id=$account->id"; - $head[$h][1] = $langs->trans("AccountCard"); - $h++; - - dolibarr_fiche_head($head, $hselected, $langs->trans("FinancialAccount")." ".($account->number?$account->number:$account->label)); - - /* - * Confirmation de la suppression - */ - if ($_GET["action"] == 'delete') - { - $form->form_confirm($_SERVER["PHP_SELF"]."?id=$account->id",$langs->trans("DeleteAccount"),$langs->trans("ConfirmDeleteAccount"),"confirm_delete"); - print '
'; - } - - print ''; - - print ''; - print ''; - - print ''; - print ''; - - print ''; - print ''; - - print ''; - print ''; - - if ($account->type == 0 || $account->type == 1) - { - print ''; - print ''; - - print ''; - print ''; - print ''; - print ''; - print ''; - - print ''; - print ''; - - print ''; - print ''; - - print '\n"; - - print '\n"; - - print '\n"; - } - - print '
'.$langs->trans("Label").''.$account->label.'
'.$langs->trans("AccountType").''.$account->type_lib[$account->type].'
'.$langs->trans("Status").''.$account->status[$account->clos].'
'.$langs->trans("Conciliable").''; - if ($account->type == 0 || $account->type == 1) print ($account->rappro==1 ? $langs->trans("Yes") : ($langs->trans("No").' ('.$langs->trans("ConciliationDisabled").')')); - if ($account->type == 2) print $langs->trans("No").' ('.$langs->trans("CashAccount").')'; - print '
'.$langs->trans("Bank").''.$account->bank.'
Code BanqueCode GuichetNuméroClé RIB
'.$account->code_banque.''.$account->code_guichet.''.$account->number.''.$account->cle_rib.'
'.$langs->trans("IBAN").''.$account->iban_prefix.'
'.$langs->trans("BIC").''.$account->bic.'
'.$langs->trans("BankAccountDomiciliation").''; - print nl2br($account->domiciliation); - print "
'.$langs->trans("BankAccountOwner").''; - print $account->proprio; - print "
'.$langs->trans("BankAccountOwnerAddress").''; - print nl2br($account->adresse_proprio); - print "
'; - - print ''; - - - /* - * Barre d'actions - * - */ - print '
'; - - if ($user->rights->banque->configurer) { - print ''.$langs->trans("Edit").''; + $account = new Account($db, $_GET["id"]); + $account->fetch($_GET["id"]); + + /* + * Affichage onglets + */ + $h = 0; + + $head[$h][0] = "fiche.php?id=$account->id"; + $head[$h][1] = $langs->trans("AccountCard"); + $h++; + + dolibarr_fiche_head($head, $hselected, $langs->trans("FinancialAccount")); + + /* + * Confirmation de la suppression + */ + if ($_GET["action"] == 'delete') + { + $form->form_confirm($_SERVER["PHP_SELF"]."?id=$account->id",$langs->trans("DeleteAccount"),$langs->trans("ConfirmDeleteAccount"),"confirm_delete"); + print '
'; + } + + print ''; + + // Ref + print ''; + print ''; + + print ''; + print ''; + + print ''; + print ''; + + print ''; + print ''; + + print ''; + print ''; + + // Code compta + if ($conf->comptaexpert->enabled) + { + print ''; + print ''; + } + + if ($account->type == 0 || $account->type == 1) + { + print ''; + print ''; + + print ''; + print ''; + print ''; + print ''; + print ''; + + print ''; + print ''; + + print ''; + print ''; + + print '\n"; + + print '\n"; + + print '\n"; + } + + print '
'.$langs->trans("Ref").''.$account->ref.'
'.$langs->trans("Label").''.$account->label.'
'.$langs->trans("AccountType").''.$account->type_lib[$account->type].'
'.$langs->trans("Status").''.$account->getLibStatut(4).'
'.$langs->trans("Conciliable").''; + if ($account->type == 0 || $account->type == 1) print ($account->rappro==1 ? $langs->trans("Yes") : ($langs->trans("No").' ('.$langs->trans("ConciliationDisabled").')')); + if ($account->type == 2) print $langs->trans("No").' ('.$langs->trans("CashAccount").')'; + print '
'.$langs->trans("AccountancyCode").''.$account->account_number.'
'.$langs->trans("Bank").''.$account->bank.'
Code BanqueCode GuichetNuméroClé RIB
'.$account->code_banque.''.$account->code_guichet.''.$account->number.''.$account->cle_rib.'
'.$langs->trans("IBAN").''.$account->iban_prefix.'
'.$langs->trans("BIC").''.$account->bic.'
'.$langs->trans("BankAccountDomiciliation").''; + print nl2br($account->domiciliation); + print "
'.$langs->trans("BankAccountOwner").''; + print $account->proprio; + print "
'.$langs->trans("BankAccountOwnerAddress").''; + print nl2br($account->adresse_proprio); + print "
'; + + print '
'; + + + /* + * Barre d'actions + * + */ + print '
'; + + if ($user->rights->banque->configurer) + { + print ''.$langs->trans("Edit").''; + } + + $canbedeleted=$account->can_be_deleted(); // Renvoi vrai si compte sans mouvements + if ($user->rights->banque->configurer && $canbedeleted) + { + print ''.$langs->trans("Delete").''; + } + + print '
'; + } - $canbedeleted=$account->can_be_deleted(); // Renvoi vrai si compte sans mouvements - if ($user->rights->banque->configurer && $canbedeleted) - { - print ''.$langs->trans("Delete").''; - } - - print ''; - - } - /* ************************************************************************** */ /* */ /* Edition */ @@ -336,6 +365,10 @@ else print ''; + // Ref + print ''; + print ''; + print ''; print ''; @@ -355,6 +388,17 @@ else if ($account->type == 2) print $langs->trans("No").' ('.$langs->trans("CashAccount").')'; print ''; + // Code compta + if ($conf->comptaexpert->enabled) + { + print ''; + print ''; + } + else + { + print ''; + } + if ($account->type == 0 || $account->type == 1) { print ''; diff --git a/mysql/migration/2.0.0-2.1.0.sql b/mysql/migration/2.0.0-2.1.0.sql index 1a2cedeb29c..1b5b22da743 100644 --- a/mysql/migration/2.0.0-2.1.0.sql +++ b/mysql/migration/2.0.0-2.1.0.sql @@ -103,6 +103,9 @@ update llx_const set name='SOCIETE_FISCAL_MONTH_START' where name='FISCAL_MONTH_ update llx_const set visible=0 where name='FACTURE_DISABLE_RECUR'; update llx_const set visible=0 where name='MAILING_EMAIL_FROM'; +insert into llx_const(name,value,type,visible,note) values('MAIN_SHOW_DEVELOPMENT_MODULES','0','yesno',1,'Make development modules visible'); + + alter table llx_paiementfourn add statut smallint(6) NOT NULL DEFAULT 0; @@ -224,4 +227,7 @@ insert into llx_c_type_contact(rowid, element, source, code, libelle, active ) v insert into llx_c_type_contact(rowid, element, source, code, libelle, active ) values (100, 'commande', 'external', 'BILLING', 'Contact client facturation commande', 1); insert into llx_c_type_contact(rowid, element, source, code, libelle, active ) values (101, 'commande', 'external', 'CUSTOMER', 'Contact client suivi commande', 1); -insert into llx_c_pays (rowid,code,libelle) values (30, 'SG', 'Singapoure'); \ No newline at end of file +insert into llx_c_pays (rowid,code,libelle) values (30, 'SG', 'Singapoure'); + + +alter table llx_bank_account add column ref varchar(12) NOT NULL; diff --git a/mysql/tables/llx_bank_account.sql b/mysql/tables/llx_bank_account.sql index d30c897ef14..ef286113828 100644 --- a/mysql/tables/llx_bank_account.sql +++ b/mysql/tables/llx_bank_account.sql @@ -30,7 +30,8 @@ create table llx_bank_account rowid integer AUTO_INCREMENT PRIMARY KEY, datec datetime, tms timestamp, - label varchar(30), + ref varchar(12) NOT NULL, + label varchar(30) NOT NULL, bank varchar(60), code_banque varchar(7), code_guichet varchar(6),
'.$langs->trans("Ref").'
'.$langs->trans("Label").'
'.$langs->trans("AccountancyCode").'
'.$langs->trans("Bank").'