Fixed: Bug cration 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);
|
||||
|
||||
Header("Location: fiche.php?facid=".$_GET["facid"]);
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
@ -99,71 +100,73 @@ if ($_POST["action"] == 'update')
|
||||
$result = $db->query( $sql);
|
||||
}
|
||||
/*
|
||||
* Création
|
||||
* Action création
|
||||
*/
|
||||
if ($_POST["action"] == 'add' && $user->rights->fournisseur->facture->creer)
|
||||
{
|
||||
if ($_POST["facnumber"])
|
||||
if ($_POST["facnumber"])
|
||||
{
|
||||
$datefacture = mktime(12,0,0,
|
||||
$_POST["remonth"],
|
||||
$_POST["reday"],
|
||||
$_POST["reyear"]);
|
||||
$tva = 0;
|
||||
$tva = ($_POST["tva_taux"] * $_POST["amount"]) / 100 ;
|
||||
$remise = 0;
|
||||
$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"];
|
||||
$datefacture = mktime(12,0,0,
|
||||
$_POST["remonth"],
|
||||
$_POST["reday"],
|
||||
$_POST["reyear"]);
|
||||
$tva = 0;
|
||||
$tva = ($_POST["tva_taux"] * $_POST["amount"]) / 100 ;
|
||||
$remise = 0;
|
||||
$total = $tva + $_POST["amount"] ;
|
||||
|
||||
$facid = $facfou->create($user);
|
||||
$db->begin();
|
||||
|
||||
// Ajout des lignes de factures
|
||||
if ($facid > 0)
|
||||
{
|
||||
for ($i = 1 ; $i < 9 ; $i++)
|
||||
// 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);
|
||||
|
||||
// Ajout des lignes de factures
|
||||
if ($facid > 0)
|
||||
{
|
||||
for ($i = 1 ; $i < 9 ; $i++)
|
||||
{
|
||||
$label = "label$i";
|
||||
$amount = "amount$i";
|
||||
$amountttc = "amountttc$i";
|
||||
$tauxtva = "tauxtva$i";
|
||||
$qty = "qty$i";
|
||||
|
||||
if (strlen($_POST[$label]) > 0 && !empty($_POST[$amount]))
|
||||
{
|
||||
$atleastoneline=1;
|
||||
$facfou->addline($_POST["$label"], $_POST["$amount"], $_POST["$tauxtva"], $_POST["$qty"], 1);
|
||||
}
|
||||
else if (strlen($_POST[$label]) > 0 && empty($_POST[$amount]))
|
||||
{
|
||||
$ht = $_POST[$amountttc] / (1 + ($_POST[$tauxtva] / 100));
|
||||
$atleastoneline=1;
|
||||
$facfou->addline($_POST[$label], $ht, $_POST[$tauxtva], $_POST[$qty], 1);
|
||||
}
|
||||
$label = "label$i";
|
||||
$amount = "amount$i";
|
||||
$amountttc = "amountttc$i";
|
||||
$tauxtva = "tauxtva$i";
|
||||
$qty = "qty$i";
|
||||
|
||||
if (strlen($_POST[$label]) > 0 && !empty($_POST[$amount]))
|
||||
{
|
||||
$atleastoneline=1;
|
||||
$facfou->addline($_POST["$label"], $_POST["$amount"], $_POST["$tauxtva"], $_POST["$qty"], 1);
|
||||
}
|
||||
else if (strlen($_POST[$label]) > 0 && empty($_POST[$amount]))
|
||||
{
|
||||
$ht = $_POST[$amountttc] / (1 + ($_POST[$tauxtva] / 100));
|
||||
$atleastoneline=1;
|
||||
$facfou->addline($_POST[$label], $ht, $_POST[$tauxtva], $_POST[$qty], 1);
|
||||
}
|
||||
}
|
||||
|
||||
$db->commit();
|
||||
}
|
||||
else
|
||||
{
|
||||
$db->rollback();
|
||||
}
|
||||
|
||||
header("Location: fiche.php?facid=$facid");
|
||||
|
||||
$db->commit();
|
||||
header("Location: fiche.php?facid=$facid");
|
||||
exit;
|
||||
}
|
||||
else
|
||||
{
|
||||
$db->rollback();
|
||||
$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();
|
||||
if ($mesg) { print "<br>$mesg<br>"; }
|
||||
|
||||
print_titre($langs->trans("NewBill"));
|
||||
|
||||
if ($mesg) { print "$mesg<br>"; }
|
||||
|
||||
if ($_GET["action"] == 'copy')
|
||||
{
|
||||
$fac_ori = new FactureFournisseur($db);
|
||||
$fac_ori->fetch($_GET["facid"]);
|
||||
}
|
||||
print_titre($langs->trans("NewBill"));
|
||||
|
||||
print '<form action="fiche.php" method="post">';
|
||||
print '<input type="hidden" name="action" value="add">';
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
/* 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>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
@ -23,16 +23,16 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
\file htdocs/fournisseur.facture.class.php
|
||||
\ingroup fournisseur
|
||||
\brief Fichier de la classe des factures fournisseurs
|
||||
\version $Revision$
|
||||
\file htdocs/fournisseur.facture.class.php
|
||||
\ingroup fournisseur
|
||||
\brief Fichier de la classe des factures fournisseurs
|
||||
\version $Revision$
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
\class FactureFournisseur
|
||||
\brief Classe permettant la gestion des factures fournisseurs
|
||||
\class FactureFournisseur
|
||||
\brief Classe permettant la gestion des factures fournisseurs
|
||||
*/
|
||||
|
||||
class FactureFournisseur
|
||||
@ -82,75 +82,74 @@ class FactureFournisseur
|
||||
|
||||
/**
|
||||
* \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)
|
||||
{
|
||||
|
||||
/*
|
||||
* Insertion dans la base
|
||||
*/
|
||||
global $langs;
|
||||
|
||||
$socid = $this->socidp;
|
||||
$number = $this->number;
|
||||
$amount = $this->amount;
|
||||
$remise = $this->remise;
|
||||
|
||||
if (! $remise)
|
||||
{
|
||||
$remise = 0 ;
|
||||
}
|
||||
{
|
||||
$remise = 0 ;
|
||||
}
|
||||
|
||||
$totalht = ($amount - $remise);
|
||||
$tva = tva($totalht);
|
||||
$total = $totalht + $tva;
|
||||
|
||||
|
||||
$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 .= $this->socid.", now(),".$this->db->idate($this->date).",'".$this->note."', ".$user->id.");";
|
||||
|
||||
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 .= " VALUES ($this->id);";
|
||||
if ($this->db->query($sql) )
|
||||
{
|
||||
$idligne = $this->db->last_insert_id(MAIN_DB_PREFIX."facture_fourn_det");
|
||||
$sql = "INSERT INTO ".MAIN_DB_PREFIX."facture_fourn_det (fk_facture_fourn)";
|
||||
$sql .= " VALUES ($this->id);";
|
||||
if ($this->db->query($sql) )
|
||||
{
|
||||
$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);
|
||||
|
||||
|
||||
return $this->id;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ($this->db->errno() == DB_ERROR_RECORD_ALREADY_EXISTS)
|
||||
{
|
||||
print "Erreur : Une facture possédant cet id existe déjà";
|
||||
if ($this->db->errno() == DB_ERROR_RECORD_ALREADY_EXISTS)
|
||||
{
|
||||
$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
|
||||
|
||||
Loading…
Reference in New Issue
Block a user