File size: 4,666 Bytes
eb0b2fd
 
 
 
 
 
 
 
 
 
caf951b
eb0b2fd
 
 
 
 
 
caf951b
eb0b2fd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
from streamlit_calendar import calendar
import streamlit as st
from datetime import datetime
from zoneinfo import ZoneInfo
from data.solicitar_data import (get_event)
import pandas as pd
import json
from pandasql import sqldf
from auth import (get_id_cliente_reciclador)
from config import CONFIG
import url64

st.set_page_config(page_title="Lista de recolecciones", page_icon="📆", layout="wide")
st.markdown("<style>#MainMenu {visibility: hidden;} footer {visibility: hidden;} /*header {visibility: hidden;}*/</style>", unsafe_allow_html=True)

query_params = st.experimental_get_query_params()

auth_token = url64.decode(query_params.get("t", [""])[0])

id_clientereciclador = None
if query_params.get("demo", [None])[0] == "true":
    id_clientereciclador = 2
else:
    raw_token = query_params.get("t", [None])[0]
    if raw_token is not None:
        # Get user id from token
        id_clientereciclador = get_id_cliente_reciclador(raw_token)

st.session_state["id_reciclador"] = id_clientereciclador


if id_clientereciclador is None:
    st.write("🔒 Parece que no tienes permiso para ver esto.")
else:
    st.title("Lista de Recolección 🚚 📆")
    st.markdown('### <span style="color:#9656E2; text-align: center">© Blau tecnología para residuos | blaucorp.com </span>', unsafe_allow_html=True)

    data = get_event(id_clientereciclador)

    now =  datetime.now(ZoneInfo('America/Mexico_City'))

    #Preprocesamiento
    rutas = data["ruta_chofer"].unique()
    clientes = data["cliente"].unique()
    sucursal = data["sucursal"].unique()
    estatus = data["estatus"].unique()

    col1, col2 = st.columns(2)
    with col1:
        ruta_filter = st.multiselect("Ruta - Chofer", options=rutas)
        estatus_filter = st.multiselect("Estatus de servicio", options=estatus)

    with col2:
        clientes_filter = st.multiselect("Cliente", options=clientes)
        sucursal_filter = st.multiselect("Sucursal", options=sucursal)

    if len(ruta_filter) == 0:
        ruta_tupla = tuple(rutas)
    else:
        ruta_tupla = tuple(ruta_filter)

    if len(estatus_filter) == 0:
        estatus_tupla = tuple(estatus)
    else:
        estatus_tupla = tuple(estatus_filter)

    if len(sucursal_filter) == 0:
        sucursal_tupla = tuple(sucursal)
    else:
        sucursal_tupla = tuple(sucursal_filter)

    if len(clientes_filter) == 0:
        clientes_tupla = tuple(clientes)
    else:
        clientes_tupla = tuple(clientes_filter)

    format_tuple = lambda t : ", ".join([f"'{v}'" for v in t])
    q1 = f""" 
        select *
        from data
        where ruta_chofer in ({format_tuple(ruta_tupla)}) and cliente in ({format_tuple(clientes_tupla)}) and estatus in ({format_tuple(estatus_tupla)}) and sucursal in ({format_tuple(sucursal_tupla)})
        """
    data_filtered = sqldf(q1)


    mode = st.selectbox(
        "Modo de calendario:",
        (
            "Vista por dia y semana",
            "Vista de lista",
            "Vista Mensual",
        )
    )

    st.markdown('Significado de colores: <span style="color:#2ECC71;"> Completado </span>,  <span style="color:#F1C40F;"> Pendiente </span>,  <span style="color:#E67E22;"> Servicio con incidencia</span>,  <span style="color:#E74C3C;"> Servicio Cancelado </span>',
        unsafe_allow_html=True
    )
    calendar_options = {
        "editable": "false",
        "locale": "es",
        "firstDay": 1
    }

    if mode == "Vista por dia y semana":
        calendar_options = {
            "editable": "false",
            "headerToolbar": {
                "left": "today prev,next",
                "center": "title",
                "right": "dayGridDay,dayGridWeek",
            },
            "navLinks": "true",
            "initialDate": str(now),
            "initialView": "dayGridWeek",
            "locale": "es",
            "firstDay": 1
                            }
    elif mode == "Vista de lista":
        calendar_options = {
            "editable": "false",
            "navLinks": "false",
            "initialDate": str(now),
            "initialView": "listDay",
            "locale": "es",
            "firstDay": 1

        }
    elif mode == "Vista Mensual":
        calendar_options = {
            "editable": "false",
            "navLinks": "true",
            "initialView": "multiMonthYear",
            "locale": "es",
            "firstDay": 1
        }

    data_json = json.loads(data_filtered.to_json(orient='records', date_format='iso'))

    state = calendar(
        events=st.session_state.get("events", data_json),
        options=calendar_options, 
        key=mode
    )

#Show the log of the click
#st.write(state)