pd-android-app/lib/screens/rd orders/rd_cancelled_details_screen.dart

831 lines
42 KiB
Dart

import 'package:auto_size_text/auto_size_text.dart';
import 'package:cheminova/controller/get_order_placed_controller.dart';
import 'package:cheminova/controller/get_rd_cancle_controller.dart';
import 'package:cheminova/models/get_rd_cancelled_model.dart';
import 'package:cheminova/models/oder_place_model.dart';
import 'package:cheminova/models/order_item_model.dart';
import 'package:cheminova/models/place_order_list_model.dart';
import 'package:cheminova/models/rd_get_order_model.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_svg/svg.dart';
import 'package:get/get.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:intl/intl.dart';
import 'package:shared_preferences/shared_preferences.dart';
import '../../controller/cart_controller.dart';
import '../../models/product_model1.dart';
class RdCancelledDetailScreen extends StatefulWidget {
//final Product? productModel;
// PlacedOrderList and PlacedOrderModel are optional parameters passed to this screen
GetRdCancelledModel? placedOrderList;
// PlacedOrderModel? placedOrderModel;
// Constructor for initializing the screen with placed order details
RdCancelledDetailScreen({super.key,this.placedOrderList});
@override
State<RdCancelledDetailScreen> createState() =>
_RdCancelledDetailScreenState();
}
class _RdCancelledDetailScreenState
extends State<RdCancelledDetailScreen> {
// Controllers for managing cart and placed orders
final CartController _cartController = Get.put(CartController());
final GetPlacedOrderController _getPlacedOrderController = Get.put(GetPlacedOrderController());
final GetRDCancleController _getRDCancleController = Get.put(GetRDCancleController());
final List<String> statusOptions = [
"new",
"pending",
"processing",
"dispatched",
"cancelled",
"delivered",
];
String selectedStatus = "All";
String _groupValue = "cheque";
// Function to format date from the API to a more readable format
String formatDate(String apiDate) {
// Parse the API date string into a DateTime object
DateTime parsedDate = DateTime.parse(apiDate).toLocal(); // Convert to local time
// Format the date and time according to your specified format
String formattedDate = DateFormat('EEE MMM dd yyyy').format(parsedDate);
return formattedDate; // Return the formatted date string
}
// Function to capitalize the first letter of a string
String capitalizeFirstLetter(String text) {
if (text.isEmpty) return text;
return text[0].toUpperCase() + text.substring(1).toLowerCase();
}
void _onPaymentModeChanged(String? value) {
setState(() {
_groupValue = value!;
});
_saveSelectedPaymentMode();
}
void _saveSelectedPaymentMode() async {
SharedPreferences prefs = await SharedPreferences.getInstance();
await prefs.setString('selectedPaymentMode', _groupValue);
}
void _loadSelectedPaymentMode() async {
SharedPreferences prefs = await SharedPreferences.getInstance();
setState(() {
_groupValue = prefs.getString('selectedPaymentMode') ?? 'cheque';
});
}
// Function to collect unique order IDs and corresponding order details
// Future<void> adduni()async {
// final Set<String> uniqueOrderIds = {};
// final List<PlacedOrderList> uniqueOrders = [];
// // Loop through placed orders and add unique orders to the list
// for (var order in _getPlacedOrderController.placedOrders) {
// if (uniqueOrderIds.add(order.uniqueId)) {
// uniqueOrders.add(order);
// }
// }
// final order = uniqueOrders[0];
//
// // Combine product names, categories, and quantities into strings
// final productNames = order.orderItem
// .map((item) => (item.name))
// .join(', ');
// final categotyName = order.orderItem
// .map((item) => (item.categoryName))
// .join(', ');
// final quantity = order.orderItem
// .map((item) => (item.quantity))
// .join(', ');
// }
@override
void initState() {
// TODO: implement initState
super.initState();
selectedStatus= widget.placedOrderList?.status ?? 'new';
}
@override
Widget build(BuildContext context) {
return Scaffold(
extendBodyBehindAppBar: true,
appBar: AppBar(
backgroundColor: Colors.transparent,
elevation: 0,
leading: GestureDetector(
onTap: () {},
child: Padding(
padding: const EdgeInsets.all(16.0),
child: SvgPicture.asset(
'assets/svg/menu.svg',
),
),
),
actions: [
GestureDetector(
onTap: () => Get.back(),
child: Padding(
padding: const EdgeInsets.all(8.0),
child: SvgPicture.asset(
'assets/svg/back_arrow.svg',
),
),
),
],
title: const Text(
"RD Cancelled Order Detail",
),
),
body: Stack(
fit: StackFit.expand,
children: [
Image.asset(
'assets/images/image_1.png',
fit: BoxFit.cover,
),
SafeArea(
child: SingleChildScrollView(
child: Column(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.start,
children: [
SizedBox(
height: Get.height * 0.02,
),
Card(
margin: const EdgeInsets.symmetric(horizontal: 18),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(19),
side: const BorderSide(color: Color(0xFFFDFDFD)),
),
color: const Color(0xFFB4D1E5).withOpacity(0.9),
child: Padding(
padding: const EdgeInsets.all(12.0),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Card(
child: Column(
children: [
SizedBox(
width: Get.width,
child: Padding(
padding:
const EdgeInsets.fromLTRB(8, 8, 8, 0),
child: Text(
"Invoices",
style: GoogleFonts.roboto(
fontSize: Get.width * 0.05,
fontWeight: FontWeight.bold,
),
),
),
),
SizedBox(
width: Get.width,
child: Padding(
padding:
const EdgeInsets.fromLTRB(8, 8, 8, 0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
"Invoice ID:",
style: GoogleFonts.roboto(
fontSize: Get.width * 0.04,
fontWeight: FontWeight.bold,
),
),
Text(widget.placedOrderList!.uniqueId),
// Text(widget.placedOrderList!.uniqueId),
],
),
),
),
SizedBox(
width: Get.width,
child: Padding(
padding: const EdgeInsets.fromLTRB(8, 8, 8, 0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
"Items: ",
style: GoogleFonts.roboto(
fontSize: Get.width * 0.04,
fontWeight: FontWeight.bold,
),
),
SizedBox(height: 10), // Add spacing between the title and the list of items
Column(
children: widget.placedOrderList!.orderItems.map((item) {
return Padding(
padding: const EdgeInsets.symmetric(vertical: 4.0), // Add some spacing between items
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Expanded(
child: Text(
"${item.name.toString()} (${item.sku.toString()})",
style: GoogleFonts.roboto(
fontSize: Get.width * 0.03,
),
overflow: TextOverflow.ellipsis, // Handle long text
),
),
Text("x ${item.remainingQuantity.toString()}"),
],
),
);
}).toList(),
),
],
),
),
),
SizedBox(
width: Get.width,
child: Padding(
padding:
const EdgeInsets.fromLTRB(8, 8, 8, 0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
"Sub Total : ",
style: GoogleFonts.roboto(
fontSize: Get.width * 0.04,
fontWeight: FontWeight.bold,
),
),
Text("${widget.placedOrderList!.subtotal}"),
],
),
),
),
// SizedBox(
// width: Get.width,
// child: Padding(
// padding:
// const EdgeInsets.fromLTRB(8, 8, 8, 0),
// child: Row(
// mainAxisAlignment: MainAxisAlignment.spaceBetween,
// children: [
// Text(
// "Gst %: ",
// style: GoogleFonts.roboto(
// fontSize: Get.width * 0.04,
// fontWeight: FontWeight.bold,
// ),
// ),
// Text(" ${widget.placedOrderList!.orderItem[0].gst}%"),
// ],
// ),
// ),
// ),
SizedBox(
width: Get.width,
child: Padding(
padding:
const EdgeInsets.fromLTRB(8, 8, 8, 0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
"GST : ",
style: GoogleFonts.roboto(
fontSize: Get.width * 0.04,
fontWeight: FontWeight.bold,
),
),
Text("${widget.placedOrderList!.gstTotal}"),
],
),
),
),
SizedBox(
width: Get.width,
child: Padding(
padding:
const EdgeInsets.fromLTRB(8, 8, 8, 0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
"Invoice Amount: ",
style: GoogleFonts.roboto(
fontSize: Get.width * 0.04,
fontWeight: FontWeight.bold,
),
),
Text("${widget.placedOrderList!.grandTotal}"),
],
),
),
),
SizedBox(
width: Get.width,
child: Padding(
padding:
const EdgeInsets.fromLTRB(8, 8, 8, 0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
"Courier Status : ",
style: GoogleFonts.roboto(
fontSize: Get.width * 0.04,
fontWeight: FontWeight.bold,
),
),
ElevatedButton(
onPressed: (){},
// Get.to(() =>
// RdOrderDetailScreen(
// placedOrderList: uniqueOrders[index])), // Navigate to detail screen
style: ElevatedButton.styleFrom(
foregroundColor: Colors.white,
backgroundColor: Colors.orange,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10)),
),
child: Text(widget.placedOrderList!.status, style: GoogleFonts.roboto(fontSize: 14, fontWeight: FontWeight.w400)),
),
//Text("₹ ${widget.placedOrderList!.gstTotal}"),
],
),
),
),
],
),
),
Card(
child: SizedBox(
height: Get.height * 0.35, // Adjust the height as per your requirement
child: Padding(
padding: EdgeInsets.all(Get.width * 0.02),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
// Add title here
Padding(
padding: const EdgeInsets.symmetric(vertical: 8.0), // Adjust padding if needed
child: Text(
"Order Summary", // Title text
style: GoogleFonts.roboto(
fontSize: Get.width * 0.05, // Adjust font size as needed
fontWeight: FontWeight.bold,
),
),
),
Expanded(
child: ListView.builder(
padding: EdgeInsets.zero,
itemCount: widget.placedOrderList?.orderItems.length ?? 0,
itemBuilder: (context, index) {
final orderItem = widget.placedOrderList!.orderItems[index];
return orderItem != null
? Card(
margin: const EdgeInsets.symmetric(vertical: 5.0),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10),
),
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Row(
children: [
Image.asset(
"assets/images/product.png",
height: 50,
width: 50,
fit: BoxFit.cover,
),
const SizedBox(width: 10),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.end,
children: [
Text(
capitalizeFirstLetter(orderItem.name),
style: GoogleFonts.roboto(
fontSize: Get.width * 0.04,
fontWeight: FontWeight.bold,
),
),
Text(
"Quantity: ${orderItem.quantity}",
style: GoogleFonts.roboto(
fontSize: Get.width * 0.03,
),
),
Text("Price: ${orderItem.price}"),
Text("Subtotal: ${widget.placedOrderList!.subtotal}"),
Text("Gst: ${orderItem.gst}%"),
Text("GST Total: ${widget.placedOrderList!.gstTotal}"),
Text("Total Amount: ${widget.placedOrderList!.grandTotal}"),
],
),
),
],
),
),
)
: const SizedBox.shrink();
},
),
),
],
),
),
),
),
const SizedBox(height: 8),
Card(
child: SizedBox(
height: Get.height * 0.35, // Adjust the height as per your requirement
child: Padding(
padding: EdgeInsets.all(Get.width * 0.02),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
// Add title here
Padding(
padding: const EdgeInsets.symmetric(vertical: 8.0), // Adjust padding if needed
child: Text(
"Order Itmes to processed", // Title text
style: GoogleFonts.roboto(
fontSize: Get.width * 0.05, // Adjust font size as needed
fontWeight: FontWeight.bold,
),
),
),
Expanded(
child: ListView.builder(
padding: EdgeInsets.zero,
itemCount: widget.placedOrderList?.orderItems.length ?? 0,
itemBuilder: (context, index) {
final orderItem = widget.placedOrderList!.orderItems[index];
return orderItem != null
? Card(
margin: const EdgeInsets.symmetric(vertical: 5.0),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10),
),
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Row(
children: [
Image.asset(
"assets/images/product.png",
height: 50,
width: 50,
fit: BoxFit.cover,
),
const SizedBox(width: 10),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.end,
children: [
Text(
capitalizeFirstLetter(orderItem.name),
style: GoogleFonts.roboto(
fontSize: Get.width * 0.04,
fontWeight: FontWeight.bold,
),
),
Text(
"Quantity: ${orderItem.remainingQuantity}",
style: GoogleFonts.roboto(
fontSize: Get.width * 0.03,
),
),
Text("Price: ${orderItem.price}"),
Text("Subtotal: ${widget.placedOrderList!.subtotal}"),
Text("Gst: ${orderItem.gst}%"),
Text("GST Total: ${widget.placedOrderList!.gstTotal}"),
Text("Total Amount: ${widget.placedOrderList!.grandTotal}"),
],
),
),
],
),
),
)
: const SizedBox.shrink();
},
),
),
],
),
),
),
),
const SizedBox(height: 8),
SizedBox(
height: Get.height* 0.19,
child: Card(
child: Column(
children: [
SizedBox(
width: Get.width,
child: Padding(
padding:
const EdgeInsets.fromLTRB(8, 8, 8, 0),
child: Text(
"Customer Details",
style: GoogleFonts.roboto(
fontSize: Get.width * 0.05,
fontWeight: FontWeight.w500,
),
),
),
),
SizedBox(
width: Get.width,
//height: Get.height*0.09,
child: Padding(
padding:
const EdgeInsets.fromLTRB(8, 8, 8, 0),
child: Row(
children: [
Text(
"Name: ",
style: GoogleFonts.roboto(
fontSize: Get.width * 0.04,
fontWeight: FontWeight.bold,
),
),
Text("${"VAIBHAV"}",maxLines: 4,
overflow:TextOverflow.ellipsis,)
, ],
)
),
),
SizedBox(
width: Get.width,
// height: Get.height*0.09,
child: Padding(
padding:
const EdgeInsets.fromLTRB(8, 8, 8, 0),
child: Row(
children: [
Text(
"Email: ",
style: GoogleFonts.roboto(
fontSize: Get.width * 0.04,
fontWeight: FontWeight.bold,
),
),
Text("${"vaibhav.gurjar20001@gmail.com"}",maxLines: 4,
overflow:TextOverflow.ellipsis,)
, ],
)
),
),
SizedBox(
width: Get.width,
// height: Get.height*0.09,
child: Padding(
padding:
const EdgeInsets.fromLTRB(8, 8, 8, 0),
child: Row(
children: [
Text(
"Mobile Number: ",
style: GoogleFonts.roboto(
fontSize: Get.width * 0.04,
fontWeight: FontWeight.bold,
),
),
Text("${"7779797976"}",maxLines: 4,
overflow:TextOverflow.ellipsis,)
, ],
)
),
)
],
),
),
),
const SizedBox(height: 8),
Card(
child: Column(
children: [
SizedBox(
width: Get.width,
child: Padding(
padding:
const EdgeInsets.fromLTRB(8, 8, 8, 0),
child: Text(
"Billing Information",
style: GoogleFonts.roboto(
fontSize: Get.width * 0.05,
fontWeight: FontWeight.w500,
),
),
),
),
SizedBox(
width: Get.width,
height: Get.height*0.06,
child: Padding(
padding:
const EdgeInsets.fromLTRB(8, 8, 8, 0),
child: Wrap(
crossAxisAlignment: WrapCrossAlignment.start,
children: [
Text(
"Address: ",
style: GoogleFonts.roboto(
fontSize: Get.width * 0.04,
fontWeight: FontWeight.bold,
),
),
Text("${widget.placedOrderList!.billTo}",maxLines: 4,
overflow:TextOverflow.ellipsis,)
],
),
),
),
],
),
),
const SizedBox(height: 8),
// Card for displaying shipping information
Card(
child: Column(
children: [
SizedBox(
width: Get.width,
child: Padding(
padding:
const EdgeInsets.fromLTRB(8, 8, 8, 0),
child: Text(
"Shipping Information",
style: GoogleFonts.roboto(
fontSize: Get.width * 0.05,
fontWeight: FontWeight.w500,
),
),
),
),
SizedBox(
width: Get.width,
height: Get.height*0.06,
child: Padding(
padding:
const EdgeInsets.fromLTRB(8, 8, 8, 0),
child: Wrap(
crossAxisAlignment: WrapCrossAlignment.start,
children: [
Text(
"Address: ",
style: GoogleFonts.roboto(
fontSize: Get.width * 0.04,
fontWeight: FontWeight.bold,
),
),
Text("${widget.placedOrderList!.shipTo}",maxLines: 4,
overflow:TextOverflow.ellipsis,)
],
),
),
),
],
),
),
const SizedBox(height: 8),
Card(
child: Column(
children: [
SizedBox(
width: Get.width,
height: Get.height*0.05,
child: Padding(
padding:
const EdgeInsets.fromLTRB(8, 8, 8, 0),
child: Row(
children: [
Text(
"Payment Mode : ",
style: GoogleFonts.roboto(
fontSize: Get.width * 0.04,
fontWeight: FontWeight.w500,
),
),
Text(capitalizeFirstLetter(widget.placedOrderList!.paymentMode)),
// Text("${widget.placedOrderList!.paymentMode}",maxLines: 4,
// overflow:TextOverflow.ellipsis,)
],
),
),
),
],
),
),
const SizedBox(height: 8),
Card(
child: Column(
children: [
SizedBox(
width: Get.width,
height: Get.height*0.05,
child: Padding(
padding:
const EdgeInsets.fromLTRB(8, 8, 8, 0),
child: Row(
children: [
Text(
"Order Status :",
style: GoogleFonts.roboto(
fontSize: Get.width * 0.04,
fontWeight: FontWeight.w500,
),
),
SizedBox(width: Get.width*0.01,),
//Text(capitalizeFirstLetter(widget.placedOrderList!.status)),
Text("${widget.placedOrderList!.status}",maxLines: 4,
overflow:TextOverflow.ellipsis,)
],
),
),
),
],
),
),
const SizedBox(height: 8),
SizedBox(
height: Get.height * 0.05,
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
const Text(
"CancelledReason: ",
style: TextStyle(fontWeight: FontWeight.bold),
),
SizedBox(width: 10), // Space between label and dropdown
Text("${widget.placedOrderList!.orderCancelledReason}",maxLines: 4,
overflow:TextOverflow.ellipsis,)
],
),
),
SizedBox(
width: Get.width * 0.4,
child: Padding(
padding: const EdgeInsets.all(8.0),
child: ElevatedButton(
onPressed: (){},
// Get.to(() =>
// RdOrderDetailScreen(
// placedOrderList: uniqueOrders[index])), // Navigate to detail screen
style: ElevatedButton.styleFrom(
foregroundColor: Colors.white,
backgroundColor: const Color(0xFF004791),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10)),
),
child: Text("Update Status", style: GoogleFonts.roboto(fontSize: 14, fontWeight: FontWeight.w400)),
),
),
)
],
),
),
),
SizedBox(height: Get.height * 0.04),
],
),
),
),
],
),
);
}
}