Page 1 of 1

Automatically choose "No" at "Princing Details" Dialog

PostPosted: Mon Sep 21, 2015 4:50 pm
by marcosomizu
Hi,

When make a Sales Order through a Quote Entry, a "Pricing Details" dialog appears asking: "Prices to be updated with current pricing details?".

I would prefer not to show this dialog and automatically choose "No".

How do I do this?

Cheers,
Marcos Omizu

Re: Automatically choose "No" at "Princing Details" Dialog  Topic is solved

PostPosted: Tue Oct 20, 2015 2:47 pm
by Scott.Pearce
This is not currently possible. I've logged enhancement request 12164 to accommodate your requirements.

Re: Automatically choose "No" at "Princing Details" Dialog

PostPosted: Fri Dec 04, 2015 5:23 pm
by marcosomizu
Hi Scott,

I have another question that may be similar with this one.

Is there a way to access the "Use Alternate Stock" dialog in the Sales Order programmatically?

Currently, Jiwa opens this dialog if you have an alternate stock set to an item and your Stock on Hand is zero. A client wants to open this dialog if you have an alternate stock set, no matter if your Stock on Hand is zero or not.

Any suggestions?

Cheers

Re: Automatically choose "No" at "Princing Details" Dialog

PostPosted: Mon Dec 07, 2015 8:40 am
by Scott.Pearce
The code currently does this when adding an inventory item:

Code: Select all
If SalesOrder.SalesOrderLines(NewKey).PhysicalItem AndAlso SalesOrder.SalesOrderLines(NewKey).QuantitySOHAvailable <= 0 AndAlso SalesOrder.OrderType <> JiwaSales.SalesOrder.SalesOrder.SalesOrderOrderTypes.e_SalesOrderOrderTypeForwardOrder Then
   If MsgBox("This item has no available stock. Look for alternatives?", MsgBoxStyle.Question + MsgBoxStyle.YesNo, "Use Alternate Stock") = MsgBoxResult.Yes Then
      InventoryID = SalesOrder.SalesOrderLines(NewKey).InventoryID
      PartNo = SalesOrder.SalesOrderLines(NewKey).PartNo
      Description = SalesOrder.SalesOrderLines(NewKey).Description
      ' Remove Item
      SalesOrder.SalesOrderLines.Remove(SalesOrder.SalesOrderLines(NewKey))

      ' Do Alternate Search
      DoAlternateInventorySearch(InventoryID, PartNo, Description)
      ' Add Alternate
      SalesOrder.SalesOrderLines.AddInventoryItem(JiwaApplication.Manager.Instance.Search.Result(1).Fields.Item(1).FieldValue, JiwaSales.SalesOrder.SalesOrderLineCollection.SalesOrderLineInventorySeedTypes.e_SalesOrderLineInventoryID, NewKey, , Row + 1)
      NewLineKey = NewKey
   End If
End If


Look at the first line, it checks for no stock:

Code: Select all
 SalesOrder.SalesOrderLines(NewKey).QuantitySOHAvailable <= 0


So, what you could do, is hook into the SalesOrder.SalesOrderLines.AddInventoryItemEnd event and perform a similar check to catch those items that have alternative stock set but *do* have stock on hand:

Code: Select all
If SalesOrder.SalesOrderLines(NewKey).PhysicalItem AndAlso SalesOrder.SalesOrderLines(NewKey).QuantitySOHAvailable > 0 AndAlso SalesOrder.OrderType <> JiwaSales.SalesOrder.SalesOrder.SalesOrderOrderTypes.e_SalesOrderOrderTypeForwardOrder Then


Here is the event signature of the event you need to hook into (it comes from the SalesOrderLinesCollection class):

Code: Select all
Public Event AddInventoryItemEnd(ByVal Item As SalesOrderLine)


You can then perform the same operation. Here is the chunk of code all together:

Code: Select all
If Item.PhysicalItem AndAlso Item.QuantitySOHAvailable > 0 AndAlso Item.SalesOrderLines.SalesOrder.OrderType <> JiwaSales.SalesOrder.SalesOrder.SalesOrderOrderTypes.e_SalesOrderOrderTypeForwardOrder Then
   If MsgBox("This item has no available stock. Look for alternatives?", MsgBoxStyle.Question + MsgBoxStyle.YesNo, "Use Alternate Stock") = MsgBoxResult.Yes Then
      InventoryID = Item.InventoryID
      PartNo = Item.PartNo
      Description = Item.Description
      ' Remove Item
      Item.SalesOrderLines.Remove(Item)

      ' Do Alternate Search
      DoAlternateInventorySearch(InventoryID, PartNo, Description)
      ' Add Alternate
      Item.SalesOrderLines.AddInventoryItem(JiwaApplication.Manager.Instance.Search.Result(1).Fields.Item(1).FieldValue, JiwaSales.SalesOrder.SalesOrderLineCollection.SalesOrderLineInventorySeedTypes.e_SalesOrderLineInventoryID, NewKey, , Row + 1)
      NewLineKey = NewKey
   End If
End If


This is off-the-top-of-my-head untested type code. Let me know if you have any problems piecing it all together.

Re: Automatically choose "No" at "Princing Details" Dialog

PostPosted: Mon Dec 07, 2015 1:41 pm
by marcosomizu
Thank you Scott!

Just one question. What DoAlternateInventorySearch would be?

Is it a native method? I couldn't find it.

Cheers

Re: Automatically choose "No" at "Princing Details" Dialog

PostPosted: Mon Dec 07, 2015 4:00 pm
by Scott.Pearce
It's a public method on the the sales order form. If you have the business logic object, you can get to the form thus:

Code: Select all
Dim salesOrderForm as JiwaSalesUI.SalesOrder.BaseSalesOrderEntryForm = SalesOrder.Client

Re: Automatically choose "No" at "Princing Details" Dialog

PostPosted: Thu Dec 10, 2015 6:33 pm
by marcosomizu
Scott,

I was not able to make it work. I am using this code (below) and I keep receiving a "Object reference not set to an instance of an object" error message in the AddInventoryItem Module.

Could you help me?

Code: Select all
   private void salesOrder_SalesOrderLines_AddInventoryItemEnd(JiwaFinancials.Jiwa.JiwaSales.SalesOrder.SalesOrderLine item)
   {   
      JiwaFinancials.Jiwa.JiwaSales.SalesOrder.SalesOrder salesOrder = (JiwaFinancials.Jiwa.JiwaSales.SalesOrder.SalesOrder)item.SalesOrderLines.SalesOrder;
      JiwaFinancials.Jiwa.JiwaApplication.BusinessLogic.GenericObjectItem genericItem = (JiwaFinancials.Jiwa.JiwaApplication.BusinessLogic.GenericObjectItem)salesOrder.GenericObjectCollection["SalesOrderForm"];
      JiwaFinancials.Jiwa.JiwaSalesUI.SalesOrder.SalesOrderEntryForm form = (JiwaFinancials.Jiwa.JiwaSalesUI.SalesOrder.SalesOrderEntryForm)genericItem.Object;
      
      if (item.PhysicalItem && item.AlternatesAvailable && item.SalesOrderLines.SalesOrder.OrderType != JiwaFinancials.Jiwa.JiwaSales.SalesOrder.SalesOrder.SalesOrderOrderTypes.e_SalesOrderOrderTypeForwardOrder)
      {
         if (MessageBox.Show("This item has Alternate Stock. Do you want to use it?", "Use Alternate Stock", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
         {
            string inventoryID = item.InventoryID;
            string partNo = item.PartNo;
            string description = item.Description;
            int row = item.ItemNo;
            object newKey = new Object();
            newKey = item.KeyField;
            
            form.DoAlternateInventorySearch(inventoryID, partNo, description, form);
            
            JiwaFinancials.Jiwa.JiwaApplication.JiwaSearch.Field field = JiwaFinancials.Jiwa.JiwaApplication.Manager.Instance.Search.Result(1).Fields[1];
            
            if (field != null)
            {
               form.SalesOrder.SalesOrderLines.AddInventoryItem(field.FieldValue.ToString(), JiwaFinancials.Jiwa.JiwaSales.SalesOrder.SalesOrderLineCollection.SalesOrderLineInventorySeedTypes.e_SalesOrderLineInventoryID, ref newKey, null, row + 1);
            }
            
            salesOrder.SalesOrderLines.Remove(item);
         }
      }
   }

Re: Automatically choose "No" at "Princing Details" Dialog

PostPosted: Fri Dec 11, 2015 8:23 am
by Scott.Pearce
Well, first of all, I get the error:

Error : Object reference not set to an instance of an object.
Module : salesOrder_SalesOrderLines_AddInventoryItemEnd

This was because salesOrder.GenericObjectCollection["SalesOrderForm"] was null, but perhaps that is because I don't have the rest of your code. I removed the lines:

Code: Select all
JiwaFinancials.Jiwa.JiwaApplication.BusinessLogic.GenericObjectItem genericItem = (JiwaFinancials.Jiwa.JiwaApplication.BusinessLogic.GenericObjectItem)salesOrder.GenericObjectCollection["SalesOrderForm"];
JiwaFinancials.Jiwa.JiwaSalesUI.SalesOrder.SalesOrderEntryForm form = (JiwaFinancials.Jiwa.JiwaSalesUI.SalesOrder.SalesOrderEntryForm)genericItem.Object;


and in their place used:

Code: Select all
JiwaFinancials.Jiwa.JiwaSalesUI.SalesOrder.SalesOrderEntryForm form = (JiwaFinancials.Jiwa.JiwaSalesUI.SalesOrder.SalesOrderEntryForm) salesOrder.Client;


This got me a little further, but then another error:

Error : Object reference not set to an instance of an object.
Module : AddInventoryItem

This is the error message you are getting. I had to trace through our source code to work this one out. It's a problem with the order of events firing. Here is what is happening:

1. You type a part no into the grid. This causes salesOrderForm.AddInventoryItem to be called.
2. salesOrderForm.AddInventoryItem does some checks, then calls SalesOrder.SalesOrderLines.AddInventoryItem.
3. SalesOrder.SalesOrderLines.AddInventoryItem adds the line and raises the AddInventoryItemEnd event (which is what you hook into).
4. Your code does it's thing, including possibly removing the sales order line (because you used an alternate in its place)
5. Control returns to salesOrderForm.AddInventoryItem, where it attempts to do some further checks on the new line WHICH NO LONGER EXISTS BECAUSE IT WAS REMOVED AT STEP 4!!

I'm messing around to try and deal with this in the plugin and will post back here soon.

Re: Automatically choose "No" at "Princing Details" Dialog

PostPosted: Fri Dec 11, 2015 8:43 am
by Scott.Pearce
OK, I've got a solution. After the line:

Code: Select all
salesOrder.SalesOrderLines.Remove(item);


add the line:

Code: Select all
throw new JiwaFinancials.Jiwa.JiwaApplication.Exceptions.ClientCancelledException();


That will stop salesOrderForm.AddInventoryItem from continuing on (which we want to stop because we ended up using an alternate part anyway).

I also notice that you will get an ugly error if you choose to cancel the alternate search screen. This can be avoided by changing the lines:

Code: Select all
JiwaFinancials.Jiwa.JiwaApplication.JiwaSearch.Field field = JiwaFinancials.Jiwa.JiwaApplication.Manager.Instance.Search.Result(1).Fields[1];
           
if (field != null)
{
  form.SalesOrder.SalesOrderLines.AddInventoryItem(field.FieldValue.ToString(), JiwaFinancials.Jiwa.JiwaSales.SalesOrder.SalesOrderLineCollection.SalesOrderLineInventorySeedTypes.e_SalesOrderLineInventoryID, ref newKey, null, row + 1);
}
           
salesOrder.SalesOrderLines.Remove(item);


to:

Code: Select all
JiwaFinancials.Jiwa.JiwaApplication.JiwaSearch.Field field = null;
if (JiwaFinancials.Jiwa.JiwaApplication.Manager.Instance.Search.Results.Count > 0)
  field = JiwaFinancials.Jiwa.JiwaApplication.Manager.Instance.Search.Result(1).Fields[1];

if (field != null)
{
  form.SalesOrder.SalesOrderLines.AddInventoryItem(field.FieldValue.ToString(), JiwaFinancials.Jiwa.JiwaSales.SalesOrder.SalesOrderLineCollection.SalesOrderLineInventorySeedTypes.e_SalesOrderLineInventoryID, ref newKey, null, row + 1);
  salesOrder.SalesOrderLines.Remove(item);
  throw new JiwaFinancials.Jiwa.JiwaApplication.Exceptions.ClientCancelledException();            
}


I've attached the modified plugin.