/*
* The MIT License
*
* Copyright 2012 Universidad de Montemorelos A. C.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package mx.edu.um.mateo.inventario.model;
import java.io.Serializable;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.Date;
import java.util.Objects;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Version;
/**
*
* @author J. David Mendoza <jdmendoza@um.edu.mx>
*/
@Entity
@Table(name = "lotes_salida")
public class LoteSalida implements Serializable {
/**
*
*/
private static final long serialVersionUID = 5004828242237142024L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Version
private Integer version;
@Column(nullable = false, scale = 3, precision = 8)
private BigDecimal cantidad;
@Column(nullable = false, scale = 2, precision = 8, name = "precio_unitario")
private BigDecimal precioUnitario;
@Column(nullable = false, scale = 2, precision = 8)
private BigDecimal iva;
@ManyToOne(optional = false)
private Producto producto;
@ManyToOne(optional = false)
private Salida salida;
@Temporal(TemporalType.TIMESTAMP)
@Column(nullable = false, name = "date_created")
private Date fechaCreacion;
public LoteSalida() {
}
public LoteSalida(Salida salida) {
this.salida = salida;
}
public LoteSalida(BigDecimal cantidad, Producto producto, Salida salida) {
this.cantidad = cantidad;
this.producto = producto;
this.salida = salida;
this.fechaCreacion = new Date();
}
/**
* @return the id
*/
public Long getId() {
return id;
}
/**
* @param id
* the id to set
*/
public void setId(Long id) {
this.id = id;
}
/**
* @return the version
*/
public Integer getVersion() {
return version;
}
/**
* @param version
* the version to set
*/
public void setVersion(Integer version) {
this.version = version;
}
/**
* @return the cantidad
*/
public BigDecimal getCantidad() {
return cantidad;
}
/**
* @param cantidad
* the cantidad to set
*/
public void setCantidad(BigDecimal cantidad) {
this.cantidad = cantidad;
}
/**
* @return the precioUnitario
*/
public BigDecimal getPrecioUnitario() {
return precioUnitario;
}
/**
* @param precioUnitario
* the precioUnitario to set
*/
public void setPrecioUnitario(BigDecimal precioUnitario) {
this.precioUnitario = precioUnitario;
}
/**
* @return the iva
*/
public BigDecimal getIva() {
return iva;
}
/**
* @param iva
* the iva to set
*/
public void setIva(BigDecimal iva) {
this.iva = iva;
}
/**
* @return the producto
*/
public Producto getProducto() {
return producto;
}
/**
* @param producto
* the producto to set
*/
public void setProducto(Producto producto) {
this.producto = producto;
}
/**
* @return the salida
*/
public Salida getSalida() {
return salida;
}
/**
* @param salida
* the salida to set
*/
public void setSalida(Salida salida) {
this.salida = salida;
}
/**
* @return the fechaCreacion
*/
public Date getFechaCreacion() {
return fechaCreacion;
}
/**
* @param fechaCreacion
* the fechaCreacion to set
*/
public void setFechaCreacion(Date fechaCreacion) {
this.fechaCreacion = fechaCreacion;
}
public BigDecimal getTotal() {
BigDecimal total = iva.add(precioUnitario.multiply(cantidad)).setScale(
2, RoundingMode.HALF_UP);
return total;
}
@Override
public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final LoteSalida other = (LoteSalida) obj;
if (!Objects.equals(this.producto, other.producto)) {
return false;
}
if (!Objects.equals(this.salida, other.salida)) {
return false;
}
if (!Objects.equals(this.fechaCreacion, other.fechaCreacion)) {
return false;
}
return true;
}
@Override
public int hashCode() {
int hash = 5;
hash = 19 * hash + Objects.hashCode(this.id);
hash = 19 * hash + Objects.hashCode(this.version);
hash = 19 * hash + Objects.hashCode(this.producto);
hash = 19 * hash + Objects.hashCode(this.salida);
hash = 19 * hash + Objects.hashCode(this.fechaCreacion);
return hash;
}
@Override
public String toString() {
return "LoteSalida{" + "cantidad=" + cantidad + ", precioUnitario="
+ precioUnitario + ", iva=" + iva + ", producto="
+ producto + ", salida=" + salida
+ ", fechaCreacion=" + fechaCreacion + '}';
}
}