1
1
$ ( document ) . ready ( function ( ) {
2
-
3
2
$ ( '.btn-primary' ) . click ( function ( e ) {
4
3
e . preventDefault ( ) ;
5
4
$ ( '#credit, #debit' ) . val ( '' ) ;
6
5
} ) ;
7
-
8
-
9
-
10
6
} ) ;
11
7
12
8
function ctrl ( $scope ) {
@@ -17,25 +13,12 @@ function ctrl($scope){
17
13
18
14
$scope . temp = false ;
19
15
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
-
33
16
$scope . total = function ( ) {
34
17
var total = 0 ;
35
18
for ( var i = 0 ; i < $scope . rows . length ; i ++ ) {
36
19
total = ( total + $scope . rows [ i ] . amount ) ;
37
20
}
38
- return total ;
21
+ return total . toFixed ( 2 ) ;
39
22
} ;
40
23
41
24
$scope . creditdebit = function ( amount ) {
@@ -48,25 +31,20 @@ function ctrl($scope){
48
31
} ;
49
32
50
33
$scope . creditTemp = function ( ) {
51
- //if($scope.temp) $scope.rows.pop();
52
- //else if($scope.creditAmount) $scope.temp = true;
53
-
54
34
rightnow = $scope . todaysDate ( ) ;
55
35
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 } ] ) ;
57
37
else $scope . temp = false ;
58
38
59
39
} ;
60
40
61
41
$scope . debitTemp = function ( ) {
62
- //if($scope.temp) $scope.rows.pop();
63
- //else if($scope.debitAmount) $scope.temp = true;
64
-
65
42
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
+ }
70
48
} ;
71
49
72
50
$scope . todaysDate = function ( ) {
@@ -87,7 +65,6 @@ function ctrl($scope){
87
65
}
88
66
89
67
today = dd + '-' + mm + '-' + yyyy + ' ' + hour + ':' + minute ;
90
-
91
68
return today ;
92
69
93
70
}
0 commit comments