/*
 * 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.cosmodas.EntCosmos;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Collection;
import java.util.Date;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;


/**
 * @author obper
 */
@Entity
@Table(name = "abonos")
@XmlRootElement
@NamedQueries({
        @NamedQuery(name = "Abonos.findAll", query = "SELECT a FROM Abonos a"),
        @NamedQuery(name = "Abonos.findByAbonoCodigo", query = "SELECT a FROM Abonos a WHERE a.abonosPK.abonoCodigo = :abonoCodigo"),
        @NamedQuery(name = "Abonos.findByAbonoTipo", query = "SELECT a FROM Abonos a WHERE a.abonosPK.abonoTipo = :abonoTipo"),
        @NamedQuery(name = "Abonos.findByAbonoFecha", query = "SELECT a FROM Abonos a WHERE a.abonoFecha = :abonoFecha"),
        @NamedQuery(name = "Abonos.findByAbonoValor", query = "SELECT a FROM Abonos a WHERE a.abonoValor = :abonoValor"),
        @NamedQuery(name = "Abonos.findByAbonoComentario", query = "SELECT a FROM Abonos a WHERE a.abonoComentario = :abonoComentario"),
        @NamedQuery(name = "Abonos.findByAbonoFechaValor", query = "SELECT a FROM Abonos a WHERE a.abonoFechaValor = :abonoFechaValor"),
        @NamedQuery(name = "Abonos.findByAbonoInventario", query = "SELECT a FROM Abonos a WHERE a.abonoInventario = :abonoInventario"),
        @NamedQuery(name = "Abonos.findByAbonoAnulado", query = "SELECT a FROM Abonos a WHERE a.abonosPK.abonoAnulado = :abonoAnulado"),
        @NamedQuery(name = "Abonos.findByAbonoSaldoAnterior", query = "SELECT a FROM Abonos a WHERE a.abonoSaldoAnterior = :abonoSaldoAnterior"),
        @NamedQuery(name = "Abonos.findByBanco", query = "SELECT a FROM Abonos a WHERE a.banco = :banco"),
        @NamedQuery(name = "Abonos.findByAbonoCodSiguiente", query = "SELECT MAX(a.abonosPK.abonoCodigo) FROM Abonos a WHERE a.abonosPK.abonoTipo = :abonoTipo AND a.sucursalCodigo.sucursalCodigo = :sucursalCodigo AND a.abonosPK.abonoAnulado='F' AND a.abonoFecha=:abonoFecha"),
        @NamedQuery(name = "Abonos.findByAbonoCodSiguienteSerieSalas", query = "SELECT MAX(a.abonosPK.abonoCodigo) FROM Abonos a WHERE a.abonosPK.abonoTipo = :abonoTipo AND a.sucursalCodigo.sucursalCodigo = :sucursalCodigo AND a.abonosPK.abonoAnulado='F'"),
        @NamedQuery(name = "Abonos.findByAbonoEnvio", query = "SELECT a FROM Abonos a WHERE a.abonoEnvio = :abonoEnvio")})
public class Abonos implements Serializable {
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "abonos")
    private Collection<DetalleAbonos> detalleAbonosCollection;
    private static final long serialVersionUID = 1L;
    @EmbeddedId
    protected AbonosPK abonosPK;
    @Basic(optional = false)
    @NotNull
    @Column(name = "abono_fecha")
    @Temporal(TemporalType.DATE)
    private Date abonoFecha;
    // @Max(value=?)  @Min(value=?)//if you know range of your decimal fields consider using these annotations to enforce field validation
    @Basic(optional = false)
    @NotNull
    @Column(name = "abono_valor")
    private BigDecimal abonoValor;
    @Size(max = 80)
    @Column(name = "abono_comentario")
    private String abonoComentario;
    @Basic(optional = false)
    @NotNull
    @Column(name = "abono_fecha_valor")
    @Temporal(TemporalType.DATE)
    private Date abonoFechaValor;
    @Basic(optional = false)
    @NotNull
    @Column(name = "abono_inventario")
    private boolean abonoInventario;
    @Basic(optional = false)
    @NotNull
    @Column(name = "abono_saldo_anterior")
    private BigDecimal abonoSaldoAnterior;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 2)
    @Column(name = "banco")
    private String banco;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 1)
    @Column(name = "abono_envio")
    private String abonoEnvio;
    @JoinColumn(name = "consultor_codigo", referencedColumnName = "consultor_codigo")
    @ManyToOne(optional = false)
    private Consultores consultorCodigo;
    @JoinColumn(name = "sucursal_codigo", referencedColumnName = "sucursal_codigo")
    @ManyToOne(optional = false)
    private Sucursales sucursalCodigo;

    public Abonos() {
    }

    public Abonos(AbonosPK abonosPK) {
        this.abonosPK = abonosPK;
    }

    public Abonos(AbonosPK abonosPK, Date abonoFecha, BigDecimal abonoValor, Date abonoFechaValor, boolean abonoInventario, BigDecimal abonoSaldoAnterior, String banco, String abonoEnvio) {
        this.abonosPK = abonosPK;
        this.abonoFecha = abonoFecha;
        this.abonoValor = abonoValor;
        this.abonoFechaValor = abonoFechaValor;
        this.abonoInventario = abonoInventario;
        this.abonoSaldoAnterior = abonoSaldoAnterior;
        this.banco = banco;
        this.abonoEnvio = abonoEnvio;
    }

    public Abonos(String abonoCodigo, String abonoTipo, String abonoAnulado) {
        this.abonosPK = new AbonosPK(abonoCodigo, abonoTipo, abonoAnulado);
    }

    public AbonosPK getAbonosPK() {
        return abonosPK;
    }

    public void setAbonosPK(AbonosPK abonosPK) {
        this.abonosPK = abonosPK;
    }

    public Date getAbonoFecha() {
        return abonoFecha;
    }

    public void setAbonoFecha(Date abonoFecha) {
        this.abonoFecha = abonoFecha;
    }

    public BigDecimal getAbonoValor() {
        return abonoValor;
    }

    public void setAbonoValor(BigDecimal abonoValor) {
        this.abonoValor = abonoValor;
    }

    public String getAbonoComentario() {
        return abonoComentario;
    }

    public void setAbonoComentario(String abonoComentario) {
        this.abonoComentario = abonoComentario;
    }

    public Date getAbonoFechaValor() {
        return abonoFechaValor;
    }

    public void setAbonoFechaValor(Date abonoFechaValor) {
        this.abonoFechaValor = abonoFechaValor;
    }

    public boolean getAbonoInventario() {
        return abonoInventario;
    }

    public void setAbonoInventario(boolean abonoInventario) {
        this.abonoInventario = abonoInventario;
    }

    public BigDecimal getAbonoSaldoAnterior() {
        return abonoSaldoAnterior;
    }

    public void setAbonoSaldoAnterior(BigDecimal abonoSaldoAnterior) {
        this.abonoSaldoAnterior = abonoSaldoAnterior;
    }

    public String getBanco() {
        return banco;
    }

    public void setBanco(String banco) {
        this.banco = banco;
    }

    public String getAbonoEnvio() {
        return abonoEnvio;
    }

    public void setAbonoEnvio(String abonoEnvio) {
        this.abonoEnvio = abonoEnvio;
    }

    public Consultores getConsultorCodigo() {
        return consultorCodigo;
    }

    public void setConsultorCodigo(Consultores consultorCodigo) {
        this.consultorCodigo = consultorCodigo;
    }

    public Sucursales getSucursalCodigo() {
        return sucursalCodigo;
    }

    public void setSucursalCodigo(Sucursales sucursalCodigo) {
        this.sucursalCodigo = sucursalCodigo;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        //   hash += (abonosPK != null ? abonosPK.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Abonos)) {
            return false;
        }
        Abonos other = (Abonos) object;
        if ((this.abonosPK == null && other.abonosPK != null) || (this.abonosPK != null && !this.abonosPK.equals(other.abonosPK))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.cosmodas.dbcon.Abonos[ abonosPK=" + abonosPK + " ]";
    }

    @XmlTransient
    public Collection<DetalleAbonos> getDetalleAbonosCollection() {
        return detalleAbonosCollection;
    }

    public void setDetalleAbonosCollection(Collection<DetalleAbonos> detalleAbonosCollection) {
        this.detalleAbonosCollection = detalleAbonosCollection;
    }


}
