{if $body.data.state == 'O'}

   <style type="text/css">
      .input-height {
         margin-bottom: 0px;
      }
      .panel-body > .form-group:last-of-type {
         margin-bottom: 0px;
      }
      .panel-title.two-lines > p {
         padding-left: 5px;
         padding-top: 2px;
         padding-bottom: 0px;
      }
      .panel-title .help-block {
         margin-top: 1px;
      }

      .disable-animations *,
      .disable-animations *:after,
      .disable-animations *:before {
         transition: none !important;
      }
   </style>
<div id="addItem">
   <div class="row bottom-space">
      <div class="col-md-3">
         <a href="#" data-form-add class="btn btn-success btn-block"><span class="glyphicon glyphicon-plus"></span>&nbsp;Přidat položku</a>
      </div>

      {if $body.items}
         <div class="col-md-2 col-md-offset-2">
            <a href="launch.php?s=storesTransfers.php&acn=edit&ID={$body.data.id}&print=1" name="Tisk" class="btn btn-sm btn-primary btn-block" title="Tisk">Tisk</a>
         </div>
         <!--div class="col-md-2 col-md-offset-3">
            <a href="launch.php?s=storesTransfers.php&acn=export&ID={$body.data.id}" name="Export" class="btn btn-sm btn-primary btn-block">Exportovat</a>
         </div-->
         <div class="col-md-2">
            <a onclick="printCodes('zebra');" target="printCenter" class="btn btn-sm btn-block btn-primary" ><span class="glyphicon glyphicon-print"></span>&nbsp;Vytisknout štítky</a>
         </div>
         <div class="col-md-2">
            <a onclick="printCodes('zebra_positions');" target="printCenter" class="btn btn-sm btn-block btn-primary" ><span class="glyphicon glyphicon-print"></span>&nbsp;Vytisknout pozice</a>
         </div>
         <div class="col-md-1 text-right">
            <a class="btn btn-sm" style="margin-right: 15px" data-form-mass-open>
               <i class="glyphicon glyphicon-plus-sign"></i>
            </a>
         </div>
      {/if}
   </div>

   <div class="panel panel-body" data-form-new style="display: none;" id="items" >
      <div class="form-group">
         <div class="col-md-2 control-label"><label>Produkt</label></div>
         <div class="col-md-9">
            <div class="input-group">
               <input type="text" class="form-control input-sm" size="5" maxlength="100" value="" data-autocomplete-search="product"/>
               <input type="text" hidden name="data[items][0][id_product]" value="">
               <input type="text" hidden name="data[items][0][id_variation]" value="">
               <div class="input-group-btn">
                  <button class="btn btn-primary btn-sm addProduct" tabindex="-1" title="Přidat nový produkt" type="button">
                     <i class="glyphicon glyphicon-plus"></i>
                  </button>
               </div>
            </div>
         </div>
         <div class="col-md-1 text-right">
            <a class="btn-sm btn btn-danger" data-form-delete>
               <input class="hidden" type="checkbox" name="data[items][0][delete]" />
               <span class="glyphicon glyphicon-remove"></span>
            </a>
         </div>
         <input type="hidden" name="data[items][0][id]" value="">
      </div>
      <div class="form-group">
         <div class="col-md-2 control-label"><label>Kod<label></div>
         <div class="col-md-2">
            <input type="text" class="form-control input-sm" name="data[items][0][code]"   maxlength="100" value=""  readonly />
         </div>
         <div class="col-md-1 control-label"><label>EAN<label></div>
         <div class="col-md-3">
            <input type="text" class="form-control input-sm" name="data[items][0][ean]"  maxlength="100" value=""  readonly />
         </div>
         <div class="col-md-1 control-label"><label>Skladem<label></div>
         <div class="col-md-1">
            <input type="text" class="form-control input-sm" name="data[items][0][in_store]" maxlength="100" value="" readonly />
         </div>
      </div>
      <div class="form-group">
         <div class="col-md-2 control-label"><label>Množství</label></div>
         <div class="col-md-2">
            <input type="text" class="form-control input-sm" name="data[items][0][quantity]" data-calculate='pieces' value="" autocomplete="off"/>
         </div>
      </div>

   </div>
</div>
<script>
   $("#addItem").on('click', '.addProduct', function(e){
      nw('product', 0, '&refresh=noopener&data[title]='+$(this).closest('.input-group').find('.ui-autocomplete-input').val())
   })
</script>
{/if}

{if $body.items}
    {$store_from = $body.data.id_store_from}
    {$store_to = $body.data.id_store_to}
<div class="panel-group panel-group-lists">
   <div class="panel">
      <div class="panel-heading" style="padding-bottom:4px">
         <div class="row">
            <div class="col-md-3">
               <small><strong>Název produktu</strong></small>
            </div>
            <div class="col-md-1 text-center">
               <small><strong>Kusů</strong></small>
            </div>
            <div class="col-md-1">
               <small><strong>Poznámka</strong></small>
            </div>
            <div class="col-md-1">
               <small><strong>Kód</strong></small>
            </div>
            {$class = 'col-md-2'}
            {if $store_from != 1 && $store_to != 1}{$class = 'col-md-1'}{/if}
            <div class="{$class}">
               <small><strong>EAN</strong></small>
            </div>
            <div class="col-md-1 text-center">
               <small><strong><abbr title="{$body.stores[$store_from]}">Sklad&nbsp;#{$store_from}</abbr></strong></small>
            </div>
            {if $store_from != 1}
               <div class="col-md-1 text-center">
                  <small><strong><abbr title="{$body.stores[$store_from]}">Min.&nbsp;množství</abbr></strong></small>
               </div>
            {/if}
            <div class="col-md-1 text-center">
               <small><strong><abbr title="{$body.stores[$store_to]}">Sklad&nbsp;#{$store_to}</abbr></strong></small>
            </div>
            {if $store_to != 1}
            <div class="col-md-1 text-center">
               <small><strong><abbr title="{$body.stores[$store_to]}">Min.&nbsp;množství</abbr></strong></small>
            </div>
            {/if}
             {ifmodule PRODUCTS_BATCHES}
             {if $body.data.state == 'R'}
                <div class="col-md-1 text-center">
                   <small><strong>Šarže</strong></small>
                </div>
             {/if}
             {/ifmodule}
         </div>
      </div>
   </div>

   <div id="items">
      {foreach $body.items as $key => $item}
         <div class="panel" data-form-item style="background-color: #FFF;">
            <div class="panel-heading" style="background-color: {$item.bg_color}" data-toggle="collapse" data-target="#collapse_{$key}">
               <div class="row">
                  <div class="col-md-3">
                     <h4 class="panel-title two-lines">
                        <p class="pull-left">
                           <a href="javascript:nw('product', '{$item.id_product}');">
                              <strong>{$item.product_title}</strong>
                              {if !empty($item.id_variation)}
                                 <span class="help-block">{$item.variation_title}</span>
                              {/if}
                           </a>
                        </p>
                     </h4>
                  </div>
                  <div class="col-md-1 text-center">
                     <p class="input-height">
                        <strong>{$item.quantity}</strong>
                     </p>
                  </div>
                  <div class="col-md-1">
                     <p class="input-height">
                        {$item.note}
                     </p>
                  </div>
                  <div class="col-md-1">
                     <p class="input-height">
                        {$item.code}
                     </p>
                  </div>
                  <div class="{$class}">
                     <p class="input-height">
                        {$item.ean}
                     </p>
                  </div>
                  <div class="col-md-1 text-center">
                     <p class="input-height">
                         {$cur_store_in_store = "store{$store_from}_in_store"}
                         {$cur_store_in_store = $item.$cur_store_in_store}
                         {if !is_null({$cur_store_in_store})}
                            <a href="javascript:nw('productOrders', '{$item.id_product}', '{$item.id_variation}')">{$cur_store_in_store}</a>
                         {/if}
                     </p>
                  </div>
                  {if $store_from != 1}
                     <div class="col-md-1 text-center">
                        <p class="input-height">
                            {$item["store{$store_from}_min_in_store"]}
                        </p>
                     </div>
                  {/if}
                  <div class="col-md-1 text-center">
                     <p class="input-height">
                         {$cur_store_in_store = "store{$store_to}_in_store"}
                         {$cur_store_in_store = $item.$cur_store_in_store}
                         {if !is_null({$cur_store_in_store})}
                             {$cur_store_in_store}
                         {/if}
                     </p>
                  </div>
                  {if $store_to != 1}
                     <div class="col-md-1 text-center">
                        <p class="input-height">
                            {$item["store{$store_to}_min_in_store"]}
                        </p>
                     </div>
                  {/if}

                   {ifmodule PRODUCTS_BATCHES}
                   {if $body.data.state == 'R'}
                      <div class="col-md-1 text-center">
                         <p class="input-height">
                             {foreach $item.batches as $batch}
                                <span style="font-size: 12px"><abbr title="{$batch.date_expiry}" style="white-space: nowrap;">{$batch.code}</abbr>:&nbsp;{$batch.pieces}</span>
                             {/foreach}
                         </p>
                      </div>
                   {/if}
                   {/ifmodule}

                  <div class="col-md-1">
                     {if $body.data.state == 'O'}
                        <a class="btn-sm btn btn-danger pull-right" data-form-delete>
                           <input class="hidden" type="checkbox" name="data[items][{$key}][delete]" />
                           <span class="glyphicon glyphicon-remove"></span>
                        </a>
                     {/if}
                  </div>
               </div>
            </div>
            <div id="collapse_{$key}" class="panel-collapse collapse">
               <div class="panel-body">
                  <div class="form-group">
                     <div class="col-md-2 control-label"><label>Množství</label></div>
                     <div class="col-md-1">
                        <input type="text" class="form-control input-sm" name="data[items][{$key}][quantity]" size="5" data-calculate='pieces' maxlength="100" value="{$item.quantity}" />
                     </div>

                     <div class="col-md-2 control-label"><label>Skladem: </label></div>
                     <div class="col-md-4">
                        {foreach $body.stores as $store_id => $store_name}
                            {$store_in_store = "store{$store_id}_in_store"}
                            {$store_in_store = $item.$store_in_store}
                            <p>
                               <b>{$store_in_store}</b> - {$store_name} (#{$store_id})
                            </p>
                        {/foreach}
                        <p>
                           <b>{$item.total_in_store}</b> - <label>Součet všech skladů</label>
                        </p>
                     </div>
                     {if $item.warning}
                     <div class="col-md-3">
                        {foreach $item.warning as $warning}
                           <p class="btn-sm" style="background-color: {$item.bg_color};">{$warning}</p>
                        {/foreach}
                     </div>
                     {/if}
                  </div>
               </div>
            </div>
         </div>
         
         {if $item@iteration is div by 100}
            {flush nocache}
         {/if}
      {/foreach}
   </div>
</div>
{/if}
