コード例 #1
0
        private static void InitializeAdjustments(APAdjust adjustment, PayBillsFilter filter)
        {
            PXProcessing <APAdjust> .SetCurrentItem(adjustment);

            adjustment.AdjgDocDate     = filter.PayDate;
            adjustment.AdjgFinPeriodID = filter.PayFinPeriodID;
            PXProcessing <APAdjust> .SetProcessed();
        }
コード例 #2
0
        private void RedirectToResult(PaymentMethod paymentMethod, PayBillsFilter filter,
                                      IEnumerable <APAdjust> adjustments)
        {
            var targetGraph = paymentMethod?.PrintOrExport == true
                ? GetPrintChecksGraph(filter, adjustments)
                : GetReleaseChecksGraph(filter, adjustments);

            throw new PXRedirectRequiredException(targetGraph, JointCheckActions.NextProcessing);
        }
コード例 #3
0
 private void GenerateJointChecks(IEnumerable <APAdjust> adjustments,
                                  PayBillsFilter filter, APInvoice invoice)
 {
     adjustments.ForEach(a => InitializeAdjustments(a, filter));
     InvoiceEntry.Clear();
     InvoiceJointPayeePayments = GetInsertedInvoiceJointPayeePayments(
         invoice.DocType, invoice.RefNbr).ToList();
     InvoiceEntry.Document.Current = invoice;
     InvoiceEntry.GetExtension <ApInvoiceEntryExt>().Initialize();
     CreateJointChecks(InvoiceJointPayeePayments);
 }
        public static void CreatePayments(List <ARInvoice> list, PayBillsFilter filter, CurrencyInfo info)
        {
            if (RunningFlagScope <ARChargeInvoices> .IsRunning)
            {
                throw new PXSetPropertyException(Messages.AnotherChargeInvoiceRunning, PXErrorLevel.Warning);
            }

            using (new RunningFlagScope <ARChargeInvoices>())
            {
                _createPayments(list, filter, info);
            }
        }
コード例 #5
0
        private PXGraph GetReleaseChecksGraph(PayBillsFilter filter, IEnumerable <APAdjust> adjustments)
        {
            var releaseChecksGraph = PXGraph.CreateInstance <APReleaseChecks>();
            var filterCopy         = PXCache <ReleaseChecksFilter> .CreateCopy(releaseChecksGraph.Filter.Current);

            filterCopy.PayTypeID    = filter.PayTypeID;
            filterCopy.PayAccountID = filter.PayAccountID;
            filterCopy.CuryID       = filter.CuryID;
            releaseChecksGraph.Filter.Cache.Update(filterCopy);
            UpdateGraphCache(releaseChecksGraph, releaseChecksGraph.APPaymentList, adjustments);
            return(releaseChecksGraph);
        }
コード例 #6
0
        private void ProcessPayments(List <APAdjust> adjustments, PayBillsFilter filter, CurrencyInfo currencyInfo,
                                     PaymentMethod paymentMethod)
        {
            var jointAdjustments   = adjustments.Where(IsJointPayment).ToList();
            var defaultAdjustments = adjustments.Except(jointAdjustments).ToList();

            PreparePaymentsAdjustmentsCache.Add(jointAdjustments);
            PreparePaymentsAdjustmentsCache.Add(defaultAdjustments);
            ProcessDefaultPayments(defaultAdjustments, filter, currencyInfo, paymentMethod);
            ProcessJointPayments(jointAdjustments, filter);
            PreparePaymentsAdjustmentsCache.ClearStoredAdjustments();
            RedirectToResult(paymentMethod, filter, adjustments);
        }
コード例 #7
0
        private PXGraph GetPrintChecksGraph(PayBillsFilter filter, IEnumerable <APAdjust> adjustments)
        {
            var printChecksGraph = PXGraph.CreateInstance <APPrintChecks>();
            var filterCopy       = PXCache <PrintChecksFilter> .CreateCopy(printChecksGraph.Filter.Current);

            filterCopy.BranchID     = filter.BranchID;
            filterCopy.PayTypeID    = filter.PayTypeID;
            filterCopy              = (PrintChecksFilter)printChecksGraph.Filter.Cache.Update(filterCopy);
            filterCopy.PayAccountID = filter.PayAccountID;
            filterCopy.CuryID       = filter.CuryID;
            printChecksGraph.Filter.Cache.Update(filterCopy);
            UpdateGraphCache(printChecksGraph, printChecksGraph.APPaymentList, adjustments);
            return(printChecksGraph);
        }
コード例 #8
0
        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);
            }
        }
コード例 #9
0
 private void ProcessDefaultPayments(List <APAdjust> defaultPayments, PayBillsFilter filter,
                                     CurrencyInfo currencyInfo, PaymentMethod paymentMethod)
 {
     try
     {
         var graph = PXGraph.CreateInstance <APPayBills>();
         graph.CreatePayments(defaultPayments, filter, currencyInfo, paymentMethod);
     }
     finally
     {
         var payments = GetGeneratedPayments(defaultPayments);
         payments.ForEach(p =>
                          lienWaiverHoldPaymentService.HoldPaymentIfNeeded(p, LienWaiverSetup.Current.ShouldStopPayments));
         Base.Caches <APPayment>().Persist(PXDBOperation.Update);
     }
 }
コード例 #10
0
 public virtual IEnumerable ProcessPayment(PXAdapter adapter)
 {
     if (this.Documents.Current != null && this.Filter.Current != null)
     {
         PendingPaymentSummary res           = this.Documents.Current;
         PendingInvoiceFilter  currentFilter = this.Filter.Current;
         APPayBills            graph         = PXGraph.CreateInstance <APPayBills>();
         PayBillsFilter        paymentFilter = graph.Filter.Current;
         paymentFilter.PayAccountID = res.PayAccountID;
         paymentFilter.PayTypeID    = res.PayTypeID;
         paymentFilter.PayDate      = currentFilter.PayDate;
         graph.Filter.Update(paymentFilter);
         throw new PXRedirectRequiredException(graph, "ProcessPayment");
     }
     return(Filter.Select());
 }
コード例 #11
0
        private void ProcessJointPayments(IEnumerable <APAdjust> jointAdjustments, PayBillsFilter filter)
        {
            CheckRunningFlagScope();
            bool allPaymentsWereProcessed;

            using (new RunningFlagScope <APPayBills>())
            {
                var invoiceEntry          = PXGraph.CreateInstance <APInvoiceEntry>();
                var paymentEntry          = PXGraph.CreateInstance <APPaymentEntry>();
                var jointAdjustmentGroups = jointAdjustments.GroupBy(adj => adj.AdjdRefNbr);
                allPaymentsWereProcessed = jointAdjustmentGroups.Select(
                    adj => ProcessJointPayment(invoiceEntry, paymentEntry, adj.ToList(), filter))
                                           .ToList().All(isValid => isValid);
            }
            if (!allPaymentsWereProcessed)
            {
                throw new Exception(JointCheckMessages.PaymentCycleWorkflowIsStarted);
            }
        }
コード例 #12
0
 private void ClearPaymentInformationIfNeeded(PayBillsFilter filter)
 {
     if (Base.cashaccount.Current != null &&
         Equals(Base.cashaccount.Current.CashAccountID, filter.PayAccountID) == false)
     {
         Base.cashaccount.Current = null;
     }
     if (Base.cashaccountdetail.Current != null &&
         (Equals(Base.cashaccountdetail.Current.CashAccountID, filter.PayAccountID) == false ||
          Equals(Base.cashaccountdetail.Current.PaymentMethodID, filter.PayTypeID) == false))
     {
         Base.cashaccountdetail.Current = null;
     }
     if (Base.paymenttype.Current != null &&
         Equals(Base.paymenttype.Current.PaymentMethodID, filter.PayTypeID) == false)
     {
         Base.paymenttype.Current = null;
     }
 }
        protected virtual void PayBillsFilter_RowSelected(PXCache sender, PXRowSelectedEventArgs e)
        {
            PayBillsFilter filter = e.Row as PayBillsFilter;

            if (filter == null)
            {
                return;
            }
            PXUIFieldAttribute.SetVisible <PayBillsFilter.curyID>(sender, filter, PXAccess.FeatureInstalled <FeaturesSet.multicurrency>());

            CurrencyInfo info = CurrencyInfo_CuryInfoID.Select(filter.CuryInfoID);

            ARDocumentList.SetProcessDelegate(
                delegate(List <ARInvoice> list)
            {
                CreatePayments(list, filter, info);
            }
                );
        }
コード例 #14
0
        protected virtual void PayBillsFilter_RowSelected(PXCache sender, PXRowSelectedEventArgs e)
        {
            PayBillsFilter filter = e.Row as PayBillsFilter;

            if (filter == null)
            {
                return;
            }
            CMSetup cmsetup = CMSetup.Current;

            PXUIFieldAttribute.SetVisible <PayBillsFilter.curyID>(sender, filter, (bool)cmsetup.MCActivated);

            CurrencyInfo info = CurrencyInfo_CuryInfoID.Select(filter.CuryInfoID);

            ARDocumentList.SetProcessDelegate(
                delegate(List <ARInvoice> list)
            {
                CreatePayments(list, filter, info);
            }
                );
        }
コード例 #15
0
        private bool ProcessJointPayment(APInvoiceEntry invoiceEntry, APPaymentEntry paymentEntry,
                                         IReadOnlyCollection <APAdjust> adjustments, PayBillsFilter filter)
        {
            var invoice = InvoiceDataProvider.GetInvoice(
                Base, adjustments.First().AdjdDocType, adjustments.First().AdjdRefNbr);

            if (IsPaymentCycleWorkflow(invoice))
            {
                PXProcessing <APAdjust> .SetError(JointCheckMessages.PaymentCycleWorkflowIsStarted);

                return(false);
            }
            paymentEntry.Clear();
            var jointCheckPreparePaymentCreator = new JointCheckPreparePaymentCreator(invoiceEntry, paymentEntry, Base1);

            jointCheckPreparePaymentCreator.GenerateChecks(invoice, adjustments, filter);
            if (Base.APSetup.Current.HoldEntry == false)
            {
                lienWaiverHoldPaymentService.HoldPaymentsIfNeeded(invoice.RefNbr,
                                                                  LienWaiverSetup.Current.ShouldStopPayments);
                Base.Caches <APPayment>().Persist(PXDBOperation.Update);
            }
            return(true);
        }
コード例 #16
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);
            }
        }
コード例 #17
0
 public void GenerateChecks(APInvoice invoice, IReadOnlyCollection <APAdjust> adjustments, PayBillsFilter filter)
 {
     using (var scope = new PXTransactionScope())
     {
         LineNumbers = adjustments.Select(adj => adj.AdjdLineNbr);
         GenerateVendorCheck(invoice, adjustments);
         GenerateJointChecks(adjustments, filter, invoice);
         ComplianceDocumentsService.ClearLinkToPaymentFlag(ComplianceDocuments);
         OpenPaymentCycleWorkflow();
         InvoiceEntry.Caches <ComplianceDocumentReference>().Persist(PXDBOperation.Delete);
         scope.Complete();
     }
 }
        protected virtual IEnumerable ardocumentlist()
        {
            PayBillsFilter filter = this.Filter.Current;

            if (filter == null || filter.PayDate == null)
            {
                yield break;
            }

            DateTime OverDueForDate = ((DateTime)filter.PayDate).AddDays((short)-1 * (short)filter.OverDueFor);
            DateTime DueInLessThan  = ((DateTime)filter.PayDate).AddDays((short)+1 * (short)filter.DueInLessThan);

            DateTime DiscountExparedWithinLast = ((DateTime)filter.PayDate).AddDays((short)-1 * (short)filter.DiscountExparedWithinLast);
            DateTime DiscountExpiresInLessThan = ((DateTime)filter.PayDate).AddDays((short)+1 * (short)filter.DiscountExpiresInLessThan);

            foreach (PXResult <ARInvoice, Customer, CustomerPaymentMethod, PaymentMethod, CashAccount, ARAdjust, ARPayment> it
                     in PXSelectJoin <ARInvoice,
                                      InnerJoinSingleTable <Customer, On <Customer.bAccountID, Equal <ARInvoice.customerID> >,
                                                            InnerJoin <CustomerPaymentMethod, On <CustomerPaymentMethod.bAccountID, Equal <ARInvoice.customerID>,
                                                                                                  And <CustomerPaymentMethod.pMInstanceID, Equal <ARInvoice.pMInstanceID>,
                                                                                                       And <CustomerPaymentMethod.isActive, Equal <True> > > >,
                                                                       InnerJoin <PaymentMethod, On <PaymentMethod.paymentMethodID, Equal <CustomerPaymentMethod.paymentMethodID>,
                                                                                                     And <PaymentMethod.paymentType, Equal <PaymentMethodType.creditCard>,
                                                                                                          And <PaymentMethod.aRIsProcessingRequired, Equal <True> > > >,
                                                                                  LeftJoin <CashAccount, On <CashAccount.cashAccountID, Equal <ARInvoice.cashAccountID> >,
                                                                                            LeftJoin <ARAdjust, On <ARAdjust.adjdDocType, Equal <ARInvoice.docType>,
                                                                                                                    And <ARAdjust.adjdRefNbr, Equal <ARInvoice.refNbr>,
                                                                                                                         And <ARAdjust.released, Equal <False>,
                                                                                                                              And <ARAdjust.voided, Equal <False> > > > >,
                                                                                                      LeftJoin <ARPayment, On <ARPayment.docType, Equal <ARAdjust.adjgDocType>,
                                                                                                                               And <ARPayment.refNbr, Equal <ARAdjust.adjgRefNbr> > > > > > > > >,
                                      Where <ARInvoice.released, Equal <True>,
                                             And <ARInvoice.openDoc, Equal <True>,
                                                  And <ARInvoice.pendingPPD, NotEqual <True>,
                                                       And2 <Where2 <Where2 <Where <Current <PayBillsFilter.showOverDueFor>, Equal <True>,
                                                                                    And <ARInvoice.dueDate, LessEqual <Required <ARInvoice.dueDate> >
                                                                                         > >,
                                                                             Or2 <Where <Current <PayBillsFilter.showDueInLessThan>, Equal <True>,
                                                                                         And <ARInvoice.dueDate, GreaterEqual <Current <PayBillsFilter.payDate> >,
                                                                                              And <ARInvoice.dueDate, LessEqual <Required <ARInvoice.dueDate> >
                                                                                                   > > >,
                                                                                  Or2 <Where <Current <PayBillsFilter.showDiscountExparedWithinLast>, Equal <True>,
                                                                                              And <ARInvoice.discDate, GreaterEqual <Required <ARInvoice.discDate> >,
                                                                                                   And <ARInvoice.discDate, LessEqual <Current <PayBillsFilter.payDate> >
                                                                                                        > > >,
                                                                                       Or <Where <Current <PayBillsFilter.showDiscountExpiresInLessThan>, Equal <True>,
                                                                                                  And <ARInvoice.discDate, GreaterEqual <Current <PayBillsFilter.payDate> >,
                                                                                                       And <ARInvoice.discDate, LessEqual <Required <ARInvoice.discDate> >
                                                                                                            > > > > > > >,
                                                                     Or <Where <Current <PayBillsFilter.showOverDueFor>, Equal <False>,
                                                                                And <Current <PayBillsFilter.showDueInLessThan>, Equal <False>,
                                                                                     And <Current <PayBillsFilter.showDiscountExparedWithinLast>, Equal <False>,
                                                                                          And <Current <PayBillsFilter.showDiscountExpiresInLessThan>, Equal <False> > > > > > >,

                                                             And <Where2 <Where <ARAdjust.adjgRefNbr, IsNull, Or <ARPayment.voided, Equal <True> > >,
                                                                          And <Match <Customer, Current <AccessInfo.userName> > > > > > > > >,
                                      OrderBy <Asc <ARInvoice.customerID> > >
                     .Select(this, OverDueForDate,
                             DueInLessThan,
                             DiscountExparedWithinLast,
                             DiscountExpiresInLessThan))
            {
                ARInvoice   doc  = it;
                CashAccount acct = it;
                if (acct == null || acct.AccountID == null)
                {
                    acct = this.findDefaultCashAccount(doc);
                }
                if (acct == null)
                {
                    continue;
                }
                if (String.IsNullOrEmpty(filter.CuryID) == false && (filter.CuryID != acct.CuryID))
                {
                    continue;
                }
                yield return(new PXResult <ARInvoice, Customer, CustomerPaymentMethod, CashAccount>(it, it, it, acct));
            }

            ARDocumentList.Cache.IsDirty = false;
        }