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;
            }
        }
Пример #2
0
 public override void Utility_Refresh(string screenName, object argument = null)
 {
     if (screenName == TabControls.ClosingSheetLinesAll)
     {
         BindGrid();
         mainList = null;
         ClosingSheetHasLinesList = null;
     }
     else if (screenName == TabControls.GLAccountPage2)
     {
         var args   = argument as object[];
         var entity = args[1] as GLAccountClient;
         if (entity != null)
         {
             var closingSheetAccount = new GLAccountClosingSheetClient();
             StreamingManager.Copy(entity, closingSheetAccount);
             args[1] = closingSheetAccount;
             dgGLTable.UpdateItemSource(args);
         }
     }
     else if (screenName == TabControls.UserNotesPage || screenName == TabControls.UserDocsPage && argument != null)
     {
         dgGLTable.UpdateItemSource(argument);
     }
 }
        void SumLines(GLAccountClosingSheetClient acc)
        {
            var sum = RecalculateSum((IEnumerable <GLClosingSheetLineLocal>)acc.Lines, acc._Account, this.postingDate, this.RoundTo100, this.VatCache);

            acc.setChangeAndNewBalance(sum);
        }
Пример #4
0
        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;
        }
Пример #5
0
        void localMenu_OnItemClicked(string ActionType)
        {
            GLAccountClosingSheetClient selectedItem = dgGLTable.SelectedItem as GLAccountClosingSheetClient;

            switch (ActionType)
            {
            case "ClosingSheetLines":
                if (selectedItem == null || !selectedItem._PostingAccount)
                {
                    return;
                }
                object[] masters = new object[] { masterRecord, dgGLTable.syncEntity, this.AccountListCache };
                AddDockItem(TabControls.ClosingSheetLines, masters, string.Format("{0}: {1}, {2}", Uniconta.ClientTools.Localization.lookup("ClosingSheetLines"), selectedItem._Account, masterRecord._Name));
                break;

            case "ClosingSheetLinesAll":
                object[] masters2 = new object[] { masterRecord };
                AddDockItem(TabControls.ClosingSheetLinesAll, masters2, string.Format("{0}: {1}", masterRecord._Name, Uniconta.ClientTools.Localization.lookup("AllLines")));
                break;

            case "ClosingSheetHasLines":
                ClosingSheetHasLines();
                break;

            case "PostClosingSheet":
                if (selectedItem != null)
                {
                    PostClosingSheet();
                }
                break;

            case "DeleteClosingSheetLine":
                if (selectedItem != null)
                {
                    DeleteClosingSheetLine();
                }
                break;

            case "RefreshGrid":
                RefreshLines();
                break;

            case "AccountStatement":
                AddDockItem(TabControls.AccountsStatementReport, masterRecord, Uniconta.ClientTools.Localization.lookup("AccountsStatement"));
                break;

            case "ReportCriteria":
                AddDockItem(TabControls.ReportCriteria, masterRecord, string.Format("{0} - {1}", Uniconta.ClientTools.Localization.lookup("ReportCriteria"), masterRecord._Name));
                break;

            case "AddNote":
                if (selectedItem != null)
                {
                    AddDockItem(TabControls.UserNotesPage, dgGLTable.syncEntity);
                }
                break;

            case "AddDoc":
                if (selectedItem != null)
                {
                    AddDockItem(TabControls.UserDocsPage, dgGLTable.syncEntity, string.Format("{0}: {1}", Uniconta.ClientTools.Localization.lookup("Documents"), selectedItem._Name));
                }
                break;

            case "AllNotes":
                object[] masters3 = new object[] { api, this.AccountListCache };
                AddDockItem(TabControls.AllNotesPage, masters3, Uniconta.ClientTools.Localization.lookup("Notes"));
                break;

            case "AddItem":
                AddDockItem(TabControls.GLAccountPage2, api, Uniconta.ClientTools.Localization.lookup("Accounts"), "Add_16x16.png");
                break;

            case "EditItem":
                if (selectedItem == null)
                {
                    return;
                }
                var param = new object[2] {
                    selectedItem, true
                };
                AddDockItem(TabControls.GLAccountPage2, param, string.Format("{0}: {1}", Uniconta.ClientTools.Localization.lookup("Accounts"), selectedItem.Account));
                break;

            default:
                gridRibbon_BaseActions(ActionType);
                break;
            }
        }