<?php
/**
 * The stat view file of attend module of ZDOO.
 *
 * @copyright   Copyright 2009-2018 青岛易软天创网络科技有限公司(QingDao Nature Easy Soft Network Technology Co,LTD, www.cnezsoft.com)
 * @license     ZPL (http://zpl.pub/page/zplv12.html)
 * @author      Tingting Dai <daitingting@xirangit.com>
 * @package     attend
 * @version     $Id$
 * @link        http://www.zdoo.com
 */
?>
<?php include '../../common/view/header.html.php';?>
<?php include '../../../sys/common/view/treeview.html.php';?>
<?php js::set('mode', $mode);?>
<?php js::set('monthList', $monthList);?>
<?php $this->app->loadLang('search');?>
<div id='menuActions'>
  <?php commonModel::printLink('attend', 'exportstat', "data=$currentYear$currentMonth", "{$lang->attend->export}", "class='iframe btn btn-primary'")?>
</div>
<div class='main-row'>
  <?php include 'side.statistic.html.php';?>
  <div class='main-col'>
    <?php if($waitReviews):?>
    <table class='table table-borderless'>
      <?php foreach($waitReviews as $module):?>
      <?php $reviewedBy   = $module == 'attend' ? zget($config->attend, 'reviewedBy', '') : $this->loadModel($module, 'oa')->getReviewedBy();?>
      <?php $reviewMethod = $module == 'attend' ? 'waitReview' : 'browseReview';?>
      <tr>
        <td>
          <?php printf($lang->attend->waitReviews, $lang->$module->common);?>
          <?php if(($this->app->user->admin == 'super') or ($reviewedBy == $this->app->user->account && commonModel::hasPriv($module, $reviewMethod))) echo html::a(helper::createLink($module, $reviewMethod), $lang->leave->review, "class='btn btn-primary'");?>
        </td>
      </tr>
      <?php endforeach;?>
    </table>
    <?php else:?>
    <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, $currentYear, "class='form-control chosen'");?>
          <div class='input-group-addon'><?php echo $lang->attend->month;?></div>
          <?php echo html::select('month', $monthList[$currentYear], $currentMonth, "class='form-control chosen'");?>
          <div class='input-group-btn'><?php echo html::a(inlink('attendstat', "month=$month"), $lang->search->common, "class='btn btn-primary btn-search'");?></div>
          <script>$('.chosen').chosen();</script>
        </div>
        <?php if($mode == 'edit'):?>
        <div class='input-group w-300px update-paid'>
          <span class='input-group-addon'><?php echo $lang->attend->paidDays;?></span>
          <?php echo html::number('paidDays', '', "class='form-control' min='0.1' max='31' step='0.1'");?>
          <span class='input-group-btn'><a href='javascript:;' class='btn btn-secondary btn-update-paid'><?php echo $lang->attend->updatePaid;?></a></span>
        </div>
        <?php endif;?>
      </div>
      <form id='statForm' method='post' action='<?php echo $this->createLink('attend', 'saveStat', "month=$month")?>'>
        <table class='table table-bordered datatable' id='attendStat' data-fixed-left-width='300' data-fixed-right-width='100'>
          <thead>
            <tr>
              <th class='text-center text-middle'><?php echo $lang->user->realname;?></th>
              <th class='text-center'><?php echo $lang->attend->deserveDays;?></th>
              <th class='text-center'><?php echo $lang->attend->actualDays;?></th>
              <th class='text-center'><?php echo $lang->attend->paidDays;?></th>
              <th class='text-center flex-col' data-width='90'><?php echo $lang->attend->statusList['normal']?></th>
              <th class='text-center flex-col' data-width='90'><?php echo $lang->attend->statusList['late'];?></th>
              <th class='text-center flex-col' data-width='90'><?php echo $lang->attend->statusList['early'];?></th>
              <th class='text-center flex-col' data-width='90'><?php echo $lang->attend->statusList['absent'];?></th>
              <th class='text-center flex-col' data-width='90'><?php echo $lang->attend->statusList['trip'];?></th>
              <th class='text-center flex-col' data-width='90'><?php echo $lang->attend->statusList['egress'];?></th>
              <th class='text-center flex-col' data-width='90'><?php echo $lang->leave->paid;?></th>
              <th class='text-center flex-col' data-width='90'><?php echo $lang->leave->unpaid;?></th>
              <th class='text-center flex-col' data-width='90'><?php echo $lang->attend->toMakeup;?></th>
              <th class='text-center flex-col' data-width='90'><?php echo $lang->overtime->typeList['time'];?></th>
              <th class='text-center flex-col' data-width='90'><?php echo $lang->overtime->typeList['rest'];?></th>
              <th class='text-center flex-col' data-width='90'><?php echo $lang->overtime->typeList['holiday'];?></th>
              <th class='text-center flex-col' data-width='90'><?php echo $lang->attend->statusList['lieu'];?></th>
              <?php if($mode == 'view' && $currentMonth):?>
              <th class='text-center' data-width='100'><?php echo $lang->actions;?></th>
              <?php endif;?>
            </tr>
          </thead>
          <tbody>
            <?php foreach($stat as $account => $accountStat):?>
            <?php if(!isset($users[$account])) continue;?>
            <tr class='view text-center'>
              <td class='text-middle'><?php echo $users[$account];?></td>
              <td><?php echo $accountStat->deserve;?></td>
              <td><?php echo $accountStat->actual;?></td>
              <td><?php echo $accountStat->paid;?></td>
              <td><?php echo $accountStat->normal;?></td>
              <td><?php echo $accountStat->late;?></td>
              <td><?php echo $accountStat->early;?></td>
              <td><?php echo $accountStat->absent;?></td>
              <td><?php echo $accountStat->trip;?></td>
              <td><?php echo $accountStat->egress;?></td>
              <td><?php echo $accountStat->paidLeave;?></td>
              <td><?php echo $accountStat->unpaidLeave;?></td>
              <td><?php echo $accountStat->toMakeup;?></td>
              <td><?php echo $accountStat->timeOvertime;?></td>
              <td><?php echo $accountStat->restOvertime;?></td>
              <td><?php echo $accountStat->holidayOvertime;?></td>
              <td><?php echo $accountStat->lieu;?></td>
              <?php if($mode == 'view' && $currentMonth):?>
              <td><?php echo html::a('javascript:;', $lang->edit, "class='singleEdit'")?></td>
              <?php endif;?>
            </tr>
            <tr class='edit text-center hidden'>
              <td class='text-middle'><?php echo $users[$account];?></td>
              <td><?php echo html::input("deserve[$account]", $accountStat->deserve, "class='form-control'");?></td>
              <td><?php echo html::input("actual[$account]", $accountStat->actual, "class='form-control'");?></td>
              <td><?php echo html::input("paid[$account]", $accountStat->paid, "class='form-control'");?></td>
              <td><?php echo html::input("normal[$account]", $accountStat->normal, "class='form-control'");?></td>
              <td><?php echo html::input("late[$account]", $accountStat->late, "class='form-control'");?></td>
              <td><?php echo html::input("early[$account]", $accountStat->early, "class='form-control'");?></td>
              <td><?php echo html::input("absent[$account]", $accountStat->absent, "class='form-control'");?></td>
              <td><?php echo html::input("trip[$account]", $accountStat->trip, "class='form-control'");?></td>
              <td><?php echo html::input("egress[$account]", $accountStat->egress, "class='form-control'");?></td>
              <td><?php echo html::input("paidLeave[$account]", $accountStat->paidLeave, "class='form-control'");?></td>
              <td><?php echo html::input("unpaidLeave[$account]", $accountStat->unpaidLeave, "class='form-control'");?></td>
              <td><?php echo html::input("toMakeup[$account]", $accountStat->toMakeup, "class='form-control'");?></td>
              <td><?php echo html::input("timeOvertime[$account]", $accountStat->timeOvertime, "class='form-control'");?></td>
              <td><?php echo html::input("restOvertime[$account]", $accountStat->restOvertime, "class='form-control'");?></td>
              <td><?php echo html::input("holidayOvertime[$account]", $accountStat->holidayOvertime, "class='form-control'");?></td>
              <td><?php echo html::input("lieu[$account]", $accountStat->lieu, "class='form-control'");?></td>
              <?php if($mode == 'view' && $currentMonth):?>
              <td class='singleSave hidden'><?php echo html::submitButton();?></td>
              <?php endif;?>
            </tr>
            <?php endforeach;?>
          </tbody>
        </table>
        <?php if($currentMonth):?>
        <div class='table-footer text-center form-actions'>
          <?php if($mode == 'view') echo html::a($this->createLink('attend', 'attendstat', "month=$month&mode=edit"), $lang->edit, "class='btn btn-primary'");?>
          <?php if($mode == 'edit') echo html::submitButton();?>
        </div>
        <?php endif;?>
      </form>
    </div>
    <?php endif;?>
  </div>
</div>
<?php include '../../common/view/footer.html.php';?>
