Report Script: Create a Packing List in report script: Difference between revisions
Report Script: Create a Packing List in report script (view source)
Revision as of 07:43, 14 April 2020
, 4 years ago→Introduction
No edit summary |
|||
(18 intermediate revisions by one other user not shown) | |||
Line 1:
==Introduction==
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 multi-location, 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=
[[File:Prog PickList.PackUOM.png|link=]]<br />
{| class="wikitable"
!colspan=2|UOM Table
|-
! UOM !! Rate
|-
| UNIT || 1
|-
| BOX || 2
|-
| CTN || 6
|}
==Report Script==
===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
===Add Calculated Field===
#Insert a '''Calculated Field'''
#:While the view is at '''Designer''',
Line 20 ⟶ 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'''
#
#:Then click the arrow button, and click '''(New)'''
#
#:and '''calcPacking_GetValue''' event is created.<br/><br/>
===Add using directive===
#Add directive
#Insert scripts into '''calcPacking_GetValue'''▼
#*'''using System.Data;'''
#Add function of '''GetSmallestQty'''▼
#*'''using System.Linq;'''
#Add function of '''GetUOMFromItem'''▼
#Add function of '''FormatCurrentUomResult'''<br/><br/>▼
Bind the calcProjDesc to this 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, and store in DataTable
DataTable tblUOM = GetUOMFromItem(GetCurrentColumnValue("ItemCode"));
if (tblUOM == null)
return;
//Calculate the quantity
//It is based on the design of this report that uses "Group Header" to group "ItemCode" and "UOMRate"
decimal smallestQty = GetSmallestQty(GetCurrentColumnValue("ItemCode"), GetCurrentColumnValue("UOMRate"));
decimal uomRate;
string result = "";
//Loop all UOMs in the UOM Table
foreach (DataRow row in tblUOM.Rows)
{
if (smallestQty <=
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 61 ⟶ 85:
smallestQty = smallestQty % uomRate;
}
//Assign the "Packing" to calcPacking
e.Value = result;
}
</syntaxhighlight>
▲#Add function of '''GetSmallestQty'''
▲#Add function of '''GetUOMFromItem'''
====Function of GetSmallestQty====
<syntaxhighlight lang="csharp">
//ItemCode and UOMRate are the grouping in this report
private decimal GetSmallestQty(object oItemCode, object oUomRate)
{
▲ .Select(g => g.Sum(r => r.Field<decimal>("Qty") * r.Field<decimal>("Rate")))
}
</syntaxhighlight>
====Function of GetUOMFromItem====
<syntaxhighlight lang="csharp">
//Get the table of available UOM of one Item
private DataTable GetUOMFromItem(object oItemCode)
{
Line 93 ⟶ 120:
}
</syntaxhighlight>
====Function of FormatCurrentUomResult====
<syntaxhighlight lang="csharp">
private string FormatCurrentUomResult(string result, decimal qty, string uom)
Line 104 ⟶ 132:
}
</syntaxhighlight>
<br/>
===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 109 ⟶ 144:
[[Category:Tutorials]]
[[Category:ReportScript]]
{{NavigateDeveloper}}
|