Access Stock Tutorial

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

Code Snippet
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

Add Code Snippet

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

Edit Code Snippet

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

Delete Code Snippet

public void DeleteItem()

{

    BCE.AutoCount.Stock.Item.ItemDataAccess cmd =

BCE.AutoCount.Stock.Item.ItemDataAccess.Create(myDBSetting);

    cmd.Delete(“1234″);

}

 

 

Item Class Properties
Item Entity 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 O 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 O Returns the creation time of this entity
CreatedUserID String(10) O Returns the entity creator user id
Data DataSet   Returns the DataSet object of this entity
DefaultUom BCE.AutoCount.Stock.Item.ItemUomEntity O 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 O 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 O Returns the last modified time
LastModifiedUserID String(10) O Returns the user id of the last modification
LastUpdate Int O 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 O Returns the ScriptObject of this documen
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 O Returns the UDF accessor
UomCount Int O Returns the UOM count of this entity

 

 

ItemUomEntity Properties

Field Name Type(Length) Read-Only Description
BalQty Decimal(18,6) O 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) O 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) O Returns the item code
LastUpdate Int O 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 O 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) O 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) O 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) O 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

Code Snippet
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
Add Code Snippet

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
Edit Code Snippet

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
Delete Code Snippet

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 O Returns the StockIssueAction object of this document
Cancelled Boolean O Returns true if the document is cancelled
CanSync Boolean   The status flag to allow sync for the document
Command BCE.AutoCount.Stock.StockIssue.StockIssueCommand O Returns the StockIssueCommand object of this document
CreatedTimeStamp BCE.Data.DBDateTime O Returns the creation time of this document
CreatedUserID BCE.Data.DBString(10) O Returns the creator user id of this document
DataTableDetail DataTable O Returns the detail table of this document
DataTableMaster DataTable O Returns the master table of this document
DataTableSerialNo DataTable O Returns the Serial No table of this document
Description BCE.Data.DBString(100)   The description assign to this document
DetailCount Int O Returns the detail count of this document
DocDate BCE.Data.DBDateTime   The document date assign to this document
DocKey Long O 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 O Returns the ExternalLink accessor
ExternalLinkText BCE.Data.DBString   The ExternalLink text assign to this document
LastModified BCE.Data.DBDateTime O Returns the last modified time
LastModifiedUserID BCE.Data.DBString(10) O Returns the user id of the last modification
Note BCE.Data.DBString   The notes assign to this document
PrintCount Short O Returns the print count of this document
ReallocatePurchaseByProject Boolean   The status flag to reallocate purchase by project
ReallocatePurchaseByProjectJEDocKey Long O 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 O Returns the ScriptObject of this document
StockIssueDataSet DataSet O Returns the Stock Issue DataSet object of this document
Total BCE.Data.DBDecimal(18,4) O Returns the Total amount assign to this document
UDF BCE.AutoCount.Data.UDFRecord O 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 O Returns the Row of this detail
Seq Int O Returns the sequence of this detail
SerialNoList BCE.Data.DBString O 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 O 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

Code Snippet

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

    }

}