|
|
|
import 'dart:convert';
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:healthcare_pharmacy/biddingrequests.dart';
|
|
|
|
import 'package:healthcare_pharmacy/dashboard.dart';
|
|
|
|
import 'package:healthcare_pharmacy/getalloffers.dart';
|
|
|
|
import 'package:healthcare_pharmacy/getmedicines.dart';
|
|
|
|
import 'package:healthcare_pharmacy/maps/app_colors.dart';
|
|
|
|
import 'package:healthcare_pharmacy/medicinedetailspage.dart';
|
|
|
|
import 'package:healthcare_pharmacy/models/biddingrequest_model.dart';
|
|
|
|
import 'package:healthcare_pharmacy/models/cartview_model.dart';
|
|
|
|
import 'package:healthcare_pharmacy/models/offersview_model.dart';
|
|
|
|
import 'package:healthcare_pharmacy/settings.dart';
|
|
|
|
import 'package:intl/intl.dart';
|
|
|
|
import 'package:flutter_cupertino_datetime_picker/flutter_cupertino_datetime_picker.dart';
|
|
|
|
|
|
|
|
|
|
|
|
class MedicineCartList extends StatefulWidget {
|
|
|
|
var bookidID;
|
|
|
|
|
|
|
|
MedicineCartList({
|
|
|
|
this.bookidID
|
|
|
|
});
|
|
|
|
|
|
|
|
@override
|
|
|
|
State<MedicineCartList> createState() => _MedicineCartListState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _MedicineCartListState extends State<MedicineCartList> with TickerProviderStateMixin {
|
|
|
|
bool isSupplierDataLoading=false;
|
|
|
|
bool isSereverIssue = false;
|
|
|
|
bool isSereverIssueConnected = false;
|
|
|
|
bool isSereverIssuePending = false;
|
|
|
|
var startdate;
|
|
|
|
var enddate;
|
|
|
|
String totalPrice='';
|
|
|
|
String medicinetime='';
|
|
|
|
|
|
|
|
String bookingidstring='';
|
|
|
|
bool isLoading=false;
|
|
|
|
double finalGrandTotal=0.0;
|
|
|
|
double gstPercentage=0.0;
|
|
|
|
double discountedTotalAmount=0.0;
|
|
|
|
double additionalDiscount=0.0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List<BiddingCartviewModel> offersviewList = [];
|
|
|
|
TextEditingController medicine_nameController = TextEditingController();
|
|
|
|
TextEditingController medicine_quantityController = TextEditingController();
|
|
|
|
TextEditingController medicine_priceController = TextEditingController();
|
|
|
|
TextEditingController medicine_gstPriceController = TextEditingController();
|
|
|
|
TextEditingController medicine_additionalPriceController = TextEditingController();
|
|
|
|
TextEditingController medicine_finalPriceController = TextEditingController();
|
|
|
|
TextEditingController BookingidController = TextEditingController();
|
|
|
|
TextEditingController medicine_timingsController = TextEditingController();
|
|
|
|
|
|
|
|
|
|
|
|
Future<void> getCartViewData() async {
|
|
|
|
isLoading = true;
|
|
|
|
|
|
|
|
try {
|
|
|
|
var response = await AppSettings.getCartDetails(widget.bookidID).then((value){
|
|
|
|
setState(() {
|
|
|
|
// offersviewList = BiddingCartviewModel.fromJson(response['items']) as List<BiddingCartviewModel>;
|
|
|
|
offersviewList =
|
|
|
|
((jsonDecode(value)['items']) as List).map((dynamic model) {
|
|
|
|
return BiddingCartviewModel.fromJson(model);
|
|
|
|
}).toList();
|
|
|
|
|
|
|
|
totalPrice=jsonDecode(value)['totalPrice'].toString();
|
|
|
|
|
|
|
|
print(medicinetime);
|
|
|
|
print(totalPrice);
|
|
|
|
isLoading = false;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
print("offersviewListdata${jsonDecode(response)}");
|
|
|
|
|
|
|
|
} catch (e) {
|
|
|
|
setState(() {
|
|
|
|
isLoading = false;
|
|
|
|
isSereverIssueConnected = true;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
// TODO: implement initState
|
|
|
|
BookingidController.text=widget.bookidID;
|
|
|
|
getCartViewData();
|
|
|
|
super.initState();
|
|
|
|
}
|
|
|
|
|
|
|
|
Widget renderzUi() {
|
|
|
|
if (offersviewList.length != 0) {
|
|
|
|
return Column(crossAxisAlignment: CrossAxisAlignment.end, children: [
|
|
|
|
Expanded(
|
|
|
|
child: ListView.builder(
|
|
|
|
padding: EdgeInsets.all(0),
|
|
|
|
itemCount: offersviewList.length,
|
|
|
|
itemBuilder: (BuildContext context, int index) {
|
|
|
|
return Card(
|
|
|
|
child: Padding(
|
|
|
|
padding: EdgeInsets.all(8),
|
|
|
|
child: Row(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
|
|
children: [
|
|
|
|
Expanded(
|
|
|
|
child: Container(
|
|
|
|
width: MediaQuery.of(context).size.width * .70,
|
|
|
|
child: Row(
|
|
|
|
children: [
|
|
|
|
Column(
|
|
|
|
mainAxisAlignment:
|
|
|
|
MainAxisAlignment.spaceBetween,
|
|
|
|
crossAxisAlignment:
|
|
|
|
CrossAxisAlignment.start,
|
|
|
|
children: [
|
|
|
|
Text('MedicineName:',
|
|
|
|
style: labelTextStyle()),
|
|
|
|
SizedBox(
|
|
|
|
height: 10,
|
|
|
|
),
|
|
|
|
Text(
|
|
|
|
'Medicine Timings:',
|
|
|
|
style: labelTextStyle()),
|
|
|
|
SizedBox(
|
|
|
|
height: 10,
|
|
|
|
),
|
|
|
|
Text('MedicineQuantity:',
|
|
|
|
style: labelTextStyle()),
|
|
|
|
SizedBox(
|
|
|
|
height: 10,
|
|
|
|
),
|
|
|
|
Text('MedicinePrice:',
|
|
|
|
style: labelTextStyle()),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
SizedBox(
|
|
|
|
width: 10,
|
|
|
|
),
|
|
|
|
Column(
|
|
|
|
mainAxisAlignment:
|
|
|
|
MainAxisAlignment.spaceBetween,
|
|
|
|
crossAxisAlignment:
|
|
|
|
CrossAxisAlignment.start,
|
|
|
|
children: [
|
|
|
|
SizedBox(
|
|
|
|
height: 12,
|
|
|
|
),
|
|
|
|
Text(
|
|
|
|
offersviewList[index].medicinename_bidding!
|
|
|
|
.toUpperCase(),
|
|
|
|
style: valuesTextStyle()),
|
|
|
|
SizedBox(
|
|
|
|
height: 12,
|
|
|
|
),
|
|
|
|
Text(
|
|
|
|
offersviewList[index].medicine_timings![0].medicineTimings!.toUpperCase(),
|
|
|
|
style: valuesTextStyle()),
|
|
|
|
SizedBox(
|
|
|
|
height: 10,
|
|
|
|
),
|
|
|
|
Text(
|
|
|
|
offersviewList[index].quantity_bidding.toString()
|
|
|
|
.toUpperCase(),
|
|
|
|
style: valuesTextStyle()),
|
|
|
|
SizedBox(
|
|
|
|
height: 10,
|
|
|
|
),
|
|
|
|
Text(
|
|
|
|
offersviewList[index].price_bidding.toString()
|
|
|
|
.toUpperCase(),
|
|
|
|
style: valuesTextStyle()),
|
|
|
|
SizedBox(
|
|
|
|
height: 10,
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
],
|
|
|
|
)),
|
|
|
|
),
|
|
|
|
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
})),
|
|
|
|
|
|
|
|
Container(
|
|
|
|
width: MediaQuery.of(context).size.width,
|
|
|
|
height: 50,
|
|
|
|
child:TextButton(
|
|
|
|
onPressed: () {
|
|
|
|
// Add your button click logic here
|
|
|
|
},
|
|
|
|
child: Text(
|
|
|
|
'Total Price:$totalPrice',
|
|
|
|
style: TextStyle(
|
|
|
|
fontSize: 20,
|
|
|
|
color: AppColors.primaryColor, // Text color
|
|
|
|
decoration: TextDecoration.underline, // Underline the text
|
|
|
|
fontWeight: FontWeight.bold, // Bold text
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),),
|
|
|
|
/* Container(
|
|
|
|
width: MediaQuery.of(context).size.width,
|
|
|
|
height: 30,
|
|
|
|
child: Align(
|
|
|
|
alignment: Alignment.center,
|
|
|
|
child: TextButton(
|
|
|
|
onPressed: () async {
|
|
|
|
await Navigator.push(
|
|
|
|
context,
|
|
|
|
MaterialPageRoute(
|
|
|
|
builder: (context) => GetAllOffers(bookidID:BookingidController.text.toString())),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
child: Text(
|
|
|
|
'Add Offers',
|
|
|
|
style: TextStyle(
|
|
|
|
fontSize:15,
|
|
|
|
color: AppColors.primaryColor, // Text color
|
|
|
|
decoration: TextDecoration.underline, // Underline the text
|
|
|
|
fontWeight: FontWeight.bold, // Bold text
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),*/
|
|
|
|
|
|
|
|
SizedBox(
|
|
|
|
height: 10,
|
|
|
|
),
|
|
|
|
Container(
|
|
|
|
width: MediaQuery.of(context).size.width,
|
|
|
|
height: 60,
|
|
|
|
padding: const EdgeInsets.fromLTRB(20, 0, 20, 10),
|
|
|
|
child: ElevatedButton(
|
|
|
|
style: ElevatedButton.styleFrom(
|
|
|
|
primary: primaryColor, // background
|
|
|
|
onPrimary: Colors.white, // foreground
|
|
|
|
),
|
|
|
|
onPressed: () async{
|
|
|
|
|
|
|
|
showDialog(
|
|
|
|
barrierDismissible: false,
|
|
|
|
context: context,
|
|
|
|
builder: (BuildContext context) {
|
|
|
|
|
|
|
|
double totalAmount = double.parse(totalPrice);
|
|
|
|
double additionalDiscountPercentage = 5;
|
|
|
|
double specialDiscountPercentage = 5;
|
|
|
|
gstPercentage = 18;
|
|
|
|
|
|
|
|
// Calculate additional discount
|
|
|
|
additionalDiscount = (totalAmount * additionalDiscountPercentage) / 100;
|
|
|
|
discountedTotalAmount = totalAmount - additionalDiscount;
|
|
|
|
|
|
|
|
// Calculate special discount
|
|
|
|
double specialDiscount = (discountedTotalAmount * specialDiscountPercentage) / 100;
|
|
|
|
double grandTotal = discountedTotalAmount - specialDiscount;
|
|
|
|
|
|
|
|
|
|
|
|
// Calculate GST on the grand total
|
|
|
|
double gstOnGrandTotal = (grandTotal * gstPercentage) / 100;
|
|
|
|
finalGrandTotal = grandTotal + gstOnGrandTotal;
|
|
|
|
medicine_priceController.text = finalGrandTotal.toString();
|
|
|
|
medicine_gstPriceController.text = gstPercentage.toString();
|
|
|
|
medicine_additionalPriceController.text = additionalDiscount.toString();
|
|
|
|
|
|
|
|
return AlertDialog(
|
|
|
|
title: Text(
|
|
|
|
'Payment Receipt',
|
|
|
|
style: TextStyle(
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
color: Colors.red,
|
|
|
|
fontSize: 20
|
|
|
|
),
|
|
|
|
),
|
|
|
|
content: Column(
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
|
|
|
Text(
|
|
|
|
'Medicines Total Amount: ${totalAmount.toStringAsFixed(2)}',
|
|
|
|
style: TextStyle(
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
color: Colors.black,
|
|
|
|
fontSize: 16
|
|
|
|
),
|
|
|
|
),
|
|
|
|
|
|
|
|
Text(
|
|
|
|
'Additional Discount (-5%): ${additionalDiscount.toStringAsFixed(2)} ',
|
|
|
|
style: TextStyle(
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
color: Colors.black,
|
|
|
|
fontSize: 16
|
|
|
|
),
|
|
|
|
),
|
|
|
|
Divider(
|
|
|
|
thickness: 2, // Adjust the thickness as needed
|
|
|
|
color: Colors.grey, // Adjust the color as needed
|
|
|
|
),
|
|
|
|
Text(
|
|
|
|
'Discounted Total Ammount: ${discountedTotalAmount.toStringAsFixed(2)}',
|
|
|
|
style: TextStyle(
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
color: Colors.black,
|
|
|
|
fontSize: 16
|
|
|
|
),
|
|
|
|
),
|
|
|
|
Text(
|
|
|
|
'Special Discount (-5%): ${specialDiscount.toStringAsFixed(2)}',
|
|
|
|
style: TextStyle(
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
color: Colors.black,
|
|
|
|
fontSize: 16
|
|
|
|
),
|
|
|
|
),
|
|
|
|
Divider(
|
|
|
|
thickness: 2, // Adjust the thickness as needed
|
|
|
|
color: Colors.grey, // Adjust the color as needed
|
|
|
|
),
|
|
|
|
Text(
|
|
|
|
'Special Discounted Total Ammount: ${grandTotal.toStringAsFixed(2)}',
|
|
|
|
style: TextStyle(
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
color: Colors.black,
|
|
|
|
fontSize: 16
|
|
|
|
),
|
|
|
|
),
|
|
|
|
Text(
|
|
|
|
'GST (+18%): ${gstOnGrandTotal.toStringAsFixed(2)}',
|
|
|
|
style: TextStyle(
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
color: Colors.black,
|
|
|
|
fontSize: 16
|
|
|
|
),
|
|
|
|
),
|
|
|
|
Divider(
|
|
|
|
thickness: 2, // Adjust the thickness as needed
|
|
|
|
color: Colors.black, // Adjust the color as needed
|
|
|
|
),
|
|
|
|
|
|
|
|
Text(
|
|
|
|
'Grand Total: ${finalGrandTotal.toStringAsFixed(2)}',
|
|
|
|
style: TextStyle(
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
color: Colors.redAccent,
|
|
|
|
fontSize: 20
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
actions: <Widget>[
|
|
|
|
Center(
|
|
|
|
child: ElevatedButton(
|
|
|
|
style: ElevatedButton.styleFrom(
|
|
|
|
primary: primaryColor, // background
|
|
|
|
onPrimary: Colors.white, // foreground
|
|
|
|
),
|
|
|
|
onPressed: () async {
|
|
|
|
if (medicine_priceController.text != '' &&
|
|
|
|
medicine_gstPriceController.text != ''&&
|
|
|
|
medicine_additionalPriceController.text != ''
|
|
|
|
) {
|
|
|
|
AppSettings.preLoaderDialog(context);
|
|
|
|
var response = await AppSettings.cartFinalAmmount(BookingidController.text,medicine_priceController.text,
|
|
|
|
medicine_gstPriceController.text,medicine_additionalPriceController.text);
|
|
|
|
print("response$response");
|
|
|
|
|
|
|
|
//String response= await addToCart("OR1690969760576127","10","300","Dolo650");
|
|
|
|
//print("response$response");
|
|
|
|
try {
|
|
|
|
if(response.statusCode==200){
|
|
|
|
var msg=jsonDecode(response.body)['message'];
|
|
|
|
print(msg);
|
|
|
|
Navigator.of(context,rootNavigator: true).pop();
|
|
|
|
AppSettings.longSuccessToast(
|
|
|
|
"Medicines Final Price Sent Successfully");
|
|
|
|
|
|
|
|
await Navigator.push(
|
|
|
|
context,
|
|
|
|
MaterialPageRoute(
|
|
|
|
builder: (context) => Dashboard()),
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
Navigator.of(context,rootNavigator: true).pop();
|
|
|
|
AppSettings.longFailedToast("Failed to Sent Final Medicines Price");
|
|
|
|
}
|
|
|
|
|
|
|
|
} catch (exception) {
|
|
|
|
print(exception);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
AppSettings.longFailedToast("Please enter valid details");
|
|
|
|
}
|
|
|
|
|
|
|
|
Navigator.of(context).pop();
|
|
|
|
},
|
|
|
|
child: Text('Submit'),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
SizedBox(height: 10), // Add some spacing between buttons
|
|
|
|
/* Center(
|
|
|
|
child: ElevatedButton(
|
|
|
|
style: ElevatedButton.styleFrom(
|
|
|
|
primary: primaryColor, // background
|
|
|
|
onPrimary: Colors.white, // fores
|
|
|
|
),
|
|
|
|
onPressed: () async{
|
|
|
|
var payload = new Map<String, dynamic>();
|
|
|
|
payload["pharmacyname"] =
|
|
|
|
"Arminta Pharma PVT LTD";
|
|
|
|
payload["pharmacyId"] =
|
|
|
|
"AWSSSUR1";
|
|
|
|
payload["customerId"] =
|
|
|
|
"AWSSSUR1";
|
|
|
|
payload["address"] =
|
|
|
|
"kphb";
|
|
|
|
payload["dateOfOrder"] =
|
|
|
|
"15/02/2024";
|
|
|
|
payload["action"] = "accept";
|
|
|
|
payload["price"] =
|
|
|
|
"1000";
|
|
|
|
payload["delivery_agent"] = "Arminta";
|
|
|
|
payload["agent_mobile"] = "8328206299";
|
|
|
|
payload["expectedDateOfDelivery"] ="20/02/2024";
|
|
|
|
|
|
|
|
bool requestStatus =
|
|
|
|
await AppSettings.assignDeliveryboyBookingRequests(
|
|
|
|
widget.bookidID,
|
|
|
|
payload);
|
|
|
|
|
|
|
|
if (requestStatus) {
|
|
|
|
Navigator.of(context).pop();
|
|
|
|
AppSettings.longSuccessToast(
|
|
|
|
"Booking Accepted");
|
|
|
|
// await getBookingRequestsData();
|
|
|
|
|
|
|
|
|
|
|
|
} else {}
|
|
|
|
},
|
|
|
|
child: Text('Assign Deliver Boy'),
|
|
|
|
),
|
|
|
|
),*/
|
|
|
|
],
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
},
|
|
|
|
);
|
|
|
|
|
|
|
|
},
|
|
|
|
child: Text('CheckOut'),
|
|
|
|
)),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
]);
|
|
|
|
} else {
|
|
|
|
return Center(
|
|
|
|
child: Padding(
|
|
|
|
padding: EdgeInsets.fromLTRB(0, 40, 0, 0),
|
|
|
|
child: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
|
|
children: [
|
|
|
|
SizedBox(
|
|
|
|
height: MediaQuery.of(context).size.height * .25,
|
|
|
|
),
|
|
|
|
Text('No Data Found'),
|
|
|
|
SizedBox(
|
|
|
|
height: 20,
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return SafeArea(
|
|
|
|
child: Scaffold(
|
|
|
|
appBar: AppBar(
|
|
|
|
// Add a back button to the leading property
|
|
|
|
backgroundColor: primaryColor,
|
|
|
|
leading: IconButton(
|
|
|
|
icon: Icon(Icons.arrow_back), // You can use a different back icon if needed
|
|
|
|
onPressed: () {
|
|
|
|
Navigator.of(context).pop();
|
|
|
|
// Implement the navigation logic to go back
|
|
|
|
/* Navigator.push(
|
|
|
|
context,
|
|
|
|
MaterialPageRoute(builder: (context) => GetMedicines()),
|
|
|
|
);*/ // This will pop the current route and go back
|
|
|
|
},
|
|
|
|
),
|
|
|
|
title: Text('Cart Details'),
|
|
|
|
),
|
|
|
|
body: isLoading?Center(
|
|
|
|
child: CircularProgressIndicator(
|
|
|
|
color: primaryColor,
|
|
|
|
strokeWidth: 5.0,
|
|
|
|
),
|
|
|
|
):renderzUi(),
|
|
|
|
));
|
|
|
|
}
|
|
|
|
}
|