<?php
/**
 * The browse view file of receivable 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     receivable
 * @version     $Id$
 * @link        http://www.zdoo.com
 */
?>
<?php include $app->appRoot . 'common/view/header.html.php';?>
<?php js::set('mode', $mode);?>
<li id='bysearchTab'><?php echo html::a('javascript:;', "<i class='icon-search icon'></i>" . $lang->search->common);?></li>
<div id='menuActions'>
  <?php if(commonModel::hasPriv($moduleName, 'export')):?>
  <div class='btn-group'>
    <button data-toggle='dropdown' class='btn btn-secondary dropdown-toggle' type='button'><?php echo $lang->exportIcon . $lang->export;?> <span class='caret'></span></button>
    <ul id='exportActionMenu' class='dropdown-menu'>
      <li><?php echo html::a(inlink('export', 'mode=all'), $lang->exportAll, "class='iframe' data-width='700'");?></li>
      <li><?php echo html::a(inlink('export', 'mode=thisPage'), $lang->exportThisPage, "class='iframe' data-width='700'");?></li>
    </ul>
  </div>
  <?php endif;?>
  <?php commonModel::printLink($moduleName, 'create', '', "<i class='icon-plus'> </i>" . $lang->fund->create, "class='btn btn-primary' data-toggle='modal'");?>
</div>
<div class='panel main-table' data-ride='table'>
  <table class='table has-sort-head table-fixed'>
    <thead>
      <tr>
        <?php $vars = "mode=$mode&orderBy=%s&recTotal=$pager->recTotal&recPerPage=$pager->recPerPage&pageID=$pager->pageID";?>
        <th class='w-70px text-center'><?php commonModel::printOrderLink('id', $orderBy, $vars, $lang->fund->id);?></th>
        <th><?php commonModel::printOrderLink('trader', $orderBy, $vars, $lang->fund->trader);?></th>
        <th class='w-110px text-center'><?php commonModel::printOrderLink('origin', $orderBy, $vars, $lang->fund->origin);?></th>
        <th><?php commonModel::printOrderLink('contract', $orderBy, $vars, $lang->fund->contract);?></th>
        <th class='w-110px'><?php commonModel::printOrderLink('order', $orderBy, $vars, $lang->fund->order);?></th>
        <th class='w-110px'><?php commonModel::printOrderLink('batch', $orderBy, $vars, $lang->fund->batch);?></th>
        <th class='w-80px text-right'><?php commonModel::printOrderLink('deserved', $orderBy, $vars, $lang->fund->deserved);?></th>
        <th class='w-80px text-right'><?php commonModel::printOrderLink('actual', $orderBy, $vars, $lang->fund->actual);?></th>
        <th class='w-80px text-right'><?php commonModel::printOrderLink('balance', $orderBy, $vars, $lang->fund->balance);?></th>
        <th class='w-<?php echo $lang->fund->actionWidth;?>px text-center'><?php echo $lang->actions;?></th>
      </tr>
    </thead>
    <tbody>
      <?php $deserved = $actual = $balance = 0;?>
      <?php foreach($receivables as $receivable):?>
      <?php $deserved += $receivable->deserved;?>
      <?php $actual   += $receivable->actual;?>
      <?php
      if($receivable->deserved > $receivable->actual)
      {
          if($receivable->origin == 'contract')
          {
              if($receivable->return != 'done') $balance += $receivable->deserved - $receivable->actual;
          }
          else
          {
              $balance += $receivable->deserved - $receivable->actual;
          }
      }
      ?>
      <tr>
        <td class='text-center'><?php echo $receivable->id;?></td>
        <td title='<?php echo zget($customers, $receivable->trader, '');?>'><?php echo zget($customers, $receivable->trader, '');?></td>
        <td class='text-center'><?php echo $lang->fund->originList[$receivable->origin];?></td>
        <td title='<?php echo zget($contracts, $receivable->contract, '');?>'><?php echo zget($contracts, $receivable->contract, '');?></td>
        <td title='<?php echo zget($orders, $receivable->order, '');?>'><?php echo zget($orders, $receivable->order, '');?></td>
        <td title='<?php echo zget($batches, $receivable->batch, '');?>'><?php echo zget($batches, $receivable->batch, '');?></td>
        <td class='text-right'><?php echo formatMoney($receivable->deserved);?></td>
        <td class='text-right'><?php echo formatMoney($receivable->actual);?></td>
        <td class='text-right'><?php echo formatMoney($receivable->balance);?></td>
        <td class='text-center'>
          <?php
          $method = $moduleName == 'receivable' ? 'receive' : 'pay';
          $label  = $moduleName == 'receivable' ? $lang->receivable->receive : $lang->payable->pay;
          if($receivable->deserved > $receivable->actual && $receivable->return != 'done')
          {
              commonModel::printLink($moduleName, $method, "payableID=$receivable->id", $label, "data-toggle='modal'");
          }
          elseif($mode == 'bysearch')
          {
              echo html::a('javascript:;', $label, "class='disabled'");
          }
          commonModel::printLink($moduleName, 'edit', "receivableID=$receivable->id", $lang->edit, "data-toggle='modal'");
          commonModel::printLink($moduleName, 'view', "receivableID=$receivable->id&mode=$mode", $lang->view);
          commonModel::printLink($moduleName, 'delete', "receivableID=$receivable->id", $lang->delete, "class='deleter'");
          ?>
        </td>
      </tr>
      <?php endforeach;?>
    </tbody>
  </table>
  <div class='table-footer'>
    <?php if($receivables):?>
    <div class='table-statistic'>
      <?php printf($lang->fund->totalMoney, $totalMoney->deserved, $totalMoney->actual, $totalMoney->balance, $deserved, $actual, $balance);?>
    </div>
    <?php endif;?>
    <?php $pager->show();?>
  </div>
</div>
<?php include $app->appRoot . 'common/view/footer.html.php';?>
