<?php
/**
 * The view file of trade 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      Tingting Dai <daitingting@xirangit.com>
 * @package     contract
 * @version     $Id$
 * @link        http://www.zdoo.com
 */
?>
<?php include '../../common/view/header.html.php';?>
<?php js::set('modeType', $mode);?>
<?php $browseLink = $this->session->tradeList ? $this->session->tradeList : inlink('browse');?>
<div id='mainTitle' class='clearfix'>
  <div class='btn-toolbar pull-left'>
    <?php if(!isonlybody()):?>
    <?php echo html::a($browseLink, '<i class="icon icon-back icon-sm"></i> ' . $lang->goback, "class='btn btn-back'");?>
    <div class="divider"></div>
    <?php endif;?>
    <div class="page-title">
      <span class="label label-id"><?php echo $trade->id?></span>
      <span class="text"><?php echo $lang->trade->view; ?></span>
    </div>
  </div>
</div>
<div class='main-row'>
  <div class='main-col col-8'>
    <div class='panel panel-block'>
      <div class='panel-heading'><strong><?php echo $lang->trade->desc;?></strong></div>
      <div class='panel-body'>
        <?php echo $trade->desc;?>
        <div><?php echo $this->fetch('file', 'printFiles', array('files' => $trade->files, 'fieldset' => 'false'))?></div>
      </div>
    </div>
    <?php echo $this->fetch('action', 'history', "objectType=trade&objectID={$trade->id}")?>
    <div class='main-actions'>
      <div class='btn-toolbar'>
        <?php
        commonModel::printBack($browseLink);
        echo "<div class='divider'></div>";

        if($mode == 'transfer')
        {
            if(commonModel::hasPriv('trade', 'edit'))
            {
                echo html::a($this->createLink('trade', 'editTransfer', "tradeID={$trade->id}"), $lang->edit, "class='btn'");
            }
        }
        else
        {
            commonModel::printLink('trade', 'edit', "tradeID={$trade->id}&mode={$mode}", $lang->edit, "class='btn'");
        }
        commonModel::printLink('trade', 'detail', "tradeID={$trade->id}", $lang->trade->detail, "data-toggle='modal' class='btn'");
        commonModel::printLink('trade', 'delete', "tradeID={$trade->id}", $lang->delete, "class='deleter btn'");
        echo "<div class='divider'></div>";
        commonModel::printRPN($preAndNext);
        ?>
      </div>
    </div>
  </div>
  <div class='side-col col-4'>
    <div class='panel panel-block'>
      <div class='panel-heading'>
        <strong><?php echo $lang->basicInfo;?></strong>
      </div>
      <div class='panel-body'>
        <table class='table table-data'>
          <tr>
            <th class='w-80px'><?php echo $lang->trade->date;?></th>
            <td><?php echo formatTime($trade->date, DT_DATE1);?></td>
          </tr>
          <?php if($trade->type == 'invest' or $trade->type == 'loan'):?>
          <tr>
            <th><?php echo $lang->trade->deadline;?></th>
            <td><?php echo formatTime($trade->deadline, DT_DATE1);?></td>
          </tr>
          <?php endif;?>
          <?php if($trade->type == 'transferout'):?>
          <tr>
            <th><?php echo $lang->trade->type;?></th>
            <td><?php echo $lang->trade->transfer;?></td>
          </tr>
          <tr>
            <th><?php echo $lang->trade->payment;?></th>
            <td><?php echo zget($depositors, $trade->depositor, '');?></td>
          </tr>
          <?php if(!empty($trade->transferIn)):?>
          <tr>
            <th><?php echo $lang->trade->receipt;?></th>
            <td><?php echo zget($depositors, $trade->transferIn->depositor, '');?></td>
          </tr>
          <?php endif;?>
          <tr>
            <th><?php echo $lang->trade->transferOut;?></th>
            <td><?php echo zget($currencySign, $trade->currency) . formatMoney($trade->money);?></td>
          </tr>
          <?php if(!empty($trade->transferIn)):?>
          <tr>
            <th><?php echo $lang->trade->transferIn;?></th>
            <td><?php echo zget($currencySign, $trade->transferIn->currency) . formatMoney($trade->transferIn->money);?></td>
          </tr>
          <?php endif;?>
          <?php if(!empty($trade->fee)):?>
          <tr>
            <th><?php echo $lang->trade->fee;?></th>
            <td><?php echo zget($currencySign, $trade->fee->currency) . formatMoney($trade->fee->money);?></td>
          </tr>
          <?php endif;?>
          <?php else:?>
          <tr>
            <th><?php echo $lang->trade->type;?></th>
            <td><?php echo $lang->trade->typeList[$trade->type];?></td>
          </tr>
          <tr>
            <th><?php echo $lang->trade->money;?></th>
            <td><?php echo zget($currencySign, $trade->currency) . formatMoney($trade->money);?></td>
          </tr>
          <?php if($trade->currency != $config->setting->mainCurrency):?>
          <tr>
            <th><?php echo $lang->trade->depositor;?></th>
            <td><?php echo zget($depositors, $trade->depositor, '');?></td>
          </tr>
          <tr>
            <th><?php echo $lang->trade->exchangeRate;?></th>
            <td><?php echo $trade->exchangeRate;?></td>
          </tr>
          <?php endif;?>
          <?php endif;?>
          <tr>
            <th><?php echo $lang->trade->dept;?></th>
            <td><?php echo !empty($dept->name) ? $dept->name : '';?></td>
          </tr>
          <tr>
            <th><?php echo $lang->trade->handlers;?></th>
            <td title='<?php foreach(explode(',', $trade->handlers) as $handler) echo zget($users, $handler) . ' ';?>'><?php foreach(explode(',', $trade->handlers) as $handler) echo zget($users, $handler) . ' ';?></td>
          </tr>
          <?php if($trade->type == 'in' or $trade->type == 'out'):?>
          <tr>
            <th><?php echo $lang->trade->product;?></th>
            <td><?php echo !empty($product->name) ? $product->name : '';?></td>
          </tr>
          <?php endif;?>
          <?php if($trade->type == 'in' or $trade->type == 'out'):?>
          <tr>
            <th><?php echo $lang->trade->category;?></th>
            <td><?php echo !empty($category->name) ? $category->name : '';?></td>
          </tr>
          <?php endif;?>
          <?php if($trade->trader and $trade->type == 'out'):?>
          <tr>
            <th><?php echo (!empty($trader->type) && $trader->type != 'provider') ? $lang->trade->customer : $lang->trade->trader;?></th>
            <td><?php echo !empty($trader->name) ? $trader->name : '';?></td>
          </tr>
          <?php endif;?>
          <?php if($trade->trader and $trade->type == 'in'):?>
          <tr>
            <th><?php echo $lang->trade->customer;?></th>
            <td><?php echo !empty($trader->name) ? $trader->name : '';?></td>
          </tr>
          <?php endif;?>
          <?php if($trade->order):?>
          <tr>
            <th><?php echo $lang->trade->order;?></th>
            <td><?php echo zget($orderList, $trade->order, '');?></td>
          </tr>
          <?php endif;?>
          <?php if($trade->contract):?>
          <tr>
            <th><?php echo $lang->trade->contract;?></th>
            <td><?php echo !empty($contract->name) ? $contract->name : '';?></td>
          </tr>
          <?php endif;?>
          <tr>
            <th><?php echo $lang->trade->createdBy;?></th>
            <td><?php echo zget($users, $trade->createdBy);?></td>
          </tr>
          <tr>
            <th><?php echo $lang->trade->createdDate;?></th>
            <td><?php echo formatTime($trade->createdDate, DT_DATE1);?></td>
          </tr>
          <tr>
            <th><?php echo $lang->trade->editedBy;?></th>
            <td><?php echo zget($users, $trade->editedBy);?></td>
          </tr>
          <tr>
            <th><?php echo $lang->trade->editedDate;?></th>
            <td><?php echo formatTime($trade->editedDate, DT_DATE1);?></td>
          </tr>
        </table>
      </div>
    </div>
  </div>
</div>
<?php include '../../common/view/footer.html.php';?>
