<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.idempiere.org/w-en/index.php?action=history&amp;feed=atom&amp;title=NF9_Extending_CommissionCalc</id>
	<title>NF9 Extending CommissionCalc - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.idempiere.org/w-en/index.php?action=history&amp;feed=atom&amp;title=NF9_Extending_CommissionCalc"/>
	<link rel="alternate" type="text/html" href="https://wiki.idempiere.org/w-en/index.php?title=NF9_Extending_CommissionCalc&amp;action=history"/>
	<updated>2026-09-30T06:16:32Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.35.2</generator>
	<entry>
		<id>https://wiki.idempiere.org/w-en/index.php?title=NF9_Extending_CommissionCalc&amp;diff=20435&amp;oldid=prev</id>
		<title>Diego.ruiz: Categorize and tag</title>
		<link rel="alternate" type="text/html" href="https://wiki.idempiere.org/w-en/index.php?title=NF9_Extending_CommissionCalc&amp;diff=20435&amp;oldid=prev"/>
		<updated>2022-09-02T12:53:16Z</updated>

		<summary type="html">&lt;p&gt;Categorize and tag&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left diff-editfont-monospace&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 12:53, 2 September 2022&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l75&quot; &gt;Line 75:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 75:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;[[Category:New Features Development]]&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;[[Category:New Features Development]]&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;[[Category:Developer documentation]]&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;[[Category:Developer documentation]]&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt; &lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;[[Category:HowTo]]&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt; &lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;[[Category:Updated2022]]&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Diego.ruiz</name></author>
	</entry>
	<entry>
		<id>https://wiki.idempiere.org/w-en/index.php?title=NF9_Extending_CommissionCalc&amp;diff=19498&amp;oldid=prev</id>
		<title>CarlosRuiz: CarlosRuiz moved page NF9.1 Extending CommissionCalc to NF9 Extending CommissionCalc</title>
		<link rel="alternate" type="text/html" href="https://wiki.idempiere.org/w-en/index.php?title=NF9_Extending_CommissionCalc&amp;diff=19498&amp;oldid=prev"/>
		<updated>2021-12-25T12:03:37Z</updated>

		<summary type="html">&lt;p&gt;CarlosRuiz moved page &lt;a href=&quot;/en/NF9.1_Extending_CommissionCalc&quot; class=&quot;mw-redirect&quot; title=&quot;NF9.1 Extending CommissionCalc&quot;&gt;NF9.1 Extending CommissionCalc&lt;/a&gt; to &lt;a href=&quot;/en/NF9_Extending_CommissionCalc&quot; title=&quot;NF9 Extending CommissionCalc&quot;&gt;NF9 Extending CommissionCalc&lt;/a&gt;&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left diff-editfont-monospace&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 12:03, 25 December 2021&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-notice&quot; lang=&quot;en&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(No difference)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
		<author><name>CarlosRuiz</name></author>
	</entry>
	<entry>
		<id>https://wiki.idempiere.org/w-en/index.php?title=NF9_Extending_CommissionCalc&amp;diff=19459&amp;oldid=prev</id>
		<title>CarlosRuiz at 12:00, 25 December 2021</title>
		<link rel="alternate" type="text/html" href="https://wiki.idempiere.org/w-en/index.php?title=NF9_Extending_CommissionCalc&amp;diff=19459&amp;oldid=prev"/>
		<updated>2021-12-25T12:00:22Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left diff-editfont-monospace&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 12:00, 25 December 2021&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l72&quot; &gt;Line 72:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 72:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;[[Category:New Features|D]]&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;[[Category:New Features|D]]&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;[[Category:New Features v9&lt;del class=&quot;diffchange diffchange-inline&quot;&gt;.1&lt;/del&gt;|D]]&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;[[Category:New Features v9|D]]&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;[[Category:New Features Development]]&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;[[Category:New Features Development]]&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;[[Category:Developer documentation]]&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;[[Category:Developer documentation]]&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>CarlosRuiz</name></author>
	</entry>
	<entry>
		<id>https://wiki.idempiere.org/w-en/index.php?title=NF9_Extending_CommissionCalc&amp;diff=19432&amp;oldid=prev</id>
		<title>Diego.ruiz: Created page with &quot;='''Feature:''' Custom Commission calculations=  '''Goal:''' Extensibility  '''Developer:''' Diego.ruiz   '''Feature Ticket:''' [https://idempiere.atlassia...&quot;</title>
		<link rel="alternate" type="text/html" href="https://wiki.idempiere.org/w-en/index.php?title=NF9_Extending_CommissionCalc&amp;diff=19432&amp;oldid=prev"/>
		<updated>2021-12-21T17:51:45Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;=&amp;#039;&amp;#039;&amp;#039;Feature:&amp;#039;&amp;#039;&amp;#039; Custom Commission calculations=  &amp;#039;&amp;#039;&amp;#039;Goal:&amp;#039;&amp;#039;&amp;#039; Extensibility  &amp;#039;&amp;#039;&amp;#039;Developer:&amp;#039;&amp;#039;&amp;#039; &lt;a href=&quot;/w-en/index.php?title=User:Diego_Ruiz&amp;amp;action=edit&amp;amp;redlink=1&quot; class=&quot;new&quot; title=&quot;User:Diego Ruiz (page does not exist)&quot;&gt;Diego.ruiz&lt;/a&gt;   &amp;#039;&amp;#039;&amp;#039;Feature Ticket:&amp;#039;&amp;#039;&amp;#039; [https://idempiere.atlassia...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;='''Feature:''' Custom Commission calculations=&lt;br /&gt;
&lt;br /&gt;
'''Goal:''' Extensibility&lt;br /&gt;
&lt;br /&gt;
'''Developer:''' [[User:Diego Ruiz|Diego.ruiz]] &lt;br /&gt;
&lt;br /&gt;
'''Feature Ticket:''' [https://idempiere.atlassian.net/browse/IDEMPIERE-5119 IDEMPIERE-5119] &lt;br /&gt;
&lt;br /&gt;
'''Description:'''&lt;br /&gt;
The core commission feature works well but it is limited. Usually, every company has a different way of calculating commissions. The goal of this ticket is to make the process that calculates the commission extensible, in a way that every implementation has the flexibility to mix their own rules with iDempiere ones without having to copy the whole class.&lt;br /&gt;
&lt;br /&gt;
==Development==&lt;br /&gt;
To extend the CommisionCalc process that is run when clicking &amp;quot;Generate Commission&amp;quot;. You need to extend CommissionCalc from your custom class and in your Process factory return your custom class when the class name = &amp;quot;&amp;quot;org.compiere.process.CommissionCalc&amp;quot;&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
Methods that you can override within your custom class.&lt;br /&gt;
&lt;br /&gt;
'''doIt''': In case you want to do something completely different.&lt;br /&gt;
&lt;br /&gt;
'''setStartEndDate:''' Sets the start and end date to parse the documents from which the commission will be calculated.&lt;br /&gt;
&lt;br /&gt;
'''createCommissionRun''': In case you want to set special values to the created commission run&lt;br /&gt;
&lt;br /&gt;
'''getCommissionRunDescription:''' If you want to set a special description to the created commission run. By default, the description is set to Start date - End Date - Currency symbol&lt;br /&gt;
&lt;br /&gt;
'''getCommissionCalculationSQL''': This is the method that defines the SQL statement used to create the commission line details. &lt;br /&gt;
&lt;br /&gt;
'''getPaymentCommissionSQL, getOrderCommissionSQL, getInvoiceCommissionSQL:''' Defines the SQL statement to set in the commission lines details based on Payment, Order, Invoice respectively. The query by default sets the columns in this order: Currency ID, Commission Amt, Qty, C_OrderLine_ID, C_InvoiceLine_ID, Reference, Info, Date. If you change this order, you need to override the createDetail method as well.&lt;br /&gt;
&lt;br /&gt;
'''createDetail:''' Creates the commission detail based on the SQL query created with the methods explained above.&lt;br /&gt;
&lt;br /&gt;
==Example==&lt;br /&gt;
Let's say your company has a rule for commissions where the commission for sales orders is calculated based on the margin (sales price - purchase price) and not on the total. &lt;br /&gt;
&lt;br /&gt;
''The explanation of where to get the purchase price is out of the scope of this guide and it will be assumed that there's a CUSTOM_PurchasePrice column in C_OrderLine that contains the purchase price of the selected product.''&lt;br /&gt;
&lt;br /&gt;
In this case, all you need to do is create a class like this to override the getOrderCommissionSQL with the right amount:&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
public class CUSTOM_CommissionCalc extends CommissionCalc  {&lt;br /&gt;
	&lt;br /&gt;
	protected String getOrderCommissionSQL() {&lt;br /&gt;
		StringBuilder sql = new StringBuilder();&lt;br /&gt;
		if (m_com.isListDetails())&lt;br /&gt;
		{&lt;br /&gt;
			sql.append(&amp;quot;SELECT h.C_Currency_ID, l.LineNetAmt - (l.CUSTOM_PurchasePrice*l.QtyOrdered) AS Amt, l.QtyOrdered, &amp;quot;)&lt;br /&gt;
				.append(&amp;quot;l.C_OrderLine_ID, NULL, h.DocumentNo,&amp;quot;)&lt;br /&gt;
				.append(&amp;quot; COALESCE(prd.Value,l.Description),h.DateOrdered &amp;quot;)&lt;br /&gt;
				.append(&amp;quot;FROM C_Order h&amp;quot;)&lt;br /&gt;
				.append(&amp;quot; INNER JOIN C_OrderLine l ON (h.C_Order_ID = l.C_Order_ID)&amp;quot;)&lt;br /&gt;
				.append(&amp;quot; LEFT OUTER JOIN M_Product prd ON (l.M_Product_ID = prd.M_Product_ID) &amp;quot;)&lt;br /&gt;
				.append(&amp;quot;WHERE h.DocStatus IN ('CL','CO')&amp;quot;)&lt;br /&gt;
				.append(&amp;quot; AND h.IsSOTrx='Y'&amp;quot;)&lt;br /&gt;
				.append(&amp;quot; AND h.AD_Client_ID = ?&amp;quot;)&lt;br /&gt;
				.append(&amp;quot; AND h.DateOrdered BETWEEN ? AND ?&amp;quot;);&lt;br /&gt;
		}&lt;br /&gt;
		else&lt;br /&gt;
		{&lt;br /&gt;
			sql.append(&amp;quot;SELECT h.C_Currency_ID, SUM(l.LineNetAmt-(CUSTOM_PurchasePrice*l.QtyOrdered)) AS Amt,&amp;quot;)&lt;br /&gt;
				.append(&amp;quot; SUM(l.QtyOrdered) AS Qty, &amp;quot;)&lt;br /&gt;
				.append(&amp;quot;NULL, NULL, NULL, NULL, MAX(h.DateOrdered) &amp;quot;)&lt;br /&gt;
				.append(&amp;quot;FROM C_Order h&amp;quot;)&lt;br /&gt;
				.append(&amp;quot; INNER JOIN C_OrderLine l ON (h.C_Order_ID = l.C_Order_ID) &amp;quot;)&lt;br /&gt;
				.append(&amp;quot;WHERE h.DocStatus IN ('CL','CO')&amp;quot;)&lt;br /&gt;
				.append(&amp;quot; AND h.IsSOTrx='Y'&amp;quot;)&lt;br /&gt;
				.append(&amp;quot; AND h.AD_Client_ID = ?&amp;quot;)&lt;br /&gt;
				.append(&amp;quot; AND h.DateOrdered BETWEEN ? AND ?&amp;quot;);&lt;br /&gt;
		}&lt;br /&gt;
		return sql.toString();&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:New Features|D]]&lt;br /&gt;
[[Category:New Features v9.1|D]]&lt;br /&gt;
[[Category:New Features Development]]&lt;br /&gt;
[[Category:Developer documentation]]&lt;/div&gt;</summary>
		<author><name>Diego.ruiz</name></author>
	</entry>
</feed>