private void calculateDiscount(){
  m_discountSchema=false;
  if (m_C_BPartner_ID == 0 || m_M_Product_ID == 0)   return;
  int M_DiscountSchema_ID=0;
  BigDecimal FlatDiscount=null;
  String sql="SELECT COALESCE(p.M_DiscountSchema_ID,g.M_DiscountSchema_ID)," + " COALESCE(p.PO_DiscountSchema_ID,g.PO_DiscountSchema_ID), p.FlatDiscount " + "FROM C_BPartner p"+ " INNER JOIN C_BP_Group g ON (p.C_BP_Group_ID=g.C_BP_Group_ID) "+ "WHERE p.C_BPartner_ID=?";
  PreparedStatement pstmt=null;
  ResultSet rs=null;
  try {
    pstmt=DB.prepareStatement(sql,null);
    pstmt.setInt(1,m_C_BPartner_ID);
    rs=pstmt.executeQuery();
    if (rs.next()) {
      M_DiscountSchema_ID=rs.getInt(m_isSOTrx ? 1 : 2);
      FlatDiscount=rs.getBigDecimal(3);
      if (FlatDiscount == null)       FlatDiscount=Env.ZERO;
    }
  }
 catch (  Exception e) {
    log.log(Level.SEVERE,sql,e);
  }
 finally {
    DB.close(rs,pstmt);
    rs=null;
    pstmt=null;
  }
  if (M_DiscountSchema_ID == 0)   return;
  MDiscountSchema sd=MDiscountSchema.get(Env.getCtx(),M_DiscountSchema_ID);
  if (sd.get_ID() == 0)   return;
  m_discountSchema=true;
  m_PriceStd=sd.calculatePrice(m_Qty,m_PriceStd,m_M_Product_ID,m_M_Product_Category_ID,FlatDiscount);
}

private void calculateDiscount ( ) { m_discountSchema = false ; if ( m_C_BPartner_ID == 0 || m_M_Product_ID == 0 ) return ; int M_DiscountSchema_ID = 0 ; BigDecimal FlatDiscount = null ; String sql = "SELECT COALESCE(p.M_DiscountSchema_ID,g.M_DiscountSchema_ID)," + " COALESCE(p.PO_DiscountSchema_ID,g.PO_DiscountSchema_ID), p.FlatDiscount " + "FROM C_BPartner p" + " INNER JOIN C_BP_Group g ON (p.C_BP_Group_ID=g.C_BP_Group_ID) " + "WHERE p.C_BPartner_ID=?" ; PreparedStatement pstmt = null ; ResultSet rs = null ; try { pstmt = DB . prepareStatement ( sql , null ) ; pstmt . setInt ( 1 , m_C_BPartner_ID ) ; rs = pstmt . executeQuery ( ) ; if ( rs . next ( ) ) { M_DiscountSchema_ID = rs . getInt ( m_isSOTrx ? 1 : 2 ) ; FlatDiscount = rs . getBigDecimal ( 3 ) ; if ( FlatDiscount == null ) FlatDiscount = Env . ZERO ; } } catch ( Exception e ) { log . log ( Level . SEVERE , sql , e ) ; } finally { DB . close ( rs , pstmt ) ; rs = null ; pstmt = null ; } if ( M_DiscountSchema_ID == 0 ) return ; MDiscountSchema sd = MDiscountSchema . get ( Env . getCtx ( ) , M_DiscountSchema_ID ) ; if ( sd . get_ID ( ) == 0 ) return ; m_discountSchema = true ; m_PriceStd = sd . calculatePrice ( m_Qty , m_PriceStd , m_M_Product_ID , m_M_Product_Category_ID , FlatDiscount ) ; }
calculate ( business partner ) discount
