private void CreateLienWaiver(LienWaiverGenerationKey generationKey, APPayment payment,
                                      string lienWaiverDocumentTypeValue)
        {
            var complianceAttribute = LienWaiverDataProvider.GetComplianceAttribute(lienWaiverDocumentTypeValue);

            LienWaiverCreator.CreateLienWaiver(generationKey, payment, complianceAttribute);
        }
Example #2
0
        private void UpdateVendorAndJointPaymentAmounts(APPayment payment)
        {
            var extension = PXCache <APPayment> .GetExtension <ApPaymentExt>(payment);

            extension.JointPaymentAmount  = JointPayeePayments.SelectMain().Sum(jpp => jpp.JointAmountToPay);
            extension.VendorPaymentAmount = payment.CuryOrigDocAmt - extension.JointPaymentAmount;
        }
Example #3
0
        public static void ReleaseDoc(CABatch aDoc)
        {
            if ((bool)aDoc.Released || (bool)aDoc.Hold)
            {
                throw new PXException(Messages.CABatchStatusIsNotValidForProcessing);
            }
            CABatchUpdate be  = PXGraph.CreateInstance <CABatchUpdate>();
            CABatch       doc = be.Document.Select(aDoc.BatchNbr);

            be.Document.Current = doc;
            if ((bool)doc.Released || (bool)doc.Hold)
            {
                throw new PXException(Messages.CABatchStatusIsNotValidForProcessing);
            }

            APPayment voided = PXSelectReadonly2 <APPayment,
                                                  InnerJoin <CABatchDetail, On <CABatchDetail.origDocType, Equal <APPayment.docType>,
                                                                                And <CABatchDetail.origRefNbr, Equal <APPayment.refNbr>,
                                                                                     And <CABatchDetail.origModule, Equal <GL.BatchModule.moduleAP> > > > >,
                                                  Where <CABatchDetail.batchNbr, Equal <Required <CABatch.batchNbr> >,
                                                         And <APPayment.voided, Equal <True> > > > .Select(be, doc.BatchNbr);

            if (voided != null && String.IsNullOrEmpty(voided.RefNbr) == false)
            {
                throw new PXException(Messages.CABatchContainsVoidedPaymentsAndConnotBeReleased);
            }

            List <APRegister>        unreleasedList   = new List <APRegister>();
            PXSelectBase <APPayment> selectUnreleased = new PXSelectReadonly2 <APPayment,
                                                                               InnerJoin <CABatchDetail, On <CABatchDetail.origDocType, Equal <APPayment.docType>,
                                                                                                             And <CABatchDetail.origRefNbr, Equal <APPayment.refNbr>,
                                                                                                                  And <CABatchDetail.origModule, Equal <GL.BatchModule.moduleAP> > > > >,
                                                                               Where <CABatchDetail.batchNbr, Equal <Optional <CABatch.batchNbr> >,
                                                                                      And <APPayment.released, Equal <boolFalse> > > >(be);

            foreach (APPayment iPmt in selectUnreleased.Select(doc.BatchNbr))
            {
                if (iPmt.Released != true)
                {
                    unreleasedList.Add(iPmt);
                }
            }
            if (unreleasedList.Count > 0)
            {
                APDocumentRelease.ReleaseDoc(unreleasedList, true);
            }

            selectUnreleased.View.Clear();
            APPayment pmt = selectUnreleased.Select(doc.BatchNbr);

            if (pmt != null)
            {
                throw new PXException(Messages.CABatchContainsUnreleasedPaymentsAndCannotBeReleased);
            }
            doc.Released   = true;
            doc.DateSeqNbr = GetNextDateSeqNbr(be, aDoc);
            be.RecalcTotals();
            doc = be.Document.Update(doc);
            be.Actions.PressSave();
        }
Example #4
0
 public virtual void AssignNumbers(APPaymentEntry paymentEntry, APPayment payment, ref string nextCheckNumber,
                                   bool skipStubs = false, AssignNumbersDelegate baseHandler = null)
 {
     lienWaiverProcessingValidationService.ValidateLienWaivers(payment,
                                                               LienWaiverSetup.Current?.ShouldStopPayments);
     baseHandler?.Invoke(paymentEntry, payment, ref nextCheckNumber, skipStubs);
 }
Example #5
0
 public virtual IEnumerable AddExtPayment(PXAdapter adapter)
 {
     if (this.Document.Current != null &&
         this.Document.Current.Released != true)
     {
         if (this.AvailablePayments.AskExt() == WebDialogResult.OK)
         {
             this.AvailablePayments.Cache.AllowInsert = true;
             foreach (APPayment it in this.AvailablePayments.Cache.Updated)
             {
                 APPayment pm = (APPayment)it;
                 if ((bool)pm.Selected)
                 {
                     this.AddPayment(pm, false);
                     pm.Selected = false;
                 }
             }
         }
         else
         {
             foreach (APPayment it in this.AvailablePayments.Cache.Updated)
             {
                 it.Selected = false;
             }
         }
         this.AvailablePayments.Cache.AllowInsert = false;
     }
     return(adapter.Get());
 }
Example #6
0
        private void UpdateJointCheckAvailability(APPayment payment)
        {
            var extension = PXCache <APPayment> .GetExtension <ApPaymentExt>(payment);

            extension.IsJointCheck = JointPayeePayments.SelectMain().Any();
            UpdateJointCheckVisibility(extension.IsJointCheck == true);
            JointPayeePayments.AllowUpdate = Base.Adjustments.AllowUpdate;
        }
        private void RedirectToFirstCheck(APPayment payment)
        {
            var paymentEntry = PXGraph.CreateInstance <APPaymentEntry>();

            TakePaymentsOffHoldIfNeeded(paymentEntry);
            paymentEntry.Document.Current = payment;
            paymentEntry.Actions.PressSave();
            throw new PXRedirectRequiredException(paymentEntry, JointCheckActions.PayInvoice);
        }
 private void CreateLienWaivers(LienWaiverGenerationKey generationKey, APPayment payment)
 {
     if (LienWaiverSetup.ShouldGenerateConditional == true)
     {
         CreateConditionalLienWaiver(generationKey, payment);
     }
     if (LienWaiverSetup.ShouldGenerateUnconditional == true)
     {
         CreateUnconditionalLienWaiver(generationKey, payment);
     }
 }
        private void SetJointPayeeVendorDependentFields(APPayment payment, ComplianceAttribute complianceAttribute)
        {
            var paymentExtension = PXCache <APPayment> .GetExtension <ApPaymentExt>(payment);

            lienWaiver.IsRequiredJointCheck  = paymentExtension.IsJointCheck ?? false;
            lienWaiver.JointVendorInternalId = generationKey.JointPayeeVendorId;
            var jointPayeePayments = GetJointPayeePaymentsWithJointPayees(payment).ToList();

            SetJointAmount(jointPayeePayments);
            SetJointLienWaiverAmount(complianceAttribute, jointPayeePayments);
        }
Example #10
0
        private APPayment CreateApPayment(IDocumentKey invoice)
        {
            var documentType = invoice.DocType == APDocType.DebitAdj
                ? APDocType.Refund
                : APDocType.Check;
            var payment = new APPayment
            {
                DocType = documentType
            };

            return(PaymentEntry.Document.Insert(payment));
        }
        /// <summary>
        /// Payment status change verification should be ignored in case of creating joint checks. The payment will be
        /// persisted second time to save <see cref="JointPayeePayment"/> records.
        /// </summary>
        private bool HasPaymentStatusChangedSinceLastSave(PXCache cache, APPayment payment)
        {
            var paymentExtension = PXCache <APPayment> .GetExtension <ApPaymentExt>(payment);

            if (paymentExtension.ShouldCreateLienWaivers == false)
            {
                return(false);
            }
            var originalStatus = CacheService.GetValueOriginal <APPayment.status>(cache, payment)?.ToString();

            return(payment.Status != originalStatus && originalStatus != APDocStatus.PendingPrint ||
                   paymentExtension.ShouldCreateLienWaivers == true);
        }
Example #12
0
 private void UpdatePayment(APInvoice invoice, APPayment payment, CashAccount cashAccount, int?payAccount,
                            Location location)
 {
     payment.VendorID         = invoice.VendorID;
     payment.VendorLocationID = invoice.PayLocationID;
     payment.AdjDate          = GetPaymentApplicationDate(invoice);
     payment.CashAccountID    = cashAccount.CuryID == invoice.CuryID
         ? payAccount
         : invoice.PayAccountID;
     payment.CuryID          = invoice.CuryID;
     payment.PaymentMethodID = invoice.PayTypeID ?? location.PaymentMethodID;
     payment.DocDesc         = invoice.DocDesc;
 }
 private void CreateLienWaiver(APPayment payment, ComplianceAttribute complianceAttribute)
 {
     lienWaiver = CreateLienWaiver();
     lienWaiver.DocumentTypeValue      = complianceAttribute.AttributeId;
     lienWaiver.Required               = true;
     lienWaiver.IsCreatedAutomatically = true;
     SetProjectDependentFields();
     SetCommitments();
     SetVendorDependentFields();
     SetTransactionDependentFields(payment, complianceAttribute);
     SetJointPayeeVendorDependentFields(payment, complianceAttribute);
     lienWaiver.ApPaymentMethodID = payment.PaymentMethodID;
 }
        private void SetTransactionDependentFields(APPayment payment, ComplianceAttribute complianceAttribute)
        {
            var transactions = LienWaiverTransactionRetriever.GetTransactions(generationKey).ToList();

            SetBillId(transactions);
            lienWaiver.LienWaiverAmount = GetLienWaiverAmount(transactions, complianceAttribute.Value);
            SetLienNoticeAmount();
            SetAccountId(transactions);
            ComplianceDocumentRefNoteAttribute.SetComplianceDocumentReference <ComplianceDocument.apCheckId>(
                Cache, lienWaiver, payment.DocType, payment.RefNbr, payment.NoteID);
            lienWaiver.PaymentDate = payment.AdjDate;
            lienWaiver.ThroughDate = GetThroughDate(complianceAttribute.Value, payment, transactions);
            lienWaiver.SourceType  = ComplianceDocumentSourceTypeAttribute.ApBill;
        }
 public virtual void CalcDetailsTotal(ref decimal?aCuryTotal, ref decimal?aTotal)
 {
     aCuryTotal = decimal.Zero;
     aTotal     = decimal.Zero;
     foreach (PXResult <CABatchDetail, APPayment> item in this.BatchPayments.Select())
     {
         APPayment payment = item;
         if (!string.IsNullOrEmpty(payment.RefNbr))
         {
             aCuryTotal += payment.CuryOrigDocAmt;
             aTotal     += payment.OrigDocAmt;
         }
     }
 }
Example #16
0
        private CABatch UpdateDocAmount(CABatchDetail row, bool negative)
        {
            CABatch document = this.Document.Current;

            if (row.OrigDocType != null && row.OrigRefNbr != null)
            {
                decimal?curyAmount = null, amount = null;
                if (row.OrigModule == GL.BatchModule.AP)
                {
                    APPayment payment = PXSelect <APPayment,
                                                  Where <APPayment.docType, Equal <Required <APPayment.docType> >,
                                                         And <APPayment.refNbr, Equal <Required <APPayment.refNbr> > > > > .Select(this, row.OrigDocType, row.OrigRefNbr);

                    if (payment != null)
                    {
                        curyAmount = payment.CuryOrigDocAmt;
                        amount     = payment.OrigDocAmt;
                    }
                }
                else
                {
                    ARPayment payment = PXSelect <ARPayment,
                                                  Where <ARPayment.docType, Equal <Required <ARPayment.docType> >,
                                                         And <ARPayment.refNbr, Equal <Required <ARPayment.refNbr> > > > > .Select(this, row.OrigDocType, row.OrigRefNbr);

                    if (payment != null)
                    {
                        curyAmount = payment.CuryOrigDocAmt;
                        amount     = payment.OrigDocAmt;
                    }
                }

                CABatch copy = (CABatch)this.Document.Cache.CreateCopy(document);

                if (curyAmount.HasValue)
                {
                    document.CuryDetailTotal += negative ? -curyAmount : curyAmount;
                }

                if (amount.HasValue)
                {
                    document.DetailTotal += negative ? -amount : amount;
                }

                document = this.Document.Update(document);
            }
            return(document);
        }
Example #17
0
        private void AddAllOutstandingInvoiceAction_Execute(object sender, SimpleActionExecuteEventArgs e)
        {
            APPayment payment = (APPayment)View.CurrentObject;
            //IObjectSpace os = Application.CreateObjectSpace();
            IList invoices = ObjectSpace.GetObjects(typeof(APInvoice), CriteriaOperator.Parse("Vendor.Oid=? and Owing>0", payment.Vendor.Oid, true));

            foreach (APInvoice invoice in invoices)
            {
                APPaymentItem item = ObjectSpace.CreateObject <APPaymentItem>();
                item.Invoice = invoice;
                item.Amount  = invoice.Owing;
                item.Payment = invoice.Owing;

                payment.Items.Add(item);
            }
        }
Example #18
0
        protected virtual bool IsPrepaymentCheck(APPayment payment)
        {
            bool prepayment = payment.DocType == APDocType.Prepayment;
            bool fromPO     = payment.OrigModule == BatchModule.PO;

            if (prepayment && fromPO)
            {
                return(false);
            }

            if (prepayment)
            {
                return(!Base.IsRequestPrepayment(payment));
            }

            return(false);
        }
Example #19
0
        public virtual CABatchDetail AddPayment(APPayment aPayment, bool skipCheck)
        {
            if (!skipCheck)
            {
                foreach (CABatchDetail iDel in this.BatchPayments.Select())
                {
                    if (IsKeyEqual(aPayment, iDel))
                    {
                        return(iDel);
                    }
                }
            }
            CABatchDetail detail = new CABatchDetail();

            detail.Copy(aPayment);
            detail = this.BatchPayments.Insert(detail);
            return(detail);
        }
Example #20
0
            public virtual void RecalcTotals()
            {
                CABatch row = this.Document.Current;

                if (row != null)
                {
                    row.DetailTotal = row.CuryDetailTotal = row.Total = decimal.Zero;
                    foreach (PXResult <APPayment, CABatchDetail> item in this.APPaymentList.Select())
                    {
                        APPayment payment = item;
                        if (!string.IsNullOrEmpty(payment.RefNbr))
                        {
                            row.CuryDetailTotal += payment.CuryOrigDocAmt;
                            row.DetailTotal     += payment.OrigDocAmt;
                        }
                    }
                }
            }
        private void GenerateLienWaiver(APPayment payment)
        {
            if (DoManuallyCreatedLienWaiversExistAndNotIgnored())
            {
                return;
            }
            var transactions = LienWaiverTransactionsProvider.GetTransactions(payment).ToList();

            if (transactions.IsEmpty())
            {
                return;
            }
            var jointPayees            = LienWaiverJointPayeesProvider.GetValidJointPayees().ToList();
            var lienWaiverGroupingKeys = LienWaiverGenerationKeyCreator.CreateGenerationKeys(
                transactions, jointPayees, payment);

            lienWaiverGroupingKeys.ForEach(groupingKey => CreateLienWaivers(groupingKey, payment));

            Base.Caches <ComplianceDocumentReference>().Persist(PXDBOperation.Delete);
        }
Example #22
0
        protected virtual void CABatchDetail_RowDeleted(PXCache sender, PXRowDeletedEventArgs e)
        {
            CABatchDetail row = (CABatchDetail)e.Row;

            if (!this._isMassDelete)
            {
                UpdateDocAmount(row, true);
            }
            #region Update APPayment.status
            var       cache   = this.Caches <APPayment>();
            APPayment payment = PXSelect <APPayment,
                                          Where <APPayment.docType, Equal <Required <APPayment.docType> >,
                                                 And <APPayment.refNbr, Equal <Required <APPayment.refNbr> > > > >
                                .Select(this, row.OrigDocType, row.OrigRefNbr);

            cache.SetValueExt <APPayment.printed>(payment, false);
            cache.SetValueExt <APPayment.hold>(payment, false);
            cache.SetValueExt <APPayment.extRefNbr>(payment, null);
            cache.MarkUpdated(payment);
            #endregion
        }
        private DateTime?GetThroughDate(string complianceAttributeValue, APPayment payment,
                                        IEnumerable <APTran> transactions)
        {
            var throughDateSource = complianceAttributeValue.IsIn(
                Constants.LienWaiverDocumentTypeValues.ConditionalFinal,
                Constants.LienWaiverDocumentTypeValues.ConditionalPartial)
                ? LienWaiverSetup.ThroughDateSourceConditional
                : LienWaiverSetup.ThroughDateSourceUnconditional;

            switch (throughDateSource)
            {
            case LienWaiverThroughDateSource.BillDate:
                return(InvoiceDataProvider.GetInvoices(Graph, transactions).Max(invoice => invoice.DocDate));

            case LienWaiverThroughDateSource.PaymentDate:
                return(payment.AdjDate);

            default:
                return(FinancialPeriodDataProvider.GetFinancialPeriod(Graph, payment.AdjFinPeriodID).EndDate
                       .GetValueOrDefault().AddDays(-1));
            }
        }
Example #24
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);
            }
        }
 public void CreateLienWaiver(LienWaiverGenerationKey lienWaiverGenerationKey, APPayment payment,
                              ComplianceAttribute complianceAttribute)
 {
     generationKey = lienWaiverGenerationKey;
     CreateLienWaiver(payment, complianceAttribute);
     Cache.Update(lienWaiver);
     Cache.Persist(PXDBOperation.Insert);
     Cache.Persisted(false);
 }
        private void CreateUnconditionalLienWaiver(LienWaiverGenerationKey generationKey, APPayment payment)
        {
            var lienWaiverDocumentTypeValue = LienWaiverTypeDeterminator.IsLienWaiverFinal(generationKey, false)
                ? Constants.LienWaiverDocumentTypeValues.UnconditionalFinal
                : Constants.LienWaiverDocumentTypeValues.UnconditionalPartial;

            CreateLienWaiver(generationKey, payment, lienWaiverDocumentTypeValue);
        }
 public static IEnumerable <List <JointPayeePayment> > GetCurrentJointPayeePaymentsByVendorGroups(PXGraph graph,
                                                                                                  APPayment payment)
 {
     return(GetNonReleasedJointPayeePaymentsAndJointPayees(graph, payment)
            .GroupBy(result => result.GetItem <JointPayee>(),
                     result => result.GetItem <JointPayeePayment>(), new JointPayeeComparer())
            .Select(group => RefreshJointPayeePayments(graph, group).ToList()));
 }
        public void DeleteJointPayeePayments(APPayment payment)
        {
            var jointPayeePayments = JointPayeePaymentDataProvider.GetJointPayeePayments(graph, payment);

            graph.Caches <JointPayeePayment>().DeleteAll(jointPayeePayments);
        }
 public void VoidCheckProc(APPayment payment, Action <APPayment> baseHandler)
 {
     VoidAutomaticallyCreatedLienWaivers();
     baseHandler(payment);
     VoidJointPayeePayments(payment);
 }
Example #30
0
 public static bool IsKeyEqual(APPayment payment, CABatchDetail detail)
 {
     return(detail.OrigModule == BatchModule.AP && payment.DocType == detail.OrigDocType && payment.RefNbr == detail.OrigRefNbr);
 }