private CABatch UpdateDocAmount(CABatchDetail row, bool negative)
        {
            CABatch doc = this.Document.Current;

            if (row.OrigDocType != null && row.OrigRefNbr != null)
            {
                decimal?  curyAmount = null, amount = null;
                ARPayment pmt = PXSelect <ARPayment,
                                          Where <ARPayment.docType, Equal <Required <ARPayment.docType> >,
                                                 And <ARPayment.refNbr, Equal <Required <ARPayment.refNbr> > > > > .Select(this, row.OrigDocType, row.OrigRefNbr);

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

                CABatch copy = (CABatch)this.Document.Cache.CreateCopy(doc);
                if (curyAmount.HasValue)
                {
                    doc.CuryDetailTotal += negative ? -curyAmount : curyAmount;
                }
                if (amount.HasValue)
                {
                    doc.DetailTotal += negative ? -amount : amount;
                }
                doc = this.Document.Update(doc);
            }
            return(doc);
        }
        public virtual IEnumerable ViewARDocument(PXAdapter adapter)
        {
            CABatchDetail doc = this.BatchPayments.Current;

            if (doc != null)
            {
                ARRegister arDoc = PXSelect <ARRegister,
                                             Where <ARRegister.docType, Equal <Required <ARRegister.docType> >,
                                                    And <ARRegister.refNbr, Equal <Required <ARRegister.refNbr> > > > > .Select(this, doc.OrigDocType, doc.OrigRefNbr);

                if (arDoc != null)
                {
                    ARPaymentEntry apGraph = PXGraph.CreateInstance <ARPaymentEntry>();
                    apGraph.Document.Current = apGraph.Document.Search <ARRegister.refNbr>(arDoc.RefNbr, arDoc.DocType);
                    if (apGraph.Document.Current != null)
                    {
                        throw new PXRedirectRequiredException(apGraph, true, "")
                              {
                                  Mode = PXBaseRedirectException.WindowMode.NewWindow
                              }
                    }
                    ;
                }
            }
            return(adapter.Get());
        }
예제 #3
0
        public static CABatch CreateBatchPayment(List <ARPayment> list, ProcessPaymentFilter filter)
        {
            CABatch result = new CABatch();

            //var resultExt = PXCache<CABatch>.GetExtension<CABatchExt>(result);
            //resultExt.BatchModule = GL.BatchModule.AR;

            ARBatchEntry be = PXGraph.CreateInstance <ARBatchEntry>();

            result = be.Document.Insert(result);
            be.Document.Current = result;
            CABatch copy = (CABatch)be.Document.Cache.CreateCopy(result);

            copy.CashAccountID   = filter.PayAccountID;
            copy.PaymentMethodID = filter.PayTypeID;
            be.Document.SetValueExt <CABatchExt.batchModule>(copy, GL.BatchModule.AR);
            result = be.Document.Update(copy);
            foreach (ARPayment iPmt in list)
            {
                if (iPmt.CashAccountID != result.CashAccountID || iPmt.PaymentMethodID != iPmt.PaymentMethodID)
                {
                    throw new PXException(AP.Messages.APPaymentDoesNotMatchCABatchByAccountOrPaymentType);
                }
                if (String.IsNullOrEmpty(iPmt.ExtRefNbr) && string.IsNullOrEmpty(filter.NextCheckNbr))
                {
                    throw new PXException(Messages.NextCheckNumberIsRequiredForProcessing);
                }
                CABatchDetail detail = be.AddPayment(iPmt);
            }
            be.Save.Press();
            result = be.Document.Current;
            return(result);
        }
        public virtual CABatchDetail AddPayment(ARPayment aPayment)
        {
            CABatchDetail detail = new CABatchDetail();

            detail.Copy(aPayment);
            detail = this.BatchPayments.Insert(detail);
            return(detail);
        }
        protected virtual void CABatchDetail_RowDeleted(PXCache sender, PXRowDeletedEventArgs e)
        {
            CABatchDetail row = (CABatchDetail)e.Row;

            if (!this._isMassDelete)
            {
                UpdateDocAmount(row, true);
            }
        }
        protected virtual void CABatchDetail_RowInserting(PXCache sender, PXRowInsertingEventArgs e)
        {
            CABatchDetail row        = (CABatchDetail)e.Row;
            bool          isReleased = false;

            ARRegister doc = PXSelect <ARRegister, Where <ARRegister.docType, Equal <Required <ARRegister.docType> >,
                                                          And <ARRegister.refNbr, Equal <Required <ARRegister.refNbr> > > > > .Select(this, row.OrigDocType, row.OrigRefNbr);

            isReleased = (bool)doc.Released;

            if (isReleased)
            {
                throw new PXException(CA.Messages.ReleasedDocumentMayNotBeAddedToCABatch);
            }
        }
예제 #7
0
        public static void ReleasePayments(List <APPayment> list, string Action)
        {
            APReleaseChecks releaseChecksGraph = CreateInstance <APReleaseChecks>();
            APPaymentEntry  pe        = CreateInstance <APPaymentEntry>();
            CABatchEntry    be        = CreateInstance <CABatchEntry>();
            bool            failed    = false;
            bool            successed = false;

            List <APRegister> docs = new List <APRegister>(list.Count);

            foreach (APPayment payment in list)
            {
                if (payment.Passed == true)
                {
                    releaseChecksGraph.TimeStamp = pe.TimeStamp = payment.tstamp;
                }

                switch (Action)
                {
                case ReleaseChecksFilter.action.ReleaseChecks:
                    payment.Printed = true;
                    break;

                case ReleaseChecksFilter.action.ReprintChecks:
                case ReleaseChecksFilter.action.VoidAndReprintChecks:
                    payment.ExtRefNbr = null;
                    payment.Printed   = false;
                    break;

                default:
                    continue;
                }

                PXProcessing <APPayment> .SetCurrentItem(payment);

                if (Action == ReleaseChecksFilter.action.ReleaseChecks)
                {
                    try
                    {
                        pe.Document.Current = pe.Document.Search <APPayment.refNbr>(payment.RefNbr, payment.DocType);
                        if (pe.Document.Current?.ExtRefNbr != payment.ExtRefNbr)
                        {
                            APPayment payment_copy = PXCache <APPayment> .CreateCopy(pe.Document.Current);

                            payment_copy.ExtRefNbr = payment.ExtRefNbr;
                            pe.Document.Update(payment_copy);
                        }

                        if (PaymentRefAttribute.PaymentRefMustBeUnique(pe.paymenttype.Current) && string.IsNullOrEmpty(payment.ExtRefNbr))
                        {
                            throw new PXException(ErrorMessages.FieldIsEmpty, typeof(APPayment.extRefNbr).Name);
                        }

                        payment.IsReleaseCheckProcess = true;

                        APPrintChecks.AssignNumbersWithNoAdditionalProcessing(pe, payment);
                        pe.Save.Press();

                        object[] persisted = PXTimeStampScope.GetPersisted(pe.Document.Cache, pe.Document.Current);
                        if (persisted == null || persisted.Length == 0)
                        {
                            //preserve timestamp which will be @@dbts after last record committed to db on previous Persist().
                            //otherwise another process updated APAdjust.
                            docs.Add(payment);
                        }
                        else
                        {
                            if (payment.Passed == true)
                            {
                                pe.Document.Current.Passed = true;
                            }
                            docs.Add(pe.Document.Current);
                        }
                        successed = true;
                    }
                    catch (PXException e)
                    {
                        PXProcessing <APPayment> .SetError(e);

                        docs.Add(null);
                        failed = true;
                    }
                }

                if (Action == ReleaseChecksFilter.action.ReprintChecks || Action == ReleaseChecksFilter.action.VoidAndReprintChecks)
                {
                    try
                    {
                        payment.IsPrintingProcess = true;
                        using (PXTransactionScope transactionScope = new PXTransactionScope())
                        {
                            #region Update CABatch if ReprintChecks
                            CABatch caBatch = PXSelectJoin <CABatch,
                                                            InnerJoin <CABatchDetail, On <CABatch.batchNbr, Equal <CABatchDetail.batchNbr> > >,
                                                            Where <CABatchDetail.origModule, Equal <Required <APPayment.origModule> >,
                                                                   And <CABatchDetail.origDocType, Equal <Required <APPayment.docType> >,
                                                                        And <CABatchDetail.origRefNbr, Equal <Required <APPayment.refNbr> > > > > > .
                                              Select(be, payment.OrigModule, payment.DocType, payment.RefNbr);

                            if (caBatch != null)
                            {
                                be.Document.Current = caBatch;
                                int           DetailCount = be.Details.Select().Count;                       // load
                                CABatchDetail detail      = be.Details.Locate(new CABatchDetail()
                                {
                                    BatchNbr    = be.Document.Current.BatchNbr,
                                    OrigModule  = payment.OrigModule,
                                    OrigDocType = payment.DocType,
                                    OrigRefNbr  = payment.RefNbr,
                                    OrigLineNbr = CABatchDetail.origLineNbr.DefaultValue,
                                });
                                if (detail != null)
                                {
                                    // payment.Status is recalculated in CABatchEntry.Delete
                                    if (DetailCount == 1)
                                    {
                                        be.Document.Delete(be.Document.Current);                                         // Details will delete by PXParent
                                    }
                                    else
                                    {
                                        be.Details.Delete(detail);                                          // recalculated batch totals
                                    }
                                }
                                be.Save.Press();
                            }
                            else
                            {
                                PXCache cacheAPPayment = releaseChecksGraph.APPaymentList.Cache;

                                cacheAPPayment.SetValueExt <APPayment.printed>(payment, false);
                                cacheAPPayment.SetValueExt <APPayment.hold>(payment, false);
                                cacheAPPayment.SetValueExt <APPayment.extRefNbr>(payment, null);
                                // APPayment.Status is recalculated by SetStatusCheckAttribute
                                cacheAPPayment.MarkUpdated(payment);

                                cacheAPPayment.PersistUpdated(payment);
                                cacheAPPayment.Persisted(false);
                            }
                            #endregion
                            // TODO: Need to rework. Use legal CRUD methods of caches!
                            releaseChecksGraph.TimeStamp = PXDatabase.SelectTimeStamp();

                            // delete check numbers only if Reprint (not Void and Reprint)
                            PaymentMethod pm = pe.paymenttype.Select(payment.PaymentMethodID);
                            if (pm.APPrintChecks == true && Action == ReleaseChecksFilter.action.ReprintChecks)
                            {
                                APPayment doc = payment;
                                new HashSet <string>(pe.Adjustments_Raw.Select(doc.DocType, doc.RefNbr)
                                                     .RowCast <APAdjust>()
                                                     .Select(adj => adj.StubNbr))
                                .ForEach(nbr => PaymentRefAttribute.DeleteCheck((int)doc.CashAccountID, doc.PaymentMethodID, nbr));

                                // sync PaymentMethodAccount.APLastRefNbr with actual last CashAccountCheck number
                                PaymentMethodAccount det = releaseChecksGraph.cashaccountdetail.SelectSingle(payment.CashAccountID, payment.PaymentMethodID);
                                PaymentRefAttribute.LastCashAccountCheckSelect.Clear(releaseChecksGraph);
                                CashAccountCheck cacheck = PaymentRefAttribute.LastCashAccountCheckSelect.SelectSingleBound(releaseChecksGraph, new object[] { det });
                                det.APLastRefNbr = cacheck?.CheckNbr;
                                releaseChecksGraph.cashaccountdetail.Cache.PersistUpdated(det);
                                releaseChecksGraph.cashaccountdetail.Cache.Persisted(false);
                            }
                            // END TODO
                            if (string.IsNullOrEmpty(payment.ExtRefNbr))
                            {
                                //try to get next number
                                releaseChecksGraph.APPaymentList.Cache.SetDefaultExt <APPayment.extRefNbr>(payment);
                            }
                            transactionScope.Complete();
                        }
                    }
                    catch (PXException e)
                    {
                        PXProcessing <APPayment> .SetError(e);
                    }
                    docs.Add(null);
                }
            }
            if (successed)
            {
                APDocumentRelease.ReleaseDoc(docs, true);
            }

            if (failed)
            {
                throw new PXOperationCompletedWithErrorException(GL.Messages.DocumentsNotReleased);
            }
        }
        protected virtual void CABatchDetail_RowInserted(PXCache sender, PXRowInsertedEventArgs e)
        {
            CABatchDetail row = (CABatchDetail)e.Row;

            UpdateDocAmount(row, false);
        }