Reports
This commit is contained in:
parent
2d45e8364c
commit
e96dfbf32a
|
|
@ -643,9 +643,9 @@ abstract class UserSettingsEntity
|
|||
|
||||
abstract class ReportSettingsEntity
|
||||
implements Built<ReportSettingsEntity, ReportSettingsEntityBuilder> {
|
||||
factory ReportSettingsEntity({int sortIndex, bool sortAscending, int sortTotalsIndex, bool sortTotalsAscending, }) {
|
||||
factory ReportSettingsEntity({String sortColumn, bool sortAscending, int sortTotalsIndex, bool sortTotalsAscending, }) {
|
||||
return _$ReportSettingsEntity._(
|
||||
sortIndex: sortIndex,
|
||||
sortColumn: sortColumn ?? '',
|
||||
sortAscending: sortAscending ?? true,
|
||||
sortTotalsIndex: sortTotalsIndex,
|
||||
sortTotalsAscending: sortTotalsAscending ?? true,
|
||||
|
|
@ -656,8 +656,8 @@ abstract class ReportSettingsEntity
|
|||
ReportSettingsEntity._();
|
||||
|
||||
@nullable
|
||||
@BuiltValueField(wireName: 'sort_index')
|
||||
int get sortIndex;
|
||||
@BuiltValueField(wireName: 'sort_column')
|
||||
String get sortColumn;
|
||||
|
||||
// TODO remove nullable
|
||||
@nullable
|
||||
|
|
|
|||
|
|
@ -943,11 +943,11 @@ class _$ReportSettingsEntitySerializer
|
|||
specifiedType:
|
||||
const FullType(BuiltList, const [const FullType(String)])),
|
||||
];
|
||||
if (object.sortIndex != null) {
|
||||
if (object.sortColumn != null) {
|
||||
result
|
||||
..add('sort_index')
|
||||
..add(serializers.serialize(object.sortIndex,
|
||||
specifiedType: const FullType(int)));
|
||||
..add('sort_column')
|
||||
..add(serializers.serialize(object.sortColumn,
|
||||
specifiedType: const FullType(String)));
|
||||
}
|
||||
if (object.sortAscending != null) {
|
||||
result
|
||||
|
|
@ -982,9 +982,9 @@ class _$ReportSettingsEntitySerializer
|
|||
iterator.moveNext();
|
||||
final dynamic value = iterator.current;
|
||||
switch (key) {
|
||||
case 'sort_index':
|
||||
result.sortIndex = serializers.deserialize(value,
|
||||
specifiedType: const FullType(int)) as int;
|
||||
case 'sort_column':
|
||||
result.sortColumn = serializers.deserialize(value,
|
||||
specifiedType: const FullType(String)) as String;
|
||||
break;
|
||||
case 'sort_ascending':
|
||||
result.sortAscending = serializers.deserialize(value,
|
||||
|
|
@ -4065,7 +4065,7 @@ class UserSettingsEntityBuilder
|
|||
|
||||
class _$ReportSettingsEntity extends ReportSettingsEntity {
|
||||
@override
|
||||
final int sortIndex;
|
||||
final String sortColumn;
|
||||
@override
|
||||
final bool sortAscending;
|
||||
@override
|
||||
|
|
@ -4080,7 +4080,7 @@ class _$ReportSettingsEntity extends ReportSettingsEntity {
|
|||
(new ReportSettingsEntityBuilder()..update(updates)).build();
|
||||
|
||||
_$ReportSettingsEntity._(
|
||||
{this.sortIndex,
|
||||
{this.sortColumn,
|
||||
this.sortAscending,
|
||||
this.sortTotalsIndex,
|
||||
this.sortTotalsAscending,
|
||||
|
|
@ -4104,7 +4104,7 @@ class _$ReportSettingsEntity extends ReportSettingsEntity {
|
|||
bool operator ==(Object other) {
|
||||
if (identical(other, this)) return true;
|
||||
return other is ReportSettingsEntity &&
|
||||
sortIndex == other.sortIndex &&
|
||||
sortColumn == other.sortColumn &&
|
||||
sortAscending == other.sortAscending &&
|
||||
sortTotalsIndex == other.sortTotalsIndex &&
|
||||
sortTotalsAscending == other.sortTotalsAscending &&
|
||||
|
|
@ -4115,7 +4115,7 @@ class _$ReportSettingsEntity extends ReportSettingsEntity {
|
|||
int get hashCode {
|
||||
return $jf($jc(
|
||||
$jc(
|
||||
$jc($jc($jc(0, sortIndex.hashCode), sortAscending.hashCode),
|
||||
$jc($jc($jc(0, sortColumn.hashCode), sortAscending.hashCode),
|
||||
sortTotalsIndex.hashCode),
|
||||
sortTotalsAscending.hashCode),
|
||||
columns.hashCode));
|
||||
|
|
@ -4124,7 +4124,7 @@ class _$ReportSettingsEntity extends ReportSettingsEntity {
|
|||
@override
|
||||
String toString() {
|
||||
return (newBuiltValueToStringHelper('ReportSettingsEntity')
|
||||
..add('sortIndex', sortIndex)
|
||||
..add('sortColumn', sortColumn)
|
||||
..add('sortAscending', sortAscending)
|
||||
..add('sortTotalsIndex', sortTotalsIndex)
|
||||
..add('sortTotalsAscending', sortTotalsAscending)
|
||||
|
|
@ -4137,9 +4137,9 @@ class ReportSettingsEntityBuilder
|
|||
implements Builder<ReportSettingsEntity, ReportSettingsEntityBuilder> {
|
||||
_$ReportSettingsEntity _$v;
|
||||
|
||||
int _sortIndex;
|
||||
int get sortIndex => _$this._sortIndex;
|
||||
set sortIndex(int sortIndex) => _$this._sortIndex = sortIndex;
|
||||
String _sortColumn;
|
||||
String get sortColumn => _$this._sortColumn;
|
||||
set sortColumn(String sortColumn) => _$this._sortColumn = sortColumn;
|
||||
|
||||
bool _sortAscending;
|
||||
bool get sortAscending => _$this._sortAscending;
|
||||
|
|
@ -4165,7 +4165,7 @@ class ReportSettingsEntityBuilder
|
|||
|
||||
ReportSettingsEntityBuilder get _$this {
|
||||
if (_$v != null) {
|
||||
_sortIndex = _$v.sortIndex;
|
||||
_sortColumn = _$v.sortColumn;
|
||||
_sortAscending = _$v.sortAscending;
|
||||
_sortTotalsIndex = _$v.sortTotalsIndex;
|
||||
_sortTotalsAscending = _$v.sortTotalsAscending;
|
||||
|
|
@ -4194,7 +4194,7 @@ class ReportSettingsEntityBuilder
|
|||
try {
|
||||
_$result = _$v ??
|
||||
new _$ReportSettingsEntity._(
|
||||
sortIndex: sortIndex,
|
||||
sortColumn: sortColumn,
|
||||
sortAscending: sortAscending,
|
||||
sortTotalsIndex: sortTotalsIndex,
|
||||
sortTotalsAscending: sortTotalsAscending,
|
||||
|
|
|
|||
|
|
@ -58,9 +58,9 @@ Reducer<UserCompanyEntity> userCompanyEntityReducer = combineReducers([
|
|||
final settings = userCompany.settings.reportSettings[action.report];
|
||||
return userCompany.rebuild((b) => b
|
||||
..settings.reportSettings[action.report] = settings.rebuild((b) => b
|
||||
..sortAscending = action.sortIndex == null
|
||||
..sortAscending = action.sortColumn == null
|
||||
? settings.sortAscending
|
||||
: action.sortIndex == settings.sortIndex
|
||||
: action.sortColumn == settings.sortColumn
|
||||
? !settings.sortAscending
|
||||
: true
|
||||
..sortTotalsAscending = action.sortTotalsIndex == null
|
||||
|
|
@ -68,14 +68,14 @@ Reducer<UserCompanyEntity> userCompanyEntityReducer = combineReducers([
|
|||
: action.sortTotalsIndex == settings.sortTotalsIndex
|
||||
? !settings.sortTotalsAscending
|
||||
: true
|
||||
..sortIndex = action.sortIndex ?? settings.sortIndex
|
||||
..sortColumn = action.sortColumn ?? settings.sortColumn
|
||||
..sortTotalsIndex =
|
||||
action.sortTotalsIndex ?? settings.sortTotalsIndex));
|
||||
} else {
|
||||
return userCompany.rebuild(
|
||||
(b) => b
|
||||
..settings.reportSettings[action.report] = ReportSettingsEntity(
|
||||
sortIndex: action.sortIndex,
|
||||
sortColumn: action.sortColumn,
|
||||
sortTotalsIndex: action.sortTotalsIndex,
|
||||
),
|
||||
);
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ class UpdateReportSettings implements PersistUI {
|
|||
this.group,
|
||||
this.selectedGroup,
|
||||
this.subgroup,
|
||||
this.sortIndex,
|
||||
this.sortColumn,
|
||||
this.sortTotalsIndex,
|
||||
this.customStartDate,
|
||||
this.customEndDate,
|
||||
|
|
@ -33,7 +33,7 @@ class UpdateReportSettings implements PersistUI {
|
|||
final String selectedGroup;
|
||||
final String chart;
|
||||
final String subgroup;
|
||||
final int sortIndex;
|
||||
final String sortColumn;
|
||||
final int sortTotalsIndex;
|
||||
final String customStartDate;
|
||||
final String customEndDate;
|
||||
|
|
|
|||
|
|
@ -279,12 +279,13 @@ ReportResult clientReport(
|
|||
}
|
||||
}
|
||||
|
||||
data.sort((rowA, rowB) => sortReportTableRows(rowA, rowB, clientReportSettings));
|
||||
final selectedColumns = columns.map((item) => EnumUtils.parse(item)).toList();
|
||||
data.sort((rowA, rowB) => sortReportTableRows(rowA, rowB, clientReportSettings, selectedColumns));
|
||||
|
||||
return ReportResult(
|
||||
allColumns:
|
||||
ClientReportFields.values.map((item) => EnumUtils.parse(item)).toList(),
|
||||
columns: columns.map((item) => EnumUtils.parse(item)).toList(),
|
||||
columns: selectedColumns,
|
||||
defaultColumns:
|
||||
defaultColumns.map((item) => EnumUtils.parse(item)).toList(),
|
||||
data: data,
|
||||
|
|
|
|||
|
|
@ -132,13 +132,14 @@ ReportResult creditReport(
|
|||
}
|
||||
}
|
||||
|
||||
final selectedColumns = columns.map((item) => EnumUtils.parse(item)).toList();
|
||||
data.sort(
|
||||
(rowA, rowB) => sortReportTableRows(rowA, rowB, creditReportSettings));
|
||||
(rowA, rowB) => sortReportTableRows(rowA, rowB, creditReportSettings, selectedColumns));
|
||||
|
||||
return ReportResult(
|
||||
allColumns:
|
||||
CreditReportFields.values.map((e) => EnumUtils.parse(e)).toList(),
|
||||
columns: columns.map((item) => EnumUtils.parse(item)).toList(),
|
||||
columns: selectedColumns,
|
||||
defaultColumns:
|
||||
defaultColumns.map((item) => EnumUtils.parse(item)).toList(),
|
||||
data: data,
|
||||
|
|
|
|||
|
|
@ -141,12 +141,13 @@ ReportResult documentReport(
|
|||
}
|
||||
}
|
||||
|
||||
data.sort((rowA, rowB) => sortReportTableRows(rowA, rowB, documentReportSettings));
|
||||
final selectedColumns = columns.map((item) => EnumUtils.parse(item)).toList();
|
||||
data.sort((rowA, rowB) => sortReportTableRows(rowA, rowB, documentReportSettings, selectedColumns));
|
||||
|
||||
return ReportResult(
|
||||
allColumns:
|
||||
DocumentReportFields.values.map((e) => EnumUtils.parse(e)).toList(),
|
||||
columns: columns.map((item) => EnumUtils.parse(item)).toList(),
|
||||
columns: selectedColumns,
|
||||
defaultColumns:
|
||||
defaultColumns.map((item) => EnumUtils.parse(item)).toList(),
|
||||
data: data,
|
||||
|
|
|
|||
|
|
@ -188,12 +188,13 @@ ReportResult expenseReport(
|
|||
}
|
||||
}
|
||||
|
||||
data.sort((rowA, rowB) => sortReportTableRows(rowA, rowB, expenseReportSettings));
|
||||
final selectedColumns = columns.map((item) => EnumUtils.parse(item)).toList();
|
||||
data.sort((rowA, rowB) => sortReportTableRows(rowA, rowB, expenseReportSettings, selectedColumns));
|
||||
|
||||
return ReportResult(
|
||||
allColumns:
|
||||
ExpenseReportFields.values.map((e) => EnumUtils.parse(e)).toList(),
|
||||
columns: columns.map((item) => EnumUtils.parse(item)).toList(),
|
||||
columns: selectedColumns,
|
||||
defaultColumns:
|
||||
defaultColumns.map((item) => EnumUtils.parse(item)).toList(),
|
||||
data: data,
|
||||
|
|
|
|||
|
|
@ -230,12 +230,13 @@ ReportResult invoiceReport(
|
|||
}
|
||||
}
|
||||
|
||||
data.sort((rowA, rowB) => sortReportTableRows(rowA, rowB, invoiceReportSettings));
|
||||
final selectedColumns = columns.map((item) => EnumUtils.parse(item)).toList();
|
||||
data.sort((rowA, rowB) => sortReportTableRows(rowA, rowB, invoiceReportSettings, selectedColumns));
|
||||
|
||||
return ReportResult(
|
||||
allColumns:
|
||||
InvoiceReportFields.values.map((e) => EnumUtils.parse(e)).toList(),
|
||||
columns: columns.map((item) => EnumUtils.parse(item)).toList(),
|
||||
columns: selectedColumns,
|
||||
defaultColumns:
|
||||
defaultColumns.map((item) => EnumUtils.parse(item)).toList(),
|
||||
data: data,
|
||||
|
|
|
|||
|
|
@ -159,12 +159,13 @@ ReportResult paymentReport(
|
|||
}
|
||||
}
|
||||
|
||||
data.sort((rowA, rowB) => sortReportTableRows(rowA, rowB, paymentReportSettings));
|
||||
final selectedColumns = columns.map((item) => EnumUtils.parse(item)).toList();
|
||||
data.sort((rowA, rowB) => sortReportTableRows(rowA, rowB, paymentReportSettings, selectedColumns));
|
||||
|
||||
return ReportResult(
|
||||
allColumns:
|
||||
PaymentReportFields.values.map((e) => EnumUtils.parse(e)).toList(),
|
||||
columns: columns.map((item) => EnumUtils.parse(item)).toList(),
|
||||
columns: selectedColumns,
|
||||
defaultColumns:
|
||||
defaultColumns.map((item) => EnumUtils.parse(item)).toList(),
|
||||
data: data,
|
||||
|
|
|
|||
|
|
@ -157,13 +157,14 @@ ReportResult productReport(
|
|||
}
|
||||
}
|
||||
|
||||
final selectedColumns = columns.map((item) => EnumUtils.parse(item)).toList();
|
||||
data.sort(
|
||||
(rowA, rowB) => sortReportTableRows(rowA, rowB, productReportSettings));
|
||||
(rowA, rowB) => sortReportTableRows(rowA, rowB, productReportSettings, selectedColumns));
|
||||
|
||||
return ReportResult(
|
||||
allColumns:
|
||||
ProductReportFields.values.map((e) => EnumUtils.parse(e)).toList(),
|
||||
columns: columns.map((item) => EnumUtils.parse(item)).toList(),
|
||||
columns: selectedColumns,
|
||||
defaultColumns:
|
||||
defaultColumns.map((item) => EnumUtils.parse(item)).toList(),
|
||||
data: data,
|
||||
|
|
|
|||
|
|
@ -378,6 +378,7 @@ class _ReportDataTableState extends State<ReportDataTable> {
|
|||
final reportSettings =
|
||||
state.userCompany.settings?.reportSettings[reportState.report] ??
|
||||
ReportSettingsEntity();
|
||||
final sortedColumns = reportResult.sortedColumns(reportState);
|
||||
|
||||
return Column(
|
||||
children: <Widget>[
|
||||
|
|
@ -411,15 +412,21 @@ class _ReportDataTableState extends State<ReportDataTable> {
|
|||
padding: const EdgeInsets.all(12),
|
||||
child: PaginatedDataTable(
|
||||
header: SizedBox(),
|
||||
/*
|
||||
sortColumnIndex: reportSettings.sortIndex != null &&
|
||||
reportResult.columns.length > reportSettings.sortIndex
|
||||
? reportSettings.sortIndex
|
||||
: null,
|
||||
*
|
||||
*/
|
||||
sortColumnIndex: sortedColumns.contains(reportSettings.sortColumn)
|
||||
? sortedColumns.indexOf(reportSettings.sortColumn)
|
||||
: null,
|
||||
sortAscending: reportSettings.sortAscending,
|
||||
columns: reportResult.tableColumns(
|
||||
context,
|
||||
(index, ascending) =>
|
||||
widget.viewModel.onReportSorted(index, ascending)),
|
||||
widget.viewModel.onReportSorted(sortedColumns[index], ascending)),
|
||||
source: dataTableSource,
|
||||
),
|
||||
)
|
||||
|
|
@ -1246,17 +1253,20 @@ class ReportBoolValue extends ReportElement {
|
|||
}
|
||||
}
|
||||
|
||||
int sortReportTableRows(
|
||||
dynamic rowA, dynamic rowB, ReportSettingsEntity reportSettings) {
|
||||
if (reportSettings.sortIndex == null) {
|
||||
return 0;
|
||||
} else if (rowA.length <= reportSettings.sortIndex ||
|
||||
rowB.length <= reportSettings.sortIndex) {
|
||||
int sortReportTableRows(dynamic rowA, dynamic rowB,
|
||||
ReportSettingsEntity reportSettings, List<String> columns) {
|
||||
if (reportSettings.sortColumn == null || reportSettings.sortColumn.isEmpty) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
final dynamic valueA = rowA[reportSettings.sortIndex].value;
|
||||
final dynamic valueB = rowB[reportSettings.sortIndex].value;
|
||||
final index = columns.indexOf(reportSettings.sortColumn);
|
||||
|
||||
if (rowA.length <= index || rowB.length <= index) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
final dynamic valueA = rowA[index].value;
|
||||
final dynamic valueB = rowB[index].value;
|
||||
|
||||
if (reportSettings.sortAscending) {
|
||||
return valueA.compareTo(valueB);
|
||||
|
|
|
|||
|
|
@ -67,7 +67,7 @@ class ReportsScreenVM {
|
|||
final Function(BuildContext, List<String>) onReportColumnsChanged;
|
||||
final Function(BuildContext) onExportPressed;
|
||||
final Function(BuildContext, BuiltMap<String, String>) onReportFiltersChanged;
|
||||
final Function(int, bool) onReportSorted;
|
||||
final Function(String, bool) onReportSorted;
|
||||
final Function(int, bool) onReportTotalsSorted;
|
||||
final Function({
|
||||
String report,
|
||||
|
|
@ -190,10 +190,10 @@ class ReportsScreenVM {
|
|||
state.uiState.reportsUIState,
|
||||
reportSettings,
|
||||
),
|
||||
onReportSorted: (index, ascending) {
|
||||
onReportSorted: (column, ascending) {
|
||||
store.dispatch(UpdateReportSettings(
|
||||
report: state.uiState.reportsUIState.report,
|
||||
sortIndex: index,
|
||||
sortColumn: column,
|
||||
));
|
||||
},
|
||||
onReportTotalsSorted: (index, ascending) {
|
||||
|
|
@ -385,14 +385,16 @@ GroupTotals calculateReportTotals({
|
|||
|
||||
final rows = totals.keys.toList();
|
||||
final sortedColumns = reportResult.sortedColumns(reportState);
|
||||
final index = sortedColumns.contains(reportSettings.sortColumn)
|
||||
? sortedColumns.indexOf(reportSettings.sortColumn)
|
||||
: 0;
|
||||
|
||||
rows.sort((rowA, rowB) {
|
||||
final valuesA = totals[rowA];
|
||||
final valuesB = totals[rowB];
|
||||
if (reportSettings.sortIndex != null &&
|
||||
reportSettings.sortIndex < columns.length) {
|
||||
final sort = sortedColumns[reportSettings.sortIndex];
|
||||
if (reportSettings.sortIndex == 0) {
|
||||
if (index != null && index < columns.length) {
|
||||
final sort = sortedColumns[index];
|
||||
if (index == 0) {
|
||||
return reportSettings.sortAscending
|
||||
? rowA.compareTo(rowB)
|
||||
: rowB.compareTo(rowA);
|
||||
|
|
|
|||
|
|
@ -190,12 +190,13 @@ ReportResult taskReport(
|
|||
}
|
||||
}
|
||||
|
||||
final selectedColumns = columns.map((item) => EnumUtils.parse(item)).toList();
|
||||
data.sort(
|
||||
(rowA, rowB) => sortReportTableRows(rowA, rowB, taskReportSettings));
|
||||
(rowA, rowB) => sortReportTableRows(rowA, rowB, taskReportSettings, selectedColumns));
|
||||
|
||||
return ReportResult(
|
||||
allColumns: TaskReportFields.values.map((e) => EnumUtils.parse(e)).toList(),
|
||||
columns: columns.map((item) => EnumUtils.parse(item)).toList(),
|
||||
columns: selectedColumns,
|
||||
defaultColumns:
|
||||
defaultColumns.map((item) => EnumUtils.parse(item)).toList(),
|
||||
data: data,
|
||||
|
|
|
|||
Loading…
Reference in New Issue