<?php use_helper( 'UrlFunctions' ); ?>
<?php use_helper( 'IncludePartial' ); ?>
<?php use_helper( 'UtilFunctions' ); ?>

<script type="text/javascript">
changeIcon = function( elm, name )
{
    var elms    = $( elm ).find( "svg" );
    var elm_sel = elms.first();

    if( $( "#" + name ).is( ":visible" ) )
    {
        $( elm_sel ).removeClass( "fa-angle-down" );
        $( elm_sel ).addClass( "fa-angle-right" );
    }
    else
    {
        $( elm_sel ).removeClass( "fa-angle-right" );
        $( elm_sel ).addClass( "fa-angle-down" );
    }
}
</script>

<style type="text/css">
.ui-dialog .ui-dialog-titlebar-close 
{
    position: absolute;
    right: .3em;
    top: 50%;
    width: 20px;
    margin: -10px 0 0 0;
    padding: 1px;
    height: 20px;
    background-position: -96px -128px;
    /*background-image: url("images/ui-icons_056b93_256x240.png");*/
    background-image: url("<?=Constantes::ROOT_DIR_APP?>web/css/jquery/themes/start_1.12.1/images/ui-icons_056b93_256x240.png");
}
</style>

<div class="shadow-sm p-3 mb-2 bg-white rounded card card-body">
    <div class="row">
        <div class="col mb-1">
            <h4 class="text-info text-nowrap mb-0"> Asociar Guias - Facturas</h4>
        </div>
    </div>
</div>
<div id="accordion" class="mb-2">
    <div class="card">
        <div class="card-header">
            <a data-toggle="collapse" href="#collapseThree" aria-expanded="true" aria-controls="collapse1" 
                class="text-info" onclick="changeIcon(this,'collapseThree');" id="cotent_a_collapse" 
                >
                <h5 class="mb-0"> Filtro <i class="fas fa-angle-right pull-right"></i></h5>
            </a>
        </div>
        <div id="collapseThree" class="collapse" data-parent="#accordion">
            <div class="card-body pb-1">
                <form class="" name="form1" id="form1" method="POST" action="">
                    <div class="form-row mx-0">
                        <div class="col-md-4 mb-1">
                            <label class="col-form-label" for="IdPersona">Proveedor</label>
                               	<select name="IdPersona" id="IdPersona" class="form-control" style="width:100%">
                                    <option value=""> - Seleccione - </option>
                                    <?php foreach ( $a_MST_PersonaMast as $o_MST_PersonaMastBN ) { ?>
                                    <option value="<?=$o_MST_PersonaMastBN->getIdPersona()?>"> <?=$o_MST_PersonaMastBN->getNombreCompleto()?> </option>
                                    <?php } ?>
                                </select> 
                        </div>
                        <div class="col-md-4 mb-1 ">
                            <div class="col-auto">
                                <label class="col-form-label	" for="NumeroFact">Factura</label>
                                <div class="input-group mb-2">
                                    <div class="input-group-prepend">
                                        <select class="form-control text-center" name="SerieFactura" id="SerieFactura" >
                                            <option value=""> - Seleccione - </option>
                                            <?php foreach ( $a_Series as $i_Key => $s_Serie ){ ?>
                                            <option value="<?=$s_Serie?>"> <?=$s_Serie?> </option>
                                            <?php } ?>
                                        </select>
                                    </div>
                                    <input type="text" name="NumeroFact" id="NumeroFact" class="form-control" style="width:40%; ">
                                </div>
                            </div>
                        
                        </div>
                        <div class="col-md-4 mb-1 ">
                            <div class="col-auto">
                                <label class="sr-only" for="FechaDocumento1">Fecha Desde</label>
                                <div class="input-group mb-2">
                                    <div class="input-group-prepend">
                                        <div class="input-group-text"><?=addImgButton( "calendar.png", array( "class"=>"", "height"=>24 ) )?></div>
                                    </div>
                                    <input type="text" class="form-control text-center" id="FechaDocumento1" name="FechaDocumento1" placeholder="Fecha Desde" value="<?=date( "Y-m-d" )?>">
                                    <script type="text/javascript">
                                    $( "#FechaDocumento1" ).datepicker( { dateFormat: "yy-mm-dd", changeYear:true, yearRange: "-5:+0", changeMonth: true, onClose: function (){ this.focus(); } } );
                                    </script>
                                </div>
                            </div>
                            <div class="col-auto">
                                <label class="sr-only" for="FechaDocumento2">Fecha Hasta</label>
                                <div class="input-group mb-2">
                                    <div class="input-group-prepend">
                                        <div class="input-group-text"><?=addImgButton( "calendar.png", array( "class"=>"", "height"=>24 ) )?></div>
                                    </div>
                                    <input type="text" class="form-control text-center" id="FechaDocumento2" name="FechaDocumento2" placeholder="Fecha Hasta">
                                    <script type="text/javascript">
                                    $( "#FechaDocumento2" ).datepicker( { dateFormat: "yy-mm-dd", changeYear:true, yearRange: "-5:+0", changeMonth: true, onClose: function (){ this.focus(); } } );
                                    </script>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="form-row mx-0">
                        <div class="col-md-4 mb-1">
                            <label class="col-form-label" for="Estado">Estado</label>
                            <select class="form-control" name="Estado" id="Estado" >
                                <option value=""> - Seleccione - </option>
                                <?php foreach ( $a_Estados as $s_Key => $s_Values ){ ?>
                                <option value="<?=$s_Key?>"> <?=$s_Values?> </option>
                                <?php } ?>
                            </select>
                            
                        </div>
                        <div class="col-md-4 mb-1">
                            <div class="col-auto">
                                <label class="col-form-label	" for="SerieGuia">Nro Guia</label>
                                <div class="input-group mb-2">
                                    <div class="input-group-prepend">
                                        <select class="form-control text-center" name="SerieGuia" id="SerieGuia" >
                                            <option value=""> - Seleccione - </option>
                                            <?php foreach ( ALM_OrdenGuiaFacturaFN::recuperarFiltroSerieGuia() as $i_Key => $s_Serie ){ ?>
                                            <option value="<?=$i_Key?>"> <?=$s_Serie?> </option>
                                            <?php } ?>
                                        </select>
                                    </div>
                                    <input type="text" name="NumeroGuiaPer" id="NumeroGuiaPer" class="form-control" style="width:40%; ">
                                </div>
                            </div>
                        </div>
                        <div class="col-md-4 mb-1">
                            <label class="col-form-label" for="IdAlmacen">Almacen</label>
                                <select class="form-control text-center" name="IdAlmacen" id="IdAlmacen" >
                                    <option value=""> - Seleccione - </option>
                                    <?php foreach ( $a_ALM_AlmacenMast as $i_Key => $o_ALM_AlmacenMastBN ){ ?>
                                    <option value="<?=$o_ALM_AlmacenMastBN->getIdAlmacen()?>"> <?=$o_ALM_AlmacenMastBN->getDescripcionLocal()?> </option>
                                    <?php } ?>
                                </select>
                        </div>
                        <div class="col-md-4 mb-1">
                            <label class="col-form-label" for="IdPersona">Nro O/C</label>
                            <input type="text" class="form-control" name="IdOrdenCompra" id="IdOrdenCompra" >
                        </div>
                        
                    </div>
                    <div class="text-center mt-2">
                    	<input type="hidden" name="IdCompania" value="<?=myUser::getUser()->getIdBusiness()?>">	
                        <button class="btn btn-primary text-center" type="button" onclick="findControl();">Buscar</button>
                        <a data-toggle="collapse" href="#collapseThree" class="text-info" onclick="changeIcon( $('#cotent_a_collapse')[0],'collapseThree');" style="background: none;">
                            Contraer <i class="fas fa-angle-up"></i>
                        </a>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>


<div id="resultContent" style=""></div>


<?=crearFuentePopupIframe( array( "div_id"=>"dialog", "iframe_id"=>"myIframe", "popup_title"=>"Asociar Factura", "modal"=>true ) )?>
<?=crearFuentePopupIframe( array( "div_id"=>"dialog2", "iframe_id"=>"myIframe2", "popup_title"=>"Desasociar Factura", "popup_width"=>"530", "popup_height"=>"350", "modal"=>true ) )?>
<?=crearFuentePopupIframe( array( "div_id"=>"dialog3", "iframe_id"=>"myIframe3", "popup_title"=>"Resumen", "modal"=>true ) )?>

<div id="jqGridPager"></div>

<script>
closeWindows = function()
{
    $( '#dialog' ).dialog( 'close' );
    $( '#dialog2' ).dialog( 'close' );
    $( '#dialog3' ).dialog( 'close' );
}
findControl = function ()
{
    strFormSerialize = $( 'form' ).serialize();
    relaodGrid( strFormSerialize );
}

relaodGrid = function( s_url_param )
{
	blockContent( 'jqGridPager' );
    executeAjaxUpdater( 
            "jqGridPager", 
            "<?=buildUrl( 'asoguias/grid', '' )?>", 
            strFormSerialize, 
            function()
            {
            	unBlockContent( 'jqGridPager' );
                
            	//var column = $( '#content_all_row td:nth-child( 4 )' );
            	//modifyTableRowspan( column );
            }
      );
}
findControl();
</script>

<script>
$( document ).bind
(
    'keyup', 
    function( e ) 
    {
        if( e.which === 13 ) //ENTER
        {
            findControl();
        }
        if( e.which == 107 || e.which == 27 || e.which == 109 ) //tecla + | ESC | -
        {
            $( "#cotent_a_collapse" ).trigger( "click" );
        }
    }
);
</script>