'use strict';

function NetTransactionsCtrl($scope, $location, net_transactions) {
    $scope.info = net_transactions;
    $scope.show = function () {
        $location.path('/NetTransactions').search({StartDate:$scope.info.StartDate, FinishDate:$scope.info.FinishDate});
    };
    $('#txtStartDate').focus();
}

NetTransactionsCtrl.resolve = {
    net_transactions:function ($q, $route, NetTransactions) {
        var deferred = $q.defer();

        var start_date = $route.current.params.StartDate;
        var finish_date = $route.current.params.FinishDate;

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

        if (typeof start_date === 'undefined' || typeof finish_date === 'undefined') {
            NetTransactions.get({}, successCb);
        } else {
            NetTransactions.get({StartDate:start_date, FinishDate:finish_date}, successCb);
        }
        return deferred.promise;
    }
};