}
@Override
public void controlliPreGenerazionePamNuovaTranche(TrancheMutuoSal tranche) throws TrancheSalException {
if (tranche.getDataRegistrazione() == null) {
throw new TrancheSalException(messages.getMessage("gestionePratica.inserimentoTranche.noDataRegistrazione"));
}
if (tranche.getDataMovimento() == null) {
throw new TrancheSalException(messages.getMessage("gestionePratica.inserimentoTranche.noDataRiferimento"));
}
if (tranche.getImportoMovimento() == null || tranche.getImportoMovimento() == 0d) {
throw new TrancheSalException(messages.getMessage("gestionePratica.inserimentoTranche.noImportoTranche"));
}
if (tranche.getPercentualeImpostaSostitutiva() == null || tranche.getPercentualeImpostaSostitutiva() == 0d) {
throw new TrancheSalException(
messages.getMessage("gestionePratica.inserimentoTranche.noImpostaSostitutiva"));
}
Date dtScadenzaUltimaRata = gestionePraticaDao.getDataScadenzaUltimaRataPrePiano(tranche.getNumeroMutuo());
if ( dtScadenzaUltimaRata!= null && tranche.getDataRegistrazione().after(dtScadenzaUltimaRata)) {
throw new TrancheSalException(messages.getMessage("gestionePratica.inserimentoTranche.ratePreNoTranche"));
}
// AGGIUNGO IL CONTROLLO CHE LA NUOVA TRANCHE SIA DOPO L'ULTIMA PRESENTE
List<TrancheMutuoSal> listaTranche = getTranchesMutuoSal(tranche.getNumeroMutuo());
for (TrancheMutuoSal tms : listaTranche) {
if (tms.getDataMovimento().after(tranche.getDataMovimento())
|| tms.getDataMovimento().equals(tranche.getDataMovimento())) {
throw new TrancheSalException(
messages.getMessage("gestionePratica.inserimentoTranche.noDataTranchePosteriore"));
}
}
//AGGIUNGO IL CONTROLLO CHE SE HO ASSICURAZIONE INCENDIO SUL MUTUO DEVO AVERE ASSICURAZIONE INCENDIO NELLA TRANCHE
List<AssicurazioneMutuo> assicurazioni = getAssicurazioniMutuoNoSurroga(tranche.getNumeroMutuo(), 270551, "I");
if(assicurazioni.size() > 0 && NumberUtils.checkNull(tranche.getImportoAssicurazioneCasa()) == 0){
throw new TrancheSalException(messages.getMessage("gestionePratica.inserimentoTranche.assicurazioneCasaObbligatoria"));
}
}