Reports
This commit is contained in:
parent
40bc318480
commit
dfcdcf15c9
|
|
@ -338,6 +338,14 @@ abstract class BaseEntity implements SelectableEntity {
|
||||||
currencyId: currencyId,
|
currencyId: currencyId,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
ReportTimestampValue getReportTimestamp({int value, String currencyId}) =>
|
||||||
|
ReportTimestampValue(
|
||||||
|
entityType: entityType,
|
||||||
|
entityId: id,
|
||||||
|
value: value,
|
||||||
|
currencyId: currencyId,
|
||||||
|
);
|
||||||
|
|
||||||
ReportNumberValue getReportDouble(
|
ReportNumberValue getReportDouble(
|
||||||
{double value,
|
{double value,
|
||||||
String currencyId,
|
String currencyId,
|
||||||
|
|
|
||||||
|
|
@ -259,6 +259,42 @@ abstract class TaskEntity extends Object
|
||||||
DateTime.parse(endDate).compareTo(lastEndDate.toLocal()) == 1;
|
DateTime.parse(endDate).compareTo(lastEndDate.toLocal()) == 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int get startTimestamp {
|
||||||
|
if (timeLog.isEmpty) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
final List<dynamic> log = jsonDecode(timeLog);
|
||||||
|
|
||||||
|
if (log.isEmpty) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
final first = log.first as List;
|
||||||
|
|
||||||
|
return first[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
int get endTimestamp {
|
||||||
|
if (timeLog.isEmpty) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
final List<dynamic> log = jsonDecode(timeLog);
|
||||||
|
|
||||||
|
if (log.isEmpty) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
final last = log.last as List;
|
||||||
|
|
||||||
|
if (last.length < 2) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return last[1];
|
||||||
|
}
|
||||||
|
|
||||||
List<TaskTime> get taskTimes {
|
List<TaskTime> get taskTimes {
|
||||||
final List<TaskTime> details = [];
|
final List<TaskTime> details = [];
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1167,22 +1167,27 @@ class ReportResult {
|
||||||
for (var j = 0; j < row.length; j++) {
|
for (var j = 0; j < row.length; j++) {
|
||||||
final cell = row[j];
|
final cell = row[j];
|
||||||
final column = columns[j];
|
final column = columns[j];
|
||||||
|
final canTotal = cell is ReportNumberValue || cell is ReportAgeValue ||
|
||||||
|
cell is ReportDurationValue;
|
||||||
|
|
||||||
if (cell is ReportNumberValue || cell is ReportAgeValue) {
|
String currencyId = '';
|
||||||
String currencyId;
|
if (canTotal) {
|
||||||
if (cell is ReportNumberValue) {
|
if (cell is ReportNumberValue) {
|
||||||
currencyId = cell.currencyId;
|
currencyId = cell.currencyId;
|
||||||
} else if (cell is ReportAgeValue) {
|
} else if (cell is ReportAgeValue) {
|
||||||
currencyId = cell.currencyId;
|
currencyId = cell.currencyId;
|
||||||
|
} else if (cell is ReportDurationValue) {
|
||||||
|
currencyId = cell.currencyId;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (!totals.containsKey(currencyId)) {
|
if (!totals.containsKey(currencyId)) {
|
||||||
totals[currencyId] = {'count': 0};
|
totals[currencyId] = {'count': 0};
|
||||||
}
|
}
|
||||||
if (!countedRow) {
|
if (!countedRow) {
|
||||||
totals[currencyId]['count']++;
|
totals[currencyId]['count']++;
|
||||||
countedRow = true;
|
countedRow = true;
|
||||||
}
|
}
|
||||||
|
if (canTotal) {
|
||||||
if (!totals[currencyId].containsKey(column)) {
|
if (!totals[currencyId].containsKey(column)) {
|
||||||
totals[currencyId][column] = 0;
|
totals[currencyId][column] = 0;
|
||||||
}
|
}
|
||||||
|
|
@ -1362,6 +1367,28 @@ class ReportDurationValue extends ReportElement {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class ReportTimestampValue extends ReportElement {
|
||||||
|
ReportTimestampValue({
|
||||||
|
@required dynamic value,
|
||||||
|
@required EntityType entityType,
|
||||||
|
@required String entityId,
|
||||||
|
@required this.currencyId,
|
||||||
|
}) : super(value: value, entityType: entityType, entityId: entityId);
|
||||||
|
|
||||||
|
final String currencyId;
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget renderWidget(BuildContext context, String column) {
|
||||||
|
return Text(renderText(context, column));
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
String renderText(BuildContext context, String column) {
|
||||||
|
return formatDate(
|
||||||
|
convertTimestampToDateString(value), context, showTime: true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
class ReportIntValue extends ReportElement {
|
class ReportIntValue extends ReportElement {
|
||||||
ReportIntValue({
|
ReportIntValue({
|
||||||
dynamic value,
|
dynamic value,
|
||||||
|
|
|
||||||
|
|
@ -8,15 +8,13 @@ import 'package:invoiceninja_flutter/data/models/models.dart';
|
||||||
import 'package:invoiceninja_flutter/redux/reports/reports_state.dart';
|
import 'package:invoiceninja_flutter/redux/reports/reports_state.dart';
|
||||||
import 'package:invoiceninja_flutter/redux/static/static_state.dart';
|
import 'package:invoiceninja_flutter/redux/static/static_state.dart';
|
||||||
import 'package:invoiceninja_flutter/ui/reports/reports_screen.dart';
|
import 'package:invoiceninja_flutter/ui/reports/reports_screen.dart';
|
||||||
import 'package:invoiceninja_flutter/utils/formatting.dart';
|
|
||||||
import 'package:memoize/memoize.dart';
|
import 'package:memoize/memoize.dart';
|
||||||
import 'package:invoiceninja_flutter/utils/extensions.dart';
|
|
||||||
|
|
||||||
enum TaskReportFields {
|
enum TaskReportFields {
|
||||||
rate,
|
rate,
|
||||||
calculated_rate,
|
calculated_rate,
|
||||||
start_date,
|
start_time,
|
||||||
end_date,
|
end_time,
|
||||||
duration,
|
duration,
|
||||||
description,
|
description,
|
||||||
invoice,
|
invoice,
|
||||||
|
|
@ -70,8 +68,9 @@ ReportResult taskReport(
|
||||||
: ReportSettingsEntity();
|
: ReportSettingsEntity();
|
||||||
|
|
||||||
final defaultColumns = [
|
final defaultColumns = [
|
||||||
TaskReportFields.start_date,
|
TaskReportFields.start_time,
|
||||||
TaskReportFields.end_date,
|
TaskReportFields.end_time,
|
||||||
|
TaskReportFields.duration,
|
||||||
TaskReportFields.description,
|
TaskReportFields.description,
|
||||||
TaskReportFields.client,
|
TaskReportFields.client,
|
||||||
TaskReportFields.invoice,
|
TaskReportFields.invoice,
|
||||||
|
|
@ -80,6 +79,7 @@ ReportResult taskReport(
|
||||||
if (taskReportSettings.columns.isNotEmpty) {
|
if (taskReportSettings.columns.isNotEmpty) {
|
||||||
columns = BuiltList(taskReportSettings.columns
|
columns = BuiltList(taskReportSettings.columns
|
||||||
.map((e) => EnumUtils.fromString(TaskReportFields.values, e))
|
.map((e) => EnumUtils.fromString(TaskReportFields.values, e))
|
||||||
|
.where((element) => element != null)
|
||||||
.toList());
|
.toList());
|
||||||
} else {
|
} else {
|
||||||
columns = BuiltList(defaultColumns);
|
columns = BuiltList(defaultColumns);
|
||||||
|
|
@ -113,12 +113,11 @@ ReportResult taskReport(
|
||||||
task: task,
|
task: task,
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
case TaskReportFields.start_date:
|
case TaskReportFields.start_time:
|
||||||
value =
|
value = task.startTimestamp;
|
||||||
convertDateTimeToSqlDate(task.taskTimes.firstOrNull?.startDate);
|
|
||||||
break;
|
break;
|
||||||
case TaskReportFields.end_date:
|
case TaskReportFields.end_time:
|
||||||
value = convertDateTimeToSqlDate(task.taskTimes.firstOrNull?.endDate);
|
value = task.endTimestamp;
|
||||||
break;
|
break;
|
||||||
case TaskReportFields.description:
|
case TaskReportFields.description:
|
||||||
value = task.description;
|
value = task.description;
|
||||||
|
|
@ -179,7 +178,10 @@ ReportResult taskReport(
|
||||||
skip = true;
|
skip = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (column == TaskReportFields.duration) {
|
if (column == TaskReportFields.start_time ||
|
||||||
|
column == TaskReportFields.end_time) {
|
||||||
|
row.add(task.getReportTimestamp(value: value));
|
||||||
|
} else if (column == TaskReportFields.duration) {
|
||||||
row.add(task.getReportDuration(value: value));
|
row.add(task.getReportDuration(value: value));
|
||||||
} else if (value.runtimeType == bool) {
|
} else if (value.runtimeType == bool) {
|
||||||
row.add(task.getReportBool(value: value));
|
row.add(task.getReportBool(value: value));
|
||||||
|
|
|
||||||
|
|
@ -20,4 +20,6 @@ extension ContextHelper on BuildContext {
|
||||||
|
|
||||||
extension ListHelper<T> on List<T> {
|
extension ListHelper<T> on List<T> {
|
||||||
T get firstOrNull => isEmpty ? null : first;
|
T get firstOrNull => isEmpty ? null : first;
|
||||||
|
|
||||||
|
T get lastOrNull => isEmpty ? null : last;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue