<style>
.panel > #refundTable{margin-bottom: 0;}
.tr-child, .tr-child > td {padding: 0;}
.tr-child > td > table {padding: 5px; background-color: #fff; border: 2px solid #DDDDDD; margin-bottom: 0;}
</style>
<div class='panel' data-ride='table'>
  <table class='table has-sort-head' id='refundTable'>
    <thead>
      <tr class='text-center'>
        <?php $vars = "date=$date&type=&orderBy=%s&recTotal={$pager->recTotal}&recPerPage={$pager->recPerPage}&pageID={$pager->pageID}";?>
        <th class='w-50px'><?php commonModel::printOrderLink('id', $orderBy, $vars, $lang->refund->id);?></th>
        <th class='w-100px text-left'><?php commonModel::printOrderLink('dept', $orderBy, $vars, $lang->refund->dept);?></th>
        <th class='text-left'><?php commonModel::printOrderLink('name', $orderBy, $vars, $lang->refund->name);?></th>
        <th class='w-120px text-left'><?php commonModel::printOrderLink('category', $orderBy, $vars, $lang->refund->category);?></th>
        <th class='w-100px text-right'><?php commonModel::printOrderLink('money', $orderBy, $vars, $lang->refund->money);?></th>
        <th class='w-90px'><?php commonModel::printOrderLink('status', $orderBy, $vars, $lang->refund->status);?></th>
        <th class='w-90px'><?php commonModel::printOrderLink('payee', $orderBy, $vars, $lang->refund->payee);?></th>
        <th class='w-90px'><?php commonModel::printOrderLink('createdDate', $orderBy, $vars, $lang->refund->createdDate);?></th>
        <th class='w-90px'><?php commonModel::printOrderLink('refundBy', $orderBy, $vars, $lang->refund->refundBy);?></th>
        <th class='w-90px'><?php commonModel::printOrderLink('refundDate', $orderBy, $vars, $lang->refund->refundDate);?></th>
        <th class='w-<?php echo $lang->refund->todoActionWidth;?>px'><?php echo $lang->actions;?></th>
      </tr>
    </thead>
    <?php foreach($refunds as $account => $accountRefunds):?>
    <?php foreach($accountRefunds as $currency => $currencyRefunds):?>
    <tr class='text-center'>
      <td><span class="refund-toggle refund-toggle-<?php echo $account . '-' . $currency;?>"><i class="icon icon-plus"></i></span></td>
      <td class='text-left'><?php echo zget($deptList, $currencyRefunds['dept'], '');?></td>
      <td></td>
      <td></td>
      <td class='text-right'><?php echo zget($currencySign, $currency) . number_format($currencyRefunds['total'], 2, '.', '');?></td>
      <td class='refund-pass'><?php echo zget($lang->refund->statusList, 'pass');?></td>
      <td><?php echo zget($userPairs, $account);?></td>
      <td></td>
      <td></td>
      <td></td>
      <td class='text-left'>
        <?php echo html::a('javascript:;', $lang->detail, "class='refund-toggle refund-toggle-$account-$currency'");?>
        <?php $idList = helper::safe64Encode(helper::jsonEncode($currencyRefunds['idList']));?>
        <?php echo html::a($this->createLink('refund', 'reimburse', "type=total&refundID={$idList}&currency={$currency}&money={$currencyRefunds['total']}"), $lang->refund->common, "data-toggle='modal' data-width='400'");?>
      </td>
    </tr>
    <tr class='tr-child hide'>
      <td colspan='11'>
        <table class='table table-hover table-fixed'>
          <?php foreach($currencyRefunds['detail'] as $refund):?>
          <tr class='text-center' id='refund<?php echo $refund->id;?>' data-url='<?php echo $this->createLink('refund', 'view', "refundID={$refund->id}&mode={$mode}");?>'>
            <td class='w-50px'><?php echo $refund->id;?></td>
            <td class='w-100px text-left'><?php echo zget($deptList, $refund->dept, '');?></td>
            <td class='text-left' title='<?php echo $refund->name;?>'><?php echo $refund->name;?></td>
            <td class='w-120px text-left' title='<?php echo zget($categories, $refund->category);?>'><?php echo zget($categories, $refund->category, ' ');?></td>
            <td class='w-100px text-right'><?php echo zget($currencySign, $refund->currency) . $refund->money;?></td>
            <td class='w-90px refund-<?php echo $refund->status?>' title='<?php echo $refund->statusLabel;?>'><?php echo $refund->statusLabel;?></td>
            <td class='w-90px'><?php echo zget($userPairs, $refund->payee);?></td>
            <td class='w-90px'><?php echo formatTime($refund->createdDate, DT_DATE1);?></td>
            <td class='w-90px'><?php echo zget($userPairs, $refund->refundBy);?></td>
            <td class='w-90px'><?php echo formatTime($refund->refundDate, DT_DATE1)?></td>
            <td class='w-<?php echo $lang->refund->todoActionWidth;?>px text-left'>
              <?php echo html::a($this->createLink('refund', 'view', "refundID={$refund->id}&mode={$mode}"), $lang->detail);?>
              <?php echo html::a($this->createLink('refund', 'reimburse', "type=single&refundID={$refund->id}"), $lang->refund->common, "data-toggle='modal' data-width='400'");?>
            </td>
          </tr>
          <?php endforeach;?>
        </table>
      </td>
    </tr>
    <?php endforeach;?>
    <?php endforeach;?>
  </table>
  <div class='table-footer'>
    <?php $totalMoney = 0;//$this->refund->total($refunds);?>
    <?php if($totalMoney):?>
    <div class='pull-left text-danger'><?php echo $lang->refund->total . $totalMoney;?></div>
    <?php endif;?>
    <?php $pager->show();?>
  </div>
</div>
<script>
$('.refund-toggle').click(function()
{
    var $tr = $(this).parents('tr');
    $tr.find('i').toggleClass('icon-plus icon-minus');
    $tr.next('tr').toggle();
    return false;
});
</script>
