Search in sources :

Example 1 with MInOutLineConfirm

use of org.compiere.model.MInOutLineConfirm 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 2 with MInOutLineConfirm

use of org.compiere.model.MInOutLineConfirm 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)

Example 3 with MInOutLineConfirm

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

the class ImportInOutConfirm method doIt.

//	prepare
/**
	 * 	doIt
	 *	@return info
	 */
protected String doIt() throws Exception {
    log.info("I_InOutLineConfirm_ID=" + p_I_InOutLineConfirm_ID);
    StringBuffer sql = null;
    int no = 0;
    String clientCheck = " AND AD_Client_ID=" + p_AD_Client_ID;
    //	Delete Old Imported
    if (p_DeleteOldImported) {
        sql = new StringBuffer("DELETE I_InOutLineConfirm " + "WHERE I_IsImported='Y'").append(clientCheck);
        no = DB.executeUpdate(sql.toString(), get_TrxName());
        log.fine("Delete Old Impored =" + no);
    }
    //	Set IsActive, Created/Updated
    sql = new StringBuffer("UPDATE I_InOutLineConfirm " + "SET IsActive = COALESCE (IsActive, 'Y')," + " Created = COALESCE (Created, SysDate)," + " CreatedBy = COALESCE (CreatedBy, 0)," + " Updated = COALESCE (Updated, SysDate)," + " UpdatedBy = COALESCE (UpdatedBy, 0)," + " I_ErrorMsg = ' '," + " I_IsImported = 'N' " + "WHERE I_IsImported<>'Y' OR I_IsImported IS NULL");
    no = DB.executeUpdate(sql.toString(), get_TrxName());
    log.info("Reset=" + no);
    //	Set Client from Name
    sql = new StringBuffer("UPDATE I_InOutLineConfirm i " + "SET AD_Client_ID=COALESCE (AD_Client_ID,").append(p_AD_Client_ID).append(") " + "WHERE (AD_Client_ID IS NULL OR AD_Client_ID=0)" + " AND I_IsImported<>'Y'");
    no = DB.executeUpdate(sql.toString(), get_TrxName());
    log.fine("Set Client from Value=" + no);
    //	Error Confirmation Line
    sql = new StringBuffer("UPDATE I_InOutLineConfirm i " + "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Invalid Confirmation Line, '" + "WHERE (M_InOutLineConfirm_ID IS NULL OR M_InOutLineConfirm_ID=0" + " OR NOT EXISTS (SELECT * FROM M_InOutLineConfirm c WHERE i.M_InOutLineConfirm_ID=c.M_InOutLineConfirm_ID))" + " AND I_IsImported<>'Y'").append(clientCheck);
    no = DB.executeUpdate(sql.toString(), get_TrxName());
    if (no != 0)
        log.warning("Invalid InOutLineConfirm=" + no);
    //	Error Confirmation No
    sql = new StringBuffer("UPDATE I_InOutLineConfirm i " + "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Missing Confirmation No, '" + "WHERE (ConfirmationNo IS NULL OR ConfirmationNo='')" + " AND I_IsImported<>'Y'").append(clientCheck);
    no = DB.executeUpdate(sql.toString(), get_TrxName());
    if (no != 0)
        log.warning("Invalid ConfirmationNo=" + no);
    //	Qty
    sql = new StringBuffer("UPDATE I_InOutLineConfirm i " + "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Target<>(Confirmed+Difference+Scrapped), ' " + "WHERE EXISTS (SELECT * FROM M_InOutLineConfirm c " + "WHERE i.M_InOutLineConfirm_ID=c.M_InOutLineConfirm_ID" + " AND c.TargetQty<>(i.ConfirmedQty+i.ScrappedQty+i.DifferenceQty))" + " AND I_IsImported<>'Y'").append(clientCheck);
    no = DB.executeUpdate(sql.toString(), get_TrxName());
    if (no != 0)
        log.warning("Invalid Qty=" + no);
    commitEx();
    /*********************************************************************/
    PreparedStatement pstmt = null;
    sql = new StringBuffer("SELECT * FROM I_InOutLineConfirm " + "WHERE I_IsImported='N'").append(clientCheck).append(" ORDER BY I_InOutLineConfirm_ID");
    no = 0;
    try {
        pstmt = DB.prepareStatement(sql.toString(), get_TrxName());
        ResultSet rs = pstmt.executeQuery();
        while (rs.next()) {
            X_I_InOutLineConfirm importLine = new X_I_InOutLineConfirm(getCtx(), rs, get_TrxName());
            MInOutLineConfirm confirmLine = new MInOutLineConfirm(getCtx(), importLine.getM_InOutLineConfirm_ID(), get_TrxName());
            if (confirmLine.get_ID() == 0 || confirmLine.get_ID() != importLine.getM_InOutLineConfirm_ID()) {
                importLine.setI_IsImported(false);
                importLine.setI_ErrorMsg("ID Not Found");
                importLine.saveEx();
            } else {
                confirmLine.setConfirmationNo(importLine.getConfirmationNo());
                confirmLine.setConfirmedQty(importLine.getConfirmedQty());
                confirmLine.setDifferenceQty(importLine.getDifferenceQty());
                confirmLine.setScrappedQty(importLine.getScrappedQty());
                confirmLine.setDescription(importLine.getDescription());
                if (confirmLine.save()) {
                    //	Import
                    importLine.setI_IsImported(true);
                    importLine.setProcessed(true);
                    if (importLine.save())
                        no++;
                }
            }
        }
        rs.close();
        pstmt.close();
        pstmt = null;
    } catch (Exception e) {
        log.log(Level.SEVERE, sql.toString(), e);
    }
    try {
        if (pstmt != null)
            pstmt.close();
        pstmt = null;
    } catch (Exception e) {
        pstmt = null;
    }
    return "@Updated@ #" + no;
}
Also used : MInOutLineConfirm(org.compiere.model.MInOutLineConfirm) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) X_I_InOutLineConfirm(org.compiere.model.X_I_InOutLineConfirm)

Aggregations

MInOutLineConfirm (org.compiere.model.MInOutLineConfirm)3 MInOut (org.compiere.model.MInOut)2 MInOutConfirm (org.compiere.model.MInOutConfirm)2 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1 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 X_I_InOutLineConfirm (org.compiere.model.X_I_InOutLineConfirm)1 ProcessInfo (org.compiere.process.ProcessInfo)1