<?php
/**
 * The set allowance view file of salary 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     salary 
 * @version     $Id$
 * @link        http://www.zdoo.com
 */
?>
<?php include '../../common/view/header.html.php';?>
<div class='main-row'>
  <div class='panel'>
    <div class='panel-heading'>
      <strong><?php echo $lang->salary->setAllowance;?></strong>
    </div>
    <div class='panel-body'>
      <form id='ajaxForm' method='post'>
        <table class='table table-condensed table-borderless'>
          <tr class='text-center'>
            <th class='w-140px'><?php echo $lang->salary->name;?></th>
            <th class='w-140px'><?php echo $lang->salary->amount;?></th>
            <th class='w-160px'><?php echo $lang->salary->rule;?></th>
            <th></th>
          </tr>
          <?php $i = 0;?>
          <?php foreach($allowanceList as $name => $allowance):?>
          <?php $readonly = $allowance->rule == 'relateSale' ? "readonly='readonly'" : '';?>
          <tr class='text-middle'>
            <td class='text-center'>
              <?php echo $name;?>
              <?php echo html::hidden("names[$i]", $name);?>
            </td>
            <td class='text-center'>
              <?php if($name == $lang->salary->allowanceList['hot']):?>
              <button type="button" class='btn' data-toggle="modal" data-target="#hotModal"><?php echo $lang->salary->setting;?></button> 
              <div class="modal fade" id="hotModal">
                <div class="modal-dialog w-500px">
                  <div class="modal-content">
                    <div class='modal-header'>
                      <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span class="sr-only"><?php echo $lang->close;?></span></button>
                      <h4 class="modal-title text-left"><?php echo $name;?></h4>
                    </div>
                    <div class='modal-body'>
                      <?php if(!empty($allowance->amount)):?>
                      <?php $amounts = (array)$allowance->amount;?>
                      <?php foreach($amounts as $month => $amount):?>
                      <div class='input-group'>
                        <span class='input-group-addon'><?php echo $lang->salary->month;?></span>
                        <?php echo html::select('months[hot][]', array('' => '') + $lang->datepicker->monthNames, $month, "class='form-control'");?>
                        <span class='input-group-addon fix-border'><?php echo $lang->salary->amount;?></span>
                        <?php echo html::input('amounts[hot][]', $amount, "class='form-control'");?>
                        <span class='input-group-btn fix-border'>
                          <a href='javascript:;' class='btn addItem'><i class='icon icon-plus'></i></a>
                        </span>
                        <span class='input-group-btn'>
                          <a href='javascript:;' class='btn delItem'><i class='icon icon-remove'></i></a>
                        </span>
                      </div>
                      <?php endforeach;?>
                      <?php else:?>
                      <div class='input-group'>
                        <span class='input-group-addon'><?php echo $lang->salary->month;?></span>
                        <?php echo html::select('months[hot][]', array('' => '') + $lang->datepicker->monthNames, '', "class='form-control'");?>
                        <span class='input-group-addon fix-border'><?php echo $lang->salary->amount;?></span>
                        <?php echo html::input('amounts[hot][]', '', "class='form-control'");?>
                        <span class='input-group-btn fix-border'>
                          <a href='javascript:;' class='btn addItem'><i class='icon icon-plus'></i></a>
                        </span>
                        <span class='input-group-btn'>
                          <a href='javascript:;' class='btn delItem'><i class='icon icon-remove'></i></a>
                        </span>
                      </div>
                      <?php endif;?>
                      <div class='table-footer'><?php echo html::commonButton($lang->save, "btn btn-primary", "data-dismiss='modal'");?></div>
                    </div>
                  </div>
                </div>
              </div>
              <?php elseif($name == $lang->salary->allowanceList['cold']):?>
              <button type="button" class='btn' data-toggle="modal" data-target="#coldModal"><?php echo $lang->salary->setting;?></button> 
              <div class="modal fade" id="coldModal">
                <div class="modal-dialog w-500px">
                  <div class="modal-content">
                    <div class='modal-header'>
                      <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span class="sr-only"><?php echo $lang->close;?></span></button>
                      <h4 class="modal-title text-left"><?php echo $name;?></h4>
                    </div>
                    <div class='modal-body'>
                      <?php if(!empty($allowance->amount)):?>
                      <?php $amounts = (array)$allowance->amount;?>
                      <?php foreach($amounts as $month => $amount):?>
                      <div class='input-group'>
                        <span class='input-group-addon'><?php echo $lang->salary->month;?></span>
                        <?php echo html::select('months[cold][]', array('' => '') + $lang->datepicker->monthNames, $month, "class='form-control'");?>
                        <span class='input-group-addon fix-border'><?php echo $lang->salary->amount;?></span>
                        <?php echo html::input('amounts[cold][]', $amount, "class='form-control'");?>
                        <span class='input-group-btn fix-border'>
                          <a href='javascript:;' class='btn addItem'><i class='icon icon-plus'></i></a>
                        </span>
                        <span class='input-group-btn'>
                          <a href='javascript:;' class='btn delItem'><i class='icon icon-remove'></i></a>
                        </span>
                      </div>
                      <?php endforeach;?>
                      <?php else:?>
                      <div class='input-group'>
                        <span class='input-group-addon'><?php echo $lang->salary->month;?></span>
                        <?php echo html::select('months[cold][]', array('' => '') + $lang->datepicker->monthNames, '', "class='form-control'");?>
                        <span class='input-group-addon fix-border'><?php echo $lang->salary->amount;?></span>
                        <?php echo html::input('amounts[cold][]', '', "class='form-control'");?>
                        <span class='input-group-btn fix-border'>
                          <a href='javascript:;' class='btn addItem'><i class='icon icon-plus'></i></a>
                        </span>
                        <span class='input-group-btn'>
                          <a href='javascript:;' class='btn delItem'><i class='icon icon-remove'></i></a>
                        </span>
                      </div>
                      <?php endif;?>
                      <div class='table-footer'><?php echo html::commonButton($lang->save, "btn btn-primary", "data-dismiss='modal'");?></div>
                    </div>
                  </div>
                </div>
              </div>
              <?php else:?>
              <?php echo html::input("amounts[$i]", $allowance->amount, "class='form-control amount' $readonly");?>
              <?php endif;?>
            </td>
            <td class='ruleTD'>
              <?php echo zget($lang->salary->ruleList, $allowance->rule, ' ');?>
              <?php echo html::hidden("rules[$i]", $allowance->rule, "class='rule'");?>
            </td>
            <td>
              <?php if(!in_array($name, $lang->salary->allowanceList)):?>
              <a href='javascript:;' class='btn add'><i class='icon-plus'></i></a>
              <a href='javascript:;' class='btn remove'><i class='icon-remove'></i></a>
              <?php endif;?>
            </td>
          </tr>
          <?php $i++;?>
          <?php endforeach;?>
          <?php unset($lang->salary->ruleList['commission']);?>
          <tr class='text-center'>
            <td><?php echo html::input("names[$i]", '', "class='form-control'");?></td>
            <td><?php echo html::input("amounts[$i]", '', "class='form-control amount'");?></td>
            <td><?php echo html::select("rules[$i]", $lang->salary->ruleList, '', "class='form-control rule'");?></td>
            <td class='text-left text-middle'>
              <a href='javascript:;' class='btn add'><i class='icon-plus'></i></a>
              <a href='javascript:;' class='btn remove'><i class='icon-remove'></i></a>
            </td>
          </tr>
          <tr>
            <th class='text-center'><?php echo $lang->salary->total;?></td>
            <td class='text-right' id='total'></td>
            <td colspan='2'></td>
          </tr>
          <tr>
            <td class='form-actions' colspan='4'><?php echo html::submitButton();?></td>
          </tr>
        </table>
      </form>
    </div>
  </div>
</div>
<?php
$select  = html::select('rules[key]', $lang->salary->ruleList, '', "class='form-control rule'");
$itemRow = <<<EOT
  <tr class='text-center'>
    <td><input type='text' value="" name="names[key]" class='form-control'></td>
    <td><input type='text' value="" name="amounts[key]" class='form-control amount'></td>
    <td>{$select}</td>
    <td class='text-left text-middle'>
      <a href='javascript:;' class='btn add'><i class='icon-plus'></i></a>
      <a href='javascript:;' class='btn remove'><i class='icon-remove'></i></a>
    </td>
  </tr>
EOT;
?>
<?php js::set('itemRow', $itemRow);?>
<?php js::set('key', ++$i);?>
<?php include '../../common/view/footer.html.php';?>
