2025-08-02 10:50:48 +07:00
|
|
|
import 'package:enaklo_pos/core/components/buttons.dart';
|
2025-08-04 02:04:03 +07:00
|
|
|
import 'package:enaklo_pos/core/components/flushbar.dart';
|
2025-08-02 10:50:48 +07:00
|
|
|
import 'package:enaklo_pos/core/components/spaces.dart';
|
2025-08-04 20:40:25 +07:00
|
|
|
import 'package:enaklo_pos/core/extensions/build_context_ext.dart';
|
2025-08-03 14:39:15 +07:00
|
|
|
import 'package:enaklo_pos/data/models/response/order_response_model.dart';
|
2025-08-03 22:44:01 +07:00
|
|
|
import 'package:enaklo_pos/presentation/home/bloc/order_form/order_form_bloc.dart';
|
2025-08-02 10:50:48 +07:00
|
|
|
import 'package:enaklo_pos/presentation/sales/blocs/day_sales/day_sales_bloc.dart';
|
2025-08-03 14:39:15 +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:enaklo_pos/presentation/sales/dialog/payment_dialog.dart';
|
2025-08-04 02:04:03 +07:00
|
|
|
import 'package:enaklo_pos/presentation/sales/dialog/refund_dialog.dart';
|
2025-08-04 20:40:25 +07:00
|
|
|
import 'package:enaklo_pos/presentation/void/pages/void_page.dart';
|
2025-08-02 10:50:48 +07:00
|
|
|
import 'package:enaklo_pos/presentation/sales/widgets/sales_detail.dart';
|
|
|
|
|
import 'package:enaklo_pos/presentation/sales/widgets/sales_list_order.dart';
|
|
|
|
|
import 'package:enaklo_pos/presentation/sales/widgets/sales_order_information.dart';
|
|
|
|
|
import 'package:enaklo_pos/presentation/sales/widgets/sales_payment.dart';
|
|
|
|
|
import 'package:enaklo_pos/presentation/sales/widgets/sales_right_title.dart';
|
2025-07-30 22:38:44 +07:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
|
|
|
|
|
2025-08-02 10:50:48 +07:00
|
|
|
import '../../../core/constants/colors.dart';
|
|
|
|
|
import '../widgets/sales_card.dart';
|
|
|
|
|
import '../widgets/sales_title.dart';
|
2025-07-30 22:38:44 +07:00
|
|
|
|
|
|
|
|
class SalesPage extends StatefulWidget {
|
2025-08-03 14:39:15 +07:00
|
|
|
final String status;
|
|
|
|
|
const SalesPage({super.key, required this.status});
|
2025-07-30 22:38:44 +07:00
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
State<SalesPage> createState() => _SalesPageState();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class _SalesPageState extends State<SalesPage> {
|
2025-08-02 10:50:48 +07:00
|
|
|
DateTime startDate = DateTime.now();
|
|
|
|
|
DateTime endDate = DateTime.now();
|
2025-08-03 14:39:15 +07:00
|
|
|
Order? orderDetail;
|
2025-08-02 10:50:48 +07:00
|
|
|
|
|
|
|
|
String searchQuery = '';
|
|
|
|
|
|
2025-07-30 22:38:44 +07:00
|
|
|
@override
|
|
|
|
|
void initState() {
|
2025-08-02 10:50:48 +07:00
|
|
|
context
|
2025-08-03 14:39:15 +07:00
|
|
|
.read<OrderLoaderBloc>()
|
|
|
|
|
.add(OrderLoaderEvent.getByStatus(widget.status));
|
2025-07-30 22:38:44 +07:00
|
|
|
super.initState();
|
|
|
|
|
}
|
|
|
|
|
|
2025-08-03 14:39:15 +07:00
|
|
|
List<Order> _filterOrders(List<Order> orders) {
|
2025-08-02 10:50:48 +07:00
|
|
|
if (searchQuery.isEmpty) {
|
|
|
|
|
return orders;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return orders.where((order) {
|
2025-08-03 14:39:15 +07:00
|
|
|
final customerName = order.orderNumber?.toLowerCase() ?? "";
|
2025-08-02 10:50:48 +07:00
|
|
|
final queryLower = searchQuery.toLowerCase();
|
|
|
|
|
return customerName.contains(queryLower);
|
|
|
|
|
}).toList();
|
|
|
|
|
}
|
|
|
|
|
|
2025-07-30 22:38:44 +07:00
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
2025-08-02 10:50:48 +07:00
|
|
|
return SafeArea(
|
|
|
|
|
child: Scaffold(
|
|
|
|
|
backgroundColor: AppColors.background,
|
|
|
|
|
body: Row(
|
|
|
|
|
children: [
|
|
|
|
|
Expanded(
|
|
|
|
|
flex: 2,
|
|
|
|
|
child: Material(
|
|
|
|
|
color: AppColors.white,
|
|
|
|
|
child: Column(
|
|
|
|
|
children: [
|
|
|
|
|
SalesTitle(
|
2025-08-03 14:39:15 +07:00
|
|
|
title: widget.status == 'pending'
|
|
|
|
|
? "Pending Pesanan"
|
|
|
|
|
: "Daftar Pesanan",
|
2025-08-02 10:50:48 +07:00
|
|
|
startDate: startDate,
|
|
|
|
|
endDate: endDate,
|
|
|
|
|
onChanged: (value) {
|
|
|
|
|
setState(() {
|
|
|
|
|
searchQuery = value;
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
onDateRangeChanged: (start, end) {
|
|
|
|
|
setState(() {
|
|
|
|
|
startDate = start;
|
|
|
|
|
endDate = end;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
context.read<DaySalesBloc>().add(
|
|
|
|
|
DaySalesEvent.getRangeDateSales(
|
|
|
|
|
startDate, endDate));
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
Expanded(
|
2025-08-03 14:39:15 +07:00
|
|
|
child: BlocBuilder<OrderLoaderBloc, OrderLoaderState>(
|
2025-08-02 10:50:48 +07:00
|
|
|
builder: (context, state) {
|
|
|
|
|
return state.maybeWhen(
|
|
|
|
|
orElse: () => const Center(
|
|
|
|
|
child: CircularProgressIndicator(),
|
|
|
|
|
),
|
2025-08-03 14:39:15 +07:00
|
|
|
loading: () => const Center(
|
|
|
|
|
child: CircularProgressIndicator(),
|
|
|
|
|
),
|
|
|
|
|
error: (message) => Center(
|
|
|
|
|
child: Text(
|
|
|
|
|
message,
|
|
|
|
|
style: TextStyle(
|
|
|
|
|
fontSize: 16.0,
|
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
loaded: (orders, totalOrder) {
|
2025-08-02 10:50:48 +07:00
|
|
|
final filtered = _filterOrders(orders);
|
|
|
|
|
if (filtered.isEmpty) {
|
|
|
|
|
return Center(
|
|
|
|
|
child: Text(
|
|
|
|
|
"Belum ada transaksi saat ini. ",
|
|
|
|
|
style: TextStyle(
|
|
|
|
|
fontSize: 16.0,
|
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
} else {
|
|
|
|
|
return SingleChildScrollView(
|
|
|
|
|
child: Column(
|
|
|
|
|
children: List.generate(
|
|
|
|
|
filtered.length,
|
|
|
|
|
(index) => GestureDetector(
|
|
|
|
|
onTap: () {
|
|
|
|
|
setState(() {
|
|
|
|
|
orderDetail = filtered[index];
|
|
|
|
|
});
|
2025-08-03 22:44:01 +07:00
|
|
|
context.read<OrderFormBloc>().add(
|
|
|
|
|
OrderFormEvent.started(
|
|
|
|
|
filtered[index]));
|
2025-08-02 10:50:48 +07:00
|
|
|
},
|
|
|
|
|
child: SalesCard(
|
|
|
|
|
order: orders[index],
|
|
|
|
|
isActive:
|
|
|
|
|
orders[index] == orderDetail,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
],
|
2025-07-30 22:38:44 +07:00
|
|
|
),
|
|
|
|
|
),
|
2025-08-02 10:50:48 +07:00
|
|
|
),
|
|
|
|
|
Expanded(
|
|
|
|
|
flex: 4,
|
|
|
|
|
child: orderDetail == null
|
|
|
|
|
? Center(
|
|
|
|
|
child: Text(
|
|
|
|
|
"Belum ada order yang dipilih.",
|
|
|
|
|
style: TextStyle(
|
|
|
|
|
fontSize: 16.0,
|
|
|
|
|
fontWeight: FontWeight.bold,
|
2025-07-30 22:38:44 +07:00
|
|
|
),
|
2025-08-02 10:50:48 +07:00
|
|
|
),
|
|
|
|
|
)
|
|
|
|
|
: Column(
|
|
|
|
|
children: [
|
|
|
|
|
SalesRightTitle(
|
|
|
|
|
order: orderDetail,
|
|
|
|
|
actionWidget: [
|
2025-08-03 14:51:13 +07:00
|
|
|
if (widget.status == 'pending') ...[
|
2025-08-04 11:39:47 +07:00
|
|
|
BlocBuilder<OrderFormBloc, OrderFormState>(
|
|
|
|
|
builder: (context, state) {
|
|
|
|
|
return state.maybeWhen(
|
|
|
|
|
orElse: () => Button.outlined(
|
|
|
|
|
onPressed: () {},
|
|
|
|
|
label: 'Void',
|
|
|
|
|
icon: Icon(Icons.undo),
|
|
|
|
|
),
|
|
|
|
|
loaded: (order, selectedItems,
|
|
|
|
|
totalVoidOrRefund, isAllSelected) =>
|
|
|
|
|
Button.outlined(
|
2025-08-04 20:40:25 +07:00
|
|
|
onPressed: () {
|
|
|
|
|
context.push(VoidPage(
|
|
|
|
|
selectedOrder: order,
|
|
|
|
|
));
|
|
|
|
|
// showDialog(
|
|
|
|
|
// context: context,
|
|
|
|
|
// builder: (context) => VoidDialog(
|
|
|
|
|
// order: orderDetail!,
|
|
|
|
|
// selectedItems: selectedItems,
|
|
|
|
|
// ),
|
|
|
|
|
// );
|
|
|
|
|
},
|
2025-08-04 11:39:47 +07:00
|
|
|
label: 'Void',
|
|
|
|
|
icon: Icon(Icons.undo),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}),
|
2025-08-03 14:51:13 +07:00
|
|
|
SpaceWidth(8),
|
|
|
|
|
Button.outlined(
|
2025-08-03 20:46:57 +07:00
|
|
|
onPressed: () => showDialog(
|
|
|
|
|
context: context,
|
|
|
|
|
builder: (context) => PaymentDialog(
|
|
|
|
|
order: orderDetail!,
|
|
|
|
|
),
|
|
|
|
|
),
|
2025-08-03 14:51:13 +07:00
|
|
|
label: 'Bayar',
|
|
|
|
|
icon: Icon(Icons.payment),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
if (widget.status == 'completed')
|
2025-08-04 02:04:03 +07:00
|
|
|
BlocBuilder<OrderFormBloc, OrderFormState>(
|
|
|
|
|
builder: (context, state) {
|
|
|
|
|
return state.maybeWhen(
|
|
|
|
|
orElse: () => Button.outlined(
|
|
|
|
|
onPressed: () {},
|
|
|
|
|
label: 'Refund',
|
|
|
|
|
icon: Icon(Icons.autorenew),
|
|
|
|
|
),
|
2025-08-04 11:39:47 +07:00
|
|
|
loaded: (order, selectedItems,
|
|
|
|
|
totalVoidOrRefund, isAllSelected) =>
|
|
|
|
|
Button.outlined(
|
2025-08-04 02:04:03 +07:00
|
|
|
onPressed: () {
|
|
|
|
|
if (selectedItems.isEmpty) {
|
|
|
|
|
AppFlushbar.showError(context,
|
|
|
|
|
'Silahkan pilih item yang ingin di refund.');
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
showDialog(
|
|
|
|
|
context: context,
|
|
|
|
|
builder: (context) => RefundDialog(
|
|
|
|
|
order: orderDetail!,
|
|
|
|
|
selectedItems: selectedItems,
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
label: 'Refund',
|
|
|
|
|
icon: Icon(Icons.autorenew),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
},
|
2025-08-03 14:51:13 +07:00
|
|
|
),
|
2025-08-02 10:50:48 +07:00
|
|
|
],
|
|
|
|
|
),
|
2025-08-03 14:39:15 +07:00
|
|
|
Expanded(
|
|
|
|
|
child: SingleChildScrollView(
|
|
|
|
|
padding: const EdgeInsets.all(16.0),
|
|
|
|
|
child: Column(
|
|
|
|
|
children: [
|
|
|
|
|
Row(
|
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
|
children: [
|
|
|
|
|
Expanded(
|
|
|
|
|
child: SalesOrderInformation(
|
|
|
|
|
order: orderDetail,
|
|
|
|
|
),
|
2025-08-02 10:50:48 +07:00
|
|
|
),
|
2025-08-03 14:39:15 +07:00
|
|
|
SpaceWidth(16),
|
|
|
|
|
Expanded(
|
|
|
|
|
child: SalesDetail(
|
|
|
|
|
order: orderDetail,
|
|
|
|
|
),
|
2025-08-02 10:50:48 +07:00
|
|
|
),
|
2025-08-03 14:39:15 +07:00
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
SalesListOrder(
|
|
|
|
|
order: orderDetail,
|
|
|
|
|
),
|
|
|
|
|
SalesPayment(
|
|
|
|
|
order: orderDetail,
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
2025-08-02 10:50:48 +07:00
|
|
|
),
|
|
|
|
|
)
|
|
|
|
|
],
|
|
|
|
|
),
|
2025-07-30 22:38:44 +07:00
|
|
|
),
|
2025-08-02 10:50:48 +07:00
|
|
|
],
|
2025-07-30 22:38:44 +07:00
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|