From 89f4dbe64f10f06ac5aa4797e6ac1e199d8baee3 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Josep=20Llu=C3=ADs?= <joseplluis@lliuretic.cat>
Date: Tue, 11 Oct 2016 16:37:44 +0200
Subject: [PATCH] Fix bug: replaced invoices in projects

In balance whole project, don't count the total amount in replaced invoices.
In invoice details the replaced invoices are OK.
---
 htdocs/projet/element.php | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/htdocs/projet/element.php b/htdocs/projet/element.php
index 502734441d7..40cf0c9e7e0 100644
--- a/htdocs/projet/element.php
+++ b/htdocs/projet/element.php
@@ -5,6 +5,7 @@
  * Copyright (C) 2012-2016 Juanjo Menent        <jmenent@2byte.es>
  * Copyright (C) 2015      Alexandre Spangaro	<aspangaro.dolibarr@gmail.com>
  * Copyright (C) 2015      Marcos García        <marcosgdf@gmail.com>
+ * Copyright (C) 2016      Josep Lluís Amador   <joseplluis@lliuretic.cat>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -484,7 +485,13 @@ foreach ($listofreferent as $key => $value)
 				}
 				else $total_ht_by_line=$element->total_ht;
 
-				$total_ht = $total_ht + $total_ht_by_line;
+				$qualifiedfortotal=true;
+				if ($key == 'invoice')
+				{
+					if (! empty($element->close_code) && $element->close_code == 'replaced') $qualifiedfortotal=false;	// Replacement invoice, do not include into total
+				}
+				
+				if ($qualifiedfortotal) $total_ht = $total_ht + $total_ht_by_line;
 
 				if ($tablename == 'don') $total_ttc_by_line=$element->amount;
 				elseif ($tablename == 'projet_task')
@@ -494,7 +501,7 @@ foreach ($listofreferent as $key => $value)
 				}
 				else $total_ttc_by_line=$element->total_ttc;
 
-				$total_ttc = $total_ttc + $total_ttc_by_line;
+				if ($qualifiedfortotal) $total_ttc = $total_ttc + $total_ttc_by_line;
 			}
 
 			// Calculate margin
-- 
GitLab