Fix regression on vat calculation when invoice was not a situation

invoice
This commit is contained in:
Laurent Destailleur 2016-03-12 20:49:38 +01:00
parent e0809fc750
commit 1b30c1adb4
5 changed files with 21 additions and 12 deletions

View File

@ -141,8 +141,8 @@ if ($result) {
// Situation invoices handling // Situation invoices handling
$line = new FactureLigne($db); $line = new FactureLigne($db);
$line->fetch($obj->rowid); $line->fetch($obj->fdid); // id of line
$prev_progress = $line->get_prev_progress(); $prev_progress = $line->get_prev_progress($obj->rowid); // id of invoice
if ($obj->type == Facture::TYPE_SITUATION) { if ($obj->type == Facture::TYPE_SITUATION) {
// Avoid divide by 0 // Avoid divide by 0
if ($obj->situation_percent == 0) { if ($obj->situation_percent == 0) {

View File

@ -1564,7 +1564,7 @@ if (empty($reshook))
$line = new FactureLigne($db); $line = new FactureLigne($db);
$line->fetch(GETPOST('lineid')); $line->fetch(GETPOST('lineid'));
$percent = $line->get_prev_progress(); $percent = $line->get_prev_progress($object->id);
if (GETPOST('progress') < $percent) if (GETPOST('progress') < $percent)
{ {
@ -1682,7 +1682,7 @@ if (empty($reshook))
{ {
foreach ($object->lines as $line) foreach ($object->lines as $line)
{ {
$percent = $line->get_prev_progress(); $percent = $line->get_prev_progress($object->id);
if (GETPOST('all_progress') < $percent) { if (GETPOST('all_progress') < $percent) {
$mesg = '<div class="warning">' . $langs->trans("CantBeLessThanMinPercent") . '</div>'; $mesg = '<div class="warning">' . $langs->trans("CantBeLessThanMinPercent") . '</div>';
$result = -1; $result = -1;

View File

@ -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 == "") { if (is_null($this->fk_prev_id) || empty($this->fk_prev_id) || $this->fk_prev_id == "") {
return 0; return 0;
} else { } 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; $sql = 'SELECT situation_percent FROM ' . MAIN_DB_PREFIX . 'facturedet WHERE rowid=' . $this->fk_prev_id;
$resql = $this->db->query($sql); $resql = $this->db->query($sql);
if ($resql && $resql->num_rows > 0) { if ($resql && $resql->num_rows > 0) {

View File

@ -166,8 +166,8 @@ if ($result)
// Situation invoices handling // Situation invoices handling
$line = new FactureLigne($db); $line = new FactureLigne($db);
$line->fetch($obj->id); $line->fetch($obj->id); // id of line
$prev_progress = $line->get_prev_progress(); $prev_progress = $line->get_prev_progress($obj->rowid); // id on invoice
if ($obj->type==Facture::TYPE_SITUATION) { if ($obj->type==Facture::TYPE_SITUATION) {
// Avoid divide by 0 // Avoid divide by 0
if ($obj->situation_percent == 0) { if ($obj->situation_percent == 0) {

View File

@ -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); $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 // 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 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; $tvaligne = $object->lines[$i]->total_tva * ($object->lines[$i]->situation_percent - $prev_progress) / $object->lines[$i]->situation_percent;
} else { } else {
$tvaligne = $object->lines[$i]->total_tva; $tvaligne = $object->lines[$i]->total_tva;
} }
$localtax1ligne=$object->lines[$i]->total_localtax1; $localtax1ligne=$object->lines[$i]->total_localtax1;
$localtax2ligne=$object->lines[$i]->total_localtax2; $localtax2ligne=$object->lines[$i]->total_localtax2;
$localtax1_rate=$object->lines[$i]->localtax1_tx; $localtax1_rate=$object->lines[$i]->localtax1_tx;
@ -1103,7 +1104,8 @@ class pdf_crabe extends ModelePDFFactures
} }
} }
} }
//}
//}
// VAT // VAT
foreach($this->tva as $tvakey => $tvaval) foreach($this->tva as $tvakey => $tvaval)
{ {