final String sBeanEmployeeUUID = getEmployee()==null ? "" : getEmployee();
String sConcept = getConcept()==null ? "" : getConcept();
Log.out.debug("validateBillNoteVsEmployee concept="+sConcept+" uuid="+sBeanEmployeeUUID);
try {
if (sConcept.length()==0)
errors.add("concepto", new LocalizableError("com.zesped.action.EditBillNote.concept.valueNotPresent"));
if (sBeanEmployeeUUID.length()==0)
errors.add("empleado", new LocalizableError("com.zesped.action.EditBillNote.employee.valueNotPresent"));
if (sConcept.length()>0 && sBeanEmployeeUUID.length()>0) {
connect(getSessionAttribute("nickname"), getSessionAttribute("password"));
Dms oDms = getSession().getDms();
TaxPayer txpy = new TaxPayer(oDms, getRecipientTaxPayer());
BillNote bill = txpy.billnotes(getSession()).forConcept(getSession(), sConcept, sBeanEmployeeUUID);
Log.out.debug("BillNote with Id "+bill.id()+" found for concept "+sConcept+" and employee "+sBeanEmployeeUUID);
if (bill.isOpen()) {
final String sBillEmployeeUUID = (bill.getEmployeeUuid()==null ? "" : bill.getEmployeeUuid());
if (sBillEmployeeUUID.length()==0) {
Log.out.debug("Assigning BillNote "+bill.id()+" to employee "+sBeanEmployeeUUID);
bill.setEmployee(txpy.employees(getSession()).seek(getSession(), sBeanEmployeeUUID));
bill.save(getSession());
setBillNoteId(bill.id());
} else if (sBillEmployeeUUID.equals(sBeanEmployeeUUID)) {
setBillNoteId(bill.id());
} else {
errors.add("empleado", new LocalizableError("com.zesped.action.EditBillNote.employeeConceptMismatch"));
}
} else {
errors.add("billnote", new LocalizableError("com.zesped.action.EditBillNote.billNoteIsClosed"));
}
disconnect();
} else {
setBillNoteId(null);
}