Search in sources :

Example 31 with MInOut

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

the class ModelValidator method docValidate.

public String docValidate(PO po, int timing) {
    log.info(po.get_TableName() + " Timing: " + timing);
    String result = null;
    // TABLE C_Invoice
    String tableName = po.get_TableName();
    if (tableName.equals(MInvoice.Table_Name)) {
        // Invoice - Validate Fixed Assets Invoice (LRO)
        if (timing == TIMING_AFTER_PREPARE) {
            MInvoice invoice = (MInvoice) po;
            validateFixedAssetsInvoice_LRO(invoice);
        }
        if (timing == TIMING_AFTER_COMPLETE) {
            MInvoice mi = (MInvoice) po;
            if (mi.isSOTrx()) {
                MInvoiceLine[] mils = mi.getLines();
                for (MInvoiceLine mil : mils) {
                    if (mil.isA_CreateAsset() && !mil.isA_Processed()) {
                        MAssetDisposed.createAssetDisposed(mil);
                    }
                }
            }
        }
        if (timing == TIMING_AFTER_VOID) {
            MInvoice invoice = (MInvoice) po;
            String error = afterVoid(invoice);
            if (error != null)
                return error;
        }
        if (timing == TIMING_BEFORE_REVERSECORRECT) {
            MInvoice invoice = (MInvoice) po;
            String error = beforeReverseCorrect(invoice);
            if (error != null)
                return error;
        }
    }
    if (tableName.equals(MInOut.Table_Name)) {
        if (timing == TIMING_AFTER_COMPLETE) {
            MInOut inOut = (MInOut) po;
            for (MInOutLine inOutLine : inOut.getLines()) {
                MProduct product = inOutLine.getProduct();
                //	Create Asset for SO
                if (product != null && inOut.isSOTrx() && product.isCreateAsset() && !product.getM_Product_Category().getA_Asset_Group().isFixedAsset() && inOutLine.getMovementQty().signum() > 0 && !inOut.isReversal()) {
                    log.fine("Asset");
                    //info.append("@A_Asset_ID@: ");
                    int noAssets = inOutLine.getMovementQty().intValue();
                    if (!product.isOneAssetPerUOM())
                        noAssets = 1;
                    for (int i = 0; i < noAssets; i++) {
                        //if (i > 0)
                        //	info.append(" - ");
                        int deliveryCount = i + 1;
                        if (!product.isOneAssetPerUOM())
                            deliveryCount = 0;
                        MAsset asset = new MAsset(inOut, inOutLine, deliveryCount);
                        if (!asset.save(inOut.get_TrxName())) {
                            //return DocAction.STATUS_Invalid;
                            throw new IllegalStateException("Could not create Asset");
                        }
                    //info.append(asset.getValue());
                    }
                }
            }
        //	Asset
        }
        if (timing == TIMING_AFTER_REVERSECORRECT) {
            MInOut inOut = (MInOut) po;
            I_M_InOut inOutReversal = inOut.getReversal();
            for (MInOutLine inOutLine : inOut.getLines()) {
                //	De-Activate Asset
                MAsset asset = MAsset.getFromShipment(inOut.getCtx(), inOutLine.getM_InOutLine_ID(), inOut.get_TrxName());
                if (asset != null) {
                    asset.setIsActive(false);
                    asset.setDescription(asset.getDescription() + " (" + inOutReversal.getDocumentNo() + " #" + inOutLine.getLine() + "<-)");
                    asset.saveEx();
                }
            }
        }
    }
    return result;
}
Also used : MInOut(org.compiere.model.MInOut) MProduct(org.compiere.model.MProduct) MInOutLine(org.compiere.model.MInOutLine) I_M_InOut(org.compiere.model.I_M_InOut) MInvoiceLine(org.compiere.model.MInvoiceLine) MInvoice(org.compiere.model.MInvoice) MAsset(org.compiere.model.MAsset)

Example 32 with MInOut

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

the class GenerateShipmentOutBound method processingShipments.

public void processingShipments() {
    shipments.entrySet().stream().forEach(entry -> {
        MInOut shipment = entry.getValue();
        shipment.setDocAction(getDocumentAction());
        shipment.processIt(getDocumentAction());
        if (!shipment.processIt(getDocumentAction())) {
            addLog("@ProcessFailed@ : " + shipment.getDocumentInfo());
            log.warning("@ProcessFailed@ :" + shipment.getDocumentInfo());
        }
        shipment.saveEx();
    });
}
Also used : MInOut(org.compiere.model.MInOut)

Example 33 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 34 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 35 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