Search in sources :

Example 1 with CommissioningPaymentData

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

the class CommissioningManager method getCollaboratorPaymentChanges.

private List<CommissioningChange> getCollaboratorPaymentChanges(final Commissioning commissioning) {
    final List<CommissioningChange> changes = new ArrayList<CommissioningChange>();
    for (CommissioningPaymentData payment : commissioning.getCollaboratorsPaymentData()) {
        // FIXME no debería haber bucle y debería funcionar con el método "contains"
        // metemos el recorrido del bucle en busca del elemento
        // ya que el método contains no está funcionando correctamente
        boolean found = false;
        for (CommissioningPaymentData paymentInSet : commissioning.getChanges().getCollaboratorsPaymentData()) {
            if (paymentInSet.equals(payment)) {
                found = true;
                break;
            }
        }
        // if (!commissioning.getChanges().getCollaboratorsPaymentData().contains(payment)) {
        if (!found) {
            changes.add(getChange("commissioning.collaborators", "", payment.getCollaborator().getName(), commissioning));
            changes.add(getChange("commissioning.paymentMode", "", "[" + payment.getCollaborator().getName() + "] " + payment.getPaymentMode().name(), commissioning));
            changes.add(getChange("commissioning.bankAccount", "", "[" + payment.getCollaborator().getName() + "] " + payment.getBankAccount(), commissioning));
            changes.add(getChange("commissioning.billNumber", "", "[" + payment.getCollaborator().getName() + "] " + payment.getBillNumber(), commissioning));
        } else {
            changes.addAll(getCollaboratorPaymentInternalChanges(payment, commissioning, false));
        }
    }
    for (CommissioningPaymentData payment : commissioning.getChanges().getCollaboratorsPaymentData()) {
        if (!commissioning.getCollaboratorsPaymentData().contains(payment)) {
            changes.add(getChange("commissioning.collaborators", payment.getCollaborator().getName(), "", commissioning));
            changes.add(getChange("commissioning.paymentMode", "[" + payment.getCollaborator().getName() + "] " + payment.getPaymentMode().name(), "", commissioning));
            changes.add(getChange("commissioning.bankAccount", "[" + payment.getCollaborator().getName() + "] " + payment.getBankAccount(), "", commissioning));
            changes.add(getChange("commissioning.billNumber", "[" + payment.getCollaborator().getName() + "] " + payment.getBillNumber(), "", commissioning));
        } else {
            changes.addAll(getCollaboratorPaymentInternalChanges(payment, commissioning, true));
        }
    }
    return changes;
}
Also used : ArrayList(java.util.ArrayList) CommissioningPaymentData(com.autentia.tnt.businessobject.CommissioningPaymentData) CommissioningChange(com.autentia.tnt.businessobject.CommissioningChange)

Example 2 with CommissioningPaymentData

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

the class CommissioningManager method getCollaboratorPaymentInternalChanges.

private Collection<? extends CommissioningChange> getCollaboratorPaymentInternalChanges(CommissioningPaymentData payment, Commissioning commissioning, boolean paymentIsPrevious) {
    final List<CommissioningChange> changes = new ArrayList<CommissioningChange>();
    CommissioningPaymentData paymentInList = null;
    // recuperamos el colaborador de la lista que coincide con el pasado
    for (CommissioningPaymentData paymentData : commissioning.getCollaboratorsPaymentData()) {
        if (payment.equals(paymentData)) {
            paymentInList = paymentData;
            break;
        }
    }
    if (paymentInList == null) {
        throw new IllegalArgumentException("PaymentInList no localizado");
    }
    // asignamos los valores de antes y despues
    CommissioningPaymentData paymentPrevious = null;
    CommissioningPaymentData paymentNow = null;
    if (paymentIsPrevious) {
        paymentPrevious = payment;
        paymentNow = paymentInList;
    } else {
        paymentPrevious = paymentInList;
        paymentNow = payment;
    }
    // sólo puede haber cambiado el modo de pago, la cuenta y la billnumber
    if (!paymentPrevious.getPaymentMode().equals(paymentNow.getPaymentMode())) {
        changes.add(getChange("commissioning.paymentMode", "[" + payment.getCollaborator().getName() + "] " + paymentPrevious.getPaymentMode().name(), "[" + payment.getCollaborator().getName() + "] " + paymentNow.getPaymentMode().name(), commissioning));
    }
    changes.add(getChange("commissioning.bankAccount", "[" + payment.getCollaborator().getName() + "] " + paymentPrevious.getBankAccount(), "[" + payment.getCollaborator().getName() + "] " + paymentNow.getBankAccount(), commissioning));
    changes.add(getChange("commissioning.billNumber", "[" + payment.getCollaborator().getName() + "] " + paymentPrevious.getBillNumber(), "[" + payment.getCollaborator().getName() + "] " + paymentNow.getBillNumber(), commissioning));
    return changes;
}
Also used : ArrayList(java.util.ArrayList) CommissioningPaymentData(com.autentia.tnt.businessobject.CommissioningPaymentData) CommissioningChange(com.autentia.tnt.businessobject.CommissioningChange)

Example 3 with CommissioningPaymentData

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

the class CommissioningBean method sendMailToCollaborators.

private void sendMailToCollaborators() {
    for (CommissioningPaymentData collaboratorPaymentData : commissioning.getCollaboratorsPaymentData()) {
        try {
            final InputStream is = ReportUtil.getReportWithoutDatabaseConnectionAsInputStream("document/ficha.de.proyecto", populateReportProperties(commissioning, collaboratorPaymentData));
            if (is != null) {
                final Map<InputStream, String> oses = new HashMap<InputStream, String>();
                oses.put(is, "ficha_proyecto.pdf");
                mailService.sendOutputStreams(collaboratorPaymentData.getCollaborator().getEMail(), ConfigurationUtil.getDefault().getCommissioningMailSubject(), ConfigurationUtil.getDefault().getCommissioningMailBody(), oses);
                FacesUtils.addInfoMessage(null, "commissioning.info.mailSentToCollaborator", collaboratorPaymentData.getCollaborator().getName(), collaboratorPaymentData.getCollaborator().getEMail());
            } else {
                log.warn("the report resume cannot be created");
                FacesUtils.addErrorMessage(null, "commissioning.error.projectReportCannotBeCreated");
            }
        } catch (Exception e) {
            log.warn("emails cannot be sent to the collaborators: " + e, e);
            FacesUtils.addErrorMessage(null, "commissioning.error.mailNotSentToCollaborator", collaboratorPaymentData.getCollaborator().getName(), collaboratorPaymentData.getCollaborator().getEMail());
        }
    }
}
Also used : HashMap(java.util.HashMap) InputStream(java.io.InputStream) CommissioningPaymentData(com.autentia.tnt.businessobject.CommissioningPaymentData) IOException(java.io.IOException)

Example 4 with CommissioningPaymentData

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

the class CommissioningBean method addCollaborator.

public String addCollaborator() {
    final Collaborator collab = getSelectedCollaborator();
    try {
        if (!commissioning.getCollaboratorsPaymentData().contains(collab)) {
            CommissioningPaymentData newCollab = new CommissioningPaymentData();
            newCollab.setCollaborator(collab);
            newCollab.setCommissioning(commissioning);
            newCollab.setPaymentMode(BillPaymentMode.UNKNOWN);
            newCollab.setBillNumber("");
            newCollab.setBankAccount("");
            commissioning.getCollaboratorsPaymentData().add(newCollab);
            // Add to history if commissioning is in a valid STATUS
            if (commissioning.getStatus() == CommissioningStatus.CONFIRMED || commissioning.getStatus() == CommissioningStatus.VALIDATED) {
                commissioning.getHistory().add(manager.getChange("commissioning.collaborator.add", "", newCollab.getCollaborator().getName(), commissioning));
            }
        }
    } catch (Exception e) {
        log.info(e.getCause());
    }
    return NavigationResults.EDIT;
}
Also used : Collaborator(com.autentia.tnt.businessobject.Collaborator) CommissioningPaymentData(com.autentia.tnt.businessobject.CommissioningPaymentData) IOException(java.io.IOException)

Example 5 with CommissioningPaymentData

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

the class CommissioningBean method validatePaymentMode.

private boolean validatePaymentMode() {
    boolean allValidationPassed = true;
    for (CommissioningPaymentData paymentData : commissioning.getCollaboratorsPaymentData()) {
        if (paymentData.getBankAccount().equals("") && paymentData.getBillNumber().equals("") || !paymentData.getBankAccount().equals("") && !paymentData.getBillNumber().equals("")) {
            allValidationPassed = false;
            FacesUtils.addErrorMessage(null, "commissioning.error.justSinglePaymentMode", paymentData.getCollaborator().getName());
        }
    }
    return allValidationPassed;
}
Also used : CommissioningPaymentData(com.autentia.tnt.businessobject.CommissioningPaymentData)

Aggregations

CommissioningPaymentData (com.autentia.tnt.businessobject.CommissioningPaymentData)6 CommissioningChange (com.autentia.tnt.businessobject.CommissioningChange)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 Collaborator (com.autentia.tnt.businessobject.Collaborator)1 InputStream (java.io.InputStream)1 HashMap (java.util.HashMap)1 UIData (javax.faces.component.UIData)1