/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.arrebol.taxiservicios.beans.admin.expense;

import com.arrebol.taxiservicios.beans.Datatable;
import com.arrebol.taxiservicios.beans.TaxiGenericBean;
import com.arrebol.taxiservicios.controller.admin.BitacoraController;
import com.arrebol.taxiservicios.controller.admin.ExpenseController;
import com.arrebol.taxiservicios.controller.admin.GenericValidationController;
import com.arrebol.taxiservicios.controller.admin.TaxiController;
import com.arrebol.taxiservicios.controller.catalog.BankCardController;
import com.arrebol.taxiservicios.controller.catalog.BankCardKardexController;
import com.arrebol.taxiservicios.controller.catalog.ExpenseIncomeCatalogController;
import com.arrebol.taxiservicios.controller.catalog.LocationController;
import com.arrebol.taxiservicios.controller.util.DateWrapper;
import com.arrebol.taxiservicios.model.admin.Expense;
import com.arrebol.taxiservicios.model.admin.Taxi;
import com.arrebol.taxiservicios.model.catalog.BankCard;
import com.arrebol.taxiservicios.model.catalog.BankCardKardex;
import com.arrebol.taxiservicios.model.catalog.ExpenseIncomeCatalog;
import com.arrebol.taxiservicios.model.catalog.Location;
import com.arrebol.taxiservicios.model.core.User;
import com.arrebol.taxiservicios.model.enums.BankCardKardexType;
import com.arrebol.taxiservicios.model.enums.BasicType;
import com.arrebol.taxiservicios.model.enums.ExpenseIncomeType;
import com.arrebol.taxiservicios.model.enums.ExpenseStatusType;
import com.arrebol.taxiservicios.model.enums.ExpenseType;
import java.io.Serializable;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.UUID;
import javax.annotation.PostConstruct;
import javax.faces.application.FacesMessage;
import javax.faces.view.ViewScoped;
import javax.inject.Named;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.primefaces.event.ReorderEvent;
import org.primefaces.event.RowEditEvent;

/**
 *
 * @author oscarvargas
 */
@Named("managerExpense")
@ViewScoped
public class ManagerExpense extends TaxiGenericBean implements Serializable, Datatable {

    public void fillExpenseDataTableBetweenDates() {
        try {
            if (getStartDate().after(getEndDate())) {
                showMessage(FacesMessage.SEVERITY_ERROR, getBundlePropertyFile().getString("generic.start.date"), getBundlePropertyFile().getString("generic.end.date.error"));
            } else {
                setExpense(getController().fillExpenseDataTableBetweenDates(getStartDate(), getEndDate(), getLoggedUser().getLocation()));
            }
        } catch (Exception e) {
            logger.error("", e);
        }
    }

    public void fillExpenseIniciosDataTableBetweenDates() {
        try {
            if (getStartDate().after(getEndDate())) {
                showMessage(FacesMessage.SEVERITY_ERROR, getBundlePropertyFile().getString("generic.start.date"), getBundlePropertyFile().getString("generic.end.date.error"));
            } else {
                setExpenseInicios(getController().fillExpenseIniciosDataTableBetweenDates(getStartDate(), getEndDate(), getLoggedUser().getLocation()));
            }
        } catch (Exception e) {
            logger.error("", e);
        }
    }

    @Override
    public void editRow(RowEditEvent event) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public void onRowCancel(RowEditEvent event) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public void onRowReorder(ReorderEvent event) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public void addRow() {
        logger.info("add Expense");
        try {
            if (getGenericController().existClosingDayByCreatedOn(new Date(), getLoggedUser())) {
                showMessage(FacesMessage.SEVERITY_WARN,
                        "Error",
                        "No se puede hacer ninguna acción si existe un corte del día");
                return;
            }
            if (getGenericController().existStableGeneralBoxByCurdate(getLoggedUser())) {
                showMessage(FacesMessage.SEVERITY_WARN,
                        "Dia cerrado",
                        "No se pueden eliminar más registros porque ya existe un cuadre de caja chica del día");
                return;
            }
            getAddExpense().setId(UUID.randomUUID().toString());
            getAddExpense().setType(ExpenseType.DISABLED);
            getAddExpense().setAmountMenudeo(0D);
            getAddExpense().setIdExpenseType(new ExpenseIncomeCatalog(getExpenseIncomeId()));
            getAddExpense().setLocation(getLoggedUser().getLocation());
            Calendar calendar = Calendar.getInstance();
            calendar.add(Calendar.HOUR, -6);
            getAddExpense().setCreatedOn(calendar.getTime());
            getAddExpense().setPaymentDate(calendar.getTime());

            getAddExpense().setLocationSend(getLoggedUser().getLocation());
            getAddExpense().setCommercialInvoiceStatus(BasicType.DISABLED);
            getAddExpense().setPaid(BasicType.ENEBLED);
            getAddExpense().setFinance(BasicType.ENEBLED);
            getAddExpense().setStatus(ExpenseStatusType.AUTHORIZED);

            if (isDeposit()) {
                getAddExpense().setDepositStatus(ExpenseStatusType.PENDING);
                getAddExpense().setBankCard(new BankCard(getBankCardId()));

            }else{
               getAddExpense().setDepositStatus(ExpenseStatusType.AUTHORIZED);
            }

            
            boolean success = getController().addExpense(
                    getAddExpense(),
                    getLoggedUser().getId(),
                    null);

            if (success) {

                expense.clear();
                expense = getController().fillExpenseDatatableLeftJoin();
                addExpense = new Expense();

                showMessage(FacesMessage.SEVERITY_INFO,
                        getBundlePropertyFile().getString("expense.add.title"),
                        getBundlePropertyFile().getString("expense.add.success.desc"));
            } else {
                logger.error("Expense " + getAddExpense() + " was not saved");
                showMessage(FacesMessage.SEVERITY_ERROR,
                        getBundlePropertyFile().getString("expense.add.title"),
                        getBundlePropertyFile().getString("expense.add.fail.desc"));
            }
        } catch (Exception e) {
            logger.error("addExpense: " + e);
            showMessage(FacesMessage.SEVERITY_FATAL,
                    getBundlePropertyFile().getString("expense.add.title"),
                    getBundlePropertyFile().getString("expense.add.exception.desc"));
        }
    }

    public void addInicioRow() {
        logger.info("add Inicio Expense");
        try {
            if (getGenericController().existClosingDayByCreatedOn(new Date(), getLoggedUser())) {
                showMessage(FacesMessage.SEVERITY_WARN,
                        "Error",
                        "No se puede hacer ninguna acción si existe un corte del día");
                return;
            }
            if (getGenericController().existStableSmallBoxByCurdate(getLoggedUser())) {
                showMessage(FacesMessage.SEVERITY_WARN,
                        "Dia cerrado",
                        "No se puede hacer ninguna acción porque ya existe un cuadre de caja chica del día");
                return;
            }
            if (getGenericController().existStableGeneralBoxByCurdate(getLoggedUser())) {
                showMessage(FacesMessage.SEVERITY_WARN,
                        "Dia cerrado",
                        "No se puede hacer ninguna acción porque ya existe un cuadre de caja general del día");
                return;
            }
            getAddInicioExpense().setId(UUID.randomUUID().toString());
            getAddInicioExpense().setType(ExpenseType.INICIO);
            getAddInicioExpense().setFolio("");
            getAddInicioExpense().setAmountMenudeo(0D);
            getAddInicioExpense().setStatus(ExpenseStatusType.AUTHORIZED);
            getAddInicioExpense().setDepositStatus(ExpenseStatusType.AUTHORIZED);
            getAddInicioExpense().setLastUpdatedBy(getLoggedUser());
            getAddInicioExpense().setLocation(getLoggedUser().getLocation());

            Calendar calendar = Calendar.getInstance();
            calendar.add(Calendar.HOUR, -6);
            getAddInicioExpense().setCreatedOn(calendar.getTime());

            getAddInicioExpense().setLocationSend(new Location(getLoggedUser().getLocation().getId()));
            getAddInicioExpense().setPaid(BasicType.ENEBLED);
            getAddInicioExpense().setFinance(BasicType.DISABLED);
            getAddInicioExpense().setCommercialInvoiceStatus(BasicType.DISABLED);

            boolean success = getController().addExpense(
                    getAddInicioExpense(),
                    getUserInicioId(),
                    null);

            if (success) {

                expense.clear();
                setExpenseInicios(getController().fillExpenseInicios(getLoggedUser().getLocation().getId()));
                setAddInicioExpense(new Expense());

                showMessage(FacesMessage.SEVERITY_INFO,
                        getBundlePropertyFile().getString("expense.inicio.title"),
                        getBundlePropertyFile().getString("expense.inicio.success.desc"));
            } else {
                logger.error("Expense inicio" + getAddInicioExpense() + " was not saved");
                showMessage(FacesMessage.SEVERITY_ERROR,
                        getBundlePropertyFile().getString("expense.inicio.title"),
                        getBundlePropertyFile().getString("expense.inicio.fail.desc"));
            }

        } catch (Exception e) {
            logger.error("addExpense: " + e);
            showMessage(FacesMessage.SEVERITY_FATAL,
                    getBundlePropertyFile().getString("expense.inicio.title"),
                    getBundlePropertyFile().getString("expense.inicio.exception.desc"));
        }
    }

    @Override
    public void deleteRow() {
        logger.info("deleteRow in Expense");
        try {

            if (getGenericController().existClosingDayByCreatedOn(new Date(), getLoggedUser())) {
                showMessage(FacesMessage.SEVERITY_WARN,
                        "Error",
                        "No se puede hacer ninguna acción si existe un corte del día");
                return;
            }
            if (getGenericController().existStableSmallBoxByCurdate(getLoggedUser())) {
                showMessage(FacesMessage.SEVERITY_WARN,
                        "Dia cerrado",
                        "No se puede hacer ninguna acción porque ya existe un cuadre de caja chica del día");
                return;
            }

            if (getSelectedExpense().getType().equals(ExpenseType.ABONO_FINANCIAMIENTO)) {
                Taxi taxi = getSelectedExpense().getTaxi();
                taxi.setAdeudo((float) (taxi.getAdeudo() + getSelectedExpense().getPayment()));
                getController().updateAdeudoTaxi(taxi);

            }

            if (getSelectedExpense().getType().equals(ExpenseType.PAGO_ORDEN_SERVICIO)) {

                getController().returnServiceOrder(getSelectedExpense(), getLoggedUser());
                getController().returnServiceOrderHasProduct(getSelectedExpense(), getLoggedUser());

            }

            boolean success = getController().deleteExpenseById(getSelectedExpense().getId());

            if (success) {
                if (null == getCommentsBitacora() || getCommentsBitacora().trim().equals("")) {
                    setCommentsBitacora("El usuario " + getLoggedUser().getUserName() + " no agrego comentarios a la hora de borrar el Ingreso/Egreso");
                }

                String actionBitacora = "Eliminar Ingreso/Egreso";
                String descBitacora = "Se eliminó el Ingreso/Egreso, con el folio " + getSelectedExpense().getFolio()
                        + ", costo " + currencyFormatNumber(getSelectedExpense().getPayment())
                        + ", tipo " + getSelectedExpense().getType().getType()
                        + ", estatus " + getSelectedExpense().getStatus().getStatus()
                        + " y fecha " + getSelectedExpense().getPaymentDate();

                getBitacoraController().saveNewRecordInBitacora(createNewRecordInBitacora(UUID.randomUUID().toString(), actionBitacora, getCommentsBitacora(), descBitacora),
                        getLoggedUser().getLocation().getId());
                getExpense().remove(getSelectedExpense());

                setSelectedExpense(null);
                setCommentsBitacora("");

                showMessage(FacesMessage.SEVERITY_INFO,
                        getBundlePropertyFile().getString("expense.delete.title"),
                        getBundlePropertyFile().getString("expense.delete.success.desc"));
            } else {
                logger.error("Expense " + getSelectedExpense() + "was not deleted");
                showMessage(FacesMessage.SEVERITY_ERROR,
                        getBundlePropertyFile().getString("expense.delete.title"),
                        getBundlePropertyFile().getString("expense.delete.fail.desc"));
            }

        } catch (Exception e) {
            logger.error("deleteRow: " + e);

            showMessage(FacesMessage.SEVERITY_FATAL,
                    getBundlePropertyFile().getString("expense.delete.title"),
                    getBundlePropertyFile().getString("expense.delete.exception.desc"));
        }
    }

    public void autorizarPendingExpense() {
        logger.info("autorizarPendingExpense");

        try {
            
            if (getGenericController().existClosingDayByCreatedOn(new Date(), getLoggedUser())) {
                showMessage(FacesMessage.SEVERITY_WARN,
                        "Error",
                        "No se puede hacer ninguna acción si existe un corte del día");
                return;
            }
            if (getGenericController().existStableSmallBoxByCurdate(getLoggedUser())) {
                showMessage(FacesMessage.SEVERITY_WARN,
                        "Dia cerrado",
                        "No se puede hacer ninguna acción porque ya existe un cuadre de caja chica del día");
                return;
            }
            boolean success = getController().autorizarExpense(getSelectedExpense().getId(), getLoggedUser());

            if (success) {

                BankCardKardex bankCardKardexObj = new BankCardKardex();

                bankCardKardexObj.setBankCard(getSelectedExpense().getBankCard());
                bankCardKardexObj.setAmount(getSelectedExpense().getPayment());
                bankCardKardexObj.setAmountBefore(getSelectedExpense().getBankCard().getBalance());

                if (getSelectedExpense().getIdExpenseType().getExpenseIncomeCatalogType().equals(ExpenseIncomeType.EARNING)) {

                    bankCardKardexObj.setAmountAfter(bankCardKardexObj.getAmountBefore() + bankCardKardexObj.getAmount());
                    bankCardKardexObj.setKardexType(BankCardKardexType.INCOME);
                    bankCardKardexObj.setDescription("Pago por gasto del tipo " + getSelectedExpense().getIdExpenseType().getName());
               
                } else if (getSelectedExpense().getIdExpenseType().getExpenseIncomeCatalogType().equals(ExpenseIncomeType.EXPENSE)) {
                
                    bankCardKardexObj.setAmountAfter(bankCardKardexObj.getAmountBefore() - bankCardKardexObj.getAmount());
                    bankCardKardexObj.setKardexType(BankCardKardexType.EXPENSE);
                    bankCardKardexObj.setDescription("Cobro por gasto del tipo " + getSelectedExpense().getIdExpenseType().getName());
                
                }

                bankCardKardexObj.setLocation(getSelectedExpense().getLocation());

                BankCardKardexController bankCardKardexCtrl = new BankCardKardexController();
                bankCardKardexCtrl.save(bankCardKardexObj, getLoggedUser().getId());

                BankCard bankCard = getSelectedExpense().getBankCard();

                bankCard.setBalance(bankCardKardexObj.getAmountAfter());

                BankCardController bankCardCtrl = new BankCardController();

                bankCardCtrl.save(bankCard, getLoggedUser().getId());

                setSelectedExpense(null);

                showMessage(FacesMessage.SEVERITY_INFO,
                        "Autorizar",
                        "Se autorizó correctamente");
                setExpensePending(getController().fillExpenseDataTablePendingDeposit(getLoggedUser().getLocation()));
            } else {
                logger.error("Sale " + getSelectedExpense() + "was not changed to no print");
                showMessage(FacesMessage.SEVERITY_ERROR,
                        "Autorizar",
                        "No se pudo autorizar");
            }

        } catch (Exception e) {
            logger.error("autorizar: " + e);

            showMessage(FacesMessage.SEVERITY_FATAL,
                    getBundlePropertyFile().getString("sale.noprint.title"),
                    getBundlePropertyFile().getString("sale.noprint.exception.desc"));
        }

    }

    public void autorizarRow() {
        logger.info("autorizarRow in Expense");
        try {

            boolean success = getController().autorizarExpenseById(getSelectedExpense().getId());

            if (success) {
                expense.clear();
                expense = getController().fillExpenseDatatableLeftJoin();
                setSelectedExpense(null);

                showMessage(FacesMessage.SEVERITY_INFO,
                        getBundlePropertyFile().getString("expense.autorizar.title"),
                        getBundlePropertyFile().getString("expense.autorizar.success.desc"));
            } else {
                logger.error("Expense " + getSelectedExpense() + "was not autorizhed");
                showMessage(FacesMessage.SEVERITY_ERROR,
                        getBundlePropertyFile().getString("expense.autorizar.title"),
                        getBundlePropertyFile().getString("expense.autorizar.fail.desc"));
            }

        } catch (Exception e) {
            logger.error("autorizarRow: " + e);

            showMessage(FacesMessage.SEVERITY_FATAL,
                    getBundlePropertyFile().getString("expense.autorizar.title"),
                    getBundlePropertyFile().getString("expense.autorizar.exception.desc"));
        }
    }

    public void autorizarInicioRow() {
        logger.info("autorizarInicioRow in Expense");
        try {

            boolean success = getController().autorizarExpenseById(getSelectedExpenseInicio().getId());

            if (success) {
                getExpenseInicios().clear();
                setExpenseInicios(getController().fillExpenseDatatableLeftJoin());
                setSelectedExpenseInicio(null);

                showMessage(FacesMessage.SEVERITY_INFO,
                        getBundlePropertyFile().getString("expense.autorizar.title"),
                        getBundlePropertyFile().getString("expense.autorizar.success.desc"));
            } else {
                logger.error("Expense " + getSelectedExpenseInicio() + "was not autorizhed");
                showMessage(FacesMessage.SEVERITY_ERROR,
                        getBundlePropertyFile().getString("expense.autorizar.title"),
                        getBundlePropertyFile().getString("expense.autorizar.fail.desc"));
            }

        } catch (Exception e) {
            logger.error("autorizarInicioRow: " + e);

            showMessage(FacesMessage.SEVERITY_FATAL,
                    getBundlePropertyFile().getString("expense.autorizar.title"),
                    getBundlePropertyFile().getString("expense.autorizar.exception.desc"));
        }
    }

    public void deleteInicioRow() {
        logger.info("deleteInicioRow in Expense");
        try {

            if (getGenericController().existClosingDayByCreatedOn(new Date(), getLoggedUser())) {
                showMessage(FacesMessage.SEVERITY_WARN,
                        "Error",
                        "No se puede hacer ninguna acción si existe un corte del día");
                return;
            }
            if (getGenericController().existStableSmallBoxByCurdate(getLoggedUser())) {
                showMessage(FacesMessage.SEVERITY_WARN,
                        "Dia cerrado",
                        "No se puede hacer ninguna acción porque ya existe un cuadre de caja chica del día");
                return;
            }
            if (getGenericController().existStableGeneralBoxByCurdate(getLoggedUser())) {
                showMessage(FacesMessage.SEVERITY_WARN,
                        "Dia cerrado",
                        "No se puede hacer ninguna acción porque ya existe un cuadre de caja general del día");
                return;
            }
            boolean success = getController().deleteExpenseById(getSelectedExpenseInicio().getId());

            if (success) {
                if (null == getCommentsBitacora() || getCommentsBitacora().trim().equals("")) {
                    setCommentsBitacora("El usuario " + getLoggedUser().getUserName() + " no agrego comentarios a la hora de borrar el inicio");
                }

                String actionBitacora = "Eliminar Inicio";
                String descBitacora = "Se eliminó el Inicio con el mondo de " + currencyFormatNumber(getSelectedExpenseInicio().getPayment())
                        + ", tipo " + getSelectedExpenseInicio().getType().getType()
                        + ", estatus " + getSelectedExpenseInicio().getStatus().getStatus()
                        + ", creado por " + getSelectedExpenseInicio().getCreatedBy().getPerson().getFirstName()
                        + " " + getSelectedExpenseInicio().getCreatedBy().getPerson().getLastName()
                        + " " + (null == getSelectedExpenseInicio().getCreatedBy().getPerson().getMiddleName() ? "" : getSelectedExpenseInicio().getCreatedBy().getPerson().getMiddleName())
                        + " y fecha " + getSelectedExpenseInicio().getPaymentDate();

                getBitacoraController().saveNewRecordInBitacora(createNewRecordInBitacora(UUID.randomUUID().toString(), actionBitacora, getCommentsBitacora(), descBitacora),
                        getLoggedUser().getLocation().getId());
                getExpenseInicios().remove(getSelectedExpenseInicio());

                setSelectedExpenseInicio(null);
                setCommentsBitacora("");

                showMessage(FacesMessage.SEVERITY_INFO,
                        getBundlePropertyFile().getString("expense.inicio.title"),
                        getBundlePropertyFile().getString("expense.inicio.delete.success.desc"));
            } else {
                logger.error("Expense " + getSelectedExpenseInicio() + "was not deleted");
                showMessage(FacesMessage.SEVERITY_ERROR,
                        getBundlePropertyFile().getString("expense.inicio.title"),
                        getBundlePropertyFile().getString("expense.inicio.delete.fail.desc"));
            }

        } catch (Exception e) {
            logger.error("deleteInicioRow: " + e);

            showMessage(FacesMessage.SEVERITY_FATAL,
                    getBundlePropertyFile().getString("expense.inicio.title"),
                    getBundlePropertyFile().getString("expense.inicio.delete.exception.desc"));
        }
    }

    public ExpenseController getController() {
        return controller;
    }

    public void setController(ExpenseController controller) {
        this.controller = controller;
    }

    public List<Expense> getExpense() {
        return expense;
    }

    public void setExpense(List<Expense> expense) {
        this.expense = expense;
    }

    public String getTaxiId() {
        return taxiId;
    }

    public void setTaxiId(String taxiId) {
        this.taxiId = taxiId;
    }

    public Expense getSelectedExpense() {
        return selectedExpense;
    }

    public void setSelectedExpense(Expense selectedExpense) {
        this.selectedExpense = selectedExpense;
    }

    public List<Taxi> getTaxis() {
        return getController().fillTaxisComboBox();
    }

    public Expense getAddExpense() {
        return addExpense;
    }

    public void setAddExpense(Expense addExpense) {
        this.addExpense = addExpense;
    }

    public String getTipo() {
        return tipo;
    }

    public void setTipo(String tipo) {
        this.tipo = tipo;
    }

    public GenericValidationController getGenericController() {
        return genericController;
    }

    public void setGenericController(GenericValidationController genericController) {
        this.genericController = genericController;
    }

    @PostConstruct
    public void init() {
        logger.info("init expense");
        try {
            loadBundlePropertyFile();
            initOneWeekBeforeToCurrdate();
            setAddExpense(new Expense());
            setAddInicioExpense(new Expense());
            setController(new ExpenseController());
            setLocationController(new LocationController());
            setBankCardController(new BankCardController());
            setGenericController(new GenericValidationController());
            setTaxiController(new TaxiController());
            //setExpense(getController().fillExpenseDatatableLeftJoin());
            setExpense(getController().fillExpenseDataTableBetweenDates(getStartDate(), getEndDate(), getLoggedUser().getLocation()));
            setExpensePending(getController().fillExpenseDataTablePendingDeposit(getLoggedUser().getLocation()));
            //setExpenseInicios(getController().fillExpenseInicios(getLoggedUser().getLocation().getId()));
            setExpenseInicios(getController().fillExpenseIniciosDataTableBetweenDates(getStartDate(), getEndDate(), getLoggedUser().getLocation()));
            setUsersInicio(getController().findAllSystemUserByLocation(getLoggedUser().getLocation()));
            setBitacoraController(new BitacoraController());
            setLastStableGeneralBox(getGenericController().lastStableGeneralBoxByDate(getLoggedUser()));
            setHayCuadre(getGenericController().existStableGeneralBoxByCurdate(getLoggedUser()));
            setLastStableSmallBox(getGenericController().lastStableSmallBoxByDate(getLoggedUser()));
            setHayCuadreSmall(getGenericController().existStableSmallBoxByCurdate(getLoggedUser()));
            setLocations(getLocationController().fillLocationDatatable());
            setExpenseIncomeCatalogController(new ExpenseIncomeCatalogController());
            setExpenseIncomeCatalog(getExpenseIncomeCatalogController().findExpenseIncomeCatalogSmallBox());
            setBankCards(getBankCardController().findAllBankCardsByLocation(getLoggedUser().getLocation().getId()));
            setDeposit(false);
        } catch (Exception e) {
            logger.error("init expense", e);
        }
    }

    /* public void totalizador(){
        totalEgreso = 0D;
        totalIngreso = 0D;
        if(getExpense() != null && !getExpense().isEmpty()){
            for(Expense tmp: getExpense()){
                if
            }
        }
    }*/
    private static final long serialVersionUID = 6305656544028190083L;

    final Logger logger = LogManager.getLogger(ManagerExpense.class);

    private ExpenseController controller;
    private GenericValidationController genericController;
    private List<Expense> expense;
    private List<Expense> expensePending;
    private String taxiId;
    private Expense selectedExpense;
    private Expense addExpense;
    private List<Expense> expenseInicios;
    private Expense selectedExpenseInicio;
    private String tipo;
    private String userInicioId;
    private List<User> usersInicio;
    private Expense addInicioExpense;
    private BitacoraController bitacoraController;
    private String commentsBitacora;
    private Date startDate;
    private Date endDate;
    private Date lastStableGeneralBox;
    private boolean hayCuadre;
    private Date lastStableSmallBox;
    private boolean hayCuadreSmall;
    private double totalIngreso;
    private double totalEgreso;
    private boolean deposit;
    private String bankCardId;
    private BankCardController bankCardController;
    private List<BankCard> bankCards;

    private List<Location> locations;
    private String locationId;
    private LocationController locationController;
    private TaxiController taxiController;

    private ExpenseIncomeCatalogController expenseIncomeCatalogController;

    private String expenseIncomeId;
    private List<ExpenseIncomeCatalog> expenseIncomeCatalog;

    public BankCardController getBankCardController() {
        return bankCardController;
    }

    public void setBankCardController(BankCardController bankCardController) {
        this.bankCardController = bankCardController;
    }

    public List<BankCard> getBankCards() {
        return bankCards;
    }

    public void setBankCards(List<BankCard> bankCards) {
        this.bankCards = bankCards;
    }

    public List<Location> getLocations() {
        return locations;
    }

    public void setLocations(List<Location> locations) {
        this.locations = locations;
    }

    public String getLocationId() {
        return locationId;
    }

    public void setLocationId(String locationId) {
        this.locationId = locationId;
    }

    public LocationController getLocationController() {
        return locationController;
    }

    public void setLocationController(LocationController locationController) {
        this.locationController = locationController;
    }

    public double getTotalIngreso() {
        return totalIngreso;
    }

    public void setTotalIngreso(double totalIngreso) {
        this.totalIngreso = totalIngreso;
    }

    public double getTotalEgreso() {
        return totalEgreso;
    }

    public void setTotalEgreso(double totalEgreso) {
        this.totalEgreso = totalEgreso;
    }

    private void initOneWeekBeforeToCurrdate() {
        try {
            Calendar start = Calendar.getInstance();

            start.set(Calendar.WEEK_OF_YEAR, start.get(Calendar.WEEK_OF_YEAR) - 1);
            start.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);

            setStartDate(start.getTime());
            setEndDate(DateWrapper.getTodayMXTime());
        } catch (Exception e) {

        }
    }

    public TaxiController getTaxiController() {
        return taxiController;
    }

    public void setTaxiController(TaxiController taxiController) {
        this.taxiController = taxiController;
    }

    public Date getLastStableGeneralBox() {
        return lastStableGeneralBox;
    }

    public void setLastStableGeneralBox(Date lastStableGeneralBox) {
        this.lastStableGeneralBox = lastStableGeneralBox;
    }

    public boolean isHayCuadre() {
        return hayCuadre;
    }

    public void setHayCuadre(boolean hayCuadre) {
        this.hayCuadre = hayCuadre;
    }

    public List<Expense> getExpenseInicios() {
        return expenseInicios;
    }

    public void setExpenseInicios(List<Expense> expenseInicios) {
        this.expenseInicios = expenseInicios;
    }

    public Expense getSelectedExpenseInicio() {
        return selectedExpenseInicio;
    }

    public Date getLastStableSmallBox() {
        return lastStableSmallBox;
    }

    public void setLastStableSmallBox(Date lastStableSmallBox) {
        this.lastStableSmallBox = lastStableSmallBox;
    }

    public boolean isHayCuadreSmall() {
        return hayCuadreSmall;
    }

    public void setHayCuadreSmall(boolean hayCuadreSmall) {
        this.hayCuadreSmall = hayCuadreSmall;
    }

    public void setSelectedExpenseInicio(Expense selectedExpenseInicio) {
        this.selectedExpenseInicio = selectedExpenseInicio;
    }

    public String getUserInicioId() {
        return userInicioId;
    }

    public void setUserInicioId(String userInicioId) {
        this.userInicioId = userInicioId;
    }

    public List<User> getUsersInicio() {
        return usersInicio;
    }

    public void setUsersInicio(List<User> usersInicio) {
        this.usersInicio = usersInicio;
    }

    public Expense getAddInicioExpense() {
        return addInicioExpense;
    }

    public void setAddInicioExpense(Expense addInicioExpense) {
        this.addInicioExpense = addInicioExpense;
    }

    public BitacoraController getBitacoraController() {
        return bitacoraController;
    }

    public void setBitacoraController(BitacoraController bitacoraController) {
        this.bitacoraController = bitacoraController;
    }

    public String getCommentsBitacora() {
        return commentsBitacora;
    }

    public void setCommentsBitacora(String commentsBitacora) {
        this.commentsBitacora = commentsBitacora;
    }

    public Date getStartDate() {
        return startDate;
    }

    public void setStartDate(Date startDate) {
        this.startDate = startDate;
    }

    public Date getEndDate() {
        return endDate;
    }

    public void setEndDate(Date endDate) {
        this.endDate = endDate;
    }

    public ExpenseIncomeCatalogController getExpenseIncomeCatalogController() {
        return expenseIncomeCatalogController;
    }

    public void setExpenseIncomeCatalogController(ExpenseIncomeCatalogController expenseIncomeCatalogController) {
        this.expenseIncomeCatalogController = expenseIncomeCatalogController;
    }

    public String getExpenseIncomeId() {
        return expenseIncomeId;
    }

    public void setExpenseIncomeId(String expenseIncomeId) {
        this.expenseIncomeId = expenseIncomeId;
    }

    public List<ExpenseIncomeCatalog> getExpenseIncomeCatalog() {
        return expenseIncomeCatalog;
    }

    public void setExpenseIncomeCatalog(List<ExpenseIncomeCatalog> expenseIncomeCatalog) {
        this.expenseIncomeCatalog = expenseIncomeCatalog;
    }

    public boolean isDeposit() {
        return deposit;
    }

    public void setDeposit(boolean deposit) {
        this.deposit = deposit;
    }

    public String getBankCardId() {
        return bankCardId;
    }

    public void setBankCardId(String bankCardId) {
        this.bankCardId = bankCardId;
    }

    public List<Expense> getExpensePending() {
        return expensePending;
    }

    public void setExpensePending(List<Expense> expensePending) {
        this.expensePending = expensePending;
    }

}
