statistiche_dao.dart 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. import 'package:drift/drift.dart';
  2. import '../database.dart';
  3. class StatisticheDao {
  4. final AppDatabase db;
  5. StatisticheDao(this.db);
  6. Future<List<StatisticheVenditaData>> getPerAgente(int idAgente, String da, String a) {
  7. return (db.select(db.statisticheVendita)
  8. ..where((t) =>
  9. t.idAgente.equals(idAgente) &
  10. t.dataFattura.isNotNull()
  11. )
  12. ..orderBy([(t) => OrderingTerm(expression: t.dataFattura)])
  13. ).get().then((rows) => rows.where((r) {
  14. final d = r.dataFattura;
  15. return d != null && d.compareTo(da) >= 0 && d.compareTo(a) <= 0;
  16. }).toList());
  17. }
  18. Future<List<StatisticheVenditaData>> getPerCliente(int idAgente, int idCliente, String da, String a) {
  19. return (db.select(db.statisticheVendita)
  20. ..where((t) =>
  21. t.idAgente.equals(idAgente) &
  22. t.idCliente.equals(idCliente) &
  23. t.dataFattura.isNotNull()
  24. )
  25. ).get().then((rows) => rows.where((r) {
  26. final d = r.dataFattura;
  27. return d != null && d.compareTo(da) >= 0 && d.compareTo(a) <= 0;
  28. }).toList());
  29. }
  30. Future<List<StatisticheVenditaData>> getPerArticolo(int idAgente, int idArticolo, String da, String a) {
  31. return (db.select(db.statisticheVendita)
  32. ..where((t) =>
  33. t.idAgente.equals(idAgente) &
  34. t.idArticolo.equals(idArticolo) &
  35. t.dataFattura.isNotNull()
  36. )
  37. ).get().then((rows) => rows.where((r) {
  38. final d = r.dataFattura;
  39. return d != null && d.compareTo(da) >= 0 && d.compareTo(a) <= 0;
  40. }).toList());
  41. }
  42. Future<void> clearAll() {
  43. return db.delete(db.statisticheVendita).go();
  44. }
  45. Future<int> insert(StatisticheVenditaData s) {
  46. return db.into(db.statisticheVendita).insert(s);
  47. }
  48. Future<int> count() async {
  49. final rows = await db.select(db.statisticheVendita).get();
  50. return rows.length;
  51. }
  52. }