feat: add payment method

This commit is contained in:
2026-07-29 21:25:56 +02:00
parent cd75d3a474
commit 3cf4787e8c
14 changed files with 652 additions and 50 deletions
+7 -1
View File
@@ -73,6 +73,8 @@ class ClosedTabs extends Table {
DateTimeColumn get closedAt => dateTime()();
TextColumn get paymentMethod => text().withDefault(const Constant('cash'))();
@override
Set<Column> get primaryKey => {id};
}
@@ -126,7 +128,7 @@ class AppDatabase extends _$AppDatabase {
AppDatabase([QueryExecutor? executor]) : super(executor ?? _openConnection());
@override
int get schemaVersion => 5;
int get schemaVersion => 6;
@override
MigrationStrategy get migration {
@@ -152,6 +154,10 @@ class AppDatabase extends _$AppDatabase {
if (from < 5) {
await migrator.createTable(appSettingsTable);
}
if (from < 6) {
await migrator.addColumn(closedTabs, closedTabs.paymentMethod);
}
},
);
}
+75 -3
View File
@@ -1417,12 +1417,25 @@ class $ClosedTabsTable extends ClosedTabs
type: DriftSqlType.dateTime,
requiredDuringInsert: true,
);
static const VerificationMeta _paymentMethodMeta = const VerificationMeta(
'paymentMethod',
);
@override
late final GeneratedColumn<String> paymentMethod = GeneratedColumn<String>(
'payment_method',
aliasedName,
false,
type: DriftSqlType.string,
requiredDuringInsert: false,
defaultValue: const Constant('cash'),
);
@override
List<GeneratedColumn> get $columns => [
id,
originalTabId,
customerName,
closedAt,
paymentMethod,
];
@override
String get aliasedName => _alias ?? actualTableName;
@@ -1471,6 +1484,15 @@ class $ClosedTabsTable extends ClosedTabs
} else if (isInserting) {
context.missing(_closedAtMeta);
}
if (data.containsKey('payment_method')) {
context.handle(
_paymentMethodMeta,
paymentMethod.isAcceptableOrUnknown(
data['payment_method']!,
_paymentMethodMeta,
),
);
}
return context;
}
@@ -1496,6 +1518,10 @@ class $ClosedTabsTable extends ClosedTabs
DriftSqlType.dateTime,
data['${effectivePrefix}closed_at'],
)!,
paymentMethod: attachedDatabase.typeMapping.read(
DriftSqlType.string,
data['${effectivePrefix}payment_method'],
)!,
);
}
@@ -1510,11 +1536,13 @@ class ClosedTabsRow extends DataClass implements Insertable<ClosedTabsRow> {
final String originalTabId;
final String customerName;
final DateTime closedAt;
final String paymentMethod;
const ClosedTabsRow({
required this.id,
required this.originalTabId,
required this.customerName,
required this.closedAt,
required this.paymentMethod,
});
@override
Map<String, Expression> toColumns(bool nullToAbsent) {
@@ -1523,6 +1551,7 @@ class ClosedTabsRow extends DataClass implements Insertable<ClosedTabsRow> {
map['original_tab_id'] = Variable<String>(originalTabId);
map['customer_name'] = Variable<String>(customerName);
map['closed_at'] = Variable<DateTime>(closedAt);
map['payment_method'] = Variable<String>(paymentMethod);
return map;
}
@@ -1532,6 +1561,7 @@ class ClosedTabsRow extends DataClass implements Insertable<ClosedTabsRow> {
originalTabId: Value(originalTabId),
customerName: Value(customerName),
closedAt: Value(closedAt),
paymentMethod: Value(paymentMethod),
);
}
@@ -1545,6 +1575,7 @@ class ClosedTabsRow extends DataClass implements Insertable<ClosedTabsRow> {
originalTabId: serializer.fromJson<String>(json['originalTabId']),
customerName: serializer.fromJson<String>(json['customerName']),
closedAt: serializer.fromJson<DateTime>(json['closedAt']),
paymentMethod: serializer.fromJson<String>(json['paymentMethod']),
);
}
@override
@@ -1555,6 +1586,7 @@ class ClosedTabsRow extends DataClass implements Insertable<ClosedTabsRow> {
'originalTabId': serializer.toJson<String>(originalTabId),
'customerName': serializer.toJson<String>(customerName),
'closedAt': serializer.toJson<DateTime>(closedAt),
'paymentMethod': serializer.toJson<String>(paymentMethod),
};
}
@@ -1563,11 +1595,13 @@ class ClosedTabsRow extends DataClass implements Insertable<ClosedTabsRow> {
String? originalTabId,
String? customerName,
DateTime? closedAt,
String? paymentMethod,
}) => ClosedTabsRow(
id: id ?? this.id,
originalTabId: originalTabId ?? this.originalTabId,
customerName: customerName ?? this.customerName,
closedAt: closedAt ?? this.closedAt,
paymentMethod: paymentMethod ?? this.paymentMethod,
);
ClosedTabsRow copyWithCompanion(ClosedTabsCompanion data) {
return ClosedTabsRow(
@@ -1579,6 +1613,9 @@ class ClosedTabsRow extends DataClass implements Insertable<ClosedTabsRow> {
? data.customerName.value
: this.customerName,
closedAt: data.closedAt.present ? data.closedAt.value : this.closedAt,
paymentMethod: data.paymentMethod.present
? data.paymentMethod.value
: this.paymentMethod,
);
}
@@ -1588,13 +1625,15 @@ class ClosedTabsRow extends DataClass implements Insertable<ClosedTabsRow> {
..write('id: $id, ')
..write('originalTabId: $originalTabId, ')
..write('customerName: $customerName, ')
..write('closedAt: $closedAt')
..write('closedAt: $closedAt, ')
..write('paymentMethod: $paymentMethod')
..write(')'))
.toString();
}
@override
int get hashCode => Object.hash(id, originalTabId, customerName, closedAt);
int get hashCode =>
Object.hash(id, originalTabId, customerName, closedAt, paymentMethod);
@override
bool operator ==(Object other) =>
identical(this, other) ||
@@ -1602,7 +1641,8 @@ class ClosedTabsRow extends DataClass implements Insertable<ClosedTabsRow> {
other.id == this.id &&
other.originalTabId == this.originalTabId &&
other.customerName == this.customerName &&
other.closedAt == this.closedAt);
other.closedAt == this.closedAt &&
other.paymentMethod == this.paymentMethod);
}
class ClosedTabsCompanion extends UpdateCompanion<ClosedTabsRow> {
@@ -1610,12 +1650,14 @@ class ClosedTabsCompanion extends UpdateCompanion<ClosedTabsRow> {
final Value<String> originalTabId;
final Value<String> customerName;
final Value<DateTime> closedAt;
final Value<String> paymentMethod;
final Value<int> rowid;
const ClosedTabsCompanion({
this.id = const Value.absent(),
this.originalTabId = const Value.absent(),
this.customerName = const Value.absent(),
this.closedAt = const Value.absent(),
this.paymentMethod = const Value.absent(),
this.rowid = const Value.absent(),
});
ClosedTabsCompanion.insert({
@@ -1623,6 +1665,7 @@ class ClosedTabsCompanion extends UpdateCompanion<ClosedTabsRow> {
required String originalTabId,
required String customerName,
required DateTime closedAt,
this.paymentMethod = const Value.absent(),
this.rowid = const Value.absent(),
}) : id = Value(id),
originalTabId = Value(originalTabId),
@@ -1633,6 +1676,7 @@ class ClosedTabsCompanion extends UpdateCompanion<ClosedTabsRow> {
Expression<String>? originalTabId,
Expression<String>? customerName,
Expression<DateTime>? closedAt,
Expression<String>? paymentMethod,
Expression<int>? rowid,
}) {
return RawValuesInsertable({
@@ -1640,6 +1684,7 @@ class ClosedTabsCompanion extends UpdateCompanion<ClosedTabsRow> {
if (originalTabId != null) 'original_tab_id': originalTabId,
if (customerName != null) 'customer_name': customerName,
if (closedAt != null) 'closed_at': closedAt,
if (paymentMethod != null) 'payment_method': paymentMethod,
if (rowid != null) 'rowid': rowid,
});
}
@@ -1649,6 +1694,7 @@ class ClosedTabsCompanion extends UpdateCompanion<ClosedTabsRow> {
Value<String>? originalTabId,
Value<String>? customerName,
Value<DateTime>? closedAt,
Value<String>? paymentMethod,
Value<int>? rowid,
}) {
return ClosedTabsCompanion(
@@ -1656,6 +1702,7 @@ class ClosedTabsCompanion extends UpdateCompanion<ClosedTabsRow> {
originalTabId: originalTabId ?? this.originalTabId,
customerName: customerName ?? this.customerName,
closedAt: closedAt ?? this.closedAt,
paymentMethod: paymentMethod ?? this.paymentMethod,
rowid: rowid ?? this.rowid,
);
}
@@ -1675,6 +1722,9 @@ class ClosedTabsCompanion extends UpdateCompanion<ClosedTabsRow> {
if (closedAt.present) {
map['closed_at'] = Variable<DateTime>(closedAt.value);
}
if (paymentMethod.present) {
map['payment_method'] = Variable<String>(paymentMethod.value);
}
if (rowid.present) {
map['rowid'] = Variable<int>(rowid.value);
}
@@ -1688,6 +1738,7 @@ class ClosedTabsCompanion extends UpdateCompanion<ClosedTabsRow> {
..write('originalTabId: $originalTabId, ')
..write('customerName: $customerName, ')
..write('closedAt: $closedAt, ')
..write('paymentMethod: $paymentMethod, ')
..write('rowid: $rowid')
..write(')'))
.toString();
@@ -3536,6 +3587,7 @@ typedef $$ClosedTabsTableCreateCompanionBuilder =
required String originalTabId,
required String customerName,
required DateTime closedAt,
Value<String> paymentMethod,
Value<int> rowid,
});
typedef $$ClosedTabsTableUpdateCompanionBuilder =
@@ -3544,6 +3596,7 @@ typedef $$ClosedTabsTableUpdateCompanionBuilder =
Value<String> originalTabId,
Value<String> customerName,
Value<DateTime> closedAt,
Value<String> paymentMethod,
Value<int> rowid,
});
@@ -3575,6 +3628,11 @@ class $$ClosedTabsTableFilterComposer
column: $table.closedAt,
builder: (column) => ColumnFilters(column),
);
ColumnFilters<String> get paymentMethod => $composableBuilder(
column: $table.paymentMethod,
builder: (column) => ColumnFilters(column),
);
}
class $$ClosedTabsTableOrderingComposer
@@ -3605,6 +3663,11 @@ class $$ClosedTabsTableOrderingComposer
column: $table.closedAt,
builder: (column) => ColumnOrderings(column),
);
ColumnOrderings<String> get paymentMethod => $composableBuilder(
column: $table.paymentMethod,
builder: (column) => ColumnOrderings(column),
);
}
class $$ClosedTabsTableAnnotationComposer
@@ -3631,6 +3694,11 @@ class $$ClosedTabsTableAnnotationComposer
GeneratedColumn<DateTime> get closedAt =>
$composableBuilder(column: $table.closedAt, builder: (column) => column);
GeneratedColumn<String> get paymentMethod => $composableBuilder(
column: $table.paymentMethod,
builder: (column) => column,
);
}
class $$ClosedTabsTableTableManager
@@ -3668,12 +3736,14 @@ class $$ClosedTabsTableTableManager
Value<String> originalTabId = const Value.absent(),
Value<String> customerName = const Value.absent(),
Value<DateTime> closedAt = const Value.absent(),
Value<String> paymentMethod = const Value.absent(),
Value<int> rowid = const Value.absent(),
}) => ClosedTabsCompanion(
id: id,
originalTabId: originalTabId,
customerName: customerName,
closedAt: closedAt,
paymentMethod: paymentMethod,
rowid: rowid,
),
createCompanionCallback:
@@ -3682,12 +3752,14 @@ class $$ClosedTabsTableTableManager
required String originalTabId,
required String customerName,
required DateTime closedAt,
Value<String> paymentMethod = const Value.absent(),
Value<int> rowid = const Value.absent(),
}) => ClosedTabsCompanion.insert(
id: id,
originalTabId: originalTabId,
customerName: customerName,
closedAt: closedAt,
paymentMethod: paymentMethod,
rowid: rowid,
),
withReferenceMapper: (p0) => p0