<div class="row px-0">
<div style="padding-left: 0px;" class="col-md-12 col-lg-6 accordion accordion accordion-bordered mt-3 accordion-without-arrow" id="addPedidosImpresion">
    <div class="card accordion-item active mt-3 mx-2">

        <h3 class="accordion-header" id="headingAddPedidosImpresion">
            <button type="button" class="accordion-button collapsed" data-bs-toggle="collapse" data-bs-target="#accordionIcon-1" aria-controls="accordionIcon-1">
                <h4><?= lang('Facturas.addPedidosImpresion') ?> </h4>
            </button>
        </h3>

        <div id="accordionAddPedidosImpresionTip" class="accordion show" data-bs-parent="#accordioAddPedidosImpresion">
            <div class="accordion-body">
                <div class="row">
                    <div class="col-md-12 col-lg-10">
                        <select name="pedidoImpresion" id="pedidoImpresion" class="form-select">
                        </select>
                    </div>

                    <div class="col-md-12 col-lg-2">    
                        <button  
                                type="button"
                                class="btn btn-label-primary float-start me-sm-3 me-1"
                                name="addNewPedidoImpresion"
                                id="addNewPedidoImpresion" >
                            
                            <?= lang("Basic.global.addNew") ?>
                        </button>
                    </div>
                </div> <!--//row -->
                    
            </div> <!--//accordion-body -->
        </div> <!--//accordionFechasTip-->
    </div> <!--//card-->
</div>


<div style="padding-right: 0px;" class="col-md-12 col-lg-6 accordion accordion accordion-bordered mt-3 accordion-without-arrow" id="addPedidosMaquetacion">
    <div class="card accordion-item active mt-3 mx-2">

        <h3 class="accordion-header" id="headingAddPedidosMaquetacion">
            <button type="button" class="accordion-button collapsed" data-bs-toggle="collapse" data-bs-target="#accordionIcon-1" aria-controls="accordionIcon-1">
                <h4><?= lang('Facturas.addPedidosMaquetacion') ?> </h4>
            </button>
        </h3>

        <div id="accordionAddPedidosMaquetacionTip" class="accordion show" data-bs-parent="#accordioAddPedidosMaquetacion">
            <div class="accordion-body">

                <div class="row">
                    <div class="col-md-12 col-lg-10">
                        <select name="pedidoMaquetacion" id="pedidoMaquetacion" class="form-select">
                        </select>
                    </div>

                    <div class="col-md-12 col-lg-2">    
                        <button  
                                type="button"
                                class="btn btn-label-primary float-start me-sm-3 me-1"
                                name="addNewPedidoMaquetacion"
                                id="addNewPedidoMaquetacion" >
                            
                            <?= lang("Basic.global.addNew") ?>
                        </button>
                    </div>
                </div> <!--//row -->
                
            </div> <!--//accordion-body -->
        </div> <!--//accordionFechasTip-->
    </div> <!--//card-->
</div>
</div> <!--//row -->

<?=$this->section('additionalInlineJs') ?>

$('#pedidoImpresion').select2({
    placeholder: "<?= lang('Facturas.pedidoImpresion') ?>",
    allowClear: true,
    ajax: {
        url: '<?= route_to("menuPedidosPendientesImpresion", $facturaEntity->cliente_id) ?>',
        type: 'post',
        dataType: 'json',

        data: function (params) {
            return {
                id: 'id',
                text: 'nombre',
                searchTerm: params.term,
                <?= csrf_token() ?? "token" ?> : <?= csrf_token() ?>v
            };
        },
        delay: 60,
        processResults: function (response) {

            yeniden(response.<?= csrf_token() ?>);

            return {
                results: response.menu
            };
        },

        cache: true
    }
});

$('#addNewPedidoImpresion').on('click', function(){
    var lineaPedido = $('#pedidoImpresion').val();
    if(lineaPedido == null) {
        return;
    }
    $.ajax({
        url: '<?= route_to("addLineaPedidoImpresion2Factura", $facturaEntity->id) ?>',
        type: 'post',
        data: {
            lineaPedido: lineaPedido,
            <?= csrf_token() ?? "token" ?> : <?= csrf_token() ?>v
        },
        success: function(response) {
            yeniden(response.<?= csrf_token() ?>);
            
            // se ajustan el ancho de las columnas
            $('#pedidoImpresion').val(null).trigger('change');
            // Se actualiza la tabla de lineas de factura
            $('#tableOfLineasFactura').DataTable().clearPipeline().draw();
            $('#tableOfLineasPagos').DataTable().clearPipeline().draw();
        }
    });
});



$('#pedidoMaquetacion').select2({
    placeholder: "<?= lang('Facturas.pedidoMaquetacion') ?>",
    allowClear: true,
    width: '100%'
});

<?=$this->endSection() ?>