<?php
/**
 * The detail 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 $app->getModuleRoot() . 'my/view/header.html.php';?>
<div class='panel panel-block'>
  <div class='panel-heading'>
    <strong>
      <?php echo sprintf($lang->salary->title, zget($users, $salary->account), substr($salary->month, 0, 4), (int)substr($salary->month, 4, 2));?>
    </strong>
  </div>
  <div class='panel-body'>
    <table class='table table-bordered'>
      <thead>
        <tr class='text-center'>
          <th rowspan='2' class='text-middle'><?php echo $lang->salary->basic;?></th>
          <?php if((float)$salary->performance):?>
          <th rowspan='2' class='text-middle'><?php echo $lang->salary->performance;?></th>
          <?php endif;?>
          <?php
          foreach($config->salary->detailFields as $field)
          {
              $listField = $field . 'List';
              if(!empty($salary->$listField))
              {
                  $count = count($salary->$listField);
                  echo "<th colspan='{$count}'>{$lang->salary->$field}</th>";
              }
          }
          ?>
          <th rowspan='2' class='text-middle'><?php echo $lang->salary->deserved;?></th>
          <th rowspan='2' class='text-middle'><?php echo $lang->salary->actual;?></th>
          <?php if((float)$salary->companySSF):?>
          <th rowspan='2' class='text-middle'><?php echo $lang->salary->companySSF;?></th>
          <?php endif;?>
          <?php if((float)$salary->companyHPF):?>
          <th rowspan='2' class='text-middle'><?php echo $lang->salary->companyHPF;?></th>
          <?php endif;?>
        </tr>
        <tr class='text-center'>
          <?php 
          foreach($config->salary->detailFields as $field)
          {
              $listField = $field . 'List';
              if(!empty($salary->$listField))
              {
                  foreach($salary->$listField as $data) echo "<th>{$data->type}</th>";
              }
          }
          ?>
        </tr>
      </thead>
      <tr class='text-center'>
        <td><?php echo formatMoney($salary->basic);?></td>
        <?php if((float)$salary->performance):?>
        <td><?php echo formatMoney($salary->performance);?></td>
        <?php endif;?>
        <?php 
        foreach($config->salary->detailFields as $field)
        {
            $listField = $field . 'List';
            if(!empty($salary->$listField))
            {
                foreach($salary->$listField as $data) echo '<td>' . formatMoney($data->amount) . '</td>';
            }
        }
        ?>
        <td><?php echo formatMoney($salary->deserved);?></td>
        <td><?php echo formatMoney($salary->actual);?></td>
        <?php if((float)$salary->companySSF):?>
        <td><?php echo formatMoney($salary->companySSF);?></td>
        <?php endif;?>
        <?php if((float)$salary->companyHPF):?>
        <td><?php echo formatMoney($salary->companyHPF);?></td>
        <?php endif;?>
      </tr>
    </table>
    <?php $lineCommissionList = isset($commissions['lineCommissionList']) ? $commissions['lineCommissionList'] : array();?>
    <?php $saleCommissionList = isset($commissions['saleCommissionList']) ? $commissions['saleCommissionList'] : array();?>
    <?php $saleRule           = isset($commissions['saleRule']) ? $commissions['saleRule'] : array();?>
  </div>
</div>

<?php if(($lineCommissionList || $saleCommissionList) && (!empty($lineRule) || !empty($saleRule))):?>
<div id='commissionDIV' class='panel panel-block'>
  <div class='panel-heading'>
    <strong><?php echo $lang->salary->viewCommissions;?></strong>
  </div>
  <div class='panel-body'>
    <?php if($lineCommissionList):?>
    <table class='table table-bordered table-fixed'>
      <thead>
        <tr class='text-center'>
          <th class='w-100px'><?php echo $lang->commission->type;?></th>
          <th class='w-180px'><?php echo $lang->salary->lineList;?></th>
          <th><?php echo $lang->salary->amount;?></th>
          <th><?php echo $lang->commission->base;?></th>
          <th><?php echo $lang->salary->rate;?></th>
          <th><?php echo $lang->salary->commission;?></th>
        </tr>
      </thead>
      <?php $i = 0;?>
      <?php $totalMoney = $totalCommission = $totalAmount = 0;?>
      <?php foreach($lineCommissionList as $commission):?>
      <tr>
        <?php if($i == 0):?>
        <th class='text-center text-middle' rowspan='<?php echo count($lineCommissionList);?>'><?php echo $lang->commission->typeList['line'];?></th>
        <?php endif;?>
        <td><?php echo $commission->line;?></td>
        <td><?php echo formatMoney($commission->money);?></td>
        <td><?php echo formatMoney($commission->commission);?></td>
        <td><?php echo $commission->rate . $lang->percent;?></td>
        <td><?php echo formatMoney($commission->amount);?></td>
      </tr>
      <?php $totalMoney      += $commission->money;?>
      <?php $totalCommission += $commission->commission;?>
      <?php $totalAmount     += $commission->amount;?>
      <?php $i++;?>
      <?php endforeach;?>
      <tfoot>
        <tr class='footer'>
          <th class='text-center'><?php echo $lang->salary->total;?></th>
          <td></td>
          <td><?php echo formatMoney($totalMoney);?></td>
          <td><?php echo formatMoney($totalCommission);?></td>
          <td></td>
          <td><?php echo formatMoney($totalAmount);?></td>
        </tr>
      </tfoot>
    </table>
    <?php endif;?>

    <?php if($saleCommissionList):?>
    <table class='table table-bordered table-fixed'>
      <thead>
        <tr class='text-center'>
          <th class='w-100px'><?php echo $lang->commission->type;?></th>
          <th><?php echo $lang->trade->trader;?></th>
          <th><?php echo $lang->trade->product;?></th>
          <th class='w-160px'><?php echo $lang->trade->money;?></th>
          <th class='w-160px'><?php echo $lang->commission->base;?></th>
          <?php if($saleRule->rule == 'multistep'):?>
          <th class='w-160px'><?php echo $lang->commission->contribution;?></th>
          <?php else:?>
          <th class='w-160px'><?php echo $lang->commission->rate;?></th>
          <?php endif;?>
          <th class='w-200px'><?php echo $lang->commission->rule;?></th>
          <th class='w-160px'><?php echo $lang->salary->commission;?></th>
        </tr>
      </thead>
      <?php $i = 0;?>
      <?php $totalMoney = $totalCommission = $totalAmount = 0;?>
      <?php foreach($saleCommissionList as $commission):?>
      <tr>
        <?php if($i == 0):?>
        <th class='text-center text-middle not-table-hover' rowspan='<?php echo count($saleCommissionList);?>'><?php echo $lang->commission->typeList['sale'];?></th>
        <?php endif;?>
        <td><?php echo zget($customerList, $commission->trader, ' ');?></td>
        <td><?php echo zget($productList, $commission->product, ' ');?></td>
        <td><?php echo formatMoney($commission->money);?></td>
        <td><?php echo formatMoney($commission->commission);?></td>
        <?php if(isset($saleRule->rule) && $saleRule->rule == 'multistep'):?>
        <td><?php echo $commission->contribution . $lang->percent;?></td>
        <?php else:?>
        <td><?php echo $commission->rate . $lang->percent;?></td>
        <?php endif;?>
        <?php if($i == 0):?>
        <td class='not-table-hover' rowspan='<?php echo count($saleCommissionList);?>'>
        <?php if(!empty($saleRule->rule)) echo $lang->commission->saleCommission->ruleList[$saleRule->rule];?>
        </td>
        <?php endif;?>
        <td><?php echo formatMoney($commission->amount);?></td>
      </tr>
      <?php
        $totalMoney      += $commission->money;
        $totalCommission += $commission->commission;
        $totalAmount     += $commission->amount;
        $i++;
        endforeach;
      ?>
      <tfoot>
        <tr class='footer'>
          <th class='text-center'><?php echo $lang->salary->total;?></th>
          <td colspan='2'></td>
          <td><?php echo formatMoney($totalMoney);?></td>
          <td><?php echo formatMoney($totalCommission);?></td>
          <td colspan='2'></td>
          <td><?php echo formatMoney($totalAmount);?></td>
        </tr>
      </tfoot>
    </table>
    <?php endif;?>
  </div>
</div>
<?php endif;?>

<div class='main-actions text-center'>
  <div class='btn-toolbar'>
    <?php echo html::backButton();?>
  </div>
</div>
<?php include $app->getModuleRoot() . 'common/view/footer.html.php';?>
