<?php 
/**
 * The detail view of order module of ZDOO.
 *
 * @copyright   Copyright 2009-2016 青岛易软天创网络科技有限公司(QingDao Nature Easy Soft Network Technology Co,LTD, www.cnezsoft.com)
 * @license     商业软件，非开源软件
 * @author      Gang Liu <liugang@cnezsoft.com>
 * @package     order 
 * @version     $Id$
 * @link        http://www.zdoo.com
 */
?>
<?php include '../../common/view/header.html.php';?>
<div id='mainTitle' class='clearfix'>
  <div class='btn-toolbar pull-left'>
    <?php if(!isonlybody()):?>
    <?php echo html::a('javascript:history.go(-1);', '<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="text"><?php echo $lang->order->view;?></span>
    </div>
  </div>
</div>
<div class='main-row'>
  <div class='main-col col-9'>
    <div class='panel main-table' data-ride='table'>
      <table class='table table-form'>
        <thead>
          <tr class='text-center'>
            <th><?php echo $lang->orderProduct->product;?></th>
            <th class='w-80px'><?php echo $lang->orderProduct->unit;?></th>
            <th class='w-120px'><?php echo $lang->orderProduct->price;?></th>
            <th class='w-120px'><?php echo $lang->orderProduct->amount;?></th>
            <th class='w-120px'><?php echo $lang->order->money;?></th>
          </tr>
        </thead>
        <?php foreach($orderProducts as $orderProduct):?>
        <tr class='text-center'>
          <?php $product = zget($products, $orderProduct->product);?>
          <td class='c-name' title='<?php echo $product->name;?>'>
            <span class='label-success label'><?php echo $lang->order->statusList[$product->status];?></span>
            <?php if(!commonModel::printLink('product', 'view', "id={$product->id}", $product->name)) echo $product->name;?>
          </td>
          <td><?php if(isset($product->unit)) echo $product->unit;?></td>
          <td><?php echo $orderProduct->price;?></td>
          <td><?php echo $orderProduct->amount;?></td>
          <td><?php echo $orderProduct->money;?></td>
        </tr>
        <?php endforeach;?>
        <tr class='text-center'>
          <th colspan='3'></th>
          <th><?php echo $lang->order->total;?></th>
          <td><?php echo $order->money;?></td>
        </tr>
      </table>
    </div>
    <?php $i = 0;?>
    <?php foreach($batches as $id => $batch):?>
    <?php $i ++;?>
    <div class='panel panel-bolck'>
      <div class='panel-heading'>
        <strong><?php echo $lang->order->batch[$order->type];?>::<?php printf($lang->batch->batchInfo, $i);?></strong> <span class='label-success label'><?php echo $lang->batch->statusList[$batch->status];?></span>
        <div class='panel-actions pull-right'>
          <?php 
            if($order->type == 'sale' || $order->type == 'purchaseRefund') if(!commonModel::printLink('batch', 'printBatch', "id={$id}&module={$moduleName}", "<i class='icon-printer'></i>", "class='btn btn-mini' title='{$lang->order->print->common}'")) echo html::a('#', "<i class='icon-printer'></i>", "class='btn btn-mini disabled'");
            if(!commonModel::printLink('batch', "edit{$mode}", "id={$id}", "<i class='icon-pencil'></i>", "class='btn btn-mini' data-toggle='modal' title='{$lang->edit}'")) echo html::a('#', "<i class='icon-pencil'></i>", "class='btn btn-mini disabled'");
            echo "<span class='btn btn-mini hand toggle-self'><span title='{$lang->order->showProducts}' class='toggle-body change-show'></span></span>";
          ?>
        </div>
      </div>
      <table class='table table-condensed table-striped'>
        <?php if($order->type == 'sale' || $order->type == 'purchaseRefund'):?>
        <tr>
          <th class='w-80px text-right'><?php echo $lang->batch->pickedBy;?></th>
          <td class='w-320px'><?php echo zget($users, $batch->pickedBy, '');?></td>
          <th class='w-100px text-right'><?php echo $lang->batch->pickedDate;?></th>
          <td class='w-320px'><?php echo formatTime($batch->pickedDate, DT_DATE1);?></td>
        </tr>
        <?php endif;?>
        <tr>
          <th class='w-80px text-right'><?php echo $lang->batch->$mode->expressedBy;?></th>
          <td class='w-320px'><?php echo zget($users, $batch->expressedBy, '');?></td>
          <th class='w-100px text-right'><?php echo $lang->batch->$mode->expressedDate;?></th>
          <td class='w-320px'><?php echo formatTime($batch->expressedDate, DT_DATE1);?></td>
        </tr>
        <tr>
          <th class='text-right'><?php echo $lang->batch->express;?></th>
          <td><?php echo zget($expresses, $batch->express, '');?></td>
          <th class='text-right'><?php echo $lang->batch->waybill;?></th>
          <td><?php echo $batch->waybill;?></td>
        </tr>
        <tr class='hide text-center'>
          <th class='text-right text-middle'><?php echo $lang->batch->product;?></th>
          <td colspan='3' class='text-middle text-left'>
            <ol>
              <?php foreach($batch->batchProducts as $batchProduct):?>
              <?php $product = zget($products, $batchProduct->product, '');?>
              <li><?php if(!commonModel::printLink('product', 'view', "id={$product->id}", $product->name)) echo $product->name; echo ' : ' . $batchProduct->amount . ' ' . $product->unit;?></li>
              <?php endforeach;?>
            </ol>
          </td>
        </tr>
      </table>
    </div>
    <?php endforeach;?>
    <?php echo $this->fetch('action', 'history', "objectType=psiorder&objectID=$order->id")?>
    <div class='main-actions'>
      <div class='btn-toolbar'>
        <?php echo html::backButton();?>
        <div class='divider'></div>
        <?php if($order->status != 'canceled' && $order->status != 'finished'):?>
        <?php if($order->type == 'sale' || $order->type == 'purchaseRefund'):?>
        <?php commonModel::printLink($moduleName, 'assignToPick', "id={$order->id}", $lang->order->pick, "class='btn'");?>
        <?php if($order->type == 'sale') commonModel::printLink($moduleName, 'assignToPurchase', "id={$order->id}", $lang->order->assignToPurchase, "class='btn' data-toggle='modal'");?>
        <?php endif;?>
        <?php endif;?>
        <?php if($order->type == 'purchase') commonModel::printLink($moduleName, 'sendMail', "id={$order->id}", $lang->order->sendMail, "class='btn' data-toggle='modal' data-width='600'");?>
        <?php commonModel::printLink($moduleName, 'printOrder', "id={$order->id}", $lang->order->print->common, "class='btn'");?>
        <div class='divider'></div>
        <?php if($order->status == 'canceled' || $order->status == 'finished'):?>
        <?php commonModel::printLink($moduleName, 'activate', "id={$order->id}", $lang->activate, "class='btn' data-toggle='modal'");?>
        <?php else:?> 
        <?php if($order->status != 'canceled' && $order->status != 'finished') commonModel::printLink($moduleName, 'edit' . $refundAppend, "id={$order->id}", $lang->edit, "class='btn'");?>
        <?php commonModel::printLink($moduleName, 'finish', "id={$order->id}", $lang->finish, "class='btn' data-toggle='modal'");?>
        <?php commonModel::printLink($moduleName, 'cancel', "id={$order->id}", $lang->cancel, "class='btn' data-toggle='modal'");?>
        <?php endif;?>
        <?php if($order->status != 'finished') commonModel::printLink($moduleName, 'delete', "id={$order->id}", $lang->delete, "class='btn deleter'");?>
      </div>
    </div>
  </div>
  <div class='side-col col-3'>
    <div class='panel panel-block'>
      <div class='panel-heading'>
        <strong><?php echo $lang->order->view;?></strong>
      </div>
      <div class='panel-body'>
        <table class='table table-data'>
          <tr>
            <th class='w-80px'><?php echo $lang->order->traderList[$order->type];?></th>
            <td>
              <?php
              if(!empty($company->name))
              {
                  $traderModule = strpos($order->type, 'sale') === 0 ? 'customer' : 'provider';
                  if(!commonModel::printLink($traderModule, 'view', "id={$order->trader}", $company->name)) echo $company->name;
              }
              ?>
            </td>
          </tr>
          <tr>
            <th><?php echo ($order->type == 'saleRefund' || $order->type == 'purchaseRefund') ? $lang->order->refundNo : $lang->order->orderNo->common;?></th>
            <td><?php echo $order->orderNo;?></td>
          </tr>
          <?php if(!empty($contract)):?>
          <th><?php echo $lang->order->contract;?></th>
          <td>
            <?php if(!commonModel::printLink('crm.contract', 'view', "contractID=$contract->id", $contract->name, "class='contract'")) echo $label;?>
          </td>
          <?php endif;?>
          <tr>
            <th><?php echo $lang->order->money;?></th>
            <td><?php echo $order->money;?></td>
          </tr>
          <tr>
            <th><?php echo $lang->order->createdBy;?></th>
            <td><?php echo zget($users, $order->createdBy, '');?></td>
          </tr>
          <tr>
            <th><?php echo $lang->order->createdDate;?></th>
            <td><?php echo formatTime($order->createdDate, DT_DATETIME1);?></td>
          </tr>
          <tr>
            <th><?php echo $lang->order->desc;?></th>
            <td><?php echo $order->desc;?></td>
          </tr>
          <tr>
            <th><?php echo ($order->type == 'saleRefund' || $order->type == 'purchaseRefund') ? $lang->order->refundStatus : $lang->order->status;?></th>
            <td><?php echo zget($lang->order->statusList, $order->status, '');?></td>
          </tr>
        </table>
      </div>
    </div>
  </div>
<?php include '../../common/view/footer.html.php';?>
