import java.util.Date;
import javax.ejb.EJB;
import javax.ejb.Stateless;
+import org.mxchange.jcontactsbusiness.model.employee.Employee;
import org.mxchange.jfinancials.database.BaseFinancialsDatabaseBean;
import org.mxchange.jfinancials.exceptions.ReceiptAlreadyAddedException;
import org.mxchange.jusercore.model.user.User;
/**
* General receipt bean
*/
- @EJB
- private FinancialReceiptSessionBean receiptBean;
+ @EJB (lookup = "java:global/jfinancials-ejb/financialReceipt!org.mxchange.jfinancials.model.receipt.FinancialReceiptSessionBeanRemote")
+ private FinancialReceiptSessionBeanRemote receiptBean;
@Override
public BillableReceipt addReceipt (final BillableReceipt receipt) throws ReceiptAlreadyAddedException {
// Add created instance
receipt.setReceiptCreated(new Date());
+ // Is user instance set?
+ if (receipt.getReceiptUser() instanceof User) {
+ // Then get managed instanced
+ final User managedUser = this.createManaged(receipt.getReceiptUser());
+
+ // Set it back
+ receipt.setReceiptUser(managedUser);
+ }
+
+ // Is employee instance set?
+ if (receipt.getReceiptSellerEmployee() instanceof Employee) {
+ // Then get managed instanced
+ final Employee managedEmployee = this.createManaged(receipt.getReceiptSellerEmployee());
+
+ // Set it back
+ receipt.setReceiptSellerEmployee(managedEmployee);
+ }
+
// Persist it
this.getEntityManager().persist(receipt);
return receipts;
}
- /**
- * Checks if given receipt is already persisted by checking receipt number
- * and branch office combination.
- * <p>
- * @param receipt Receipt instance
- * <p>
- * @return Whether the receipt has already been registered
- */
+ @Override
public boolean isReceiptRegistered (final BillableReceipt receipt) {
// Get all receipts
final List<BillableReceipt> receipts = this.allReceipts();