示例#1
0
 //TODO: duplicate check
 private void SetAmount(TRANSACTIONSTABLE t, decimal tranAmount, string amountCurrency, string defaultCurrency)
 {
     t.conversionRateNew = _currencyExchange.GetRate(defaultCurrency, amountCurrency);
     //Amount is stored in base currency, regardless of transaction currency
     t.amount = (long)decimal.Round(tranAmount / t.conversionRateNew * TransactionAmountFactor);
     t.transactionCurrency = amountCurrency;
 }
示例#2
0
        private void ImportTransactions(IDbConnection connection, Database database, BluecoinDatabase bluecoinDatabase)
        {
            foreach (var transaction in database.Transactions)
            {
                if (transaction.Type == TransactionType.Adjustment)
                {
                    var item = new ITEMTABLE {
                        itemTableID = connection.NextID <ITEMTABLE>(), itemName = transaction.FromAccount.Name, MmmTransaction = transaction
                    };
                    connection.Insert(item);

                    var tran = new TRANSACTIONSTABLE
                    {
                        itemID             = item.itemTableID,
                        transactionTypeID  = bluecoinDatabase.TransactionTypes.NewAccount,
                        MmmTransaction     = transaction,
                        categoryID         = bluecoinDatabase.SpecialCategories.NewAccountCatID,
                        accountID          = bluecoinDatabase.Accounts.Single(a => a.MmmAccount == transaction.FromAccount).accountsTableID,
                        accountPairID      = bluecoinDatabase.Accounts.Single(a => a.MmmAccount == transaction.FromAccount).accountsTableID,
                        notes              = transaction.Notes,
                        status             = 2, //TODO: meaning is not clear
                        deletedTransaction = 6, //TODO: meaning is not clear
                        date             = transaction.Date,
                        accountReference = 3,
                    };
                    SetAmount(tran, transaction.FromAmount, transaction.FromAccount.CurrencyCode, bluecoinDatabase.DefaultCurrency);

                    tran.transactionsTableID = tran.uidPairID = connection.NextID <TRANSACTIONSTABLE>();
                    connection.Insert(tran);
                }
                if (transaction.Type == TransactionType.Transfer)
                {
                    var item = new ITEMTABLE {
                        itemName = transaction.FromAccount.Name, MmmTransaction = transaction
                    };
                    var tran = new TRANSACTIONSTABLE
                    {
                        transactionTypeID  = bluecoinDatabase.TransactionTypes.Transfer,
                        MmmTransaction     = transaction,
                        categoryID         = bluecoinDatabase.SpecialCategories.TransferCatID,
                        accountID          = bluecoinDatabase.Accounts.Single(a => a.MmmAccount == transaction.FromAccount).accountsTableID,
                        accountPairID      = bluecoinDatabase.Accounts.Single(a => a.MmmAccount == transaction.ToAccount).accountsTableID,
                        notes              = transaction.Notes,
                        status             = 0, //TODO: meaning is not clear
                        deletedTransaction = 6, //TODO: meaning is not clear
                        date             = transaction.Date,
                        accountReference = 2    //TODO
                    };
                    SetAmount(tran, -transaction.FromAmount, transaction.FromAccount.CurrencyCode, bluecoinDatabase.DefaultCurrency);

                    tran.itemID = item.itemTableID = connection.NextID <ITEMTABLE>();
                    connection.Insert(item);
                    tran.transactionsTableID = tran.transferGroupID = connection.NextID <TRANSACTIONSTABLE>();
                    connection.Insert(tran);

                    var tran2 = new TRANSACTIONSTABLE
                    {
                        itemID             = item.itemTableID,
                        transactionTypeID  = bluecoinDatabase.TransactionTypes.Transfer,
                        MmmTransaction     = transaction,
                        categoryID         = bluecoinDatabase.SpecialCategories.TransferCatID,
                        accountID          = bluecoinDatabase.Accounts.Single(a => a.MmmAccount == transaction.ToAccount).accountsTableID,
                        accountPairID      = bluecoinDatabase.Accounts.Single(a => a.MmmAccount == transaction.FromAccount).accountsTableID,
                        notes              = transaction.Notes,
                        status             = 0, //TODO: meaning is not clear
                        deletedTransaction = 6, //TODO: meaning is not clear
                        uidPairID          = tran.transactionsTableID,
                        transferGroupID    = tran.transactionsTableID,
                        date             = transaction.Date,
                        accountReference = 2 //TODO
                    };
                    SetAmount(tran2, transaction.ToAmount, transaction.ToAccount.CurrencyCode, bluecoinDatabase.DefaultCurrency);
                    tran2.transactionsTableID = tran.uidPairID = connection.NextID <TRANSACTIONSTABLE>();
                    connection.Insert(tran2);

                    connection.Update <TRANSACTIONSTABLE>(tran);
                }

                if (transaction.Type == TransactionType.Income)
                {
                    var item = new ITEMTABLE {
                        itemName = transaction.Notes, MmmTransaction = transaction
                    };
                    var tran = new TRANSACTIONSTABLE
                    {
                        transactionTypeID  = bluecoinDatabase.TransactionTypes.Income,
                        MmmTransaction     = transaction,
                        categoryID         = bluecoinDatabase.ChildCategories.Single(c => c.MmmCategory == transaction.Category).categoryTableID,
                        accountID          = bluecoinDatabase.Accounts.Single(a => a.MmmAccount == transaction.ToAccount).accountsTableID,
                        accountPairID      = bluecoinDatabase.Accounts.Single(a => a.MmmAccount == transaction.ToAccount).accountsTableID,
                        notes              = transaction.Notes,
                        status             = 0, //TODO: meaning is not clear
                        deletedTransaction = 6, //TODO: meaning is not clear
                        date             = transaction.Date,
                        accountReference = 1    //TODO
                    };
                    SetAmount(tran, transaction.ToAmount, transaction.ToAccount.CurrencyCode, bluecoinDatabase.DefaultCurrency);

                    tran.itemID = item.itemTableID = connection.NextID <ITEMTABLE>();
                    connection.Insert(item);
                    tran.transactionsTableID = tran.uidPairID = connection.NextID <TRANSACTIONSTABLE>();
                    connection.Insert(tran);
                }

                if (transaction.Type == TransactionType.Expense)
                {
                    var item = new ITEMTABLE {
                        itemName = transaction.Notes, MmmTransaction = transaction
                    };
                    var tran = new TRANSACTIONSTABLE
                    {
                        transactionTypeID  = bluecoinDatabase.TransactionTypes.Expense,
                        MmmTransaction     = transaction,
                        categoryID         = bluecoinDatabase.ChildCategories.Single(c => c.MmmCategory == transaction.Category).categoryTableID,
                        accountID          = bluecoinDatabase.Accounts.Single(a => a.MmmAccount == transaction.FromAccount).accountsTableID,
                        accountPairID      = bluecoinDatabase.Accounts.Single(a => a.MmmAccount == transaction.FromAccount).accountsTableID,
                        notes              = transaction.Notes,
                        status             = 0, //TODO: meaning is not clear
                        deletedTransaction = 6, //TODO: meaning is not clear
                        date             = transaction.Date,
                        accountReference = 1    //TODO
                    };
                    SetAmount(tran, -transaction.FromAmount, transaction.FromAccount.CurrencyCode, bluecoinDatabase.DefaultCurrency);

                    tran.itemID = item.itemTableID = connection.NextID <ITEMTABLE>();
                    connection.Insert(item);
                    tran.transactionsTableID = tran.uidPairID = connection.NextID <TRANSACTIONSTABLE>();
                    connection.Insert(tran);
                }
            }
        }