(function() {
	window.app.factory('transactionSvc', [
		'$http', 'inventorySvc',
		function($http, inventorySvc) {

			var svc = {
				filterByPage: filterByPage,
				filterByInventoryId: filterByInventoryId,
				deleteTransaction: deleteTransaction
			};

			return svc;

			function filterByPage(pageNumber, pageSize) {
				return getTransactions({ pageNumber: pageNumber, pageSize: pageSize });
			}

			function filterByInventoryId(inventoryId) {
				return getTransactions({ inventoryId: inventoryId });
			}

			function getTransactions(params) {
				var url = '/Transaction/Get';
				return $http.post(url, params)
					.success(function(data) {
					});
			}

			function deleteTransaction(transactionId) {
				return $http.post('/Transaction/Delete', { transactionId: transactionId })
					.success(function(data) {
						inventorySvc.refresh(data.inventoryId);
					});
			}
		}]);
})();