'use strict';

var CashFlowCtrl = ['$scope', '$routeParams', '$location', 'cash_flow', function ($scope, $routeParams, $location, cash_flow) {
    $scope.info = cash_flow;
    $scope.show = function () {
        $location.path('/CashFlow').search({StartDate:$scope.info.StartDate, FinishDate:$scope.info.FinishDate});
    };
    $('#txtStartDate').focus();
}]
CashFlowCtrl.resolve = {
    cash_flow:['$q', '$route', 'CashFlow', function ($q, $route, CashFlow) {
        var deferred = $q.defer();

        var id = $route.current.params.id;
        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') {
            CashFlow.get({}, successCb);
        } else if (typeof id === 'undefined') {
            CashFlow.get({StartDate:start_date, FinishDate:finish_date}, successCb);
        } else {
            CashFlow.get({id:id, StartDate:start_date, FinishDate:finish_date}, successCb);
        }
        return deferred.promise;
    }]
};
