Files
sendico/frontend/pweb/lib/pages/report/table/row.dart
Arseni 0172176978 fixes
2026-03-11 18:26:21 +03:00

65 lines
2.1 KiB
Dart

import 'package:flutter/material.dart';
import 'package:pshared/models/money.dart';
import 'package:pshared/models/payment/operation.dart';
import 'package:pshared/models/payment/status.dart';
import 'package:pshared/utils/currency.dart';
import 'package:pweb/pages/report/table/badge.dart';
import 'package:pweb/utils/money_display.dart';
import 'package:pweb/utils/report/download_act.dart';
import 'package:pweb/generated/i18n/app_localizations.dart';
class OperationRow {
static DataRow build(OperationItem op, BuildContext context) {
final isUnknownDate = op.date.millisecondsSinceEpoch == 0;
final localDate = op.date.toLocal();
final loc = AppLocalizations.of(context)!;
final dateLabel = isUnknownDate
? '-'
: '${TimeOfDay.fromDateTime(localDate).format(context)}\n'
'${localDate.toIso8601String().split("T").first}';
final canDownload =
op.status == OperationStatus.success &&
(op.operationRef ?? '').trim().isNotEmpty &&
(op.gatewayService ?? '').trim().isNotEmpty;
final documentCell = canDownload
? TextButton.icon(
onPressed: () => downloadPaymentAct(
context,
gatewayService: op.gatewayService ?? '',
operationRef: op.operationRef ?? '',
),
icon: const Icon(Icons.download),
label: Text(loc.downloadAct),
)
: Text(op.fileName ?? '');
final amountLabel = formatMoneyUiWithL10n(
loc,
Money(amount: amountToString(op.amount), currency: op.currency),
);
final toAmountLabel = formatMoneyUiWithL10n(
loc,
Money(amount: amountToString(op.toAmount), currency: op.toCurrency),
);
return DataRow(
cells: [
DataCell(OperationStatusBadge(status: op.status)),
DataCell(documentCell),
DataCell(Text(amountLabel)),
DataCell(Text(toAmountLabel)),
DataCell(Text(op.payId)),
DataCell(Text(op.cardNumber ?? '-')),
DataCell(Text(op.name)),
DataCell(Text(dateLabel)),
DataCell(Text(op.comment)),
],
);
}
}