public static SortableBindingList<Kunchik> GetAccountsTest(DateTime startDate, DateTime endDate, decimal[] balCodes, int? deptId)
        {
            var list = new Dictionary<List<AccountStatementRecord>, AltasoftAPI.AccountsAPI.Account>();
            var list2 = new List<Kunchik>();

            #region AccountsService
            AltasoftAPI.AccountsAPI.AccountsService a = new AltasoftAPI.AccountsAPI.AccountsService();
            a.RequestHeadersValue = new AltasoftAPI.AccountsAPI.RequestHeaders() { ApplicationKey = "BusinessCreditClient", RequestId = Guid.NewGuid().ToString() };
            #endregion

            var lll = new Dictionary<AccountStatement, AltasoftAPI.AccountsAPI.Account>();

            var result = new List<AltasoftAPI.AccountsAPI.Account>();

            foreach (var balCode in balCodes)
            {
                result.AddRange(a.ListAccounts(new ListAccountsQuery()
                {
                    ControlFlags = AccountControlFlags.Basic | AccountControlFlags.Balances,
                    BalAcc = balCode,
                    BalAccSpecified = true,
                    DeptId = deptId,
                    DeptIdSpecified = deptId.HasValue
                }));
            }

            foreach (var item in result)
            {
                AccountStatement bal = a.GetStatement(new InternalAccountIdentification() { IBAN = item.IBAN, Ccy = item.Ccy }, new Period() { Start = startDate.Date, End = endDate.Date }, true, true, TransactionStatus.Green, true, 0, false);

                lll.Add(bal, item);
            }

            foreach (var item in lll)
                foreach (var item2 in item.Key.Records)
                    list.Add(item.Key.Records.ToList(), item.Value);

            foreach (var item in list)
            {
                foreach (var itt in item.Key)
                {

                    list2.Add(new Kunchik()
                    {
                        AccountNumber = item.Value.AccountNumber,
                        AccountNumberSpecified = item.Value.AccountNumberSpecified,
                        Balance = itt.Balance,
                        BalanceEqu = itt.BalanceEqu,
                        BalanceEquSpecified = itt.BalanceEquSpecified,
                        BranchId = item.Value.BranchId,
                        BranchIdSpecified = item.Value.BranchIdSpecified,
                        Ccy = item.Value.Ccy,
                        CreditAmount = itt.CreditAmount,
                        CreditAmountEqu = itt.CreditAmountEqu,
                        CreditAmountEquSpecified = itt.CreditAmountEquSpecified,
                        CreditAmountSpecified = itt.CreditAmountSpecified,
                        Date = itt.Date,
                        DebitAmount = itt.DebitAmount,
                        DebitAmountEqu = itt.DebitAmountEqu,
                        DebitAmountEquSpecified = itt.DebitAmountEquSpecified,
                        DebitAmountSpecified = itt.DebitAmountSpecified,
                        DocNum = itt.DocNum,
                        DocNumSpecified = itt.DocNumSpecified,
                        ExtraDescription = itt.ExtraDescription,
                        IBAN = item.Value.IBAN,
                        Id = item.Value.Id,
                        IdSpecified = item.Value.IdSpecified,
                        OpCode = itt.OpCode,
                        OrderDate = itt.OrderDate,
                        OrderDateSpecified = itt.OrderDateSpecified,
                        OrderId = itt.OrderId,
                        Purpose = itt.Purpose,
                        Status = itt.Status,
                        TransactionType = itt.TransactionType,
                        AccountName = item.Value.DisplayName.ValueGeo,
                        BC_IBAN = itt.PartnerAccountId.IBAN
                    });
                }
            }

            return new SortableBindingList<Kunchik>(list2.GroupBy(x => x.OrderId).Select(x => x.First()).ToList());

            //TaxOrderGenerator.ExportToExcel(new SortableBindingList<object>(list2), typeof(Kunchik));

            //var list2 = list.GroupBy(x => x.Date);

            //var list3 = new List<BalanceReportModel>();

            //foreach (var item in list2)
            //{
            //    list3.Add(new BalanceReportModel()
            //    {
            //        Date = item.FirstOrDefault().Date,
            //        Balance = item.Sum(x => x.Balance)
            //    });
            //}

            //return new SortableBindingList<BalanceReportModel>(list3);
        }
        public static SortableBindingList<BalanceReportModel> GetAccounts(DateTime startDate, DateTime endDate, decimal? balCode, int? deptId)
        {
            var dates = new List<DateTime>();

            for (var date = startDate; date <= endDate; date = date.AddDays(1))
                dates.Add(startDate);

            var list = new List<BalanceReportModel>();

            AltasoftAPI.AccountsAPI.Account[] result = null;

            foreach (var date in dates)
            {
                #region AccountsService
                AltasoftAPI.AccountsAPI.AccountsService a = new AltasoftAPI.AccountsAPI.AccountsService();
                a.RequestHeadersValue = new AltasoftAPI.AccountsAPI.RequestHeaders() { ApplicationKey = "BusinessCreditClient", RequestId = Guid.NewGuid().ToString() };
                #endregion

                var lll = new List<AccountStatement>();

                result = a.ListAccounts(new ListAccountsQuery()
                {
                    ControlFlags = AccountControlFlags.Basic | AccountControlFlags.Balances,
                    BalAcc = balCode,
                    BalAccSpecified = balCode.HasValue,
                    DeptId = deptId,
                    DeptIdSpecified = deptId.HasValue
                });

                foreach (var item in result)
                {
                    AccountStatement bal;

                    if (item.Ccy == "GEL")
                        bal = a.GetStatement(new InternalAccountIdentification() { IBAN = item.IBAN, Ccy = item.Ccy }, new Period() { Start = date, End = date }, false, false, TransactionStatus.Green, true, 0, false);
                    else
                        bal = a.GetStatement(new InternalAccountIdentification() { IBAN = item.IBAN, Ccy = item.Ccy }, new Period() { Start = date, End = date }, true, true, TransactionStatus.Green, true, 0, false);
                    lll.Add(bal);
                }

                foreach (var item in lll)
                {
                    list.Add(new BalanceReportModel()
                        {
                            Date = date,
                            Balance = item.EndingBalanceEqu.HasValue ? item.EndingBalanceEqu.Value : item.EndingBalance,
                            CreditAmount = item.Records.Sum(x => x.CreditAmountEqu.HasValue ? x.CreditAmountEqu.Value : x.CreditAmount.Value),
                            DebitAmount = item.Records.Sum(x => x.DebitAmountEqu.HasValue ? x.DebitAmountEqu.Value : x.DebitAmount.Value)
                        });
                }
            }

            var list2 = list.GroupBy(x => x.Date);

            var list3 = new List<BalanceReportModel>();

            foreach (var item in list2)
            {
                list3.Add(new BalanceReportModel()
                    {
                        Date = item.FirstOrDefault().Date,
                        Balance = item.Sum(x => x.Balance)
                    });
            }

            #region AccountsService
            AltasoftAPI.AccountsAPI.AccountsService g = new AltasoftAPI.AccountsAPI.AccountsService();
            g.RequestHeadersValue = new AltasoftAPI.AccountsAPI.RequestHeaders() { ApplicationKey = "BusinessCreditClient", RequestId = Guid.NewGuid().ToString() };
            #endregion

            List<AccountStatementRecord> sts = new List<AccountStatementRecord>();

            foreach (var item in result)
                sts.AddRange(g.GetStatement(new InternalAccountIdentification() { IBAN = item.IBAN, Ccy = item.Ccy }, new Period() { Start = startDate, End = endDate }, true, true, TransactionStatus.Green, true, 0, false).Records);//.Sum(x => x.DebitAmountEqu.HasValue ? x.DebitAmountEqu.Value : x.DebitAmount.Value);

            var grouppedsts = sts.GroupBy(x => x.Date);

            foreach (var item in grouppedsts)
            {
                list3.FirstOrDefault(x => x.Date == item.Key).DebitAmount = item.Sum(x => x.DebitAmountEqu.HasValue ? x.DebitAmountEqu.Value : x.DebitAmount.HasValue ? x.DebitAmount.Value : 0);
                list3.FirstOrDefault(x => x.Date == item.Key).CreditAmount = item.Sum(x => x.CreditAmountEqu.HasValue ? x.CreditAmountEqu.Value : x.CreditAmount.HasValue ? x.CreditAmount.Value : 0);
            }

            return new SortableBindingList<BalanceReportModel>(list3);
        }
        public static SortableBindingList<BalanceReportModel> GetAccounts3(DateTime startDate, DateTime endDate, decimal? balCode, int? deptId)
        {
            var list3 = new List<BalanceReportModel>();

            #region AccountsService
            AltasoftAPI.AccountsAPI.AccountsService g = new AltasoftAPI.AccountsAPI.AccountsService();
            g.RequestHeadersValue = new AltasoftAPI.AccountsAPI.RequestHeaders() { ApplicationKey = "BusinessCreditClient", RequestId = Guid.NewGuid().ToString() };
            #endregion

            var result = g.ListAccounts(new ListAccountsQuery()
            {
                ControlFlags = AccountControlFlags.Basic | AccountControlFlags.Balances,
                BalAcc = balCode,
                BalAccSpecified = balCode.HasValue,
                DeptId = deptId,
                DeptIdSpecified = deptId.HasValue
            });

            List<AccountStatementRecord> sts = new List<AccountStatementRecord>();

            foreach (var item in result)
                sts.AddRange(g.GetStatement(new InternalAccountIdentification() { IBAN = item.IBAN, Ccy = item.Ccy }, new Period() { Start = startDate, End = endDate }, true, true, TransactionStatus.Green, true, 0, false).Records);//.Sum(x => x.DebitAmountEqu.HasValue ? x.DebitAmountEqu.Value : x.DebitAmount.Value);

            var grouppedsts = sts.GroupBy(x => x.Date);

            foreach (var item in grouppedsts)
            {
                list3.Add(new BalanceReportModel() { DebitAmount = item.Sum(x => x.DebitAmountEqu.HasValue ? x.DebitAmountEqu.Value : x.DebitAmount.HasValue ? x.DebitAmount.Value : 0), CreditAmount = item.Sum(x => x.CreditAmountEqu.HasValue ? x.CreditAmountEqu.Value : x.CreditAmount.HasValue ? x.CreditAmount.Value : 0), Date = item.Key });
            }

            return new SortableBindingList<BalanceReportModel>(list3);
        }