// given the current invoice, it will 'rewind' to the previous one public void setPrevious() throws SQLException, EmptyResultDataAccessException { prepareStatement(InvoiceSQL.previous); cachedResults.setInt(1, invoice.getBaseUser().getUserId().intValue()); cachedResults.setInt(2, invoice.getId()); boolean found = false; execute(); if (cachedResults.next()) { int value = cachedResults.getInt(1); if (!cachedResults.wasNull()) { set(Integer.valueOf(value)); found = true; } } conn.close(); if (!found) { throw new EmptyResultDataAccessException("No previous invoice found", 1); } }
public InvoiceBL(InvoiceDTO invoice) { init(); set(invoice.getId()); }
public InvoiceBL(Integer invoiceId) { init(); set(invoiceId); }
public void sendReminders(Date today) throws SQLException, SessionInternalError { GregorianCalendar cal = new GregorianCalendar(); for (Iterator it = new CompanyDAS().findEntities().iterator(); it.hasNext(); ) { CompanyDTO thisEntity = (CompanyDTO) it.next(); Integer entityId = thisEntity.getId(); PreferenceBL pref = new PreferenceBL(); try { pref.set(entityId, Constants.PREFERENCE_USE_INVOICE_REMINDERS); } catch (EmptyResultDataAccessException e1) { // let it use the defaults } if (pref.getInt() == 1) { prepareStatement(InvoiceSQL.toRemind); cachedResults.setDate(1, new java.sql.Date(today.getTime())); cal.setTime(today); pref.set(entityId, Constants.PREFERENCE_FIRST_REMINDER); cal.add(GregorianCalendar.DAY_OF_MONTH, -pref.getInt()); cachedResults.setDate(2, new java.sql.Date(cal.getTimeInMillis())); cal.setTime(today); pref.set(entityId, Constants.PREFERENCE_NEXT_REMINDER); cal.add(GregorianCalendar.DAY_OF_MONTH, -pref.getInt()); cachedResults.setDate(3, new java.sql.Date(cal.getTimeInMillis())); cachedResults.setInt(4, entityId.intValue()); execute(); while (cachedResults.next()) { int invoiceId = cachedResults.getInt(1); set(Integer.valueOf(invoiceId)); NotificationBL notif = new NotificationBL(); long mils = invoice.getDueDate().getTime() - today.getTime(); int days = Math.round(mils / 1000 / 60 / 60 / 24); try { MessageDTO message = notif.getInvoiceReminderMessage( entityId, invoice.getBaseUser().getUserId(), Integer.valueOf(days), invoice.getDueDate(), invoice.getPublicNumber(), invoice.getTotal(), invoice.getCreateDatetime(), invoice.getCurrency().getId()); INotificationSessionBean notificationSess = (INotificationSessionBean) Context.getBean(Context.Name.NOTIFICATION_SESSION); notificationSess.notify(invoice.getBaseUser(), message); invoice.setLastReminder(today); } catch (NotificationNotFoundException e) { LOG.warn( "There are invoice to send reminders, but " + "the notification message is missing for " + "entity " + entityId); } } } } if (conn != null) { // only if somthing run conn.close(); } }