<?php
/**
 * The set line commission 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('dept', $dept);?>
<?php js::set('account', empty($accountList) ? $account : helper::jsonEncode($accountList));?>
<?php js::set('noResultsMatch', $lang->noResultsMatch);?>
<div class='main-row'>
  <?php include './side.html.php';?>
  <div class='main-col'>
    <div class='row'>
      <div class='col-xs-2'>
        <div class='panel'>
          <div class='panel-heading'><strong><i class="icon-building"></i> <?php echo $lang->dept->common;?></strong></div>
          <div class='panel-body'>
            <?php echo $treeMenu;?>
          </div>
        </div>
      </div>
      <div class='col-xs-10'>
        <form id='ajaxForm' method='post' action='<?php echo inlink('setLineCommission', "step=save&mode=$mode&dept=$dept&account=$account");?>'>
          <div class='panel'>
            <div class='panel-heading'>
              <strong>
                <?php if($step == 'create'):?>
                <?php echo $lang->commission->lineCommission->common . ' :: ' . $lang->create;?>
                <?php elseif($account):?>
                <?php echo $lang->commission->lineCommission->common . ' :: ' . zget($userList, $account, ' ');?>
                <?php else:?>
                <?php echo $lang->commission->lineCommission->common . ' :: ' . $lang->commission->batchSetting;?>
                <?php endif;?>
              </strong>
            </div>
            <div class='panel-body'>
              <?php $i = 0;?>
              <?php if(empty($lineList)):?>
              <?php commonModel::printLink('crm.tree', 'browse', 'type=product', $lang->commission->lineCommission->lineList, "class='btn btn-primary setting'");?>
              <?php else:?>
              <table class='table table-form'>
                <?php if($step == 'create'):?>
                <tr>
                  <th class='w-50px'><?php echo $lang->commission->account;?></th>
                  <td class='w-180px'><?php echo html::select('accountList[]', $userList, '', "class='form-control chosen'");?></td>
                  <td class='w-180px'></td>
                  <td class='w-130px'></td>
                  <td></td>
                </tr>
                <?php endif;?>
                <?php if($account):?>
                <?php foreach($commissionList as $line => $rate):?>
                <tr>
                  <th class='w-50px'><?php echo $lang->commission->lineCommission->lineList;?></th>
                  <td><?php echo html::select("lines[$i]", array('' => '') + $lineList, $line, "class='form-control chosen'");?></td>
                  <td>
                    <div class='input-group'>
                      <span class='input-group-addon'><?php echo $lang->commission->rate;?></span>
                      <?php echo html::input("rates[$i]", !is_object($rate) ? $rate : '', "class='form-control rate'");?>
                      <span class='input-group-addon'><?php echo $lang->percent;?></span>
                    </div>
                  </td>
                  <td>
                    <?php echo $lang->commission->lineCommission->remainRates;?>
                    <span id='remainRates'></span>
                  </td>
                  <td>
                    <a href='#' class='btn add'><i class='icon-plus'></i></a>
                    <a href='#' class='btn remove'><i class='icon-remove'></i></a>
                  </td>
                </tr>
                <?php $i++;?>
                <?php endforeach;?>
                <?php endif;?>
                <tr>
                  <th class='w-50px'><?php echo $lang->commission->lineCommission->lineList;?></th>
                  <td><?php echo html::select("lines[$i]", array('' => '') + $lineList, '', "class='form-control chosen'");?></td>
                  <td>
                    <div class='input-group'>
                      <span class='input-group-addon'><?php echo $lang->commission->rate;?></span>
                      <?php echo html::input("rates[$i]", '', "class='form-control rate'");?>
                      <span class='input-group-addon'><?php echo $lang->percent;?></span>
                    </div>
                  </td>
                  <td>
                    <?php echo $lang->commission->lineCommission->remainRates;?>
                    <span id='remainRates'></span>
                  </td>
                  <td>
                    <a href='#' class='btn add'><i class='icon-plus'></i></a>
                    <a href='#' class='btn remove'><i class='icon-remove'></i></a>
                  </td>
                </tr>
                <tr>
                  <td colspan='5' class='form-actions'>
                    <?php echo html::submitButton() . ' ' . html::backButton();?>
                    <?php if(!isset($accountList)) commonModel::printLink('commission', 'setLineCommission', "step=delete&mode={$mode}&dept={$dept}&account={$account}", $lang->cancel . $lang->commission->common, "class='btn btn-default deleter'");?>
                  </td>
                </tr>
              </table>
              <?php if(isset($accountList)):?>
              <div class='hide'>
                <?php foreach($accountList as $curAccount):?>
                <?php echo html::hidden('accountList[]', $curAccount);?>
                <?php endforeach;?>
              </div>
              <?php endif;?>
              <?php endif;?>
            </div>
          </div>
        </form>
      </div>
    </div>
  </div>
</div>
<?php
$select  = html::select('lines[key]', array('' => '') + $lineList, '', "class='form-control chosen'");
$itemRow = <<<EOT
  <tr>
    <th class='w-50px'>{$lang->commission->lineCommission->lineList}</th>
    <td>{$select}</td>
    <td>
      <div class='input-group'>
        <span class='input-group-addon'>{$lang->commission->rate}</span>
        <input type='text' value="" name="rates[key]" class='form-control rate'>
        <span class='input-group-addon'>{$lang->percent}</span>
      </div>
    </td>
    <td>
      {$lang->commission->lineCommission->remainRates}
      <span id='remainRates'></span>
    </td>
    <td>
      <a href='#' class='btn add'><i class='icon-plus'></i></a>
      <a href='#' class='btn remove'><i class='icon-remove'></i></a>
    </td>
  </tr>
EOT;
js::set('itemRow', $itemRow);
js::set('key', ++$i);
?>
<?php include '../../common/view/footer.html.php';?>
