<? global $config;?>
<div class="panel panel-info panel-border top">
  <div class="panel-heading" style="height: auto; padding-bottom: 4px;">
    <div class="row" style="color: #666666;">
      <div class="col-xs-12 col-sm-6 col-md-4 text-centred-xs">
        <span class="pr25">Netto ogółem: <b><?= $this -> _profit;?></b></span>
      </div>
      <div class="col-xs-12 col-sm-12 col-md-4 text-centred-xs">
        <select name="month_global" class="form-control ranker-select" id="month_global" onChange="document.location.href='./?p=ranker_summary&id=<?= $this -> _site['id'];?>&year=' + $( '#year_global' ).val() + '&month=' + $( this ).val();">
          <option value="01" <? if ( $this -> _month == '01' ) echo 'selected="selected"'; ?>>Styczeń</option>
          <option value="02" <? if ( $this -> _month == '02' ) echo 'selected="selected"'; ?>>Luty</option>
          <option value="03" <? if ( $this -> _month == '03' ) echo 'selected="selected"'; ?>>Marzec</option>
          <option value="04" <? if ( $this -> _month == '04' ) echo 'selected="selected"'; ?>>Kwiecień</option>
          <option value="05" <? if ( $this -> _month == '05' ) echo 'selected="selected"'; ?>>Maj</option>
          <option value="06" <? if ( $this -> _month == '06' ) echo 'selected="selected"'; ?>>Czerwiec</option>
          <option value="07" <? if ( $this -> _month == '07' ) echo 'selected="selected"'; ?>>Lipiec</option>
          <option value="08" <? if ( $this -> _month == '08' ) echo 'selected="selected"'; ?>>Sierpień</option>
          <option value="09" <? if ( $this -> _month == '09' ) echo 'selected="selected"'; ?>>Wrzesień</option>
          <option value="10" <? if ( $this -> _month == '10' ) echo 'selected="selected"'; ?>>Październik</option>
          <option value="11" <? if ( $this -> _month == '11' ) echo 'selected="selected"'; ?>>Listopad</option>
          <option value="12" <? if ( $this -> _month == '12' ) echo 'selected="selected"'; ?>>Grudzień</option>
        </select>
        <select name="year_global" id="year_global" class="form-control ranker-select" onChange="document.location.href='./?p=ranker_summary&id=<?= $this -> _site['id'];?>&year=' + $( this ).val() + '&month=' + $( '#month_global' ).val();">
          <? for ( $i = date( 'Y') - 2; $i <= date( 'Y') + 2; $i++ ):?>
            <option value="<?= $i;?>" <? if ( $i == $this -> _year ) echo 'selected="selected"'; ?>><?=$i;?></option>
          <? endfor;?>
        </select>
      </div>
    </div>
  </div>
</div>
<div class="row auto-clear">
  <? if ( is_array( $this -> _clients ) ): foreach ( $this -> _clients as $client ):?>
    <? if ( $client['type'] != 2 ):?>
      <div class="col-xs-12 col-sm-6 col-lg-4">
        <div class="panel panel-info">
          <div class="panel-heading">
            <span class="panel-title"><?= $client['login'];?></span>
          </div>
          <div class="panel-body p0">
            <table class="table table-bordered table-condensed table-striped table-hover">
              <tbody>
                <? $client_sum = 0;?>
                <? if ( is_array( $client['sites'] ) ): foreach ( $client['sites'] as $site ):?>
                  <tr>
                    <td><?= $site['name'];?><? if ( $site['subscription'] > 0 ) echo ' (<span class="text-danger">Ab: ' . \S::number_display( $site['subscription'] ) . '</span>)';?></td>
                    <td class="text-right <? if ( $site['subscription'] > 0 ) echo 'text-system';?>">
                      <?
                      $site_sum = 0;

                      if ( is_array( $site['phrases'] ) ) foreach ( $site['phrases'] as $phrase )
                      {
                        $discount = '';

                        if ( $site['discount'] )
                          $discount = $site['discount'];

                        if ( $phrase['discount'] )
                          $discount = $phrase['discount'];

                        if ( is_array( $phrase['prices'] ) ) foreach ( $phrase['prices'] as $price )
                        {
                          $price_c  = \S::number( $price['price'] - \S::number( $price['price'] * $discount / 100 ) );  
                          $site_sum = $site_sum + $price_c * $price['count'];
                        }
                      }
                      $client_sum = $client_sum + $site_sum + $site['subscription'];
                      echo \S::number_display( $site_sum + $site['subscription'] );
                      ?>
                    </td>
                    <td class="text-right <? if ( $site['subscription'] > 0 ) echo 'text-system';?>">
                      <?= \S::number_display( ( $site_sum + $site['subscription'] ) * $config['profit']['vat'] );?>
                    </td>
                  </tr>
                <? endforeach; endif;?>
                <tr>
                  <td class="text-right">Razem:</td>
                  <td class="alert-dark dark text-right"><?= \S::number_display( $client_sum );?></td>
                  <td class="alert-dark dark text-right"><?= \S::number_display( $client_sum * $config['profit']['vat'] );?></td>
                </tr>
              </tbody>
            </table>
          </div>
        </div>
      </div>
    <? endif;?>
  <? endforeach; endif;?>
</div>