示例#1
0
        public FinancialBalance GetFinancial()
        {
            FinancialBalance fb = new FinancialBalance();

            fb.Node             = erpNodeDBContext._dbName;
            fb.AssetBalance     = this.AssetAccounts.Sum(i => i.CurrentBalance);
            fb.LiabilityBalance = this.LiabilityAccounts.Sum(i => i.CurrentBalance);
            fb.EquityBalance    = fb.AssetBalance - fb.LiabilityBalance;

            fb.ExpenseBalance = this.organization.FiscalYears.CurrentPeriod.Expense;
            fb.IncomeBalance  = this.organization.FiscalYears.CurrentPeriod.Income;
            return(fb);
        }
示例#2
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;
        }