Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created March 13, 2020 20:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parzibyte/b9804b00f8c0011673f08cd0fdd23d19 to your computer and use it in GitHub Desktop.
Save parzibyte/b9804b00f8c0011673f08cd0fdd23d19 to your computer and use it in GitHub Desktop.
func consulta(fechaInicio, fechaFin string) ([]EmpleadoConGanancia, error) {
var empleados []EmpleadoConGanancia
bd, err := obtenerBd()
if err != nil {
return empleados, err
}
defer bd.Close()
rows, err := bd.Raw(`select sum(operaciones_de_cortes.precio * bultos_de_cortes.piezas) as ganancia,
empleados.id
from bihorarios
inner join bultos_de_empleados
on bihorarios.id_bulto_de_empleado = bultos_de_empleados.id
inner join operaciones_de_cortes
on operaciones_de_cortes.id = bultos_de_empleados.id_operacion_de_corte
inner join empleados
on bultos_de_empleados.id_empleado = empleados.id
inner join bultos_de_cortes
on bultos_de_cortes.id = bultos_de_empleados.id_bulto_de_corte
where bultos_de_empleados.fecha_terminacion != ''
and bultos_de_empleados.fecha_terminacion >= ?
and bultos_de_empleados.fecha_terminacion <= ?
group by empleados.id;`, fechaInicio, fechaFin).
Rows()
if err != nil {
return empleados, err
}
defer rows.Close()
for rows.Next() {
var e EmpleadoConGanancia
bd.ScanRows(rows, &e)
empleados = append(empleados, e)
}
return empleados, nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment