From 0476ef27c09bfa78890888fc76a01020cfa78ab4 Mon Sep 17 00:00:00 2001
From: lowercase-donkey <lowercasedonkey@gmail.com>
Date: Wed, 16 Jan 2019 14:01:56 -0500
Subject: [PATCH] Add template literals and improve totals display

---
 src/js/economyJS.tw              |  7 ++++---
 src/uncategorized/costsBudget.tw | 14 ++++++++------
 2 files changed, 12 insertions(+), 9 deletions(-)

diff --git a/src/js/economyJS.tw b/src/js/economyJS.tw
index a8de24b77f4..7c597fa8250 100644
--- a/src/js/economyJS.tw
+++ b/src/js/economyJS.tw
@@ -934,7 +934,8 @@ window.cashX = function(cost, what, who) {
 	const V = State.variables;
 
 	if(isNaN(cost)){
-		V.lastWeeksErrors += (' NaN: \"' + cost + '\"" at ' + what + ',');
+		V.lastWeeksErrors += `NaN: "${cost}" at ${what},
+		`;
 	} else {
 		
 		//INCOME
@@ -957,7 +958,7 @@ window.cashX = function(cost, what, who) {
 					//Spend the money
 					V.cash += cost;
 				} else {
-					V.lastWeeksErrors += (' unknown place \"' + what +'\",');
+					V.lastWeeksErrors += `Unknown place "${what}",`;
 				}
 		}
 		
@@ -976,7 +977,7 @@ window.cashX = function(cost, what, who) {
 					//Spend the money
 					V.cash += cost;
 				} else {
-					V.lastWeeksErrors += (' unknown place \"' + what +'\",');
+					V.lastWeeksErrors += `Unknown place "${what}",`;
 				}
 		}
 		else {
diff --git a/src/uncategorized/costsBudget.tw b/src/uncategorized/costsBudget.tw
index 837941601d6..2c6f913fd5c 100644
--- a/src/uncategorized/costsBudget.tw
+++ b/src/uncategorized/costsBudget.tw
@@ -1006,7 +1006,7 @@ for(var i = 0; i < State.variables.lastWeeksCashIncome.length; i++){
 
 	<tr><td></td></tr>
 	<tr>
-		<td>Totals</td>	
+		<td>Tracked totals</td>	
 		<td>
 			<<set $lastWeeksCashIncome.Total = hashSum($lastWeeksCashIncome)>>
 			$lastWeeksCashIncome.Total
@@ -1017,10 +1017,12 @@ for(var i = 0; i < State.variables.lastWeeksCashIncome.length; i++){
 			$lastWeeksCashExpenses.Total
 		</td>
 		<td>
-			<<print hashSum($lastWeeksCashProfits)>>
-			<br>
-			<<set $lastWeeksCashProfits.Total  = ($lastWeeksCashIncome.Total + $lastWeeksCashExpenses.Total)
-			>>
+			<<set $lastWeeksCashProfits.Total  = ($lastWeeksCashIncome.Total + $lastWeeksCashExpenses.Total)>> 
+			/* each "profit" item is calculated on this sheet, and there's two ways to generate a profit total: the difference of the income and expense totals, and adding all the profit items.  If they aren't the same, I probably forgot to properly add an item's profit calculation to this sheet.*/
+			<<if $lastWeeksCashProfits.Total != hashSum($lastWeeksCashProfits) - $lastWeeksCashProfits.Total>>/* Profits includes the total number of profits, so we have to subtract it back out */
+				<<print (hashSum($lastWeeksCashProfits)-$lastWeeksCashProfits.Total)>><br>
+				@@.red;Fix profit calc<br>@@
+			<</if>>
 			$lastWeeksCashProfits.Total			
 		</td>
 	</tr>
@@ -1035,7 +1037,7 @@ for(var i = 0; i < State.variables.lastWeeksCashIncome.length; i++){
 		<td>Transaction tracking off by:</td>
 		<td></td>
 		<td><<print ($lastWeeksCashExpenses.Total + $costs)>></td>
-		<td><<print off: ($lastWeeksCashProfits.Total - ($cash-$cashLastWeek))>></td>	
+		<td><<print ($lastWeeksCashProfits.Total - ($cash-$cashLastWeek))>></td>	
 	</tr>
 
 </table>
-- 
GitLab