<?php 
$i = 1; 
$newItemsCount = $config->order->itemsCount;
$productsCount = 0;
?>
<?php if(isset($order)):?>
<?php $productsCount = count($order->orderProducts);?>
<?php foreach($order->orderProducts as $orderProduct):?>
<tr>
  <?php if($i == 1):?>
  <th id='product_title' class='w-70px' rowspan='<?php echo $productsCount < $newItemsCount ? $newItemsCount : $productsCount + 1;?>'><?php echo $lang->order->product;?></th>
  <?php endif;?>
  <td class='w-260px'>
    <div class='input-group'>
      <?php $product = zget($products, $orderProduct->product);?>
      <select id='product<?php echo $i;?>' name='product[<?php echo $i;?>]' class='product-batchEdit select-product form-control chosen' data-placeholder='<?php echo $lang->orderProduct->product;?>'>
        <option></option>
        <?php foreach($products as $product):?>
        <option value='<?php echo $product->id;?>' data-keys='<?php echo $product->pinyin;?>' data-unit='<?php echo $product->unit;?>' <?php if($product->id == $orderProduct->product) echo 'selected';?>><?php echo $product->name;?></option>
        <?php endforeach;?>
      </select>
      <?php if(commonModel::hasPriv('product', 'createFromOrder')):?>
      <span class='input-group-addon'>
        <?php echo html::a($this->createLink('product','createFromOrder', "id=product{$i}"), $lang->create, "data-toggle='modal'");?>
      </span>
      <?php endif;?>
    </div>
  </td>
  <td><?php echo html::input("unit[$i]", $orderProduct->unit, "id='unit{$i}' class='product-batchEdit form-control' placeholder='{$lang->orderProduct->unit}'");?></td>
  <td><?php echo html::input("price[$i]", $orderProduct->price, "id='price{$i}' class='product-batchEdit form-control product-price' placeholder='{$lang->orderProduct->price}'");?></td>
  <td><?php echo html::input("amount[$i]", $orderProduct->amount, "id='amount{$i}' class='product-batchEdit form-control product-amount' placeholder='{$lang->orderProduct->amount}'");?></td>
  <td><?php echo html::input("money[$i]", $orderProduct->money, "id='money{$i}' class='product-batchEdit form-control product-money' placeholder='{$lang->orderProduct->money}'");?></td>
  <td>
    <?php 
    echo html::a('javascript:;', "<i class='icon-plus'></i>", "class='btn-plus'") . html::a('javascript:;', "<i class='icon-remove'></i>", "class='btn-remove'");
    echo html::hidden("mode[$i]", 'update', "id='mode{$i}'");
    echo html::hidden("id[$i]", $orderProduct->id, "id='id{$i}'");
    ?>
  </td>
</tr>
<?php $i ++;?>
<?php endforeach;?>
<?php endif;?>
<?php $count = $productsCount < $newItemsCount ? $newItemsCount - $productsCount : 1;?>
<?php for($j = 0; $j < $count; $j ++, $i ++):?>
<tr>
  <?php if($i == 1):?>
  <th id='product_title' rowspan='<?php echo $productsCount < $newItemsCount ? $newItemsCount : $productsCount + 1;?>'><?php echo $lang->order->product;?></th>
  <?php endif;?>
  <td>
    <div class='input-group'>
      <select id='product<?php echo $i;?>' name='product[<?php echo $i;?>]' class='product-batchEdit select-product form-control chosen' data-placeholder='<?php echo $lang->orderProduct->product;?>'>
        <option></option>
        <?php foreach($products as $product):?>
        <option value='<?php echo $product->id;?>' data-keys='<?php echo $product->pinyin;?>' data-unit='<?php echo $product->unit;?>'><?php echo $product->name;?></option>
        <?php endforeach;?>
      </select>
      <?php if(commonModel::hasPriv('product', 'createFromOrder')):?>
      <span class='input-group-addon'>
        <?php echo html::a($this->createLink('product','createFromOrder', "id=product{$i}"), $lang->create, "data-toggle='modal'");?>
      </span>
      <?php endif;?>
    </div>
  </td>
  <td><?php echo html::input("unit[$i]", '', "id='unit{$i}' class='product-batchEdit form-control' placeholder='{$lang->orderProduct->unit}'");?></td>
  <td><?php echo html::input("price[$i]", '', "id='price{$i}' class='product-batchEdit form-control product-price' placeholder='{$lang->orderProduct->price}'");?></td>
  <td><?php echo html::input("amount[$i]", '', "id='amount{$i}' class='product-batchEdit form-control product-amount' placeholder='{$lang->orderProduct->amount}'");?></td>
  <td><?php echo html::input("money[$i]", '', "id='money{$i}' class='product-batchEdit form-control product-money' placeholder='{$lang->orderProduct->money}'");?></td>
  <td>
    <?php echo html::a('javascript:;', "<i class='icon-plus'></i>", "class='btn-plus'");?>
    <?php echo html::a('javascript:;', "<i class='icon-remove'></i>", "class='btn-remove'");?>
    <?php echo html::hidden("mode[$i]", 'new', "id='mode{$i}' class='product-batchEdit'");?>
  </td>
</tr>
<?php endfor;?>
