Programmer:Stock Assembly: Difference between revisions

From AutoCount Resource Center
Content added Content deleted
m (Protected "Programmer:Stock Assembly" ([Edit=Allow only administrators] (indefinite) [Move=Allow only administrators] (indefinite) [Delete=Allow only administrators] (indefinite)))
mNo edit summary
 
(24 intermediate revisions by the same user not shown)
Line 1: Line 1:
==Technical Specification==
{{NavigateDeveloper}}
# Quantity of Item must be in '''base UOM'''
===Rules in Sale Invoice===
# The Quantity Assigned to Item in Detail (raw material) is the quantity that is consumed by Total quantity of Finished Goods.
# Item's UOM of quantity must be in '''base uom'''
#:Eg. Finished Goods Qty = 3 Unit
#: Raw Material A Qty = 12kg
#: 12kg of Raw Material A is consumed by 3 Unit Finished Goods
# In Application, Finished Goods must be maintained in '''Item Maintenance''' and '''Item BOM Maintenance'''


===Assemblies version 1.8===
==References of AutoCount Accounting version 1.8, 1.9==
{{BaseReferenceAC18}}
<pre>
BCE.AutoCount.Stock.dll
'''BCE.AutoCount.Stock.dll'''
BCE.AutoCount.Manufacturing.dll
'''BCE.AutoCount.Manufacturing.dll'''
</pre>


==Sample with data model==
===Create New Stock Assembly===
===Create New Stock Assembly===
<syntaxhighlight lang="csharp">
<syntaxhighlight lang="csharp">
Line 17: Line 21:
BCE.AutoCount.Manufacturing.StockAssembly.StockAssembly doc = cmd.AddNew();
BCE.AutoCount.Manufacturing.StockAssembly.StockAssembly doc = cmd.AddNew();


doc.DocNo = source.DocNo;
doc.DocNo = source.DocNo ?? doc.DocNo;
doc.DocDate = source.DocDate;
doc.DocDate = source.DocDate;
doc.ItemCode = source.ItemCode;
doc.ItemCode = source.ItemCode;
doc.Qty = source.Quantity;
doc.Qty = source.Quantity;
doc.Location = source.Location;
doc.Location = source.Location ?? doc.Location;
doc.ProjNo = source.Project;
if (source.Project != null)
doc.DeptNo = source.Department;
doc.ProjNo = source.Project;
if (source.Department != null)
doc.DeptNo = source.Department;
doc.RefDocNo = source.ReferenceNo;
doc.RefDocNo = source.ReferenceNo;
doc.AssemblyCost = source.AssemblyCost == null ? doc.AssemblyCost : BCE.Data.Convert.ToDBDecimal(source.AssemblyCost);

//Item's UOM is always Base UOM
//Item's UOM is always Base UOM


//When the Finished Goods is maintained as BOM Item,
source.Detail.ForEach(s => AddStockAssemblyDetail(s, doc.AddDetail));
//there are raw materials (sub item) maintained & added accordance to the finished goods
//So, when Finished Goods is assigned, AutoCount API will auto insert raw materials (sub items) into the detail.
//A quick & simple solution is to clear all items in detail, before adding items from source into detail
doc.ClearDetails();

//There are two types of Cost update;
//1) UpdateItemCostWithUpToDateCost : Get the latest cost from stock card
//2) UpdateItemCostWithStandardCost : Get the cost from Item Maintenance, Standard Cost of base UOM
source.Detail.ForEach(s => AddStockAssemblyDetail(
s, doc.AddDetail, doc.UpdateItemCostWithStandardCost));


try
try
Line 40: Line 58:
}
}


public void AddStockAssemblyDetail(StockAssemblyDetailSource source, Func<BCE.AutoCount.Manufacturing.StockAssembly.StockAssemblyDetail> addDetail)
public void AddStockAssemblyDetail(StockAssemblyDetailSource source,
Func<BCE.AutoCount.Manufacturing.StockAssembly.StockAssemblyDetail> addDetail,
Action<System.Data.DataRow> calcItemCost)
{
{
BCE.AutoCount.Manufacturing.StockAssembly.StockAssemblyDetail dtl = addDetail();
BCE.AutoCount.Manufacturing.StockAssembly.StockAssemblyDetail dtl = addDetail();
dtl.ItemCode = source.ItemCode;
dtl.ItemCode = source.ItemCode;
dtl.Description = source.Description;
dtl.Description = source.Description ?? dtl.Description;
dtl.Location = source.Location;
dtl.Location = source.Location ?? dtl.Location;
dtl.ProjNo = source.Project;
if (source.Project != null)
dtl.DeptNo = source.Department;
dtl.ProjNo = source.Project;
if (source.Department != null)
dtl.DeptNo = source.Department;
dtl.Qty = source.Quantity;
dtl.Qty = source.Quantity;

dtl.ItemCost = source.UnitCost;
//When UnitCost is null, Calculate Cost using system update Cost.
if (source.UnitCost.HasValue)
dtl.ItemCost = source.UnitCost.Value;
else
calcItemCost(dtl.Row);

dtl.OverHeadCost = source.OverheadCost;
dtl.OverHeadCost = source.OverheadCost;
//Item's UOM is always Base UOM
//Item's UOM is always Base UOM
Line 61: Line 89:
public string DocNo { get; set; }
public string DocNo { get; set; }
public DateTime DocDate { get; set; }
public DateTime DocDate { get; set; }
public string Description { get; set; }
//Finished Goods
//Finished Goods
public string ItemCode { get; set; }
public string ItemCode { get; set; }
Line 69: Line 98:
public string Department { get; set; }
public string Department { get; set; }
public string ReferenceNo { get; set; }
public string ReferenceNo { get; set; }
public decimal? AssemblyCost { get; set; }


public List<StockAssemblyDetailSource> Detail = new List<StockAssemblyDetailSource>();
public List<StockAssemblyDetailSource> Detail = new List<StockAssemblyDetailSource>();
Line 82: Line 112:
public string Department { get; set; }
public string Department { get; set; }
public decimal Quantity { get; set; }
public decimal Quantity { get; set; }
public decimal UnitCost { get; set; }
public decimal? UnitCost { get; set; }
public decimal OverheadCost { get; set; }
public decimal OverheadCost { get; set; }
}
}
Line 88: Line 118:


===Implementation===
===Implementation===
[[File:PrgApiSTKAsembly1.PNG|link=]]
<syntaxhighlight lang="csharp">
<syntaxhighlight lang="csharp">
public void MainEntry(BCE.Data.DBSetting dbSetting)
{
StockAssemblySource newDoc = new StockAssemblySource()
{
DocDate = new DateTime(2017, 12, 7),
//Finished Goods
ItemCode = "FG00001",
Quantity = 3,
};
//Raw Materials
newDoc.Detail.Add(new StockAssemblyDetailSource() { ItemCode = "RW00001", Description = "Metal", Quantity = 12, UnitCost = 1 });
newDoc.Detail.Add(new StockAssemblyDetailSource() { ItemCode = "RW00002", Description = "Casing", Quantity = 1, UnitCost = 20, OverheadCost = 30 });
newDoc.Detail.Add(new StockAssemblyDetailSource() { ItemCode = "RW00003", Description = "WireRed", Quantity = 5, UnitCost = 0.40M });
newDoc.Detail.Add(new StockAssemblyDetailSource() { ItemCode = "RW00003", Description = "WireBlue", Quantity = 5, OverheadCost = 30 });


//Warning: API does not check if "FG00001" is maintained in Item BOM.
//Though Stock Card does record this entry.
CreateNewStockAssembly(dbSetting, newDoc);
}
</syntaxhighlight>
</syntaxhighlight>


==Sample Code of Stock Assembly Transferred from Stock Assembly Order==
==See Also==
* If the transfer quantity of Stock Assembly is greater than the remaining quantity in Stock Assembly Order, an error of "exceeded Qty Limit" will be thrown;
* [[Programmer:Quotation]]
* and this stock assembly will not be created or updated.
* [[Programmer:Sales Order]]
* [[Programmer:Delivery Order]]
* [[Programmer:Sales Invoice]]
* [[Programmer:Cash Sale with Payment]]



[[Category:Programmer]]
<syntaxhighlight lang="csharp">
[[Category:API]]
private void NewStockAssemblyTransferFromAssemblyOrder(BCE.Data.DBSetting dbSetting)
[[Category:Integrate]]
{
[[Category:Plug-In]]
//two parameter of Assembly Order is required,
//(1) Assembly Order Document No.
//(2) Qty of Assembly Order to be transferred to this Stock Assembly
DataSet ds = LoadAODataSet("AO-000001", dbSetting);

if (ds != null)
{
BCE.AutoCount.Manufacturing.StockAssembly.StockAssemblyCommand cmd =
BCE.AutoCount.Manufacturing.StockAssembly.StockAssemblyCommand.Create(dbSetting);

BCE.AutoCount.Manufacturing.StockAssembly.StockAssembly doc = cmd.AddNew();
doc.TransferFromAO(ds, 2);

try
{
doc.Save();
//Log success
BCE.Application.AppMessage.ShowMessage($"Assembly Created {doc.DocNo}");
}
catch (BCE.Application.AppException ex)
{
//log fail
BCE.Application.AppMessage.ShowMessage(ex.Message);
}
}
else
{
//log fail when DocNo of Assembly Order cannot be found,
//or connection to database server failed.
}
}

private DataSet LoadAODataSet(string docNoAO, BCE.Data.DBSetting dbSetting)
{
BCE.AutoCount.Manufacturing.StockAssemblyOrder.StockAssemblyOrderCommand cmd =
BCE.AutoCount.Manufacturing.StockAssemblyOrder.StockAssemblyOrderCommand.Create(dbSetting);

BCE.AutoCount.Manufacturing.StockAssemblyOrder.StockAssemblyOrder ao = cmd.View(docNoAO);

return ao.StockAssemblyOrderDataSet;
}
</syntaxhighlight>


{{SeeAlsoStock}}
{{NavigateDeveloper}}

Latest revision as of 06:27, 5 June 2018

Technical Specification

  1. Quantity of Item must be in base UOM
  2. The Quantity Assigned to Item in Detail (raw material) is the quantity that is consumed by Total quantity of Finished Goods.
    Eg. Finished Goods Qty = 3 Unit
    Raw Material A Qty = 12kg
    12kg of Raw Material A is consumed by 3 Unit Finished Goods
  3. In Application, Finished Goods must be maintained in Item Maintenance and Item BOM Maintenance

References of AutoCount Accounting version 1.8, 1.9

BCE.AutoCount.dll
BCE.AutoCount.CommonAccounting.dll
BCE.AutoCount.MainEntry.dll
BCE.Utils.dll
BCE.Utils.UI.dll
BCE.AutoCount.Stock.dll
BCE.AutoCount.Manufacturing.dll

Sample with data model

Create New Stock Assembly

public void CreateNewStockAssembly(BCE.Data.DBSetting dbSetting, StockAssemblySource source)
{
    BCE.AutoCount.Manufacturing.StockAssembly.StockAssemblyCommand cmd = 
        BCE.AutoCount.Manufacturing.StockAssembly.StockAssemblyCommand.Create(dbSetting);
    BCE.AutoCount.Manufacturing.StockAssembly.StockAssembly doc = cmd.AddNew();

    doc.DocNo = source.DocNo ?? doc.DocNo;
    doc.DocDate = source.DocDate;
    doc.ItemCode = source.ItemCode;
    doc.Qty = source.Quantity;
    doc.Location = source.Location ?? doc.Location;
    if (source.Project != null)
        doc.ProjNo = source.Project;
    if (source.Department != null)
        doc.DeptNo = source.Department;
    doc.RefDocNo = source.ReferenceNo;
    doc.AssemblyCost = source.AssemblyCost == null ? doc.AssemblyCost : BCE.Data.Convert.ToDBDecimal(source.AssemblyCost);

    //Item's UOM is always Base UOM

    //When the Finished Goods is maintained as BOM Item,
    //there are raw materials (sub item) maintained & added accordance to the finished goods
    //So, when Finished Goods is assigned, AutoCount API will auto insert raw materials (sub items) into the detail.
    //A quick & simple solution is to clear all items in detail, before adding items from source into detail
    doc.ClearDetails();

    //There are two types of Cost update;
    //1) UpdateItemCostWithUpToDateCost : Get the latest cost from stock card
    //2) UpdateItemCostWithStandardCost : Get the cost from Item Maintenance, Standard Cost of base UOM
    source.Detail.ForEach(s => AddStockAssemblyDetail(
        s, doc.AddDetail, doc.UpdateItemCostWithStandardCost));

    try
    {
        doc.Save();
        //Log Successful
    }
    catch (BCE.Application.AppException ex)
    {
        //Log error
    }
}

public void AddStockAssemblyDetail(StockAssemblyDetailSource source,
                                   Func<BCE.AutoCount.Manufacturing.StockAssembly.StockAssemblyDetail> addDetail,
                                   Action<System.Data.DataRow> calcItemCost)
{
    BCE.AutoCount.Manufacturing.StockAssembly.StockAssemblyDetail dtl = addDetail();
    dtl.ItemCode = source.ItemCode;
    dtl.Description = source.Description ?? dtl.Description;
    dtl.Location = source.Location ?? dtl.Location;
    if (source.Project != null)
        dtl.ProjNo = source.Project;
    if (source.Department != null)
        dtl.DeptNo = source.Department;
    dtl.Qty = source.Quantity;

    //When UnitCost is null, Calculate Cost using system update Cost.
    if (source.UnitCost.HasValue)
        dtl.ItemCost = source.UnitCost.Value;
    else
        calcItemCost(dtl.Row);

    dtl.OverHeadCost = source.OverheadCost;
    //Item's UOM is always Base UOM
}

Classes of source

public class StockAssemblySource
{
    public string DocNo { get; set; }
    public DateTime DocDate { get; set; }
    public string Description { get; set; }
    //Finished Goods
    public string ItemCode { get; set; }
    //Finished Goods Assembled Qty
    public decimal Quantity { get; set; }
    public string Location { get; set; }
    public string Project { get; set; }
    public string Department { get; set; }
    public string ReferenceNo { get; set; }
    public decimal? AssemblyCost { get; set; }

    public List<StockAssemblyDetailSource> Detail = new List<StockAssemblyDetailSource>();
}

public class StockAssemblyDetailSource
{
    //Raw Materials
    public string ItemCode { get; set; }
    public string Description { get; set; }
    public string Location { get; set; }
    public string Project { get; set; }
    public string Department { get; set; }
    public decimal Quantity { get; set; }
    public decimal? UnitCost { get; set; }
    public decimal OverheadCost { get; set; }
}

Implementation

public void MainEntry(BCE.Data.DBSetting dbSetting)
{
    StockAssemblySource newDoc = new StockAssemblySource()
    {
        DocDate = new DateTime(2017, 12, 7),
        //Finished Goods
        ItemCode = "FG00001",
        Quantity = 3,
    };
    
    //Raw Materials
    newDoc.Detail.Add(new StockAssemblyDetailSource() { ItemCode = "RW00001", Description = "Metal",    Quantity = 12, UnitCost = 1 });
    newDoc.Detail.Add(new StockAssemblyDetailSource() { ItemCode = "RW00002", Description = "Casing",   Quantity = 1,  UnitCost = 20,   OverheadCost = 30 });
    newDoc.Detail.Add(new StockAssemblyDetailSource() { ItemCode = "RW00003", Description = "WireRed",  Quantity = 5,  UnitCost = 0.40M });
    newDoc.Detail.Add(new StockAssemblyDetailSource() { ItemCode = "RW00003", Description = "WireBlue", Quantity = 5,                   OverheadCost = 30 });

    //Warning: API does not check if "FG00001" is maintained in Item BOM.
    //Though Stock Card does record this entry.
    CreateNewStockAssembly(dbSetting, newDoc);
}

Sample Code of Stock Assembly Transferred from Stock Assembly Order

  • If the transfer quantity of Stock Assembly is greater than the remaining quantity in Stock Assembly Order, an error of "exceeded Qty Limit" will be thrown;
  • and this stock assembly will not be created or updated.


private void NewStockAssemblyTransferFromAssemblyOrder(BCE.Data.DBSetting dbSetting)
{
    //two parameter of Assembly Order is required, 
    //(1) Assembly Order Document No.
    //(2) Qty of Assembly Order to be transferred to this Stock Assembly
    DataSet ds = LoadAODataSet("AO-000001", dbSetting);

    if (ds != null)
    {
        BCE.AutoCount.Manufacturing.StockAssembly.StockAssemblyCommand cmd =
            BCE.AutoCount.Manufacturing.StockAssembly.StockAssemblyCommand.Create(dbSetting);

        BCE.AutoCount.Manufacturing.StockAssembly.StockAssembly doc = cmd.AddNew();
        doc.TransferFromAO(ds, 2);

        try
        {
            doc.Save();
            //Log success
            BCE.Application.AppMessage.ShowMessage($"Assembly Created {doc.DocNo}");
        }
        catch (BCE.Application.AppException ex)
        {
            //log fail
            BCE.Application.AppMessage.ShowMessage(ex.Message);
        }
    }
    else
    {
        //log fail when DocNo of Assembly Order cannot be found,
        //or connection to database server failed.
    }
}

private DataSet LoadAODataSet(string docNoAO, BCE.Data.DBSetting dbSetting)
{
    BCE.AutoCount.Manufacturing.StockAssemblyOrder.StockAssemblyOrderCommand cmd =
        BCE.AutoCount.Manufacturing.StockAssemblyOrder.StockAssemblyOrderCommand.Create(dbSetting);

    BCE.AutoCount.Manufacturing.StockAssemblyOrder.StockAssemblyOrder ao = cmd.View(docNoAO);

    return ao.StockAssemblyOrderDataSet;
}


See Also

Go to menu

Go to top
Resources For AutoCount Software Developers