/******************************************************************************
* Product: Adempiere ERP & CRM Smart Business Solution *
* Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. *
* This program is free software; you can redistribute it and/or modify it *
* under the terms version 2 of the GNU General Public License as published *
* by the Free Software Foundation. This program is distributed in the hope *
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied *
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
* See the GNU General Public License for more details. *
* You should have received a copy of the GNU General Public License along *
* with this program; if not, write to the Free Software Foundation, Inc., *
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
* For the text or an alternative of this public license, you may reach us *
* ComPiere, Inc., 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA *
* or via info@compiere.org or http://www.compiere.org/license.html *
*****************************************************************************/
package org.compiere.model;
import java.math.BigDecimal;
import java.sql.ResultSet;
import java.util.Properties;
import org.compiere.util.DB;
import org.compiere.util.Env;
import org.compiere.util.Msg;
/**
* Physical Inventory Line Model
*
* @author Jorg Janke
* @version $Id: MInventoryLine.java,v 1.3 2006/07/30 00:51:02 jjanke Exp $
*
* @author Teo Sarca, SC ARHIPAC SERVICE SRL
* <li>BF [ 1817757 ] Error on saving MInventoryLine in a custom environment
* <li>BF [ 1722982 ] Error with inventory when you enter count qty in negative
*/
public class MInventoryLine extends X_M_InventoryLine
{
/**
*
*/
private static final long serialVersionUID = 5649152656460089476L;
/**
* Get Inventory Line with parameters
* @param inventory inventory
* @param M_Locator_ID locator
* @param M_Product_ID product
* @param M_AttributeSetInstance_ID asi
* @return line or null
*/
public static MInventoryLine get (MInventory inventory,
int M_Locator_ID, int M_Product_ID, int M_AttributeSetInstance_ID)
{
final String whereClause = "M_Inventory_ID=? AND M_Locator_ID=?"
+" AND M_Product_ID=? AND M_AttributeSetInstance_ID=?";
return new Query(inventory.getCtx(), I_M_InventoryLine.Table_Name, whereClause, inventory.get_TrxName())
.setParameters(inventory.get_ID(), M_Locator_ID, M_Product_ID, M_AttributeSetInstance_ID)
.firstOnly();
} // get
...
public boolean resultaNegativo()
{
/*
* Información del método
*
* Creado por: ingenierojosefrancisco@gmail.com
* Fecha de creación: 24/07/2015 11:27 am
* Fecha de modificación: 24/07/2015 11:27 am
* Descripción: este método valida que el usuario
* no saque la cantidad de producto arriba de lo disponible
*
*/
int disponible = 0;
boolean negativo = false;
// Línea con Atributos
if(getM_AttributeSetInstance_ID() != 0)
{
// Obtener los valores del atributo seleccionado
MAttributeSetInstance a = MAttributeSetInstance.get(Env.getCtx(), getM_AttributeSetInstance_ID(), getM_Product_ID());
// No permitir al usuario grabar una linea
// si no hay productos disponibles
StringBuilder sql = new StringBuilder();
sql.append("SELECT COALESCE((SELECT ");
sql.append(" SUM(t.MovementQty) as cantidad ");
sql.append("FROM M_Transaction t ");
sql.append(" JOIN M_AttributeSetInstance ia ");
sql.append(" ON t.M_AttributeSetInstance_ID = ia.M_AttributeSetInstance_ID ");
sql.append("WHERE t.AD_Client_ID = " + this.getAD_Client_ID() + " ");
sql.append(" AND t.M_Locator_ID = " + this.getM_Locator_ID() + " ");
sql.append(" AND t.M_Product_ID = " + this.getM_Product_ID() + " ");
sql.append(" AND ia.Description = '" + a.getDescription() + "'), 0);");
// System.out.println(sql.toString());
disponible = DB.getSQLValue(null, sql.toString());
// System.out.println(disponible);
if(getQtyInternalUse().intValue() > disponible)
{
negativo = true;
}
}
// Línea sin Atributos
if(getM_AttributeSetInstance_ID() == 0)
{
// No permitir al usuario grabar una linea
// si no hay productos disponibles
StringBuilder sql = new StringBuilder();
sql.append("SELECT COALESCE((SELECT ");
sql.append(" SUM(t.MovementQty) as cantidad ");
sql.append("FROM M_Transaction t ");
sql.append("WHERE t.AD_Client_ID = " + this.getAD_Client_ID() + " ");
sql.append(" AND t.M_Locator_ID = " + this.getM_Locator_ID() + " ");
sql.append(" AND t.M_Product_ID = " + this.getM_Product_ID() + "), 0);");
disponible = DB.getSQLValue(null, sql.toString());
if(getQtyInternalUse().intValue() > disponible)
{
negativo = true;
}
}
return negativo;
}
/**
* Before Save
* @param newRecord new
* @return true if can be saved
*/
protected boolean beforeSave (boolean newRecord)
{
if(resultaNegativo() == true)
{
log.saveError("Cantidad Insuficiente", "Cantidad insuficiente para realizar la salida");
return false;
}
...
/**
* @return true if is an outgoing transaction
*/
public boolean isSOTrx() {
return getMovementQty().signum() < 0;
}
} // MInventoryLine
No hay comentarios:
Publicar un comentario