Exemplo n.º 1
0
        public static void UpdateCounterCcyAmt(CashFlow obj, decimal fromAmt, Currency fromCcy)
        {
            if (obj.CounterCcy == null)
            {
                return;
            }
            var session = obj.Session;

            if (obj.CounterCcy.Oid == fromCcy.Oid)
            {
                obj.CounterCcyAmt = fromAmt;
            }
            else if (obj.TranDate != default(DateTime))
            {
                var rateObj = GetForexRateObject(session, fromCcy, obj.CounterCcy, (DateTime)obj.TranDate);
                if (rateObj != null)
                {
                    // TODO: do not assume that Local Currency is 'AUD'
                    var value = Math.Round(fromAmt * (decimal)rateObj.ConversionRate, 2);
                    obj.SetPropertyValue("CounterCcyAmt", ref obj._CounterCcyAmt, value);
                }
            }
        }
Exemplo n.º 2
0
        public static void UpdateFunctionalCcyAmt(CashFlow obj, decimal fromAmt, Currency fromCcy)
        {
            if (obj == null || fromCcy == null)
            {
                return;
            }
            var session = obj.Session;

            var funcCcy = SetOfBooks.GetInstance(session).FunctionalCurrency;

            if (SetOfBooks.CachedInstance.FunctionalCurrency.Oid == fromCcy.Oid)
            {
                obj.FunctionalCcyAmt = fromAmt;
            }
            else if (obj.TranDate != default(DateTime))
            {
                var rateObj = GetForexRateObject(session, fromCcy, funcCcy, (DateTime)obj.TranDate);
                if (rateObj != null)
                {
                    var value = fromAmt * (decimal)rateObj.ConversionRate;
                    obj.FunctionalCcyAmt = value;
                }
            }
        }
Exemplo n.º 3
0
        public static void CalculateCashFlow(XPObjectSpace objSpace, DateTime fromDate, DateTime toDate, IList <CashFlowSnapshot> snapshots)
        {
            // delete cash flows within the date range
            CriteriaOperator deleteCriteria = CriteriaOperator.Parse("TranDate Between (?, ?) And LineType = ?",
                                                                     fromDate, toDate, AccountSummaryLineType.Flow);
            var snapshotOids = GetOidsFromSnapshots(snapshots);

            deleteCriteria = deleteCriteria & new InOperator("Snapshot.Oid", snapshotOids);
            objSpace.Session.Delete(objSpace.GetObjects <AccountSummary>(deleteCriteria));

            // get currenet snapshot GUID
            var curSnapshotOid = SetOfBooks.CachedInstance.CurrentCashFlowSnapshot.Oid;

            // add cash flows to AccountSummary
            var maxActualDate            = CashFlow.GetMaxActualTranDate(objSpace.Session); // TODO: why default(DateTime)?
            XPQuery <CashFlow> cashFlows = new XPQuery <CashFlow>(((XPObjectSpace)objSpace).Session);

            foreach (Guid snapshotOid in snapshotOids)
            {
                IQueryable <CashFlowGrouped> cfQuery = null;
                if (snapshotOid != curSnapshotOid)
                {
                    // previous snapshot
                    if (maxActualDate == default(DateTime))
                    {
                        // exclude max actual date from query
                        cfQuery = from c in cashFlows
                                  where c.TranDate >= fromDate && c.TranDate <= toDate &&
                                  (c.Snapshot.Oid == curSnapshotOid &&
                                   c.Status == CashFlowStatus.Actual
                                   ||
                                   c.Snapshot.Oid == snapshotOid
                                   // && c.TranDate > maxActualDate
                                  )
                                  orderby c.TranDate ascending
                                  group c by new { c.TranDate, c.Account } into grp
                            select new CashFlowGrouped(
                            grp.Key.TranDate,
                            grp.Key.Account,
                            (decimal)grp.Sum(c => c.AccountCcyAmt)
                            );
                    }
                    else
                    {
                        cfQuery = from c in cashFlows
                                  where c.TranDate >= fromDate && c.TranDate <= toDate &&
                                  (c.Snapshot.Oid == curSnapshotOid &&
                                   c.Status == CashFlowStatus.Actual
                                   ||
                                   c.Snapshot.Oid == snapshotOid &&
                                   c.TranDate > maxActualDate
                                  )
                                  orderby c.TranDate ascending
                                  group c by new { c.TranDate, c.Account } into grp
                            select new CashFlowGrouped(
                            grp.Key.TranDate,
                            grp.Key.Account,
                            (decimal)grp.Sum(c => c.AccountCcyAmt)
                            );
                    }
                }
                else
                {
                    // current snapshot
                    cfQuery = from c in cashFlows
                              where c.TranDate >= fromDate && c.TranDate <= toDate &&
                              c.Snapshot.Oid == snapshotOid
                              orderby c.TranDate ascending
                              group c by new { c.TranDate, c.Account } into grp
                        select new CashFlowGrouped(
                        grp.Key.TranDate,
                        grp.Key.Account,
                        (decimal)grp.Sum(c => c.AccountCcyAmt)
                        );
                }

                foreach (var cfItem in cfQuery)
                {
                    var summary = objSpace.CreateObject <AccountSummary>();
                    summary.Snapshot      = objSpace.GetObjectByKey <CashFlowSnapshot>(snapshotOid);
                    summary.TranDate      = cfItem.TranDate;
                    summary.Account       = cfItem.Account;
                    summary.AccountCcyAmt = cfItem.AccountCcyAmt;
                    summary.LineType      = AccountSummaryLineType.Flow;
                }
            }
            objSpace.CommitChanges();
        }
Exemplo n.º 4
0
 public void UpdateFunctionalCcyAmt(decimal fromAmt, Currency fromCcy)
 {
     CashFlow.UpdateFunctionalCcyAmt(this, fromAmt, fromCcy);
 }
Exemplo n.º 5
0
        public static void CalculateBalance(XPObjectSpace objSpace, DateTime atDate, IList <CashFlowSnapshot> snapshots)
        {
            // delete balances matching the specified date
            CriteriaOperator deleteCriteria = Fields.TranDate == atDate & Fields.LineType == new OperandValue(AccountSummaryLineType.Balance);
            var snapshotOids = GetOidsFromSnapshots(snapshots);

            deleteCriteria = deleteCriteria & new InOperator(AccountSummary.Fields.SnapshotOid.PropertyName, snapshotOids);
            objSpace.Session.Delete(objSpace.GetObjects <AccountSummary>(deleteCriteria));

            // get currenet snapshot GUID
            var curSnapshotOid = SetOfBooks.CachedInstance.CurrentCashFlowSnapshot.Oid;

            // add balances to Account Summary
            var maxActualDate            = CashFlow.GetMaxActualTranDate(objSpace.Session);
            XPQuery <CashFlow> cashFlows = new XPQuery <CashFlow>(((XPObjectSpace)objSpace).Session);

            foreach (Guid snapshotOid in snapshotOids)
            {
                IQueryable <CashBalanceGrouped> cfGrouped = null;

                if (snapshotOid != curSnapshotOid)
                {
                    // previous snapshot
                    if (maxActualDate == default(DateTime))
                    {
                        cfGrouped = from c in cashFlows
                                    where c.TranDate <= atDate &&
                                    (
                            c.Snapshot.Oid == snapshotOid
                            //&& c.TranDate > maxActualDate
                            || c.Snapshot.Oid == curSnapshotOid &&
                            c.Status == CashFlowStatus.Actual
                                    )
                                    group c by new { c.Account } into grp
                            select new CashBalanceGrouped(
                            grp.Key.Account,
                            (decimal)grp.Sum(c => c.AccountCcyAmt)
                            );
                    }
                    else
                    {
                        cfGrouped = from c in cashFlows
                                    where c.TranDate <= atDate &&
                                    (
                            c.Snapshot.Oid == snapshotOid &&
                            c.TranDate > maxActualDate ||
                            c.Snapshot.Oid == curSnapshotOid &&
                            c.Status == CashFlowStatus.Actual
                                    )
                                    group c by new { c.Account } into grp
                            select new CashBalanceGrouped(
                            grp.Key.Account,
                            (decimal)grp.Sum(c => c.AccountCcyAmt)
                            );
                    }
                }
                else
                {
                    // current snapshot

                    cfGrouped = from c in cashFlows
                                where c.TranDate <= atDate && c.Snapshot.Oid == snapshotOid
                                group c by new { c.Account } into grp
                        select new CashBalanceGrouped(
                        grp.Key.Account,
                        (decimal)grp.Sum(c => c.AccountCcyAmt)
                        );
                }

                if (cfGrouped == null)
                {
                    return;
                }
                foreach (var cfItem in cfGrouped)
                {
                    var summary = objSpace.CreateObject <AccountSummary>();
                    summary.Snapshot      = objSpace.GetObjectByKey <CashFlowSnapshot>(snapshotOid);
                    summary.TranDate      = atDate;
                    summary.Account       = cfItem.Account;
                    summary.AccountCcyAmt = cfItem.AccountCcyAmt;
                    summary.LineType      = AccountSummaryLineType.Balance;
                }
            }
            objSpace.CommitChanges();
        }