<?php
/**
 * The browse view file of commission module of ZDOO.
 *
 * @copyright   Copyright 2009-2016 青岛易软天创网络科技有限公司(QingDao Nature Easy Soft Network Technology Co,LTD, www.cnezsoft.com)
 * @license     商业软件，非开源软件
 * @author      Gang Liu <liugang@cnezsoft.com>
 * @package     commission 
 * @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('type', $type);?>
<div class='main-row'>
  <div class='side-col'>
    <div class='panel'>
      <div class='panel-body'>
        <ul class='tree' data-collapsed='true'>
          <?php foreach($tradeYears as $tradeYear):?>
          <li class='<?php echo $tradeYear == $currentYear ? 'active' : '';?>'>
            <?php commonModel::printLink('commission', 'browse', "type={$type}&date={$tradeYear}", $tradeYear);?>
            <ul>
              <?php foreach($tradeMonths[$tradeYear] as $month):?>
              <li class='<?php echo ($tradeYear == $currentYear && $month == $currentMonth) ? 'active' : '';?>'><?php commonModel::printLink('commission', 'browse', "type={$type}&date=$tradeYear$month", $tradeYear . $month);?></li>
              <?php endforeach;?>
            </ul>
          </li>
          <?php endforeach;?>
        </ul>
      </div>
    </div>
  </div>
  <div class='main-col'>
    <div class='panel main-table' data-ride='table'>
      <?php $param = $type == 'ignored' ? '&commission=0' : '';?>
      <?php $label = $type == 'ignored' ? $lang->commission->restore : $lang->ignore;?>
      <?php $canBatchIgnore = ($trades && $type != 'commissioned' && commonModel::hasPriv('hr.commission', 'batchSwitchIgnore'));?>
      <?php if($canBatchIgnore):?>
      <form id='ajaxForm' method='post' action='<?php echo inlink('batchSwitchIgnore', "type={$type}&date=$currentYear$currentMonth{$param}");?>'>
      <?php endif;?>
        <table id='tradeList' class='table has-sort-head table-fixed'>
          <thead>
            <tr>
              <?php $vars = "type={$type}&date={$date}&orderBy=%s&recTotal={$pager->recTotal}&recPerPage={$pager->recPerPage}&pageID={$pager->pageID}";?>
              <th class='w-80px text-left'>
                <?php if($canBatchIgnore):?>
                <div class='checkbox-primary check-all' title='<?php echo $this->lang->selectAll;?>'><label></label></div>
                <?php endif;?>
                <?php echo $lang->trade->id;?>
              </th>
              <th class='w-90px'><?php commonModel::printOrderLink('date', $orderBy, $vars, $lang->trade->date);?></th>
              <th class='text-left'><?php commonModel::printOrderLink('trader', $orderBy, $vars, $lang->trade->customer);?></th>
              <th class='text-left'><?php commonModel::printOrderLink('product', $orderBy, $vars, $lang->trade->product);?></th>
              <th class='w-120px'><?php commonModel::printOrderLink('category', $orderBy, $vars, $lang->trade->category);?></th>
              <th class='w-80px'><?php commonModel::printOrderLink('dept', $orderBy, $vars, $lang->trade->dept);?></th>
              <th class='w-80px'><?php commonModel::printOrderLink('handlers', $orderBy, $vars, $lang->trade->handlers);?></th>
              <th class='w-100px text-right'><?php commonModel::printOrderLink('money', $orderBy, $vars, $lang->commission->money);?></th>
              <?php if($type == 'commissioned'):?>
              <th class='w-100px text-right'><?php echo $lang->commission->amount;?></th>
              <?php endif;?>
              <?php $class = $this->app->clientLang == 'en' ? 'w-150px' : 'w-120px';?>
              <th class='<?php echo $class;?> text-center'><?php echo $lang->actions;?></th>
            </tr>
          </thead>
          <tbody>
            <?php foreach($trades as $trade):?>
            <tr>
              <td>
                <?php if($canBatchIgnore):?>
                <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 $trade->id;?>
              </td>
              <td><?php echo formatTime($trade->date, DT_DATE1);?></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-left' title="<?php echo zget($productList, $trade->product, ' ');?>"><?php echo zget($productList, $trade->product, ' ');?></td>
              <td><?php echo zget($categories, $trade->category, ' ');?></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-right'>
                <?php echo zget($lang->currencySymbols, $config->setting->mainCurrency, '') . formatMoney($trade->money * $trade->exchangeRate);?>
              </td>
              <?php if($type == 'commissioned'):?>
              <td class='text-right'>
                <?php echo formatMoney($trade->commissionedAmount);?>
              </td>
              <?php endif;?>
              <td class='text-center'>
                <?php if($type == 'commissioned') commonModel::printLink('commission', 'create', "type={$type}&tradeID={$trade->id}", $lang->commission->commissioned, "class='commissioned'");?>
                <?php if($type == 'uncommission') commonModel::printLink('commission', 'create', "type={$type}&tradeID={$trade->id}", $lang->commission->commission);?>
                <?php if($type != 'commissioned') commonModel::printLink('commission', 'switchIgnore', "type={$type}&tradeID={$trade->id}&date=$currentYear$currentMonth{$param}", $label, "class='jsoner'");?> 
              </td>
            </tr>
            <?php endforeach;?>
          </tbody>
        </table>
        <div class='table-footer'>
          <?php if($canBatchIgnore):?>
          <div class='checkbox-primary check-all'><label><?php echo $lang->selectAll;?></label></div>
          <div class='table-actions btn-toolbar'><?php echo html::submitButton($label, 'btn');?></div>
          <div class='table-statistic'></div>
          <?php endif;?>
          <?php echo $pager->get();?>
        </div>
      </form>
    </div>
  </div>
</div>
<?php include '../../common/view/footer.html.php';?>
