'use strict';

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

RawMaterialCostController.resolve = {
    rawMaterialCost: ['$route', 'RawMaterialCost', function ($route, RawMaterialCost) {
        var id = $route.current.params.id,
            startDate = $route.current.params.StartDate,
            finishDate = $route.current.params.FinishDate;

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