use of org.compiere.model.MInOut in project adempiere by adempiere.
the class SB_InvoiceGenerateFromOrderLine method generate.
// doIt
/**
* Generate Shipments
* @param pstmt order query
* @return info
*/
private String generate(MOrder order) {
try {
{
// New Invoice Location
if (!p_ConsolidateDocument || (m_invoice != null && m_invoice.getC_BPartner_Location_ID() != order.getBill_Location_ID()))
completeInvoice();
boolean completeOrder = MOrder.INVOICERULE_AfterOrderDelivered.equals(order.getInvoiceRule());
// Schedule After Delivery
boolean doInvoice = false;
if (MOrder.INVOICERULE_CustomerScheduleAfterDelivery.equals(order.getInvoiceRule())) {
m_bp = new MBPartner(getCtx(), order.getBill_BPartner_ID(), null);
if (m_bp.getC_InvoiceSchedule_ID() == 0) {
log.warning("BPartner has no Schedule - set to After Delivery");
order.setInvoiceRule(MOrder.INVOICERULE_AfterDelivery);
order.saveEx();
} else {
MInvoiceSchedule is = MInvoiceSchedule.get(getCtx(), m_bp.getC_InvoiceSchedule_ID(), get_TrxName());
if (is.canInvoice(order.getDateOrdered(), order.getGrandTotal()))
doInvoice = true;
else
return "";
}
}
// After Delivery
if (doInvoice || MOrder.INVOICERULE_AfterDelivery.equals(order.getInvoiceRule())) {
MInOut[] shipments = order.getShipments();
for (int i = 0; i < shipments.length; i++) {
MInOut ship = shipments[i];
if (// ignore incomplete or reversals
!ship.isComplete() || ship.getDocStatus().equals(MInOut.DOCSTATUS_Reversed))
continue;
MInOutLine[] shipLines = ship.getLines(false);
for (int j = 0; j < shipLines.length; j++) {
MInOutLine shipLine = shipLines[j];
if (!order.isOrderLine(shipLine.getC_OrderLine_ID()))
continue;
if (!getSelectionKeys().contains(shipLine.getC_OrderLine_ID()))
continue;
if (!shipLine.isInvoiced())
createLine(order, ship, shipLine);
}
m_line += 1000;
}
} else // After Order Delivered, Immediate
{
MOrderLine[] oLines = order.getLines(true, null);
for (int i = 0; i < oLines.length; i++) {
MOrderLine oLine = oLines[i];
if (!getSelectionKeys().contains(oLine.getC_OrderLine_ID()))
continue;
BigDecimal toInvoice = oLine.getQtyOrdered().subtract(oLine.getQtyInvoiced());
if (toInvoice.compareTo(Env.ZERO) == 0 && oLine.getM_Product_ID() != 0)
continue;
BigDecimal notInvoicedShipment = oLine.getQtyDelivered().subtract(oLine.getQtyInvoiced());
//
boolean fullyDelivered = oLine.getQtyOrdered().compareTo(oLine.getQtyDelivered()) == 0;
// Complete Order
if (completeOrder && !fullyDelivered) {
log.fine("Failed CompleteOrder - " + oLine);
// Elaine 2008/11/25
addLog("Failed CompleteOrder - " + oLine);
completeOrder = false;
break;
} else // Immediate
if (MOrder.INVOICERULE_Immediate.equals(order.getInvoiceRule())) {
log.fine("Immediate - ToInvoice=" + toInvoice + " - " + oLine);
BigDecimal qtyEntered = toInvoice;
if (oLine.getQtyEntered().compareTo(oLine.getQtyOrdered()) != 0)
qtyEntered = toInvoice.multiply(oLine.getQtyEntered()).divide(oLine.getQtyOrdered(), 12, BigDecimal.ROUND_HALF_UP);
createLine(order, oLine, toInvoice, qtyEntered);
} else {
log.fine("Failed: " + order.getInvoiceRule() + " - ToInvoice=" + toInvoice + " - " + oLine);
addLog("Failed: " + order.getInvoiceRule() + " - ToInvoice=" + toInvoice + " - " + oLine);
}
}
// for all order lines
if (MOrder.INVOICERULE_Immediate.equals(order.getInvoiceRule()))
m_line += 1000;
}
// Complete Order successful
if (completeOrder && MOrder.INVOICERULE_AfterOrderDelivered.equals(order.getInvoiceRule())) {
MInOut[] shipments = order.getShipments();
for (int i = 0; i < shipments.length; i++) {
MInOut ship = shipments[i];
if (// ignore incomplete or reversals
!ship.isComplete() || ship.getDocStatus().equals(MInOut.DOCSTATUS_Reversed))
continue;
MInOutLine[] shipLines = ship.getLines(false);
for (int j = 0; j < shipLines.length; j++) {
MInOutLine shipLine = shipLines[j];
if (!order.isOrderLine(shipLine.getC_OrderLine_ID()))
continue;
if (!shipLine.isInvoiced())
createLine(order, ship, shipLine);
}
m_line += 1000;
}
}
// complete Order
}
// for all orders
} catch (Exception e) {
log.log(Level.SEVERE, "", e);
}
completeInvoice();
return "@Created@ = " + m_created;
}
use of org.compiere.model.MInOut in project adempiere by adempiere.
the class InOutGenerateRMA method createShipment.
private MInOut createShipment(MRMA rma) {
int docTypeId = getShipmentDocTypeId(rma.get_ID());
if (docTypeId == -1) {
throw new IllegalStateException("Could not get invoice document type for Vendor RMA");
}
MInOut originalReceipt = rma.getShipment();
MInOut shipment = new MInOut(getCtx(), 0, get_TrxName());
shipment.setM_RMA_ID(rma.get_ID());
shipment.setAD_Org_ID(rma.getAD_Org_ID());
shipment.setAD_OrgTrx_ID(originalReceipt.getAD_OrgTrx_ID());
shipment.setDescription(rma.getDescription());
shipment.setC_BPartner_ID(rma.getC_BPartner_ID());
shipment.setC_BPartner_Location_ID(originalReceipt.getC_BPartner_Location_ID());
shipment.setIsSOTrx(rma.isSOTrx());
shipment.setC_DocType_ID(docTypeId);
shipment.setM_Warehouse_ID(originalReceipt.getM_Warehouse_ID());
shipment.setMovementType(MInOut.MOVEMENTTYPE_VendorReturns);
shipment.setC_Project_ID(originalReceipt.getC_Project_ID());
shipment.setC_Campaign_ID(originalReceipt.getC_Campaign_ID());
shipment.setC_Activity_ID(originalReceipt.getC_Activity_ID());
shipment.setUser1_ID(originalReceipt.getUser1_ID());
shipment.setUser2_ID(originalReceipt.getUser2_ID());
shipment.setUser3_ID(originalReceipt.getUser3_ID());
shipment.setUser4_ID(originalReceipt.getUser4_ID());
if (!shipment.save()) {
throw new IllegalStateException("Could not create Shipment");
}
return shipment;
}
use of org.compiere.model.MInOut in project adempiere by adempiere.
the class CreateFromShipment method save.
/**
* Save - Create Invoice Lines
* @return true if saved
*/
public boolean save(IMiniTable miniTable, String trxName) {
/*
dataTable.stopEditor(true);
log.config("");
TableModel model = dataTable.getModel();
int rows = model.getRowCount();
if (rows == 0)
return false;
//
Integer defaultLoc = (Integer) locatorField.getValue();
if (defaultLoc == null || defaultLoc.intValue() == 0) {
locatorField.setBackground(AdempierePLAF.getFieldBackground_Error());
return false;
}
*/
int M_Locator_ID = defaultLocator_ID;
if (M_Locator_ID == 0) {
return false;
}
// Get Shipment
MInOut inout = new MInOut(Env.getCtx(), m_Record_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
// Qty
BigDecimal QtyEntered = (BigDecimal) miniTable.getValueAt(i, 1);
// UOM
KeyNamePair pp = (KeyNamePair) miniTable.getValueAt(i, 2);
int C_UOM_ID = pp.getKey();
// Locator
pp = (KeyNamePair) miniTable.getValueAt(i, 3);
// 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;
// Product
pp = (KeyNamePair) miniTable.getValueAt(i, 4);
int M_Product_ID = pp.getKey();
int C_OrderLine_ID = 0;
// OrderLine
pp = (KeyNamePair) miniTable.getValueAt(i, 6);
if (pp != null)
C_OrderLine_ID = pp.getKey();
int M_RMALine_ID = 0;
// RMA
pp = (KeyNamePair) miniTable.getValueAt(i, 7);
// If we have RMA
if (pp != null)
M_RMALine_ID = pp.getKey();
int C_InvoiceLine_ID = 0;
MInvoiceLine il = null;
// InvoiceLine
pp = (KeyNamePair) miniTable.getValueAt(i, 8);
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);
// Line UOM
iol.setM_Product_ID(M_Product_ID, C_UOM_ID);
// Movement/Entered
iol.setQty(QtyEntered);
//
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());
iol.setUser3_ID(ol.getUser3_ID());
iol.setUser4_ID(ol.getUser4_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());
iol.setUser3_ID(il.getUser3_ID());
iol.setUser4_ID(il.getUser4_ID());
} else 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());
iol.setUser3_ID(rmal.getUser3_ID());
iol.setUser4_ID(rmal.getUser4_ID());
}
// Charge
if (M_Product_ID == 0) {
if (// from order
ol != null && ol.getC_Charge_ID() != 0)
iol.setC_Charge_ID(ol.getC_Charge_ID());
else if (// from invoice
il != null && il.getC_Charge_ID() != 0)
iol.setC_Charge_ID(il.getC_Charge_ID());
else if (// from rma
rmal != null && rmal.getC_Charge_ID() != 0)
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);
else // Create Invoice Line Link
if (il != null) {
il.setM_InOutLine_ID(iol.getM_InOutLine_ID());
il.saveEx();
}
}
// if selected
}
/**
* 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());
inout.setUser3_ID(p_order.getUser3_ID());
inout.setUser4_ID(p_order.getUser4_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());
inout.setUser3_ID(m_invoice.getUser3_ID());
inout.setUser4_ID(m_invoice.getUser4_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.setUser3_ID(originalIO.getUser3_ID());
inout.setUser4_ID(originalIO.getUser4_ID());
}
inout.saveEx();
return true;
}
use of org.compiere.model.MInOut in project adempiere by adempiere.
the class CreateFromInvoice method getShipmentData.
/**
* Load Data - Shipment not invoiced
* @param M_InOut_ID InOut
*/
protected Vector<Vector<Object>> getShipmentData(int M_InOut_ID) {
log.config("M_InOut_ID=" + M_InOut_ID);
MInOut inout = new MInOut(Env.getCtx(), M_InOut_ID, null);
p_order = null;
if (inout.getC_Order_ID() != 0)
p_order = new MOrder(Env.getCtx(), inout.getC_Order_ID(), null);
m_rma = null;
if (inout.getM_RMA_ID() != 0)
m_rma = new MRMA(Env.getCtx(), inout.getM_RMA_ID(), null);
//
Vector<Vector<Object>> data = new Vector<Vector<Object>>();
StringBuffer sql = new StringBuffer(// QtyEntered
"SELECT " + "l.MovementQty-SUM(NVL(mi.Qty, 0)), l.QtyEntered/l.MovementQty," + // 3..4
" l.C_UOM_ID, COALESCE(uom.UOMSymbol, uom.Name)," + // 5..9
" l.M_Product_ID, p.Name, po.VendorProductNo, l.M_InOutLine_ID, l.Line," + // 10
" l.C_OrderLine_ID " + " FROM M_InOutLine l ");
if (Env.isBaseLanguage(Env.getCtx(), "C_UOM"))
sql.append(" LEFT OUTER JOIN C_UOM uom ON (l.C_UOM_ID=uom.C_UOM_ID)");
else
sql.append(" LEFT OUTER JOIN C_UOM_Trl uom ON (l.C_UOM_ID=uom.C_UOM_ID AND uom.AD_Language='").append(Env.getAD_Language(Env.getCtx())).append("')");
sql.append(" LEFT OUTER JOIN M_Product p ON (l.M_Product_ID=p.M_Product_ID)").append(" INNER JOIN M_InOut io ON (l.M_InOut_ID=io.M_InOut_ID)").append(" LEFT OUTER JOIN M_Product_PO po ON (l.M_Product_ID = po.M_Product_ID AND io.C_BPartner_ID = po.C_BPartner_ID)").append(" LEFT OUTER JOIN M_MatchInv mi ON (l.M_InOutLine_ID=mi.M_InOutLine_ID)").append(" WHERE l.M_InOut_ID=? AND l.MovementQty<>0 ").append("GROUP BY l.MovementQty, l.QtyEntered/l.MovementQty, " + "l.C_UOM_ID, COALESCE(uom.UOMSymbol, uom.Name), " + "l.M_Product_ID, p.Name, po.VendorProductNo, l.M_InOutLine_ID, l.Line, l.C_OrderLine_ID ").append("ORDER BY l.Line");
try {
PreparedStatement pstmt = DB.prepareStatement(sql.toString(), null);
pstmt.setInt(1, M_InOut_ID);
ResultSet rs = pstmt.executeQuery();
while (rs.next()) {
Vector<Object> line = new Vector<Object>(7);
// 0-Selection
line.add(new Boolean(false));
BigDecimal qtyMovement = rs.getBigDecimal(1);
BigDecimal multiplier = rs.getBigDecimal(2);
BigDecimal qtyEntered = qtyMovement.multiply(multiplier);
// 1-Qty
line.add(qtyEntered);
KeyNamePair pp = new KeyNamePair(rs.getInt(3), rs.getString(4).trim());
// 2-UOM
line.add(pp);
pp = new KeyNamePair(rs.getInt(5), rs.getString(6));
// 3-Product
line.add(pp);
// 4-VendorProductNo
line.add(rs.getString(7));
int C_OrderLine_ID = rs.getInt(10);
if (rs.wasNull())
// 5-Order
line.add(null);
else
line.add(new KeyNamePair(C_OrderLine_ID, "."));
pp = new KeyNamePair(rs.getInt(8), rs.getString(9));
// 6-Ship
line.add(pp);
// 7-RMA
line.add(null);
data.add(line);
}
rs.close();
pstmt.close();
} catch (SQLException e) {
log.log(Level.SEVERE, sql.toString(), e);
}
return data;
}
use of org.compiere.model.MInOut in project adempiere by adempiere.
the class WebInfo method getShipments.
// getOrder
/**
* Get Shipments
* @return shipments of BP
*/
public ArrayList<MInOut> getShipments() {
m_infoMessage = null;
ArrayList<MInOut> list = new ArrayList<MInOut>();
if (m_wu != null && !m_wu.hasBPAccess(X_AD_UserBPAccess.BPACCESSTYPE_BusinessDocuments, new Object[] { MDocType.DOCBASETYPE_MaterialReceipt, MDocType.DOCBASETYPE_MaterialDelivery })) {
log.info("No Access");
return list;
}
String sql = "SELECT * FROM M_InOut WHERE C_BPartner_ID=?" + " AND DocStatus NOT IN ('DR','IN') " + " ORDER BY DocumentNo DESC";
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
pstmt = DB.prepareStatement(sql, null);
pstmt.setInt(1, getC_BPartner_ID());
rs = pstmt.executeQuery();
while (rs.next()) list.add(new MInOut(m_ctx, rs, null));
} catch (Exception e) {
log.log(Level.SEVERE, sql, e);
} finally {
DB.close(rs, pstmt);
rs = null;
pstmt = null;
}
log.fine("#" + list.size());
return list;
}
Aggregations