コード例 #1
0
ファイル: Mapper.cs プロジェクト: ewin66/CashDiscipline
 public IList <TMap> RefreshMaps()
 {
     this.maps = objSpace.GetObjects <TMap>();
     return(maps);
 }
コード例 #2
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();
        }
コード例 #3
0
 public IList <CashFlowFixMapping> RefreshMaps()
 {
     this.maps = objSpace.GetObjects <CashFlowFixMapping>();
     return(maps);
 }
コード例 #4
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();
        }