Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created November 22, 2022 21:18
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/cdce99bddc094a0fc9885ee6918f166e to your computer and use it in GitHub Desktop.
Save parzibyte/cdce99bddc094a0fc9885ee6918f166e to your computer and use it in GitHub Desktop.
func (d *DatosGraficasController) productosMasVendidos(fechaInicio, fechaFin string) []ProductoVendidoParaGrafica {
// Nota: "masVendidosContado" se usa para mezclar tanto los vendidos al contado como apartados, se usa para evitar declarar un temporal
masVendidosApartados := d.productosMasVendidosEnApartados(fechaInicio, fechaFin)
masVendidosContado := d.productosMasVendidosAlContado(fechaInicio, fechaFin)
for _, producto := range masVendidosApartados {
indice := existeProducto(masVendidosContado, producto)
if indice != -1 {
masVendidosContado[indice].VecesVendido += producto.VecesVendido
} else {
masVendidosContado = append(masVendidosContado, producto)
}
}
quicksort(&masVendidosContado, 0, int64(len(masVendidosContado)-1))
if len(masVendidosContado) > LimiteProductosMasVendidos {
return masVendidosContado[:LimiteProductosMasVendidos]
} else {
return masVendidosContado
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment