-
-
Save parzibyte/9504c00ffc4c064579b121b7745c2ef2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func obtenerTotalVendidoEnPeriodoAgrupadoPorMetodoDePago(fechaInicio, fechaFin string) ([]EtiquetaConTotal, error) { | |
diasConTotalVendido := []EtiquetaConTotal{} | |
bd, err := obtenerBD() | |
if err != nil { | |
return diasConTotalVendido, err | |
} | |
defer bd.Close() | |
filas, err := bd.Query(`SELECT | |
strftime("%m", ordenes.fecha_solicitud) AS mes, | |
coalesce(sum(pagos.monto), 0) AS total_vendido | |
FROM | |
pagos | |
INNER JOIN ordenes ON ordenes.id = pagos.id_orden | |
AND ordenes.fecha_solicitud >= ? | |
AND ordenes.fecha_solicitud <= ? | |
GROUP BY | |
mes | |
ORDER BY | |
mes`, fechaInicio, fechaFin) | |
if err != nil { | |
return diasConTotalVendido, err | |
} | |
var diaConTotalVendido EtiquetaConTotal | |
for filas.Next() { | |
err = filas.Scan(&diaConTotalVendido.Etiqueta, &diaConTotalVendido.Total) | |
if err != nil { | |
return diasConTotalVendido, err | |
} | |
diasConTotalVendido = append(diasConTotalVendido, diaConTotalVendido) | |
} | |
return diasConTotalVendido, nil | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment