Fix: bug #33918 : Écriture bancaire fantôme

This commit is contained in:
Laurent Destailleur 2011-08-05 21:05:19 +00:00
parent e6b1143daa
commit 1bcc5d148b
7 changed files with 167 additions and 68 deletions

View File

@ -23,7 +23,7 @@
* \file htdocs/compta/bank/class/account.class.php
* \ingroup banque
* \brief File of class to manage bank accounts
* \version $Id: account.class.php,v 1.33 2011/07/31 22:23:30 eldy Exp $
* \version $Id: account.class.php,v 1.34 2011/08/05 21:05:19 eldy Exp $
*/
require_once(DOL_DOCUMENT_ROOT ."/core/class/commonobject.class.php");
@ -146,7 +146,7 @@ class Account extends CommonObject
$sql.= ", '".$type."'";
$sql.= ")";
dol_syslog("Account::add_url_line sql=".$sql);
dol_syslog(get_class($this)."::add_url_line sql=".$sql);
if ($this->db->query($sql))
{
$rowid = $this->db->last_insert_id(MAIN_DB_PREFIX."bank_url");
@ -155,25 +155,37 @@ class Account extends CommonObject
else
{
$this->error=$this->db->lasterror();
dol_syslog("Account:add_url_line ".$this->error, LOG_ERR);
dol_syslog(get_class($this)."::add_url_line ".$this->error, LOG_ERR);
return -1;
}
}
/**
* Return array with links
* @param line_id Id transaction line
* TODO Move this into AccountLine
* Return array with links from llx_bank_url
* @param fk_bank To search using bank transaction id
* @param url_id To search using link to
* @param type To search using type
* @return array Array of links
*/
function get_url($line_id)
function get_url($fk_bank='', $url_id='', $type='')
{
$lines = array();
$sql = "SELECT url_id, url, label, type";
// Check parameters
if (! empty($fk_bank) && (! empty($url_id) || ! empty($type)))
{
$this->error="ErrorBadParameter";
return -1;
}
$sql = "SELECT fk_bank, url_id, url, label, type";
$sql.= " FROM ".MAIN_DB_PREFIX."bank_url";
$sql.= " WHERE fk_bank = ".$line_id;
if ($fk_bank > 0) { $sql.= " WHERE fk_bank = ".$fk_bank; }
else { $sql.= " WHERE url_id = ".$url_id." AND type = '".$type."'"; }
$sql.= " ORDER BY type, label";
dol_syslog(get_class($this)."::get_url sql=".$sql);
$result = $this->db->query($sql);
if ($result)
{
@ -192,10 +204,13 @@ class Account extends CommonObject
$lines[$i]['url_id'] = $obj->url_id;
$lines[$i]['label'] = $obj->label;
$lines[$i]['type'] = $obj->type;
$lines[$i]['fk_bank'] = $obj->fk_bank;
$i++;
}
return $lines;
}
else dol_print_error($this->db);
return $lines;
}
/**
@ -779,11 +794,11 @@ class Account extends CommonObject
{
$obj=$this->db->fetch_object($resql);
$newdate=$this->db->jdate($obj->datev)+(3600*24*$sign);
$sql = "UPDATE ".MAIN_DB_PREFIX."bank SET ";
$sql.= " datev = '".$this->db->idate($newdate)."'";
$sql.= " WHERE rowid = ".$rowid;
$result = $this->db->query($sql);
if ($result)
{
@ -801,7 +816,7 @@ class Account extends CommonObject
else dol_print_error($this->db);
return 0;
}
/**
* @param rowid
*/
@ -997,7 +1012,7 @@ class Account extends CommonObject
/**
* \class AccountLine
* \brief Classto manage bank transaction lines
* \brief Class to manage bank transaction lines
*/
class AccountLine extends CommonObject
{
@ -1112,7 +1127,7 @@ class AccountLine extends CommonObject
/**
* Delete bank line record
* Delete transaction bank line record
* @param user User object that delete
* @return int <0 if KO, >0 if OK
*/
@ -1129,12 +1144,14 @@ class AccountLine extends CommonObject
$this->db->begin();
$sql = "DELETE FROM ".MAIN_DB_PREFIX."bank_class WHERE lineid=".$this->rowid;
dol_syslog("AccountLine::delete sql=".$sql);
$result = $this->db->query($sql);
if (! $result) $nbko++;
// Delete urls
$result=$this->delete_urls();
if ($result < 0)
{
$nbko++;
}
$sql = "DELETE FROM ".MAIN_DB_PREFIX."bank_url WHERE fk_bank=".$this->rowid;
$sql = "DELETE FROM ".MAIN_DB_PREFIX."bank_class WHERE lineid=".$this->rowid;
dol_syslog("AccountLine::delete sql=".$sql);
$result = $this->db->query($sql);
if (! $result) $nbko++;
@ -1157,6 +1174,42 @@ class AccountLine extends CommonObject
}
/**
* Delete bank line records
* @param user User object that delete
* @return int <0 if KO, >0 if OK
*/
function delete_urls($user=0)
{
$nbko=0;
if ($this->rappro)
{
// Protection to avoid any delete of consolidated lines
$this->error="ErrorDeleteNotPossibleLineIsConsolidated";
return -1;
}
$this->db->begin();
$sql = "DELETE FROM ".MAIN_DB_PREFIX."bank_url WHERE fk_bank=".$this->rowid;
dol_syslog("AccountLine::delete_urls sql=".$sql);
$result = $this->db->query($sql);
if (! $result) $nbko++;
if (! $nbko)
{
$this->db->commit();
return 1;
}
else
{
$this->db->rollback();
return -$nbko;
}
}
/**
* Update bank account record in database
* @param user Object user making update

View File

@ -21,7 +21,7 @@
* \file htdocs/compta/paiement/class/paiement.class.php
* \ingroup facture
* \brief File of class to manage payments of customers invoices
* \version $Id: paiement.class.php,v 1.22 2011/08/03 00:46:39 eldy Exp $
* \version $Id: paiement.class.php,v 1.23 2011/08/05 21:06:55 eldy Exp $
*/
require_once(DOL_DOCUMENT_ROOT ."/core/class/commonobject.class.php");
@ -259,9 +259,9 @@ class Paiement extends CommonObject
function delete($notrigger=0)
{
global $conf, $user, $langs;
$error=0;
$bank_line_id = $this->bank_line;
$this->db->begin();
@ -273,7 +273,7 @@ class Paiement extends CommonObject
{
if (sizeof($billsarray))
{
$this->error="Impossible de supprimer un paiement portant sur au moins une facture fermee";
$this->error="ErrorDeletePaymentLinkedToAClosedInvoiceNotPossible";
$this->db->rollback();
return -1;
}
@ -284,18 +284,18 @@ class Paiement extends CommonObject
return -2;
}
// Verifier si paiement ne porte pas sur ecriture bancaire rapprochee
// Si c'est le cas, on refuse le paiement
// Delete bank urls. If payment if on a conciliated line, return error.
if ($bank_line_id)
{
$accline = new AccountLine($this->db,$bank_line_id);
$accline = new AccountLine($this->db);
$accline->fetch($bank_line_id);
if ($accline->rappro)
{
$this->error="Impossible de supprimer un paiement qui a genere une ecriture qui a ete rapprochee";
$result=$accline->delete_urls($user);
if ($result < 0)
{
$this->error=$accline->error;
$this->db->rollback();
return -3;
}
}
}
// Delete payment (into paiement_facture and paiement)
@ -309,7 +309,7 @@ class Paiement extends CommonObject
$result = $this->db->query($sql);
if (! $result)
{
$this->error=$this->db->error();
$this->error=$this->db->lasterror();
$this->db->rollback();
return -3;
}
@ -327,7 +327,7 @@ class Paiement extends CommonObject
return -4;
}
}
if (! $notrigger)
{
// Appel des triggers

View File

@ -23,7 +23,7 @@
* \ingroup facture
* \brief Page of a customer payment
* \remarks Nearly same file than fournisseur/paiement/fiche.php
* \version $Id: fiche.php,v 1.76 2011/08/03 00:46:35 eldy Exp $
* \version $Id: fiche.php,v 1.77 2011/08/05 21:06:55 eldy Exp $
*/
require("../../main.inc.php");
@ -84,7 +84,8 @@ if ($action == 'confirm_delete' && GETPOST('confirm') == 'yes' && $user->rights-
}
else
{
$mesg='<div class="error">'.$paiement->error.'</div>';
$langs->load("errors");
$mesg='<div class="error">'.$langs->trans($paiement->error).'</div>';
$db->rollback();
}
}
@ -120,7 +121,8 @@ if ($action == 'confirm_valide' && GETPOST('confirm') == 'yes' && $user->rights-
}
else
{
$mesg='<div class="error">'.$paiement->error.'</div>';
$langs->load("errors");
$mesg='<div class="error">'.$langs->trans($paiement->error).'</div>';
$db->rollback();
}
}
@ -178,7 +180,7 @@ if ($action == 'valide')
}
if ($mesg) print $mesg.'<br>';
dol_htmloutput_mesg($mesg);
print '<table class="border" width="100%">';
@ -356,5 +358,5 @@ print '</div>';
$db->close();
llxFooter('$Date: 2011/08/03 00:46:35 $ - $Revision: 1.76 $');
llxFooter('$Date: 2011/08/05 21:06:55 $ - $Revision: 1.77 $');
?>

View File

@ -1,5 +1,5 @@
<?php
/* Copyright (C) 2004-2010 Laurent Destailleur <eldy@users.sourceforge.net>
/* Copyright (C) 2004-2011 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2005-2009 Regis Houssin <regis@dolibarr.fr>
*
* This program is free software; you can redistribute it and/or modify
@ -20,7 +20,7 @@
* \file htdocs/compta/sociales/charges.php
* \ingroup tax
* \brief Social contribution car page
* \version $Id: charges.php,v 1.65 2011/07/31 22:23:20 eldy Exp $
* \version $Id: charges.php,v 1.66 2011/08/05 21:11:50 eldy Exp $
*/
require('../../main.inc.php');
@ -29,10 +29,10 @@ require(DOL_DOCUMENT_ROOT."/compta/sociales/class/chargesociales.class.php");
$langs->load("compta");
$langs->load("bills");
$chid=isset($_GET["id"])?$_GET["id"]:$_POST["id"];
$chid=GETPOST("id");
// Security check
$socid = isset($_GET["socid"])?$_GET["socid"]:'';
$socid = GETPOST("socid");
if ($user->societe_id) $socid=$user->societe_id;
$result = restrictedArea($user, 'tax', '', '', 'charges');
@ -62,7 +62,7 @@ if ($_REQUEST["action"] == 'confirm_paid' && $_REQUEST["confirm"] == 'yes')
if ($_REQUEST["action"] == 'confirm_delete' && $_REQUEST["confirm"] == 'yes')
{
$chargesociales=new ChargeSociales($db);
$chargesociales->id=$_GET["id"];
$chargesociales->fetch($chid);
$result=$chargesociales->delete($user);
if ($result > 0)
{
@ -129,8 +129,8 @@ if ($_POST["action"] == 'add' && $user->rights->tax->charges->creer)
if ($_GET["action"] == 'update' && ! $_POST["cancel"] && $user->rights->tax->charges->creer)
{
$dateech=@dol_mktime($_POST["echhour"],$_POST["echmin"],$_POST["echsec"],$_POST["echmonth"],$_POST["echday"],$_POST["echyear"]);
$dateperiod=@dol_mktime($_POST["periodhour"],$_POST["periodmin"],$_POST["periodsec"],$_POST["periodmonth"],$_POST["periodday"],$_POST["periodyear"]);
$dateech=dol_mktime($_POST["echhour"],$_POST["echmin"],$_POST["echsec"],$_POST["echmonth"],$_POST["echday"],$_POST["echyear"]);
$dateperiod=dol_mktime($_POST["periodhour"],$_POST["periodmin"],$_POST["periodsec"],$_POST["periodmonth"],$_POST["periodday"],$_POST["periodyear"]);
if (! $dateech)
{
$mesg='<div class="error">'.$langs->trans("ErrorFieldRequired",$langs->transnoentities("DateDue")).'</div>';
@ -172,10 +172,7 @@ llxHeader('',$langs->trans("SocialContribution"));
$html = new Form($db);
/*
* Mode creation
*
*/
// Mode creation
if ($_GET["action"] == 'create')
{
print_fiche_titre($langs->trans("NewSocialContribution"));
@ -251,7 +248,7 @@ if ($chid > 0)
if ($result > 0)
{
if ($mesg) print $mesg.'<br>';
dol_htmloutput_mesg($mesg);
$h = 0;
$head[$h][0] = DOL_URL_ROOT.'/compta/sociales/charges.php?id='.$cha->id;
@ -268,15 +265,13 @@ if ($chid > 0)
if ($_GET["action"] == 'paid')
{
$text=$langs->trans('ConfirmPaySocialContribution');
$ret=$html->form_confirm($_SERVER["PHP_SELF"]."?id=$cha->id&amp;action=confirm_paid",$langs->trans('PaySocialContribution'),$text,"confirm_paid");
if ($ret == 'html') print '<br>';
print $html->formconfirm($_SERVER["PHP_SELF"]."?id=".$cha->id,$langs->trans('PaySocialContribution'),$text,"confirm_paid",'','',2);
}
if ($_GET['action'] == 'delete')
{
$text=$langs->trans('ConfirmDeleteSocialContribution');
$ret=$html->form_confirm($_SERVER['PHP_SELF'].'?id='.$cha->id,$langs->trans('DeleteSocialContribution'),$text,'confirm_delete');
if ($ret == 'html') print '<br>';
print $html->formconfirm($_SERVER['PHP_SELF'].'?id='.$cha->id,$langs->trans('DeleteSocialContribution'),$text,'confirm_delete','','',2);
}
if ($_GET['action'] == 'edit')
@ -353,9 +348,9 @@ if ($chid > 0)
{
$objp = $db->fetch_object($resql);
$var=!$var;
print "<tr $bc[$var]><td>";
print "<tr ".$bc[$var]."><td>";
print '<a href="'.DOL_URL_ROOT.'/compta/payment_sc/fiche.php?id='.$objp->rowid.'">'.img_object($langs->trans("Payment"),"payment").'</a> ';
print dol_print_date($db->jdate($objp->dp))."</td>\n";
print dol_print_date($db->jdate($objp->dp),'day')."</td>\n";
print "<td>".$objp->paiement_type.' '.$objp->num_paiement."</td>\n";
print '<td align="right">'.price($objp->amount)."</td><td>&nbsp;".$langs->trans("Currency".$conf->monnaie)."</td>\n";
print "</tr>";
@ -445,7 +440,7 @@ if ($chid > 0)
}
// Delete
if ($cha->paye == 0 && $totalpaye <=0 && $user->rights->tax->charges->supprimer)
if ($user->rights->tax->charges->supprimer)
{
print "<a class=\"butActionDelete\" href=\"".DOL_URL_ROOT."/compta/sociales/charges.php?id=$cha->id&amp;action=delete\">".$langs->trans("Delete")."</a>";
}
@ -462,5 +457,5 @@ if ($chid > 0)
$db->close();
llxFooter('$Date: 2011/07/31 22:23:20 $ - $Revision: 1.65 $');
llxFooter('$Date: 2011/08/05 21:11:50 $ - $Revision: 1.66 $');
?>

View File

@ -20,7 +20,7 @@
* \file htdocs/compta/sociales/class/chargesociales.class.php
* \ingroup facture
* \brief Fichier de la classe des charges sociales
* \version $Id: chargesociales.class.php,v 1.14 2011/08/03 00:46:38 eldy Exp $
* \version $Id: chargesociales.class.php,v 1.15 2011/08/05 21:11:50 eldy Exp $
*/
require_once(DOL_DOCUMENT_ROOT."/core/class/commonobject.class.php");
@ -147,25 +147,72 @@ class ChargeSociales extends CommonObject
/**
* \brief Efface un charge sociale
* \param user Utilisateur qui cree le paiement
* \return int <0 si erreur, >0 si ok
* Delete a social contribution
* @param user Object user making delete
* @return int <0 if KO, >0 if OK
*/
function delete($user)
{
$sql = "DELETE FROM ".MAIN_DB_PREFIX."chargesociales where rowid='".$this->id."'";
$error=0;
dol_syslog("ChargesSociales::delete sql=".$sql);
$resql=$this->db->query($sql);
if ($resql)
$this->db->begin();
// Get bank transaction lines for this social contributions
include_once(DOL_DOCUMENT_ROOT."/compta/bank/class/account.class.php");
$account=new Account($this->db);
$lines_url=$account->get_url('',$this->id,'sc');
// Delete bank urls
foreach ($lines_url as $line_url)
{
if (! $error)
{
$accountline=new AccountLine($this->db);
$accountline->fetch($line_url['fk_bank']);
$result=$accountline->delete_urls($user);
if ($result < 0)
{
$error++;
}
}
}
// Delete payments
if (! $error)
{
$sql = "DELETE FROM ".MAIN_DB_PREFIX."paiementcharge where fk_charge='".$this->id."'";
dol_syslog(get_class($this)."::delete sql=".$sql);
$resql=$this->db->query($sql);
if (! $resql)
{
$error++;
$this->error=$this->db->lasterror();
}
}
if (! $error)
{
$sql = "DELETE FROM ".MAIN_DB_PREFIX."chargesociales where rowid='".$this->id."'";
dol_syslog(get_class($this)."::delete sql=".$sql);
$resql=$this->db->query($sql);
if (! $resql)
{
$error++;
$this->error=$this->db->lasterror();
}
}
if (! $error)
{
$this->db->commit();
return 1;
}
else
{
$this->error=$this->db->error();
$this->db->rollback();
return -1;
}
}

View File

@ -81,4 +81,5 @@ ErrorBadMask=Error on mask
ErrorBadMaskFailedToLocatePosOfSequence=Error, mask without sequence number
ErrorBadMaskBadRazMonth=Error, bad reset value
ErrorSelectAtLeastOne=Error. Select at least one entry.
ErrorProductWithRefNotExist=Product with reference '<i>%s</i>' don't exist
ErrorProductWithRefNotExist=Product with reference '<i>%s</i>' don't exist
ErrorDeleteNotPossibleLineIsConsolidated=Delete not possible because record is linked to a bank transation that is conciliated

View File

@ -82,4 +82,5 @@ ErrorBadMask=Erreur sur le masque
ErrorBadMaskFailedToLocatePosOfSequence=Erreur, masque sans numéro de séquence
ErrorBadMaskBadRazMonth=Erreur, mauvais valeur de remise à zéro
ErrorSelectAtLeastOne=Erreur. Sélectionnez au moins une entrée.
ErrorProductWithRefNotExist=La référence produit '<i>%s</i>' n'existe pas
ErrorProductWithRefNotExist=La référence produit '<i>%s</i>' n'existe pas
ErrorDeleteNotPossibleLineIsConsolidated=Suppression impossible car l'enregistrement porte sur au moins une transaction bancaire rapprochée