diff --git a/data/ui/query.tree.ui b/data/ui/query.tree.ui index 37ac7b3..f4d3c22 100644 --- a/data/ui/query.tree.ui +++ b/data/ui/query.tree.ui @@ -78,12 +78,24 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND fixed Tour Name + + + + 0 + + fixed Total Value + + + + 1 + + @@ -106,12 +118,24 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND fixed Tour Name + + + + 0 + + fixed Coordinator Total + + + + 1 + + @@ -134,12 +158,24 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND fixed Tour Name + + + + 0 + + fixed Tourist Total + + + + 1 + + @@ -162,6 +198,12 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND fixed Percentage + + + + 0 + + diff --git a/data/ui/query.window.ui b/data/ui/query.window.ui index c5fcbcf..0c93b5a 100644 --- a/data/ui/query.window.ui +++ b/data/ui/query.window.ui @@ -21,8 +21,8 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND popup True center-on-parent - 640 - 480 + 800 + 600 True sernatur dialog diff --git a/lib/db.vala b/lib/db.vala index ae16558..f871a1c 100644 --- a/lib/db.vala +++ b/lib/db.vala @@ -32,6 +32,9 @@ namespace LibSernatur { CONNECT } + /** + * The errors that can be thrown while doing queries in the database + */ public errordomain DBError { /** * Invalid value diff --git a/lib/db/arrienda.vala b/lib/db/arrienda.vala index f229b45..06fe72c 100644 --- a/lib/db/arrienda.vala +++ b/lib/db/arrienda.vala @@ -57,7 +57,7 @@ namespace LibSernatur { * @param conn The database connection to use * @return Returns a list of Arrienda */ - public static List get_all_arriendas(Database conn) { + public static List get_all_arriendas (Database conn) { var res = conn.exec (" SELECT A.precio, A.fecha_devolucion, V.patente, V.ano_vehiculo, V.marca, V.capacidad, diff --git a/lib/db/asociado.vala b/lib/db/asociado.vala index 1d084f8..06bb25b 100644 --- a/lib/db/asociado.vala +++ b/lib/db/asociado.vala @@ -51,7 +51,7 @@ namespace LibSernatur { * @param conn The database connection to use * @return Returns a list of Asociado */ - public static List get_all_asociados(Database conn) { + public static List get_all_asociados (Database conn) { var res = conn.exec (" SELECT A.fecha_llegada, A.hora_llegada, A.fecha_salida, A.hora_salida T.id_tour, T.nombre_tour, T.costo_indiv, T.costo_grupal, T.minima_personas, diff --git a/lib/db/categoria.vala b/lib/db/categoria.vala index 9ddc4dc..a026d76 100644 --- a/lib/db/categoria.vala +++ b/lib/db/categoria.vala @@ -45,7 +45,7 @@ namespace LibSernatur { * @param conn The database connection to use * @return Returns a list of Categoria */ - public static List get_all_categorias(Database conn) { + public static List get_all_categorias (Database conn) { var res = conn.exec (" SELECT id_categoria, descripcion_categoria FROM categoria "); diff --git a/lib/db/ciudad.vala b/lib/db/ciudad.vala index 5559d69..efa1322 100644 --- a/lib/db/ciudad.vala +++ b/lib/db/ciudad.vala @@ -51,7 +51,7 @@ namespace LibSernatur { * @param conn The database connection to use * @return Returns a list of Ciudad */ - public static List get_all_ciudades(Database conn) { + public static List get_all_ciudades (Database conn) { var res = conn.exec (" SELECT C.id_ciudad, C.nombre_ciudad, R.id_region, R.nombre_region diff --git a/lib/db/contacto_emergencia.vala b/lib/db/contacto_emergencia.vala index 74b3156..a37534c 100644 --- a/lib/db/contacto_emergencia.vala +++ b/lib/db/contacto_emergencia.vala @@ -51,7 +51,7 @@ namespace LibSernatur { * @param conn The database connection to use * @return Returns a list of ContactoEmergencia */ - public static List get_all_contactos(Database conn) { + public static List get_all_contactos (Database conn) { var res = conn.exec ("SELECT id_contacto, telefono_emergencia, nombre_emergencia FROM contacto_emergencia"); if (res.get_status () != ExecStatus.TUPLES_OK) { #if DEBUG diff --git a/lib/db/descuento.vala b/lib/db/descuento.vala index eb83539..0213403 100644 --- a/lib/db/descuento.vala +++ b/lib/db/descuento.vala @@ -51,7 +51,7 @@ namespace LibSernatur { * @param conn The database connection to use * @return Returns a list of Descuento */ - public static List get_all_descuentos(Database conn) { + public static List get_all_descuentos (Database conn) { var res = conn.exec (" SELECT id_descuento, descripcion_descuento, porcentaje FROM descuento "); diff --git a/lib/db/empresa.vala b/lib/db/empresa.vala index 4dc3f6c..3f306c4 100644 --- a/lib/db/empresa.vala +++ b/lib/db/empresa.vala @@ -57,7 +57,7 @@ namespace LibSernatur { * @param conn The database connection to use * @return Returns a list of Empresa */ - public static List get_all_empresas(Database conn) { + public static List get_all_empresas (Database conn) { var res = conn.exec (" SELECT rut_empresa, nombre_empresa, contacto, telefono FROM empresa "); diff --git a/lib/db/enfermedad.vala b/lib/db/enfermedad.vala index a8640ed..b7c9795 100644 --- a/lib/db/enfermedad.vala +++ b/lib/db/enfermedad.vala @@ -45,7 +45,7 @@ namespace LibSernatur { * @param conn The database connection to use * @return Returns a list of Enfermedad */ - public static List get_all_enfermedades(Database conn) { + public static List get_all_enfermedades (Database conn) { var res = conn.exec (" SELECT id_enfermedad, descripcion_enfermedad FROM enfermedad "); diff --git a/lib/db/especialidad.vala b/lib/db/especialidad.vala index 99915d8..1bdb0ea 100644 --- a/lib/db/especialidad.vala +++ b/lib/db/especialidad.vala @@ -45,7 +45,7 @@ namespace LibSernatur { * @param conn The database connection to use * @return Returns a list of Especialidad */ - public static List get_all_especialidades(Database conn) { + public static List get_all_especialidades (Database conn) { var res = conn.exec (" SELECT id_especialidad, descripcion_especialidad FROM especialidad "); diff --git a/lib/db/guia.vala b/lib/db/guia.vala index b93e139..6b2dd05 100644 --- a/lib/db/guia.vala +++ b/lib/db/guia.vala @@ -63,7 +63,7 @@ namespace LibSernatur { * @param conn The database connection to use * @return Returns a list of Guia */ - public static List get_all_guias(Database conn) { + public static List get_all_guias (Database conn) { var res = conn.exec (" SELECT G.rut_guia, G.nombre_guia, G.calle, G.numero, C.id_ciudad, C.nombre_ciudad, diff --git a/lib/db/lugar.vala b/lib/db/lugar.vala index 93288df..c1d1569 100644 --- a/lib/db/lugar.vala +++ b/lib/db/lugar.vala @@ -63,7 +63,7 @@ namespace LibSernatur { * @param conn The database connection to use * @return Returns a list of Lugar */ - public static List get_all_lugares(Database conn) { + public static List get_all_lugares (Database conn) { var res = conn.exec (" SELECT L.id_lugar, L.nombre_lugar, L.valor_entrada, L.nivel, C.id_ciudad, C.nombre_ciudad, diff --git a/lib/db/participa.vala b/lib/db/participa.vala index 8ca6671..ddba6e4 100644 --- a/lib/db/participa.vala +++ b/lib/db/participa.vala @@ -51,7 +51,7 @@ namespace LibSernatur { * @param conn The database connection to use * @return Returns a list of Participa */ - public static List get_all_participas(Database conn) { + public static List get_all_participas (Database conn) { var res = conn.exec (" SELECT T.id_tour, T.nombre_tour, T.costo_indiv, T.costo_grupal, T.minima_personas, C.id_ciudad, C.nombre_ciudad, diff --git a/lib/db/posee.vala b/lib/db/posee.vala index d55e194..975e420 100644 --- a/lib/db/posee.vala +++ b/lib/db/posee.vala @@ -51,7 +51,7 @@ namespace LibSernatur { * @param conn The database connection to use * @return Returns a list of Posee */ - public static List get_all_posees(Database conn) { + public static List get_all_posees (Database conn) { var res = conn.exec (" SELECT P.nivel_especialidad, G.rut_guia, G.nombre_guia, G.calle, G.numero, diff --git a/lib/db/realiza.vala b/lib/db/realiza.vala index c189e8d..166d828 100644 --- a/lib/db/realiza.vala +++ b/lib/db/realiza.vala @@ -51,7 +51,7 @@ namespace LibSernatur { * @param conn The database connection to use * @return Returns a list of Realiza */ - public static List get_all_realizas(Database conn) { + public static List get_all_realizas (Database conn) { var res = conn.exec (" SELECT T.id_tour, T.nombre_tour, T.costo_indiv, T.costo_grupal, T.minima_personas, C.id_ciudad, C.nombre_ciudad, diff --git a/lib/db/region.vala b/lib/db/region.vala index 297880e..90c27e3 100644 --- a/lib/db/region.vala +++ b/lib/db/region.vala @@ -45,7 +45,7 @@ namespace LibSernatur { * @param conn The database connection to use * @return Returns a list of Region */ - public static List get_all_regiones(Database conn) { + public static List get_all_regiones (Database conn) { var res = conn.exec (" SELECT id_region, nombre_region FROM region "); diff --git a/lib/db/regiones_sin_descuento.vala b/lib/db/regiones_sin_descuento.vala index 4a59f14..550c8aa 100644 --- a/lib/db/regiones_sin_descuento.vala +++ b/lib/db/regiones_sin_descuento.vala @@ -18,7 +18,7 @@ namespace LibSernatur { using Wrapper; /** - * The Region class based on the database table + * The RegionesSinDescuento class based on the database table */ public class RegionesSinDescuento : GLib.Object { /** @@ -44,9 +44,9 @@ namespace LibSernatur { * @param conn The database connection to use * @return Returns a list of RegionesSinDescuento */ - public static List get_regions(Database conn) { + public static List get_all_regions_without_discount (Database conn) { var res = conn.exec (" -SELECT nombreRegion, cantidad FROM REGIONES_SINDESCUENTO WHERE (cantidad = (SELECT MAX(cantidad) FROM REGIONES_SINDESCUENTO)) +SELECT nombreRegion, cantidad FROM REGIONES_SINDESCUENTO "); if (res.get_status () != ExecStatus.TUPLES_OK) { #if DEBUG diff --git a/lib/db/requerir_auto.vala b/lib/db/requerir_auto.vala index f3e49e5..64de523 100644 --- a/lib/db/requerir_auto.vala +++ b/lib/db/requerir_auto.vala @@ -51,7 +51,7 @@ namespace LibSernatur { * @param conn The database connection to use * @return Returns a list of RequerirAuto */ - public static List get_all_requerir_autos(Database conn) { + public static List get_all_requerir_autos (Database conn) { var res = conn.exec (" SELECT R.chofer, T.id_tour, T.nombre_tour, T.costo_indiv, T.costo_grupal, T.minima_personas, diff --git a/lib/db/tiene_enfermedad.vala b/lib/db/tiene_enfermedad.vala index dd3e495..517580d 100644 --- a/lib/db/tiene_enfermedad.vala +++ b/lib/db/tiene_enfermedad.vala @@ -45,7 +45,7 @@ namespace LibSernatur { * @param conn The database connection to use * @return Returns a list of TieneEnfermedad */ - public static List get_all_tiene_enfermedades(Database conn) { + public static List get_all_tiene_enfermedades (Database conn) { var res = conn.exec (" SELECT T.rut_turista, T.nombre_turista, T.fecha_nacimento, C.id_contacto, C.telefono_emergencia, C.nombre_emergencia, diff --git a/lib/db/total_arriendos.vala b/lib/db/total_arriendos.vala new file mode 100644 index 0000000..fc67006 --- /dev/null +++ b/lib/db/total_arriendos.vala @@ -0,0 +1,75 @@ +/* + * Copyright 2018-2019 Chris Cromer + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +namespace LibSernatur { + namespace DB { + using Postgres; + using Wrapper; + + /** + * The TotalArriendos class based on the database table + */ + public class TotalArriendos : GLib.Object { + /** + * The total of rented vehicles + */ + public uint total_arriendo { get; set; default = 0; } + + /** + * Initialize the TotalArriendos class + * @param total_arriendo The total of rented vehicles + */ + public TotalArriendos (uint total_arriendo = 0) { + this.total_arriendo = total_arriendo; + } + + /** + * Get all tuples and fields from database + * @param conn The database connection to use + * @return Returns a list of TotalArriendos + */ + public static List get_all_rent_totals (Database conn) { + var res = conn.exec (" +SELECT TotalArriendo FROM TOTAL_ARRIENDOS + "); + if (res.get_status () != ExecStatus.TUPLES_OK) { + #if DEBUG + error (conn.get_error_message ()); + #else + warning (conn.get_error_message ()); + return new List (); + #endif + } + + var wra = new ResultWrapper (res); + List list = new List (); + int n = res.get_n_tuples (); + for (int i = 0; i < n; i++) { + try { + var total = new TotalArriendos (wra.get_int_n (i, "TotalArriendo")); + list.append (total); + } + catch (Error e) { + #if DEBUG + error (e.message); + #else + warning (e.message); + #endif + } + } + return list; + } + } + } +} diff --git a/lib/db/total_coordinadores.vala b/lib/db/total_coordinadores.vala new file mode 100644 index 0000000..c187a3b --- /dev/null +++ b/lib/db/total_coordinadores.vala @@ -0,0 +1,90 @@ +/* + * Copyright 2018-2019 Chris Cromer + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +namespace LibSernatur { + namespace DB { + using Postgres; + using Wrapper; + + /** + * The TotalCoordinadores class based on the database table + */ + public class TotalCoordinadores : GLib.Object { + /** + * The id of the region + */ + public uint id_tour { get; set; default = 0; } + /** + * The name of the region + */ + public string nombre_tour { get; set; default = ""; } + /** + * The total number of coordinators + */ + public uint total_coordinadores { get; set; default = 0; } + + /** + * Initialize the TotalCoordinadores class + * @param id_tour The tour id + * @param nombre_tour The tour name + * @param total_coordinadores The total number of coordinators + */ + public TotalCoordinadores (uint id_tour = 0, string nombre_tour = "", uint total_coordinadores = 0) { + this.id_tour = id_tour; + this.nombre_tour = nombre_tour; + this.total_coordinadores = total_coordinadores; + } + + /** + * Get all tuples and fields from database + * @param conn The database connection to use + * @return Returns a list of TotalCoordinadores + */ + public static List get_all_coordinator_totals (Database conn) { + var res = conn.exec (" +SELECT idT, nombreT, TotalCoordinadores FROM TOTAL_COORDINADORES + "); + if (res.get_status () != ExecStatus.TUPLES_OK) { + #if DEBUG + error (conn.get_error_message ()); + #else + warning (conn.get_error_message ()); + return new List (); + #endif + } + + var wra = new ResultWrapper (res); + List list = new List (); + int n = res.get_n_tuples (); + for (int i = 0; i < n; i++) { + try { + var total = new TotalCoordinadores (wra.get_int_n (i, "idT"), + wra.get_string_n (i, "nombreT"), + wra.get_int_n (i, "TotalCoordinadores") + ); + list.append (total); + } + catch (Error e) { + #if DEBUG + error (e.message); + #else + warning (e.message); + #endif + } + } + return list; + } + } + } +} diff --git a/lib/db/total_turistas.vala b/lib/db/total_turistas.vala new file mode 100644 index 0000000..0f31600 --- /dev/null +++ b/lib/db/total_turistas.vala @@ -0,0 +1,90 @@ +/* + * Copyright 2018-2019 Chris Cromer + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +namespace LibSernatur { + namespace DB { + using Postgres; + using Wrapper; + + /** + * The TotalTuristas class based on the database table + */ + public class TotalTuristas : GLib.Object { + /** + * The id of the tour + */ + public uint id_tour { get; set; default = 0; } + /** + * The name of the tour + */ + public string nombre_tour { get; set; default = ""; } + /** + * The total number of tourists + */ + public uint total_turistas { get; set; default = 0; } + + /** + * Initialize the TotalTuristas class + * @param id_tour The tour id + * @param nombre_tour The tour name + * @param total_turistas The number of tourists + */ + public TotalTuristas (uint id_tour = 0, string nombre_tour = "", uint total_turistas = 0) { + this.id_tour = id_tour; + this.nombre_tour = nombre_tour; + this.total_turistas = total_turistas; + } + + /** + * Get all tuples and fields from database + * @param conn The database connection to use + * @return Returns a list of TotalTuristas + */ + public static List get_all_tourist_totals (Database conn) { + var res = conn.exec (" +SELECT idT, nombreT, TotalTuristas FROM TOTAL_TURISTAS + "); + if (res.get_status () != ExecStatus.TUPLES_OK) { + #if DEBUG + error (conn.get_error_message ()); + #else + warning (conn.get_error_message ()); + return new List (); + #endif + } + + var wra = new ResultWrapper (res); + List list = new List (); + int n = res.get_n_tuples (); + for (int i = 0; i < n; i++) { + try { + var total = new TotalTuristas (wra.get_int_n (i, "idT"), + wra.get_string_n (i, "nombreT"), + wra.get_int_n (i, "TotalTuristas") + ); + list.append (total); + } + catch (Error e) { + #if DEBUG + error (e.message); + #else + warning (e.message); + #endif + } + } + return list; + } + } + } +} diff --git a/lib/db/total_vehiculos.vala b/lib/db/total_vehiculos.vala new file mode 100644 index 0000000..483b539 --- /dev/null +++ b/lib/db/total_vehiculos.vala @@ -0,0 +1,75 @@ +/* + * Copyright 2018-2019 Chris Cromer + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +namespace LibSernatur { + namespace DB { + using Postgres; + using Wrapper; + + /** + * The TotalVehiculos class based on the database table + */ + public class TotalVehiculos : GLib.Object { + /** + * The total of vehicles + */ + public uint total_veh { get; set; default = 0; } + + /** + * Initialize the TotalVehiculos class + * @param total_veh The total of vehicles + */ + public TotalVehiculos (uint total_veh = 0) { + this.total_veh = total_veh; + } + + /** + * Get all tuples and fields from database + * @param conn The database connection to use + * @return Returns a list of TotalVehiculos + */ + public static List get_all_vehicle_totals (Database conn) { + var res = conn.exec (" +SELECT TotalVeh FROM TOTAL_VEHICULOS + "); + if (res.get_status () != ExecStatus.TUPLES_OK) { + #if DEBUG + error (conn.get_error_message ()); + #else + warning (conn.get_error_message ()); + return new List (); + #endif + } + + var wra = new ResultWrapper (res); + List list = new List (); + int n = res.get_n_tuples (); + for (int i = 0; i < n; i++) { + try { + var total = new TotalVehiculos (wra.get_int_n (i, "TotalVeh")); + list.append (total); + } + catch (Error e) { + #if DEBUG + error (e.message); + #else + warning (e.message); + #endif + } + } + return list; + } + } + } +} diff --git a/lib/db/tour.vala b/lib/db/tour.vala index 354ef1c..9f1aa5f 100644 --- a/lib/db/tour.vala +++ b/lib/db/tour.vala @@ -69,7 +69,7 @@ namespace LibSernatur { * @param conn The database connection to use * @return Returns a list of Tour */ - public static List get_all_tours(Database conn) { + public static List get_all_tours (Database conn) { var res = conn.exec (Query.get_query (Query.Type.SELECT_ALL_TOURS, null)); if (res.get_status () != ExecStatus.TUPLES_OK) { #if DEBUG @@ -112,8 +112,8 @@ namespace LibSernatur { /** * Update a tour in the database + * @param conn The database connection * @param tour The tour to update - * @return Returns true if updated * @throws DBError Thrown if the data in the object is invalid */ public static void update_tour (Database conn, Tour tour) throws DBError { diff --git a/lib/db/turista.vala b/lib/db/turista.vala index b4b0a78..995e880 100644 --- a/lib/db/turista.vala +++ b/lib/db/turista.vala @@ -52,13 +52,12 @@ namespace LibSernatur { this.contacto_emergencia = contacto_emergencia; } - /** * Get all tuples and fields from database * @param conn The database connection to use * @return Returns a list of Turista */ - public static List get_all_turistas(Database conn) { + public static List get_all_turistas (Database conn) { var res = conn.exec (" SELECT T.rut_turista, T.nombre_turista, T.fecha_nacimento, C.id_contacto, C.telefono_emergencia, C.nombre_emergencia diff --git a/lib/db/valores_tours.vala b/lib/db/valores_tours.vala new file mode 100644 index 0000000..10436b7 --- /dev/null +++ b/lib/db/valores_tours.vala @@ -0,0 +1,90 @@ +/* + * Copyright 2018-2019 Chris Cromer + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +namespace LibSernatur { + namespace DB { + using Postgres; + using Wrapper; + + /** + * The ValoresTours class based on the database table + */ + public class ValoresTours : GLib.Object { + /** + * The id of the tour + */ + public uint id_tour { get; set; default = 0; } + /** + * The name of the tour + */ + public string nombre_tour { get; set; default = ""; } + /** + * The total sales value + */ + public uint total_ventas { get; set; default = 0; } + + /** + * Initialize the ValoresTours class + * @param id_tour The tour id + * @param nombre_tour The tour name + * @param total_ventas The sales total + */ + public ValoresTours (uint id_tour = 0, string nombre_tour = "", uint total_ventas = 0) { + this.id_tour = id_tour; + this.nombre_tour = nombre_tour; + this.total_ventas = total_ventas; + } + + /** + * Get all tuples and fields from database + * @param conn The database connection to use + * @return Returns a list of ValoresTours + */ + public static List get_all_tour_sales (Database conn) { + var res = conn.exec (" +SELECT idT, nombreT, TotalVentas FROM VALORES_TOURS + "); + if (res.get_status () != ExecStatus.TUPLES_OK) { + #if DEBUG + error (conn.get_error_message ()); + #else + warning (conn.get_error_message ()); + return new List (); + #endif + } + + var wra = new ResultWrapper (res); + List list = new List (); + int n = res.get_n_tuples (); + for (int i = 0; i < n; i++) { + try { + var tour_value = new ValoresTours (wra.get_int_n (i, "idT"), + wra.get_string_n (i, "nombreT"), + wra.get_int_n (i, "TotalVentas") + ); + list.append (tour_value); + } + catch (Error e) { + #if DEBUG + error (e.message); + #else + warning (e.message); + #endif + } + } + return list; + } + } + } +} diff --git a/lib/db/vehiculo.vala b/lib/db/vehiculo.vala index 6d98151..e57f3a9 100644 --- a/lib/db/vehiculo.vala +++ b/lib/db/vehiculo.vala @@ -57,7 +57,7 @@ namespace LibSernatur { * @param conn The database connection to use * @return Returns a list of Vehiculo */ - public static List get_all_vehiculos(Database conn) { + public static List get_all_vehiculos (Database conn) { var res = conn.exec (" SELECT patente, ano_vehiculo, marca, capacidad FROM vehiculo "); diff --git a/lib/db/views.vala b/lib/db/views.vala new file mode 100644 index 0000000..30730af --- /dev/null +++ b/lib/db/views.vala @@ -0,0 +1,281 @@ +/* + * Copyright 2018-2019 Chris Cromer + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +namespace LibSernatur { + namespace DB { + /** + * The views namespace for the 5 views + */ + namespace Views { + using Postgres; + using Wrapper; + + /** + * The Q1 class based on the database table + */ + public class Q1 : GLib.Object { + /** + * Get all tuples and fields from database + * @param conn The database connection to use + * @return Returns a list of RegionesSinDescuento + */ + public static List get_regions_without_discount (Database conn) { + var res = conn.exec (" +SELECT nombreRegion, cantidad FROM REGIONES_SINDESCUENTO WHERE (cantidad = (SELECT MAX(cantidad) FROM REGIONES_SINDESCUENTO)) + "); + if (res.get_status () != ExecStatus.TUPLES_OK) { + #if DEBUG + error (conn.get_error_message ()); + #else + warning (conn.get_error_message ()); + return new List (); + #endif + } + + var wra = new ResultWrapper (res); + List list = new List (); + int n = res.get_n_tuples (); + for (int i = 0; i < n; i++) { + try { + var region_sin_descuento = new RegionesSinDescuento (wra.get_string_n (i, "nombreRegion"), + wra.get_int_n (i, "cantidad") + ); + list.append (region_sin_descuento); + } + catch (Error e) { + #if DEBUG + error (e.message); + #else + warning (e.message); + #endif + } + } + return list; + } + } + + /** + * The Q2 class based on the database table + */ + public class Q2 : GLib.Object { + /** + * The name of the tour + */ + public string nombre_tour { get; set; default = ""; } + /** + * The value received + */ + public uint valor_recibido { get; set; default = 0; } + + /** + * Initialize the Q2 class + * @param nombre_tour The name of the tour + * @param valor_recibido The money value received + */ + public Q2 (string nombre_tour = "", uint valor_recibido = 0) { + this.nombre_tour = nombre_tour; + this.valor_recibido = valor_recibido; + } + + /** + * Get all tuples and fields from database + * @param conn The database connection to use + * @return Returns a list of Q2 + */ + public static List get_value_received (Database conn) { + var res = conn.exec (" +SELECT V.nombreT, (V.TotalVentas - COALESCE(MAX(T.TotalDescuentos), 0)) AS ValorTotalRecibido +FROM VALORES_TOURS V FULL JOIN TOUR_DESCUENTOS T ON (T.idT = V.idT) GROUP BY (V.nombreT, V.TotalVentas) + "); + if (res.get_status () != ExecStatus.TUPLES_OK) { + #if DEBUG + error (conn.get_error_message ()); + #else + warning (conn.get_error_message ()); + return new List (); + #endif + } + + var wra = new ResultWrapper (res); + List list = new List (); + int n = res.get_n_tuples (); + for (int i = 0; i < n; i++) { + try { + var values = new Q2 (wra.get_string_n (i, "nombreT"), + wra.get_int_n (i, "ValorTotalRecibido") + ); + list.append (values); + } + catch (Error e) { + #if DEBUG + error (e.message); + #else + warning (e.message); + #endif + } + } + return list; + } + } + + /** + * The Q3 class based on the database table + */ + public class Q3 : GLib.Object { + /** + * Get all tuples and fields from database + * @param conn The database connection to use + * @return Returns a list of TotalCoordinadores + */ + public static List get_total_coordinators (Database conn) { + var res = conn.exec (" +SELECT nombreT, TotalCoordinadores +FROM TOTAL_COORDINADORES WHERE (TotalCoordinadores = (SELECT MAX(TotalCoordinadores) FROM TOTAL_COORDINADORES)) + "); + if (res.get_status () != ExecStatus.TUPLES_OK) { + #if DEBUG + error (conn.get_error_message ()); + #else + warning (conn.get_error_message ()); + return new List (); + #endif + } + + var wra = new ResultWrapper (res); + List list = new List (); + int n = res.get_n_tuples (); + for (int i = 0; i < n; i++) { + try { + var total = new TotalCoordinadores (0, + wra.get_string_n (i, "nombreT"), + wra.get_int_n (i, "TotalCoordinadores") + ); + list.append (total); + } + catch (Error e) { + #if DEBUG + error (e.message); + #else + warning (e.message); + #endif + } + } + return list; + } + } + + /** + * The Q4 class based on the database table + */ + public class Q4 : GLib.Object { + /** + * Get all tuples and fields from database + * @param conn The database connection to use + * @return Returns a list of TotalTuristas + */ + public static List get_total_tourists (Database conn) { + var res = conn.exec (" +SELECT nombreT, TotalTuristas FROM TOTAL_TURISTAS WHERE (TotalTuristas = (SELECT MAX(TotalTuristas) FROM TOTAL_TURISTAS)) + "); + if (res.get_status () != ExecStatus.TUPLES_OK) { + #if DEBUG + error (conn.get_error_message ()); + #else + warning (conn.get_error_message ()); + return new List (); + #endif + } + + var wra = new ResultWrapper (res); + List list = new List (); + int n = res.get_n_tuples (); + for (int i = 0; i < n; i++) { + try { + var total = new TotalTuristas (0, + wra.get_string_n (i, "nombreT"), + wra.get_int_n (i, "TotalTuristas") + ); + list.append (total); + } + catch (Error e) { + #if DEBUG + error (e.message); + #else + warning (e.message); + #endif + } + } + return list; + } + } + + /** + * The Q5 class based on the database table + */ + public class Q5 : GLib.Object { + /** + * The percentage of cars that were rented and used + */ + public float porcentaje { get; set; default = 0; } + + /** + * Initialize the Q5 class + * @param porcentaje The percentage of cars that were rented and used + */ + public Q5 (float porcentaje = 0) { + this.porcentaje = porcentaje; + } + + /** + * Get all tuples and fields from database + * @param conn The database connection to use + * @return Returns a list of Q5 + */ + public static List get_percentage (Database conn) { + var res = conn.exec (" +SELECT + (cast(T1.totalarriendo AS DECIMAL(3,2)) / cast(T2.totalveh AS DECIMAL(3,2))) AS porcentaje +FROM total_arriendos AS T1, total_vehiculos AS T2 + "); + if (res.get_status () != ExecStatus.TUPLES_OK) { + #if DEBUG + error (conn.get_error_message ()); + #else + warning (conn.get_error_message ()); + return new List (); + #endif + } + + var wra = new ResultWrapper (res); + List list = new List (); + int n = res.get_n_tuples (); + for (int i = 0; i < n; i++) { + try { + var percentage = new Q5 (wra.get_float_n (i, "porcentaje")); + list.append (percentage); + } + catch (Error e) { + #if DEBUG + error (e.message); + #else + warning (e.message); + #endif + } + } + return list; + } + } + } + } +} diff --git a/lib/meson.build b/lib/meson.build index ac5f330..a707a33 100644 --- a/lib/meson.build +++ b/lib/meson.build @@ -25,9 +25,15 @@ lib_sources = files( 'db/regiones_sin_descuento.vala', 'db/requerir_auto.vala', 'db/tiene_enfermedad.vala', + 'db/total_arriendos.vala', + 'db/total_coordinadores.vala', + 'db/total_turistas.vala', + 'db/total_vehiculos.vala', 'db/tour.vala', 'db/turista.vala', - 'db/vehiculo.vala') + 'db/valores_tours.vala', + 'db/vehiculo.vala', + 'db/views.vala') vala_args = ['--vapidir=' + join_paths(meson.source_root(), 'vapi')] diff --git a/lib/misc.vala b/lib/misc.vala index 8d8c34b..1772b5b 100644 --- a/lib/misc.vala +++ b/lib/misc.vala @@ -14,7 +14,7 @@ namespace LibSernatur { /** - * The person name space + * The misc name space */ namespace Misc { @@ -36,8 +36,39 @@ namespace LibSernatur { INVALIDVERIFIER } + /** + * This class converts a float or double into a percentage string + */ + public class Percentage : GLib.Object { + /** + * Format a float into a percentage string + * @param value The value to convert + * @return Returns a string of the percentage + */ + public static string format_float (float value) { + return (value * 100).to_string () + "%"; + } + + /** + * Format a double into a percentage string + * @param value The value to convert + * @return Returns a string of the percentage + */ + public static string format_double (double value) { + return (value * 100).to_string () + "%"; + } + } + + /** + * This class handles making money look pretty + */ public class Money : GLib.Object { - public static string format_int (uint value) { + /** + * Format an int to look pretty + * @param value The value to format + * @return Returns a pretty string + */ + public static string format_int (int value) { string money = ""; string temp_money = value.to_string ().reverse (); int money_length = temp_money.length; @@ -53,6 +84,11 @@ namespace LibSernatur { return "$" + money; } + /** + * Format a uint to look pretty + * @param value The value to format + * @return Returns a pretty string + */ public static string format_uint (uint value) { string money = ""; string temp_money = value.to_string ().reverse (); @@ -69,6 +105,11 @@ namespace LibSernatur { return "$" + money; } + /** + * Format a string to look pretty + * @param value The value to format + * @return Returns a pretty string + */ public static string format_string (string value) { string money = ""; string temp_money = value.reverse (); diff --git a/po/POTFILES b/po/POTFILES index 6b7849f..dceb23c 100644 --- a/po/POTFILES +++ b/po/POTFILES @@ -1,27 +1,6 @@ lib/db.vala lib/dbwrapper.vala lib/misc.vala -#lib/db/arrienda.vala -#lib/db/asociado.vala -#lib/db/categoria.vala -#lib/db/ciudad.vala -#lib/db/contacto_emergencia.vala -#lib/db/descuento.vala -#lib/db/empresa.vala -#lib/db/enfermedad.vala -#lib/db/especialidad.vala -#lib/db/guia.vala -#lib/db/lugar.vala -#lib/db/participa.vala -#lib/db/posee.vala -#lib/db/realiza.vala -#lib/db/region.vala -#lib/db/regiones_sin_descuento.vala -#lib/db/requerir_auto.vala -#lib/db/tiene_enfermedad.vala -#lib/db/tour.vala -#lib/db/turista.vala -#lib/db/vehiculo.vala src/sernatur.vala src/main_window.vala src/tour_list.vala diff --git a/po/es.po b/po/es.po index 738d138..1bb533f 100644 --- a/po/es.po +++ b/po/es.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: sernatur\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-01-14 11:35-0300\n" +"POT-Creation-Date: 2019-01-15 13:12-0300\n" "PO-Revision-Date: 2019-01-14 11:37-0300\n" "Last-Translator: Chris Cromer \n" "Language-Team: none\n" @@ -20,7 +20,7 @@ msgstr "" "X-Poedit-SourceCharset: UTF-8\n" "X-Poedit-Basepath: .\n" -#: lib/db.vala:67 +#: lib/db.vala:70 msgid "Postgresql server version:" msgstr "Versión del servidor Postgresql:" @@ -29,17 +29,17 @@ msgstr "Versión del servidor Postgresql:" msgid "The field %s was not found in the query results!" msgstr "La campo %s no estaba en los resultados de la consulta!" -#: lib/misc.vala:138 +#: lib/misc.vala:179 #, c-format msgid "The RUT %s has an invalid character!" msgstr "El RUT %s tiene un carácter invalido!" -#: lib/misc.vala:154 +#: lib/misc.vala:195 #, c-format msgid "The RUT %s is too big!" msgstr "El RUT %s es demasiado grande!" -#: lib/misc.vala:159 +#: lib/misc.vala:200 #, c-format msgid "The verifier %C is invalid!" msgstr "El verificador %C es invalido!" @@ -51,8 +51,7 @@ msgstr "Error %s\n" #: src/sernatur.vala:89 #, c-format -msgid "" -"Run '%s --help' to see a full list of available command line options.\n" +msgid "Run '%s --help' to see a full list of available command line options.\n" msgstr "" "Correr '%s --help' para ver una lista completa de las opciones de la " "consola.\n" @@ -69,23 +68,23 @@ msgstr "Error: No se puede conectar al base de datos!" msgid "Error" msgstr "Error" -#: src/query_window.vala:232 data/ui/main.window.ui:143 +#: src/query_window.vala:290 data/ui/main.window.ui:143 msgid "(Q1) Regions with discounts" msgstr "(Q1) Regiones sin descuentos" -#: src/query_window.vala:245 data/ui/main.window.ui:151 +#: src/query_window.vala:303 data/ui/main.window.ui:151 msgid "(Q2) Tour values" msgstr "(Q2) Valores tour" -#: src/query_window.vala:258 data/ui/main.window.ui:159 +#: src/query_window.vala:316 data/ui/main.window.ui:159 msgid "(Q3) Coordinator total" msgstr "(Q3) Total de coordinadores" -#: src/query_window.vala:271 data/ui/main.window.ui:167 +#: src/query_window.vala:329 data/ui/main.window.ui:167 msgid "(Q4) Tourist total" msgstr "(Q4) Total de turistas" -#: src/query_window.vala:284 data/ui/main.window.ui:175 +#: src/query_window.vala:342 data/ui/main.window.ui:175 msgid "(Q5) Vehicle total" msgstr "(Q5) Total de vehículos" @@ -134,7 +133,7 @@ msgid "Christopher Cromer" msgstr "Christopher Cromer" #: data/ui/tour.list.ui:68 data/ui/tour.editor.ui:54 data/ui/query.tree.ui:80 -#: data/ui/query.tree.ui:108 data/ui/query.tree.ui:136 +#: data/ui/query.tree.ui:120 data/ui/query.tree.ui:160 msgid "Tour Name" msgstr "Nombre del Tour" @@ -234,19 +233,19 @@ msgstr "Nombre de Región" msgid "Quantity" msgstr "Cantidad" -#: data/ui/query.tree.ui:86 +#: data/ui/query.tree.ui:92 msgid "Total Value" msgstr "Valor Total" -#: data/ui/query.tree.ui:114 +#: data/ui/query.tree.ui:132 msgid "Coordinator Total" msgstr "Total de Coordinadores" -#: data/ui/query.tree.ui:142 +#: data/ui/query.tree.ui:172 msgid "Tourist Total" msgstr "Total de Turistas" -#: data/ui/query.tree.ui:164 +#: data/ui/query.tree.ui:200 msgid "Percentage" msgstr "Porcentaje" diff --git a/po/sernatur.pot b/po/sernatur.pot index 2910456..41aa8b8 100644 --- a/po/sernatur.pot +++ b/po/sernatur.pot @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: sernatur\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-01-14 11:35-0300\n" +"POT-Creation-Date: 2019-01-15 13:12-0300\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -17,7 +17,7 @@ msgstr "" "Content-Type: text/plain; charset=CHARSET\n" "Content-Transfer-Encoding: 8bit\n" -#: lib/db.vala:67 +#: lib/db.vala:70 msgid "Postgresql server version:" msgstr "" @@ -26,17 +26,17 @@ msgstr "" msgid "The field %s was not found in the query results!" msgstr "" -#: lib/misc.vala:138 +#: lib/misc.vala:179 #, c-format msgid "The RUT %s has an invalid character!" msgstr "" -#: lib/misc.vala:154 +#: lib/misc.vala:195 #, c-format msgid "The RUT %s is too big!" msgstr "" -#: lib/misc.vala:159 +#: lib/misc.vala:200 #, c-format msgid "The verifier %C is invalid!" msgstr "" @@ -63,23 +63,23 @@ msgstr "" msgid "Error" msgstr "" -#: src/query_window.vala:232 data/ui/main.window.ui:143 +#: src/query_window.vala:290 data/ui/main.window.ui:143 msgid "(Q1) Regions with discounts" msgstr "" -#: src/query_window.vala:245 data/ui/main.window.ui:151 +#: src/query_window.vala:303 data/ui/main.window.ui:151 msgid "(Q2) Tour values" msgstr "" -#: src/query_window.vala:258 data/ui/main.window.ui:159 +#: src/query_window.vala:316 data/ui/main.window.ui:159 msgid "(Q3) Coordinator total" msgstr "" -#: src/query_window.vala:271 data/ui/main.window.ui:167 +#: src/query_window.vala:329 data/ui/main.window.ui:167 msgid "(Q4) Tourist total" msgstr "" -#: src/query_window.vala:284 data/ui/main.window.ui:175 +#: src/query_window.vala:342 data/ui/main.window.ui:175 msgid "(Q5) Vehicle total" msgstr "" @@ -128,7 +128,7 @@ msgid "Christopher Cromer" msgstr "" #: data/ui/tour.list.ui:68 data/ui/tour.editor.ui:54 data/ui/query.tree.ui:80 -#: data/ui/query.tree.ui:108 data/ui/query.tree.ui:136 +#: data/ui/query.tree.ui:120 data/ui/query.tree.ui:160 msgid "Tour Name" msgstr "" @@ -228,19 +228,19 @@ msgstr "" msgid "Quantity" msgstr "" -#: data/ui/query.tree.ui:86 +#: data/ui/query.tree.ui:92 msgid "Total Value" msgstr "" -#: data/ui/query.tree.ui:114 +#: data/ui/query.tree.ui:132 msgid "Coordinator Total" msgstr "" -#: data/ui/query.tree.ui:142 +#: data/ui/query.tree.ui:172 msgid "Tourist Total" msgstr "" -#: data/ui/query.tree.ui:164 +#: data/ui/query.tree.ui:200 msgid "Percentage" msgstr "" diff --git a/src/queries.vala b/src/queries.vala index aa1b2c8..8d2b227 100644 --- a/src/queries.vala +++ b/src/queries.vala @@ -39,34 +39,123 @@ namespace Sernatur { */ public const string Q1_SQL = "CREATE VIEW REGIONES_SINDESCUENTO(nombreRegion, cantidad) AS ( - SELECT nombre_region, COUNT(R2.rut_turista) FROM region R - JOIN ciudad C ON (C.id_region = R.id_region) JOIN tour T ON (T.id_ciudad = C.id_ciudad) - JOIN realiza R2 ON (R2.id_tour = T.id_tour) - WHERE ( - EXISTS(SELECT fecha_llegada - FROM asociado - WHERE (id_tour = T.id_tour AND fecha_llegada BETWEEN '2018-11-01' AND '2018-11-30') - ) AND - R2.id_descuento = 2 - ) - GROUP BY (R.nombre_region) + SELECT nombre_region, COUNT(R2.rut_turista) FROM region R + JOIN ciudad C ON (C.id_region = R.id_region) JOIN tour T ON (T.id_ciudad = C.id_ciudad) + JOIN realiza R2 ON (R2.id_tour = T.id_tour) + WHERE ( + EXISTS(SELECT fecha_llegada + FROM asociado + WHERE (id_tour = T.id_tour AND fecha_llegada BETWEEN '2018-11-01' AND '2018-11-30') + ) AND + R2.id_descuento = 2 + ) + GROUP BY (R.nombre_region) ); SELECT nombreRegion, cantidad FROM REGIONES_SINDESCUENTO WHERE (cantidad = (SELECT MAX(cantidad) FROM REGIONES_SINDESCUENTO));"; /** * The Q2 SQL */ - public const string Q2_SQL = ""; + public const string Q2_SQL = "CREATE VIEW VALORES_TOURS(idT, nombreT, TotalVentas) +AS ( + SELECT T.id_tour, T.nombre_tour, + ((CASE + WHEN T.minima_personas <= (SELECT COUNT(rut_turista) FROM realiza WHERE (id_tour = T.id_tour)) + THEN (SELECT costo_grupal FROM tour WHERE (id_tour = T.id_tour)) + ELSE (SELECT costo_indiv FROM tour WHERE (id_tour = T.id_tour)) + END) * COUNT(rut_turista)) AS cantidad + FROM tour T + JOIN realiza R ON (T.id_tour = R.id_tour) + GROUP BY (T.id_tour) +); + +CREATE VIEW TOUR_DESCUENTOS(idT, nombreT, TotalDescuentos) +AS ( + SELECT T.id_tour, T.nombre_tour, + SUM(DISTINCT (SELECT porcentaje FROM descuento WHERE (id_descuento = R.id_descuento)) * + (SELECT COUNT(rut_turista) FROM realiza WHERE (id_tour = R.id_tour AND id_descuento = R.id_descuento)) * + (CASE + WHEN T.minima_personas <= (SELECT COUNT(rut_turista) FROM realiza WHERE (id_tour = T.id_tour)) + THEN (SELECT costo_grupal FROM tour WHERE (id_tour = T.id_tour)) + ELSE (SELECT costo_indiv FROM tour WHERE (id_tour = T.id_tour)) + END)) AS test + FROM tour T + JOIN realiza R ON (T.id_tour = R.id_tour) + WHERE (R.id_descuento != 2) + GROUP BY (T.id_tour) +); + +SELECT V.nombreT, (V.TotalVentas - COALESCE(MAX(T.TotalDescuentos), 0)) AS ValorTotalRecibido +FROM VALORES_TOURS V FULL JOIN TOUR_DESCUENTOS T ON (T.idT = V.idT) GROUP BY (V.nombreT, V.TotalVentas);"; /** * The Q3 SQL */ - public const string Q3_SQL = ""; + public const string Q3_SQL = "CREATE VIEW TOTAL_COORDINADORES(idT, nombreT, TotalCoordinadores) +AS ( + SELECT T.id_tour, T.nombre_tour, COUNT(DISTINCT P.rut_guia) + FROM participa P + JOIN tour T ON (T.id_tour = P.id_tour) + JOIN guia G ON (G.rut_guia = P.rut_guia) + JOIN categoria C ON (C.id_categoria = P.id_categoria) + JOIN posee P2 ON (G.rut_guia = P2.rut_guia) + JOIN asociado A ON (A.id_tour = T.id_tour) + JOIN lugar L ON (L.id_lugar = A.id_lugar) + WHERE ( + C.descripcion_categoria = 'Coordinador' AND + EXISTS(SELECT FROM lugar WHERE (id_lugar = L.id_lugar AND L.nivel = 3)) AND + (SELECT COUNT(rut_guia) FROM posee WHERE (rut_guia = G.rut_guia)) > 3 + ) + GROUP BY (T.id_tour) +); + +SELECT nombreT, TotalCoordinadores FROM TOTAL_COORDINADORES WHERE (TotalCoordinadores = (SELECT MAX(TotalCoordinadores) FROM TOTAL_COORDINADORES));"; /** * The Q4 SQL */ - public const string Q4_SQL = ""; + public const string Q4_SQL = "CREATE VIEW TOTAL_TURISTAS(idT, nombreT, TotalTuristas) +AS ( + SELECT T.id_tour, T.nombre_tour, COUNT(R.rut_turista) + FROM tour T + JOIN realiza R ON (T.id_tour = R.id_tour) + JOIN asociado A ON (T.id_tour = A.id_tour) + JOIN lugar L ON (A.id_lugar = L.id_lugar) + WHERE ( + EXISTS (SELECT id_lugar FROM lugar WHERE (id_lugar = L.id_lugar AND nivel >= 5)) AND + (A.fecha_llegada BETWEEN '2018-10-01' AND '2018-10-31') AND + NOT EXISTS ( + SELECT id_enfermedad + FROM tiene_enfermedad + WHERE (rut_turista = R.rut_turista AND + (id_enfermedad = 1 OR id_enfermedad = 3) + ) + ) + ) + GROUP BY (T.id_tour) +); + +SELECT nombreT, TotalTuristas FROM TOTAL_TURISTAS WHERE (TotalTuristas = (SELECT MAX(TotalTuristas) FROM TOTAL_TURISTAS));"; /** * The Q5 SQL */ - public const string Q5_SQL = ""; + public const string Q5_SQL = "CREATE VIEW TOTAL_ARRIENDOS(TotalArriendo) +AS (SELECT COUNT(A.patente) + FROM arrienda A + JOIN requerir_auto R ON (R.patente = A.patente) + JOIN tour T ON (T.id_tour = R.id_tour) + JOIN asociado A2 ON (T.id_tour = A2.id_tour) + WHERE (A2.fecha_llegada BETWEEN '2018-01-01' AND '2018-02-28') +); + +CREATE VIEW TOTAL_VEHICULOS(TotalVeh) +AS (SELECT COUNT(V.patente) + FROM vehiculo V + JOIN requerir_auto R ON (R.patente = V.patente) + JOIN tour T ON (T.id_tour = R.id_tour) + JOIN asociado A ON (T.id_tour = A.id_tour) + WHERE (A.fecha_llegada BETWEEN '2018-01-01' AND '2018-02-28') +); + +SELECT + (cast(T1.totalarriendo AS DECIMAL(3,2)) / cast(T2.totalveh AS DECIMAL(3,2))) AS porcentaje +FROM total_arriendos AS T1, total_vehiculos AS T2;"; } } diff --git a/src/query_window.vala b/src/query_window.vala index 3588c63..3d86190 100644 --- a/src/query_window.vala +++ b/src/query_window.vala @@ -30,10 +30,25 @@ namespace Sernatur { * The queries that can be called */ public enum Query { + /** + * The Q1 query + */ Q1, + /** + * The Q2 query + */ Q2, + /** + * The Q3 query + */ Q3, + /** + * The Q4 query + */ Q4, + /** + * The Q5 query + */ Q5 } /** @@ -164,7 +179,7 @@ namespace Sernatur { if (button == run_query) { list_store.clear (); if (query == Query.Q1) { - var region_list = RegionesSinDescuento.get_regions (conn.db); + var region_list = Views.Q1.get_regions_without_discount (conn.db); region_list.foreach ((entry) => { Gtk.TreeIter iter; @@ -174,6 +189,49 @@ namespace Sernatur { Q1Column.QUANTITY, entry.cantidad); }); } + else if (query == Query.Q2) { + var value_list = Views.Q2.get_value_received (conn.db); + + value_list.foreach ((entry) => { + Gtk.TreeIter iter; + list_store.append (out iter); + list_store.set (iter, + Q2Column.TOUR_NAME, entry.nombre_tour, + Q2Column.TOTAL_VALUE, Money.format_uint (entry.valor_recibido)); + }); + } + else if (query == Query.Q3) { + var value_list = Views.Q3.get_total_coordinators (conn.db); + + value_list.foreach ((entry) => { + Gtk.TreeIter iter; + list_store.append (out iter); + list_store.set (iter, + Q3Column.TOUR_NAME, entry.nombre_tour, + Q3Column.COORDINATOR_TOTAL, entry.total_coordinadores); + }); + } + else if (query == Query.Q4) { + var value_list = Views.Q4.get_total_tourists (conn.db); + + value_list.foreach ((entry) => { + Gtk.TreeIter iter; + list_store.append (out iter); + list_store.set (iter, + Q4Column.TOUR_NAME, entry.nombre_tour, + Q4Column.TOURIST_TOTAL, entry.total_turistas); + }); + } + else if (query == Query.Q5) { + var value_list = Views.Q5.get_percentage (conn.db); + + value_list.foreach ((entry) => { + Gtk.TreeIter iter; + list_store.append (out iter); + list_store.set (iter, + Q5Column.PERCENTAGE, Percentage.format_float (entry.porcentaje)); + }); + } } else if (button == close_query) { this.close (); @@ -246,7 +304,7 @@ namespace Sernatur { list_store = new Gtk.ListStore (Q2Column.N_COLUMNS, typeof (string), - typeof (uint)); + typeof (string)); query_tree.set_model (list_store); @@ -284,7 +342,7 @@ namespace Sernatur { this.set_title (dgettext (null, "(Q5) Vehicle total")); list_store = new Gtk.ListStore (Q5Column.N_COLUMNS, - typeof (float)); + typeof (string)); query_tree.set_model (list_store);