Commits

Dan Connolly committed a35f408

basic budget export table seems to work

Comments (0)

Files changed (1)

 
 function make_budget_window(){
     var categories = Mint.CategorySearch.getJson();
+    var current_income = Mint.PlanningData.getJson(true, new Date());
+    var current_spending = Mint.PlanningData.getJson(false, new Date());
 
+    var budget = function(id) {
+	for (i=0; i<current_income.bu.length; i++) {
+	    var b = current_income.bu[i];
+	    if (b.cat == id) {
+		return b;
+	    }
+	}
+	for (i=0; i<current_spending.bu.length; i++) {
+	    var b = current_spending.bu[i];
+	    if (b.cat == id) {
+		return b;
+	    }
+	}
+    }
     //http://www.quirksmode.org/js/popup.html
     ugly_but_reportedly_necessary_global = window.open('', 'budget_window',
 						       'height=400, width=600');
 
     mk(b, 'h1').textContent = 'Budget';
     var t = mk(b, 'table');
-    mk(mk(t, 'tr'), 'th').textContent = 'Category';
+    var thead = mk(t, 'tr')
+    mk(thead, 'th').textContent = 'id';
+    mk(thead, 'th').textContent = 'Category';
+    mk(thead, 'th').textContent = 'Subcategory';
+    mk(thead, 'th').textContent = 'Amount';
+    mk(thead, 'th').textContent = 'Budget';
+
+    var docat = function(cat, subcat) {
+	var b, row = mk(t, 'tr');
+	mk(row, 'td').textContent = subcat ? subcat.id : cat.id;
+	mk(row, 'td').textContent = cat.value;
+	if (subcat) {
+	    mk(row, 'td').textContent = subcat.value;
+	    b = budget(subcat.id);
+	    if (!b) {
+		YAHOO.log('no budget for subcat: ' + subcat.value);
+	    }
+	} else {
+	    mk(row, 'td');
+	    b = budget(cat.id);
+	    if (!b) {
+		YAHOO.log('no budget for: ' + cat.value);
+	    }
+	}
+
+	if (b) {
+	    mk(row, 'td').textContent = b.amt;
+	    mk(row, 'td').textContent = b.bgt;
+	}
+    }
+
     categories.forEach(function(cat) {
-	mk(mk(t, 'tr'), 'td').textContent = cat.value;
+	docat(cat);
+	var row = mk(t, 'tr')
+	cat.children.forEach(function(subcat) {
+	    docat(cat, subcat);
+	});
     });
 }
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.