Report Script: Create a Packing List in report script: Difference between revisions

no edit summary
No edit summary
No edit summary
Line 2:
This tutorial shows how to add a text which displays packing that is based on largest UOM to smallest UOM with report scripting.<br/>
Does not take into consideration of area and customer.
 
==Tasks in this tutorial==
*Add Calculate Field in Report
*Construct a text that join UOMs
 
==Product==
AutoCount Accounting 1.8 / 1.9<br/>
Applicable to AutoCount Accounting 2.0 (require to manual modify some code)
 
{{SourceDownload|link=https://drive.google.com/open?id=11uJzctlWBNC6YQ1Z8rdWgNPgAxZ4N_ZO|remark=(AutoCount Accounting 1.8 / 1.9)|Download Report Template|Packing in Delivery Detail Listing.}}
Line 20 ⟶ 24:
| CTN || 6
|}
 
 
==Report Script==
===Show the packing from any UOM===
===Open Report Designer and Load Report Template===
#At main window, go to Sales | Delivery Order
#On the main menu, click Report | Design Detail Listing Report
#Select "Picking List - Delivery Order" report template<br/><br/>
===Add Calculated Field===
#Insert a '''Calculated Field'''
#:While the view is at '''Designer''',
Line 34 ⟶ 39:
#:Locate & Select the newly added calculated field
#:In '''Property Grid''', rename '''(Name)''' to '''calcPacking'''
===Add Script Event===
#Create new event of '''GetValue''' to '''calcPacking'''
#:Click [+] to expand '''Scripts'''
#:Click the box on the right of "Get a Value"
#:Then click the arrow button, and click '''(New)'''
#:Report Designer will switch to Scripts editor,
#:and '''calcPacking_GetValue''' event is created.<br/><br/>
===Add using directive===
#Add directive at the top of '''Scripts''', if has not already added.
#*'''using System.Data;'''
#*'''using System.Linq;'''
#===Insert scripts into '''calcPacking_GetValue'''===
#Add function of '''GetSmallestQty'''
#Add function of '''GetUOMFromItem'''
#Add function of '''FormatCurrentUomResult'''<br/><br/>
#Add a new Label into existing Group Header
#:Bind the calcProjDesc to this new label
#:Drag calcPacking from '''1 Main Data: Delivery Order Master''' in Field List onto the new label
#Click Preview tab to see the result
<syntaxhighlight lang="csharp">
//Main Entry
private void calcPacking_GetValue(object sender, DevExpress.XtraReports.UI.GetValueEventArgs e)
{
//Get all UOM of current Item
DataTable tblUOM = GetUOMFromItem(GetCurrentColumnValue("ItemCode"));
if (tblUOM == null)
return;
 
//Get total smallest UOM Qty of same ItemCode and UOMRate
decimal smallestQty = GetSmallestQty(GetCurrentColumnValue("ItemCode"), GetCurrentColumnValue("UOMRate"));
 
Line 65 ⟶ 66:
string result = "";
 
//Loop all uomsUOMs in the UOM Table
foreach (DataRow row in tblUOM.Rows)
{
Line 71 ⟶ 72:
break;
 
//Get the rate of current UOM in tblUOM (DataTable)
uomRate = BCE.Data.Convert.ToDecimal(row["Rate"]);
 
//Store each formatted UOM Packing
result = FormatCurrentUomResult(result,
uomRate > 0 ? Math.Floor(smallestQty / uomRate) : 0,
Line 79 ⟶ 83:
smallestQty = smallestQty % uomRate;
}
 
//Assign the "Packing" to calcPacking
e.Value = result;
}
</syntaxhighlight>
===Function#Add function of '''GetSmallestQty==='''
#Add function of '''GetSmallestQtyGetUOMFromItem'''
#Add function of '''GetUOMFromItemFormatCurrentUomResult'''
====Function of GetSmallestQty====
<syntaxhighlight lang="csharp">
//ItemCode and UOMRate are the grouping in this report
Line 97 ⟶ 106:
}
</syntaxhighlight>
====Function of GetUOMFromItem====
<syntaxhighlight lang="csharp">
//Get the table of available UOM of one Item
Line 108 ⟶ 117:
}
</syntaxhighlight>
====Function of FormatCurrentUomResult====
<syntaxhighlight lang="csharp">
private string FormatCurrentUomResult(string result, decimal qty, string uom)
Line 120 ⟶ 129:
}
</syntaxhighlight>
 
===Add label to display "Packing"===
#Add a new Label into existing Group Header
#:Bind the calcProjDesc to this new label
#:Drag calcPacking from '''1 Main Data: Delivery Order Master''' in Field List onto the new label
#Click Preview tab to see the result
 
<br/>
Line 125 ⟶ 140:
[[Category:Tutorials]]
[[Category:ReportScript]]
 
{{NavigateDeveloper}}