'use strict';

var PurchasesController = ['$scope', '$routeParams', '$location', 'asDateFilter', 'purchases', function ($scope, $routeParams, $location, asDate, purchases) {
    $scope.info = purchases;
    $scope.show = function () {
        var startDate = asDate($scope.info.StartDate),
            finishDate = asDate($scope.info.FinishDate);
        $location.path('/Purchases').search({s: startDate, f: finishDate});
    };
}];
PurchasesController.resolve = {
    purchases: ['$route', 'Purchases', function ($route, Purchases) {
        var startDate = $route.current.params.s,
            finishDate = $route.current.params.f;

        if (angular.isUndefined(startDate) || angular.isUndefined(finishDate)) {
            return Purchases.get({}).$promise;
        } else {
            return Purchases.get({s: startDate, f: finishDate}).$promise;
        }
    }]
};
