Merge branch '5.0' of git@github.com:Dolibarr/dolibarr.git into develop

This commit is contained in:
Laurent Destailleur 2017-02-27 12:15:31 +01:00
commit 821324868a
9 changed files with 148 additions and 43 deletions

View File

@ -526,7 +526,17 @@ class Categorie extends CommonObject
} }
if (! $error) if (! $error)
{ {
$sql = "DELETE FROM ".MAIN_DB_PREFIX."categorie_project"; $sql = "DELETE FROM ".MAIN_DB_PREFIX."categorie_contact";
$sql .= " WHERE fk_categorie = ".$this->id;
if (!$this->db->query($sql))
{
$this->error=$this->db->lasterror();
$error++;
}
}
if (! $error)
{
$sql = "DELETE FROM ".MAIN_DB_PREFIX."categorie_account";
$sql .= " WHERE fk_categorie = ".$this->id; $sql .= " WHERE fk_categorie = ".$this->id;
if (!$this->db->query($sql)) if (!$this->db->query($sql))
{ {
@ -535,7 +545,18 @@ class Categorie extends CommonObject
$error++; $error++;
} }
} }
if (! $error)
{
$sql = "DELETE FROM ".MAIN_DB_PREFIX."bank_class";
$sql .= " WHERE fk_categ = ".$this->id;
if (!$this->db->query($sql))
{
$this->error=$this->db->lasterror();
dol_syslog("Error sql=".$sql." ".$this->error, LOG_ERR);
$error++;
}
}
if (! $error) if (! $error)
{ {
$sql = "DELETE FROM ".MAIN_DB_PREFIX."categorie_lang"; $sql = "DELETE FROM ".MAIN_DB_PREFIX."categorie_lang";

View File

@ -62,6 +62,7 @@ $extrafields = new ExtraFields($db);
$extralabels=$extrafields->fetch_name_optionals_label($object->table_element); $extralabels=$extrafields->fetch_name_optionals_label($object->table_element);
/* /*
* Actions * Actions
*/ */
@ -152,6 +153,7 @@ if ($action == 'add')
else { else {
$error++; $error++;
setEventMessages($object->error, $object->errors, 'errors'); setEventMessages($object->error, $object->errors, 'errors');
$action='create'; // Force chargement page en mode creation $action='create'; // Force chargement page en mode creation
} }
} }
@ -247,15 +249,24 @@ if ($action == 'update')
} }
} }
if ($_POST["action"] == 'confirm_delete' && $_POST["confirm"] == "yes" && $user->rights->banque->configurer) if ($action == 'confirm_delete' && $_POST["confirm"] == "yes" && $user->rights->banque->configurer)
{ {
// Delete // Delete
$object = new Account($db); $object = new Account($db);
$object->fetch(GETPOST("id","int")); $object->fetch(GETPOST("id","int"));
$object->delete(); $result = $object->delete($user);
header("Location: ".DOL_URL_ROOT."/compta/bank/index.php"); if ($result > 0)
exit; {
setEventMessages($langs->trans("RecordDeleted"), null, 'mesgs');
header("Location: ".DOL_URL_ROOT."/compta/bank/index.php");
exit;
}
else
{
setEventMessages($account->error, $account->errors, 'errors');
$action='';
}
} }

View File

@ -72,6 +72,7 @@ if ($categid) {
} }
} }
/* /*
* View * View
*/ */

View File

@ -385,7 +385,7 @@ class Account extends CommonObject
/** /**
* Add an entry into table ".MAIN_DB_PREFIX."bank * Add an entry into table ".MAIN_DB_PREFIX."bank
* *
* @param int $date Date operation * @param int $date Date operation
* @param string $oper 1,2,3,4... (deprecated) or TYP,VIR,PRE,LIQ,VAD,CB,CHQ... * @param string $oper 1,2,3,4... (deprecated) or TYP,VIR,PRE,LIQ,VAD,CB,CHQ...
* @param string $label Descripton * @param string $label Descripton
* @param float $amount Amount * @param float $amount Amount
@ -602,6 +602,7 @@ class Account extends CommonObject
$accline->datec = $this->db->idate($now); $accline->datec = $this->db->idate($now);
$accline->label = '('.$langs->trans("InitialBankBalance").')'; $accline->label = '('.$langs->trans("InitialBankBalance").')';
$accline->amount = price2num($this->solde); $accline->amount = price2num($this->solde);
$accline->fk_user_author = $user->id;
$accline->fk_account = $this->id; $accline->fk_account = $this->id;
$accline->datev = $this->db->idate($this->date_solde); $accline->datev = $this->db->idate($this->date_solde);
$accline->dateo = $this->db->idate($this->date_solde); $accline->dateo = $this->db->idate($this->date_solde);
@ -609,6 +610,8 @@ class Account extends CommonObject
if ($accline->insert() < 0) { if ($accline->insert() < 0) {
$error++; $error++;
$this->error = $accline->error;
$this->errors = $accline->errors;
} }
if (! $error) if (! $error)
@ -980,29 +983,59 @@ class Account extends CommonObject
{ {
global $conf; global $conf;
$sql = "DELETE FROM ".MAIN_DB_PREFIX."bank_account"; $error=0;
$sql.= " WHERE rowid = ".$this->rowid;
$sql.= " AND entity = ".$conf->entity; $this->db->begin();
dol_syslog(get_class($this)."::delete", LOG_DEBUG); // Delete link between tag and bank account
$result = $this->db->query($sql); if (! $error)
if ($result) { {
$sql = "DELETE FROM ".MAIN_DB_PREFIX."categorie_account";
// Remove extrafields $sql.= " WHERE fk_account = ".$this->id;
if ((empty($conf->global->MAIN_EXTRAFIELDS_DISABLED))) // For avoid conflicts if trigger used
{ $resql = $this->db->query($sql);
$result=$this->deleteExtraFields(); if (!$resql)
if ($result < 0) {
{ $error++;
dol_syslog(get_class($this)."::delete error -4 ".$this->error, LOG_ERR); $this->error = "Error ".$this->db->lasterror();
return -1; }
} }
}
if (! $error)
{
$sql = "DELETE FROM ".MAIN_DB_PREFIX."bank_account";
$sql.= " WHERE rowid = ".$this->rowid;
dol_syslog(get_class($this)."::delete", LOG_DEBUG);
$result = $this->db->query($sql);
if ($result)
{
// Remove extrafields
if ((empty($conf->global->MAIN_EXTRAFIELDS_DISABLED))) // For avoid conflicts if trigger used
{
$result=$this->deleteExtraFields();
if ($result < 0)
{
$error++;
dol_syslog(get_class($this)."::delete error -4 ".$this->error, LOG_ERR);
}
}
}
else
{
$error++;
$this->error = "Error ".$this->db->lasterror();
}
}
if (! $error)
{
$this->db->commit();
return 1; return 1;
} }
else { else
dol_print_error($this->db); {
$this->db->rollback();
return -1; return -1;
} }
} }

View File

@ -188,29 +188,60 @@ class BankCateg // extends CommonObject
/** /**
* Delete object in database * Delete object in database
* *
* @param User $user User that delete * @param User $user User that delete
* @param int $notrigger 0=launch triggers after, 1=disable triggers * @param int $notrigger 0=launch triggers after, 1=disable triggers
* @return int <0 if KO, >0 if OK * @return int <0 if KO, >0 if OK
*/ */
public function delete(User $user, $notrigger = 0) public function delete(User $user, $notrigger = 0)
{ {
global $conf; global $conf;
$error = 0; $error = 0;
$sql = "DELETE FROM ".MAIN_DB_PREFIX."bank_categ";
$sql .= " WHERE rowid=".$this->id;
$sql .= " AND entity = ".$conf->entity;
$this->db->begin(); $this->db->begin();
dol_syslog(get_class($this)."::delete", LOG_DEBUG); // Delete link between tag and bank account
$resql = $this->db->query($sql); if (! $error)
if (!$resql) { {
$error++; $sql = "DELETE FROM ".MAIN_DB_PREFIX."categorie_account";
$this->errors[] = "Error ".$this->db->lasterror(); $sql.= " WHERE fk_categorie = ".$this->id;
$resql = $this->db->query($sql);
if (!$resql)
{
$error++;
$this->errors[] = "Error ".$this->db->lasterror();
}
} }
// Commit or rollback // Delete link between tag and bank lines
if (! $error)
{
$sql = "DELETE FROM ".MAIN_DB_PREFIX."bank_class";
$sql.= " WHERE fk_categ = ".$this->id;
$resql = $this->db->query($sql);
if (!$resql)
{
$error++;
$this->errors[] = "Error ".$this->db->lasterror();
}
}
// Delete bank categ
if (! $error)
{
$sql = "DELETE FROM ".MAIN_DB_PREFIX."bank_categ";
$sql .= " WHERE rowid=".$this->id;
$resql = $this->db->query($sql);
if (!$resql)
{
$error++;
$this->errors[] = "Error ".$this->db->lasterror();
}
}
// Commit or rollback
if ($error) { if ($error) {
foreach ($this->errors as $errmsg) { foreach ($this->errors as $errmsg) {
dol_syslog(get_class($this)."::delete ".$errmsg, LOG_ERR); dol_syslog(get_class($this)."::delete ".$errmsg, LOG_ERR);

View File

@ -1,5 +1,5 @@
-- =================================================================== -- ===================================================================
-- Copyright (C) 2004-2007 Laurent Destailleur <eldy@users.sourceforge.net> -- Copyright (C) 2004-2017 Laurent Destailleur <eldy@users.sourceforge.net>
-- --
-- This program is free software; you can redistribute it and/or modify -- 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 -- it under the terms of the GNU General Public License as published by
@ -14,6 +14,7 @@
-- You should have received a copy of the GNU General Public License -- You should have received a copy of the GNU General Public License
-- along with this program. If not, see <http://www.gnu.org/licenses/>. -- along with this program. If not, see <http://www.gnu.org/licenses/>.
-- --
-- Table to link bank tag/categories with bank lines
-- =================================================================== -- ===================================================================
create table llx_bank_class create table llx_bank_class

View File

@ -15,6 +15,7 @@
-- You should have received a copy of the GNU General Public License -- You should have received a copy of the GNU General Public License
-- along with this program. If not, see <http://www.gnu.org/licenses/>. -- along with this program. If not, see <http://www.gnu.org/licenses/>.
-- --
-- Table to link bank tag/categories with bank accounts
-- =========================================================================== -- ===========================================================================
CREATE TABLE llx_categorie_account CREATE TABLE llx_categorie_account

View File

@ -1502,6 +1502,9 @@ div#login_left, div#login_right {
text-align: center; text-align: center;
vertical-align: middle; vertical-align: middle;
} }
div#login_right select#entity {
margin-top: 10px;
}
table.login_table tr td table.none tr td { table.login_table tr td table.none tr td {
padding: 2px; padding: 2px;
} }

View File

@ -1508,6 +1508,9 @@ div#login_left, div#login_right {
text-align: center; text-align: center;
vertical-align: middle; vertical-align: middle;
} }
div#login_right select#entity {
margin-top: 10px;
}
table.login_table tr td table.none tr td { table.login_table tr td table.none tr td {
padding: 2px; padding: 2px;
} }