mirror of
https://github.com/gwenhael-le-moine/ledgerrb.git
synced 2025-01-26 07:58:10 +01:00
refactoring
This commit is contained in:
parent
7f8f165279
commit
d6469c6007
2 changed files with 34 additions and 60 deletions
|
@ -89,83 +89,57 @@ app.controller( 'BalanceCtrl',
|
|||
|
||||
$scope.balance = {
|
||||
buckets: [ {
|
||||
name: 'Expenses',
|
||||
categories: 'Expenses',
|
||||
data: [],
|
||||
total: 0
|
||||
}, {
|
||||
name: 'Income',
|
||||
categories: 'Income Equity',
|
||||
data: [],
|
||||
total: 0
|
||||
} ],
|
||||
details: {}
|
||||
};
|
||||
|
||||
$http.get( '/api/ledger/balance', {
|
||||
params: {
|
||||
period: period,
|
||||
categories: 'Expenses'
|
||||
}
|
||||
} )
|
||||
.then( function ( response ) {
|
||||
$scope.balance.buckets[ 0 ].data = _( response.data ).sortBy( function ( account ) {
|
||||
return 1 / account.amount;
|
||||
} );
|
||||
_( $scope.balance.buckets[ 0 ].data ).each(
|
||||
function ( account ) {
|
||||
$http.get( '/api/ledger/register', {
|
||||
params: {
|
||||
period: period,
|
||||
category: account.account
|
||||
}
|
||||
_($scope.balance.buckets).each( function( bucket ) {
|
||||
$http.get( '/api/ledger/balance', {
|
||||
params: {
|
||||
period: period,
|
||||
categories: bucket.categories
|
||||
}
|
||||
} )
|
||||
.then( function ( response ) {
|
||||
bucket.data = _.chain( response.data )
|
||||
.map( function( account ) {
|
||||
account.amount = ( account.amount < 0 ) ? account.amount * -1 : account.amount;
|
||||
return account;
|
||||
} )
|
||||
.then( function ( response ) {
|
||||
$scope.balance.details[ account.account ] = response.data;
|
||||
} );
|
||||
} );
|
||||
$scope.balance.buckets[ 0 ].total = _( response.data ).reduce( function ( memo, account ) {
|
||||
return memo + account.amount;
|
||||
}, 0 );
|
||||
} );
|
||||
$http.get( '/api/ledger/balance', {
|
||||
params: {
|
||||
period: period,
|
||||
categories: 'Income'
|
||||
}
|
||||
} )
|
||||
|
||||
.then( function ( response ) {
|
||||
$scope.balance.buckets[ 1 ].data = _( response.data )
|
||||
.map( function ( account ) {
|
||||
account.amount = account.amount * -1;
|
||||
return account;
|
||||
} );
|
||||
$scope.balance.buckets[ 1 ].data = _( $scope.balance.buckets[ 1 ].data )
|
||||
.sortBy( function ( account ) {
|
||||
return account.amount;
|
||||
} );
|
||||
_( $scope.balance.buckets[ 1 ].data )
|
||||
.each( function ( account ) {
|
||||
$http.get( '/api/ledger/register', {
|
||||
params: {
|
||||
period: period,
|
||||
category: account.account
|
||||
}
|
||||
.sortBy( function ( account ) {
|
||||
return 1 / account.amount;
|
||||
} )
|
||||
.then( function ( response ) {
|
||||
$scope.balance.details[ account.account ] = response.data;
|
||||
} );
|
||||
} );
|
||||
$scope.balance.buckets[ 1 ].total = _( response.data )
|
||||
.reduce( function ( memo, account ) {
|
||||
.value();
|
||||
_( bucket.data ).each(
|
||||
function ( account ) {
|
||||
$http.get( '/api/ledger/register', {
|
||||
params: {
|
||||
period: period,
|
||||
category: account.account
|
||||
}
|
||||
} )
|
||||
.then( function ( response ) {
|
||||
$scope.balance.details[ account.account ] = response.data;
|
||||
} );
|
||||
} );
|
||||
bucket.total = _( response.data ).reduce( function ( memo, account ) {
|
||||
return memo + account.amount;
|
||||
}, 0 );
|
||||
} );
|
||||
} );
|
||||
} );
|
||||
};
|
||||
|
||||
$scope.dates_salaries = [];
|
||||
$scope.period_offset = 0;
|
||||
$scope.after = function () {
|
||||
if ( $scope.period_offset < $scope.dates_salaries.length - 1 ) {
|
||||
if ( $scope.period_offset < $scope.dates_salaries.length ) {
|
||||
$scope.period_offset++;
|
||||
}
|
||||
};
|
||||
|
|
|
@ -27,7 +27,7 @@
|
|||
<div layout="vertical" layout-md="horizontal" layout-padding>
|
||||
<div flex data-ng-repeat="bucket in balance.buckets">
|
||||
<material-toolbar class="material-theme-light">
|
||||
<h3>{{bucket.name}}, total = {{bucket.total | number:2}} €</h3>
|
||||
<h3>{{bucket.categories}}, total = {{bucket.total | number:2}} €</h3>
|
||||
</material-toolbar>
|
||||
<material-content>
|
||||
<nvd3-pie-chart data="bucket.data"
|
||||
|
|
Loading…
Add table
Reference in a new issue