use of org.compiere.model.MRMALine in project adempiere by adempiere.
the class CreateFromRMA method save.
/**
* Save Record
* @param miniTable
* @param trxName
* @return
*/
public boolean save(IMiniTable miniTable, String trxName) {
log.config("");
// Integer bpId = (Integer)bPartnerField.getValue();
MRMA rma = new MRMA(Env.getCtx(), m_Record_ID, trxName);
for (int i = 0; i < miniTable.getRowCount(); i++) {
if (((Boolean) miniTable.getValueAt(i, 0)).booleanValue()) {
// 5-Movement Qty
BigDecimal d = (BigDecimal) miniTable.getValueAt(i, 5);
// 1-Line
KeyNamePair pp = (KeyNamePair) miniTable.getValueAt(i, 1);
int inOutLineId = pp.getKey();
MRMALine rmaLine = new MRMALine(rma.getCtx(), 0, rma.get_TrxName());
rmaLine.setM_RMA_ID(m_Record_ID);
rmaLine.setM_InOutLine_ID(inOutLineId);
rmaLine.setQty(d);
rmaLine.setAD_Org_ID(rma.getAD_Org_ID());
if (!rmaLine.save()) {
throw new IllegalStateException("Could not create RMA Line");
}
}
}
rma.saveEx();
return true;
}
use of org.compiere.model.MRMALine in project adempiere by adempiere.
the class LiberoValidator method updateMPPOrder.
// getAD_Client_ID
private void updateMPPOrder(MInOutLine outline) {
MPPOrder order = null;
BigDecimal qtyShipment = Env.ZERO;
MInOut inout = outline.getParent();
String movementType = inout.getMovementType();
int orderLineId = 0;
if (MInOut.MOVEMENTTYPE_CustomerShipment.equals(movementType)) {
orderLineId = outline.getC_OrderLine_ID();
qtyShipment = outline.getMovementQty();
} else if (MInOut.MOVEMENTTYPE_CustomerReturns.equals(movementType)) {
MRMALine rmaline = new MRMALine(outline.getCtx(), outline.getM_RMALine_ID(), null);
MInOutLine line = (MInOutLine) rmaline.getM_InOutLine();
orderLineId = line.getC_OrderLine_ID();
qtyShipment = outline.getMovementQty().negate();
}
final String whereClause = " C_OrderLine_ID = ? " + " AND DocStatus IN (?,?)" + " AND EXISTS (SELECT 1 FROM PP_Order_BOM " + " WHERE PP_Order_BOM.PP_Order_ID=PP_Order.PP_Order_ID AND PP_Order_BOM.BOMType =? )";
order = new Query(outline.getCtx(), MPPOrder.Table_Name, whereClause, outline.get_TrxName()).setParameters(orderLineId, MPPOrder.DOCSTATUS_InProgress, MPPOrder.DOCSTATUS_Completed, MPPOrderBOM.BOMTYPE_Make_To_Kit).firstOnly();
if (order == null || order.get_ID() <= 0)
return;
if (MPPOrder.DOCSTATUS_InProgress.equals(order.getDocStatus())) {
order.completeIt();
order.setDocStatus(MPPOrder.ACTION_Complete);
order.setDocAction(MPPOrder.DOCACTION_Close);
order.saveEx();
}
if (MPPOrder.DOCSTATUS_Completed.equals(order.getDocStatus())) {
String description = order.getDescription() != null ? order.getDescription() : "" + Msg.translate(inout.getCtx(), MInOut.COLUMNNAME_M_InOut_ID) + " : " + Msg.translate(inout.getCtx(), MInOut.COLUMNNAME_DocumentNo);
order.setDescription(description);
order.updateMakeToKit(qtyShipment);
order.saveEx();
}
if (order.getQtyToDeliver().signum() == 0) {
order.closeIt();
order.setDocStatus(MPPOrder.DOCACTION_Close);
order.setDocAction(MPPOrder.DOCACTION_None);
order.saveEx();
}
return;
}
use of org.compiere.model.MRMALine in project adempiere by adempiere.
the class InOutCreateFrom method doIt.
@Override
protected String doIt() throws Exception {
// Valid Record Identifier
if (getRecord_ID() == 0)
return "";
AtomicInteger referenceId = new AtomicInteger(0);
AtomicInteger created = new AtomicInteger(0);
// Get Shipment
MInOut inout = new MInOut(getCtx(), getRecord_ID(), get_TrxName());
log.config(inout + ", C_Locator_ID=" + getLocator());
// Get Default Locator
MLocator defaultLocator = MLocator.getDefault((MWarehouse) inout.getM_Warehouse());
List<Integer> recordIds = getSelectionKeys();
String createFromType = recordIds.size() > 0 ? getSelectionAsString(recordIds.get(0), "CF_CreateFromType") : null;
log.fine("CreateFromType=" + createFromType);
if (createFromType == null || createFromType.length() == 0)
throw new AdempiereException("@CreateFromType@ @NotFound@");
// Loop
recordIds.stream().forEach(key -> {
int productId = getSelectionAsInt(key, "CF_M_Product_ID");
int chargeId = getSelectionAsInt(key, "CF_C_Charge_ID");
int uomId = getSelectionAsInt(key, "CF_C_UOM_ID");
int locatorId = getSelectionAsInt(key, "CF_M_Locator_ID");
BigDecimal qtyEntered = getSelectionAsBigDecimal(key, "CF_QtyEntered");
locatorId = getValidLocator(locatorId, defaultLocator);
MInvoiceLine invoiceLine = null;
int precision = 2;
if (productId != 0) {
MProduct product = MProduct.get(getCtx(), productId);
precision = product.getUOMPrecision();
}
qtyEntered = qtyEntered.setScale(precision, BigDecimal.ROUND_HALF_DOWN);
log.fine("Line QtyEntered=" + qtyEntered + ", Product=" + productId + ", Key=" + key);
MInOutLine inOutLine = new MInOutLine(inout);
inOutLine.setM_Product_ID(productId, uomId);
inOutLine.setQty(qtyEntered);
if (createFromType.equals(ORDER)) {
MOrderLine orderLine = new MOrderLine(getCtx(), key, get_TrxName());
referenceId.set(orderLine.getC_Order_ID());
inOutLine.setC_OrderLine_ID(key);
if (orderLine.getQtyEntered().compareTo(orderLine.getQtyOrdered()) != 0) {
inOutLine.setMovementQty(qtyEntered.multiply(orderLine.getQtyOrdered()).divide(orderLine.getQtyEntered(), 12, BigDecimal.ROUND_HALF_UP));
inOutLine.setC_UOM_ID(orderLine.getC_UOM_ID());
}
inOutLine.setM_AttributeSetInstance_ID(orderLine.getM_AttributeSetInstance_ID());
inOutLine.setDescription(orderLine.getDescription());
inOutLine.setC_Project_ID(orderLine.getC_Project_ID());
inOutLine.setC_ProjectPhase_ID(orderLine.getC_ProjectPhase_ID());
inOutLine.setC_ProjectTask_ID(orderLine.getC_ProjectTask_ID());
inOutLine.setC_Activity_ID(orderLine.getC_Activity_ID());
inOutLine.setC_Campaign_ID(orderLine.getC_Campaign_ID());
inOutLine.setAD_OrgTrx_ID(orderLine.getAD_OrgTrx_ID());
inOutLine.setUser1_ID(orderLine.getUser1_ID());
inOutLine.setUser2_ID(orderLine.getUser2_ID());
inOutLine.setUser3_ID(orderLine.getUser3_ID());
inOutLine.setUser4_ID(orderLine.getUser4_ID());
} else if (createFromType.equals(INVOICE)) {
invoiceLine = new MInvoiceLine(getCtx(), key, get_TrxName());
MInvoice invoice = invoiceLine.getParent();
referenceId.getAndSet(invoice.getC_Invoice_ID());
if (invoice.isCreditMemo()) {
qtyEntered = qtyEntered.negate();
inOutLine.setQty(qtyEntered);
}
if (invoiceLine.getQtyEntered().compareTo(invoiceLine.getQtyInvoiced()) != 0) {
inOutLine.setMovementQty(qtyEntered.multiply(invoiceLine.getQtyInvoiced()).divide(invoiceLine.getQtyEntered(), 12, BigDecimal.ROUND_HALF_UP));
inOutLine.setC_UOM_ID(invoiceLine.getC_UOM_ID());
}
inOutLine.setDescription(invoiceLine.getDescription());
inOutLine.setC_Project_ID(invoiceLine.getC_Project_ID());
inOutLine.setC_ProjectPhase_ID(invoiceLine.getC_ProjectPhase_ID());
inOutLine.setC_ProjectTask_ID(invoiceLine.getC_ProjectTask_ID());
inOutLine.setC_Activity_ID(invoiceLine.getC_Activity_ID());
inOutLine.setC_Campaign_ID(invoiceLine.getC_Campaign_ID());
inOutLine.setAD_OrgTrx_ID(invoiceLine.getAD_OrgTrx_ID());
inOutLine.setUser1_ID(invoiceLine.getUser1_ID());
inOutLine.setUser2_ID(invoiceLine.getUser2_ID());
inOutLine.setUser3_ID(invoiceLine.getUser3_ID());
inOutLine.setUser4_ID(invoiceLine.getUser4_ID());
} else if (createFromType.equals(RMA)) {
MRMALine rmal = new MRMALine(getCtx(), key, get_TrxName());
referenceId.set(rmal.getM_RMA_ID());
inOutLine.setM_RMALine_ID(key);
inOutLine.setQtyEntered(qtyEntered);
inOutLine.setDescription(rmal.getDescription());
inOutLine.setM_AttributeSetInstance_ID(rmal.getM_AttributeSetInstance_ID());
inOutLine.setC_Project_ID(rmal.getC_Project_ID());
inOutLine.setC_ProjectPhase_ID(rmal.getC_ProjectPhase_ID());
inOutLine.setC_ProjectTask_ID(rmal.getC_ProjectTask_ID());
inOutLine.setC_Activity_ID(rmal.getC_Activity_ID());
inOutLine.setAD_OrgTrx_ID(rmal.getAD_OrgTrx_ID());
inOutLine.setUser1_ID(rmal.getUser1_ID());
inOutLine.setUser2_ID(rmal.getUser2_ID());
inOutLine.setUser3_ID(rmal.getUser3_ID());
inOutLine.setUser4_ID(rmal.getUser4_ID());
}
if (chargeId != 0)
inOutLine.setC_Charge_ID(chargeId);
inOutLine.setM_Locator_ID(locatorId);
inOutLine.saveEx();
if (invoiceLine != null) {
invoiceLine.setM_InOutLine_ID(inOutLine.getM_InOutLine_ID());
invoiceLine.saveEx();
}
created.updateAndGet(createNo -> createNo + 1);
});
// Add reference to Order / Invoice / RMA
addReference(inout, createFromType, referenceId.get());
//
return "@Created@ " + created.get();
}
use of org.compiere.model.MRMALine in project adempiere by adempiere.
the class ReverseTheSalesTransaction method cancelShipments.
private void cancelShipments(MInOut[] sourceShipments) {
for (MInOut sourceShipment : sourceShipments) {
MRMA rma = new MRMA(getCtx(), 0, get_TrxName());
rma.setM_InOut_ID(sourceShipment.getM_InOut_ID());
rma.setAD_Org_ID(sourceShipment.getAD_Org_ID());
rma.setM_RMAType_ID(getRMATypeId());
rma.setC_BPartner_ID(sourceShipment.getC_BPartner_ID());
rma.setName(sourceShipment.getDocumentInfo());
rma.setIsSOTrx(true);
rma.setSalesRep_ID(sourceShipment.getSalesRep_ID());
rma.setC_DocType_ID(MDocType.getDocTypeBaseOnSubType(sourceShipment.getAD_Org_ID(), MDocType.DOCBASETYPE_SalesOrder, MDocType.DOCSUBTYPESO_ReturnMaterial));
rma.setDocStatus(DocAction.STATUS_Drafted);
rma.setDocAction(DocAction.ACTION_Complete);
rma.saveEx();
MInOut customerReturn = new MInOut(getCtx(), 0, get_TrxName());
PO.copyValues(sourceShipment, customerReturn);
customerReturn.setDocumentNo(null);
customerReturn.setM_RMA_ID(rma.getM_RMA_ID());
customerReturn.setIsSOTrx(true);
customerReturn.setC_BPartner_ID(sourceShipment.getC_BPartner_ID());
customerReturn.setC_Order_ID(-1);
for (MDocType documentType : MDocType.getOfDocBaseType(getCtx(), MDocType.DOCBASETYPE_MaterialReceipt)) if (documentType.isSOTrx())
customerReturn.setC_DocType_ID();
customerReturn.setMovementType(MInOut.MOVEMENTTYPE_CustomerReturns);
customerReturn.setDocStatus(DocAction.STATUS_Drafted);
customerReturn.setDocAction(DocAction.ACTION_Complete);
customerReturn.setProcessed(false);
customerReturn.saveEx();
for (MInOutLine sourceShipmentLine : sourceShipment.getLines()) {
MRMALine rmaLine = new MRMALine(getCtx(), 0, get_TrxName());
rmaLine.setM_RMA_ID(rma.getM_RMA_ID());
rmaLine.setAD_Org_ID(sourceShipmentLine.getAD_Org_ID());
rmaLine.setM_InOutLine_ID(sourceShipmentLine.getM_InOutLine_ID());
rmaLine.setQty(sourceShipmentLine.getMovementQty());
rmaLine.saveEx();
MInOutLine customerReturnLine = new MInOutLine(getCtx(), 0, get_TrxName());
customerReturnLine.setM_InOut_ID(customerReturn.getM_InOut_ID());
customerReturnLine.setM_RMALine_ID(rmaLine.getM_RMALine_ID());
customerReturnLine.setM_Product_ID(rmaLine.getM_Product_ID());
customerReturnLine.setM_Locator_ID(sourceShipmentLine.getM_Locator_ID());
customerReturnLine.setMovementQty(rmaLine.getQty());
customerReturnLine.saveEx();
}
rma.processIt(DocAction.ACTION_Complete);
rma.saveEx();
addLog(rma.getDocumentInfo());
if (customerReturn.getC_DocType().isShipConfirm() && isShipReceiptConfirmation()) {
customerReturn.processIt(DocAction.STATUS_InProgress);
customerReturn.saveEx();
for (MInOutConfirm confirm : customerReturn.getConfirmations(true)) {
for (MInOutLineConfirm confirmLine : confirm.getLines(true)) {
confirmLine.setConfirmedQty(confirmLine.getTargetQty());
confirmLine.saveEx();
}
confirm.processIt(DocAction.ACTION_Complete);
confirm.saveEx();
addLog(confirm.getDocumentInfo());
}
}
customerReturn.processIt(DocAction.STATUS_Completed);
customerReturn.saveEx();
addLog(customerReturn.getDocumentInfo());
customerReturns.add(customerReturn);
}
}
use of org.compiere.model.MRMALine in project adempiere by adempiere.
the class InvoiceCreateFrom method doIt.
@Override
protected String doIt() throws Exception {
// Valid Record Identifier
if (getRecord_ID() == 0)
return "";
// Get Shipment
MInvoice invoice = new MInvoice(getCtx(), getRecord_ID(), get_TrxName());
AtomicInteger referenceId = new AtomicInteger(0);
AtomicInteger created = new AtomicInteger(0);
List<Integer> recordIds = getSelectionKeys();
String createFromType = recordIds.size() > 0 ? getSelectionAsString(recordIds.get(0), "CF_CreateFromType") : null;
log.fine("CreateFromType=" + createFromType);
if (createFromType == null || createFromType.length() == 0)
throw new AdempiereException("@CreateFromType@ @NotFound@");
// Loop
recordIds.stream().forEach(key -> {
int productId = getSelectionAsInt(key, "CF_M_Product_ID");
int chargeId = getSelectionAsInt(key, "CF_C_Charge_ID");
int uomId = getSelectionAsInt(key, "CF_C_UOM_ID");
BigDecimal qtyEntered = getSelectionAsBigDecimal(key, "CF_QtyEntered");
log.fine("Line QtyEntered=" + qtyEntered + ", Product=" + productId + ", CreateFromType=" + createFromType + ", Key=" + key);
MInvoiceLine invoiceLine = new MInvoiceLine(invoice);
BigDecimal qtyInvoiced = null;
int precision = 2;
if (productId > 0) {
MProduct product = MProduct.get(Env.getCtx(), productId);
if (product != null) {
invoiceLine.setM_Product_ID(product.getM_Product_ID(), uomId);
precision = product.getUOMPrecision();
if (product.getC_UOM_ID() != uomId) {
qtyEntered = qtyEntered.setScale(precision, BigDecimal.ROUND_HALF_DOWN);
qtyInvoiced = MUOMConversion.convertProductFrom(Env.getCtx(), productId, uomId, qtyEntered);
}
}
} else if (chargeId != 0) {
invoiceLine.setC_Charge_ID(chargeId);
}
qtyEntered = qtyEntered.setScale(precision, BigDecimal.ROUND_HALF_DOWN);
if (qtyInvoiced == null)
qtyInvoiced = qtyEntered;
invoiceLine.setQty(qtyEntered);
invoiceLine.setQtyInvoiced(qtyInvoiced);
if (createFromType.equals(ORDER)) {
MOrderLine orderLine = new MOrderLine(getCtx(), key, get_TrxName());
referenceId.set(orderLine.getC_Order_ID());
String whereClause = "EXISTS (SELECT 1 " + "FROM M_InOut io " + "WHERE io.M_InOut_ID = M_InOutLine.M_InOut_ID " + "AND io.DocStatus IN ('CO','CL'))";
MInOutLine[] inOutLines = MInOutLine.getOfOrderLine(Env.getCtx(), key, whereClause, get_TrxName());
log.fine("Receipt Lines with OrderLine = #" + inOutLines.length);
final BigDecimal qty = qtyEntered;
MInOutLine inOutLine = Arrays.stream(inOutLines).filter(ioLine -> ioLine != null && ioLine.getQtyEntered().compareTo(qty) == 0).findFirst().orElse(inOutLines.length > 0 ? inOutLines[0] : null);
if (inOutLine != null)
invoiceLine.setShipLine(inOutLine);
else
invoiceLine.setOrderLine(orderLine);
} else if (createFromType.equals(INVOICE)) {
MInvoiceLine fromLine = new MInvoiceLine(getCtx(), key, get_TrxName());
referenceId.set(invoiceLine.getParent().getC_Invoice_ID());
PO.copyValues(fromLine, invoiceLine);
invoiceLine.setC_Invoice_ID(invoiceLine.getParent().getC_Invoice_ID());
invoiceLine.setAD_Org_ID(fromLine.getAD_Org_ID());
invoiceLine.setC_OrderLine_ID(0);
invoiceLine.setRef_InvoiceLine_ID(0);
invoiceLine.setM_InOutLine_ID(0);
invoiceLine.setA_Asset_ID(0);
invoiceLine.setM_AttributeSetInstance_ID(0);
invoiceLine.setS_ResourceAssignment_ID(0);
if (invoiceLine.getParent().getC_BPartner_ID() != fromLine.getC_Invoice().getC_BPartner_ID())
invoiceLine.setTax();
invoiceLine.setProcessed(false);
} else if (createFromType.equals(RMA)) {
MRMALine rmaLine = new MRMALine(getCtx(), key, get_TrxName());
referenceId.set(rmaLine.getM_RMA_ID());
invoiceLine.setRMALine(rmaLine);
} else if (createFromType.equals(RECEIPT)) {
MInOutLine inOutLine = new MInOutLine(getCtx(), key, get_TrxName());
referenceId.set(inOutLine.getM_InOut_ID());
invoiceLine.setShipLine(inOutLine);
}
invoiceLine.saveEx();
if (createFromType.equals(INVOICE)) {
MInvoiceLine fromLine = new MInvoiceLine(getCtx(), key, get_TrxName());
invoiceLine.copyLandedCostFrom(fromLine);
invoiceLine.allocateLandedCosts();
}
created.updateAndGet(createNo -> createNo + 1);
});
// Add reference to Order / Invoice / RMA
addReference(invoice, createFromType, referenceId.get());
return "@Created@ " + created.get();
}
Aggregations