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

// шаблон - вывод ссылками без разделитея
  function HTML_report_body($options=array())
  { $debug=(_IS_SYSTEM_IP)? 0:0;
    $usl=array() ;
    $usl[]='event_id='.$this->event_id ;
    if (MEMBER()->personal_viewer_name) $usl['account_personal_filter']='pkey in (select pkey from '.MEMBER()->personal_viewer_name.')' ;
    $usl_select=implode(' and ',$usl) ;
    $stats=execSQL('select _org_id,_org_name,event_status,count(pkey) as cnt from view_event_personals where '.$usl_select.' group by _org_id,event_status order by _org_name,event_status ',$debug,1) ;
    $arr=group_by_field('_org_id',$stats,'event_status') ;

    $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>Документы получены,<br>Проходят ПМО</th><th>Прошли ПМО</th><th>КВ</th></tr><?
          if (_sizeof($arr)) foreach($arr as $group_id=>$rec_stats) if ($group_id>0)
          {   $cnt_all=0 ;
              foreach($rec_stats as $rec_status) $cnt_all+=$rec_status['cnt'] ;
              $cnt_1=$rec_stats[1]['cnt'] ;
              $cnt_2=$rec_stats[2]['cnt'] ;
              $cnt_22=$rec_stats[22]['cnt'] ;
              $cnt_3=$rec_stats[3]['cnt']+$rec_stats[4]['cnt']+$rec_stats[5]['cnt'] ;
              $cnt_6=$rec_stats[6]['cnt']+$rec_stats[7]['cnt'];
              $cnt_8=$rec_stats[8]['cnt']+$rec_stats[9]['cnt'];
              $kv=$cnt_8/$cnt_all*100 ;
              ?><tr class="item">
                  <td class="left"><?echo $rec_status['_org_name']?></td>
                  <td><?echo ($cnt_all)? $cnt_all:'-'?></td>
                  <td><?echo ($cnt_1)? $cnt_1:'-'?></td>
                  <td><?echo ($cnt_2)? $cnt_2:'-'?></td>
                  <td><?echo ($cnt_22)? $cnt_22:'-'?></td>
                  <td><?echo ($cnt_3)? $cnt_3:'-'?></td>
                  <td><?echo ($cnt_6)? $cnt_6:'-'?></td>
                  <td><?echo ($cnt_8)? $cnt_8:'-'?></td>
                  <td><?echo round($kv,2)?> %</td>
              </tr><?
          }
      ?></table><?
      //damp_array($rec) ;
  }


}

?>
