Skip to main content
Solved

Last Ordered Date For Stock Items


Helo,

     Im a newbie to acumatica. I want to add last ordered date field for each stock item. So,whenever a new order arrives i want to update last ordered date of that ordered item. How could i do that? please reply asap….

Best answer by Naveen Boga

Hi @sandy95 ,

 

I wrote a sample example code just now, where I’m updating LastOrderedDate in the Stock Items screen for the particular SKUs.

Please modify according to your DAC field names.

 public class SOOrderEntryExt : PXGraphExtension<SOOrderEntry>
        {

            public delegate void PersistDelegate();
            [PXOverride]
            public void Persist(PersistDelegate del)
            {

                #region Check Del
                try
                {
                    if (Base.Document.Current != null)
                    {
                        if (Base.Document.Cache != null && Base.Document.Cache.GetStatus((object)Base.Document.Current) == PXEntryStatus.Inserted)
                        {
                            InventoryItemMaint itemMaint = PXGraph.CreateInstance<InventoryItemMaint>();

                            foreach (SOLine objSOLine in Base.Transactions.Select())
                            {
                                InventoryItem objInventoryItem = PXSelect<InventoryItem, Where<InventoryItem.inventoryID, Equal<Required<InventoryItem.inventoryID>>>>.Select(Base, objSOLine.InventoryID);
                                if (objInventoryItem != null)
                                {
                                    InventoryItemExt itemExt = objInventoryItem.GetExtension<InventoryItemExt>();
                                    itemExt.LastOrderedDate = Base.Document.Current?.OrderDate;
                                    itemMaint.Item.Cache.Update(objInventoryItem);
                                }
                            }
                            itemMaint.Actions.PressSave();
                        }

                        del();
                    }
                }
                catch (Exception ex)
                {
                    throw new PXException(ex.Message);
                }
            }
        }

 

Hope this helps!!

View original
Did this topic help you find an answer to your question?

8 replies

Gabriel Michaud
Captain II
Forum|alt.badge.img+10

Hi @sandy95,

Where do you want to see the last ordered date? Also, are you talking about a Sales Order or a Purchase Order? It sounds like you’re talking about Sales Order from a customer, but just want to be sure.

 


Naveen Boga
Captain II
Forum|alt.badge.img+19
  • Captain II
  • 3377 replies
  • March 15, 2021

Hi @sandy95,

I’m assuming that below is your requirement.

In the Stock Item screen, you have added a new customization field and you want to show the Last Ordered Date of that SKU in that field.  

 

If this is your requirement, then yes, it more of customization, and below are the steps.

 

You need to extend the SOOrderEntry graph and add a logic to update the “LastOrderedDate” in the Stock Item screen of the 1st Save of the Sales Order (Persist Delegate).

 

Hope this helps!!


  • Author
  • Freshman I
  • 4 replies
  • March 16, 2021
Naveen B wrote:

Hi @sandy95,

I’m assuming that below is your requirement.

In the Stock Item screen, you have added a new customization field and you want to show the Last Ordered Date of that SKU in that field.  

 

If this is your requirement, then yes, it more of customization, and below are the steps.

 

You need to extend the SOOrderEntry graph and add a logic to update the “LastOrderedDate” in the Stock Item screen of the 1st Save of the Sales Order (Persist Delegate).

 

Hope this helps!!

 

hi,

Yes exactly i want the way you defined. I already added LastOrderedDate field in Stock Item Screen. And about to extend SOOrderEntry graph but didn’t understand how to save that field . Please Reply. Thanks in advance.


Naveen Boga
Captain II
Forum|alt.badge.img+19
  • Captain II
  • 3377 replies
  • Answer
  • March 16, 2021

Hi @sandy95 ,

 

I wrote a sample example code just now, where I’m updating LastOrderedDate in the Stock Items screen for the particular SKUs.

Please modify according to your DAC field names.

 public class SOOrderEntryExt : PXGraphExtension<SOOrderEntry>
        {

            public delegate void PersistDelegate();
            [PXOverride]
            public void Persist(PersistDelegate del)
            {

                #region Check Del
                try
                {
                    if (Base.Document.Current != null)
                    {
                        if (Base.Document.Cache != null && Base.Document.Cache.GetStatus((object)Base.Document.Current) == PXEntryStatus.Inserted)
                        {
                            InventoryItemMaint itemMaint = PXGraph.CreateInstance<InventoryItemMaint>();

                            foreach (SOLine objSOLine in Base.Transactions.Select())
                            {
                                InventoryItem objInventoryItem = PXSelect<InventoryItem, Where<InventoryItem.inventoryID, Equal<Required<InventoryItem.inventoryID>>>>.Select(Base, objSOLine.InventoryID);
                                if (objInventoryItem != null)
                                {
                                    InventoryItemExt itemExt = objInventoryItem.GetExtension<InventoryItemExt>();
                                    itemExt.LastOrderedDate = Base.Document.Current?.OrderDate;
                                    itemMaint.Item.Cache.Update(objInventoryItem);
                                }
                            }
                            itemMaint.Actions.PressSave();
                        }

                        del();
                    }
                }
                catch (Exception ex)
                {
                    throw new PXException(ex.Message);
                }
            }
        }

 

Hope this helps!!


  • Author
  • Freshman I
  • 4 replies
  • March 17, 2021
Naveen B wrote:

Hi @sandy95 ,

 

I wrote a sample example code just now, where I’m updating LastOrderedDate in the Stock Items screen for the particular SKUs.

Please modify according to your DAC field names.

 public class SOOrderEntryExt : PXGraphExtension<SOOrderEntry>
        {

            public delegate void PersistDelegate();
            [PXOverride]
            public void Persist(PersistDelegate del)
            {

                #region Check Del
                try
                {
                    if (Base.Document.Current != null)
                    {
                        if (Base.Document.Cache != null && Base.Document.Cache.GetStatus((object)Base.Document.Current) == PXEntryStatus.Inserted)
                        {
                            InventoryItemMaint itemMaint = PXGraph.CreateInstance<InventoryItemMaint>();

                            foreach (SOLine objSOLine in Base.Transactions.Select())
                            {
                                InventoryItem objInventoryItem = PXSelect<InventoryItem, Where<InventoryItem.inventoryID, Equal<Required<InventoryItem.inventoryID>>>>.Select(Base, objSOLine.InventoryID);
                                if (objInventoryItem != null)
                                {
                                    InventoryItemExt itemExt = objInventoryItem.GetExtension<InventoryItemExt>();
                                    itemExt.LastOrderedDate = Base.Document.Current?.OrderDate;
                                    itemMaint.Item.Cache.Update(objInventoryItem);
                                }
                            }
                            itemMaint.Actions.PressSave();
                        }

                        del();
                    }
                }
                catch (Exception ex)
                {
                    throw new PXException(ex.Message);
                }
            }
        }

 

Hope this helps!!

 


Thanks @Naveen B ,

       It works.. :)

 


Naveen Boga
Captain II
Forum|alt.badge.img+19
  • Captain II
  • 3377 replies
  • March 17, 2021

@sandy95 That’s great :) Now, I hope you clear with the cache updates.


  • Author
  • Freshman I
  • 4 replies
  • March 27, 2021

How to update all existing orders last updated date for stock items?


Naveen Boga
Captain II
Forum|alt.badge.img+19
  • Captain II
  • 3377 replies
  • March 27, 2021

Create an updated SQL script to update the LastOrderDate in the Stock Items screen. This is a one-time activity and for the new orders, your customization will take care of.


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings