{include file="header.tpl"}

{literal}
<script language="javascript">
  function go(p) {
    document.opts.page.value = p;
    document.opts.submit();
  }
</script>
{/literal}

<div class="main-content">
  <div class="page-content">
    <div class="row">
      <div class="col-xl-12">
        <div class="card">
          <div class="card-body">

            <h4 class="card-title">History</h4>

            <form method="post" name="opts">
              <input type="hidden" name="a" value="earnings">
              <input type="hidden" name="page" value="{$current_page}">

              <div class="row g-3">
                <div class="col-md-3">
                  <label class="form-label">Transaction Type</label>
                  <select name="type" class="form-control form-control-sm" onchange="document.opts.submit();">
                    <option value="">All transactions</option>
                    {section name=opt loop=$options}
                      <option value="{$options[opt].type}" {if $options[opt].selected}selected{/if}>{$options[opt].type_name}</option>
                    {/section}
                  </select>
                </div>

                {if $ecs}
                <div class="col-md-3">
                  <label class="form-label">eCurrency</label>
                  <select name="ec" class="form-control form-control-sm">
                    <option value="-1">All eCurrencies</option>
                    {section name=ec loop=$ecs}
                      <option value="{$ecs[ec].id}" {if $frm.ec eq $ecs[ec].id}selected{/if}>{$ecs[ec].name}</option>
                    {/section}
                  </select>
                </div>
                {/if}

                <div class="col-md-3">
                  <label class="form-label">From</label>
                  <div class="d-flex gap-1">
                    <select name="month_from" class="form-control form-control-sm">
                      {section name=month_from loop=$month}
                        <option value="{$smarty.section.month_from.index+1}" {if $smarty.section.month_from.index+1 == $frm.month_from}selected{/if}>{$month[month_from]}</option>
                      {/section}
                    </select>
                    <select name="day_from" class="form-control form-control-sm">
                      {section name=day_from loop=$day}
                        <option value="{$smarty.section.day_from.index+1}" {if $smarty.section.day_from.index+1 == $frm.day_from}selected{/if}>{$day[day_from]}</option>
                      {/section}
                    </select>
                    <select name="year_from" class="form-control form-control-sm">
                      {section name=year_from loop=$year}
                        <option value="{$year[year_from]}" {if $year[year_from] == $frm.year_from}selected{/if}>{$year[year_from]}</option>
                      {/section}
                    </select>
                  </div>
                </div>

                <div class="col-md-3">
                  <label class="form-label">To</label>
                  <div class="d-flex gap-1">
                    <select name="month_to" class="form-control form-control-sm">
                      {section name=month_to loop=$month}
                        <option value="{$smarty.section.month_to.index+1}" {if $smarty.section.month_to.index+1 == $frm.month_to}selected{/if}>{$month[month_to]}</option>
                      {/section}
                    </select>
                    <select name="day_to" class="form-control form-control-sm">
                      {section name=day_to loop=$day}
                        <option value="{$smarty.section.day_to.index+1}" {if $smarty.section.day_to.index+1 == $frm.day_to}selected{/if}>{$day[day_to]}</option>
                      {/section}
                    </select>
                    <select name="year_to" class="form-control form-control-sm">
                      {section name=year_to loop=$year}
                        <option value="{$year[year_to]}" {if $year[year_to] == $frm.year_to}selected{/if}>{$year[year_to]}</option>
                      {/section}
                    </select>
                  </div>
                </div>

                <div class="col-md-2 d-flex align-items-end">
                  <input type="submit" value="Go" class="btn btn-sm btn-primary">
                </div>
              </div>
            </form>

            <br><br>

            <table class="table table-bordered table-sm">
              <thead>
                <tr>
                  <th>Type</th>
                  <th>Amount</th>
                  <th>Date</th>
                </tr>
              </thead>
              <tbody>
                {if $qtrans > 0}
                  {section name=trans loop=$trans}
                    <tr>
                      <td><b>{$trans[trans].transtype}</b></td>
                      <td align="right"><b>{$currency_sign} {$trans[trans].actual_amount}</b> <img src="images/{$trans[trans].ec}.gif" height="17"></td>
                      <td align="center"><small>{$trans[trans].d}</small></td>
                    </tr>
                    <tr>
                      <td colspan="3" class="text-muted"><small>{$trans[trans].description}</small></td>
                    </tr>
                  {/section}
                {else}
                  <tr>
                    <td colspan="3" class="text-center">No transactions found</td>
                  </tr>
                {/if}
              </tbody>
              <tfoot>
                {if $qtrans > 0}
                  <tr>
                    <td colspan="2">For this period:</td>
                    <td align="right"><b>{$currency_sign} {$periodsum}</b></td>
                  </tr>
                {/if}
                <tr>
                  <td colspan="2">Total:</td>
                  <td align="right"><b>{$currency_sign} {$allsum}</b></td>
                </tr>
              </tfoot>
            </table>

            {if $colpages > 1}
              <div class="text-center mt-3">
                {if $prev_page > 0}
                  <a href="javascript:go('{$prev_page}')" class="btn btn-sm btn-light">&laquo;</a>
                {/if}
                {section name=p loop=$pages}
                  {if $pages[p].current == 1}
                    <span class="btn btn-sm btn-primary disabled">{$pages[p].page}</span>
                  {else}
                    <a href="javascript:go('{$pages[p].page}')" class="btn btn-sm btn-light">{$pages[p].page}</a>
                  {/if}
                {/section}
                {if $next_page > 0}
                  <a href="javascript:go('{$next_page}')" class="btn btn-sm btn-light">&raquo;</a>
                {/if}
              </div>
            {/if}

          </div>
        </div>
      </div>
    </div>
  </div>
</div>

{include file="footer.tpl"}
