示例#1
0
        private async Task <ResponseAccountBalance> CalcAccountByCodeAsync(int organId, string code, BalanceType balanceType)
        {
            var organId2 = Convert.ToInt32(SecurityManager.CurrentUserContext.OrganizationId);

            var     responseAccountBalance = new ResponseAccountBalance();
            decimal amount = 0;

            TransactionRule transactionRule = new TransactionRule();
            var             transactions    = await transactionRule.GetAllByOrganIdAsync(organId);

            AccountRule accountRule = new AccountRule();
            var         accounts    = await accountRule.GetAllByOrganIdAsync(organId);

            var operatinIncomeAccount = accounts.Where(x => x.ComplteCoding == code).SingleOrDefault();

            var accountsMoienQuery = accounts.AsQueryable().Where(x => x.ParentId == operatinIncomeAccount.ID);

            var allAccountQuery = accounts.AsQueryable();

            List <int> childIds = (from account in accountsMoienQuery
                                   select account.ID).ToList();

            List <int> childChildIds = (from account in allAccountQuery
                                        join accountsMoien in accountsMoienQuery
                                        on account.ParentId equals accountsMoien.ID
                                        select account.ID).ToList();


            var selected = transactions.Where(a => a.AccountId == operatinIncomeAccount.ID || childIds.Contains(a.AccountId) || childChildIds.Contains(a.AccountId)).ToList();

            responseAccountBalance.Type = 2;
            if (selected.Any())
            {
                var credit = selected.Sum(x => x.Credit);
                var debit  = selected.Sum(x => x.Debit);

                if (balanceType == BalanceType.Debit)
                {
                    amount = debit - credit;

                    if (amount > 0)
                    {
                        responseAccountBalance.Type = 0;
                    }
                    else
                    {
                        responseAccountBalance.Type = 1;
                    }
                }
                else if (balanceType == BalanceType.Credit)
                {
                    amount = credit - debit;
                    if (amount < 0)
                    {
                        responseAccountBalance.Type = 0;
                    }
                    else
                    {
                        responseAccountBalance.Type = 1;
                    }
                }

                responseAccountBalance.Balance = Math.Abs(amount);
            }

            return(responseAccountBalance);
        }
示例#2
0
        public virtual async Task <HttpResponseMessage> GetFinanAccountsBalance()
        {
            var organId = Convert.ToInt32(SecurityManager.CurrentUserContext.OrganizationId);

            AccountRule accountRule = new AccountRule();
            var         accounts    = await accountRule.GetAllByOrganIdAsync(organId);

            accounts = accounts.Where(x => x.Level == AccountType.Moen).ToList();
            var responseFinanAccounts = new ResponseFinanAccounts();

            responseFinanAccounts.systemAccountTypes = new[] { "حساب های دریافتنی", "حساب های پرداختنی",
                                                               "صندوق", "بانک", "تنخواه گردان", "اسناد دریافتنی", "اسناد پرداختنی", "اسناد در جریان وصول",
                                                               "موجودی کالا", "فروش", "خرید", "برگشت از فروش", "برگشت از خرید", "مالیات بر ارزش افزوده",
                                                               "مالیات بر ارزش افزوده فروش", "مالیات بر ارزش افزوده خرید", "مالیات بر درآمد", "فروش خدمات",
                                                               "هزینه خدمات خریداری شده", "سرمایه اولیه", "افزایش یا کاهش سرمایه", "برداشت", "سهم سود و زیان",
                                                               "تخفیفات نقدی خرید", "تخفیفات نقدی فروش", "هزینه ضایعات کالا", "کنترل ضایعات کالا", "حقوق", "تراز افتتاحیه",
                                                               "تراز اختتامیه", "خلاصه سود و زیان", "سود انباشته" };

            responseFinanAccounts.finanAccounts = new List <FinanAccount>();

            var finanAccounts = new FinanAccount();

            foreach (var account in accounts)
            {
                var parentAccount = await accountRule.FindAsync(account.ParentId);

                var parentParentAccount = await accountRule.FindAsync(parentAccount.ParentId);

                ResponseAccountBalance res = new ResponseAccountBalance();
                if (parentParentAccount.ComplteCoding == "1" || parentParentAccount.ComplteCoding == "5" || parentParentAccount.ComplteCoding == "8")
                {
                    res = await CalcAccountByCodeAsync(organId, account.ComplteCoding, BalanceType.Debit);
                }
                else
                {
                    res = await CalcAccountByCodeAsync(organId, account.ComplteCoding, BalanceType.Credit);
                }


                finanAccounts = new FinanAccount();

                finanAccounts.Balance     = res.Balance;
                finanAccounts.BalanceType = res.Type;
                finanAccounts.Code        = account.Coding;
                finanAccounts.Coding      = account.ComplteCoding;
                finanAccounts.credit      = res.SumCredit;
                finanAccounts.debit       = res.SumDebit;
                finanAccounts.Id          = account.ID;
                finanAccounts.Level       = account.Level;
                finanAccounts.LevelString = "معین";
                finanAccounts.Name        = account.Name.Replace("(گروه)", "").Replace("(کل)", "").Replace("(معین)", "");

                if (parentAccount != null)
                {
                    finanAccounts.ParentCoding = parentAccount.ComplteCoding;
                }
                finanAccounts.SystemAccountName = account.Name;
                responseFinanAccounts.finanAccounts.Add(finanAccounts);
            }



            return(Request.CreateResponse(HttpStatusCode.OK, new { resultCode = (int)ResultCode.Successful, data = responseFinanAccounts }));
        }