Example #1
0
        public static CABatch CreateBatchPayment(List <APPayment> list, PrintChecksFilter filter)
        {
            CABatchEntry be     = CreateInstance <CABatchEntry>();
            CABatch      result = be.Document.Insert(new CABatch());

            be.Document.Current = result;

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

            copy.CashAccountID   = filter.PayAccountID;
            copy.PaymentMethodID = filter.PayTypeID;
            result = be.Document.Update(copy);

            foreach (APPayment iPmt in list)
            {
                if (iPmt.CashAccountID != result.CashAccountID || iPmt.PaymentMethodID != result.PaymentMethodID)
                {
                    throw new PXException(Messages.APPaymentDoesNotMatchCABatchByAccountOrPaymentType);
                }

                if (string.IsNullOrEmpty(iPmt.ExtRefNbr) && string.IsNullOrEmpty(filter.NextCheckNbr))
                {
                    throw new PXException(Messages.NextCheckNumberIsRequiredForProcessing);
                }

                be.AddPayment(iPmt, true);
            }

            be.Save.Press();
            result = be.Document.Current;
            return(result);
        }
Example #2
0
 public virtual IEnumerable ProcessPayment(PXAdapter adapter)
 {
     if (this.Documents.Current != null && this.Filter.Current != null)
     {
         CheckSummary      res           = this.Documents.Current;
         DocFilter         currentFilter = this.Filter.Current;
         APPrintChecks     graph         = PXGraph.CreateInstance <APPrintChecks>();
         PrintChecksFilter paymentFilter = graph.Filter.Current;
         paymentFilter.PayAccountID = res.PayAccountID;
         paymentFilter.PayTypeID    = res.PayTypeID;
         graph.Filter.Update(paymentFilter);
         throw new PXRedirectRequiredException(graph, "ProcessPayment");
     }
     return(Filter.Select());
 }
Example #3
0
        protected virtual void PrintChecksFilter_RowUpdated(PXCache sender, PXRowUpdatedEventArgs e)
        {
            //refresh last number when saved values are populated in filter
            PrintChecksFilter oldRow = (PrintChecksFilter)e.OldRow;
            PrintChecksFilter row    = (PrintChecksFilter)e.Row;

            if ((oldRow.PayAccountID == null && oldRow.PayTypeID == null) ||
                (oldRow.PayAccountID != row.PayAccountID || oldRow.PayTypeID != row.PayTypeID))
            {
                ((PrintChecksFilter)e.Row).CurySelTotal = 0m;
                ((PrintChecksFilter)e.Row).SelTotal     = 0m;
                ((PrintChecksFilter)e.Row).SelCount     = 0;
                ((PrintChecksFilter)e.Row).NextCheckNbr = null;
                APPaymentList.Cache.Clear();
            }
        }
Example #4
0
        protected virtual void APPayment_RowUpdated(PXCache sender, PXRowUpdatedEventArgs e)
        {
            PrintChecksFilter filter = Filter.Current;

            if (filter != null)
            {
                object OldRow = e.OldRow;
                if (ReferenceEquals(e.Row, e.OldRow) && !_copies.TryGetValue(e.Row, out OldRow))
                {
                    decimal?curyval = 0m;
                    decimal?val     = 0m;
                    int?    count   = 0;
                    foreach (APPayment res in APPaymentList.Select())
                    {
                        if (res.Selected == true)
                        {
                            curyval += res.CuryOrigDocAmt ?? 0m;
                            val     += res.OrigDocAmt ?? 0m;
                            count++;
                        }
                    }

                    filter.CurySelTotal = curyval;
                    filter.SelTotal     = val;
                    filter.SelCount     = count;
                }
                else
                {
                    APPayment old_row = OldRow as APPayment;
                    APPayment new_row = e.Row as APPayment;

                    filter.CurySelTotal -= old_row.Selected == true ? old_row.CuryOrigDocAmt : 0m;
                    filter.CurySelTotal += new_row.Selected == true ? new_row.CuryOrigDocAmt : 0m;

                    filter.SelTotal -= old_row.Selected == true ? old_row.OrigDocAmt : 0m;
                    filter.SelTotal += new_row.Selected == true ? new_row.OrigDocAmt : 0m;

                    filter.SelCount -= old_row.Selected == true ? 1 : 0;
                    filter.SelCount += new_row.Selected == true ? 1 : 0;
                }
            }
        }
Example #5
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);
            }
                );
        }
Example #6
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);
                    }
                }
            }
        }
Example #7
0
        protected virtual void PrintChecksFilter_RowSelected(PXCache sender, PXRowSelectedEventArgs e)
        {
            bool SuggestNextNumber = false;
            PrintChecksFilter row  = (PrintChecksFilter)e.Row;

            PXUIFieldAttribute.SetVisible <PrintChecksFilter.curyID>(sender, null, (bool)CMSetup.Current.MCActivated);

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

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

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

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

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

            if (cashaccountdetail.Current != null && (bool)cashaccountdetail.Current.APAutoNextNbr == true)
            {
                //PXUIFieldAttribute.SetVisible<PrintChecksFilter.nextCheckNbr>(sender, null, true);
                if (SuggestNextNumber)
                {
                    if (string.IsNullOrEmpty(cashaccountdetail.Current.APLastRefNbr) == false)
                    {
                        row.NextCheckNbr = AutoNumberAttribute.NextNumber(cashaccountdetail.Current.APLastRefNbr);
                    }
                    else
                    {
                        row.NextCheckNbr = string.Empty;
                    }
                }
            }
            else
            {
                //PXUIFieldAttribute.SetVisible<PrintChecksFilter.nextCheckNbr>(sender, null, false);
                //row.NextCheckNbr = null;
            }

            if (paymenttype.Current != null && ((bool)paymenttype.Current.APPrintChecks == false && (bool)paymenttype.Current.APCreateBatchPayment == false))
            {
                sender.RaiseExceptionHandling <PrintChecksFilter.payTypeID>(e.Row, row.PayTypeID, new PXSetPropertyException(Messages.PaymentTypeNoPrintCheck, PXErrorLevel.Warning));
            }
            else
            {
                sender.RaiseExceptionHandling <PrintChecksFilter.payTypeID>(e.Row, row.PayTypeID, null);
            }

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


            PrintChecksFilter filter = Filter.Current;
            PaymentMethod     pt     = paymenttype.Current;

            APPaymentList.SetProcessTooltip(Messages.ProcessSelectedRecordsTooltip);
            APPaymentList.SetProcessAllTooltip(Messages.ProcessAllRecordsTooltip);
            APPaymentList.SetProcessDelegate(
                delegate(List <APPayment> list)
            {
                var graph = PXGraph.CreateInstance <APPrintChecks>();
                graph.PrintPayments(list, filter, pt);
                //CreateBatchPayment(list, filter);
            }
                );
        }
Example #8
0
        protected virtual void PrintPayments(List <APPayment> list, PrintChecksFilter filter, PaymentMethod paymenttype)
        {
            if (list.Count == 0)
            {
                return;
            }

            bool printAdditionRemit = false;

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

                    string NextCheckNbr = filter.NextCheckNbr;
                    for (int i = 0; i < list.Count; i++)
                    {
                        try
                        {
                            AssignNumbers(pe, list[i], ref NextCheckNbr, true);

                            if (list[i].Passed == true)
                            {
                                pe.TimeStamp = list[i].tstamp;
                            }
                            pe.Save.Press();
                            list[i].tstamp = pe.TimeStamp;
                            pe.Clear();
                            APPayment seldoc = (APPayment)pe.Document.Search <APPayment.refNbr>(list[i].RefNbr, list[i].DocType);
                            printAdditionRemit = seldoc.BillCntr > paymenttype.APStubLines;
                        }
                        catch (Exception e)
                        {
                            PXProcessing <APPayment> .SetError(i, e);

                            failed = true;
                        }
                    }
                    if (failed)
                    {
                        throw new PXOperationCompletedException(Messages.APPaymentsAreAddedToTheBatchButWasNotUpdatedCorrectly, batch.BatchNbr);
                    }
                    else
                    {
                        RedirectToResultWithCreateBatch(batch);
                    }
                }
            }
            else
            {
                APReleaseChecks     pp          = PXGraph.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      = PXGraph.CreateInstance <APPaymentEntry>();
                bool                        failed  = false;
                List <APPayment>            paylist = new List <APPayment>(list.Count);
                Dictionary <string, string> d       = new Dictionary <string, string>();

                string NextCheckNbr = null;

                if (filter != null)
                {
                    NextCheckNbr = filter.NextCheckNbr;
                }

                int idxReportFilter = 0;

                for (int i = 0; i < list.Count; i++)
                {
                    try
                    {
                        AssignNumbers(pe, list[i], ref NextCheckNbr);

                        if (list[i].Passed == true)
                        {
                            pe.TimeStamp = list[i].tstamp;
                        }
                        pe.Save.Press();
                        list[i].tstamp = pe.TimeStamp;
                        pe.Clear();

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

                        printAdditionRemit = seldoc.BillCntr > paymenttype.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()] = list[i].DocType == APDocType.QuickCheck ? APDocType.QuickCheck : APDocType.Check;
                        d[sbRefNbr.ToString()]  = list[i].RefNbr;
                    }
                    catch (Exception e)
                    {
                        PXProcessing <APPayment> .SetError(i, e);

                        failed = true;
                    }
                }

                if (failed)
                {
                    if (d.Count > 0)
                    {
                        d[ReportMessages.CheckReportFlag] = ReportMessages.CheckReportFlagValue;
                        var requiredException = new PXReportRequiredException(d, paymenttype.APCheckReportID,
                                                                              PXBaseRedirectException.WindowMode.New, "Check");
                        throw new PXException(GL.Messages.DocumentsNotReleased, requiredException);
                    }
                    throw new PXOperationCompletedException(GL.Messages.DocumentsNotReleased);
                }
                else
                {
                    if (d.Count > 0)
                    {
                        RedirectToResultNoBatch(pp, d, paymenttype, printAdditionRemit, NextCheckNbr);
                    }
                }
            }
        }