feat: delivery type

This commit is contained in:
efrilm
2025-08-06 18:47:20 +07:00
parent a46a2cfa7c
commit 6fdaac2c0f
22 changed files with 1560 additions and 679 deletions
@@ -2,6 +2,7 @@ import 'dart:developer';
import 'package:bloc/bloc.dart';
import 'package:enaklo_pos/data/datasources/product_local_datasource.dart';
import 'package:enaklo_pos/data/models/response/delivery_response_model.dart';
import 'package:enaklo_pos/data/models/response/discount_response_model.dart';
import 'package:enaklo_pos/presentation/table/models/draft_order_item.dart';
import 'package:enaklo_pos/presentation/table/models/draft_order_model.dart';
@@ -58,7 +59,8 @@ class CheckoutBloc extends Bloc<CheckoutEvent, CheckoutState> {
currentState.totalQuantity,
currentState.totalPrice,
currentState.draftName,
currentState.orderType));
currentState.orderType,
currentState.deliveryType));
});
on<_RemoveItem>((event, emit) {
@@ -91,7 +93,8 @@ class CheckoutBloc extends Bloc<CheckoutEvent, CheckoutState> {
currentState.totalQuantity,
currentState.totalPrice,
currentState.draftName,
currentState.orderType));
currentState.orderType,
currentState.deliveryType));
});
on<_DeleteItem>((event, emit) {
@@ -116,7 +119,8 @@ class CheckoutBloc extends Bloc<CheckoutEvent, CheckoutState> {
currentState.totalQuantity,
currentState.totalPrice,
currentState.draftName,
currentState.orderType));
currentState.orderType,
currentState.deliveryType));
});
on<_Started>((event, emit) async {
@@ -126,29 +130,41 @@ class CheckoutBloc extends Bloc<CheckoutEvent, CheckoutState> {
final tax = await settingsLocalDatasource.getTax();
final serviceCharge = await settingsLocalDatasource.getServiceCharge();
emit(_Loaded([], null, 0, 0, tax.value, serviceCharge, 0, 0, '',
OrderType.dineIn));
emit(_Loaded(
[],
null,
0,
0,
tax.value,
serviceCharge,
0,
0,
'',
OrderType.dineIn,
null,
));
} catch (e) {
// If loading fails, use default values
log('Failed to load settings: $e');
emit(const _Loaded([], null, 0, 0, 10, 5, 0, 0, '', OrderType.dineIn));
emit(const _Loaded(
[], null, 0, 0, 10, 5, 0, 0, '', OrderType.dineIn, null));
}
});
on<_AddDiscount>((event, emit) {
var currentState = state as _Loaded;
emit(_Loaded(
currentState.items,
event.discount,
currentState.discount,
currentState.discountAmount,
currentState.tax,
currentState.serviceCharge,
currentState.totalQuantity,
currentState.totalPrice,
currentState.draftName,
currentState.orderType,
));
currentState.items,
event.discount,
currentState.discount,
currentState.discountAmount,
currentState.tax,
currentState.serviceCharge,
currentState.totalQuantity,
currentState.totalPrice,
currentState.draftName,
currentState.orderType,
currentState.deliveryType));
});
on<_RemoveDiscount>((event, emit) {
@@ -163,7 +179,8 @@ class CheckoutBloc extends Bloc<CheckoutEvent, CheckoutState> {
currentState.totalQuantity,
currentState.totalPrice,
currentState.draftName,
currentState.orderType));
currentState.orderType,
currentState.deliveryType));
});
on<_AddTax>((event, emit) {
@@ -178,7 +195,8 @@ class CheckoutBloc extends Bloc<CheckoutEvent, CheckoutState> {
currentState.totalQuantity,
currentState.totalPrice,
currentState.draftName,
currentState.orderType));
currentState.orderType,
currentState.deliveryType));
});
on<_AddServiceCharge>((event, emit) {
@@ -194,6 +212,7 @@ class CheckoutBloc extends Bloc<CheckoutEvent, CheckoutState> {
currentState.totalPrice,
currentState.draftName,
currentState.orderType,
currentState.deliveryType,
));
});
@@ -209,7 +228,8 @@ class CheckoutBloc extends Bloc<CheckoutEvent, CheckoutState> {
currentState.totalQuantity,
currentState.totalPrice,
currentState.draftName,
currentState.orderType));
currentState.orderType,
currentState.deliveryType));
});
on<_RemoveServiceCharge>((event, emit) {
@@ -224,7 +244,8 @@ class CheckoutBloc extends Bloc<CheckoutEvent, CheckoutState> {
currentState.totalQuantity,
currentState.totalPrice,
currentState.draftName,
currentState.orderType));
currentState.orderType,
currentState.deliveryType));
});
on<_UpdateOrderType>((event, emit) {
@@ -239,7 +260,8 @@ class CheckoutBloc extends Bloc<CheckoutEvent, CheckoutState> {
currentState.totalQuantity,
currentState.totalPrice,
currentState.draftName,
event.orderType));
event.orderType,
currentState.deliveryType));
});
on<_UpdateItemNotes>((event, emit) {
@@ -260,7 +282,8 @@ class CheckoutBloc extends Bloc<CheckoutEvent, CheckoutState> {
currentState.totalQuantity,
currentState.totalPrice,
currentState.draftName,
currentState.orderType));
currentState.orderType,
currentState.deliveryType));
});
on<_SaveDraftOrder>((event, emit) async {
@@ -298,19 +321,38 @@ class CheckoutBloc extends Bloc<CheckoutEvent, CheckoutState> {
final draftOrder = event.data;
log("draftOrder: ${draftOrder.toMap()}");
emit(_Loaded(
draftOrder.orders
.map((e) =>
ProductQuantity(product: e.product, quantity: e.quantity))
.toList(),
null,
draftOrder.discount,
draftOrder.discountAmount,
draftOrder.tax,
draftOrder.serviceCharge,
draftOrder.totalQuantity,
draftOrder.totalPrice,
draftOrder.draftName,
OrderType.dineIn));
draftOrder.orders
.map((e) =>
ProductQuantity(product: e.product, quantity: e.quantity))
.toList(),
null,
draftOrder.discount,
draftOrder.discountAmount,
draftOrder.tax,
draftOrder.serviceCharge,
draftOrder.totalQuantity,
draftOrder.totalPrice,
draftOrder.draftName,
OrderType.dineIn,
null,
));
});
on<_UpdateDeliveryType>((event, emit) {
var currentState = state as _Loaded;
emit(_Loaded(
currentState.items,
currentState.discountModel,
currentState.discount,
currentState.discountAmount,
currentState.tax,
currentState.serviceCharge,
currentState.totalQuantity,
currentState.totalPrice,
currentState.draftName,
currentState.orderType,
event.delivery,
));
});
}
}
File diff suppressed because it is too large Load Diff
@@ -42,4 +42,8 @@ class CheckoutEvent with _$CheckoutEvent {
//load draft order
const factory CheckoutEvent.loadDraftOrder(DraftOrderModel data) =
_LoadDraftOrder;
// Update delivery type
const factory CheckoutEvent.updateDeliveryType(DeliveryModel delivery) =
_UpdateDeliveryType;
}
@@ -5,16 +5,18 @@ class CheckoutState with _$CheckoutState {
const factory CheckoutState.initial() = _Initial;
const factory CheckoutState.loading() = _Loading;
const factory CheckoutState.loaded(
List<ProductQuantity> items,
Discount? discountModel,
int discount,
int discountAmount,
int tax,
int serviceCharge,
int totalQuantity,
int totalPrice,
String draftName,
OrderType orderType) = _Loaded;
List<ProductQuantity> items,
Discount? discountModel,
int discount,
int discountAmount,
int tax,
int serviceCharge,
int totalQuantity,
int totalPrice,
String draftName,
OrderType orderType,
DeliveryModel? deliveryType,
) = _Loaded;
const factory CheckoutState.error(String message) = _Error;
//save draft order