コード例 #1
0
        protected bool setOppAccountID(bool cd, int newAccountID)
        {
            if (newAccountID == SpclAccount.MULTIPLE || newAccountID == SpclAccount.NULL)
            {
                return(false);
            }

            FFDataSet.LineItemRow[] rows    = this.transactionRow.GetLineItemRows();
            FFDataSet.LineItemRow   oppLine = null;
            int  count  = 0;
            bool result = false;

            foreach (FFDataSet.LineItemRow row in rows)
            {
                if (row.creditDebit != cd)
                {
                    count++;
                    oppLine = row;
                    result  = true;
                }
            }

            // if count is 0 or 1 oppAccountID already has the right value
            // if count > 2 then change to multiple.
            if (count == 1)
            {
                oppLine.accountID = newAccountID;
            }

            return(result);
        }
コード例 #2
0
        private void importQIFSimpleTransaction(QifTransaction qTrans)
        {
            // Easy stuff (date, type, account, description, confNum, complete, amount, creditdebit)
            FFDataSet.LineItemRow newLine = this.getEasyLineData(qTrans);

            // Set oppAccount and envelopeID, and import envelope Lines
            byte cat = (qTrans.Amount > 0.0m) ? SpclAccountCat.INCOME : SpclAccountCat.EXPENSE;

            newLine.oppAccountID = this.ffDataSet.myImportAccount(qTrans.Payee, "", cat);
            newLine.envelopeID   = this.importEnvelopeLines(qTrans, newLine.id);

            if (newLine.accountID == newLine.oppAccountID)
            {
                newLine.oppAccountID = this.ffDataSet.myImportAccount(qTrans.Payee + "-Payee", "", cat);
            }

            // Build the oppLine
            FFDataSet.LineItemRow payeeLine = this.ffDataSet.LineItem.NewLineItemRow();
            payeeLine.transactionID      = newLine.transactionID;
            payeeLine.date               = newLine.date;
            payeeLine.typeID             = newLine.typeID;
            payeeLine.accountID          = newLine.oppAccountID;
            payeeLine.oppAccountID       = newLine.accountID;
            payeeLine.description        = newLine.description;
            payeeLine.confirmationNumber = newLine.confirmationNumber;
            payeeLine.envelopeID         = SpclEnvelope.NULL;
            payeeLine.complete           = newLine.complete;
            payeeLine.amount             = newLine.amount;
            payeeLine.creditDebit        = !newLine.creditDebit;

            // Add the lines to the table
            this.ffDataSet.LineItem.AddLineItemRow(newLine);
            this.ffDataSet.LineItem.AddLineItemRow(payeeLine);
        }
コード例 #3
0
        public TransactionLine(FFDataSet.LineItemRow lineRow)
        {
            if (lineRow == null)
            {
                throw new Exception("Null Line Item Row.");
            }

            FFDataSet.TransactionRow tRow;
            tRow = DataSetModel.Instance.getTransactionRowWithID(lineRow.transactionID);

            if (tRow == null)
            {
                throw new Exception("Orphan Line Item Row.");
            }

            this.Transaction = new TransactionModel(tRow);

            foreach (LineItemModel line in Transaction.LineItems)
            {
                if (line.LineID == lineRow.id)
                {
                    this.LineItem = line;
                }
            }

            if (this.LineItem == null)
            {
                throw new Exception("No line with matching ID.");
            }
        }
コード例 #4
0
        public FFDataSet.LineItemRow NewLineItemRow(TransactionDRM transaction)
        {
            FFDataSet.LineItemRow newRow = this.NewLineItemRow();

            newRow.transactionID = transaction.TransactionID;

            return(newRow);
        }
コード例 #5
0
        private FFDataSet.LineItemRow getEasyLineData(QifTransaction qTrans)
        {
            FFDataSet.LineItemRow newLine = this.ffDataSet.LineItem.NewLineItemRow();

            newLine.date        = qTrans.Date;
            newLine.accountID   = qTrans.AccountID;
            newLine.description = qTrans.Memo + " " + qTrans.Address;

            // Set the amount and creditDebit
            if (qTrans.Amount >= 0)
            {
                newLine.amount      = qTrans.Amount;
                newLine.creditDebit = LineCD.DEBIT;
            }
            else
            {
                newLine.amount      = Decimal.Negate(qTrans.Amount);
                newLine.creditDebit = LineCD.CREDIT;
            }

            // Set the complete
            switch (qTrans.ClearedStatus)
            {
            case "S":
                newLine.complete = LineState.RECONSILED;
                break;

            case "X":
                newLine.complete = LineState.RECONSILED;
                break;

            case "*":
                newLine.complete = LineState.CLEARED;
                break;

            case "":
                newLine.complete = LineState.PENDING;
                break;

            default:
                newLine.complete = LineState.PENDING;
                break;
            }

            // Set the Num/Type and Confermation number if needed.
            try
            {
                Convert.ToInt32(qTrans.Num);
                newLine.typeID             = this.ffDataSet.myImportLineType("Check");
                newLine.confirmationNumber = "Check Number: " + qTrans.Num;
            }
            catch (FormatException)
            {
                newLine.typeID = this.ffDataSet.myImportLineType(qTrans.Num);
            }

            return(newLine);
        }
コード例 #6
0
        ///////////////////////////////////////////////////////////////////////
        // Protected functions
        ///////////////////////////////////////////////////////////////////////



        ///////////////////////////////////////////////////////////////////////
        // Public functions
        ///////////////////////////////////////////////////////////////////////
        /// <summary>
        /// Default constructor. Adds a new transaction row to the table.
        /// </summary>
        public LineItemModel()
        {
            this.lineItemRow = MyData.getInstance().LineItem.NewLineItemRow();

            this.lineItemRow.transactionID = TransactionID;

            MyData.getInstance().LineItem.AddLineItemRow(this.lineItemRow);
            this.saveRow();
        }
コード例 #7
0
        public LineItemModel(FFDataSet.LineItemRow lRow) : base(lRow)
        {
            this.EnvelopeLines = new ObservableCollection <EnvelopeLineDRM>();
            this.EnvelopeLines.CollectionChanged += new System.Collections.Specialized.NotifyCollectionChangedEventHandler(EnvelopeLines_CollectionChanged);

            // add the line this way so the collection(add/Remove) event can handle
            // subscribing and unsubscribing
            foreach (EnvelopeLineDRM envLine in this.getEnvelopeLineRows())
            {
                this.EnvelopeLines.Add(envLine);
            }
        }
コード例 #8
0
        private void LineItem_TableNewRow(object sender, System.Data.DataTableNewRowEventArgs e)
        {
            FFDataSet.LineItemRow row = e.Row as FFDataSet.LineItemRow;

            int max =
                (from LineItem in this.LineItem
                 select LineItem.id).Max();

            row.id = max + 1;
            // TransactionID needs to be set by calling function.
            row.accountID   = SpclAccount.NULL;
            row.amount      = 0.0m;
            row.creditDebit = LineCD.CREDIT;
        }
コード例 #9
0
        public FFDataSet.LineItemRow NewLineItemRow()
        {
            FFDataSet.LineItemRow newRow = ffDataSet.LineItem.NewLineItemRow();

            newRow.id                 = this.getNextIDFromTableNamed("LineItem");
            newRow.transactionID      = TransactionCON.NULL.ID;
            newRow.accountID          = AccountCON.NULL.ID;
            newRow.confirmationNumber = "";
            newRow.amount             = 0m;
            newRow.polarity           = PolarityCON.CREDIT.Value;
            newRow.state              = TransactionStateCON.PENDING.Value;

            ffDataSet.LineItem.AddLineItemRow(newRow);

            return(newRow);
        }
コード例 #10
0
        private static bool copyFromOppLines(FFDataSet dataSet, FFDataSet.LineItemRow line, decimal envSum)
        {
            bool copied = false;

            List <FFDataSet.EnvelopeLineRow> oppELines = new List <FFDataSet.EnvelopeLineRow>();
            decimal sum = 0.0m;

            // get opp Envelope lines
            foreach (FFDataSet.EnvelopeLineRow oppELine in dataSet.EnvelopeLine)
            {
                if (oppELine.LineItemRow.transactionID == line.transactionID &&
                    oppELine.LineItemRow.creditDebit != line.creditDebit)
                {
                    oppELines.Add(oppELine);
                    sum += oppELine.amount;
                }
            }

            if (sum == line.amount - envSum)
            {
                foreach (FFDataSet.EnvelopeLineRow eLine in oppELines)
                {
                    FFDataSet.EnvelopeLineRow newEline = dataSet.EnvelopeLine.NewEnvelopeLineRow();

                    newEline.lineItemID  = line.id;
                    newEline.envelopeID  = eLine.envelopeID;
                    newEline.description = eLine.description;
                    newEline.amount      = eLine.amount;

                    dataSet.EnvelopeLine.AddEnvelopeLineRow(newEline);

                    if (oppELines.Count == 1)
                    {
                        newEline.LineItemRow.envelopeID = eLine.envelopeID;
                    }

                    else if (oppELines.Count > 1)
                    {
                        newEline.LineItemRow.envelopeID = SpclEnvelope.SPLIT;
                    }
                }

                copied = true;
            }

            return(copied);
        }
コード例 #11
0
        ///////////////////////////////////////////////////////////////////////
        // Protected functions
        ///////////////////////////////////////////////////////////////////////



        ///////////////////////////////////////////////////////////////////////
        // Public functions
        ///////////////////////////////////////////////////////////////////////
        public LineItemRegModel() : base()
        {
            // Build up the first lineItem.
            this.lineItemRow = MyData.getInstance().LineItem.NewLineItemRow();
            this.lineItemRow.transactionID = base.ID;
            this.lineItemRow.accountID     = currentAccountID;
            this.lineItemRow.creditDebit   = LineCD.CREDIT;
            MyData.getInstance().LineItem.AddLineItemRow(this.lineItemRow);
            MyData.getInstance().saveRow(this.lineItemRow);

            // Build up the opposite lineItem.
            FFDataSet.LineItemRow oppLine = MyData.getInstance().LineItem.NewLineItemRow();
            oppLine.transactionID = base.ID;
            oppLine.accountID     = SpclAccount.NULL;
            oppLine.creditDebit   = LineCD.DEBIT;
            MyData.getInstance().LineItem.AddLineItemRow(oppLine);
            MyData.getInstance().saveRow(oppLine);
        }
コード例 #12
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;
                    }
                }
            }
        }
コード例 #13
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="row"></param>
 public LineItemModel(FFDataSet.LineItemRow row)
 {
     this.lineItemRow = row;
 }
コード例 #14
0
        static public void Distribute(int accountID)
        {
            List <EnvBal>   envelopes  = new List <EnvBal>();
            Queue <LineSum> holdLines  = new Queue <LineSum>();
            decimal         skipAmount = 0.0m;

            FFDataSet dataSet = new FFDataSet();

            dataSet.myInit();
            dataSet.myFillForAutoDistribute();

            for (int index = 0; index < dataSet.LineItem.Count; index++)
            {
                FFDataSet.LineItemRow line = dataSet.LineItem[index];

                if (line.accountID != accountID)
                {
                    continue;
                }

                FFDataSet.EnvelopeLineRow[] envLines = line.GetEnvelopeLineRows();
                decimal envSum = envLineSum(envLines);

                // Decide what to do with this line
                if (envSum == line.amount)
                {
                    updateEnvelopes(line.creditDebit, envLines, envelopes);
                }

                else if (copyFromOppLines(dataSet, line, envSum))
                {
                    envLines = line.GetEnvelopeLineRows();
                    updateEnvelopes(line.creditDebit, envLines, envelopes);

                    if (envLines.Length > 1)
                    {
                        line.envelopeID = SpclEnvelope.SPLIT;
                    }

                    else if (envLines.Length == 1)
                    {
                        line.envelopeID = envLines[0].envelopeID;
                    }
                }
                else if (line.creditDebit == LineCD.CREDIT && envLines.Length > 0)
                {
                    updateEnvelopes(line.creditDebit, envLines, envelopes);
                    skipAmount += line.amount - envSum;
                }
                else if (line.creditDebit == LineCD.CREDIT && envLines.Length == 0)
                {
                    skipAmount += line.amount;
                }
                else if (line.creditDebit == LineCD.DEBIT)
                {
                    if (envLines.Length > 0)
                    {
                        updateEnvelopes(line.creditDebit, envLines, envelopes);
                    }

                    holdLines.Enqueue(new LineSum(line, line.amount - envSum));
                }

                // See if there are enough negative envelopes and skip amounts to disribute the
                // next line being held.
                while (holdLines.Count > 0 && holdLines.Peek().RemainingAmount <= skipAmount)
                {
                    LineSum lineSum = holdLines.Dequeue();
                    skipAmount -= lineSum.RemainingAmount;
                }

                while (holdLines.Count > 0 && holdLines.Peek().RemainingAmount <= skipAmount + getNegativeSum(envelopes))
                {
                    LineSum lineSum = holdLines.Dequeue();
                    fillInFromEnvelopeLines(dataSet, lineSum, envelopes, skipAmount);
                    skipAmount = 0.0m;

                    envLines = lineSum.Line.GetEnvelopeLineRows();

                    if (envLines.Length > 1)
                    {
                        lineSum.Line.envelopeID = SpclEnvelope.SPLIT;
                    }

                    else if (envLines.Length == 1)
                    {
                        lineSum.Line.envelopeID = envLines[0].envelopeID;
                    }
                }
            }

            dataSet.mySaveData();
            dataSet.Clear();
            envelopes.Clear();
            holdLines.Clear();
        }
コード例 #15
0
 public LineSum(FFDataSet.LineItemRow line, decimal remainingAmount)
 {
     this.Line            = line;
     this.RemainingAmount = remainingAmount;
 }
コード例 #16
0
 public LineItemDRM(FFDataSet.LineItemRow lineRow)
 {
     this.lineItemRow = lineRow;
 }
コード例 #17
0
        private void addRequiredTableRows()
        {
            ////////////////////////////
            // Required Account type Rows
            FFDataSet.AccountTypeRow accountTypeNull = this.ffDataSet.AccountType.FindByid(AccountTypeCON.NULL.ID);

            if (accountTypeNull == null)
            {
                accountTypeNull = this.ffDataSet.AccountType.AddAccountTypeRow(AccountTypeCON.NULL.ID, AccountTypeCON.NULL.Name);
            }


            ////////////////////////////
            // Required Envelope Group Rows
            FFDataSet.EnvelopeGroupRow envelopeGroupNull = this.ffDataSet.EnvelopeGroup.FindByid(EnvelopeGroupCON.NULL.ID);

            if (envelopeGroupNull == null)
            {
                envelopeGroupNull = this.ffDataSet.EnvelopeGroup.AddEnvelopeGroupRow(EnvelopeGroupCON.NULL.ID, AccountTypeCON.NULL.Name, 0.0m, 0.0m);
            }


            ////////////////////////////
            // Required Transaction Type Rows
            FFDataSet.TransactionTypeRow transactionTypeNull = this.ffDataSet.TransactionType.FindByid(TransactionTypeCON.NULL.ID);

            if (transactionTypeNull == null)
            {
                transactionTypeNull = this.ffDataSet.TransactionType.AddTransactionTypeRow(TransactionTypeCON.NULL.ID, TransactionTypeCON.NULL.Name);
            }


            ////////////////////////////
            // Required Bank Rows
            FFDataSet.BankRow bankNull = this.ffDataSet.Bank.FindByid(BankCON.NULL.ID);

            if (bankNull == null)
            {
                bankNull = this.ffDataSet.Bank.AddBankRow(BankCON.NULL.ID, BankCON.NULL.Name, " ");
            }


            ////////////////////////////
            // Required Account Rows
            FFDataSet.AccountRow accountNull = this.ffDataSet.Account.FindByid(AccountCON.NULL.ID);

            if (accountNull == null)
            {
                accountNull = this.ffDataSet.Account.AddAccountRow(AccountCON.NULL.ID, AccountCON.NULL.Name, accountTypeNull, CatagoryCON.NULL.ID, false, false);
            }


            ////////////////////////////
            // Required Envelope Rows
            FFDataSet.EnvelopeRow envelopeNull       = this.ffDataSet.Envelope.FindByid(EnvelopeCON.NULL.ID);
            FFDataSet.EnvelopeRow envelopeNoEnvelope = this.ffDataSet.Envelope.FindByid(EnvelopeCON.NO_ENVELOPE.ID);

            if (envelopeNull == null)
            {
                envelopeNull = this.ffDataSet.Envelope.AddEnvelopeRow(EnvelopeCON.NULL.ID, EnvelopeCON.NULL.Name, envelopeGroupNull, false, accountNull, 0, " ", "N");
            }

            if (envelopeNoEnvelope == null)
            {
                envelopeNoEnvelope = this.ffDataSet.Envelope.AddEnvelopeRow(EnvelopeCON.NO_ENVELOPE.ID, EnvelopeCON.NO_ENVELOPE.Name, envelopeGroupNull, false, accountNull, 0, " ", "N");
            }


            ////////////////////////////
            // Required Transaction Row
            FFDataSet.TransactionRow transactionNull = this.ffDataSet.Transaction.FindByid(TransactionCON.NULL.ID);

            if (transactionNull == null)
            {
                transactionNull = this.ffDataSet.Transaction.AddTransactionRow(TransactionCON.NULL.ID, DateTime.MinValue, transactionTypeNull, "");
            }


            ////////////////////////////
            // Required LineItem Row
            FFDataSet.LineItemRow lineItemNull = this.ffDataSet.LineItem.FindByid(LineItemCON.NULL.ID);

            if (lineItemNull == null)
            {
                lineItemNull = this.ffDataSet.LineItem.AddLineItemRow(LineItemCON.NULL.ID, transactionNull, accountNull, "", 0, TransactionStateCON.PENDING.Value, false);
            }
        }
コード例 #18
0
 public LineItemRegModel(FFDataSet.LineItemRow row) : base(row.TransactionRow)
 {
     this.lineItemRow = row;
 }
コード例 #19
0
        ///////////////////////////////////////////////////////////////////////////////////////////
        // Private Functions
        ///////////////////////////////////////////////////////////////////////////////////////////


        ///////////////////////////////////////////////////////////////////////////////////////////
        // Public Functions
        ///////////////////////////////////////////////////////////////////////////////////////////
        public LineItemDRM()
        {
            this.lineItemRow = DataSetModel.Instance.NewLineItemRow();
        }