{* Smarty *}

{literal}
<script type="text/javascript">
//<![CDATA[
var chart;
var tbl;
$(function() {
  tbl = $('#ReportSvtForWritteoffDiv').html();
  $("#ReportSvtForWritteoffButtonRadio").buttonset();
  $("#ReportSvtForWritteoffButtonChart").click(function() {
    $("#ReportSvtForWritteoffDiv").hide();
    ChartsInit(tbl);
  });
  $("#ReportSvtForWritteoffButtonTable").click(function() {
    ChartsDestroy();
    $("#ReportSvtForWritteoffDiv").show();
    $("#ReportSvtForWritteoff").show();
    tableToGrid("#ReportSvtForWritteoff", {height:345, caption:'Списание по типам СВТ'});
  });
  $("#ReportSvtForWritteoffButtonChart").click();
});

Highcharts.visualize = function(table, options) {
  options.xAxis.categories = [];
  //$('tbody th', table).each( function(i) {
  $('tbody tr td:first-child', table).each( function(i) {
    options.xAxis.categories.push(this.innerHTML);
  });

  options.series = [];
  $('tr', table).each( function(i) {
    var tr = this;
    $('th, td', tr).each( function(j) {
      if (j > 0) {
        if (i == 0) {
          options.series[j - 1] = { 
            name: this.innerHTML,
            data: []
          };
        } else {
          options.series[j - 1].data.push(parseFloat(this.innerHTML));
        }
      }
    });
  });

  chart = new Highcharts.Chart(options);
}

//$(function(){
function ChartsInit(tbl){
  $('#ReportSvtForWritteoffDiv').html(tbl);
  var table = $('#ReportSvtForWritteoff'),
  options = {
    chart: {
       renderTo: 'ReportSvtForWritteoffChartsContainer',
       defaultSeriesType: 'column'
    },
    colors: ['#89A54E', '#AA4643'],
    title: {
       text: 'Списание по типам СВТ'
    },
    xAxis: {
       labels: {
       rotation: -45,
       align: 'right',
       style: {
           fontSize: '12px',
           fontFamily: 'Verdana, sans-serif'
       }
      }
    },
    yAxis: {
      min: 0,
       title: {
          text: 'Количество'
       }
    },
    tooltip: {
       formatter: function() {
           return ''+
               this.series.name +': '+ this.y +' ('+ Math.round(this.percentage) +'%)';
       }
    },
    plotOptions: {
       column: {
           stacking: 'percent'
       }
    }
  };
  Highcharts.visualize(table, options);
}//);
  
function ChartsDestroy(){
  chart && chart.destroy();
  chart = null;
}  
//]]>
</script>
{/literal}

<div id="ReportSvtForWritteoffButtonRadio">
  <input type="radio" id="ReportSvtForWritteoffButtonChart" name="ReportSvtForWritteoffButtonRadio"><label for="ReportSvtForWritteoffButtonChart">График</label>
  <input type="radio" id="ReportSvtForWritteoffButtonTable" name="ReportSvtForWritteoffButtonRadio" checked="checked"><label for="ReportSvtForWritteoffButtonTable">Таблица</label>
</div>
<div id="ReportSvtForWritteoffDiv" style="width: 800px; margin: 0 auto;">
  <table id="ReportSvtForWritteoff" style="display: none;">
    <thead>
      <tr>
        <th></th>
        <th>Остальные</th>
        <th>СВТ для списания</th>
      </tr>
    </thead>
    <tbody>
    {foreach $ArrSvtTypeAll as $key => $val}
      {if $ArrSvtType.$key.svt_count}
        {$VarCountWriteoff = $ArrSvtType.$key.svt_count}
      {else}
        {$VarCountWriteoff = 0}
      {/if}
      <tr>
        <td>{$val.svttype_name}(лет: {$val.svttype_writeoff})</td>
        <td>{$val.svt_count - $VarCountWriteoff}</td>
        <td>{$VarCountWriteoff}</td>
      </tr>
    {/foreach}
    </tbody>
  </table>
</div>
<div id="ReportSvtForWritteoffChartsContainer" style="width: 800px; margin: 0 auto;"></div>