Fix: Correction problem ajout facture fournisseur. Suppression methode inutiles dans la classe
This commit is contained in:
parent
e7d113f273
commit
836cfa8dee
@ -61,95 +61,6 @@ class FactureFourn
|
||||
|
||||
$this->lignes = array();
|
||||
}
|
||||
/*
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
Function add_ligne($label, $amount, $tauxtva, $qty=1, $write=0)
|
||||
{
|
||||
$i = sizeof($this->lignes);
|
||||
|
||||
$this->lignes[$i][0] = $label;
|
||||
$this->lignes[$i][1] = $amount;
|
||||
$this->lignes[$i][2] = $tauxtva;
|
||||
$this->lignes[$i][3] = $qty;
|
||||
|
||||
if ($write)
|
||||
{
|
||||
|
||||
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();
|
||||
|
||||
$this->update_ligne($idligne,
|
||||
$this->lignes[$i][0],
|
||||
$this->lignes[$i][1],
|
||||
$this->lignes[$i][2],
|
||||
$this->lignes[$i][3]);
|
||||
}
|
||||
else
|
||||
{
|
||||
print $this->db->error();
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Mise à jour prix
|
||||
*/
|
||||
|
||||
$this->updateprice($this->id);
|
||||
}
|
||||
}
|
||||
/*
|
||||
*
|
||||
*/
|
||||
Function update_ligne($id, $label, $puht, $tauxtva, $qty=1)
|
||||
{
|
||||
|
||||
$puht = ereg_replace(",",".",$puht);
|
||||
|
||||
$totalht = $puht * $qty;
|
||||
$tva = tva($totalht, $tauxtva);
|
||||
$totalttc = $totalht + $tva;
|
||||
|
||||
|
||||
$sql = "UPDATE ".MAIN_DB_PREFIX."facture_fourn_det ";
|
||||
$sql .= "SET description ='".$label."'";
|
||||
$sql .= ", pu_ht = " . $puht;
|
||||
$sql .= ", qty =".$qty;
|
||||
$sql .= ", total_ht=".$totalht;
|
||||
$sql .= ", tva=".$tva;
|
||||
$sql .= ", tva_taux=".$tauxtva;
|
||||
$sql .= ", total_ttc=".$totalttc;
|
||||
|
||||
$sql .= " WHERE rowid = $id";
|
||||
|
||||
if (! $this->db->query($sql) )
|
||||
{
|
||||
print $this->db->error() . '<b><br>'.$sql;
|
||||
}
|
||||
}
|
||||
/*
|
||||
*
|
||||
*/
|
||||
Function delete_ligne($id)
|
||||
{
|
||||
|
||||
$sql = "DELETE FROM ".MAIN_DB_PREFIX."facture_fourn_det ";
|
||||
$sql .= " WHERE rowid = $id";
|
||||
|
||||
if (! $this->db->query($sql) )
|
||||
{
|
||||
print $this->db->error() . '<b><br>'.$sql;
|
||||
}
|
||||
$this->updateprice($this->id);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* Création d'une facture fournisseur
|
||||
@ -191,27 +102,34 @@ class FactureFourn
|
||||
{
|
||||
$idligne = $this->db->last_insert_id();
|
||||
|
||||
$this->update_ligne($idligne,
|
||||
$this->updateline($idligne,
|
||||
$this->lignes[$i][0],
|
||||
$this->lignes[$i][1],
|
||||
$this->lignes[$i][2],
|
||||
$this->lignes[$i][3]);
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Mise à jour prix
|
||||
*/
|
||||
|
||||
$this->updateprice($this->id);
|
||||
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/*
|
||||
* Mise à jour prix
|
||||
*/
|
||||
|
||||
$this->updateprice($this->id);
|
||||
|
||||
return $this->id;
|
||||
}
|
||||
else
|
||||
{
|
||||
print $this->db->error() . '<b><br>'.$sql;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
{
|
||||
if ($this->db->errno() == $this->db->ERROR_DUPLICATE) {
|
||||
print "Erreur : Une facture possédant cet id existe déjà";
|
||||
}
|
||||
else {
|
||||
print "Erreur : ".$this->db->error() . '<b><br>'.$sql;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
*
|
||||
@ -347,38 +265,81 @@ class FactureFourn
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
*
|
||||
*
|
||||
*/
|
||||
Function addline($facid, $desc, $pu, $qty)
|
||||
{
|
||||
$sql = "INSERT INTO ".MAIN_DB_PREFIX."facture_fourn_det (fk_facture,description,price,qty) VALUES ($facid, '$desc', $pu, $qty) ;";
|
||||
$result = $this->db->query( $sql);
|
||||
|
||||
$this->updateprice($facid);
|
||||
/*
|
||||
* Ajout ligne facture fourn
|
||||
*/
|
||||
Function addline($desc, $pu, $tauxtva, $qty)
|
||||
{
|
||||
|
||||
$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();
|
||||
|
||||
$this->updateline($idligne, $desc, $pu, $tauxtva, $qty);
|
||||
}
|
||||
else
|
||||
{
|
||||
print $this->db->error();
|
||||
}
|
||||
|
||||
// Mise a jour prix facture
|
||||
$this->updateprice($this->id);
|
||||
|
||||
}
|
||||
/*
|
||||
*
|
||||
* Mise a jour ligne facture fourn
|
||||
*
|
||||
*/
|
||||
Function updateline($rowid, $desc, $pu, $qty)
|
||||
Function updateline($id, $label, $puht, $tauxtva, $qty=1)
|
||||
{
|
||||
$sql = "UPDATE ".MAIN_DB_PREFIX."facture-fourn_det set description='$desc',price=$pu,qty=$qty WHERE rowid = $rowid ;";
|
||||
$result = $this->db->query( $sql);
|
||||
|
||||
$this->updateprice($this->id);
|
||||
$puht = ereg_replace(",",".",$puht);
|
||||
|
||||
$totalht = $puht * $qty;
|
||||
$tva = tva($totalht, $tauxtva);
|
||||
$totalttc = $totalht + $tva;
|
||||
|
||||
|
||||
$sql = "UPDATE ".MAIN_DB_PREFIX."facture_fourn_det ";
|
||||
$sql .= "SET description ='".$label."'";
|
||||
$sql .= ", pu_ht = " . $puht;
|
||||
$sql .= ", qty =".$qty;
|
||||
$sql .= ", total_ht=".$totalht;
|
||||
$sql .= ", tva=".$tva;
|
||||
$sql .= ", tva_taux=".$tauxtva;
|
||||
$sql .= ", total_ttc=".$totalttc;
|
||||
|
||||
$sql .= " WHERE rowid = $id";
|
||||
|
||||
if (! $this->db->query($sql) )
|
||||
{
|
||||
print $this->db->error() . '<b><br>'.$sql;
|
||||
}
|
||||
|
||||
// Mise a jour prix facture
|
||||
$this->updateprice($this->id);
|
||||
}
|
||||
/*
|
||||
*
|
||||
* Supprime ligne facture fourn
|
||||
*
|
||||
*/
|
||||
Function deleteline($rowid)
|
||||
{
|
||||
$sql = "DELETE FROM ".MAIN_DB_PREFIX."facture_fourn_det WHERE rowid = $rowid;";
|
||||
$result = $this->db->query( $sql);
|
||||
// Supprime ligne
|
||||
$sql = "DELETE FROM ".MAIN_DB_PREFIX."facture_fourn_det ";
|
||||
$sql .= " WHERE rowid = $rowid";
|
||||
|
||||
if (! $this->db->query($sql) )
|
||||
{
|
||||
print "Erreur : ".$this->db->error() . '<b><br>'.$sql;
|
||||
}
|
||||
|
||||
$this->updateprice($this->id);
|
||||
// Mise a jour prix facture
|
||||
$this->updateprice($this->id);
|
||||
|
||||
return 1;
|
||||
}
|
||||
/*
|
||||
*
|
||||
|
||||
@ -114,7 +114,7 @@ if ($action == 'add')
|
||||
$facid = $facfou->create($user);
|
||||
|
||||
// Ajout des lignes de factures
|
||||
if ($facid) {
|
||||
if ($facid > 0) {
|
||||
for ($i = 1 ; $i < 9 ; $i++)
|
||||
{
|
||||
$label = "label$i";
|
||||
@ -122,16 +122,18 @@ if ($action == 'add')
|
||||
$tauxtva = "tauxtva$i";
|
||||
$qty = "qty$i";
|
||||
|
||||
if (strlen($$label) && $$amount > 0)
|
||||
if (strlen($$label) > 0 && $$amount > 0)
|
||||
{
|
||||
$atleastoneline=1;
|
||||
$facfou->add_ligne($$label, $$amount, $$tauxtva, $$qty);
|
||||
$facfou->addline($$label, $$amount, $$tauxtva, $$qty, 1);
|
||||
}
|
||||
}
|
||||
|
||||
$db->commit();
|
||||
}
|
||||
else {
|
||||
$db->rollback();
|
||||
}
|
||||
|
||||
$db->commit();
|
||||
|
||||
}
|
||||
else {
|
||||
$mesg="<div class=\"error\">Erreur: Un numéro de facture fournisseur est obligatoire.</div>";
|
||||
@ -142,21 +144,16 @@ if ($action == 'del_ligne')
|
||||
{
|
||||
$facfou = new FactureFourn($db,"",$facid);
|
||||
|
||||
if ($facfou->delete_ligne($ligne_id))
|
||||
{
|
||||
$action="edit";
|
||||
}
|
||||
$facfou->deleteline($ligne_id);
|
||||
|
||||
$action="edit";
|
||||
}
|
||||
|
||||
if ($action == 'add_ligne')
|
||||
{
|
||||
$facfou = new FactureFourn($db,"", $facid);
|
||||
|
||||
$facfou->add_ligne($_POST["label"],
|
||||
$_POST["amount"],
|
||||
$_POST["tauxtva"],
|
||||
$_POST["qty"],
|
||||
1);
|
||||
$facfou->addline($_POST["label"], $_POST["amount"], $_POST["tauxtva"], $_POST["qty"]);
|
||||
|
||||
$action="edit";
|
||||
}
|
||||
|
||||
@ -39,7 +39,7 @@ function llxHeader($head = "", $urlp = "") {
|
||||
|
||||
if ($user->societe_id == 0)
|
||||
{
|
||||
$menu->add_submenu(DOL_URL_ROOT."/soc.php?action=create","Nouvelle société");
|
||||
$menu->add_submenu(DOL_URL_ROOT."/soc.php?action=create&type=f","Nouveau");
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -40,7 +40,7 @@ function llxHeader($head = "", $urlp = "")
|
||||
*/
|
||||
if ($user->societe_id == 0)
|
||||
{
|
||||
$menu->add_submenu(DOL_URL_ROOT."/soc.php?action=create","Nouvelle société");
|
||||
$menu->add_submenu(DOL_URL_ROOT."/soc.php?action=create&type=f","Nouveau");
|
||||
}
|
||||
|
||||
$menu->add_submenu("contact.php","Contacts");
|
||||
|
||||
@ -25,6 +25,10 @@
|
||||
class DoliDb {
|
||||
var $db, $results, $ok, $connected, $database_selected;
|
||||
|
||||
// Constantes pour code erreurs
|
||||
var $ERROR_DUPLICATE=1062;
|
||||
var $ERROR_TABLEEXISTS=1050;
|
||||
|
||||
Function DoliDb($type = 'mysql', $host = '', $user = '', $pass = '', $name = '')
|
||||
// Se connecte au serveur et éventuellement à une base (si spécifié)
|
||||
// Renvoie 1 en cas de succès, 0 sinon
|
||||
@ -140,6 +144,8 @@ class DoliDb {
|
||||
return mysql_close($this->db);
|
||||
}
|
||||
|
||||
|
||||
// Start transaction
|
||||
Function begin($do=1)
|
||||
{
|
||||
if ($do)
|
||||
@ -152,6 +158,7 @@ class DoliDb {
|
||||
}
|
||||
}
|
||||
|
||||
// Commit transaction
|
||||
Function commit($do=1)
|
||||
{
|
||||
if ($do)
|
||||
@ -164,6 +171,7 @@ class DoliDb {
|
||||
}
|
||||
}
|
||||
|
||||
// Rollback transaction
|
||||
Function rollback($do=1)
|
||||
{
|
||||
if ($do)
|
||||
@ -260,8 +268,8 @@ class DoliDb {
|
||||
|
||||
Function errno()
|
||||
{
|
||||
// 1050 Table already exists
|
||||
// 1062 Duplicate key
|
||||
// $ERROR_DUPLICATE=1062;
|
||||
// $ERROR_TABLEEXISTS=1050;
|
||||
return mysql_errno($this->db);
|
||||
}
|
||||
|
||||
|
||||
@ -79,6 +79,10 @@ if ($action == 'create')
|
||||
* Fiche societe en mode création
|
||||
*/
|
||||
$soc = new Societe($db);
|
||||
if ($_GET["type"]=='f') { $soc->fournisseur=1; }
|
||||
if ($_GET["type"]=='c') { $soc->client=1; }
|
||||
if ($_GET["type"]=='p') { $soc->client=2; }
|
||||
|
||||
print '<div class="titre">Nouvelle société (prospect, client, fournisseur)</div><br>';
|
||||
print '<form action="soc.php" method="post">';
|
||||
print '<input type="hidden" name="action" value="add">';
|
||||
@ -126,9 +130,9 @@ if ($action == 'create')
|
||||
print '</td></tr>';
|
||||
|
||||
print '<tr><td>Prospect / Client</td><td><select name="client">';
|
||||
print '<option value="2" selected>Prospect';
|
||||
print '<option value="1">Client';
|
||||
print '<option value="0">Ni client, ni prospect';
|
||||
print '<option value="2"'.($soc->client==2?' selected':'').'>Prospect</option>';
|
||||
print '<option value="1"'.($soc->client==1?' selected':'').'>Client</option>';
|
||||
print '<option value="0"'.($soc->client==0?' selected':'').'>Ni client, ni prospect</option>';
|
||||
print '</select></td>';
|
||||
|
||||
print '<td>Fournisseur</td><td><select name="fournisseur">';
|
||||
@ -199,25 +203,9 @@ elseif ($action == 'edit')
|
||||
print '</td></tr>';
|
||||
|
||||
print '<tr><td>Prospect / Client</td><td><select name="client">';
|
||||
if ($soc->client == 2)
|
||||
{
|
||||
print '<option value="2" selected>Prospect</option>';
|
||||
print '<option value="1">Client</option>';
|
||||
print '<option value="0">Ni client, ni prospect</option>';
|
||||
}
|
||||
elseif ($soc->client == 1)
|
||||
{
|
||||
print '<option value="2">Prospect</option>';
|
||||
print '<option value="1" selected>Client</option>';
|
||||
print '<option value="0">Ni client, ni prospect</option>';
|
||||
}
|
||||
else
|
||||
{
|
||||
print '<option value="2">Prospect</option>';
|
||||
print '<option value="1">Client</option>';
|
||||
print '<option value="0" selected>Ni client, ni prospect</option>';
|
||||
}
|
||||
|
||||
print '<option value="2"'.($soc->client==2?' selected':'').'>Prospect</option>';
|
||||
print '<option value="1"'.($soc->client==1?' selected':'').'>Client</option>';
|
||||
print '<option value="0"'.($soc->client==0?' selected':'').'>Ni client, ni prospect</option>';
|
||||
print '</select></td>';
|
||||
|
||||
print '<td>Fournisseur</td><td><select name="fournisseur">';
|
||||
|
||||
Loading…
Reference in New Issue
Block a user