2025-08-04 12:38:33 +07:00
|
|
|
import 'dart:developer';
|
|
|
|
|
|
2025-08-03 20:46:57 +07:00
|
|
|
import 'package:enaklo_pos/core/components/buttons.dart';
|
|
|
|
|
import 'package:enaklo_pos/core/components/dashed_divider.dart';
|
|
|
|
|
import 'package:enaklo_pos/core/components/spaces.dart';
|
|
|
|
|
import 'package:enaklo_pos/core/constants/colors.dart';
|
|
|
|
|
import 'package:enaklo_pos/core/extensions/build_context_ext.dart';
|
|
|
|
|
import 'package:enaklo_pos/core/extensions/date_time_ext.dart';
|
|
|
|
|
import 'package:enaklo_pos/core/extensions/string_ext.dart';
|
2025-08-04 12:38:33 +07:00
|
|
|
import 'package:enaklo_pos/core/utils/printer_service.dart';
|
|
|
|
|
import 'package:enaklo_pos/data/dataoutputs/print_dataoutputs.dart';
|
|
|
|
|
import 'package:enaklo_pos/data/datasources/product_local_datasource.dart';
|
2025-08-03 20:46:57 +07:00
|
|
|
import 'package:enaklo_pos/data/models/response/payment_response_model.dart';
|
2025-08-04 12:38:33 +07:00
|
|
|
import 'package:enaklo_pos/presentation/home/models/product_quantity.dart';
|
2025-08-03 20:46:57 +07:00
|
|
|
import 'package:enaklo_pos/presentation/home/pages/dashboard_page.dart';
|
2025-08-04 12:38:33 +07:00
|
|
|
import 'package:enaklo_pos/presentation/sales/blocs/order_loader/order_loader_bloc.dart';
|
2025-08-03 20:46:57 +07:00
|
|
|
import 'package:flutter/material.dart';
|
2025-08-04 12:38:33 +07:00
|
|
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
2025-08-03 20:46:57 +07:00
|
|
|
|
2025-08-04 12:38:33 +07:00
|
|
|
class SuccessPaymentPage extends StatefulWidget {
|
|
|
|
|
final List<ProductQuantity> productQuantity;
|
2025-08-03 20:46:57 +07:00
|
|
|
final PaymentData payment;
|
2025-08-04 12:38:33 +07:00
|
|
|
const SuccessPaymentPage(
|
|
|
|
|
{super.key, required this.payment, required this.productQuantity});
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
State<SuccessPaymentPage> createState() => _SuccessPaymentPageState();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class _SuccessPaymentPageState extends State<SuccessPaymentPage> {
|
|
|
|
|
@override
|
|
|
|
|
void initState() {
|
|
|
|
|
super.initState();
|
|
|
|
|
context
|
|
|
|
|
.read<OrderLoaderBloc>()
|
|
|
|
|
.add(OrderLoaderEvent.getById(widget.payment.orderId ?? ""));
|
|
|
|
|
}
|
2025-08-03 20:46:57 +07:00
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
return Scaffold(
|
|
|
|
|
backgroundColor: AppColors.background,
|
|
|
|
|
body: Center(
|
|
|
|
|
child: Container(
|
|
|
|
|
width: context.deviceWidth * 0.4,
|
|
|
|
|
height: context.deviceHeight * 0.8,
|
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
|
color: AppColors.white,
|
|
|
|
|
borderRadius: const BorderRadius.all(Radius.circular(12.0)),
|
|
|
|
|
),
|
2025-08-04 12:38:33 +07:00
|
|
|
child: BlocBuilder<OrderLoaderBloc, OrderLoaderState>(
|
|
|
|
|
builder: (context, state) {
|
|
|
|
|
return state.maybeWhen(
|
|
|
|
|
orElse: () => Center(
|
|
|
|
|
child: CircularProgressIndicator(),
|
2025-08-03 20:46:57 +07:00
|
|
|
),
|
2025-08-04 12:38:33 +07:00
|
|
|
loading: () => Center(
|
|
|
|
|
child: CircularProgressIndicator(),
|
2025-08-03 20:46:57 +07:00
|
|
|
),
|
2025-08-04 12:38:33 +07:00
|
|
|
error: (message) => Center(
|
|
|
|
|
child: Text(message),
|
2025-08-03 20:46:57 +07:00
|
|
|
),
|
2025-08-04 12:38:33 +07:00
|
|
|
loadedDetail: (order) => Column(
|
2025-08-03 20:46:57 +07:00
|
|
|
children: [
|
2025-08-04 12:38:33 +07:00
|
|
|
Padding(
|
|
|
|
|
padding: const EdgeInsets.all(16.0),
|
|
|
|
|
child: Column(
|
|
|
|
|
children: [
|
|
|
|
|
Text(
|
|
|
|
|
'Pembayaran!',
|
|
|
|
|
style: const TextStyle(
|
|
|
|
|
fontSize: 18, fontWeight: FontWeight.bold),
|
|
|
|
|
),
|
|
|
|
|
Text('Pembayaran berhasil dilalukan',
|
|
|
|
|
style: const TextStyle(fontSize: 14)),
|
|
|
|
|
],
|
|
|
|
|
),
|
2025-08-03 20:46:57 +07:00
|
|
|
),
|
2025-08-04 12:38:33 +07:00
|
|
|
DashedDivider(
|
|
|
|
|
color: AppColors.grey,
|
2025-08-03 20:46:57 +07:00
|
|
|
),
|
2025-08-04 12:38:33 +07:00
|
|
|
SpaceHeight(24),
|
|
|
|
|
Padding(
|
|
|
|
|
padding: const EdgeInsets.symmetric(horizontal: 16.0),
|
|
|
|
|
child: Icon(
|
|
|
|
|
Icons.check_circle_outline,
|
|
|
|
|
size: 64,
|
|
|
|
|
color: Colors.green,
|
|
|
|
|
),
|
2025-08-03 20:46:57 +07:00
|
|
|
),
|
2025-08-04 12:38:33 +07:00
|
|
|
Spacer(),
|
|
|
|
|
Padding(
|
|
|
|
|
padding: const EdgeInsets.all(16.0).copyWith(top: 24),
|
|
|
|
|
child: Column(
|
|
|
|
|
children: [
|
|
|
|
|
Row(
|
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
|
|
|
children: [
|
|
|
|
|
Text(
|
|
|
|
|
'No. Pesanan',
|
|
|
|
|
),
|
|
|
|
|
Text(
|
|
|
|
|
order.orderNumber ?? "-",
|
|
|
|
|
style: const TextStyle(
|
|
|
|
|
fontWeight: FontWeight.bold),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
SpaceHeight(4),
|
|
|
|
|
Row(
|
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
|
|
|
children: [
|
|
|
|
|
Text(
|
|
|
|
|
'Waktu',
|
|
|
|
|
),
|
|
|
|
|
Text(
|
|
|
|
|
(widget.payment.createdAt ?? DateTime.now())
|
|
|
|
|
.toFormattedDate3(),
|
|
|
|
|
style: const TextStyle(
|
|
|
|
|
fontWeight: FontWeight.bold),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
2025-08-03 20:46:57 +07:00
|
|
|
),
|
2025-08-04 12:38:33 +07:00
|
|
|
DashedDivider(
|
|
|
|
|
color: AppColors.grey,
|
|
|
|
|
),
|
|
|
|
|
Padding(
|
|
|
|
|
padding: const EdgeInsets.all(16.0),
|
|
|
|
|
child: Row(
|
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
|
|
|
children: [
|
|
|
|
|
Text(
|
|
|
|
|
'Status Pembayaran',
|
|
|
|
|
),
|
|
|
|
|
Text(
|
|
|
|
|
'Lunas',
|
|
|
|
|
style: const TextStyle(
|
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
|
color: Colors.green),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
DashedDivider(
|
|
|
|
|
color: AppColors.grey,
|
|
|
|
|
),
|
|
|
|
|
Padding(
|
|
|
|
|
padding: const EdgeInsets.all(16.0),
|
|
|
|
|
child: Row(
|
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
|
|
|
children: [
|
|
|
|
|
Text(
|
|
|
|
|
'Total Pembayaran',
|
|
|
|
|
),
|
|
|
|
|
Text(
|
|
|
|
|
(widget.payment.amount ?? 0)
|
|
|
|
|
.toString()
|
|
|
|
|
.currencyFormatRpV2,
|
|
|
|
|
style: const TextStyle(fontWeight: FontWeight.bold),
|
|
|
|
|
),
|
|
|
|
|
],
|
2025-08-03 20:46:57 +07:00
|
|
|
),
|
|
|
|
|
),
|
2025-08-04 12:38:33 +07:00
|
|
|
DashedDivider(
|
|
|
|
|
color: AppColors.grey,
|
|
|
|
|
),
|
|
|
|
|
Spacer(),
|
|
|
|
|
Padding(
|
|
|
|
|
padding: const EdgeInsets.all(16.0),
|
|
|
|
|
child: Row(
|
|
|
|
|
children: [
|
|
|
|
|
Expanded(
|
|
|
|
|
child: Button.outlined(
|
|
|
|
|
onPressed: () =>
|
|
|
|
|
context.pushReplacement(DashboardPage()),
|
|
|
|
|
label: 'Kembali',
|
|
|
|
|
height: 44,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
SpaceWidth(12),
|
|
|
|
|
Expanded(
|
|
|
|
|
child: 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.productQuantity,
|
|
|
|
|
order.tableNumber ?? "",
|
|
|
|
|
order.orderNumber ?? "",
|
|
|
|
|
'kasir',
|
|
|
|
|
checkerPrinter.paper.toIntegerFromText,
|
|
|
|
|
order.orderType ?? "",
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
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.productQuantity,
|
|
|
|
|
order.tableNumber!,
|
|
|
|
|
order.orderNumber ?? "",
|
|
|
|
|
'kasir',
|
|
|
|
|
kitchenPrinter.paper.toIntegerFromText,
|
|
|
|
|
order.orderType ?? "",
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
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.productQuantity,
|
|
|
|
|
order.tableNumber ?? "",
|
|
|
|
|
order.orderNumber ?? "",
|
|
|
|
|
'kasir',
|
|
|
|
|
barPrinter.paper.toIntegerFromText,
|
|
|
|
|
order.orderType ?? "",
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
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: 'Cetak',
|
|
|
|
|
icon: Icon(
|
|
|
|
|
Icons.print,
|
|
|
|
|
color: AppColors.white,
|
|
|
|
|
),
|
|
|
|
|
height: 44,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
],
|
2025-08-03 20:46:57 +07:00
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
2025-08-04 12:38:33 +07:00
|
|
|
);
|
|
|
|
|
},
|
2025-08-03 20:46:57 +07:00
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|