/*
 * 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.taxiservicios.beans.mutual;

import com.arrebol.taxiservicios.beans.Datatable;
import com.arrebol.taxiservicios.beans.SendMSN;
import com.arrebol.taxiservicios.beans.TaxiGenericBean;
import com.arrebol.taxiservicios.controller.admin.BitacoraController;
import com.arrebol.taxiservicios.controller.admin.GenericValidationController;
import com.arrebol.taxiservicios.controller.mutual.MutualClosingDayController;
import com.arrebol.taxiservicios.controller.mutual.MutualStableSmallBoxController;
import com.arrebol.taxiservicios.model.core.User;
import com.arrebol.taxiservicios.model.enums.BasicType;
import com.arrebol.taxiservicios.model.mutual.MutualClosingDay;
import com.arrebol.taxiservicios.model.mutual.MutualStableSmallBox;
import com.itextpdf.text.BaseColor;
import com.itextpdf.text.Chunk;
import com.itextpdf.text.Document;
import com.itextpdf.text.Element;
import com.itextpdf.text.FontFactory;
import com.itextpdf.text.PageSize;
import com.itextpdf.text.Paragraph;
import com.itextpdf.text.pdf.PdfPCell;
import com.itextpdf.text.pdf.PdfPTable;
import com.itextpdf.text.pdf.PdfWriter;
import java.awt.Font;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.Serializable;
import java.math.BigDecimal;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
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.context.FacesContext;
import javax.faces.view.ViewScoped;
import javax.inject.Named;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.primefaces.event.ReorderEvent;
import org.primefaces.event.RowEditEvent;
import java.sql.Timestamp;

/**
 *
 * @author Carlos Janitzio Zavala Lopez <janitzio.zavala@arrebol.com.mx>
 */
@Named
@ViewScoped
public class MutualStableSmallBoxBean extends TaxiGenericBean implements Serializable, Datatable {

    public void imprimir(){
        Document document = new Document(PageSize.LETTER);
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        try
        {
          PdfWriter.getInstance(document, baos);
          List<MutualClosingDay> results = new ArrayList<>();
          
          Date startDate = getClosingController().lastMutualStableSmallBoxBySmallBox(selectedRow);
          
          results = getClosingController().findMutualClosingDailyListBetweenDates(startDate, selectedRow.getCreatedOn(), 
                  getLoggedUser().getLocation().getId());
          User userTmp = selectedRow.getCreatedBy();
          document.open();
          
          DateFormat formatter = new SimpleDateFormat("dd/MM/yy");
          
          Paragraph printDate = new Paragraph("Fecha de impresión: " + formatter.format(new Date()), FontFactory.getFont("arial", 10, Font.BOLD, BaseColor.DARK_GRAY));
          printDate.setAlignment(Element.ALIGN_RIGHT);
          document.add(printDate);
          
          Paragraph title = new Paragraph("Mutual - Cuadre de caja chica - " + selectedRow.getLocation().getName(), FontFactory.getFont("arial", 18, Font.BOLD, BaseColor.DARK_GRAY));
          title.setAlignment(Element.ALIGN_CENTER);
          document.add(title);
          
          String date = formatter.format(selectedRow.getCreatedOn());
          document.add(new Paragraph("Fecha de creación: ", FontFactory.getFont("arial", 8, Font.BOLD, BaseColor.BLACK)));
          document.add(new Paragraph(date, FontFactory.getFont("arial", 8, Font.PLAIN, BaseColor.BLACK)));
          document.add(new Paragraph("Usuario creación: ", FontFactory.getFont("arial", 8, Font.BOLD, BaseColor.BLACK)));
          document.add(new Paragraph(userTmp.getPerson().getFirstName() + " " + userTmp.getPerson().getLastName(), FontFactory.getFont("arial", 8, Font.PLAIN, BaseColor.BLACK)));
          
          document.add(new Paragraph("Total en caja: ", FontFactory.getFont("arial", 8, Font.BOLD, BaseColor.BLACK)));
          document.add(new Paragraph("$" + selectedRow.getTotalSmallBox().toString(), FontFactory.getFont("arial", 8, Font.PLAIN, BaseColor.BLACK)));
          
          document.add(new Paragraph("Deje en sobres: ", FontFactory.getFont("arial", 8, Font.BOLD, BaseColor.BLACK)));
          document.add(new Paragraph("$" + selectedRow.getTotalEnvelope().toString(), FontFactory.getFont("arial", 8, Font.PLAIN, BaseColor.BLACK)));
          
          document.add(new Paragraph("Efectivo: ", FontFactory.getFont("arial", 8, Font.BOLD, BaseColor.BLACK)));
          document.add(new Paragraph("$" + selectedRow.getTotalBankNote().toString(), FontFactory.getFont("arial", 8, Font.PLAIN, BaseColor.BLACK)));
          
          document.add(new Paragraph("Monedas: ", FontFactory.getFont("arial", 8, Font.BOLD, BaseColor.BLACK)));
          document.add(new Paragraph("$" + selectedRow.getTotalCoin().toString(), FontFactory.getFont("arial", 8, Font.PLAIN, BaseColor.BLACK)));
          
          document.add(new Paragraph("Diferencia: ", FontFactory.getFont("arial", 8, Font.BOLD, BaseColor.BLACK)));
          document.add(new Paragraph("$" + (selectedRow.getTotalStable().subtract(selectedRow.getTotalSmallBox())).toString(), FontFactory.getFont("arial", 8, Font.PLAIN, BaseColor.BLACK)));
          
          document.add(new Paragraph("Descripción: ", FontFactory.getFont("arial", 8, Font.BOLD, BaseColor.BLACK)));
          document.add(new Paragraph(selectedRow.getDescription(), FontFactory.getFont("arial", 8, Font.PLAIN, BaseColor.BLACK)));
          
          document.add(Chunk.NEWLINE); 
          
          PdfPTable table =new PdfPTable(7);
          table.setTotalWidth(new float[]{100,60,60,60,80,100,100});
          
          table.setLockedWidth(true);
          PdfPCell cell = new PdfPCell(new Paragraph("Cortes del dia", 
                  FontFactory.getFont("arial", 10, Font.BOLD, BaseColor.WHITE)));
          
          cell.setHorizontalAlignment(Element.ALIGN_CENTER);
          cell.setBackgroundColor(BaseColor.BLUE);
          cell.setColspan(7);
          table.addCell(cell);
          
          cell = new PdfPCell(new Paragraph("Usuario", 
                  FontFactory.getFont("arial", 8, Font.BOLD, BaseColor.BLACK)));
          cell.setHorizontalAlignment(Element.ALIGN_CENTER);
          cell.setColspan(1);
          table.addCell(cell);
          
          cell = new PdfPCell(new Paragraph("Monto a reportar", 
                  FontFactory.getFont("arial", 8, Font.BOLD, BaseColor.BLACK)));
          cell.setHorizontalAlignment(Element.ALIGN_CENTER);
          cell.setColspan(1);
          table.addCell(cell);
          
          cell = new PdfPCell(new Paragraph("Monto reportado", 
                  FontFactory.getFont("arial", 8, Font.BOLD, BaseColor.BLACK)));
          cell.setHorizontalAlignment(Element.ALIGN_CENTER);
          cell.setColspan(1);
          table.addCell(cell);
          
          cell = new PdfPCell(new Paragraph("Diferencia", 
                  FontFactory.getFont("arial", 8, Font.BOLD, BaseColor.BLACK)));
          cell.setHorizontalAlignment(Element.ALIGN_CENTER);
          cell.setColspan(1);
          table.addCell(cell);
          
          cell = new PdfPCell(new Paragraph("Fecha", 
                  FontFactory.getFont("arial", 8, Font.BOLD, BaseColor.BLACK)));
          cell.setHorizontalAlignment(Element.ALIGN_CENTER);
          cell.setColspan(1);
          table.addCell(cell);
          
          cell = new PdfPCell(new Paragraph("Comentarios", 
                  FontFactory.getFont("arial", 8, Font.BOLD, BaseColor.BLACK)));
          cell.setHorizontalAlignment(Element.ALIGN_CENTER);
          cell.setColspan(1);
          table.addCell(cell);
          
          cell = new PdfPCell(new Paragraph("Creado por", 
                  FontFactory.getFont("arial", 8, Font.BOLD, BaseColor.BLACK)));
          cell.setHorizontalAlignment(Element.ALIGN_CENTER);
          cell.setColspan(1);
          table.addCell(cell);
          
          for(MutualClosingDay tmp : results)
          {
              cell = new PdfPCell(new Paragraph(tmp.getUser().getPerson().getFirstName() + " " + tmp.getUser().getPerson().getLastName(), 
                  FontFactory.getFont("arial", 6, Font.PLAIN, BaseColor.BLACK)));
                cell.setHorizontalAlignment(Element.ALIGN_LEFT);
                cell.setColspan(1);
                table.addCell(cell);
                
                cell = new PdfPCell(new Paragraph(tmp.getAmountExpected().doubleValue() + "", 
                  FontFactory.getFont("arial", 6, Font.PLAIN, BaseColor.BLACK)));
                cell.setHorizontalAlignment(Element.ALIGN_LEFT);
                cell.setColspan(1);
                table.addCell(cell);
                
                cell = new PdfPCell(new Paragraph(tmp.getAmountPaid().doubleValue() + "", 
                  FontFactory.getFont("arial", 6, Font.PLAIN, BaseColor.BLACK)));
                cell.setHorizontalAlignment(Element.ALIGN_LEFT);
                cell.setColspan(1);
                table.addCell(cell);
                
                cell = new PdfPCell(new Paragraph((tmp.getAmountPaid().subtract(tmp.getAmountExpected())).doubleValue() + "", 
                  FontFactory.getFont("arial", 6, Font.PLAIN, BaseColor.BLACK)));
                cell.setHorizontalAlignment(Element.ALIGN_LEFT);
                cell.setColspan(1);
                table.addCell(cell);
                
                cell = new PdfPCell(new Paragraph(tmp.getCreatedOn().toString(), 
                  FontFactory.getFont("arial", 6, Font.PLAIN, BaseColor.BLACK)));
                cell.setHorizontalAlignment(Element.ALIGN_LEFT);
                cell.setColspan(1);
                table.addCell(cell);
                
                cell = new PdfPCell(new Paragraph(tmp.getComments(), 
                  FontFactory.getFont("arial", 6, Font.PLAIN, BaseColor.BLACK)));
                cell.setHorizontalAlignment(Element.ALIGN_LEFT);
                cell.setColspan(1);
                table.addCell(cell);
                
                cell = new PdfPCell(new Paragraph(tmp.getCreatedBy().getPerson().getFirstName() + " " + tmp.getCreatedBy().getPerson().getLastName(), 
                  FontFactory.getFont("arial", 6, Font.PLAIN, BaseColor.BLACK)));
                cell.setHorizontalAlignment(Element.ALIGN_LEFT);
                cell.setColspan(1);
                table.addCell(cell);
          }
          
          document.add(table);
          document.add(Chunk.NEWLINE); 
          document.add(Chunk.NEWLINE); 
          document.add(Chunk.NEWLINE); 
          document.add(Chunk.NEWLINE);
          
          document.add(new Paragraph("                  __________________________                 __________________________"));
          document.add(new Paragraph("                                      Firma                                      Nombre y firma del revisor"));
          document.add(new Paragraph("                                "+ userTmp.getPerson().getFirstName() + " " + userTmp.getPerson().getLastName()));
        
        }
        catch(Exception e){
            System.out.print("Error 1: " + e.getMessage());
        }
        
        document.close();
        FacesContext context = FacesContext.getCurrentInstance();
        Object response = context.getExternalContext().getResponse();
        if(response instanceof HttpServletResponse)
        {
            HttpServletResponse hrs = (HttpServletResponse) response;
            hrs.setContentType("application/pdf");
            hrs.setHeader("Content-disposition", "attachment");
            hrs.setContentLength(baos.size());
            try
            {
                ServletOutputStream out = hrs.getOutputStream();
                baos.writeTo(out);
                out.flush();
                
            }
            catch(IOException e){
                System.out.print("Error 2: " + e.getMessage());
            }
            context.responseComplete();
        }
        
    }
    /**
     * Clean add new stable small box entry form.
     */
    public void cleanForm() {
        try {
            getStableSmallBox().setTotalSmallBox(getController().getTotalInBox(getLoggedUser().getLocation().getId()));
            getStableSmallBox().setTotalCoin(BigDecimal.ZERO);
            getStableSmallBox().setTotalBankNote(BigDecimal.ZERO);
            getStableSmallBox().setTotalEnvelope(BigDecimal.ZERO);
            getStableSmallBox().setCreatedOn(new Date());
            getStableSmallBox().setTotalStable(BigDecimal.ZERO);
            getStableSmallBox().setTotalTransfer(BigDecimal.ZERO);
            getStableSmallBox().setDescription(null);
        } catch (Exception e) {
            logger.error("cleanForm", e);
            showMessage(FacesMessage.SEVERITY_ERROR,
                    getBundlePropertyFile().getString("stable.small.box"),
                    getBundlePropertyFile().getString("stable.small.box.clean.form.error"));
        }
    }

    /**
     *
     */
    public void calculateDifference() {
        try {
            getStableSmallBox().setTotalStable(getStableSmallBox().getTotalCoin()
                    .add(getStableSmallBox().getTotalBankNote())
                    .add(getStableSmallBox().getTotalEnvelope())
                    .subtract(getStableSmallBox().getTotalSmallBox()));
        } catch (Exception e) {
            logger.error("calculateDifference", e);
            showMessage(FacesMessage.SEVERITY_ERROR,
                    getBundlePropertyFile().getString("stable.small.box"),
                    getBundlePropertyFile().getString("stable.small.box.calculate.difference.error"));
        }
    }

    /**
     * Update stable small box list between start date and end date.
     */
    public void updateHistoryStableSmallBoxList() {
        logger.info("updateHistoryStableSmallBoxList");
        try {
            if (getStartDate().after(getEndDate())) {
                showMessage(FacesMessage.SEVERITY_ERROR,
                        getBundlePropertyFile().getString("stable.small.box"),
                        getBundlePropertyFile().getString("start.date.after.error"));
            } else {
                setUpDates(false);
                setHistoryStableSmallBox(
                        getController().findStableSmallBoxBetweenDates(
                                getStartDate(),
                                getEndDate(),
                                getLoggedUser().getLocation().getId()
                        )
                );
            }
        } catch (Exception e) {
            logger.error("updateHistoryStableSmallBoxList", 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("addRow");
        try {

                    getStableSmallBox().setId(UUID.randomUUID().toString());
                    getStableSmallBox().setActiveStatus(BasicType.ENEBLED);
                    getStableSmallBox().setCreatedBy(getLoggedUser());
                    getStableSmallBox().setCreatedOn(new Timestamp(new Date().getTime()));
                    getStableSmallBox().setTotalStable(getStableSmallBox().getTotalBankNote().add(getStableSmallBox().getTotalCoin()).add(getStableSmallBox().getTotalEnvelope()));
                    getStableSmallBox().setLocation(getLoggedUser().getLocation());
                    getStableSmallBox().setTotalTransfer(BigDecimal.ZERO);
                    
                    if (getController().saveStableSmallBox(getStableSmallBox())) {

                        if (isUserInRoleBeanInBackground("admin.stable.small.box.name")
                                || isUserInRoleBeanInBackground("admin.stable.small.box.delete")) {
                            setUpDates(false);
                            setHistoryStableSmallBox(
                                    getController().findStableSmallBoxBetweenDates(
                                            getStartDate(),
                                            getEndDate(),
                                            getLoggedUser().getLocation().getId()
                                    )
                            );
                        }

                        showMessage(FacesMessage.SEVERITY_INFO,
                                getBundlePropertyFile().getString("stable.small.box"),
                                getBundlePropertyFile().getString("stable.small.box.add.success.desc"));
                        
                        try
                            {
                            SendMSN msn = new SendMSN("Mutual - Caja chica - "+getLoggedUser().getLocation().getName() +" - "
                                    + "Por entregar: $" + currencyFormatNumber(getStableSmallBox().getTotalStable()) + ", entregado: $" + 
                                    currencyFormatNumber(getStableSmallBox().getTotalSmallBox()), 
                                    SendMSN.getNumberPhoneFormat("3314666450"));
                            msn.sendMessage();
                            }catch(Exception e)
                            {
                                logger.error(e.getMessage());
                                showMessage(FacesMessage.SEVERITY_ERROR,
                                "Error en notificación",
                                "No fue posible enviar el mensaje al receptor, contacta al administrador.");
                            }
                        
                        initStableSmallBoxObject();
                    } else {
                        logger.error("Stable small box couldnot saved");
                        showMessage(FacesMessage.SEVERITY_ERROR,
                                getBundlePropertyFile().getString("stable.small.box"),
                                getBundlePropertyFile().getString("stable.small.box.add.exception.desc"));
                    }

        } catch (Exception e) {
            logger.error("addRow", e);
            showMessage(FacesMessage.SEVERITY_FATAL,
                    getBundlePropertyFile().getString("stable.small.box"),
                    getBundlePropertyFile().getString("stable.small.box.add.exception.desc"));
        }
    }

    @Override
    public void deleteRow() {
        logger.info("deleteRow");
        try {
            if (getController().existNextPaidStableSmallBoxByCreatedOn(getSelectedRow().getCreatedOn(), getLoggedUser().getLocation().getId())) {
                showMessage(FacesMessage.SEVERITY_WARN,
                        getBundlePropertyFile().getString("stable.small.box"),
                        getBundlePropertyFile().getString("stable.small.box.delete.not.allow.desc"));
            } else {
                
                    if (getController().updateStableSmallBoxById(getSelectedRow().getId(), BasicType.DISABLED, getLoggedUser())) {
                        
                        if (null == getCommentsBitacora() || getCommentsBitacora().trim().equals("")) {
                            setCommentsBitacora("El usuario " + getLoggedUser().getUserName() + " no agrego comentarios a la hora de borrar este corte caja chica");
                        }

                        String actionBitacora = "Eliminar corte caja chica";
                        String descBitacora = "Se eliminó el corte de caja chica con total en caja " + currencyFormatNumber(getSelectedRow().getTotalSmallBox())
                                + ", total sobre " + currencyFormatNumber(getSelectedRow().getTotalEnvelope())
                                + ", total monedas " + currencyFormatNumber(getSelectedRow().getTotalCoin())
                                + ", total efectivo " + currencyFormatNumber(getSelectedRow().getTotalBankNote())
                                + ", diferencia de " + currencyFormatNumber(getSelectedRow().getTotalSmallBox().subtract(getSelectedRow().getTotalEnvelope()).subtract(getSelectedRow().getTotalCoin()).subtract(getSelectedRow().getTotalBankNote()))
                                + " y fecha " + getSelectedRow().getCreatedOn();

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

                        setSelectedRow(null);

                        showMessage(FacesMessage.SEVERITY_INFO,
                                getBundlePropertyFile().getString("stable.small.box"),
                                getBundlePropertyFile().getString("stable.small.box.delete.success.desc"));
                    } else {
                        showMessage(FacesMessage.SEVERITY_ERROR,
                                getBundlePropertyFile().getString("stable.small.box"),
                                getBundlePropertyFile().getString("stable.small.box.delete.exception.desc"));
                    }
                
            }
        } catch (Exception e) {
            logger.error("deleteRow", e);
            showMessage(FacesMessage.SEVERITY_FATAL,
                    getBundlePropertyFile().getString("stable.small.box"),
                    getBundlePropertyFile().getString("stable.small.box.delete.exception.desc"));
        }
    }

    /**
     * Setup start date and end date.
     *
     * @param init True if comes from @PostConstruct otherwise false.
     */
    private void setUpDates(boolean init) {
        Calendar startCalendar = Calendar.getInstance();
        Calendar endCalendar = Calendar.getInstance();

        if (!init) {
            startCalendar.setTime(getStartDate());
            endCalendar.setTime(getEndDate());
        } else {
            startCalendar.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
            endCalendar.setTime(new Date());
        }

        startCalendar.add(Calendar.HOUR_OF_DAY, 2);
        startCalendar.add(Calendar.MINUTE, 0);
        startCalendar.add(Calendar.SECOND, 0);
        startCalendar.add(Calendar.MILLISECOND, 0);

        endCalendar.add(Calendar.HOUR_OF_DAY, 22);
        endCalendar.add(Calendar.MINUTE, 59);
        endCalendar.add(Calendar.SECOND, 59);
        endCalendar.add(Calendar.MILLISECOND, 0);

        setStartDate(startCalendar.getTime());
        setEndDate(endCalendar.getTime());
    }

    /**
     *
     */
    private void initStableSmallBoxObject() {
        logger.info("initStableSmallBoxObject");
        try {
            setStableSmallBox(new MutualStableSmallBox());

            getStableSmallBox().setTotalSmallBox(getController().getTotalInBox(getLoggedUser().getLocation().getId()));
            getStableSmallBox().setTotalCoin(BigDecimal.ZERO);
            getStableSmallBox().setTotalBankNote(BigDecimal.ZERO);
            getStableSmallBox().setTotalEnvelope(BigDecimal.ZERO);
            getStableSmallBox().setTotalStable(BigDecimal.ZERO.subtract(getStableSmallBox().getTotalSmallBox()));
            getStableSmallBox().setTotalTransfer(getController().getTotalInTransferBox(getLoggedUser().getLocation().getId()));
            getStableSmallBox().setCreatedOn(new Date());
        } catch (Exception e) {
            logger.error("initStableSmallBoxObject", e);
        }
    }

    @PostConstruct
    public void init() {
        logger.info("init");
        try {
            loadBundlePropertyFile();

            setController(new MutualStableSmallBoxController());
            setClosingController(new MutualClosingDayController());
            setBitacoraController(new BitacoraController());
            setCreatedOn(new Date());
            setClosings(getClosingController().findMutualClosingDailyCurdate(getLoggedUser().getLocation().getId()));
            setGenericController(new GenericValidationController());
            setLastStableGeneralBox(getGenericController().lastStableGeneralBoxByDate(getLoggedUser()));
            setHayCuadre(getGenericController().existStableGeneralBoxByCurdate(getLoggedUser()));

            if (isUserInRoleBeanInBackground("admin.stable.small.box.add")) {
                initStableSmallBoxObject();
            }

            if (isUserInRoleBeanInBackground("admin.stable.small.box.name")
                    || isUserInRoleBeanInBackground("admin.stable.small.box.delete")) {
                setUpDates(true);
                setHistoryStableSmallBox(
                        getController().findStableSmallBoxBetweenDates(
                                getStartDate(),
                                getEndDate(),
                                getLoggedUser().getLocation().getId()
                        )
                );
            }
        } catch (Exception e) {
            logger.error(e);
        }
    }

    private MutualStableSmallBoxController controller;
    private MutualClosingDayController closingController;
    private List<MutualStableSmallBox> historyStableSmallBox;
    private List<MutualClosingDay> closings;
    private MutualStableSmallBox selectedRow;
    private Date startDate;
    private Date endDate;
    private Date createdOn;
    private MutualStableSmallBox stableSmallBox;
    private BigDecimal zero;
    private BitacoraController bitacoraController;
    private String commentsBitacora;
    private GenericValidationController genericController;
    private Date lastStableGeneralBox;
    private boolean hayCuadre;
    
    private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd");

    public GenericValidationController getGenericController() {
        return genericController;
    }

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

    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<MutualClosingDay> getClosings() {
        return closings;
    }

    public void setClosings(List<MutualClosingDay> closings) {
        this.closings = closings;
    }

    public MutualClosingDayController getClosingController() {
        return closingController;
    }

    public void setClosingController(MutualClosingDayController closingController) {
        this.closingController = closingController;
    }

    public MutualStableSmallBoxController getController() {
        return controller;
    }

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

    public List<MutualStableSmallBox> getHistoryStableSmallBox() {
        return historyStableSmallBox;
    }

    public void setHistoryStableSmallBox(List<MutualStableSmallBox> historyStableSmallBox) {
        this.historyStableSmallBox = historyStableSmallBox;
    }

    public MutualStableSmallBox getSelectedRow() {
        return selectedRow;
    }

    public void setSelectedRow(MutualStableSmallBox selectedRow) {
        this.selectedRow = selectedRow;
    }

    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 Date getCreatedOn() {
        return createdOn;
    }

    public void setCreatedOn(Date createdOn) {
        this.createdOn = createdOn;
    }

    public MutualStableSmallBox getStableSmallBox() {
        return stableSmallBox;
    }

    public void setStableSmallBox(MutualStableSmallBox stableSmallBox) {
        this.stableSmallBox = stableSmallBox;
    }

    public BigDecimal getZero() {
        if (null == zero) {
            zero = BigDecimal.ZERO;
        }
        return zero;
    }

    public void setZero(BigDecimal zero) {
        this.zero = zero;
    }

    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;
    }

    private static final long serialVersionUID = 7328275333340376725L;
    final Logger logger = LogManager.getLogger(MutualStableSmallBoxBean.class);

}
