Esempio n. 1
0
        public override void Persist()
        {
            foreach (BatchSelection updatedBatch in Batch_Detail.Cache.Updated)
            {
                UpdateTransactionsLedgerBalanceType(updatedBatch);

                if (updatedBatch.Voided == false)
                {
                    updatedBatch.Scheduled  = true;
                    updatedBatch.ScheduleID = Schedule_Header.Current.ScheduleID;

                    Batch_Detail.Cache.Update(updatedBatch);
                }
            }

            foreach (BatchSelection deletedBatch in Batch_Detail.Cache.Deleted)
            {
                PXDBDefaultAttribute.SetDefaultForUpdate <BatchSelection.scheduleID>(Batch_Detail.Cache, deletedBatch, false);

                UpdateTransactionsLedgerBalanceType(deletedBatch);

                deletedBatch.Scheduled  = false;
                deletedBatch.Voided     = true;
                deletedBatch.ScheduleID = null;

                Batch_Detail.Cache.SetStatus(deletedBatch, PXEntryStatus.Updated);
                Batch_Detail.Cache.Update(deletedBatch);
            }

            base.Persist();
        }
Esempio n. 2
0
        public override void Persist()
        {
            foreach (DocumentSelection b in Document_Detail.Cache.Updated)
            {
                ARReleaseProcess.UpdateARBalances(this, b, -b.OrigDocAmt);

                if (b.Voided == false)
                {
                    b.Scheduled  = true;
                    b.ScheduleID = Schedule_Header.Current.ScheduleID;
                    Document_Detail.Cache.Update(b);
                }

                ARReleaseProcess.UpdateARBalances(this, b, b.OrigDocAmt);
            }

            foreach (DocumentSelection b in Document_Detail.Cache.Deleted)
            {
                ARReleaseProcess.UpdateARBalances(this, b, -b.OrigDocAmt);

                PXDBDefaultAttribute.SetDefaultForUpdate <DocumentSelection.scheduleID>(Document_Detail.Cache, b, false);
                b.Voided     = true;
                b.OpenDoc    = false;
                b.Scheduled  = false;
                b.ScheduleID = null;
                Document_Detail.Cache.SetStatus(b, PXEntryStatus.Updated);
                Document_Detail.Cache.Update(b);

                ARReleaseProcess.UpdateARBalances(this, b, b.OrigDocAmt);
            }
            base.Persist();
        }
        public override void Persist()
        {
            foreach (DocumentSelection document in Document_Detail.Cache.Updated)
            {
                if (document.Voided == false)
                {
                    document.Scheduled  = true;
                    document.ScheduleID = Schedule_Header.Current.ScheduleID;

                    Document_Detail.Cache.Update(document);
                }
            }

            foreach (DocumentSelection document in Document_Detail.Cache.Deleted)
            {
                PXDBDefaultAttribute.SetDefaultForUpdate <DocumentSelection.scheduleID>(Document_Detail.Cache, document, false);

                document.Voided     = true;
                document.OpenDoc    = false;
                document.Scheduled  = false;
                document.ScheduleID = null;

                Document_Detail.Cache.SetStatus(document, PXEntryStatus.Updated);
                Document_Detail.Cache.Update(document);
            }

            base.Persist();
        }
Esempio n. 4
0
        public override void Persist()
        {
            foreach (DocumentSelection document in Document_Detail.Cache.Inserted)
            {
                // This case happens in Import Scenarios when rows have state "Inserted"
                // Move rows to collection Updated to set ScheduleID in next foreach
                Document_Detail.Cache.SetStatus(document, PXEntryStatus.Updated);
            }

            foreach (DocumentSelection document in Document_Detail.Cache.Updated)
            {
                if (document.Voided == false)
                {
                    document.Scheduled  = true;
                    document.ScheduleID = Schedule_Header.Current.ScheduleID;

                    Document_Detail.Cache.Update(document);
                }
            }

            foreach (DocumentSelection document in Document_Detail.Cache.Deleted)
            {
                PXDBDefaultAttribute.SetDefaultForUpdate <DocumentSelection.scheduleID>(Document_Detail.Cache, document, false);

                document.Voided     = true;
                document.OpenDoc    = false;
                document.Scheduled  = false;
                document.ScheduleID = null;

                Document_Detail.Cache.SetStatus(document, PXEntryStatus.Updated);
                Document_Detail.Cache.Update(document);
            }

            base.Persist();
        }
        public override void Initialize()
        {
            base.Initialize();

            PXDBDefaultAttribute.SetDefaultForUpdate <INTran.refNbr>(intranselect.Cache, null, false);
            PXDBDefaultAttribute.SetDefaultForUpdate <INTran.tranDate>(intranselect.Cache, null, false);
        }
        protected void PersistMessages(IEnumerable <CRSMEmail> messages)
        {
            using (PXTransactionScope ts = new PXTransactionScope())
            {
                foreach (CRSMEmail item in messages)
                {
                    try
                    {
                        var activityCache = Graph.Caches[item.GetType()];
                        PXDBDefaultAttribute.SetSourceType <CRSMEmail.refNoteID>(activityCache, item, null);
                        activityCache.PersistInserted(item);
                    }
                    catch (Exception e)
                    {
                        if (!MassProcessMode)
                        {
                            throw;
                        }
                        PXTrace.WriteInformation(e);
                    }
                }
                Graph.Caches <CRActivityStatistics>().Persist(PXDBOperation.Insert);
                Graph.Caches <CRActivityStatistics>().Persist(PXDBOperation.Update);

                ts.Complete();
            }
        }
Esempio n. 7
0
        public INIntegrityCheck()
        {
            INSetup record = insetup.Current;

            INItemList.SetProcessCaption(Messages.Process);
            INItemList.SetProcessAllCaption(Messages.ProcessAll);

            PXDBDefaultAttribute.SetDefaultForUpdate <INTranSplit.refNbr>(this.Caches[typeof(INTranSplit)], null, false);
            PXDBDefaultAttribute.SetDefaultForUpdate <INTranSplit.tranDate>(this.Caches[typeof(INTranSplit)], null, false);
        }
        public override void Persist()
        {
            foreach (BatchSelection updatedBatch in Batch_Detail.Cache.Updated)
            {
                if (updatedBatch.Voided == false)
                {
                    foreach (CATran cashTransaction in PXSelect <
                                 CATran,
                                 Where <
                                     CATran.origModule, Equal <Current <BatchSelection.module> >,
                                     And <CATran.origRefNbr, Equal <Current <BatchSelection.batchNbr> >,
                                          And <CATran.origTranType, Equal <CAAPARTranType.gLEntry> > > > >
                             .SelectMultiBound(this, new object[] { updatedBatch }))
                    {
                        CATransactions.Delete(cashTransaction);
                    }

                    foreach (GLTran glTransaction in PXSelect <
                                 GLTran,
                                 Where <
                                     GLTran.module, Equal <Current <BatchSelection.module> >,
                                     And <GLTran.batchNbr, Equal <Current <BatchSelection.batchNbr> > > > >
                             .SelectMultiBound(this, new object[] { updatedBatch }))
                    {
                        glTransaction.CATranID          = null;
                        glTransaction.LedgerBalanceType = "N";

                        GLTransactions.Update(glTransaction);
                    }

                    updatedBatch.Scheduled  = true;
                    updatedBatch.ScheduleID = Schedule_Header.Current.ScheduleID;

                    Batch_Detail.Cache.Update(updatedBatch);
                }
            }

            foreach (BatchSelection deletedBatch in Batch_Detail.Cache.Deleted)
            {
                PXDBDefaultAttribute.SetDefaultForUpdate <BatchSelection.scheduleID>(Batch_Detail.Cache, deletedBatch, false);

                deletedBatch.Scheduled  = false;
                deletedBatch.Voided     = true;
                deletedBatch.ScheduleID = null;

                Batch_Detail.Cache.SetStatus(deletedBatch, PXEntryStatus.Updated);
                Batch_Detail.Cache.Update(deletedBatch);
            }

            base.Persist();
        }
        protected virtual void SetupGraph()
        {
            graph.Clear();
            graph.Views.Caches.Add(typeof(Contract));
            graph.Views.Caches.Add(typeof(ContractDetail));
            graph.Views.Caches.Add(typeof(ContractBillingSchedule));

            PXCache <ContractBillingSchedule> scheduleCache = (PXCache <ContractBillingSchedule>)graph.Caches[typeof(ContractBillingSchedule)];

            PXDBDefaultAttribute.SetDefaultForUpdate <ContractBillingSchedule.contractID>(scheduleCache, null, false);

            PXCache <ContractDetail> contractItemCache = (PXCache <ContractDetail>)graph.Caches[typeof(ContractDetail)];

            PXDBDefaultAttribute.SetDefaultForUpdate <ContractDetail.contractID>(contractItemCache, null, false);
        }
Esempio n. 10
0
        public InventoryItemMaintBase()
        {
            INSetup     record      = insetup.Current;
            SOSetup     soSetup     = sosetup.Current;
            CommonSetup commonSetup = commonsetup.Current;

            PXUIFieldAttribute.SetVisible <INUnit.toUnit>(itemunits.Cache, null, false);
            PXUIFieldAttribute.SetEnabled <INUnit.toUnit>(itemunits.Cache, null, false);

            PXUIFieldAttribute.SetVisible <INUnit.sampleToUnit>(itemunits.Cache, null, true);
            PXUIFieldAttribute.SetEnabled <INUnit.sampleToUnit>(itemunits.Cache, null, false);
            PXUIFieldAttribute.SetVisible <INUnit.priceAdjustmentMultiplier>(itemunits.Cache, null, soSetup?.UsePriceAdjustmentMultiplier == true);

            PXDBDefaultAttribute.SetDefaultForInsert <INItemXRef.inventoryID>(itemxrefrecords.Cache, null, true);
        }
Esempio n. 11
0
        protected virtual void FillRelations <TNoteField>(CRRelationsList <TNoteField> relations, TTarget target) where TNoteField : IBqlField
        {
            var entity   = Documents.Current;
            var relation = (CRRelation)relations.Cache.CreateInstance();

            relation.RefNoteID    = target.NoteID;
            relation.Role         = CRRoleTypeList.Source;
            relation.TargetType   = TargetType;
            relation.TargetNoteID = entity.NoteID;
            relation.ContactID    = entity.RefContactID;

            // otherwise value would be rewriten from cache
            PXDBDefaultAttribute.SetDefaultForInsert <CRRelation.refNoteID>(relations.Cache, relation, false);

            relations.Insert(relation);
        }
        protected void PersistMessages(IEnumerable <EPActivity> messages)
        {
            using (PXTransactionScope ts = new PXTransactionScope())
            {
                foreach (EPActivity item in messages)
                {
                    var activityCache = Graph.Caches[item.GetType()];
                    PXDBDefaultAttribute.SetSourceType <EPActivity.refNoteID>(activityCache, item, null);
                    activityCache.PersistInserted(item);
                }
                Graph.Caches <CRActivityStatistics>().Persist(PXDBOperation.Insert);
                Graph.Caches <CRActivityStatistics>().Persist(PXDBOperation.Update);

                ts.Complete();
            }
        }
Esempio n. 13
0
        protected virtual void Schedule_RowDeleting(PXCache sender, PXRowDeletingEventArgs e)
        {
            foreach (BatchSelection b in PXSelect <BatchSelection, Where <BatchSelection.scheduleID, Equal <Required <Schedule.scheduleID> > > > .Select(this, ((Schedule)e.Row).ScheduleID))
            {
                if (b.Scheduled == true)
                {
                    b.Voided    = true;
                    b.Scheduled = false;
                }
                b.ScheduleID = null;

                if (Batch_Detail.Cache.GetStatus(b) == PXEntryStatus.Notchanged)
                {
                    Batch_Detail.Cache.SetStatus(b, PXEntryStatus.Updated);
                }
                PXDBDefaultAttribute.SetDefaultForUpdate <BatchSelection.scheduleID>(Batch_Detail.Cache, b, false);
            }
        }
Esempio n. 14
0
        protected virtual void Schedule_RowDeleting(PXCache sender, PXRowDeletingEventArgs e)
        {
            foreach (DocumentSelection document in PXSelect <
                         DocumentSelection,
                         Where <DocumentSelection.scheduleID, Equal <Required <Schedule.scheduleID> > > >
                     .Select(this, ((Schedule)e.Row).ScheduleID))
            {
                if ((bool)document.Scheduled)
                {
                    document.Voided    = true;
                    document.Scheduled = false;
                }

                document.ScheduleID = null;

                PXDBDefaultAttribute.SetDefaultForUpdate <DocumentSelection.scheduleID>(Document_Detail.Cache, document, false);

                Document_Detail.Cache.Update(document);
            }
        }
Esempio n. 15
0
        public override void Persist()
        {
            foreach (WZScenario b in Scenarios.Cache.Updated)
            {
                b.Scheduled  = true;
                b.ScheduleID = Schedule_Header.Current.ScheduleID;
                Scenarios.Cache.Update(b);
            }

            foreach (WZScenario b in Scenarios.Cache.Deleted)
            {
                PXDBDefaultAttribute.SetDefaultForUpdate <WZScenario.scheduleID>(Scenarios.Cache, b, false);
                b.Scheduled  = false;
                b.ScheduleID = null;
                Scenarios.Cache.SetStatus(b, PXEntryStatus.Updated);
                Scenarios.Cache.Update(b);
            }

            base.Persist();
        }
Esempio n. 16
0
        protected void PersistMessages(IEnumerable <CRSMEmail> messages)
        {
            using (PXTransactionScope ts = new PXTransactionScope())
            {
                if (_newAttachments.Count > 0)
                {
                    var upload = PXGraph.CreateInstance <UploadFileMaintenance>();
                    upload.IgnoreFileRestrictions = true;
                    foreach (FileInfo file in _newAttachments)
                    {
                        upload.SaveFile(file);
                        if (file.UID == null)
                        {
                            throw new Exception(string.Format("Cannot save file '{0}'" + file.Name));
                        }
                    }
                }

                foreach (CRSMEmail item in messages)
                {
                    try
                    {
                        var activityCache = Graph.Caches[item.GetType()];
                        PXDBDefaultAttribute.SetSourceType <CRSMEmail.refNoteID>(activityCache, item, null);
                        activityCache.PersistInserted(item);
                    }
                    catch (Exception e)
                    {
                        if (!MassProcessMode)
                        {
                            throw;
                        }
                        PXTrace.WriteInformation(e);
                    }
                }
                Graph.Caches <CRActivityStatistics>().Persist(PXDBOperation.Insert);
                Graph.Caches <CRActivityStatistics>().Persist(PXDBOperation.Update);

                ts.Complete();
            }
        }
Esempio n. 17
0
        protected virtual void Schedule_RowDeleting(PXCache sender, PXRowDeletingEventArgs e)
        {
            foreach (BatchSelection batch in PXSelect <
                         BatchSelection,
                         Where <
                             BatchSelection.scheduleID, Equal <Required <Schedule.scheduleID> > > >
                     .Select(this, ((Schedule)e.Row).ScheduleID))
            {
                if (batch.Scheduled == true)
                {
                    batch.Voided    = true;
                    batch.Scheduled = false;
                }

                batch.ScheduleID = null;

                Batch_Detail.Cache.MarkUpdated(batch);

                PXDBDefaultAttribute.SetDefaultForUpdate <BatchSelection.scheduleID>(Batch_Detail.Cache, batch, false);
            }
        }
Esempio n. 18
0
        public INSiteMaint()
        {
            INSetup record = insetup.Current;

            PXDBDefaultAttribute.SetDefaultForInsert <INLocation.siteID>(location.Cache, null, true);
            PXDBDefaultAttribute.SetDefaultForUpdate <INLocation.siteID>(location.Cache, null, true);

            PXUIFieldAttribute.SetVisible <INSite.pPVAcctID>(siteaccounts.Cache, null, true);
            PXUIFieldAttribute.SetVisible <INSite.pPVSubID>(siteaccounts.Cache, null, true);

            PXUIFieldAttribute.SetVisible <INSite.discAcctID>(siteaccounts.Cache, null, false);
            PXUIFieldAttribute.SetVisible <INSite.discSubID>(siteaccounts.Cache, null, false);

            PXUIFieldAttribute.SetVisible <INSite.freightAcctID>(siteaccounts.Cache, null, false);
            PXUIFieldAttribute.SetVisible <INSite.freightSubID>(siteaccounts.Cache, null, false);

            PXUIFieldAttribute.SetVisible <INSite.miscAcctID>(siteaccounts.Cache, null, false);
            PXUIFieldAttribute.SetVisible <INSite.miscSubID>(siteaccounts.Cache, null, false);

            PXUIFieldAttribute.SetDisplayName(Caches[typeof(Contact)], typeof(Contact.salutation).Name, CR.Messages.Attention);

            PXUIFieldAttribute.SetEnabled <Contact.fullName>(Caches[typeof(Contact)], null);
        }
Esempio n. 19
0
 public PMBillEngine()
 {
     PXDBDefaultAttribute.SetDefaultForUpdate <ContractBillingSchedule.contractID>(BillingSchedule.Cache, null, false);
     PXDBDefaultAttribute.SetDefaultForUpdate <ContractDetail.contractID>(ContractDetail.Cache, null, false);
 }
Esempio n. 20
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);
            }
        }
Esempio n. 21
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);
            }
        }
        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);
            }
        }