| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- import 'package:drift/drift.dart';
- import '../database.dart';
- class StatisticheDao {
- final AppDatabase db;
- StatisticheDao(this.db);
- Future<List<StatisticheVenditaData>> getPerAgente(int idAgente, String da, String a) {
- return (db.select(db.statisticheVendita)
- ..where((t) =>
- t.idAgente.equals(idAgente) &
- t.dataFattura.isNotNull()
- )
- ..orderBy([(t) => OrderingTerm(expression: t.dataFattura)])
- ).get().then((rows) => rows.where((r) {
- final d = r.dataFattura;
- return d != null && d.compareTo(da) >= 0 && d.compareTo(a) <= 0;
- }).toList());
- }
- Future<List<StatisticheVenditaData>> getPerCliente(int idAgente, int idCliente, String da, String a) {
- return (db.select(db.statisticheVendita)
- ..where((t) =>
- t.idAgente.equals(idAgente) &
- t.idCliente.equals(idCliente) &
- t.dataFattura.isNotNull()
- )
- ).get().then((rows) => rows.where((r) {
- final d = r.dataFattura;
- return d != null && d.compareTo(da) >= 0 && d.compareTo(a) <= 0;
- }).toList());
- }
- Future<List<StatisticheVenditaData>> getPerArticolo(int idAgente, int idArticolo, String da, String a) {
- return (db.select(db.statisticheVendita)
- ..where((t) =>
- t.idAgente.equals(idAgente) &
- t.idArticolo.equals(idArticolo) &
- t.dataFattura.isNotNull()
- )
- ).get().then((rows) => rows.where((r) {
- final d = r.dataFattura;
- return d != null && d.compareTo(da) >= 0 && d.compareTo(a) <= 0;
- }).toList());
- }
- Future<void> clearAll() {
- return db.delete(db.statisticheVendita).go();
- }
- Future<int> insert(StatisticheVenditaData s) {
- return db.into(db.statisticheVendita).insert(s);
- }
- Future<int> count() async {
- final rows = await db.select(db.statisticheVendita).get();
- return rows.length;
- }
- }
|