Ejemplo n.º 1
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();
        }
Ejemplo n.º 2
0
 private void populateNewStartingDataSet()
 {
     ffDataSet.Clear();
     addRequiredTableRows();
     addGoodDefaultRows();
 }