Separate solds and balance from account model.
This commit is contained in:
@ -19,11 +19,19 @@
|
||||
accountantApp
|
||||
|
||||
.factory("Account", ["$resource", function($resource) {
|
||||
return $resource(
|
||||
var Account = $resource(
|
||||
"/api/account/:id", {
|
||||
id: "@id"
|
||||
}
|
||||
);
|
||||
|
||||
Account.prototype.getSolds = function() {
|
||||
var Solds = $resource("/api/account/:id/solds", {id: this.id});
|
||||
|
||||
this.solds = Solds.get();
|
||||
};
|
||||
|
||||
return Account;
|
||||
}])
|
||||
|
||||
.controller(
|
||||
|
@ -43,13 +43,22 @@ accountantApp
|
||||
);
|
||||
}])
|
||||
|
||||
.factory("Balance", [ "$resource", "$routeParams",
|
||||
function($resource, $routeParams) {
|
||||
return $resource(
|
||||
"/api/account/:account_id/balance", {
|
||||
account_id: $routeParams.accountId
|
||||
}
|
||||
);
|
||||
}])
|
||||
|
||||
/*
|
||||
* Controller for category chart.
|
||||
*/
|
||||
.controller(
|
||||
"CategoryChartController", [
|
||||
"$rootScope", "$scope", "$http", "$routeParams", "Category",
|
||||
function($rootScope, $scope, $http, $routeParams, Category) {
|
||||
"$rootScope", "$scope", "$http", "Category", "Balance",
|
||||
function($rootScope, $scope, $http, Category, Balance) {
|
||||
|
||||
var colors = Highcharts.getOptions().colors;
|
||||
$scope.revenueColor = colors[2];
|
||||
@ -150,30 +159,25 @@ accountantApp
|
||||
};
|
||||
|
||||
/*
|
||||
* Get account status.
|
||||
* Get account balance.
|
||||
*/
|
||||
$scope.getAccountStatus = function(begin, end) {
|
||||
$http.get("/api/account/" + $routeParams.accountId, {
|
||||
params: {
|
||||
begin: begin.format('YYYY-MM-DD'),
|
||||
end: end.format('YYYY-MM-DD')
|
||||
}
|
||||
}).success(function(account) {
|
||||
// Emit accountLoadedEvent.
|
||||
$scope.$emit("accountLoadedEvent", account);
|
||||
|
||||
$scope.getBalance = function(begin, end) {
|
||||
Balance.get({
|
||||
begin: begin.format("YYYY-MM-DD"),
|
||||
end: end.format("YYYY-MM-DD")
|
||||
}, function(balance) {
|
||||
// Update pie chart subtitle with Balance.
|
||||
$scope.config.subtitle = {
|
||||
text: "Balance: " + account.balance
|
||||
text: "Balance: " + balance.balance
|
||||
};
|
||||
|
||||
$scope.config.series[0].data = [{
|
||||
name: "Revenues",
|
||||
y: account.revenues,
|
||||
y: balance.revenues,
|
||||
color: $scope.revenueColor
|
||||
}, {
|
||||
name: "Expenses",
|
||||
y: -account.expenses,
|
||||
y: -balance.expenses,
|
||||
color: $scope.expenseColor,
|
||||
}];
|
||||
});
|
||||
@ -182,7 +186,7 @@ accountantApp
|
||||
// Reload categories and account status on range selection.
|
||||
$rootScope.$on("rangeSelectedEvent", function(e, args) {
|
||||
$scope.load(args.begin, args.end);
|
||||
$scope.getAccountStatus(args.begin, args.end);
|
||||
$scope.getBalance(args.begin, args.end);
|
||||
});
|
||||
}])
|
||||
|
||||
@ -329,8 +333,8 @@ accountantApp
|
||||
*/
|
||||
.controller(
|
||||
"OperationController", [
|
||||
"$scope", "$rootScope", "$routeParams", "notify", "Operation",
|
||||
function($scope, $rootScope, $routeParams, notify, Operation) {
|
||||
"$scope", "$rootScope", "$routeParams", "notify", "Account", "Operation",
|
||||
function($scope, $rootScope, $routeParams, notify, Account, Operation) {
|
||||
// List of operations.
|
||||
$scope.operations = [];
|
||||
|
||||
@ -442,11 +446,8 @@ accountantApp
|
||||
);
|
||||
};
|
||||
|
||||
/*
|
||||
* Save account in scope to colorize with authorized overdraft.
|
||||
*/
|
||||
$rootScope.$on("accountLoadedEvent", function(e, account) {
|
||||
$scope.account = account;
|
||||
$scope.account = Account.get({
|
||||
id: $routeParams.accountId
|
||||
});
|
||||
|
||||
/*
|
||||
|
@ -37,7 +37,7 @@
|
||||
|
||||
<tr id="{{ account.id }}"
|
||||
class="form-inline" ng-class="rowClass(account)"
|
||||
ng-repeat="account in accounts">
|
||||
ng-repeat="account in accounts" ng-init="account.getSolds()">
|
||||
<td>
|
||||
<span editable-text="account.name"
|
||||
e-placeholder="Nom du compte"
|
||||
@ -48,14 +48,14 @@
|
||||
</td>
|
||||
|
||||
<td>
|
||||
<span ng-class="valueClass(account, account.current)">
|
||||
{{ account.current | currency : "€" }}
|
||||
<span ng-class="valueClass(account, account.solds.current)">
|
||||
{{ account.solds.current | currency : "€" }}
|
||||
</span>
|
||||
</td>
|
||||
|
||||
<td>
|
||||
<span ng-class="valueClass(account, account.pointed)">
|
||||
{{ account.pointed | currency : "€" }}
|
||||
<span ng-class="valueClass(account, account.solds.pointed)">
|
||||
{{ account.solds.pointed | currency : "€" }}
|
||||
</span>
|
||||
</td>
|
||||
|
||||
|
Reference in New Issue
Block a user