private static void ValidateCADailySummary(CATranEntryLight graph, CashAccount cashAccount, IFinPeriod period)
        {
            using (new PXConnectionScope())
            {
                using (PXTransactionScope ts = new PXTransactionScope())
                {
                    graph.dailycache.Clear();
                    ts.Complete(graph);
                }
            }

            PXDatabase.Delete <CADailySummary>(
                new PXDataFieldRestrict(nameof(CADailySummary.CashAccountID), PXDbType.Int, 4, cashAccount.CashAccountID, PXComp.EQ),
                new PXDataFieldRestrict(nameof(CADailySummary.TranDate), PXDbType.DateTime, 8, period.StartDate, PXComp.GE));

            foreach (CATran tran in PXSelect <CATran,
                                              Where <CATran.cashAccountID, Equal <Required <CATran.cashAccountID> >,
                                                     And <CATran.tranDate, GreaterEqual <Required <CATran.tranDate> > > > > .Select(graph, cashAccount.CashAccountID, period.StartDate))
            {
                CADailyAccumulatorAttribute.RowInserted <CATran.tranDate>(graph.catrancache, tran);
            }

            graph.dailycache.Persist(PXDBOperation.Insert);
            graph.dailycache.Persist(PXDBOperation.Update);

            graph.dailycache.Persisted(false);
        }
Exemplo n.º 2
0
        private static void Validate(CATranEntryLight te, CashAccount tlist)
        {
            using (new PXConnectionScope())
            {
                using (PXTransactionScope ts = new PXTransactionScope())
                {
                    Account account = PXSelect <Account, Where <Account.isCashAccount, Equal <False>,
                                                                And <Account.accountID, Equal <Required <Account.accountID> > > > > .Select(te, tlist.AccountID);

                    if (account != null)
                    {
                        account.IsCashAccount = true;
                        te.account.Update(account);
                        te.account.Cache.Persist(PXDBOperation.Update);
                        te.account.Cache.Persisted(false);
                    }
                    ts.Complete(te);
                }
            }
            te.Clear();

            if (tlist.Reconcile != true)
            {
                te.Clear();
                using (new PXConnectionScope())
                {
                    using (PXTransactionScope ts = new PXTransactionScope())
                    {
                        PXCache adjcache = te.Caches[typeof(CATran)];
                        foreach (CATran catran in PXSelect <CATran, Where <CATran.cashAccountID, Equal <Required <CATran.cashAccountID> > > > .Select(te, tlist.CashAccountID))
                        {
                            if (tlist.Reconcile != true && (catran.Cleared != true || catran.TranDate == null))
                            {
                                catran.Cleared   = true;
                                catran.ClearDate = catran.TranDate;
                            }
                            te.catrancache.Update(catran);
                        }
                        te.catrancache.Persist(PXDBOperation.Update);
                        ts.Complete(te);
                    }
                    te.catrancache.Persisted(false);
                }
            }

            te.Clear();

            using (new PXConnectionScope())
            {
                PXCache adjcache = te.Caches[typeof(CAAdj)];

                using (PXTransactionScope ts = new PXTransactionScope())
                {
                    foreach (PXResult <CAAdj, CATran> res in PXSelectJoin <CAAdj, LeftJoin <CATran, On <CATran.tranID, Equal <CAAdj.tranID> >,
                                                                                            LeftJoin <GLTranDoc, On <GLTranDoc.refNbr, Equal <CAAdj.adjRefNbr>, And <GLTranDoc.tranType, Equal <CAAdj.adjTranType>, And <GLTranDoc.tranModule, Equal <BatchModule.moduleCA> > > > > >,
                                                                           Where <CAAdj.cashAccountID, Equal <Required <CAAdj.cashAccountID> >, And <CATran.tranID, IsNull, And <GLTranDoc.refNbr, IsNull> > > > .Select(te, tlist.CashAccountID))
                    {
                        CAAdj caadj = (CAAdj)res;

                        GLTran gltran = PXSelectJoin <GLTran, InnerJoin <CashAccount,
                                                                         On <CashAccount.accountID, Equal <GLTran.accountID>,
                                                                             And <CashAccount.subID, Equal <GLTran.subID>,
                                                                                  And <CashAccount.branchID, Equal <GLTran.branchID> > > > >,
                                                      Where <GLTran.cATranID, Equal <Required <CAAdj.tranID> >,
                                                             And <CashAccount.cashAccountID, Equal <Required <CAAdj.cashAccountID> > > > > .Select(te, caadj.TranID, caadj.CashAccountID);

                        adjcache.SetValue <CAAdj.tranID>(caadj, null);
                        adjcache.SetValue <CAAdj.cleared>(caadj, false);

                        CATran catran = AdjCashTranIDAttribute.DefaultValues <CAAdj.tranID>(adjcache, caadj);
                        catran.BatchNbr = gltran?.BatchNbr;

                        long?id = null;

                        if (catran != null)
                        {
                            catran = (CATran)te.catrancache.Insert(catran);
                            te.catrancache.PersistInserted(catran);
                            id = Convert.ToInt64(PXDatabase.SelectIdentity());

                            te.SelectTimeStamp();

                            adjcache.SetValue <CAAdj.tranID>(caadj, id);
                            adjcache.Update(caadj);
                        }

                        if (id.HasValue && gltran?.TranID != null)
                        {
                            gltran.CATranID = id;
                            te.gltrancache.Update(gltran);
                            te.gltrancache.Persist(PXDBOperation.Update);
                        }
                    }

                    adjcache.Persist(PXDBOperation.Update);

                    ts.Complete(te);
                }

                adjcache.Persisted(false);
                te.catrancache.Persisted(false);
                te.gltrancache.Persisted(false);
            }

            te.Clear();

            using (new PXConnectionScope())
            {
                PXCache transfercache = te.Caches[typeof(CATransfer)];

                using (PXTransactionScope ts = new PXTransactionScope())
                {
                    foreach (PXResult <CATransfer, CATran> res in PXSelectJoin <CATransfer, LeftJoin <CATran, On <CATran.tranID, Equal <CATransfer.tranIDIn> > >, Where <CATransfer.inAccountID, Equal <Required <CATransfer.inAccountID> >, And <CATran.tranID, IsNull> > > .Select(te, tlist.CashAccountID))
                    {
                        CATransfer catransfer = (CATransfer)res;

                        transfercache.SetValue <CATransfer.tranIDIn>(catransfer, null);
                        transfercache.SetValue <CATransfer.clearedIn>(catransfer, false);
                        if (transfercache.GetValue <CATransfer.clearedOut>(catransfer) == null)
                        {
                            transfercache.SetValue <CATransfer.clearedOut>(catransfer, false);
                        }

                        CATran catran = TransferCashTranIDAttribute.DefaultValues <CATransfer.tranIDIn>(transfercache, catransfer);

                        if (catran != null)
                        {
                            catran = (CATran)te.catrancache.Insert(catran);
                            te.catrancache.PersistInserted(catran);
                            long id = Convert.ToInt64(PXDatabase.SelectIdentity());

                            transfercache.SetValue <CATransfer.tranIDIn>(catransfer, id);
                            transfercache.Update(catransfer);
                        }
                    }

                    foreach (PXResult <CATransfer, CATran> res in PXSelectJoin <CATransfer, LeftJoin <CATran, On <CATran.tranID, Equal <CATransfer.tranIDOut> > >, Where <CATransfer.outAccountID, Equal <Required <CATransfer.outAccountID> >, And <CATran.tranID, IsNull> > > .Select(te, tlist.CashAccountID))
                    {
                        CATransfer catransfer = (CATransfer)res;

                        transfercache.SetValue <CATransfer.tranIDOut>(catransfer, null);
                        transfercache.SetValue <CATransfer.clearedOut>(catransfer, false);
                        if (transfercache.GetValue <CATransfer.clearedIn>(catransfer) == null)
                        {
                            transfercache.SetValue <CATransfer.clearedIn>(catransfer, false);
                        }

                        CATran catran = TransferCashTranIDAttribute.DefaultValues <CATransfer.tranIDOut>(transfercache, catransfer);

                        if (catran != null)
                        {
                            catran = (CATran)te.catrancache.Insert(catran);
                            te.catrancache.PersistInserted(catran);
                            long id = Convert.ToInt64(PXDatabase.SelectIdentity());

                            transfercache.SetValue <CATransfer.tranIDOut>(catransfer, id);
                            transfercache.Update(catransfer);
                        }
                    }

                    transfercache.Persist(PXDBOperation.Update);

                    ts.Complete(te);
                }

                transfercache.Persisted(false);
                te.catrancache.Persisted(false);
            }

            te.Clear();

            PXDBDefaultAttribute.SetDefaultForUpdate <GLTran.module>(te.Caches[typeof(GLTran)], null, false);
            PXDBDefaultAttribute.SetDefaultForUpdate <GLTran.batchNbr>(te.Caches[typeof(GLTran)], null, false);
            PXDBDefaultAttribute.SetDefaultForUpdate <GLTran.ledgerID>(te.Caches[typeof(GLTran)], null, false);
            PXDBDefaultAttribute.SetDefaultForUpdate <GLTran.finPeriodID>(te.Caches[typeof(GLTran)], null, false);

            using (new PXConnectionScope())
            {
                const int rowsPerCycle = 10000;
                bool      noMoreTran   = false;
                int?      lastGLTranIDOnPreviousStep = null;
                int       previousCountRows          = 0;

                while (!noMoreTran)
                {
                    noMoreTran = true;
                    int countRows    = 0;
                    int?lastGLTranID = null;
                    using (PXTransactionScope ts = new PXTransactionScope())
                    {
                        foreach (PXResult <GLTran, Ledger, Batch> res in PXSelectJoin <GLTran, InnerJoin <Ledger, On <Ledger.ledgerID, Equal <GLTran.ledgerID> >,
                                                                                                          InnerJoin <Batch, On <Batch.module, Equal <GLTran.module>, And <Batch.batchNbr, Equal <GLTran.batchNbr>,
                                                                                                                                                                          And <Batch.scheduled, Equal <False>, And <Batch.voided, NotEqual <True> > > > > > >,
                                                                                       Where <GLTran.accountID, Equal <Required <GLTran.accountID> >,
                                                                                              And <GLTran.subID, Equal <Required <GLTran.subID> >,
                                                                                                   And <GLTran.branchID, Equal <Required <GLTran.branchID> >,
                                                                                                        And <Ledger.balanceType, Equal <LedgerBalanceType.actual>,
                                                                                                             //ignoring CM because DefaultValues always return null for CM
                                                                                                             And <GLTran.module, NotEqual <BatchModule.moduleCM>,
                                                                                                                  And <GLTran.cATranID, IsNull> > > > > >, OrderBy <Asc <GLTran.tranID> > > .SelectWindowed(te, 0, rowsPerCycle, tlist.AccountID, tlist.SubID, tlist.BranchID))
                        {
                            GLTran gltran = (GLTran)res;
                            lastGLTranID = gltran.TranID;
                            noMoreTran   = false;
                            countRows++;
                            CATran catran = GLCashTranIDAttribute.DefaultValues <GLTran.cATranID>(te.gltrancache, gltran);
                            if (catran != null)
                            {
                                long id;
                                bool newCATRan = false;
                                if (te.catrancache.Locate(catran) == null)
                                {
                                    catran    = (CATran)te.catrancache.Insert(catran);
                                    newCATRan = true;
                                    te.catrancache.PersistInserted(catran);
                                    id = Convert.ToInt64(PXDatabase.SelectIdentity());
                                }
                                else
                                {
                                    catran = (CATran)te.catrancache.Update(catran);
                                    te.catrancache.PersistUpdated(catran);
                                    id = catran.TranID.Value;
                                }

                                gltran.CATranID = id;
                                te.gltrancache.Update(gltran);

                                if (catran.OrigModule != GLTranType.GLEntry)
                                {
                                    switch (catran.OrigModule)
                                    {
                                    case BatchModule.AR:
                                        ARPayment arPayment = PXSelect <ARPayment, Where <ARPayment.docType, Equal <Required <ARPayment.docType> >,
                                                                                          And <ARPayment.refNbr, Equal <Required <ARPayment.refNbr> > > > > .Select(te, catran.OrigTranType, catran.OrigRefNbr);

                                        if (arPayment != null && (arPayment.CATranID == null || newCATRan))
                                        {
                                            arPayment.CATranID = id;
                                            arPayment          = (ARPayment)te.Caches[typeof(ARPayment)].Update(arPayment);
                                            te.Caches[typeof(ARPayment)].PersistUpdated(arPayment);
                                        }
                                        break;

                                    case BatchModule.AP:
                                        APPayment apPayment = PXSelect <APPayment, Where <APPayment.docType, Equal <Required <APPayment.docType> >,
                                                                                          And <APPayment.refNbr, Equal <Required <APPayment.refNbr> > > > > .Select(te, catran.OrigTranType, catran.OrigRefNbr);

                                        if (apPayment != null && (apPayment.CATranID == null || newCATRan))
                                        {
                                            apPayment.CATranID = id;
                                            apPayment          = (APPayment)te.Caches[typeof(APPayment)].Update(apPayment);
                                            te.Caches[typeof(APPayment)].PersistUpdated(apPayment);
                                        }
                                        break;
                                    }
                                }
                            }
                        }

                        if (!noMoreTran && countRows == previousCountRows && lastGLTranID == lastGLTranIDOnPreviousStep)
                        {
                            throw new PXException(Messages.ProcessCannotBeCompleted);
                        }

                        previousCountRows          = countRows;
                        lastGLTranIDOnPreviousStep = lastGLTranID;

                        te.gltrancache.ClearQueryCache();
                        te.gltrancache.Persist(PXDBOperation.Update);
                        te.gltrancache.Clear();
                        te.catrancache.Clear();
                        te.catrancache.ClearQueryCache();
                        te.dailycache.Clear();
                        te.Caches[typeof(APPayment)].Clear();
                        te.Caches[typeof(ARPayment)].Clear();
                        ts.Complete(te);
                    }
                }

                PXDatabase.Delete <CADailySummary>(
                    new PXDataFieldRestrict("CashAccountID", PXDbType.Int, 4, tlist.CashAccountID, PXComp.EQ));

                foreach (CATran tran in PXSelect <CATran, Where <CATran.cashAccountID, Equal <Required <CATran.cashAccountID> > > > .Select(te, tlist.CashAccountID))
                {
                    CADailyAccumulatorAttribute.RowInserted <CATran.tranDate>(te.catrancache, tran);
                }

                te.dailycache.Persist(PXDBOperation.Insert);
                te.dailycache.Persist(PXDBOperation.Update);


                te.gltrancache.Persisted(false);
                te.catrancache.Persisted(false);
                te.dailycache.Persisted(false);
            }
        }
Exemplo n.º 3
0
        private static void Validate(CATranEntry te, CashAccount tlist)
        {
            if (tlist.Reconcile != true)
            {
                te.Clear();
                using (new PXConnectionScope())
                {
                    using (PXTransactionScope ts = new PXTransactionScope())
                    {
                        PXCache adjcache = te.Caches[typeof(CATran)];
                        foreach (CATran catran in PXSelect <CATran, Where <CATran.cashAccountID, Equal <Required <CATran.cashAccountID> > > > .Select(te, tlist.CashAccountID))
                        {
                            if (tlist.Reconcile != true && (catran.Cleared != true || catran.TranDate == null))
                            {
                                catran.Cleared   = true;
                                catran.ClearDate = catran.TranDate;
                            }
                            te.catrancache.Update(catran);
                        }
                        te.catrancache.Persist(PXDBOperation.Update);
                        ts.Complete(te);
                    }
                    te.catrancache.Persisted(false);
                }
            }

            te.Clear();

            using (new PXConnectionScope())
            {
                PXCache adjcache = te.Caches[typeof(CAAdj)];

                using (PXTransactionScope ts = new PXTransactionScope())
                {
                    foreach (PXResult <CAAdj, CATran> res in PXSelectJoin <CAAdj, LeftJoin <CATran, On <CATran.tranID, Equal <CAAdj.tranID> > >, Where <CAAdj.cashAccountID, Equal <Required <CAAdj.cashAccountID> >, And <CATran.tranID, IsNull> > > .Select(te, tlist.CashAccountID))
                    {
                        CAAdj caadj = (CAAdj)res;

                        adjcache.SetValue <CAAdj.tranID>(caadj, null);
                        adjcache.SetValue <CAAdj.cleared>(caadj, false);

                        CATran catran = AdjCashTranIDAttribute.DefaultValues <CAAdj.tranID>(adjcache, caadj);

                        if (catran != null)
                        {
                            catran = (CATran)te.catrancache.Insert(catran);
                            te.catrancache.PersistInserted(catran);
                            long id = Convert.ToInt64(PXDatabase.SelectIdentity());

                            adjcache.SetValue <CAAdj.tranID>(caadj, id);
                            adjcache.Update(caadj);
                        }
                    }

                    adjcache.Persist(PXDBOperation.Update);

                    ts.Complete(te);
                }

                adjcache.Persisted(false);
                te.catrancache.Persisted(false);
            }

            te.Clear();

            using (new PXConnectionScope())
            {
                PXCache transfercache = te.Caches[typeof(CATransfer)];

                using (PXTransactionScope ts = new PXTransactionScope())
                {
                    foreach (PXResult <CATransfer, CATran> res in PXSelectJoin <CATransfer, LeftJoin <CATran, On <CATran.tranID, Equal <CATransfer.tranIDIn> > >, Where <CATransfer.inAccountID, Equal <Required <CATransfer.inAccountID> >, And <CATran.tranID, IsNull> > > .Select(te, tlist.CashAccountID))
                    {
                        CATransfer catransfer = (CATransfer)res;

                        transfercache.SetValue <CATransfer.tranIDIn>(catransfer, null);
                        transfercache.SetValue <CATransfer.clearedIn>(catransfer, false);
                        if (transfercache.GetValue <CATransfer.clearedOut>(catransfer) == null)
                        {
                            transfercache.SetValue <CATransfer.clearedOut>(catransfer, false);
                        }

                        CATran catran = TransferCashTranIDAttribute.DefaultValues <CATransfer.tranIDIn>(transfercache, catransfer);

                        if (catran != null)
                        {
                            catran = (CATran)te.catrancache.Insert(catran);
                            te.catrancache.PersistInserted(catran);
                            long id = Convert.ToInt64(PXDatabase.SelectIdentity());

                            transfercache.SetValue <CATransfer.tranIDIn>(catransfer, id);
                            transfercache.Update(catransfer);
                        }
                    }

                    foreach (PXResult <CATransfer, CATran> res in PXSelectJoin <CATransfer, LeftJoin <CATran, On <CATran.tranID, Equal <CATransfer.tranIDOut> > >, Where <CATransfer.outAccountID, Equal <Required <CATransfer.outAccountID> >, And <CATran.tranID, IsNull> > > .Select(te, tlist.CashAccountID))
                    {
                        CATransfer catransfer = (CATransfer)res;

                        transfercache.SetValue <CATransfer.tranIDOut>(catransfer, null);
                        transfercache.SetValue <CATransfer.clearedOut>(catransfer, false);
                        if (transfercache.GetValue <CATransfer.clearedIn>(catransfer) == null)
                        {
                            transfercache.SetValue <CATransfer.clearedIn>(catransfer, false);
                        }

                        CATran catran = TransferCashTranIDAttribute.DefaultValues <CATransfer.tranIDOut>(transfercache, catransfer);

                        if (catran != null)
                        {
                            catran = (CATran)te.catrancache.Insert(catran);
                            te.catrancache.PersistInserted(catran);
                            long id = Convert.ToInt64(PXDatabase.SelectIdentity());

                            transfercache.SetValue <CATransfer.tranIDOut>(catransfer, id);
                            transfercache.Update(catransfer);
                        }
                    }

                    transfercache.Persist(PXDBOperation.Update);

                    ts.Complete(te);
                }

                transfercache.Persisted(false);
                te.catrancache.Persisted(false);
            }

            te.Clear();

            PXDBDefaultAttribute.SetDefaultForUpdate <GLTran.module>(te.Caches[typeof(GLTran)], null, false);
            PXDBDefaultAttribute.SetDefaultForUpdate <GLTran.batchNbr>(te.Caches[typeof(GLTran)], null, false);
            PXDBDefaultAttribute.SetDefaultForUpdate <GLTran.ledgerID>(te.Caches[typeof(GLTran)], null, false);
            PXDBDefaultAttribute.SetDefaultForUpdate <GLTran.finPeriodID>(te.Caches[typeof(GLTran)], null, false);

            using (new PXConnectionScope())
            {
                using (PXTransactionScope ts = new PXTransactionScope())
                {
                    foreach (PXResult <GLTran, Ledger, Batch> res in PXSelectJoin <GLTran, InnerJoin <Ledger, On <Ledger.ledgerID, Equal <GLTran.ledgerID> >,
                                                                                                      InnerJoin <Batch, On <Batch.module, Equal <GLTran.module>, And <Batch.batchNbr, Equal <GLTran.batchNbr>,
                                                                                                                                                                      And <Batch.scheduled, Equal <False> > > > > >,
                                                                                   Where <GLTran.accountID, Equal <Required <GLTran.accountID> >, And <GLTran.subID, Equal <Required <GLTran.subID> >,
                                                                                                                                                       And <Ledger.balanceType, Equal <LedgerBalanceType.actual>, And <GLTran.cATranID, IsNull> > > > > .Select(te, tlist.AccountID, tlist.SubID))
                    {
                        GLTran gltran = (GLTran)res;
                        CATran catran = GLCashTranIDAttribute.DefaultValues <GLTran.cATranID>(te.gltrancache, gltran);

                        if (catran != null)
                        {
                            catran = (CATran)te.catrancache.Insert(catran);
                            te.catrancache.PersistInserted(catran);
                            long id = Convert.ToInt64(PXDatabase.SelectIdentity());

                            gltran.CATranID = id;
                            te.gltrancache.Update(gltran);
                        }
                    }

                    te.gltrancache.Persist(PXDBOperation.Update);

                    te.dailycache.Clear();

                    PXDatabase.Delete <CADailySummary>(
                        new PXDataFieldRestrict("CashAccountID", PXDbType.Int, 4, tlist.CashAccountID, PXComp.EQ)
                        );

                    foreach (CATran tran in PXSelect <CATran, Where <CATran.cashAccountID, Equal <Required <CATran.cashAccountID> > > > .Select(te, tlist.CashAccountID))
                    {
                        CADailyAccumulatorAttribute.RowInserted <CATran.tranDate>(te.catrancache, tran);
                    }

                    te.dailycache.Persist(PXDBOperation.Insert);
                    te.dailycache.Persist(PXDBOperation.Update);

                    ts.Complete(te);
                }

                te.gltrancache.Persisted(false);
                te.catrancache.Persisted(false);
                te.dailycache.Persisted(false);
            }
        }