Search in sources :

Example 1 with MInOutConfirm

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();
}
Also used : MInOut(org.compiere.model.MInOut) MInOutConfirm(org.compiere.model.MInOutConfirm)

Example 2 with MInOutConfirm

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);
    }
}
Also used : MInOut(org.compiere.model.MInOut) MDocType(org.compiere.model.MDocType) MInOutLine(org.compiere.model.MInOutLine) MInOutLineConfirm(org.compiere.model.MInOutLineConfirm) MRMALine(org.compiere.model.MRMALine) MInOutConfirm(org.compiere.model.MInOutConfirm) MRMA(org.compiere.model.MRMA)

Example 3 with MInOutConfirm

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;
}
Also used : MInOut(org.compiere.model.MInOut) MOrder(org.compiere.model.MOrder) MInOutLineConfirm(org.compiere.model.MInOutLineConfirm) MPayment(org.compiere.model.MPayment) ArrayList(java.util.ArrayList) ProcessInfo(org.compiere.process.ProcessInfo) MInOutConfirm(org.compiere.model.MInOutConfirm) Timestamp(java.sql.Timestamp)

Aggregations

MInOut (org.compiere.model.MInOut)3 MInOutConfirm (org.compiere.model.MInOutConfirm)3 MInOutLineConfirm (org.compiere.model.MInOutLineConfirm)2 Timestamp (java.sql.Timestamp)1 ArrayList (java.util.ArrayList)1 MDocType (org.compiere.model.MDocType)1 MInOutLine (org.compiere.model.MInOutLine)1 MOrder (org.compiere.model.MOrder)1 MPayment (org.compiere.model.MPayment)1 MRMA (org.compiere.model.MRMA)1 MRMALine (org.compiere.model.MRMALine)1 ProcessInfo (org.compiere.process.ProcessInfo)1