<?php
/**
 * The browse view file of contract 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      Yidong Wang <yidong@cnezsoft.com>
 * @package     contract
 * @version     $Id$
 * @link        http://www.zdoo.com
 */
?>
<?php include '../../common/view/header.html.php';?>
<?php js::set('type', $type);?>
<?php js::set('mode', $mode);?>
<?php $extendFields = $this->loadModel('customer')->getFlowExtendFields();?>
<li id='bysearchTab'><?php echo html::a('#', "<i class='icon-search icon'></i>" . $lang->search->common)?></li>
<div id='menuActions'>
  <?php if(commonModel::hasPriv($moduleType, 'export')):?>
  <div class='btn-group'>
    <button data-toggle='dropdown' class='btn btn-secondary dropdown-toggle' type='button'><?php echo $lang->exportIcon . $lang->export;?> <span class='caret'></span></button>
    <ul id='exportActionMenu' class='dropdown-menu'>
      <li><?php echo html::a(inlink('export', "type={$type}&mode=all"), $lang->exportAll, "class='iframe' data-width='700'");?></li>
      <li><?php echo html::a(inlink('export', "type={$type}&mode=thisPage"), $lang->exportThisPage, "class='iframe' data-width='700'");?></li>
    </ul>
  </div>
  <?php endif;?>
  <?php commonModel::printLink($moduleType, 'create', '', '<i class="icon-plus"></i> ' . $lang->$moduleType->create, "class='btn btn-primary'");?>
</div>
<div class='panel main-table' data-ride='table'>
  <table class='table has-sort-head' id='contractList'>
    <thead>
      <tr class='text-center'>
        <?php $vars = "mode={$mode}&orderBy=%s&recTotal={$pager->recTotal}&recPerPage={$pager->recPerPage}&pageID={$pager->pageID}";?>
        <th class='w-50px'> <?php commonModel::printOrderLink('id',         $orderBy, $vars, $lang->$moduleType->id);?></th>
        <th class='w-100px'><?php commonModel::printOrderLink('code',       $orderBy, $vars, $lang->$moduleType->code);?></th>
        <th class='c-name'><?php commonModel::printOrderLink('name',        $orderBy, $vars, $lang->$moduleType->name);?></th>
        <th class='w-90px'><?php commonModel::printOrderLink('amount',      $orderBy, $vars, $lang->$moduleType->amount);?></th>
        <th class='w-90px'><?php echo $lang->$moduleType->unReturn;?></th>
        <th class='w-90px'><?php commonModel::printOrderLink('createdDate', $orderBy, $vars, $lang->$moduleType->createdDate);?></th>
        <th class='w-90px'><?php commonModel::printOrderLink('begin',       $orderBy, $vars, $lang->$moduleType->begin);?></th>
        <th class='w-90px'><?php commonModel::printOrderLink('end',         $orderBy, $vars, $lang->$moduleType->end);?></th>
        <th class='w-70px'> <?php commonModel::printOrderLink('return',     $orderBy, $vars, $lang->$moduleType->return);?></th>
        <?php if($moduleType == 'contract'):?>
        <th class='w-70px'> <?php commonModel::printOrderLink('delivery',   $orderBy, $vars, $lang->$moduleType->delivery);?></th>
        <?php endif;?>
        <th class='w-60px'> <?php commonModel::printOrderLink('status',     $orderBy, $vars, $lang->$moduleType->status);?></th>
        <?php foreach($extendFields as $extendField) echo "<th class='" . ($extendField->width != 'auto' ? "w-{$extendField->width}px" : '')  . "'>{$extendField->name}</th>";?>
        <th style='width: <?php echo $lang->$moduleType->actionWidth;?>px'><?php echo $lang->actions;?></th>
      </tr>
    </thead>
    <tbody>
      <?php $canView = commonModel::hasPriv('contract', 'view');?>
      <?php foreach($contracts as $contract):?>
      <tr class='text-center' data-customer="<?php echo $contract->customer;?>" data-contract="<?php echo $contract->id;?>">
        <td><?php echo $contract->id;?></td>
        <td class='text-left' title='<?php echo $contract->code;?>'><?php echo $contract->code;?></td>
        <td class='text-left c-name' title='<?php echo $contract->name;?>'><?php echo $canView ? html::a(inlink('view', 'contractID=' . $contract->id), $contract->name) : $contract->name;?></td>
        <td class='text-right'><?php echo zget($currencySign, $contract->currency, '') . formatMoney($contract->amount);?></td>
        <td class='text-right'><?php echo zget($currencySign, $contract->currency, '') . $contract->unReturn;?></td>
        <td><?php echo formatTime($contract->createdDate, DT_DATE1);?></td>
        <td><?php echo formatTime($contract->begin, DT_DATE1);?></td>
        <td><?php echo formatTime($contract->end, DT_DATE1);?></td>
        <td><?php echo $lang->$moduleType->returnList[$contract->return];?></td>
        <?php if($moduleType == 'contract'):?>
        <td><?php echo $lang->$moduleType->deliveryList[$contract->delivery];?></td>
        <?php endif;?>
        <td class='<?php echo "contract-{$contract->status}";?>'><?php echo $lang->$moduleType->statusList[$contract->status];?></td>
        <?php foreach($extendFields as $extendField) echo "<td>" . $this->loadModel('flow')->getFieldValue($extendField, $contract) . "</td>";?>
        <td class='actions'>
          <?php echo $this->$moduleType->buildOperateMenu($contract, 'browse');?>
        </td>
      </tr>
      <?php endforeach;?>
    </tbody>
  </table>
  <div class='table-footer'>
    <?php if(!empty($totalAmount)):?>
    <div class='table-statistic'>
      <span>
        <?php printf($lang->$moduleType->totalAmount, implode('，', $totalAmount['contract']), implode('，', $totalAmount['return']), implode('，', $totalAmount['unReturn']), implode('，', $totalAmount['currentMonth']));?>
      </span>
    </div>
    <?php endif;?>
    <?php $pager->show();?>
  </div>
</div>
<?php if($moduleType == 'contract'):?>
<script>
<?php helper::import('../js/team.js');?>
</script>
<?php endif;?>
<?php include '../../common/view/footer.html.php';?>
