'use strict';

var PurchaseEntriesController = ['$scope', '$location', 'asDateFilter', 'purchaseEntries', function ($scope, $location, asDate, purchaseEntries) {
    $scope.info = purchaseEntries;

    $scope.show = function () {
        var startDate = asDate($scope.info.StartDate),
            finishDate = asDate($scope.info.FinishDate);
        $location.path('/PurchaseEntries').search({StartDate: startDate, FinishDate: finishDate});
    };
    $scope.foDate = true;
}];

PurchaseEntriesController.resolve = {
    purchaseEntries: ['$route', 'PurchaseEntries', function ($route, PurchaseEntries) {
        var startDate = $route.current.params.StartDate,
            finishDate = $route.current.params.FinishDate;

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