'use strict'; var ProductLedgerController = ['$scope', '$routeParams', '$location', 'asDateFilter', 'productLedger', 'ProductLedger', 'Product', 'uibDateParser', function ($scope, $routeParams, $location, asDate, productLedger, ProductLedger, Product, dateParser) { var _info_StartDate = dateParser.parse(productLedger.StartDate, "dd-MMM-yyyy"), _info_FinishDate = dateParser.parse(productLedger.FinishDate, "dd-MMM-yyyy"); $scope.info_StartDate = function (value) { if (arguments.length) { $scope.info.StartDate = asDate(value); _info_StartDate = value; } return _info_StartDate; }; $scope.info_FinishDate = function (value) { if (arguments.length) { $scope.info.FinishDate = asDate(value); _info_FinishDate = value; } return _info_FinishDate; }; $scope.info = productLedger; $scope.show = function () { var id = $scope.info.Product.ProductID; if (id === $routeParams.id && $scope.info.StartDate === $routeParams.StartDate && $scope.info.FinishDate === $routeParams.FinishDate) { ProductLedger.get({id: id, StartDate: $scope.info.StartDate, FinishDate: $scope.info.FinishDate}, function (data) { $scope.info = data; }); } else { $location.path('/ProductLedger/' + $scope.info.Product.ProductID).search('StartDate', $scope.info.StartDate).search('FinishDate', $scope.info.FinishDate); } }; $scope.downloadTable = function () { var table = $('#gvGrid'), html = table.clone().wrap('
').parent().html(); html = html.replace(/á/g, 'á'); window.open('data:application/vnd.ms-excel;charset=UTF-8,' + encodeURIComponent(html)); }; $scope.products = function ($viewValue) { return Product.autocomplete({term: $viewValue, count: 20}).$promise; }; $scope.foProduct = true; }]; ProductLedgerController.resolve = { productLedger: ['$route', 'ProductLedger', function ($route, ProductLedger) { var id = $route.current.params.id, startDate = $route.current.params.StartDate, finishDate = $route.current.params.FinishDate; if (angular.isUndefined(id)) { return ProductLedger.get({}).$promise; } else { return ProductLedger.get({id: id, StartDate: startDate, FinishDate: finishDate}).$promise; } }] };