<?php
/**
 * The browse trade view file of deal module of ZDOO.
 *
 * @copyright   Copyright 2009-2017 青岛易软天创网络科技有限公司(QingDao Nature Easy Soft Network Technology Co,LTD, www.cnezsoft.com)
 * @license     ZPL (http://zpl.pub/page/zplv12.html)
 * @author      Gang Liu <liugang@cnezsoft.com>
 * @package     deal 
 * @version     $Id$
 * @link        http://www.zdoo.com
 */
?>
<?php include '../../common/view/header.html.php';?>
<div id='menuActions'>
  <?php 
  echo $menuActions;
  if(commonModel::hasPriv('deal', 'batchShare')) 
  {
      $url = inlink('batchShare', "type=$type&month=$month");
      echo html::a('javascript:;', "<i class='icon icon-sitemap'> </i>" . $lang->deal->batchShareList[$type], "class='btn btn-primary batchShare' data-url='$url'");
  }
  ?>
</div>
<div class='panel main-table' data-ride='table'>
  <?php $canBatchEdit   = commonModel::hasPriv('cash.trade', 'batchEdit');?>
  <?php $canBatchSwitch = commonModel::hasPriv('ameba.deal', 'batchSwitchTradeStatus');?>
  <?php $canBatchAction = ($canBatchEdit or $canBatchSwitch);?>
  <?php if($canBatchAction):?>
  <form id='tradeForm' method='post'>
  <?php endif;?>
    <table class='table has-sort-head table-fixed'>
      <thead>
        <tr class='text-center'>
          <?php $vars = "month=$month&status=$status&orderBy=%s&recTotal=$pager->recTotal&recPerPage=$pager->recPerPage&pageID=$pager->pageID";?>
          <th class='w-120px text-left'>
            <?php if($canBatchAction && count($tradeList) > 1):?>
            <div class='checkbox-primary check-all' title='<?php echo $this->lang->selectAll;?>'><label></label></div>
            <?php endif;?>
            <?php commonModel::printOrderLink('date', $orderBy, $vars, $lang->trade->date);?>
          </th>
          <th class='w-100px'><?php commonModel::printOrderLink('depositor', $orderBy, $vars, $lang->trade->depositor);?></th>
          <th class='w-60px'><?php commonModel::printOrderLink('type', $orderBy, $vars, $lang->trade->type);?></th>
          <th><?php commonModel::printOrderLink('trader', $orderBy, $vars, $lang->trade->trader);?></th>
          <th class='w-120px text-right'><?php commonModel::printOrderLink('money', $orderBy, $vars, $lang->trade->money);?></th>
          <th class='w-100px'><?php commonModel::printOrderLink('dept', $orderBy, $vars, $lang->trade->dept);?></th>
          <th class='w-100px'><?php commonModel::printOrderLink('handlers', $orderBy, $vars, $lang->trade->handlers);?></th>
          <th class='w-200px'><?php commonModel::printOrderLink('product', $orderBy, $vars, $lang->trade->product . $lang->slash . $lang->trade->category);?></th>
          <th class='w-200px'><?php echo $lang->trade->desc;?></th>
          <th class='w-100px'><?php echo $lang->actions;?></th>
        </tr>
      </thead>
      <tbody>
        <?php foreach($tradeList as $trade):?>
        <tr class='text-center'>
          <td class='text-left'>
            <?php if($canBatchAction && count($tradeList) > 1):?>
            <div class='checkbox-primary'><input type='checkbox' name='tradeIDList[]' value="<?php echo $trade->id;?>" id="tradeIDList<?php echo $trade->id;?>">
              <label for="tradeIDList<?php echo $trade->id;?>"></label>
            </div>
            <?php endif;?>
            <?php echo formatTime($trade->date, DT_DATE1);?>
          </td>
          <td class='text-left'><?php echo zget($depositorList, $trade->depositor, ' ');?></td>
          <td><?php echo $lang->trade->typeList[$trade->type];?></td>
          <td class='text-left' title="<?php echo zget($customerList, $trade->trader, '');?>"><?php if($trade->trader) echo zget($customerList, $trade->trader, ' ');?></td>
          <td class='text-right'><?php echo zget($currencySign, $config->setting->mainCurrency, '') . formatMoney($trade->money * $trade->exchangeRate);?></td>
          <td><?php echo zget($deptList, $trade->dept, '');?></td>
          <td title='<?php foreach(explode(',', $trade->handlers) as $handler) echo zget($users, $handler) . ' ';?>'><?php foreach(explode(',', $trade->handlers) as $handler) echo zget($users, $handler) . ' ';?></td>
          <td class='text-left'><?php echo isset($productList[$trade->product]) ? $productList[$trade->product] . $lang->slash . zget($categories, $trade->category, ' ') : zget($categories, $trade->category, ' ');?></td>
          <td class='text-left'><div title="<?php echo $trade->desc;?>" class='w-200px text-ellipsis'><?php echo $trade->desc;?><div></td>
          <td>
            <?php $width = $type == 'in' ? "data-width='1000'" : '';?>
            <?php if($status != 'ignored') commonModel::printLink('cash.trade', 'share', "tradeID=$trade->id", $lang->trade->shareList[$type], "data-toggle='modal' $width");?>
            <?php if($status != 'ignored') commonModel::printLink('deal', 'switchTradeStatus', "tradeID=$trade->id&status=ignored&type=$type&month=$month", $lang->trade->ignore, "class='jsoner'");?>
            <?php if($status == 'ignored') commonModel::printLink('deal', 'switchTradeStatus', "tradeID=$trade->id&status=wait&type=$type&month=$month", $lang->trade->restore, "class='jsoner'");?>
            <?php commonModel::printLink('cash.trade', 'edit', "tradeID=$trade->id", $lang->edit, "class='editTrade'");?> 
          </td>
        </tr>
        <?php endforeach;?>
      </tbody>
    </table>  
    <div class='table-footer'>
      <?php if($canBatchAction && count($tradeList) > 1):?>
      <div class='checkbox-primary check-all'><label><?php echo $lang->selectAll?></label></div>
      <div class="table-actions btn-toolbar">
        <?php
        if($canBatchEdit)
        {
            $editLink = helper::createLink('cash.trade', 'batchEdit', "step=form&mode=deal&type=$type&month=$month&status=$status");
            echo html::a('javascript:;', $lang->edit, "class='btn' onclick=\"setFormAction('$editLink')\"");
        }
        if($canBatchSwitch)
        {
            $label        = $status == 'ignored' ? $lang->trade->restore : $lang->trade->ignore;
            $switchStatus = $status == 'ignored' ? 'wait' : 'ignored';
            $switchLink   = inlink('batchSwitchTradeStatus', "status=$switchStatus&type=$type&month=$month");
            echo html::a('javascript:;', $label, "class='btn' onclick=\"setFormAction('$switchLink')\"");
        }
        ?>
      </div>
      <div class='table-statistic'></div>
      <?php endif;?>
      <?php echo $pager->show();?>
    </div>
  </form>
</div>
<?php include '../../common/view/footer.html.php';?>
