import 'package:drift/drift.dart'; import '../database.dart'; class StatisticheDao { final AppDatabase db; StatisticheDao(this.db); Future> 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> 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> 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 clearAll() { return db.delete(db.statisticheVendita).go(); } Future insert(StatisticheVenditaData s) { return db.into(db.statisticheVendita).insert(s); } Future count() async { final rows = await db.select(db.statisticheVendita).get(); return rows.length; } }