Print Sort by Month in PDF
This commit is contained in:
parent
6600766724
commit
10664ee9fa
@ -1,4 +1,5 @@
|
||||
import 'package:get/get.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import 'package:pdf/pdf.dart';
|
||||
import 'package:pdf/widgets.dart' as pw;
|
||||
import 'package:printing/printing.dart';
|
||||
@ -19,6 +20,17 @@ class PrintController extends GetxController {
|
||||
final List<AppWriteTankModel> tankungen =
|
||||
tankList.map((e) => AppWriteTankModel.fromMap(e)).toList();
|
||||
|
||||
// Daten nach Monat gruppieren
|
||||
final dFormat = DateFormat('MMMM yyyy', 'de');
|
||||
final Map<String, List<AppWriteTankModel>> tankungenByMonth = {};
|
||||
for (var tankung in tankungen) {
|
||||
final month = dFormat.format(DateTime.parse(tankung.date));
|
||||
if (!tankungenByMonth.containsKey(month)) {
|
||||
tankungenByMonth[month] = [];
|
||||
}
|
||||
tankungenByMonth[month]!.add(tankung);
|
||||
}
|
||||
|
||||
doc.addPage(
|
||||
pw.Page(
|
||||
pageFormat: PdfPageFormat.a4,
|
||||
@ -40,6 +52,24 @@ class PrintController extends GetxController {
|
||||
pw.Divider(color: PdfColors.grey400),
|
||||
pw.SizedBox(height: 20),
|
||||
|
||||
// Dynamische Erstellung der monatlichen Abschnitte
|
||||
...tankungenByMonth.entries.map((entry) {
|
||||
final monthName = entry.key;
|
||||
final monthlyData = entry.value;
|
||||
return pw.Column(
|
||||
crossAxisAlignment: pw.CrossAxisAlignment.start,
|
||||
children: [
|
||||
// Monatsüberschrift
|
||||
pw.Text(
|
||||
monthName,
|
||||
style: pw.TextStyle(
|
||||
fontWeight: pw.FontWeight.bold,
|
||||
fontSize: 18,
|
||||
font: font,
|
||||
),
|
||||
),
|
||||
pw.SizedBox(height: 10),
|
||||
// Tabelle für den jeweiligen Monat
|
||||
pw.TableHelper.fromTextArray(
|
||||
headers: [
|
||||
'Datum',
|
||||
@ -50,11 +80,12 @@ class PrintController extends GetxController {
|
||||
],
|
||||
cellAlignment: pw.Alignment.centerLeft,
|
||||
border: pw.TableBorder.all(color: PdfColors.grey200),
|
||||
headerStyle:
|
||||
pw.TextStyle(fontWeight: pw.FontWeight.bold, font: font),
|
||||
data: tankungen.map((item) {
|
||||
headerStyle: pw.TextStyle(
|
||||
fontWeight: pw.FontWeight.bold, font: font),
|
||||
data: monthlyData.map((item) {
|
||||
var modDate = item.date.substring(5);
|
||||
var modPreisPerLiter = item.pricePerLiter.padRight(5, '0');
|
||||
var modPreisPerLiter =
|
||||
item.pricePerLiter.padRight(5, '0');
|
||||
return [
|
||||
modDate,
|
||||
item.location,
|
||||
@ -64,6 +95,35 @@ class PrintController extends GetxController {
|
||||
];
|
||||
}).toList(),
|
||||
),
|
||||
pw.SizedBox(height: 20),
|
||||
],
|
||||
);
|
||||
}),
|
||||
|
||||
// pw.TableHelper.fromTextArray(
|
||||
// headers: [
|
||||
// 'Datum',
|
||||
// 'Ort',
|
||||
// 'Menge (L)',
|
||||
// 'Preis/L (€)',
|
||||
// 'Summe (€)'
|
||||
// ],
|
||||
// cellAlignment: pw.Alignment.centerLeft,
|
||||
// border: pw.TableBorder.all(color: PdfColors.grey200),
|
||||
// headerStyle:
|
||||
// pw.TextStyle(fontWeight: pw.FontWeight.bold, font: font),
|
||||
// data: tankungen.map((item) {
|
||||
// var modDate = item.date.substring(5);
|
||||
// var modPreisPerLiter = item.pricePerLiter.padRight(5, '0');
|
||||
// return [
|
||||
// modDate,
|
||||
// item.location,
|
||||
// item.liters,
|
||||
// modPreisPerLiter,
|
||||
// item.szSummePreis ?? '0.0',
|
||||
// ];
|
||||
// }).toList(),
|
||||
// ),
|
||||
|
||||
pw.Spacer(),
|
||||
pw.Divider(color: PdfColors.grey400),
|
||||
|
||||
@ -5,6 +5,7 @@ import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_dotenv/flutter_dotenv.dart';
|
||||
import 'package:window_manager/window_manager.dart';
|
||||
import 'package:intl/date_symbol_data_local.dart';
|
||||
|
||||
import './extensions/http_overrides.dart';
|
||||
|
||||
@ -22,6 +23,7 @@ class AppInitializer {
|
||||
_ensureInitialized();
|
||||
await _setupWindowDimensions();
|
||||
await _setupDeviceOrientation();
|
||||
await _setupDateFormating();
|
||||
//dotENV initial
|
||||
await dotenv.load(fileName: '.env');
|
||||
//Overrides initial
|
||||
@ -30,7 +32,6 @@ class AppInitializer {
|
||||
|
||||
/// Ensures that Flutter bindings are initialized.
|
||||
static _ensureInitialized() {
|
||||
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
}
|
||||
|
||||
@ -59,4 +60,8 @@ class AppInitializer {
|
||||
overlays: [SystemUiOverlay.bottom, SystemUiOverlay.top],
|
||||
);
|
||||
}
|
||||
// Initialisiert die Lokalisierungsdaten für eine bestimmte Sprache
|
||||
static Future<void> _setupDateFormating() async {
|
||||
await initializeDateFormatting('de_DE', null);
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user