Access Stock Tutorial
Posted on November 3, 2014 | By Mohd Imran
Contents
Introduction
In this part of the tutorial, you will learn about accessing a Stock document via code.
In the first part of the tutorial, an example on how to programmatically add, edit and delete a Stock Item will be shown while in the second part of the tutorial, an example on how to programmatically add, edit and delete a Stock Issue document will be shown. Note: For all the property table, the red entries are compulsory property
Accessing Stock Item
Similarly to previous tutorials, we begin with creating an object that works as the data access bridge between the database with the data we wish to add, edit or delete. For Stock Item this bridge is the ItemDataAccess class.
- BCE.AutoCount.Stock.Item.ItemDataAccess cmd = BCE.AutoCount.Stock.Item.ItemDataAccess.Create(myDBSetting);
After creating the object acting as the bridge, you may call the specific methods you need to create, edit or delete a Stock Item.
Action | Method Name |
---|---|
Add | NewItem |
Edit | LoadItem |
Delete | Delete |
The following examples illustrates how to use the above methods to do each specific task:
Add Stock Item
- public void AddItem()
- {
- BCE.AutoCount.Stock.Item.ItemDataAccess cmd = BCE.AutoCount.Stock.Item.ItemDataAccess.Create(myDBSetting);
- BCE.AutoCount.Stock.Item.ItemEntity doc = cmd.NewItem();
- doc.ItemCode = “1234″;
- doc.Description = “item 1234″;
- doc.BaseUomRecord.Uom = “PCS”;
- doc.BaseUomRecord.StandardCost = 10;
- doc.BaseUomRecord.StandardSellingPrice = 5;
- // To add new Uom, refer to code below
- BCE.AutoCount.Stock.Item.ItemUomEntity uom = doc.NewUom(12);
- uom.Uom = “BOX”;
- uom.StandardSellingPrice = 120;
- uom.StandardCost = 60;
- // To access to any Uom, refer to code below.
- BCE.AutoCount.Stock.Item.ItemUomEntity[] uoms = doc.GetUomByRate(12);
- if (uoms != null && uoms.Length > 0)
- {
- uoms[0].BarCode = “123123″;
- }
- bool isSuccessRecalculate = false;
- cmd.SaveData(doc, ref isSuccessRecalculate);
- }
Edit Stock Item
- public void EditItem()
- {
- BCE.AutoCount.Stock.Item.ItemDataAccess cmd = BCE.AutoCount.Stock.Item.ItemDataAccess.Create(myDBSetting);
- BCE.AutoCount.Stock.Item.ItemEntity doc = cmd.LoadItem(“1234″, BCE.AutoCount.Stock.Item.ItemEntryAction.Edit);
- doc.Description = “special modified item”;
- BCE.AutoCount.Stock.Item.ItemUomEntity uom = doc.NewUom(24);
- uom.Uom = “CARTON”;
- uom.StandardSellingPrice = 220;
- uom.StandardCost = 110;
- bool isSuccessRecalculate = false;
- cmd.SaveData(doc, ref isSuccessRecalculate);
- }
Delete Stock Item
- public void DeleteItem()
- {
- BCE.AutoCount.Stock.Item.ItemDataAccess cmd = BCE.AutoCount.Stock.Item.ItemDataAccess.Create(myDBSetting);
- cmd.Delete(“1234″);
- }
Item Class Properties
ItemEntity Properties
Field Name | Type(Length) | Read-only | Description |
---|---|---|---|
AllowDuplicateItemCode | boolean | The status flag to allow duplicate item code | |
AssemblyCost | decimal(18,8) | The assembly cost assign to this entity | |
BackOrderControl | boolean | The status flag to show that the entity is under back order control | |
BaseUOM | string(8) | The base UOM assign to this entity | |
BaseUOMRecord | BCE.AutoCount.Stock.Item.ItemUomEntity | √ | Returns the base UOM record |
CostingMethod | int | Enter either of the following: 0 - Fixed Cost, 1 - Weighted Average, 2 - FIFO, 3 - LIFO, 4 - Most Recently |
|
CreatedTimeStamp | DateTime | √ | Returns the creation time of this entity |
CreatedUserID | string(10) | √ | Returns the entity creator user id |
Data | DataSet | Returns the DataSet object of this entity | |
DefaultUom | BCE.AutoCount.Stock.Item.ItemUomEntity | √ | Returns the default UOM record |
Desc2 | string(100) | The secondary description assign to this entity | |
Description | string(100) | The description assign to this entity | |
DisableMissingDetailUomChecking | boolean | Disable the "missing detail UOM" checking | |
DisableRateOneChecking | boolean | Disable the "item must have at least Rate 1 UOM and BaseUOM is Rate 1" checking | |
DisableUomExistedChecking | boolean | Disable the "UOM column at item table value must exist at ItemUOM table" checking | |
Discountinued | boolean | The status flag to show that the entity has been discountinued | |
DocKey | long | √ | Returns the document key of this entity |
DutyRate | decimal(18,6) | The duty rate assign to this entity | |
ExternalLink | string | The external link assign to this entity | |
FurtherDescription | string | The further description assign to this detail | |
HasBatchNo | boolean | The status flag to show the entity has batch no | |
HasSerialNo | boolean | The status flag to show the entity has serial no | |
ImageFileName | string(120) | The image file name assign to the entity | |
IsActive | boolean | The status flag to show the entity is active | |
IsCalcBonusPoint | boolean | The status flag that entity uses calculate bonus point | |
ItemBatchTable | DataTable | The Item Batch data table assign to the entity | |
ItemCode | string(30) | The Item Code assign to the entity | |
ItemEntryAction | BCE.AutoCount.Stock.Item.ItemEntryAction | The Item Entry Action assign to the entity | |
ItemGroup | string(8) | The Item Group assign to the entity | |
ItemReplacementTable | DataTable | The Item Replacement data table assign to the entity | |
ItemSubCodeTable | DataTable | The Item SubCode data table assign to the entity | |
ItemTable | DataTable | The Item data table assign to the entity | |
ItemType | string(12) | The Item Type assign to the entity | |
ItemUomTable | DataTable | The Item UOM data table assign to the entity | |
LastModified | DateTime | √ | Returns the last modified time |
LastModifiedUserID | string(10) | √ | Returns the user id of the last modification |
LastUpdate | int | √ | Returns the number of update |
LeadTime | string(40) | The lead time assign to this document | |
Note | string | The notes assign to this document | |
POSPricePlanTable | DataTable | The POS Price Plan data table assign to the entity | |
PuchaseTaxType | string(14) | The Purchase Tax Type assign to the entity | |
PurchaseUom | string(8) | The Purchase UOM assign to the entity | |
ReportUom | string(8) | The Report UOM assign to the entity | |
SalesUom | string(8) | The Sales UOM assign to the entity | |
ScriptObject | BCE.AutoCount.Scripting.ScriptObject | √ | Returns the ScriptObject of this document |
ShowRecalculateStockCostingProgressWindow | boolean | The status flag to show the recalculate stock costing progress window | |
SNFormatName | string(20) | The serial number format name assign to the entity | |
StockControl | boolean | The status flag to show that the entity is under stock control | |
TaxType | string(14) | The tax type assign to the entity | |
UDF | BCE.AutoCount.Data.UDFRecord | √ | Returns the UDF accessor |
UomCount | int | √ | Returns the UOM count of this entity |
ItemUomEntity Properties
Field Name | Type(Length) | Read-only | Description |
---|---|---|---|
BalQty | decimal(18,6) | √ | Returns the balance qty |
BarCode | string(30) | The barcode assign to the entity | |
BonusPoint | decimal(19,2) | The bonus point assign to the entity | |
BonusPointQty | decimal(18,6) | The bonus point qty assign to the entity | |
CSGNQty | decimal(18,6) | √ | Returns the consignment qty |
FOCLevel | decimal(18,6) | The FOC level assign to the entity | |
FOCQty | decimal(18,6) | The FOC Qty assign to the entity | |
ItemCode | string(30) | √ | Returns the item code |
LastUpdate | int | √ | Returns the number of update |
MaxPurchasePrice | decimal(18,6) | The maximum purchase price assign to the entity | |
MaxQty | decimal(18,6) | The maximum qty assign to the entity | |
MaxSalePrice | decimal(18,6) | The maximum sale price assign to the entity | |
MinPurchasePrice | decimal(18,6) | The minimum purchase price assign to the entity | |
MinQty | decimal(18,6) | The minimum qty assign to the entity | |
MinSalePrice | decimal(18,6) | The minimum sale price assign to the entity | |
MostRecentlyCost | decimal(18,8) | The most recently cost assign to the entity | |
NormalLevel | decimal(18,6) | The normal level qty assign to the entity | |
Rate | decimal(18,6) | The rate assign to the entity | |
RealCost | decimal(18,8) | The real cost assign to the entity | |
RedeemBonusPoint | int | The redeem bonus point assign to the entity | |
ReOLevel | decimal(18,6) | The reorder level assign to the entity | |
ReOQty | decimal(18,6) | The reorder qty assign to the entity | |
Shelf | string(20) | The shelf assign to the entity | |
StandardCost | decimal(18,8) | The standard cost assign to the entity | |
StandardSellingPrice | decimal(18,6) | The standard selling price assign to the entity | |
StandardSellingPrice2 | decimal(18,6) | The standard selling price 2 assign to the entity | |
UDF | BCE.AutoCount.Data.UDFRecord | √ | Returns the UDF accessor |
Uom | string(8) | The UOM assign to the entity | |
Volume | decimal(18,6) | The volume assign to the entity | |
VolumeUOM | string(8) | The volume UOM assign to the entity | |
Weight | decimal(18,6) | The weight assign to the entity | |
WeightUOM | string(8) | The weight UOM assign to the entity |
ItemBatchEntity Properties
Field Name | Type(Length) | Read-only | Description |
---|---|---|---|
BalQty | decimal(18,6) | √ | Returns the balance quantity |
BatchNo | string(20) | The batch number assign to this entity | |
Description | string(40) | The description assign to this entity | |
ExpiryDate | DateTime | The expiry date assign to this entity | |
ItemCode | string(30) | The item code assign to this entity | |
LastSaleDate | DateTime | The last sale date assign to this entity | |
ManufacturedDate | DateTime | The manufactured date assign to this entity |
ItemReplacementEntity Properties
Field Name | Type(Length) | Read-only | Description |
---|---|---|---|
ItemCode | string(30) | √ | Returns the Item Code assign to this entity |
Note | string | The notes assign to this entity | |
ReplacementDegree | decimal(18,6) | The replacement degree assign to this entity | |
ReplacementItemCode | string(30) | The replacement item code assign to this entity |
ItemSubCodeEntity Properties
Field Name | Type(Length) | Read-only | Description |
---|---|---|---|
ItemCode | string(30) | √ | Returns the Item Code assign to this entity |
SubCode | string(30) | The sub code assign to this entity |
Accessing Stock Documents
As previously mentioned, the following examples will use the Stock Issue document to illustrate how to access a Stock Document programmatically to do the 3 basic functions.
Similarly to previous tutorials, we begin with creating an object that works as the data access bridge between the database with the data we wish to add, edit or delete. For Stock Issue this bridge is the StockIssueCommand class.
- BCE.AutoCount.Stock.StockIssue.StockIssueCommand cmd = BCE.AutoCount.Stock.StockIssue.StockIssueCommand.Create(myDBSetting);
After creating the object acting as the bridge, you may call the specific methods you need to create, edit or delete a Stock Issue document.
Action | Method Name |
---|---|
Add | AddNew |
Edit | Edit |
Delete | Delete |
The following examples illustrates how to use the above methods to do each specific task:
Add Stock Issue
- public void AddStockIssue()
- {
- BCE.AutoCount.Stock.StockIssue.StockIssueCommand cmd = BCE.AutoCount.Stock.StockIssue.StockIssueCommand.Create(myDBSetting);
- BCE.AutoCount.Stock.StockIssue.StockIssue doc = cmd.AddNew();
- doc.Description = “Stock Issue from program code”;
- BCE.AutoCount.Stock.StockIssue.StockIssueDetail detail = doc.AddDetail();
- detail.ItemCode = “1234″;
- detail.Qty = 2;
- doc.Save(BCE.AutoCount.Authentication.UserAuthentication.GetOrCreate(myDBSetting).LoginUserID);
- }
Edit Stock Issue
- public void EditStockIssue()
- {
- BCE.AutoCount.Stock.StockIssue.StockIssueCommand cmd = BCE.AutoCount.Stock.StockIssue.StockIssueCommand.Create(myDBSetting);
- BCE.AutoCount.Stock.StockIssue.StockIssue doc = cmd.Edit(“SI-000001″);
- doc.Description = “Modified Stock Issue from program code”;
- doc.ClearDetails();
- BCE.AutoCount.Stock.StockIssue.StockIssueDetail detail = doc.AddDetail();
- detail.ItemCode = “1234″;
- detail.Qty = 5;
- doc.Save(BCE.AutoCount.Authentication.UserAuthentication.GetOrCreate(myDBSetting).LoginUserID);
- }
Delete Stock Issue
- public void DeleteStockIssue()
- {
- BCE.AutoCount.Stock.StockIssue.StockIssueCommand cmd = BCE.AutoCount.Stock.StockIssue.StockIssueCommand.Create(myDBSetting);
- cmd.Delete(“SI-000001″);
- }
StockIssue Class Properties
StockIssue Properties
Field Name | Type(Length) | Read-only | Description |
---|---|---|---|
Action | BCE.AutoCount.Stock.StockIssue.StockIssueAction | √ | Returns the StockIssueAction object of this document |
Cancelled | boolean | √ | Returns true if the document is cancelled |
CanSync | boolean | The status flag to allow sync for the document | |
Command | BCE.AutoCount.Stock.StockIssue.StockIssueCommand | √ | Returns the StockIssueCommand object of this document |
CreatedTimeStamp | BCE.Data.DBDateTime | √ | Returns the creation time of this document |
CreatedUserID | BCE.Data.DBString(10) | √ | Returns the creator user id of this document |
DataTableDetail | DataTable | √ | Returns the detail table of this document |
DataTableMaster | DataTable | √ | Returns the master table of this document |
DataTableSerialNo | DataTable | √ | Returns the Serial No table of this document |
Description | BCE.Data.DBString(100) | The description assign to this document | |
DetailCount | int | √ | Returns the detail count of this document |
DocDate | BCE.Data.DBDateTime | The document date assign to this document | |
DocKey | long | √ | Returns the document key of this document |
DocNo | BCE.Data.DBString(20) | The document number assign to this document | |
DocNoFormatName | BCE.Data.DBString | The document number format name assign to this document | |
EnableAutoLoadItemDetail | booleam | The status flag to enable auto loading of item detail | |
ExternalLink | BCE.AutoCount.Common.ExtrenalLink | √ | Returns the ExternalLink accessor |
ExternalLinkText | BCE.Data.DBString | The ExternalLink text assign to this document | |
LastModified | BCE.Data.DBDateTime | √ | Returns the last modified time |
LastModifiedUserID | BCE.Data.DBString(10) | √ | Returns the user id of the last modification |
Note | BCE.Data.DBString | The notes assign to this document | |
PrintCount | short | √ | Returns the print count of this document |
ReallocatePurchaseByProject | boolean | The status flag to reallocate purchase by project | |
ReallocatePurchaseByProjectJEDocKey | long | √ | Returns the journal entry document key for reallocate purchase by project |
ReallocatePurchaseByProjectNo | BCE.Data.DBString(10) | The project number use for reallocate purchase by project assign to this document | |
RefDocNo | BCE.Data.DBString(20) | The reference document number assign to this document | |
Remark1 | BCE.Data.DBString(40) | The Remark1 assign to this document | |
Remark2 | BCE.Data.DBString(40) | The Remark2 assign to this document | |
Remark3 | BCE.Data.DBString(40) | The Remark3 assign to this document | |
Remark4 | BCE.Data.DBString(40) | The Remark4 assign to this document | |
ScriptObject | BCE.AutoCount.Scripting.ScriptObject | √ | Returns the ScriptObject of this document |
StockIssueDataSet | DataSet | √ | Returns the Stock Issue DataSet object of this document |
Total | BCE.Data.DBDecimal(18,4) | √ | Returns the Total amount assign to this document |
UDF | BCE.AutoCount.Data.UDFRecord | √ | Returns the UDF accessor |
UserData | object | The object that contains user data. This is use for scripting purposes. |
StockIssueDetail Properties
Field Name | Type(Length) | Read-only | Description |
---|---|---|---|
BatchNo | BCE.Data.DBString(20) | The Batch Number assign to this detail | |
DeptNo | BCE.Data.DBString(10) | The Department Number assign to this detail | |
Description | BCE.Data.DBString(100) | The Description assign to this detail | |
FurtherDescription | BCE.Data.DBString | The further description assign to this detail | |
ItemCode | BCE.Data.DBString(30) | The Item Code assign to this detail | |
Location | BCE.Data.DBString(8) | The Location assign to this detail | |
Numbering | BCE.Data.DBString(6) | The Numbering assign to this detail | |
PrintOut | boolean | The status flag to print out this detail | |
ProjNo | BCE.Data.DBString(10) | The project number assign to this detail | |
Qty | BCE.Data.DBDecimal(18,6) | The Qty assign to this detail | |
Row | DataRow | √ | Returns the Row of this detail |
Seq | int | √ | Returns the sequence of this detail |
SerialNoList | BCE.Data.DBString | √ | Returns the serial number list of this detail |
SubTotal | BCE.Data.DBDecimal(18,4) | The Sub Total assign to this detail | |
UDF | BCE.AutoCount.Data.UDFRecord | √ | Returns the UDF accessor |
UnitPrice | BCE.Data.DBDecimal(18,8) | The Unit Price assign to this detail | |
UOM | BCE.Data.DBString(8) | The UOM assign to this detail |
Full example
- using System;
- using System.Collections.Generic;
- using System.Text;
- using BCE.Data;
- namespace AccessingAccounting
- {
- public class AccessStock
- {
- private DBSetting myDBSetting;
- public AccessStock(DBSetting dbSetting)
- {
- myDBSetting = dbSetting;
- }
- #region Accessing Stock Item
- public void AddItem()
- {
- BCE.AutoCount.Stock.Item.ItemDataAccess cmd = BCE.AutoCount.Stock.Item.ItemDataAccess.Create(myDBSetting);
- BCE.AutoCount.Stock.Item.ItemEntity doc = cmd.NewItem();
- doc.ItemCode = “1234″;
- doc.Description = “item 1234″;
- doc.BaseUomRecord.Uom = “PCS”;
- doc.BaseUomRecord.StandardCost = 10;
- doc.BaseUomRecord.StandardSellingPrice = 5;
- // To add new Uom, refer to code below
- BCE.AutoCount.Stock.Item.ItemUomEntity uom = doc.NewUom(12);
- uom.Uom = “BOX”;
- uom.StandardSellingPrice = 120;
- uom.StandardCost = 60;
- // To access to any Uom, refer to code below.
- BCE.AutoCount.Stock.Item.ItemUomEntity[] uoms = doc.GetUomByRate(12);
- if (uoms != null && uoms.Length > 0)
- {
- uoms[0].BarCode = “123123″;
- }
- bool isSuccessRecalculate = false;
- cmd.SaveData(doc, ref isSuccessRecalculate);
- }
- public void EditItem()
- {
- BCE.AutoCount.Stock.Item.ItemDataAccess cmd = BCE.AutoCount.Stock.Item.ItemDataAccess.Create(myDBSetting);
- BCE.AutoCount.Stock.Item.ItemEntity doc = cmd.LoadItem(“1234″, BCE.AutoCount.Stock.Item.ItemEntryAction.Edit);
- doc.Description = “special modified item”;
- BCE.AutoCount.Stock.Item.ItemUomEntity uom = doc.NewUom(24);
- uom.Uom = “CARTON”;
- uom.StandardSellingPrice = 220;
- uom.StandardCost = 110;
- bool isSuccessRecalculate = false;
- cmd.SaveData(doc, ref isSuccessRecalculate);
- }
- public void DeleteItem()
- {
- BCE.AutoCount.Stock.Item.ItemDataAccess cmd = BCE.AutoCount.Stock.Item.ItemDataAccess.Create(myDBSetting);
- cmd.Delete(“1234″);
- }
- #endregion
- #region Accessing Stock Issue
- public void AddStockIssue()
- {
- BCE.AutoCount.Stock.StockIssue.StockIssueCommand cmd = BCE.AutoCount.Stock.StockIssue.StockIssueCommand.Create(myDBSetting);
- BCE.AutoCount.Stock.StockIssue.StockIssue doc = cmd.AddNew();
- doc.Description = “Stock Issue from program code”;
- BCE.AutoCount.Stock.StockIssue.StockIssueDetail detail = doc.AddDetail();
- detail.ItemCode = “1234″;
- detail.Qty = 2;
- doc.Save(BCE.AutoCount.Authentication.UserAuthentication.GetOrCreate(myDBSetting).LoginUserID);
- }
- public void EditStockIssue()
- {
- BCE.AutoCount.Stock.StockIssue.StockIssueCommand cmd = BCE.AutoCount.Stock.StockIssue.StockIssueCommand.Create(myDBSetting);
- BCE.AutoCount.Stock.StockIssue.StockIssue doc = cmd.Edit(“SI-000001″);
- doc.Description = “Modified Stock Issue from program code”;
- doc.ClearDetails();
- BCE.AutoCount.Stock.StockIssue.StockIssueDetail detail = doc.AddDetail();
- detail.ItemCode = “1234″;
- detail.Qty = 5;
- doc.Save(BCE.AutoCount.Authentication.UserAuthentication.GetOrCreate(myDBSetting).LoginUserID);
- }
- public void DeleteStockIssue()
- {
- BCE.AutoCount.Stock.StockIssue.StockIssueCommand cmd = BCE.AutoCount.Stock.StockIssue.StockIssueCommand.Create(myDBSetting);
- cmd.Delete(“SI-000001″);
- }
- #endregion
- }
- }