'use strict';

var TrialBalanceCtrl = ['$scope', '$location', 'dateFilter', 'trial_balance', function ($scope, $location, dateFilter, trial_balance) {
    $scope.info = trial_balance;

    $scope.show = function () {
        if (angular.isDate($scope.info.Date)) {
            $scope.info.Date = dateFilter($scope.info.Date, 'dd-MMM-yyyy');
        }
        $location.path('/TrialBalance/' + $scope.info.Date);
    };
    $('#txtDate').focus();
}];
TrialBalanceCtrl.resolve = {
    trial_balance: ['$q', '$route', 'TrialBalance', function ($q, $route, TrialBalance) {
        var deferred = $q.defer();

        var date = $route.current.params.date;

        var successCb = function (result) {
            deferred.resolve(result);
        };

        if (typeof date === 'undefined') {
            TrialBalance.get({}, successCb);
        } else {
            TrialBalance.get({date: date}, successCb);
        }
        return deferred.promise;
    }]
};