FIX situation invoice total with credit note
This commit is contained in:
parent
969be3a2a7
commit
b1380a6902
@ -953,6 +953,8 @@ if (empty($reshook))
|
||||
|
||||
if($facture_source->type == Facture::TYPE_SITUATION)
|
||||
{
|
||||
|
||||
$line->fk_prev_id = $line->id;
|
||||
|
||||
if(!empty($facture_source->tab_previous_situation_invoice))
|
||||
{
|
||||
|
||||
@ -4830,7 +4830,7 @@ class FactureLigne extends CommonInvoiceLine
|
||||
* @param int $invoiceid Invoice id
|
||||
* @return int >= 0
|
||||
*/
|
||||
function get_prev_progress($invoiceid)
|
||||
function get_prev_progress($invoiceid, $include_credit_note = true)
|
||||
{
|
||||
if (is_null($this->fk_prev_id) || empty($this->fk_prev_id) || $this->fk_prev_id == "") {
|
||||
return 0;
|
||||
@ -4844,7 +4844,26 @@ class FactureLigne extends CommonInvoiceLine
|
||||
$resql = $this->db->query($sql);
|
||||
if ($resql && $resql->num_rows > 0) {
|
||||
$res = $this->db->fetch_array($resql);
|
||||
return floatval($res['situation_percent']);
|
||||
|
||||
$returnPercent = floatval($res['situation_percent']);
|
||||
|
||||
if($include_credit_note) {
|
||||
|
||||
$sql = 'SELECT fd.situation_percent FROM ' . MAIN_DB_PREFIX . 'facturedet fd';
|
||||
$sql.= ' JOIN ' . MAIN_DB_PREFIX . 'facture f ON (f.rowid = fd.fk_facture) ';
|
||||
$sql.= ' WHERE fd.fk_prev_id =' . $this->fk_prev_id;
|
||||
$sql.= ' AND f.situation_cycle_ref = '.$tmpinvoice->situation_cycle_ref; // Prevent cycle outed
|
||||
$sql.= ' AND f.type = '.Facture::TYPE_CREDIT_NOTE;
|
||||
|
||||
$res = $this->db->query($sql);
|
||||
if($res) {
|
||||
while($obj = $this->db->fetch_object($res)) {
|
||||
$returnPercent = $returnPercent + floatval($obj->situation_percent);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $returnPercent;
|
||||
} else {
|
||||
$this->error = $this->db->error();
|
||||
dol_syslog(get_class($this) . "::select Error " . $this->error, LOG_ERR);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user