<?php use_helper('UrlFunctions'); ?>
<?php use_helper( 'IncludePartial' ); ?>
<style>
  .ui-autocomplete-loading { background: white url("<?=Constantes::ROOT_DIR_IMG?>common/progress.gif") right center no-repeat; }
</style>
<style>
.header { background-color: #E1E1E1; color: #444444; font-family: Arial,Helvetica,sans-serif; font-size: 11px; font-weight: bold; }
.pager { background-color: #F4F4F4; background-image: none; border-bottom: thin solid #999999; }
</style>
<style type="text/css">
.marcoTabActive {
  /*background:#F1F1F1 none repeat scroll 0 0;*/
  background:#A3C1E0 none repeat scroll 0 0;  font-family:Geneva, Arial, Helvetica, sans-serif;  font-size:14px;  border-top-width: 1px;
  border-right-width: 1px;  border-left-width: 1px;  border-top-style: solid;  border-right-style: solid;  border-left-style: solid;  border-top-color: #999999;
  border-right-color: #999999;  border-left-color: #999999;  font-weight: bold;  /*color:#990000;*/
}
.label { color: #444444; }
.lblSmall { color: #8D8D8D; font-size: 10px; padding-right: 8px; }
</style>
<style>
.codigoItem{ color: blue; text-decoration: underline; cursor: pointer; }
.codigoItem:hover{ text-decoration: none; cursor: pointer; }
</style>
<script>
mostrarMensajeError = function( s_MensajeError )
{
    $( "#resultContent" ).html( '<div id="mensaje_error_content" class="error">' + s_MensajeError + '</div>' );
    setTimeout( function(){ $( "#mensaje_error_content" ).fadeOut( 800 ).fadeIn( 800 ).fadeOut( 500 ).fadeIn( 500 ).fadeOut( 300 ); }, 4000 );
}
</script>
<script type="text/javascript">
Abrirpagina = function()
{
    window.open('<?=buildUrl( 'pro/printPDF', 'vHtml=1&i_Id='.$o_VTA_DocumentoBN->getIdConcat() )?>', '_blank', '');
}

verPDFOrdenVenta = function()
{
    window.open('<?=buildUrl( 'pro/printPDF', 'i_Id='.$o_VTA_DocumentoBN->getIdConcat() )?>', '_blank', '');
}

clonarDocumentoVenta = function()
{
    x = confirm( "Esta seguro de copiar la Orden?" );
    if( x )
    {
        blockContent( 'content_buttons' );
        blockContent( 'content_result_grid1' );

        var IdTipoDocumento  = $( "#IdTipoDocumento" ).val();
        var FechaDocumento   = $( "#FechaDocumento" ).val();
        var TipoDocumentoCod = $( "#TipoDocumentoCod" ).val();
        var DocumentoSerie   = $( "#DocumentoSerie" ).val();
        var DocumentoNumero  = $( "#DocumentoNumero" ).val();

        var str_serialize = "id=<?=$i_Id?>&IdTipoDocumento=" + IdTipoDocumento + "&TipoDocumentoCod=" + TipoDocumentoCod + "&DocumentoSerie=" + DocumentoSerie + "&DocumentoNumero=" + DocumentoNumero + "&FechaDocumento=" + FechaDocumento;
        
        executeAjaxJson
        (
            "<?php echo buildUrl( 'pro/copiarDocumento' ) ?>",
            str_serialize,
            function( o_json )
            {
                pr( o_json );
                unBlockContent( 'content_result_grid1' );
                unBlockContent( 'content_buttons' );
                if( o_json.error )
                {
                    mostrarMensajeError( o_json.mensaje_error );
                    return false;
                }
                //location.href = "<?php echo buildUrl( 'pro/detailVta', "i_Id=" ) ?>" + o_json.id;
                window.open('<?=buildUrl( 'pro/detailVta', 'i_Id=' )?>' + o_json.id, '_blank', '');
            }
        );
    }
}
preClonacionOrden = function()
{
    $( '#dialog6' ).dialog( 'open' );
}
</script>

<div class="titleBody descripProy" style="width: 100%; display: inline-block; padding-left: 0px; padding-right: 0px; margin-bottom: 10px;">
    <div style="text-align: right; display: inline-block; width: 30%; float: right;" id="content_buttons">

        <!-- <input class="ui-button ui-widget ui-corner-all" style="padding-top: 0.1em; padding-bottom: 0.2em; font-size: 0.5em;" type="button" value="Copiar" onclick="preClonacionOrden();"> -->
        <input class="ui-button ui-widget ui-corner-all" style="padding-top: 0.1em; padding-bottom: 0.2em; font-size: 0.5em;" type="button" value="PDF Plantilla" onclick="verPDFOrdenVenta();">
        <input class="ui-button ui-widget ui-corner-all" style="padding-top: 0.1em; padding-bottom: 0.2em; font-size: 0.5em;" type="button" value="Ver Resumen" onclick="Abrirpagina();">

    </div>
</div>

<script>
var b_ControlBuscarSerie = true;
recuperarInfoVentaSerie = function()
{
    if( b_ControlBuscarSerie )
    {
        var value = $( "#IdTipoDocumento" ).val();
        executeAjaxJson
        ( 
            '<?php echo buildUrl( 'pro/request' ) ?>', 
            'TipoProc=getSerieNumero&IdTipoDocumento=' + value, 
            function( o_json )
            {
                pr( o_json );
                if( o_json.error )
                {
                    alert( o_json.mensaje_error );
                    return false;
                }
                if( o_json.Result )
                {
                    $( "#DocumentoSerie" ).val( o_json.Serie );
                    $( "#DocumentoNumero" ).val( o_json.Numero );
                    $( "#TipoDocumentoCod" ).val( o_json.TipoDocumentoCod );
                }
            }
        );
    }        
}
</script>

<div id="dialog6">
    <table border="0" cellspacing="5" cellpadding="0" style=""  width="100%">
        <tr>
            
            <td nowrap="nowrap" width="45%" align="center">
                <label class="label req" for="IdTipoDocumento" >Clase</label>
                <select class="combo required" id="IdTipoDocumento" name="IdTipoDocumento" onchange="recuperarInfoVentaSerie();" style="">
                    <option value=""> - Seleccione - </option>
                    <?php foreach ( $a_VTA_TipoDocumento as $i_Key => $o_VTA_TipoDocumentoBN ){ ?>
                    <option value="<?=$o_VTA_TipoDocumentoBN->getIdTipoDocumento()?>" > <?=$o_VTA_TipoDocumentoBN->getDescripcionLocal() ?> </option>
                    <?php } ?>
                </select>
                <label class="label req" for="IdTipoDocumento" >Fecha</label>
                <input type="text" class="text required text0" name="FechaDocumento" id="FechaDocumento" value="<?=date( "Y-m-d" )?>" style="width:25%; text-align:center; color: #fc6d00; font-size: 12px; font-weight: bold;" readonly/>
                <script type="text/javascript">
                $( "#FechaDocumento" ).datepicker( { dateFormat: "yy-mm-dd", changeYear:true, yearRange: "-1:+1", changeMonth: true, onClose: function ( s_date ){ this.focus(); $( "#FechaVencimiento" ).val( s_date ); } } );
                </script>
            </td>
        </tr>
        <tr>
            <td nowrap="nowrap" class="" colspan="2" align="left">
                <input type="hidden" name="TipoDocumentoCod" id="TipoDocumentoCod" class="notin" value="">

                <label class="label req" for="DocumentoSerie" >Serie :</label>
                <input type="text" class="text notin" name="DocumentoSerie" id="DocumentoSerie" style="width:20%; text-align:center; color: #fc6d00; font-size: 20px; font-weight: bold;" value="" readonly>
                &nbsp;
                <label class="label req" for="Serie" >N&uacute;mero :</label>
                <input type="text" class="text notin" name="DocumentoNumero" id="DocumentoNumero" style="width:45%; text-align:center; color: #fc6d00; font-size: 20px; font-weight: bold;" value="" readonly>
            </td>
        </tr>
        <tr>
            <td align="center"> <input type="button" value="Clonar Documento" class="ui-button ui-corner-all ui-widget notin" onclick="clonarDocumentoVenta()"> </td>
        </tr>
    </table>
</div>
<script>
    objMainTab.modalUIDialog( "#dialog6", { title : "", width : 500, height  : 170, modal : true } );
</script>

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

<form id="form1" name="form1" method="POST" onsubmit="return false;"  enctype="multipart/form-data">
<table class="cuerpo" width="100%" border="0" cellpadding="0" cellspacing="0">
    <tr>
        <td valign="top">
            
                <input type="hidden" name="s_TipoProc" id="s_TipoProc" value="<?=$s_TipoProc?>">
                <input type="hidden" name="s_TipoProc" id="i_Id" value="<?=$i_Id?>">
                <input type="hidden" name="TypeSub" id="TypeSub" value="0">
                <table class="" width="100%">
                    <tr>
                        <td valign="top">
                            <table width="100%" border="0" cellspacing="0" cellpadding="0">
                                <tr>
                                    <td class="marco">
                                        <table class="" width="100%" height="100%" border="0" cellspacing="0" cellpadding="0">
                                            <tr>
                                                <td width="100%" valign="top">
                                                    <fieldset class="formGen">
                                                        <legend class="fielsettex">[<?=$o_VTA_DocumentoBN->getNumeroDocumento()?>] <?=$o_VTA_DocumentoBN->getDocumentoTipoSerieNumero()?></legend>
                                                        <?php include_partial( 
                                                                                "infohead", 
                                                                                array( 
                                                                                        "o_VTA_DocumentoBN"   => $o_VTA_DocumentoBN,
                                                                                        "o_GSS_MonedaMastBN"  => $o_GSS_MonedaMastBN,
                                                                                        "o_MST_PersonaMastFN" => $o_MST_PersonaMastFN,
                                                                                        "a_VTA_FormaPago"     => $a_VTA_FormaPago
                                                                                     )
                                                                             ); ?>
                                                    </fieldset>
                                                </td>
                                            </tr>
                                        </table>
                                    </td>
                                </tr>
                                <tr><td>&nbsp;</td></tr>
                                <tr>
                                    <td class="marco">
                                        <table class="" width="100%" height="100%" border="0" cellspacing="0" cellpadding="0">
                                            <tr>
                                                <td width="100%" valign="top">
                                                    <fieldset class="formGen">
                                                        <legend class="fielsettex">Detalles</legend>
                                                        <?php include_partial( 
                                                                                "detail", 
                                                                                array( 
                                                                                        "o_VTA_DocumentoBN"      => $o_VTA_DocumentoBN,
                                                                                        "a_VTA_DocumentoDetalle" => $a_VTA_DocumentoDetalle
                                                                                     )
                                                                             ); ?>
                                                    </fieldset>
                                                </td>
                                            </tr>
                                        </table>
                                    </td>
                                </tr>
                            </table>
                        </td>
                    </tr>
                </table>
            
        </td>
    </tr>
</table>

<table cellpadding="0" cellspacing="0" width="100%" border="0" style="">
    <tr>
        <td align="center" >
            <input type="button" class="button" value="Salir" onclick="parent.closeWindow();">
        </td>
    </tr>
</table>

</form>

<?=crearPopupResumenStock( array( "name_function"=>"buscarResumenStock" ) )?>

<script>
executeFindDetail = function()
{
	var i_Id = $( "#i_Id" ).val();
	
    var a_Params = [];
    a_Params.push( "i_Id=" + i_Id );
    
    executeAjaxUpdater( 
                            "content_result_grid1", 
                            "<?php echo buildUrl( 'pro/findDetailVta', "block=001&noedit=1" ) ?>", 
                            a_Params.join( "&" ), 
                            function( response )
                            {
                                convertirTextoTodosLosInputs();
                            } 
                      );
}
convertirTextoTodosLosInputs = function()
{
    $( "#form1 input:text, #form1 select, textarea" ).replaceWith
    (
        function () 
        {
            //console.log( this );
            if( this.id )
            {
                console.log( $( "#" + this.id + " option:selected" ).text() );
                return '<label class=labelData >' + $( "#" + this.id + " option:selected" ).text() + '</label>';
            }
            else
            {
                console.log( $( this ).val() );
                return '<label class=labelData >' + $( this ).val() + '</label>';
            }
            //var text_select = $( "#" + this.id + " option:selected" ).text()
            //console.log( $( "#" + this.id + " option:selected" ).text() );
            //console.log( $( this ).text() );
            //return '<label class=labelData >' + $( this ).val() + '</label>';
        }
    );
}
</script>

<script>
convertirTextoTodosLosInputs();
</script>