<?php
/**
 * The report view file of invoice 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     invoice 
 * @version     $Id$
 * @link        http://www.zdoo.com
 */
?>
<?php include '../../common/view/header.html.php';?>
<?php include '../../../sys/common/view/chart.html.php';?>
<?php js::set('status', array_keys($lang->invoice->statusList));?>
<?php js::set('colors', $config->invoice->colorList);?>
<?php js::set('company', $currentCompany);?>
<?php js::set('month', $currentMonth);?>
<?php if($currentMonth) js::set('companies', $companies);?>
<?php $unitList = $lang->invoice->report->unitList;?>
<div class='panel'>
  <div class='panel-heading'>
    <div class='date dropdown'>
      <?php
      $yearLabel = $currentYear;
      if($this->app->getClientLang() == 'zh-cn' or $this->app->getClientLang() == 'zh-tw')
      {
          $monthLabel = $currentMonth ? (int)$currentMonth . $lang->month : '';
          if($monthLabel) $yearLabel .= $lang->year . $monthLabel;
      }
      else
      {
          $monthLabel = zget($lang->invoice->monthList, $currentMonth, '');
          if($monthLabel) $yearLabel = $monthLabel . ', ' . $yearLabel . ' ';
      }
      ?>
      <button type='button' class='btn btn-sm btn-default dropdown-toggle' data-toggle='dropdown'><?php echo $yearLabel;?> <span class="caret"></span></button>
      <ul class='dropdown-menu'>
        <?php foreach($monthList as $year => $months):?>
        <li class='dropdown-submenu'>
          <?php echo html::a(inlink('report', "company=$currentCompany&month=$year&unit=$currentUnit"), $year);?>
          <ul class='dropdown-menu'>
            <?php foreach($months as $month):?>
            <?php $monthLabel = (($this->app->getClientLang() == 'zh-cn' or $this->app->getClientLang() == 'zh-tw') ? $month . $lang->month : zget($lang->invoice->monthList, $month, ''));?>
            <li><?php echo html::a(inlink('report', "company=$currentCompany&month=$year$month&unit=$currentUnit"), $monthLabel);?></li>
            <?php endforeach;?>
          </ul>
        </li>
        <?php endforeach;?>
      </ul>
    </div>
    <div class='company dropdown'>
      <button type='button' class='btn btn-sm btn-default dropdown-toggle' data-toggle='dropdown'><?php echo zget($companies, $currentCompany, $lang->invoice->company);?> <span class="caret"></span></button>
      <ul class='dropdown-menu'>
        <?php foreach($companies as $companyID => $companyName):?>
        <li><?php echo html::a(inlink('report', "company=$companyID&month=$currentYear$currentMonth&unit=$currentUnit"), $companyName);?></li>
        <?php endforeach;?>
      </ul>
    </div>
    <div class='unit dropdown'>
      <button type='button' class='btn btn-sm btn-default dropdown-toggle' data-toggle='dropdown'><?php echo zget($unitList, $currentUnit, zget($unitList, 1));?> <span class='caret'></span></button>
      <ul class='dropdown-menu'>
        <?php foreach($unitList as $key => $unit):?>
        <li><?php echo html::a(inlink('report', "company=$currentCompany&month=$currentYear$currentMonth&unit=$key"), $unit);?></li>
        <?php endforeach;?>
      </ul>
    </div>
  </div>
  <div class='panel-body'>
    <?php if($currentMonth):?>
    <?php foreach($data as $monthKey => $monthData):?>
    <table class='table active-disabled'>
      <tr>
        <td colspan='3' class='annual'>
          <div class='chart-wrapper text-center'>
            <h5><?php echo $yearLabel . zget($companies, $currentCompany) . $lang->invoice->report->title . '(' . zget($unitList, $currentUnit, zget($unitList, 1)) . ')';?></h5>
            <div class='chart-canvas'><canvas height='260' width='800' id='chart-<?php echo $currentMonth;?>'></canvas></div>
          </div>
        </td>
        <td class='w-500px annual hasTable'>
          <div style="overflow:auto;" class='table-wrapper'>
            <table id='barChart-<?php echo $monthKey;?>' class='table table-condensed table-hover table-striped table-bordered table-chart table-fixed' data-chart='bar' data-target='#myBarChart' data-animation='false'>
              <thead>
                <tr class='text-center'>
                  <th class='w-200px'><?php echo $lang->invoice->company;?></th>
                  <?php foreach($lang->invoice->statusList as $status => $label):?>
                  <th class='chart-label-<?php echo $status;?>'><i class='chart-color-dot-<?php echo $status;?> icon-circle'></i> <?php echo $label;?></th>
                  <?php endforeach;?>
                </tr>
              </thead>
              <tbody>
              <?php foreach($monthData as $companyKey => $companyData):?>
              <tr class='text-center'>
                <td class='chart-label <?php if($companyKey != 'total') echo 'text-left';?>' title='<?php echo zget($companies, $companyKey, $lang->invoice->total);?>'><?php echo zget($companies, $companyKey, $lang->invoice->total);?></td>
                <?php foreach($lang->invoice->statusList as $status => $label):?>
                <td class='chart-value-<?php echo $status;?> text-right'><?php echo number_format(round(zget($companyData, $status, 0) / $currentUnit, 2), 2);?></td>
                <?php endforeach;?>
              </tr>
              <?php endforeach;?>
              </tbody>
            </table>
          </div>
        </td>
      </tr>
    </table>
    <?php endforeach;?>
    <?php else:?>
    <?php foreach($data as $companyKey => $companyData):?>
    <table class='table active-disabled'>
      <tr>
        <td colspan='3' class='annual'>
          <div class='chart-wrapper text-center'>
            <h5><?php echo $yearLabel . zget($companies, $companyKey) . $lang->invoice->report->title . '(' . zget($unitList, $currentUnit, zget($unitList, 1)) . ')';?></h5>
            <div class='chart-canvas'><canvas height='260' width='800' id='chart-<?php echo $companyKey;?>'></canvas></div>
          </div>
        </td>
        <td class='w-400px annual'>
          <div style="overflow:auto;" class='table-wrapper'>
            <table id='barChart-<?php echo $companyKey;?>' class='table table-condensed table-hover table-striped table-bordered table-chart' data-chart='bar' data-target='#myBarChart' data-animation='false'>
              <thead>
                <tr class='text-center'>
                  <th><?php echo $lang->invoice->month;?></th>
                  <?php foreach($lang->invoice->statusList as $status => $label):?>
                  <th class='chart-label-<?php echo $status;?>'><i class='chart-color-dot-<?php echo $status;?> icon-circle'></i> <?php echo $label;?></th>
                  <?php endforeach;?>
                </tr>
              </thead>
              <tbody>
              <?php foreach($companyData as $monthKey => $monthData):?>
              <tr class='text-center'>
                <td class='chart-label'><?php echo $monthKey == 'total' ? $lang->invoice->total : $monthKey;?></td>
                <?php foreach($lang->invoice->statusList as $status => $label):?>
                <td class='chart-value-<?php echo $status;?> text-right'><?php echo number_format(round(zget($monthData, $status, 0) / $currentUnit, 2), 2);?></td>
                <?php endforeach;?>
              </tr>
              <?php endforeach;?>
              </tbody>
            </table>
          </div>
        </td>
      </tr>
    </table>
    <?php endforeach;?>
    <?php endif;?>
  </div>
</div>
<?php include '../../common/view/footer.html.php';?>
