} // prepare /// <summary> /// Process /// </summary> /// <returns>Info</returns> protected override String DoIt() { log.Info("SourceAcctSchema_ID=" + _SourceAcctSchema_ID + ", TargetAcctSchema_ID=" + _TargetAcctSchema_ID); if (_SourceAcctSchema_ID == 0 || _TargetAcctSchema_ID == 0) { throw new Exception("ID=0"); } if (_SourceAcctSchema_ID == _TargetAcctSchema_ID) { throw new Exception("Account Schema must be different"); } MAcctSchema source = MAcctSchema.Get(GetCtx(), _SourceAcctSchema_ID, null); if (source.Get_ID() == 0) { throw new Exception("@NotFound@ Source @C_AcctSchema_ID@=" + _SourceAcctSchema_ID); } MAcctSchema target = new MAcctSchema(GetCtx(), _TargetAcctSchema_ID, Get_Trx()); if (target.Get_ID() == 0) { throw new Exception("@NotFound@ Target @C_AcctSchema_ID@=" + _TargetAcctSchema_ID); } // // MAcctSchemaElement[] sourceElements = source.getAcctSchemaElements(); MAcctSchemaElement[] targetElements = target.GetAcctSchemaElements(); if (targetElements.Length == 0) { throw new Exception("@NotFound@ Target C_AcctSchema_Element"); } // Accounting Element must be the same MAcctSchemaElement sourceAcctElement = source.GetAcctSchemaElement(MAcctSchemaElement.ELEMENTTYPE_Account); if (sourceAcctElement == null) { throw new Exception("NotFound Source AC C_AcctSchema_Element"); } MAcctSchemaElement targetAcctElement = target.GetAcctSchemaElement(MAcctSchemaElement.ELEMENTTYPE_Account); if (targetAcctElement == null) { throw new Exception("NotFound Target AC C_AcctSchema_Element"); } if (sourceAcctElement.GetC_Element_ID() != targetAcctElement.GetC_Element_ID()) { throw new Exception("@C_Element_ID@ different"); } if (MAcctSchemaGL.Get(GetCtx(), _TargetAcctSchema_ID) == null) { CopyGL(target); } if (MAcctSchemaDefault.Get(GetCtx(), _TargetAcctSchema_ID) == null) { CopyDefault(target); } return("@OK@"); } // doIt
} // updateDefaults /// <summary> /// Update Default Accounts. // _Default.xxxx = C_ValidCombination_ID => Account_ID=C_ElementValue_ID /// </summary> /// <param name="C_AcctSchema_ID">Accounting Schema</param> private void UpdateDefaultAccounts(int C_AcctSchema_ID) { log.Config("C_AcctSchema_ID=" + C_AcctSchema_ID); MAcctSchema aas = new MAcctSchema(GetCtx(), C_AcctSchema_ID, null); if (aas.GetAcctSchemaElement("AC").GetC_Element_ID() != _C_Element_ID) { log.Log(Level.SEVERE, "C_Element_ID=" + _C_Element_ID + " not in AcctSchema=" + aas); return; } int[] counts = new int[] { 0, 0, 0 }; String sql = "SELECT i.C_ElementValue_ID, t.TableName, c.ColumnName, i.I_ElementValue_ID " + "FROM I_ElementValue i" + " INNER JOIN AD_Column c ON (i.AD_Column_ID=c.AD_Column_ID)" + " INNER JOIN AD_Table t ON (c.AD_Table_ID=t.AD_Table_ID) " + "WHERE i.I_IsImported='Y' AND Processing='-'" + " AND i.C_ElementValue_ID IS NOT NULL AND C_Element_ID=@param"; SqlParameter[] param = new SqlParameter[1]; IDataReader idr = null; try { //PreparedStatement pstmt = DataBase.prepareStatement(sql, Get_TrxName()); //pstmt.setInt(1, _C_Element_ID); param[0] = new SqlParameter("@param", _C_Element_ID); idr = DataBase.DB.ExecuteReader(sql, param, Get_TrxName()); while (idr.Read()) { int C_ElementValue_ID = Utility.Util.GetValueOfInt(idr[0]); // rs.getInt(1); String TableName = Utility.Util.GetValueOfString(idr[1]); // rs.getString(2); String ColumnName = Utility.Util.GetValueOfString(idr[2]); int I_ElementValue_ID = Utility.Util.GetValueOfInt(idr[3]); // Update it int u = UpdateDefaultAccount(TableName, ColumnName, C_AcctSchema_ID, C_ElementValue_ID); counts[u]++; if (u != UPDATE_ERROR) { sql = "UPDATE I_ElementValue SET Processing='N' " + "WHERE I_ElementValue_ID=" + I_ElementValue_ID; int no = DataBase.DB.ExecuteQuery(sql.ToString(), null, Get_TrxName()); if (no != 1) { log.Log(Level.SEVERE, "Updated=" + no); } } } idr.Close(); } catch (Exception e) { if (idr != null) { idr.Close(); } log.Log(Level.SEVERE, "", e); } AddLog(0, null, Utility.Util.GetValueOfDecimal(counts[UPDATE_ERROR]), aas.ToString() + ": @Errors@"); AddLog(0, null, Utility.Util.GetValueOfDecimal(counts[UPDATE_YES]), aas.ToString() + ": @Updated@"); AddLog(0, null, Utility.Util.GetValueOfDecimal(counts[UPDATE_SAME]), aas.ToString() + ": OK"); } // createDefaultAccounts
/// <summary> /// Set Account Info /// </summary> /// <param name="acctSchema">account schema</param> /// <param name="acct">account</param> public void SetAccount(MAcctSchema acctSchema, MAccount acct) { _acctSchema = acctSchema; SetC_AcctSchema_ID(acctSchema.GetC_AcctSchema_ID()); // _acct = acct; if (GetAD_Client_ID() == 0) { SetAD_Client_ID(_acct.GetAD_Client_ID()); } SetAccount_ID(_acct.GetAccount_ID()); SetC_SubAcct_ID(_acct.GetC_SubAcct_ID()); // User Defined References MAcctSchemaElement ud1 = _acctSchema.GetAcctSchemaElement( X_C_AcctSchema_Element.ELEMENTTYPE_UserElement1); if (ud1 != null) { String ColumnName1 = ud1.GetDisplayColumnName(); if (ColumnName1 != null) { int ID1 = 0; if (_docLine != null) { ID1 = _docLine.GetValue(ColumnName1); } if (ID1 == 0) { if (_doc == null) { throw new ArgumentException("Document not set yet"); } ID1 = _doc.GetValue(ColumnName1); } if (ID1 != 0) { SetUserElement1_ID(ID1); } } } MAcctSchemaElement ud2 = _acctSchema.GetAcctSchemaElement( X_C_AcctSchema_Element.ELEMENTTYPE_UserElement2); if (ud2 != null) { String ColumnName2 = ud2.GetDisplayColumnName(); if (ColumnName2 != null) { int ID2 = 0; if (_docLine != null) { ID2 = _docLine.GetValue(ColumnName2); } if (ID2 == 0) { if (_doc == null) { throw new ArgumentException("Document not set yet"); } ID2 = _doc.GetValue(ColumnName2); } if (ID2 != 0) { SetUserElement2_ID(ID2); } } } }