/*
 * 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.model.views;

import com.arrebol.apc.model.enums.ActiveStatus;
import java.io.Serializable;
import java.math.BigDecimal;
import java.math.MathContext;
import java.util.Calendar;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;
import org.hibernate.annotations.Immutable;

/**
 *
 * @author Oscar Armando Vargas Cardenas <oscar.vargas@arrebol.com.mx>
 */
@Entity
@Immutable
@Table(name = "APC_INFORMATION_LOAN_WEEK_VIEW")
public class InformationLoanWeekView implements Serializable {

    private static final long serialVersionUID = -6384789811291615117L;

    @Id
    @Column(name = "id", length = 36)
    private String id;

    @Column(name = "id_office")
    private String idOffice;

    @Column(name = "loan_type_name")
    private String loanTypeName;

    @Column(name = "id_user")
    private String idUser;

    @Column(name = "estatus_prestamo")
    private String estatusPrestamo;

    @Column(name = "fecha")
    private Date fecha;

    @Column(name = "apoyos")
    private BigDecimal apoyos;

    @Column(name = "apoyos_total")
    private BigDecimal apoyosTotal;

    @Column(name = "comision_apertura")
    private BigDecimal comisionApertura;

    @Column(name = "aval")
    private String aval;

    @Column(name = "customer")
    private String customer;

    @Column(name = "documento_por")
    private BigDecimal documentoPor;

    @Column(name = "abono_diario")
    private BigDecimal abonoDiario;

    @Column(name = "amount_paid")
    private BigDecimal amountPaid;

    @Column(name = "saldo_insoluto")
    private BigDecimal saldoInsoluto;

    @Column(name = "route_name")
    private String routeName;

    @Column(name = "asesor")
    private String asesor;

    @Column(name = "num_fee")
    private int numFee;

    @Column(name = "payment_monday")
    private BigDecimal paymentMonday;

    @Column(name = "fee_monday")
    private BigDecimal feeMonday;

    @Column(name = "payment_tuesday")
    private BigDecimal paymentTuesday;

    @Column(name = "fee_tuesday")
    private BigDecimal feeTuesday;

    @Column(name = "payment_wednesday")
    private BigDecimal paymentWednesday;

    @Column(name = "fee_wednesday")
    private BigDecimal feeWednesday;

    @Column(name = "payment_thursday")
    private BigDecimal paymentThursday;

    @Column(name = "fee_thursday")
    private BigDecimal feeThursday;

    @Column(name = "payment_friday")
    private BigDecimal paymentFriday;

    @Column(name = "fee_friday")
    private BigDecimal feeFriday;

    @Column(name = "payment_saturday")
    private BigDecimal paymentSaturday;

    @Column(name = "fee_saturday")
    private BigDecimal feeSaturday;

    @Column(name = "faltante")
    private BigDecimal faltante;

    @Column(name = "new_customer")
    private String newCustomer;

    @Column(name = "renovation")
    private String renovation;

    @Column(name = "num_pagos_all")
    private BigDecimal numPagosAll;

    @Column(name = "num_pagos_week")
    private BigDecimal numPagosWeek;

    @Column(name = "fee_todos")
    private BigDecimal feeTodos;

    @Enumerated(EnumType.STRING)
    @Column(name = "frozen")
    private ActiveStatus frozen;

    @Transient
    private BigDecimal totalPaid;

    @Transient
    private BigDecimal numPagosLoanType;

    @Transient
    private String movimientosMonday;

    @Transient
    private String movimientosTuesday;

    @Transient
    private String movimientosWednesday;

    @Transient
    private String movimientosThursday;

    @Transient
    private String movimientosFriday;

    @Transient
    private String movimientosSaturday;

    @Transient
    private String renovationMonday;

    @Transient
    private String renovationTuesday;

    @Transient
    private String renovationWednesday;

    @Transient
    private String renovationThursday;

    @Transient
    private String renovationFriday;

    @Transient
    private String renovationSaturday;

    @Transient
    private String reactivation;

    @Transient
    private String weekOfCreation;

    private BigDecimal faltanteHistorico;

    private BigDecimal recuperado;

    private BigDecimal faltanteSemana;

    private BigDecimal feeSemana;

    public ActiveStatus getFrozen() {
        if (frozen == null) {
            frozen = ActiveStatus.DISABLED;
        }
        return frozen;
    }

    public void setFrozen(ActiveStatus frozen) {
        this.frozen = frozen;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getLoanTypeName() {
        return loanTypeName;
    }

    public void setLoanTypeName(String loanTypeName) {
        this.loanTypeName = loanTypeName;
    }

    public String getEstatusPrestamo() {
        return estatusPrestamo;
    }

    public void setEstatusPrestamo(String estatusPrestamo) {
        this.estatusPrestamo = estatusPrestamo;
    }

    public String getIdOffice() {
        return idOffice;
    }

    public void setIdOffice(String idOffice) {
        this.idOffice = idOffice;
    }

    public String getIdUser() {
        return idUser;
    }

    public void setIdUser(String idUser) {
        this.idUser = idUser;
    }

    public Date getFecha() {
        return fecha;
    }

    public void setFecha(Date fecha) {
        this.fecha = fecha;
    }

    public BigDecimal getApoyos() {
        return apoyos;
    }

    public void setApoyos(BigDecimal apoyos) {
        this.apoyos = apoyos;
    }

    public BigDecimal getApoyosTotal() {
        return apoyosTotal;
    }

    public void setApoyosTotal(BigDecimal apoyosTotal) {
        this.apoyosTotal = apoyosTotal;
    }

    public BigDecimal getComisionApertura() {
        return comisionApertura;
    }

    public void setComisionApertura(BigDecimal comisionApertura) {
        this.comisionApertura = comisionApertura;
    }

    public String getAval() {
        return aval;
    }

    public void setAval(String aval) {
        this.aval = aval;
    }

    public String getCustomer() {
        return customer;
    }

    public void setCustomer(String customer) {
        this.customer = customer;
    }

    public BigDecimal getDocumentoPor() {
        return documentoPor;
    }

    public void setDocumentoPor(BigDecimal documentoPor) {
        this.documentoPor = documentoPor;
    }

    public BigDecimal getAbonoDiario() {
        return abonoDiario;
    }

    public void setAbonoDiario(BigDecimal abonoDiario) {
        this.abonoDiario = abonoDiario;
    }

    public BigDecimal getAmountPaid() {
        return amountPaid;
    }

    public void setAmountPaid(BigDecimal amountPaid) {
        this.amountPaid = amountPaid;
    }

    public BigDecimal getSaldoInsoluto() {
        return saldoInsoluto;
    }

    public void setSaldoInsoluto(BigDecimal saldoInsoluto) {
        this.saldoInsoluto = saldoInsoluto;
    }

    public String getRouteName() {
        return routeName;
    }

    public void setRouteName(String routeName) {
        this.routeName = routeName;
    }

    public String getAsesor() {
        return asesor;
    }

    public void setAsesor(String asesor) {
        this.asesor = asesor;
    }

    public int getNumFee() {
        return numFee;
    }

    public void setNumFee(int numFee) {
        this.numFee = numFee;
    }

    public BigDecimal getPaymentMonday() {
        return paymentMonday;
    }

    public void setPaymentMonday(BigDecimal paymentMonday) {
        this.paymentMonday = paymentMonday;
    }

    public BigDecimal getFeeMonday() {
        return feeMonday;
    }

    public void setFeeMonday(BigDecimal feeMonday) {
        this.feeMonday = feeMonday;
    }

    public BigDecimal getPaymentTuesday() {
        return paymentTuesday;
    }

    public void setPaymentTuesday(BigDecimal paymentTuesday) {
        this.paymentTuesday = paymentTuesday;
    }

    public BigDecimal getFeeTuesday() {
        return feeTuesday;
    }

    public void setFeeTuesday(BigDecimal feeTuesday) {
        this.feeTuesday = feeTuesday;
    }

    public BigDecimal getPaymentWednesday() {
        return paymentWednesday;
    }

    public void setPaymentWednesday(BigDecimal paymentWednesday) {
        this.paymentWednesday = paymentWednesday;
    }

    public BigDecimal getFeeWednesday() {
        return feeWednesday;
    }

    public void setFeeWednesday(BigDecimal feeWednesday) {
        this.feeWednesday = feeWednesday;
    }

    public BigDecimal getPaymentThursday() {
        return paymentThursday;
    }

    public void setPaymentThursday(BigDecimal paymentThursday) {
        this.paymentThursday = paymentThursday;
    }

    public BigDecimal getFeeThursday() {
        return feeThursday;
    }

    public void setFeeThursday(BigDecimal feeThursday) {
        this.feeThursday = feeThursday;
    }

    public BigDecimal getPaymentFriday() {
        return paymentFriday;
    }

    public void setPaymentFriday(BigDecimal paymentFriday) {
        this.paymentFriday = paymentFriday;
    }

    public BigDecimal getFeeFriday() {
        return feeFriday;
    }

    public void setFeeFriday(BigDecimal feeFriday) {
        this.feeFriday = feeFriday;
    }

    public BigDecimal getPaymentSaturday() {
        return paymentSaturday;
    }

    public void setPaymentSaturday(BigDecimal paymentSaturday) {
        this.paymentSaturday = paymentSaturday;
    }

    public BigDecimal getFeeSaturday() {
        return feeSaturday;
    }

    public void setFeeSaturday(BigDecimal feeSaturday) {
        this.feeSaturday = feeSaturday;
    }

    public BigDecimal getNumPagosAll() {
        return numPagosAll;
    }

    public void setNumPagosAll(BigDecimal numPagosAll) {
        this.numPagosAll = numPagosAll;
    }

    public BigDecimal getNumPagosWeek() {
        return numPagosWeek;
    }

    public void setNumPagosWeek(BigDecimal numPagosWeek) {
        this.numPagosWeek = numPagosWeek;
    }

    public BigDecimal getFeeTodos() {
        return feeTodos;
    }

    public void setFeeTodos(BigDecimal feeTodos) {
        this.feeTodos = feeTodos;
    }

    public BigDecimal getTotalPaid() {
        return totalPaid;
    }

    public void setTotalPaid(BigDecimal totalPaid) {
        this.totalPaid = totalPaid;
    }

    public BigDecimal getNumPagosLoanType() {
        return numPagosLoanType;
    }

    public void setNumPagosLoanType(BigDecimal numPagosLoanType) {
        this.numPagosLoanType = numPagosLoanType;
    }

    public BigDecimal getFaltante() {

         //if(id.equals("f911ef4c-b6f2-4ecf-91b6-3d6d6bcf9faa")){
        BigDecimal montoPagadoTotalEsperado = (numPagosAll.subtract(numPagosWeek)).multiply(abonoDiario);

        if (numPagosAll.subtract(numPagosWeek).compareTo(numPagosLoanType) >= 0) {

            montoPagadoTotalEsperado = (numPagosLoanType).multiply(abonoDiario);
        }

        BigDecimal montoPagadoSemana = paymentFriday.add(paymentMonday).add(paymentSaturday).add(paymentThursday).add(paymentTuesday).add(paymentWednesday);

        BigDecimal montoPagadoTotalPasado = totalPaid.subtract(montoPagadoSemana);

        BigDecimal faltanteAcomulado = (montoPagadoTotalEsperado.add(feeTodos)).subtract(montoPagadoTotalPasado);
        
        BigDecimal faltanteSemanaCalculo = getFaltanteSemana();
        
        BigDecimal recuperadoSemana = getRecuperado();

        BigDecimal montoEsperadoSemana = numPagosWeek.multiply(abonoDiario);

        BigDecimal feeSemana = feeFriday.add(feeMonday).add(feeSaturday).add(feeThursday).add(feeTuesday).add(feeWednesday);

        //montoPagadoTotalEsperado.add(feeSemana).add(feeTodos);
        //RN1
        //Si el pago esperado por semana es igual al total de abonos en la semana, entonces faltante 0
        if (montoPagadoSemana.compareTo(montoEsperadoSemana) == 0) {
            return BigDecimal.ZERO;
        }

        // RN4
        /*if(renovation.equalsIgnoreCase("Si") && faltante.compareTo(BigDecimal.ZERO) > 0){
            return BigDecimal.ZERO;
        }*/
        if (renovationMonday.equalsIgnoreCase("Si") || renovationTuesday.equalsIgnoreCase("Si")
                || renovationThursday.equalsIgnoreCase("Si") || renovationWednesday.equalsIgnoreCase("Si")
                || renovationFriday.equalsIgnoreCase("Si") || renovationSaturday.equalsIgnoreCase("Si")) {

            if (faltanteAcomulado.compareTo(BigDecimal.ZERO) <= 0) {
                return BigDecimal.ZERO;
            }

            return faltanteAcomulado.negate();
        }

        // RN5
        // if (numPagosAll.compareTo(BigDecimal.valueOf(22)) > 0 && faltante.compareTo(BigDecimal.ZERO) > 0) {
        //   return BigDecimal.ZERO;
        //}
        // RN6
        if (loanTypeName.toLowerCase().contains("con") || loanTypeName.toLowerCase().contains("conv")
                || loanTypeName.toLowerCase().contains("conve") || loanTypeName.toLowerCase().contains("convenio")) {
            return BigDecimal.ZERO;
        }

        //RN7
        if (getFrozen().equals(ActiveStatus.ENEBLED)) {
            return BigDecimal.ZERO;
        }

        if (numPagosAll.compareTo(BigDecimal.valueOf(22)) > 0) {

            return montoPagadoSemana.negate();

        }

        //RN2
        //Si el total de abonos por semana es menor al total de abonos esperado, entonces se muestra la diferencia
        if (montoPagadoSemana.compareTo(montoEsperadoSemana) < 0) {
            if (faltanteAcomulado.compareTo(BigDecimal.ZERO) < 0) {

                faltanteAcomulado = faltanteAcomulado.negate();

                switch ((faltanteAcomulado).compareTo(faltanteSemanaCalculo)) {
                    case (-1):
                        return montoEsperadoSemana.subtract(montoPagadoSemana).subtract(faltanteAcomulado);
                    case (0):
                        return BigDecimal.ZERO;
                    case (1):
                        return BigDecimal.ZERO;
                }

            }

            return montoEsperadoSemana.subtract(montoPagadoSemana);

        }

        //RN3
        //Si el total de abonos por semana es mayor al total de abonos esperado, 
        if (montoPagadoSemana.compareTo(montoEsperadoSemana) > 0) {
            if (faltanteAcomulado.compareTo(BigDecimal.ZERO) < 0) {
                return BigDecimal.ZERO;
            }

            if (faltanteAcomulado.compareTo(BigDecimal.ZERO) > 0) {
                if (faltanteAcomulado.compareTo((recuperadoSemana)) == 0) {

                    return faltanteAcomulado.negate();
                }
                if (faltanteAcomulado.compareTo(recuperadoSemana) > 0) {
                    return montoPagadoSemana.subtract(montoEsperadoSemana).negate();
                }
                if (faltanteAcomulado.compareTo(recuperadoSemana) < 0) {

                    if ((feeSemana).compareTo(BigDecimal.ZERO) == 0) {
                        return faltanteAcomulado.negate();
                    }

                    switch ((faltanteAcomulado.add(feeSemana)).compareTo((recuperadoSemana))) {
                        case (-1):
                            return (feeSemana.add(faltanteAcomulado)).negate();
                        case (0):
                            return BigDecimal.ZERO;
                        case (1):
                            return (montoPagadoSemana.subtract(montoEsperadoSemana)).negate();
                    }

                }
            }
        }
        //return faltante;
        //}

        return BigDecimal.ZERO;
    }

    public void setFaltante(BigDecimal faltante) {
        this.faltante = faltante;
    }

    public BigDecimal getFaltanteHistorico() {
        BigDecimal montoPagadoTotalEsperado = (numPagosAll.subtract(numPagosWeek)).multiply(abonoDiario);

        if (numPagosAll.subtract(numPagosWeek).compareTo(numPagosLoanType) >= 0) {

            montoPagadoTotalEsperado = (numPagosLoanType).multiply(abonoDiario);
        }
        BigDecimal montoPagadoSemana = paymentFriday.add(paymentMonday).add(paymentSaturday).add(paymentThursday).add(paymentTuesday).add(paymentWednesday);
        BigDecimal montoPagadoTotal = totalPaid;
        BigDecimal montoPagadoTotalPasado = montoPagadoTotal.subtract(montoPagadoSemana);

        return montoPagadoTotalEsperado.add(feeTodos).subtract(montoPagadoTotalPasado);
    }

    public void setFaltanteHistorico(BigDecimal faltanteHistorico) {
        this.faltanteHistorico = faltanteHistorico;
    }

    public BigDecimal getRecuperado() {
        BigDecimal recuperadoSemanaPorDia = BigDecimal.ZERO;

        //if(id.equals("4177c7d0-46ee-4862-aa5f-d0526798cc41")){
        if ((numPagosAll.subtract(numPagosWeek)).compareTo(BigDecimal.valueOf(22)) >= 0) {

            return paymentMonday.add(paymentThursday).add(paymentWednesday).add(paymentTuesday).add(paymentFriday).add(paymentSaturday);

        }

        /*if(getFaltanteHistorico().compareTo(BigDecimal.ZERO)<0)
        {
            return BigDecimal.ZERO;
        }*/
        if (renovationMonday.equalsIgnoreCase("Si")) {
            return recuperadoSemanaPorDia;

        }

        if (movimientosMonday.equalsIgnoreCase("Si")) {
            recuperadoSemanaPorDia = ((paymentMonday.subtract(abonoDiario).compareTo(BigDecimal.ZERO)) > 0) ? recuperadoSemanaPorDia.add(paymentMonday.subtract(abonoDiario)) : recuperadoSemanaPorDia;
        }

        if (renovationTuesday.equalsIgnoreCase("Si")) {
            return recuperadoSemanaPorDia;

        }

        if (movimientosTuesday.equalsIgnoreCase("Si")) {
            recuperadoSemanaPorDia = ((paymentTuesday.subtract(abonoDiario).compareTo(BigDecimal.ZERO)) > 0) ? recuperadoSemanaPorDia.add(paymentTuesday.subtract(abonoDiario)) : recuperadoSemanaPorDia;
        }

        if (renovationWednesday.equalsIgnoreCase("Si")) {
            return recuperadoSemanaPorDia;

        }
        if (movimientosWednesday.equalsIgnoreCase("Si")) {
            recuperadoSemanaPorDia = ((paymentWednesday.subtract(abonoDiario).compareTo(BigDecimal.ZERO)) > 0) ? recuperadoSemanaPorDia.add(paymentWednesday.subtract(abonoDiario)) : recuperadoSemanaPorDia;

        }

        if (renovationThursday.equalsIgnoreCase("Si")) {
            return recuperadoSemanaPorDia;

        }

        if (movimientosThursday.equalsIgnoreCase("Si")) {
            recuperadoSemanaPorDia = ((paymentThursday.subtract(abonoDiario).compareTo(BigDecimal.ZERO)) > 0) ? recuperadoSemanaPorDia.add(paymentThursday.subtract(abonoDiario)) : recuperadoSemanaPorDia;

        }

        if (renovationFriday.equalsIgnoreCase("Si")) {
            return recuperadoSemanaPorDia;

        }

        if (movimientosFriday.equalsIgnoreCase("Si")) {
            recuperadoSemanaPorDia = ((paymentFriday.subtract(abonoDiario).compareTo(BigDecimal.ZERO)) > 0) ? recuperadoSemanaPorDia.add(paymentFriday.subtract(abonoDiario)) : recuperadoSemanaPorDia;

        }

        if (renovationSaturday.equalsIgnoreCase("Si")) {
            return recuperadoSemanaPorDia;

        }

        if (movimientosSaturday.equalsIgnoreCase("Si")) {
            recuperadoSemanaPorDia = ((paymentSaturday.subtract(abonoDiario).compareTo(BigDecimal.ZERO)) > 0) ? recuperadoSemanaPorDia.add(paymentSaturday.subtract(abonoDiario)) : recuperadoSemanaPorDia;

        }
        //}

        BigDecimal faltanteTotal = getFaltanteHistorico().add(getFaltanteSemana());

        if (faltanteTotal.compareTo(BigDecimal.ZERO) > 0) {

            switch (recuperadoSemanaPorDia.compareTo(faltanteTotal)) {
                case (-1):
                    return recuperadoSemanaPorDia;
                case (0):
                    return recuperadoSemanaPorDia;
                case (1):
                    return faltanteTotal;

            }
        } else {
            return BigDecimal.ZERO;
        }

        return recuperadoSemanaPorDia;

    }

    public void setRecuperado(BigDecimal recuperado) {
        this.recuperado = recuperado;
    }

    public BigDecimal getFaltanteSemana() {
        getId();

        BigDecimal faltanteSemanaPorDia = BigDecimal.ZERO;
        //if(id.equals("93ad8123-9b0d-4087-a85b-3216af2bacbf")){

        if ((numPagosAll.subtract(numPagosWeek)).compareTo(BigDecimal.valueOf(22)) >= 0) {

            return faltanteSemanaPorDia;

        }

        if (renovationMonday.equalsIgnoreCase("Si")) {
            return faltanteSemanaPorDia;

        }
        if ((numPagosAll.subtract(numPagosWeek).add(BigDecimal.valueOf(1))).compareTo(BigDecimal.valueOf(22)) <= 0) {
            if (movimientosMonday.equalsIgnoreCase("Si")) {

                if (feeMonday.compareTo(BigDecimal.ZERO) > 0) {
                    faltanteSemanaPorDia = ((abonoDiario.subtract(paymentMonday).compareTo(BigDecimal.ZERO)) > 0) ? faltanteSemanaPorDia.add(abonoDiario.subtract(paymentMonday)) : faltanteSemanaPorDia;

                } else if (paymentMonday.compareTo(BigDecimal.ZERO) == 0) {

                } else {
                    faltanteSemanaPorDia = ((abonoDiario.subtract(paymentMonday).compareTo(BigDecimal.ZERO)) > 0) ? faltanteSemanaPorDia.add(abonoDiario.subtract(paymentMonday)) : faltanteSemanaPorDia;
                }

            }
        }

        if (renovationTuesday.equalsIgnoreCase("Si")) {
            return faltanteSemanaPorDia;

        }

        if ((numPagosAll.subtract(numPagosWeek).add(BigDecimal.valueOf(2))).compareTo(BigDecimal.valueOf(22)) <= 0) {
            if (movimientosTuesday.equalsIgnoreCase("Si")) {

                if (feeTuesday.compareTo(BigDecimal.ZERO) > 0) {
                    faltanteSemanaPorDia = ((abonoDiario.subtract(paymentTuesday).compareTo(BigDecimal.ZERO)) > 0) ? faltanteSemanaPorDia.add(abonoDiario.subtract(paymentTuesday)) : faltanteSemanaPorDia;

                } else if (paymentTuesday.compareTo(BigDecimal.ZERO) == 0) {

                } else {
                    faltanteSemanaPorDia = ((abonoDiario.subtract(paymentTuesday).compareTo(BigDecimal.ZERO)) > 0) ? faltanteSemanaPorDia.add(abonoDiario.subtract(paymentTuesday)) : faltanteSemanaPorDia;
                }

            }
        }

        if (renovationWednesday.equalsIgnoreCase("Si")) {
            return faltanteSemanaPorDia;

        }
        if ((numPagosAll.subtract(numPagosWeek).add(BigDecimal.valueOf(3))).compareTo(BigDecimal.valueOf(22)) <= 0) {
            if (movimientosWednesday.equalsIgnoreCase("Si")) {

                if (feeWednesday.compareTo(BigDecimal.ZERO) > 0) {
                    faltanteSemanaPorDia = ((abonoDiario.subtract(paymentWednesday).compareTo(BigDecimal.ZERO)) > 0) ? faltanteSemanaPorDia.add(abonoDiario.subtract(paymentWednesday)) : faltanteSemanaPorDia;

                } else if (paymentWednesday.compareTo(BigDecimal.ZERO) == 0) {

                } else {
                    faltanteSemanaPorDia = ((abonoDiario.subtract(paymentWednesday).compareTo(BigDecimal.ZERO)) > 0) ? faltanteSemanaPorDia.add(abonoDiario.subtract(paymentWednesday)) : faltanteSemanaPorDia;
                }

            }
        }

        if (renovationThursday.equalsIgnoreCase("Si")) {
            return faltanteSemanaPorDia;

        }
        if ((numPagosAll.subtract(numPagosWeek).add(BigDecimal.valueOf(4))).compareTo(BigDecimal.valueOf(22)) <= 0) {
            if (movimientosThursday.equalsIgnoreCase("Si")) {

                if (feeThursday.compareTo(BigDecimal.ZERO) > 0) {
                    faltanteSemanaPorDia = ((abonoDiario.subtract(paymentThursday).compareTo(BigDecimal.ZERO)) > 0) ? faltanteSemanaPorDia.add(abonoDiario.subtract(paymentThursday)) : faltanteSemanaPorDia;

                } else if (paymentThursday.compareTo(BigDecimal.ZERO) == 0) {

                } else {
                    faltanteSemanaPorDia = ((abonoDiario.subtract(paymentThursday).compareTo(BigDecimal.ZERO)) > 0) ? faltanteSemanaPorDia.add(abonoDiario.subtract(paymentThursday)) : faltanteSemanaPorDia;
                }
            }
        }

        if (renovationFriday.equalsIgnoreCase("Si")) {
            return faltanteSemanaPorDia;

        }
        if ((numPagosAll.subtract(numPagosWeek).add(BigDecimal.valueOf(5))).compareTo(BigDecimal.valueOf(22)) <= 0) {
            if (movimientosFriday.equalsIgnoreCase("Si")) {

                if (feeFriday.compareTo(BigDecimal.ZERO) > 0) {
                    faltanteSemanaPorDia = ((abonoDiario.subtract(paymentFriday).compareTo(BigDecimal.ZERO)) > 0) ? faltanteSemanaPorDia.add(abonoDiario.subtract(paymentFriday)) : faltanteSemanaPorDia;

                } else if (paymentFriday.compareTo(BigDecimal.ZERO) == 0) {

                } else {
                    faltanteSemanaPorDia = ((abonoDiario.subtract(paymentFriday).compareTo(BigDecimal.ZERO)) > 0) ? faltanteSemanaPorDia.add(abonoDiario.subtract(paymentFriday)) : faltanteSemanaPorDia;
                }
            }
        }

        if (renovationSaturday.equalsIgnoreCase("Si")) {
            return faltanteSemanaPorDia;

        }
        if ((numPagosAll.subtract(numPagosWeek).add(BigDecimal.valueOf(6))).compareTo(BigDecimal.valueOf(22)) <= 0) {
            if (movimientosSaturday.equalsIgnoreCase("Si")) {

                if (feeSaturday.compareTo(BigDecimal.ZERO) > 0) {
                    faltanteSemanaPorDia = ((abonoDiario.subtract(paymentSaturday).compareTo(BigDecimal.ZERO)) > 0) ? faltanteSemanaPorDia.add(abonoDiario.subtract(paymentSaturday)) : faltanteSemanaPorDia;

                } else if (paymentSaturday.compareTo(BigDecimal.ZERO) == 0) {

                } else {
                    faltanteSemanaPorDia = ((abonoDiario.subtract(paymentSaturday).compareTo(BigDecimal.ZERO)) > 0) ? faltanteSemanaPorDia.add(abonoDiario.subtract(paymentSaturday)) : faltanteSemanaPorDia;
                }
            }
        }
       // }

        /*
        if(getFaltanteHistorico().compareTo(BigDecimal.ZERO)<0)
        {
            BigDecimal faltanteHistoricoAbsoluto = getFaltanteHistorico().abs();
            switch(faltanteHistoricoAbsoluto.compareTo(faltanteSemanaPorDia)){
                case (-1): return faltanteSemanaPorDia.subtract(faltanteHistoricoAbsoluto);
                case (0): return BigDecimal.ZERO;
                case (1): return BigDecimal.ZERO;
            }
        }*/
        return faltanteSemanaPorDia;
    }

    public void setFaltanteSemana(BigDecimal faltanteSemana) {
        this.faltanteSemana = faltanteSemana;
    }

    public String getNewCustomer() {
        return newCustomer;
    }

    public void setNewCustomer(String newCustomer) {
        this.newCustomer = newCustomer;
    }

    public String getRenovation() {
        return renovation;
    }

    public void setRenovation(String renovation) {
        this.renovation = renovation;
    }

    public String getConditionLunes() {
        if (feeMonday.compareTo(BigDecimal.ZERO) > 0) {
            return "redRow";
        } else if (paymentMonday.compareTo(BigDecimal.ZERO) == 0 && feeMonday.compareTo(BigDecimal.ZERO) == 0) {
            return "greenRow";
        } else if (feeMonday.compareTo(BigDecimal.ZERO) == 0 && paymentMonday.compareTo(BigDecimal.ZERO) > 0 && (paymentMonday.compareTo(abonoDiario) < 0)) {
            return "yellowRow";
        } else if (feeMonday.compareTo(BigDecimal.ZERO) == 0 && paymentMonday.compareTo(BigDecimal.ZERO) > 0 && (paymentMonday.compareTo(abonoDiario) > 0)) {
            return "blueRow";
        } else {
            return null;
        }
    }

    public String getConditionMartes() {
        if (feeTuesday.compareTo(BigDecimal.ZERO) > 0) {
            return "redRow";
        } else if (paymentTuesday.compareTo(BigDecimal.ZERO) == 0 && feeTuesday.compareTo(BigDecimal.ZERO) == 0) {
            return "greenRow";
        } else if (feeTuesday.compareTo(BigDecimal.ZERO) == 0 && paymentTuesday.compareTo(BigDecimal.ZERO) > 0 && (paymentTuesday.compareTo(abonoDiario) < 0)) {
            return "yellowRow";
        } else if (feeTuesday.compareTo(BigDecimal.ZERO) == 0 && paymentTuesday.compareTo(BigDecimal.ZERO) > 0 && (paymentTuesday.compareTo(abonoDiario) > 0)) {
            return "blueRow";
        } else {
            return null;
        }
    }

    public String getConditionMiercoles() {
        if (feeWednesday.compareTo(BigDecimal.ZERO) > 0) {
            return "redRow";
        } else if (paymentWednesday.compareTo(BigDecimal.ZERO) == 0 && feeWednesday.compareTo(BigDecimal.ZERO) == 0) {
            return "greenRow";
        } else if (feeWednesday.compareTo(BigDecimal.ZERO) == 0 && paymentWednesday.compareTo(BigDecimal.ZERO) > 0 && (paymentWednesday.compareTo(abonoDiario) < 0)) {
            return "yellowRow";
        } else if (feeWednesday.compareTo(BigDecimal.ZERO) == 0 && paymentWednesday.compareTo(BigDecimal.ZERO) > 0 && (paymentWednesday.compareTo(abonoDiario) > 0)) {
            return "blueRow";
        } else {
            return null;
        }
    }

    public String getConditionJueves() {
        if (feeThursday.compareTo(BigDecimal.ZERO) > 0) {
            return "redRow";
        } else if (paymentThursday.compareTo(BigDecimal.ZERO) == 0 && feeThursday.compareTo(BigDecimal.ZERO) == 0) {
            return "greenRow";
        } else if (feeThursday.compareTo(BigDecimal.ZERO) == 0 && paymentThursday.compareTo(BigDecimal.ZERO) > 0 && (paymentThursday.compareTo(abonoDiario) < 0)) {
            return "yellowRow";
        } else if (feeThursday.compareTo(BigDecimal.ZERO) == 0 && paymentThursday.compareTo(BigDecimal.ZERO) > 0 && (paymentThursday.compareTo(abonoDiario) > 0)) {
            return "blueRow";
        } else {
            return null;
        }
    }

    public String getConditionViernes() {
        if (feeFriday.compareTo(BigDecimal.ZERO) > 0) {
            return "redRow";
        } else if (paymentFriday.compareTo(BigDecimal.ZERO) == 0 && feeFriday.compareTo(BigDecimal.ZERO) == 0) {
            return "greenRow";
        } else if (feeFriday.compareTo(BigDecimal.ZERO) == 0 && paymentFriday.compareTo(BigDecimal.ZERO) > 0 && (paymentFriday.compareTo(abonoDiario) < 0)) {
            return "yellowRow";
        } else if (feeFriday.compareTo(BigDecimal.ZERO) == 0 && paymentFriday.compareTo(BigDecimal.ZERO) > 0 && (paymentFriday.compareTo(abonoDiario) > 0)) {
            return "blueRow";
        } else if (feeSaturday.compareTo(BigDecimal.ZERO) == 0 && paymentSaturday.compareTo(BigDecimal.ZERO) > 0 && (paymentSaturday.compareTo(abonoDiario) > 0)) {
            return "blueRow";
        } else {
            return null;
        }
    }

    public String getConditionSabado() {
        if (feeSaturday.compareTo(BigDecimal.ZERO) > 0) {
            return "redRow";
        } else if (paymentSaturday.compareTo(BigDecimal.ZERO) == 0 && feeSaturday.compareTo(BigDecimal.ZERO) == 0) {
            return "greenRow";
        } else if (feeSaturday.compareTo(BigDecimal.ZERO) == 0 && paymentSaturday.compareTo(BigDecimal.ZERO) > 0 && (paymentSaturday.compareTo(abonoDiario) < 0)) {
            return "yellowRow";
        } else {
            return null;
        }
    }

    public String getConditionNewCustomer() {
        if (newCustomer.equalsIgnoreCase("Si")) {
            return "greenRow";
        } else {
            return null;
        }
    }

    public String getConditionRenovation() {
        if (getFrozen().equals(ActiveStatus.ENEBLED)) {
            return "blueLightRow";
        }

        if (newCustomer.equalsIgnoreCase("Si")) {
            return "orangeRow";
        } else if (renovation.equalsIgnoreCase("Si")) {
            return "greenLigthRow";
        } else if (getReactivation().equalsIgnoreCase("Si") && getWeekOfCreation().equalsIgnoreCase("Si")) {
            return "limeGreenRow";
        } else if (getSaldoInsoluto().compareTo(BigDecimal.ZERO) == 0) {
            return "greenStrongRow";
        } else {
            return null;
        }

    }

    public int getWeekLoanDate() {
        Calendar c2 = Calendar.getInstance();
        c2.setTime(getFecha());
        int weekLoanDate = c2.get(Calendar.WEEK_OF_YEAR);

        return weekLoanDate;
    }

    public int getWeekCurrentDate() {
        Calendar c2 = Calendar.getInstance();
        int weekCurrentDate = c2.get(Calendar.WEEK_OF_YEAR);

        return weekCurrentDate;
    }

    public BigDecimal getFeeSemana() {

        feeSemana = feeMonday.add(feeThursday).add(feeWednesday).add(feeTuesday).add(feeFriday).add(feeSaturday);
        return feeSemana;
    }

    public void setFeeSemana(BigDecimal feeSemana) {
        this.feeSemana = feeSemana;
    }

    public String getMovimientosMonday() {
        return movimientosMonday;
    }

    public void setMovimientosMonday(String movimientosMonday) {
        this.movimientosMonday = movimientosMonday;
    }

    public String getMovimientosTuesday() {
        return movimientosTuesday;
    }

    public void setMovimientosTuesday(String movimientosTuesday) {
        this.movimientosTuesday = movimientosTuesday;
    }

    public String getMovimientosWednesday() {
        return movimientosWednesday;
    }

    public void setMovimientosWednesday(String movimientosWednesday) {
        this.movimientosWednesday = movimientosWednesday;
    }

    public String getMovimientosThursday() {
        return movimientosThursday;
    }

    public void setMovimientosThursday(String movimientosThursday) {
        this.movimientosThursday = movimientosThursday;
    }

    public String getMovimientosFriday() {
        return movimientosFriday;
    }

    public void setMovimientosFriday(String movimientosFriday) {
        this.movimientosFriday = movimientosFriday;
    }

    public String getMovimientosSaturday() {
        return movimientosSaturday;
    }

    public void setMovimientosSaturday(String movimientosSaturday) {
        this.movimientosSaturday = movimientosSaturday;
    }

    public String getRenovationMonday() {
        return renovationMonday;
    }

    public void setRenovationMonday(String renovationMonday) {
        this.renovationMonday = renovationMonday;
    }

    public String getRenovationTuesday() {
        return renovationTuesday;
    }

    public void setRenovationTuesday(String renovationTuesday) {
        this.renovationTuesday = renovationTuesday;
    }

    public String getRenovationWednesday() {
        return renovationWednesday;
    }

    public void setRenovationWednesday(String renovationWednesday) {
        this.renovationWednesday = renovationWednesday;
    }

    public String getRenovationThursday() {
        return renovationThursday;
    }

    public void setRenovationThursday(String renovationThursday) {
        this.renovationThursday = renovationThursday;
    }

    public String getRenovationFriday() {
        return renovationFriday;
    }

    public void setRenovationFriday(String renovationFriday) {
        this.renovationFriday = renovationFriday;
    }

    public String getRenovationSaturday() {
        return renovationSaturday;
    }

    public void setRenovationSaturday(String renovationSaturday) {
        this.renovationSaturday = renovationSaturday;
    }

    public String getReactivation() {

        return reactivation;
    }

    public void setReactivation(String reactivation) {
        this.reactivation = reactivation;
    }

    public String getWeekOfCreation() {
        return weekOfCreation;
    }

    public void setWeekOfCreation(String weekOfCreation) {
        this.weekOfCreation = weekOfCreation;
    }

}
