Autocount - 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
  1. 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
  1. public void AddItem()
  2. {
  3.     BCE.AutoCount.Stock.Item.ItemDataAccess cmd = BCE.AutoCount.Stock.Item.ItemDataAccess.Create(myDBSetting);
  4.  
  5.     BCE.AutoCount.Stock.Item.ItemEntity doc = cmd.NewItem();
  6.  
  7.     doc.ItemCode = “1234″;
  8.     doc.Description = “item 1234″;
  9.     doc.BaseUomRecord.Uom = “PCS”;
  10.     doc.BaseUomRecord.StandardCost = 10;
  11.     doc.BaseUomRecord.StandardSellingPrice = 5;
  12.  
  13.     // To add new Uom, refer to code below
  14.     BCE.AutoCount.Stock.Item.ItemUomEntity uom = doc.NewUom(12);
  15.     uom.Uom = “BOX”;
  16.     uom.StandardSellingPrice = 120;
  17.     uom.StandardCost = 60;
  18.  
  19.     // To access to any Uom, refer to code below.
  20.     BCE.AutoCount.Stock.Item.ItemUomEntity[] uoms = doc.GetUomByRate(12);
  21.     if (uoms != null && uoms.Length > 0)
  22.     {
  23.         uoms[0].BarCode = “123123″;
  24.     }
  25.  
  26.     bool isSuccessRecalculate = false;
  27.  
  28.     cmd.SaveData(doc, ref isSuccessRecalculate);
  29. }

Edit Stock Item

Edit Code Snippet
  1. public void EditItem()
  2. {
  3.     BCE.AutoCount.Stock.Item.ItemDataAccess cmd = BCE.AutoCount.Stock.Item.ItemDataAccess.Create(myDBSetting);
  4.  
  5.     BCE.AutoCount.Stock.Item.ItemEntity doc = cmd.LoadItem(“1234″, BCE.AutoCount.Stock.Item.ItemEntryAction.Edit);
  6.  
  7.     doc.Description = “special modified item”;
  8.  
  9.     BCE.AutoCount.Stock.Item.ItemUomEntity uom = doc.NewUom(24);
  10.     uom.Uom = “CARTON”;
  11.     uom.StandardSellingPrice = 220;
  12.     uom.StandardCost = 110;
  13.  
  14.     bool isSuccessRecalculate = false;
  15.  
  16.     cmd.SaveData(doc, ref isSuccessRecalculate);
  17. }

Delete Stock Item

Delete Code Snippet
  1. public void DeleteItem()
  2. {
  3.     BCE.AutoCount.Stock.Item.ItemDataAccess cmd = BCE.AutoCount.Stock.Item.ItemDataAccess.Create(myDBSetting);
  4.     cmd.Delete(“1234″);
  5. }

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

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
BCE.AutoCount.Stock.Item.ItemUomEntity

Returns the default UOM record

 

Showing 1 to 10 of 51 entries

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

 

Showing 1 to 10 of 32 entries

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
Showing 1 to 7 of 7 entries

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
Showing 1 to 4 of 4 entries

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
Showing 1 to 2 of 2 entries

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
  1. 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
  1. public void AddStockIssue()
  2. {
  3.     BCE.AutoCount.Stock.StockIssue.StockIssueCommand cmd = BCE.AutoCount.Stock.StockIssue.StockIssueCommand.Create(myDBSetting);
  4.  
  5.     BCE.AutoCount.Stock.StockIssue.StockIssue doc = cmd.AddNew();
  6.     doc.Description = “Stock Issue from program code”;
  7.     BCE.AutoCount.Stock.StockIssue.StockIssueDetail detail = doc.AddDetail();
  8.     detail.ItemCode = “1234″;
  9.     detail.Qty = 2;
  10.  
  11.     doc.Save(BCE.AutoCount.Authentication.UserAuthentication.GetOrCreate(myDBSetting).LoginUserID);
  12. }

Edit Stock Issue

Edit Code Snippet
  1. public void EditStockIssue()
  2. {
  3.     BCE.AutoCount.Stock.StockIssue.StockIssueCommand cmd = BCE.AutoCount.Stock.StockIssue.StockIssueCommand.Create(myDBSetting);
  4.  
  5.     BCE.AutoCount.Stock.StockIssue.StockIssue doc = cmd.Edit(“SI-000001″);
  6.     doc.Description = “Modified Stock Issue from program code”;
  7.     doc.ClearDetails();
  8.     BCE.AutoCount.Stock.StockIssue.StockIssueDetail detail = doc.AddDetail();
  9.     detail.ItemCode = “1234″;
  10.     detail.Qty = 5;
  11.  
  12.     doc.Save(BCE.AutoCount.Authentication.UserAuthentication.GetOrCreate(myDBSetting).LoginUserID);
  13. }

Delete Stock Issue

Delete Code Snippet
  1. public void DeleteStockIssue()
  2. {
  3.     BCE.AutoCount.Stock.StockIssue.StockIssueCommand cmd = BCE.AutoCount.Stock.StockIssue.StockIssueCommand.Create(myDBSetting);
  4.     cmd.Delete(“SI-000001″);
  5. }

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
Showing 1 to 10 of 35 entries

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
Showing 1 to 10 of 17 entries

Full example

Code Snippet
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using BCE.Data;
  5.  
  6. namespace AccessingAccounting
  7. {
  8.     public class AccessStock
  9.     {
  10.         private DBSetting myDBSetting;
  11.  
  12.         public AccessStock(DBSetting dbSetting)
  13.         {
  14.             myDBSetting = dbSetting;
  15.         }
  16.  
  17.         #region Accessing Stock Item
  18.         public void AddItem()
  19.         {
  20.             BCE.AutoCount.Stock.Item.ItemDataAccess cmd = BCE.AutoCount.Stock.Item.ItemDataAccess.Create(myDBSetting);
  21.  
  22.             BCE.AutoCount.Stock.Item.ItemEntity doc = cmd.NewItem();
  23.  
  24.             doc.ItemCode = “1234″;
  25.             doc.Description = “item 1234″;
  26.             doc.BaseUomRecord.Uom = “PCS”;
  27.             doc.BaseUomRecord.StandardCost = 10;
  28.             doc.BaseUomRecord.StandardSellingPrice = 5;
  29.  
  30.             // To add new Uom, refer to code below
  31.             BCE.AutoCount.Stock.Item.ItemUomEntity uom = doc.NewUom(12);
  32.             uom.Uom = “BOX”;
  33.             uom.StandardSellingPrice = 120;
  34.             uom.StandardCost = 60;
  35.  
  36.             // To access to any Uom, refer to code below.
  37.             BCE.AutoCount.Stock.Item.ItemUomEntity[] uoms = doc.GetUomByRate(12);
  38.             if (uoms != null && uoms.Length > 0)
  39.             {
  40.                 uoms[0].BarCode = “123123″;
  41.             }
  42.  
  43.             bool isSuccessRecalculate = false;
  44.  
  45.             cmd.SaveData(doc, ref isSuccessRecalculate);
  46.         }
  47.  
  48.         public void EditItem()
  49.         {
  50.             BCE.AutoCount.Stock.Item.ItemDataAccess cmd = BCE.AutoCount.Stock.Item.ItemDataAccess.Create(myDBSetting);
  51.  
  52.             BCE.AutoCount.Stock.Item.ItemEntity doc = cmd.LoadItem(“1234″, BCE.AutoCount.Stock.Item.ItemEntryAction.Edit);
  53.  
  54.             doc.Description = “special modified item”;
  55.  
  56.             BCE.AutoCount.Stock.Item.ItemUomEntity uom = doc.NewUom(24);
  57.             uom.Uom = “CARTON”;
  58.             uom.StandardSellingPrice = 220;
  59.             uom.StandardCost = 110;
  60.  
  61.             bool isSuccessRecalculate = false;
  62.  
  63.             cmd.SaveData(doc, ref isSuccessRecalculate);
  64.         }
  65.  
  66.         public void DeleteItem()
  67.         {
  68.             BCE.AutoCount.Stock.Item.ItemDataAccess cmd = BCE.AutoCount.Stock.Item.ItemDataAccess.Create(myDBSetting);
  69.             cmd.Delete(“1234″);
  70.         }
  71.         #endregion
  72.  
  73.         #region Accessing Stock Issue
  74.         public void AddStockIssue()
  75.         {
  76.             BCE.AutoCount.Stock.StockIssue.StockIssueCommand cmd = BCE.AutoCount.Stock.StockIssue.StockIssueCommand.Create(myDBSetting);
  77.  
  78.             BCE.AutoCount.Stock.StockIssue.StockIssue doc = cmd.AddNew();
  79.             doc.Description = “Stock Issue from program code”;
  80.             BCE.AutoCount.Stock.StockIssue.StockIssueDetail detail = doc.AddDetail();
  81.             detail.ItemCode = “1234″;
  82.             detail.Qty = 2;
  83.  
  84.             doc.Save(BCE.AutoCount.Authentication.UserAuthentication.GetOrCreate(myDBSetting).LoginUserID);
  85.         }
  86.  
  87.         public void EditStockIssue()
  88.         {
  89.             BCE.AutoCount.Stock.StockIssue.StockIssueCommand cmd = BCE.AutoCount.Stock.StockIssue.StockIssueCommand.Create(myDBSetting);
  90.  
  91.             BCE.AutoCount.Stock.StockIssue.StockIssue doc = cmd.Edit(“SI-000001″);
  92.             doc.Description = “Modified Stock Issue from program code”;
  93.             doc.ClearDetails();
  94.             BCE.AutoCount.Stock.StockIssue.StockIssueDetail detail = doc.AddDetail();
  95.             detail.ItemCode = “1234″;
  96.             detail.Qty = 5;
  97.  
  98.             doc.Save(BCE.AutoCount.Authentication.UserAuthentication.GetOrCreate(myDBSetting).LoginUserID);
  99.         }
  100.  
  101.         public void DeleteStockIssue()
  102.         {
  103.             BCE.AutoCount.Stock.StockIssue.StockIssueCommand cmd = BCE.AutoCount.Stock.StockIssue.StockIssueCommand.Create(myDBSetting);
  104.             cmd.Delete(“SI-000001″);
  105.         }
  106.         #endregion
  107.     }
  108. }