Search in sources :

Example 1 with PeriodicalAccountEntry

use of com.autentia.tnt.businessobject.PeriodicalAccountEntry in project TNTConcept by autentia.

the class PeriodicalAccountEntryManager method createNewPeriodicalAccountEntry.

/**
 * Create a new PeriodicalAccountEntry
 * @param periodicalAccountEntry
 * @param nextDate
 * @return
 */
private PeriodicalAccountEntry createNewPeriodicalAccountEntry(PeriodicalAccountEntry periodicalAccountEntry, Date nextDate) {
    PeriodicalAccountEntry newPeriodicalAccountEntry = new PeriodicalAccountEntry();
    newPeriodicalAccountEntry.setDate(nextDate);
    newPeriodicalAccountEntry.setAccount(periodicalAccountEntry.getAccount());
    newPeriodicalAccountEntry.setAmount(periodicalAccountEntry.getAmount());
    newPeriodicalAccountEntry.setConcept(periodicalAccountEntry.getConcept());
    newPeriodicalAccountEntry.setFrequency(periodicalAccountEntry.getFrequency());
    newPeriodicalAccountEntry.setOrganization(periodicalAccountEntry.getOrganization());
    newPeriodicalAccountEntry.setObservations(periodicalAccountEntry.getObservations());
    newPeriodicalAccountEntry.setRise(periodicalAccountEntry.getRise());
    newPeriodicalAccountEntry.setType(periodicalAccountEntry.getType());
    return newPeriodicalAccountEntry;
}
Also used : PeriodicalAccountEntry(com.autentia.tnt.businessobject.PeriodicalAccountEntry)

Example 2 with PeriodicalAccountEntry

use of com.autentia.tnt.businessobject.PeriodicalAccountEntry in project TNTConcept by autentia.

the class PeriodicalAccountEntryManager method copy.

public PeriodicalAccountEntry copy(int id) {
    PeriodicalAccountEntry periodicalAccountEntry = new PeriodicalAccountEntry();
    AccountEntryDAO accountEntryDAO = new AccountEntryDAO();
    AccountEntry copyAccountEntry = accountEntryDAO.loadById(id);
    /*
		 	periodicalAccountEntry.setConcept(copyAccountEntry.getConcept());
		   	periodicalAccountEntry.setAccount(copyAccountEntry.getAccount());
		   	periodicalAccountEntry.setDate(copyAccountEntry.getDate());
		   	periodicalAccountEntry.setObservations(copyAccountEntry.getObservations());
			periodicalAccountEntry.setType(copyAccountEntry.getType());
			periodicalAccountEntry.setAmount(copyAccountEntry.getAmount());
*/
    BeanUtils.copyTransferObject(copyAccountEntry, periodicalAccountEntry);
    return periodicalAccountEntry;
}
Also used : PeriodicalAccountEntry(com.autentia.tnt.businessobject.PeriodicalAccountEntry) PeriodicalAccountEntry(com.autentia.tnt.businessobject.PeriodicalAccountEntry) AccountEntry(com.autentia.tnt.businessobject.AccountEntry) AccountEntryDAO(com.autentia.tnt.dao.hibernate.AccountEntryDAO) PeriodicalAccountEntryDAO(com.autentia.tnt.dao.hibernate.PeriodicalAccountEntryDAO)

Example 3 with PeriodicalAccountEntry

use of com.autentia.tnt.businessobject.PeriodicalAccountEntry in project TNTConcept by autentia.

the class PeriodicalAccountEntryManager method getEntities.

/**
 * List periodicalAccountEntrys between start and end dates
 * @param search search filter to apply
 * @param sort sorting criteria
 * @param start the start date
 * @param end the end date
 * @return the list of all periodicalAccountEntrys sorted by requested criterion
 */
public List<PeriodicalAccountEntry> getEntities(PeriodicalAccountEntrySearch search, SortCriteria sort, Date start, Date end) {
    List<PeriodicalAccountEntry> res = periodicalAccountEntryDAO.search(search, sort);
    List<PeriodicalAccountEntry> list = new ArrayList<PeriodicalAccountEntry>();
    Calendar calendar = Calendar.getInstance();
    boolean outOfRange;
    PeriodicalAccountEntry newPeriodicalAccountEntry = null;
    // Recorremos la lista de PeriodicalAccountEntry
    for (PeriodicalAccountEntry item : res) {
        // Metemos en el calendar la fecha del item
        calendar.setTime(item.getDate());
        outOfRange = false;
        /* Comparamos la fecha del item con el rango de fechas seleccionado por el usuario. Mientras no nos salgamos del rango
		     se calculan tantos pagos como entren en el periodo que va entre las fechas start y end*/
        while (!outOfRange) {
            // Si la fecha está dentro del rango de fechas seleccionado se añade a la lista con la fecha calculada del próximo pago
            if ((calendar.getTimeInMillis() >= start.getTime()) && (calendar.getTimeInMillis() <= end.getTime())) {
                // Creamos un nuevo PeriodicalAccountEntry
                newPeriodicalAccountEntry = createNewPeriodicalAccountEntry(item, new Date(calendar.getTimeInMillis()));
                // Añadimos a la lista
                list.add(newPeriodicalAccountEntry);
                // Si la frecuencia es 'ocasional' terminamos con este item
                if (item.getFrequency().getMonths() == 0) {
                    outOfRange = true;
                } else {
                    // Sumamos la frecuencia del pago a la fecha del item
                    calendar.add(Calendar.MONTH, item.getFrequency().getMonths());
                }
            } else if (calendar.getTimeInMillis() > end.getTime()) {
                // Si la fecha calculada se ha salido de rango terminamos con este item
                outOfRange = true;
            } else {
                // Sumamos la frecuencia del pago a la fecha del item
                calendar.add(Calendar.MONTH, item.getFrequency().getMonths());
            }
        }
    }
    return list;
}
Also used : PeriodicalAccountEntry(com.autentia.tnt.businessobject.PeriodicalAccountEntry) Calendar(java.util.Calendar) ArrayList(java.util.ArrayList) Date(java.util.Date)

Example 4 with PeriodicalAccountEntry

use of com.autentia.tnt.businessobject.PeriodicalAccountEntry in project TNTConcept by autentia.

the class NOFBean method orderListByDate.

/**
 * Order list by date.
 * @param res the list of PeriodicaAccountEntry
 */
private void orderListByDate(List<PeriodicalAccountEntry> res) {
    PeriodicalAccountEntry temp = null;
    boolean sorted = false;
    for (int i = 0; i < res.size() && !sorted; i++) {
        sorted = true;
        for (int j = res.size() - 1; j > i; j--) {
            PeriodicalAccountEntry first = null;
            PeriodicalAccountEntry second = null;
            // Ascending order
            first = res.get(j);
            second = res.get(j - 1);
            if (first.getDate().getTime() < second.getDate().getTime()) {
                temp = res.get(j);
                res.set(j, res.get(j - 1));
                res.set(j - 1, temp);
                sorted = false;
            }
        }
    }
}
Also used : PeriodicalAccountEntry(com.autentia.tnt.businessobject.PeriodicalAccountEntry)

Example 5 with PeriodicalAccountEntry

use of com.autentia.tnt.businessobject.PeriodicalAccountEntry in project TNTConcept by autentia.

the class NOFBean method convertFromPeriodicalAccountEntryToGenericNOF.

/**
 * Converts from list of periodical account entries to a list of GeneticNOF objects to be seen in the page
 */
public List<GenericNOF> convertFromPeriodicalAccountEntryToGenericNOF(List<PeriodicalAccountEntry> periodicalAccountEntries) {
    List<GenericNOF> genericNOFList = new ArrayList<GenericNOF>(periodicalAccountEntries.size());
    for (PeriodicalAccountEntry periodicalAccountEntry : periodicalAccountEntries) {
        GenericNOF genericNOF = new GenericNOF();
        genericNOF.setEndDate(periodicalAccountEntry.getDate());
        genericNOF.setType(NOFType.PERIODICAL_ACCOUNT_ENTRY);
        genericNOF.setProvider(periodicalAccountEntry.getAccount().getName());
        genericNOF.setBillType(BillType.RECIEVED);
        genericNOF.setOrganization(periodicalAccountEntry.getOrganization());
        genericNOF.setDescription(periodicalAccountEntry.getConcept());
        genericNOF.setFrecuency(periodicalAccountEntry.getFrequency().getName());
        genericNOF.setTotal(periodicalAccountEntry.getAmount().multiply(new BigDecimal(-1)));
        genericNOF.setPeriodicalTypeDescription(periodicalAccountEntry.getType().getName());
        genericNOFList.add(genericNOF);
    }
    return genericNOFList;
}
Also used : PeriodicalAccountEntry(com.autentia.tnt.businessobject.PeriodicalAccountEntry) ArrayList(java.util.ArrayList) BigDecimal(java.math.BigDecimal)

Aggregations

PeriodicalAccountEntry (com.autentia.tnt.businessobject.PeriodicalAccountEntry)5 ArrayList (java.util.ArrayList)2 AccountEntry (com.autentia.tnt.businessobject.AccountEntry)1 AccountEntryDAO (com.autentia.tnt.dao.hibernate.AccountEntryDAO)1 PeriodicalAccountEntryDAO (com.autentia.tnt.dao.hibernate.PeriodicalAccountEntryDAO)1 BigDecimal (java.math.BigDecimal)1 Calendar (java.util.Calendar)1 Date (java.util.Date)1