<span style="border-collapse:collapse;font-family:arial, sans-serif;font-size:13px"><div><span style="border-collapse:collapse;font-family:arial, sans-serif;font-size:13px">(Note: This was cross-posted earlier to the Jess User Group as well)</span></div>
<div><span style="border-collapse:collapse;font-family:arial, sans-serif;font-size:13px"><br></span></div>We wrote code to solve this problem (described later) many years ago, when I was not aware of rule based approaches. However, I wonder if a rules based solution  might represent a better  approach to solve this problem... and if so, how would one do it? <div>

<br></div><div><b>BACKGROUND</b></div><div>We have departments setup in a hierarchical structure (i.e. parent departments) </div><div>An employee can belong to one and only one department.</div><div>An employee can  be the manager of one or more departments; a manager  may or not belong to that department.</div>

<div>A department can have many employees and many managers.</div><div><br></div><div><b>PROBLEM</b></div><div>Find the approver for an employee&#39;s expenses.</div><div>An approver is a &#39;higher level&#39; manager relative to employee in the organizational hierarchy.</div>

<div>Note that since the manager is employee as well, this includes the problem of finding the manager of a manager.</div><div><br></div><div><b>RULES</b></div><div>1. The approver  the nearest manager to the employee (traversing up the department hierarchy)</div>

<div>Typical cases then are:</div><div>- for a non-manager employee, the approver is the manager of the employee&#39;s department</div><div>- for a manager who manages a single department and belongs to that department, the approver is the manager of the parent unit </div>

<div><br></div><div>2. The approver for a manager cannot the manager himself or a peer manager (in the same department).</div><div><br></div><div>3. An approver cannot report to the employee </div><div>This sometimes happens when the manager is an employee in one department but manager for a department a few levels up in the hierarchy</div>

<div><br></div><div>3a. An approver cannot be the peer to someone who reports to the manager</div><div><br></div><div><br></div><div><br></div><div><b>SAMPLE DATA</b></div><div>A              (manager Hillary)      </div>

<div>   A1         (manager John  and Jane )                </div><div>       A11   </div><div>       A12   (manager Mike; employees John and Mike)</div><div>       A13</div><div>   A2          (manager Kate)</div><div><div>

       A21    (manager Jessica, employee Janet)</div></div><div>       A22    (manager Erica, employee Jane)</div><div><div><br></div></div><div>1. Approver for Janet is Jessica</div><div>2. Approver for Jessica is Kate</div>

<div>3.Approver for John  is Hillary (cannot be Mike, John himself or Jane)</div><div>4. Approver for Jane is Erica via A22 (no reporting relationship).</div><div><br></div><div><b>ALGORITHMIC SOLUTION</b></div><div>Define the department  reporting vector  starting from the employee department</div>

<div>    e.g. for (1) it would be A21 -&gt; A2 -&gt; A and </div><div>           for (3) it would be A12 -&gt; A1 -&gt; A</div><div>Then for each, define managers and then employees</div><div>        (1) : A21( jessica/ janet )    -&gt; A2: ( Kate)  -&gt; A(  Hillary)</div>

<div>        (2):  A12 (Mike/  John, Mike)   -&gt; A1 (John, Jane)  -&gt; A (Hillary)</div><div>Then starting from the top (i.e. A), move down looking for the employee (in manager or employee list)</div><div>If  the employee is found in  the manager list, approver is the manager of the parent department</div>

<div>If the employee is found in the employee list, the approver is the manager of this unit (not the parent)</div><div>(I may have missed a few rules in the algorithmic solution)</div><div><br></div><div><br></div><div>
<b>RULE BASED SOLUTION?</b></div>
<div>Is this a good problem for rule bases solution?</div><div>I started to model this and will post my solution if I can come up with something useful but would absolutely welcome your inputs.</div><div><br></div><div><br>

</div><div><br></div><div><br></div></span>