/*
 * Arrebol Consultancy copyright.
 * 
 * This code belongs to Arrebol Consultancy
 * its use, redistribution or modification are prohibited 
 * without written authorization from Arrebol Consultancy.
 */
package com.arrebol.apc.controller.mobile.controller.tracking;

import com.arrebol.apc.controller.mobile.moxy.views.PaymentTrackingViewJaxb;
import com.arrebol.apc.controller.mobile.repository.tracking.PaymentTrackingRepository;
import com.arrebol.apc.model.ModelParameter;
import com.arrebol.apc.model.core.Office;
import com.arrebol.apc.model.core.User;
import com.arrebol.apc.model.views.AdvanceUserDailyView;
import com.arrebol.apc.model.views.constance.AdvanceUserDailyViewCfg;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

/**
 *
 * @author Carlos Janitzio Zavala Lopez <janitzio.zavala@arrebol.com.mx>
 */
public class PaymentTrackingController implements Serializable {

    public PaymentTrackingViewJaxb paymentTrakingByUserDetails(String idUser, String idOffice) {
        PaymentTrackingViewJaxb paymentTracking = new PaymentTrackingViewJaxb();
        logger.debug("paymentTrakingByUserDetails");
        try {

            List<ModelParameter> parameters = new ArrayList<>();

            parameters.add(
                    new ModelParameter(
                            AdvanceUserDailyViewCfg.FIELD_VIEW_USER,
                            new User(idUser)
                    )
            );
            parameters.add(
                    new ModelParameter(
                            AdvanceUserDailyViewCfg.FIELD_VIEW_OFFICE,
                            new Office(idOffice)
                    )
            );

            PaymentTrackingRepository repository = new PaymentTrackingRepository();

            AdvanceUserDailyView result = repository.paymentTrakingByUserDetails(
                    AdvanceUserDailyView.class,
                    AdvanceUserDailyViewCfg.QUERY_PAYMENT_TRACKING_BY_IDS,
                    parameters);

            if (null != result) {
                paymentTracking.setTotalExpected(result.getTotalExpected());
                paymentTracking.setTotalNow(result.getTotalNow());
            }
        } catch (Exception e) {
            logger.error("paymentTrakingByUserDetails");
        }

        return paymentTracking;
    }

    private static final long serialVersionUID = -3224360462532091920L;
    final Logger logger = LogManager.getLogger(PaymentTrackingController.class);
}
