private int getDoctorSessionValue() { int sessionVal = 0; Doctor doctor = doctorService.get(Long.parseLong(doctorID)); SessionPayment sp = spService.getSpExistPatient(id); for (DoctorSession ds : sp.getListOfSession()) { if (ds.getDoctor().getId() == doctor.getId()) { sessionVal += ds.getSum(); } } return sessionVal; }
@Action( value = "savePayment", results = { @Result( name = "success", location = "spPayment", type = "redirectAction", params = {"model.id", "${id}"}), @Result(name = "input", type = "tiles", location = "/payment.tiles") }) public String save() { if (payment != null && payment.hashCode() != paymentHash) { if (doctorID != null && doctorID.equals("")) { addFieldError("doctorID", Messages.getString("DoctorSessionAction.CheckDoctor")); return INPUT; } if (!payment.getPaymentMethod().equals(PaymentMethod.MONEY_BACK) && payment.getValue() <= 0) { addFieldError("value", Messages.getString("PaymentAction.WrongValue")); return INPUT; } if (Messages.getCustomer("customer").trim().equals(Customer.degfim.toString().trim()) && getDoctors() != null) { if (!payment.getPaymentMethod().equals(PaymentMethod.MONEY_BACK)) { if (payment.getValue() > checkVal()) { addFieldError("value", "Мөнгөн дүн " + checkVal() + " -аас дээш байж болохгүй"); return INPUT; } } else { if (payment.getValue() > getDoctorSessionValue()) { addFieldError( "value", "Мөнгөн дүн " + getDoctorSessionValue() + " -аас дээш байж болохгүй"); return INPUT; } } } if (numberService.findAll().size() == 0) numberService.saveOrUpdate(new PaymentNumberCounter()); PaymentMethod method = payment.getPaymentMethod(); List<Patient> patientList = patientService.searchById(id); payment.setPatient(patientList.get(0)); if (method.equals(PaymentMethod.MONEY_BACK) && payment.getValue() > 0) { payment.setValue(payment.getValue() * (-1)); } if (doctorID != null) payment.setDoctor(doctorService.get(Long.parseLong(doctorID))); payment.setPaymentNumber(numberService.getNextPaymentNumber(method)); payment.setId(null); paymentService.saveOrUpdate(payment); ssm.logInfo(payment); return SUCCESS; } return INPUT; }
public int checkVal() { Doctor doctor = doctorService.get(Long.parseLong(doctorID)); SessionPayment sp = spService.getSpExistPatient(id); int sessionVal = 0; for (DoctorSession ds : sp.getListOfSession()) { if (ds.getDoctor().getId() == doctor.getId()) { sessionVal += ds.getSum(); } } int paymentVal = 0; for (Payment p : sp.getListOfPayment()) { Doctor doctor1 = paymentService.get(p.getId()).getDoctor(); if (doctor1 != null) if (doctor1.getId() == doctor.getId()) { paymentVal += p.getValue(); } } return sessionVal - paymentVal; }
public List<Doctor> getAllDoctors() { return doctorService.findAll(); }