{extends "../windowFrame.tpl"}

{block body_class}class="panel_frame"{/block}

{block content}
   <div class="container-fluid" id="variants">
      {if $body.choices_categorized|@count == 0}
         <div class="alert alert-info alert-dismissable">{'alertNullVariations'|translate:'products'}</div>
      {else}
         {if $body.variations|@count == 0}
            <div class="alert alert-info alert-dismissable">{'alertNewVariations'|translate:'products'}</div>
         {/if}
         <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;{'addNewVariation'|translate:'products'}</a>
            </div>
            {if $body.choices_categorized|@count >= 1}
               <div class="col-md-4">
                  <form name="valuesgen" method="post" action="launch.php?s={$body.s}&amp;ID={$body.ID}">
                     <input type="submit" name="submitGenerateCombinations" class="btn btn-block btn-sm confirm" value="{'generateAllVariations'|translate:'products'}"/>
                  </form>
               </div>
            {/if}
            {if $body.variations}
               <div class="col-md-1 pull-right" data-form-mass-open>
                  <a class="btn btn-sm">
                     <i class="glyphicon glyphicon-plus-sign"></i>
                  </a>
               </div>
            {/if}
         </div>
      {/if}

      <form name="editform" method="post" action="launch.php?s=products.variations.php&amp;ID={$body.ID}" class="form-horizontal">
         <div id="stockin" class="panel-group panel-group-lists">
            <div class="panel">
               <div class="panel-heading" style="padding-bottom:4px">
                  <div class="row">
                     <div class="col-md-4">
                        <small><strong>{'variation'|translate:'products'}</strong></small>
                     </div>
                     <div class="col-md-2">
                        <small><strong>{'price'|translate:'base'}</strong></small>
                     </div>
                     <div class="col-md-2">
                        <small><strong>{'deliveryTime'|translate:'products'}</strong></small>
                     </div>
                     <div class="col-md-4">
                        <small><strong>{'code'|translate:'products'}</strong></small>
                     </div>
                  </div>
               </div>
            </div>
            <div class="panel-group panel-group-lists panel" id="variants">
               {foreach array_merge([['figure'=>'Y']], $body.variations) as $varkey => $variation}
                  {block 'variations_foreach'}
                  <div class="panel" {if $varkey == 0}data-form-new style="display:none" {else}data-form-item{/if}>
                     {block "variation-edit-header"}
                     {$class = "row-green"}
                     {if $variation.in_store <= 0}
                        {if $variation.in_store + $variation.piecesInSuppliers > 0}
                           {$class = "row-orange"}
                        {else}
                           {$class = "row-red"}
                        {/if}
                     {/if}
                     <div class="panel-heading {$class}" data-toggle="collapse" data-target="#collapse_{$variation.id}">
                        <input type="hidden" class="variation-id" name="data[variations][{$varkey}][id]" value="{$variation.id}">
                        {if $varkey <= 0}
                           {* ##### VYPIS SELECTU VARIANT #####  *}
                           <div class="row">
                               {foreach from=$body.choices_categorized item=choice_id}
                                 <div class="col-md-2 control-label">
                                    <label>{$body.choices[$choice_id]}</label>
                                 </div>
                                 <div class="col-md-2">
                                    <select name="data[variations][{$varkey}][combination][{$choice_id}]" class="selecter">
                                       {foreach from=$body.choices_values[$choice_id] item=value_value key=value_id}
                                          <option value="{$value_id}">{$value_value}</option>
                                       {/foreach}
                                    </select>
                                 </div>
                              {/foreach}

                              <div class="col-md-1 pull-right text-right">
                                 {if $varkey <= 0 && {find_right name="PROD_ERASE"}}
                                    <a class="btn-sm btn btn-danger" data-form-delete>
                                       <input class="hidden" type="checkbox" name="data[variations][{$varkey}][delete]"/>
                                       <span class="glyphicon glyphicon-remove"></span>
                                    </a>
                                 {/if}
                              </div>
                           </div>
                           {* ##### KONEC VYPIS SELECTU VARIANT #####  *}
                        {/if}
                        {if $varkey > 0}
                           {* ##### HLAVICKA ZASOUVACIHO PANELU #####  *}
                           <div class="row">
                              <div class="col-md-4">
                                 <input type="checkbox" style="display: none;" value="1" name="variation[{$variation.id}][changed]"/>
                                 <h4 class="panel-title">
                                    {foreach from=$body.combinations[{$variation.id}] item=combination}
                                       <p class="pull-left variation">
                                          <strong>{$body.choices[$combination.id_label]}:</strong>
                                          {$body.values[$combination.id_value]}
                                       </p>
                                    {/foreach}
                                    {block "variation-title-addon"}{/block}
                                 </h4>
                              </div>
                              <div class="col-md-2">
                                 <p>
                                    {if $variation.price > 0}<strong>{$variation.price_real|format_price}</strong>{else}{$variation.price_real|format_price}{/if}
                                    {block "variation-price-addon"}{/block}
                                 </p>
                              </div>
                              <div class="col-md-2">
                                 {* odečítá se ze skladu, kusy skladem *}
                                 {if $variation.in_store > 0 && $dbcfg.prod_subtract_from_store == 'Y'}
                                    <p>skladem {$variation.in_store} {$body.product.unit}</p>
                                    {* neoodečítá se ze skladu, kusy skladem *}
                                 {elseif $variation.in_store > 0 && $dbcfg.prod_subtract_from_store == 'N'}
                                    <p>skladem</p>
                                 {else}
                                    {* žádné kusy skladem *}
                                    <p>
                                       {$cfg.Products.DeliveryTime[$variation.delivery_time]|regex_replace:"/%s/":$variation.delivery_time_days}
                                       {* deliverytime je skladem a zároveň 0 ks *}
                                       {if $variation.delivery_time == 0 && $dbcfg.prod_subtract_from_store == 'Y'}{$variation.in_store} {$body.product.unit}{/if}
                                    </p>
                                 {/if}
                              </div>
                              <div class="col-md-4">
                                 <div class="row">
                                    <div class="col-md-5">
                                       <p>
                                          {if !empty($cfg.Modules.products.note)}
                                             {$variation.note}
                                          {/if}
                                          {$variation.code}
                                          {block "variation-code-addon"}{/block}
                                       </p>
                                    </div>
                                    <div class="col-md-7 text-right">
                                       <div class="btn-group">
                                          <span title="{'piecesInStore'|translate:'products'}" class="btn btn-sm {if $variation.in_store > 0 }btn-success{else}btn-warning{/if}"
                                                style="width:50px;">{$variation.in_store}{$body.product.unit}</span>
                                          {if {find_module name='stock_in'} && {find_right name="INSTORE_STOCKIN"}}
                                             <a href="javascript:nw('productStockIn', '{$body.ID}', '{$variation.id}');" title="{'invoicesContainsProduct'|translate:'products'}"
                                                class="btn btn-sm">
                                                <span class="glyphicon glyphicon-list-alt"></span>
                                             </a>
                                          {/if}
                                          <a href="javascript:nw('productOrders', '{$body.ID}', '{$variation.id}', '&sold=1');" title="{'ordersWithProduct'|translate:'products'}"
                                             class="btn btn-sm">
                                             <span class="glyphicon glyphicon-shopping-cart"></span>
                                          </a>
                                       </div>
                                 {if {find_right name="PROD_ERASE"}}
                                       <a class="btn-sm btn btn-danger" data-form-delete title="{'removeVariation'|translate:'products'}">
                                          <input class="hidden" type="checkbox" name="data[variations][{$varkey}][delete]"/>
                                          <span class="glyphicon glyphicon-remove"></span>
                                       </a>
                                 {/if}
                                    </div>
                                 </div>
                              </div>
                           </div>
                           {* ##### KONEC HLAVICKA ZASOUVACIHO PANELU #####  *}
                        {/if}
                        {/block}
                     </div>
                     {* ##### TELO PANELU #####  *}
                     {if $varkey > 0}
                     <div id="collapse_{$variation.id}" class="panel-collapse collapse">{/if}
                        <div class="panel-body">
                            {block "variation-edit-body"}
                            {if $varkey > 0}
                               <div class="row">
                                   {* ##### VYPIS SELECTU VARIANT #####  *}
                                   {$choices = []}
                                   {foreach $body.combinations[{$variation.id}] as $combination}
                                       {$choice_id = $combination.id_label}
                                       {$selected_value = $combination.id_value}
                                      <div class="col-md-2 control-label">
                                         <label>{$body.choices[$choice_id]}</label>
                                      </div>
                                      <div class="col-md-2">
                                         <select name="data[variations][{$varkey}][combination][{$choice_id}]" class="selecter" data-preload="VariationValuesOnly" data-autocomplete-params="id_label={$combination.id_label}" data-autocomplete="variationsLabelValues">
                                            <option value="{$selected_value}">{$selected_value}</option>
                                         </select>
                                      </div>
                                       {$choices[] = $choice_id}
                                   {/foreach}
                                   {$choices = array_diff($body.choices_categorized, $choices)}
                                   {foreach $choices as $choice_id}
                                      <div class="col-md-2 control-label">
                                         <label>{$body.choices[$choice_id]}</label>
                                      </div>
                                      <div class="col-md-2">
                                         <select required name="data[variations][{$varkey}][combination][{$choice_id}]" class="selecter" data-preload="VariationValuesOnly" data-autocomplete-params="id_label={$choice_id}" data-autocomplete="variationsLabelValues">
                                            <option value="">Vyberte hodnotu</option>
                                         </select>
                                      </div>
                                   {/foreach}
                                  {if isSuperuser()}

                                  <div class="col-md-3 control-label">

                                     <div class="copy-to-clipboard" data-copy-clipboard="{$variation.id}"
                                                             data-toggle="tooltip" title="{'clipboard-copy'|translate:'button'}">
                                        <span class="glyphicon glyphicon-flash" style="color:#AAB2BD;" title="Vidí pouze superadmin"></span>
                                        {'Id'}: <strong>{$variation.id}</strong>
                                     </div>
                                  </div>

                                  {/if}
                                   {* ##### KONEC VYPIS SELECTU VARIANT #####  *}
                               </div>
                            {/if}
                        </div>
                           <div class="panel-body">
                           {block "variations-deliverytime"}
                              <div class="form-group">
                                 <div class="col-md-2 control-label">
                                    <label>{'deliveryTime'|translate:'products'}</label>
                                    <a class="help-tip" data-toggle="tooltip" title="" data-original-title="{'variationAvailabilitySettings'|translate:'products' nofilter}"><i
                                               class="bi bi-question-circle"></i></a>
                                 </div>
                                 <div class="col-md-10">
                                    {capture some_content assign=input}
                                       <input type="text" class="form-control input-sm small" name="data[variations][{$varkey}][delivery_time_days]"
                                              value="{$variation.delivery_time_days}" size="2" maxlength="2" onkeypress="checkInputData('int');"/>
                                    {/capture}
                                    {foreach from=$cfg.Products.DeliveryTime item=value key=key name=delivers}
                                       {if findModule('products_suppliers', 'delivery_time') !== $key}
                                          <div class="radio pull-left">
                                             <input type="radio" name="data[variations][{$varkey}][delivery_time]" value="{$key}" id="dT[{$varkey}][{$key}]" class="check"
                                                    {if ($varkey == 0 && $key == -2) || ($varkey != 0 && $key == $variation.delivery_time)}checked="checked"{/if}/>
                                             <label for="dT[{$varkey}][{$key}]">{$value|regex_replace:"/%s/":$input nofilter}</label>
                                          </div>
                                       {/if}
                                    {/foreach}
                                 </div>
                              </div>
                              {/block}
                              <div class="form-group">
                                 <div class="col-md-2 control-label">
                                    <label>{'piecesInStore'|translate:'products'}</label>
                                 </div>
                                 <div class="col-md-2">
                                    {if {find_right name="PROD_STOCK"}}
                                       <input type="checkbox" name="data[variations][{$varkey}][inStoreOverride]" value="1" style="display:none;">
                                    {/if}
                                    <div class="input-group">
                                       <input style="min-width: 60px" type="text" name="data[variations][{$varkey}][in_store]" size="4" maxlength="9" value="{$variation.in_store}"
                                              onKeyPress="checkInputData('int-signed');" class="form-control input-sm"
                                              onChange="$('input[name=data\\[variations\\]\\[{$varkey}\\]\\[inStoreOverride\\]]').prop('checked', true)"
                                              {if !{find_right name="PROD_STOCK"}}disabled="disabled"{/if}/>
                                              {if (findModule("orders_of_suppliers"))}
                                                 <div class="input-group-btn">
                                                     <a href="javascript:showProductCodes('{$body.ID}', '{$variation.id}');" title="{'supplierCodes'|translate}"
                                                        class="btn btn-primary btn-sm">
                                                        <span class="glyphicon glyphicon-sort"></span>
                                                     </a>
                                                 </div>
                                              {/if}
                                       {ifmodule STORES}
                                          <div class="input-group-btn">
                                             <a href="javascript:nw('list', 'productInStores', 'IDp={$body.ID}&IDv={$variation.id}');" title="{'productInStoresTitle'|translate:'storesProducts'}" class="btn btn-primary btn-sm">
                                                <span class="glyphicon glyphicon-th-list"></span>
                                             </a>
                                          </div>
                                       {elsemodule}
                                          {if $variation.piecesOrdered}
                                             <span class="input-group-addon" title="{'inStoreTitle'|translate:'products'}">({$variation.piecesOrdered + $variation.in_store})</span>
                                          {/if}
                                       {/ifmodule}

                                       {if {find_module name='warehouse'}}
                                          <div class="input-group-btn">
                                             <a href="javascript:nw('list', 'warehouseProducts', 'id_product={$body.ID}&id_variation={$variation.id}&products=1');" title="Pozice ve skladu" class="btn btn-primary btn-sm">
                                                <span class="glyphicon glyphicon-home"></span>
                                             </a>
                                          </div>
                                       {/if}
                                       {ifmodule WATCHDOG}
                                          {*<span class="input-group-btn">
                                             <a href='javascript:nw("list", "Watchdog", "id_products[]={$body.ID}&id_variation[]={$variation.id}");'
                                                class="btn btn-primary btn-sm" title="{'showWatchdogProducts'|translate:'users'}">
                                                <span class="glyphicon glyphicon-asterisk"></span>
                                             </a>
                                          </span>*}
                                       {/ifmodule}
                                    </div>
                                 </div>
                                 {if !empty($cfg.Modules.products_variations.variationCode)}
                                    <div class="col-md-1 control-label">
                                       <label>{'code'|translate:'products'}</label>
                                    </div>
                                    <div class="col-md-3">
                                       <div class="input-group">
                                          <input type="text" class="form-control input-sm" class="input" name="data[variations][{$varkey}][code]" size="3" maxlength="50"
                                                 value="{$variation.code}"/>
                                          {if {find_right name="INSTORE_STOCKIN"}}
                                          <div class="input-group-btn">
                                             <a href="javascript:nw('productCodes', {$body.ID}, {$variation.id});" title="{'supplierCodes'|translate:'products'}"
                                                class="btn btn-primary btn-sm" {if $varkey == 0}disabled onclick="return false;"{/if}>
                                                <span class="glyphicon glyphicon-list-alt"></span>
                                             </a>
                                          </div>
                                          {/if}
                                          {block "generate-code"}
                                             {* automaticke generovani kodu varianty, napr. kupkolo *}
                                          {/block}
                                          <span class="input-group-btn">
                                             <a  {if !$variation.code} href="javascript:void(0)" disabled="" {else} href="launch.php?s=printCenter.php&amp;type=product&amp;ID={$body.ID}&amp;IDv={$variation.id}&amp;by=code" target="printCenter" {/if}
                                                class="btn btn-primary btn-sm" title="{'printCode'|translate:'products'}"><span class="glyphicon glyphicon-print"></span></a>
                                       </span>
                                       </div>

                                    </div>
                                 {/if}
                                 <div class="col-md-1 control-label">
                                    <label>{'ean'|translate:'products'}</label>
                                 </div>
                                 <div class="col-md-3">
                                    <div class="input-group">
                                       <input type="text" class="form-control input-sm" name="data[variations][{$varkey}][ean]" maxlength="13" value="{$variation.ean|format_ean}"/>
                                       {block "generate-ean"}
                                          {* automaticke generovani eanu varianty, napr. kupkolo *}
                                          {if findModule('products', 'generate_ean') && $variation.id}
                                             <div class="input-group-btn">
                                                 <a title="{'generateEan'|translate:'products'}"
                                                    href="launch.php?s=products.variations.php&amp;acn=generateEan&amp;ID={$body.ID}&amp;id_variation={$variation.id}"
                                                    class="btn btn-sm btn-primary confirm">
                                                    <span class="glyphicon glyphicon-plus"></span>
                                                 </a>
                                              </div>
                                           {/if}
                                       {/block}
                                       <span class="input-group-btn">
                                             <a  {if !$variation.ean} href="javascript:void(0)" disabled="" {else} href="launch.php?s=printCenter.php&amp;type=product&amp;ID={$body.ID}&amp;IDv={$variation.id}&amp;by=ean" target="printCenter"{/if}
                                                 class="btn btn-primary btn-sm" title="{'printCode'|translate:'products'}"><span class="glyphicon glyphicon-print"></span></a>
                                       </span>
                                    </div>
                                 </div>
                              </div>
                              <div class="form-group">
                                 <div class="col-md-2 control-label">
                                    <label>{'price'|translate:'base'}</label>
                                 </div>
                                 <div class="col-md-3">
                                    <div class="input-group" data-price="wrap">
                                       <input type="text" name="data[variations][{$varkey}][price]" data-orig="{$variation.price_orig}" data-discount="{$body.product.discount}"
                                              data-vat="{$body.product.vat}" data-price="price" id="price_[{$varkey}]" size="7" maxlength="20" value="{toDecimal($variation.price)|format_editable_price}"
                                              onKeyPress="checkInputData('float');" class="form-control input-sm"/>
                                       <input type="hidden" name="data[variations][{$varkey}][priceWithVat]" data-price="with_vat" value="{$dbcfg.prod_prefer_price_vat}"/>
                                       <span class="input-group-addon">{$dbcfg.currency}</span>
                                       <div class="input-group-btn">
                                          <a class="btn btn-primary dropdown-toggle btn-sm" data-toggle="dropdown"><span data-price="with_vat_text"></span> <span
                                                     class="caret"></span></a>
                                          <ul class="dropdown-menu">
                                             <li><a data-value="Y">{'withTax'|translate:'choice'}</a></li>
                                             <li><a data-value="N">{'withoutTax'|translate:'choice'}</a></li>
                                             <li><a data-value="F">{'final'|translate:'choice'}</a></li>
                                          </ul>
                                       </div>
                                    </div>
                                 </div>
                                 {if $module.PRODUCTS__PRICE_BUY && findRight('PROD_PRICEBUY')}
                                    <div class="col-md-2 control-label two-lines">
                                       <label class="control-label">{'priceBuy'|translate:'products'}</label>
                                    </div>
                                    <div class="col-md-3">
                                       <div class="input-group priceBuyVatDropdown">
                                          <input type="text" class="form-control input-sm" name="data[variations][{$varkey}][price_buy][value]" data-price  value="{$variation.price_buy}" maxlength="20"
                                                 onKeyPress="checkInputData('float');"/>
                                          <input type="hidden" name="data[variations][{$varkey}][price_buy][with_vat]" data-price-vat value="">
                                          <input type="hidden" name="data[variations][{$varkey}][price_buy][vat]" data-vat value="{$body.product.vat}">
                                          <span class="input-group-addon">{$dbcfg.currency}</span>
                                          <div class="input-group-btn dropdown-menu-right" data-dropdown="">
                                             <a class="btn btn-primary dropdown-toggle btn-sm" data-toggle="dropdown">
                                                <span data-dropdown-state=""></span>
                                                <span class="caret"></span>
                                             </a>
                                             <ul class="dropdown-menu dropdown-menu-right">
                                                <li><a data-value="1">{'withTax'|translate:'choice'}</a></li>
                                                <li><a data-value="0">{'withoutTax'|translate:'choice'}</a></li>
                                             </ul>
                                          </div>
                                       </div>
                                    </div>
                                 {/if}

                              </div>
                              {ifmodule PRICE_HISTORY}
                              <div class="form-group">
                                 <div class="col-md-2 control-label">
                                    <label>{'priceForDiscount'|translate:'products'}</label>
                                 </div>
                                 <div class="col-md-3">
                                    {$price_for_discount = $variation.price_for_discount}
                                    {if $price_for_discount && $price_for_discount == -1}
                                       <a title="{'activatePriceForDiscount'|translate:'products'}"
                                          href="launch.php?s=products.variations.php&amp;acn=activatePriceForDiscount&amp;ID={$body.ID}&amp;id_variation={$variation.id}"
                                          class="btn btn-sm confirm">{'activatePriceForDiscount'|translate:'products'}</a>
                                    {else}
                                    <div class="input-group">
                                       {if $price_for_discount}
                                          {$price_for_discount = toDecimal($price_for_discount)}
                                          {$withVat = ($dbcfg.prod_prefer_price_vat|default:"Y" != "N")}
                                          {if $withVat}
                                             {$price_for_discount = $price_for_discount->addVat($body.product.vat)}
                                          {/if}
                                       {/if}
                                       <input type="text" class="form-control input-sm" disabled readonly
                                              name="data[variations][{$varkey}][price_for_discount]"
                                              value="{if $price_for_discount}{$price_for_discount|format_editable_price}{/if}"/>
                                       <span class="input-group-addon">{$dbcfg.currency}</span>
                                       <span class="input-group-addon">{if $withVat}{'withTax'|translate:'choice'}{else}{'withoutTax'|translate:'choice'}{/if}</span>
                                       {if $variation.id}
                                       <div class="input-group-btn">
                                          <a title="{'deactivatePriceForDiscount'|translate:'products'}"
                                             href="launch.php?s=products.variations.php&amp;acn=deactivatePriceForDiscount&amp;ID={$body.ID}&amp;id_variation={$variation.id}"
                                             class="btn btn-sm btn-primary confirm"><span class="glyphicon glyphicon-ban-circle"></span></a>
                                       </div>
                                       <span class="input-group-text">
                                          <a class="help-tip" data-toggle="tooltip" title="{'deactivatepriceForDiscountTooltip'|translate:'products'}"
                                             style="right: -22px;"><i class="bi bi-question-circle"></i></a>
                                       </span>
                                       {/if}
                                    </div>
                                    {/if}
                                 </div>
                              </div>
                              {/ifmodule}
                              <div class="form-group form-group-flex">
                               <div class="col-md-2 control-label"><label>{'figureVisible'|translate:'products'}</label></div>
                               <div class="col-md-1">
                                    {print_toggle name="variations][`$varkey`][figure" value=$variation.figure}
                               </div>
                                 <div class="col-md-9">
                                    {include "utils/translations.figure.tpl"
                                       figureData=$body.variationTranslationsFigure[$variation.id]
                                       parentFigure=$variation.figure
                                       inputPrefix="data[variations][`$varkey`]"
                                       parentFigureInput="[name=\"data[variations][`$varkey`][figure]\"]"
                                    }
                                 </div>
                              </div>
                              <div class="form-group form-group-flex">
                                 {if findModule('products', 'weight')}
                                    <div class="col-md-2 control-label">
                                       <label>{'weight'|translate:'products'}</label>
                                    </div>
                                    <div class="col-md-2">
                                       <div class="input-group">
                                          <input type="text" class="form-control input-sm" name="data[variations][{$varkey}][weight]" maxlength="50"
                                                 value="{$variation.weight|format_editable_number:-6}"/>
                                          <span class="input-group-addon">Kg</span>
                                       </div>
                                    </div>
                                 {/if}
                                 <div class="col-md-2 control-label">
                                    <label>{'dimensions'|translate:'products'}</label>
                                 </div>
                                 <div class="col-md-4">
                                    <div class="input-group input-group-flex">
                                       <input type="text" class="form-control input-sm" name="data[variations][{$varkey}][width]" value="{$variation.width}" placeholder="{'width'|translate:'products'}" title="{'width'|translate:'products'}"/>
                                       <input type="text" class="form-control input-sm" name="data[variations][{$varkey}][height]" value="{$variation.height}" placeholder="{'height'|translate:'products'}" title="{'height'|translate:'products'}"/>
                                       <input type="text" class="form-control input-sm" name="data[variations][{$varkey}][depth]" value="{$variation.depth}" placeholder="{'depth'|translate:'products'}" title="{'depth'|translate:'products'}"/>
                                       <span class="input-group-addon">cm</span>
                                    </div>
                                 </div>
                              </div>

                              {ifmodule PRODUCTS__UNITS}
                                 <div class="form-group form-group-flex">
                                    <div class="col-md-2 control-label">
                                       <label>{'measure_quantity'|translate: 'productsUnits'}</label>
                                    </div>
                                    <div class="col-md-2">
                                       <div class="input-group">
                                          <input type="text" class="form-control input-sm" name="data[variations][{$varkey}][measure_quantity]" maxlength="50"
                                                 value="{$variation.measure_quantity}"/>
                                          <span class="input-group-addon">{$body.product.measure_quantity_name}</span>
                                       </div>
                                    </div>
                                 </div>
                              {/ifmodule}

                              {if !empty($cfg.Modules.products.note) or findModule('products', 'showMax') or $module.BONUS_PROGRAM or findModule('products', 'price_common')}
                                 <div class="form-group form-group-flex">
                                    {if !empty($cfg.Modules.products.note)}
                                       <div class="col-md-2 control-label">
                                          <label>{'note'|translate:'products'}</label>
                                       </div>
                                       <div class="col-md-2">
                                          <input type="text" class="form-control input-sm" name="data[variations][{$varkey}][note]" maxlength="50" value="{$variation.note}"/>
                                       </div>
                                    {/if}
                                    {if findModule('products', 'showMax')}
                                       <div class="col-md-2 control-label">
                                          <label>{'showMax'|translate:'products'}</label>
                                       </div>
                                       <div class="col-md-2">
                                          <input type="text" class="form-control input-sm" name="data[variations][{$varkey}][in_store_show_max]" size="3" maxlength="10"
                                                 value="{if empty($variation.in_store_show_max)}{$cfg.Modules.products.showMax}{else}{$variation.in_store_show_max}{/if}"
                                                 onKeyPress="checkInputData('int');"/>
                                       </div>
                                    {/if}
                                    {if $module.BONUS_PROGRAM}
                                       <div class="col-md-2 control-label">
                                          <label>{'bonusPoints'|translate:'products'}</label>
                                       </div>
                                       <div class="col-md-2">
                                          <div class="input-group">
                                             <input type="text" class="form-control input-sm" name="data[variations][{$varkey}][bonus_points]"
                                                    value="{$variation.bonus_points}" maxlength="10">
                                             <span class="input-group-addon">{'bonusPointsAddon'|translate:"products"}</span>
                                          </div>
                                       </div>
                                    {/if}

                                    {if $module.MISSING_PRODUCTS}
                                       <div class="col-md-1 col-md-offset-1 control-label two-lines">
                                          <label>{'inStoreMin'|translate:'products'}</label>
                                       </div>
                                       <div class="col-md-2">
                                          <div class="input-group">
                                             <input type="text" class="form-control input-sm" name="data[variations][{$varkey}][in_store_min]" size="3" maxlength="3" value="{$variation.in_store_min}"
                                                    onKeyPress="checkInputData('int');" />
                                             <span class="input-group-addon">ks</span>
                                          </div>
                                       </div>

                                    {/if}

                                    {ifmodule PRODUCTS__PRICE_COMMON}
                                       <div class="col-md-2 control-label">
                                          <label>{'priceLineThrough'|translate:'products'}</label>
                                       </div>
                                       <div class="col-md-2">
                                          <div class="input-group">
                                             <input type="text" class="form-control input-sm" name="data[variations][{$varkey}][price_common]" maxlength="50" value="{if $variation.price_common}{toDecimal($variation.price_common)|format_editable_price:-4}{/if}"/>
                                             <span class="input-group-addon">{$dbcfg.currency}</span>
                                          </div>
                                       </div>
                                    {/ifmodule}
                                 </div>
                                 {if $module.WAREHOUSE && $variation.ean}
                                    <div class="form-group">
                                       <div class="col-md-2">
                                          {insert_barcode height=30 width=2 code=$variation.ean}
                                       </div>
                                    </div>
                                 {/if}
                              {/if}
                              {block "custom-data"}{/block}
                           {/block}
                        </div>
                        {if $varkey > 0}
                     </div>{/if}


                     {* ##### KONEC TELO PANELU #####  *}
                  </div>
                  {/block}
               {/foreach}
            </div>
         </div>
         <div class="row bottom-space">
            {if $body.variations|@count > 0}
               <div class="col-md-3">
                  <a href="javascript:display('divVariationsLabels')" class="btn btn-block">{'manageNameplates'|translate:'products'}</a>
               </div>
            {/if}

            <div class="col-md-2">
            </div>

            <div class="col-md-4 pull-right">
               {if $body.choices_categorized|@count > 0}
                  <input type="submit" name="submitUpdateVariation" class="btn btn-primary btn-block" value="{'saveVariations'|translate:'products'}"/>
               {/if}
            </div>
         </div>

      </form>

      <div class="row bottom-space" id="divVariationsLabels" {if $body.variations|@count > 0}style="display: none;"{/if}>
         <form name="editform1" method="post" action="launch.php?s={$body.s}&amp;ID={$body.ID}" class="form-horizontal">
            <div class="col-md-6">
               <h4 class="h4 main-panel-title">{'addNewNameplate'|translate:'products'}</h4>
               <div class="row bottom-space">
                  <div class="col-md-5">
                     <select name="id_label" class="selecter selecter-up" data-label-select>
                        {foreach from=$body.choices item=choice_label key=choice_id}
                           {if in_array($choice_id, $body.choices_categorized) == false}
                              <option value="{$choice_id}">{$choice_label}</option>
                           {/if}
                        {/foreach}
                     </select>
                  </div>
                  <div class="col-md-5">
                     {if $body.variations|@count == 0 || $body.choices_categorized|@count == 0}
                        <input type="hidden" name="list_order" value="{$body.choices_categorized|@count + 1 }"/>
                        <input type="submit" name="submitAddChoice" class="btn btn-sm btn-primary btn-block" value="{'add'|translate:'button'}"/>
                     {else}
                        <input type="hidden" name="id_label_value" value="" data-autocomplete-value>
                        <input class="form-control input-sm" data-autocomplete-search="label_values" name="label_search" placeholder="Hodnota jmenovky..." autocomplete="off">
                     {/if}
                  </div>
                   {if $body.variations|@count != 0 && $body.choices_categorized|@count != 0}
                      <div class="col-md-2">
                         <input type="hidden" name="list_order" value="{$body.choices_categorized|@count + 1 }">
                         <input type="submit" name="submitAddChoice" class="btn btn-sm btn-primary btn-block"
                                value="{'add'|translate:'button'}">
                      </div>
                   {/if}
               </div>

            </div>
            <div class="col-md-5 pull-right">
               <h4 class="h4 main-panel-title">{'assignedNameplate'|translate:'products'}</h4>
               <div class="row bottom-space">
                  <div class="col-md-6">
                     <select name="id_label_del" class="selecter selecter-up">
                         {foreach from=$body.choices item=choice_label key=choice_id}
                             {if in_array($choice_id, $body.choices_categorized) == true}
                                <option value="{$choice_id}">{$choice_label}</option>
                             {/if}
                         {/foreach}
                     </select>
                  </div>
                  <div class="col-md-6">
                     <input type="hidden" name="list_order" value="{$body.choices_categorized|@count + 1 }">
                     <input type="button" value="{'edit'|translate:'button'}" class="btn btn-sm"
                            onClick="nw('productsVarLabels', $('select[name=id_label_del]').val())">
                     <input type="submit" name="submitDeleteChoice" value="{'delete'|translate:'button'}"
                            class="btn btn-sm btn-danger confirm" title="{{'delete'|translate:'button'}|lower}">
                  </div>
               </div>
            </div>
         </form>
      </div>


      <div class="bottom-space row" id="divVariationsCopy" style="display: none;">
         <div class="col-md-12">
            <form name="copy" method="post" action="launch.php?s={$body.s}&amp;ID={$body.ID}" class="form-horizontal">
               <h4 class="h4 main-panel-title">{'copyVariations'|translate:'products'}</h4>
               <div class="col-md-2 control-label">
                  <label>{'product'|translate:'products'}</label>
               </div>
               <div class="col-md-4">
                  {* <div class="input-group"> *}
                  <input type="text" id="productID" name="productID" class="form-control input-sm">
                  <script type="text/javascript">
                     new $.wpjAutoComplete({
                        input: $('#productID'),
                     });
                  </script>
                  {* <div class="input-group-btn">
                      <a href="javascript:searchWnd('product', '#productID', '');" class="btn btn-sm">{'findProduct'|translate:"products"}</a>
                   </div>
                </div> *}
               </div>
               <div class="col-md-2">
                  <input type="submit" name="submitCopy" class="btn btn-sm btn-primary btn-block" value="{'copy'|translate:'button'}"/>
               </div>
            </form>
         </div>
      </div>

   </div>
{/block}


<script type="text/javascript">
   {block onready append}
   $('.priceBuyVatDropdown').each(function() { priceVatDropdown($(this),{($dbcfg.prod_prefer_price_vat == 'Y') ? 1 : 0})})

   $('form[name=editform]').on('change ifClicked', ':input', function() {
      $(this).closest('.panel').find('input[name$=\\[changed\\]]').prop('checked', true);
   });

   $('[data-autocomplete-search="label_values"]').adminAutoComplete({
      type: 'VariationsLabelValues',
      parameters: 'id_label=' + $('[data-label-select]').val(),
      {literal}
      subtemplates: {
         menuItem: '<div tabindex="-1" data-autocomplete-item="{{=index}}">' +
            '<p>{{=item.text}}</p>' +
            '{{#def.buttons}}' +
            '</div>' +
            '{{#def.bottom}}',
      },
      {/literal}
      select: function (e, data) {
         var item = data.data.items[data.item.data('autocomplete-item')];

         $('[data-autocomplete-value]').val(item.value);
         $('[data-autocomplete-search="label_values"]').val(item.text);

         return false;
      },
   });

   $('[data-label-select]').on('change', function () {
      $('[data-autocomplete-search="label_values"]').adminAutoComplete('option', 'parameters', 'id_label=' + $(this).val());
   });

   function initPriceWithVat(selector) {
      var $selector = $(selector);
      $selector.on('click', 'li a', function() {
         var $this = $(this);
         var value = $this.data('value');
         var text = $this.html();
         var $wrap = $this.closest('[data-price=wrap]');
         var $input = $wrap.find('[data-price=with_vat]');

         if ($input.val() != value) {
            var $text = $wrap.find('[data-price=with_vat_text]');
            var $price = $wrap.find('[data-price=price]');
            $text.html(text);
            $input.val(value);

            var price = parseFloat($price.data('orig'));

            if (price) {
               var vat = parseFloat($price.data('vat'));
               var discount = parseFloat($price.data('discount'));

               switch (value) {
                  case 'Y':
                     price *= (100 + vat) / 100;
                     break;
                  case 'N':
                     break;
                  case 'F':
                     price *= ((100 + vat) / 100) * ((100 - discount) / 100);
                     break;
               }

               $price.val(formatPrice(price));
            }
         }
      });

      $selector.each(function() {
         var $this = $(this);

         var $input = $this.find('[data-price=with_vat]');
         var $select = $this.find('li a[data-value=' + $input.val() + ']');
         $select.click();
         $this.find('[data-price=with_vat_text]').html($select.html());
      });
   }

   initPriceWithVat('[data-price=wrap]');

   {block initAddForm}
   initForm({
      selector: '#variants',
      beforeAdd: function(original) {
         var $item = original();
         initPriceWithVat($item);
         $item.find('[name$="[inStoreOverride]"]').prop('checked', true);
         window.somethingChanged = true;
      },
   });
   {/block}
   {/block}
</script>
