'use strict';

function PurchaseEntriesCtrl($scope, $location, purchase_entries) {
    $scope.info = purchase_entries;

    $scope.show = function () {
        $location.path('/PurchaseEntries').search({StartDate:$scope.info.StartDate, FinishDate:$scope.info.FinishDate});
    };
    $('#txtStartDate').focus();
}

PurchaseEntriesCtrl.resolve = {
    purchase_entries:function ($q, $route, PurchaseEntries) {
        var deferred = $q.defer();

        var start_date = $route.current.params.StartDate;
        var finish_date = $route.current.params.FinishDate;

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

        if (typeof start_date === 'undefined' || typeof finish_date === 'undefined') {
            PurchaseEntries.get({}, successCb);
        } else {
            PurchaseEntries.get({StartDate:start_date, FinishDate:finish_date}, successCb);
        }
        return deferred.promise;
    }
};


