Programmer:Item Opening Maintenance: Difference between revisions

From AutoCount Resource Center
Content added Content deleted
(Created page with "==Technical Specification== #Quantity of the Item Opening must not be zero #*When adding a new entry to Item Opening, zero qty entry will be removed before saving to database...")
 
No edit summary
 
(10 intermediate revisions by the same user not shown)
Line 12: Line 12:
#*The filtering will have impact on adding new record of an ItemCode that is not in the range of the filtered range.
#*The filtering will have impact on adding new record of an ItemCode that is not in the range of the filtered range.
#*:If the newly added ItemCode is not in the filter range, system throw exception message of "Item Code is not in Filter range."
#*:If the newly added ItemCode is not in the filter range, system throw exception message of "Item Code is not in Filter range."
#'''Seq''' cannot repeat the same, when the below columns are all the same, or already exist in the record of Item Opening:
#The value of '''Seq''' cannot repeat the same, when the value of below columns are the same, or already exist in the record of Item Opening:
#*ItemCode
#*ItemCode
#*UOM
#*UOM
Line 18: Line 18:
#*BatchNo
#*BatchNo
#:If there is any occasion when '''Seq''' is repeated for the same ItemCode, UOM, Location and BatchNo, below error message is thrown:
#:If there is any occasion when '''Seq''' is repeated for the same ItemCode, UOM, Location and BatchNo, below error message is thrown:
#:Sequence for Item 'FG00001', UOM 'UNIT', Location 'HQ', BatchNo '' is not correct.
#:'''Sequence for Item''' 'FG00001', '''UOM''' 'UNIT', '''Location''' 'HQ', '''BatchNo''' ' ' '''is not correct'''.
#'''Seq''' will affect how the '''cost''' of '''FIFO''' and '''LIFO''' is calculated.


==References of AutoCount Accounting version 1.8==
==References of AutoCount Accounting version 1.8==
Line 135: Line 136:
===Adding two entries of same ItemCode to Item Opening===
===Adding two entries of same ItemCode to Item Opening===
Following example shows the increase of '''Seq''' when 2nd entry of Item Opening has the same '''ItemCode''', '''UOM''', '''Location''' and '''BatchNo''' from the 1st entry.
Following example shows the increase of '''Seq''' when 2nd entry of Item Opening has the same '''ItemCode''', '''UOM''', '''Location''' and '''BatchNo''' from the 1st entry.
<syntaxhighlight lang="csharp">
<syntaxhighlight lang="csharp" highlight="22-24,31-33,27,36">
public void NewTwoEntriesOfSameItem(BCE.Data.DBSetting dbSetting)
public void NewTwoEntriesOfSameItem(BCE.Data.DBSetting dbSetting)
{
{
Line 185: Line 186:
</syntaxhighlight>
</syntaxhighlight>


==Delete Item Opening entry==
==Find and Delete Item Opening entry==
When existing item opening entry has to be deleted before adding / update to Item Opening.<br/>
When delete existing item opening entry, "ItemOpeningKey" is required.<br/>
This example uses a function to find the ItemOpeningKey.<br/>
Checking the existing record can avoid the error of '''"Sequence for Item 'FG00001', UOM 'UNIT', Location 'HQ', BatchNo '' is not correct."'''<br/>
Highlighted shows the function to get the list of keys and deletion of existing keys.
Highlighted shows the function to get the list of keys and deletion of existing keys.<br/><br/>
Get "ItemOpeningKey" can be also applied to check the existing record when it can avoid the error of<br/>'''"Sequence for Item 'FG00001', UOM 'UNIT', Location 'HQ', BatchNo ' ' is not correct."'''<br/>
<syntaxhighlight lang="csharp" highlight="22,23">
<syntaxhighlight lang="csharp" highlight="22,23">
public void CheckNewEntryBeforeAdding(BCE.Data.DBSetting dbSetting)
public void CheckNewEntryBeforeAdding(BCE.Data.DBSetting dbSetting)
Line 244: Line 246:
</syntaxhighlight>
</syntaxhighlight>


===Get '''ItemOpeningKey'''===
Function to find a list of keys that is/are matching.
Function to find a list of keys that is/are matching.
<syntaxhighlight lang="csharp">
<syntaxhighlight lang="csharp">
public List<long> GetExistItemOpeningKey(DataTable table, string itemCode, string uom, string location, string batchNo)
public List<long> GetExistItemOpeningKey(DataTable table, string itemCode, string uom, string location, string batchNo)
{
{
return table.AsEnumerable().Where(r =>
return table.AsEnumerable().Where(r => r.RowState != DataRowState.Deleted &&
r.RowState != DataRowState.Deleted &&
r.Field<string>("ItemCode") == itemCode &&
r.Field<string>("ItemCode") == itemCode &&
r.Field<string>("UOM") == uom &&
r.Field<string>("UOM") == uom &&
Line 259: Line 261:
</syntaxhighlight>
</syntaxhighlight>


Another function to specially handle Deleting matching Item Opening
<syntaxhighlight lang="csharp">
public void DeleteAllMatchingItemOpening(IEnumerable<DataRow> itemOpenings, string itemCode, string uom, string location, string batchNo, Action<long> deleteOpening)
{
itemOpenings.Where(r => r.RowState != DataRowState.Deleted &&
r.Field<string>("ItemCode") == itemCode &&
r.Field<string>("UOM") == uom &&
r.Field<string>("Location") == location &&
r.Field<string>("BatchNo") == batchNo
).Select(r => r.Field<long>("ItemOpeningKey"))
.ToList().ForEach(key => deleteOpening(key));
}
</syntaxhighlight>
To apply this function code;
<syntaxhighlight lang="csharp">
DeleteAllMatchingItemOpening(entities.ItemOpeningTable.AsEnumerable(), "FG00001", "UNIT", "HQ", null, entities.DeleteItemOpening);
</syntaxhighlight>
<br/>
{{SeeAlsoStock}}
{{SeeAlsoStock}}
{{NavigateDeveloper}}
{{NavigateDeveloper}}

Latest revision as of 06:14, 25 September 2018

Technical Specification

  1. Quantity of the Item Opening must not be zero
    • When adding a new entry to Item Opening, zero qty entry will be removed before saving to database
    • Positive (+ve) & negative (-ve) quantity are allowed
  2. Best to filter the loading of Item Opening
    • Avoid loading entire data of Item Opening, when there might be more than 100k records in Item Opening of different UOM, location, batches and etc.
    • Filters that can be applied to reduce the loading of Item Opening data
      • ItemCode
      • ItemGroup
      • ItemType
      • Location
    • The filtering will have impact on adding new record of an ItemCode that is not in the range of the filtered range.
      If the newly added ItemCode is not in the filter range, system throw exception message of "Item Code is not in Filter range."
  3. The value of Seq cannot repeat the same, when the value of below columns are the same, or already exist in the record of Item Opening:
    • ItemCode
    • UOM
    • Location
    • BatchNo
    If there is any occasion when Seq is repeated for the same ItemCode, UOM, Location and BatchNo, below error message is thrown:
    Sequence for Item 'FG00001', UOM 'UNIT', Location 'HQ', BatchNo ' ' is not correct.
  4. Seq will affect how the cost of FIFO and LIFO is calculated.

References of AutoCount Accounting version 1.8

BCE.AutoCount.dll
BCE.AutoCount.CommonAccounting.dll
BCE.AutoCount.MainEntry.dll
BCE.Utils.dll
BCE.Utils.UI.dll
BCE.AutoCount.StockMaint.dll


Load Item Opening

Load Item Opening with ItemCode Filtering

public DataTable GetStockOpening(BCE.Data.DBSetting dbSetting)
{
    BCE.AutoCount.Stock.Item.ItemOpeningDataAccess cmd = BCE.AutoCount.Stock.Item.ItemOpeningDataAccess.Create(dbSetting);
    BCE.AutoCount.Stock.Item.ItemOpeningCriteria crit = new BCE.AutoCount.Stock.Item.ItemOpeningCriteria();

    crit.ItemCodeFilter.Type = BCE.AutoCount.SearchFilter.FilterType.ByRange;
    crit.ItemCodeFilter.From = "FG00001";
    crit.ItemCodeFilter.To = "FG00003";

    DataTable dtOpening = cmd.LoadAutoGenerateTable(crit);
    return dtOpening;
}
  • This example shows the loading of ItemCode from "FG00001" to "FG00003".

Load Item Opening with Location Filtering

public DataTable GetStockOpening(BCE.Data.DBSetting dbSetting)
{
    BCE.AutoCount.Stock.Item.ItemOpeningDataAccess cmd = BCE.AutoCount.Stock.Item.ItemOpeningDataAccess.Create(dbSetting);
    BCE.AutoCount.Stock.Item.ItemOpeningCriteria crit = new BCE.AutoCount.Stock.Item.ItemOpeningCriteria();

    crit.LocationFilter.Type = BCE.AutoCount.SearchFilter.FilterType.ByRange;
    crit.LocationFilter.From = "HQ";
    crit.LocationFilter.To = "HQ";

    DataTable dtOpening = cmd.LoadAutoGenerateTable(crit);
    return dtOpening;
}
  • This example shows the loading of items opening at location "HQ".

Load Item Opening with the combination of filters

public DataTable GetStockOpening(BCE.Data.DBSetting dbSetting)
{
    BCE.AutoCount.Stock.Item.ItemOpeningDataAccess cmd = BCE.AutoCount.Stock.Item.ItemOpeningDataAccess.Create(dbSetting);
    BCE.AutoCount.Stock.Item.ItemOpeningCriteria crit = new BCE.AutoCount.Stock.Item.ItemOpeningCriteria();

    //Filter ItemCode
    crit.ItemCodeFilter.Type = BCE.AutoCount.SearchFilter.FilterType.ByRange;
    crit.ItemCodeFilter.From = "FG00001";
    crit.ItemCodeFilter.To = "FG00003";

    //Filter Location
    crit.LocationFilter.Type = BCE.AutoCount.SearchFilter.FilterType.ByRange;
    crit.LocationFilter.From = "HQ";
    crit.LocationFilter.To = "HQ";

    DataTable dtOpening = cmd.LoadAutoGenerateTable(crit);
    return dtOpening;
}

Add New Entry to Item Opening

Add New Item Opening with the method of NewItemOpening()

public void NewStockOpening(BCE.Data.DBSetting dbSetting)
{
    BCE.AutoCount.Stock.Item.ItemOpeningDataAccess cmd = BCE.AutoCount.Stock.Item.ItemOpeningDataAccess.Create(dbSetting);

    //Create and define ItemOpeningCriteria
    BCE.AutoCount.Stock.Item.ItemOpeningCriteria crit = new BCE.AutoCount.Stock.Item.ItemOpeningCriteria();

    //Filter ItemCode by each item
    crit.ItemCodeFilter.Type = BCE.AutoCount.SearchFilter.FilterType.ByIndividual;
    crit.ItemCodeFilter.Add("FG00001");
    crit.ItemCodeFilter.Add("FG00003");

    //Filter only location to "HQ"
    crit.LocationFilter.Type = BCE.AutoCount.SearchFilter.FilterType.ByRange;
    crit.LocationFilter.From = "HQ";
    crit.LocationFilter.To = "HQ";

    //Load records of existing Items
    BCE.AutoCount.Stock.Item.ItemOpeningEntities entities = cmd.LoadItemOpening(crit);

    //Create new Item Opening Entry
    BCE.AutoCount.Stock.Item.ItemOpeningEntity entity1 = entities.NewItemOpening();
    entity1.ItemCode = "FG00001";
    entity1.Uom = "UNIT";
    entity1.Location = "HQ";
    entity1.Qty = 1;
    entity1.Cost = 5.01M;

    //Create new Item Opening Entry
    BCE.AutoCount.Stock.Item.ItemOpeningEntity entity2 = entities.NewItemOpening();
    entity1.ItemCode = "FG00003";
    entity1.Uom = "UNIT";
    entity1.Location = "HQ";
    entity1.Qty = 2;
    entity1.Cost = 6M;

    try
    {
        cmd.Save(entities);
        BCE.Application.AppMessage.ShowMessage("Item Opening Saved.");
    }
    catch (BCE.Application.AppException ex)
    {
        BCE.Application.AppMessage.ShowErrorMessage(ex.Message);
    }
}

Adding two entries of same ItemCode to Item Opening

Following example shows the increase of Seq when 2nd entry of Item Opening has the same ItemCode, UOM, Location and BatchNo from the 1st entry.

public void NewTwoEntriesOfSameItem(BCE.Data.DBSetting dbSetting)
{
    BCE.AutoCount.Stock.Item.ItemOpeningDataAccess cmd = BCE.AutoCount.Stock.Item.ItemOpeningDataAccess.Create(dbSetting);

    //Create and define ItemOpeningCriteria
    BCE.AutoCount.Stock.Item.ItemOpeningCriteria crit = new BCE.AutoCount.Stock.Item.ItemOpeningCriteria();

    //Filter ItemCode by each item
    crit.ItemCodeFilter.Type = BCE.AutoCount.SearchFilter.FilterType.ByIndividual;
    crit.ItemCodeFilter.Add("FG00001");

    //Filter only location to "HQ"
    crit.LocationFilter.Type = BCE.AutoCount.SearchFilter.FilterType.ByRange;
    crit.LocationFilter.From = "HQ";
    crit.LocationFilter.To = "HQ";

    //Load records of existing Items
    BCE.AutoCount.Stock.Item.ItemOpeningEntities entities = cmd.LoadItemOpening(crit);

    //Create new Item Opening Entry
    BCE.AutoCount.Stock.Item.ItemOpeningEntity entity = entities.NewItemOpening();
    entity.ItemCode = "FG00001";
    entity.Uom = "UNIT";
    entity.Location = "HQ";
    entity.Qty = 2;
    entity.Cost = 5.01M;
    entity.Seq = 0;

    //Increase the Seq of 2nd Entry of same item
    entity = entities.NewItemOpening();
    entity.ItemCode = "FG00001";
    entity.Uom = "UNIT";
    entity.Location = "HQ";
    entity.Qty = 5;
    entity.Cost = 5.02M;
    entity.Seq = 1;

    try
    {
        cmd.Save(entities);
        BCE.Application.AppMessage.ShowMessage("Item Opening Saved.");
    }
    catch (BCE.Application.AppException ex)
    {
        BCE.Application.AppMessage.ShowErrorMessage(ex.Message);
    }
}

Find and Delete Item Opening entry

When delete existing item opening entry, "ItemOpeningKey" is required.
This example uses a function to find the ItemOpeningKey.
Highlighted shows the function to get the list of keys and deletion of existing keys.

Get "ItemOpeningKey" can be also applied to check the existing record when it can avoid the error of
"Sequence for Item 'FG00001', UOM 'UNIT', Location 'HQ', BatchNo ' ' is not correct."

public void CheckNewEntryBeforeAdding(BCE.Data.DBSetting dbSetting)
{
    BCE.AutoCount.Stock.Item.ItemOpeningDataAccess cmd = BCE.AutoCount.Stock.Item.ItemOpeningDataAccess.Create(dbSetting);

    //Create and define ItemOpeningCriteria
    BCE.AutoCount.Stock.Item.ItemOpeningCriteria crit = new BCE.AutoCount.Stock.Item.ItemOpeningCriteria();

    //Filter ItemCode by each item
    crit.ItemCodeFilter.Type = BCE.AutoCount.SearchFilter.FilterType.ByIndividual;
    crit.ItemCodeFilter.Add("FG00001");

    //Filter only location to "HQ"
    crit.LocationFilter.Type = BCE.AutoCount.SearchFilter.FilterType.ByRange;
    crit.LocationFilter.From = "HQ";
    crit.LocationFilter.To = "HQ";

    //Load records of existing Items
    BCE.AutoCount.Stock.Item.ItemOpeningEntities entities = cmd.LoadItemOpening(crit);

    //Delete any existing entries that has same ItemCode, UOM, Location and BatchNo,
    //before adding new entries
    List<long> listKeys = GetExistItemOpeningKey(entities.ItemOpeningTable, "FG00001", "UNIT", "HQ", null);
    listKeys.ForEach(key => entities.DeleteItemOpening(key));

    //Create new Item Opening Entry
    BCE.AutoCount.Stock.Item.ItemOpeningEntity entity = entities.NewItemOpening();
    entity.ItemCode = "FG00001";
    entity.Uom = "UNIT";
    entity.Location = "HQ";
    entity.Qty = 2;
    entity.Cost = 5.01M;
    entity.Seq = 0;

    //Increase the Seq of 2nd Entry of same item
    entity = entities.NewItemOpening();
    entity.ItemCode = "FG00001";
    entity.Uom = "UNIT";
    entity.Location = "HQ";
    entity.Qty = 5;
    entity.Cost = 5.02M;
    entity.Seq = 1;

    try
    {
        cmd.Save(entities);
        BCE.Application.AppMessage.ShowMessage("Item Opening Saved.");
    }
    catch (BCE.Application.AppException ex)
    {
        BCE.Application.AppMessage.ShowErrorMessage(ex.Message);
    }
}

Get ItemOpeningKey

Function to find a list of keys that is/are matching.

public List<long> GetExistItemOpeningKey(DataTable table, string itemCode, string uom, string location, string batchNo)
{
    return table.AsEnumerable().Where(r => r.RowState != DataRowState.Deleted &&
        r.Field<string>("ItemCode") == itemCode &&
        r.Field<string>("UOM") == uom &&
        r.Field<string>("Location") == location &&
        r.Field<string>("BatchNo") == batchNo
    ).Select(r => r.Field<long>("ItemOpeningKey"))
    .ToList();
}

Another function to specially handle Deleting matching Item Opening

public void DeleteAllMatchingItemOpening(IEnumerable<DataRow> itemOpenings, string itemCode, string uom, string location, string batchNo, Action<long> deleteOpening)
{
    itemOpenings.Where(r => r.RowState != DataRowState.Deleted &&
        r.Field<string>("ItemCode") == itemCode &&
        r.Field<string>("UOM") == uom &&
        r.Field<string>("Location") == location &&
        r.Field<string>("BatchNo") == batchNo
    ).Select(r => r.Field<long>("ItemOpeningKey"))
    .ToList().ForEach(key => deleteOpening(key));
}

To apply this function code;

DeleteAllMatchingItemOpening(entities.ItemOpeningTable.AsEnumerable(), "FG00001", "UNIT", "HQ", null, entities.DeleteItemOpening);


See Also

Go to menu

Go to top
Resources For AutoCount Software Developers