﻿'use strict';
(function () {
    angular.module('app')
           .controller('accounts', accounts);

    accounts.$inject = ['$scope', '$state', '$stateParams', 'authService', 'accountsService', 'categoryService', 'transactionService'];

    function accounts($scope, $state, $stateParams, authService, accountsService, categoryService, transactionService) {


        
        $scope.authentication = authService.authentication;
        $scope.currentHouseHold = authService.authentication.currentHouseHold;
        $scope.income = null;
        $scope.expenses = null;
        $scope.name = '';
        $scope.balance = '';
        $scope.categories = [];
        $scope.deleteAccountId = null;
        accountsService.refreshAccounts($scope.currentHouseHold);
        categoryService.refreshCategories();
        $scope.getAccounts = accountsService.getAccounts;

        $scope.deleteAccount = function (accountid) {
            accountsService.deleteAccount(accountid);
        }

        $scope.updateAccount = function (data, id) {
            angular.extend(data, { id: id });
            accountsService.updateAccount(data);
        }

        $scope.getExpenses = function () {
            return $scope.categories = categoryService.getExpenseCategories;
        }

        $scope.getIncome = function () {
           return $scope.categories = categoryService.getIncomeCategories;
        }

        $scope.submit = function () {
            accountsService.newAccount($scope.currentHouseHold, $scope.name, $scope.balance);
            $scope.name = '';
            $scope.balance = '';
        }
    };
})();

