Exemplo n.º 1
0
        protected virtual ProcessingResult HandleErrorThatPeriodIsClosed(IFinPeriod finPeriod)
        {
            ProcessingResult result = new ProcessingResult();

            if (!CanPostToClosedPeriod())
            {
                result.AddErrorMessage(Messages.FinPeriodIsClosedInCompany,
                                       FinPeriodIDFormattingAttribute.FormatForError(finPeriod.FinPeriodID),
                                       PXAccess.GetOrganizationCD(finPeriod.OrganizationID));
            }

            return(result);
        }
Exemplo n.º 2
0
        public virtual ProcessingResult CanPostToPeriod(IFinPeriod finPeriod, Type fieldModuleClosed = null)
        {
            ProcessingResult result = new ProcessingResult();

            if (finPeriod.Status == FinPeriod.status.Locked)
            {
                result.AddErrorMessage(Messages.FinPeriodIsLockedInCompany,
                                       FinPeriodIDFormattingAttribute.FormatForError(finPeriod.FinPeriodID),
                                       PXAccess.GetOrganizationCD(finPeriod.OrganizationID));

                return(result);
            }

            if (AllowPostToUnlockedPeriodAnyway)
            {
                return(result);
            }

            if (finPeriod.Status == FinPeriod.status.Inactive)
            {
                result.AddErrorMessage(Messages.FinPeriodIsInactiveInCompany,
                                       FinPeriodIDFormattingAttribute.FormatForError(finPeriod.FinPeriodID),
                                       PXAccess.GetOrganizationCD(finPeriod.OrganizationID));

                return(result);
            }

            if (finPeriod.Status == FinPeriod.status.Closed)
            {
                result = HandleErrorThatPeriodIsClosed(finPeriod);

                if (result.HasWarningOrError)
                {
                    return(result);
                }
            }

            if (fieldModuleClosed != null)
            {
                PXCache cache = Graph.Caches[BqlCommand.GetItemType(fieldModuleClosed)];

                bool?isClosedInModule = (bool)cache.GetValue(finPeriod, fieldModuleClosed.Name);

                if (isClosedInModule == true)
                {
                    result = HandleErrorThatPeriodIsClosed(finPeriod);
                }
            }

            return(result);
        }
        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);
        }
 private static void ValidateCleared(CATranEntryLight graph, CashAccount cashAccount, IFinPeriod period)
 {
     if (cashAccount.Reconcile != true)
     {
         graph.Clear();
         using (new PXConnectionScope())
         {
             using (PXTransactionScope ts = new PXTransactionScope())
             {
                 foreach (CATran catran in PXSelect <CATran, Where <CATran.cashAccountID, Equal <Required <CATran.cashAccountID> >,
                                                                    And <CATran.finPeriodID, GreaterEqual <Required <CATran.finPeriodID> > > > > .Select(graph, cashAccount.CashAccountID, period.FinPeriodID))
                 {
                     if (cashAccount.Reconcile != true && (catran.Cleared != true || catran.TranDate == null))
                     {
                         catran.Cleared   = true;
                         catran.ClearDate = catran.TranDate;
                     }
                     graph.catrancache.Update(catran);
                 }
                 graph.catrancache.Persist(PXDBOperation.Update);
                 ts.Complete(graph);
             }
             graph.catrancache.Persisted(false);
         }
     }
 }
        private static void ValidateCAAdjustments(CATranEntryLight graph, CashAccount cashAccount, IFinPeriod period)
        {
            using (new PXConnectionScope())
            {
                PXCache adjcache = graph.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,
                                                                                            And <CAAdj.finPeriodID, GreaterEqual <Required <CAAdj.finPeriodID> > > > > > > .Select(graph, cashAccount.CashAccountID, period.FinPeriodID))
                    {
                        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(graph, 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)graph.catrancache.Insert(catran);
                            graph.catrancache.PersistInserted(catran);
                            id = Convert.ToInt64(PXDatabase.SelectIdentity());

                            graph.SelectTimeStamp();

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

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

                    adjcache.Persist(PXDBOperation.Update);

                    ts.Complete(graph);
                }

                adjcache.Persisted(false);
                graph.catrancache.Persisted(false);
                graph.gltrancache.Persisted(false);
            }
        }
        private static void ValidateCATransfers(CATranEntryLight graph, CashAccount cashAccount, IFinPeriod period)
        {
            using (new PXConnectionScope())
            {
                PXCache transfercache = graph.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,
                                                                                            And <CATransfer.inDate, GreaterEqual <Required <CATransfer.inDate> > > > > > .Select(graph, cashAccount.CashAccountID, period.StartDate))
                    {
                        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)graph.catrancache.Insert(catran);
                            graph.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,
                                                                                            And <CATransfer.outDate, GreaterEqual <Required <CATransfer.outDate> > > > > > .Select(graph, cashAccount.CashAccountID, period.StartDate))
                    {
                        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)graph.catrancache.Insert(catran);
                            graph.catrancache.PersistInserted(catran);
                            long id = Convert.ToInt64(PXDatabase.SelectIdentity());

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

                    transfercache.Persist(PXDBOperation.Update);

                    ts.Complete(graph);
                }

                transfercache.Persisted(false);
                graph.catrancache.Persisted(false);
            }
        }
        private static void ValidateCATrans(CATranEntryLight graph, CashAccount cashAccount, IFinPeriod period)
        {
            PXDBDefaultAttribute.SetDefaultForUpdate <GLTran.module>(graph.Caches[typeof(GLTran)], null, false);
            PXDBDefaultAttribute.SetDefaultForUpdate <GLTran.batchNbr>(graph.Caches[typeof(GLTran)], null, false);
            PXDBDefaultAttribute.SetDefaultForUpdate <GLTran.ledgerID>(graph.Caches[typeof(GLTran)], null, false);
            PXDBDefaultAttribute.SetDefaultForUpdate <GLTran.finPeriodID>(graph.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,
                                                                                                                       And <GLTran.finPeriodID, GreaterEqual <Required <GLTran.finPeriodID> > > > > > > > >,
                                                                                       OrderBy <Asc <GLTran.tranID> > > .SelectWindowed(graph, 0, rowsPerCycle, cashAccount.AccountID, cashAccount.SubID, cashAccount.BranchID, period.FinPeriodID))
                        {
                            GLTran gltran = (GLTran)res;
                            lastGLTranID = gltran.TranID;
                            noMoreTran   = false;
                            countRows++;
                            CATran catran = GLCashTranIDAttribute.DefaultValues <GLTran.cATranID>(graph.gltrancache, gltran);
                            if (catran != null)
                            {
                                long id;
                                bool newCATRan = false;
                                if (graph.catrancache.Locate(catran) == null)
                                {
                                    catran    = (CATran)graph.catrancache.Insert(catran);
                                    newCATRan = true;
                                    graph.catrancache.PersistInserted(catran);
                                    id = Convert.ToInt64(PXDatabase.SelectIdentity());
                                }
                                else
                                {
                                    catran = (CATran)graph.catrancache.Update(catran);
                                    graph.catrancache.PersistUpdated(catran);
                                    id = catran.TranID.Value;
                                }

                                gltran.CATranID = id;
                                graph.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(graph, catran.OrigTranType, catran.OrigRefNbr);

                                        if (arPayment != null && (arPayment.CATranID == null || newCATRan))
                                        {
                                            arPayment.CATranID = id;
                                            arPayment          = (ARPayment)graph.Caches[typeof(ARPayment)].Update(arPayment);
                                            graph.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(graph, catran.OrigTranType, catran.OrigRefNbr);

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

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

                        previousCountRows          = countRows;
                        lastGLTranIDOnPreviousStep = lastGLTranID;

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

                graph.gltrancache.Persisted(false);
                graph.catrancache.Persisted(false);
            }
        }