public void Capture(XPObjectSpace objectSpace)
        {
            var objectType  = XafTypesInfo.Instance.FindBussinessObjectType <ISequenceReleasedObject>();
            var objectByKey = objectSpace.GetObjectByKey(objectType, _sequenceReleasedObjectKey);

            if (objectByKey != null)
            {
                objectSpace.Delete(objectByKey);
            }
        }
예제 #2
0
        public FixCashFlowsAlgorithm(XPObjectSpace objSpace, CashFlowFixParam paramObj, CashFlowFixMapper mapper)
        {
            this.objSpace = objSpace;
            this.paramObj = paramObj;

            if (paramObj.Snapshot == null)
            {
                currentSnapshot = GetCurrentSnapshot(objSpace.Session);
            }
            else
            {
                currentSnapshot = paramObj.Snapshot;
            }

            if (paramObj.ApReclassActivity != null)
            {
                paramApReclassActivity = objSpace.GetObjectByKey <Activity>(objSpace.GetKeyValue(paramObj.ApReclassActivity));
            }

            defaultCounterparty = objSpace.FindObject <Counterparty>(
                CriteriaOperator.Parse("Name LIKE ?", CashDiscipline.Common.Constants.DefaultFixCounterparty));

            var query = new XPQuery <CashForecastFixTag>(objSpace.Session);

            reversalFixTag = query
                             .Where(x => x.Name == CashDiscipline.Common.Constants.ReversalFixTag).FirstOrDefault();

            revRecFixTag = query
                           .Where(x => x.Name == CashDiscipline.Common.Constants.RevRecFixTag).FirstOrDefault();

            resRevRecFixTag = query
                              .Where(x => x.Name == CashDiscipline.Common.Constants.ResRevRecFixTag).FirstOrDefault();

            payrollFixTag = query
                            .Where(x => x.Name == CashDiscipline.Common.Constants.PayrollFixTag).FirstOrDefault();

            autoFixTag = query
                         .Where(x => x.Name == CashDiscipline.Common.Constants.AutoFixTag).FirstOrDefault();

            setOfBooks  = SetOfBooks.GetInstance(objSpace);
            this.mapper = mapper;

            this.sqlDeclareClauses = CreateSqlDeclareClauses();
            var sqlStringUtil = new SqlStringUtil();

            this.parameterCommandText = sqlStringUtil.CreateCommandText(sqlDeclareClauses);
        }
        private void Control_TokensChanged(object sender, EventArgs e)
        {
            ASPxTokenBox control = (ASPxTokenBox)sender;

            foreach (ListEditItem item in control.Items)
            {
                object obj = _ObjectSpace.GetObjectByKey(MemberInfo.ListElementTypeInfo.Type, item.Value);
                if (ItemIsTagged((Guid)item.Value))
                {
                    tokenItems.BaseAdd(obj);
                }
                else
                {
                    tokenItems.BaseRemove(obj);
                }
            }
            OnControlValueChanged();
            _ObjectSpace.SetModified(CurrentObject);
        }
 public void Capture(XPObjectSpace objectSpace) {
     var objectType = XafTypesInfo.Instance.FindBussinessObjectType<ISequenceReleasedObject>();
     var objectByKey = objectSpace.GetObjectByKey(objectType, _sequenceReleasedObjectKey);
     if (objectByKey != null)
         objectSpace.Delete(objectByKey);
 }
예제 #5
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();
        }
예제 #6
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();
        }