Advanced [Exercise 6: Adjustment button] (Training slides exercise)

Create an input field to be able to select a range of accounts from the TB, then display a table underneath that will show the account link, a blank input field for description and a blank input field to indicate the adjustment value so that the user can fill them out.

Create an adjustment button under the table that will post the adjustments entered by the user to the relevant account. Remember to add a counteraccount so that the journal zeros out

The table should look like this:

|686px;x130px;

When clicking on ‘Post adjustment’ you should get something like the image below:

|716px;x227px;

Hint: Use arrays to capture the description and values and then create a for loop inside the adjustment button

Solution:

{% input custom.select.accounts as:account_collection range:'1__9' accounts_var:accounts %}

{% stripnewlines %}
{% for account in accounts %}
  {% if forloop.first %}
    |---30%-----
    |---50%----
    |---20%-----:#
    {% newline %}
  {% endif %}
  | {{ account.link }}
  | {% input custom.description.[account.id] placeholder:'Description' %}
  {% assign description_array = description_array | append:custom.description.[account.id] | append:';' %}
  | {%=$1+input custom.adjustment.[account.id] as:currency_dc placeholder:'0.00' %}
  {% assign adjustment_values_array = adjustment_values_array | append:custom.adjustment.[account.id] | append:';' %}
  {% newline %}
{% endfor %}
{% newline %}
{% endstripnewlines %}

{% assign description_array = description_array | split:';' %}
{% assign adjustment_values_array = adjustment_values_array | split:';' %}

{% adjustmentbutton text:"Post adjustment" category:"internal" %}
  {% capture counter_account %}401000.000{% endcapture %}
  {% capture counter_account_name %}{{ period.accounts.["401000.000"].first.name }}{% endcapture %}
  {% for account in accounts %}
    {% adjustmenttransaction original_account_number:account.number account_name:account.name description:description_array[forloop.index0] value:adjustment_values_array[forloop.index0] %}
  {% endfor %}
  {% adjustmenttransaction original_account_number:counter_account account_name:counter_account_name description:'Total' value:-$1 %}
{% endadjustmentbutton %} 

Solution using HTML Tables:

{% input custom.select.accounts as:account_collection range:'1__9' accounts_var:accounts %}

<table class="usr-width-100 usr-bordered">
  {% for account in accounts %}
    <tr>
      <td class="usr-width-30">{{ account.link }}</td>
      <td class="usr-width-50">{% input custom.description.[account.id] placeholder:'Description' %}</td>
      {% assign description_array = description_array | append:custom.description.[account.id] | append:';' %}
      <td class="usr-width-20 usr-align-right">{% input custom.adjustment.[account.id] as:currency_dc placeholder:'0.00' %}</td>
      {% assign adj_value = adj_value+custom.adjustment.[account.id] %}
      {% assign adjustment_values_array = adjustment_values_array | append:custom.adjustment.[account.id] | append:';' %}
    </tr>
  {% endfor %}
</table>

{% assign description_array = description_array | split:';' %}
{% assign adjustment_values_array = adjustment_values_array | split:';' %}

{% adjustmentbutton text:"Post adjustment" category:"internal" %}
  {% capture counter_account %}401000.000{% endcapture %}
  {% capture counter_account_name %}{{ period.accounts.["401000.000"].first.name }}{% endcapture %}
  {% for account in accounts %}
    {% adjustmenttransaction original_account_number:account.number account_name:account.name description:description_array[forloop.index0] value:adjustment_values_array[forloop.index0] %}
  {% endfor %}
  {% adjustmenttransaction original_account_number:counter_account account_name:counter_account_name description:'Total' value:-adj_value %}
{% endadjustmentbutton %}