예제 #1
0
        protected virtual void ReleaseChecksFilter_RowSelected(PXCache sender, PXRowSelectedEventArgs e)
        {
            PXUIFieldAttribute.SetVisible <ReleaseChecksFilter.curyID>(sender, null, PXAccess.FeatureInstalled <FeaturesSet.multicurrency>());

            ReleaseChecksFilter filter = e.Row as ReleaseChecksFilter;

            if (filter == null)
            {
                return;
            }

            PaymentMethod paymentMethod = PXSelect <PaymentMethod,
                                                    Where <PaymentMethod.paymentMethodID, Equal <Required <ReleaseChecksFilter.payTypeID> > > > .Select(this, filter.PayTypeID);

            Reprint.SetEnabled(paymentMethod != null && paymentMethod.PrintOrExport == true);
            VoidReprint.SetEnabled(paymentMethod != null && paymentMethod.PrintOrExport == true);

            List <Tuple <string, string> > availableActions = new List <Tuple <string, PXAction> >
            {
                new Tuple <string, PXAction>(ReleaseChecksFilter.action.ReleaseChecks, Release),
                new Tuple <string, PXAction>(ReleaseChecksFilter.action.ReprintChecks, Reprint),
                new Tuple <string, PXAction>(ReleaseChecksFilter.action.VoidAndReprintChecks, VoidReprint)
            }
            .Select(t => new { ShortCut = t.Item1, State = t.Item2.GetState(filter) as PXButtonState })
            .Where(t => t.State?.Enabled == true)
            .Select(t => new Tuple <string, string>(t.ShortCut, t.State.DisplayName)).ToList();

            string[] actions = availableActions.Select(t => t.Item1).ToArray();
            PXStringListAttribute.SetLocalizable <ReleaseChecksFilter.action>(Filter.Cache, null, false);
            PXStringListAttribute.SetList <ReleaseChecksFilter.action>(Filter.Cache, null, actions, availableActions.Select(t => t.Item2).ToArray());
            PXUIFieldAttribute.SetEnabled <ReleaseChecksFilter.action>(Filter.Cache, filter, availableActions.Count > 1);

            if (availableActions.Count > 0)
            {
                if (filter.Action == null || !actions.Contains(filter.Action))
                {
                    filter.Action = actions[0];
                }
            }
            else
            {
                filter.Action = null;
            }

            string action = filter.Action;

            APPaymentList.SetProcessEnabled(action != null);
            APPaymentList.SetProcessAllEnabled(action != null);

            APPaymentList.SetProcessDelegate(list => ReleasePayments(list, action));
        }
예제 #2
0
        public virtual void SetPreloaded(APPrintChecks graph)
        {
            ReleaseChecksFilter filter_copy = PXCache <ReleaseChecksFilter> .CreateCopy(Filter.Current);

            filter_copy.PayAccountID = graph.Filter.Current.PayAccountID;
            filter_copy.PayTypeID    = graph.Filter.Current.PayTypeID;
            filter_copy.CuryID       = graph.Filter.Current.CuryID;
            Filter.Cache.Update(filter_copy);

            foreach (APPayment seldoc in graph.APPaymentList.Cache.Updated)
            {
                seldoc.Passed = true;
                APPaymentList.Cache.Update(seldoc);
                APPaymentList.Cache.SetStatus(seldoc, PXEntryStatus.Updated);
            }
            APPaymentList.Cache.IsDirty = false;

            TimeStamp = graph.TimeStamp;
        }
예제 #3
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);
                    }
                }
            }
        }
예제 #4
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);
                    }
                }
            }
        }