Search in sources :

Example 31 with AdempiereSystemError

use of org.compiere.util.AdempiereSystemError in project adempiere by adempiere.

the class AcctSchemaCopyAcct method doIt.

//	prepare
/**
	 * 	Process
	 *	@return info
	 *	@throws Exception
	 */
protected String doIt() throws Exception {
    log.info("SourceAcctSchema_ID=" + p_SourceAcctSchema_ID + ", TargetAcctSchema_ID=" + p_TargetAcctSchema_ID);
    if (p_SourceAcctSchema_ID == 0 || p_TargetAcctSchema_ID == 0)
        throw new AdempiereSystemError("ID=0");
    if (p_SourceAcctSchema_ID == p_TargetAcctSchema_ID)
        throw new AdempiereUserError("Must be different");
    MAcctSchema source = MAcctSchema.get(getCtx(), p_SourceAcctSchema_ID, null);
    if (source.get_ID() == 0)
        throw new AdempiereSystemError("NotFound Source C_AcctSchema_ID=" + p_SourceAcctSchema_ID);
    MAcctSchema target = new MAcctSchema(getCtx(), p_TargetAcctSchema_ID, get_TrxName());
    if (target.get_ID() == 0)
        throw new AdempiereSystemError("NotFound Target C_AcctSchema_ID=" + p_TargetAcctSchema_ID);
    //
    MAcctSchemaElement[] targetElements = target.getAcctSchemaElements();
    if (targetElements.length == 0)
        throw new AdempiereUserError("NotFound Target C_AcctSchema_Element");
    //	Accounting Element must be the same
    MAcctSchemaElement sourceAcctElement = source.getAcctSchemaElement(MAcctSchemaElement.ELEMENTTYPE_Account);
    if (sourceAcctElement == null)
        throw new AdempiereUserError("NotFound Source AC C_AcctSchema_Element");
    MAcctSchemaElement targetAcctElement = target.getAcctSchemaElement(MAcctSchemaElement.ELEMENTTYPE_Account);
    if (targetAcctElement == null)
        throw new AdempiereUserError("NotFound Target AC C_AcctSchema_Element");
    if (sourceAcctElement.getC_Element_ID() != targetAcctElement.getC_Element_ID())
        throw new AdempiereUserError("@C_Element_ID@ different");
    if (MAcctSchemaGL.get(getCtx(), p_TargetAcctSchema_ID) == null)
        copyGL(target);
    if (MAcctSchemaDefault.get(getCtx(), p_TargetAcctSchema_ID) == null)
        copyDefault(target);
    return "@OK@";
}
Also used : MAcctSchema(org.compiere.model.MAcctSchema) AdempiereUserError(org.compiere.util.AdempiereUserError) AdempiereSystemError(org.compiere.util.AdempiereSystemError) MAcctSchemaElement(org.compiere.model.MAcctSchemaElement)

Example 32 with AdempiereSystemError

use of org.compiere.util.AdempiereSystemError in project adempiere by adempiere.

the class AcctSchemaCopyAcct method copyGL.

//	doIt
/**
	 * 	Copy GL 
	 *	@param targetAS target
	 *	@throws Exception
	 */
private void copyGL(MAcctSchema targetAS) throws Exception {
    MAcctSchemaGL source = MAcctSchemaGL.get(getCtx(), p_SourceAcctSchema_ID);
    MAcctSchemaGL target = new MAcctSchemaGL(getCtx(), 0, get_TrxName());
    target.setC_AcctSchema_ID(p_TargetAcctSchema_ID);
    ArrayList<KeyNamePair> list = source.getAcctInfo();
    for (int i = 0; i < list.size(); i++) {
        KeyNamePair pp = list.get(i);
        int sourceC_ValidCombination_ID = pp.getKey();
        String columnName = pp.getName();
        MAccount sourceAccount = MAccount.get(getCtx(), sourceC_ValidCombination_ID);
        MAccount targetAccount = createAccount(targetAS, sourceAccount);
        target.setValue(columnName, new Integer(targetAccount.getC_ValidCombination_ID()));
    }
    if (!target.save())
        throw new AdempiereSystemError("Could not Save GL");
}
Also used : MAcctSchemaGL(org.compiere.model.MAcctSchemaGL) AdempiereSystemError(org.compiere.util.AdempiereSystemError) MAccount(org.compiere.model.MAccount) KeyNamePair(org.compiere.util.KeyNamePair)

Example 33 with AdempiereSystemError

use of org.compiere.util.AdempiereSystemError in project adempiere by adempiere.

the class TaxDeclarationCreate method doIt.

//	prepare
/**
	 * 	Process
	 *	@return info
	 *	@throws Exception
	 */
protected String doIt() throws Exception {
    log.info("C_TaxDeclaration_ID=" + p_C_TaxDeclaration_ID);
    m_td = new MTaxDeclaration(getCtx(), p_C_TaxDeclaration_ID, get_TrxName());
    if (m_td.get_ID() == 0)
        throw new AdempiereSystemError("@NotFound@ @C_TaxDeclaration_ID@ = " + p_C_TaxDeclaration_ID);
    if (p_DeleteOld) {
        //	Delete old
        String sql = "DELETE C_TaxDeclarationLine WHERE C_TaxDeclaration_ID=?";
        int no = DB.executeUpdate(sql, p_C_TaxDeclaration_ID, false, get_TrxName());
        if (no != 0)
            log.config("Delete Line #" + no);
        sql = "DELETE C_TaxDeclarationAcct WHERE C_TaxDeclaration_ID=?";
        no = DB.executeUpdate(sql, p_C_TaxDeclaration_ID, false, get_TrxName());
        if (no != 0)
            log.config("Delete Acct #" + no);
    }
    //	Get Invoices
    String sql = "SELECT * FROM C_Invoice i " + "WHERE TRUNC(i.DateInvoiced, 'DD') >= ? AND TRUNC(i.DateInvoiced, 'DD') <= ? " + " AND Processed='Y'" + " AND NOT EXISTS (SELECT * FROM C_TaxDeclarationLine tdl " + "WHERE i.C_Invoice_ID=tdl.C_Invoice_ID)";
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    int noInvoices = 0;
    try {
        pstmt = DB.prepareStatement(sql, get_TrxName());
        pstmt.setTimestamp(1, m_td.getDateFrom());
        pstmt.setTimestamp(2, m_td.getDateTo());
        rs = pstmt.executeQuery();
        while (rs.next()) {
            //	no lock
            create(new MInvoice(getCtx(), rs, null));
            noInvoices++;
        }
    } catch (Exception e) {
        log.log(Level.SEVERE, sql, e);
    } finally {
        DB.close(rs, pstmt);
        rs = null;
        pstmt = null;
    }
    return "@C_Invoice_ID@ #" + noInvoices + " (" + m_noLines + ", " + m_noAccts + ")";
}
Also used : AdempiereSystemError(org.compiere.util.AdempiereSystemError) ResultSet(java.sql.ResultSet) MInvoice(org.compiere.model.MInvoice) PreparedStatement(java.sql.PreparedStatement) MTaxDeclaration(org.compiere.model.MTaxDeclaration)

Example 34 with AdempiereSystemError

use of org.compiere.util.AdempiereSystemError in project adempiere by adempiere.

the class InventoryCountCreate method doIt.

//	prepare
/**
	 * 	Process
	 *	@return message
	 *	@throws Exception
	 */
protected String doIt() throws Exception {
    log.info("M_Inventory_ID=" + p_M_Inventory_ID + ", M_Locator_ID=" + p_M_Locator_ID + ", LocatorValue=" + p_LocatorValue + ", ProductValue=" + p_ProductValue + ", M_Product_Category_ID=" + p_M_Product_Category_ID + ", QtyRange=" + p_QtyRange + ", DeleteOld=" + p_DeleteOld);
    m_inventory = new MInventory(getCtx(), p_M_Inventory_ID, get_TrxName());
    if (m_inventory.get_ID() == 0)
        throw new AdempiereSystemError("Not found: M_Inventory_ID=" + p_M_Inventory_ID);
    if (m_inventory.isProcessed())
        throw new AdempiereSystemError("@M_Inventory_ID@ @Processed@");
    //
    if (p_DeleteOld) {
        //Added Line by armen
        String sql1 = "DELETE FROM M_InventoryLineMA ma WHERE EXISTS " + "(SELECT * FROM M_InventoryLine l WHERE l.M_InventoryLine_ID=ma.M_InventoryLine_ID" + " AND Processed='N' AND M_Inventory_ID=" + p_M_Inventory_ID + ")";
        int no1 = DB.executeUpdate(sql1, get_TrxName());
        log.fine("doIt - Deleted MA #" + no1);
        //End of Added Line
        String sql = "DELETE M_InventoryLine WHERE Processed='N' " + "AND M_Inventory_ID=" + p_M_Inventory_ID;
        int no = DB.executeUpdate(sql, get_TrxName());
        log.fine("doIt - Deleted #" + no);
    }
    //	Create Null Storage records
    if (p_QtyRange != null && p_QtyRange.equals("=")) {
        String sql = "INSERT INTO M_Storage " + "(AD_Client_ID, AD_Org_ID, IsActive, Created, CreatedBy, Updated, UpdatedBy," + " M_Locator_ID, M_Product_ID, M_AttributeSetInstance_ID," + " QtyOnHand, QtyReserved, QtyOrdered, DateLastInventory) " + "SELECT l.AD_CLIENT_ID, l.AD_ORG_ID, 'Y', SysDate, 0,SysDate, 0," + " l.M_Locator_ID, p.M_Product_ID, 0," + " 0,0,0,null " + "FROM M_Locator l" + " INNER JOIN M_Product p ON (l.AD_Client_ID=p.AD_Client_ID) " + "WHERE l.M_Warehouse_ID=" + m_inventory.getM_Warehouse_ID();
        if (p_M_Locator_ID != 0)
            sql += " AND l.M_Locator_ID=" + p_M_Locator_ID;
        sql += " AND l.IsDefault='Y'" + " AND p.IsActive='Y' AND p.IsStocked='Y' and p.ProductType='I'" + " AND NOT EXISTS (SELECT * FROM M_Storage s" + " INNER JOIN M_Locator sl ON (s.M_Locator_ID=sl.M_Locator_ID) " + "WHERE sl.M_Warehouse_ID=l.M_Warehouse_ID" + " AND s.M_Product_ID=p.M_Product_ID)";
        int no = DB.executeUpdate(sql, get_TrxName());
        log.fine("'0' Inserted #" + no);
    }
    StringBuffer sql = new StringBuffer("SELECT s.M_Product_ID, s.M_Locator_ID, s.M_AttributeSetInstance_ID," + " s.QtyOnHand, p.M_AttributeSet_ID " + "FROM M_Product p" + " INNER JOIN M_Storage s ON (s.M_Product_ID=p.M_Product_ID)" + " INNER JOIN M_Locator l ON (s.M_Locator_ID=l.M_Locator_ID) " + "WHERE l.M_Warehouse_ID=?" + " AND p.IsActive='Y' AND p.IsStocked='Y' and p.ProductType='I'");
    //
    if (p_M_Locator_ID != 0)
        sql.append(" AND s.M_Locator_ID=?");
    //
    if (p_LocatorValue != null && (p_LocatorValue.trim().length() == 0 || p_LocatorValue.equals("%")))
        p_LocatorValue = null;
    if (p_LocatorValue != null)
        sql.append(" AND UPPER(l.Value) LIKE ?");
    //
    if (p_ProductValue != null && (p_ProductValue.trim().length() == 0 || p_ProductValue.equals("%")))
        p_ProductValue = null;
    if (p_ProductValue != null)
        sql.append(" AND UPPER(p.Value) LIKE ?");
    //
    if (p_M_Product_Category_ID != 0)
        sql.append(" AND p.M_Product_Category_ID IN (" + getSubCategoryWhereClause(p_M_Product_Category_ID) + ")");
    //	Do not overwrite existing records
    if (!p_DeleteOld)
        sql.append(" AND NOT EXISTS (SELECT * FROM M_InventoryLine il " + "WHERE il.M_Inventory_ID=?" + " AND il.M_Product_ID=s.M_Product_ID" + " AND il.M_Locator_ID=s.M_Locator_ID" + " AND COALESCE(il.M_AttributeSetInstance_ID,0)=COALESCE(s.M_AttributeSetInstance_ID,0))");
    //	+ " AND il.M_AttributeSetInstance_ID=s.M_AttributeSetInstance_ID)");
    //
    //	Locator/Product
    sql.append(" ORDER BY l.Value, p.Value, s.QtyOnHand DESC");
    //
    int count = 0;
    PreparedStatement pstmt = null;
    try {
        pstmt = DB.prepareStatement(sql.toString(), get_TrxName());
        int index = 1;
        pstmt.setInt(index++, m_inventory.getM_Warehouse_ID());
        if (p_M_Locator_ID != 0)
            pstmt.setInt(index++, p_M_Locator_ID);
        if (p_LocatorValue != null)
            pstmt.setString(index++, p_LocatorValue.toUpperCase());
        if (p_ProductValue != null)
            pstmt.setString(index++, p_ProductValue.toUpperCase());
        if (!p_DeleteOld)
            pstmt.setInt(index++, p_M_Inventory_ID);
        ResultSet rs = pstmt.executeQuery();
        while (rs.next()) {
            int M_Product_ID = rs.getInt(1);
            int M_Locator_ID = rs.getInt(2);
            int M_AttributeSetInstance_ID = rs.getInt(3);
            BigDecimal QtyOnHand = rs.getBigDecimal(4);
            if (QtyOnHand == null)
                QtyOnHand = Env.ZERO;
            int M_AttributeSet_ID = rs.getInt(5);
            //
            int compare = QtyOnHand.compareTo(Env.ZERO);
            if (p_QtyRange == null || (p_QtyRange.equals(">") && compare > 0) || (p_QtyRange.equals("<") && compare < 0) || (p_QtyRange.equals("=") && compare == 0) || (p_QtyRange.equals("N") && compare != 0)) {
                count += createInventoryLine(M_Locator_ID, M_Product_ID, M_AttributeSetInstance_ID, QtyOnHand, M_AttributeSet_ID);
            }
        }
        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;
    }
    //	Set Count to Zero
    if (p_InventoryCountSetZero) {
        String sql1 = "UPDATE M_InventoryLine l " + "SET QtyCount=0 " + "WHERE M_Inventory_ID=" + p_M_Inventory_ID;
        int no = DB.executeUpdate(sql1, get_TrxName());
        log.info("Set Cont to Zero=" + no);
    }
    //
    return "@M_InventoryLine_ID@ - #" + count;
}
Also used : AdempiereSystemError(org.compiere.util.AdempiereSystemError) MInventory(org.compiere.model.MInventory) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) BigDecimal(java.math.BigDecimal) SQLException(java.sql.SQLException)

Example 35 with AdempiereSystemError

use of org.compiere.util.AdempiereSystemError in project adempiere by adempiere.

the class OrderOpen method doIt.

//	prepare
/**
	 *  Perform process.
	 *  @return Message
	 *  @throws Exception if not successful
	 */
protected String doIt() throws AdempiereSystemError {
    log.info("doIt - Open C_Order_ID=" + p_C_Order_ID);
    if (p_C_Order_ID == 0)
        return "";
    //
    MOrder order = new MOrder(getCtx(), p_C_Order_ID, get_TrxName());
    String msg = order.reopenIt();
    if (msg.length() != 0) {
        throw new AdempiereSystemError(msg);
    }
    return order.save() ? "@OK@" : "@Error@";
}
Also used : MOrder(org.compiere.model.MOrder) AdempiereSystemError(org.compiere.util.AdempiereSystemError)

Aggregations

AdempiereSystemError (org.compiere.util.AdempiereSystemError)36 ResultSet (java.sql.ResultSet)9 BigDecimal (java.math.BigDecimal)8 PreparedStatement (java.sql.PreparedStatement)8 AdempiereUserError (org.compiere.util.AdempiereUserError)8 Timestamp (java.sql.Timestamp)6 MAcctSchema (org.compiere.model.MAcctSchema)5 MPayment (org.compiere.model.MPayment)5 MInvoice (org.compiere.model.MInvoice)4 SQLException (java.sql.SQLException)3 MInventory (org.compiere.model.MInventory)3 MTable (org.compiere.model.MTable)3 Statement (java.sql.Statement)2 SimpleDateFormat (java.text.SimpleDateFormat)2 Vector (java.util.Vector)2 MAccount (org.compiere.model.MAccount)2 MAcctSchemaDefault (org.compiere.model.MAcctSchemaDefault)2 MColumn (org.compiere.model.MColumn)2 MDocType (org.compiere.model.MDocType)2 MWarehouse (org.compiere.model.MWarehouse)2