feat: get table

This commit is contained in:
efrilm 2025-08-03 23:53:06 +07:00
parent 8431b07057
commit 6afd62b617
14 changed files with 769 additions and 478 deletions

View File

@ -358,19 +358,19 @@ class ProductLocalDatasource {
// generate table managent with count
Future<void> createTableManagement(String tableName, Offset position) async {
final db = await instance.database;
TableModel newTable = TableModel(
tableName: tableName,
status: 'available',
orderId: 0,
paymentAmount: 0,
startTime: DateTime.now().toIso8601String(),
position: position,
);
await db.insert(
tableManagement,
newTable.toMap(),
);
// final db = await instance.database;
// TableModel newTable = TableModel(
// tableName: tableName,
// status: 'available',
// orderId: 0,
// paymentAmount: 0,
// startTime: DateTime.now().toIso8601String(),
// position: position,
// );
// await db.insert(
// tableManagement,
// newTable.toMap(),
// );
}
// change position table

View File

@ -2,6 +2,7 @@ import 'dart:developer';
import 'package:dartz/dartz.dart';
import 'package:dio/dio.dart';
import 'package:enaklo_pos/core/network/dio_client.dart';
import 'package:enaklo_pos/data/models/response/table_model.dart';
import '../../core/constants/variables.dart';
import 'auth_local_datasource.dart';
@ -50,4 +51,41 @@ class TableRemoteDataSource {
return const Left('Unexpected error occurred');
}
}
Future<Either<String, TableResponseModel>> getTable({
int page = 1,
int limit = 10,
}) async {
try {
final authData = await AuthLocalDataSource().getAuthData();
final url = '${Variables.baseUrl}/api/v1/tables';
final response = await dio.get(
url,
queryParameters: {
'page': page,
'limit': limit,
'outlet_id': authData.user?.outletId,
},
options: Options(
headers: {
'Authorization': 'Bearer ${authData.token}',
'Accept': 'application/json',
},
),
);
if (response.statusCode == 200) {
return Right(TableResponseModel.fromMap(response.data));
} else {
return const Left('Failed to get tables');
}
} on DioException catch (e) {
log("Dio error: ${e.message}");
return Left(e.response?.data['message'] ?? 'Gagal mengambil data meja');
} catch (e) {
log("Unexpected error: $e");
return const Left('Unexpected error occurred');
}
}
}

View File

@ -1,74 +1,132 @@
// ignore_for_file: public_member_api_docs, sort_constructors_first
import 'dart:ui';
import 'dart:convert';
class TableResponseModel {
final bool? success;
final TableData? data;
final dynamic errors;
TableResponseModel({
this.success,
this.data,
this.errors,
});
factory TableResponseModel.fromJson(String str) =>
TableResponseModel.fromMap(json.decode(str));
String toJson() => json.encode(toMap());
factory TableResponseModel.fromMap(Map<String, dynamic> json) =>
TableResponseModel(
success: json["success"],
data: json["data"] == null ? null : TableData.fromMap(json["data"]),
errors: json["errors"],
);
Map<String, dynamic> toMap() => {
"success": success,
"data": data?.toMap(),
"errors": errors,
};
}
class TableData {
final List<TableModel>? tables;
final int? totalCount;
final int? page;
final int? limit;
final int? totalPages;
TableData({
this.tables,
this.totalCount,
this.page,
this.limit,
this.totalPages,
});
factory TableData.fromMap(Map<String, dynamic> json) => TableData(
tables: json["tables"] == null
? []
: List<TableModel>.from(
json["tables"].map((x) => TableModel.fromMap(x))),
totalCount: json["total_count"],
page: json["page"],
limit: json["limit"],
totalPages: json["total_pages"],
);
Map<String, dynamic> toMap() => {
"tables": tables == null
? []
: List<dynamic>.from(tables!.map((x) => x.toMap())),
"total_count": totalCount,
"page": page,
"limit": limit,
"total_pages": totalPages,
};
}
class TableModel {
int? id;
final String tableName;
final String startTime;
final String status;
final int orderId;
final int paymentAmount;
final Offset position;
final String? id;
final String? organizationId;
final String? outletId;
final String? tableName;
final String? status;
final int? paymentAmount;
final double? positionX;
final double? positionY;
final int? capacity;
final bool? isActive;
final DateTime? createdAt;
final DateTime? updatedAt;
TableModel({
this.id,
required this.tableName,
required this.startTime,
required this.status,
required this.orderId,
required this.paymentAmount,
required this.position,
this.organizationId,
this.outletId,
this.tableName,
this.status,
this.paymentAmount,
this.positionX,
this.positionY,
this.capacity,
this.isActive,
this.createdAt,
this.updatedAt,
});
@override
factory TableModel.fromMap(Map<String, dynamic> json) => TableModel(
id: json["id"],
organizationId: json["organization_id"],
outletId: json["outlet_id"],
tableName: json["table_name"],
status: json["status"],
paymentAmount: json["payment_amount"],
positionX: json["position_x"]?.toDouble(),
positionY: json["position_y"]?.toDouble(),
capacity: json["capacity"],
isActive: json["is_active"],
createdAt: json["created_at"] == null
? null
: DateTime.parse(json["created_at"]),
updatedAt: json["updated_at"] == null
? null
: DateTime.parse(json["updated_at"]),
);
// from map
factory TableModel.fromMap(Map<String, dynamic> map) {
return TableModel(
id: map['id'],
tableName: map['table_name'],
startTime: map['start_time'],
status: map['status'],
orderId: map['order_id'],
paymentAmount: map['payment_amount'],
position: Offset(map['x_position'], map['y_position']),
);
}
// to map
Map<String, dynamic> toMap() {
return {
'table_name': tableName,
'status': status,
'start_time': startTime,
'order_id': orderId,
'payment_amount': paymentAmount,
'x_position': position.dx,
'y_position': position.dy,
};
}
@override
bool operator ==(covariant TableModel other) {
if (identical(this, other)) return true;
return other.id == id &&
other.tableName == tableName &&
other.startTime == startTime &&
other.status == status &&
other.orderId == orderId &&
other.paymentAmount == paymentAmount &&
other.position == position;
}
@override
int get hashCode {
return id.hashCode ^
tableName.hashCode ^
startTime.hashCode ^
status.hashCode ^
orderId.hashCode ^
paymentAmount.hashCode ^
position.hashCode;
}
Map<String, dynamic> toMap() => {
"id": id,
"organization_id": organizationId,
"outlet_id": outletId,
"table_name": tableName,
"status": status,
"payment_amount": paymentAmount,
"position_x": positionX,
"position_y": positionY,
"capacity": capacity,
"is_active": isActive,
"created_at": createdAt?.toIso8601String(),
"updated_at": updatedAt?.toIso8601String(),
};
}

View File

@ -154,7 +154,7 @@ class _MyAppState extends State<MyApp> {
create: (context) => ChangePositionTableBloc(),
),
BlocProvider(
create: (context) => GetTableBloc(),
create: (context) => GetTableBloc(TableRemoteDataSource()),
),
BlocProvider(
create: (context) => UpdateTableBloc(),

View File

@ -117,7 +117,7 @@ class _PaymentSaveDialogState extends State<PaymentSaveDialog> {
(TableModel value) =>
DropdownMenuItem<TableModel>(
value: value,
child: Text(value.tableName),
child: Text(value.tableName ?? ""),
),
)
.toList(),

View File

@ -829,7 +829,8 @@ class _ConfirmPaymentPageState extends State<ConfirmPaymentPage> {
DropdownMenuItem<
TableModel>(
value: value,
child: Text(value.tableName),
child: Text(
value.tableName ?? ""),
),
)
.toList(),
@ -1192,28 +1193,28 @@ class _ConfirmPaymentPageState extends State<ConfirmPaymentPage> {
savedDraftOrder: (orderDraftId) {
log("PRICEVALUE: ${priceValue}");
final newTabel = TableModel(
id: widget.isTable
? widget.table!.id
: selectTable?.id,
tableName: widget.isTable
? widget.table!.tableName
: selectTable?.tableName ??
'0',
status: 'occupied',
paymentAmount: priceValue,
orderId: orderDraftId,
startTime: DateTime.now()
.toIso8601String(),
position: widget.isTable
? widget.table!.position
: selectTable!.position);
log('new tabel: ${newTabel.toMap()}');
context
.read<StatusTableBloc>()
.add(StatusTableEvent.statusTabel(
newTabel,
));
// final newTabel = TableModel(
// id: widget.isTable
// ? widget.table!.id
// : selectTable?.id,
// tableName: widget.isTable
// ? widget.table!.tableName
// : selectTable?.tableName ??
// '0',
// status: 'occupied',
// paymentAmount: priceValue,
// orderId: orderDraftId,
// startTime: DateTime.now()
// .toIso8601String(),
// position: widget.isTable
// ? widget.table!.position
// : selectTable!.position);
// log('new tabel: ${newTabel.toMap()}');
// context
// .read<StatusTableBloc>()
// .add(StatusTableEvent.statusTabel(
// newTabel,
// ));
});
},
child:
@ -1357,16 +1358,16 @@ class _ConfirmPaymentPageState extends State<ConfirmPaymentPage> {
if (widget.isTable) {
log("discountAmountValue: $totalDiscount");
context.read<CheckoutBloc>().add(
CheckoutEvent
.saveDraftOrder(
widget.isTable == true
? widget.table!.id!
: selectTable!.id!,
customerController.text,
totalDiscount.toInt(),
),
);
// context.read<CheckoutBloc>().add(
// CheckoutEvent
// .saveDraftOrder(
// widget.isTable == true
// ? widget.table!.id!
// : selectTable!.id!,
// customerController.text,
// totalDiscount.toInt(),
// ),
// );
await showDialog(
context: context,
barrierDismissible: false,
@ -1515,120 +1516,120 @@ class _ConfirmPaymentPageState extends State<ConfirmPaymentPage> {
// Tambahkan ke pesanan meja yang sudah ada
if (selectTable != null) {
// Ambil draft order yang sudah ada
final existingDraftOrder =
await ProductLocalDatasource
.instance
.getDraftOrderById(
selectTable
?.orderId ??
0);
// final existingDraftOrder =
// await ProductLocalDatasource
// .instance
// .getDraftOrderById(
// selectTable
// ?.orderId ??
// 0);
if (existingDraftOrder !=
null) {
// Convert items ke DraftOrderItem
final newDraftItems = items
.map((item) =>
DraftOrderItem(
product:
item.product,
quantity:
item.quantity,
))
.toList();
// if (existingDraftOrder !=
// null) {
// // Convert items ke DraftOrderItem
// final newDraftItems = items
// .map((item) =>
// DraftOrderItem(
// product:
// item.product,
// quantity:
// item.quantity,
// ))
// .toList();
// Gabungkan dengan pesanan yang sudah ada
final updatedItems = [
...existingDraftOrder
.orders,
...newDraftItems
];
// // Gabungkan dengan pesanan yang sudah ada
// final updatedItems = [
// ...existingDraftOrder
// .orders,
// ...newDraftItems
// ];
final updatedDraftOrder =
existingDraftOrder
.copyWith(
orders: updatedItems,
totalQuantity:
updatedItems.fold<int>(
0,
(sum, item) =>
sum +
item.quantity),
subTotal: updatedItems.fold<
int>(
0,
(sum, item) =>
sum +
(item.product
.price ??
0) *
item.quantity),
);
// final updatedDraftOrder =
// existingDraftOrder
// .copyWith(
// orders: updatedItems,
// totalQuantity:
// updatedItems.fold<int>(
// 0,
// (sum, item) =>
// sum +
// item.quantity),
// subTotal: updatedItems.fold<
// int>(
// 0,
// (sum, item) =>
// sum +
// (item.product
// .price ??
// 0) *
// item.quantity),
// );
// Update draft order
await ProductLocalDatasource
.instance
.updateDraftOrder(
updatedDraftOrder);
// // Update draft order
// await ProductLocalDatasource
// .instance
// .updateDraftOrder(
// updatedDraftOrder);
// Tampilkan dialog sukses
await showDialog(
context: context,
barrierDismissible: false,
builder: (context) =>
SaveOrderDialog(
data: items,
totalQty: totalQty,
totalPrice:
totalPriceFinal,
totalTax:
finalTax.toInt(),
totalDiscount:
totalDiscount.toInt(),
subTotal:
subTotal.toInt(),
normalPrice: price,
table: selectTable!,
draftName:
customerController
.text,
),
);
} else {
// Jika tidak ada draft order, buat baru
context
.read<CheckoutBloc>()
.add(
CheckoutEvent
.saveDraftOrder(
selectTable!.id!,
customerController
.text,
totalDiscount.toInt(),
),
);
await showDialog(
context: context,
barrierDismissible: false,
builder: (context) =>
SaveOrderDialog(
data: items,
totalQty: totalQty,
totalPrice:
totalPriceFinal,
totalTax:
finalTax.toInt(),
totalDiscount:
totalDiscount.toInt(),
subTotal:
subTotal.toInt(),
normalPrice: price,
table: selectTable!,
draftName:
customerController
.text,
),
);
}
// // Tampilkan dialog sukses
// await showDialog(
// context: context,
// barrierDismissible: false,
// builder: (context) =>
// SaveOrderDialog(
// data: items,
// totalQty: totalQty,
// totalPrice:
// totalPriceFinal,
// totalTax:
// finalTax.toInt(),
// totalDiscount:
// totalDiscount.toInt(),
// subTotal:
// subTotal.toInt(),
// normalPrice: price,
// table: selectTable!,
// draftName:
// customerController
// .text,
// ),
// );
// } else {
// // Jika tidak ada draft order, buat baru
// context
// .read<CheckoutBloc>()
// .add(
// CheckoutEvent
// .saveDraftOrder(
// selectTable!.id!,
// customerController
// .text,
// totalDiscount.toInt(),
// ),
// );
// await showDialog(
// context: context,
// barrierDismissible: false,
// builder: (context) =>
// SaveOrderDialog(
// data: items,
// totalQty: totalQty,
// totalPrice:
// totalPriceFinal,
// totalTax:
// finalTax.toInt(),
// totalDiscount:
// totalDiscount.toInt(),
// subTotal:
// subTotal.toInt(),
// normalPrice: price,
// table: selectTable!,
// draftName:
// customerController
// .text,
// ),
// );
// }
} else {
ScaffoldMessenger.of(context)
.showSnackBar(
@ -1640,16 +1641,16 @@ class _ConfirmPaymentPageState extends State<ConfirmPaymentPage> {
);
}
} else {
context.read<CheckoutBloc>().add(
CheckoutEvent
.saveDraftOrder(
widget.isTable == true
? widget.table!.id!
: selectTable!.id!,
customerController.text,
totalDiscount.toInt(),
),
);
// context.read<CheckoutBloc>().add(
// CheckoutEvent
// .saveDraftOrder(
// widget.isTable == true
// ? widget.table!.id!
// : selectTable!.id!,
// customerController.text,
// totalDiscount.toInt(),
// ),
// );
await showDialog(
context: context,
barrierDismissible: false,

View File

@ -97,98 +97,108 @@ class _SaveOrderDialogState extends State<SaveOrderDialog> {
builder: (context, state) {
final orderType = state.maybeWhen(
orElse: () => OrderType.dineIn,
loaded: (items, discountModel, discount, discountAmount, tax, serviceCharge, totalQuantity, totalPrice, draftName, orderType) => orderType,
loaded: (items,
discountModel,
discount,
discountAmount,
tax,
serviceCharge,
totalQuantity,
totalPrice,
draftName,
orderType) =>
orderType,
);
return Button.filled(
onPressed: () async {
final checkerPrinter = await ProductLocalDatasource
.instance
.getPrinterByCode('checker');
final kitchenPrinter = await ProductLocalDatasource
.instance
.getPrinterByCode('kitchen');
final barPrinter = await ProductLocalDatasource.instance
.getPrinterByCode('bar');
log("Checker printer: ${checkerPrinter?.toMap()}");
log("Kitchen printer: ${kitchenPrinter?.toMap()}");
log("Bar printer: ${barPrinter?.toMap()}");
// Checker printer
if (checkerPrinter != null) {
try {
final printValue = await PrintDataoutputs.instance
.printChecker(
widget.data,
widget.table.tableName,
widget.draftName,
'kasir',
checkerPrinter.paper.toIntegerFromText,
orderType.value);
await PrinterService().printWithPrinter(
checkerPrinter,
printValue,
context
);
} catch (e) {
log("Error printing checker: $e");
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text('Error printing checker: $e')),
);
}
}
final checkerPrinter = await ProductLocalDatasource
.instance
.getPrinterByCode('checker');
final kitchenPrinter = await ProductLocalDatasource
.instance
.getPrinterByCode('kitchen');
final barPrinter = await ProductLocalDatasource
.instance
.getPrinterByCode('bar');
// Kitchen printer
if (kitchenPrinter != null) {
try {
final printValue = await PrintDataoutputs.instance.printKitchen(
widget.data,
widget.table.tableName,
widget.draftName,
'kasir',
kitchenPrinter.paper.toIntegerFromText,
orderType.value,
);
await PrinterService().printWithPrinter(
kitchenPrinter,
printValue,
context
);
} catch (e) {
log("Error printing kitchen order: $e");
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text('Error printing kitchen order: $e')),
);
}
}
log("Checker printer: ${checkerPrinter?.toMap()}");
log("Kitchen printer: ${kitchenPrinter?.toMap()}");
log("Bar printer: ${barPrinter?.toMap()}");
// Bar printer
if (barPrinter != null) {
try {
final printValue = await PrintDataoutputs.instance.printBar(
widget.data,
widget.table.tableName,
widget.draftName,
'kasir',
barPrinter.paper.toIntegerFromText,
orderType.value,
);
await PrinterService().printWithPrinter(
barPrinter,
printValue,
context
);
} catch (e) {
log("Error printing bar order: $e");
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text('Error printing bar order: $e')),
);
}
}
// Checker printer
if (checkerPrinter != null) {
try {
final printValue = await PrintDataoutputs.instance
.printChecker(
widget.data,
widget.table.tableName!,
widget.draftName,
'kasir',
checkerPrinter.paper.toIntegerFromText,
orderType.value);
await PrinterService().printWithPrinter(
checkerPrinter, printValue, context);
} catch (e) {
log("Error printing checker: $e");
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content:
Text('Error printing checker: $e')),
);
}
}
// Kitchen printer
if (kitchenPrinter != null) {
try {
final printValue =
await PrintDataoutputs.instance.printKitchen(
widget.data,
widget.table.tableName!,
widget.draftName,
'kasir',
kitchenPrinter.paper.toIntegerFromText,
orderType.value,
);
await PrinterService().printWithPrinter(
kitchenPrinter, printValue, context);
} catch (e) {
log("Error printing kitchen order: $e");
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(
'Error printing kitchen order: $e')),
);
}
}
// Bar printer
if (barPrinter != null) {
try {
final printValue =
await PrintDataoutputs.instance.printBar(
widget.data,
widget.table.tableName!,
widget.draftName,
'kasir',
barPrinter.paper.toIntegerFromText,
orderType.value,
);
await PrinterService().printWithPrinter(
barPrinter, printValue, context);
} catch (e) {
log("Error printing bar order: $e");
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content:
Text('Error printing bar order: $e')),
);
}
}
},
label: 'Print Checker',
);

View File

@ -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!),
),
);
});
}
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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),
),

View File

@ -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,

View File

@ -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,

View File

@ -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",