Fix: Error when creating a supplier payment

This commit is contained in:
Laurent Destailleur 2008-05-02 23:09:33 +00:00
parent 8ae77a8d49
commit 91a5463ca2
5 changed files with 40 additions and 29 deletions

View File

@ -1,7 +1,7 @@
<?php <?php
/* Copyright (C) 2001-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org> /* Copyright (C) 2001-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2003 Jean-Louis Bergamo <jlb@j1b.org> * Copyright (C) 2003 Jean-Louis Bergamo <jlb@j1b.org>
* Copyright (C) 2004-2006 Laurent Destailleur <eldy@users.sourceforge.net> * Copyright (C) 2004-2008 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2004 Christophe Combelles <ccomb@free.fr> * Copyright (C) 2004 Christophe Combelles <ccomb@free.fr>
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
@ -17,15 +17,13 @@
* 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, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* $Id$
*/ */
/** /**
\file htdocs/compta/bank/account.class.php \file htdocs/compta/bank/account.class.php
\ingroup banque \ingroup banque
\brief Fichier de la classe des comptes bancaires \brief Fichier de la classe des comptes bancaires
\version $Revision$ \version $Id$
*/ */
require_once(DOL_DOCUMENT_ROOT ."/commonobject.class.php"); require_once(DOL_DOCUMENT_ROOT ."/commonobject.class.php");
@ -164,16 +162,16 @@ class Account extends CommonObject
/** /**
\brief Ajoute une entree dans la table ".MAIN_DB_PREFIX."bank \brief Ajoute une entree dans la table ".MAIN_DB_PREFIX."bank
\param $date Date TMS op<EFBFBD>ration \param $date Date operation
\param $oper 1,2,3,4... \param $oper 1,2,3,4...
\param $label Descripton \param $label Descripton
\param $amount Montant \param $amount Montant
\param $num_chq Numero cheque ou virement \param $num_chq Numero cheque ou virement
\param $categorie Categorie optionnelle \param $categorie Categorie optionnelle
\param $user Utilisateur qui cr<EFBFBD>e \param $user User that create
\param $emetteur Nom emetteur \param $emetteur Nom emetteur
\param $banque Banque emettrice \param $banque Banque emettrice
\return int Rowid de l'entr<EFBFBD>e ajout<EFBFBD>e, <0 si erreur \return int Rowid of added entry, <0 si erreur
*/ */
function addline($date, $oper, $label, $amount, $num_chq='', $categorie='', $user, $emetteur='',$banque='') function addline($date, $oper, $label, $amount, $num_chq='', $categorie='', $user, $emetteur='',$banque='')
{ {
@ -257,8 +255,9 @@ class Account extends CommonObject
} }
else else
{ {
$this->error=$this->db->lasterror();
dolibarr_syslog("Account::addline ".$this->error, LOG_ERR);
$this->db->rollback(); $this->db->rollback();
$this->error=$this->db->error();
return -2; return -2;
} }
} }

View File

@ -76,10 +76,11 @@ if ($action == 'add_paiement')
} }
} }
// Effectue les vérifications des parametres // Effectue les vérifications des parametres
if ($_POST['paiementid'] <= 0) if ($_POST['paiementid'] <= 0)
{ {
$fiche_erreur_message = '<div class="error">'.$langs->trans('ErrorFieldRequired',$langs->transnoentities('PaymentMode')).'</div>'; $mesg = '<div class="error">'.$langs->trans('ErrorFieldRequired',$langs->transnoentities('PaymentMode')).'</div>';
$error++; $error++;
} }
@ -89,7 +90,7 @@ if ($action == 'add_paiement')
// d'un paiement // d'un paiement
if (! $_POST['accountid']) if (! $_POST['accountid'])
{ {
$fiche_erreur_message = '<div class="error">'.$langs->trans('ErrorFieldRequired',$langs->transnoentities('AccountToCredit')).'</div>'; $mesg = '<div class="error">'.$langs->trans('ErrorFieldRequired',$langs->transnoentities('AccountToCredit')).'</div>';
$error++; $error++;
} }
} }
@ -98,7 +99,7 @@ if ($action == 'add_paiement')
\TODO A activer qd gestion avoir active et que creation facture fournisseur negative interdit \TODO A activer qd gestion avoir active et que creation facture fournisseur negative interdit
if ($total <= 0) if ($total <= 0)
{ {
$fiche_erreur_message = '<div class="error">'.$langs->trans('ErrorFieldRequired',$langs->transnoentities('Amount')).'</div>'; $mesg = '<div class="error">'.$langs->trans('ErrorFieldRequired',$langs->transnoentities('Amount')).'</div>';
$error++; $error++;
} }
*/ */
@ -110,7 +111,7 @@ if ($action == 'add_paiement')
// Creation de la ligne paiement // Creation de la ligne paiement
$paiement = new PaiementFourn($db); $paiement = new PaiementFourn($db);
$paiement->datepaye = $datepaye; $paiement->datepaye = $datepaye;
$paiement->amounts = $amounts; // Tableau de montant $paiement->amounts = $amounts; // Array of amounts
$paiement->paiementid = $_POST['paiementid']; $paiement->paiementid = $_POST['paiementid'];
$paiement->num_paiement = $_POST['num_paiement']; $paiement->num_paiement = $_POST['num_paiement'];
$paiement->note = $_POST['comment']; $paiement->note = $_POST['comment'];
@ -149,7 +150,7 @@ if ($action == 'add_paiement')
DOL_URL_ROOT.'/fourn/paiement/fiche.php?id=', DOL_URL_ROOT.'/fourn/paiement/fiche.php?id=',
'(paiement)', '(paiement)',
'payment_supplier'); 'payment_supplier');
$acc->add_url_line($bank_line_id, $acc->add_url_line($bank_line_id,
$fac->fournisseur->id, $fac->fournisseur->id,
DOL_URL_ROOT.'/fourn/fiche.php?socid=', DOL_URL_ROOT.'/fourn/fiche.php?socid=',
$fac->fournisseur->nom, $fac->fournisseur->nom,
@ -164,7 +165,7 @@ if ($action == 'add_paiement')
} }
else else
{ {
$fiche_erreur_message = '<div class="error">'.$langs->trans("Error").'</div>'; $mesg = '<div class="error">'.$langs->trans($paiement->error).'</div>';
$error++; $error++;
} }
@ -190,9 +191,9 @@ llxHeader();
$html=new Form($db); $html=new Form($db);
if ($fiche_erreur_message) if ($mesg)
{ {
print '<tr><td colspan="3" align="center">'.$fiche_erreur_message.'</td></tr>'; print '<tr><td colspan="3" align="center">'.$mesg.'</td></tr>';
} }
if ($action == 'create' || $action == 'add_paiement') if ($action == 'create' || $action == 'add_paiement')

View File

@ -65,8 +65,8 @@ class PaiementFourn
} }
/** /**
* \brief R<EFBFBD>cup<EFBFBD>re l'objet paiement * \brief Load payment object
* \param id id du paiement a r<EFBFBD>cup<EFBFBD>rer * \param id id paiement to get
* \return int <0 si ko, >0 si ok * \return int <0 si ko, >0 si ok
*/ */
function fetch($id) function fetch($id)
@ -112,7 +112,7 @@ class PaiementFourn
} }
/** /**
* \brief Creta payment in database * \brief Create payment in database
* \param user Object of creating user * \param user Object of creating user
* \return int id of created payment, < 0 if error * \return int id of created payment, < 0 if error
*/ */
@ -136,10 +136,14 @@ class PaiementFourn
$this->db->begin(); $this->db->begin();
if ($this->total <> 0) // On accepte les montants n<EFBFBD>gatifs if ($this->total <> 0) // On accepte les montants negatifs
{ {
$sql = 'INSERT INTO '.MAIN_DB_PREFIX.'paiementfourn (datec, datep, amount, fk_paiement, num_paiement, note, fk_user_author)'; $sql = 'INSERT INTO '.MAIN_DB_PREFIX.'paiementfourn (';
$sql .= ' VALUES (now(), '.$this->db->idate($this->datepaye).', \''.$this->total.'\', '.$this->paiementid.', \''.$this->num_paiement.'\', \''.$this->note.'\', '.$user->id.')'; $sql.= 'datec, datep, amount, fk_paiement, num_paiement, note, fk_user_author, fk_bank)';
$sql.= ' VALUES (now(),';
$sql.= ' '.$this->db->idate($this->datepaye).', \''.$this->total.'\', '.$this->paiementid.', \''.$this->num_paiement.'\', \''.$this->note.'\', '.$user->id.', 0)';
dolibarr_syslog("PaiementFourn::create sql=".$sql);
$resql = $this->db->query($sql); $resql = $this->db->query($sql);
if ($resql) if ($resql)
{ {
@ -162,7 +166,7 @@ class PaiementFourn
} }
else else
{ {
dolibarr_syslog('PaiementFourn::Create Montant non num<EFBFBD>rique'); dolibarr_syslog('PaiementFourn::Create Montant non numerique',LOG_ERR);
} }
} }
@ -178,12 +182,19 @@ class PaiementFourn
} }
else else
{ {
dolibarr_syslog('PaiementFourn::Create Erreur INSERT dans paiementfourn'); $this->error=$this->db->lasterror();
dolibarr_syslog('PaiementFourn::Create Error '.$this->error, LOG_ERR);
$error++; $error++;
} }
} }
else
{
$this->error="ErrorTotalIsNull";
dolibarr_syslog('PaiementFourn::Create Error '.$this->error, LOG_ERR);
$error++;
}
if ( $this->total <> 0 && $error == 0 ) // On accepte les montants n<>gatifs if ($this->total <> 0 && $error == 0) // On accepte les montants negatifs
{ {
$this->db->commit(); $this->db->commit();
dolibarr_syslog('PaiementFourn::Create Ok Total = '.$this->total); dolibarr_syslog('PaiementFourn::Create Ok Total = '.$this->total);
@ -192,7 +203,6 @@ class PaiementFourn
else else
{ {
$this->db->rollback(); $this->db->rollback();
dolibarr_syslog('PaiementFourn::Create Erreur');
return -1; return -1;
} }
} }

View File

@ -290,5 +290,6 @@ create table llx_ecm_document
private smallint DEFAULT 0 private smallint DEFAULT 0
) type=innodb; ) type=innodb;
ALTER TABLE llx_bank modify num_chq varchar(50);
ALTER TABLE llx_menu_const ADD UNIQUE KEY uk_menu_const(fk_menu, fk_constraint); ALTER TABLE llx_menu_const ADD UNIQUE KEY uk_menu_const(fk_menu, fk_constraint);

View File

@ -1,6 +1,6 @@
-- =================================================================== -- ===================================================================
-- Copyright (C) 2000-2006 Rodolphe Quiedeville <rodolphe@quiedeville.org> -- Copyright (C) 2000-2006 Rodolphe Quiedeville <rodolphe@quiedeville.org>
-- Copyright (C) 2005 Laurent Destailleur <eldy@users.sourceforge.net> -- Copyright (C) 2005-2008 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
@ -32,7 +32,7 @@ create table llx_bank
fk_user_rappro integer, fk_user_rappro integer,
fk_type varchar(4), -- CB, Virement, cheque fk_type varchar(4), -- CB, Virement, cheque
num_releve varchar(50), num_releve varchar(50),
num_chq int, num_chq varchar(50),
rappro tinyint default 0, rappro tinyint default 0,
note text, note text,
fk_bordereau integer DEFAULT 0, fk_bordereau integer DEFAULT 0,