diff --git a/htdocs/accountancy/journal/sellsjournal.php b/htdocs/accountancy/journal/sellsjournal.php index 61f503f5fcb7b17ce153f407e9e00e82ed762528..d0c65e8e909ee63ea28e9c00df561fbad9cbb866 100644 --- a/htdocs/accountancy/journal/sellsjournal.php +++ b/htdocs/accountancy/journal/sellsjournal.php @@ -141,8 +141,8 @@ if ($result) { // Situation invoices handling $line = new FactureLigne($db); - $line->fetch($obj->rowid); - $prev_progress = $line->get_prev_progress(); + $line->fetch($obj->fdid); // id of line + $prev_progress = $line->get_prev_progress($obj->rowid); // id of invoice if ($obj->type == Facture::TYPE_SITUATION) { // Avoid divide by 0 if ($obj->situation_percent == 0) { diff --git a/htdocs/compta/facture.php b/htdocs/compta/facture.php index 951270c19fe91aac96ff339b55c0dd5cc1c3a9e7..b45ce4a33e3287aad49cbd55f8c4911d9664cdcf 100644 --- a/htdocs/compta/facture.php +++ b/htdocs/compta/facture.php @@ -1564,7 +1564,7 @@ if (empty($reshook)) $line = new FactureLigne($db); $line->fetch(GETPOST('lineid')); - $percent = $line->get_prev_progress(); + $percent = $line->get_prev_progress($object->id); if (GETPOST('progress') < $percent) { @@ -1682,7 +1682,7 @@ if (empty($reshook)) { foreach ($object->lines as $line) { - $percent = $line->get_prev_progress(); + $percent = $line->get_prev_progress($object->id); if (GETPOST('all_progress') < $percent) { $mesg = '<div class="warning">' . $langs->trans("CantBeLessThanMinPercent") . '</div>'; $result = -1; diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php index 7c761ccb40f5034ba92e652a4446e4999052add6..0f41620bd89f4277ec635dbdcbaec81b66e48ce0 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -4256,15 +4256,22 @@ class FactureLigne extends CommonInvoiceLine } /** - * Returns situation_percent of the previous line + * Returns situation_percent of the previous line. + * Warning: If invoice is a replacement invoice, this->fk_prev_id is id of the replaced line. * - * @return int >= 0 + * @param int $invoiceid Invoice id + * @return int >= 0 */ - function get_prev_progress() + function get_prev_progress($invoiceid) { if (is_null($this->fk_prev_id) || empty($this->fk_prev_id) || $this->fk_prev_id == "") { return 0; } else { + // If invoice is a not a situation invoice, this->fk_prev_id is used for something else + $tmpinvoice=new Facture($this->db); + $tmpinvoice->fetch($invoiceid); + if ($tmpinvoice->type != Facture::TYPE_SITUATION) return 0; + $sql = 'SELECT situation_percent FROM ' . MAIN_DB_PREFIX . 'facturedet WHERE rowid=' . $this->fk_prev_id; $resql = $this->db->query($sql); if ($resql && $resql->num_rows > 0) { diff --git a/htdocs/compta/journal/sellsjournal.php b/htdocs/compta/journal/sellsjournal.php index cddbdcaa064746046f1a9a169dff426847e7a738..c0ebdb1aa3ac9f9eb0ef101d616f0c0d1b8a7774 100644 --- a/htdocs/compta/journal/sellsjournal.php +++ b/htdocs/compta/journal/sellsjournal.php @@ -166,8 +166,8 @@ if ($result) // Situation invoices handling $line = new FactureLigne($db); - $line->fetch($obj->id); - $prev_progress = $line->get_prev_progress(); + $line->fetch($obj->id); // id of line + $prev_progress = $line->get_prev_progress($obj->rowid); // id on invoice if ($obj->type==Facture::TYPE_SITUATION) { // Avoid divide by 0 if ($obj->situation_percent == 0) { diff --git a/htdocs/core/modules/facture/doc/pdf_crabe.modules.php b/htdocs/core/modules/facture/doc/pdf_crabe.modules.php index 8637f02bebce8b67aa687ddb9176d2f0119f3e1e..c627da6841890b59065c83dccc673fb8a11c0b6d 100644 --- a/htdocs/core/modules/facture/doc/pdf_crabe.modules.php +++ b/htdocs/core/modules/facture/doc/pdf_crabe.modules.php @@ -167,7 +167,7 @@ class pdf_crabe extends ModelePDFFactures function write_file($object,$outputlangs,$srctemplatepath='',$hidedetails=0,$hidedesc=0,$hideref=0) { global $user,$langs,$conf,$mysoc,$db,$hookmanager; - + if (! is_object($outputlangs)) $outputlangs=$langs; // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO if (! empty($conf->global->MAIN_USE_FPDF)) $outputlangs->charset_output='ISO-8859-1'; @@ -540,13 +540,14 @@ class pdf_crabe extends ModelePDFFactures $pdf->MultiCell($this->page_largeur-$this->marge_droite-$this->postotalht, 3, $total_excl_tax, 0, 'R', 0); // Collecte des totaux par valeur de tva dans $this->tva["taux"]=total_tva - $prev_progress = $object->lines[$i]->get_prev_progress(); + $prev_progress = $object->lines[$i]->get_prev_progress($object->id); if ($prev_progress > 0) // Compute progress from previous situation { $tvaligne = $object->lines[$i]->total_tva * ($object->lines[$i]->situation_percent - $prev_progress) / $object->lines[$i]->situation_percent; } else { $tvaligne = $object->lines[$i]->total_tva; } + $localtax1ligne=$object->lines[$i]->total_localtax1; $localtax2ligne=$object->lines[$i]->total_localtax2; $localtax1_rate=$object->lines[$i]->localtax1_tx; @@ -1103,7 +1104,8 @@ class pdf_crabe extends ModelePDFFactures } } } - //} + + //} // VAT foreach($this->tva as $tvakey => $tvaval) {