[% USE Branches %]
[% USE Koha %]
[% USE KohaDates %]
[% USE Price %]
[% PROCESS 'accounts.inc' %]
<table>
  [% IF ( Koha.Preference('LibraryName') ) %]
    <tr>
      <th colspan='4' class='centerednames'>
        <h1>[% Koha.Preference('LibraryName') | html %]</h1>
      </th>
    </tr>
  [% END %]

  <tr>
    <th colspan='4' class='centerednames'>
      <h2>[% Branches.GetName( borrower.branchcode ) | html %]</h2>
    </th>
  </tr>

  <tr>
    <th colspan='4' class='centerednames'>
      <h3>Cuentas remanentes</h3>
    </th>
  </tr>

  <tr>
    <th colspan='4' class='centerednames'>
      <h4>Deudas</h4>
    </th>
  </tr>
  [% IF borrower.account.outstanding_debits.total_outstanding %]
  <tr>
    <th>Fecha</th>
    <th>Cargo</th>
    <th>Cantidad</th>
    <th>Remanente</th>
  </tr>
  [% FOREACH debit IN borrower.account.outstanding_debits %]
  <tr>
    <td>[% debit.date | $KohaDates %]</td>
    <td>
      [% PROCESS account_type_description account=debit %]
      [%- IF debit.description %], [% debit.description | html %][% END %]
    </td>
    <td class='debit'>[% debit.amount | $Price %]</td>
    <td class='debit'>[% debit.amountoutstanding | $Price %]</td>
  </tr>
  [% END %]
  [% ELSE %]
  <tr>
    <td colspan='4'>No hay débitos remanentes en su cuenta</td>
  </tr>
  [% END %]

  <tr>
    <th colspan='4' class='centerednames'>
      <h4>Créditos</h4>
    </th>
  </tr>
  [% IF borrower.account.outstanding_credits.total_outstanding %]
  <tr>
    <th>Fecha</th>
    <th>Crédito</th>
    <th>Cantidad</th>
    <th>Remanente</th>
  </tr>
  [% FOREACH credit IN borrower.account.outstanding_credits %]
  <tr>
    <td>[% credit.date | $KohaDates%]</td>
    <td>
      [% PROCESS account_type_description account=credit %]
      [%- IF credit.description %], [% credit.description | html %][% END %]
    </td>
    <td class='credit'>[% credit.amount *-1 | $Price %]</td>
    <td class='credit'>[% credit.amountoutstanding *-1 | $Price %]</td>
  </tr>
  [% END %]
  [% ELSE %]
  <tr>
    <td colspan='4'>No hay créditos remanentes en su cuenta</td>
  </tr>
  [% END %]

  <tfoot>
    <td colspan='3'>
      [% IF borrower.account.balance < 0 %]
        Crédito total al [% today | $KohaDates %]:
      [% ELSE %]
        Total de vencimientos pendientes al [% today | $KohaDates %]:
      [% END %]
    </td>
    [% IF ( borrower.account.balance <= 0 ) %]<td class='credit'>[% borrower.account.balance * -1 | $Price %]</td>
    [% ELSE %]<td class='debit'>[% borrower.account.balance | $Price %]</td>[% END %]
  </tfoot>
</table>