Пример #1
0
        public virtual IEnumerable applications(PXAdapter adapter)
        {
            ARPPDCreditMemoParameters filter = Filter.Current;

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

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

            if (filter.CustomerID != null)
            {
                select.WhereAnd <Where <PendingPPDCreditMemoApp.customerID, Equal <Current <ARPPDCreditMemoParameters.customerID> > > >();
            }

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

            Filter.Cache.IsDirty = false;
        }
Пример #2
0
        public virtual void ARPPDCreditMemoParameters_RowUpdated(PXCache sender, PXRowUpdatedEventArgs e)
        {
            ARPPDCreditMemoParameters row    = (ARPPDCreditMemoParameters)e.Row;
            ARPPDCreditMemoParameters oldRow = (ARPPDCreditMemoParameters)e.OldRow;

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

            if (!sender.ObjectsEqual <ARPPDCreditMemoParameters.applicationDate, ARPPDCreditMemoParameters.branchID, ARPPDCreditMemoParameters.customerID>(oldRow, row))
            {
                Applications.Cache.Clear();
                Applications.Cache.ClearQueryCache();
            }
        }
Пример #3
0
        protected virtual void ARPPDCreditMemoParameters_GenerateOnePerCustomer_FieldUpdated(PXCache sender, PXFieldUpdatedEventArgs e)
        {
            ARPPDCreditMemoParameters filter = (ARPPDCreditMemoParameters)e.Row;

            if (filter == null)
            {
                return;
            }

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

                sender.SetValuePending <ARPPDCreditMemoParameters.creditMemoDate>(filter, null);
                sender.SetValuePending <ARPPDCreditMemoParameters.finPeriodID>(filter, null);
            }
        }
Пример #4
0
        protected virtual void ARPPDCreditMemoParameters_RowSelected(PXCache sender, PXRowSelectedEventArgs e)
        {
            ARPPDCreditMemoParameters filter = (ARPPDCreditMemoParameters)e.Row;

            if (filter == null)
            {
                return;
            }

            ARSetup setup = arsetup.Current;

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

            bool generateOnePerCustomer = filter.GenerateOnePerCustomer == true;

            PXUIFieldAttribute.SetEnabled <ARPPDCreditMemoParameters.creditMemoDate>(sender, filter, generateOnePerCustomer);
            PXUIFieldAttribute.SetEnabled <ARPPDCreditMemoParameters.finPeriodID>(sender, filter, generateOnePerCustomer);
            PXUIFieldAttribute.SetRequired <ARPPDCreditMemoParameters.creditMemoDate>(sender, generateOnePerCustomer);
            PXUIFieldAttribute.SetRequired <ARPPDCreditMemoParameters.finPeriodID>(sender, generateOnePerCustomer);
        }
Пример #5
0
        private static ARInvoice CreatePPDCreditMemo(ARInvoiceEntry ie, ARPPDCreditMemoParameters filter, List <PendingPPDCreditMemoApp> list)
        {
            int       index = 0;
            ARInvoice invoice;

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

                invoice = ie.CreatePPDCreditMemo(filter, list, ref index);

                PXProcessing <PendingPPDCreditMemoApp> .SetInfo(index, ActionsMessages.RecordProcessed);
            }
            catch (Exception e)
            {
                PXProcessing <PendingPPDCreditMemoApp> .SetError(index, e);

                invoice = null;
            }

            return(invoice);
        }
Пример #6
0
        public static void CreatePPDCreditMemos(PXCache cache, ARPPDCreditMemoParameters filter, ARSetup setup, List <PendingPPDCreditMemoApp> docs)
        {
            int  i      = 0;
            bool failed = false;

            List <ARRegister> toRelease = new List <ARRegister>();
            ARInvoiceEntry    ie        = PXGraph.CreateInstance <ARInvoiceEntry>();

            ie.ARSetup.Current = setup;

            if (filter.GenerateOnePerCustomer == true)
            {
                if (filter.CreditMemoDate == null)
                {
                    throw new PXSetPropertyException(CR.Messages.EmptyValueErrorFormat,
                                                     PXUIFieldAttribute.GetDisplayName <ARPPDCreditMemoParameters.creditMemoDate>(cache));
                }

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

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

                    PPDCreditMemoKey key = new PPDCreditMemoKey();
                    doc.Index              = i++;
                    key.BranchID           = doc.AdjdBranchID;
                    key.CustomerID         = doc.AdjdCustomerID;
                    key.CustomerLocationID = doc.InvCustomerLocationID;
                    key.CuryID             = info.CuryID;
                    key.CuryRate           = info.CuryRate;
                    key.ARAccountID        = doc.AdjdARAcct;
                    key.ARSubID            = doc.AdjdARSub;
                    key.TaxZoneID          = doc.InvTaxZoneID;

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

                    list.Add(doc);
                }

                foreach (List <PendingPPDCreditMemoApp> list in dict.Values)
                {
                    ARInvoice invoice = CreatePPDCreditMemo(ie, filter, list);
                    if (invoice != null)
                    {
                        toRelease.Add(invoice);
                    }
                    else
                    {
                        failed = true;
                    }
                }
            }
            else
            {
                foreach (PendingPPDCreditMemoApp doc in docs)
                {
                    List <PendingPPDCreditMemoApp> list = new List <PendingPPDCreditMemoApp>(1);
                    doc.Index = i++;
                    list.Add(doc);

                    ARInvoice invoice = CreatePPDCreditMemo(ie, filter, list);
                    if (invoice != null)
                    {
                        toRelease.Add(invoice);
                    }
                    else
                    {
                        failed = true;
                    }
                }
            }

            if (setup.AutoReleasePPDCreditMemo == true && toRelease.Count > 0)
            {
                using (new PXTimeStampScope(null))
                {
                    ARDocumentRelease.ReleaseDoc(toRelease, true);
                }
            }

            if (failed)
            {
                throw new PXException(GL.Messages.DocumentsNotReleased);
            }
        }
Пример #7
0
        private static ARInvoice CreatePPDCreditMemo(ARInvoiceEntry ie, ARPPDCreditMemoParameters filter, ARSetup setup, List <PendingPPDCreditMemoApp> list)
        {
            int       index = 0;
            ARInvoice invoice;

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

                Customer customer = null;
                invoice = (ARInvoice)ie.Document.Cache.CreateInstance();

                bool firstApp = true;
                foreach (PendingPPDCreditMemoApp doc in list)
                {
                    if (firstApp)
                    {
                        firstApp = false;
                        index    = doc.Index;

                        customer = PXSelect <Customer, Where <Customer.bAccountID, Equal <Required <Customer.bAccountID> > > > .Select(ie, doc.AdjdCustomerID);

                        CurrencyInfo info = PXSelect <CurrencyInfo, Where <CurrencyInfo.curyInfoID, Equal <Required <CurrencyInfo.curyInfoID> > > > .Select(ie, doc.InvCuryInfoID);

                        info.CuryInfoID = null;
                        info            = ie.currencyinfo.Insert(info);

                        invoice.DocType     = ARDocType.CreditMemo;
                        invoice.DocDate     = filter.GenerateOnePerCustomer == true ? filter.CreditMemoDate : doc.AdjgDocDate;
                        invoice.FinPeriodID = filter.GenerateOnePerCustomer == true ? filter.FinPeriodID : doc.AdjgFinPeriodID;
                        invoice             = PXCache <ARInvoice> .CreateCopy(ie.Document.Insert(invoice));

                        invoice.CustomerID         = doc.AdjdCustomerID;
                        invoice.CustomerLocationID = doc.InvCustomerLocationID;
                        invoice.CuryInfoID         = info.CuryInfoID;
                        invoice.CuryID             = info.CuryID;
                        invoice.DocDesc            = setup.PPDCreditMemoDescr;
                        invoice.BranchID           = doc.AdjdBranchID;
                        invoice.ARAccountID        = doc.AdjdARAcct;
                        invoice.ARSubID            = doc.AdjdARSub;
                        invoice.TaxZoneID          = doc.InvTaxZoneID;
                        invoice.Hold       = false;
                        invoice.PendingPPD = true;

                        invoice = ie.Document.Update(invoice);

                        invoice.DontPrint = true;
                        invoice.DontEmail = true;
                    }

                    AddTaxesAndApplications(ie, doc, customer, invoice);
                }

                ie.ARDiscountDetails.Select().RowCast <ARInvoiceDiscountDetail>().
                ForEach(discountDetail => ie.ARDiscountDetails.Cache.Delete(discountDetail));

                if (setup.RequireControlTotal == true)
                {
                    invoice.CuryOrigDocAmt = invoice.CuryDocBal;
                    ie.Document.Cache.Update(invoice);
                }

                ie.Save.Press();
                string refNbr = invoice.RefNbr;
                list.ForEach(doc => PXUpdate <Set <ARAdjust.pPDCrMemoRefNbr, Required <ARAdjust.pPDCrMemoRefNbr> >, ARAdjust,
                                              Where <ARAdjust.adjdDocType, Equal <Required <ARAdjust.adjdDocType> >,
                                                     And <ARAdjust.adjdRefNbr, Equal <Required <ARAdjust.adjdRefNbr> >,
                                                          And <ARAdjust.adjgDocType, Equal <Required <ARAdjust.adjgDocType> >,
                                                               And <ARAdjust.adjgRefNbr, Equal <Required <ARAdjust.adjgRefNbr> >,
                                                                    And <ARAdjust.released, Equal <True>,
                                                                         And <ARAdjust.voided, NotEqual <True>,
                                                                              And <ARAdjust.pendingPPD, Equal <True> > > > > > > > >
                             .Update(ie, refNbr, doc.AdjdDocType, doc.AdjdRefNbr, doc.AdjgDocType, doc.AdjgRefNbr));
                PXProcessing <PendingPPDCreditMemoApp> .SetInfo(index, ActionsMessages.RecordProcessed);
            }
            catch (Exception e)
            {
                PXProcessing <PendingPPDCreditMemoApp> .SetError(index, e);

                invoice = null;
            }

            return(invoice);
        }