<?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/kindeditor.html.php';?>
<?php
$payed = $order->status == 'payed';
$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>
    <?php echo $this->fetch('action', 'history', "objectType=order&objectID={$order->id}");?>
    <div class='main-actions'>
      <div class='btn-toolbar'>
        <?php
        commonModel::printBack($browseLink);
        echo "<div class='divider'></div>";

        commonModel::printLink('action', 'createRecord', "objectType=order&objectID={$order->id}&customer={$order->customer}&history=", $lang->order->record, "class='btn' data-toggle='modal' data-width='800'");
        if($order->status == 'normal') commonModel::printLink('contract', 'create', "customer={$order->customer}&orderID={$order->id}", $lang->order->sign, "class='btn btn-default'");

        if($order->status != 'normal') echo html::a('###', $lang->order->sign, "class='btn' disabled='disabled' class='disabled'");
        if($order->status != 'closed') commonModel::printLink('order', 'assign', "orderID=$order->id", $lang->assign, "data-toggle='modal' class='btn btn-default'");

        if($order->status == 'closed') echo html::a('###', $lang->assign, "data-toggle='modal' class='btn btn-default disabled' disabled");

        echo "<div class='divider'></div>";

        if($order->status != 'closed') commonModel::printLink('order', 'close', "orderID=$order->id", $lang->close, "class='btn btn-default' data-toggle='modal'");
        if($order->closedReason == 'payed') echo html::a('###', $lang->close, "disabled='disabled' class='disabled btn'");
        if($order->closedReason != 'payed' and $order->status == 'closed') commonModel::printLink('order', 'activate', "orderID=$order->id", $lang->activate, "class='btn' data-toggle='modal'");
        if($order->closedReason == 'payed' or  $order->status != 'closed') echo html::a('###', $lang->activate, "class='btn disabled' data-toggle='modal'");

        echo "<div class='divider'></div>";

        commonModel::printLink('order', 'edit', "orderID=$order->id", $lang->edit, "class='btn btn-default'");
        if($order->status == 'normal' or $order->closedReason == 'failed') commonModel::printLink('order', 'delete', "orderID=$order->id", $lang->delete, "class='btn btn-default deleter'");
        echo html::a('#commentBox', $this->lang->comment, "class='btn btn-default' onclick=setComment()");

        echo "<div class='divider'></div>";

        commonModel::printRPN($preAndNext);
        ?>
      </div>
    </div>
    <div id='commentBox' class='hide panel panel-block'>
      <div class='panel-heading'><strong><?php echo $lang->comment;?></strong></div>
      <div class='panel-body'>
        <form id='ajaxForm' method='post' action='<?php echo inlink('edit', "orderID={$order->id}&comment=true")?>'>
          <div class='form-group'><?php echo html::textarea('comment', '',"rows='5' class='w-p100'");?></div>
          <div class='form-actions'><?php echo html::submitButton() . html::commonButton($lang->cancel, 'btn btn-back', "onclick=setComment()");?></div>
        </form>
      </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'>
        <?php $payed = $order->status == 'payed';?>
        <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';?>
