2
0
forked from Wavyzz/dolibarr

Fix: Correction problem ajout facture fournisseur. Suppression methode inutiles dans la classe

This commit is contained in:
Laurent Destailleur
2004-06-13 18:25:43 +00:00
parent e7d113f273
commit 836cfa8dee
6 changed files with 117 additions and 163 deletions

View File

@@ -61,95 +61,6 @@ class FactureFourn
$this->lignes = array(); $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 <20> 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<43>ation d'une facture fournisseur * Cr<43>ation d'une facture fournisseur
@@ -191,27 +102,34 @@ class FactureFourn
{ {
$idligne = $this->db->last_insert_id(); $idligne = $this->db->last_insert_id();
$this->update_ligne($idligne, $this->updateline($idligne,
$this->lignes[$i][0], $this->lignes[$i][0],
$this->lignes[$i][1], $this->lignes[$i][1],
$this->lignes[$i][2], $this->lignes[$i][2],
$this->lignes[$i][3]); $this->lignes[$i][3]);
} }
} }
/*
* Mise <20> jour prix /*
*/ * Mise <20> jour prix
*/
$this->updateprice($this->id);
$this->updateprice($this->id);
return $this->id;
} return $this->id;
}
else else
{ {
print $this->db->error() . '<b><br>'.$sql; if ($this->db->errno() == $this->db->ERROR_DUPLICATE) {
return 0; print "Erreur : Une facture poss<73>dant cet id existe d<>j<EFBFBD>";
} }
} 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 ;"; $puht = ereg_replace(",",".",$puht);
$result = $this->db->query( $sql);
$totalht = $puht * $qty;
$this->updateprice($this->id); $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) Function deleteline($rowid)
{ {
$sql = "DELETE FROM ".MAIN_DB_PREFIX."facture_fourn_det WHERE rowid = $rowid;"; // Supprime ligne
$result = $this->db->query( $sql); $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;
} }
/* /*
* *

View File

@@ -114,7 +114,7 @@ if ($action == 'add')
$facid = $facfou->create($user); $facid = $facfou->create($user);
// Ajout des lignes de factures // Ajout des lignes de factures
if ($facid) { if ($facid > 0) {
for ($i = 1 ; $i < 9 ; $i++) for ($i = 1 ; $i < 9 ; $i++)
{ {
$label = "label$i"; $label = "label$i";
@@ -122,16 +122,18 @@ if ($action == 'add')
$tauxtva = "tauxtva$i"; $tauxtva = "tauxtva$i";
$qty = "qty$i"; $qty = "qty$i";
if (strlen($$label) && $$amount > 0) if (strlen($$label) > 0 && $$amount > 0)
{ {
$atleastoneline=1; $atleastoneline=1;
$facfou->add_ligne($$label, $$amount, $$tauxtva, $$qty); $facfou->addline($$label, $$amount, $$tauxtva, $$qty, 1);
} }
} }
$db->commit();
}
else {
$db->rollback();
} }
$db->commit();
} }
else { else {
$mesg="<div class=\"error\">Erreur: Un num<75>ro de facture fournisseur est obligatoire.</div>"; $mesg="<div class=\"error\">Erreur: Un num<75>ro de facture fournisseur est obligatoire.</div>";
@@ -142,21 +144,16 @@ if ($action == 'del_ligne')
{ {
$facfou = new FactureFourn($db,"",$facid); $facfou = new FactureFourn($db,"",$facid);
if ($facfou->delete_ligne($ligne_id)) $facfou->deleteline($ligne_id);
{
$action="edit"; $action="edit";
}
} }
if ($action == 'add_ligne') if ($action == 'add_ligne')
{ {
$facfou = new FactureFourn($db,"", $facid); $facfou = new FactureFourn($db,"", $facid);
$facfou->add_ligne($_POST["label"], $facfou->addline($_POST["label"], $_POST["amount"], $_POST["tauxtva"], $_POST["qty"]);
$_POST["amount"],
$_POST["tauxtva"],
$_POST["qty"],
1);
$action="edit"; $action="edit";
} }

View File

@@ -39,7 +39,7 @@ function llxHeader($head = "", $urlp = "") {
if ($user->societe_id == 0) if ($user->societe_id == 0)
{ {
$menu->add_submenu(DOL_URL_ROOT."/soc.php?action=create","Nouvelle soci<63>t<EFBFBD>"); $menu->add_submenu(DOL_URL_ROOT."/soc.php?action=create&type=f","Nouveau");
} }

View File

@@ -40,7 +40,7 @@ function llxHeader($head = "", $urlp = "")
*/ */
if ($user->societe_id == 0) if ($user->societe_id == 0)
{ {
$menu->add_submenu(DOL_URL_ROOT."/soc.php?action=create","Nouvelle soci<63>t<EFBFBD>"); $menu->add_submenu(DOL_URL_ROOT."/soc.php?action=create&type=f","Nouveau");
} }
$menu->add_submenu("contact.php","Contacts"); $menu->add_submenu("contact.php","Contacts");

View File

@@ -25,6 +25,10 @@
class DoliDb { class DoliDb {
var $db, $results, $ok, $connected, $database_selected; 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 = '') Function DoliDb($type = 'mysql', $host = '', $user = '', $pass = '', $name = '')
// Se connecte au serveur et <20>ventuellement <20> une base (si sp<73>cifi<66>) // Se connecte au serveur et <20>ventuellement <20> une base (si sp<73>cifi<66>)
// Renvoie 1 en cas de succ<63>s, 0 sinon // Renvoie 1 en cas de succ<63>s, 0 sinon
@@ -140,6 +144,8 @@ class DoliDb {
return mysql_close($this->db); return mysql_close($this->db);
} }
// Start transaction
Function begin($do=1) Function begin($do=1)
{ {
if ($do) if ($do)
@@ -152,6 +158,7 @@ class DoliDb {
} }
} }
// Commit transaction
Function commit($do=1) Function commit($do=1)
{ {
if ($do) if ($do)
@@ -164,6 +171,7 @@ class DoliDb {
} }
} }
// Rollback transaction
Function rollback($do=1) Function rollback($do=1)
{ {
if ($do) if ($do)
@@ -260,8 +268,8 @@ class DoliDb {
Function errno() Function errno()
{ {
// 1050 Table already exists // $ERROR_DUPLICATE=1062;
// 1062 Duplicate key // $ERROR_TABLEEXISTS=1050;
return mysql_errno($this->db); return mysql_errno($this->db);
} }

View File

@@ -79,6 +79,10 @@ if ($action == 'create')
* Fiche societe en mode cr<63>ation * Fiche societe en mode cr<63>ation
*/ */
$soc = new Societe($db); $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<63>t<EFBFBD> (prospect, client, fournisseur)</div><br>'; print '<div class="titre">Nouvelle soci<63>t<EFBFBD> (prospect, client, fournisseur)</div><br>';
print '<form action="soc.php" method="post">'; print '<form action="soc.php" method="post">';
print '<input type="hidden" name="action" value="add">'; print '<input type="hidden" name="action" value="add">';
@@ -126,9 +130,9 @@ if ($action == 'create')
print '</td></tr>'; print '</td></tr>';
print '<tr><td>Prospect / Client</td><td><select name="client">'; print '<tr><td>Prospect / Client</td><td><select name="client">';
print '<option value="2" selected>Prospect'; print '<option value="2"'.($soc->client==2?' selected':'').'>Prospect</option>';
print '<option value="1">Client'; print '<option value="1"'.($soc->client==1?' selected':'').'>Client</option>';
print '<option value="0">Ni client, ni prospect'; print '<option value="0"'.($soc->client==0?' selected':'').'>Ni client, ni prospect</option>';
print '</select></td>'; print '</select></td>';
print '<td>Fournisseur</td><td><select name="fournisseur">'; print '<td>Fournisseur</td><td><select name="fournisseur">';
@@ -199,25 +203,9 @@ elseif ($action == 'edit')
print '</td></tr>'; print '</td></tr>';
print '<tr><td>Prospect / Client</td><td><select name="client">'; print '<tr><td>Prospect / Client</td><td><select name="client">';
if ($soc->client == 2) print '<option value="2"'.($soc->client==2?' selected':'').'>Prospect</option>';
{ print '<option value="1"'.($soc->client==1?' selected':'').'>Client</option>';
print '<option value="2" selected>Prospect</option>'; print '<option value="0"'.($soc->client==0?' selected':'').'>Ni client, ni 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 '</select></td>'; print '</select></td>';
print '<td>Fournisseur</td><td><select name="fournisseur">'; print '<td>Fournisseur</td><td><select name="fournisseur">';