Ejemplo n.º 1
0
        private void SetAccount(Account pAccount)
        {
            if (!pAccount.ParentAccountId.HasValue)
            {
                string name = "";
                List<AccountCategory> accountCategories =
                    ServicesProvider.GetInstance().GetChartOfAccountsServices().SelectAccountCategories();

                foreach (var accountCategory in
                    accountCategories.Where(accountCategory => accountCategory.Id == (int) pAccount.AccountCategory))
                {
                    name = accountCategory.Name;
                }
                treeViewAccounts.SelectedNode = treeViewAccounts.Nodes.Find(name, false)[0];
            }
            else
            {
                treeViewAccounts.SelectedNode = treeViewAccounts.Nodes.Find(pAccount.ParentAccountId.ToString(), true)[0];
            }

            textNumericNumber.Text = pAccount.Number;
            textBoxLabel.Text = pAccount.Label;

            if (pAccount.Type)
            {
                textNumericNumber.Enabled = false;
            }

            rbCredit.Checked = !pAccount.DebitPlus;
            rbDebit.Checked = pAccount.DebitPlus;
        }
Ejemplo n.º 2
0
        public void AddChildAccountInDatabase()
        {
            Assert.Ignore();
            AccountManager accountManager = (AccountManager)container["AccountManager"];
            SqlTransaction sqlTransac = null;//ConnectionManager.GetInstance().GetSqlTransaction("");

            AccountCategory accountCategory = new AccountCategory {Name = "test"};
            int idCategory = accountManager.InsertAccountCategory(accountCategory, sqlTransac);

            Account account = new Account
            {
                Balance = 20,
                DebitPlus = true,
                AccountCategory = (OAccountCategories) idCategory,
                Label = "Child of CASH",
                Number = "10111",
                StockBalance = 10,
                TypeCode = "1111",
                CurrencyId = 1,
                ParentAccountId = 100
            };

            try
            {
                accountManager.Insert(account, sqlTransac);
                Assert.Fail("The account can be added in DB, the parent account id doesn't exist");
            }
            catch { }

            account.ParentAccountId = 2;
            accountManager.Update(account);

            List<Account> accounts = accountManager.SelectAllAccounts();
            Assert.AreEqual(1, accounts.Count);
        }
Ejemplo n.º 3
0
 public void SetUp()
 {
     chartOfAccounts.Accounts = new List<Account>();
     Account cash = new Account();
     cash.DebitPlus = true;
     cash.Number = "1011";
     cash.Balance = 10000;
     cash.TypeCode = "CASH";
     chartOfAccounts.AddAccount(cash);
 }
Ejemplo n.º 4
0
        public Booking(int pNumber, Account pCreditaccount, OCurrency pAmount, Account pDebitaccount, OAccountingLabels pLabel, DateTime pDate, Branch branch)
		{
            Number = pNumber;
            CreditAccount = pCreditaccount;
            DebitAccount = pDebitaccount;
            _amount = pAmount;
		    Label = pLabel;
            Date = pDate;
            Branch = branch;
		}
Ejemplo n.º 5
0
        public int AddAccount(Account account)
        {
            string sqlText = "INSERT INTO [Accounts]([account_number], [local_account_number], [label], "+
                "[balance], [debit_plus], [type_code], [description]) "+
                " VALUES (@number,@localNumber,@label,@balance,@debitPlus,@typeCode,@description) SELECT SCOPE_IDENTITY()";

            SqlCommand insertInAccountTable = new SqlCommand(sqlText,CurrentConnection);
            _SetAccount(insertInAccountTable,account);

            return int.Parse(insertInAccountTable.ExecuteScalar().ToString());
        }
Ejemplo n.º 6
0
 public PaymentMethod(int id, int linkId, string name, string description, bool isPending, Branch branch, DateTime date, Account account)
 {
     Id = id;
     LinkId = linkId;
     Name = name;
     Description = description;
     IsPending = isPending;
     Branch = branch;
     Account = account;
     Date = date;
     DeterminePaymentMethodByName();
 }
        public void SetUp()
        {
            _rules = new AccountingRuleCollection();
            _accounts = DefaultAccounts.DefaultAccount(1);

            Account cashSavings = new Account("1020", "CASH_SAVINGS", 0, "CASH_SAVIGNS", true, OAccountCategories.BalanceSheetAsset, 1);
            _accounts.Add(cashSavings);

            _rules.Add(new ContractAccountingRule
            {
                DebitAccount = _accounts[0],
                CreditAccount = cashSavings,
                ProductType = OProductTypes.Saving,
                SavingProduct = null,
                ClientType = OClientTypes.All,
                EconomicActivity = null,
                BookingDirection = OBookingDirections.Both
            });

            _loanProductEde34 = new LoanProduct { Id = 1, Code = "EDE34", Name = "EDEN 34", Currency = new Currency { Id = 1} };

            Account cashEDE34 = new Account("1051", "CASH_EDE34", 0, "CASH_EDE34", true, OAccountCategories.BalanceSheetAsset, 1);
            _accounts.Add(cashEDE34);

            _rules.Add(new ContractAccountingRule
            {
                DebitAccount = _accounts[0],
                CreditAccount = cashEDE34,
                ProductType = OProductTypes.Loan,
                LoanProduct = _loanProductEde34,
                ClientType = OClientTypes.Person,
                EconomicActivity = new EconomicActivity(1, "Agriculture", null, false),
                BookingDirection = OBookingDirections.Both
            });

            _loanProductEde60 = new LoanProduct { Id = 2, Code = "EDE60", Name = "EDEN 60", Currency = new Currency { Id = 1 } };

            Account cashEDE60 = new Account("1052", "CASH_EDE60", 0, "CASH_EDE60", true, OAccountCategories.BalanceSheetAsset, 1);
            _accounts.Add(cashEDE60);

            _rules.Add(new ContractAccountingRule
            {
                DebitAccount = _accounts[0],
                CreditAccount = cashEDE60,
                ProductType = OProductTypes.Loan,
                LoanProduct = _loanProductEde60,
                ClientType = OClientTypes.Person,
                EconomicActivity = new EconomicActivity(1, "Agriculture", null, false),
                BookingDirection = OBookingDirections.Credit
            });
        }
Ejemplo n.º 8
0
        public void AddAccountInDatabase()
        {
            AccountManager accountManager = (AccountManager)container["AccountManager"];
            Account account = new Account
                                  {
                                      Balance = 20,
                                      DebitPlus = true,
                                      AccountCategory = OAccountCategories.BalanceSheetAsset,
                                      Label = "Test",
                                      Number = "234567",
                                      StockBalance = 10,
                                      TypeCode = "1111",
                                      CurrencyId = 1
                                  };

            //int id = accountManager.Add(account);
            Assert.AreNotEqual(0,1);
        }
Ejemplo n.º 9
0
 public void TestBook()
 {
     Account cashCredit = new Account();
     cashCredit.DebitPlus = true;
     cashCredit.Number = "1031";
     cashCredit.TypeCode = "CASH_CREDIT";
     cashCredit.Balance = 0;
     cashCredit.CurrencyId = 1;
     chartOfAccounts.AddAccount(cash);
     chartOfAccounts.AddAccount(cashCredit);
     // OMFS-200
     AccountingTransaction movementSet = new AccountingTransaction();
     Booking mvt = new Booking(2, cashCredit, 100, cash, movementSet.Date, new Branch{Id = 1});
     movementSet.AddBooking(mvt);
     chartOfAccounts.Book(movementSet);
     Assert.AreEqual(1100m,chartOfAccounts.GetAccountByTypeCode("CASH",1).Balance.Value);
     Assert.AreEqual(-100m,chartOfAccounts.GetAccountByTypeCode("CASH_CREDIT",1).Balance.Value);
 }
Ejemplo n.º 10
0
        private void ImportAccounts()
        {
            fileDialog.InitialDirectory = Application.CommonAppDataPath;
            fileDialog.Filter = @"CSV (*.csv)|*.csv|All files (*.*)|*.*";
            fileDialog.FilterIndex = 1;
            fileDialog.RestoreDirectory = true;

            if (fileDialog.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    bool deleteRelated = Confirm(MultiLanguageStrings.GetString(Ressource.ChartOfAccountsForm, "ToDeleteTheChartOfAccounts.Text"));

                    CsvImportExport importer = new CsvImportExport();
                    string filePath = fileDialog.FileName;
                    List<Account> accounts = new List<Account>();
                    ChartOfAccountsServices coaServices = ServicesProvider.GetInstance().GetChartOfAccountsServices();
                    if(deleteRelated)
                    {
                        IEnumerable<string> relatedDatas = coaServices.HasRelatedDatas();
                        if(relatedDatas != null && relatedDatas.Any())
                        {
                            string[] domainObjects =
                                relatedDatas
                                    .Select(
                                        r => GetString(string.Format("RelatedData.{0}", r))
                                    ).Distinct().ToArray();

                            string message =
                                string.Format(
                                    GetString("RelatedDataExists.Text"),
                                    string.Join(",", domainObjects));
                            if(!Confirm(message)) return;
                        }
                    }
                    importer.Import(filePath, items =>
                                                  {
                                                      Account account = new Account
                                                      {
                                                          Id = Convert.ToInt32(items[0]),
                                                          Number = items[1],
                                                          Label = items[2],
                                                          DebitPlus = Convert.ToBoolean(items[3]),
                                                          TypeCode = items[4],
                                                          AccountCategory = (OAccountCategories)(Convert.ToInt32(items[5])),
                                                          Type = Convert.ToBoolean(items[6]),
                                                          ParentAccountId = items[5].ToUpper() == "0" ? null : (int?)Convert.ToInt32(items[7]),
                                                          Left = Convert.ToInt32(items[8]),
                                                          Right = Convert.ToInt32(items[9])
                                                      };
                                                      accounts.Add(account);
                                                  });
                    
                    coaServices.InsertCoa(accounts.ToArray(), deleteRelated);
                    IntializeTreeViewChartOfAccounts();
                }
                catch (Exception ex)
                {
                    new frmShowError(CustomExceptionHandler.ShowExceptionText(ex)).ShowDialog();
                }
            }
        }
Ejemplo n.º 11
0
        private void _InitializeListViewBookings(Account pAccount, DateTime pBeginDate, DateTime pEndDate, OBookingTypes pBookingType)
        {
            lvBooking.Items.Clear();
            lblAccountBalance.Text = String.Empty;
            if (pAccount != null)
            {
                _bookingsStock = ServicesProvider.GetInstance().GetAccountingServices().FindAllBookings(pAccount, pBeginDate, pEndDate, ((Currency) (cmbCurrencies.SelectedItem)).Id , pBookingType, ((Branch) cmbBranches.SelectedItem).Id);
                if (_bookingsStock.Count != 0)
                {
                    foreach (BookingToView bookingToView in _bookingsStock)
                    {
                        ListViewItem listViewItem = new ListViewItem(bookingToView.Date.ToShortDateString());
                        if (bookingToView.Direction == OBookingDirections.Debit)
                        {
                            listViewItem.SubItems.Add(bookingToView.AmountInternal.GetFormatedValue(true));
                            listViewItem.SubItems.Add("");
                        }
                        else
                        {
                            listViewItem.SubItems.Add("");
                            listViewItem.SubItems.Add(bookingToView.AmountInternal.GetFormatedValue(true));
                        }

                        if (cmbCurrencies.Items.Count > 0)
                        {
                            listViewItem.SubItems.Add(bookingToView.ExchangeRate.ToString());
                            if (!bookingToView.ExchangeRate.HasValue)
                                listViewItem.BackColor = Color.Red;
                            listViewItem.SubItems.Add(bookingToView.ExternalAmount.GetFormatedValue(true));
                        }

                        if (bookingToView.IsExported)
                            listViewItem.ForeColor = Color.Gray;
                            
                        string purpose = string.Format("{0} {1} {2}", 
                            MultiLanguageStrings.GetString(Ressource.AccountView, bookingToView.EventCode + @".Text"), 
                            bookingToView.ContractCode, 
                            MultiLanguageStrings.GetString(Ressource.AccountView, bookingToView.AccountingLabel + @".Text"));

                        listViewItem.SubItems.Add(purpose);
                        lvBooking.Items.Add(listViewItem);
                    }
                }

                if (((Currency) cmbCurrencies.SelectedItem).Id != 0)
                {
                    Currency selectedcur = cmbCurrencies.SelectedItem as Currency;
                    OCurrency balance = ServicesProvider.GetInstance().GetAccountingServices().
                        GetAccountBalance(pAccount.Id, selectedcur.Id, 0, null, 0, (cmbBranches.SelectedItem as Branch).Id);
                    lblAccountBalance.Text = string.Format("{0}  {1}", balance.GetFormatedValue(selectedcur.UseCents), selectedcur);
                    
                }
                else
                {
                    Currency selectedcur = new Currency();
                    foreach (var item in cmbCurrencies.Items)
                    {
                        if(((Currency) item).IsPivot)
                        {
                            selectedcur = (Currency) item;
                        }
                    }
                    OCurrency balance = ServicesProvider.GetInstance().GetAccountingServices().
                        GetAccountBalance(pAccount.Id, 0, 0, null, 0, (cmbBranches.SelectedItem as Branch).Id);
                    lblAccountBalance.Text = string.Format("{0} {1}", balance.GetFormatedValue(selectedcur.UseCents), selectedcur.Name);
                }
            }
            else _bookingsStock = null;
        }
 private bool _validateAccount(Account pAccount)
 {
     if (pAccount != null)
         return (pAccount.Id != 0 && pAccount.Number != null);
     return false;
 }
Ejemplo n.º 13
0
        public void SetUp()
        {
            Account _account = new Account();
            _account.Balance = 300;

            BookingToView _booking1 = new BookingToView(OBookingDirections.Debit,1000,new DateTime(2008,1,1),
                                                        3.45,"S/01/2008-1","LDRE34");

            BookingToView _booking2 = new BookingToView(OBookingDirections.Credit, 1333, new DateTime(2008, 1, 2),
                                                        4,"S/01/2008-1","LDRE35");

            BookingToView _booking3 = new BookingToView(OBookingDirections.Debit, 10, new DateTime(2008, 1, 5),
                                                        5.45,"S/01/2008-3","LDRE36");

            _bookingToViewStock = new BookingToViewStock(_account);
            _bookingToViewStock.Add(_booking1);
            _bookingToViewStock.Add(_booking2);
            _bookingToViewStock.Add(_booking3);
        }
Ejemplo n.º 14
0
 private static void SetAccount(OpenCbsCommand cmd, Account pAccount)
 {
     cmd.AddParam("@number", pAccount.Number);
     cmd.AddParam("@label",  pAccount.Label);
     cmd.AddParam("@debitPlus", pAccount.DebitPlus);
     cmd.AddParam("@type",  pAccount.Type);
     cmd.AddParam("@typeCode",  pAccount.TypeCode);
     cmd.AddParam("@account_category_id",  (int)pAccount.AccountCategory);
     if (pAccount.ParentAccountId == 0 || pAccount.ParentAccountId == null)
         cmd.AddParam("parentAccountId", null);
     else
         cmd.AddParam("@parentAccountId",  pAccount.ParentAccountId);
     cmd.AddParam("@lft", pAccount.Left);
     cmd.AddParam("@rgt", pAccount.Right);
 }
Ejemplo n.º 15
0
        public bool SelectAccountingRuleByChartOfAccountsId(Account account)
        {
            const string sqlText = @"SELECT TOP 1 id
                                    FROM AccountingRules
                                    WHERE debit_account_number_id = @id OR credit_account_number_id = @id";

            using (SqlConnection conn = GetConnection())
            {
                using (OpenCbsCommand select = new OpenCbsCommand(sqlText, conn))
                {
                    select.AddParam("@id", account.Id);

                    int? inUse;
                    using (OpenCbsReader reader = select.ExecuteReader())
                    {
                        if (reader == null || reader.Empty) return false;

                        reader.Read();
                        inUse = reader.GetInt("id");
                    }
                    return (inUse != null);
                }
            }
        }
Ejemplo n.º 16
0
 public void Insert(Account account, SqlTransaction sqlTransac)
 {
     Insert(account, sqlTransac, false);
 }
Ejemplo n.º 17
0
        public void Insert(Account account, SqlTransaction sqlTransac, bool setIdentity)
        {
            int rightMostSibling;
            string sqlText;
            if (null == account.ParentAccountId || 0 == account.ParentAccountId)
            {
                 sqlText = @"SELECT CASE
                                             WHEN MAX(rgt) IS NULL THEN 1
                                             ELSE MAX(rgt) + 1
                                    END
                                    FROM dbo.ChartOfAccounts";
                using (OpenCbsCommand cmd = new OpenCbsCommand(sqlText, sqlTransac.Connection, sqlTransac))
                {
                    rightMostSibling = Convert.ToInt32(cmd.ExecuteScalar());
                }

            }
            else
            {
                 sqlText = @"SELECT rgt
                                    FROM dbo.ChartOfAccounts
                                    WHERE id = @parent_account_id";
                using (OpenCbsCommand cmd = new OpenCbsCommand(sqlText, sqlTransac.Connection, sqlTransac))
                {
                    cmd.AddParam("@parent_account_id", account.ParentAccountId);
                    rightMostSibling = Convert.ToInt32(cmd.ExecuteScalar());
                }
            }

            sqlText = @"UPDATE dbo.ChartOfAccounts
                                SET lft = CASE
                                            WHEN lft > @right_most_sibling THEN lft + 2
                                            ELSE lft
                                          END
                                , rgt = CASE
                                          WHEN rgt >= @right_most_sibling THEN rgt + 2
                                          ELSE rgt
                                        END
                                WHERE rgt >= @right_most_sibling";
            using (OpenCbsCommand cmd = new OpenCbsCommand(sqlText, sqlTransac.Connection, sqlTransac))
            {
                cmd.AddParam("@right_most_sibling", rightMostSibling);
                cmd.ExecuteNonQuery();

                account.Left = rightMostSibling;
                account.Right = account.Left + 1;
            }
            if (setIdentity)
            {
                sqlText = @"
                                SET IDENTITY_INSERT [ChartOFAccounts] ON
                                INSERT INTO ChartOFAccounts (
                                  id,
                                  account_number,
                                  label,
                                  debit_plus,
                                  type_code,
                                  account_category_id,
                                  type,
                                  parent_account_id,
                                  lft,
                                  rgt)
                                VALUES (
                                  @id,
                                  @number,
                                  @label,
                                  @debitPlus,
                                  @typeCode,
                                  @account_category_id,
                                  @type,
                                  @parentAccountId,
                                  @lft,
                                  @rgt)
                                SET IDENTITY_INSERT [ChartOFAccounts] OFF
                ";
                using (OpenCbsCommand cmd = new OpenCbsCommand(sqlText, sqlTransac.Connection, sqlTransac))
                {
                    cmd.AddParam("@id", account.Id);
                    SetAccount(cmd, account);
                    cmd.ExecuteNonQuery();
                }
            }
            else
            {
                sqlText =
                    @"INSERT INTO ChartOFAccounts (
                                  account_number,
                                  label,
                                  debit_plus,
                                  type_code,
                                  account_category_id,
                                  type,
                                  parent_account_id,
                                  lft,
                                  rgt)
                                VALUES (
                                  @number,
                                  @label,
                                  @debitPlus,
                                  @typeCode,
                                  @account_category_id,
                                  @type,
                                  @parentAccountId,
                                  @lft,
                                  @rgt)";
                using (OpenCbsCommand cmd = new OpenCbsCommand(sqlText, sqlTransac.Connection, sqlTransac))
                {
                    SetAccount(cmd, account);
                    cmd.ExecuteNonQuery();
                }
            }
        }
Ejemplo n.º 18
0
        public void InsertCoa(Account[] accounts, bool deleteRelated)
        {
            Array.ForEach(accounts, CheckAccountData);
            if(!deleteRelated && accounts.Any())
            {
                int[] ids = accounts.Select(a => a.Id).ToArray();
                if (_accountManagement.IdsExist(ids)) throw new OpenCbsAccountException(OpenCbsAccountExceptionsEnum.ImportIdExist);

                string[] accountNumbers = accounts.Select(a => a.Number).ToArray();
                if (_accountManagement.NumbersExist(accountNumbers)) throw new OpenCbsAccountException(OpenCbsAccountExceptionsEnum.ImportNumbersExist);
            }
            RunAction(transaction=>
                    {
                        _tellerManager.DeleteAll(transaction);
                        if(deleteRelated)
                        {
                            _accountManagement.DeleteRelatedRecords(transaction);
                            _accountManagement.Delete(transaction);
                        }

                        List<Account> accountsToInsert = new List<Account>(accounts);
                        List<Account> insertedAccounts = new List<Account>(accounts.Length);
                        while (accountsToInsert.Count > 0)
                        {
                            int oldCount = insertedAccounts.Count;
                            for (int index = 0; index < accountsToInsert.Count; index++)
                            {
                                Account account = accountsToInsert[index];
                                int? parentAccountId = account.ParentAccountId;

                                Account parentAccount = null;
                                if (parentAccountId.HasValue && parentAccountId != 0)
                                {
                                    if(deleteRelated)
                                        parentAccount = insertedAccounts.FirstOrDefault(a => a.Id == parentAccountId);
                                    else
                                        parentAccount =
                                            _accountManagement.SelectChartAccount(parentAccountId.Value) ??
                                            insertedAccounts.FirstOrDefault(a => a.Id == parentAccountId);
                                }

                                if (
                                    (parentAccountId == null || parentAccountId == 0) ||
                                    parentAccount != null
                                )
                                {
                                    if(parentAccount != null) CheckAccountParent(account, parentAccount);
                                    try
                                    {
                                        _accountManagement.Insert(account, transaction, true);
                                    }
                                    catch(SqlException exception)
                                    {
                                        if (exception.Number == 2627)
                                            //2627 is a standard number of error related to unique keys duplication
                                            throw new OpenCbsAccountException(OpenCbsAccountExceptionsEnum.DuplicatedAccount);
                                    }

                                    insertedAccounts.Add(account);
                                    accountsToInsert.Remove(account);
                                    index--;
                                }
                            }

                            if (oldCount == insertedAccounts.Count)
                                throw new OpenCbsException(string.Format(
                                    "Chart of accounts contain non valid tree. Please check these accounts {0}.",
                                    string.Join(",", accountsToInsert.Select(a => a.Number).ToArray())));
                        }
                    }, _user);
        }
Ejemplo n.º 19
0
        public void Update(Account pAccount)
        {
            const string sqlText = @"UPDATE [ChartOFAccounts]
                                    SET [account_number] = @number,
                                        [label] = @label,
                                        [debit_plus] = @debitPlus,
                                        [type_code] = @typeCode,
                                        [account_category_id] = @account_category_id,
                                        [parent_account_id] = @parentAccountId
                                     WHERE id = @id";

            using (SqlConnection conn = GetConnection())
            {
                using (OpenCbsCommand update = new OpenCbsCommand(sqlText, conn))
                {
                    update.AddParam("@id",  pAccount.Id);
                    SetAccount(update, pAccount);

                    update.ExecuteNonQuery();
                }
            }
        }
Ejemplo n.º 20
0
 public void UpdateAccount(Account account)
 {
     CheckDatasAreCorrecltyFilled(account);
     _accountManagement.Update(account);
 }
Ejemplo n.º 21
0
        public void DeleteAccount(Account account)
        {
            using (SqlConnection conn = GetConnection())
            {
                OpenCbsCommand cmd = new OpenCbsCommand
                                         {
                                             Connection = conn,
                                             CommandText =
                                                 @"DELETE FROM dbo.ChartOfAccounts
                                               WHERE lft >= @lft AND rgt <= @rgt"
                                         };
                cmd.AddParam("@lft", account.Left);
                cmd.AddParam("@rgt", account.Right);
                cmd.ExecuteNonQuery();

                cmd.ResetParams();
                cmd.CommandText =
                    @"UPDATE dbo.ChartOfAccounts
                                SET lft = lft - @diff, rgt = rgt - @diff
                                WHERE lft > @lft";
                cmd.AddParam("@diff", account.Right - account.Left + 1);
                cmd.AddParam("@lft", account.Left);
                cmd.ExecuteNonQuery();
            }
        }
Ejemplo n.º 22
0
 private static void CheckAccountParent(Account account, Account parentAccount)
 {
     if (parentAccount == null)
         throw new OpenCbsAccountException(OpenCbsAccountExceptionsEnum.ParentAccountDoesntExists);
     if (parentAccount.AccountCategory != account.AccountCategory)
         throw new OpenCbsAccountException(OpenCbsAccountExceptionsEnum.ParentAccountNotSameDescription);
     if (parentAccount.Id == account.Id)
         throw new OpenCbsAccountException(OpenCbsAccountExceptionsEnum.ParentAccountIsInvalid);
 }
Ejemplo n.º 23
0
		public void AddAccount(Account account)
		{
			_accounts.Add(account);
		}
Ejemplo n.º 24
0
 private void CheckAccountData(Account account)
 {
     if (account == null)
         throw new OpenCbsAccountException(OpenCbsAccountExceptionsEnum.AccountIsNull);
     if (string.IsNullOrEmpty(account.Number))
         throw new OpenCbsAccountException(OpenCbsAccountExceptionsEnum.NumberIsNull);
     if (string.IsNullOrEmpty(account.Label))
         throw new OpenCbsAccountException(OpenCbsAccountExceptionsEnum.LabelIsNull);
     if (_accountManagement.SelectAccountCategoriesById((int) account.AccountCategory) == null)
         throw new OpenCbsAccountException(OpenCbsAccountExceptionsEnum.ParentAccountDoesntExists);
 }
Ejemplo n.º 25
0
 private void comboBoxSelectAccount_SelectionChangeCommitted(object sender, EventArgs e)
 {
     lvBooking.Items.Clear();
     if (cbAccounts.SelectedItem != null)
     {
         _filterAccount = ((Account) cbAccounts.SelectedItem);
         if (cmbCurrencies.SelectedItem == null) 
             _filterAccount.CurrencyId = _pivotCurrency.Id;
         else 
             _filterAccount.CurrencyId = ((Currency) cmbCurrencies.SelectedItem).Id;
         _InitializeListViewBookings(_filterAccount, _filterBeginDate, _filterEndDate, _bookingType);
     }
     else
         _filterAccount = null;
 }
Ejemplo n.º 26
0
        private OCurrency _getChildsBalance(List<Account> pAccounts, Account pAccount)
        {
            OCurrency balance = 0;
            foreach (Account account in pAccounts.Where(item => item.ParentAccountId == pAccount.Id))
            {
                account.Balance += _getChildsBalance(pAccounts, account);
                balance += account.Balance;
            }

            return balance;
        }
Ejemplo n.º 27
0
        private void comboBoxCurrencies_SelectedIndexChanged(object sender, EventArgs e)
        {
            _InitializeComboBoxAccounts();
            columnHeaderCredit.Text = MultiLanguageStrings.GetString(Ressource.AccountView, @"CreditColumn.Text") + @" " + ((Currency) cmbCurrencies.SelectedItem).Name;
            columnHeaderDebit.Text = MultiLanguageStrings.GetString(Ressource.AccountView, @"DebitColumn.Text") + @" " + (cmbCurrencies.SelectedItem as Currency).Name;
            if(columnHeaderAmountEC!=null) columnHeaderAmountEC.Text = MultiLanguageStrings.GetString(Ressource.AccountView, "AmountColumn.Text") + @" " + _pivotCurrency.Name;

            if (cbAccounts.SelectedItem != null)
            {
                _filterAccount = ((Account) cbAccounts.SelectedItem);
                _InitializeListViewBookings(_filterAccount, _filterBeginDate, _filterEndDate, _bookingType);
            }
            else
                _filterAccount = null;
            
        }
Ejemplo n.º 28
0
 private static BookingToView GetBooking(Account pAccount, OpenCbsReader reader)
 {
     return new BookingToView
                {
                    Date = reader.GetDateTime("date"),
                    EventCode = reader.GetString("event_code"),
                    ExchangeRate = reader.GetNullDouble("exchange_rate"),
                    AmountInternal = reader.GetMoney("amount"),
                    ContractCode = reader.GetString("contract_code"),
                    Direction =
                        (reader.GetString("debit_local_account_number") == pAccount.Number
                             ? OBookingDirections.Debit
                             : OBookingDirections.Credit),
                    IsExported = reader.GetBool("is_exported")
                };
 }
Ejemplo n.º 29
0
        private void IntializeTreeViewChartOfAccounts()
        {
            List<Account> accounts = ServicesProvider.GetInstance().GetChartOfAccountsServices().FindAllAccounts();
            List<AccountCategory> accountCategories = ServicesProvider.GetInstance().GetChartOfAccountsServices().SelectAccountCategories();

            tlvAccounts.CanExpandGetter = delegate(object o)
            {
                Account account = (Account)o;
                if (account.Id == -1)
                    return true;

                return accounts.FirstOrDefault(item => item.ParentAccountId == account.Id) != null;
            };

            tlvAccounts.ChildrenGetter = delegate(object o)
            {
                Account account = (Account)o;
                if (account.Id == -1)
                    return accounts.Where(item => item.AccountCategory == account.AccountCategory && item.ParentAccountId == null);
                
                return accounts.Where(item => item.ParentAccountId == account.Id);
            };

            tlvAccounts.RowFormatter = delegate(OLVListItem o)
            {
                Account account = (Account)o.RowObject;
                if (account.Id == -1)
                {
                    o.ForeColor = Color.FromArgb(0, 88, 56);
                    o.Font = new Font("Arial", 9);
                }
            };

            TreeListView.TreeRenderer renderer = tlvAccounts.TreeColumnRenderer;
            renderer.LinePen = new Pen(Color.Gray, 0.5f) {DashStyle = DashStyle.Dot};

            List<Account> list = new List<Account>();

            foreach(AccountCategory accountCategory in accountCategories)
            {
                string name = MultiLanguageStrings.GetString(
                    Ressource.ChartOfAccountsForm, accountCategory.Name + ".Text");
                name = name ?? accountCategory.Name;

                Account account = new Account
                    {
                        Number = name,
                        AccountCategory = (OAccountCategories) accountCategory.Id,
                        Id = -1
                    };
                
                list.Add(account);
            }
            tlvAccounts.Roots = list;
            tlvAccounts.ExpandAll();
        }
Ejemplo n.º 30
0
        public BookingToViewStock SelectBookings(Account pAccount, DateTime pBeginDate, DateTime pEndDate,
                                                 int currencyId, OBookingTypes pBookingType, int pBranchId)
        {
            const string sqlQuery = "GetAccountBookings";

            bool? isExported = null;
            switch (pBookingType)
            {
                case OBookingTypes.Exported:
                    isExported = true;
                    break;
                case OBookingTypes.NotExported:
                    isExported = false;
                    break;
            }

            using (SqlConnection conn = GetConnection())
            using (OpenCbsCommand cmd = new OpenCbsCommand(sqlQuery, conn).AsStoredProcedure())
                {
                    cmd.AddParam("@beginDate",pBeginDate);
                    cmd.AddParam("@endDate", pEndDate);
                    cmd.AddParam("@account_id",  pAccount.Id);
                    cmd.AddParam("@currency_id", currencyId);
                    cmd.AddParam("@is_exported",  isExported);
                    cmd.AddParam("@branch_id",  pBranchId);

                    using (OpenCbsReader reader = cmd.ExecuteReader())
                    {
                        if (reader == null || reader.Empty) return new BookingToViewStock(pAccount);

                        BookingToViewStock stock = new BookingToViewStock(pAccount);
                        while (reader.Read())
                        {
                            stock.Add(GetBooking(pAccount, reader));
                        }
                        return stock;
                    }
                }
        }