clearPeriodLogAfterSpecificDate method
Delete past period data from specific date
Implementation
Future<int> clearPeriodLogAfterSpecificDate(
String customerId, String lastLogDate) async {
Database? db = await instance.database;
final List<Map<String, dynamic>> queryResponse = await db!.rawQuery(
"Select * from $tableUserPeriodsLogsData WHERE $columnCustomerId='$customerId'");
List<DateTime> selectedPeriodsDate = [];
List.generate(queryResponse.length, (i) {
selectedPeriodsDate.add(DateTime.parse(Encryption.instance
.decrypt(queryResponse[i][columnPeriodEncryptDate])));
});
selectedPeriodsDate.sort((a, b) => a.compareTo(b));
/* printMenstrualCycleLogs(
"Before Delete count ${selectedPeriodsDate.length}");*/
for (int index = 0; index < selectedPeriodsDate.length; index++) {
if (DateTime.parse(lastLogDate).isBefore(selectedPeriodsDate[index])) {
await db.rawDelete(
"DELETE FROM $tableUserPeriodsLogsData WHERE $columnCustomerId='$customerId' AND $columnPeriodEncryptDate='${Encryption.instance.encrypt(CalenderDateUtils.dateDayFormat(selectedPeriodsDate[index]))}'");
}
}
return 1;
}