package com.alexanderlogistics;

import java.io.Serializable;
import java.util.List;
import java.util.logging.Logger;

import javax.enterprise.context.ConversationScoped;
import javax.inject.Inject;
import javax.inject.Named;

import org.imixs.workflow.ItemCollection;
import org.imixs.workflow.engine.DocumentService;
import org.imixs.workflow.faces.data.WorkflowController;
import org.imixs.workflow.sepa.controller.SepaController;

/**
 * Der SEPAExportControllerAGL dient dazu die IBAN/BIC einstellungen in
 * einem SEPA Export zu aktualiseren. Er wird von der Form
 * sepa_export.xhtml aus per Ajax angesteuert.
 * 
 * @author rsoika
 *
 */
@Named(value = "sepaExportControllerAGL")
@ConversationScoped
public class SEPAExportControllerAGL implements Serializable {

    private static final long serialVersionUID = 1L;

    private static Logger logger = Logger.getLogger(SEPAExportControllerAGL.class.getName());

    @Inject
    protected WorkflowController workflowController;

    @Inject
    protected DocumentService documentService;

    @Inject
    SepaController sepaController;

    /**
     * This method removes an uniqueid form the item $workitemref
     */
    public void updateIBANBIC() {

        String paymentType = workflowController.getWorkitem().getItemValueString("payment.type");

        logger.info("Neuer Payment Type=" + paymentType);

        // lookup config
        List<ItemCollection> dbrtList = sepaController.getDbtrList();
        for (ItemCollection dbtr : dbrtList) {
            if (paymentType.equals(dbtr.getItemValueString("name"))) {
                workflowController.getWorkitem().setItemValue("dbtr.iban", dbtr.getItemValueString("dbtr.iban"));
                workflowController.getWorkitem().setItemValue("dbtr.bic", dbtr.getItemValueString("dbtr.bic"));
                break;
            }
        }

    }

}
