'use strict';

var ClosingStockCtrl = ['$scope', '$location', 'dateFilter', 'info', function ($scope, $location, dateFilter, info) {
    $scope.info = info;
    $scope.show = function () {
        if (angular.isDate($scope.info.Date)) {
            $scope.info.Date = dateFilter($scope.info.Date, 'dd-MMM-yyyy');
        }
        $location.path('/ClosingStock/' + $scope.info.Date);
    };
    $('#txtDate').focus();
}];

ClosingStockCtrl.resolve = {
    info:['$route', 'ClosingStock', function ($route, ClosingStock) {
        var date = $route.current.params.date;

        if (typeof date === 'undefined') {
            return ClosingStock.get({}).$promise;
        } else {
            return ClosingStock.get({date:date}).$promise;
        }
    }]
};