'use strict';

var ProfitLossCtrl = ['$scope', '$location', 'asDateFilter', 'profit_loss', function ($scope, $location, asDate, profit_loss) {
    $scope.info = profit_loss;
    $scope.show = function () {
        var startDate = asDate($scope.info.StartDate),
            finishDate = asDate($scope.info.FinishDate);
        $location.path('/ProfitLoss').search({StartDate: startDate, FinishDate: finishDate});
    };
    $('#txtStartDate').focus();
}];

ProfitLossCtrl.resolve = {
    profit_loss: ['$route', 'ProfitLoss', function ($route, ProfitLoss) {
        var startDate = $route.current.params.StartDate,
            finishDate = $route.current.params.FinishDate;

        if (angular.isUndefined(startDate) || angular.isUndefined(finishDate)) {
            return ProfitLoss.get({}).$promise;
        } else {
            return ProfitLoss.get({StartDate: startDate, FinishDate: finishDate}).$promise;
        }
    }]
};