title: Complex financial calculations/business rules in Angular
body: <p>I am looking at developing a SPA application probably with Angular.</p>
  
  <p>One of the challenges we face is that we have considerable amount of financial based calculations that comes into play whilst the user is entering values on a form.  Here’s a simplified example:</p>
  
  <blockquote>
    <p>The user is entering a detail line on a sales transaction entry form.
    As they enter the Net amount, the system should calculate the Sales
    Tax amount and Gross value based on the net value entered (as I say,
    it does get more complex than this).
    <strong>The important thing to note here, is that as the user tabs out of the Net field, they should see the Tax and Gross fields update.</strong></p>
  </blockquote>
  
  <p>So I see two high level options here:</p>
  
  <ol>
  <li>Either code this calculation in JavaScript </li>
  <li>Make a service call to
  perform the calculation</li>
  </ol>
  
  <p>Either way, I want the Angular style model to be updated with the result of the calculation which will cause the view to update.</p>
  
  <p>Where possible, I would prefer to do this through a service call, as that way it opens the door to re-using this logic from other clients in the future.  I also think that coding this sort of logic in C# should be faster to develop and more maintainable (and keeps the logic in one place).</p>
  
  <p>Ideally I would like this logic in the C# entity in the service that models the transaction.</p>
  
  <p>How should I therefore go about calling such server side logic?  </p>
  
  <ol>
  <li>Should I somehow pass the whole client side representation of the
  model back up to the service and have it calculate the other values?
  Not sure how I would do this in terms of telling the service which
  values actually need calculating. </li>
  <li>Or should I have (lots of) individual
  service methods named things like CalculateTax(net, taxPercentage)
  that returns the Tax amount.</li>
  </ol>
  
  <p>Or is there some other method or pattern that I am missing altogether here?</p>
  
  <p>Many thanks</p>