<?php
/**
 * The stat view file of attend module of ZDOO.
 *
 * @copyright   Copyright 2009-2022 青岛易软天创网络科技有限公司(QingDao Nature Easy Soft Network Technology Co,LTD, www.cnezsoft.com)
 * @license     ZPL (http://zpl.pub/page/zplv12.html)
 * @author      Wangyuting <wangyuting@easycorp.ltd>
 * @package     attend
 * @version     $Id$
 * @link        http://www.zdoo.com
 */
?>
<?php include '../../common/view/header.html.php';?>
<?php $this->app->loadLang('search');?>
<div class='main-row'>
  <?php include 'side.statistic.html.php';?>
  <div class='main-col'>
    <div class='panel col-md-12'>
      <div class='panel-heading no-padding-l'>
        <div class='input-group w-500px'>
          <div class='input-group-addon'><?php echo $lang->attend->year;?></div>
          <?php echo html::select('year', $yearList, $year, "class='form-control chosen'");?>
          <div class='input-group-addon'><?php echo $lang->attend->dept;?></div>
          <?php echo html::select('dept', $deptList, $dept, "class='form-control chosen'");?>
          <div class='input-group-btn'><?php echo html::a(inlink('latestat', "year=$year&dept=$dept"), $lang->search->common, "class='btn btn-primary btn-search'");?></div>
          <script>$('.chosen').chosen();</script>
        </div>
      </div>
      <table id='lateStatTable' class='table table-bordered table-hover table-striped table-report'>
        <thead>
          <tr class='text-center'>
            <th class='w-120px'><?php echo $lang->user->dept;?></th>
            <th class='w-120px'><?php echo $lang->user->account;?></th>
            <th class='w-120px'><?php echo $lang->attend->type;?></th>
            <?php foreach($lang->datepicker->monthNames as $month):?>
            <th class='w-80px'><?php echo $month;?></th>
            <?php endforeach;?>
            <th class='w-80px'><?php echo $lang->total;?></th>
          </tr>
        </thead>
        <?php $total = array();?>
        <?php foreach($reportData as $deptID => $accountReport):?>
        <?php $rowCount = count($accountReport);?>
        <?php $subTotal = array();?>
        <?php foreach($accountReport as $account => $report):?>
        <?php foreach($lang->attend->lateStatType as $type => $typeLang):?>
        <?php $rightTotal = 0;?>
        <tr class='text-center text-middle'>
          <?php if($rowCount):?>
          <th rowspan='<?php echo ($rowCount + 1) * 2;?>'><?php echo zget($depts, $deptID);?></th>
          <?php $rowCount = 0;?>
          <?php endif;?>
          <?php if($type == 'count'):?>
          <th rowspan='2'><?php echo zget($users, $account);?></th>
          <?php endif;?>
          <th><?php echo $typeLang;?></th>
          <?php foreach(range(1, 12) as $i):?>
          <td>
            <?php if(isset($report[$i][$type])):?>
            <?php echo $report[$i][$type];?>
            <?php $rightTotal += $report[$i][$type];?>
            <?php $total[$i][$type] = !empty($total[$i][$type]) ? $total[$i][$type] + $report[$i][$type] : $report[$i][$type];?>
            <?php $subTotal[$i][$type] = !empty($subTotal[$i][$type]) ? $subTotal[$i][$type] + $report[$i][$type] : $report[$i][$type];?>
            <?php endif;?>
          </td>
          <?php endforeach;?>
          <td><?php echo $rightTotal;?></td>
        </tr>
        <?php endforeach;?>
        <?php endforeach;?>
        <?php foreach($lang->attend->lateStatType as $type => $typeLang):?>
        <?php $rightTotal = 0;?>
        <tr class='text-center text-middle'>
          <?php if($type == 'count'):?>
          <th rowspan='2'><?php echo $lang->attend->subtotal;?></th>
          <?php endif;?>
          <th><?php echo $typeLang;?></th>
          <?php foreach(range(1, 12) as $i):?>
          <td>
            <?php if(isset($subTotal[$i][$type])):?>
            <?php echo $subTotal[$i][$type];?>
            <?php $rightTotal += $subTotal[$i][$type];?>
            <?php endif;?>
          </td>
          <?php endforeach;?>
          <td><?php echo $rightTotal;?></td>
        </tr>
        <?php endforeach;?>
        <?php endforeach;?>
        <?php foreach($lang->attend->lateStatType as $type => $typeLang):?>
        <?php $rightTotal = 0;?>
        <tr class='text-center text-middle'>
          <?php if($type == 'count'):?>
          <th colspan='2' rowspan='2'><?php echo $lang->total;?></th>
          <?php endif;?>
          <th><?php echo $typeLang;?></th>
          <?php foreach(range(1, 12) as $i):?>
          <td>
            <?php if(isset($total[$i][$type])):?>
            <?php echo $total[$i][$type];?>
            <?php $rightTotal += $total[$i][$type];?>
            <?php endif;?>
          </td>
          <?php endforeach;?>
          <td><?php echo $rightTotal;?></td>
        </tr>
        <?php endforeach;?>
      </table>
      </div>
    </div>
  </div>
</div>
<?php include '../../common/view/footer.html.php';?>
