Page 1 of 1

Get selling price for inventory

PostPosted: Tue Nov 16, 2021 12:33 pm
by SBarnes
How can I in c# get a sell price for an inventory object such as P1 based upon its effective date, i.e. at today's date?

Re: Get selling price for inventory

PostPosted: Fri Nov 26, 2021 12:32 pm
by Mike.Sheen
SBarnes wrote:How can I in c# get a sell price for an inventory object such as P1 based upon its effective date, i.e. at today's date?


The sure-fire lazy method is to use a price scheme - create a disposable price scheme, add the sell price 1 stored proc to it, call the GetPrice method with the InventoryID, DebtorID, WarehouseId and date and quantity, then discard the price scheme without saving it.

Code: Select all
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace GetInventorySellPriceAsAtDate
{
    class Program
    {
        static void Main(string[] args)
        {
            JiwaFinancials.Jiwa.JiwaApplication.Manager manager = new JiwaFinancials.Jiwa.JiwaApplication.Manager();
            manager.Logon("localhost", "JiwaDemo721-3", JiwaFinancials.Jiwa.JiwaODBC.database.AuthenticationModes.JiwaAuthentication, "Admin", "password");

            JiwaFinancials.Jiwa.JiwaPriceSchemes.PriceScheme priceScheme = manager.BusinessLogicFactory.CreateBusinessLogic<JiwaFinancials.Jiwa.JiwaPriceSchemes.PriceScheme>(null);
            priceScheme.CreateNew();
            JiwaFinancials.Jiwa.JiwaPriceSchemes.PriceUsed usedPrice = manager.CollectionItemFactory.CreateCollectionItem<JiwaFinancials.Jiwa.JiwaPriceSchemes.PriceUsed>();
            usedPrice.Price = manager.CollectionItemFactory.CreateCollectionItem<JiwaFinancials.Jiwa.JiwaPriceSchemes.Price>();
            usedPrice.Price.IsStoredProc = true;
            usedPrice.Price.StoredProcName = "usp_Jiwa_Price_SellPrice1";
            priceScheme.PriceUsedCollection.Add(usedPrice);

            JiwaFinancials.Jiwa.JiwaApplication.Entities.Inventory.Inventory inventory = manager.EntityFactory.CreateEntity<JiwaFinancials.Jiwa.JiwaApplication.Entities.Inventory.Inventory>();
            inventory.ReadRecordFromPartNo("1170");

            JiwaFinancials.Jiwa.JiwaApplication.Entities.Debtor.Debtor debtor = manager.EntityFactory.CreateEntity<JiwaFinancials.Jiwa.JiwaApplication.Entities.Debtor.Debtor>();
            debtor.ReadRecordFromAccountNo("1001");

            decimal price = 0;
            bool priceIsIncTax = false;
            priceScheme.GetPrice(JiwaFinancials.Jiwa.JiwaPriceSchemes.PriceScheme.PriceSchemePriceChangeOrigin.e_PriceSchemePriceChangeOriginSalesOrder, null, inventory.InventoryID, debtor.DebtorID, DateTime.Now, "ZZZZZZZZZZ0000000000", 1, ref price, ref priceIsIncTax);

            Console.WriteLine("Price is {0}", price);
        }
    }
}



Or you can just call the stored proc directly.

Re: Get selling price for inventory  Topic is solved

PostPosted: Fri Nov 26, 2021 12:39 pm
by SBarnes
Thanks Mike,

But I wasn't after it for a given debtor, my request was unclear sorry, what I was actually after was

Code: Select all
Inventory.SellingPrices["P1"].get_CurrentPrice(this.get_Manager().SysDateTime);


depending on the decompiler you can get you can get

Code: Select all
Inventory.SellingPrices["P1"][this.get_Manager().SysDateTime];


which won't compile in a plugin.