parent
3feda06988
commit
487a76bafe
@ -359,177 +359,195 @@ class FactureRec
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Ajoute une ligne de facture
|
* Ajoute une ligne de facture
|
||||||
*/
|
*/
|
||||||
function addline($facid, $desc, $pu, $qty, $txtva, $fk_product='NULL', $remise_percent=0)
|
function addline($facid, $desc, $pu, $qty, $txtva, $fk_product='NULL', $remise_percent=0)
|
||||||
{
|
{
|
||||||
if ($this->brouillon)
|
if ($this->brouillon)
|
||||||
{
|
{
|
||||||
if (strlen(trim($qty))==0)
|
if (strlen(trim($qty))==0)
|
||||||
{
|
{
|
||||||
$qty=1;
|
$qty=1;
|
||||||
}
|
}
|
||||||
$remise = 0;
|
$remise = 0;
|
||||||
$price = round(ereg_replace(",",".",$pu), 2);
|
$price = round(ereg_replace(",",".",$pu), 2);
|
||||||
$subprice = $price;
|
$subprice = $price;
|
||||||
if (trim(strlen($remise_percent)) > 0)
|
if (trim(strlen($remise_percent)) > 0)
|
||||||
{
|
{
|
||||||
$remise = round(($pu * $remise_percent / 100), 2);
|
$remise = round(($pu * $remise_percent / 100), 2);
|
||||||
$price = $pu - $remise;
|
$price = $pu - $remise;
|
||||||
}
|
}
|
||||||
|
|
||||||
$sql = "INSERT INTO ".MAIN_DB_PREFIX."facturedet_rec (fk_facture,description,price,qty,tva_taux, fk_product, remise_percent, subprice, remise)";
|
$sql = "INSERT INTO ".MAIN_DB_PREFIX."facturedet_rec (fk_facture,description,price,qty,tva_taux, fk_product, remise_percent, subprice, remise)";
|
||||||
$sql .= " VALUES ('$facid', '$desc', '$price', '$qty', '$txtva', '$fk_product', '$remise_percent', '$subprice', '$remise') ;";
|
$sql .= " VALUES ('$facid', '$desc'";
|
||||||
|
$sql .= ",".ereg_replace(",",".",$price);
|
||||||
|
$sql .= ",".ereg_replace(",",".",$qty);
|
||||||
|
$sql .= ",".ereg_replace(",",".",$txtva);
|
||||||
|
$sql .= ",'$fk_product'";
|
||||||
|
$sql .= ",'".ereg_replace(",",".",$remise_percent)."'";
|
||||||
|
$sql .= ",'".ereg_replace(",",".",$subprice)."'";
|
||||||
|
$sql .= ",'".ereg_replace(",",".",$remise)."') ;";
|
||||||
|
|
||||||
if ( $this->db->query( $sql) )
|
if ( $this->db->query( $sql) )
|
||||||
{
|
{
|
||||||
$this->updateprice($facid);
|
$this->updateprice($facid);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
print "$sql";
|
print "$sql";
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Mets à jour une ligne de facture
|
* Mets à jour une ligne de facture
|
||||||
*/
|
*/
|
||||||
function updateline($rowid, $desc, $pu, $qty, $remise_percent=0)
|
function updateline($rowid, $desc, $pu, $qty, $remise_percent=0)
|
||||||
{
|
{
|
||||||
if ($this->brouillon)
|
if ($this->brouillon)
|
||||||
{
|
{
|
||||||
if (strlen(trim($qty))==0)
|
if (strlen(trim($qty))==0)
|
||||||
{
|
{
|
||||||
$qty=1;
|
$qty=1;
|
||||||
}
|
}
|
||||||
$remise = 0;
|
$remise = 0;
|
||||||
$price = round(ereg_replace(",",".",$pu), 2);
|
$price = round(ereg_replace(",",".",$pu), 2);
|
||||||
$subprice = $price;
|
$subprice = $price;
|
||||||
if (trim(strlen($remise_percent)) > 0)
|
if (trim(strlen($remise_percent)) > 0)
|
||||||
{
|
{
|
||||||
$remise = round(($pu * $remise_percent / 100), 2);
|
$remise = round(($pu * $remise_percent / 100), 2);
|
||||||
$price = $pu - $remise;
|
$price = $pu - $remise;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$remise_percent=0;
|
$remise_percent=0;
|
||||||
}
|
}
|
||||||
|
|
||||||
$sql = "UPDATE ".MAIN_DB_PREFIX."facturedet set description='$desc',price=$price,subprice=$subprice,remise=$remise,remise_percent=$remise_percent,qty=$qty WHERE rowid = $rowid ;";
|
$sql = "UPDATE ".MAIN_DB_PREFIX."facturedet set description='$desc'";
|
||||||
$result = $this->db->query( $sql);
|
$sql .= ",price=".ereg_replace(",",".",$price);
|
||||||
|
$sql .= ",subprice=".ereg_replace(",",".",$subprice);
|
||||||
|
$sql .= ",remise=".ereg_replace(",",".",$remise);
|
||||||
|
$sql .= ",remise_percent=".ereg_replace(",",".",$remise_percent);
|
||||||
|
$sql .= ",qty=".ereg_replace(",",".",$qty);
|
||||||
|
$sql .= " WHERE rowid = $rowid ;";
|
||||||
|
|
||||||
$this->updateprice($this->id);
|
$result = $this->db->query( $sql);
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
$this->updateprice($this->id);
|
||||||
* Supprime une ligne
|
}
|
||||||
*/
|
}
|
||||||
function deleteline($rowid)
|
|
||||||
{
|
|
||||||
if ($this->brouillon)
|
|
||||||
{
|
|
||||||
$sql = "DELETE FROM ".MAIN_DB_PREFIX."facturedet WHERE rowid = $rowid;";
|
|
||||||
$result = $this->db->query( $sql);
|
|
||||||
|
|
||||||
$this->updateprice($this->id);
|
/**
|
||||||
}
|
* Supprime une ligne
|
||||||
}
|
*/
|
||||||
|
function deleteline($rowid)
|
||||||
|
{
|
||||||
|
if ($this->brouillon)
|
||||||
|
{
|
||||||
|
$sql = "DELETE FROM ".MAIN_DB_PREFIX."facturedet WHERE rowid = $rowid;";
|
||||||
|
$result = $this->db->query( $sql);
|
||||||
|
|
||||||
/**
|
$this->updateprice($this->id);
|
||||||
* Mise à jour des sommes de la facture
|
}
|
||||||
*/
|
}
|
||||||
function updateprice($facid)
|
|
||||||
{
|
|
||||||
include_once DOL_DOCUMENT_ROOT . "/lib/price.lib.php";
|
|
||||||
$err=0;
|
|
||||||
$sql = "SELECT price, qty, tva_taux FROM ".MAIN_DB_PREFIX."facturedet_rec WHERE fk_facture = $facid;";
|
|
||||||
|
|
||||||
$result = $this->db->query($sql);
|
/**
|
||||||
|
* Mise à jour des sommes de la facture
|
||||||
|
*/
|
||||||
|
function updateprice($facid)
|
||||||
|
{
|
||||||
|
include_once DOL_DOCUMENT_ROOT . "/lib/price.lib.php";
|
||||||
|
$err=0;
|
||||||
|
$sql = "SELECT price, qty, tva_taux FROM ".MAIN_DB_PREFIX."facturedet_rec WHERE fk_facture = $facid;";
|
||||||
|
|
||||||
if ($result)
|
$result = $this->db->query($sql);
|
||||||
{
|
|
||||||
$num = $this->db->num_rows();
|
|
||||||
$i = 0;
|
|
||||||
while ($i < $num)
|
|
||||||
{
|
|
||||||
$obj = $this->db->fetch_object($result);
|
|
||||||
|
|
||||||
$products[$i][0] = $obj->price;
|
if ($result)
|
||||||
$products[$i][1] = $obj->qty;
|
{
|
||||||
$products[$i][2] = $obj->tva_taux;
|
$num = $this->db->num_rows();
|
||||||
|
$i = 0;
|
||||||
|
while ($i < $num)
|
||||||
|
{
|
||||||
|
$obj = $this->db->fetch_object($result);
|
||||||
|
|
||||||
$i++;
|
$products[$i][0] = $obj->price;
|
||||||
}
|
$products[$i][1] = $obj->qty;
|
||||||
|
$products[$i][2] = $obj->tva_taux;
|
||||||
|
|
||||||
$this->db->free();
|
$i++;
|
||||||
|
}
|
||||||
|
|
||||||
$calculs = calcul_price($products, $this->remise_percent);
|
$this->db->free();
|
||||||
|
|
||||||
$this->total_remise = $calculs[3];
|
$calculs = calcul_price($products, $this->remise_percent);
|
||||||
$this->amount_ht = $calculs[4];
|
|
||||||
$this->total_ht = $calculs[0];
|
|
||||||
$this->total_tva = $calculs[1];
|
|
||||||
$this->total_ttc = $calculs[2];
|
|
||||||
$tvas = $calculs[5];
|
|
||||||
|
|
||||||
$sql = "UPDATE ".MAIN_DB_PREFIX."facture_rec SET amount = $this->amount_ht, remise=$this->total_remise, total=$this->total_ht, tva=$this->total_tva, total_ttc=$this->total_ttc";
|
$this->total_remise = $calculs[3];
|
||||||
$sql .= " WHERE rowid = $facid ;";
|
$this->amount_ht = $calculs[4];
|
||||||
|
$this->total_ht = $calculs[0];
|
||||||
|
$this->total_tva = $calculs[1];
|
||||||
|
$this->total_ttc = $calculs[2];
|
||||||
|
$tvas = $calculs[5];
|
||||||
|
|
||||||
if ( $this->db->query($sql) )
|
$sql = "UPDATE ".MAIN_DB_PREFIX."facture_rec SET ";
|
||||||
{
|
$sql .= " amount = ".ereg_replace(",",".",$this->amount_ht);
|
||||||
if ($err == 0)
|
$sql .= ", remise=".ereg_replace(",",".",$this->total_remise);
|
||||||
{
|
$sql .= ", total=".ereg_replace(",",".",$this->total_ht);
|
||||||
return 1;
|
$sql .= ", tva=".ereg_replace(",",".",$this->total_tva);
|
||||||
}
|
$sql .= ", total_ttc=".ereg_replace(",",".",$this->total_ttc);
|
||||||
else
|
|
||||||
{
|
$sql .= " WHERE rowid = $facid ;";
|
||||||
return -3;
|
|
||||||
}
|
if ( $this->db->query($sql) )
|
||||||
}
|
{
|
||||||
else
|
if ($err == 0)
|
||||||
{
|
{
|
||||||
print "$sql<br>";
|
return 1;
|
||||||
return -2;
|
}
|
||||||
}
|
else
|
||||||
}
|
{
|
||||||
else
|
return -3;
|
||||||
{
|
}
|
||||||
print "Error";
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
print "$sql<br>";
|
||||||
|
return -2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
print "Error";
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Applique une remise
|
* Applique une remise
|
||||||
*/
|
*/
|
||||||
function set_remise($user, $remise)
|
function set_remise($user, $remise)
|
||||||
{
|
{
|
||||||
if ($user->rights->facture->creer)
|
if ($user->rights->facture->creer)
|
||||||
{
|
{
|
||||||
|
|
||||||
$this->remise_percent = $remise ;
|
$this->remise_percent = $remise ;
|
||||||
|
|
||||||
$sql = "UPDATE ".MAIN_DB_PREFIX."facture SET remise_percent = ".ereg_replace(",",".",$remise);
|
$sql = "UPDATE ".MAIN_DB_PREFIX."facture SET remise_percent = ".ereg_replace(",",".",$remise);
|
||||||
$sql .= " WHERE rowid = $this->id AND fk_statut = 0 ;";
|
$sql .= " WHERE rowid = $this->id AND fk_statut = 0 ;";
|
||||||
|
|
||||||
if ($this->db->query($sql) )
|
|
||||||
{
|
|
||||||
$this->updateprice($this->id);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
print $this->db->error() . ' in ' . $sql;
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
if ($this->db->query($sql) )
|
||||||
|
{
|
||||||
|
$this->updateprice($this->id);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
print $this->db->error() . ' in ' . $sql;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user