Exemplo n.º 1
0
        private void importSpecialCaseTransactions()
        {
            List <QifTransaction> majorTransList = new List <QifTransaction>();

            // Gather in all the Major Halfs of the transactions. Those that have multiple oppLines
            foreach (QifTransaction majorTrans in this.qifTransfers)
            {
                if (majorTrans.OppAccountID == SpclAccount.MULTIPLE)
                {
                    majorTransList.Add(majorTrans);

                    foreach (QifSplit split in majorTrans.OppLines)
                    {
                        int aID;
                        if (split.Catagory.StartsWith("["))
                        {
                            if (this.ffDataSet.myGetAccount(split.Catagory, out aID))
                            {
                                split.OppAccountID = aID;
                            }
                            else
                            {
                                throw new InvalidDataException("Invalid Account");
                            }
                        }
                        else
                        {
                            byte cat = (split.Amount > 0.0m) ? SpclAccountCat.INCOME : SpclAccountCat.EXPENSE;
                            split.OppAccountID = this.ffDataSet.myImportAccount(split.Catagory, "", cat);
                        }
                    }
                }
            }

            foreach (QifTransaction majorTrans in majorTransList)
            {
                // Condense duplicate [Accounts]
                for (int x = 0; x < majorTrans.OppLines.Count - 1; x++)
                {
                    for (int y = x + 1; y < majorTrans.OppLines.Count; y++)
                    {
                        if (majorTrans.OppLines[x].OppAccountID == majorTrans.OppLines[y].OppAccountID)
                        {
                            string newMemo;
                            newMemo  = majorTrans.OppLines[x].Memo + " ";
                            newMemo += majorTrans.OppLines[x].Amount.ToString("C2") + ", ";
                            newMemo += majorTrans.OppLines[y].Memo + " ";
                            newMemo += majorTrans.OppLines[y].Amount.ToString("C2") + " ";

                            majorTrans.OppLines[x].Memo    = newMemo;
                            majorTrans.OppLines[x].Amount += majorTrans.OppLines[y].Amount;

                            majorTrans.OppLines.RemoveAt(y);
                            y--;
                        }
                    }
                }

                // Pull out the payee if it exists
                QifSplit payee = null;
                foreach (QifSplit split in majorTrans.OppLines)
                {
                    if (!split.Catagory.StartsWith("["))
                    {
                        payee = split;
                        break;
                    }
                }

                this.importQIFTransfers(majorTrans, payee);
            }
        }
Exemplo n.º 2
0
        private void importQIFTransfers(QifTransaction majorTrans, QifSplit payee)
        {
            List <FFDataSet.LineItemRow> transLines   = new List <FFDataSet.LineItemRow>();
            List <QifTransaction>        oppTransList = new List <QifTransaction>();

            // Match up
            foreach (QifSplit split in majorTrans.OppLines)
            {
                // Skip the payee oppline
                if (split.Catagory.StartsWith("["))
                {
                    foreach (QifTransaction minorTrans in this.qifTransfers)
                    {
                        if (majorTrans.Date.Equals(minorTrans.Date) &&
                            majorTrans.AccountID.Equals(minorTrans.OppAccountID) &&
                            split.OppAccountID.Equals(minorTrans.AccountID) &&
                            split.Amount.Equals(Decimal.Negate(minorTrans.Amount)))
                        {
                            oppTransList.Add(minorTrans);
                        }
                    }
                }
            }

            // Complex transfer between more than two accounts.
            if (payee == null && majorTrans.OppLines.Count == oppTransList.Count)
            {
                // Finish the MajorLine
                FFDataSet.LineItemRow majorLine = this.getEasyLineData(majorTrans);

                majorLine.envelopeID = this.importEnvelopeLines(majorTrans, majorLine.id);

                if (oppTransList.Count == 1)
                {
                    majorLine.oppAccountID = oppTransList[0].AccountID;
                }
                else
                {
                    majorLine.oppAccountID = SpclAccount.MULTIPLE;
                }

                this.ffDataSet.LineItem.AddLineItemRow(majorLine);
                transLines.Add(majorLine);

                this.qifTransfers.Remove(majorTrans);

                // Finish the MinorLines
                foreach (QifTransaction minorTrans in oppTransList)
                {
                    FFDataSet.LineItemRow minorLine = this.getEasyLineData(minorTrans);

                    minorLine.transactionID = majorLine.transactionID;
                    minorLine.oppAccountID  = majorLine.accountID;
                    minorLine.envelopeID    = this.importEnvelopeLines(minorTrans, minorLine.id);

                    this.ffDataSet.LineItem.AddLineItemRow(minorLine);
                    transLines.Add(minorLine);

                    this.qifTransfers.Remove(minorTrans);
                }
            }

            // Complex transfer between atleast two accounts and a payee
            if (payee != null && majorTrans.OppLines.Count == oppTransList.Count + 1)
            {
                // Finish the MajorLine
                FFDataSet.LineItemRow majorLine = this.getEasyLineData(majorTrans);

                majorLine.oppAccountID = SpclAccount.MULTIPLE;
                majorLine.envelopeID   = this.importEnvelopeLines(majorTrans, majorLine.id);

                this.ffDataSet.LineItem.AddLineItemRow(majorLine);
                transLines.Add(majorLine);

                this.qifTransfers.Remove(majorTrans);

                // Make the Payee Line
                FFDataSet.LineItemRow payeeLine = this.getEasyLineData(majorTrans);
                payeeLine.transactionID      = majorLine.transactionID;
                payeeLine.date               = majorLine.date;
                payeeLine.typeID             = majorLine.typeID;
                payeeLine.oppAccountID       = majorLine.accountID;
                payeeLine.confirmationNumber = majorLine.confirmationNumber;
                payeeLine.complete           = majorLine.complete;
                payeeLine.envelopeID         = SpclEnvelope.NULL;
                payeeLine.creditDebit        = !majorLine.creditDebit;

                payeeLine.accountID   = payee.OppAccountID;
                payeeLine.description = payee.Memo;

                if (payee.Amount > 0.0m)
                {
                    payeeLine.amount = payee.Amount;
                }
                else
                {
                    payeeLine.amount = Decimal.Negate(payee.Amount);
                }

                this.ffDataSet.LineItem.AddLineItemRow(payeeLine);
                transLines.Add(payeeLine);

                // Finish the MinorLines
                foreach (QifTransaction minorTrans in oppTransList)
                {
                    FFDataSet.LineItemRow minorLine = this.getEasyLineData(minorTrans);

                    minorLine.transactionID = majorLine.transactionID;
                    minorLine.oppAccountID  = majorLine.accountID;
                    minorLine.envelopeID    = this.importEnvelopeLines(minorTrans, minorLine.id);

                    this.ffDataSet.LineItem.AddLineItemRow(minorLine);
                    transLines.Add(minorLine);

                    this.qifTransfers.Remove(minorTrans);
                }

                // Make sure the oppAccount was set correctly
                int debitCount      = 0;
                int creditCount     = 0;
                int debitAccountID  = SpclAccount.NULL;
                int creditAccountID = SpclAccount.NULL;

                // Count things up
                foreach (FFDataSet.LineItemRow line in transLines)
                {
                    if (line.creditDebit == LineCD.CREDIT)
                    {
                        creditCount++;
                        creditAccountID = line.accountID;
                    }
                    else
                    {
                        debitCount++;
                        debitAccountID = line.accountID;
                    }
                }

                // Set correct values
                foreach (FFDataSet.LineItemRow line in transLines)
                {
                    if (line.creditDebit == LineCD.CREDIT && debitCount == 1)
                    {
                        line.oppAccountID = debitAccountID;
                    }

                    else if (line.creditDebit == LineCD.CREDIT && debitCount > 1)
                    {
                        line.oppAccountID = SpclAccount.MULTIPLE;
                    }

                    else if (line.creditDebit == LineCD.DEBIT && creditCount == 1)
                    {
                        line.oppAccountID = creditAccountID;
                    }

                    else if (line.creditDebit == LineCD.DEBIT && creditCount > 1)
                    {
                        line.oppAccountID = SpclAccount.MULTIPLE;
                    }
                }
            }
        }
Exemplo n.º 3
0
        private void getTransactionData(QifAccount account, string data)
        {
            string[] transArray = data.Split(new string[] { "\n^" }, StringSplitOptions.RemoveEmptyEntries);

            foreach (string transInfo in transArray)
            {
                string[]       properties     = transInfo.Split(new string[] { "\n" }, StringSplitOptions.RemoveEmptyEntries);
                QifTransaction newTransaction = new QifTransaction();
                QifSplit       newSplit       = null;

                foreach (string property in properties)
                {
                    switch (property[0])
                    {
                    case 'D':        //D    Date
                        newTransaction.Date = myStringToDate(property.Substring(1));
                        continue;

                    case 'T':        //T    Amount
                        newTransaction.Amount = Convert.ToDecimal(property.Substring(1));
                        continue;

                    case 'C':        //C    Cleared status
                        newTransaction.ClearedStatus = property.Substring(1);
                        continue;

                    case 'N':        //N    Num (check or reference number)
                        newTransaction.Num = property.Substring(1);
                        continue;

                    case 'M':        //M    Memo
                        newTransaction.Memo = property.Substring(1);
                        continue;

                    case 'P':        //P    Payee
                        newTransaction.Payee = property.Substring(1);
                        continue;

                    case 'A':        //A    Address (up to five lines; the sixth line is an optional message)
                        newTransaction.Address += property.Substring(1);
                        continue;

                    case 'L':        //L    Category (Category/Subcategory/Transfer/Class)
                        newTransaction.Catagory = property.Substring(1);
                        continue;

                    case 'S':        //S    Category in split (Category/Transfer/Class)
                        newSplit          = new QifSplit();
                        newSplit.Catagory = property.Substring(1);
                        continue;

                    case 'E':         //E   Memo in split
                        newSplit.Memo = property.Substring(1);
                        continue;

                    case '$':        //$    Dollar amount of split
                        newSplit.Amount = Convert.ToDecimal(property.Substring(1));
                        if (newSplit.Catagory.StartsWith("["))
                        {
                            newTransaction.OppLines.Add(newSplit);
                        }
                        else
                        {
                            newTransaction.EnvLines.Add(newSplit);
                        }
                        continue;

                    case 'U':        //Don't know. Always seams to be the same as T (The amount).
                        continue;

                    default:
                        throw new Exception("Not handled " + property);
                    } // End switch
                }     // End foreach property

                account.Transactions.Add(newTransaction);
            }// End foreach accInfo
        }