finishCartV4 function
Implementation
Future<String?> finishCartV4(ProductData currentService, bool temporary, String paymentMethodId,
bool cachePayment,
String stringFromUser, /// strings.get(160) /// "From user:",
String stringNewBooking, /// strings.get(157) /// "New Booking was arrived",
) async{
User? user = FirebaseAuth.instance.currentUser;
if (user == null)
return "finishCartV4 user == null";
if (cartCurrentProvider == null)
return "finish cartCurrentProvider = null";
try{
var _products = cartGetProductsForBooking();
for (var item in _products){
List<AddonData> _addon = [];
if (item.addon.isNotEmpty)
for (var item in currentService.addon) {
if (!item.selected)
continue;
_addon.add(item);
}
item.addon = _addon;
}
var _totalPrice = cartGetTotalForAllServices();
var _data = OrderData(
status: temporary ? "temp" : appSettings.statuses[0].id,
history: [StatusHistory(
statusId: appSettings.statuses[0].id,
time: DateTime.now().toUtc(),
byCustomer: true,
activateUserId : user.uid
)],
customerId: user.uid,
customer: getCurrentAddress().name,
customerAvatar: userAccountData.userAvatar,
providerId: cartCurrentProvider!.id,
provider: cartCurrentProvider!.name,
providerPhone: cartCurrentProvider!.phone,
providerAvatar: cartCurrentProvider!.imageUpperServerPath,
serviceId: "",
service: [],
serviceImage: cartGetImage(),
// price
price: 0,
discPrice: 0,
priceUnit: "",
count: 0,
priceName: [],
// coupon
couponId: couponId,
couponName: couponId.isEmpty ? "" : couponCode,
discount: couponId.isEmpty ? 0 : discount,
discountType: couponId.isEmpty ? "fixed" : discountType,
//
tax: 0,
taxAdmin: 0,
total: _totalPrice.total,
paymentMethod: paymentMethodId,
paymentMethodCache: cachePayment,
//
comment: cartHint,
address: getCurrentAddress().address,
anyTime: cartAnyTime,
selectTime: cartSelectTime,
//
time: DateTime.now(),
timeModify: DateTime.now(),
viewByAdmin: false,
viewByProvider: false,
//
addon: [],
products: _products,
ver4: true,
customerPhone: getCurrentAddress().phone,
customerEmail: userAccountData.userEmail,
);
await cartFinish(_data);
if (!temporary){
var providerId = await getProviderId(cartCurrentProvider!.login);
if (providerId.isNotEmpty)
sendMessage("$stringFromUser ${userAccountData.userName}", /// "From user:",
stringNewBooking, /// "New Booking was arrived",
providerId, true, appSettings.cloudKey);
clearCart();
}
// else
// lastBooking = cartLastAddedId ; //retBooking.id;
// lastBookingForUser = cartLastAddedId; //retBooking.id;
}catch(ex){
dprint(ex.toString());
return "finish:ver4 " + ex.toString();
}
}