{~@types=array(@receipt_sales=>'Чеки Продаж', @receipt_return=>'Чеки Возвратов', @receipt_cashin=>'Внесение в кассу', @receipt_cashout=>'Изъятие из кассы', @receipt_keg_connection=>'Подключение кега', @receipt_writeoff=>'Списание', 'receipt_remote'=>'Удалённо', @receipt_chpok=>'Вскрытие тары')~}
<div class="content2">
  <check if="{{in_array('changes/search', @authorization_user.module)}}">
  <form id="changes_search" name="canges_search" align="center" action="/changes/search" method="GET">
    <div class="order_hide"><b>Найти смену</b>:</div>
    <input type="text" name="dates" placeholder="Период" value="{{@GET.dates}}" autocomplete="off">
    <button>
      <i class="fas fa-search"></i>
    </button>
  </form>
  </check>
  <div class="reports" href="/receipts/reports">
    <div class="reload">
    <check if="{{@change}}">
      <true>
      <h1>Смена № {{@change.id}}</h1>
      <check if="{{in_array('changes/x', @authorization_user.module)}}">
      <p align="center" class="gray">
        Открыта {{date("d.m.Y H:i", @change.time_start)}}
        |
        <check if="{{@change.time_end>0}}">
        Закрыта {{date("d.m.Y H:i", @change.time_end)}}
        <br>
        </check>
        Наличность при открытии {{number_format(round(@change.cash_start, 2), 2 , '.', '')}}
        <check if="{{@change.time_end>0}}">
        |
        Наличность при закрытии {{number_format(round(@change.cash_end, 2), 2 , '.', '')}}
        </check>
      </p>
      {~@sum[1]=@change.cash_start~}
      {~@colspan=count(@report)+2~}
      {~if(@base_settings['cafe_mode']!=1)@colspan-=1~}
      <div class="mobile_scroll">
        <table class="work_table mobile_font_12">
          <tr>
            <th></th>
            <th>
              Начало периода
            </th>
            <repeat group="{{@report}}" key="{{@type}}" value="{{@r}}">
              <check if="{{@type!=@receipt_chpok || @base_settings['cafe_mode']==1}}">
            <th>
              {{@types[@type]}}
            </th>
              </check>
            </repeat>
            <th>
              Сумма
            </th>
          </tr>
          <tr>
            <th>
              Кол-во
            </th>
            <td align="center">
              1
            </td>
            <repeat group="{{@report}}" key="{{@type}}" value="{{@r}}">
              <check if="{{@type!=@receipt_chpok || @base_settings['cafe_mode']==1}}">
            <td align="center">
              {{@r['count']}}
              {~if(@type!='receipt_remote')@count+=@r['count']~}
            </td>
              </check>
            </repeat>
            <td align="center">
              {{@count}}
            </td>
          </tr>
          <repeat group="{{@paymentmethods}}" key="{{@pid}}" value="{{@pay}}">
          <tr>
            <th width="150">
              {{@pay['title']}}
              <check if="{{@pay['cash']==0 && isset(@epays) && count(@epays)>1}}">
              <p align="right"><small><a class="show_epays_report"><span class="txt_show">подробнее</span><span class="txt_hide">скрыть</span></a></small></p>
              </check>
            </th>
            <td align="center">
              {{@pay['cash']==1?number_format(round(@change.cash_start, 2), 2 , '.', ''):'0.00'}}
            </td>
            <repeat group="{{@report}}" key="{{@type}}" value="{{@r}}">
              <check if="{{@type!=@receipt_chpok || @base_settings['cafe_mode']==1}}">
            <td align="center">
              {~@r['pay'][@pid]=round(@r['pay'][@pid], 2)~}
              {{number_format(abs(@r['pay'][@pid]), 2, '.', '')}}
              {~if(@type!='receipt_remote')if(@type==@receipt_return) @sum[@pay['cash']]-=@r['pay'][@pid]; else @sum[@pay['cash']]+=@r['pay'][@pid];~}
            </td>
              </check>
            </repeat>
            <td align="center">
              {{number_format(@sum[@pay['cash']], 2, '.', '')}}
            </td>
          </tr>
            <check if="{{@pay['cash']==0 && isset(@epays) && count(@epays)>1}}">
              <repeat group="{{@epays}}" value="{{@epay}}">
          <tr class="epays_report">
            <th align="right">
              - <i>{{@epay['title']}}</i>
            </th>
            <td align="center">
              <i>0.00</i>
            </td>
            <repeat group="{{@report}}" key="{{@type}}" value="{{@r}}">
              <check if="{{@type!=@receipt_chpok || @base_settings['cafe_mode']==1}}">
            <td align="center">
              {~@r['epay'][@epay['id']]['sum']=round(@r['epay'][@epay['id']]['sum'], 2)~}
              <i>{{number_format(abs(@r['epay'][@epay['id']]['sum']), 2, '.', '')}}</i>
              {~if(@type!='receipt_remote')if(@type==@receipt_return) @epay_sum[@epay['id']]-=@r['epay'][@epay['id']]['sum']; else @epay_sum[@epay['id']]+=@r['epay'][@epay['id']]['sum'];~}
            </td>
              </check>
            </repeat>
            <td align="center">
              <i>{{number_format(@epay_sum[@epay['id']], 2, '.', '')}}</i>
            </td>
          </tr>
              </repeat>
            </check>
          </repeat>
          <tr>
            <th>
              Сумма
            </th>
            <td align="center">
              {{number_format(round(@change.cash_start, 2), 2 , '.', '')}}
              {~@total=@change.cash_start~}
            </td>
            <repeat group="{{@report}}" key="{{@type}}" value="{{@r}}">
              <check if="{{@type!=@receipt_chpok || @base_settings['cafe_mode']==1}}">
            <td align="center">
              {{number_format(abs(@r['sum']), 2, '.', '')}}
              {~@total+=abs(@r['sum'])~}
            </td>
              </check>
            </repeat>
            <td align="center">
              
            </td>
          </tr>
          <tr>
            <td colspan="2" align="right">
              <b>Выручка</b>
            </td>
            <td colspan="2" align="center">
              {{number_format(@report[1]['sum']-@report[2]['sum'], 2, '.', '')}}
            </td>
            <td colspan="{{@colspan-3}}"></td>
          </tr>
          <tr>
            <td colspan="{{@colspan}}" align="right">
              <b>Наличность в кассе</b>
            </td>
            <td align="center">
              <big>{{number_format(round(@sum[1], 2), 2, '.', '')}}</big>
            </td>
          </tr>
        </table>
      </div>
      </check>
      <br>
      <check if="{{!@change.time_end}}">
        <true>
      <p align="center">
        <check if="{{in_array('changes/x', @authorization_user.module)}}">
        <input type="button" class="show_window" href="/changes/x" value="X-отчет">
        </check>
        <check if="{{in_array('changes/z', @authorization_user.module)}}">
        <input type="button" class="show_window" href="/messages/continue?uri={{urlencode("/changes/z")}}" value="Закрыть смену">
        </check>
      </p>
        <check if="{{in_array('receipts/salesreport', @authorization_user.module)}}">
      <p align="center">
      <input type="button" class="show_window" href="/receipts/salesreport?change_id={{@change.id}}" value="Отчет за смену">
      </p>
        </check>
        </true>
        <false>
          <check if="{{in_array('receipts/salesreport', @authorization_user.module)}}">
      <p align="center">
      <input type="button" class="show_window" href="/receipts/salesreport?change_id={{@change.id}}" value="Отчет за смену">
      </p>
          </check>
        </false>
      </check>
      </true>
      <false>
        <check if="{{!@error}}">
          <true>
      <h1>Смена закрыта</h1>
          </true>
          <false>
      <p class="false" align="center">{{@error}}</p>
          </false>
        </check>
      <check if="{{in_array('changes/open', @authorization_user.module)}}">
      <p align="center">
        <input type="button" class="send_ajax" href="/changes/open" value="Открыть смену">
      </p>
      </check>
      </false>
    </check>
    </div>
  </div>
</div>

<script type="text/javascript" src="/ui/scripts/moment.min.js"></script>
<script type="text/javascript" src="/ui/scripts/daterangepicker.min.js"></script>
<link rel="stylesheet" type="text/css" href="/ui/css/daterangepicker.css" />
<script>
calendar($('input[name="dates"]'));
</script>
