mirror of
https://github.com/Dolibarr/dolibarr.git
synced 2025-12-06 17:48:25 +01:00
Fix: property object_total_discount was not working when quantity was
not 1.
This commit is contained in:
@@ -2253,24 +2253,43 @@ abstract class CommonObject
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Function that returns the total amount of discounts applied.
|
* Function that returns the total amount HT of discounts applied for all lines.
|
||||||
*
|
*
|
||||||
* @return false|float False is returned if the discount couldn't be retrieved
|
* @return in 0 if no discount
|
||||||
*/
|
*/
|
||||||
function getTotalDiscount()
|
function getTotalDiscount()
|
||||||
{
|
{
|
||||||
$sql = 'SELECT (SUM(`subprice`) - SUM(`total_ht`)) as `discount` FROM '.MAIN_DB_PREFIX.$this->table_element.'det WHERE `'.$this->fk_element.'` = '.$this->id;
|
$total_discount=0;
|
||||||
|
|
||||||
$query = $this->db->query($sql);
|
$sql = "SELECT subprice as pu_ht, qty, remise_percent, total_ht";
|
||||||
|
$sql.= " FROM ".MAIN_DB_PREFIX.$this->table_element."det";
|
||||||
|
$sql.= " WHERE ".$this->fk_element." = ".$this->id;
|
||||||
|
|
||||||
if ($query)
|
dol_syslog(get_class($this).'::getTotalDiscount sql='.$sql);
|
||||||
|
$resql = $this->db->query($sql);
|
||||||
|
if ($resql)
|
||||||
{
|
{
|
||||||
$result = $this->db->fetch_object($query);
|
$num=$this->db->num_rows($resql);
|
||||||
|
$i=0;
|
||||||
|
while ($i < $num)
|
||||||
|
{
|
||||||
|
$obj = $this->db->fetch_object($query);
|
||||||
|
|
||||||
return price2num($result->discount);
|
$pu_ht = $obj->pu_ht;
|
||||||
|
$qty= $obj->qty;
|
||||||
|
$discount_percent_line = $obj->remise_percent;
|
||||||
|
$total_ht = $obj->total_ht;
|
||||||
|
|
||||||
|
$total_discount_line = price2num(($pu_ht * $qty) - $total_ht, 'MT');
|
||||||
|
$total_discount += $total_discount_line;
|
||||||
|
|
||||||
|
$i++;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
else dol_syslog(get_class($this).'::getTotalDiscount '.$this->db->lasterror(), LOG_ERR);
|
||||||
|
|
||||||
return false;
|
//print $total_discount; exit;
|
||||||
|
return price2num($total_discount);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -115,7 +115,7 @@ class doc_generic_order_odt extends ModelePDFCommandes
|
|||||||
'object_total_ht'=>price($object->total_ht,0,$outputlangs),
|
'object_total_ht'=>price($object->total_ht,0,$outputlangs),
|
||||||
'object_total_vat'=>price($object->total_tva,0,$outputlangs),
|
'object_total_vat'=>price($object->total_tva,0,$outputlangs),
|
||||||
'object_total_ttc'=>price($object->total_ttc,0,$outputlangs),
|
'object_total_ttc'=>price($object->total_ttc,0,$outputlangs),
|
||||||
'object_total_discount' => price($object->getTotalDiscount(), 0, $outputlangs),
|
'object_total_discount_ht' => price($object->getTotalDiscount(), 0, $outputlangs),
|
||||||
'object_vatrate'=>vatrate($object->tva),
|
'object_vatrate'=>vatrate($object->tva),
|
||||||
'object_note_private'=>$object->note,
|
'object_note_private'=>$object->note,
|
||||||
'object_note'=>$object->note_public,
|
'object_note'=>$object->note_public,
|
||||||
|
|||||||
@@ -124,7 +124,7 @@ class doc_generic_invoice_odt extends ModelePDFFactures
|
|||||||
'object_total_ht'=>price($object->total_ht,0,$outputlangs),
|
'object_total_ht'=>price($object->total_ht,0,$outputlangs),
|
||||||
'object_total_vat'=>price($object->total_tva,0,$outputlangs),
|
'object_total_vat'=>price($object->total_tva,0,$outputlangs),
|
||||||
'object_total_ttc'=>price($object->total_ttc,0,$outputlangs),
|
'object_total_ttc'=>price($object->total_ttc,0,$outputlangs),
|
||||||
'object_total_discount' => price($object->getTotalDiscount(), 0, $outputlangs),
|
'object_total_discount_ht' => price($object->getTotalDiscount(), 0, $outputlangs),
|
||||||
'object_vatrate'=>(isset($object->tva)?vatrate($object->tva):''),
|
'object_vatrate'=>(isset($object->tva)?vatrate($object->tva):''),
|
||||||
'object_note_private'=>$object->note,
|
'object_note_private'=>$object->note,
|
||||||
'object_note'=>$object->note_public,
|
'object_note'=>$object->note_public,
|
||||||
|
|||||||
@@ -114,7 +114,7 @@ class doc_generic_proposal_odt extends ModelePDFPropales
|
|||||||
'object_total_ht'=>price($object->total_ht,0,$outputlangs),
|
'object_total_ht'=>price($object->total_ht,0,$outputlangs),
|
||||||
'object_total_vat'=>price($object->total_tva,0,$outputlangs),
|
'object_total_vat'=>price($object->total_tva,0,$outputlangs),
|
||||||
'object_total_ttc'=>price($object->total_ttc,0,$outputlangs),
|
'object_total_ttc'=>price($object->total_ttc,0,$outputlangs),
|
||||||
'object_total_discount' => price($object->getTotalDiscount(), 0, $outputlangs),
|
'object_total_discount_ht' => price($object->getTotalDiscount(), 0, $outputlangs),
|
||||||
'object_vatrate'=>vatrate($object->tva),
|
'object_vatrate'=>vatrate($object->tva),
|
||||||
'object_note_private'=>$object->note,
|
'object_note_private'=>$object->note,
|
||||||
'object_note'=>$object->note_public,
|
'object_note'=>$object->note_public,
|
||||||
|
|||||||
Binary file not shown.
Reference in New Issue
Block a user