<?php
/**
 * The browse view file of budget module of ZDOO.
 *
 * @copyright   Copyright 2009-2017 青岛易软天创网络科技有限公司(QingDao Nature Easy Soft Network Technology Co,LTD, www.cnezsoft.com)
 * @license     ZPL (http://zpl.pub/page/zplv12.html)
 * @author      Gang Liu <liugang@cnezsoft.com>
 * @package     budget
 * @version     $Id$
 * @link        http://www.zdoo.com
 */
?>
<?php include '../../common/view/header.html.php';?>
<?php $clientLang = $this->app->getClientLang();?>
<div id='menuActions'>
  <?php commonModel::printLink('budget', 'export', "period={$period}&year={$year}&month={$month}&week={$week}&dept={$dept}&amebaAccount={$amebaAccount}", $lang->exportIcon . $lang->export, "class='btn btn-secondary iframe' data-width='700'");?>
  <?php if($period == 'year'):?>
  <div class='btn-group'>
    <button period='button' data-toggle='dropdown' class='btn btn-primary dropdown-toggle'>
      <i class='icon icon-plus'> </i><?php echo $lang->budget->yearBudget;?> <span class='caret'></span>
    </button>
    <ul class='dropdown-menu'>
      <?php commonModel::printLink('budget', 'create', '', $lang->budget->create, "data-toggle='modal'", true, false, 'li');?>
      <?php commonModel::printLink('budget', 'batchCreate', "period=year&year={$year}&month=&week=&dept={$dept}&amebaAccount={$amebaAccount}&method=browse", $lang->budget->batchCreate, '', true, false, 'li');?>
    </ul>
  </div>
  <?php endif;?>
  <?php if($period == 'year') commonModel::printLink('budget', 'batchCreate', "period=month&year={$year}&month=&week=&dept={$dept}&amebaAccount=&method=report", "<i class='icon icon-plus'> </i>" . $lang->budget->monthBudget, "class='btn btn-primary'");?>
  <?php if($period == 'month') commonModel::printLink('budget', 'batchCreate', "period=week&year={$year}&month={$month}&week=&dept={$dept}&amebaAccount=&method=report", "<i class='icon icon-plus'> </i>" . $lang->budget->weekBudget, "class='btn btn-primary'");?>
  <?php if(strpos(",{$amebaConfig->shareDepts},", ",{$dept},") !== false && $amebaAccount == 'shareExpense') commonModel::printLink('budget', 'share', "period=all&year={$year}&month={$month}&week={$week}&dept={$dept}&amebaAccount={$amebaAccount}", "<i class='icon icon-sitemap'> </i>" . $lang->budget->share, "class='btn btn-primary' data-toggle='modal' data-width='400'");?>
</div>
<div class='panel main-table' data-ride='table'>
  <table class='table has-sort-head'>
    <thead>
      <tr class='text-center'>
        <?php $vars = "period={$period}&year={$year}&month={$month}&week={$week}&dept={$dept}&amebaAccount={$amebaAccount}&orderBy=%s&recTotal={$pager->recTotal}&recPerPage={$pager->recPerPage}&pageID={$pager->pageID}";?>
        <th class='w-60px'> <?php commonModel::printOrderLink('id', $orderBy, $vars, $lang->budget->id);?></th>
        <th class='w-70px'><?php commonModel::printOrderLink('year', $orderBy, $vars, $lang->budget->year);?></th>
        <th class='w-100px'><?php commonModel::printOrderLink('dept', $orderBy, $vars, $lang->budget->dept);?></th>
        <?php $class = ($clientLang == 'en' ? 'w-130px' : 'w-100px');?>
        <th class='<?php echo $class;?>'><?php commonModel::printOrderLink('amebaAccount', $orderBy, $vars, $lang->budget->amebaAccount);?></th>
        <?php if($amebaAccount == 'internalIncome' or $amebaAccount == 'internalDeal'):?>
        <th class='w-100px'><?php commonModel::printOrderLink('tradeDept', $orderBy, $vars, $lang->budget->tradeDept);?></th>
        <?php endif;?>
        <?php $class = ($clientLang == 'en' ? 'w-200px' : 'w-160px');?>
        <th class='<?php echo $class;?>'><?php commonModel::printOrderLink('line', $orderBy, $vars, $lang->budget->line);?></th>
        <th class='<?php echo $class;?> text-left'><?php commonModel::printOrderLink('product', $orderBy, $vars, $lang->budget->product);?></th>
        <th class='w-160px text-left'><?php commonModel::printOrderLink('category', $orderBy, $vars, $lang->budget->category);?></th>
        <th class='w-100px text-right'><?php commonModel::printOrderLink('money', $orderBy, $vars, $lang->budget->money);?></th>
        <th><?php echo $lang->budget->desc;?></th>
        <th class='w-140px'><?php echo $lang->actions;?></th>
      </tr>
    </thead>
    <?php $totalMoney = 0;?>
    <?php foreach($budgetList as $budget):?>
    <?php $totalMoney += $budget->money;?>
    <tr class='text-center'>
      <td><?php if(!commonModel::printLink('budget', 'view', "period={$period}&budgetID={$budget->id}", $budget->id)) echo $budget->id;?></td>
      <td><?php echo $budget->year;?></td>
      <td><?php echo zget($deptList, $budget->dept);?></td>
      <td><?php echo zget($lang->budget->amebaAccountList, $budget->amebaAccount);?></td>
      <?php if($amebaAccount == 'internalIncome' or $amebaAccount == 'internalDeal'):?>
      <td><?php echo zget($deptList, $budget->tradeDept, '');?></td>
      <?php endif;?>
      <td><?php echo zget($productLines, $budget->line, '');?></td>
      <td class='text-left'><?php echo zget($products, $budget->product, '');?></td>
      <td class='text-left'><?php echo zget($categoryList, $budget->category);?></td>
      <td class='text-right'><?php echo formatMoney($budget->money);?></td>
      <td class='text-left' title='<?php echo $budget->desc;?>'><?php echo $budget->desc;?></td>
      <td>
        <?php commonModel::printLink('budget', 'view',   "period={$period}&budgetID={$budget->id}", $lang->detail);?>
        <?php if($period == 'year') commonModel::printLink('budget', 'edit',   "budgetID={$budget->id}", $lang->edit,   "data-toggle='modal'");?>
        <?php if($period == 'year') commonModel::printLink('budget', 'delete', "budgetID={$budget->id}", $lang->delete, "class='deleter'");?>
      </td>
    </tr>
    <?php endforeach;?>
  </table>
  <div class='table-footer'>
    <?php if(!empty($totalMoney)):?>
    <div class='table-statistic'>
      <?php printf($lang->budget->totalMoney, formatMoney($totalMoney));?>
    </div>
    <?php endif;?>
    <?php echo $pager->show();?>
  </div>
</div>
<?php include '../../common/view/footer.html.php';?>
