angular.module('pricebooksService',[]).factory('Products',function($http){
	return {
		getPaging:function(filter){
			 return $http({
                method: 'POST',
                headers: headers,
                url: url_server + 'productspaging',
                data:filter,
                withCredentials: true
            });
			// return $http({method:'POST',url:url_server + 'productspaging',data:filter});
		},
		getSelect:function(){
			return $http({method:'POST',url:url_server + 'products/getall'});
		},
		getSelect2:function(filter, type){
			return $http({
                method: 'POST',
                headers: headers,
                url: url_server +  'products/search',
                data:{filter:filter, type:type},
                withCredentials: true
            });
			// return $http({method:'POST',url:url_server + 'products/search',data:{filter:filter, type:type}});
		},
		getProductsClass:function(){
			 return $http({
                method: 'POST',
                headers: headers,
                url: url_server + 'products/getProductsClass',
                withCredentials: true
            });
			return $http({method:'POST',url:url_server + 'products/getProductsClass'});
		},
		getSecondaryLevel:function(parent_id){
			return $http({
                method: 'POST',
                headers: headers,
                url: url_server + 'products/getSecondaryLevel',
                data:{parent_id:parent_id},
                withCredentials: true
            });
			// return $http({method:'POST',url:url_server + 'products/getSecondaryLevel', data:{parent_id:parent_id}});
		},
		getTertiaryLevel:function(id){
			return $http({
                method: 'POST',
                headers: headers,
                url: url_server + 'products/getTertiaryLevel',
                data:{id:id},
                withCredentials: true
            });
			// return $http({method:'POST',url:url_server + 'products/getTertiaryLevel', data:{id:id}});
		},
		getWarranty:function(){
			 return $http({
                method: 'POST',
                headers: headers,
                url: url_server + 'products/getWarranty',
                withCredentials: true
            });
			// return $http({method:'POST',url:url_server + 'products/getWarranty'});
		},
		getDataProduct:function(id, action){
			return $http({
                method: 'POST',
                headers: headers,
                url: url_server + 'products/getDataProduct',
                data:{id:id, action:action},
                withCredentials: true
            });
			// return $http({method:'POST',url:url_server + 'products/getDataProduct', data:{id:id, action:action}});
		},
		check_order:function(id){
			return $http({
                method: 'POST',
                headers: headers,
                url:url_server + 'products/check_order',
                data:{id:id},
                withCredentials: true
            });
			// return $http({method:'POST',url:url_server + 'products/check_order', data:{id:id}});
		},
		createPricebook:function(PricebookData, file){
			return Upload.upload({url: url_server+'products/createPricebook',fields: PricebookData, file: file});
		},
		EditPricebook:function(PricebookData){
			return $http({
                method: 'POST',
                headers: headers,
                url:url_server+'products/EditPricebook',
                data:PricebookData,
                withCredentials: true
            });
			// return Upload.upload({url: url_server+'products/EditPricebook',fields: PricebookData, file: file});
		},
		show:function(id){
			return $http.get(url_server+ 'products/'+id);
		},
		save:function(productsData){
			return $http({
                method: 'POST',
                headers: headers,
               url:url_server+'products',
               data:productsData,
                withCredentials: true
            });
			// return $http({method:'POST',
			// 				url:url_server+'products',
			// 				data:productsData});
		},
		update:function(id, productsData){
			return $http.put(url_server+'products/'+id,productsData, {
				headers:headers, withCredentials: true });
			
			// return $http.put(url_server+'products/'+id,productsData);
		},
		destroy:function(id){
			return $http.delete(url_server + 'products/'+id);
		},
		import:function(url){
			return $http({method:'POST',url:url_server + 'products/import', data:{url:url}});
		},
		Import_anyway:function(url){
			return $http({method:'POST',url:url_server + 'products/Import_anyway', data:{url:url}});
		},
		uploadFilePricebook:function(file){
			return Upload.upload({url: url_server+'products/uploadFile' ,file: file});
		},
		getManufacturers:function(){
			return $http({
                method: 'POST',
                headers: headers,
                url:url_server+'products/getmanufacturers',
                withCredentials: true
            });
		},
		getProductAvailabilities:function(){
			return $http({
                method: 'POST',
                headers: headers,
                url:url_server+'products/getproductavailabilities',
                withCredentials: true
            });
		},
		getPairProduct: function (data) {
            return $http({
                method: 'POST',
                url: url_server + 'products/getpairproduct',
                data:data,
                headers: headers,
                withCredentials: true
            });
        },
	};
});
