<form id="formEditVarianteNew" method="post" enctype="multipart/form-data" action="<?php url('variantes/guardar'); ?>">
    <input type="hidden" name="token" value="<?= token(); ?>">
    <input type="hidden" name="pv_proid" value="<?= $producto->pro_id; ?>">
    <div class="card bg-light mb-2">
        <div class="card-header">
            <button class="btn btn-outline-success" type="button" data-toggle="collapse"
                    data-target="#formEditVarianteNewCollapse" aria-expanded="false" aria-controls="collapseExample">
                <i class="fas fa-plus fa-fw" aria-hidden="true"></i> Nuevo
            </button>
            &nbsp; Variantes
        </div>
        <div class="collapse" id="formEditVarianteNewCollapse">
            <div class="card-body">
                <div class="row">
                    <div class="col-md-12">
                        <div class="form-row ">
                            <div class="col-md-4">
                                <div class="form-group">
                                    <label>Referencia</label>
                                    <div class="input-group">
                                        <div class="input-group-prepend"><span class="input-group-text"><i
                                                        class="fas fa-hashtag fa-fw"></i></span></div>
                                        <input type="text" name="pv_codigo" value="" class="form-control" maxlength="30"
                                               required="">
                                    </div>
                                </div>
                            </div>
                            <div class="col-md-4">
                                <div class="form-group">
                                    <label><a href="<?php url('atributos'); ?>">Atributo 1</a></label>
                                    <select name="pv_atributovalor1" class="form-control">
                                        <option value="">Seleccione...</option>
                                        <?php foreach ($atributos as $atributo): ?>
                                            <option value="<?php echo $atributo->pa_id; ?>"><?php echo strtoupper($atributo->pa_id).' '.$atributo->pa_id; ?></option>
                                        <?php endforeach; ?>
                                    </select>
                                </div>
                            </div>
                            <div class="col-md-4">
                                <div class="form-group">
                                    <label><a href="<?php url('atributos'); ?>">Atributo 2</a></label>
                                    <select name="pv_atributovalor2" class="form-control">
                                        <option value="">Seleccione...</option>
                                        <?php foreach ($atributos as $atributo): ?>
                                            <option value="<?php echo $atributo->pa_id; ?>"><?php echo strtoupper($atributo->pa_id).' '.$atributo->pa_id; ?></option>s
                                        <?php endforeach; ?>
                                    </select>
                                </div>
                            </div>
                            <div class="col-md-3">
                                <div class="form-group">
                                    <label>Código de barras</label>
                                    <div class="input-group">
                                        <div class="input-group-prepend"><span class="input-group-text"><i
                                                        class="fas fa-barcode fa-fw"></i></span></div>
                                        <input type="text" name="pv_codigobarras" class="form-control">
                                    </div>
                                </div>
                            </div>
                            <div class="col-md-3">
                                <div class="form-group">
                                    <label>Precio</label>
                                    <div class="input-group">
                                        <div class="input-group-prepend"><span class="input-group-text"><i
                                                        class="fas fa-euro-sign fa-fw"></i></span></div>
                                        <input type="number" name="pv_precio" value="0" class="form-control" step="any">
                                    </div>
                                </div>
                            </div>
                            <div class="col-md-3">
                                <div class="form-group">
                                    <label>Precio de coste</label>
                                    <div class="input-group">
                                        <div class="input-group-prepend"><span class="input-group-text"><i
                                                        class="fas fa-euro-sign fa-fw"></i></span></div>
                                        <input type="number" name="pv_coste" value="0" class="form-control" step="any">
                                    </div>
                                </div>
                            </div>
                            <div class="col-md-3">
                                <div class="form-group">
                                    <label>Stock</label>
                                    <input type="number" name="pv_stockfis" value="0" class="form-control" step="any"
                                           readonly="">
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="row">
                    <div class="col-12 text-right">
                        <button class="btn btn-sm btn-primary" type="submit">
                            <i class="fas fa-save fa-fw" aria-hidden="true"></i>
                            <span class="d-none d-sm-inline-block">Guardar</span>
                        </button>
                    </div>
                </div>
            </div>
        </div>
    </div>
</form>


<?php
    //verifico si exite algun registro, si este existe lo muestro el siguiente codigo
    if (!is_null($producto_variantes)):
        //muestro el numero de formularios segun el numero de variantes tenga el producto buscado
        foreach ($producto_variantes as $producto_variante):
            ?>
            <form id="formEditVariante0" method="post" enctype="multipart/form-data">
                <div class="card mb-2">
                    <div class="card-body">
                        <div class="row">
                            <div class="col-md-12">
                                <div class="form-row ">
                                    <div class="col-md-4">
                                        <div class="form-group">
                                            <label>Referencia</label>
                                            <div class="input-group">
                                                <div class="input-group-prepend"><span class="input-group-text"><i
                                                                class="fas fa-hashtag fa-fw"></i></span></div>
                                                <input type="text" name="pv_codigo"
                                                       value="<?= $producto_variante->pv_codigo; ?>" class="form-control"
                                                       maxlength="30" required="">
                                            </div>
                                        </div>
                                    </div>
                                    <div class="col-md-4">
                                        <div class="form-group">
                                            <label><a href="<?php url('atributos'); ?>">Atributo 1</a></label>
                                            <select name="pv_atributovalor1" class="form-control">
                                                <option value="">Seleccione...</option>
                                                <?php foreach ($atributos as $atributo): ?>
                                                    <?php if ($atributo->pa_id == $producto_variante->pv_atributovalor1): ?>
                                                        <option selected=""
                                                                value="<?php echo $atributo->pa_id; ?>"><?php echo strtoupper($atributo->pa_id).' '.$atributo->pa_id; ?></option>
                                                    <?php else: ?>

                                                        <option value="<?php echo $atributo->pa_id; ?>"><?php echo strtoupper($atributo->pa_id).' '.$atributo->pa_id; ?></option>

                                                    <?php endif; endforeach; ?>
                                            </select>
                                        </div>
                                    </div>
                                    <div class="col-md-4">
                                        <div class="form-group">
                                            <label><a href="<?php url('atributos'); ?>">Atributo 2</a></label>
                                            <select name="pv_atributovalor2" class="form-control">
                                                <option value="" selected="">Seleccione...</option>
                                                <?php foreach ($atributos as $atributo):
                                                    echo 'marico'.$atributo->pa_id.'---'.$producto_variante->pv_atributovalor2; ?>
                                                    <?php if ($atributo->pa_id == $producto_variante->pv_atributovalor2): ?>
                                                    <option selected=""
                                                            value="<?php echo $atributo->pa_id; ?>"><?php echo strtoupper($atributo->pa_id).' '.$atributo->pa_id; ?></option>
                                                <?php else: ?>
                                                    <option value="<?php echo $atributo->pa_id; ?>"><?php echo strtoupper($atributo->pa_id).' '.$atributo->pa_id; ?></option>
                                                <?php endif; endforeach; ?>
                                            </select>
                                        </div>
                                    </div>
                                    <div class="col-md-3">
                                        <div class="form-group">
                                            <label>Código de barras</label>
                                            <div class="input-group">
                                                <div class="input-group-prepend"><span class="input-group-text"><i
                                                                class="fas fa-barcode fa-fw"></i></span></div>
                                                <input type="text" name="pv_codigobarras"
                                                       value="<?= $producto_variante->pv_codigobarras; ?>"
                                                       class="form-control">
                                            </div>
                                        </div>
                                    </div>
                                    <div class="col-md-3">
                                        <div class="form-group">
                                            <label>Precio</label>
                                            <div class="input-group">
                                                <div class="input-group-prepend"><span class="input-group-text"><i
                                                                class="fas fa-euro-sign fa-fw"></i></span></div>
                                                <input type="number" name="pv_precio"
                                                       value="<?= $producto_variante->pv_precio; ?>" class="form-control"
                                                       step="any">
                                            </div>
                                        </div>
                                    </div>
                                    <div class="col-md-3">
                                        <div class="form-group">
                                            <label>Precio de coste</label>
                                            <div class="input-group">
                                                <div class="input-group-prepend"><span class="input-group-text"><i
                                                                class="fas fa-euro-sign fa-fw"></i></span></div>
                                                <input type="number" name="pv_coste"
                                                       value="<?= $producto_variante->pv_coste; ?>" class="form-control"
                                                       step="any">
                                            </div>
                                        </div>
                                    </div>
                                    <div class="col-md-3">
                                        <div class="form-group">
                                            <label>Stock</label>
                                            <input type="number" name="pv_stockfis"
                                                   value="<?= $producto_variante->pv_stockfis; ?>" class="form-control"
                                                   step="any" readonly="">
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="row">
                            <div class="col">
                                <a href="<?php url('variantes/eliminar/'.$producto_variante->pv_id); ?>"
                                   class="btn btn-sm btn-danger" onclick="editListViewDelete('EditVariante0');">
                                    <i class="fas fa-trash-alt fa-fw" aria-hidden="true"></i>
                                    <span class="d-none d-sm-inline-block">Eliminar</span>
                                </a>
                            </div>
                            <div class="col text-right">
                                <button class="btn btn-sm btn-secondary" type="reset">
                                    <i class="fas fa-undo fa-fw" aria-hidden="true"></i>
                                    <span class="d-none d-sm-inline-block">Deshacer</span>
                                </button>
                                <button class="btn btn-sm btn-primary" type="submit">
                                    <i class="fas fa-save fa-fw" aria-hidden="true"></i>
                                    <span class="d-none d-sm-inline-block">Guardar</span>
                                </button>
                            </div>
                        </div>
                    </div>
                </div>
            </form>
        <?php endforeach; endif; ?>
