feat: get table
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import 'package:enaklo_pos/data/datasources/table_remote_datasource.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:enaklo_pos/data/datasources/product_local_datasource.dart';
|
||||
import 'package:enaklo_pos/data/models/response/table_model.dart';
|
||||
@@ -8,11 +9,17 @@ part 'get_table_state.dart';
|
||||
part 'get_table_bloc.freezed.dart';
|
||||
|
||||
class GetTableBloc extends Bloc<GetTableEvent, GetTableState> {
|
||||
GetTableBloc() : super(_Initial()) {
|
||||
final TableRemoteDataSource _tableRemoteDataSource;
|
||||
GetTableBloc(this._tableRemoteDataSource) : super(GetTableState.initial()) {
|
||||
on<_GetTables>((event, emit) async {
|
||||
emit(_Loading());
|
||||
final tables = await ProductLocalDatasource.instance.getAllTable();
|
||||
emit(_Success(tables));
|
||||
final tables = await _tableRemoteDataSource.getTable();
|
||||
tables.fold(
|
||||
(l) => emit(_Error(l)),
|
||||
(r) => emit(
|
||||
_Success(r.data!.tables!),
|
||||
),
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -294,6 +294,7 @@ mixin _$GetTableState {
|
||||
required TResult Function() initial,
|
||||
required TResult Function() loading,
|
||||
required TResult Function(List<TableModel> tables) success,
|
||||
required TResult Function(String message) error,
|
||||
}) =>
|
||||
throw _privateConstructorUsedError;
|
||||
@optionalTypeArgs
|
||||
@@ -301,6 +302,7 @@ mixin _$GetTableState {
|
||||
TResult? Function()? initial,
|
||||
TResult? Function()? loading,
|
||||
TResult? Function(List<TableModel> tables)? success,
|
||||
TResult? Function(String message)? error,
|
||||
}) =>
|
||||
throw _privateConstructorUsedError;
|
||||
@optionalTypeArgs
|
||||
@@ -308,6 +310,7 @@ mixin _$GetTableState {
|
||||
TResult Function()? initial,
|
||||
TResult Function()? loading,
|
||||
TResult Function(List<TableModel> tables)? success,
|
||||
TResult Function(String message)? error,
|
||||
required TResult orElse(),
|
||||
}) =>
|
||||
throw _privateConstructorUsedError;
|
||||
@@ -316,6 +319,7 @@ mixin _$GetTableState {
|
||||
required TResult Function(_Initial value) initial,
|
||||
required TResult Function(_Loading value) loading,
|
||||
required TResult Function(_Success value) success,
|
||||
required TResult Function(_Error value) error,
|
||||
}) =>
|
||||
throw _privateConstructorUsedError;
|
||||
@optionalTypeArgs
|
||||
@@ -323,6 +327,7 @@ mixin _$GetTableState {
|
||||
TResult? Function(_Initial value)? initial,
|
||||
TResult? Function(_Loading value)? loading,
|
||||
TResult? Function(_Success value)? success,
|
||||
TResult? Function(_Error value)? error,
|
||||
}) =>
|
||||
throw _privateConstructorUsedError;
|
||||
@optionalTypeArgs
|
||||
@@ -330,6 +335,7 @@ mixin _$GetTableState {
|
||||
TResult Function(_Initial value)? initial,
|
||||
TResult Function(_Loading value)? loading,
|
||||
TResult Function(_Success value)? success,
|
||||
TResult Function(_Error value)? error,
|
||||
required TResult orElse(),
|
||||
}) =>
|
||||
throw _privateConstructorUsedError;
|
||||
@@ -400,6 +406,7 @@ class _$InitialImpl implements _Initial {
|
||||
required TResult Function() initial,
|
||||
required TResult Function() loading,
|
||||
required TResult Function(List<TableModel> tables) success,
|
||||
required TResult Function(String message) error,
|
||||
}) {
|
||||
return initial();
|
||||
}
|
||||
@@ -410,6 +417,7 @@ class _$InitialImpl implements _Initial {
|
||||
TResult? Function()? initial,
|
||||
TResult? Function()? loading,
|
||||
TResult? Function(List<TableModel> tables)? success,
|
||||
TResult? Function(String message)? error,
|
||||
}) {
|
||||
return initial?.call();
|
||||
}
|
||||
@@ -420,6 +428,7 @@ class _$InitialImpl implements _Initial {
|
||||
TResult Function()? initial,
|
||||
TResult Function()? loading,
|
||||
TResult Function(List<TableModel> tables)? success,
|
||||
TResult Function(String message)? error,
|
||||
required TResult orElse(),
|
||||
}) {
|
||||
if (initial != null) {
|
||||
@@ -434,6 +443,7 @@ class _$InitialImpl implements _Initial {
|
||||
required TResult Function(_Initial value) initial,
|
||||
required TResult Function(_Loading value) loading,
|
||||
required TResult Function(_Success value) success,
|
||||
required TResult Function(_Error value) error,
|
||||
}) {
|
||||
return initial(this);
|
||||
}
|
||||
@@ -444,6 +454,7 @@ class _$InitialImpl implements _Initial {
|
||||
TResult? Function(_Initial value)? initial,
|
||||
TResult? Function(_Loading value)? loading,
|
||||
TResult? Function(_Success value)? success,
|
||||
TResult? Function(_Error value)? error,
|
||||
}) {
|
||||
return initial?.call(this);
|
||||
}
|
||||
@@ -454,6 +465,7 @@ class _$InitialImpl implements _Initial {
|
||||
TResult Function(_Initial value)? initial,
|
||||
TResult Function(_Loading value)? loading,
|
||||
TResult Function(_Success value)? success,
|
||||
TResult Function(_Error value)? error,
|
||||
required TResult orElse(),
|
||||
}) {
|
||||
if (initial != null) {
|
||||
@@ -511,6 +523,7 @@ class _$LoadingImpl implements _Loading {
|
||||
required TResult Function() initial,
|
||||
required TResult Function() loading,
|
||||
required TResult Function(List<TableModel> tables) success,
|
||||
required TResult Function(String message) error,
|
||||
}) {
|
||||
return loading();
|
||||
}
|
||||
@@ -521,6 +534,7 @@ class _$LoadingImpl implements _Loading {
|
||||
TResult? Function()? initial,
|
||||
TResult? Function()? loading,
|
||||
TResult? Function(List<TableModel> tables)? success,
|
||||
TResult? Function(String message)? error,
|
||||
}) {
|
||||
return loading?.call();
|
||||
}
|
||||
@@ -531,6 +545,7 @@ class _$LoadingImpl implements _Loading {
|
||||
TResult Function()? initial,
|
||||
TResult Function()? loading,
|
||||
TResult Function(List<TableModel> tables)? success,
|
||||
TResult Function(String message)? error,
|
||||
required TResult orElse(),
|
||||
}) {
|
||||
if (loading != null) {
|
||||
@@ -545,6 +560,7 @@ class _$LoadingImpl implements _Loading {
|
||||
required TResult Function(_Initial value) initial,
|
||||
required TResult Function(_Loading value) loading,
|
||||
required TResult Function(_Success value) success,
|
||||
required TResult Function(_Error value) error,
|
||||
}) {
|
||||
return loading(this);
|
||||
}
|
||||
@@ -555,6 +571,7 @@ class _$LoadingImpl implements _Loading {
|
||||
TResult? Function(_Initial value)? initial,
|
||||
TResult? Function(_Loading value)? loading,
|
||||
TResult? Function(_Success value)? success,
|
||||
TResult? Function(_Error value)? error,
|
||||
}) {
|
||||
return loading?.call(this);
|
||||
}
|
||||
@@ -565,6 +582,7 @@ class _$LoadingImpl implements _Loading {
|
||||
TResult Function(_Initial value)? initial,
|
||||
TResult Function(_Loading value)? loading,
|
||||
TResult Function(_Success value)? success,
|
||||
TResult Function(_Error value)? error,
|
||||
required TResult orElse(),
|
||||
}) {
|
||||
if (loading != null) {
|
||||
@@ -655,6 +673,7 @@ class _$SuccessImpl implements _Success {
|
||||
required TResult Function() initial,
|
||||
required TResult Function() loading,
|
||||
required TResult Function(List<TableModel> tables) success,
|
||||
required TResult Function(String message) error,
|
||||
}) {
|
||||
return success(tables);
|
||||
}
|
||||
@@ -665,6 +684,7 @@ class _$SuccessImpl implements _Success {
|
||||
TResult? Function()? initial,
|
||||
TResult? Function()? loading,
|
||||
TResult? Function(List<TableModel> tables)? success,
|
||||
TResult? Function(String message)? error,
|
||||
}) {
|
||||
return success?.call(tables);
|
||||
}
|
||||
@@ -675,6 +695,7 @@ class _$SuccessImpl implements _Success {
|
||||
TResult Function()? initial,
|
||||
TResult Function()? loading,
|
||||
TResult Function(List<TableModel> tables)? success,
|
||||
TResult Function(String message)? error,
|
||||
required TResult orElse(),
|
||||
}) {
|
||||
if (success != null) {
|
||||
@@ -689,6 +710,7 @@ class _$SuccessImpl implements _Success {
|
||||
required TResult Function(_Initial value) initial,
|
||||
required TResult Function(_Loading value) loading,
|
||||
required TResult Function(_Success value) success,
|
||||
required TResult Function(_Error value) error,
|
||||
}) {
|
||||
return success(this);
|
||||
}
|
||||
@@ -699,6 +721,7 @@ class _$SuccessImpl implements _Success {
|
||||
TResult? Function(_Initial value)? initial,
|
||||
TResult? Function(_Loading value)? loading,
|
||||
TResult? Function(_Success value)? success,
|
||||
TResult? Function(_Error value)? error,
|
||||
}) {
|
||||
return success?.call(this);
|
||||
}
|
||||
@@ -709,6 +732,7 @@ class _$SuccessImpl implements _Success {
|
||||
TResult Function(_Initial value)? initial,
|
||||
TResult Function(_Loading value)? loading,
|
||||
TResult Function(_Success value)? success,
|
||||
TResult Function(_Error value)? error,
|
||||
required TResult orElse(),
|
||||
}) {
|
||||
if (success != null) {
|
||||
@@ -729,3 +753,155 @@ abstract class _Success implements GetTableState {
|
||||
_$$SuccessImplCopyWith<_$SuccessImpl> get copyWith =>
|
||||
throw _privateConstructorUsedError;
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
abstract class _$$ErrorImplCopyWith<$Res> {
|
||||
factory _$$ErrorImplCopyWith(
|
||||
_$ErrorImpl value, $Res Function(_$ErrorImpl) then) =
|
||||
__$$ErrorImplCopyWithImpl<$Res>;
|
||||
@useResult
|
||||
$Res call({String message});
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
class __$$ErrorImplCopyWithImpl<$Res>
|
||||
extends _$GetTableStateCopyWithImpl<$Res, _$ErrorImpl>
|
||||
implements _$$ErrorImplCopyWith<$Res> {
|
||||
__$$ErrorImplCopyWithImpl(
|
||||
_$ErrorImpl _value, $Res Function(_$ErrorImpl) _then)
|
||||
: super(_value, _then);
|
||||
|
||||
/// Create a copy of GetTableState
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@pragma('vm:prefer-inline')
|
||||
@override
|
||||
$Res call({
|
||||
Object? message = null,
|
||||
}) {
|
||||
return _then(_$ErrorImpl(
|
||||
null == message
|
||||
? _value.message
|
||||
: message // ignore: cast_nullable_to_non_nullable
|
||||
as String,
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
|
||||
class _$ErrorImpl implements _Error {
|
||||
const _$ErrorImpl(this.message);
|
||||
|
||||
@override
|
||||
final String message;
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'GetTableState.error(message: $message)';
|
||||
}
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
return identical(this, other) ||
|
||||
(other.runtimeType == runtimeType &&
|
||||
other is _$ErrorImpl &&
|
||||
(identical(other.message, message) || other.message == message));
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode => Object.hash(runtimeType, message);
|
||||
|
||||
/// Create a copy of GetTableState
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||
@override
|
||||
@pragma('vm:prefer-inline')
|
||||
_$$ErrorImplCopyWith<_$ErrorImpl> get copyWith =>
|
||||
__$$ErrorImplCopyWithImpl<_$ErrorImpl>(this, _$identity);
|
||||
|
||||
@override
|
||||
@optionalTypeArgs
|
||||
TResult when<TResult extends Object?>({
|
||||
required TResult Function() initial,
|
||||
required TResult Function() loading,
|
||||
required TResult Function(List<TableModel> tables) success,
|
||||
required TResult Function(String message) error,
|
||||
}) {
|
||||
return error(message);
|
||||
}
|
||||
|
||||
@override
|
||||
@optionalTypeArgs
|
||||
TResult? whenOrNull<TResult extends Object?>({
|
||||
TResult? Function()? initial,
|
||||
TResult? Function()? loading,
|
||||
TResult? Function(List<TableModel> tables)? success,
|
||||
TResult? Function(String message)? error,
|
||||
}) {
|
||||
return error?.call(message);
|
||||
}
|
||||
|
||||
@override
|
||||
@optionalTypeArgs
|
||||
TResult maybeWhen<TResult extends Object?>({
|
||||
TResult Function()? initial,
|
||||
TResult Function()? loading,
|
||||
TResult Function(List<TableModel> tables)? success,
|
||||
TResult Function(String message)? error,
|
||||
required TResult orElse(),
|
||||
}) {
|
||||
if (error != null) {
|
||||
return error(message);
|
||||
}
|
||||
return orElse();
|
||||
}
|
||||
|
||||
@override
|
||||
@optionalTypeArgs
|
||||
TResult map<TResult extends Object?>({
|
||||
required TResult Function(_Initial value) initial,
|
||||
required TResult Function(_Loading value) loading,
|
||||
required TResult Function(_Success value) success,
|
||||
required TResult Function(_Error value) error,
|
||||
}) {
|
||||
return error(this);
|
||||
}
|
||||
|
||||
@override
|
||||
@optionalTypeArgs
|
||||
TResult? mapOrNull<TResult extends Object?>({
|
||||
TResult? Function(_Initial value)? initial,
|
||||
TResult? Function(_Loading value)? loading,
|
||||
TResult? Function(_Success value)? success,
|
||||
TResult? Function(_Error value)? error,
|
||||
}) {
|
||||
return error?.call(this);
|
||||
}
|
||||
|
||||
@override
|
||||
@optionalTypeArgs
|
||||
TResult maybeMap<TResult extends Object?>({
|
||||
TResult Function(_Initial value)? initial,
|
||||
TResult Function(_Loading value)? loading,
|
||||
TResult Function(_Success value)? success,
|
||||
TResult Function(_Error value)? error,
|
||||
required TResult orElse(),
|
||||
}) {
|
||||
if (error != null) {
|
||||
return error(this);
|
||||
}
|
||||
return orElse();
|
||||
}
|
||||
}
|
||||
|
||||
abstract class _Error implements GetTableState {
|
||||
const factory _Error(final String message) = _$ErrorImpl;
|
||||
|
||||
String get message;
|
||||
|
||||
/// Create a copy of GetTableState
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||
_$$ErrorImplCopyWith<_$ErrorImpl> get copyWith =>
|
||||
throw _privateConstructorUsedError;
|
||||
}
|
||||
|
||||
@@ -5,4 +5,5 @@ class GetTableState with _$GetTableState {
|
||||
const factory GetTableState.initial() = _Initial;
|
||||
const factory GetTableState.loading() = _Loading;
|
||||
const factory GetTableState.success(List<TableModel> tables) = _Success;
|
||||
const factory GetTableState.error(String message) = _Error;
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:enaklo_pos/core/components/components.dart';
|
||||
import 'package:enaklo_pos/core/constants/colors.dart';
|
||||
import 'package:enaklo_pos/core/extensions/build_context_ext.dart';
|
||||
import 'package:enaklo_pos/presentation/table/blocs/change_position_table/change_position_table_bloc.dart';
|
||||
import 'package:enaklo_pos/presentation/table/blocs/create_table/create_table_bloc.dart';
|
||||
import 'package:enaklo_pos/presentation/table/blocs/get_table/get_table_bloc.dart';
|
||||
@@ -94,8 +93,8 @@ class _TableManagementScreenState extends State<TableManagementScreen> {
|
||||
return Stack(
|
||||
children: tables.map((table) {
|
||||
return Positioned(
|
||||
left: table.position.dx - 116,
|
||||
top: table.position.dy - 80,
|
||||
left: (table.positionX ?? 0) - 116,
|
||||
top: (table.positionY ?? 0) - 80,
|
||||
child: BlocListener<ChangePositionTableBloc,
|
||||
ChangePositionTableState>(
|
||||
listener: (context, state) {
|
||||
@@ -111,12 +110,12 @@ class _TableManagementScreenState extends State<TableManagementScreen> {
|
||||
feedback: TableWidget(table: table),
|
||||
childWhenDragging: SizedBox.shrink(),
|
||||
onDragEnd: (details) {
|
||||
context
|
||||
.read<ChangePositionTableBloc>()
|
||||
.add(ChangePositionTableEvent.changePositionTable(
|
||||
tableId: table.id!,
|
||||
position: details.offset,
|
||||
));
|
||||
// context
|
||||
// .read<ChangePositionTableBloc>()
|
||||
// .add(ChangePositionTableEvent.changePositionTable(
|
||||
// tableId: table.id,
|
||||
// position: details.offset,
|
||||
// ));
|
||||
},
|
||||
child: TableWidget(table: table),
|
||||
),
|
||||
|
||||
@@ -51,18 +51,18 @@ class _PaymentTablePageState extends State<PaymentTablePage> {
|
||||
Future<void> _handlePostPaymentCleanup() async {
|
||||
if (widget.table != null && widget.draftOrder?.id != null) {
|
||||
// Update table status to available
|
||||
final newTable = TableModel(
|
||||
id: widget.table!.id,
|
||||
tableName: widget.table!.tableName,
|
||||
status: 'available',
|
||||
orderId: 0,
|
||||
paymentAmount: 0,
|
||||
startTime: DateTime.now().toIso8601String(),
|
||||
position: widget.table!.position,
|
||||
);
|
||||
// final newTable = TableModel(
|
||||
// id: widget.table!.id,
|
||||
// tableName: widget.table!.tableName,
|
||||
// status: 'available',
|
||||
// orderId: 0,
|
||||
// paymentAmount: 0,
|
||||
// startTime: DateTime.now().toIso8601String(),
|
||||
// position: widget.table!.position,
|
||||
// );
|
||||
|
||||
// Update table status
|
||||
await ProductLocalDatasource.instance.updateStatusTable(newTable);
|
||||
// await ProductLocalDatasource.instance.updateStatusTable(newTable);
|
||||
|
||||
// Remove draft order
|
||||
await ProductLocalDatasource.instance
|
||||
@@ -965,25 +965,25 @@ class _PaymentTablePageState extends State<PaymentTablePage> {
|
||||
onPressed: () {
|
||||
// Void the order
|
||||
if (widget.table != null) {
|
||||
final newTable = TableModel(
|
||||
id: widget.table!.id,
|
||||
tableName: widget
|
||||
.table!.tableName,
|
||||
status: 'available',
|
||||
orderId: 0,
|
||||
paymentAmount: 0,
|
||||
startTime: DateTime.now()
|
||||
.toIso8601String(),
|
||||
position: widget
|
||||
.table!.position,
|
||||
);
|
||||
context
|
||||
.read<StatusTableBloc>()
|
||||
.add(
|
||||
StatusTableEvent
|
||||
.statusTabel(
|
||||
newTable),
|
||||
);
|
||||
// final newTable = TableModel(
|
||||
// id: widget.table!.id,
|
||||
// tableName: widget
|
||||
// .table!.tableName,
|
||||
// status: 'available',
|
||||
// orderId: 0,
|
||||
// paymentAmount: 0,
|
||||
// startTime: DateTime.now()
|
||||
// .toIso8601String(),
|
||||
// position: widget
|
||||
// .table!.position,
|
||||
// );
|
||||
// context
|
||||
// .read<StatusTableBloc>()
|
||||
// .add(
|
||||
// StatusTableEvent
|
||||
// .statusTabel(
|
||||
// newTable),
|
||||
// );
|
||||
}
|
||||
// Remove draft order from local storage
|
||||
if (widget.draftOrder?.id !=
|
||||
@@ -1013,21 +1013,21 @@ class _PaymentTablePageState extends State<PaymentTablePage> {
|
||||
const SpaceWidth(8.0),
|
||||
BlocListener<OrderBloc, OrderState>(
|
||||
listener: (context, state) {
|
||||
final newTable = TableModel(
|
||||
id: widget.table!.id,
|
||||
tableName: widget.table!.tableName,
|
||||
status: 'available',
|
||||
orderId: 0,
|
||||
paymentAmount: 0,
|
||||
startTime:
|
||||
DateTime.now().toIso8601String(),
|
||||
position: widget.table!.position,
|
||||
);
|
||||
context.read<StatusTableBloc>().add(
|
||||
StatusTableEvent.statusTabel(
|
||||
newTable,
|
||||
),
|
||||
);
|
||||
// final newTable = TableModel(
|
||||
// id: widget.table!.id,
|
||||
// tableName: widget.table!.tableName,
|
||||
// status: 'available',
|
||||
// orderId: 0,
|
||||
// paymentAmount: 0,
|
||||
// startTime:
|
||||
// DateTime.now().toIso8601String(),
|
||||
// position: widget.table!.position,
|
||||
// );
|
||||
// context.read<StatusTableBloc>().add(
|
||||
// StatusTableEvent.statusTabel(
|
||||
// newTable,
|
||||
// ),
|
||||
// );
|
||||
ProductLocalDatasource.instance
|
||||
.removeDraftOrderById(
|
||||
widget.draftOrder!.id!);
|
||||
@@ -1160,24 +1160,24 @@ class _PaymentTablePageState extends State<PaymentTablePage> {
|
||||
'uang tunai' ||
|
||||
paymentMethodName ==
|
||||
'cash payment') {
|
||||
context.read<OrderBloc>().add(
|
||||
OrderEvent.order(
|
||||
items,
|
||||
discount,
|
||||
discountAmountFinal,
|
||||
finalTax.toInt(),
|
||||
0,
|
||||
totalPriceController.text
|
||||
.toIntegerFromText,
|
||||
customerController.text,
|
||||
widget.table?.id ?? 0,
|
||||
'completed',
|
||||
'paid',
|
||||
selectedPaymentMethod
|
||||
?.name ??
|
||||
'Cash',
|
||||
totalPriceFinal,
|
||||
orderType));
|
||||
// context.read<OrderBloc>().add(
|
||||
// OrderEvent.order(
|
||||
// items,
|
||||
// discount,
|
||||
// discountAmountFinal,
|
||||
// finalTax.toInt(),
|
||||
// 0,
|
||||
// totalPriceController.text
|
||||
// .toIntegerFromText,
|
||||
// customerController.text,
|
||||
// widget.table?.id ?? 0,
|
||||
// 'completed',
|
||||
// 'paid',
|
||||
// selectedPaymentMethod
|
||||
// ?.name ??
|
||||
// 'Cash',
|
||||
// totalPriceFinal,
|
||||
// orderType));
|
||||
|
||||
await showDialog(
|
||||
context: context,
|
||||
@@ -1202,24 +1202,24 @@ class _PaymentTablePageState extends State<PaymentTablePage> {
|
||||
await _handlePostPaymentCleanup();
|
||||
} else {
|
||||
log("Processing non-cash payment: ${selectedPaymentMethod?.name}");
|
||||
context.read<OrderBloc>().add(
|
||||
OrderEvent.order(
|
||||
items,
|
||||
discount,
|
||||
discountAmountFinal,
|
||||
finalTax.toInt(),
|
||||
0,
|
||||
totalPriceController.text
|
||||
.toIntegerFromText,
|
||||
customerController.text,
|
||||
widget.table?.id ?? 0,
|
||||
'completed',
|
||||
'paid',
|
||||
selectedPaymentMethod
|
||||
?.name ??
|
||||
'Unknown Payment Method',
|
||||
totalPriceFinal,
|
||||
orderType));
|
||||
// context.read<OrderBloc>().add(
|
||||
// OrderEvent.order(
|
||||
// items,
|
||||
// discount,
|
||||
// discountAmountFinal,
|
||||
// finalTax.toInt(),
|
||||
// 0,
|
||||
// totalPriceController.text
|
||||
// .toIntegerFromText,
|
||||
// customerController.text,
|
||||
// widget.table?.id ?? 0,
|
||||
// 'completed',
|
||||
// 'paid',
|
||||
// selectedPaymentMethod
|
||||
// ?.name ??
|
||||
// 'Unknown Payment Method',
|
||||
// totalPriceFinal,
|
||||
// orderType));
|
||||
|
||||
await showDialog(
|
||||
context: context,
|
||||
|
||||
@@ -39,8 +39,8 @@ class _CardTableWidgetState extends State<CardTableWidget> {
|
||||
|
||||
loadData() async {
|
||||
if (widget.table.status != 'available') {
|
||||
data = await ProductLocalDatasource.instance
|
||||
.getDraftOrderById(widget.table.orderId);
|
||||
// data = await ProductLocalDatasource.instance
|
||||
// .getDraftOrderById(widget.table.orderId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,9 +70,10 @@ class _CardTableWidgetState extends State<CardTableWidget> {
|
||||
),
|
||||
),
|
||||
Text(
|
||||
widget.table.status == 'available'
|
||||
? widget.table.status
|
||||
: "${widget.table.status} - ${DateTime.parse(widget.table.startTime).toFormattedTime()}",
|
||||
// widget.table.status == 'available'
|
||||
// ? widget.table.status
|
||||
// : "${widget.table.status} - ${DateTime.parse(widget.table.startTime).toFormattedTime()}",
|
||||
"",
|
||||
style: TextStyle(
|
||||
color: AppColors.black,
|
||||
fontSize: 24,
|
||||
|
||||
@@ -51,8 +51,8 @@ class _TableWidgetState extends State<TableWidget> {
|
||||
|
||||
loadData() async {
|
||||
if (widget.table.status != 'available') {
|
||||
data = await ProductLocalDatasource.instance
|
||||
.getDraftOrderById(widget.table.orderId);
|
||||
// data = await ProductLocalDatasource.instance
|
||||
// .getDraftOrderById(widget.table.orderId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -136,33 +136,33 @@ class _TableWidgetState extends State<TableWidget> {
|
||||
Expanded(
|
||||
child: Button.filled(
|
||||
onPressed: () {
|
||||
final newData =
|
||||
TableModel(
|
||||
id: widget.table.id,
|
||||
tableName:
|
||||
tableNameController!
|
||||
.text,
|
||||
status:
|
||||
widget.table.status,
|
||||
startTime: widget
|
||||
.table.startTime,
|
||||
orderId: widget
|
||||
.table.orderId,
|
||||
paymentAmount: widget
|
||||
.table
|
||||
.paymentAmount,
|
||||
position: widget
|
||||
.table.position,
|
||||
);
|
||||
context
|
||||
.read<
|
||||
UpdateTableBloc>()
|
||||
.add(
|
||||
UpdateTableEvent
|
||||
.updateTable(
|
||||
newData,
|
||||
),
|
||||
);
|
||||
// final newData =
|
||||
// TableModel(
|
||||
// id: widget.table.id,
|
||||
// tableName:
|
||||
// tableNameController!
|
||||
// .text,
|
||||
// status:
|
||||
// widget.table.status,
|
||||
// startTime: widget
|
||||
// .table.startTime,
|
||||
// orderId: widget
|
||||
// .table.orderId,
|
||||
// paymentAmount: widget
|
||||
// .table
|
||||
// .paymentAmount,
|
||||
// position: widget
|
||||
// .table.position,
|
||||
// );
|
||||
// context
|
||||
// .read<
|
||||
// UpdateTableBloc>()
|
||||
// .add(
|
||||
// UpdateTableEvent
|
||||
// .updateTable(
|
||||
// newData,
|
||||
// ),
|
||||
// );
|
||||
context
|
||||
.pop(); // close dialog after adding
|
||||
},
|
||||
@@ -194,16 +194,16 @@ class _TableWidgetState extends State<TableWidget> {
|
||||
color: widget.table.status == 'available'
|
||||
? Colors.green
|
||||
: Colors.red),
|
||||
widget.table.status == 'available'
|
||||
? SizedBox.shrink()
|
||||
: _buildInfoRow(
|
||||
'Start Time:',
|
||||
DateFormatter.formatDateTime2(
|
||||
widget.table.startTime)),
|
||||
widget.table.status == 'available'
|
||||
? SizedBox.shrink()
|
||||
: _buildInfoRow(
|
||||
'Order ID:', widget.table.orderId.toString()),
|
||||
// widget.table.status == 'available'
|
||||
// ? SizedBox.shrink()
|
||||
// : _buildInfoRow(
|
||||
// 'Start Time:',
|
||||
// DateFormatter.formatDateTime2(
|
||||
// widget.table.startTime)),
|
||||
// widget.table.status == 'available'
|
||||
// ? SizedBox.shrink()
|
||||
// : _buildInfoRow(
|
||||
// 'Order ID:', widget.table.orderId.toString()),
|
||||
widget.table.status == 'available'
|
||||
? SizedBox.shrink()
|
||||
: SpaceHeight(16),
|
||||
@@ -267,29 +267,29 @@ class _TableWidgetState extends State<TableWidget> {
|
||||
backgroundColor: AppColors.red,
|
||||
),
|
||||
onPressed: () {
|
||||
// Void the order
|
||||
final newTable = TableModel(
|
||||
id: widget.table.id,
|
||||
tableName:
|
||||
widget.table.tableName,
|
||||
status: 'available',
|
||||
orderId: 0,
|
||||
paymentAmount: 0,
|
||||
startTime: DateTime.now()
|
||||
.toIso8601String(),
|
||||
position: widget.table.position,
|
||||
);
|
||||
context
|
||||
.read<StatusTableBloc>()
|
||||
.add(
|
||||
StatusTableEvent
|
||||
.statusTabel(newTable),
|
||||
);
|
||||
// Remove draft order from local storage
|
||||
ProductLocalDatasource.instance
|
||||
.removeDraftOrderById(
|
||||
widget.table.orderId);
|
||||
log("Voided order for table: ${widget.table.tableName}");
|
||||
// // Void the order
|
||||
// final newTable = TableModel(
|
||||
// id: widget.table.id,
|
||||
// tableName:
|
||||
// widget.table.tableName,
|
||||
// status: 'available',
|
||||
// orderId: 0,
|
||||
// paymentAmount: 0,
|
||||
// startTime: DateTime.now()
|
||||
// .toIso8601String(),
|
||||
// position: widget.table.position,
|
||||
// );
|
||||
// context
|
||||
// .read<StatusTableBloc>()
|
||||
// .add(
|
||||
// StatusTableEvent
|
||||
// .statusTabel(newTable),
|
||||
// );
|
||||
// // Remove draft order from local storage
|
||||
// ProductLocalDatasource.instance
|
||||
// .removeDraftOrderById(
|
||||
// widget.table.orderId);
|
||||
// log("Voided order for table: ${widget.table.tableName}");
|
||||
},
|
||||
child: const Text(
|
||||
"Ya, Batalkan",
|
||||
|
||||
Reference in New Issue
Block a user