feat: void order
This commit is contained in:
@@ -5,6 +5,7 @@ import 'package:enaklo_pos/core/components/flushbar.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';
|
||||
import 'package:enaklo_pos/data/models/response/order_response_model.dart';
|
||||
import 'package:enaklo_pos/presentation/home/bloc/order_form/order_form_bloc.dart';
|
||||
@@ -30,29 +31,87 @@ class _RefundDialogState extends State<RefundDialog> {
|
||||
return CustomModalDialog(
|
||||
title: 'Refund',
|
||||
subtitle: 'Pengembalian dana',
|
||||
minWidth: context.deviceWidth * 0.5,
|
||||
contentPadding:
|
||||
const EdgeInsets.symmetric(horizontal: 16.0, vertical: 24.0),
|
||||
child: Column(
|
||||
children: [
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text('No. Pesanan'),
|
||||
Text(
|
||||
'Pesanan yang akan di refund',
|
||||
style: const TextStyle(
|
||||
widget.order.orderNumber ?? '',
|
||||
style: TextStyle(
|
||||
color: AppColors.black,
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: AppColors.black,
|
||||
),
|
||||
),
|
||||
SpaceHeight(12),
|
||||
Column(
|
||||
children: widget.selectedItems
|
||||
.map((item) => _item(context, item))
|
||||
.toList(),
|
||||
],
|
||||
),
|
||||
SpaceHeight(8),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text('Tanggal'),
|
||||
Text(
|
||||
(widget.order.createdAt ?? DateTime.now()).toFormattedDate2(),
|
||||
style: TextStyle(
|
||||
color: AppColors.black,
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
SpaceHeight(8),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text('Tagihan'),
|
||||
Text(
|
||||
widget.selectedItems.isEmpty
|
||||
? widget.order.totalAmount.toString().currencyFormatRpV2
|
||||
: widget.selectedItems
|
||||
.fold(
|
||||
0,
|
||||
(sum, item) =>
|
||||
sum +
|
||||
((item.unitPrice ?? 0) * (item.quantity ?? 0)),
|
||||
)
|
||||
.toString()
|
||||
.currencyFormatRpV2,
|
||||
style: TextStyle(
|
||||
color: AppColors.black,
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 16),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
'Pesanan yang akan di refund',
|
||||
style: const TextStyle(
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: AppColors.black,
|
||||
),
|
||||
),
|
||||
SpaceHeight(12),
|
||||
Column(
|
||||
children: widget.selectedItems
|
||||
.map((item) => _item(context, item))
|
||||
.toList(),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
SpaceHeight(16),
|
||||
CustomTextField(
|
||||
controller: _reasonController,
|
||||
|
||||
@@ -0,0 +1,204 @@
|
||||
import 'package:enaklo_pos/core/components/buttons.dart';
|
||||
import 'package:enaklo_pos/core/components/custom_modal_dialog.dart';
|
||||
import 'package:enaklo_pos/core/components/custom_text_field.dart';
|
||||
import 'package:enaklo_pos/core/components/flushbar.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';
|
||||
import 'package:enaklo_pos/data/models/response/order_response_model.dart';
|
||||
import 'package:enaklo_pos/presentation/home/bloc/order_form/order_form_bloc.dart';
|
||||
import 'package:enaklo_pos/presentation/sales/blocs/order_loader/order_loader_bloc.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
|
||||
class VoidDialog extends StatefulWidget {
|
||||
final Order order;
|
||||
final List<OrderItem> selectedItems;
|
||||
const VoidDialog(
|
||||
{super.key, required this.order, required this.selectedItems});
|
||||
|
||||
@override
|
||||
State<VoidDialog> createState() => _VoidDialogState();
|
||||
}
|
||||
|
||||
class _VoidDialogState extends State<VoidDialog> {
|
||||
final TextEditingController _reasonController = TextEditingController();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return CustomModalDialog(
|
||||
title: 'Void',
|
||||
minWidth: context.deviceWidth * 0.5,
|
||||
contentPadding:
|
||||
const EdgeInsets.symmetric(horizontal: 16.0, vertical: 24.0),
|
||||
child: Column(
|
||||
children: [
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text('No. Pesanan'),
|
||||
Text(
|
||||
widget.order.orderNumber ?? '',
|
||||
style: TextStyle(
|
||||
color: AppColors.black,
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
SpaceHeight(8),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text('Tanggal'),
|
||||
Text(
|
||||
(widget.order.createdAt ?? DateTime.now()).toFormattedDate2(),
|
||||
style: TextStyle(
|
||||
color: AppColors.black,
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
SpaceHeight(8),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text('Tagihan'),
|
||||
Text(
|
||||
widget.selectedItems.isEmpty
|
||||
? widget.order.totalAmount.toString().currencyFormatRpV2
|
||||
: widget.selectedItems
|
||||
.fold(
|
||||
0,
|
||||
(sum, item) =>
|
||||
sum +
|
||||
((item.unitPrice ?? 0) * (item.quantity ?? 0)),
|
||||
)
|
||||
.toString()
|
||||
.currencyFormatRpV2,
|
||||
style: TextStyle(
|
||||
color: AppColors.black,
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
if (widget.selectedItems.isNotEmpty)
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
'Pesanan yang akan di void',
|
||||
style: const TextStyle(
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: AppColors.black,
|
||||
),
|
||||
),
|
||||
SpaceHeight(12),
|
||||
Column(
|
||||
children: widget.selectedItems
|
||||
.map((item) => _item(context, item))
|
||||
.toList(),
|
||||
),
|
||||
],
|
||||
),
|
||||
SpaceHeight(16),
|
||||
CustomTextField(
|
||||
controller: _reasonController,
|
||||
label: 'Alasan',
|
||||
),
|
||||
SpaceHeight(24),
|
||||
BlocListener<OrderFormBloc, OrderFormState>(
|
||||
listener: (context, state) {
|
||||
state.maybeWhen(
|
||||
orElse: () {},
|
||||
successMsg: () {
|
||||
context.pop();
|
||||
AppFlushbar.showSuccess(context, 'Void berhasil!');
|
||||
context
|
||||
.read<OrderLoaderBloc>()
|
||||
.add(OrderLoaderEvent.getByStatus('pending'));
|
||||
},
|
||||
error: (msg) {
|
||||
AppFlushbar.showError(context, msg);
|
||||
},
|
||||
);
|
||||
},
|
||||
child: BlocBuilder<OrderFormBloc, OrderFormState>(
|
||||
builder: (context, state) {
|
||||
return state.maybeWhen(
|
||||
orElse: () => Button.filled(
|
||||
onPressed: () {
|
||||
context.read<OrderFormBloc>().add(
|
||||
OrderFormEvent.voidOrder(
|
||||
orderId: widget.order.id ?? '',
|
||||
reason: _reasonController.text,
|
||||
items: widget.selectedItems,
|
||||
),
|
||||
);
|
||||
},
|
||||
label: 'Refund',
|
||||
),
|
||||
loading: () => Center(
|
||||
child: const CircularProgressIndicator(),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Row _item(
|
||||
BuildContext context,
|
||||
OrderItem product,
|
||||
) {
|
||||
return Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
SizedBox(
|
||||
width: context.deviceWidth * 0.1,
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
product.productName ?? '',
|
||||
style: const TextStyle(
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
Text(
|
||||
(product.unitPrice ?? 0).toString().currencyFormatRpV2,
|
||||
style: const TextStyle(
|
||||
fontSize: 14,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
Text(
|
||||
'X${product.quantity}',
|
||||
style: const TextStyle(
|
||||
fontSize: 14,
|
||||
),
|
||||
),
|
||||
Text(
|
||||
(product.totalPrice ?? 0).toString().currencyFormatRpV2,
|
||||
style: const TextStyle(
|
||||
fontSize: 14,
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,7 @@ import 'package:enaklo_pos/presentation/sales/blocs/day_sales/day_sales_bloc.dar
|
||||
import 'package:enaklo_pos/presentation/sales/blocs/order_loader/order_loader_bloc.dart';
|
||||
import 'package:enaklo_pos/presentation/sales/dialog/payment_dialog.dart';
|
||||
import 'package:enaklo_pos/presentation/sales/dialog/refund_dialog.dart';
|
||||
import 'package:enaklo_pos/presentation/sales/dialog/void_dialog.dart';
|
||||
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';
|
||||
@@ -171,11 +172,29 @@ class _SalesPageState extends State<SalesPage> {
|
||||
order: orderDetail,
|
||||
actionWidget: [
|
||||
if (widget.status == 'pending') ...[
|
||||
Button.outlined(
|
||||
onPressed: () {},
|
||||
label: 'Void',
|
||||
icon: Icon(Icons.undo),
|
||||
),
|
||||
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(
|
||||
onPressed: () => showDialog(
|
||||
context: context,
|
||||
builder: (context) => VoidDialog(
|
||||
order: orderDetail!,
|
||||
selectedItems: selectedItems,
|
||||
),
|
||||
),
|
||||
label: 'Void',
|
||||
icon: Icon(Icons.undo),
|
||||
),
|
||||
);
|
||||
}),
|
||||
SpaceWidth(8),
|
||||
Button.outlined(
|
||||
onPressed: () => showDialog(
|
||||
@@ -197,14 +216,13 @@ class _SalesPageState extends State<SalesPage> {
|
||||
label: 'Refund',
|
||||
icon: Icon(Icons.autorenew),
|
||||
),
|
||||
loaded:
|
||||
(order, selectedItems, isAllSelected) =>
|
||||
Button.outlined(
|
||||
loaded: (order, selectedItems,
|
||||
totalVoidOrRefund, isAllSelected) =>
|
||||
Button.outlined(
|
||||
onPressed: () {
|
||||
if (selectedItems.isEmpty) {
|
||||
AppFlushbar.showError(context,
|
||||
'Silahkan pilih item yang ingin di refund.');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -23,7 +23,8 @@ class SalesListOrder extends StatelessWidget {
|
||||
builder: (context, state) {
|
||||
return state.maybeWhen(
|
||||
orElse: () => const SizedBox.shrink(),
|
||||
loaded: (orderX, selectedItems, isAllSelected) => Column(
|
||||
loaded: (orderX, selectedItems, totalVoidOrRefund, isAllSelected) =>
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Container(
|
||||
@@ -83,54 +84,83 @@ class SalesListOrder extends StatelessWidget {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 12, horizontal: 16)
|
||||
.copyWith(top: 0),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
child: Column(
|
||||
children: [
|
||||
SizedBox(
|
||||
width: context.deviceWidth * 0.2,
|
||||
child: Row(
|
||||
children: [
|
||||
Checkbox(
|
||||
value: isSelected,
|
||||
activeColor: AppColors.primary,
|
||||
onChanged: (_) {
|
||||
context
|
||||
.read<OrderFormBloc>()
|
||||
.add(OrderFormEvent.toggleItem(product));
|
||||
},
|
||||
),
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
Align(
|
||||
alignment: Alignment.centerRight,
|
||||
child: Text(
|
||||
product.status == "pending"
|
||||
? "Pending"
|
||||
: product.status == "cancelled"
|
||||
? "Batal"
|
||||
: product.status == 'refund'
|
||||
? "Refund"
|
||||
: "Selesai",
|
||||
style: TextStyle(
|
||||
fontSize: 10,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: product.status == "pending"
|
||||
? Colors.blue
|
||||
: product.status == "cancelled"
|
||||
? Colors.red
|
||||
: product.status == 'refund'
|
||||
? Colors.red
|
||||
: Colors.green,
|
||||
),
|
||||
),
|
||||
),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
SizedBox(
|
||||
width: context.deviceWidth * 0.2,
|
||||
child: Row(
|
||||
children: [
|
||||
Text(
|
||||
product.productName ?? '',
|
||||
style: const TextStyle(
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
Checkbox(
|
||||
value: isSelected,
|
||||
activeColor: AppColors.primary,
|
||||
onChanged: (_) {
|
||||
context
|
||||
.read<OrderFormBloc>()
|
||||
.add(OrderFormEvent.toggleItem(product));
|
||||
},
|
||||
),
|
||||
Text(
|
||||
(product.unitPrice ?? 0).toString().currencyFormatRpV2,
|
||||
style: const TextStyle(
|
||||
fontSize: 14,
|
||||
),
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
product.productName ?? '',
|
||||
style: const TextStyle(
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
Text(
|
||||
(product.unitPrice ?? 0)
|
||||
.toString()
|
||||
.currencyFormatRpV2,
|
||||
style: const TextStyle(
|
||||
fontSize: 14,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
Text(
|
||||
'X${product.quantity}',
|
||||
style: const TextStyle(
|
||||
fontSize: 14,
|
||||
),
|
||||
),
|
||||
Text(
|
||||
(product.totalPrice ?? 0).toString().currencyFormatRpV2,
|
||||
style: const TextStyle(
|
||||
fontSize: 14,
|
||||
),
|
||||
),
|
||||
Text(
|
||||
'X${product.quantity}',
|
||||
style: const TextStyle(
|
||||
fontSize: 14,
|
||||
),
|
||||
),
|
||||
Text(
|
||||
(product.totalPrice ?? 0).toString().currencyFormatRpV2,
|
||||
style: const TextStyle(
|
||||
fontSize: 14,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user