(function() {
	window.app.factory("reportSvc",
	[
		"$http",
		function($http) {
			var distributionData = [];
			var distributionQuery = {};
			var movementData = {};

			var svc = {
				distributionData: distributionData,
				distributionQuery: distributionQuery,
				loadDistributionReport: loadDistributionReport,
				exportDistributionReport: exportDistributionReport,
				movementData: movementData,
				loadMovementData: loadMovementData,
				exportMovementData: exportMovementData
			};

			return svc;

			function loadDistributionReport(query) {
				return $http.post("/Report/Distribution", query)
					.success(function(data) {
						distributionQuery = angular.copy(query, distributionQuery);
						angular.copy(data, distributionData);
					});
			}

			function exportDistributionReport(query) {
				return $http.post("/Report/DistributionExcel", query, { responseType: "arraybuffer" });
			}

			function loadMovementData(query) {
				return $http.post("/Report/Movement", query)
					.success(function(data) {
						angular.copy(data, movementData);
					});
			}

			function exportMovementData(query) {
				return $http.post("/Report/MovementExcel", query, { responseType: "arraybuffer" });
			}
		}
	]);
})();