<?php
include_once("c_pl.php");
class c_page_cab_pl_sign_stats extends c_page_cab_pl
{
    public $h1 = 'Путевой лист - статистика по ожиданию подписи документов';

    function block_main()
    {
        $this->page_title();

        $stats=execSQL('   select dr.mo_group_id as group_id,grp.obj_name as group_name,
                           acc.pkey,acc.obj_name as account_name,
                           acc.time_login,acc.time_logout,acc.smena,
                           count(distinct pk.pkey) as cnt,
                           min(pk.c_data) as date_from,
                           max(pk.c_data) as date_to
                           from  pl_packets pk
                           inner join pl_packet_driver dr on dr.packet_id=pk.pkey
                           inner join obj_site_account acc on acc.pkey=dr.mo_doctor_id
                           left join obj_site_account grp on grp.pkey=dr.mo_group_id
                           where pk.status=2 
                             and dr.mo_doctor_id is not null and dr.mo_doctor_id>0
                             and dr.mo_id is not null and dr.mo_id>0
                           group by dr.mo_group_id,grp.obj_name,acc.pkey,acc.obj_name,
                                    acc.time_login,acc.time_logout,acc.smena
                           order by count(distinct pk.pkey) desc 
                       ',0,1) ;
        //print_2x_arr($stats);
        $all=0 ; $date_from=0 ; $date_to=0;
        ?><table class="basic fz_small">
            <tr>
                <th>Группа</th>
                <th>Фельдшер</th>
                <th>Вход</th>
                <th>Выход</th>
                <th>Статус смены</th>
                <th>Число пакетов на подпись</th>
                <th>Дата, от</th>
                <th>Дата, до</th>
            </tr>
        <?
        if (sizeof($stats)>0) foreach ($stats as $rec)
            {
               ?><tr>
                    <td class="left"><?echo $rec['group_name']?></td>
                    <td class="left"><?echo $rec['account_name']?></td>
                    <td><?echo ($rec['time_login'])? date('d.m.Y H:i',$rec['time_login']):'-'?></td>
                    <td><?echo ($rec['time_logout'])? date('d.m.Y H:i',$rec['time_logout']):'-'?></td>
                    <td><?echo $_SESSION['ARR_smena_status'][$rec['smena']]?></td>
                    <td><?echo $rec['cnt'] ; ?></td>
                    <td><?echo date('d.m.Y H:i',$rec['date_from'])?></td>
                    <td><?echo date('d.m.Y H:i',$rec['date_to'])?></td>
                </tr><?
                $all+=$rec['cnt'];
                if (!$date_from) $date_from=$rec['date_from'] ;
                if ($date_from and $date_from>$rec['date_from']) $date_from=$rec['date_from'] ;
                if ($date_to<$rec['date_to']) $date_to=$rec['date_to'] ;
            }
        ?><tr>
            <td colspan="5">ВСЕГО:</td>
            <td><?echo $all?></td>
            <td><?if ($date_from) echo date('d.m.Y H:i',$date_from)?></td>
            <td><?if ($date_to) echo date('d.m.Y H:i',$date_to)?></td>
         </tr>
        </table><?
        if (!sizeof($stats)) echo 'Пакеты на подпись отсутствуют' ;
    }


}


?>
