private int createRevenueRecognition(int C_RevenueRecognition_ID,int C_InvoiceLine_ID,int AD_Client_ID,int AD_Org_ID,int AD_User_ID,int Account_ID,int C_SubAcct_ID,int M_Product_ID,int C_BPartner_ID,int AD_OrgTrx_ID,int C_LocFrom_ID,int C_LocTo_ID,int C_SRegion_ID,int C_Project_ID,int C_Campaign_ID,int C_Activity_ID,int User1_ID,int User2_ID,int UserElement1_ID,int UserElement2_ID){
  log.fine("From Accout_ID=" + Account_ID);
  MAccount revenue=MAccount.get(getCtx(),AD_Client_ID,AD_Org_ID,getC_AcctSchema_ID(),Account_ID,C_SubAcct_ID,M_Product_ID,C_BPartner_ID,AD_OrgTrx_ID,C_LocFrom_ID,C_LocTo_ID,C_SRegion_ID,C_Project_ID,C_Campaign_ID,C_Activity_ID,User1_ID,User2_ID,UserElement1_ID,UserElement2_ID,null);
  if (revenue != null && revenue.get_ID() == 0)   revenue.saveEx();
  if (revenue == null || revenue.get_ID() == 0) {
    log.severe("Revenue_Acct not found");
    return Account_ID;
  }
  int P_Revenue_Acct=revenue.get_ID();
  int UnearnedRevenue_Acct=0;
  int new_Account_ID=0;
  String sql="SELECT ga.UnearnedRevenue_Acct, vc.Account_ID " + "FROM C_BP_Group_Acct ga, C_BPartner p, C_ValidCombination vc " + "WHERE ga.C_BP_Group_ID=p.C_BP_Group_ID"+ " AND ga.UnearnedRevenue_Acct=vc.C_ValidCombination_ID"+ " AND ga.C_AcctSchema_ID=? AND p.C_BPartner_ID=?";
  PreparedStatement pstmt=null;
  ResultSet rs=null;
  try {
    pstmt=DB.prepareStatement(sql,get_TrxName());
    pstmt.setInt(1,getC_AcctSchema_ID());
    pstmt.setInt(2,C_BPartner_ID);
    rs=pstmt.executeQuery();
    if (rs.next()) {
      UnearnedRevenue_Acct=rs.getInt(1);
      new_Account_ID=rs.getInt(2);
    }
  }
 catch (  SQLException e) {
    log.log(Level.SEVERE,sql,e);
  }
 finally {
    DB.close(rs,pstmt);
    rs=null;
    pstmt=null;
  }
  if (new_Account_ID == 0) {
    log.severe("UnearnedRevenue_Acct not found");
    return Account_ID;
  }
  MRevenueRecognitionPlan plan=new MRevenueRecognitionPlan(getCtx(),0,null);
  plan.setC_RevenueRecognition_ID(C_RevenueRecognition_ID);
  plan.setC_AcctSchema_ID(getC_AcctSchema_ID());
  plan.setC_InvoiceLine_ID(C_InvoiceLine_ID);
  plan.setUnEarnedRevenue_Acct(UnearnedRevenue_Acct);
  plan.setP_Revenue_Acct(P_Revenue_Acct);
  plan.setC_Currency_ID(getC_Currency_ID());
  plan.setTotalAmt(getAcctBalance());
  if (!plan.save(get_TrxName())) {
    log.severe("Plan NOT created");
    return Account_ID;
  }
  log.fine("From Acctount_ID=" + Account_ID + " to "+ new_Account_ID+ " - Plan from UnearnedRevenue_Acct="+ UnearnedRevenue_Acct+ " to Revenue_Acct="+ P_Revenue_Acct);
  return new_Account_ID;
}

private int createRevenueRecognition ( int C_RevenueRecognition_ID , int C_InvoiceLine_ID , int AD_Client_ID , int AD_Org_ID , int AD_User_ID , int Account_ID , int C_SubAcct_ID , int M_Product_ID , int C_BPartner_ID , int AD_OrgTrx_ID , int C_LocFrom_ID , int C_LocTo_ID , int C_SRegion_ID , int C_Project_ID , int C_Campaign_ID , int C_Activity_ID , int User1_ID , int User2_ID , int UserElement1_ID , int UserElement2_ID ) { log . fine ( "From Accout_ID=" + Account_ID ) ; MAccount revenue = MAccount . get ( getCtx ( ) , AD_Client_ID , AD_Org_ID , getC_AcctSchema_ID ( ) , Account_ID , C_SubAcct_ID , M_Product_ID , C_BPartner_ID , AD_OrgTrx_ID , C_LocFrom_ID , C_LocTo_ID , C_SRegion_ID , C_Project_ID , C_Campaign_ID , C_Activity_ID , User1_ID , User2_ID , UserElement1_ID , UserElement2_ID , null ) ; if ( revenue != null && revenue . get_ID ( ) == 0 ) revenue . saveEx ( ) ; if ( revenue == null || revenue . get_ID ( ) == 0 ) { log . severe ( "Revenue_Acct not found" ) ; return Account_ID ; } int P_Revenue_Acct = revenue . get_ID ( ) ; int UnearnedRevenue_Acct = 0 ; int new_Account_ID = 0 ; String sql = "SELECT ga.UnearnedRevenue_Acct, vc.Account_ID " + "FROM C_BP_Group_Acct ga, C_BPartner p, C_ValidCombination vc " + "WHERE ga.C_BP_Group_ID=p.C_BP_Group_ID" + " AND ga.UnearnedRevenue_Acct=vc.C_ValidCombination_ID" + " AND ga.C_AcctSchema_ID=? AND p.C_BPartner_ID=?" ; PreparedStatement pstmt = null ; ResultSet rs = null ; try { pstmt = DB . prepareStatement ( sql , get_TrxName ( ) ) ; pstmt . setInt ( 1 , getC_AcctSchema_ID ( ) ) ; pstmt . setInt ( 2 , C_BPartner_ID ) ; rs = pstmt . executeQuery ( ) ; if ( rs . next ( ) ) { UnearnedRevenue_Acct = rs . getInt ( 1 ) ; new_Account_ID = rs . getInt ( 2 ) ; } } catch ( SQLException e ) { log . log ( Level . SEVERE , sql , e ) ; } finally { DB . close ( rs , pstmt ) ; rs = null ; pstmt = null ; } if ( new_Account_ID == 0 ) { log . severe ( "UnearnedRevenue_Acct not found" ) ; return Account_ID ; } MRevenueRecognitionPlan plan = new MRevenueRecognitionPlan ( getCtx ( ) , 0 , null ) ; plan . setC_RevenueRecognition_ID ( C_RevenueRecognition_ID ) ; plan . setC_AcctSchema_ID ( getC_AcctSchema_ID ( ) ) ; plan . setC_InvoiceLine_ID ( C_InvoiceLine_ID ) ; plan . setUnEarnedRevenue_Acct ( UnearnedRevenue_Acct ) ; plan . setP_Revenue_Acct ( P_Revenue_Acct ) ; plan . setC_Currency_ID ( getC_Currency_ID ( ) ) ; plan . setTotalAmt ( getAcctBalance ( ) ) ; if ( ! plan . save ( get_TrxName ( ) ) ) { log . severe ( "Plan NOT created" ) ; return Account_ID ; } log . fine ( "From Acctount_ID=" + Account_ID + " to " + new_Account_ID + " - Plan from UnearnedRevenue_Acct=" + UnearnedRevenue_Acct + " to Revenue_Acct=" + P_Revenue_Acct ) ; return new_Account_ID ; }
revenue recognition . called from factline . save < p > create revenue recognition plan and return unearned revenue account to be used instead of revenue account . if not found , it returns the revenue account .
