How to adjust inventory quantities programmatically by using the Small Business Accounting Software Development Kit together with the IInventoryAdjustment interface (920193)



The information in this article applies to:

  • Microsoft Office Small Business Accounting 2006
  • Microsoft Office Small Business Accounting 2006 Software Development Kit 1.2
  • Microsoft Office Small Business Management Edition 2006

INTRODUCTION

Microsoft Small Business Accounting lets users adjust inventory quantities. You can adjust inventory quantities programmatically by using the Small Business Accounting Software Development Kit (SDK) together with the IInventoryAdjustment interface.

MORE INFORMATION

The following code creates one inventory adjustment that decreases quantities for two items in the Northwind Traders company.

Note Northwind Traders is the fictitious company that is used for demonstration in Small Business Accounting.

Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements.
ISmallBusinessInstance iSbi = // The iSbi variable is instantiated here.

IFinancialAccount ifa = (IFinancialAccount) GetAccountByName(iSbi.FinancialAccounts, "Other Expenses");

IInventoryAdjustment ia = iSbi.CreateInventoryAdjustment();
ia.FinancialDateTime = DateTime.Now.AddDays(2);
ia.FinancialAccount = ifa;

// The following line retrieves the first item for which you want to adjust the quantity.
IInventoryItemAccount item1 = (IInventoryItemAccount) GetAccountByName(iSbi.ItemAccounts, "Hockey Stick");

// The following line creates an array of adjustment lines that has two elements.
IInventoryAdjustmentLine[] lines = new IInventoryAdjustmentLine[2];

lines[0] = ia.CreateInventoryAdjustmentLine();
lines[0].InventoryItemAccount = item1;
lines[0].AdjustedQuantity = -3;

// The following line retrieves the second item for which you want to adjust the quantity.
IInventoryItemAccount item2 = (IInventoryItemAccount) GetAccountByName(iSbi.ItemAccounts, "Hook");

lines[1] = ia.CreateInventoryAdjustmentLine();
lines[1].InventoryItemAccount = item2;
lines[1].AdjustedQuantity = -1;

// Persist the inventory adjustment to the database.
ia.Save();


static IAccount GetAccountByName(IBaseMasterView view, string acctName)
{
	IAccount account = null;
	DataRow row = null;

	if (view != null)
	{
		DataView dv = view.DataView;

		// Verify that there is a Name column, or a run-time exception occurs.
		if (dv.Table.Columns.Contains("Name"))
		{
			dv.RowFilter = String.Format("Name='{0}'", acctName);
		}
		// The IJobAccount does not have a Name column. Therefore, you must search by using JobName.
		else if (dv.Table.Columns.Contains("JobName"))
		{
			dv.RowFilter = String.Format("JobName='{0}'", acctName);
		}
		
		// Verify that there is a ModifiedDateTime column, or a run-time exception occurs.
		if (dv.Table.Columns.Contains("ModifiedDateTime"))
		{
			dv.Sort = "ModifiedDateTime DESC";
		}
    
		// If there is more than one row, obtain the first row.
		if (dv.Count > 0)
		{
			row = dv[0].Row;
		}
	}

	if (row != null)
	{
		account = (IAccount) view.GetByDataRow(row);
	}

	return account;
}

Modification Type:MajorLast Reviewed:7/12/2006
Keywords:kbExpertiseAdvanced kbhowto KB920193 kbAudDeveloper