'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:['$q', '$route', 'ClosingStock', function ($q, $route, ClosingStock) {
        var deferred = $q.defer();

        var date = $route.current.params.date;

        var successCb = function(result){
          deferred.resolve(result);
        };

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