<% @Import Namespace="Seven.Front" %>
<% @Import Namespace="Seven.Front.Globals" %>
<% @Import Namespace="Seven.Front.Objects" %>
<%@ Page Language="C#" MasterPageFile="Model.Master" AutoEventWireup="true" CodeBehind="DisponibilidadHabitacionesW.aspx.cs" Inherits="Seven.Front.DisponibilidadHabitacionesW" %>

<%@ Register Assembly="Microsoft.ReportViewer.WebForms, Version=11.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91"
    Namespace="Microsoft.Reporting.WebForms" TagPrefix="rsweb" %>

<asp:Content ID="Content1" ContentPlaceHolderID="cpHeader" runat="server">

    <title><%=L.TIT("DisponibilidadHabitaciones") %> [4.6]</title>
    
    <script type="text/javascript">

        function Ver()
        {
            window.location.href = "DisponibilidadHabitacionesW.aspx?s=" + $('#txtFecIni').val() +
                "&f=" + $('#txtFecFin').val() + "&t=" + $('#cbTipoHabi').val() + "&o=" + $('input[name=rbOrden]:checked').val();
        }

        function VerInforme() {
            window.open("DisponibilidadHabitaciones.aspx?s=" + $('#txtFecIni').val() +
                "&f=" + $('#txtFecFin').val() + "&t=" + $('#cbTipoHabi').val() + "&o=" + $('input[name=rbOrden]:checked').val(), "_blank");
        }

        function DialogoDetalle(hab, fecha, estado) {
            $.ajax({
                url: 'Servicio.svc/GetDisponibilidadHabitacionesDetalle',
                data: {
                    "id_habi": hab, "fecha" : fecha, "estado": estado
                , "U": "<%=Request.Cookies[Parametros.COOKIE_USR].Value %>", "N": "<%=Request.Cookies[Parametros.COOKIE_NOM].Value %>"
                , "D": "<%=Request.Cookies[Parametros.COOKIE_DAT].Value %>", "I": "<%=Enigma.Encriptar(Request.ServerVariables["REMOTE_ADDR"]) %>"
                , "LangCode": "<%=LangCode %>"
                },
                dataType: "json",
                type: "GET",
                contentType: "application/json; charset=utf-8",
                beforeSend: function () {
                    $('#dlgCargando').dialog('open');
                },
                success: function (json) {
                    $('#dlgCargando').dialog('close');
                    try {
                        $('#dlgDetalleCargo').html(json.d);
                        $('#dlgDetalleCargo').dialog('open');
                    }
                    catch (err) {
                        $('#dlgInformation').html(json.d);
                        $('#dlgInformation').dialog('open');
                    }
                }
            });
        }

        function CambiarHabi(rese, nro, hab) {
            $.ajax({
                url: 'Servicio.svc/PutDHCambioHabitacion',
                data: {
                    "reserva": rese, "numero": nro, "id_habi_ori": hab, "id_habi_des": $('#cbCambioHabiDH').val()
                , "U": "<%=Request.Cookies[Parametros.COOKIE_USR].Value %>", "N": "<%=Request.Cookies[Parametros.COOKIE_NOM].Value %>"
                , "D": "<%=Request.Cookies[Parametros.COOKIE_DAT].Value %>", "I": "<%=Enigma.Encriptar(Request.ServerVariables["REMOTE_ADDR"]) %>"
                , "LangCode": "<%=LangCode %>"
                },
                dataType: "json",
                type: "GET",
                contentType: "application/json; charset=utf-8",
                beforeSend: function () {
                    $('#dlgCargando').dialog('open');
                },
                success: function (json) {
                    var res = json.d;
                    if (res > 0 || res < 0) {
                        Ver();
                    }
                    else {
                        $('#dlgCargando').dialog('close');
                        $('#dlgInformation').html(json.d);
                        $('#dlgInformation').dialog('open');
                    }
                }
            });
        }

        Date.prototype.addDays = function (days) {
            var dat = new Date(this.valueOf());
            dat.setDate(dat.getDate() + days);
            return dat;
        }

        function InitializeComponentsDH()
        {
            $('#txtFecIni').on('change', function () {
                var hasta = $('#txtFecIni').datepicker('getDate');
                $('#txtFecFin').datepicker('setDate', hasta.addDays(30));
            });
            $('#txtFecIni').on('input', function ()
            {
                var hasta = $('#txtFecIni').datepicker('getDate');
                $('#txtFecFin').datepicker('setDate', hasta.addDays(30));
            });
        }

    </script>

    <script type="text/javascript">

        $(document).ready(function () {

            $("#dlgCargando").dialog({
                autoOpen: false,
                show: "fade",
                hide: "curtain",
                resizable: false,
                height: 100,
                width: 270,
                modal: true,
                dialogClass: 'no-close'
            });

            $("#dlgDetalleCargo").dialog({
                autoOpen: false,
                show: "fade",
                hide: "curtain",
                resizable: false,
                height: 500,
                width: 510,
                modal: true,
                buttons: {
                    "<%=L.LBL("LblGENAceptar") %>": function () {
                        $(this).dialog("close");
                    }
                }
            });

            $("#dlgInformation").dialog({
                autoOpen: false,
                show: "fade",
                hide: "curtain",
                resizable: false,
                height: 167,
                width: 500,
                modal: true
            });

            $("#SevenMenu").accordion("option", "active", 4);

            $("#EnlaceMaestro").focus();

            $("#cbTipoHabi").val(<%=id_thab %>);

            InitializeComponentsDH();

        });

    </script>

    <style type="text/css">
        .tblDH
        {
            border-bottom:0;
            border-left:0;
            font-size: 9pt;

            table-layout: fixed;
        }

        .tblDH thead tr {
            display: block;
            position: relative;
        }

        .tblDH tbody {
            display: block;
            overflow-x: hidden;
            overflow-y: auto;
            width: 100%;
            height: 450px;
        }

        .tblDH td
        {
            min-width: 100px;
            text-align: center;
            white-space: nowrap;
            border: 1px solid #B3B1B1;
            border-top:0;
            border-right:0;
            cursor: pointer;
        }

        .tblDH th
        {
            min-width: 100px;
            text-align: center;
            white-space: nowrap;
            border: 1px solid #B3B1B1;
            /*border-top:0;*/
            border-right:0;
            font-weight: bold;
            font-style: italic;
        }

        .titDH
        {
            font-weight: bold;
            text-decoration: underline;
            color: blue;
        }
    </style>

</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="cpPrincipal" runat="server">

    <div id="SevenBreadcrumb" class="ui-state-default">
        <table style="width: 100%; white-space: nowrap;">
            <tr>
                <td>
                    <div class="SevenEnlaces" onclick="window.location.href='Menu.aspx#M5';" style="cursor: pointer;">
                        <table>
                            <tr>
                                <td>
                                    <img src="img/application-icon-large.png" />
                                </td>
                                <td>
                                    <%=L.LBL("LblGENMenuTactil") %>
                                </td>
                            </tr>
                        </table>
                    </div>
                </td>
                <td>&nbsp;</td>
                <td>
                    <a href="../Inicio.aspx"><%=L.LBL("LblGENInicio") %></a>
                    <img src="../img/arrow.png" alt="" />
                    <a href="#"><%=L.TIT("DisponibilidadHabitaciones") %> [4.6]</a>
                </td>
                <td style="width: 100%;"></td>
                <td>
                    <%=L.LBL("LblGENLanguage") %>
                </td>
                <td>
                    <!-- #include file="LanguageCombo.html" -->
                </td>
            </tr>
        </table>
        
    </div>
            
    <div id="SevenPrincipal">
                
        <div id="SevenMedio">
                    
            <div id="SevenInterno" style="width: 1000px; height: 650px;">

                <div id="dlgCargando" title="<%=L.LBL("LblGENLoading") %>" style="text-align: center; padding-top: 25px">
                    <img src="img/cargando2.gif" alt="<%=L.LBL("LblGENLoading") %>" />
                </div>

                <div id="dlgInformation" title="<%=L.LBL("LblGENInformation") %>" style="text-align: center; padding-top: 25px">
                </div>

                <div id="dlgDetalleCargo" title="<%=L.LBL("LblGENInformation") %>" style="padding-top: 25px">
                    
                </div>

                <br />

                <table>
                    <tr>
                        <td>
                            <span class="SevenTitulo"><%=L.TIT("DisponibilidadHabitaciones") %> [4.6]</span>
                        </td>
                        <td>&nbsp;&nbsp;&nbsp;</td>
                        <td>
                            <div class="SevenEnlaces">
                                <table>
                                    <tr>
                                        <td>
                                            <a href="#" onclick="window.open('http://mysevenmanuales.jimdo.com/front-desk/4-6-disponibilidad-por-habitaciones/', '_blank');" id="A1" >
                                                <img src="../img/question.png" /> <%=L.LBL("LblGENHelp") %>
                                            </a>
                                        </td>
                                    </tr>
                                </table>
                            </div>
                        </td>
                        <td>
                            <div class="SevenEnlaces">
                                <table>
                                    <tr>
                                        <td>
                                            <a href="#" onclick="VerInforme();" id="A2" >
                                                <img src="../img/report.png" /> <%=L.LBL("LblGENInforme") %>
                                            </a>
                                        </td>
                                    </tr>
                                </table>
                            </div>
                        </td>
                    </tr>
                </table>

                <br />

                <table>
                    <tr>
                        <td>
                            <%=L.LBL("LblGENStart") %>:
                        </td>
                        <td>
                            <input type="text" id="txtFecIni" value="<%=String.Format("{0:d}", FecIni) %>" class="eligeFecha" style="width: 100px;" />
                        </td>
                        <td>
                            <%=L.LBL("LblGENEnd") %>:
                        </td>
                        <td>
                            <input type="text" id="txtFecFin" value="<%=String.Format("{0:d}", FecFin) %>" class="eligeFecha" style="width: 100px;" />
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <%=L.LBL("LblGENTipoHab") %>:
                        </td>
                        <td colspan="3">
                            <%=cbTipoHabi %>
                        </td>
                        <td>
                            <%=L.LBL("LblGENOrder") %>:
                        </td>
                        <td>
                            <input type="radio" name="rbOrden" value="1" <% if(orden == 1){ %> checked="checked" <% } %> /><%=L.LBL("LblGENRoomType") %>
                            <input type="radio" name="rbOrden" value="0" <% if(orden == 0){ %> checked="checked" <% } %> /><%=L.LBL("LblGENRoom") %>
                            <%--<input type="radio" name="rbOrden" value="1" <% if(orden == 2){ %> checked="checked" <% } %> /><%=L.LBL("LblGENRoomTypeByOrder") %>--%>
                        </td>
                        <td>
                            <button type="button" onclick="Ver();">
                                <table>
                                    <tr>
                                        <td>
                                            <img src="img/magnifier16.png" alt="" />
                                        </td>
                                        <td>
                                            <%=L.LBL("LblGENVer") %>
                                        </td>
                                    </tr>
                                </table>
                            </button>
                        </td>
                    </tr>
                </table>

                <br />

                <table style="width: 90%; font-size: 9pt; font-weight: bold;">
                    <tr>
                        <td><%=L.LBL("LblGENLeyenda") %>:</td>
                        <td style="width: 20px; background-color: #FFFFFF; border: 1px solid black;"></td>
                        <td><%=L.LBL("LblFDKDCVacia") %></td>
                        <td style="width: 20px; background-color: #fff5a2; border: 1px solid black;"></td>
                        <td><%=L.LBL("LblFDKEHReservada") %></td>
                        <td style="width: 20px; background-color: #a1ffa1; border: 1px solid black;"></td>
                        <td><%=L.LBL("LblFDKESRERooming") %></td>
                        <td style="width: 20px; background-color: #acb9ff; border: 1px solid black;"></td>
                        <td><%=L.LBL("LblFDKEHPreasig") %></td>
                        <td style="width: 20px; background-color: #cccccc; border: 1px solid black;"></td>
                        <td><%=L.LBL("LblFDKFueraOrden") %></td>
                        <td style="width: 20px; background-color: #ffb6b6; border: 1px solid black;"></td>
                        <td><%=L.LBL("LblFDKEHOcupada") %></td>
                        <td style="width: 20px; background-color: #FFFFFF; border: 1px solid black; color: blue; text-align: center;">***</td>
                        <td><%=L.LBL("LblFDKCheckOut") %></td>
                        <td style="width: 20px; background-color: #d1a2e0; border: 1px solid black;"></td>
                        <td><%=L.LBL("LblDHCheckInProceso") %></td>
                    </tr>
                </table>

                <br />

                <div style="width: 1000px; max-height: 500px; overflow-x: scroll; overflow-y: hidden;">
                    <table class="tblDH">
                        <thead>
                            <tr>
                                <th class="ui-state-default" style="min-width: 100px; padding-left: 10px;">
                                    <%=L.LBL("LblGENRoom") %>
                                </th>
                                <th class="ui-state-default" style="min-width: 100px;">
                                    <%=L.LBL("LblGENType") %>
                                </th>
                                <% 
                                    // Creación del Encabezado
                                    DateTime FecAct = FecIni;
                                    while(FecAct <= FecFin)
                                    {
                                        Response.Write("<th class=\"ui-state-default\" style=\"min-width: 100px;\">" + string.Format("{0:d}", FecAct) + "</th>");
                                        FecAct = FecAct.AddDays(1);
                                    }
                                %>
                            </tr>
                        </thead>
                        <tbody>
                            <% 
                                // Detalle
                                bool Primero = true;
                                string Sucia = L.LBL("LblFDKSucia").ToCharArray()[0].ToString().ToLower();
                                foreach(System.Data.DataRow dr in DatosDH.Tables[0].Rows)
                                {
                                    FecAct = DateTime.Parse(dr["Fecha"].ToString());
                                    int estado = int.Parse(dr["estado"].ToString());
                                    int estado_real = int.Parse(dr["estado_real"].ToString());

                                    if (FecAct == FecIni)
                                    {
                                        // Inicio de una fila nueva.
                                        if (!Primero)
                                        {
                                            Response.Write("</tr>");
                                        }
                                        else
                                        {
                                            Primero = false;
                                        }
                                        Response.Write("<tr>");
                                        Response.Write("<td class=\"titDH\" style=\"min-width: 100px; text-align: left; padding-left: 10px; background-color: white;\" " 
                                            + "onclick=\"DialogoDetalle('" + dr["id_habi"].ToString()
                                            + "', '" + dr["Fecha"].ToString()
	                                        + "', '-1');\""
                                            + " >"
                                            + dr["habitacion"].ToString().Trim() + "</td>");
                                        Response.Write("<td style=\"min-width: 100px; text-align: left; background-color: white;\" " 
                                            + "onclick=\"DialogoDetalle('" + dr["id_habi"].ToString()
                                            + "', '" + dr["Fecha"].ToString()
	                                        + "', '-1');\""
                                            + ">"
                                            + dr["tipo_habi"].ToString().Trim() + (int.Parse(dr["limpia"].ToString()) == 1 ? "" : " (" + Sucia + ")") + "</td>");
                                    
                                        Response.Write("<td class=\"titDH\" style=\"background-color: " + dr["estado_color"].ToString() + ";\" "
                                            + "onclick=\"DialogoDetalle('" + dr["id_habi"].ToString()
	                                        + "', '" + dr["Fecha"].ToString()
	                                        + "', '" + (estado != 1 && estado_real == 1 ? "1" : estado.ToString()) + "');\""
                                            + " >" 
                                            + (estado != 1 && estado_real == 1 ? "***" : dr["referencia"].ToString())
                                            + "</td>");
                                    }
                                    else
                                    {
                                        // Celda siguiente en la fila.
                                        Response.Write("<td class=\"titDH\" style=\"background-color: " + dr["estado_color"].ToString() + ";\" " 
                                            + "onclick=\"DialogoDetalle('" + dr["id_habi"].ToString()
	                                        + "', '" + dr["Fecha"].ToString()
	                                        + "', '" + (estado != 1 && estado_real == 1 ? "1" : estado.ToString()) + "');\""
                                            + " >" 
                                            + dr["referencia"].ToString() + "</td>");
                                    }
                                }
                            %>
                        </tbody>
                    </table> 
                </div>
            </div>
                    
        </div>
                
    </div>

</asp:Content>
