//Setting up the application services.....

function transformToInteger(data, headersGetter, status) {
	return {value:parseInt(data)}
}

function transformToString(data, headersGetter, status) {
	return {value:data.substring(1,data.length-1)} // strips the quotes
}

function transformToBoolean(data, headersGetter, status){
	return {value: data=="true"};
}

angular.module('services', ['ngResource'])
// Define the API
	.factory('UserManager', function($resource,$q) {
		var data = $resource(AppConfig.url + 'user/:action/:user', {}, {
			GetUserInfo: {method:'GET', params:{action:'userinfo'}, cache:false},
			Login: {method: 'POST', params: {action: 'login'}, cache:false},
			AutenticationGroups: {method: 'POST', params:{action: 'authentication_groups'}, isArray: true, cache:false},
			Logout: {method: 'GET', params: {action: 'logout'}, cache:false},
			AppVariables: {method:'GET', params:{action:'appvariables'}, cache:false},
			ValidSession: {method:'GET',params:{action:'validSession'},cache:false,transformResponse: transformToBoolean},
			List: {
				method:'GET',
				url:AppConfig.url + 'user/:action/:start-:size?orderField=:orderField&filter=:filter',
				params:{action:'list',start:'@start',size:'@size', orderField:'@orderField', filter:'@filter'},
				hasBody: true,
				cache:false,
				isArray:true
			},
			New: {
				method:'GET',
				url:AppConfig.url + 'user/:action',
				params:{action:'new'},
				hasBody: true,
				cache:false,
				isArray:false
			},
			Count: {
				method:'GET', 
				url:AppConfig.url + 'user/:action?filter=:filter',
				params:{action:'count', filter:'@filter'}, 
				isArray:false, 
				cache:false,
				transformResponse: transformToInteger
			},
			Delete: {
				method:'DELETE',
				url: AppConfig.url + 'user/:action/:id',
				params:{action: 'delete', id:'@id'},
				hasBody: true,
				cache:false,
				isArray:false
			}
		});
		return data;
	})
	.factory('ComboManager', function($resource){
		var data = $resource(AppConfig.url + 'combo/:type/:tipologia', {}, {
			List: {method:'GET', isArray: true, cache:false},
			Count: {method:'GET', url: AppConfig.url + 'combo/:type/count', params:{tipologia:'@tipologia', type:'@type'}, isArray:false, cache:false,
				transformResponse: transformToInteger},
			CausaliEsiti:{
				method:'GET',
				url: AppConfig.url + 'combo/causaliEsiti',
				isArray: true,
				cache: false				
			}
		});
		return data;
	})
	.factory('DisposizioniRid', function($resource) {
		var data = $resource(AppConfig.url + 'DisposizioniRid/:action', {}, {
			Get: {
				method:'GET',
				url:AppConfig.url + 'DisposizioniRid/:id',
				params:{id:'@id'},
				hasBody: true,
				cache:false,
				isArray:false
				
			},
			Count: {
				method:'POST',  
				params: {action: 'count'}, 
				isArray:false,
				hasBody: true,
				cache:false,
				transformResponse: transformToInteger
			},				
			List: {
				method:'POST', 
				url:AppConfig.url + 'DisposizioniRid/:action/:start-:size',
				params:{action:'list',start:'@start',size:'@size'},
				hasBody: true,
				cache:false,
				isArray:true
			},
			Export: {method:'POST', url:AppConfig.url + 'DisposizioniRid/:action',
				params:{action:'export',start:'@start',size:'@size', ids:'@ids'}, 
				cache:false,
				isArray:false,
				tresponseType: 'arraybuffer',
				transformResponse: function (data) {
			        var pdf;
			        if (data) {
			            pdf = new Blob([data], {
			                type: 'text/csv'
			            });
			        }
			        return {
			            response: pdf
			        };
			    }
			},
			ExportFiltered: {method:'POST', url:AppConfig.url + 'DisposizioniRid/:action',
				params:{action:'exportFiltered', ids:'@ids'}, 
				cache:false,
				isArray:false,
				transformResponse: function (data) {
			        var pdf;
			        if (data) {
			            pdf = new Blob([data], {
			                type: 'text/csv'
			            });
			        }
			        return {
			            response: pdf
			        };
			    }
			},
			Print: {method:'POST', url:AppConfig.url + 'DisposizioniRid/:action?label=:label',
				params:{action:'print', label:'@label'}, 
				cache:false,
				isArray:false,
				responseType: 'arraybuffer',
				transformResponse: function (data) {
				        var pdf;
				        if (data) {
				            pdf = new Blob([data], {
				                type: 'application/pdf'
				            });
				        }
				        return {
				            response: pdf
				        };
				    }
			},
			PrintFiltered: {method:'POST', url:AppConfig.url + 'DisposizioniRid/:action?label=:label',
				params:{action:'printFiltered', label:'@label'}, 
				cache:false,
				isArray:false,
				responseType: 'arraybuffer',
				transformResponse: function (data) {
			        var pdf;
			        if (data) {
			            pdf = new Blob([data], {
			                type: 'application/pdf'
			            });
			        }
			        return {
			            response: pdf
			        };
			    }
				
			},				
			MassDelete: {
				method:'POST', 
				url:AppConfig.url + 'DisposizioniRid/:action/',
				params:{action:'massDelete'},
				hasBody: true,
				cache:false,
				isArray:false,
				transformResponse: transformToBoolean
			},
			LogStati: {
				method:'GET',
				url:AppConfig.url + 'DisposizioniRid/:action/:id',
				params:{action:'logStati', id:'@id'},
				cache:false,
				isArray:true				
			},
			LogVariazioni: {
				method:'GET',
				url:AppConfig.url + 'DisposizioniRid/:action/:id',
				params:{action:'logVariazioni', id:'@id'},
				cache:false,
				isArray:true				
			},				
			Filter: {
				method:'POST', 
				url:AppConfig.url + 'DisposizioniRid/:action/:start-:size?orderField=:orderField',
				params:{action:'filter',start:'@start',size:'@size',orderField:'@orderField'},
				cache:false,
				hasBody: true,
				isArray:true
			},
			CountFiltered: {
				method:'POST', 
				params: {action: 'countfilter'}, 
				isArray:false,
				hasBody: true,
				cache:false,
				transformResponse: transformToInteger
			}
		});
		return data;
	})
	.factory('DisposizioniAea', function($resource) {
		var data = $resource(AppConfig.url + 'DisposizioniAea/:action', {}, {
			Get: {
				method:'GET',
				url:AppConfig.url + 'DisposizioniAea/:id',
				params:{id:'@id'},
				hasBody: true,
				cache:false,
				isArray:false
				
			},
			Count: {
				method:'POST', 
				params: {action: 'count'}, 
				isArray:false,
				hasBody: true,
				cache:false,
				transformResponse: transformToInteger
			},				
			List: {
				method:'POST', 
				url:AppConfig.url + 'DisposizioniAea/:action/:start-:size',
				params:{action:'list',start:'@start',size:'@size'},
				hasBody: true,
				cache:false,
				isArray:true
			},
			Export: {method:'POST', url:AppConfig.url + 'DisposizioniAea/:action',
				params:{action:'export',start:'@start',size:'@size'}, 
				cache:false,
				isArray:false,
				transformResponse: function (data) {
			        var pdf;
			        if (data) {
			            pdf = new Blob([data], {
			                type: 'text/csv'
			            });
			        }
			        return {
			            response: pdf
			        };
			    }
			},
			ExportFiltered: {method:'POST', url:AppConfig.url + 'DisposizioniAea/:action',
				params:{action:'exportFiltered'}, 
				cache:false,
				isArray:false,
				transformResponse: function (data) {
			        var pdf;
			        if (data) {
			            pdf = new Blob([data], {
			                type: 'text/csv'
			            });
			        }
			        return {
			            response: pdf
			        };
			    }
			},
			Print: {method:'POST', url:AppConfig.url + 'DisposizioniAea/:action',
				params:{action:'print'}, 
				cache:false,
				isArray:false,
				responseType: 'arraybuffer',
				transformResponse: function (data) {
				        var pdf;
				        if (data) {
				            pdf = new Blob([data], {
				                type: 'application/pdf'
				            });
				        }
				        return {
				            response: pdf
				        };
				    }
			},
			PrintFiltered: {method:'POST', url:AppConfig.url + 'DisposizioniAea/:action',
				params:{action:'printFiltered'}, 
				cache:false,
				isArray:false,
				responseType: 'arraybuffer',
				transformResponse: function (data) {
			        var pdf;
			        if (data) {
			            pdf = new Blob([data], {
			                type: 'application/pdf'
			            });
			        }
			        return {
			            response: pdf
			        };
			    }
				
			},				
			MassDelete: {
				method:'POST', 
				url:AppConfig.url + 'DisposizioniAea/:action/',
				params:{action:'massDelete'},
				hasBody: true,
				cache:false,
				isArray:false,
				transformResponse: transformToBoolean
			},
			LogStati: {
				method:'GET',
				url:AppConfig.url + 'DisposizioniAea/:action/:id',
				params:{action:'logStati', id:'@id'},
				cache:false,
				isArray:true				
			},
			LogVariazioni: {
				method:'GET',
				url:AppConfig.url + 'DisposizioniAea/:action/:id',
				params:{action:'logVariazioni', id:'@id'},
				cache:false,
				isArray:true				
			},
			Filter: {
				method:'POST', 
				url:AppConfig.url + 'DisposizioniAea/:action/:start-:size?orderField=:orderField',
				params:{action:'filter',start:'@start',size:'@size',orderField:'@orderField'},
				hasBody: true,
				cache:false,
				isArray:true
			},
			CountFiltered: {
				method:'POST', 
				params: {action: 'countfilter'}, 
				isArray:false,
				cache:false,
				hasBody: true,
				transformResponse: transformToInteger
			}
		});
		return data;
	})	
	.factory('DisposizioniBonifici', function($resource) {
		var data = $resource(AppConfig.url + 'DisposizioniBonifici/:action', {}, {
			Get: {
				method:'GET',
				url:AppConfig.url + 'DisposizioniBonifici/:id',
				params:{id:'@id'},
				hasBody: true,
				cache:false,
				isArray:false
				
			},
			Count: {
				method:'POST', 
				params: {action: 'count'}, 
				isArray:false,
				hasBody: true,
				cache:false,
				transformResponse: transformToInteger
			},				
			List: {
				method:'POST', 
				url:AppConfig.url + 'DisposizioniBonifici/:action/:start-:size',
				params:{action:'list',start:'@start',size:'@size'},
				hasBody: true,
				cache:false,
				isArray:true
			},
			Export: {
				method:'POST', 
				url:AppConfig.url + 'DisposizioniBonifici/:action',
				params:{action:'export'}, 
				cache:false,
				isArray:false,
				transformResponse: function (data) {
			        var pdf;
			        if (data) {
			            pdf = new Blob([data], {
			                type: 'text/csv'
			            });
			        }
			        return {
			            response: pdf
			        };
			    }
			},
			ExportFiltered: {method:'POST', url:AppConfig.url + 'DisposizioniBonifici/:action',
				params:{action:'exportFiltered'}, 
				cache:false,
				isArray:false,
				transformResponse: function (data) {
			        var pdf;
			        if (data) {
			            pdf = new Blob([data], {
			                type: 'text/csv'
			            });
			        }
			        return {
			            response: pdf
			        };
			    }
			},
			Filter: {
				method:'POST', 
				url:AppConfig.url + 'DisposizioniBonifici/:action/:start-:size?orderField=:orderField',
				params:{action:'filter',start:'@start',size:'@size',orderField:'@orderField'},
				hasBody: true,
				cache:false,
				isArray:true
			},
			CountFiltered: {
				method:'POST', 
				params: {action: 'countfilter'}, 
				isArray:false,
				cache:false,
				hasBody: true,
				transformResponse: transformToInteger
			},
			Print: {method:'POST', url:AppConfig.url + 'DisposizioniBonifici/:action',
				params:{action:'print'}, 
				cache:false,
				isArray:false,
				responseType: 'arraybuffer',
				transformResponse: function (data) {
				        var pdf;
				        if (data) {
				            pdf = new Blob([data], {
				                type: 'application/pdf'
				            });
				        }
				        return {
				            response: pdf
				        };
				    }
			},
			PrintFiltered: {method:'POST', url:AppConfig.url + 'DisposizioniBonifici/:action',
				params:{action:'printFiltered'}, 
				cache:false,
				isArray:false,
				responseType: 'arraybuffer',
				transformResponse: function (data) {
			        var pdf;
			        if (data) {
			            pdf = new Blob([data], {
			                type: 'application/pdf'
			            });
			        }
			        return {
			            response: pdf
			        };
			    }
				
			},
			StampaContabile:{
				Method:'GET',
				url:AppConfig.url + 'DisposizioniBonifici/:action/:id',
				params:{id:'@id', action:'stampaContabile'},
				cache:false,
				isArray:false,
				responseType: 'arraybuffer',
				transformResponse: function (data) {
				        var pdf;
				        if (data) {
				            pdf = new Blob([data], {
				                type: 'application/pdf'
				            });
				        }
				        return {
				            response: pdf
				        };
				    }
			},			
			StampaRichiamo:{
				method:'POST',
				url:AppConfig.url + 'DisposizioniBonifici/:action/:id',
				params:{id:'@id', action:'stampaRichiamo'},
				cache:false,
				hasBody: true,
				isArray:false,
				responseType: 'arraybuffer',
				transformResponse: function (data) {
				        var pdf;
				        if (data) {
				            pdf = new Blob([data], {
				                type: 'application/pdf'
				            });
				        }
				        return {
				            response: pdf
				        };
				    }
			},			
			MassDelete: {
				method:'POST', 
				url:AppConfig.url + 'DisposizioniBonifici/:action/',
				params:{action:'massDelete'},
				hasBody: true,
				cache:false,
				isArray:false,
				transformResponse: transformToBoolean
			},
			LogStati: {
				method:'GET',
				url:AppConfig.url + 'DisposizioniBonifici/:action/:id',
				params:{action:'logStati', id:'@id'},
				cache:false,
				isArray:true				
			},
			LogVariazioni: {
				method:'GET',
				url:AppConfig.url + 'DisposizioniBonifici/:action/:id',
				params:{action:'logVariazioni', id:'@id'},
				cache:false,
				isArray:true				
			},
			GeneraRichiamo:{
				method:'GET',
				url:AppConfig.url + 'DisposizioniBonifici/:action/:idDistinta/:idDisposizione',
				params:{action:'generaRichiamo', idDistinta:'@idDistinta', idDisposizione:'@idDisposizione'},
				cache: false,
				isArray: false,
				transformResponse: transformToInteger
			}
		});
		return data;
	})	
	.factory('DelegheSepa', function($resource) {
		var data = $resource(AppConfig.url + 'delegheSepa/:action', {}, {
			Count: {
				method:'POST', 
				params: {action: 'count'}, 
				isArray:false,
				hasBody: true,
				cache:false,
				transformResponse: transformToInteger
			},				
			List: {
				method:'POST', 
				url:AppConfig.url + 'delegheSepa/:action/:start-:size',
				params:{action:'list',start:'@start',size:'@size'},
				hasBody: true,
				cache:false,
				isArray:true
			},
			Print: {method:'POST', url:AppConfig.url + 'delegheSepa/:action',
				params:{action:'print'}, 
				cache:false,
				isArray:false,
				responseType: 'arraybuffer',
				transformResponse: function (data) {
				        var pdf;
				        if (data) {
				            pdf = new Blob([data], {
				                type: 'application/pdf'
				            });
				        }
				        return {
				            response: pdf
				        };
				    }
			},
			Export: {method:'POST', url:AppConfig.url + 'delegheSepa/:action',
				params:{action:'export'}, 
				cache:false,
				isArray:false,
				tresponseType: 'arraybuffer',
				transformResponse: function (data) {
			        var pdf;
			        if (data) {
			            pdf = new Blob([data], {
			                type: 'text/csv'
			            });
			        }
			        return {
			            response: pdf
			        };
			    }
				
			},


		})
		return data;
	})
	.factory('Banche', function($resource) {
		var data = $resource(AppConfig.url + 'abi/:action', {}, {
			AutocompleteIstituti: {
				method:'GET',
				url:AppConfig.url + 'abi/autocomplete/:filter',
				params:{filter:'@filter'},
				cache:false,
				isArray:true
			},
			GetByAbi: {
				method:'GET',
				url:AppConfig.url + 'abi/:action/:abi',
				params:{action: 'byAbi', abi:'@abi'},
				cache:false,
				isArray:false
			},
			FilterFiliali: {
				method:'POST',
				url:AppConfig.url + 'abi/filiali/',
				hasBody: true,
				cache:false,
				isArray: true
			},
			SaveBanca: {
				method:'POST',
				params:{action: 'saveBanca'},
				hasBody: true,
				cache:false,
				transformResponse: transformToString
			},
			NuovaBanca:{
				method:'GET',
				params:{action: 'nuovaBanca'},
				hasBody: true,
				cache:false
			},
			NuovoSportello:{
				method:'GET',
				params:{action: 'nuovaFiliale'},
				hasBody: true,
				cache:false,
				isArray: false
			},
			SaveFiliale: {
				method:'POST',
				params:{action: 'saveFiliale'},
				hasBody: true,
				cache:false,
				transformResponse: transformToString
			},
			EliminaFiliale:{
				method:'GET',
				url:AppConfig.url + 'abi/:action/:id',
				params:{action: 'eliminaFiliale', id:'@id'},
				cache:false,
				transformResponse: transformToString
			}
			
			
		});
		return data;
	})
	.factory('Deleghe', function($resource) {
		var data = $resource(AppConfig.url + 'deleghe/:codiceClienteDebitore/:action', {}, {
			ListAea: {
				method:'POST', 
				url:AppConfig.url + 'deleghe/:action/:codiceClienteDebitore',
				params:{action:'listAea', codiceClienteDebitore: '@codiceClienteDebitore'},
				hasBody: true,
				cache:false,
				isArray:true
			},
			ListRid: {
				method:'POST', 
				url:AppConfig.url + 'deleghe/:action/:codiceClienteDebitore',
				params:{action:'listRid', codiceClienteDebitore: '@codiceClienteDebitore'},
				hasBody: true,
				cache:false,
				isArray:true
			}
		});
		return data;
	})
	.factory('LogSicuraScheduler', function($resource) {
		var data = $resource(AppConfig.url + 'logSicura/:action?inputFile=:inputFile', {}, {
			Count: {
				method:'POST', 
				params: {action: 'count', inputFile: '@inputFile'}, 
				isArray:false,
				cache:false,
				hasBody: true,
				transformResponse: transformToInteger
			},				
			List: {
				method:'POST', 
				url:AppConfig.url + 'logSicura/:action/:start-:size?inputFile=:inputFile&orderBy=:orderBy',
				params:{action:'list',start:'@start',size:'@size', inputFile: '@inputFile', orderBy: '@orderBy'},
				hasBody: true,
				cache:false,
				isArray:true
			},
			LogDetail: {
				method:'GET', 
				url:AppConfig.url + 'logSicura/:action/:id',
				params:{action:'details',id:'@id'},
				hasBody: true,
				cache:false,
				transformResponse: transformToString
			}
		});
		return data;
	})
	.factory('PianiEstrazioneDistinte', function($resource) {
		var data = $resource(AppConfig.url + 'pianiEstrazione/:action?orderBy=:orderBy', {}, {
			List: {
				method:'GET', 
				params:{action:'list',orderBy: '@orderBy'},
				hasBody: true,
				cache:false,
				isArray:true
			},
			Save: {
				method:'POST', 
				url: AppConfig.url + 'pianiEstrazione',
				hasBody: true,
				cache:false,
				isArray:false,
				transformResponse: transformToInteger
			},
			New: {
				method:'GET', 
				url:AppConfig.url + 'pianiEstrazione/:action',
				params:{action:'new'},
				cache:false,
				isArray: false
			},
			Delete: {
				method:'DELETE', 
				url:AppConfig.url + 'pianiEstrazione/:id',
				params:{id:'@id'},
				cache:false,
				isArray: false,
				transformResponse: transformToInteger
			},
			Istruzioni: {
				method:'GET', 
				url:AppConfig.url + 'pianiEstrazione/:action/:id',
				params:{action:'istruzioni',id:'@id'},
				hasBody: true,
				cache:false,
				isArray: true
			},
			NewIstruzione: {
				method:'GET', 
				url:AppConfig.url + 'pianiEstrazione/:action/new/:id',
				params:{action:'istruzioni',id:'@id'},
				hasBody: true,
				cache:false,
				isArray: false
			}
			,
			Exec: {
				method:'GET', 
				url:AppConfig.url + 'pianiEstrazione/:action/:id',
				params:{action:'exec',id:'@id'},
				hasBody: true,
				cache:false,
				isArray: false,
				transformResponse: transformToString
			}
		});
		return data;
	})
	.factory('FunzioniOrdinanti', function($resource) {
		var data = $resource(AppConfig.url + 'funzioniOrdinanti/:action', {}, {
			List: {
				method:'GET', 
				params:{action:'list',orderBy: '@orderBy', filter:'@filter'},
				cache:false,
				isArray:true
			},
			ListItems: {
				method:'GET',
				url:AppConfig.url + 'funzioniOrdinanti/:action/:start-:size',
				params:{action:'list',orderBy: '@orderBy', filter:'@filter'},
				cache:false,
				isArray:true
			},			
			Count: {
				method:'GET', 
				params:{action:'count',filter:'@filter'},
				cache:false,
				isArray:false,
				transformResponse: transformToInteger
			},			
			save: {
				method:'POST', 
				cache:false,
				isArray:false,
				transformResponse: transformToString
			},
			New: {
				method:'GET', 
				params:{action:'new'},
				cache:false,
				isArray:false,
			},
			Delete: {
				method:'DELETE',
				url: AppConfig.url + 'funzioniOrdinanti/:id',
				params:{id:'@id'},
				cache:false,
				isArray:false,
			},
			ListForUser: {
				method:'GET',
				params:{action:'utente',orderBy:'FunzioneOrdinante'},
				cache:false,
				isArray: true
			},
			ListAllForUser: {
				method:'GET',
				params:{action:'all',orderBy:'FunzioneOrdinante'},
				cache:false,
				isArray: true
			}
			
		});
		return data;
	})
	.factory('ProvenienzaDisposizioni', function($resource) {
		var data = $resource(AppConfig.url + 'provenienza/:type', {}, {
			List: {
				method:'GET', 
				params:{type: '@type'},
				cache:false,
				isArray:true
			},
		});
		return data;
	})
	.factory('Conti', function($resource) {
		var data = $resource(AppConfig.url + 'conti/:action', {}, {
			List: {
				method:'POST',
				params:{action:'list'},
				isBody: true,
				cache:false,
				isArray:true
			}
		});
		return data;
	})
	.factory('Remuneration', function($resource) {
		var data = $resource(AppConfig.url + 'remuneration/:action', {}, {
			HeaderCount: {
				method:'GET',
				params:{action:'headercount'},
				cache:false,
				transformResponse: transformToInteger
			},
			Header: {
				method:'GET',
				url:AppConfig.url + 'remuneration/:action/:start-:size?orderBy=:orderBy',
				params:{action:'header',start:'@start',size:'@size',orderBy: '@orderBy'},
				cache:false,
				isArray:true
			},
			ExportMessaggi:{
				method:'GET',
				url: AppConfig.url + 'remuneration/:action/:idremuneration',
				params:{action:'exportMessaggi', idremuneration:'@idremuneration'},
				cache:false,
				isArray:false,
				 transformResponse: function (data) {
					    return {
					    	
					    	response: data //new Blob([data], {type: 'text/csv'})
					    }
				    }
			},
			ProvisioningCount:{
				method:'GET',
				url:AppConfig.url + 'remuneration/:action/:id',
				params:{action:'provisioningcount',id:'@id'},
				cache:false,
				transformResponse: transformToInteger								
			},
			Provisioning:{
				method:'GET',
				url:AppConfig.url + 'remuneration/:action/:id/:start-:size?orderBy=:orderBy',
				params:{action:'provisioning',id:'@id', start:'@start',size:'@size',orderBy: '@orderBy'},
				cache:false,
				isArray:true
			},
			DetailCount:{
				method:'GET',
				url:AppConfig.url + 'remuneration/:action/:id',
				params:{action:'detailCount',id:'@id'},
				cache:false,
				transformResponse: transformToInteger								
			},
			Detail:{
				method:'GET',
				url:AppConfig.url + 'remuneration/:action/:id/:start-:size?orderBy=:orderBy',
				params:{action:'detail',id:'@id', start:'@start',size:'@size',orderBy: '@orderBy'},
				cache:false,
				isArray:true
			},
			GeneraRichiestaDettagli:{
				method:'GET',
				url:AppConfig.url + 'remuneration/:action/:id',
				params:{action:'generaRichiestaDettagli', id:'@id'},
				isArray:false,
				cache:false,
				transformResponse: transformToString
			},
			GeneraRichiestaDettagliTrimestre:{
				method:'GET',
				url:AppConfig.url + 'remuneration/:action/:id/:idDettaglio',
				params:{action:'generaRichiestaDettagli', id:'@id', idDettaglio:'@idDettaglio'},
				isArray:false,
				cache:false,
				transformResponse: transformToString
			},
			QuadraRemuneration:{
				method:'GET',
				url:AppConfig.url + 'remuneration/:action/:id',
				params:{action:'quadra', id:'@id'},
				isArray:false,
				cache:false,
				transformResponse: transformToString
			},
			QuadraDetail:{
				method:'GET',
				url:AppConfig.url + 'remuneration/:action/:id/:idDettaglio',
				params:{action:'quadra', id:'@id', idDettaglio:'@idDettaglio'},
				isArray:false,
				cache:false,
				transformResponse: transformToString
			},
			CodiciSia:{
				method:'GET',
				url:AppConfig.url + 'remuneration/:action',
				params:{action:'codiciSia'},
				cache:false,
				isArray: true
			},
			PrintPrevisioning: {method:'POST', url:AppConfig.url + 'remuneration/:action/:id',
				params:{action:'print',id:'@id'}, 
				cache:false,
				isArray:false,
				responseType: 'arraybuffer',
				transformResponse: function (data) {
				        var pdf;
				        if (data) {
				            pdf = new Blob([data], {
				                type: 'application/pdf'
				            });
				        }
				        return {
				            response: pdf
				        };
				    }
			},
			PrintDetails: {method:'POST', url:AppConfig.url + 'remuneration/:action/:id',
				params:{action:'printDetails',id:'@id'}, 
				cache:false,
				isArray:false,
				responseType: 'arraybuffer',
				transformResponse: function (data) {
				        var pdf;
				        if (data) {
				            pdf = new Blob([data], {
				                type: 'application/pdf'
				            });
				        }
				        return {
				            response: pdf
				        };
				    }
			},
		});
		return data;
	})
	.factory('DistinteBanca', function($resource) {
	var data = $resource(AppConfig.url + 'distinte/:action', {}, {
		Count:{
			method:'POST',
			url:AppConfig.url + 'distinte/:action',
			params:{action:'count'},
			hasBody: true,
			cache:false,
			transformResponse: transformToInteger			
		},
		List: {
			method:'POST',
			url:AppConfig.url + 'distinte/:action/:start-:size?orderBy=:orderBy',
			params:{action:'list',start:'@start',size:'@size',orderBy: '@orderBy'},
			hasBody: true,
			cache:false,
			isArray:true
		},
		FirmaDistinta: {
			method:'GET',
			url:AppConfig.url + 'distinte/:action/:tipoFirma/:generaFlusso/:idDistintaBanca',
			params:{action:'firmaDistinta',tipoFirma:'@tipoFirma',idDistintaBanca:'@idDistintaBanca'},
			cache:false,
			isArray:false
		},
		LogStati: {
			method:'GET',
			url:AppConfig.url + 'distinte/:action/:id',
			params:{action:'logStati', id:'@id', generaFlusso:'@generaFlusso', idDistintaBanca:'@idDistintaBanca'},
			cache:false,
			isArray:true				
		},
		AnnullaDistinta: {
			method:'POST',
			params:{action:'annulla'},
			hasBody: true,
			cache:false,
			isArray: false
		},
		ModificaContoDistinta: {
			method:'POST',
			params:{action:'modificaConto'},
			hasBody: true,
			cache:false,
			isArray: false
		},
		ModificaDataValuta: {
			method:'POST',
			params:{action:'modificaDataValuta'},
			hasBody: true,
			cache:false,
			isArray: false
		},
		ModificaDataEsecuzione: {
			method:'POST',
			params:{action:'modificaDataEsecuzione'},
			hasBody: true,
			cache:false,
			isArray: false
		},
		ValidaEGeneraFlusso: {
			method:'GET',
			url:AppConfig.url + 'distinte/:action/:id',
			params:{action:'validaEGenera', id:'@id'},
			isArray: false,
			cache:false,
			transformResponse: transformToString
		},
		GeneraFlusso: {
			method:'GET',
			url:AppConfig.url + 'distinte/:action/:id',
			params:{action:'genera', id:'@id'},
			isArray: false,
			cache:false,
			transformResponse: transformToString
		},
		EsportaTASC: {
			method:'POST',
			url:AppConfig.url + 'distinte/:action',
			params:{action:'esportaTASC'},
			hasBody: true,
		    cache: false,
		    transformResponse: function (data) {
			    return {
			    	
			    	response: data //new Blob([data], {type: 'text/csv'})
			    }
		    }

		},
		Print: {method:'POST', url:AppConfig.url + 'distinte/:action',
			params:{action:'print'}, 
			cache:false,
			isArray:false,
			responseType: 'arraybuffer',
			transformResponse: function (data) {
			        var pdf;
			        if (data) {
			            pdf = new Blob([data], {
			                type: 'application/pdf'
			            });
			        }
			        return {
			            response: pdf
			        };
			    }
		},
		ForzaturaInviata: {
			method:'GET',
			url:AppConfig.url + 'distinte/forzaturaInviata/:id',
			params:{id:'@id'},
			hasBody: true,
			cache:false,
			isArray:false,
			transformResponse: transformToInteger
		}
		});
		return data;
	})
	.factory('DistintaFlussiInput', function($resource) {
	var data = $resource(AppConfig.url + 'DistintaFlussiInput/', {}, {
		Count:{
			method:'GET',
			url:AppConfig.url + 'DistintaFlussiInput/:action',
			params:{action:'count'},
			cache:false,
			transformResponse: transformToInteger			
		},
		List: {
			method:'GET',
			url:AppConfig.url + 'DistintaFlussiInput/:action/:start-:size?orderBy=:orderBy',
			params:{action:'list',start:'@start',size:'@size',orderBy: '@orderBy'},
			hasBody: true,
			cache:false,
			isArray:true
		},
		Annulla: {
			method: 'GET',
			url:AppConfig.url + 'DistintaFlussiInput/:action/:id',
			params:{action:'annulla', id:'@id'},
			cache:false,
			transformResponse: transformToString
		},
		LogStati: {
			method:'GET',
			url:AppConfig.url + 'DistintaFlussiInput/:action/:id',
			params:{action:'logStati', id:'@id'},
			cache:false,
			isArray:true				
		},
		Print: {method:'POST', url:AppConfig.url + 'DistintaFlussiInput/:action',
			params:{action:'print'}, 
			cache:false,
			isArray:false,
			responseType: 'arraybuffer',
			transformResponse: function (data) {
			        var pdf;
			        if (data) {
			            pdf = new Blob([data], {
			                type: 'application/pdf'
			            });
			        }
			        return {
			            response: pdf
			        };
			    }
		}
		});
		return data;
	})
	.factory('LogModifiche', function($resource) {
		var data = $resource(AppConfig.url + 'logModifiche/:idDisposizione', {}, {
			SaveAll: {
				method:'POST',
				url:AppConfig.url + 'logModifiche/:idDisposizione',
				hasBody: true,
				cache:false,
				isArray:true
			}
		});
		return data;
	})
	.factory('DelegatoFirma', function($resource) {
		var data = $resource(AppConfig.url + 'delegato/:action', {}, {
			List: {
				method:'GET',
				params:{action: 'list'},
				hasBody: true,
				cache:false,
				isArray:true
			},
			SetStatus: {
				method:'GET',
				url:AppConfig.url +  'delegato/:action/:id/:status',
				params:{action: 'setStatus', id:'@id', status:'@status'},
				hasBody: true,
				cache:false,
				isArray:true
				
			}
		});
		return data;
	})
	.factory('PianoEstrazioneTipoFlusso', function($resource) {
		var data = $resource(AppConfig.url + 'tipoFlusso/:action', {}, {
			List: {
				method:'GET',
				url: AppConfig.url + 'tipoFlusso/:action/:id',
				params:{action: 'list', id:'@id'},
				hasBody: true,
				cache:false,
				isArray:true
			},
			New: {
				method:'GET',
				url: AppConfig.url + 'tipoFlusso/:action/:id',
				params:{action: 'new', id:'@id'},
				hasBody: true,
				cache:false,
				isArray:false
			},
			Save: {
				method:'POST',
				url: AppConfig.url + 'tipoFlusso/:action/:idPiano',
				params:{action: 'save', idPiano:'@idPiano'},
				hasBody: true,
				cache:false,
				isArray:false
			}
			,
			Delete: {
				method:'DELETE',
				url: AppConfig.url + 'tipoFlusso/:action/:idPiano/:id',
				params:{action: 'delete', idPiano:'@idPiano', id:'@id'},
				hasBody: true,
				cache:false,
				isArray:false
			}
		});
		return data;
	})
	.factory('Tipologie', function($resource) {
		var data = $resource(AppConfig.url + 'tipologie/:action', {}, {
			List: {
				method:'GET', 
				params:{action:'list'},
				cache:false,
				isArray:true
			},
			Count: {
				method:'GET', 
				params:{action:'count',filter:'@filter'},
				cache:false,
				isArray:false,
				transformResponse: transformToInteger
			}
		});
		return data;
	})	
	.factory('Firme', function($resource) {
		var data = $resource(AppConfig.url + 'firme/:action', {}, {
			List: {
				method:'GET', 
				params:{action:'list'},
				cache:false,
				isArray:true
			},
			Count: {
				method:'GET', 
				params:{action:'count',filter:'@filter'},
				cache:false,
				isArray:false,
				transformResponse: transformToInteger
			},
			New: {
				method:'GET',
				params:{action: 'new'},
				hasBody: true,
				cache:false,
				isArray:false
			},
			Delete: {
				method:'DELETE',
				url: AppConfig.url + 'firme/:id',
				params:{id: '@id'},
				hasBody: true,
				cache:false,
				isArray:false
			}
		});
		return data;
	})	
	.factory('FlussiNonSeda', function($resource) {
		var data = $resource(AppConfig.url + 'flussiNonSeda/:action', {}, {
			List: {
				method:'GET', 
				params:{action:'list'},
				cache:false,
				isArray:true
			},
			Count: {
				method:'GET', 
				params:{action:'count',filter:'@filter'},
				cache:false,
				isArray:false,
				transformResponse: transformToInteger
			},
			New: {
				method:'GET',
				params:{action: 'new'},
				hasBody: true,
				cache:false,
				isArray:false
			},
			Delete: {
				method:'DELETE',
				url: AppConfig.url + 'flussiNonSeda/:id',
				params:{id: '@id'},
				hasBody: true,
				cache:false,
				isArray:false
			}
		});
		return data;
	})	
	.factory('Ordinanti', function($resource) {
		var data = $resource(AppConfig.url + 'ordinanti/:action', {}, {
			List: {
				url: AppConfig.url + 'ordinanti/:action?filter=:filter',
				method:'GET', 
				params:{action:'list'},
				cache:false,
				isArray:true
			},
			Count: {
				url: AppConfig.url + 'ordinanti/:action?filter=:filter',
				method:'GET', 
				params:{action:'count'},
				cache:false,
				isArray:false,
				transformResponse: transformToInteger
			},
			New: {
				method:'GET', 
				params:{action:'new'},
				cache:false,
				isArray:false,
			},
			Delete: {
				method:'DELETE',
				url: AppConfig.url + 'ordinanti/:id',
				params:{id:'@id'},
				cache:false,
				isArray:false,
			},
			Print: {
				method:'GET',
				params:{action:'print'}, 
				cache:false,
				isArray:false,
				responseType: 'arraybuffer',
				transformResponse: function (data) {
				        var pdf;
				        if (data) {
				            pdf = new Blob([data], {
				                type: 'application/pdf'
				            });
				        }
				        return {
				            response: pdf
				        };
				    }
			}
		});
		return data;
	})	
	.factory('Destinatari', function($resource) {
		var data = $resource(AppConfig.url + 'destinatari/:action/:idOrdinante', {}, {
			List: {
				method:'GET',
				url: AppConfig.url + 'destinatari/:action/:idOrdinante/:start-:size?filter=:filter&orderBy=:orderBy',
				params:{action:'list', idOrdinante: '@idOrdinante'},
				cache:false,
				isArray:true
			},
			Count: {
				method:'GET',
				url: AppConfig.url + 'destinatari/:action/:idOrdinante?filter=:filter&orderBy=:orderBy',
				params:{action:'count', idOrdinante: '@idOrdinante'},
				cache:false,
				isArray:false,
				transformResponse: transformToInteger
			},
			New: {
				method:'GET', 
				params:{action:'new'},
				cache:false,
				isArray:false
			},
			Delete: {
				method:'DELETE', 
				url: AppConfig.url + 'destinatari/:idDestinatario',
				cache:false,
				isArray:false
			},
			CambioOrdinanti:{
				method:'POST',
				url: AppConfig.url + 'destinatari/:action',
				params:{action:'cambioOrdinante'},
				cache:false,
				isArray:false
			},
			Print:{
				method:'GET',
				params:{action:'print'},
				cache:false,
				isArray:false,
				responseType: 'arraybuffer',
				transformResponse: function (data) {
				        var pdf;
				        if (data) {
				            pdf = new Blob([data], {
				                type: 'application/pdf'
				            });
				        }
				        return {
				            response: pdf
				        };
				    }

			}

		});
		return data;
	})	
	.factory('ContiDestinatario', function($resource) {
		var data = $resource(AppConfig.url + 'contiDestinatario/:action/:idDestinatario', {}, {
			List: {
				method:'GET', 
				url: AppConfig.url + 'contiDestinatario/:action/:idDestinatario/:start-:size?orderBy=:orderBy',
				params:{action:'list', idDestinatario: '@idDestinatario',start:'@start',size:'@size',orderBy: '@orderBy'},
				cache:false,
				isArray:true
			},
			Count: {
				method:'GET', 
				params:{action:'count', idDestinatario: '@idDestinatario'},
				cache:false,
				isArray:false,
				transformResponse: transformToInteger
			},
			Save: {
				method:'POST',
				url: AppConfig.url + 'contiDestinatario',
				cache:false,
				isArray:false,
				transformResponse: transformToString
			},
			New: {
				method:'GET', 
				params:{action:'new'},
				cache:false,
				isArray:false
			},
			Delete: {
				method:'DELETE', 
				url: AppConfig.url + 'contiDestinatario/:idConto',
				cache:false,
				isArray:false
			}
		});
		return data;
	})	
	.factory('ReportPagamenti', function($resource) {
		var data = $resource(AppConfig.url + 'reportPagamenti/:action', {}, {
			Get: {
				method:'GET',
				url:AppConfig.url + 'reportPagamenti/:id',
				params:{id:'@id'},
				hasBody: true,
				cache:false,
				isArray:false
				
			},
			List: {
				method:'GET', 
				params:{action:'list'},
				cache:false,
				isArray:true
			},
			Count: {
				method:'GET', 
				params:{action:'count',filter:'@filter'},
				cache:false,
				isArray:false,
				transformResponse: transformToInteger
			},
			Download: {method:'GET', url:AppConfig.url + 'reportPagamenti/:action/:id',
				params:{action:'downloadFile', id:'@id'}, 
				cache:false,
				isArray:false,
				responseType: 'arraybuffer',
				transformResponse: function (data) {
				        var txt;
				        if (data) {
				            txt = new Blob([data], {
				                type: 'text/plain'
				            });
				        }
				        return {
				            response: txt
				        };
				    }
			}
		});
		return data;
	})	
	.factory('AppParam', function($resource){
		var data = $resource(AppConfig.url + 'param', {}, {
			Get: {method:'GET', isArray: false, cache:false},
			Set: {method:'POST', isArray:false, cache:false},
		});
		return data;
	})
;

	
