Search in sources :

Example 1 with OfferRole

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

the class OfferManager method duplicateOffer.

/* Offer - generated by stajanov (do not edit/delete) */
public Offer duplicateOffer(final Offer offer) {
    final Set<Interaction> interactions = new LinkedHashSet<Interaction>();
    final Set<OfferRole> offerRoles = new LinkedHashSet<OfferRole>();
    final Set<OfferCost> offerCosts = new LinkedHashSet<OfferCost>();
    // copy simple data and delete identificative info
    final Offer duplicatedOffer = (Offer) SerializationUtils.clone(offer);
    duplicatedOffer.setId(null);
    duplicatedOffer.setNumber(null);
    // copy interactions
    if (offer.getInteractions() != null) {
        for (Interaction interaction : offer.getInteractions()) {
            Interaction duplicatedInteraction = (Interaction) SerializationUtils.clone(interaction);
            duplicatedInteraction.setId(null);
            duplicatedInteraction.setOffer(duplicatedOffer);
            interactions.add(duplicatedInteraction);
        }
    }
    duplicatedOffer.setInteractions(interactions);
    // copy roles
    if (offer.getRoles() != null) {
        for (OfferRole offerRole : offer.getRoles()) {
            OfferRole duplicatedRole = (OfferRole) SerializationUtils.clone(offerRole);
            duplicatedRole.setId(null);
            duplicatedRole.setOffer(duplicatedOffer);
            offerRoles.add(duplicatedRole);
        }
    }
    duplicatedOffer.setRoles(offerRoles);
    // copy costs
    if (offer.getCosts() != null) {
        for (OfferCost offerCost : offer.getCosts()) {
            OfferCost duplicatedCost = (OfferCost) SerializationUtils.clone(offerCost);
            duplicatedCost.setId(null);
            duplicatedCost.setOffer(duplicatedOffer);
            offerCosts.add(duplicatedCost);
        }
    }
    duplicatedOffer.setCosts(offerCosts);
    return duplicatedOffer;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Offer(com.autentia.tnt.businessobject.Offer) Interaction(com.autentia.tnt.businessobject.Interaction) OfferCost(com.autentia.tnt.businessobject.OfferCost) OfferRole(com.autentia.tnt.businessobject.OfferRole)

Example 2 with OfferRole

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

the class BillManager method convertFromOfferRolesToBillBreakDowns.

private Set<BillBreakDown> convertFromOfferRolesToBillBreakDowns(final Bill bill, final Set<OfferRole> offerRoles) {
    final Set<BillBreakDown> billBreakDowns = new LinkedHashSet<BillBreakDown>();
    if (offerRoles != null) {
        for (OfferRole role : offerRoles) {
            BillBreakDown billBreakDown = new BillBreakDown();
            billBreakDown.setConcept(role.getName());
            billBreakDown.setUnits(new BigDecimal(role.getExpectedHours()));
            billBreakDown.setAmount(role.getCostPerHour());
            billBreakDown.setIva(role.getIva());
            billBreakDown.setBill(bill);
            billBreakDowns.add(billBreakDown);
        }
    }
    return billBreakDowns;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) OfferRole(com.autentia.tnt.businessobject.OfferRole) BillBreakDown(com.autentia.tnt.businessobject.BillBreakDown) BigDecimal(java.math.BigDecimal)

Example 3 with OfferRole

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

the class OfferBeanTest method createRolesIn2009Test.

@Test
public void createRolesIn2009Test() {
    final OfferBean offerBean = new OfferBean();
    offerBean.create();
    final GregorianCalendar calendar = new GregorianCalendar(2009, 8, 31);
    offerBean.setCreationDate(calendar.getTime());
    offerBean.createRoles();
    for (OfferRole offerRole : offerBean.getRoles()) {
        assertEquals(IVA16, offerRole.getIva());
    }
}
Also used : GregorianCalendar(java.util.GregorianCalendar) OfferRole(com.autentia.tnt.businessobject.OfferRole) Test(org.junit.Test)

Example 4 with OfferRole

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

the class OfferBeanTest method createRolesInLastDayOf18Test.

@Test
public void createRolesInLastDayOf18Test() {
    OfferBean offerBean = new OfferBean();
    offerBean.create();
    final GregorianCalendar calendar = new GregorianCalendar(2012, 7, 31);
    offerBean.setCreationDate(calendar.getTime());
    offerBean.createRoles();
    for (OfferRole offerRole : offerBean.getRoles()) {
        assertEquals(IVA18, offerRole.getIva());
    }
}
Also used : GregorianCalendar(java.util.GregorianCalendar) OfferRole(com.autentia.tnt.businessobject.OfferRole) Test(org.junit.Test)

Example 5 with OfferRole

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

the class OfferBean method createRoles.

// Methods to create/remove instances of one-to-many entities (slave
// entities)
/**
 * Create a new empty instance of the one-to-many field
 *
 * @return forward to the same page
 */
public String createRoles() {
    OfferRole item = new OfferRole();
    item.setOffer(offer);
    IvaApplicator.applyIvaToTaxableObject(offer.getCreationDate(), item);
    if (offer.getRoles() == null) {
        offer.setRoles(new HashSet());
    }
    offer.getRoles().add(item);
    return null;
}
Also used : OfferRole(com.autentia.tnt.businessobject.OfferRole) HashSet(java.util.HashSet)

Aggregations

OfferRole (com.autentia.tnt.businessobject.OfferRole)9 LinkedHashSet (java.util.LinkedHashSet)4 BigDecimal (java.math.BigDecimal)3 GregorianCalendar (java.util.GregorianCalendar)3 Test (org.junit.Test)3 BillBreakDown (com.autentia.tnt.businessobject.BillBreakDown)1 Interaction (com.autentia.tnt.businessobject.Interaction)1 Offer (com.autentia.tnt.businessobject.Offer)1 OfferCost (com.autentia.tnt.businessobject.OfferCost)1 SortCriteria (com.autentia.tnt.dao.SortCriteria)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 SelectItem (javax.faces.model.SelectItem)1