示例#1
0
        protected virtual void PrintChecksFilter_RowSelected(PXCache sender, PXRowSelectedEventArgs e)
        {
            bool SuggestNextNumber   = false;
            PrintChecksFilter filter = (PrintChecksFilter)e.Row;

            PXUIFieldAttribute.SetVisible <PrintChecksFilter.curyID>(sender, null, PXAccess.FeatureInstalled <FeaturesSet.multicurrency>());

            if (e.Row != null &&
                cashaccountdetail.Current != null &&
                (!Equals(cashaccountdetail.Current.CashAccountID, filter.PayAccountID) ||
                 !Equals(cashaccountdetail.Current.PaymentMethodID, filter.PayTypeID)))
            {
                cashaccountdetail.Current = null;
                SuggestNextNumber         = true;
            }

            if (e.Row != null && paymenttype.Current != null && (!Equals(paymenttype.Current.PaymentMethodID, filter.PayTypeID)))
            {
                paymenttype.Current = null;
            }

            if (e.Row != null && string.IsNullOrEmpty(filter.NextCheckNbr))
            {
                SuggestNextNumber = true;
            }

            PXUIFieldAttribute.SetVisible <PrintChecksFilter.nextCheckNbr>(sender, null, true);

            if (e.Row == null)
            {
                return;
            }

            if (cashaccountdetail.Current != null && true == cashaccountdetail.Current.APAutoNextNbr && SuggestNextNumber)
            {
                filter.NextCheckNbr = PaymentRefAttribute.GetNextPaymentRef(
                    sender.Graph,
                    cashaccountdetail.Current.CashAccountID,
                    cashaccountdetail.Current.PaymentMethodID);
            }

            bool printOrExport = paymenttype.Current == null || paymenttype.Current.PrintOrExport == true;

            bool isNextNumberDuplicated = false;

            if (paymenttype.Current != null && paymenttype.Current.PrintOrExport == true && string.IsNullOrEmpty(filter.NextCheckNbr))
            {
                sender.RaiseExceptionHandling <PrintChecksFilter.nextCheckNbr>(e.Row, filter.NextCheckNbr,
                                                                               new PXSetPropertyException(Messages.NextCheckNumberIsRequiredForProcessing, PXErrorLevel.Warning));
            }
            else if (!string.IsNullOrEmpty(filter.NextCheckNbr) && !AutoNumberAttribute.CanNextNumber(filter.NextCheckNbr))
            {
                sender.RaiseExceptionHandling <PrintChecksFilter.nextCheckNbr>(e.Row, filter.NextCheckNbr,
                                                                               new PXSetPropertyException(Messages.NextCheckNumberCanNotBeInc, PXErrorLevel.Warning));
            }
            else if (paymenttype.Current != null && paymenttype.Current.APPrintChecks == true &&
                     (isNextNumberDuplicated = filter.IsNextNumberDuplicated(sender.Graph, filter.NextCheckNbr)))
            {
                sender.RaiseExceptionHandling <PrintChecksFilter.nextCheckNbr>(e.Row, filter.NextCheckNbr,
                                                                               new PXSetPropertyException(Messages.ConflictWithExistingCheckNumber, filter.NextCheckNbr));
            }
            else
            {
                sender.RaiseExceptionHandling <PrintChecksFilter.nextCheckNbr>(e.Row, filter.NextCheckNbr, null);
            }

            APPaymentList.SetProcessEnabled(!isNextNumberDuplicated && printOrExport && filter.PayTypeID != null);
            APPaymentList.SetProcessAllEnabled(!isNextNumberDuplicated && printOrExport && filter.PayTypeID != null);

            if (HttpContext.Current != null && Filter.Current.BranchID != PXAccess.GetBranchID())
            {
                Filter.Current.BranchID = PXAccess.GetBranchID();
            }

            PaymentMethod pt = paymenttype.Current;

            APPaymentList.SetProcessDelegate(
                delegate(List <APPayment> list)
            {
                APPrintChecks graph = CreateInstance <APPrintChecks>();
                graph.PrintPayments(list, filter, pt);
            }
                );
        }
示例#2
0
        protected virtual void PrintPayments(List <APPayment> list, PrintChecksFilter filter, PaymentMethod paymentMethod)
        {
            if (list.Count == 0)
            {
                return;
            }

            if (paymentMethod.UseForAP == true)
            {
                if (paymentMethod.APPrintChecks == true && string.IsNullOrEmpty(paymentMethod.APCheckReportID))
                {
                    throw new PXException(Messages.FieldNotSetInPaymentMethod, PXUIFieldAttribute.GetDisplayName <PaymentMethod.aPCheckReportID>(paymenttype.Cache), paymentMethod.PaymentMethodID);
                }

                if (paymentMethod.APPrintChecks == true && paymentMethod.APPrintRemittance == true && string.IsNullOrEmpty(paymentMethod.APRemittanceReportID))
                {
                    throw new PXException(Messages.FieldNotSetInPaymentMethod, PXUIFieldAttribute.GetDisplayName <PaymentMethod.aPRemittanceReportID>(paymenttype.Cache), paymentMethod.PaymentMethodID);
                }
            }

            bool printAdditionRemit = false;

            if (paymentMethod.APCreateBatchPayment == true)
            {
                CABatch batch = CreateBatchPayment(list, filter);
                if (batch != null)
                {
                    bool           failed = false;
                    APPaymentEntry pe     = CreateInstance <APPaymentEntry>();

                    string NextCheckNbr = filter.NextCheckNbr;
                    foreach (APPayment pmt in list)
                    {
                        APPayment payment = pmt;
                        PXProcessing <APPayment> .SetCurrentItem(payment);

                        try
                        {
                            payment = pe.Document.Search <APPayment.refNbr>(payment.RefNbr, payment.DocType);
                            if (payment.PrintCheck != true)
                            {
                                throw new PXException(Messages.CantPrintNonprintableCheck);
                            }
                            if ((payment.DocType == APDocType.Check || payment.DocType == APDocType.QuickCheck) &&
                                payment.Status != APDocStatus.PendingPrint)
                            {
                                throw new PXException(Messages.ChecksMayBePrintedInPendingPrintStatus);
                            }

                            AssignNumbers(pe, payment, ref NextCheckNbr, true);

                            if (payment.Passed == true)
                            {
                                pe.TimeStamp = payment.tstamp;
                            }
                            pe.Save.Press();
                            payment.tstamp = pe.TimeStamp;
                            pe.Clear();
                        }
                        catch (PXException e)
                        {
                            PXProcessing <APPayment> .SetError(e);

                            failed = true;
                        }
                    }
                    if (failed)
                    {
                        throw new PXOperationCompletedWithErrorException(Messages.APPaymentsAreAddedToTheBatchButWasNotUpdatedCorrectly, batch.BatchNbr);
                    }
                    RedirectToResultWithCreateBatch(batch);
                }
            }
            else
            {
                APReleaseChecks     pp          = CreateInstance <APReleaseChecks>();
                ReleaseChecksFilter filter_copy = PXCache <ReleaseChecksFilter> .CreateCopy(pp.Filter.Current);

                filter_copy.PayAccountID = filter.PayAccountID;
                filter_copy.PayTypeID    = filter.PayTypeID;
                filter_copy.CuryID       = filter.CuryID;
                pp.Filter.Cache.Update(filter_copy);

                APPaymentEntry pe             = CreateInstance <APPaymentEntry>();
                bool           failed         = false;
                Dictionary <string, string> d = new Dictionary <string, string>();

                string nextCheckNbr = filter.NextCheckNbr;
                string prevCheckNbr = nextCheckNbr;

                int idxReportFilter = 0;
                foreach (APPayment pmt in list)
                {
                    APPayment payment = pmt;
                    PXProcessing <APPayment> .SetCurrentItem(payment);

                    try
                    {
                        prevCheckNbr = nextCheckNbr;
                        if (filter.IsNextNumberDuplicated(this, nextCheckNbr))
                        {
                            string duplicate = nextCheckNbr;
                            nextCheckNbr = AutoNumberAttribute.NextNumber(nextCheckNbr);
                            throw new PXException(Messages.ConflictWithExistingCheckNumber, duplicate);
                        }

                        payment = pe.Document.Search <APPayment.refNbr>(payment.RefNbr, payment.DocType);
                        if (payment.PrintCheck != true)
                        {
                            throw new PXException(Messages.CantPrintNonprintableCheck);
                        }
                        if ((payment.DocType == APDocType.Check || payment.DocType == APDocType.QuickCheck) &&
                            payment.Status != APDocStatus.PendingPrint)
                        {
                            throw new PXException(Messages.ChecksMayBePrintedInPendingPrintStatus);
                        }
                        AssignNumbers(pe, payment, ref nextCheckNbr);

                        if (payment.Passed == true)
                        {
                            pe.TimeStamp = payment.tstamp;
                        }
                        pe.Save.Press();
                        payment.tstamp = pe.TimeStamp;
                        pe.Clear();

                        APPayment seldoc = pe.Document.Search <APPayment.refNbr>(payment.RefNbr, payment.DocType);
                        seldoc.Selected = true;
                        seldoc.Passed   = true;
                        seldoc.tstamp   = payment.tstamp;
                        pp.APPaymentList.Cache.Update(seldoc);
                        pp.APPaymentList.Cache.SetStatus(seldoc, PXEntryStatus.Updated);

                        printAdditionRemit |= seldoc.BillCntr > paymentMethod.APStubLines;

                        StringBuilder sbDocType = new StringBuilder("APPayment.DocType");
                        sbDocType.Append(Convert.ToString(idxReportFilter));
                        StringBuilder sbRefNbr = new StringBuilder("APPayment.RefNbr");
                        sbRefNbr.Append(Convert.ToString(idxReportFilter));

                        idxReportFilter++;

                        d[sbDocType.ToString()] = payment.DocType == APDocType.QuickCheck ? APDocType.QuickCheck : APDocType.Check;
                        d[sbRefNbr.ToString()]  = payment.RefNbr;
                        PXProcessing <APPayment> .SetProcessed();
                    }
                    catch (PXException e)
                    {
                        PXProcessing <APPayment> .SetError(e);

                        failed       = true;
                        nextCheckNbr = prevCheckNbr;
                    }
                }

                if (failed)
                {
                    PXReportRequiredException report = null;
                    if (d.Count > 0)
                    {
                        d[ReportMessages.CheckReportFlag] = ReportMessages.CheckReportFlagValue;
                        report = new PXReportRequiredException(d, paymentMethod.APCheckReportID, PXBaseRedirectException.WindowMode.New, "Check");
                    }
                    throw new PXOperationCompletedWithErrorException(GL.Messages.DocumentsNotReleased, report);
                }
                else
                {
                    if (d.Count > 0)
                    {
                        RedirectToResultNoBatch(pp, d, paymentMethod, printAdditionRemit, nextCheckNbr);
                    }
                }
            }
        }