Exemple #1
0
        private void runCashValuationMutationJobForAccount(IDalSession session, IList<IJournalEntryLine> lines, IAccountTypeCustomer account, DateTime maxDate, out IValuationCashMutation[] cashMutationsToSave)
        {
            //raiseProgressEvent(string.Format("Create Cash valuations for {0}", account.DisplayNumberWithName));
            cashMutationsToSave = null;
            IDictionary<string, IValuationCashMutation> mutations = new Dictionary<string, IValuationCashMutation>();
            IValuationCashMutation mutation;
            IList<IJournalEntryLine> notRelevantLines = new List<IJournalEntryLine>();

            if (lines != null && lines.Count > 0)
            {
                foreach (IJournalEntryLine line in lines.Where(u => u.GLAccount.ValuationCashType != ValuationCashTypes.None))
                {
                    if (line.BookDate <= maxDate && (Util.IsNullDate(account.ValuationsEndDate) || line.BookDate <= account.ValuationsEndDate))
                    {
                        if (line.IsRelevant)
                        {
                            ValuationCashMutationKey key = new ValuationCashMutationKey((IAccountTypeCustomer)line.GiroAccount, line.BookingRelatedInstrument, line.GLAccount.ValuationCashType);

                            // search key in account
                            // It's possible because of storno's or earlier tx that there is no LastCashMutation
                            // In this case create new CashMutation
                            if (account.LastValuationCashMutations.Count > 0 && account.LastValuationCashMutations.ContainsKey(key) && account.LastValuationCashMutations[key].LastCashMutation != null)
                            {
                                ILastValuationCashMutationHolder holder = account.LastValuationCashMutations[key];

                                // If pos Date is earlier than last recorded date -> skip it
                                if (holder.LastCashMutation.Date <= line.BookDate)
                                {
                                    // Is the TxDate the same
                                    if (holder.LastCashMutation.Date.Equals(line.BookDate))
                                    {
                                        // check whether line not already stored
                                        if (!holder.LastCashMutation.ContainsLine(line))
                                            mutation = holder.LastCashMutation;
                                        else
                                            mutation = null;
                                    }
                                    else
                                    {
                                        mutation = new ValuationCashMutation(line.BookDate, holder.LastCashMutation);
                                    }
                                }
                                else
                                    mutation = null;
                            }
                            else
                            {
                                // Create Complete New Cash Valuation
                                mutation = new ValuationCashMutation(line);
                            }

                            if (mutation != null)
                            {
                                mutation.AddLine(line);

                                if (account.LastValuationCashMutations.ContainsKey(key))
                                    account.LastValuationCashMutations[key].LastCashMutation = mutation;
                                else
                                    account.LastValuationCashMutations.Add(key, mutation);

                                if (!mutations.Keys.Contains(mutation.GetUniqueCode))
                                    mutations.Add(mutation.GetUniqueCode, mutation);
                            }
                        }
                        else
                            notRelevantLines.Add(line);
                    }
                }
                if (mutations != null && mutations.Count > 0)
                {
                    cashMutationsToSave = new IValuationCashMutation[mutations.Count];
                    mutations.Values.CopyTo(cashMutationsToSave, 0);

                    if (notRelevantLines.Count > 0)
                        addNotRelevantLinesToCashMutations(ref cashMutationsToSave, notRelevantLines);

                    // Validate mutations
                    foreach (IValuationCashMutation mut in cashMutationsToSave)
                        mut.Validate();
                }
            }
        }
 internal LastValuationCashMutationHolder(ValuationCashMutationKey key, IValuationCashMutation lastCashMutation)
 {
     this.CashMutKey = key;
     this.LastCashMutation = lastCashMutation;
 }