use of org.compiere.model.MInOutConfirm in project adempiere by adempiere.
the class InOutCreateConfirm method doIt.
// prepare
/**
* Create Confirmation
* @return document no
* @throws Exception
*/
protected String doIt() throws Exception {
log.info("M_InOut_ID=" + p_M_InOut_ID + ", Type=" + p_ConfirmType);
MInOut shipment = new MInOut(getCtx(), p_M_InOut_ID, get_TrxName());
if (shipment.get_ID() == 0)
throw new IllegalArgumentException("Not found M_InOut_ID=" + p_M_InOut_ID);
//
MInOutConfirm confirm = MInOutConfirm.create(shipment, p_ConfirmType, true);
if (confirm == null)
throw new Exception("Cannot create Confirmation for " + shipment.getDocumentNo());
//
return confirm.getDocumentNo();
}
use of org.compiere.model.MInOutConfirm 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.MInOutConfirm in project adempiere by adempiere.
the class CPOS method completeReturn.
/**
* Complete return material
* @param trxName
* @return String error Message
*/
private String completeReturn(String trxName) {
if (isDrafted() || isInProgress() || isInvalid()) {
if (!processOrder(trxName, false, false)) {
return Msg.parseTranslation(getCtx(), " @ProcessRunError@. " + "@order.no@: " + getDocumentNo() + ". @Process@: " + CommandManager.COMPLETE_DOCUMENT);
}
// For certain documents, there is no further processing
String docSubTypeSO = getDocSubTypeSO();
if ((docSubTypeSO.equals(MOrder.DocSubTypeSO_Standard) || docSubTypeSO.equals(MOrder.DocSubTypeSO_OnCredit) || docSubTypeSO.equals(MOrder.DocSubTypeSO_Warehouse)) && isCompleted())
return "@POS.IsNotReturn@";
}
// Create
MOrder returnOrder = new MOrder(getCtx(), getC_Order_ID(), trxName);
returnOrder.setInvoiceRule(MOrder.INVOICERULE_Immediate);
returnOrder.setDeliveryRule(MOrder.DELIVERYRULE_Force);
returnOrder.saveEx();
List<Integer> selectionIds = new ArrayList<Integer>();
selectionIds.add(returnOrder.get_ID());
//Generate Return using InOutGenerate
ProcessInfo processInfo = ProcessBuilder.create(getCtx()).process(199).withParameter(MOrder.COLUMNNAME_M_Warehouse_ID, getM_Warehouse_ID()).withParameter("Selection", true).withSelectedRecordsIds(selectionIds).withoutTransactionClose().execute(trxName);
if (processInfo.isError()) {
return processInfo.getLogInfo();
}
//Force the confirmation
for (MInOut customerReturn : returnOrder.getShipments()) {
customerReturn.processIt(DocAction.ACTION_Complete);
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();
}
}
MOrder sourceOrder = (MOrder) returnOrder.getRef_Order();
if (sourceOrder != null && returnOrder.getC_Order_ID() > 0) {
if (sourceOrder.getInvoices().length > 0) {
//Generate Credit note InvoiceGenerate
processInfo = ProcessBuilder.create(getCtx()).process(134).withTitle(processInfo.getTitle()).withParameter("Selection", true).withSelectedRecordsIds(selectionIds).withParameter(MInvoice.COLUMNNAME_DocAction, MInvoice.DOCACTION_Complete).withoutTransactionClose().execute(trxName);
// Validate Error
if (processInfo.isError()) {
return processInfo.getLogInfo();
}
} else // if not exist invoice then return of payment
{
Timestamp today = new Timestamp(System.currentTimeMillis());
// Create return payment
MPayment payment = new MPayment(returnOrder.getCtx(), 0, returnOrder.get_TrxName());
payment.setDateTrx(today);
payment.setC_Order_ID(returnOrder.getC_Order_ID());
payment.setC_BankAccount_ID(getC_BankAccount_ID());
payment.setDateAcct(today);
payment.addDescription(Msg.parseTranslation(returnOrder.getCtx(), " @C_Order_ID@ " + returnOrder.getDocumentNo()));
payment.setIsReceipt(false);
payment.setC_DocType_ID(MDocType.getDocType(MDocType.DOCBASETYPE_APPayment));
payment.setAmount(returnOrder.getC_Currency_ID(), returnOrder.getGrandTotal());
payment.setDocAction(DocAction.ACTION_Complete);
payment.setDocStatus(DocAction.STATUS_Drafted);
payment.setIsPrepayment(true);
payment.saveEx();
payment.processIt(DocAction.ACTION_Complete);
payment.saveEx();
returnOrder.setC_POS_ID(getC_POS_ID());
returnOrder.saveEx();
processInfo.addLog(0, null, null, payment.getDocumentInfo());
}
}
setIsToPrint(true);
// Default return
return null;
}
Aggregations