Simplest way to do this update would be subscribing to GRN save ending event and run SQL command to update IN_Main.DefaultPrice based on GP% and last cost for all inventory items in GRN, if GRN being activated.
Please see code example below. (
** not tested)
- Code: Select all
#region "BusinessLogicPlugin"
using System;
using System.Data.SqlClient;
using System.Linq;
public class BusinessLogicPlugin : System.MarshalByRefObject, JiwaFinancials.Jiwa.JiwaApplication.IJiwaBusinessLogicPlugin
{
public override object InitializeLifetimeService()
{
// returning null here will prevent the lease manager
// from deleting the Object.
return null;
}
public void Setup(JiwaFinancials.Jiwa.JiwaApplication.IJiwaBusinessLogic JiwaBusinessLogic, JiwaFinancials.Jiwa.JiwaApplication.Plugin.Plugin Plugin)
{
if (JiwaBusinessLogic is JiwaFinancials.Jiwa.JiwaInvReceival.Receival)
{
JiwaFinancials.Jiwa.JiwaInvReceival.Receival invReceival = JiwaBusinessLogic as JiwaFinancials.Jiwa.JiwaInvReceival.Receival;
invReceival.SaveEnding += delegate (object sender, EventArgs e)
{
if (invReceival.OriginalStatus == JiwaFinancials.Jiwa.JiwaInvReceival.Receival.Statuses.UnActivated
&& invReceival.Status == JiwaFinancials.Jiwa.JiwaInvReceival.Receival.Statuses.Activated) //GRN being activated
{
if (invReceival.SystemSettings.UpdateLastCost == true) //if last cost being updated
{
string[] inventoryIDs = invReceival.Lines.Cast<JiwaFinancials.Jiwa.JiwaInvReceival.Line>()
.Where(l => l.LineType == JiwaFinancials.Jiwa.JiwaInvReceival.Line.ReceivalLineType.Inventory)
.Select(l => l.InventoryID)
.ToArray();
if (inventoryIDs != null && inventoryIDs.Any())
{
string updatePriceSQLCommand = @"UPDATE
IN_Main
SET
DefaultPrice = LCost / (( 100.0 - 25.0 /*gp % = 25*/) / 100.0)
WHERE
InventoryID IN ({0})";
updatePriceSQLCommand = string.Format(updatePriceSQLCommand, string.Join(",", inventoryIDs.Select(invId => string.Format("'{0}'", invId))));
var database = invReceival.Manager.Database;
using (SqlCommand sqlCommand = new SqlCommand(updatePriceSQLCommand, database.SQLConnection, database.SQLTransaction))
{
sqlCommand.ExecuteNonQuery();
}
}
}
}
};
}
}
}
#endregion