<?php 
/**
 * The browse 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';?>
<?php js::set('mode', $mode);?>
<li id='bysearchTab'><?php echo html::a('javascript:;', "<i class='icon-search icon'></i>" . $lang->search->common)?></li>
<div id='menuActions'>
  <?php commonModel::printLink($type, 'create', '', '<i class="icon-plus"></i> ' . $lang->order->create, 'class="btn btn-primary"');?>
</div>
<div class='main-table' data-ride='table'>
  <table class='table has-sort-head'>
    <thead>
      <tr>
        <?php $vars = "mode={$mode}&orderBy=%s&recTotal={$pager->recTotal}&recPerPage={$pager->recPerPage}&pageID={$pager->pageID}";?>
        <th class='w-120px'><?php commonModel::printOrderLink('orderNo', $orderBy, $vars, $lang->order->orderNo->common);?></th>
        <th><?php commonModel::printOrderLink('trader', $orderBy, $vars, $lang->order->traderList[$type]);?></th>
        <th class='w-100px'><?php commonModel::printOrderLink('createdBy', $orderBy, $vars, $lang->order->createdBy);?></th>
        <th class='w-100px'><?php commonModel::printOrderLink('createdDate', $orderBy, $vars, $lang->order->createdDate);?></th>
        <th class='w-110px'><?php commonModel::printOrderLink('finishedDate', $orderBy, $vars, $lang->order->finishedDate);?></th>
        <th class='w-100px text-right'><?php commonModel::printOrderLink('money', $orderBy, $vars, $lang->order->money);?></th>
        <th class='w-100px'><?php commonModel::printOrderLink('status', $orderBy, $vars, $lang->order->status);?></th>
        <th class='w-<?php echo $lang->order->actionWidth;?>px text-center'><?php echo $lang->actions;?></th>
      </tr>
    </thead>
    <tbody>
      <?php foreach($orders as $id => $order):?>
      <?php $refundAppend = ($order->type == 'saleRefund' || $order->type == 'purchaseRefund') ? 'Refund' : '';?>
      <tr data-url='<?php echo inlink('detail', "id={$id}")?>'>
        <td><?php echo $order->orderNo;?></td>
        <td><?php echo zget($companies, $order->trader, '');?></td>
        <td><?php echo zget($users, $order->createdBy, '');?></td>
        <td><?php echo formatTime($order->createdDate, DT_DATE1);?></td>
        <td><?php echo formatTime($order->finishedDate, DT_DATE1);?></td>
        <td class='text-right'><?php echo $order->money;?></td>
        <td><?php echo zget($lang->order->statusList, $order->status, '');?></td>
        <td class='text-center'>
          <?php
          if($order->status == 'canceled' || $order->status == 'finished')
          {
              if($order->type == 'sale' || $order->type == 'purchaseRefund')
              {
                  echo html::a('javascript:;', $this->lang->order->pick, "class='disabled'");
                  if($order->type == 'sale') echo html::a('javascript:;', $this->lang->order->assignToPurchase, "class='disabled'");
              }
          }
          else
          {
              if($order->type == 'sale' || $order->type == 'purchaseRefund')
              {
                  if(!commonModel::printLink($type, 'assignToPick', "id={$order->id}", $this->lang->order->pick)) echo html::a('javascript:;', $this->lang->order->pick, "class='disabled'");

                  if($order->type == 'sale')
                  {
                      if(!commonModel::printLink($type, 'assignToPurchase', "id={$order->id}", $this->lang->order->assignToPurchase, "data-toggle='modal'")) echo html::a('javascript:;', $this->lang->order->assignToPurchase, "class='disabled'");
                  }
              }
              elseif($order->type == 'saleRefund')
              {
                  echo html::a('javascript:;', $this->lang->order->pick, "class='disabled'");
                  echo html::a('javascript:;', $this->lang->order->assignToPurchase, "class='disabled'");
              }
          }

          if(!commonModel::printLink($type, 'printOrder', "id={$order->id}", $this->lang->order->print->common)) echo html::a('javascript:;', $this->lang->order->print->common, "class='disabled'");
          
          if($order->status == 'canceled' || $order->status == 'finished')
          {
              echo html::a('javascript:;', $this->lang->edit, "class='disabled'");
              echo html::a('javascript:;', $this->lang->finish, "class='disabled'");
          }
          else
          {
              if(!commonModel::printLink($type, 'edit' . $refundAppend, "id={$order->id}", $this->lang->edit)) echo html::a('javascript:;', $this->lang->edit, "class='disabled'");

              if(!commonModel::printLink($type, 'finish', "id={$order->id}", $this->lang->finish, "data-toggle='modal'")) echo html::a('javascript:;', $this->lang->finish, "class='disabled'");
          }

          if(!commonModel::printLink($type, 'detail', "id={$order->id}", $this->lang->detail)) echo html::a('javascript:;', $this->lang->detail, "class='disabled'");
          ?>
        </td>
      </tr>
      <?php endforeach;?>
    </tbody>
  </table>
  <div class='table-footer'><?php $pager->show();?></div>
</div>
<?php include '../../common/view/footer.html.php';?>
