void insertOrUpdateAccount(string account, GLClosingSheetLineLocal lin, GLClosingSheetLineLocal clone) { if (account != null && account != masterAccount._Account) { var acc = FindAccount(account); if (acc != null) { var accLines = acc.Lines; if (accLines == null) { acc.Lines = new List <GLClosingSheetLineLocal>() { clone } } ; else { var linOffset = FindLine(accLines, lin.RowId); if (linOffset == null) { ((List <GLClosingSheetLineLocal>)accLines).Add(clone); } else { StreamingManager.Copy(lin, linOffset); } } SumLines(acc); } } }
void BindClosingSheet(GLAccountClosingSheetClient acc) { if (acc != null) { this.primo = acc.OrgBalance; this.masterAccount = acc; var Account = acc._Account; dgClosingSheetLine.MasterAccount = Account; List <GLClosingSheetLineLocal> lst = new List <GLClosingSheetLineLocal>(); if (acc.Lines != null) { foreach (var l in acc.Lines) { var lin = new GLClosingSheetLineLocal(); StreamingManager.Copy(l, lin); lst.Add(lin); lin.Swap = (lin._OffsetAccount == Account); } } dgClosingSheetLine.ItemsSource = lst; dgClosingSheetLine.SelectRange(0, 0); dgClosingSheetLine.Visibility = Visibility.Visible; } }
private void localMenu_OnItemClicked(string ActionType) { var trans = dgAccountsTransGrid.SelectedItem as GLTransClient; switch (ActionType) { case "AddRow": dgClosingSheetLine.AddRow(); break; case "CopyRow": dgClosingSheetLine.CopyRow(); RecalculateSum(); break; case "SaveGrid": saveGrid(); break; case "DeleteRow": dgClosingSheetLine.DeleteRow(); RecalculateSum(); break; case "VoucherTransactions": if (trans == null) { return; } string vheader = string.Format("{0} ({1})", Uniconta.ClientTools.Localization.lookup("VoucherTransactions"), trans._Voucher); AddDockItem(TabControls.AccountsTransaction, dgAccountsTransGrid.syncEntity, vheader); break; case "ReverseVoucher": if (trans == null) { return; } GLClosingSheetLineLocal closingLine = new GLClosingSheetLineLocal(); closingLine.Account = trans._Account; closingLine.Text = trans._Text; closingLine.TransType = trans._TransType; closingLine.Dimension1 = trans._Dimension1; closingLine.Dimension2 = trans._Dimension2; closingLine.Dimension3 = trans._Dimension3; closingLine.Dimension4 = trans._Dimension4; closingLine.Dimension5 = trans._Dimension5; closingLine.Amount = -trans._Amount; dgClosingSheetLine.AddRow(closingLine); RecalculateSum(); break; default: gridRibbon_BaseActions(ActionType); break; } }
protected async override Task <ErrorCodes> saveGrid() { if (!dgClosingSheetLine.HasUnsavedData) { return(ErrorCodes.Succes); } anyChange = true; dgClosingSheetLine.SelectedItem = null; var err = await dgClosingSheetLine.SaveData(); if (err == 0 && masterAccount != null) { var Account = masterAccount._Account; var Lines = dgClosingSheetLine.ItemsSource as List <GLClosingSheetLineLocal>; if (masterAccount.Lines != null) { // first loop over the old lines and find lines that has been deleted or offset account has changed foreach (var oldLin in masterAccount.Lines) { var RowId = oldLin.RowId; var newLin = FindLine(Lines, RowId); if (newLin != null) { if (newLin._Account != oldLin._Account) { removeAccount(oldLin._Account, RowId); } if (newLin._OffsetAccount != oldLin._OffsetAccount) { removeAccount(oldLin._OffsetAccount, RowId); } } else // line has been delete { removeAccount(oldLin._Account, RowId); removeAccount(oldLin._OffsetAccount, RowId); if (oldLin._Account != oldLin._ShowOnAccount) { removeAccount(oldLin._ShowOnAccount, RowId); } } } } // loop over the new lines and update offset accounts List <GLClosingSheetLineLocal> lst = new List <GLClosingSheetLineLocal>(); foreach (var lin in Lines) { var clone = new GLClosingSheetLineLocal(); StreamingManager.Copy(lin, clone); insertOrUpdateAccount(lin._Account, lin, clone); insertOrUpdateAccount(lin._OffsetAccount, lin, clone); if (lin._Account != lin._ShowOnAccount) { insertOrUpdateAccount(lin._ShowOnAccount, lin, clone); } lst.Add(clone); } masterAccount.Lines = lst; SumLines(masterAccount); } BindTransactionGrid(); return(err); }
void AddLineToAccount(string account, GLClosingSheetLineClient lin, int factor) { var ac = (GLAccountClosingSheetClient)AccountListCache.Get(account); if (ac != null) { ac._TmpChange += lin._AmountCent * factor; if (ac.Lines != null) { ((List <GLClosingSheetLineClient>)ac.Lines).Add(lin); } else { ac.Lines = new List <GLClosingSheetLineClient>() { lin } }; } } void UpdateLines(GLClosingSheetLine[] ClosingLines, GLTrans[] PostedLines) { if (ClosingLines == null) { return; } var AccountListCache = this.AccountListCache; var ReconciledDate = masterRecord._ToDate; foreach (var ac in (GLAccountClosingSheetClient[])AccountListCache.GetNotNullArray) { ac._TmpChange = 0; ac.Lines = null; if (ac.ReconciledDate == DateTime.MinValue) { ac.ReconciledDate = ReconciledDate; } } int factor = (PostedLines != null) ? 0 : 1; foreach (var _lin in ClosingLines) { var lin = _lin as GLClosingSheetLineClient; if (lin == null) { lin = new GLClosingSheetLineLocal(); StreamingManager.Copy(_lin, lin); } AddLineToAccount(lin._Account, lin, factor); if (lin._ShowOnAccount != null && lin._ShowOnAccount != lin._Account) { AddLineToAccount(lin._ShowOnAccount, lin, factor); } if (lin._OffsetAccount != null) { AddLineToAccount(lin._OffsetAccount, lin, -factor); } } if (PostedLines != null) { foreach (var lin in PostedLines) { var ac = (GLAccountClosingSheetClient)AccountListCache.Get(lin._Account); if (ac != null) { ac._TmpChange += lin._AmountCent; } } } var SumCol = new List <FinancialBalance>(); foreach (var ac in (GLAccountClosingSheetClient[])AccountListCache.GetNotNullArray) { if (ac._TmpChange != 0) { var bal = new FinancialBalance(); bal.AccountRowId = ac.RowId; bal._Debit = ac._TmpChange; bal._Credit = 0; SumCol.Add(bal); } } var BalanceChange = SumCol.ToArray(); var balance = rApi.Format(BalanceChange, LedgerCache); foreach (var bal in balance) { var ac = (GLAccountClosingSheetClient)AccountListCache.Get(bal.Account.RowId); ac?.setChange(bal.SumAll()); } SumCol.Clear(); foreach (var ac in (GLAccountClosingSheetClient[])AccountListCache.GetNotNullArray) { if ((ac._OrgBalance != 0 || ac._Change != 0) && ac._PostingAccount) { var bal = new FinancialBalance(); bal.AccountRowId = ac.RowId; bal._Debit = ac._OrgBalance + ac._Change; bal._Credit = 0; SumCol.Add(bal); } } var NewBalance = SumCol.ToArray(); balance = rApi.Format(NewBalance, LedgerCache); foreach (var bal in balance) { var ac = (GLAccountClosingSheetClient)AccountListCache.Get(bal.Account.RowId); ac?.setNewBalance(bal.SumAll()); } } async Task BindGrid(bool ForceLoadAcc = false) { busyIndicator.IsBusy = true; var rApi = this.rApi; var api = this.api; LedgerCache = api.CompanyEntity.GetCache(typeof(GLAccount)) ?? await api.CompanyEntity.LoadCache(typeof(GLAccount), api); var masterRecord = this.masterRecord; var numbers = await rApi.GenerateTotals(masterRecord._FromDate, masterRecord._ToDate); if (numbers == null || LedgerCache == null) { return; } BalanceHeader[] balance = rApi.Format(numbers, LedgerCache); var LocalAccounts = new List <GLAccountClosingSheetClient>(); var FromAccount = masterRecord._FromAccount; var ToAccount = masterRecord._ToAccount; foreach (var bal in balance) { var ac = bal.Account; if (FromAccount != null && string.Compare(ac._Account, FromAccount, StringComparison.CurrentCultureIgnoreCase) < 0) { continue; } if (ToAccount != null && string.Compare(ac._Account, ToAccount, StringComparison.CurrentCultureIgnoreCase) > 0) { continue; } var ac2 = new GLAccountClosingSheetClient(); StreamingManager.Copy(ac, ac2); ac2._OrgBalance = bal.SumAll(); ac2._LastPeriod = 0; LocalAccounts.Add(ac2); } this.AccountListCache = new SQLCache(LocalAccounts.ToArray(), true); if (masterRecord._FromDate2 != DateTime.MinValue) { numbers = null; balance = null; numbers = await rApi.GenerateTotals(masterRecord._FromDate2, masterRecord._ToDate2); if (numbers != null) { balance = rApi.Format(numbers, LedgerCache); foreach (var bal in balance) { var ac = (GLAccountClosingSheetClient)AccountListCache.Get(bal.Account.RowId); if (ac != null) { ac._LastPeriod = bal.SumAll(); } } } } numbers = null; balance = null; RefreshLines(); dgGLTable.SelectRange(0, 0); dgGLTable.Visibility = Visibility.Visible; }