<?php 
/**
 * The create view file of batch 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     batch 
 * @version     $Id$
 * @link        http://www.zdoo.com
 */
?>
<?php include '../../common/view/header.html.php';?>
<?php include '../../../sys/common/view/datepicker.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 ($mode == 'pick' ? $lang->order->pick : $lang->batch->receive->common) . $lang->minus . $company->name;?></span>
    </div>
  </div>
</div>
<form method='post' id='ajaxForm' class='main-row'>
  <div class='main-col col-8'>
    <?php if($mode == 'receive'):?>
    <div class='panel panel-block'>
      <div class='panel-heading'>
        <strong><?php echo $lang->batch->$mode->info;?></strong>
      </div>
      <div class='panel-body'>
        <table class='table table-form'>
          <tr>
            <th class='w-70px'><?php echo $lang->batch->$mode->expressedBy;?></th>
            <td><?php echo html::select('expressedBy', $users, $this->app->user->account, "class='form-control chosen'");?></td>
            <th class='w-70px'><?php echo $lang->batch->$mode->expressedDate;?></th>
            <td><?php echo html::input('expressedDate', helper::now(), "class='form-control form-date'");?></td>
          </tr>
          <tr>
            <th class='w-80px'><?php echo $lang->batch->express;?></th>
            <td>
              <div class='input-group'>
                <?php echo html::select('express', $expresses, '', "class='form-control'");?>             
                <?php echo html::input('newExpress', '', "class='form-control newProperty' style='display:none'");?>
                <span class='input-group-addon'><?php echo html::checkbox('createExpress', $lang->batch->createExpress, '', "class='createProperty'");?></span>
              </div>
            </td>
            <th class='w-80px'><?php echo $lang->batch->waybill;?></th>
            <td class='w-320px'><?php echo html::input('waybill', '', "class='form-control'");?></td>
          </tr>
        </table>
      </div>
    </div>
    <?php endif;?>
    <div id='productInfo' class='panel panel-block'>
      <div class='panel-heading'>
        <strong><?php echo $lang->batch->productInfo;?></strong>
      </div>
      <div class='panel-body'>
        <table class='table table-bordered'>
          <thead>
            <tr class='text-center'>
              <th><?php echo $lang->batch->product;?></th>
              <th class='w-60px' ><?php echo $lang->batch->unit;?></th>
              <th class='w-140px'><?php echo $lang->batch->orderAmount;?></th>
              <th class='w-140px'><?php echo $mode == 'receive' ? $lang->batch->receivedAmount : $lang->batch->pickedAmount;?></th>
              <th class='w-140px'><?php echo $lang->batch->$mode->amount;?></th>
            </tr>
          </thead>
          <?php 
            $i          = 1;
            $amount     = 0;
            $sentAmount = 0;
            foreach($order->products as $orderProduct):
            $amount     += $orderProduct->amount;
            $sentAmount += $orderProduct->sentAmount;
            $product     = zget($products, $orderProduct->product, '');
          ?>
          <tr class='text-center text-middle'>
            <td>
              <?php echo $product->name;?>
              <?php echo html::hidden("product[$i]", $orderProduct->product);?>
            </td>
            <td><?php echo $product->unit;?></td>
            <td>
              <?php echo $orderProduct->amount;?>
              <?php echo html::hidden("price[$i]", $orderProduct->price);?>
              <?php echo html::hidden("totalAmount[$i]", $orderProduct->amount);?>
            </td>
            <td>
              <?php echo $orderProduct->sentAmount;?>
              <?php echo html::hidden("sentAmount[$i]", $orderProduct->sentAmount, "id='sentAmount{$i}'");?>
            </td>
            <td><?php echo $orderProduct->amount > $orderProduct->sentAmount ? html::input("amount[$i]", $orderProduct->amount-$orderProduct->sentAmount, "id='amount{$i}' class='form-control'") : '';?></td>
          </tr>
          <?php $i++;?>
          <?php endforeach;?>
          <?php if($mode == 'pick' && $amount > $sentAmount):?>
          <tr>
            <td colspan='3'></td>
            <th class='text-right text-middle'><?php echo $lang->batch->pickedBy;?></th>
            <td><?php echo html::select('pickedBy', $users, '', "class='form-control chosen'");?></td>
          </tr>
          <?php endif;?>
        </table>
      </div>
    </div>
    <div class='main-actions text-center'>
      <input type='hidden' id='emptyAmount' value=''>
      <?php 
      echo html::hidden('type', $mode == 'receive' ? 'in' : 'out');
      echo html::hidden('order', $order->id);
      echo html::hidden('trader', $order->trader);
      $buttonLBL = $mode == 'pick' ? $lang->order->pick : $lang->batch->receive->common;
      if($amount > $sentAmount) echo html::submitButton($buttonLBL);
      echo html::backButton();
      ?>
    </div>

    <?php $i=0;?>
    <?php foreach($batches as $id => $batch):?>
    <?php $i++;?>
    <div class='panel panel-block'>
      <div class='panel-heading'>
        <strong><?php echo $lang->batch->$mode->common;?>::<?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($batch->type == 'out') if(!commonModel::printLink('batch', 'printBatch', "id={$id}&module=sale", "<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' title='{$lang->order->showProducts}'><i class='icon icon-plus'></i></span>";
        ?>
        </div>
      </div>
      <div class='panel-body'>
        <table class='table table-data'>
          <?php if($batch->type == 'out'):?>
          <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;?>
          <?php if($batch->status != 'picking'):?>
          <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>
          <?php endif;?>
          <tr class='hide text-center'>
            <th class='text-right text-middle'><?php echo $lang->batch->product;?></th>
            <td colspan='3' class='text-left text-middle'>
              <ol>
                <?php foreach($batch->products as $batchProduct):?>
                <?php $product = zget($products, $batchProduct->product);?>
                <li><?php echo $product->name . ' : ' . $batchProduct->amount . ' ' . $product->unit;?></li>
                <?php endforeach;?>
              </ol>
            </td>
          </tr>
        </table>
      </div>
    </div>
    <?php endforeach;?>
  </div>
  <div class='side-col col-4'>
    <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(!commonModel::printLink(strpos($order->type, 'sale') === 0 ? 'customer' : 'provider', 'view', "id={$company->id}", $company->name)) echo $company->name;?>
            </td>
          </tr>
          <tr>
            <th><?php echo $lang->order->orderNo->common;?></th>
            <td>
              <?php if(!commonModel::printLink(str_replace('Refund', '', $order->type), 'detail', "id={$order->id}", $order->orderNo)) echo $order->orderNo;?>
            </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 $lang->order->status;?></th>
            <td><?php echo zget($lang->order->statusList, $order->status, ' ');?></td>
          </tr>
        </table>
      </div>
    </div>
  </div>
</form>
<?php include '../../common/view/footer.html.php';?>
