if (M_Locator_ID == 0) {
return false;
}
// Get Shipment
int M_InOut_ID = ((Integer) getGridTab().getValue("M_InOut_ID")).intValue();
MInOut inout = new MInOut(Env.getCtx(), M_InOut_ID, trxName);
log.config(inout + ", C_Locator_ID=" + M_Locator_ID);
// Lines
for (int i = 0; i < miniTable.getRowCount(); i++)
{
if (((Boolean)miniTable.getValueAt(i, 0)).booleanValue()) {
// variable values
BigDecimal QtyEntered = (BigDecimal) miniTable.getValueAt(i, 1); // Qty
KeyNamePair pp = (KeyNamePair) miniTable.getValueAt(i, 2); // UOM
int C_UOM_ID = pp.getKey();
pp = (KeyNamePair) miniTable.getValueAt(i, 3); // Locator
// If a locator is specified on the product, choose that otherwise default locator
M_Locator_ID = pp!=null && pp.getKey()!=0 ? pp.getKey() : defaultLocator_ID;
pp = (KeyNamePair) miniTable.getValueAt(i, 4); // Product
int M_Product_ID = pp.getKey();
int C_OrderLine_ID = 0;
pp = (KeyNamePair) miniTable.getValueAt(i, 6); // OrderLine
if (pp != null)
C_OrderLine_ID = pp.getKey();
int M_RMALine_ID = 0;
pp = (KeyNamePair) miniTable.getValueAt(i, 7); // RMA
// If we have RMA
if (pp != null)
M_RMALine_ID = pp.getKey();
int C_InvoiceLine_ID = 0;
MInvoiceLine il = null;
pp = (KeyNamePair) miniTable.getValueAt(i, 8); // InvoiceLine
if (pp != null)
C_InvoiceLine_ID = pp.getKey();
if (C_InvoiceLine_ID != 0)
il = new MInvoiceLine (Env.getCtx(), C_InvoiceLine_ID, trxName);
//boolean isInvoiced = (C_InvoiceLine_ID != 0);
// Precision of Qty UOM
int precision = 2;
if (M_Product_ID != 0)
{
MProduct product = MProduct.get(Env.getCtx(), M_Product_ID);
precision = product.getUOMPrecision();
}
QtyEntered = QtyEntered.setScale(precision, BigDecimal.ROUND_HALF_DOWN);
//
log.fine("Line QtyEntered=" + QtyEntered
+ ", Product=" + M_Product_ID
+ ", OrderLine=" + C_OrderLine_ID + ", InvoiceLine=" + C_InvoiceLine_ID);
// Credit Memo - negative Qty
if (m_invoice != null && m_invoice.isCreditMemo() )
QtyEntered = QtyEntered.negate();
// Create new InOut Line
MInOutLine iol = new MInOutLine (inout);
iol.setM_Product_ID(M_Product_ID, C_UOM_ID); // Line UOM
iol.setQty(QtyEntered); // Movement/Entered
//
MOrderLine ol = null;
MRMALine rmal = null;
if (C_OrderLine_ID != 0)
{
iol.setC_OrderLine_ID(C_OrderLine_ID);
ol = new MOrderLine (Env.getCtx(), C_OrderLine_ID, trxName);
if (ol.getQtyEntered().compareTo(ol.getQtyOrdered()) != 0)
{
iol.setMovementQty(QtyEntered
.multiply(ol.getQtyOrdered())
.divide(ol.getQtyEntered(), 12, BigDecimal.ROUND_HALF_UP));
iol.setC_UOM_ID(ol.getC_UOM_ID());
}
iol.setM_AttributeSetInstance_ID(ol.getM_AttributeSetInstance_ID());
iol.setDescription(ol.getDescription());
//
iol.setC_Project_ID(ol.getC_Project_ID());
iol.setC_ProjectPhase_ID(ol.getC_ProjectPhase_ID());
iol.setC_ProjectTask_ID(ol.getC_ProjectTask_ID());
iol.setC_Activity_ID(ol.getC_Activity_ID());
iol.setC_Campaign_ID(ol.getC_Campaign_ID());
iol.setAD_OrgTrx_ID(ol.getAD_OrgTrx_ID());
iol.setUser1_ID(ol.getUser1_ID());
iol.setUser2_ID(ol.getUser2_ID());
}
else if (il != null)
{
if (il.getQtyEntered().compareTo(il.getQtyInvoiced()) != 0)
{
iol.setQtyEntered(QtyEntered
.multiply(il.getQtyInvoiced())
.divide(il.getQtyEntered(), 12, BigDecimal.ROUND_HALF_UP));
iol.setC_UOM_ID(il.getC_UOM_ID());
}
iol.setDescription(il.getDescription());
iol.setC_Project_ID(il.getC_Project_ID());
iol.setC_ProjectPhase_ID(il.getC_ProjectPhase_ID());
iol.setC_ProjectTask_ID(il.getC_ProjectTask_ID());
iol.setC_Activity_ID(il.getC_Activity_ID());
iol.setC_Campaign_ID(il.getC_Campaign_ID());
iol.setAD_OrgTrx_ID(il.getAD_OrgTrx_ID());
iol.setUser1_ID(il.getUser1_ID());
iol.setUser2_ID(il.getUser2_ID());
}
// 25-09-2009 rgliddon: Made following if block independent from the
// previous if-else block.
if (M_RMALine_ID != 0)
{
rmal = new MRMALine(Env.getCtx(), M_RMALine_ID, trxName);
iol.setM_RMALine_ID(M_RMALine_ID);
iol.setQtyEntered(QtyEntered);
iol.setDescription(rmal.getDescription());
iol.setM_AttributeSetInstance_ID(rmal.getM_AttributeSetInstance_ID());
iol.setC_Project_ID(rmal.getC_Project_ID());
iol.setC_ProjectPhase_ID(rmal.getC_ProjectPhase_ID());
iol.setC_ProjectTask_ID(rmal.getC_ProjectTask_ID());
iol.setC_Activity_ID(rmal.getC_Activity_ID());
iol.setAD_OrgTrx_ID(rmal.getAD_OrgTrx_ID());
iol.setUser1_ID(rmal.getUser1_ID());
iol.setUser2_ID(rmal.getUser2_ID());
}
// Charge
if (M_Product_ID == 0)
{
if (ol != null && ol.getC_Charge_ID() != 0) // from order
iol.setC_Charge_ID(ol.getC_Charge_ID());
else if (il != null && il.getC_Charge_ID() != 0) // from invoice
iol.setC_Charge_ID(il.getC_Charge_ID());
else if (rmal != null && rmal.getC_Charge_ID() != 0) // from rma
iol.setC_Charge_ID(rmal.getC_Charge_ID());
}
// Set locator
iol.setM_Locator_ID(M_Locator_ID);
if (!iol.save())
log.log(Level.SEVERE, "Line NOT created #" + i);
// Create Invoice Line Link
else if (il != null)
{
il.setM_InOutLine_ID(iol.getM_InOutLine_ID());
il.saveEx();
}
} // if selected
} // for all rows
/**
* Update Header
* - if linked to another order/invoice/rma - remove link
* - if no link set it
*/
if (p_order != null && p_order.getC_Order_ID() != 0)
{
inout.setC_Order_ID (p_order.getC_Order_ID());
inout.setAD_OrgTrx_ID(p_order.getAD_OrgTrx_ID());
inout.setC_Project_ID(p_order.getC_Project_ID());
inout.setC_Campaign_ID(p_order.getC_Campaign_ID());
inout.setC_Activity_ID(p_order.getC_Activity_ID());
inout.setUser1_ID(p_order.getUser1_ID());
inout.setUser2_ID(p_order.getUser2_ID());
if ( p_order.isDropShip() )
{
inout.setM_Warehouse_ID( p_order.getM_Warehouse_ID() );
inout.setIsDropShip(p_order.isDropShip());
inout.setDropShip_BPartner_ID(p_order.getDropShip_BPartner_ID());
inout.setDropShip_Location_ID(p_order.getDropShip_Location_ID());
inout.setDropShip_User_ID(p_order.getDropShip_User_ID());
}
}
if (m_invoice != null && m_invoice.getC_Invoice_ID() != 0)
{
if (inout.getC_Order_ID() == 0)
inout.setC_Order_ID (m_invoice.getC_Order_ID());
inout.setC_Invoice_ID (m_invoice.getC_Invoice_ID());
inout.setAD_OrgTrx_ID(m_invoice.getAD_OrgTrx_ID());
inout.setC_Project_ID(m_invoice.getC_Project_ID());
inout.setC_Campaign_ID(m_invoice.getC_Campaign_ID());
inout.setC_Activity_ID(m_invoice.getC_Activity_ID());
inout.setUser1_ID(m_invoice.getUser1_ID());
inout.setUser2_ID(m_invoice.getUser2_ID());
}
if (m_rma != null && m_rma.getM_RMA_ID() != 0)
{
MInOut originalIO = m_rma.getShipment();
inout.setIsSOTrx(m_rma.isSOTrx());
inout.setC_Order_ID(0);
inout.setC_Invoice_ID(0);
inout.setM_RMA_ID(m_rma.getM_RMA_ID());
inout.setAD_OrgTrx_ID(originalIO.getAD_OrgTrx_ID());
inout.setC_Project_ID(originalIO.getC_Project_ID());
inout.setC_Campaign_ID(originalIO.getC_Campaign_ID());
inout.setC_Activity_ID(originalIO.getC_Activity_ID());
inout.setUser1_ID(originalIO.getUser1_ID());
inout.setUser2_ID(originalIO.getUser2_ID());
}
inout.saveEx();
return true;
} // saveInvoice