<?php
/**
 * The browse view file of overtime 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     overtime
 * @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('confirmReview', $lang->overtime->confirmReview)?>
<div id='menuActions'>
  <?php commonModel::printLink('oa.overtime', 'export', "mode=all", $lang->exportIcon . $lang->export, "class='btn btn-secondary iframe' data-width='700'");?>
  <?php commonModel::printLink('oa.overtime', 'create', "", "<i class='icon icon-plus'></i> {$lang->overtime->create}", "data-toggle='modal' class='btn btn-primary'")?>
</div>
<?php if($type != 'browseReview'):?>
<div class='main-row'>
  <div class='side-col'>
    <div class='panel'>
      <div class='panel-body'>
        <ul class='tree' data-collapsed='true'>
          <?php foreach($yearList as $year):?>
          <li class='<?php echo $year == $currentYear ? 'active' : ''?>'>
            <?php commonModel::printLink('oa.overtime', $type, "date=$year", $year);?>
            <ul>
              <?php foreach($monthList[$year] as $month):?>
              <li class='<?php echo ($year == $currentYear and $month == $currentMonth) ? 'active' : ''?>'>
                <?php commonModel::printLink('oa.overtime', $type, "date=$year$month", $year . $month);?>
              </li>
              <?php endforeach;?>
            </ul>
          </li>
          <?php endforeach;?>
        </ul>
      </div>
    </div>
  </div>
  <div class='main-col'>
<?php endif;?>
    <div class='panel main-table' data-ride='table'>
      <?php $canBatchReview = ($overtimeList && $type == 'browseReview' && commonModel::hasPriv('overtime', 'batchReview'));?>
      <?php if($canBatchReview):?>
      <form id='batchReviewForm' method='post' action='<?php echo inlink('batchReview', 'status=pass');?>'>
      <?php endif;?>
        <table class='table has-sort-head' id='overtimeTable'>
          <thead>
            <tr class='text-center'>
              <?php $vars = "&date={$date}&orderBy=%s&recTotal=$pager->recTotal&recPerPage=$pager->recPerPage&pageID=$pager->pageID";?>
              <th class='w-70px text-left'>
                <?php if($canBatchReview):?>
                <div class='checkbox-primary check-all' title='<?php echo $this->lang->selectAll;?>'><label></label></div>
                <?php endif;?>
                <?php commonModel::printOrderLink('id', $orderBy, $vars, $lang->overtime->id);?>
              </th>
              <th class='w-90px'><?php commonModel::printOrderLink('createdBy', $orderBy, $vars, $lang->overtime->createdBy);?></th>
              <th class='w-100px'><?php echo $lang->user->dept;?></th>
              <th class='w-90px'><?php commonModel::printOrderLink('type', $orderBy, $vars, $lang->overtime->type);?></th>
              <th class='w-120px'><?php commonModel::printOrderLink('begin', $orderBy, $vars, $lang->overtime->begin);?></th>
              <th class='w-120px'><?php commonModel::printOrderLink('end', $orderBy, $vars, $lang->overtime->end);?></th>
              <th class='w-70px'><?php commonModel::printOrderLink('hours', $orderBy, $vars, $lang->overtime->hours);?></th>
              <th class='c-desc text-left'><?php echo $lang->overtime->desc;?></th>
              <th class='w-100px'><?php commonModel::printOrderLink('status', $orderBy, $vars, $lang->overtime->status);?></th>
              <?php if($type == 'personal'):?>
              <th class='w-<?php echo $lang->overtime->personalActionWidth;?>px'><?php echo $lang->actions;?></th>
              <?php else:?>
              <th class='w-<?php echo $lang->overtime->actionWidth;?>px'><?php echo $lang->actions;?></th>
              <?php endif;?>
            </tr>
          </thead>
          <?php foreach($overtimeList as $overtime):?>
          <?php $viewUrl = commonModel::hasPriv('oa.overtime', 'view') ? $this->createLink('oa.overtime', 'view', "id=$overtime->id&type=$type") : '';?>
          <tr class='text-center' id='overtime<?php echo $overtime->id;?>' url='<?php echo $viewUrl;?>'>
            <td class='idTD text-left'>
              <?php if($canBatchReview):?>
              <div class='checkbox-primary'><input type='checkbox' name='overtimeIDList[]' value="<?php echo $overtime->id;?>" id="overtimeIDList<?php echo $overtime->id;?>">
                <label for="overtimeIDList<?php echo $overtime->id;?>"></label>
              </div>
              <?php endif;?>
              <?php echo $overtime->id;?>
            </td>
            <td><?php echo zget($users, $overtime->createdBy);?></td>
            <td><?php echo zget($deptList, $overtime->dept);?></td>
            <td><?php echo zget($this->lang->overtime->typeList, $overtime->type);?></td>
            <td><?php echo formatTime($overtime->begin . ' ' . $overtime->start, DT_DATETIME2);?></td>
            <td><?php echo formatTime($overtime->end . ' ' . $overtime->finish, DT_DATETIME2);?></td>
            <td><?php echo $overtime->hours == 0 ? '' : $overtime->hours;?></td>
            <td class='text-left c-desc' title='<?php echo $overtime->desc?>'><?php echo $overtime->desc;?></td>
            <td class='overtime-<?php echo $overtime->status?>'><?php echo $overtime->statusLabel;?></td>
            <td class='actionTD text-left'>
              <?php 
              if($viewUrl) echo html::a($viewUrl, $lang->detail, "data-toggle='modal'");

              if($type == 'personal')
              {
                  $canEdit   = $this->overtime->isClickable($overtime, 'edit');
                  $canDelete = $this->overtime->isClickable($overtime, 'delete');
                  $canSwitch = $this->overtime->isClickable($overtime, 'switchStatus');

                  $switchLabel = $overtime->status == 'wait' ? $lang->overtime->cancel : $lang->overtime->submit;
                  if($canSwitch)
                  {
                      commonModel::printLink('oa.overtime', 'switchstatus', "id=$overtime->id", $switchLabel, "class='reload'");
                  }
                  else
                  {
                      echo html::a('javascript:;', $switchLabel,  "class='disabled'");
                  }

                  if($canEdit)
                  {
                      echo html::a(inlink('edit', "id=$overtime->id"), $lang->edit, "data-toggle='modal'");
                  }
                  else
                  {
                      echo html::a('javascript:;', $lang->edit, "class='disabled'");
                  }

                  if($canDelete)
                  {
                      echo html::a(inlink('delete', "id=$overtime->id"), $lang->delete, "class='deleter'");
                  }
                  else
                  {
                      echo html::a('javascript:;', $lang->delete, "class='disabled'");
                  }
              }
              else
              {
                  $canReview = $this->overtime->isClickable($overtime, 'review');

                  if($canReview)
                  {
                      echo html::a(inlink('review', "id=$overtime->id&status=pass"),   $lang->overtime->reviewStatusList['pass'],   "class='reviewPass'");
                      echo html::a(inlink('review', "id=$overtime->id&status=reject"), $lang->overtime->reviewStatusList['reject'], "data-toggle='modal'");
                  }
                  else
                  {
                      echo html::a('javascript:;', $lang->overtime->reviewStatusList['pass'],   "class='disabled'");
                      echo html::a('javascript:;', $lang->overtime->reviewStatusList['reject'], "class='disabled'");
                  }
              }
              ?>
            </td>
          </tr>
          <?php endforeach;?>
        </table>
        <div class='table-footer'>
          <?php if($canBatchReview):?>
          <div class='checkbox-primary check-all'><label><?php echo $lang->selectAll?></label></div>
          <div class='table-actions btn-toolbar'><?php echo html::a('javascript:;', $lang->overtime->reviewStatusList['pass'], "class='btn batchPass'");?></div>
          <?php endif;?>
          <div class='table-statistic'></div>
          <?php $pager->show();?>
        </div>
     <?php if($canBatchReview):?>
      </form>
      <?php endif;?>
    </div>
<?php if($type != 'browseReview'):?>
  </div>
</div>
<?php endif;?>
<?php include '../../common/view/footer.html.php';?>
