<?php
/**
 * The browse account view file of kingdee module of ZDOO.
 *
 * @copyright   Copyright 2009-2018 青岛易软天创网络科技有限公司(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     kingdee
 * @version     $Id$
 * @link        http://www.zdoo.com
 */
?>
<?php include '../../common/view/header.html.php';?>
<?php js::set('status', $status);?>
<?php js::set('confirmation', $lang->voucher->confirmation);?>
<?php
$canBatchConfirm = commonModel::hasPriv('kingdee', 'batchConfirmVoucher');
$canBatchDelete  = commonModel::hasPriv('kingdee', 'batchDeleteVoucher');
$canBatchAction  = ($vouchers && ($canBatchConfirm or $canBatchDelete));
?>
<div id='menuActions'>
  <?php commonModel::printLink('kingdee', 'exportVoucher', "company={$company}", $lang->exportIcon . $lang->kingdee->exportVoucher, "class='btn btn-secondary iframe' data-width='900'");?>
  <?php commonModel::printLink('kingdee', 'batchCreateVoucher', "company={$company}", "<i class='icon icon-plus'> </i>" . $lang->kingdee->batchCreateVoucher, "class='btn btn-secondary'");?>
</div>
<div class='main-row'>
  <div class='side-col w-160px'>
    <div class='panel'>
      <div class='panel-body'>
        <ul class='tree' data-collapsed='true'>
          <?php foreach($yearList as $year):?>
          <?php foreach($monthList[$year] as $month):?>
          <li class='<?php echo ($year == $currentYear and $month == $currentMonth) ? 'active' : ''?>'>
            <?php commonModel::printLink('kingdee', 'browseVoucher', "company={$company}&date=$year$month&status=$status", $year . $month);?>
          </li>
          <?php endforeach;?>
          <?php endforeach;?>
        </ul>
      </div>
    </div>
  </div>
  <div class='main-col'>
    <div class='panel main-table' data-ride='table'>
      <?php if($canBatchAction && $status == 'wait'):?>
      <form id='jaxForm' method='post'>
      <?php endif;?>
        <table class='table' id='voucherTable'>
          <thead>
            <tr class='text-center'>
              <th class='w-70px text-left'>
                <?php if($canBatchAction && $status == 'wait'):?>
                <div class='checkbox-primary check-all' title='<?php echo $this->lang->selectAll;?>'><label></label></div>
                <?php endif;?>
                <?php echo $lang->voucher->FNumber;?>
              </th>
              <th class='w-50px'><?php echo $lang->voucher->FGroupID;?></th>
              <th><?php echo $lang->voucher->FExplanation;?></th>
              <th class='w-200px'><?php echo $lang->voucher->FAccountName;?></th>
              <th class='w-60px'><?php echo $lang->voucher->FCurrencyName;?></th>
              <th class='w-100px text-right'><?php echo $lang->voucher->FAmountFor;?></th>
              <th class='w-100px text-right'><?php echo $lang->voucher->FDebit;?></th>
              <th class='w-100px text-right'><?php echo $lang->voucher->FCredit;?></th>
              <th class='w-80px'><?php echo $lang->voucher->status;?></th>
              <th><?php echo $lang->voucher->FItem;?></th>
              <th class='w-140px'><?php echo $lang->actions;?></th>
            </tr>
          </thead>
          <tbody>
            <?php foreach($vouchers as $voucher):?>
            <?php $i = 1;?>
            <?php foreach($voucher->detailList as $voucherDetail):?>
            <tr class='text-center'>
              <td class='text-left'>
                <?php if($canBatchAction && $status == 'wait'):?>
                <div class='checkbox-primary'>
                  <input type='checkbox' name='voucherIDList[]' value="<?php echo $voucher->id;?>" id="voucherIDList<?php echo $voucher->id;?>">
                  <label for="voucherIDList<?php echo $voucher->id;?>"></label>
                </div>
                <?php endif;?>
                <?php echo $voucher->number;?>
              </td>
              <td><?php echo $voucher->type;?></td>
              <td class='text-left'><?php echo $voucherDetail->explanation;?> </td>
              <td class='text-left'><?php echo zget($accountPairs, $voucherDetail->account);?> </td>
              <td><?php echo zget($this->lang->currencyList, strtolower($voucherDetail->currency));?> </td>
              <td class='text-right'><?php echo $voucherDetail->debit != 0 ? $voucherDetail->debit : $voucherDetail->credit;?> </td>
              <td class='text-right'><?php echo $voucherDetail->debit;?> </td>
              <td class='text-right'><?php echo $voucherDetail->credit;?> </td>
              <?php $class = $voucher->status == 'wait' ? 'text-danger' : 'text-success';?>
              <td class='<?php echo $class;?>'><?php echo zget($lang->voucher->statusList, $voucher->status);?> </td>
              <td class='text-left' title='<?php echo $voucherDetail->item;?>'><?php echo $voucherDetail->item;?> </td>
              <td>
                <?php if($i == 1):?>
                <?php if($voucher->status == 'wait'):?>
                <?php commonModel::printLink('kingdee', 'confirmVoucher', "id={$voucher->id}", $lang->confirm, "class='jsoner'");?>
                <?php else:?>
                <?php echo html::a('javascript:;', $lang->confirm, "disabled='disabled' class='disabled'");?>
                <?php endif;?>

                <?php commonModel::printLink('kingdee', 'editVoucher', "id={$voucher->id}", $lang->edit);?>
                <?php commonModel::printLink('kingdee', 'deleteVoucher', "id={$voucher->id}", $lang->delete, "class='deleter'");?>
                <?php echo html::a('javascript:;', $lang->kingdee->more, "class='showMore' data-voucher={$voucher->number}");?>
                <?php endif;?>
              </td>
            </tr>
            <?php $i++;?>
            <?php endforeach;?>
    
            <tr class='relatedData<?php echo $voucher->number;?> hide'>
              <td colspan='11'>
                <table class='w-p100'>
                  <tr>
                    <th class='w-p50 no-padding'>
                      <table class='table table-bordered'>
                        <tr class='text-center'>
                          <th class='w-100px'><?php echo $lang->invoice->drawnDate;?></th>
                          <th class='w-200px'><?php echo $lang->invoice->sn;?></th>
                          <th><?php echo $lang->invoice->invoiceTitle;?></th>
                          <th class='w-120px'><?php echo $lang->invoice->money;?></th>
                        </tr>
                      </table>
                    </th>
                    <th class='table no-padding'>
                      <table class='w-p100 table-bordered'>
                        <tr class='text-center'>  
                          <th class='w-120px'><?php echo $lang->trade->date;?></th>
                          <th><?php echo $lang->trade->customer;?></th>
                          <th class='w-120px'><?php echo $lang->trade->money;?></th>
                        </tr>
                      </table>
                    </th>
                  </tr>
                  <?php foreach($voucher->relatedDataList as $type => $relatedDatas):?>
                  <?php foreach($relatedDatas as $relatedDataID):?>
                  <?php
                  $trades = array();
                  unset($invoice);
                  if($type == 'invoices')
                  {
                      if(isset($statistics['both'][$relatedDataID]))
                      {
                          $invoice = $statistics['both'][$relatedDataID]['invoice'];
                          $trades  = $statistics['both'][$relatedDataID]['trade'];
                      } 
                      elseif(isset($statistics['invoice'][$relatedDataID]))
                      {
                          $invoice = $statistics['invoice'][$relatedDataID]['invoice'];
                          $trades  = array();
                      }
                  }
                  else
                  {
                      if(isset($statistics['trade'][$relatedDataID]['trade'])) $trades = $statistics['trade'][$relatedDataID]['trade'];
                  }
    
                  $rowspan = count($trades) ? count($trades) : 1;
                  ?>
                  <?php if(!isset($invoice) && empty($trades)) continue;?>
                  <tr>
                    <td class='w-p50 no-padding'>
                      <?php if(!empty($invoice)):?>
                      <table class='table table-bordered'>
                        <tr class='text-center' rowspan='<?php echo $rowspan;?>'>
                          <td class='w-100px'><?php echo formatTime($invoice->drawnDate, DT_DATE1);?></td>
                          <td class='w-200px'><?php echo $invoice->sn;?></td>
                          <td><?php echo $invoice->invoiceTitle;?></td>
                          <td class='w-120px text-right' rowspan='<?php echo $rowspan;?>' title='<?php echo $lang->detail;?>'>
                            <?php if($invoice->id):?>
                            <?php echo html::a($this->createLink('cash.invoice', 'view', "invoiceID={$invoice->id}"), number_format($invoice->money, 2));?>
                            <?php else:?>
                            <?php echo $invoice->money ? number_format($invoice->money, 2) : '&nbsp;';?>
                            <?php endif;?>
                          </td>
                        </tr>
                      </table>
                      <?php endif;?>
                    </td>
                    <td class='w-p50 no-padding'>
                      <table class='table table-bordered'>
                        <?php if($trades):?>
                        <?php foreach($trades as $trade):?>
                        <?php $tradeID     = zget($trade, 'id', 0);?>
                        <?php $date        = formatTime(zget($trade, 'date', ''), DT_DATE1);?>
                        <?php $customer    = zget($customers, zget($trade, 'trader', ''), '&nbsp;');?>
                        <?php $tradeMoney  = zget($trade, 'money', 0);?>
                        <tr>
                          <td class='w-120px text-center'><?php echo $date;;?></td>
                          <td title='<?php echo $customer;?>'><?php echo $customer;?></td>
                          <td class='w-120px text-right' title='<?php echo $lang->detail;?>'>
                            <?php if($tradeID):?>
                            <?php echo html::a($this->createLink('cash.trade', 'view', "tradeID={$tradeID}&mode=in"), number_format($tradeMoney, 2));?>
                            <?php else:?>
                            <?php echo $tradeMoney ? number_format($tradeMoney, 2) : '&nbsp;';?>
                            <?php endif;?>
                          </td>
                        </tr>
                        <?php endforeach;?>
                        <?php else:?>
                        <tr>
                          <td class='w-120px'>&nbsp;</td>
                          <td>&nbsp;</td>
                          <td class='w-120px'>&nbsp;</td>
                        </tr>
                        <?php endif;?>
                      </table>
                    </td>
                  </tr>
                  <?php endforeach;?>
                  <?php endforeach;?>
                </table>
              </td>
            </tr>
            <?php endforeach;?>
          </tbody>
        </table>
        <div class='table-footer'>
          <?php if($canBatchAction && $status == 'wait'):?>
          <div class='checkbox-primary check-all'><label><?php echo $lang->selectAll?></label></div>
          <div class='table-actions btn-toolbar'>
            <div class='btn-group dropup no-margin-top'>
              <?php
              $confirmLink = $this->createLink('kingdee', 'batchConfirmVoucher');
              $class      = $canBatchConfirm ? '' : 'disabled';
              echo html::commonButton($lang->confirm, "btn btn-default $class", "data-form-action='{$confirmLink}'");
              ?>
              <?php if($canBatchDelete):?>
              <button type='button' class='btn dropdown-toggle' data-toggle='dropdown'><span class='caret'></span></button>
              <ul class='dropdown-menu'>
                <?php
                if($canBatchDelete)
                {
                    $deleteLink = $this->createLink('kingdee', 'batchDeleteVoucher');
                    echo '<li>' . html::a('javascript:;', $lang->delete, "onclick=\"setFormAction('$deleteLink')\"") . '</li>';
                }
                ?>
              </ul>
              <?php endif;?>
            </div>
          </div>
          <?php endif;?>
        </div>
      <?php if($canBatchAction && $status == 'wait'):?>
      </form>
      <?php endif;?>
    </div>
  </div>
</div>
<?php include '../../common/view/footer.html.php';?>
