Search in sources :

Example 61 with AdempiereException

use of org.adempiere.exceptions.AdempiereException in project adempiere by adempiere.

the class MSequence method getDocumentNo.

/**
	 * 	Get Document No based on Document Type
	 *	@param C_DocType_ID document type
	 * 	@param trxName optional Transaction Name
	 *  @param definite asking for a definitive or temporary sequence
	 *  @param po
	 *	@return document no or null
	 */
public static String getDocumentNo(int C_DocType_ID, String trxName, boolean definite, PO po) {
    if (C_DocType_ID == 0) {
        s_log.severe("C_DocType_ID=0");
        return null;
    }
    //	wrong for SERVER, but r/o
    MDocType dt = MDocType.get(Env.getCtx(), C_DocType_ID);
    if (dt != null && !dt.isDocNoControlled()) {
        s_log.finer("DocType_ID=" + C_DocType_ID + " Not DocNo controlled");
        return null;
    }
    if (definite && !dt.isOverwriteSeqOnComplete()) {
        s_log.finer("DocType_ID=" + C_DocType_ID + " Not Sequence Overwrite on Complete");
        return null;
    }
    if (dt == null || dt.getDocNoSequence_ID() == 0) {
        s_log.warning("No Sequence for DocType - " + dt);
        return null;
    }
    if (definite && dt.getDefiniteSequence_ID() == 0) {
        s_log.warning("No Definite Sequence for DocType - " + dt);
        return null;
    }
    //	Check AdempiereSys
    boolean adempiereSys = Ini.isPropertyBool(Ini.P_ADEMPIERESYS);
    if (CLogMgt.isLevel(LOGLEVEL))
        s_log.log(LOGLEVEL, "DocType_ID=" + C_DocType_ID + " [" + trxName + "]");
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    boolean isStartNewYear = false;
    String dateColumn = null;
    if (!adempiereSys) {
        // Get the Start New Year & Sequence Type
        String startNewYearSQL = "SELECT StartNewYear, DateColumn FROM AD_Sequence " + "WHERE AD_Sequence_ID = ? AND IsActive = 'Y' AND IsTableID = 'N' AND IsAutoSequence='Y'";
        try {
            pstmt = DB.prepareStatement(startNewYearSQL, trxName);
            pstmt.setInt(1, definite ? dt.getDefiniteSequence_ID() : dt.getDocNoSequence_ID());
            rs = pstmt.executeQuery();
            if (rs.next()) {
                isStartNewYear = "Y".equals(rs.getString(1));
                dateColumn = rs.getString(2);
            }
        } catch (Exception e) {
            s_log.log(Level.SEVERE, "(Table) [" + trxName + "]", e);
        } finally {
            DB.close(rs, pstmt);
        }
    }
    String selectSQL = null;
    if (DB.isOracle() == false) {
        if (isStartNewYear) {
            selectSQL = "SELECT y.CurrentNext, s.CurrentNextSys, s.IncrementNo, s.Prefix, s.Suffix, s.DecimalPattern, s.AD_Client_ID, s.AD_Sequence_ID " + "FROM AD_Sequence_No y, AD_Sequence s " + "WHERE y.AD_Sequence_ID = s.AD_Sequence_ID " + "AND s.AD_Sequence_ID = ? " + "AND y.CalendarYear = ? " + "AND s.IsActive='Y' AND s.IsTableID='N' AND s.IsAutoSequence='Y' " + //OF y"; //dete: MySql
            "FOR UPDATE ";
        } else {
            selectSQL = "SELECT CurrentNext, CurrentNextSys, IncrementNo, Prefix, Suffix, DecimalPattern, AD_Client_ID, AD_Sequence_ID " + "FROM AD_Sequence " + "WHERE AD_Sequence_ID = ? " + "AND IsActive='Y' AND IsTableID='N' AND IsAutoSequence='Y' " + //OF AD_Sequence"; //dete: MySql
            "FOR UPDATE ";
        }
        USE_PROCEDURE = false;
    } else {
        if (isStartNewYear) {
            selectSQL = "SELECT y.CurrentNext, s.CurrentNextSys, s.IncrementNo, s.Prefix, s.Suffix, s.DecimalPattern, s.AD_Client_ID, s.AD_Sequence_ID " + "FROM AD_Sequence_No y, AD_Sequence s " + "WHERE y.AD_Sequence_ID = s.AD_Sequence_ID " + "AND s.AD_Sequence_ID = ? " + "AND y.CalendarYear = ? " + "AND s.IsActive='Y' AND s.IsTableID='N' AND s.IsAutoSequence='Y' ";
        } else {
            selectSQL = "SELECT CurrentNext, CurrentNextSys, IncrementNo, Prefix, Suffix, DecimalPattern, AD_Client_ID, AD_Sequence_ID " + "FROM AD_Sequence " + "WHERE AD_Sequence_ID = ? " + "AND IsActive='Y' AND IsTableID='N' AND IsAutoSequence='Y' ";
        }
        USE_PROCEDURE = true;
    }
    Connection conn = null;
    Trx trx = trxName == null ? null : Trx.get(trxName, true);
    //
    int AD_Sequence_ID = 0;
    int incrementNo = 0;
    int next = -1;
    String prefix = "";
    String suffix = "";
    String decimalPattern = "";
    String calendarYear = "";
    try {
        if (trx != null)
            conn = trx.getConnection();
        else
            conn = DB.getConnectionID();
        //	Error
        if (conn == null)
            return null;
        if (isStartNewYear) {
            if (po != null && dateColumn != null && dateColumn.length() > 0) {
                Date docDate = (Date) po.get_Value(dateColumn);
                SimpleDateFormat sdf = new SimpleDateFormat("yyyy");
                calendarYear = sdf.format(docDate);
            } else {
                SimpleDateFormat sdf = new SimpleDateFormat("yyyy");
                calendarYear = sdf.format(new Date());
            }
        }
        pstmt = conn.prepareStatement(selectSQL, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE);
        if (definite)
            pstmt.setInt(1, dt.getDefiniteSequence_ID());
        else
            pstmt.setInt(1, dt.getDocNoSequence_ID());
        if (isStartNewYear)
            pstmt.setString(2, calendarYear);
        //
        if (!USE_PROCEDURE && DB.getDatabase().isQueryTimeoutSupported())
            pstmt.setQueryTimeout(QUERY_TIME_OUT);
        rs = pstmt.executeQuery();
        //		+ " - Type=" + pstmt.getResultSetType() + " - Concur=" + pstmt.getResultSetConcurrency());
        if (rs.next()) {
            incrementNo = rs.getInt(3);
            prefix = rs.getString(4);
            suffix = rs.getString(5);
            decimalPattern = rs.getString(6);
            int AD_Client_ID = rs.getInt(7);
            if (adempiereSys && AD_Client_ID > 11)
                adempiereSys = false;
            AD_Sequence_ID = rs.getInt(8);
            if (USE_PROCEDURE) {
                next = isStartNewYear ? nextIDByYear(conn, AD_Sequence_ID, incrementNo, calendarYear) : nextID(conn, AD_Sequence_ID, adempiereSys);
            } else {
                PreparedStatement updateSQL = null;
                try {
                    if (adempiereSys) {
                        updateSQL = conn.prepareStatement("UPDATE AD_Sequence SET CurrentNextSys = CurrentNextSys + ? WHERE AD_Sequence_ID = ?");
                        next = rs.getInt(2);
                    } else {
                        String sql = isStartNewYear ? "UPDATE AD_Sequence_No SET CurrentNext = CurrentNext + ? WHERE AD_Sequence_ID = ? AND CalendarYear = ?" : "UPDATE AD_Sequence SET CurrentNext = CurrentNext + ? WHERE AD_Sequence_ID = ?";
                        updateSQL = conn.prepareStatement(sql);
                        next = rs.getInt(1);
                    }
                    updateSQL.setInt(1, incrementNo);
                    updateSQL.setInt(2, AD_Sequence_ID);
                    if (isStartNewYear)
                        updateSQL.setString(3, calendarYear);
                    updateSQL.executeUpdate();
                } finally {
                    DB.close(updateSQL);
                }
            }
        } else {
            s_log.warning("(DocType)- no record found - " + dt);
            next = -2;
        }
        //	Commit
        if (trx == null) {
            conn.commit();
        }
    } catch (Exception e) {
        s_log.log(Level.SEVERE, "(DocType) [" + trxName + "]", e);
        if (DBException.isTimeout(e))
            throw new AdempiereException("GenerateDocumentNoTimeOut", e);
        else
            throw new AdempiereException("GenerateDocumentNoError", e);
    } finally {
        //	Finish
        try {
            DB.close(rs, pstmt);
            if (trx == null && conn != null) {
                conn.close();
                conn = null;
            }
        } catch (Exception e) {
            s_log.log(Level.SEVERE, "(DocType) - finish", e);
        }
    }
    //	Error
    if (next < 0)
        return null;
    //	create DocumentNo
    StringBuffer doc = new StringBuffer();
    if (prefix != null && prefix.length() > 0)
        doc.append(Env.parseVariable(prefix, po, trxName, false));
    if (decimalPattern != null && decimalPattern.length() > 0)
        doc.append(new DecimalFormat(decimalPattern).format(next));
    else
        doc.append(next);
    if (suffix != null && suffix.length() > 0)
        doc.append(Env.parseVariable(suffix, po, trxName, false));
    String documentNo = doc.toString();
    s_log.finer(documentNo + " (" + incrementNo + ")" + " - C_DocType_ID=" + C_DocType_ID + " [" + trx + "]");
    return documentNo;
}
Also used : DecimalFormat(java.text.DecimalFormat) HttpURLConnection(java.net.HttpURLConnection) Connection(java.sql.Connection) CConnection(org.compiere.db.CConnection) PreparedStatement(java.sql.PreparedStatement) SQLException(java.sql.SQLException) DBException(org.adempiere.exceptions.DBException) AdempiereException(org.adempiere.exceptions.AdempiereException) Date(java.util.Date) AdempiereException(org.adempiere.exceptions.AdempiereException) ResultSet(java.sql.ResultSet) Trx(org.compiere.util.Trx) SimpleDateFormat(java.text.SimpleDateFormat)

Example 62 with AdempiereException

use of org.adempiere.exceptions.AdempiereException in project adempiere by adempiere.

the class MSequence method getDocumentNo.

/**************************************************************************
	 * 	Get Document No from table
	 *	@param AD_Client_ID client
	 *	@param TableName table name
	 * 	@param trxName optional Transaction Name
	 *  @param PO
	 *	@return document no or null
	 */
public static String getDocumentNo(int AD_Client_ID, String TableName, String trxName, PO po) {
    if (TableName == null || TableName.length() == 0)
        throw new IllegalArgumentException("TableName missing");
    //	Check AdempiereSys
    boolean adempiereSys = Ini.isPropertyBool(Ini.P_ADEMPIERESYS);
    if (adempiereSys && AD_Client_ID > 11)
        adempiereSys = false;
    //
    if (CLogMgt.isLevel(LOGLEVEL))
        s_log.log(LOGLEVEL, TableName + " - AdempiereSys=" + adempiereSys + " [" + trxName + "]");
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    boolean isStartNewYear = false;
    String dateColumn = null;
    if (!adempiereSys) {
        // Get the Start New Year flag
        String startNewYearSQL = "SELECT StartNewYear, DateColumn FROM AD_Sequence " + "WHERE Name = ? AND IsActive = 'Y' AND IsTableID = 'N' AND IsAutoSequence='Y' AND AD_Client_ID = ?";
        try {
            pstmt = DB.prepareStatement(startNewYearSQL, trxName);
            pstmt.setString(1, PREFIX_DOCSEQ + TableName);
            pstmt.setInt(2, AD_Client_ID);
            rs = pstmt.executeQuery();
            if (rs.next()) {
                isStartNewYear = "Y".equals(rs.getString(1));
                dateColumn = rs.getString(2);
            }
        } catch (Exception e) {
            s_log.log(Level.SEVERE, "(Table) [" + trxName + "]", e);
        } finally {
            DB.close(rs, pstmt);
        }
    }
    String selectSQL = null;
    if (DB.isOracle() == false) {
        if (isStartNewYear) {
            selectSQL = "SELECT y.CurrentNext, s.CurrentNextSys, s.IncrementNo, s.Prefix, s.Suffix, s.DecimalPattern, s.AD_Sequence_ID " + "FROM AD_Sequence_No y, AD_Sequence s " + "WHERE y.AD_Sequence_ID = s.AD_Sequence_ID " + "AND s.Name = ? " + "AND s.AD_Client_ID = ? " + "AND y.CalendarYear = ? " + "AND s.IsActive='Y' AND s.IsTableID='N' AND s.IsAutoSequence='Y' " + "ORDER BY s.AD_Client_ID DESC " + //OF y"; // dete: MySql
            "FOR UPDATE ";
        } else {
            selectSQL = "SELECT CurrentNext, CurrentNextSys, IncrementNo, Prefix, Suffix, DecimalPattern, AD_Sequence_ID " + "FROM AD_Sequence " + "WHERE Name = ? " + "AND AD_Client_ID = ? " + "AND IsActive='Y' AND IsTableID='N' AND IsAutoSequence='Y' " + "ORDER BY AD_Client_ID DESC " + //OF AD_Sequence"; //dete: MySql
            "FOR UPDATE ";
        }
        USE_PROCEDURE = false;
    } else {
        if (isStartNewYear) {
            selectSQL = "SELECT y.CurrentNext, s.CurrentNextSys, s.IncrementNo, Prefix, Suffix, DecimalPattern, s.AD_Sequence_ID " + "FROM AD_Sequence_No y, AD_Sequence s " + "WHERE y.AD_Sequence_ID = s.AD_Sequence_ID " + "AND s.Name = ? " + "AND s.AD_Client_ID = ? " + "AND y.CalendarYear = ? " + "AND s.IsActive='Y' AND s.IsTableID='N' AND s.IsAutoSequence='Y' " + "ORDER BY s.AD_Client_ID DESC";
        } else {
            selectSQL = "SELECT CurrentNext, CurrentNextSys, IncrementNo, Prefix, Suffix, DecimalPattern, AD_Sequence_ID " + "FROM AD_Sequence " + "WHERE Name = ? " + "AND AD_Client_ID = ? " + "AND IsActive='Y' AND IsTableID='N' AND IsAutoSequence='Y' " + "ORDER BY AD_Client_ID DESC";
        }
        USE_PROCEDURE = true;
    }
    Connection conn = null;
    Trx trx = trxName == null ? null : Trx.get(trxName, true);
    //
    int AD_Sequence_ID = 0;
    int incrementNo = 0;
    int next = -1;
    String prefix = "";
    String suffix = "";
    String decimalPattern = "";
    String calendarYear = "";
    try {
        if (trx != null)
            conn = trx.getConnection();
        else
            conn = DB.getConnectionID();
        //	Error
        if (conn == null)
            return null;
        if (isStartNewYear) {
            if (po != null && dateColumn != null && dateColumn.length() > 0) {
                Date docDate = (Date) po.get_Value(dateColumn);
                SimpleDateFormat sdf = new SimpleDateFormat("yyyy");
                calendarYear = sdf.format(docDate);
            } else {
                SimpleDateFormat sdf = new SimpleDateFormat("yyyy");
                calendarYear = sdf.format(new Date());
            }
        }
        //
        pstmt = conn.prepareStatement(selectSQL, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE);
        pstmt.setString(1, PREFIX_DOCSEQ + TableName);
        pstmt.setInt(2, AD_Client_ID);
        if (isStartNewYear)
            pstmt.setString(3, calendarYear);
        //
        if (!USE_PROCEDURE && DB.getDatabase().isQueryTimeoutSupported())
            pstmt.setQueryTimeout(QUERY_TIME_OUT);
        rs = pstmt.executeQuery();
        //		+ " - Type=" + pstmt.getResultSetType() + " - Concur=" + pstmt.getResultSetConcurrency());
        if (rs.next()) {
            AD_Sequence_ID = rs.getInt(7);
            prefix = rs.getString(4);
            suffix = rs.getString(5);
            decimalPattern = rs.getString(6);
            incrementNo = rs.getInt(3);
            if (USE_PROCEDURE) {
                next = isStartNewYear ? nextIDByYear(conn, AD_Sequence_ID, incrementNo, calendarYear) : nextID(conn, AD_Sequence_ID, adempiereSys);
            } else {
                PreparedStatement updateSQL = null;
                try {
                    if (adempiereSys) {
                        updateSQL = conn.prepareStatement("UPDATE AD_Sequence SET CurrentNextSys = CurrentNextSys + ? WHERE AD_Sequence_ID = ?");
                        next = rs.getInt(2);
                    } else {
                        String sql = isStartNewYear ? "UPDATE AD_Sequence_No SET CurrentNext = CurrentNext + ? WHERE AD_Sequence_ID = ? AND CalendarYear = ?" : "UPDATE AD_Sequence SET CurrentNext = CurrentNext + ? WHERE AD_Sequence_ID = ?";
                        updateSQL = conn.prepareStatement(sql);
                        next = rs.getInt(1);
                    }
                    updateSQL.setInt(1, incrementNo);
                    updateSQL.setInt(2, AD_Sequence_ID);
                    if (isStartNewYear)
                        updateSQL.setString(3, calendarYear);
                    updateSQL.executeUpdate();
                } finally {
                    DB.close(updateSQL);
                }
            }
        } else {
            s_log.warning("(Table) - no record found - " + TableName);
            MSequence seq = new MSequence(Env.getCtx(), AD_Client_ID, TableName, null);
            next = seq.getNextID();
            seq.saveEx();
        }
        //	Commit
        if (trx == null) {
            conn.commit();
        }
    } catch (Exception e) {
        s_log.log(Level.SEVERE, "(Table) [" + trxName + "]", e);
        if (DBException.isTimeout(e))
            throw new AdempiereException("GenerateDocumentNoTimeOut", e);
        else
            throw new AdempiereException("GenerateDocumentNoError", e);
    } finally {
        //Finish
        DB.close(rs, pstmt);
        try {
            if (trx == null && conn != null) {
                conn.close();
                conn = null;
            }
        } catch (Exception e) {
            s_log.log(Level.SEVERE, "(Table) - finish", e);
        }
    }
    //	Error
    if (next < 0)
        return null;
    //	create DocumentNo
    StringBuffer doc = new StringBuffer();
    if (prefix != null && prefix.length() > 0)
        doc.append(Env.parseVariable(prefix, po, trxName, false));
    if (decimalPattern != null && decimalPattern.length() > 0)
        doc.append(new DecimalFormat(decimalPattern).format(next));
    else
        doc.append(next);
    if (suffix != null && suffix.length() > 0)
        doc.append(Env.parseVariable(suffix, po, trxName, false));
    String documentNo = doc.toString();
    s_log.finer(documentNo + " (" + incrementNo + ")" + " - Table=" + TableName + " [" + trx + "]");
    return documentNo;
}
Also used : DecimalFormat(java.text.DecimalFormat) HttpURLConnection(java.net.HttpURLConnection) Connection(java.sql.Connection) CConnection(org.compiere.db.CConnection) PreparedStatement(java.sql.PreparedStatement) SQLException(java.sql.SQLException) DBException(org.adempiere.exceptions.DBException) AdempiereException(org.adempiere.exceptions.AdempiereException) Date(java.util.Date) AdempiereException(org.adempiere.exceptions.AdempiereException) ResultSet(java.sql.ResultSet) Trx(org.compiere.util.Trx) SimpleDateFormat(java.text.SimpleDateFormat)

Example 63 with AdempiereException

use of org.adempiere.exceptions.AdempiereException in project adempiere by adempiere.

the class InOutCreateFrom method doIt.

@Override
protected String doIt() throws Exception {
    // Valid Record Identifier
    if (getRecord_ID() == 0)
        return "";
    AtomicInteger referenceId = new AtomicInteger(0);
    AtomicInteger created = new AtomicInteger(0);
    //	Get Shipment
    MInOut inout = new MInOut(getCtx(), getRecord_ID(), get_TrxName());
    log.config(inout + ", C_Locator_ID=" + getLocator());
    //	Get Default Locator
    MLocator defaultLocator = MLocator.getDefault((MWarehouse) inout.getM_Warehouse());
    List<Integer> recordIds = getSelectionKeys();
    String createFromType = recordIds.size() > 0 ? getSelectionAsString(recordIds.get(0), "CF_CreateFromType") : null;
    log.fine("CreateFromType=" + createFromType);
    if (createFromType == null || createFromType.length() == 0)
        throw new AdempiereException("@CreateFromType@ @NotFound@");
    //	Loop
    recordIds.stream().forEach(key -> {
        int productId = getSelectionAsInt(key, "CF_M_Product_ID");
        int chargeId = getSelectionAsInt(key, "CF_C_Charge_ID");
        int uomId = getSelectionAsInt(key, "CF_C_UOM_ID");
        int locatorId = getSelectionAsInt(key, "CF_M_Locator_ID");
        BigDecimal qtyEntered = getSelectionAsBigDecimal(key, "CF_QtyEntered");
        locatorId = getValidLocator(locatorId, defaultLocator);
        MInvoiceLine invoiceLine = null;
        int precision = 2;
        if (productId != 0) {
            MProduct product = MProduct.get(getCtx(), productId);
            precision = product.getUOMPrecision();
        }
        qtyEntered = qtyEntered.setScale(precision, BigDecimal.ROUND_HALF_DOWN);
        log.fine("Line QtyEntered=" + qtyEntered + ", Product=" + productId + ", Key=" + key);
        MInOutLine inOutLine = new MInOutLine(inout);
        inOutLine.setM_Product_ID(productId, uomId);
        inOutLine.setQty(qtyEntered);
        if (createFromType.equals(ORDER)) {
            MOrderLine orderLine = new MOrderLine(getCtx(), key, get_TrxName());
            referenceId.set(orderLine.getC_Order_ID());
            inOutLine.setC_OrderLine_ID(key);
            if (orderLine.getQtyEntered().compareTo(orderLine.getQtyOrdered()) != 0) {
                inOutLine.setMovementQty(qtyEntered.multiply(orderLine.getQtyOrdered()).divide(orderLine.getQtyEntered(), 12, BigDecimal.ROUND_HALF_UP));
                inOutLine.setC_UOM_ID(orderLine.getC_UOM_ID());
            }
            inOutLine.setM_AttributeSetInstance_ID(orderLine.getM_AttributeSetInstance_ID());
            inOutLine.setDescription(orderLine.getDescription());
            inOutLine.setC_Project_ID(orderLine.getC_Project_ID());
            inOutLine.setC_ProjectPhase_ID(orderLine.getC_ProjectPhase_ID());
            inOutLine.setC_ProjectTask_ID(orderLine.getC_ProjectTask_ID());
            inOutLine.setC_Activity_ID(orderLine.getC_Activity_ID());
            inOutLine.setC_Campaign_ID(orderLine.getC_Campaign_ID());
            inOutLine.setAD_OrgTrx_ID(orderLine.getAD_OrgTrx_ID());
            inOutLine.setUser1_ID(orderLine.getUser1_ID());
            inOutLine.setUser2_ID(orderLine.getUser2_ID());
            inOutLine.setUser3_ID(orderLine.getUser3_ID());
            inOutLine.setUser4_ID(orderLine.getUser4_ID());
        } else if (createFromType.equals(INVOICE)) {
            invoiceLine = new MInvoiceLine(getCtx(), key, get_TrxName());
            MInvoice invoice = invoiceLine.getParent();
            referenceId.getAndSet(invoice.getC_Invoice_ID());
            if (invoice.isCreditMemo()) {
                qtyEntered = qtyEntered.negate();
                inOutLine.setQty(qtyEntered);
            }
            if (invoiceLine.getQtyEntered().compareTo(invoiceLine.getQtyInvoiced()) != 0) {
                inOutLine.setMovementQty(qtyEntered.multiply(invoiceLine.getQtyInvoiced()).divide(invoiceLine.getQtyEntered(), 12, BigDecimal.ROUND_HALF_UP));
                inOutLine.setC_UOM_ID(invoiceLine.getC_UOM_ID());
            }
            inOutLine.setDescription(invoiceLine.getDescription());
            inOutLine.setC_Project_ID(invoiceLine.getC_Project_ID());
            inOutLine.setC_ProjectPhase_ID(invoiceLine.getC_ProjectPhase_ID());
            inOutLine.setC_ProjectTask_ID(invoiceLine.getC_ProjectTask_ID());
            inOutLine.setC_Activity_ID(invoiceLine.getC_Activity_ID());
            inOutLine.setC_Campaign_ID(invoiceLine.getC_Campaign_ID());
            inOutLine.setAD_OrgTrx_ID(invoiceLine.getAD_OrgTrx_ID());
            inOutLine.setUser1_ID(invoiceLine.getUser1_ID());
            inOutLine.setUser2_ID(invoiceLine.getUser2_ID());
            inOutLine.setUser3_ID(invoiceLine.getUser3_ID());
            inOutLine.setUser4_ID(invoiceLine.getUser4_ID());
        } else if (createFromType.equals(RMA)) {
            MRMALine rmal = new MRMALine(getCtx(), key, get_TrxName());
            referenceId.set(rmal.getM_RMA_ID());
            inOutLine.setM_RMALine_ID(key);
            inOutLine.setQtyEntered(qtyEntered);
            inOutLine.setDescription(rmal.getDescription());
            inOutLine.setM_AttributeSetInstance_ID(rmal.getM_AttributeSetInstance_ID());
            inOutLine.setC_Project_ID(rmal.getC_Project_ID());
            inOutLine.setC_ProjectPhase_ID(rmal.getC_ProjectPhase_ID());
            inOutLine.setC_ProjectTask_ID(rmal.getC_ProjectTask_ID());
            inOutLine.setC_Activity_ID(rmal.getC_Activity_ID());
            inOutLine.setAD_OrgTrx_ID(rmal.getAD_OrgTrx_ID());
            inOutLine.setUser1_ID(rmal.getUser1_ID());
            inOutLine.setUser2_ID(rmal.getUser2_ID());
            inOutLine.setUser3_ID(rmal.getUser3_ID());
            inOutLine.setUser4_ID(rmal.getUser4_ID());
        }
        if (chargeId != 0)
            inOutLine.setC_Charge_ID(chargeId);
        inOutLine.setM_Locator_ID(locatorId);
        inOutLine.saveEx();
        if (invoiceLine != null) {
            invoiceLine.setM_InOutLine_ID(inOutLine.getM_InOutLine_ID());
            invoiceLine.saveEx();
        }
        created.updateAndGet(createNo -> createNo + 1);
    });
    //	Add reference to Order / Invoice / RMA
    addReference(inout, createFromType, referenceId.get());
    //	
    return "@Created@ " + created.get();
}
Also used : MInOut(org.compiere.model.MInOut) MProduct(org.compiere.model.MProduct) MInOutLine(org.compiere.model.MInOutLine) MInvoiceLine(org.compiere.model.MInvoiceLine) MInvoice(org.compiere.model.MInvoice) BigDecimal(java.math.BigDecimal) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AdempiereException(org.adempiere.exceptions.AdempiereException) MLocator(org.compiere.model.MLocator) MOrderLine(org.compiere.model.MOrderLine) MRMALine(org.compiere.model.MRMALine)

Example 64 with AdempiereException

use of org.adempiere.exceptions.AdempiereException in project adempiere by adempiere.

the class MigrationApply method doIt.

@Override
protected String doIt() throws Exception {
    if (Ini.isPropertyBool(Ini.P_LOGMIGRATIONSCRIPT)) {
        addLog(Msg.getMsg(getCtx(), "LogMigrationScriptFlagIsSetMessage"));
        return "@Error@";
    }
    // Use a null transaction to generate a read only query
    // Doesn't lock table 
    MMigration migration = new MMigration(getCtx(), getRecord_ID(), null);
    if (migration.is_new()) {
        addLog(Msg.getMsg(getCtx(), "NoMigrationMessage"));
        //return;
        return "@Error@";
    }
    migration.setIsForce(isForce());
    try {
        addLog(migration.apply());
    } catch (AdempiereException e) {
        addLog(e.getMessage());
        if (// abort on first error
        !isForce())
            throw new AdempiereException(e.getMessage(), e);
    }
    return "@OK@";
}
Also used : AdempiereException(org.adempiere.exceptions.AdempiereException) MMigration(org.compiere.model.MMigration)

Example 65 with AdempiereException

use of org.adempiere.exceptions.AdempiereException in project adempiere by adempiere.

the class MigrationFromXML method loadXML.

/**
	 * Load the XML migration file or files.  
	 */
@SuppressWarnings("unchecked")
private void loadXML() {
    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    dbf.setNamespaceAware(true);
    dbf.setIgnoringElementContentWhitespace(true);
    // file can be a file or directory
    File file = new File(getFileName());
    try {
        builder = dbf.newDocumentBuilder();
        List<File> migrationFiles = new ArrayList<File>();
        if (!file.exists()) {
            log.log(Level.WARNING, "No file or directory found");
            return;
        } else if (// file exists
        file.isDirectory()) {
            log.log(Level.CONFIG, "Processing migration files in directory: " + file.getAbsolutePath());
            // Recursively find files
            migrationFiles = (List<File>) FileUtils.listFiles(file, new String[] { "xml" }, true);
            Collections.sort(migrationFiles, fileComparator);
        } else {
            log.log(Level.CONFIG, "Processing migration file: " + file.getAbsolutePath());
            migrationFiles.add(file);
        }
        success = true;
        for (File migFile : migrationFiles) {
            loadFile(migFile);
            if (!success)
                break;
        }
    } catch (ParserConfigurationException | SAXException | IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (AdempiereException e) {
        if (!isForce())
            throw new AdempiereException("Loading Migration from XML failed.", e);
    }
}
Also used : DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) AdempiereException(org.adempiere.exceptions.AdempiereException) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) NodeList(org.w3c.dom.NodeList) List(java.util.List) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) IOException(java.io.IOException) File(java.io.File) SAXException(org.xml.sax.SAXException)

Aggregations

AdempiereException (org.adempiere.exceptions.AdempiereException)326 BigDecimal (java.math.BigDecimal)79 SQLException (java.sql.SQLException)46 ArrayList (java.util.ArrayList)36 ResultSet (java.sql.ResultSet)33 PreparedStatement (java.sql.PreparedStatement)31 Timestamp (java.sql.Timestamp)31 MProduct (org.compiere.model.MProduct)28 List (java.util.List)25 Query (org.compiere.model.Query)20 File (java.io.File)17 Properties (java.util.Properties)16 PO (org.compiere.model.PO)16 Env (org.compiere.util.Env)15 MBPartner (org.compiere.model.MBPartner)14 ImmutableList (com.google.common.collect.ImmutableList)12 I_M_HU (de.metas.handlingunits.model.I_M_HU)12 FillMandatoryException (org.adempiere.exceptions.FillMandatoryException)12 ProcessInfo (org.compiere.process.ProcessInfo)12 DocumentId (de.metas.ui.web.window.datatypes.DocumentId)11