Les fonctions de suppression du compte banquaire passent par une classe delete.

This commit is contained in:
Laurent Destailleur 2007-06-01 20:32:35 +00:00
parent d2cc4a0881
commit 3bbadca803
6 changed files with 75 additions and 55 deletions

View File

@ -91,42 +91,8 @@ class Account
return 1; return 1;
} }
/**
* \brief Efface une entree dans la table ".MAIN_DB_PREFIX."bank
* \param rowid Id de l'ecriture a effacer
* \return int <0 si ko, >0 si ok
*/
function deleteline($rowid)
{
$nbko=0;
$this->db->begin();
$sql = "DELETE FROM ".MAIN_DB_PREFIX."bank_class WHERE lineid=".$rowid;
$result = $this->db->query($sql);
if (! $result) $nbko++;
$sql = "DELETE FROM ".MAIN_DB_PREFIX."bank WHERE rowid=".$rowid; /**
$result = $this->db->query($sql);
if (! $result) $nbko++;
$sql = "DELETE FROM ".MAIN_DB_PREFIX."bank_url WHERE fk_bank=".$rowid;
$result = $this->db->query($sql);
if (! $result) $nbko++;
if (! $nbko)
{
$this->db->commit();
return 1;
}
else
{
$this->db->rollback();
return -$nbko;
}
}
/**
* \brief Ajoute lien entre ecriture bancaire et sources * \brief Ajoute lien entre ecriture bancaire et sources
* \param line_id Id ecriture bancaire * \param line_id Id ecriture bancaire
* \param url_id Id parametre url * \param url_id Id parametre url
@ -140,6 +106,7 @@ class Account
$sql = "INSERT INTO ".MAIN_DB_PREFIX."bank_url (fk_bank, url_id, url, label, type)"; $sql = "INSERT INTO ".MAIN_DB_PREFIX."bank_url (fk_bank, url_id, url, label, type)";
$sql .= " VALUES ('$line_id', '$url_id', '$url', '$label', '$type')"; $sql .= " VALUES ('$line_id', '$url_id', '$url', '$label', '$type')";
dolibarr_syslog("Account::add_url_line sql=".$sql);
if ($this->db->query($sql)) if ($this->db->query($sql))
{ {
$rowid = $this->db->last_insert_id(MAIN_DB_PREFIX."bank_url"); $rowid = $this->db->last_insert_id(MAIN_DB_PREFIX."bank_url");
@ -528,6 +495,8 @@ class Account
{ {
$sql = "DELETE FROM ".MAIN_DB_PREFIX."bank_account"; $sql = "DELETE FROM ".MAIN_DB_PREFIX."bank_account";
$sql .= " WHERE rowid = ".$this->rowid; $sql .= " WHERE rowid = ".$this->rowid;
dolibarr_syslog("Account::delete sql=".$sql);
$result = $this->db->query($sql); $result = $this->db->query($sql);
if ($result) { if ($result) {
return 1; return 1;
@ -761,6 +730,9 @@ class AccountLine
{ {
var $db; var $db;
var $rappro;
/** /**
* Constructeur * Constructeur
*/ */
@ -785,6 +757,7 @@ class AccountLine
$sql.= " FROM ".MAIN_DB_PREFIX."bank"; $sql.= " FROM ".MAIN_DB_PREFIX."bank";
$sql.= " WHERE rowid = ".$rowid; $sql.= " WHERE rowid = ".$rowid;
dolibarr_syslog("AccountLine::fetch sql=".$sql);
$result = $this->db->query($sql); $result = $this->db->query($sql);
if ($result) if ($result)
{ {
@ -820,6 +793,51 @@ class AccountLine
} }
/**
* \brief Efface ligne bancaire
* \return int <0 si KO, >0 si OK
*/
function delete()
{
$nbko=0;
if ($this->rappro)
{
// Protection pour eviter tout suppression d'une ligne consolidée
$this->error="DeleteNotPossibleLineIsConsolidated";
return -1;
}
$this->db->begin();
$sql = "DELETE FROM ".MAIN_DB_PREFIX."bank_class WHERE lineid=".$this->rowid;
dolibarr_syslog("AccountLine::delete sql=".$sql);
$result = $this->db->query($sql);
if (! $result) $nbko++;
$sql = "DELETE FROM ".MAIN_DB_PREFIX."bank_url WHERE fk_bank=".$this->rowid;
dolibarr_syslog("AccountLine::delete sql=".$sql);
$result = $this->db->query($sql);
if (! $result) $nbko++;
$sql = "DELETE FROM ".MAIN_DB_PREFIX."bank WHERE rowid=".$this->rowid;
dolibarr_syslog("AccountLine::delete sql=".$sql);
$result = $this->db->query($sql);
if (! $result) $nbko++;
if (! $nbko)
{
$this->db->commit();
return 1;
}
else
{
$this->db->rollback();
return -$nbko;
}
}
/** /**
* \brief Charge les informations d'ordre info dans l'objet facture * \brief Charge les informations d'ordre info dans l'objet facture
* \param id Id de la facture a charger * \param id Id de la facture a charger

View File

@ -97,9 +97,9 @@ if ($_POST["action"] == 'add' && $account && ! isset($_POST["cancel"]) && $user-
} }
if ($_POST["action"] == 'confirm_delete' && $_POST["confirm"]=='yes' && $user->rights->banque->modifier) if ($_POST["action"] == 'confirm_delete' && $_POST["confirm"]=='yes' && $user->rights->banque->modifier)
{ {
$acct=new Account($db); $accline=new AccountLine($db);
$acct->id=$account; $accline->fetch($_GET["rowid"]);
$result=$acct->deleteline($_GET["rowid"]); $result=$accline->delete();
} }

View File

@ -96,10 +96,12 @@ if ($user->rights->banque->consolidate && $_POST["action"] == 'rappro')
*/ */
if ($_GET["action"] == 'del') if ($_GET["action"] == 'del')
{ {
$sql = "DELETE FROM ".MAIN_DB_PREFIX."bank WHERE rowid=".$_GET["rowid"]; $accline=new AccountLine($db);
$resql = $db->query($sql); $accline->fetch($_GET["rowid"]);
if (! $resql) { $result=$accline->delete();
dolibarr_print_error($db); if ($result < 0)
{
dolibarr_print_error($db,$accline->error);
} }
} }

View File

@ -262,14 +262,15 @@ class PaiementFourn
// Supprimer l'écriture bancaire si paiement lié à écriture // Supprimer l'écriture bancaire si paiement lié à écriture
if ($bank_line_id) if ($bank_line_id)
{ {
$acc = new Account($this->db); $accline = new AccountLine($this->db);
$result=$acc->deleteline($bank_line_id); $accline->fetch($bank_line_id);
if ($result < 0) $result=$accline->delete();
{ if ($result < 0)
$this->error=$acc->error; {
$this->db->rollback(); $this->error=$accline->error;
return -4; $this->db->rollback();
} return -4;
}
} }
$this->db->commit(); $this->db->commit();
return 1; return 1;

View File

@ -117,7 +117,6 @@ if (isset($_POST['action']) && $_POST['action'] == 'upgrade')
* Pour PHP_WriteExcel: PHP_WRITEEXCEL_PATH * Pour PHP_WriteExcel: PHP_WRITEEXCEL_PATH
* Pour MagpieRss: MAGPIERSS_PATH * Pour MagpieRss: MAGPIERSS_PATH
* Pour PHPlot: PHPLOT_PATH * Pour PHPlot: PHPLOT_PATH
* Pour JPGraph: JPGRAPH_PATH
* Pour NuSOAP: NUSOAP_PATH * Pour NuSOAP: NUSOAP_PATH
* Pour TCPDF: TCPDF_PATH * Pour TCPDF: TCPDF_PATH
*/ */
@ -126,7 +125,6 @@ if (isset($_POST['action']) && $_POST['action'] == 'upgrade')
if (! defined('PHP_WRITEEXCEL_PATH')) { define('PHP_WRITEEXCEL_PATH',DOL_DOCUMENT_ROOT .'/includes/php_writeexcel/'); } if (! defined('PHP_WRITEEXCEL_PATH')) { define('PHP_WRITEEXCEL_PATH',DOL_DOCUMENT_ROOT .'/includes/php_writeexcel/'); }
if (! defined('MAGPIERSS_PATH')) { define('MAGPIERSS_PATH', DOL_DOCUMENT_ROOT .'/includes/magpierss/'); } if (! defined('MAGPIERSS_PATH')) { define('MAGPIERSS_PATH', DOL_DOCUMENT_ROOT .'/includes/magpierss/'); }
if (! defined('PHPLOT_PATH')) { define('PHPLOT_PATH', DOL_DOCUMENT_ROOT .'/includes/phplot/'); } if (! defined('PHPLOT_PATH')) { define('PHPLOT_PATH', DOL_DOCUMENT_ROOT .'/includes/phplot/'); }
if (! defined('JPGRAPH_PATH')) { define('JPGRAPH_PATH', DOL_DOCUMENT_ROOT .'/includes/jpgraph/'); }
if (! defined('NUSOAP_PATH')) { define('NUSOAP_PATH', DOL_DOCUMENT_ROOT .'/includes/nusoap/lib/'); } if (! defined('NUSOAP_PATH')) { define('NUSOAP_PATH', DOL_DOCUMENT_ROOT .'/includes/nusoap/lib/'); }
if (! defined('TCPDF_PATH')) { define('TCPDF_PATH', DOL_DOCUMENT_ROOT .'/includes/fpdf/tcpdf/'); } if (! defined('TCPDF_PATH')) { define('TCPDF_PATH', DOL_DOCUMENT_ROOT .'/includes/fpdf/tcpdf/'); }
// Les autres path // Les autres path

View File

@ -269,11 +269,12 @@ class Paiement
// Supprimer l'écriture bancaire si paiement lié à écriture // Supprimer l'écriture bancaire si paiement lié à écriture
if ($bank_line_id) if ($bank_line_id)
{ {
$acc = new Account($this->db); $accline = new AccountLine($this->db);
$result=$acc->deleteline($bank_line_id); $accline->fetch($bank_line_id);
$result=$accline->delete();
if ($result < 0) if ($result < 0)
{ {
$this->error=$acc->error; $this->error=$accline->error;
$this->db->rollback(); $this->db->rollback();
return -4; return -4;
} }