public virtual IEnumerable applications(PXAdapter adapter)
        {
            APPPDDebitAdjParameters filter = Filter.Current;

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

            PXSelectBase <PendingPPDDebitAdjApp> select = new PXSelect <PendingPPDDebitAdjApp,
                                                                        Where <PendingPPDDebitAdjApp.adjgDocDate, LessEqual <Current <APPPDDebitAdjParameters.applicationDate> >,
                                                                               And <PendingPPDDebitAdjApp.adjdBranchID, Equal <Current <APPPDDebitAdjParameters.branchID> > > > >(this);

            if (filter.VendorID != null)
            {
                select.WhereAnd <Where <PendingPPDDebitAdjApp.vendorID, Equal <Current <APPPDDebitAdjParameters.vendorID> > > >();
            }

            foreach (PendingPPDDebitAdjApp res in select.Select())
            {
                yield return(res);
            }

            Filter.Cache.IsDirty = false;
        }
Example #2
0
        private const bool AutoReleaseDebitAdjustments = true;         //TODO: now (26.10.2017) we can't apply nonreleased debit adjustment

        public static APInvoice CreateAndReleasePPDDebitAdj(APInvoiceEntry ie, APPPDDebitAdjParameters filter, List <PendingPPDDebitAdjApp> list, bool autoReleaseDebitAdjustments)
        {
            APInvoice invDebitAdj;

            try
            {
                ie.Clear(PXClearOption.ClearAll);
                PXUIFieldAttribute.SetError(ie.Document.Cache, null, null, null);

                using (var ts = new PXTransactionScope())
                {
                    invDebitAdj = ie.CreatePPDDebitAdj(filter, list);
                    if (invDebitAdj != null)
                    {
                        if (autoReleaseDebitAdjustments == true)
                        {
                            using (new PXTimeStampScope(null))
                            {
                                APDocumentRelease.ReleaseDoc(new List <APRegister> {
                                    invDebitAdj
                                }, false);
                                APPaymentEntry paymentEntry = PXGraph.CreateInstance <APPaymentEntry>();
                                APPayment      debitAdj     = PXSelect <APPayment,
                                                                        Where <APPayment.docType, Equal <Required <APPayment.docType> >,
                                                                               And <APPayment.refNbr, Equal <Required <APPayment.refNbr> > > > >
                                                              .Select(paymentEntry, invDebitAdj.DocType, invDebitAdj.RefNbr)
                                                              .First();

                                paymentEntry.Document.Current = debitAdj;
                                paymentEntry.SelectTimeStamp();
                                CreatePPDApplications(paymentEntry, list, debitAdj);
                                paymentEntry.Persist();
                                APDocumentRelease.ReleaseDoc(new List <APRegister> {
                                    invDebitAdj
                                }, false);                                                                                               // It needs to release applications
                            }
                        }

                        foreach (PendingPPDDebitAdjApp adj in list)
                        {
                            PXProcessing <PendingPPDDebitAdjApp> .SetInfo(adj.Index, ActionsMessages.RecordProcessed);
                        }
                    }
                    ts.Complete();
                }
            }
            catch (Exception e)
            {
                foreach (PendingPPDDebitAdjApp adj in list)
                {
                    PXProcessing <PendingPPDDebitAdjApp> .SetError(adj.Index, e);
                }

                invDebitAdj = null;
            }

            return(invDebitAdj);
        }
        public virtual void APPPDDebitAdjParameters_RowUpdated(PXCache sender, PXRowUpdatedEventArgs e)
        {
            APPPDDebitAdjParameters row    = (APPPDDebitAdjParameters)e.Row;
            APPPDDebitAdjParameters oldRow = (APPPDDebitAdjParameters)e.OldRow;

            if (row == null || oldRow == null)
            {
                return;
            }

            if (!sender.ObjectsEqual <APPPDDebitAdjParameters.applicationDate, APPPDDebitAdjParameters.branchID, APPPDDebitAdjParameters.vendorID>(oldRow, row))
            {
                Applications.Cache.Clear();
                Applications.Cache.ClearQueryCacheObsolete();
            }
        }
        protected virtual void APPPDDebitAdjParameters_GenerateOnePerVendor_FieldUpdated(PXCache sender, PXFieldUpdatedEventArgs e)
        {
            APPPDDebitAdjParameters filter = (APPPDDebitAdjParameters)e.Row;

            if (filter == null)
            {
                return;
            }

            if (filter.GenerateOnePerVendor != true && (bool?)e.OldValue == true)
            {
                filter.DebitAdjDate = null;
                filter.FinPeriodID  = null;

                sender.SetValuePending <APPPDDebitAdjParameters.debitAdjDate>(filter, null);
                sender.SetValuePending <APPPDDebitAdjParameters.finPeriodID>(filter, null);
            }
        }
        protected virtual void APPPDDebitAdjParameters_RowSelected(PXCache sender, PXRowSelectedEventArgs e)
        {
            APPPDDebitAdjParameters filter = (APPPDDebitAdjParameters)e.Row;

            if (filter == null)
            {
                return;
            }

            APSetup setup = apsetup.Current;

            Applications.SetProcessDelegate(list => CreatePPDDebitAdjs(sender, filter, setup, list));

            bool generateOnePerVendor = filter.GenerateOnePerVendor == true;

            PXUIFieldAttribute.SetEnabled <APPPDDebitAdjParameters.debitAdjDate>(sender, filter, generateOnePerVendor);
            PXUIFieldAttribute.SetEnabled <APPPDDebitAdjParameters.finPeriodID>(sender, filter, generateOnePerVendor);
            PXUIFieldAttribute.SetRequired <APPPDDebitAdjParameters.debitAdjDate>(sender, generateOnePerVendor);
            PXUIFieldAttribute.SetRequired <APPPDDebitAdjParameters.finPeriodID>(sender, generateOnePerVendor);
        }
        public static void CreatePPDDebitAdjs(PXCache cache, APPPDDebitAdjParameters filter, APSetup setup, List <PendingPPDDebitAdjApp> docs)
        {
            int            i      = 0;
            bool           failed = false;
            APInvoiceEntry ie     = PXGraph.CreateInstance <APInvoiceEntry>();

            ie.APSetup.Current = setup;

            if (filter.GenerateOnePerVendor == true)
            {
                if (filter.DebitAdjDate == null)
                {
                    throw new PXSetPropertyException(CR.Messages.EmptyValueErrorFormat,
                                                     PXUIFieldAttribute.GetDisplayName <APPPDDebitAdjParameters.debitAdjDate>(cache));
                }

                if (filter.FinPeriodID == null)
                {
                    throw new PXSetPropertyException(CR.Messages.EmptyValueErrorFormat,
                                                     PXUIFieldAttribute.GetDisplayName <APPPDDebitAdjParameters.finPeriodID>(cache));
                }

                Dictionary <PPDApplicationKey, List <PendingPPDDebitAdjApp> > dict = new Dictionary <PPDApplicationKey, List <PendingPPDDebitAdjApp> >();
                foreach (PendingPPDDebitAdjApp pendingPPDDebitAdjApp in docs)
                {
                    CurrencyInfo info = PXSelect <CurrencyInfo, Where <CurrencyInfo.curyInfoID, Equal <Required <CurrencyInfo.curyInfoID> > > > .Select(ie, pendingPPDDebitAdjApp.InvCuryInfoID);

                    PPDApplicationKey key = new PPDApplicationKey();
                    pendingPPDDebitAdjApp.Index = i++;
                    key.BranchID   = pendingPPDDebitAdjApp.AdjdBranchID;
                    key.BAccountID = pendingPPDDebitAdjApp.VendorID;
                    key.LocationID = pendingPPDDebitAdjApp.InvVendorLocationID;
                    key.CuryID     = info.CuryID;
                    key.CuryRate   = info.CuryRate;
                    key.AccountID  = pendingPPDDebitAdjApp.AdjdAPAcct;
                    key.SubID      = pendingPPDDebitAdjApp.AdjdAPSub;
                    key.TaxZoneID  = pendingPPDDebitAdjApp.InvTaxZoneID;

                    List <PendingPPDDebitAdjApp> list;
                    if (!dict.TryGetValue(key, out list))
                    {
                        dict[key] = list = new List <PendingPPDDebitAdjApp>();
                    }

                    list.Add(pendingPPDDebitAdjApp);
                }

                foreach (List <PendingPPDDebitAdjApp> list in dict.Values)
                {
                    APInvoice invoice = CreateAndReleasePPDDebitAdj(ie, filter, list, AutoReleaseDebitAdjustments);

                    if (invoice == null)
                    {
                        failed = true;
                    }
                }
            }
            else
            {
                foreach (PendingPPDDebitAdjApp pendingPPDDebitAdjApp in docs)
                {
                    List <PendingPPDDebitAdjApp> list = new List <PendingPPDDebitAdjApp>(1);
                    pendingPPDDebitAdjApp.Index = i++;
                    list.Add(pendingPPDDebitAdjApp);

                    APInvoice invoice = CreateAndReleasePPDDebitAdj(ie, filter, list, AutoReleaseDebitAdjustments);

                    if (invoice == null)
                    {
                        failed = true;
                    }
                }
            }

            if (failed)
            {
                throw new PXException(GL.Messages.DocumentsNotReleased);
            }
        }