Skip to content

Commit 3c726f3

Browse files
author
Conway Hyacienth
committed
all that needed now is persistant data
1 parent 424c397 commit 3c726f3

File tree

1 file changed

+7
-30
lines changed

1 file changed

+7
-30
lines changed

js/main.js

+7-30
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
11
$(document).ready(function() {
2-
32
$('.btn-primary').click(function(e) {
43
e.preventDefault();
54
$('#credit, #debit').val('');
65
});
7-
8-
9-
106
});
117

128
function ctrl($scope){
@@ -17,25 +13,12 @@ function ctrl($scope){
1713

1814
$scope.temp = false;
1915

20-
$scope.addRow = function(){
21-
$scope.temp = false;
22-
$scope.addName="";
23-
};
24-
25-
$scope.deleteRow = function(row){
26-
$scope.rows.splice($scope.rows.indexOf(row),1);
27-
};
28-
29-
$scope.plural = function (tab){
30-
return tab.length > 1 ? 's': '';
31-
};
32-
3316
$scope.total = function (){
3417
var total = 0;
3518
for(var i = 0; i < $scope.rows.length; i++){
3619
total = (total + $scope.rows[i].amount);
3720
}
38-
return total;
21+
return total.toFixed(2);
3922
};
4023

4124
$scope.creditdebit = function (amount){
@@ -48,25 +31,20 @@ function ctrl($scope){
4831
};
4932

5033
$scope.creditTemp = function(){
51-
//if($scope.temp) $scope.rows.pop();
52-
//else if($scope.creditAmount) $scope.temp = true;
53-
5434
rightnow = $scope.todaysDate();
5535

56-
if($scope.creditAmount) $scope.rows = $scope.rows.concat( [{amount:+$scope.creditAmount, date:rightnow}] );
36+
if($scope.creditAmount) $scope.rows = $scope.rows.concat( [{amount:+$scope.creditAmount.toFixed(2), date:rightnow}] );
5737
else $scope.temp = false;
5838

5939
};
6040

6141
$scope.debitTemp = function(){
62-
//if($scope.temp) $scope.rows.pop();
63-
//else if($scope.debitAmount) $scope.temp = true;
64-
6542
rightnow = $scope.todaysDate();
66-
67-
if($scope.debitAmount) $scope.rows = $scope.rows.concat( [{amount:-$scope.debitAmount, date:rightnow}] );
68-
else $scope.temp = false;
69-
43+
total = $scope.total();
44+
if((parseFloat(total) - parseFloat($scope.debitAmount)) > 0 ){
45+
if($scope.debitAmount) $scope.rows = $scope.rows.concat( [{amount:-$scope.debitAmount.toFixed(2), date:rightnow}] );
46+
else $scope.temp = false;
47+
}
7048
};
7149

7250
$scope.todaysDate = function(){
@@ -87,7 +65,6 @@ function ctrl($scope){
8765
}
8866

8967
today = dd+'-'+mm+'-'+yyyy+' '+hour+':'+minute;
90-
9168
return today;
9269

9370
}

0 commit comments

Comments
 (0)