<?php
class report_event_instruktion_info extends c_report
{
 var $title='Статистика прохождения инструктажа' ;
 var $view_by_space_filter=1 ;

 // шаблон - вывод ссылками без разделитея
  function view_as_HTML($options=array())
  { $debug=(_IS_SYSTEM_IP)? 0:0;
    $_usl=array() ;
    $_usl[]='event_id='.$this->event_id ;
    $_usl[]='(fired_data=0 or fired_data is null)';
    //$_usl[]='org_group_id in ('.ACCOUNTS()->tree[MEMBER()->cur_group_id]->get_list_child().')' ;   // фильтр сортрудников по группе ЭСМО
    if (MEMBER()->personal_viewer_name) $_usl['account_personal_filter']='personal_id in (select pkey from '.MEMBER()->personal_viewer_name.')' ; // фильтр сортрудников аккаунта

    $usl=implode(' and ',$_usl) ;

    $stats=execSQL('select org_group_id,org_group_name,event_status,count(pkey) as cnt from view_event_personals where '.$usl.' group by org_group_id,event_status order by org_group_name',$debug,1) ;
    $arr=group_by_field('org_group_id',$stats,'event_status') ;
    //damp_array($arr) ;


    $id=($options['id'])? 'id='.$options['id']:'' ;
    ?><table class="basic fz_small full auto"<?echo $id?>>
        <tr><th style="text-align:left;">АТП: <input type="text" id="table_fast_search_in_td"></th><th>Подлежат участию</th><th>Направлены</th><th>Проходят</th><th>Прошли</th><th>Всего</th><th>КВ</th></tr><?
          if (_sizeof($arr)) foreach($arr as $group_id=>$rec_stats)
          {   $cnt_all=0 ;
              foreach($rec_stats as $rec_status) $cnt_all+=$rec_status['cnt'] ;
              $cnt_in=$rec_stats[1]['cnt'] ;
              $cnt_start=$rec_stats[2]['cnt']+$rec_stats[3]['cnt'] ;
              $cnt_process=$rec_stats[4]['cnt']+$rec_stats[5]['cnt']+$rec_stats[6]['cnt'] ;
              $cnt_end=$rec_stats[7]['cnt']+$rec_stats[8]['cnt'];
              $kv=$cnt_end/$cnt_all*100 ;
              ?><tr class="item">
                  <td class="left"><?echo $rec_status['org_group_name']?></td>
                  <td><?echo ($cnt_in)? $cnt_in:'-'?></td>
                  <td><?echo ($cnt_start)? $cnt_start:'-'?></td>
                  <td><?echo ($cnt_process)? $cnt_process:'-'?></td>
                  <td><?echo ($cnt_end)? $cnt_end:'-'?></td>
                  <td><?echo ($cnt_all)? $cnt_all:'-'?></td>
                  <td><?echo round($kv,2)?> %</td>
              </tr><?
          }
      ?></table><?
  }


}

?>
