'use strict';

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

StockMovementCtrl.resolve = {
    stockMovement: ['$route', 'StockMovement', function ($route, StockMovement) {
        var startDate = $route.current.params.StartDate,
            finishDate = $route.current.params.FinishDate;

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