Refactoring
- organize imports - delete large commented code - improve indentation
This commit is contained in:
parent
577394612f
commit
e3f0d270bb
|
@ -29,7 +29,6 @@ import java.util.logging.Level;
|
|||
import org.compiere.print.ReportEngine;
|
||||
import org.compiere.process.DocAction;
|
||||
import org.compiere.process.DocumentEngine;
|
||||
import org.compiere.report.MReportTree;
|
||||
import org.compiere.util.CLogger;
|
||||
import org.compiere.util.DB;
|
||||
import org.compiere.util.Env;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/******************************************************************************
|
||||
* Product: Adempiere ERP & CRM Smart Business Solution *
|
||||
* 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 *
|
||||
|
@ -16,13 +16,21 @@
|
|||
*****************************************************************************/
|
||||
package org.compiere.model;
|
||||
|
||||
import java.io.*;
|
||||
import java.math.*;
|
||||
import java.sql.*;
|
||||
import java.util.*;
|
||||
import java.util.logging.*;
|
||||
import org.compiere.process.*;
|
||||
import org.compiere.util.*;
|
||||
import java.io.File;
|
||||
import java.math.BigDecimal;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.Timestamp;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Properties;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import org.compiere.process.DocAction;
|
||||
import org.compiere.process.DocumentEngine;
|
||||
import org.compiere.util.CCache;
|
||||
import org.compiere.util.DB;
|
||||
import org.compiere.util.Env;
|
||||
import org.compiere.util.Msg;
|
||||
|
||||
/**
|
||||
* Physical Inventory Model
|
||||
|
@ -57,8 +65,8 @@ public class MInventory extends X_M_Inventory implements DocAction
|
|||
|
||||
/** Cache */
|
||||
private static CCache<Integer,MInventory> s_cache = new CCache<Integer,MInventory>("M_Inventory", 5, 5);
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Standard Constructor
|
||||
* @param ctx context
|
||||
|
@ -378,7 +386,7 @@ public class MInventory extends X_M_Inventory implements DocAction
|
|||
if (!DocAction.STATUS_InProgress.equals(status))
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
m_processMsg = ModelValidationEngine.get().fireDocValidate(this, ModelValidator.TIMING_BEFORE_COMPLETE);
|
||||
if (m_processMsg != null)
|
||||
return DocAction.STATUS_Invalid;
|
||||
|
@ -387,237 +395,38 @@ public class MInventory extends X_M_Inventory implements DocAction
|
|||
if (!isApproved())
|
||||
approveIt();
|
||||
log.info(toString());
|
||||
|
||||
//vpj-cd begin e-evolution recalculate the attribute instances and qty.
|
||||
/*MInventoryLine[] linesup = getLines(false);
|
||||
for (int i = 0; i < linesup.length; i++)
|
||||
{
|
||||
MInventoryLine line = linesup[i];
|
||||
|
||||
String sql1 = "Delete From M_InventoryLineMA "
|
||||
+ " WHERE M_InventoryLine_ID=" +line.getM_InventoryLine_ID();
|
||||
int no = DB.executeUpdate(sql1, get_TrxName());
|
||||
log.info("MA deleted " + no);
|
||||
|
||||
StringBuffer sql = new StringBuffer(
|
||||
"SELECT s.M_Product_ID, s.M_Locator_ID, s.M_AttributeSetInstance_ID,"
|
||||
+ " s.QtyOnHand, p.M_AttributeSet_ID "
|
||||
+ "FROM M_Product p"
|
||||
+ " INNER JOIN M_Storage s ON (s.M_Product_ID=p.M_Product_ID)"
|
||||
+ " INNER JOIN M_Locator l ON (s.M_Locator_ID=l.M_Locator_ID) "
|
||||
+ "WHERE l.M_Warehouse_ID=?"
|
||||
+ " AND p.IsActive='Y' AND p.IsStocked='Y' and p.ProductType='I'"
|
||||
+ " AND s.M_Locator_ID=" +line.getM_Locator_ID()
|
||||
+ " AND s.M_Product_ID=" +line.getM_Product_ID()
|
||||
+ " AND s.QtyOnHand <> 0 "
|
||||
);
|
||||
PreparedStatement pstmt = null;
|
||||
try
|
||||
{
|
||||
pstmt = DB.prepareStatement (sql.toString(), get_TrxName());
|
||||
int index = 1;
|
||||
pstmt.setInt (index++, getM_Warehouse_ID());
|
||||
ResultSet rs = pstmt.executeQuery ();
|
||||
while (rs.next ())
|
||||
{
|
||||
MInventoryLineMA maup = new MInventoryLineMA (line,
|
||||
rs.getInt(3), rs.getBigDecimal(4));
|
||||
|
||||
if (!maup.save())
|
||||
;
|
||||
}
|
||||
rs.close ();
|
||||
pstmt.close ();
|
||||
pstmt = null;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
log.log(Level.SEVERE, sql.toString(), e);
|
||||
}
|
||||
try
|
||||
{
|
||||
if (pstmt != null)
|
||||
pstmt.close ();
|
||||
pstmt = null;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
pstmt = null;
|
||||
}
|
||||
}*/
|
||||
//vpj-cd e-evolution recalculate the attribute instances and qty END.
|
||||
/*
|
||||
//
|
||||
MInventoryLine[] lines = getLines(false);
|
||||
for (int i = 0; i < lines.length; i++)
|
||||
{
|
||||
MInventoryLine line = lines[i];
|
||||
if (!line.isActive())
|
||||
continue;
|
||||
|
||||
MTransaction trx = null;
|
||||
if (line.getM_AttributeSetInstance_ID() == 0)
|
||||
{
|
||||
BigDecimal qtyDiff = line.getQtyInternalUse().negate();
|
||||
if (qtyDiff.signum() == 0)
|
||||
qtyDiff = line.getQtyCount().subtract(line.getQtyBook());
|
||||
//
|
||||
if (qtyDiff.signum() > 0)
|
||||
{
|
||||
// Storage
|
||||
MStorage storage = MStorage.get(getCtx(), line.getM_Locator_ID(),
|
||||
line.getM_Product_ID(), 0, get_TrxName());
|
||||
if (storage == null)
|
||||
storage = MStorage.getCreate(getCtx(), line.getM_Locator_ID(),
|
||||
line.getM_Product_ID(), 0, get_TrxName());
|
||||
BigDecimal qtyNew = storage.getQtyOnHand().add(qtyDiff);
|
||||
log.fine("Diff=" + qtyDiff
|
||||
+ " - OnHand=" + storage.getQtyOnHand() + "->" + qtyNew);
|
||||
storage.setQtyOnHand(qtyNew);
|
||||
storage.setDateLastInventory(getMovementDate());
|
||||
if (!storage.save(get_TrxName()))
|
||||
{
|
||||
m_processMsg = "Storage not updated(1)";
|
||||
return DocAction.STATUS_Invalid;
|
||||
}
|
||||
log.fine(storage.toString());
|
||||
// Transaction
|
||||
trx = new MTransaction (getCtx(), line.getAD_Org_ID(),
|
||||
MTransaction.MOVEMENTTYPE_InventoryIn,
|
||||
line.getM_Locator_ID(), line.getM_Product_ID(), 0,
|
||||
qtyDiff, getMovementDate(), get_TrxName());
|
||||
trx.setM_InventoryLine_ID(line.getM_InventoryLine_ID());
|
||||
if (!trx.save())
|
||||
{
|
||||
m_processMsg = "Transaction not inserted(1)";
|
||||
return DocAction.STATUS_Invalid;
|
||||
}
|
||||
}
|
||||
else // negative qty
|
||||
{
|
||||
MInventoryLineMA mas[] = MInventoryLineMA.get(getCtx(),
|
||||
line.getM_InventoryLine_ID(), get_TrxName());
|
||||
for (int j = 0; j < mas.length; j++)
|
||||
{
|
||||
MInventoryLineMA ma = mas[j];
|
||||
// Storage
|
||||
MStorage storage = MStorage.get(getCtx(), line.getM_Locator_ID(),
|
||||
line.getM_Product_ID(), ma.getM_AttributeSetInstance_ID(), get_TrxName());
|
||||
if (storage == null)
|
||||
storage = MStorage.getCreate(getCtx(), line.getM_Locator_ID(),
|
||||
line.getM_Product_ID(), ma.getM_AttributeSetInstance_ID(), get_TrxName());
|
||||
//
|
||||
BigDecimal maxDiff = qtyDiff;
|
||||
if (maxDiff.signum() < 0
|
||||
&& ma.getMovementQty().compareTo(maxDiff.negate()) < 0)
|
||||
maxDiff = ma.getMovementQty().negate();
|
||||
BigDecimal qtyNew = ma.getMovementQty().add(maxDiff); // Storage+Diff
|
||||
log.fine("MA Qty=" + ma.getMovementQty()
|
||||
+ ",Diff=" + qtyDiff + "|" + maxDiff
|
||||
+ " - OnHand=" + storage.getQtyOnHand() + "->" + qtyNew
|
||||
+ " {" + ma.getM_AttributeSetInstance_ID() + "}");
|
||||
//
|
||||
storage.setQtyOnHand(qtyNew);
|
||||
storage.setDateLastInventory(getMovementDate());
|
||||
if (!storage.save(get_TrxName()))
|
||||
{
|
||||
m_processMsg = "Storage not updated (MA)";
|
||||
return DocAction.STATUS_Invalid;
|
||||
}
|
||||
log.fine(storage.toString());
|
||||
|
||||
// Transaction
|
||||
trx = new MTransaction (getCtx(), line.getAD_Org_ID(),
|
||||
MTransaction.MOVEMENTTYPE_InventoryIn,
|
||||
line.getM_Locator_ID(), line.getM_Product_ID(), ma.getM_AttributeSetInstance_ID(),
|
||||
maxDiff, getMovementDate(), get_TrxName());
|
||||
trx.setM_InventoryLine_ID(line.getM_InventoryLine_ID());
|
||||
if (!trx.save())
|
||||
{
|
||||
m_processMsg = "Transaction not inserted (MA)";
|
||||
return DocAction.STATUS_Invalid;
|
||||
}
|
||||
//
|
||||
qtyDiff = qtyDiff.subtract(maxDiff);
|
||||
if (qtyDiff.signum() == 0)
|
||||
break;
|
||||
}
|
||||
} // negative qty
|
||||
}
|
||||
// Fallback
|
||||
if (trx == null)
|
||||
{
|
||||
// Storage
|
||||
MStorage storage = MStorage.get(getCtx(), line.getM_Locator_ID(),
|
||||
line.getM_Product_ID(), line.getM_AttributeSetInstance_ID(), get_TrxName());
|
||||
if (storage == null)
|
||||
storage = MStorage.getCreate(getCtx(), line.getM_Locator_ID(),
|
||||
line.getM_Product_ID(), line.getM_AttributeSetInstance_ID(), get_TrxName());
|
||||
//
|
||||
BigDecimal qtyDiff = line.getQtyInternalUse().negate();
|
||||
if (Env.ZERO.compareTo(qtyDiff) == 0)
|
||||
qtyDiff = line.getQtyCount().subtract(line.getQtyBook());
|
||||
BigDecimal qtyNew = storage.getQtyOnHand().add(qtyDiff);
|
||||
log.fine("Count=" + line.getQtyCount()
|
||||
+ ",Book=" + line.getQtyBook() + ", Difference=" + qtyDiff
|
||||
+ " - OnHand=" + storage.getQtyOnHand() + "->" + qtyNew);
|
||||
//
|
||||
storage.setQtyOnHand(qtyNew);
|
||||
storage.setDateLastInventory(getMovementDate());
|
||||
if (!storage.save(get_TrxName()))
|
||||
{
|
||||
m_processMsg = "Storage not updated(2)";
|
||||
return DocAction.STATUS_Invalid;
|
||||
}
|
||||
log.fine(storage.toString());
|
||||
|
||||
// Transaction
|
||||
trx = new MTransaction (getCtx(), line.getAD_Org_ID(),
|
||||
MTransaction.MOVEMENTTYPE_InventoryIn,
|
||||
line.getM_Locator_ID(), line.getM_Product_ID(), line.getM_AttributeSetInstance_ID(),
|
||||
qtyDiff, getMovementDate(), get_TrxName());
|
||||
trx.setM_InventoryLine_ID(line.getM_InventoryLine_ID());
|
||||
if (!trx.save())
|
||||
{
|
||||
m_processMsg = "Transaction not inserted(2)";
|
||||
return DocAction.STATUS_Invalid;
|
||||
}
|
||||
} // Fallback
|
||||
|
||||
*/
|
||||
|
||||
|
||||
|
||||
MInventoryLine[] lines = getLines(false);
|
||||
for (MInventoryLine line : lines)
|
||||
{
|
||||
if (!line.isActive())
|
||||
continue;
|
||||
|
||||
|
||||
MProduct product = line.getProduct();
|
||||
|
||||
|
||||
//Get Quantity to Inventory Inernal Use
|
||||
BigDecimal qtyDiff = line.getQtyInternalUse().negate();
|
||||
//If Quantity to Inventory Internal Use = Zero Then is Physical Inventory Else is Inventory Internal Use
|
||||
if (qtyDiff.signum() == 0)
|
||||
qtyDiff = line.getQtyCount().subtract(line.getQtyBook());
|
||||
|
||||
|
||||
//Ignore the Material Policy when is Reverse Correction
|
||||
if(!isReversal())
|
||||
checkMaterialPolicy(line, qtyDiff);
|
||||
|
||||
checkMaterialPolicy(line, qtyDiff);
|
||||
|
||||
// Stock Movement - Counterpart MOrder.reserveStock
|
||||
if (product != null
|
||||
&& product.isStocked() )
|
||||
&& product.isStocked() )
|
||||
{
|
||||
log.fine("Material Transaction");
|
||||
MTransaction mtrx = null;
|
||||
|
||||
|
||||
//If AttributeSetInstance = Zero then create new AttributeSetInstance use Inventory Line MA else use current AttributeSetInstance
|
||||
if (line.getM_AttributeSetInstance_ID() == 0 || qtyDiff.compareTo(Env.ZERO) == 0)
|
||||
{
|
||||
MInventoryLineMA mas[] = MInventoryLineMA.get(getCtx(),
|
||||
line.getM_InventoryLine_ID(), get_TrxName());
|
||||
|
||||
line.getM_InventoryLine_ID(), get_TrxName());
|
||||
|
||||
for (int j = 0; j < mas.length; j++)
|
||||
{
|
||||
MInventoryLineMA ma = mas[j];
|
||||
|
@ -625,49 +434,49 @@ public class MInventory extends X_M_Inventory implements DocAction
|
|||
BigDecimal QtyNew = QtyMA.add(qtyDiff);
|
||||
log.fine("Diff=" + qtyDiff
|
||||
+ " - Instance OnHand=" + QtyMA + "->" + QtyNew);
|
||||
|
||||
if (!MStorage.add(getCtx(), getM_Warehouse_ID(),
|
||||
line.getM_Locator_ID(),
|
||||
line.getM_Product_ID(),
|
||||
ma.getM_AttributeSetInstance_ID(), 0,
|
||||
QtyMA.negate(), Env.ZERO, Env.ZERO, get_TrxName()))
|
||||
|
||||
if (!MStorage.add(getCtx(), getM_Warehouse_ID(),
|
||||
line.getM_Locator_ID(),
|
||||
line.getM_Product_ID(),
|
||||
ma.getM_AttributeSetInstance_ID(), 0,
|
||||
QtyMA.negate(), Env.ZERO, Env.ZERO, get_TrxName()))
|
||||
{
|
||||
m_processMsg = "Cannot correct Inventory (MA)";
|
||||
return DocAction.STATUS_Invalid;
|
||||
}
|
||||
|
||||
// Only Update Date Last Inventory if is a Physical Inventory
|
||||
if(line.getQtyInternalUse().compareTo(Env.ZERO) == 0)
|
||||
{
|
||||
MStorage storage = MStorage.get(getCtx(), line.getM_Locator_ID(),
|
||||
line.getM_Product_ID(), ma.getM_AttributeSetInstance_ID(), get_TrxName());
|
||||
storage.setDateLastInventory(getMovementDate());
|
||||
if (!storage.save(get_TrxName()))
|
||||
{
|
||||
m_processMsg = "Cannot correct Inventory (MA)";
|
||||
return DocAction.STATUS_Invalid;
|
||||
}
|
||||
|
||||
// Only Update Date Last Inventory if is a Physical Inventory
|
||||
if(line.getQtyInternalUse().compareTo(Env.ZERO) == 0)
|
||||
{
|
||||
MStorage storage = MStorage.get(getCtx(), line.getM_Locator_ID(),
|
||||
line.getM_Product_ID(), ma.getM_AttributeSetInstance_ID(), get_TrxName());
|
||||
storage.setDateLastInventory(getMovementDate());
|
||||
if (!storage.save(get_TrxName()))
|
||||
{
|
||||
m_processMsg = "Storage not updated(2)";
|
||||
return DocAction.STATUS_Invalid;
|
||||
}
|
||||
}
|
||||
|
||||
String m_MovementType =null;
|
||||
if(QtyMA.negate().compareTo(Env.ZERO) > 0 )
|
||||
m_MovementType = MTransaction.MOVEMENTTYPE_InventoryIn;
|
||||
else
|
||||
m_MovementType = MTransaction.MOVEMENTTYPE_InventoryOut;
|
||||
// Transaction
|
||||
mtrx = new MTransaction (getCtx(), line.getAD_Org_ID(), m_MovementType,
|
||||
line.getM_Locator_ID(), line.getM_Product_ID(), ma.getM_AttributeSetInstance_ID(),
|
||||
QtyMA.negate(), getMovementDate(), get_TrxName());
|
||||
mtrx.setM_InventoryLine_ID(line.getM_InventoryLine_ID());
|
||||
if (!mtrx.save())
|
||||
{
|
||||
m_processMsg = "Transaction not inserted(2)";
|
||||
m_processMsg = "Storage not updated(2)";
|
||||
return DocAction.STATUS_Invalid;
|
||||
}
|
||||
qtyDiff = QtyNew;
|
||||
}
|
||||
|
||||
String m_MovementType =null;
|
||||
if(QtyMA.negate().compareTo(Env.ZERO) > 0 )
|
||||
m_MovementType = MTransaction.MOVEMENTTYPE_InventoryIn;
|
||||
else
|
||||
m_MovementType = MTransaction.MOVEMENTTYPE_InventoryOut;
|
||||
// Transaction
|
||||
mtrx = new MTransaction (getCtx(), line.getAD_Org_ID(), m_MovementType,
|
||||
line.getM_Locator_ID(), line.getM_Product_ID(), ma.getM_AttributeSetInstance_ID(),
|
||||
QtyMA.negate(), getMovementDate(), get_TrxName());
|
||||
mtrx.setM_InventoryLine_ID(line.getM_InventoryLine_ID());
|
||||
if (!mtrx.save())
|
||||
{
|
||||
m_processMsg = "Transaction not inserted(2)";
|
||||
return DocAction.STATUS_Invalid;
|
||||
}
|
||||
qtyDiff = QtyNew;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//sLine.getM_AttributeSetInstance_ID() != 0
|
||||
// Fallback
|
||||
if (mtrx == null)
|
||||
|
@ -679,16 +488,16 @@ public class MInventory extends X_M_Inventory implements DocAction
|
|||
line.getM_AttributeSetInstance_ID(), 0,
|
||||
qtyDiff, Env.ZERO, Env.ZERO, get_TrxName()))
|
||||
{
|
||||
m_processMsg = "Cannot correct Inventory (MA)";
|
||||
return DocAction.STATUS_Invalid;
|
||||
m_processMsg = "Cannot correct Inventory (MA)";
|
||||
return DocAction.STATUS_Invalid;
|
||||
}
|
||||
|
||||
|
||||
// Only Update Date Last Inventory if is a Physical Inventory
|
||||
if(line.getQtyInternalUse().compareTo(Env.ZERO) == 0)
|
||||
{
|
||||
MStorage storage = MStorage.get(getCtx(), line.getM_Locator_ID(),
|
||||
line.getM_Product_ID(), line.getM_AttributeSetInstance_ID(), get_TrxName());
|
||||
|
||||
|
||||
storage.setDateLastInventory(getMovementDate());
|
||||
if (!storage.save(get_TrxName()))
|
||||
{
|
||||
|
@ -696,7 +505,7 @@ public class MInventory extends X_M_Inventory implements DocAction
|
|||
return DocAction.STATUS_Invalid;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
String m_MovementType =null;
|
||||
if(qtyDiff.compareTo(Env.ZERO) > 0 )
|
||||
m_MovementType = MTransaction.MOVEMENTTYPE_InventoryIn;
|
||||
|
@ -704,8 +513,8 @@ public class MInventory extends X_M_Inventory implements DocAction
|
|||
m_MovementType = MTransaction.MOVEMENTTYPE_InventoryOut;
|
||||
// Transaction
|
||||
mtrx = new MTransaction (getCtx(), line.getAD_Org_ID(), m_MovementType,
|
||||
line.getM_Locator_ID(), line.getM_Product_ID(), line.getM_AttributeSetInstance_ID(),
|
||||
qtyDiff, getMovementDate(), get_TrxName());
|
||||
line.getM_Locator_ID(), line.getM_Product_ID(), line.getM_AttributeSetInstance_ID(),
|
||||
qtyDiff, getMovementDate(), get_TrxName());
|
||||
mtrx.setM_InventoryLine_ID(line.getM_InventoryLine_ID());
|
||||
if (!mtrx.save())
|
||||
{
|
||||
|
@ -713,11 +522,11 @@ public class MInventory extends X_M_Inventory implements DocAction
|
|||
return DocAction.STATUS_Invalid;
|
||||
}
|
||||
} // Fallback
|
||||
} // stock movement
|
||||
|
||||
|
||||
} // stock movement
|
||||
|
||||
|
||||
} // for all lines
|
||||
|
||||
|
||||
// User Validation
|
||||
String valid = ModelValidationEngine.get().fireDocValidate(this, ModelValidator.TIMING_AFTER_COMPLETE);
|
||||
if (valid != null)
|
||||
|
@ -760,131 +569,86 @@ public class MInventory extends X_M_Inventory implements DocAction
|
|||
int no = MInventoryLineMA.deleteInventoryMA(line.getM_InventoryLine_ID(), get_TrxName());
|
||||
if (no > 0)
|
||||
log.config("Delete old #" + no);
|
||||
|
||||
|
||||
// Check Line
|
||||
boolean needSave = false;
|
||||
BigDecimal qtyASI = Env.ZERO ;
|
||||
// Attribute Set Instance
|
||||
if (line.getM_AttributeSetInstance_ID() == 0)
|
||||
|
||||
|
||||
// Check Line
|
||||
boolean needSave = false;
|
||||
BigDecimal qtyASI = Env.ZERO ;
|
||||
// Attribute Set Instance
|
||||
if (line.getM_AttributeSetInstance_ID() == 0)
|
||||
{
|
||||
MProduct product = MProduct.get(getCtx(), line.getM_Product_ID());
|
||||
if (qtyDiff.signum() > 0) // Incoming Trx
|
||||
{
|
||||
MProduct product = MProduct.get(getCtx(), line.getM_Product_ID());
|
||||
if (qtyDiff.signum() > 0) // Incoming Trx
|
||||
MAttributeSetInstance asi = new MAttributeSetInstance(getCtx(), 0, get_TrxName());
|
||||
asi.setClientOrg(getAD_Client_ID(), 0);
|
||||
asi.setM_AttributeSet_ID(product.getM_AttributeSet_ID());
|
||||
if (!asi.save())
|
||||
{
|
||||
MAttributeSetInstance asi = new MAttributeSetInstance(getCtx(), 0, get_TrxName());
|
||||
asi.setClientOrg(getAD_Client_ID(), 0);
|
||||
asi.setM_AttributeSet_ID(product.getM_AttributeSet_ID());
|
||||
if (!asi.save())
|
||||
{
|
||||
throw new IllegalStateException("Error try create ASI Reservation");
|
||||
}
|
||||
if (asi.save())
|
||||
{
|
||||
line.setM_AttributeSetInstance_ID(asi.getM_AttributeSetInstance_ID());
|
||||
needSave = true;
|
||||
}
|
||||
throw new IllegalStateException("Error try create ASI Reservation");
|
||||
}
|
||||
if (asi.save())
|
||||
{
|
||||
line.setM_AttributeSetInstance_ID(asi.getM_AttributeSetInstance_ID());
|
||||
needSave = true;
|
||||
}
|
||||
else // Outgoing Trx
|
||||
{
|
||||
String MMPolicy = product.getMMPolicy();
|
||||
MStorage[] storages = MStorage.getAllWithASI(getCtx(),
|
||||
}
|
||||
else // Outgoing Trx
|
||||
{
|
||||
String MMPolicy = product.getMMPolicy();
|
||||
MStorage[] storages = MStorage.getAllWithASI(getCtx(),
|
||||
line.getM_Product_ID(), line.getM_Locator_ID(),
|
||||
MClient.MMPOLICY_FiFo.equals(MMPolicy), get_TrxName());
|
||||
BigDecimal qtyToDeliver = qtyDiff.negate();
|
||||
|
||||
/*for (int ii = 0; ii < storages.length; ii++)
|
||||
BigDecimal qtyToDeliver = qtyDiff.negate();
|
||||
|
||||
for (MStorage storage: storages)
|
||||
{
|
||||
//cosume ASI Zero
|
||||
if (storage.getM_AttributeSetInstance_ID() == 0)
|
||||
{
|
||||
MStorage storage = storages[ii];
|
||||
if (ii == 0)
|
||||
{
|
||||
if (storage.getQtyOnHand().compareTo(qtyToDeliver) >= 0)
|
||||
{
|
||||
line.setM_AttributeSetInstance_ID(storage.getM_AttributeSetInstance_ID());
|
||||
needSave = true;
|
||||
log.config("Direct - " + line);
|
||||
qtyToDeliver = Env.ZERO;
|
||||
}
|
||||
else
|
||||
{
|
||||
log.config("Split - " + line);
|
||||
MInventoryLineMA ma = new MInventoryLineMA (line,
|
||||
storage.getM_AttributeSetInstance_ID(),
|
||||
storage.getQtyOnHand().negate());
|
||||
if (!ma.save())
|
||||
;
|
||||
qtyToDeliver = qtyToDeliver.subtract(storage.getQtyOnHand());
|
||||
log.fine("#" + ii + ": " + ma + ", QtyToDeliver=" + qtyToDeliver);
|
||||
}
|
||||
}
|
||||
else // create addl material allocation
|
||||
{
|
||||
MInventoryLineMA ma = new MInventoryLineMA (line,
|
||||
qtyASI = qtyASI.add(storage.getQtyOnHand());
|
||||
qtyToDeliver = qtyToDeliver.subtract(storage.getQtyOnHand());
|
||||
continue;
|
||||
}
|
||||
|
||||
if (storage.getQtyOnHand().compareTo(qtyToDeliver) >= 0)
|
||||
{
|
||||
MInventoryLineMA ma = new MInventoryLineMA (line,
|
||||
storage.getM_AttributeSetInstance_ID(),
|
||||
qtyToDeliver.negate());
|
||||
if (storage.getQtyOnHand().compareTo(qtyToDeliver) >= 0)
|
||||
qtyToDeliver = Env.ZERO;
|
||||
else
|
||||
{
|
||||
ma.setMovementQty(storage.getQtyOnHand().negate());
|
||||
qtyToDeliver = qtyToDeliver.subtract(storage.getQtyOnHand());
|
||||
}
|
||||
if (!ma.save())
|
||||
;
|
||||
log.fine("#" + ii + ": " + ma + ", QtyToDeliver=" + qtyToDeliver);
|
||||
}
|
||||
if (qtyToDeliver.signum() == 0)
|
||||
break;
|
||||
} // for all storages
|
||||
*/
|
||||
|
||||
for (MStorage storage: storages)
|
||||
{
|
||||
//cosume ASI Zero
|
||||
if (storage.getM_AttributeSetInstance_ID() == 0)
|
||||
{
|
||||
qtyASI = qtyASI.add(storage.getQtyOnHand());
|
||||
qtyToDeliver = qtyToDeliver.subtract(storage.getQtyOnHand());
|
||||
continue;
|
||||
}
|
||||
|
||||
if (storage.getQtyOnHand().compareTo(qtyToDeliver) >= 0)
|
||||
{
|
||||
MInventoryLineMA ma = new MInventoryLineMA (line,
|
||||
storage.getM_AttributeSetInstance_ID(),
|
||||
qtyToDeliver);
|
||||
if (!ma.save())
|
||||
{
|
||||
throw new IllegalStateException("Error try create ASI Reservation");
|
||||
}
|
||||
qtyToDeliver = Env.ZERO;
|
||||
log.fine( ma + ", QtyToDeliver=" + qtyToDeliver);
|
||||
//return;
|
||||
}
|
||||
else
|
||||
{
|
||||
MInventoryLineMA ma = new MInventoryLineMA (line,
|
||||
storage.getM_AttributeSetInstance_ID(),
|
||||
storage.getQtyOnHand());
|
||||
if (!ma.save())
|
||||
{
|
||||
throw new IllegalStateException("Error try create ASI Reservation");
|
||||
}
|
||||
qtyToDeliver = qtyToDeliver.subtract(storage.getQtyOnHand());
|
||||
log.fine( ma + ", QtyToDeliver=" + qtyToDeliver);
|
||||
}
|
||||
}
|
||||
|
||||
// No AttributeSetInstance found for remainder
|
||||
if (qtyToDeliver.signum() != 0 || qtyASI.signum() != 0)
|
||||
{
|
||||
MInventoryLineMA ma = new MInventoryLineMA (line, 0 , qtyToDeliver.add(qtyASI));
|
||||
|
||||
qtyToDeliver);
|
||||
if (!ma.save())
|
||||
;
|
||||
log.fine("##: " + ma);
|
||||
{
|
||||
throw new IllegalStateException("Error try create ASI Reservation");
|
||||
}
|
||||
qtyToDeliver = Env.ZERO;
|
||||
log.fine( ma + ", QtyToDeliver=" + qtyToDeliver);
|
||||
//return;
|
||||
}
|
||||
} // outgoing Trx
|
||||
|
||||
else
|
||||
{
|
||||
MInventoryLineMA ma = new MInventoryLineMA (line,
|
||||
storage.getM_AttributeSetInstance_ID(),
|
||||
storage.getQtyOnHand());
|
||||
if (!ma.save())
|
||||
{
|
||||
throw new IllegalStateException("Error try create ASI Reservation");
|
||||
}
|
||||
qtyToDeliver = qtyToDeliver.subtract(storage.getQtyOnHand());
|
||||
log.fine( ma + ", QtyToDeliver=" + qtyToDeliver);
|
||||
}
|
||||
}
|
||||
|
||||
// No AttributeSetInstance found for remainder
|
||||
if (qtyToDeliver.signum() != 0 || qtyASI.signum() != 0)
|
||||
{
|
||||
MInventoryLineMA ma = new MInventoryLineMA (line, 0 , qtyToDeliver.add(qtyASI));
|
||||
|
||||
if (!ma.save())
|
||||
;
|
||||
log.fine("##: " + ma);
|
||||
}
|
||||
} // outgoing Trx
|
||||
|
||||
if (needSave && !line.save())
|
||||
log.severe("NOT saved " + line);
|
||||
} // for all lines
|
||||
|
@ -980,7 +744,7 @@ public class MInventory extends X_M_Inventory implements DocAction
|
|||
m_processMsg = ModelValidationEngine.get().fireDocValidate(this,ModelValidator.TIMING_BEFORE_REVERSECORRECT);
|
||||
if (m_processMsg != null)
|
||||
return false;
|
||||
|
||||
|
||||
MDocType dt = MDocType.get(getCtx(), getC_DocType_ID());
|
||||
if (!MPeriod.isOpen(getCtx(), getMovementDate(), dt.getDocBaseType()))
|
||||
{
|
||||
|
@ -1005,7 +769,7 @@ public class MInventory extends X_M_Inventory implements DocAction
|
|||
return false;
|
||||
}
|
||||
reversal.setReversal(true);
|
||||
|
||||
|
||||
// Reverse Line Qty
|
||||
MInventoryLine[] oLines = getLines(true);
|
||||
for (int i = 0; i < oLines.length; i++)
|
||||
|
@ -1022,23 +786,23 @@ public class MInventory extends X_M_Inventory implements DocAction
|
|||
rLine.setQtyBook (oLine.getQtyCount()); // switch
|
||||
rLine.setQtyCount (oLine.getQtyBook());
|
||||
rLine.setQtyInternalUse (oLine.getQtyInternalUse().negate());
|
||||
|
||||
|
||||
if (!rLine.save())
|
||||
{
|
||||
m_processMsg = "Could not create Inventory Reversal Line";
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
//We need to copy MA
|
||||
if (rLine.getM_AttributeSetInstance_ID() == 0)
|
||||
{
|
||||
MInventoryLineMA mas[] = MInventoryLineMA.get(getCtx(),
|
||||
oLines[i].getM_InventoryLine_ID(), get_TrxName());
|
||||
oLines[i].getM_InventoryLine_ID(), get_TrxName());
|
||||
for (int j = 0; j < mas.length; j++)
|
||||
{
|
||||
MInventoryLineMA ma = new MInventoryLineMA (rLine,
|
||||
mas[j].getM_AttributeSetInstance_ID(),
|
||||
mas[j].getMovementQty().negate());
|
||||
mas[j].getM_AttributeSetInstance_ID(),
|
||||
mas[j].getMovementQty().negate());
|
||||
if (!ma.save())
|
||||
;
|
||||
}
|
||||
|
@ -1055,7 +819,7 @@ public class MInventory extends X_M_Inventory implements DocAction
|
|||
reversal.setDocAction(DOCACTION_None);
|
||||
reversal.save();
|
||||
m_processMsg = reversal.getDocumentNo();
|
||||
|
||||
|
||||
// Update Reversed (this)
|
||||
addDescription("(" + reversal.getDocumentNo() + "<-)");
|
||||
// After reverseCorrect
|
||||
|
@ -1067,9 +831,9 @@ public class MInventory extends X_M_Inventory implements DocAction
|
|||
setReversal_ID(reversal.getM_Inventory_ID());
|
||||
setDocStatus(DOCSTATUS_Reversed); // may come from void
|
||||
setDocAction(DOCACTION_None);
|
||||
|
||||
|
||||
return true;
|
||||
} // reverseCorrectionIt
|
||||
} // reverseCorrectIt
|
||||
|
||||
/**
|
||||
* Reverse Accrual
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/******************************************************************************
|
||||
* Product: Adempiere ERP & CRM Smart Business Solution *
|
||||
* 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 *
|
||||
|
@ -16,12 +16,16 @@
|
|||
*****************************************************************************/
|
||||
package org.compiere.model;
|
||||
|
||||
import java.math.*;
|
||||
import java.sql.*;
|
||||
import java.util.*;
|
||||
import java.util.logging.*;
|
||||
import java.math.BigDecimal;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.util.Properties;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import org.compiere.util.*;
|
||||
import org.compiere.util.CLogger;
|
||||
import org.compiere.util.DB;
|
||||
import org.compiere.util.Env;
|
||||
import org.compiere.util.Msg;
|
||||
|
||||
/**
|
||||
* Physical Inventory Line Model
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/******************************************************************************
|
||||
* Product: Adempiere ERP & CRM Smart Business Solution *
|
||||
* 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 *
|
||||
|
@ -16,11 +16,15 @@
|
|||
*****************************************************************************/
|
||||
package org.compiere.model;
|
||||
|
||||
import java.math.*;
|
||||
import java.sql.*;
|
||||
import java.util.*;
|
||||
import java.util.logging.*;
|
||||
import org.compiere.util.*;
|
||||
import java.math.BigDecimal;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Properties;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import org.compiere.util.CLogger;
|
||||
import org.compiere.util.DB;
|
||||
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/******************************************************************************
|
||||
* Product: Adempiere ERP & CRM Smart Business Solution *
|
||||
* 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 *
|
||||
|
@ -16,10 +16,15 @@
|
|||
*****************************************************************************/
|
||||
package org.compiere.model;
|
||||
|
||||
import java.sql.*;
|
||||
import java.util.*;
|
||||
import java.util.logging.*;
|
||||
import org.compiere.util.*;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Properties;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import org.compiere.util.CCache;
|
||||
import org.compiere.util.CLogger;
|
||||
import org.compiere.util.DB;
|
||||
|
||||
/**
|
||||
* Warehouse Locator Object
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/******************************************************************************
|
||||
* Product: Adempiere ERP & CRM Smart Business Solution *
|
||||
* 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 *
|
||||
|
@ -16,15 +16,23 @@
|
|||
*****************************************************************************/
|
||||
package org.compiere.model;
|
||||
|
||||
import java.io.*;
|
||||
import java.math.*;
|
||||
import java.sql.*;
|
||||
import java.util.*;
|
||||
import java.util.logging.*;
|
||||
import org.compiere.process.*;
|
||||
import org.compiere.util.*;
|
||||
import java.io.File;
|
||||
import java.math.BigDecimal;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.Timestamp;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import org.eevolution.model.*;
|
||||
import org.compiere.process.DocAction;
|
||||
import org.compiere.process.DocumentEngine;
|
||||
import org.compiere.util.DB;
|
||||
import org.compiere.util.Env;
|
||||
import org.compiere.util.Msg;
|
||||
import org.eevolution.model.MDDOrder;
|
||||
import org.eevolution.model.MDDOrderLine;
|
||||
/**
|
||||
* Inventory Movement Model
|
||||
*
|
||||
|
@ -439,7 +447,7 @@ public class MMovement extends X_M_Movement implements DocAction
|
|||
line.getM_Product_ID(), ma.getM_AttributeSetInstance_ID(), get_TrxName());
|
||||
//*/
|
||||
|
||||
MLocator locatorTo = new MLocator (getCtx(), line.getM_LocatorTo_ID(), get_TrxName());
|
||||
// MLocator locatorTo = new MLocator (getCtx(), line.getM_LocatorTo_ID(), get_TrxName());
|
||||
//Update Storage
|
||||
if (!MStorage.add(getCtx(),locator.getM_Warehouse_ID(),
|
||||
line.getM_LocatorTo_ID(),
|
||||
|
@ -530,7 +538,7 @@ public class MMovement extends X_M_Movement implements DocAction
|
|||
return DocAction.STATUS_Invalid;
|
||||
}
|
||||
|
||||
MLocator locatorTo = new MLocator (getCtx(), line.getM_LocatorTo_ID(), get_TrxName());
|
||||
// MLocator locatorTo = new MLocator (getCtx(), line.getM_LocatorTo_ID(), get_TrxName());
|
||||
//Update Storage
|
||||
if (!MStorage.add(getCtx(),locator.getM_Warehouse_ID(),
|
||||
line.getM_LocatorTo_ID(),
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/******************************************************************************
|
||||
* Product: Adempiere ERP & CRM Smart Business Solution *
|
||||
* 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 *
|
||||
|
@ -16,11 +16,19 @@
|
|||
*****************************************************************************/
|
||||
package org.compiere.model;
|
||||
|
||||
import java.math.*;
|
||||
import java.sql.*;
|
||||
import java.util.*;
|
||||
import java.util.logging.*;
|
||||
import org.compiere.util.*;
|
||||
import java.math.BigDecimal;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Timestamp;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Properties;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import org.compiere.util.CLogMgt;
|
||||
import org.compiere.util.CLogger;
|
||||
import org.compiere.util.DB;
|
||||
import org.compiere.util.Env;
|
||||
|
||||
/**
|
||||
* Inventory Storage Model
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/******************************************************************************
|
||||
* Product: Adempiere ERP & CRM Smart Business Solution *
|
||||
* 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 *
|
||||
|
|
Loading…
Reference in New Issue