<?php
/**
 * The view file for the method of view of order 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     customer
 * @version     $Id$
 * @link        http://www.zdoo.com
 */
?>
<?php include '../../common/view/header.html.php'; ?>
<?php include '../../../sys/common/view/editor.html.php';?>
<?php
$customerLink = html::a($this->createLink('customer', 'view', "customerID={$customer->id}"), $customer->name);
$productLink = '';
$productText = '';
foreach($order->products as $product)
{
    $productLink .= html::a($this->createLink('product', 'view', "productID={$product->id}"), $product->name);
    $productText .= $product->name . ' ';
}
$browseLink = $this->session->orderList ? $this->session->orderList : inlink('browse');
$orderName = sprintf($lang->order->infoBuy, $customer->name, $productText);
?>
<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 $order->id?></span>
      <span class="text" title='<?php echo $orderName; ?>'><?php echo $orderName; ?></span>
    </div>
  </div>
</div>
<div class='main-row'>
  <div class='main-col col-8'>
    <div class='panel panel-block table-row' id='orderDetailPanel'>
      <?php if($contract) $contractLink = html::a($this->createLink('contract', 'view', "contractID={$contract->id}"), $contract->name);?>
      <div class='panel-heading table-col col-5 no-padding-right text-middle'>
        <div class='table-row table-auto'>
          <div class='table-col col-10 text-md strong title'>
            <div class='table-row space-sm'><?php echo $customerLink;?></div>
            <div class='table-row space-sm'><?php echo $productLink;?></div>
            <div class='table-row'>
            <?php if(!empty($lang->customer->levelNameList[$customer->level])):?>
            <span class='label label-pale label-lg'><span class='text-yellow'><?php echo $lang->customer->levelNameList[$customer->level];?></span></span>
            <?php endif;?>
            <span class='label label-pale label-lg'><?php echo $lang->order->statusList[$order->status];?></span>
            </div>
          </div>
          <div class='table-col col-2 text-md text-right has-padding-sm-h no-padding-right'>
           <?php echo $lang->order->buy;?>
          </div>
          <div class="table-col divider-right has-padding-h"></div>
        </div>
      </div>
      <div class='panel-body table-col has-padding-lg no-padding-left col-7'>
        <div class='table-row width-auto'>
          <?php if($contract):?>
          <div class='table-row'>
            <div class='table-col has-padding-lg-h has-padding-sm-v'>
              <span class='text-gray space-sm has-padding-lg-h no-padding-left'><?php echo $lang->order->infoContract;?></span>
              <span class='text-md'><?php echo $contractLink;?></span>
            </div>
          </div>
          <?php endif;?>
          <div class='table-row'>
            <div class='table-col col-6 has-padding-lg-h has-padding-sm-v'>
              <span class='text-gray space-sm has-padding-lg-h no-padding-left'><?php echo $lang->order->infoPlanAmount;?></span>
              <span class='text-md'><?php echo zget($currencySign, $order->currency, '');?><strong><?php echo formatMoney($order->plan);?></strong></span>
            </div>
            <div class='table-col col-6 has-padding-lg-h has-padding-sm-v'>
              <span class='text-gray space-sm has-padding-lg-h no-padding-left'><?php echo $lang->order->infoRealAmount;?></span>
              <span class='text-md'><?php echo zget($currencySign, $order->currency, '');?><strong class='text-red'><?php echo formatMoney($order->real);?></strong></span>
            </div>
          </div>
          <?php if(formatTime($order->contactedDate) || formatTime($order->nextDate)):?>
          <div class='table-row'>
            <?php if(formatTime($order->contactedDate)):?>
            <div class='table-col col-6 has-padding-lg-h has-padding-sm-v'>
              <span class='text-gray space-sm has-padding-lg-h no-padding-left'><?php echo $lang->order->infoContacted;?></span>
              <span><?php echo formatTime($order->contactedDate, DT_DATE1);?></span>
            </div>
            <?php endif;?>
            <?php if(formatTime($order->nextDate)):?>
            <div class='table-col col-6 has-padding-lg-h has-padding-sm-v'>
              <span class='text-gray space-sm has-padding-lg-h no-padding-left'><?php echo $lang->order->infoNextDate;?></span>
              <span><?php echo formatTime($order->nextDate, DT_DATE1);?></span>
            </div>
            <?php endif;?>
          </div>
          <?php endif;?>
        </div>
      </div>
    </div>
    <div class='panel panel-block'>
      <div class='panel-heading'>
        <strong><?php echo $lang->files;?></strong>
      </div> 
      <div class='panel-body'>
        <?php echo $this->fetch('file', 'printFiles', array('files' => $order->files, 'fieldset' => 'false'))?>
      </div>
    </div>
    <?php echo $this->fetch('action', 'history', "objectType=order&objectID={$order->id}");?>
    <div class='main-actions'>
      <div class='btn-toolbar'>
        <?php commonModel::printBack($browseLink);?>
        <div class='divider'></div>
        <?php echo $this->order->buildOperateMenu($order, 'view');?>
        <div class='divider'></div>
        <?php commonModel::printRPN($preAndNext);?>
      </div>
    </div>
  </div>
  <div class='side-col col-4'>
    <?php echo $this->fetch('contact', 'block', "customer={$order->customer}");?>
    <div class='panel panel-block'>
      <div class='panel-heading'><strong class='title'><?php echo $lang->order->lifetime;?></strong></div>
      <div class='panel-body'>
        <table class='table table-data'>
          <tr>
            <th class='<?php echo $app->getClientLang() == 'en' ? 'w-100px' : 'w-60px'; ?>'><?php echo $lang->lifetime->createdBy;?></th>
            <td><?php echo zget($users, $order->createdBy) . $lang->at . formatTime($order->createdDate, DT_DATETIME1);?></td>
          </tr>
          <tr>
            <th><?php echo $lang->lifetime->assignedTo;?></th>
            <td><?php if($order->assignedTo) echo zget($users, $order->assignedTo) . $lang->at . formatTime($order->assignedDate, DT_DATETIME1);?></td>
          </tr>
          <tr>
            <th><?php echo $lang->lifetime->closedBy;?></th>
            <td><?php if($order->closedBy) echo zget($users, $order->closedBy) . $lang->at . formatTime($order->closedDate, DT_DATETIME1);?></td>
          </tr>
          <tr>
            <th><?php echo $lang->lifetime->closedReason;?></th>
            <td><?php echo $lang->order->closedReasonList[$order->closedReason];?></td>
          </tr>
          <tr>
            <th><?php echo $lang->lifetime->signedBy;?></th>
            <td>
              <?php if($contract and $contract->signedBy and $contract->status != 'canceled') echo zget($users, $contract->signedBy) . $lang->at . formatTime($contract->signedDate, DT_DATE1);?>
            </td>
          </tr>
          <tr>
            <th><?php echo $lang->order->editedBy;?></th>
            <td><?php if($order->editedBy) echo zget($users, $order->editedBy) . $lang->at . formatTime($order->editedDate, DT_DATETIME1);?></td>
          </tr>
        </table>
      </div>
    </div>
  </div>
</div>

<?php include '../../common/view/footer.html.php';?>
