private static void _createPayments(List <ARInvoice> list, PayBillsFilter filter, CurrencyInfo info)
        {
            bool           failed = false;
            ARPaymentEntry pe     = PXGraph.CreateInstance <ARPaymentEntry>();

            list.Sort((in1, in2) =>
            {
                if (in1.CustomerID != in2.CustomerID)
                {
                    return(((IComparable)in1.CustomerID).CompareTo(in2.CustomerID));
                }
                return(((IComparable)in1.PMInstanceID).CompareTo(in2.PMInstanceID));
            }
                      );
            for (int i = 0; i < list.Count; i++)
            {
                ARInvoice doc       = list[i];
                ARPayment pmt       = null;
                bool      docFailed = false;
                try
                {
                    pe.CreatePayment(doc, info, filter.PayDate, filter.PayFinPeriodID, false);
                    pmt = pe.Document.Current;
                    if (pmt != null)
                    {
                        pmt.Hold = false;

                        FinPeriodIDAttribute.SetPeriodsByMaster <ARPayment.finPeriodID>(pe.Document.Cache, pmt, filter.PayFinPeriodID);
                    }
                    pe.Save.Press();
                }
                catch (Exception e)
                {
                    PXFilteredProcessing <ARInvoice, PayBillsFilter> .SetError(i, e.Message);

                    docFailed = failed = true;
                }

                if (!docFailed)
                {
                    PXFilteredProcessing <ARInvoice, PayBillsFilter> .SetInfo(i, PXMessages.LocalizeFormatNoPrefixNLA(Messages.ARPaymentIsCreatedProcessingINProgress, pmt.RefNbr));
                }
            }
            if (failed)
            {
                throw new PXException(Messages.CreationOfARPaymentFailedForSomeInvoices);
            }
        }
Exemple #2
0
        public static void CreatePayments(List <ARInvoice> list, PayBillsFilter filter, CurrencyInfo info)
        {
            Dictionary <ARPayment, List <int> > pmtRows = new Dictionary <ARPayment, List <int> >();

            bool             failed  = false;
            ARPaymentEntry   pe      = PXGraph.CreateInstance <ARPaymentEntry>();
            List <ARPayment> paylist = new List <ARPayment>();

            list.Sort((in1, in2) =>
            {
                if (in1.CustomerID != in2.CustomerID)
                {
                    return(((IComparable)in1.CustomerID).CompareTo(in2.CustomerID));
                }
                return(((IComparable)in1.PMInstanceID).CompareTo(in2.PMInstanceID));
            }
                      );
            for (int i = 0; i < list.Count; i++)
            {
                ARInvoice doc       = list[i];
                ARPayment pmt       = null;
                bool      docFailed = false;
                try
                {
                    pe.CreatePayment(doc, info, filter.PayDate, filter.PayFinPeriodID, false);
                    pmt = pe.Document.Current;
                    if (pmt != null)
                    {
                        if (!paylist.Contains(pmt))
                        {
                            if (String.IsNullOrEmpty(pmt.ExtRefNbr))
                            {
                                pe.Document.Current.ExtRefNbr = string.Format(Messages.ARAutoPaymentRefNbrFormat, filter.PayDate.Value);
                            }
                            paylist.Add(pmt);
                        }
                        if (!pmtRows.ContainsKey(pmt))
                        {
                            pmtRows[pmt] = new List <int>();
                        }
                        pmtRows[pmt].Add(i);

                        pmt.Hold        = false;
                        pmt.FinPeriodID = filter.PayFinPeriodID;
                    }
                    pe.Save.Press();
                }
                catch (Exception e)
                {
                    PXFilteredProcessing <PayBillsFilter, ARInvoice> .SetError(i, e.Message);

                    docFailed = failed = true;
                }

                if (!docFailed)
                {
                    PXFilteredProcessing <PayBillsFilter, ARInvoice> .SetInfo(i, string.Format(Messages.ARPaymentIsCreatedProcessingINProgress, pmt.RefNbr));
                }
            }
            if (failed)
            {
                throw new PXException(Messages.CreationOfARPaymentFailedForSomeInvoices);
            }
        }