Search in sources :

Example 36 with MInOut

use of org.compiere.model.MInOut in project adempiere by adempiere.

the class GenerateShipmentOutBound method getShipment.

/**
	 * Create Shipment heder
	 * @param orderLine Sales Order Line
	 * @return MInOut return the Shipment header
	 */
private MInOut getShipment(MOrderLine orderLine) {
    MInOut shipment = shipments.get(orderLine.getC_Order_ID());
    if (shipment != null)
        return shipment;
    MOrder order = orderLine.getParent();
    int docTypeId = MDocType.getDocType(MDocType.DOCBASETYPE_MaterialDelivery, orderLine.getAD_Org_ID());
    shipment = new MInOut(order, docTypeId, getMovementDate());
    shipment.setIsSOTrx(true);
    shipment.saveEx();
    shipments.put(order.getC_Order_ID(), shipment);
    return shipment;
}
Also used : MInOut(org.compiere.model.MInOut) MOrder(org.compiere.model.MOrder)

Example 37 with MInOut

use of org.compiere.model.MInOut in project adempiere by adempiere.

the class ReverseTheSalesTransaction method cancelInvoices.

private void cancelInvoices() {
    for (MInOut customerReturn : customerReturns) {
        ProcessInfo processInfo = ProcessBuilder.create(getCtx()).process(// AD_Process_ID = 154
        "M_InOut_CreateInvoice").withTitle("Generate Invoice from Receipt").withRecordId(MInOut.Table_ID, customerReturn.getM_InOut_ID()).withoutTransactionClose().execute(get_TrxName());
        if (processInfo.isError()) {
            String errorMessage = Msg.parseTranslation(getCtx(), processInfo.getTitle() + " @ProcessRunError@ " + processInfo.getSummary() + " " + processInfo.getLogInfo());
            throw new AdempierePOSException(errorMessage);
        }
        addLog(processInfo.getLogInfo());
        for (MInvoice creditNote : getCreditNotes(customerReturn.getM_RMA_ID())) {
            if (creditNote != null && creditNote.getC_Invoice_ID() > 0) {
                creditNote.setDateInvoiced(today);
                creditNote.setDateAcct(today);
                creditNote.processIt(DocAction.ACTION_Complete);
                creditNote.saveEx();
                addLog(creditNote.getDocumentInfo());
            }
        }
    }
}
Also used : MInOut(org.compiere.model.MInOut) AdempierePOSException(org.adempiere.pos.AdempierePOSException) MInvoice(org.compiere.model.MInvoice) ProcessInfo(org.compiere.process.ProcessInfo)

Example 38 with MInOut

use of org.compiere.model.MInOut 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)38 MInOutLine (org.compiere.model.MInOutLine)22 BigDecimal (java.math.BigDecimal)13 MOrder (org.compiere.model.MOrder)13 MInvoice (org.compiere.model.MInvoice)10 MOrderLine (org.compiere.model.MOrderLine)9 ArrayList (java.util.ArrayList)6 MProduct (org.compiere.model.MProduct)5 MRMA (org.compiere.model.MRMA)5 ResultSet (java.sql.ResultSet)4 Timestamp (java.sql.Timestamp)4 MInvoiceLine (org.compiere.model.MInvoiceLine)4 MRMALine (org.compiere.model.MRMALine)4 MBPartner (org.compiere.model.MBPartner)3 MInOutConfirm (org.compiere.model.MInOutConfirm)3 MInvoiceSchedule (org.compiere.model.MInvoiceSchedule)3 MLocator (org.compiere.model.MLocator)3 MStorage (org.compiere.model.MStorage)3 PreparedStatement (java.sql.PreparedStatement)2 AdempiereException (org.adempiere.exceptions.AdempiereException)2