finish queries window

This commit is contained in:
Chris Cromer 2019-01-15 13:12:38 -03:00
parent 0f6ddb8075
commit 24932b6d94
Signed by: cromer
GPG Key ID: 39CC813FF3C8708A
37 changed files with 1018 additions and 101 deletions

View File

@ -78,12 +78,24 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
<object class="GtkTreeViewColumn" id="tour_name_q2">
<property name="sizing">fixed</property>
<property name="title" translatable="yes">Tour Name</property>
<child>
<object class="GtkCellRendererText"/>
<attributes>
<attribute name="markup">0</attribute>
</attributes>
</child>
</object>
</child>
<child>
<object class="GtkTreeViewColumn" id="total_value">
<property name="sizing">fixed</property>
<property name="title" translatable="yes">Total Value</property>
<child>
<object class="GtkCellRendererText"/>
<attributes>
<attribute name="markup">1</attribute>
</attributes>
</child>
</object>
</child>
</object>
@ -106,12 +118,24 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
<object class="GtkTreeViewColumn" id="tour_name_q3">
<property name="sizing">fixed</property>
<property name="title" translatable="yes">Tour Name</property>
<child>
<object class="GtkCellRendererText"/>
<attributes>
<attribute name="markup">0</attribute>
</attributes>
</child>
</object>
</child>
<child>
<object class="GtkTreeViewColumn" id="coordinator_total">
<property name="sizing">fixed</property>
<property name="title" translatable="yes">Coordinator Total</property>
<child>
<object class="GtkCellRendererText"/>
<attributes>
<attribute name="markup">1</attribute>
</attributes>
</child>
</object>
</child>
</object>
@ -134,12 +158,24 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
<object class="GtkTreeViewColumn" id="tour_name_q">
<property name="sizing">fixed</property>
<property name="title" translatable="yes">Tour Name</property>
<child>
<object class="GtkCellRendererText"/>
<attributes>
<attribute name="markup">0</attribute>
</attributes>
</child>
</object>
</child>
<child>
<object class="GtkTreeViewColumn" id="tourist_total">
<property name="sizing">fixed</property>
<property name="title" translatable="yes">Tourist Total</property>
<child>
<object class="GtkCellRendererText"/>
<attributes>
<attribute name="markup">1</attribute>
</attributes>
</child>
</object>
</child>
</object>
@ -162,6 +198,12 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
<object class="GtkTreeViewColumn" id="percentage">
<property name="sizing">fixed</property>
<property name="title" translatable="yes">Percentage</property>
<child>
<object class="GtkCellRendererText"/>
<attributes>
<attribute name="markup">0</attribute>
</attributes>
</child>
</object>
</child>
</object>

View File

@ -21,8 +21,8 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
<property name="type">popup</property>
<property name="modal">True</property>
<property name="window_position">center-on-parent</property>
<property name="default_width">640</property>
<property name="default_height">480</property>
<property name="default_width">800</property>
<property name="default_height">600</property>
<property name="destroy_with_parent">True</property>
<property name="icon_name">sernatur</property>
<property name="type_hint">dialog</property>

View File

@ -32,6 +32,9 @@ namespace LibSernatur {
CONNECT
}
/**
* The errors that can be thrown while doing queries in the database
*/
public errordomain DBError {
/**
* Invalid value

View File

@ -57,7 +57,7 @@ namespace LibSernatur {
* @param conn The database connection to use
* @return Returns a list of Arrienda
*/
public static List<Arrienda> get_all_arriendas(Database conn) {
public static List<Arrienda> get_all_arriendas (Database conn) {
var res = conn.exec ("
SELECT A.precio, A.fecha_devolucion,
V.patente, V.ano_vehiculo, V.marca, V.capacidad,

View File

@ -51,7 +51,7 @@ namespace LibSernatur {
* @param conn The database connection to use
* @return Returns a list of Asociado
*/
public static List<Asociado> get_all_asociados(Database conn) {
public static List<Asociado> 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,

View File

@ -45,7 +45,7 @@ namespace LibSernatur {
* @param conn The database connection to use
* @return Returns a list of Categoria
*/
public static List<Categoria> get_all_categorias(Database conn) {
public static List<Categoria> get_all_categorias (Database conn) {
var res = conn.exec ("
SELECT id_categoria, descripcion_categoria FROM categoria
");

View File

@ -51,7 +51,7 @@ namespace LibSernatur {
* @param conn The database connection to use
* @return Returns a list of Ciudad
*/
public static List<Ciudad> get_all_ciudades(Database conn) {
public static List<Ciudad> get_all_ciudades (Database conn) {
var res = conn.exec ("
SELECT C.id_ciudad, C.nombre_ciudad,
R.id_region, R.nombre_region

View File

@ -51,7 +51,7 @@ namespace LibSernatur {
* @param conn The database connection to use
* @return Returns a list of ContactoEmergencia
*/
public static List<ContactoEmergencia> get_all_contactos(Database conn) {
public static List<ContactoEmergencia> 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

View File

@ -51,7 +51,7 @@ namespace LibSernatur {
* @param conn The database connection to use
* @return Returns a list of Descuento
*/
public static List<Descuento> get_all_descuentos(Database conn) {
public static List<Descuento> get_all_descuentos (Database conn) {
var res = conn.exec ("
SELECT id_descuento, descripcion_descuento, porcentaje FROM descuento
");

View File

@ -57,7 +57,7 @@ namespace LibSernatur {
* @param conn The database connection to use
* @return Returns a list of Empresa
*/
public static List<Empresa> get_all_empresas(Database conn) {
public static List<Empresa> get_all_empresas (Database conn) {
var res = conn.exec ("
SELECT rut_empresa, nombre_empresa, contacto, telefono FROM empresa
");

View File

@ -45,7 +45,7 @@ namespace LibSernatur {
* @param conn The database connection to use
* @return Returns a list of Enfermedad
*/
public static List<Enfermedad> get_all_enfermedades(Database conn) {
public static List<Enfermedad> get_all_enfermedades (Database conn) {
var res = conn.exec ("
SELECT id_enfermedad, descripcion_enfermedad FROM enfermedad
");

View File

@ -45,7 +45,7 @@ namespace LibSernatur {
* @param conn The database connection to use
* @return Returns a list of Especialidad
*/
public static List<Especialidad> get_all_especialidades(Database conn) {
public static List<Especialidad> get_all_especialidades (Database conn) {
var res = conn.exec ("
SELECT id_especialidad, descripcion_especialidad FROM especialidad
");

View File

@ -63,7 +63,7 @@ namespace LibSernatur {
* @param conn The database connection to use
* @return Returns a list of Guia
*/
public static List<Guia> get_all_guias(Database conn) {
public static List<Guia> 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,

View File

@ -63,7 +63,7 @@ namespace LibSernatur {
* @param conn The database connection to use
* @return Returns a list of Lugar
*/
public static List<Lugar> get_all_lugares(Database conn) {
public static List<Lugar> 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,

View File

@ -51,7 +51,7 @@ namespace LibSernatur {
* @param conn The database connection to use
* @return Returns a list of Participa
*/
public static List<Participa> get_all_participas(Database conn) {
public static List<Participa> 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,

View File

@ -51,7 +51,7 @@ namespace LibSernatur {
* @param conn The database connection to use
* @return Returns a list of Posee
*/
public static List<Posee> get_all_posees(Database conn) {
public static List<Posee> get_all_posees (Database conn) {
var res = conn.exec ("
SELECT P.nivel_especialidad,
G.rut_guia, G.nombre_guia, G.calle, G.numero,

View File

@ -51,7 +51,7 @@ namespace LibSernatur {
* @param conn The database connection to use
* @return Returns a list of Realiza
*/
public static List<Realiza> get_all_realizas(Database conn) {
public static List<Realiza> 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,

View File

@ -45,7 +45,7 @@ namespace LibSernatur {
* @param conn The database connection to use
* @return Returns a list of Region
*/
public static List<Region> get_all_regiones(Database conn) {
public static List<Region> get_all_regiones (Database conn) {
var res = conn.exec ("
SELECT id_region, nombre_region FROM region
");

View File

@ -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<RegionesSinDescuento> get_regions(Database conn) {
public static List<RegionesSinDescuento> 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

View File

@ -51,7 +51,7 @@ namespace LibSernatur {
* @param conn The database connection to use
* @return Returns a list of RequerirAuto
*/
public static List<RequerirAuto> get_all_requerir_autos(Database conn) {
public static List<RequerirAuto> 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,

View File

@ -45,7 +45,7 @@ namespace LibSernatur {
* @param conn The database connection to use
* @return Returns a list of TieneEnfermedad
*/
public static List<TieneEnfermedad> get_all_tiene_enfermedades(Database conn) {
public static List<TieneEnfermedad> 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,

View File

@ -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<TotalArriendos> 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<TotalArriendos> ();
#endif
}
var wra = new ResultWrapper (res);
List<TotalArriendos> list = new List<TotalArriendos> ();
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;
}
}
}
}

View File

@ -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<TotalCoordinadores> 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<TotalCoordinadores> ();
#endif
}
var wra = new ResultWrapper (res);
List<TotalCoordinadores> list = new List<TotalCoordinadores> ();
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;
}
}
}
}

View File

@ -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<TotalTuristas> 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<TotalTuristas> ();
#endif
}
var wra = new ResultWrapper (res);
List<TotalTuristas> list = new List<TotalTuristas> ();
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;
}
}
}
}

View File

@ -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<TotalVehiculos> 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<TotalVehiculos> ();
#endif
}
var wra = new ResultWrapper (res);
List<TotalVehiculos> list = new List<TotalVehiculos> ();
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;
}
}
}
}

View File

@ -69,7 +69,7 @@ namespace LibSernatur {
* @param conn The database connection to use
* @return Returns a list of Tour
*/
public static List<Tour> get_all_tours(Database conn) {
public static List<Tour> 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 {

View File

@ -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<Turista> get_all_turistas(Database conn) {
public static List<Turista> 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

90
lib/db/valores_tours.vala Normal file
View File

@ -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<ValoresTours> 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<ValoresTours> ();
#endif
}
var wra = new ResultWrapper (res);
List<ValoresTours> list = new List<ValoresTours> ();
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;
}
}
}
}

View File

@ -57,7 +57,7 @@ namespace LibSernatur {
* @param conn The database connection to use
* @return Returns a list of Vehiculo
*/
public static List<Vehiculo> get_all_vehiculos(Database conn) {
public static List<Vehiculo> get_all_vehiculos (Database conn) {
var res = conn.exec ("
SELECT patente, ano_vehiculo, marca, capacidad FROM vehiculo
");

281
lib/db/views.vala Normal file
View File

@ -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<RegionesSinDescuento> 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<RegionesSinDescuento> ();
#endif
}
var wra = new ResultWrapper (res);
List<RegionesSinDescuento> list = new List<RegionesSinDescuento> ();
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<Q2> 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<Q2> ();
#endif
}
var wra = new ResultWrapper (res);
List<Q2> list = new List<Q2> ();
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<TotalCoordinadores> 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<TotalCoordinadores> ();
#endif
}
var wra = new ResultWrapper (res);
List<TotalCoordinadores> list = new List<TotalCoordinadores> ();
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<TotalTuristas> 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<TotalTuristas> ();
#endif
}
var wra = new ResultWrapper (res);
List<TotalTuristas> list = new List<TotalTuristas> ();
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<Q5> 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<Q5> ();
#endif
}
var wra = new ResultWrapper (res);
List<Q5> list = new List<Q5> ();
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;
}
}
}
}
}

View File

@ -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')]

View File

@ -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 ();

View File

@ -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

View File

@ -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 <chris@cromer.cl>\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"

View File

@ -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 <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\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 ""

View File

@ -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;";
}
}

View File

@ -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);