Fixed: Bug création facture fournisseur. Correction gestion erreur.
This commit is contained in:
parent
2251bcbac4
commit
eac9d46bfd
@ -57,6 +57,7 @@ if ($_POST["action"] == 'confirm_valid' && $_POST["confirm"] == yes && $user->ri
|
|||||||
$facturefourn->set_valid($user->id);
|
$facturefourn->set_valid($user->id);
|
||||||
|
|
||||||
Header("Location: fiche.php?facid=".$_GET["facid"]);
|
Header("Location: fiche.php?facid=".$_GET["facid"]);
|
||||||
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -99,71 +100,73 @@ if ($_POST["action"] == 'update')
|
|||||||
$result = $db->query( $sql);
|
$result = $db->query( $sql);
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
* Création
|
* Action création
|
||||||
*/
|
*/
|
||||||
if ($_POST["action"] == 'add' && $user->rights->fournisseur->facture->creer)
|
if ($_POST["action"] == 'add' && $user->rights->fournisseur->facture->creer)
|
||||||
{
|
{
|
||||||
if ($_POST["facnumber"])
|
if ($_POST["facnumber"])
|
||||||
{
|
{
|
||||||
$datefacture = mktime(12,0,0,
|
$datefacture = mktime(12,0,0,
|
||||||
$_POST["remonth"],
|
$_POST["remonth"],
|
||||||
$_POST["reday"],
|
$_POST["reday"],
|
||||||
$_POST["reyear"]);
|
$_POST["reyear"]);
|
||||||
$tva = 0;
|
$tva = 0;
|
||||||
$tva = ($_POST["tva_taux"] * $_POST["amount"]) / 100 ;
|
$tva = ($_POST["tva_taux"] * $_POST["amount"]) / 100 ;
|
||||||
$remise = 0;
|
$remise = 0;
|
||||||
$total = $tva + $_POST["amount"] ;
|
$total = $tva + $_POST["amount"] ;
|
||||||
|
|
||||||
$db->begin();
|
|
||||||
|
|
||||||
// Creation facture
|
|
||||||
$facfou = new FactureFournisseur($db);
|
|
||||||
|
|
||||||
$facfou->number = $_POST["facnumber"];
|
|
||||||
$facfou->socid = $_POST["socidp"];
|
|
||||||
$facfou->libelle = $_POST["libelle"];
|
|
||||||
$facfou->date = $datefacture;
|
|
||||||
$facfou->note = $_POST["note"];
|
|
||||||
|
|
||||||
$facid = $facfou->create($user);
|
$db->begin();
|
||||||
|
|
||||||
// Ajout des lignes de factures
|
// Creation facture
|
||||||
if ($facid > 0)
|
$facfou = new FactureFournisseur($db);
|
||||||
{
|
|
||||||
for ($i = 1 ; $i < 9 ; $i++)
|
$facfou->number = $_POST["facnumber"];
|
||||||
|
$facfou->socid = $_POST["socidp"];
|
||||||
|
$facfou->libelle = $_POST["libelle"];
|
||||||
|
$facfou->date = $datefacture;
|
||||||
|
$facfou->note = $_POST["note"];
|
||||||
|
|
||||||
|
$facid = $facfou->create($user);
|
||||||
|
|
||||||
|
// Ajout des lignes de factures
|
||||||
|
if ($facid > 0)
|
||||||
|
{
|
||||||
|
for ($i = 1 ; $i < 9 ; $i++)
|
||||||
{
|
{
|
||||||
$label = "label$i";
|
$label = "label$i";
|
||||||
$amount = "amount$i";
|
$amount = "amount$i";
|
||||||
$amountttc = "amountttc$i";
|
$amountttc = "amountttc$i";
|
||||||
$tauxtva = "tauxtva$i";
|
$tauxtva = "tauxtva$i";
|
||||||
$qty = "qty$i";
|
$qty = "qty$i";
|
||||||
|
|
||||||
if (strlen($_POST[$label]) > 0 && !empty($_POST[$amount]))
|
if (strlen($_POST[$label]) > 0 && !empty($_POST[$amount]))
|
||||||
{
|
{
|
||||||
$atleastoneline=1;
|
$atleastoneline=1;
|
||||||
$facfou->addline($_POST["$label"], $_POST["$amount"], $_POST["$tauxtva"], $_POST["$qty"], 1);
|
$facfou->addline($_POST["$label"], $_POST["$amount"], $_POST["$tauxtva"], $_POST["$qty"], 1);
|
||||||
}
|
}
|
||||||
else if (strlen($_POST[$label]) > 0 && empty($_POST[$amount]))
|
else if (strlen($_POST[$label]) > 0 && empty($_POST[$amount]))
|
||||||
{
|
{
|
||||||
$ht = $_POST[$amountttc] / (1 + ($_POST[$tauxtva] / 100));
|
$ht = $_POST[$amountttc] / (1 + ($_POST[$tauxtva] / 100));
|
||||||
$atleastoneline=1;
|
$atleastoneline=1;
|
||||||
$facfou->addline($_POST[$label], $ht, $_POST[$tauxtva], $_POST[$qty], 1);
|
$facfou->addline($_POST[$label], $ht, $_POST[$tauxtva], $_POST[$qty], 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$db->commit();
|
$db->commit();
|
||||||
}
|
header("Location: fiche.php?facid=$facid");
|
||||||
else
|
exit;
|
||||||
{
|
}
|
||||||
$db->rollback();
|
else
|
||||||
}
|
{
|
||||||
|
$db->rollback();
|
||||||
header("Location: fiche.php?facid=$facid");
|
$mesg='<div class="error">'.$facfou->error.'</div>';
|
||||||
|
$_GET["action"]='create';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$mesg="<div class=\"error\">Erreur: Un numéro de facture fournisseur est obligatoire.</div>";
|
$mesg='<div class="error">'.$langs->trans("ErrorFieldRequired",$langs->trans("Ref")).'</div>';
|
||||||
|
$_GET["action"]='create';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -207,14 +210,16 @@ if ($_GET["action"] == 'create' or $_GET["action"] == 'copy')
|
|||||||
{
|
{
|
||||||
|
|
||||||
llxHeader();
|
llxHeader();
|
||||||
if ($mesg) { print "<br>$mesg<br>"; }
|
|
||||||
|
print_titre($langs->trans("NewBill"));
|
||||||
|
|
||||||
|
if ($mesg) { print "$mesg<br>"; }
|
||||||
|
|
||||||
if ($_GET["action"] == 'copy')
|
if ($_GET["action"] == 'copy')
|
||||||
{
|
{
|
||||||
$fac_ori = new FactureFournisseur($db);
|
$fac_ori = new FactureFournisseur($db);
|
||||||
$fac_ori->fetch($_GET["facid"]);
|
$fac_ori->fetch($_GET["facid"]);
|
||||||
}
|
}
|
||||||
print_titre($langs->trans("NewBill"));
|
|
||||||
|
|
||||||
print '<form action="fiche.php" method="post">';
|
print '<form action="fiche.php" method="post">';
|
||||||
print '<input type="hidden" name="action" value="add">';
|
print '<input type="hidden" name="action" value="add">';
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
/* Copyright (C) 2002-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
/* Copyright (C) 2002-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
||||||
* Copyright (C) 2004 Laurent Destailleur <eldy@users.sourceforge.net>
|
* Copyright (C) 2004-2005 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
|
||||||
@ -23,16 +23,16 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
\file htdocs/fournisseur.facture.class.php
|
\file htdocs/fournisseur.facture.class.php
|
||||||
\ingroup fournisseur
|
\ingroup fournisseur
|
||||||
\brief Fichier de la classe des factures fournisseurs
|
\brief Fichier de la classe des factures fournisseurs
|
||||||
\version $Revision$
|
\version $Revision$
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
\class FactureFournisseur
|
\class FactureFournisseur
|
||||||
\brief Classe permettant la gestion des factures fournisseurs
|
\brief Classe permettant la gestion des factures fournisseurs
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class FactureFournisseur
|
class FactureFournisseur
|
||||||
@ -82,75 +82,74 @@ class FactureFournisseur
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Création de la facture en base
|
* \brief Création de la facture en base
|
||||||
* \param user object utilisateur qui crée
|
* \param user object utilisateur qui crée
|
||||||
*
|
* \return int id facture si ok, < 0 si erreur
|
||||||
*/
|
*/
|
||||||
function create($user)
|
function create($user)
|
||||||
{
|
{
|
||||||
|
global $langs;
|
||||||
/*
|
|
||||||
* Insertion dans la base
|
|
||||||
*/
|
|
||||||
$socid = $this->socidp;
|
$socid = $this->socidp;
|
||||||
$number = $this->number;
|
$number = $this->number;
|
||||||
$amount = $this->amount;
|
$amount = $this->amount;
|
||||||
$remise = $this->remise;
|
$remise = $this->remise;
|
||||||
|
|
||||||
if (! $remise)
|
if (! $remise)
|
||||||
{
|
{
|
||||||
$remise = 0 ;
|
$remise = 0 ;
|
||||||
}
|
}
|
||||||
|
|
||||||
$totalht = ($amount - $remise);
|
$totalht = ($amount - $remise);
|
||||||
$tva = tva($totalht);
|
$tva = tva($totalht);
|
||||||
$total = $totalht + $tva;
|
$total = $totalht + $tva;
|
||||||
|
|
||||||
$sql = "INSERT INTO ".MAIN_DB_PREFIX."facture_fourn (facnumber, libelle, fk_soc, datec, datef, note, fk_user_author) ";
|
$sql = "INSERT INTO ".MAIN_DB_PREFIX."facture_fourn (facnumber, libelle, fk_soc, datec, datef, note, fk_user_author) ";
|
||||||
$sql .= " VALUES ('".$this->number."','".$this->libelle."',";
|
$sql .= " VALUES ('".$this->number."','".$this->libelle."',";
|
||||||
$sql .= $this->socid.", now(),".$this->db->idate($this->date).",'".$this->note."', ".$user->id.");";
|
$sql .= $this->socid.", now(),".$this->db->idate($this->date).",'".$this->note."', ".$user->id.");";
|
||||||
|
|
||||||
if ( $this->db->query($sql) )
|
if ( $this->db->query($sql) )
|
||||||
{
|
{
|
||||||
$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."facture_fourn");
|
$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."facture_fourn");
|
||||||
|
|
||||||
for ($i = 0 ; $i < sizeof($this->lignes) ; $i++)
|
for ($i = 0 ; $i < sizeof($this->lignes) ; $i++)
|
||||||
{
|
{
|
||||||
|
|
||||||
$sql = "INSERT INTO ".MAIN_DB_PREFIX."facture_fourn_det (fk_facture_fourn)";
|
$sql = "INSERT INTO ".MAIN_DB_PREFIX."facture_fourn_det (fk_facture_fourn)";
|
||||||
$sql .= " VALUES ($this->id);";
|
$sql .= " VALUES ($this->id);";
|
||||||
if ($this->db->query($sql) )
|
if ($this->db->query($sql) )
|
||||||
{
|
{
|
||||||
$idligne = $this->db->last_insert_id(MAIN_DB_PREFIX."facture_fourn_det");
|
$idligne = $this->db->last_insert_id(MAIN_DB_PREFIX."facture_fourn_det");
|
||||||
|
|
||||||
|
$this->updateline($idligne,
|
||||||
|
$this->lignes[$i][0],
|
||||||
|
$this->lignes[$i][1],
|
||||||
|
$this->lignes[$i][2],
|
||||||
|
$this->lignes[$i][3]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$this->updateline($idligne,
|
|
||||||
$this->lignes[$i][0],
|
|
||||||
$this->lignes[$i][1],
|
|
||||||
$this->lignes[$i][2],
|
|
||||||
$this->lignes[$i][3]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Mise à jour prix
|
* Mise à jour prix
|
||||||
*/
|
*/
|
||||||
|
|
||||||
$this->updateprice($this->id);
|
$this->updateprice($this->id);
|
||||||
|
|
||||||
return $this->id;
|
return $this->id;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if ($this->db->errno() == DB_ERROR_RECORD_ALREADY_EXISTS)
|
if ($this->db->errno() == DB_ERROR_RECORD_ALREADY_EXISTS)
|
||||||
{
|
{
|
||||||
print "Erreur : Une facture possédant cet id existe déjà";
|
$this->error=$langs->trans("ErrorBillRefAlreadyExists");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
dolibarr_print_error($this->db);
|
||||||
|
return -2;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
dolibarr_print_error($this->db);
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Recupére l'objet facture et ses lignes de factures
|
* \brief Recupére l'objet facture et ses lignes de factures
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user