int count = 0;
Money total = new Money(0);
String idOperation = getIdOperation(system);
Account account = system.getAccounts().get(accountId);
Expenditure expenditure = system.getExpenditure().get(expenditureId);
// Expenditure myExpenditure = new Expenditure(expediture.getId(), expediture.getDescription(), expediture.getNextPaymentDate(), expediture.getFrequency(), expediture.getNumberOfOcurrencies(), expediture.getValue(), expediture.isFixedValue(), expediture.getCategoryId());
// myExpenditure.setActive(false);
Operation operation;
if(typeOfPayment == null){
typeOfPayment = system.getPaymentMoney();
}else{
if (typeOfPayment.getType().equals("Dinheiro")) {
typeOfPayment = system.getPaymentMoney();
} else if (typeOfPayment.getType().equals("D�bito autom�tico")) {
typeOfPayment = system.getPaymentAutomaticDebit();
} else if (typeOfPayment.getType().equals("Pagamento eletr�nico")) {
typeOfPayment = system.getPaymentEletronic();
} else if (typeOfPayment.getType().equals("Transfer�ncia eletr�nica")) {
typeOfPayment = system.getPaymentEletronicTransfer();
} else if (typeOfPayment.getType().equals("TED")) {
typeOfPayment = system.getPaymentTED();
} else if (typeOfPayment.getType().equals("DOC")) {
typeOfPayment = system.getPaymentDOC();
} else if (typeOfPayment.getType().equals("Saque cart�o")) {
typeOfPayment = system.getPaymentGetMoney();
}
}
if(idExtractItem == null){
operation = new Operation(idOperation, account,expenditure.getCategoryId(),date, expenditure.getDescription(),new Money(value).getFloatValue(),typeOfPayment, true, expenditure.getId());
} else {
operation = new Operation(idOperation, account,expenditure.getCategoryId(),date, expenditure.getDescription(),new Money(value).getFloatValue(),typeOfPayment, true, expenditure.getId(), idExtractItem);
operation.setOperationLinked(true);
system.getExtractItemMap().remove(idExtractItem);
}
system.getOperations().put(idOperation, operation);
expenditure.skip();
if (expenditure.getLastPaymentDate() != null && (expenditure.getFrequency() == 0 || expenditure.getNextPaymentDate().afterDay(expenditure.getLastPaymentDate())) || (expenditure.getLastPaymentDate() == null && expenditure.getFrequency() == 0)) {
expenditure.setActive(false);
} else {
if (!expenditure.isFixedValue()) {
for (Operation operationTemp : system.getOperations().values()) {
if(operationTemp.isExpenditure()) {
if (operationTemp.getBillId().equals(expenditure.getId())) {
total.credit(operationTemp.getValue());
count++;
}
}
}
expenditure.setValue(new Money(total.getValue() / count));
}
}
}