feat: split add customer optional

This commit is contained in:
efrilm 2025-08-07 22:45:06 +07:00
parent de22251440
commit b1a1303a40
2 changed files with 138 additions and 106 deletions

View File

@ -19,11 +19,13 @@ class PaymentPage extends StatefulWidget {
final Order order; final Order order;
final bool isSplit; final bool isSplit;
final String? splitType; final String? splitType;
final String? customerId;
const PaymentPage({ const PaymentPage({
super.key, super.key,
required this.order, required this.order,
this.isSplit = false, this.isSplit = false,
this.splitType, this.splitType,
this.customerId,
}); });
@override @override
@ -462,7 +464,7 @@ class _PaymentPageState extends State<PaymentPage> {
} else { } else {
final request = PaymentSplitBillRequest( final request = PaymentSplitBillRequest(
amount: widget.order.totalAmount ?? 0, amount: widget.order.totalAmount ?? 0,
customerId: '', customerId: widget.customerId ?? "",
items: itemPending items: itemPending
?.map((item) => SplitItem( ?.map((item) => SplitItem(
orderItemId: item.id ?? "", orderItemId: item.id ?? "",

View File

@ -2,7 +2,9 @@ import 'dart:developer';
import 'package:enaklo_pos/core/components/flushbar.dart'; import 'package:enaklo_pos/core/components/flushbar.dart';
import 'package:enaklo_pos/core/extensions/build_context_ext.dart'; import 'package:enaklo_pos/core/extensions/build_context_ext.dart';
import 'package:enaklo_pos/data/models/response/customer_response_model.dart';
import 'package:enaklo_pos/data/models/response/order_response_model.dart'; import 'package:enaklo_pos/data/models/response/order_response_model.dart';
import 'package:enaklo_pos/presentation/home/widgets/customer_auto_complete_field.dart';
import 'package:enaklo_pos/presentation/payment/pages/payment_page.dart'; import 'package:enaklo_pos/presentation/payment/pages/payment_page.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
@ -26,6 +28,9 @@ class SplitBillPage extends StatefulWidget {
} }
class _SplitBillPageState extends State<SplitBillPage> { class _SplitBillPageState extends State<SplitBillPage> {
final customerController = TextEditingController();
Customer? selectedCustomer;
int selectedSplitType = 0; // 0 = Per Product, 1 = Per Amount int selectedSplitType = 0; // 0 = Per Product, 1 = Per Amount
// Per Product Split Data // Per Product Split Data
@ -186,6 +191,7 @@ class _SplitBillPageState extends State<SplitBillPage> {
flex: 3, flex: 3,
child: Container( child: Container(
padding: EdgeInsets.all(24), padding: EdgeInsets.all(24),
child: SingleChildScrollView(
child: Column( child: Column(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
@ -199,6 +205,10 @@ class _SplitBillPageState extends State<SplitBillPage> {
), ),
SizedBox(height: 24), SizedBox(height: 24),
_buildCustomer(context),
SizedBox(height: 24),
// Split Type Selection // Split Type Selection
Row( Row(
children: [ children: [
@ -211,7 +221,7 @@ class _SplitBillPageState extends State<SplitBillPage> {
SizedBox(height: 32), SizedBox(height: 32),
// Split Content // Split Content
Expanded( Container(
child: selectedSplitType == 0 child: selectedSplitType == 0
? _buildPerProductSplit() ? _buildPerProductSplit()
: _buildPerAmountSplit(), : _buildPerAmountSplit(),
@ -247,11 +257,32 @@ class _SplitBillPageState extends State<SplitBillPage> {
), ),
), ),
), ),
),
], ],
), ),
); );
} }
Widget _buildCustomer(BuildContext context) {
return Container(
padding: EdgeInsets.all(16),
decoration: BoxDecoration(
color: AppColorSplitBill.cardBackground,
border: Border.all(color: AppColorSplitBill.border),
borderRadius: BorderRadius.circular(8),
),
child: CustomerAutocomplete(
controller: customerController,
selectedCustomer: selectedCustomer,
onSelected: (customer) {
setState(() {
selectedCustomer = customer;
});
},
),
);
}
Widget _buildOrderItem(OrderItem item) { Widget _buildOrderItem(OrderItem item) {
return Container( return Container(
padding: EdgeInsets.symmetric(vertical: 12), padding: EdgeInsets.symmetric(vertical: 12),
@ -347,8 +378,7 @@ class _SplitBillPageState extends State<SplitBillPage> {
), ),
), ),
SizedBox(height: 16), SizedBox(height: 16),
Expanded( Container(
child: Container(
padding: EdgeInsets.all(16), padding: EdgeInsets.all(16),
decoration: BoxDecoration( decoration: BoxDecoration(
color: AppColorSplitBill.cardBackground, color: AppColorSplitBill.cardBackground,
@ -367,15 +397,14 @@ class _SplitBillPageState extends State<SplitBillPage> {
), ),
), ),
SizedBox(height: 16), SizedBox(height: 16),
Expanded( ListView.builder(
child: ListView.builder(
itemCount: getOrderItemPending().length, itemCount: getOrderItemPending().length,
shrinkWrap: true,
physics: NeverScrollableScrollPhysics(),
itemBuilder: (context, index) { itemBuilder: (context, index) {
return _buildProductSplitItem( return _buildProductSplitItem(getOrderItemPending()[index]);
getOrderItemPending()[index]);
}, },
), ),
),
Container( Container(
width: double.infinity, width: double.infinity,
height: 1, height: 1,
@ -406,7 +435,6 @@ class _SplitBillPageState extends State<SplitBillPage> {
], ],
), ),
), ),
),
], ],
); );
} }
@ -764,6 +792,7 @@ class _SplitBillPageState extends State<SplitBillPage> {
order: splitOrder, order: splitOrder,
isSplit: true, isSplit: true,
splitType: 'ITEM', splitType: 'ITEM',
customerId: selectedCustomer?.id,
)); ));
} else { } else {
AppFlushbar.showError(context, "Pilih minimal satu produk untuk split"); AppFlushbar.showError(context, "Pilih minimal satu produk untuk split");
@ -790,6 +819,7 @@ class _SplitBillPageState extends State<SplitBillPage> {
order: splitOrder, order: splitOrder,
isSplit: true, isSplit: true,
splitType: 'AMOUNT', splitType: 'AMOUNT',
customerId: selectedCustomer?.id,
), ),
); );
} else if (splitAmount > totalAmount) { } else if (splitAmount > totalAmount) {