From b1380a690242a354ac02712a39f82b18bc5b7125 Mon Sep 17 00:00:00 2001 From: John BOTELLA Date: Mon, 24 Sep 2018 16:12:00 +0200 Subject: [PATCH 1/4] FIX situation invoice total with credit note --- htdocs/compta/facture/card.php | 2 ++ htdocs/compta/facture/class/facture.class.php | 23 +++++++++++++++++-- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/htdocs/compta/facture/card.php b/htdocs/compta/facture/card.php index 0465530ec27..f31b41753f0 100644 --- a/htdocs/compta/facture/card.php +++ b/htdocs/compta/facture/card.php @@ -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)) { diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php index 1ebd9fedfd6..8c756dc5264 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -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); From 791c373db5b1f1f71d8989ffd84ec626c6cba64a Mon Sep 17 00:00:00 2001 From: John BOTELLA Date: Tue, 25 Sep 2018 09:54:58 +0200 Subject: [PATCH 2/4] FIX credit note progression --- htdocs/compta/facture/card.php | 6 +++--- htdocs/compta/facture/class/facture.class.php | 1 + 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/htdocs/compta/facture/card.php b/htdocs/compta/facture/card.php index f31b41753f0..e3a68f9654c 100644 --- a/htdocs/compta/facture/card.php +++ b/htdocs/compta/facture/card.php @@ -953,8 +953,8 @@ if (empty($reshook)) if($facture_source->type == Facture::TYPE_SITUATION) { - - $line->fk_prev_id = $line->id; + $source_fk_prev_id = $line->fk_prev_id; // temporary storing situation invoice fk_prev_id + $line->fk_prev_id = $line->id; // Credit note line need to be linked to the situation invoice it is create from if(!empty($facture_source->tab_previous_situation_invoice)) { @@ -978,7 +978,7 @@ if (empty($reshook)) $maxPrevSituationPercent = 0; foreach($facture_source->tab_previous_situation_invoice[$lineIndex]->lines as $prevLine) { - if($prevLine->id == $line->fk_prev_id) + if($prevLine->id == $source_fk_prev_id) { $maxPrevSituationPercent = max($maxPrevSituationPercent,$prevLine->situation_percent); diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php index 8c756dc5264..277f1c85e40 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -4828,6 +4828,7 @@ class FactureLigne extends CommonInvoiceLine * Warning: If invoice is a replacement invoice, this->fk_prev_id is id of the replaced line. * * @param int $invoiceid Invoice id + * @param bool $include_credit_note * @return int >= 0 */ function get_prev_progress($invoiceid, $include_credit_note = true) From 022f842cb09775fd2577348a743153382fbf5e29 Mon Sep 17 00:00:00 2001 From: John BOTELLA Date: Tue, 25 Sep 2018 10:28:47 +0200 Subject: [PATCH 3/4] Fix display good progress for new situation invoices --- htdocs/compta/facture/card.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/htdocs/compta/facture/card.php b/htdocs/compta/facture/card.php index e3a68f9654c..8834d93d162 100644 --- a/htdocs/compta/facture/card.php +++ b/htdocs/compta/facture/card.php @@ -1536,7 +1536,8 @@ if (empty($reshook)) $line->origin = $object->origin; $line->origin_id = $line->id; $line->fetch_optionals($line->id); - + $line->situation_percent = $line->get_prev_progress($object->id); // get good progress including credit note + // Si fk_remise_except defini on vérifie si la réduction à déjà été appliquée if ($line->fk_remise_except) { From e3b1cb9fdb72e62980e2a6545541426021d67566 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 27 Sep 2018 09:25:37 +0200 Subject: [PATCH 4/4] Update facture.class.php --- htdocs/compta/facture/class/facture.class.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php index 277f1c85e40..f90505a58d9 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -4828,10 +4828,10 @@ class FactureLigne extends CommonInvoiceLine * Warning: If invoice is a replacement invoice, this->fk_prev_id is id of the replaced line. * * @param int $invoiceid Invoice id - * @param bool $include_credit_note + * @param bool $include_credit_note Include credit note or not * @return int >= 0 */ - function get_prev_progress($invoiceid, $include_credit_note = true) + 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;