private void LoadData() { FAccountRow = null; if (FTransaction != null) { FAccountTable = AAccountAccess.LoadViaALedger(FLedgerNumber, FTransaction); } else { TDBTransaction Transaction = null; DBAccess.GDBAccessObj.GetNewOrExistingAutoReadTransaction(IsolationLevel.ReadCommitted, TEnforceIsolationLevel.eilMinimum, ref Transaction, delegate { FAccountTable = AAccountAccess.LoadViaALedger(FLedgerNumber, Transaction); }); } #region Validate Data if ((FAccountTable == null) || (FAccountTable.Count == 0)) { throw new EFinanceSystemDataTableReturnedNoDataException(String.Format(Catalog.GetString( "Function:{0} - Account data for Ledger {1} does not exist or could not be accessed!"), Utilities.GetMethodName(true), FLedgerNumber)); } #endregion Validate Data }
private bool AccountIsActive(string AAccountCode = "") { bool retVal = true; AAccountRow currentAccountRow = null; //If empty, read value from combo if (AAccountCode == string.Empty) { if ((FAccountTable != null) && (cmbDetailBankAccountCode.SelectedIndex != -1) && (cmbDetailBankAccountCode.Count > 0) && (cmbDetailBankAccountCode.GetSelectedString() != null)) { AAccountCode = cmbDetailBankAccountCode.GetSelectedString(); } } if (FAccountTable != null) { currentAccountRow = (AAccountRow)FAccountTable.Rows.Find(new object[] { FLedgerNumber, AAccountCode }); } if (currentAccountRow != null) { retVal = currentAccountRow.AccountActiveFlag; } return(retVal); }
private void LoadData() { FAccountRow = null; if (FTransaction != null) { FAccountTable = AAccountAccess.LoadViaALedger(FLedgerNumber, FTransaction); } else { TDBTransaction Transaction = new TDBTransaction(); TDataBase db = DBAccess.Connect("TAccountInfo.LoadData"); db.ReadTransaction( ref Transaction, delegate { FAccountTable = AAccountAccess.LoadViaALedger(FLedgerNumber, Transaction); }); db.CloseDBConnection(); } #region Validate Data if ((FAccountTable == null) || (FAccountTable.Count == 0)) { throw new EFinanceSystemDataTableReturnedNoDataException(String.Format(Catalog.GetString( "Function:{0} - Account data for Ledger {1} does not exist or could not be accessed!"), Utilities.GetMethodName(true), FLedgerNumber)); } #endregion Validate Data }
/// <summary> /// Post a budget /// </summary> private static void PostBudget(int ALedgerNumber, ABudgetRow ABudgetRow, List <ABudgetPeriodRow> ABudgetPeriodRows) { //gb5300.p string AccountCode = ABudgetRow.AccountCode; string CostCentreList = ABudgetRow.CostCentreCode; /* posting CC and parents */ //Populate list of affected Cost Centres CostCentreParentsList(ALedgerNumber, ref CostCentreList); //Locate the row for the current account AAccountRow AccountRow = (AAccountRow)GLPostingDS.AAccount.Rows.Find(new object[] { ALedgerNumber, AccountCode }); GLPostingDS.AGeneralLedgerMaster.DefaultView.Sort = String.Format("{0},{1},{2},{3}", AGeneralLedgerMasterTable.GetLedgerNumberDBName(), AGeneralLedgerMasterTable.GetYearDBName(), AGeneralLedgerMasterTable.GetAccountCodeDBName(), AGeneralLedgerMasterTable.GetCostCentreCodeDBName()); /* calculate values for budgets and store them in a temp table; uses lb_budget */ ProcessAccountParent( ALedgerNumber, AccountCode, AccountRow.DebitCreditIndicator, CostCentreList, ABudgetRow, ABudgetPeriodRows); }
private void AddNewAccount(Object sender, EventArgs e) { if (FCurrentAccount == null) { MessageBox.Show(Catalog.GetString("You can only add a new account after selecting a parent account")); return; } ValidateAllData(true, false); string newName = FNameForNewAccounts; Int32 countNewAccount = 0; if (FMainDS.AAccount.Rows.Find(new object[] { FLedgerNumber, newName }) != null) { while (FMainDS.AAccount.Rows.Find(new object[] { FLedgerNumber, newName + countNewAccount.ToString() }) != null) { countNewAccount++; } newName += countNewAccount.ToString(); } // ChangeAccountCodeValue() needs this value! strOldDetailAccountCode = newName; AAccountRow parentAccount = FCurrentAccount.AccountRow; GLSetupTDSAAccountRow newAccountRow = FMainDS.AAccount.NewRowTyped(); newAccountRow.AccountCode = newName; newAccountRow.LedgerNumber = FLedgerNumber; newAccountRow.AccountActiveFlag = true; newAccountRow.DebitCreditIndicator = parentAccount.DebitCreditIndicator; newAccountRow.AccountType = parentAccount.AccountType; newAccountRow.ValidCcCombo = parentAccount.ValidCcCombo; newAccountRow.PostingStatus = true; FMainDS.AAccount.Rows.Add(newAccountRow); AAccountHierarchyDetailRow hierarchyDetailRow = FMainDS.AAccountHierarchyDetail.NewRowTyped(); hierarchyDetailRow.LedgerNumber = FLedgerNumber; hierarchyDetailRow.AccountHierarchyCode = FSelectedHierarchy; hierarchyDetailRow.AccountCodeToReportTo = parentAccount.AccountCode; hierarchyDetailRow.ReportingAccountCode = newName; // change posting/summary flag of parent account if it was previously a leaf parentAccount.PostingStatus = false; // The parent is now a summary account! hierarchyDetailRow.ReportOrder = ucoAccountsTree.GetLastChildReportingOrder() + 1; FMainDS.AAccountHierarchyDetail.Rows.Add(hierarchyDetailRow); FIAmUpdating++; ShowDetails(newAccountRow); FIAmUpdating--; ucoAccountsTree.AddNewAccount(newAccountRow, hierarchyDetailRow); txtDetailAccountCode.Focus(); FPetraUtilsObject.SetChangedFlag(); }
/// <summary> /// Update the name of the currently selected node /// </summary> public void SetNodeLabel(AAccountRow ARow, TreeNode ThisNode = null) { if ((ARow == null) || (ARow.RowState == DataRowState.Deleted) || (ARow.RowState == DataRowState.Detached)) { return; } SetNodeLabel(ARow.AccountCode, ARow.AccountCodeShortDesc, ThisNode); }
/// <summary> /// Add this new account as child of the currently selected node /// </summary> public void AddNewAccount(AAccountRow AccountRow, AAccountHierarchyDetailRow HierarchyDetailRow) { trvAccounts.BeginUpdate(); TreeNode newNode = trvAccounts.SelectedNode.Nodes.Add(AccountRow.AccountCode); AccountNodeDetails NewAccount = AccountNodeDetails.AddNewAccount(newNode, AccountRow, HierarchyDetailRow); trvAccounts.EndUpdate(); FParentForm.SetSelectedAccount(NewAccount); }
private void RunRevaluationIntern() { Boolean NewTransaction; TDBTransaction DBTransaction = DBAccess.GDBAccessObj.GetNewOrExistingTransaction(IsolationLevel.ReadCommitted, out NewTransaction); AAccountTable accountTable = new AAccountTable(); AAccountRow accountTemplate = (AAccountRow)accountTable.NewRowTyped(false); accountTemplate.LedgerNumber = F_LedgerNum; accountTemplate.AccountActiveFlag = true; accountTemplate.ForeignCurrencyFlag = true; accountTable = AAccountAccess.LoadUsingTemplate(accountTemplate, DBTransaction); AGeneralLedgerMasterTable glmTable = new AGeneralLedgerMasterTable(); AGeneralLedgerMasterRow glmTemplate = (AGeneralLedgerMasterRow)glmTable.NewRowTyped(false); glmTemplate.LedgerNumber = F_LedgerNum; glmTemplate.Year = F_FinancialYear; glmTable = AGeneralLedgerMasterAccess.LoadUsingTemplate(glmTemplate, DBTransaction); if (NewTransaction) { DBAccess.GDBAccessObj.RollbackTransaction(); } if (accountTable.Rows.Count == 0) // not using any foreign accounts? { return; } for (int iCnt = 0; iCnt < accountTable.Rows.Count; ++iCnt) { AAccountRow accountRow = (AAccountRow)accountTable[iCnt]; for (int kCnt = 0; kCnt < F_CurrencyCode.Length; ++kCnt) { // AForeignCurrency[] and ANewExchangeRate[] shall support a value // for this account resp. for the currency of the account if (accountRow.ForeignCurrencyCode.Equals(F_CurrencyCode[kCnt])) { glmTable.DefaultView.RowFilter = "a_account_code_c = '" + accountRow.AccountCode + "'"; if (glmTable.DefaultView.Count > 0) { RevaluateAccount(glmTable.DefaultView, F_ExchangeRate[kCnt]); } } } } CloseRevaluationAccountingBatch(); }
/// <summary>If this is a foreign currency supplier, it must be linked to accounts in that currency. /// (And if it's not, it mustn't be!)</summary> /// <param name="AccountRef"></param> /// <param name="AccountType"></param> /// <returns>true if the default back account is OK.</returns> private bool ValidateAccountCurrency(string AccountRef, string AccountType) { bool CurrencyIsOk = true; if (AccountRef == "") // I've not been given a default bank account. Perhaps this is OK? { return(CurrencyIsOk); } DataTable TempTbl = TDataCache.TMFinance.GetCacheableFinanceTable(TCacheableFinanceTablesEnum.AccountList, FLedgerNumber); AAccountTable AccountList = (AAccountTable)TempTbl; AccountList.DefaultView.RowFilter = String.Format("a_ledger_number_i={0} AND a_account_code_c='{1}'", FLedgerNumber, AccountRef); if (AccountList.DefaultView.Count == 1) { AAccountRow AccountDetail = (AAccountRow)AccountList.DefaultView[0].Row; if (FMainDS.AApSupplier[0].CurrencyCode == FLedgerRow.BaseCurrency) { CurrencyIsOk = (AccountDetail.ForeignCurrencyFlag == false); } else { CurrencyIsOk = ((AccountDetail.ForeignCurrencyFlag == true) && (AccountDetail.ForeignCurrencyCode == FMainDS.AApSupplier[0].CurrencyCode)); } if (!CurrencyIsOk) { MessageBox.Show(String.Format(Catalog.GetString("The {0} must be a {1} currency account."), AccountType, FMainDS.AApSupplier[0].CurrencyCode), "Validation"); FMainDS.AApSupplier.Rows[0].EndEdit(); // This call isn't really useful, because although the user may go and create the required account, // she won't have done so yet... TDataCache.TMFinance.RefreshCacheableFinanceTable(TCacheableFinanceTablesEnum.AccountList, FLedgerNumber); // scrub the cache so that I'll notice if the user makes a change } } else { MessageBox.Show(String.Format(Catalog.GetString("Unable to access {0} account {1}"), AccountType, AccountRef), "Error"); FMainDS.AApSupplier.Rows[0].EndEdit(); TDataCache.TMFinance.RefreshCacheableFinanceTable(TCacheableFinanceTablesEnum.AccountList); // scrub the cache - perhaps I'll get a different answer next time! CurrencyIsOk = false; } return(CurrencyIsOk); }
/// <summary> /// Make this account a child of the selected one in the hierarchy (from drag-drop). /// </summary> /// <param name="AChild"></param> /// <param name="ANewParent"></param> private void DoReassignment(TreeNode AChild, TreeNode ANewParent) { if ((AChild != null) && (ANewParent != null)) { if (((AccountNodeDetails)AChild.Tag).AccountRow.SystemAccountFlag) { MessageBox.Show(String.Format(Catalog.GetString("{0} is a System Account and cannot be moved."), ((AccountNodeDetails)AChild.Tag).AccountRow.AccountCode), Catalog.GetString("Re-assign Account"), MessageBoxButtons.OK, MessageBoxIcon.Stop); ShowNodeSelected(null); return; } AAccountRow newParentRow = ((AccountNodeDetails)ANewParent.Tag).AccountRow; if (newParentRow.PostingStatus) { if (MessageBox.Show(String.Format(Catalog.GetString("Do you want to promote {0} to a summary Account?"), newParentRow.AccountCode), Catalog.GetString("Move Account"), MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.No) { ShowNodeSelected(null); return; } } FParentForm.SetSelectedAccount(null); String PrevParent = AChild.Parent.Text; AccountNodeDetails DraggedAccount = (AccountNodeDetails)AChild.Tag; TreeNode NewNode = (TreeNode)AChild.Clone(); // A new TreeNode is made (and the previous will be deleted), // but the actual DataRows are only tweaked to show the new parent. DraggedAccount.linkedTreeNode = NewNode; DraggedAccount.DetailRow.AccountCodeToReportTo = newParentRow.AccountCode; InsertInOrder(ANewParent, NewNode); NewNode.Expand(); ANewParent.Expand(); newParentRow.PostingStatus = false; // The parent is now a summary account! ((AccountNodeDetails)ANewParent.Tag).CanDelete = false; ANewParent.BackColor = Color.White; FParentForm.ShowStatus(String.Format(Catalog.GetString("{0} was moved from {1} to {2}."), AChild.Text, PrevParent, ANewParent.Text)); AChild.Remove(); FPetraUtilsObject.SetChangedFlag(); FParentForm.SetSelectedAccount(DraggedAccount); // SetSelectionUsingTimer(DraggedAccount); // Calling SetSelectedAccount directly doesn't work // because Remove(), above, has left a selection "in the queue". } }
/// <summary> /// Move to the next row ... /// </summary> /// <returns></returns> public bool MoveNext() { ++FRowIdx; if (FRowIdx < FAccountTable.Rows.Count) { FAccountRow = (AAccountRow)FAccountTable[FRowIdx]; return(true); } else { FAccountRow = null; return(false); } }
/// <summary> /// TAccountPropertyEnum defines a set of special accounts and here one of them /// can be selected. .. /// </summary> /// <param name="AENum"></param> public void SetSpecialAccountCode(TAccountPropertyEnum AENum) { FAccountRow = null; if (FAccountPropertyHandler == null) { FAccountPropertyHandler = new THandleAccountPropertyInfo(FLedgerInfo); } string account = FAccountPropertyHandler.GetAccountCode(AENum); if (!account.Equals(string.Empty)) { AccountCode = account; } }
private void GetChildrenIntern(IList <String> help, string AAccountCode, Boolean OnlyPosting, int AChildLevel) { if (FHierarchyDetailTable.Rows.Count > 0) { FHierarchyDetailTable.DefaultView.Sort = AAccountHierarchyDetailTable.GetReportOrderDBName() + ", " + AAccountHierarchyDetailTable.GetReportingAccountCodeDBName(); foreach (DataRowView rv in FHierarchyDetailTable.DefaultView) { AAccountHierarchyDetailRow Row = (AAccountHierarchyDetailRow)rv.Row; if (Row.AccountCodeToReportTo.Equals(AAccountCode)) { if (Row.AccountHierarchyCode.Equals(STANDARD)) { Boolean includeThis = true; if (OnlyPosting) { Int32 pos = FAccountTable.DefaultView.Find(Row.ReportingAccountCode); if (pos >= 0) { AAccountRow account = (AAccountRow)FAccountTable.DefaultView[pos].Row; if (!account.PostingStatus) { includeThis = false; } } } if (includeThis) { help.Add(Row.ReportingAccountCode); } if (AChildLevel != 0) { GetChildrenIntern(help, Row.ReportingAccountCode, OnlyPosting, --AChildLevel); } } } } } }
private void InsertNodeIntoTreeView(GLSetupTDS MainDS, Int32 LedgerNumber, TreeNode AParent, DataView view, AAccountHierarchyDetailRow ADetailRow) { AAccountRow AccountRow = (AAccountRow)MainDS.AAccount.Rows.Find( new object[] { LedgerNumber, ADetailRow.ReportingAccountCode }); TreeNode Child = new TreeNode(); AccountNodeDetails NodeTag = AccountNodeDetails.AddNewAccount(Child, AccountRow, ADetailRow); NodeTag.IsNew = false; SetNodeLabel(AccountRow, Child); if (AParent == null) { trvAccounts.Nodes.Add(Child); } else { InsertInOrder(AParent, Child); } // Now add the children of this node: view.RowFilter = AAccountHierarchyDetailTable.GetAccountHierarchyCodeDBName() + " = '" + ADetailRow.AccountHierarchyCode + "' AND " + AAccountHierarchyDetailTable.GetAccountCodeToReportToDBName() + " = '" + ADetailRow.ReportingAccountCode + "'"; if (view.Count > 0) { // An account cannot be deleted if it has children. NodeTag.CanDelete = false; NodeTag.Msg = Catalog.GetString("Child accounts must be deleted first."); NodeTag.CanHaveChildren = true; foreach (DataRowView rowView in view) { AAccountHierarchyDetailRow accountDetail = (AAccountHierarchyDetailRow)rowView.Row; InsertNodeIntoTreeView(MainDS, LedgerNumber, Child, view, accountDetail); } } }
private bool AccountIsActive(string AAccountCode) { bool retVal = true; AAccountRow currentAccountRow = null; if (FAccountTable != null) { currentAccountRow = (AAccountRow)FAccountTable.Rows.Find(new object[] { FLedgerNumber, AAccountCode }); } if (currentAccountRow != null) { retVal = currentAccountRow.AccountActiveFlag; } return(retVal); }
/// <summary> /// This method is called when the system wants to draw a comboBox item in the list. /// We choose the colour and weight for the font, showing inactive codes in bold red text /// </summary> private void DrawComboBoxItem(object sender, DrawItemEventArgs e) { e.DrawBackground(); TCmbAutoComplete cmb = (TCmbAutoComplete)sender; DataRowView drv = (DataRowView)cmb.Items[e.Index]; string content = drv[1].ToString(); Brush brush = Brushes.Black; if (cmb.Name.StartsWith("cmbDetailBankCostCentre")) { if (FCostCentreTable != null) { ACostCentreRow row = (ACostCentreRow)FCostCentreTable.Rows.Find(new object[] { FLedgerNumber, content }); if ((row != null) && !row.CostCentreActiveFlag) { brush = Brushes.Red; } } } else if (cmb.Name.StartsWith("cmbDetailBankAccount")) { if (FAccountTable != null) { AAccountRow row = (AAccountRow)FAccountTable.Rows.Find(new object[] { FLedgerNumber, content }); if ((row != null) && !row.AccountActiveFlag) { brush = Brushes.Red; } } } else { throw new ArgumentException("Unexpected caller of DrawComboBoxItem event"); } Font font = new Font(((Control)sender).Font, (brush == Brushes.Red) ? FontStyle.Bold : FontStyle.Regular); e.Graphics.DrawString(content, font, brush, new PointF(e.Bounds.X, e.Bounds.Y)); }
private void LoadData() { bool NewTransaction = false; try { TDBTransaction transaction = DBAccess.GDBAccessObj.GetNewOrExistingTransaction(IsolationLevel.ReadCommitted, TEnforceIsolationLevel.eilMinimum, out NewTransaction); FAccountTable = AAccountAccess.LoadViaALedger( FLedgerInfo.LedgerNumber, transaction); } finally { if (NewTransaction) { DBAccess.GDBAccessObj.RollbackTransaction(); } } FAccountRow = null; }
/// <summary> /// </summary> /// <returns></returns> public string SetCarryForwardAccount() { FAccountRow = null; if (FAccountPropertyHandler == null) { FAccountPropertyHandler = new THandleAccountPropertyInfo(FLedgerInfo); } string result = FAccountPropertyHandler.GetAccountCode("CARRYFORWARDCC"); string[] arrStrHelp = result.Split(new Char[] { ',' }); if (arrStrHelp.Length < 2) { return(""); } AccountCode = arrStrHelp[0]; return(arrStrHelp[1]); }
/// <summary> /// Create an AccountNodeDetails object for this account /// </summary> public static AccountNodeDetails AddNewAccount(TreeNode NewTreeNode, AAccountRow AccountRow, AAccountHierarchyDetailRow HierarchyDetailRow) { AccountNodeDetails NodeDetails = new AccountNodeDetails(); NodeDetails.CanHaveChildren = true; if (AccountRow.PostingStatus) // A "Posting account" that's not been used may yet be promoted to a "Summary account". { NodeDetails.CanHaveChildren = null; } else // A "Summary account" can have children. { NodeDetails.CanHaveChildren = true; } NodeDetails.IsNew = true; NodeDetails.DetailRow = HierarchyDetailRow; NodeDetails.AccountRow = AccountRow; NewTreeNode.Tag = NodeDetails; NodeDetails.linkedTreeNode = NewTreeNode; return(NodeDetails); }
/// <summary> /// Get the actual amount /// </summary> /// <param name="ALedgerNumber"></param> /// <param name="AGLMSeqThisYear"></param> /// <param name="AGLMSeqNextYear"></param> /// <param name="APeriodNumber"></param> /// <param name="ANumberAccountingPeriods"></param> /// <param name="ACurrentFinancialYear"></param> /// <param name="AThisYear"></param> /// <param name="AYTD"></param> /// <param name="ABalSheetForwardPeriods"></param> /// <param name="ACurrencySelect"></param> /// <returns></returns> private static decimal GetActualInternal(int ALedgerNumber, int AGLMSeqThisYear, int AGLMSeqNextYear, int APeriodNumber, int ANumberAccountingPeriods, int ACurrentFinancialYear, int AThisYear, bool AYTD, bool ABalSheetForwardPeriods, string ACurrencySelect) { decimal retVal = 0; decimal currencyAmount = 0; bool incExpAccountFwdPeriod = false; //DEFINE BUFFER a_glm_period FOR a_general_ledger_master_period. //DEFINE BUFFER a_glm FOR a_general_ledger_master. //DEFINE BUFFER buf_account FOR a_account. if (AGLMSeqThisYear == -1) { return(retVal); } bool newTransaction = false; TDataBase db = DBAccess.Connect("GetActualInternal"); TDBTransaction dBTransaction = db.GetNewOrExistingTransaction(IsolationLevel.ReadCommitted, out newTransaction); AGeneralLedgerMasterTable generalLedgerMasterTable = null; AGeneralLedgerMasterRow generalLedgerMasterRow = null; AGeneralLedgerMasterPeriodTable generalLedgerMasterPeriodTable = null; AGeneralLedgerMasterPeriodRow generalLedgerMasterPeriodRow = null; AAccountTable AccountTable = null; AAccountRow AccountRow = null; try { if (APeriodNumber == 0) /* start balance */ { generalLedgerMasterTable = AGeneralLedgerMasterAccess.LoadByPrimaryKey(AGLMSeqThisYear, dBTransaction); generalLedgerMasterRow = (AGeneralLedgerMasterRow)generalLedgerMasterTable.Rows[0]; switch (ACurrencySelect) { case MFinanceConstants.CURRENCY_BASE: currencyAmount = generalLedgerMasterRow.StartBalanceBase; break; case MFinanceConstants.CURRENCY_INTERNATIONAL: currencyAmount = generalLedgerMasterRow.StartBalanceIntl; break; default: currencyAmount = generalLedgerMasterRow.StartBalanceForeign; break; } } else if (APeriodNumber > ANumberAccountingPeriods) /* forwarding periods only exist for the current financial year */ { if (ACurrentFinancialYear == AThisYear) { generalLedgerMasterPeriodTable = AGeneralLedgerMasterPeriodAccess.LoadByPrimaryKey(AGLMSeqThisYear, APeriodNumber, dBTransaction); generalLedgerMasterPeriodRow = (AGeneralLedgerMasterPeriodRow)generalLedgerMasterPeriodTable.Rows[0]; } else { generalLedgerMasterPeriodTable = AGeneralLedgerMasterPeriodAccess.LoadByPrimaryKey(AGLMSeqNextYear, (APeriodNumber - ANumberAccountingPeriods), dBTransaction); generalLedgerMasterPeriodRow = (AGeneralLedgerMasterPeriodRow)generalLedgerMasterPeriodTable.Rows[0]; } } else /* normal period */ { generalLedgerMasterPeriodTable = AGeneralLedgerMasterPeriodAccess.LoadByPrimaryKey(AGLMSeqThisYear, APeriodNumber, dBTransaction); generalLedgerMasterPeriodRow = (AGeneralLedgerMasterPeriodRow)generalLedgerMasterPeriodTable.Rows[0]; } if (generalLedgerMasterPeriodRow != null) { switch (ACurrencySelect) { case MFinanceConstants.CURRENCY_BASE: currencyAmount = generalLedgerMasterPeriodRow.ActualBase; break; case MFinanceConstants.CURRENCY_INTERNATIONAL: currencyAmount = generalLedgerMasterPeriodRow.ActualIntl; break; default: currencyAmount = generalLedgerMasterPeriodRow.ActualForeign; break; } } if ((APeriodNumber > ANumberAccountingPeriods) && (ACurrentFinancialYear == AThisYear)) { generalLedgerMasterTable = AGeneralLedgerMasterAccess.LoadByPrimaryKey(AGLMSeqThisYear, dBTransaction); generalLedgerMasterRow = (AGeneralLedgerMasterRow)generalLedgerMasterTable.Rows[0]; AccountTable = AAccountAccess.LoadByPrimaryKey(ALedgerNumber, generalLedgerMasterRow.AccountCode, dBTransaction); AccountRow = (AAccountRow)AccountTable.Rows[0]; if ((AccountRow.AccountCode.ToUpper() == MFinanceConstants.ACCOUNT_TYPE_INCOME.ToUpper()) || (AccountRow.AccountCode.ToUpper() == MFinanceConstants.ACCOUNT_TYPE_EXPENSE.ToUpper()) && !ABalSheetForwardPeriods) { incExpAccountFwdPeriod = true; currencyAmount -= GetActualInternal(ALedgerNumber, AGLMSeqThisYear, AGLMSeqNextYear, ANumberAccountingPeriods, ANumberAccountingPeriods, ACurrentFinancialYear, AThisYear, true, ABalSheetForwardPeriods, ACurrencySelect); } } if (!AYTD) { if (!((APeriodNumber == (ANumberAccountingPeriods + 1)) && incExpAccountFwdPeriod) && !((APeriodNumber == (ANumberAccountingPeriods + 1)) && (ACurrentFinancialYear > AThisYear))) { /* if it is an income expense acount, and we are in period 13, nothing needs to be subtracted, * because that was done in correcting the amount in the block above; * if we are in a previous year, in period 13, don't worry about subtracting. * * THIS IS CLEARLY INCORRECT - THE CONDITION ABOVE APPLIES *ONLY* IN THE FIRST FORWARDING PERIOD, NOT IN EVERY FORWARDING PERIOD. * IF THE METHOD IS ONLY CALLED FROM AUTOGENERATE BUDGETS, THIS IS PROBABLY INCONSEQUENTIAL. */ currencyAmount -= GetActualInternal(ALedgerNumber, AGLMSeqThisYear, AGLMSeqNextYear, (APeriodNumber - 1), ANumberAccountingPeriods, ACurrentFinancialYear, AThisYear, true, ABalSheetForwardPeriods, ACurrencySelect); } } retVal = currencyAmount; } finally { if (newTransaction) { dBTransaction.Rollback(); } } return(retVal); }
/// <summary> /// </summary> /// <returns></returns> public string SetCarryForwardAccount() { FAccountRow = null; if (FAccountPropertyHandler == null) { FAccountPropertyHandler = new THandleAccountPropertyInfo(FLedgerInfo); } string result = FAccountPropertyHandler.GetAccountCode("CARRYFORWARDCC"); string[] arrStrHelp = result.Split(new Char[] { ',' }); if (arrStrHelp.Length < 2) { return ""; } AccountCode = arrStrHelp[0]; return arrStrHelp[1]; }
/// <summary> /// Create an AccountNodeDetails object for this account /// </summary> public static AccountNodeDetails AddNewAccount(TreeNode NewTreeNode, AAccountRow AccountRow, AAccountHierarchyDetailRow HierarchyDetailRow) { AccountNodeDetails NodeDetails = new AccountNodeDetails(); NodeDetails.CanHaveChildren = true; if (AccountRow.PostingStatus) // A "Posting account" that's not been used may yet be promoted to a "Summary account". { NodeDetails.CanHaveChildren = null; } else // A "Summary account" can have children. { NodeDetails.CanHaveChildren = true; } NodeDetails.IsNew = true; NodeDetails.DetailRow = HierarchyDetailRow; NodeDetails.AccountRow = AccountRow; NewTreeNode.Tag = NodeDetails; NodeDetails.linkedTreeNode = NewTreeNode; return NodeDetails; }
/// <summary> /// To build a CSV list of accounts /// </summary> /// <param name="ALedgerNumber"></param> /// <param name="AAccountRowFirst"></param> /// <param name="DBTransaction"></param> /// <param name="AChildAccounts"></param> /// <param name="AVerificationResult"></param> private static void BuildChildAccountList(int ALedgerNumber, AAccountRow AAccountRowFirst, TDBTransaction DBTransaction, ref string AChildAccounts, ref TVerificationResultCollection AVerificationResult) { //Return value string AccountCode = AAccountRowFirst.AccountCode; //Error handling string ErrorContext = Catalog.GetString("List Child Accounts"); string ErrorMessage = String.Empty; //Set default type as non-critical TResultSeverity ErrorType = TResultSeverity.Resv_Noncritical; try { if (AAccountRowFirst.PostingStatus) { AChildAccounts += AccountCode + ","; } else { AAccountHierarchyDetailTable AccountHierarchyDetailTable1 = new AAccountHierarchyDetailTable(); AAccountHierarchyDetailRow TemplateRow = (AAccountHierarchyDetailRow)AccountHierarchyDetailTable1.NewRowTyped(false); TemplateRow.LedgerNumber = ALedgerNumber; TemplateRow.AccountHierarchyCode = MFinanceConstants.ACCOUNT_HIERARCHY_CODE; TemplateRow.AccountCodeToReportTo = AAccountRowFirst.AccountCode; StringCollection operators = StringHelper.InitStrArr(new string[] { "=", "=", "=" }); AAccountHierarchyDetailTable AccountHierarchyDetailTable2 = AAccountHierarchyDetailAccess.LoadUsingTemplate(TemplateRow, operators, null, DBTransaction); if (AccountHierarchyDetailTable2 != null) { for (int m = 0; m < AccountHierarchyDetailTable2.Count; m++) { AAccountHierarchyDetailRow AccountHierarchyDetailRow = (AAccountHierarchyDetailRow)AccountHierarchyDetailTable2.Rows[m]; AAccountTable AccountTable = AAccountAccess.LoadByPrimaryKey(ALedgerNumber, AccountHierarchyDetailRow.ReportingAccountCode, DBTransaction); if (AccountTable != null) { AAccountRow AccountRow = (AAccountRow)AccountTable.Rows[0]; BuildChildAccountList(ALedgerNumber, AccountRow, DBTransaction, ref AChildAccounts, ref AVerificationResult); } else { break; } } } } } catch (ArgumentException ex) { AVerificationResult.Add(new TVerificationResult(ErrorContext, ex.Message, ErrorType)); } catch (InvalidOperationException ex) { AVerificationResult.Add(new TVerificationResult(ErrorContext, ex.Message, ErrorType)); } catch (Exception ex) { ErrorMessage = String.Format(Catalog.GetString("Unknown error while building list of Child Accounts for Ledger: {0} and Account code: {1}" + Environment.NewLine + Environment.NewLine + ex.ToString()), ALedgerNumber, AAccountRowFirst.AccountCode ); ErrorType = TResultSeverity.Resv_Critical; AVerificationResult.Add(new TVerificationResult(ErrorContext, ErrorMessage, ErrorType)); } }
/// <summary> /// Reset the row list /// </summary> public void Reset() { FRowIdx = -1; FAccountRow = null; }
/// <summary> /// Move to the next row ... /// </summary> /// <returns></returns> public bool MoveNext() { ++FRowIdx; if (FRowIdx < FAccountTable.Rows.Count) { FAccountRow = (AAccountRow)FAccountTable[FRowIdx]; return true; } else { FAccountRow = null; return false; } }
/// <summary> /// Validates the GL Detail data. /// </summary> /// <param name="AContext">Context that describes where the data validation failed.</param> /// <param name="ABatchRow">Manually added to bring over some GL Batch fields</param> /// <param name="ARow">The <see cref="DataRow" /> which holds the the data against which the validation is run.</param> /// <param name="AVerificationResultCollection">Will be filled with any <see cref="TVerificationResult" /> items if /// data validation errors occur.</param> /// <param name="AValidationCostCentreTable">REQUIRED for importing. A reference to a cost centre table so that inputs can be validated.</param> /// <param name="AvalidationAccountTable">REQUIRED for importing. A reference to an account table so that inputs can be validated.</param> /// <returns>True if the validation found no data validation errors, otherwise false.</returns> public static bool ValidateGLDetailManual(object AContext, ABatchRow ABatchRow, ATransactionRow ARow, ref TVerificationResultCollection AVerificationResultCollection, ACostCentreTable AValidationCostCentreTable = null, AAccountTable AvalidationAccountTable = null) { DataColumn ValidationColumn; TVerificationResult VerificationResult = null; object ValidationContext; int VerifResultCollAddedCount = 0; // Don't validate deleted DataRows or non-unposted batches if ((ABatchRow.BatchStatus != MFinanceConstants.BATCH_UNPOSTED) || (ARow.RowState == DataRowState.Deleted)) { return(true); } bool isImporting = AContext.ToString().Contains("Importing"); // When used by the GUI TransactionAmount is not in the dictionary so had to pass the control directly // But when importing we do have a dictionary entry if (isImporting) { // 'GL amount must be non-zero and positive ValidationColumn = ARow.Table.Columns[ATransactionTable.ColumnTransactionAmountId]; if (true) { VerificationResult = TNumericalChecks.IsPositiveDecimal(ARow.TransactionAmount, String.Empty, AContext, ValidationColumn); // Handle addition/removal to/from TVerificationResultCollection if (AVerificationResultCollection.Auto_Add_Or_AddOrRemove(AContext, VerificationResult)) { VerifResultCollAddedCount++; } } } else { if (true) { // 'GL amount must be non-zero and positive ValidationColumn = ARow.Table.Columns[ATransactionTable.ColumnTransactionAmountId]; ValidationContext = String.Format("Transaction number {0} (batch:{1} journal:{2})", ARow.TransactionNumber, ARow.BatchNumber, ARow.JournalNumber); VerificationResult = TNumericalChecks.IsPositiveOrZeroDecimal(ARow.TransactionAmount, "Amount of " + ValidationContext, AContext, ValidationColumn); if (VerificationResult != null) { VerificationResult.SuppressValidationToolTip = true; } // Handle addition/removal to/from TVerificationResultCollection if (AVerificationResultCollection.Auto_Add_Or_AddOrRemove(AContext, VerificationResult)) { VerifResultCollAddedCount++; } return(VerifResultCollAddedCount == 0); } } // 'Narrative must not be empty ValidationColumn = ARow.Table.Columns[ATransactionTable.ColumnNarrativeId]; ValidationContext = String.Format("Transaction number {0} (batch:{1} journal:{2})", ARow.TransactionNumber, ARow.BatchNumber, ARow.JournalNumber); if (true) { VerificationResult = TStringChecks.StringMustNotBeEmpty(ARow.Narrative, (isImporting) ? String.Empty : "Narrative of " + ValidationContext, AContext, ValidationColumn); // Handle addition/removal to/from TVerificationResultCollection if (AVerificationResultCollection.Auto_Add_Or_AddOrRemove(AContext, VerificationResult)) { VerifResultCollAddedCount++; } } // 'Entered From Date' must be valid ValidationColumn = ARow.Table.Columns[ATransactionTable.ColumnTransactionDateId]; ValidationContext = String.Format("Transaction number {0} (batch:{1} journal:{2})", ARow.TransactionNumber, ARow.BatchNumber, ARow.JournalNumber); if (true) { DateTime StartDatePeriod; DateTime EndDatePeriod; TSharedFinanceValidationHelper.GetValidPeriodDates(ARow.LedgerNumber, ABatchRow.BatchYear, 0, ABatchRow.BatchPeriod, out StartDatePeriod, out EndDatePeriod); VerificationResult = (TScreenVerificationResult)TDateChecks.IsDateBetweenDates(ARow.TransactionDate, StartDatePeriod, EndDatePeriod, (isImporting) ? String.Empty : "Transaction Date for " + ValidationContext.ToString(), TDateBetweenDatesCheckType.dbdctUnspecific, TDateBetweenDatesCheckType.dbdctUnspecific, AContext, ValidationColumn); // Handle addition/removal to/from TVerificationResultCollection if (AVerificationResultCollection.Auto_Add_Or_AddOrRemove(AContext, VerificationResult)) { VerifResultCollAddedCount++; } } if (true) { // "Reference" is mandatory ValidationColumn = ARow.Table.Columns[ATransactionTable.ColumnReferenceId]; ValidationContext = String.Format("Transaction number {0} (batch:{1} journal:{2})", ARow.TransactionNumber, ARow.BatchNumber, ARow.JournalNumber); if (true) { VerificationResult = TStringChecks.StringMustNotBeEmpty(ARow.Reference, (isImporting) ? String.Empty : "Reference of " + ValidationContext, AContext, ValidationColumn); // Handle addition/removal to/from TVerificationResultCollection if (AVerificationResultCollection.Auto_Add_Or_AddOrRemove(AContext, VerificationResult)) { VerifResultCollAddedCount++; } } } // 'CostCentre' must be valid ValidationColumn = ARow.Table.Columns[ATransactionTable.ColumnCostCentreCodeId]; ValidationContext = String.Format("Transaction number {0} (batch:{1} journal:{2})", ARow.TransactionNumber, ARow.BatchNumber, ARow.JournalNumber); if (true) { if ((AValidationCostCentreTable != null) && !ARow.IsCostCentreCodeNull()) { // Code must exist in the cost centre table ACostCentreRow foundRow = (ACostCentreRow)AValidationCostCentreTable.Rows.Find( new object[] { ARow.LedgerNumber, ARow.CostCentreCode }); if ((foundRow == null) && AVerificationResultCollection.Auto_Add_Or_AddOrRemove( ValidationContext, new TVerificationResult(ValidationContext, String.Format(Catalog.GetString("Cost centre code '{0}' does not exist."), ARow.CostCentreCode), TResultSeverity.Resv_Critical))) { VerifResultCollAddedCount++; } // cost centre must be a posting cost centre if ((foundRow != null) && !foundRow.PostingCostCentreFlag) { if (AVerificationResultCollection.Auto_Add_Or_AddOrRemove(ValidationContext, new TVerificationResult(ValidationContext, String.Format(Catalog.GetString("Cost centre code '{0}' is not a posting cost centre."), ARow.CostCentreCode), TResultSeverity.Resv_Critical))) { VerifResultCollAddedCount++; } } //TODO: Maybe add a user preference to determine what to do with inactive values on importing // cost centre must not be inactive //if ((foundRow != null) && !foundRow.CostCentreActiveFlag) //{ // if (AVerificationResultCollection.Auto_Add_Or_AddOrRemove(ValidationContext, // new TVerificationResult(ValidationContext, // String.Format(Catalog.GetString("Cost centre code '{0}' is an inactive cost centre."), ARow.CostCentreCode), // TResultSeverity.Resv_Critical), // ValidationColumn)) // { // VerifResultCollAddedCount++; // } //} } } // 'Account code' must be valid ValidationColumn = ARow.Table.Columns[ATransactionTable.ColumnAccountCodeId]; ValidationContext = String.Format("Transaction number {0} (batch:{1} journal:{2})", ARow.TransactionNumber, ARow.BatchNumber, ARow.JournalNumber); if (true) { if ((AvalidationAccountTable != null) && !ARow.IsAccountCodeNull()) { // Code must exist in the account table AAccountRow foundRow = (AAccountRow)AvalidationAccountTable.Rows.Find( new object[] { ARow.LedgerNumber, ARow.AccountCode }); if ((foundRow == null) && AVerificationResultCollection.Auto_Add_Or_AddOrRemove( ValidationContext, new TVerificationResult(ValidationContext, String.Format(Catalog.GetString("Account code '{0}' does not exist."), ARow.AccountCode), TResultSeverity.Resv_Critical))) { VerifResultCollAddedCount++; } // Account code must be a posting Account code if ((foundRow != null) && !foundRow.PostingStatus) { if (AVerificationResultCollection.Auto_Add_Or_AddOrRemove(ValidationContext, new TVerificationResult(ValidationContext, String.Format(Catalog.GetString("Account code '{0}' is not a posting account."), ARow.AccountCode), TResultSeverity.Resv_Critical))) { VerifResultCollAddedCount++; } } //TODO: Maybe add a user preference to determine what to do with inactive values on importing // Account code must not be inactive //if ((foundRow != null) && !foundRow.AccountActiveFlag) //{ // if (AVerificationResultCollection.Auto_Add_Or_AddOrRemove(ValidationContext, // new TVerificationResult(ValidationContext, // String.Format(Catalog.GetString("Account code '{0}' is an inactive account."), ARow.AccountCode), // TResultSeverity.Resv_Critical), // ValidationColumn)) // { // VerifResultCollAddedCount++; // } //} } } return(VerifResultCollAddedCount == 0); }
/// <summary> /// Process the account code parent codes /// </summary> private static void ProcessAccountParent( int ALedgerNumber, string CurrAccountCode, bool ADebitCreditIndicator, string ACostCentreList, ABudgetRow ABudgetRow, List <ABudgetPeriodRow> ABudgetPeriods) { AAccountRow AccountRow = (AAccountRow)GLPostingDS.AAccount.Rows.Find(new object[] { ALedgerNumber, CurrAccountCode }); AAccountHierarchyDetailRow AccountHierarchyDetailRow = (AAccountHierarchyDetailRow)GLPostingDS.AAccountHierarchyDetail.Rows.Find( new object[] { ALedgerNumber, MFinanceConstants.ACCOUNT_HIERARCHY_STANDARD, CurrAccountCode }); if (AccountHierarchyDetailRow != null) { string AccountCodeToReportTo = AccountHierarchyDetailRow.AccountCodeToReportTo; if ((AccountCodeToReportTo != null) && (AccountCodeToReportTo != string.Empty)) { /* Recursively call this procedure. */ ProcessAccountParent( ALedgerNumber, AccountCodeToReportTo, ADebitCreditIndicator, ACostCentreList, ABudgetRow, ABudgetPeriods); } } int DebitCreditMultiply = 1; /* needed if the debit credit indicator is not the same */ /* If the account has the same db/cr indicator as the original * account for which the budget was created, add the budget amount. * Otherwise, subtract. */ if (AccountRow.DebitCreditIndicator != ADebitCreditIndicator) { DebitCreditMultiply = -1; } string[] CostCentres = ACostCentreList.Split(':'); string AccCode = AccountRow.AccountCode; /* For each associated Cost Centre, update the General Ledger Master. */ foreach (string CostCentreCode in CostCentres) { int glmRowIndex = GLPostingDS.AGeneralLedgerMaster.DefaultView.Find(new object[] { ALedgerNumber, ABudgetRow.Year, AccCode, CostCentreCode }); if (glmRowIndex == -1) { TGLPosting.CreateGLMYear(ref GLPostingDS, ALedgerNumber, ABudgetRow.Year, AccCode, CostCentreCode); glmRowIndex = GLPostingDS.AGeneralLedgerMaster.DefaultView.Find(new object[] { ALedgerNumber, ABudgetRow.Year, AccCode, CostCentreCode }); } int GLMSequence = ((AGeneralLedgerMasterRow)GLPostingDS.AGeneralLedgerMaster.DefaultView[glmRowIndex].Row).GlmSequence; /* Update totals for the General Ledger Master period record. */ foreach (ABudgetPeriodRow BPR in ABudgetPeriods) { AddBudgetValue(GLMSequence, BPR.PeriodNumber, DebitCreditMultiply * BPR.BudgetBase); } } }
private void DeleteAccount(Object sender, EventArgs ev) { string AccountCode = FCurrentAccount.DetailRow.ReportingAccountCode; if (!FCurrentAccount.CanDelete.HasValue) { MessageBox.Show(Catalog.GetString("Fault: CanDelete status is unknown."), Catalog.GetString( "Delete Account"), MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (!FCurrentAccount.CanDelete.Value) { MessageBox.Show( String.Format(Catalog.GetString( "Account {0} cannot be deleted. You can deactivate the account, but not delete it."), AccountCode) + "\r\n" + FCurrentAccount.Msg, Catalog.GetString("Delete Account"), MessageBoxButtons.OK, MessageBoxIcon.Error); return; } ucoAccountsTree.DeleteSelectedAccount(); // Calling this changes the current FCurrentAccount to the parent of the deleted account! // // If this account has analysis Attributes, // I need to remove them. if (FMainDS.AAnalysisAttribute != null) { DataView DeleteThese = new DataView(FMainDS.AAnalysisAttribute); DeleteThese.RowFilter = String.Format("a_ledger_number_i={0} AND a_account_code_c='{1}'", FLedgerNumber, AccountCode); foreach (DataRowView rv in DeleteThese) { DataRow TempRow = rv.Row; TempRow.Delete(); } } AAccountHierarchyDetailRow AccountHDetailToBeDeleted = (AAccountHierarchyDetailRow)FMainDS.AAccountHierarchyDetail.Rows.Find( new object[] { FLedgerNumber, FSelectedHierarchy, AccountCode }); AccountHDetailToBeDeleted.Delete(); // // I can delete this account if it no longer appears in any Hieararchy. DataView AHD_stillInUse = new DataView(FMainDS.AAccountHierarchyDetail); AHD_stillInUse.RowFilter = String.Format("a_ledger_number_i={0} AND a_reporting_account_code_c='{1}'", FLedgerNumber, AccountCode); if (AHD_stillInUse.Count == 0) { AAccountRow AccountToBeDeleted = (AAccountRow)FMainDS.AAccount.Rows.Find( new object[] { FLedgerNumber, AccountCode }); AccountToBeDeleted.Delete(); } else { MessageBox.Show(String.Format( Catalog.GetString( "The account {0} is removed from the {1} hierarchy, but not deleted, since it remains part of another heirarchy."), AccountCode, FSelectedHierarchy), Catalog.GetString("Delete Account"), MessageBoxButtons.OK, MessageBoxIcon.Information); } // FCurrentAccount is now the parent of the account that was just deleted. // If the parent account now has no accounts reporting to it (in any hierarchies), mark it as posting account. FCurrentAccount.GetAttrributes(); tbbDeleteAccount.Enabled = (FCurrentAccount.CanDelete.HasValue ? FCurrentAccount.CanDelete.Value : false); AAccountRow ParentAccountRow = FCurrentAccount.AccountRow; AHD_stillInUse.RowFilter = String.Format("a_ledger_number_i={0} AND a_account_code_to_report_to_c='{1}'", FLedgerNumber, ParentAccountRow.AccountCode); if (AHD_stillInUse.Count == 0) // No-one now reports to this account, so I can mark it as "Posting" { // Note that since the "Posting" status is now editable, this is unneccessary and may be inappropriate. ParentAccountRow.PostingStatus = true; chkDetailForeignCurrencyFlag.Enabled = (!ParentAccountRow.SystemAccountFlag); cmbDetailForeignCurrencyCode.Enabled = (!ParentAccountRow.SystemAccountFlag && ParentAccountRow.ForeignCurrencyFlag); // It's possible this account could now be deleted, but the user would need to save and re-load first, // if the server still has it down as a summary account. } FPetraUtilsObject.SetChangedFlag(); }