1) annaucement api integration done

This commit is contained in:
saritabirare 2024-10-15 10:28:22 +05:30
parent 3f4c0bced9
commit ef6ef970bb
27 changed files with 2660 additions and 1161 deletions

View File

@ -0,0 +1,27 @@
import 'package:get/get.dart';
import 'package:shared_preferences/shared_preferences.dart';
import '../models/annauncement_model.dart';
import 'annaucement_service.dart';
class AnnouncementController extends GetxController {
final AnnouncementService _announcementService = AnnouncementService();
var announcements = <AnnouncementModel>[].obs;
var isLoading = true.obs;
var errorMessage = ''.obs;
Future<void> fetchAnnouncements() async {
isLoading.value = true;
try {
SharedPreferences prefs = await SharedPreferences.getInstance();
String? token = prefs.getString('token');
final List<AnnouncementModel>? fetchedAnnouncements =
await _announcementService.fetchAnnouncements(token!);
announcements.assignAll(fetchedAnnouncements as Iterable<AnnouncementModel>);
} catch (e) {
errorMessage.value = e.toString();
} finally {
isLoading.value = false;
}
}
}

View File

@ -0,0 +1,26 @@
import 'package:cheminova/utils/api_urls.dart';
import 'package:dio/dio.dart';
import '../models/annauncement_model.dart';
class AnnouncementService {
final Dio _dio = Dio();
Future<List<AnnouncementModel>> fetchAnnouncements(String token) async {
final String url = ApiUrls.AnnaouncementUrl;
try {
_dio.options.headers['Authorization'] = 'Bearer $token';
final Response response = await _dio.get(url);
if (response.statusCode == 200) {
List<dynamic> data = response.data;
return data.map((announcement) => AnnouncementModel.fromJson(announcement)).toList();
} else {
throw Exception('Failed to load announcements');
}
} catch (e) {
throw Exception('Error occurred while fetching announcements: $e');
}
}
}

View File

@ -1,33 +1,59 @@
import 'package:dio/dio.dart'; import 'package:dio/dio.dart';
import '../models/get_invoice_model.dart'; import '../models/get_invoice_model.dart';
import '../utils/api_urls.dart';
import '../utils/common_api_service.dart'; import '../utils/common_api_service.dart';
import '../utils/show_snackbar.dart';
class GetSingleInvoiceService {
Dio _dio = Dio();
class GetSingleInvoiceService{
final Dio _dio = Dio();
Future<GetInvoiceModel?> fetchInvoice(String token, String invoiceId) async { Future<GetInvoiceModel?> fetchInvoice(String token, String invoiceId) async {
final url = 'https://api.cnapp.co.in/api/pd-get-invoices/$invoiceId';
try { try {
final response = await _dio.get( // Ensure the base URL and orderId are concatenated properly
url, String url = "/api/pd-get-invoices/$invoiceId";
options: Options(
headers: { final response = await commonApiService<GetInvoiceModel>(
'Authorization': 'Bearer $token', method: "GET",
url: url,
additionalHeaders: {
'Authorization': 'Bearer $token', // Correctly pass the token as 'Bearer <token>'
},
fromJson: (json) {
// Pass the entire JSON response to the fromJson method of GetInvoiceModel
return GetInvoiceModel.fromJson(json as Map<String, dynamic>);
}, },
)
); );
if (response.statusCode == 200) { return response; // Return the fetched invoice if successful
return GetInvoiceModel.fromJson(response.data);
} else {
throw Exception('Failed to load invoice');
}
} catch (e) { } catch (e) {
print(e); // Handle error here // Show a snackbar with the error message
return null; showSnackbar(e.toString());
return null; // Return null to indicate an error occurred
} }
} }
// Future<GetInvoiceModel?> fetchInvoice(String token, String invoiceId) async {
// try {
// final response = await _dio.get(
// 'https://api.cnapp.co.in/api/pd-get-invoices/$invoiceId',
// options: Options(
// headers: {
// 'Authorization': 'Bearer $token',
// },
// ),
// );
//
// // Check if the response data is not null and status code is 200
// if (response.statusCode == 200 && response.data != null) {
// return GetInvoiceModel.fromJson(response.data); // Parse the response
// } else {
// print('Invoice not found or server error');
// return null; // Return null if data is not as expected
// }
// } catch (e) {
// print('Error fetching invoice: $e');
// return null; // Return null if there is an error
// }
// }
} }

View File

@ -1,7 +1,10 @@
import 'package:cheminova/controller/rd_processing_invoice_service.dart';
import 'package:cheminova/models/get_invoice_model.dart'; import 'package:cheminova/models/get_invoice_model.dart';
import 'package:get/get.dart'; import 'package:get/get.dart';
import 'package:shared_preferences/shared_preferences.dart'; import 'package:shared_preferences/shared_preferences.dart';
import '../models/rd_processing_invoice_model.dart';
import '../utils/show_snackbar.dart';
import 'get_single_invoice_Service.dart'; import 'get_single_invoice_Service.dart';
class GetSingleInvoiceController extends GetxController { class GetSingleInvoiceController extends GetxController {
@ -24,15 +27,63 @@ class GetSingleInvoiceController extends GetxController {
try { try {
SharedPreferences prefs = await SharedPreferences.getInstance(); SharedPreferences prefs = await SharedPreferences.getInstance();
String? token = prefs.getString('token'); String? token = prefs.getString('token');
invoice.value = (await GetSingleInvoiceService().fetchInvoice(token!,invoiceId)) final List<InvoiceResponseModel>? allOrders = await RdProcessingInvoiceService().getRDProcessingProduct(token!);
as List<GetInvoiceModel?>;
if (invoice.value == null) { // Check if the token is null or empty
errorMessage.value = 'Invoice not found'; if (token == null || token.isEmpty) {
errorMessage.value = 'Token not found'; // Handle token not being available
return;
} }
} catch (e) {
errorMessage.value = e.toString(); // Set the error message
if (allOrders == null || allOrders.isEmpty) {
print("No orders found.");
showSnackbar("No orders found.");
return;
}
// Display the number of fetched orders
print("Fetched ${allOrders.length} orders.");
// Get the ID of the first order and convert it to a String
final String firstOrderId = allOrders[0].id.toString(); // Convert to String
print("First order ID: $firstOrderId"); // Debugging: Log the order ID
// Fetch the single order using the first order ID
final GetInvoiceModel? result = await GetSingleInvoiceService().fetchInvoice(token, firstOrderId);
// Check if the result is not null
if (result != null) {
// Here, you should add the single order to your observable list
invoice.clear(); // Clear the previous data if necessary
invoice.add(result); // Add the single order to the list
} else {
// If the result is null, you can clear the list
invoice.clear();
}
// For debugging, log the fetched orders count
print("Fetched orders count: ${invoice.length}");
}
// Attempt to fetch the invoice
// final fetchedInvoice = await GetSingleInvoiceService().fetchInvoice(token, invoiceId);
// Check if the fetchedInvoice is null before accessing it
// if (fetchedInvoice != null) {
// invoice.value = fetchedInvoice as List<GetInvoiceModel?>; // Assign the fetched invoice to the observable
// } else {
// errorMessage.value = 'Invoice not found'; // Handle the case where the invoice could not be fetched
// }
// }
catch (e) {
errorMessage.value = 'Error fetching invoice: $e'; // Set the error message with more context
} finally { } finally {
isLoading.value = false; // Set loading state to false isLoading.value = false; // Set loading state to false
} }
} }
} }

View File

@ -1,73 +1,77 @@
import 'dart:convert';
import 'package:cheminova/models/single_get_order_model.dart'; import 'package:cheminova/models/single_get_order_model.dart';
import 'package:dio/dio.dart'; import 'package:dio/dio.dart';
import '../models/rd_get_order_model.dart';
import '../utils/api_urls.dart';
import '../utils/common_api_service.dart'; import '../utils/common_api_service.dart';
import '../utils/show_snackbar.dart'; import '../utils/show_snackbar.dart';
class GetSingleProductService{
// Future<SingleGetOrderModel?> getSingleOrder(String token,String orderId) async {
// try {
// // Ensure the base URL and orderId are concatenated properly
// String url = "/api/pd-get-single-place-order/$orderId";
//
// final response = await commonApiService<SingleGetOrderModel>(
// method: "GET",
// url: url,
// additionalHeaders: {
// 'Authorization': 'Bearer $token', // Correctly pass the token as 'Bearer <token>'
// },
// fromJson: (json) {
// // Check if the JSON response contains the 'singleOrder' key
// if (json['singleOrder'] != null) {
// // Convert the JSON response to a SingleGetOrderModel
// return SingleGetOrderModel.fromJson(json['singleOrder'] as Map<String, dynamic>);
// } else {
// // Handle the case when the order is not found
// throw Exception("Order not found in response.");
// }
// },
// );
//
// return response; // Return the fetched order if successful
// } catch (e) {
// // Show a snackbar with the error message
// showSnackbar(e.toString());
// return null; // Return null to indicate an error occurred
// }
// }
class GetSingleProductService {
Future<SingleGetOrderModel?> getSingleOrder(String token,String orderId) async {
Future<SingleGetOrderModel?> GetsingleOrder(String token,String orderId) async {
try { try {
final response = await Dio().get( // Ensure the base URL and orderId are concatenated properly
'https://api.cnapp.co.in/api/pd-get-single-place-order/$orderId', String url = "/api/pd-get-single-place-order/$orderId";
options: Options( final response = await commonApiService<SingleGetOrderModel>(
headers: { method: "GET",
'Authorization': 'Bearer $token', url: url,
additionalHeaders: {
'Authorization': 'Bearer $token', // Correctly pass the token as 'Bearer <token>'
},
fromJson: (json) {
// Check if the JSON response contains the 'singleOrder' key
if (json['singleOrder'] != null) {
// Convert the JSON response to a SingleGetOrderModel
return SingleGetOrderModel.fromJson(json['singleOrder'] as Map<String, dynamic>);
} else {
// Handle the case when the order is not found
throw Exception("Order not found in response.");
}
}, },
),
); );
return response; // Return the fetched order if successful
if (response.statusCode == 200) {
final data = response.data['singleOrder'];
jsonDecode(data);
return SingleGetOrderModel.fromJson(data);
} else {
print('Failed to load order');
return null;
}
} catch (e) { } catch (e) {
print('Error: $e'); // Show a snackbar with the error message
return null; showSnackbar(e.toString());
return null; // Return null to indicate an error occurred
} }
} }
//
// Future<SingleGetOrderModel?> fetchSingleOrder(String token,
// String orderId) async {
// final String url = 'https://api.cnapp.co.in/api/pd-get-single-place-order/$orderId';
//
// try {
// Response response = await Dio().get(
// url,
// options: Options(
// headers: {
// 'Authorization': 'Bearer $token',
// 'Content-Type': 'application/json',
// },
// ),
// );
//
// if (response.statusCode == 200 && response.data != null) {
// // Check if 'singleOrder' is present in the response
// final singleOrderData = response.data['singleOrder'];
//
// if (singleOrderData != null) {
// return SingleGetOrderModel.fromJson(singleOrderData);
// } else {
// print('No single order data found in response.');
// return null;
// }
// } else {
// print('Failed to load order data: ${response.statusCode}');
// return null;
// }
// } catch (e) {
// print('Error fetching order data: $e');
// return null;
// }
// }
} }

View File

@ -30,7 +30,9 @@ class RDOrderPlacedService {
if (response.statusCode != 200) { if (response.statusCode != 200) {
throw Exception('Failed to RD place order'); throw Exception('Failed to RD place order');
} }
else if(response.statusCode != 200 && response.statusCode == 400){
showSnackbar("stock not Available");
}
} }
Future<void> RDOrderCancel(String token, String orderId, String reason) async { Future<void> RDOrderCancel(String token, String orderId, String reason) async {

View File

@ -1,52 +1,115 @@
import 'dart:convert'; import 'dart:convert';
import 'package:cheminova/controller/rd_get_order_service.dart';
import 'package:cheminova/controller/rd_get_single_service.dart'; import 'package:cheminova/controller/rd_get_single_service.dart';
import 'package:cheminova/models/single_get_order_model.dart'; import 'package:cheminova/models/single_get_order_model.dart';
import 'package:get/get.dart'; import 'package:get/get.dart';
import 'package:shared_preferences/shared_preferences.dart'; import 'package:shared_preferences/shared_preferences.dart';
import '../models/rd_get_order_model.dart';
import '../utils/show_snackbar.dart'; import '../utils/show_snackbar.dart';
class RdSingleOrderController extends GetxController { class RdSingleOrderController extends GetxController {
var isLoading = true.obs; // Tracks the loading state var isLoading = true.obs; // Tracks the loading state
var productRDOrderSingleList = <SingleGetOrderModel>[].obs; // List of products var productRDOrderSingleList = <SingleGetOrderModel>[].obs; // List of products
//
Future<void> fetchRDSingleOrderProduct(String id) async { Future<void> fetchAllOrdersAndSingleOrder() async {
try {
SharedPreferences prefs = await SharedPreferences.getInstance(); SharedPreferences prefs = await SharedPreferences.getInstance();
String? token = prefs.getString('token'); String? token = prefs.getString('token');
// Check if the token exists before proceeding final List<PlacedOrdersResponse>? allOrders = await GetProductRDService().getRDProducts(token!);
if (token == null || token.isEmpty) {
print("Token is missing");
throw Exception("Token is missing");
}
print("Login token: $token"); if (allOrders == null || allOrders.isEmpty) {
isLoading(true); // Start loading
// Check if the list has any elements
if (productRDOrderSingleList.isEmpty) {
print("No orders found."); print("No orders found.");
showSnackbar("No orders found."); showSnackbar("No orders found.");
return; // Early exit if no orders are available return;
} }
// Fetch the product using the API call, passing the token // Display the number of fetched orders
final response = await GetSingleProductService().GetsingleOrder(token, id); print("Fetched ${allOrders.length} orders.");
if (response != null) { // Get the ID of the first order and convert it to a String
// Assign the fetched products to the observable list (uncomment this if needed) final String firstOrderId = allOrders[0].id.toString(); // Convert to String
// productRDOrderSingleList.assignAll(response); print("First order ID: $firstOrderId"); // Debugging: Log the order ID
print("Fetched order details: $response");
// Fetch the single order using the first order ID
final SingleGetOrderModel? result = await GetSingleProductService().getSingleOrder(token!, firstOrderId);
// Check if the result is not null
if (result != null) {
// Here, you should add the single order to your observable list
productRDOrderSingleList.clear(); // Clear the previous data if necessary
productRDOrderSingleList.add(result); // Add the single order to the list
} else { } else {
print("Response is null"); // If the result is null, you can clear the list
showSnackbar("Response is null"); productRDOrderSingleList.clear();
}
} catch (e) {
// Print the error for debugging
print("Error: $e");
showSnackbar("Error: $e");
} finally {
isLoading(false); // End loading
} }
// For debugging, log the fetched orders count
print("Fetched orders count: ${productRDOrderSingleList.length}");
} }
//
// Future<void> fetchAllOrdersAndSingleOrder() async {
// try {
// // Fetch all orders from your API
// SharedPreferences prefs = await SharedPreferences.getInstance();
// String? token = prefs.getString('token');
// final response = await GetProductRDService().getRDProducts(token!); // Adjust as per your API
//
// if (response != null && response.isNotEmpty) {
// productRDOrderSingleList.value = jsonDecode(response.toString()); // Assuming response is a List of orders
// } else {
// productRDOrderSingleList;
// }
// } catch (e) {
// print('Error fetching orders: $e');
// productRDOrderSingleList; // Ensure the list is empty on error
// }
// }
} }
// Future<void> fetchAllOrdersAndSingleOrder(String id) async {
// SharedPreferences prefs = await SharedPreferences.getInstance();
// String? token = prefs.getString('token');
//
// final List<PlacedOrdersResponse>? allOrders = await GetProductRDService().getRDProducts(token!);
//
// if (allOrders == null || allOrders.isEmpty) {
// print("No orders found.");
// showSnackbar("No orders found.");
// return;
// }
//
// // Display the number of fetched orders
// print("Fetched ${allOrders.length} orders.");
//
// // Fetch the single order using the provided selectedOrderId
// String orderIdToFetch = allOrders[0].id.toString(); // Use provided ID or first order ID
// print("Fetching order ID: $orderIdToFetch"); // Debugging: Log the order ID
//
// final result = (await GetSingleProductService().getSingleOrder(token, orderIdToFetch)) ;
//
// // Check if the result is not null
// if (result != null) {
// // Here, you should add the single order to your observable list
// productRDOrderSingleList.clear(); // Clear the previous data if necessary
// productRDOrderSingleList.add(result); // Add the single order to the list
// } else {
// // If the result is null, you can clear the list
// productRDOrderSingleList.clear();
// }
//
// // For debugging, log the fetched orders count
// print("Fetched orders count: ${productRDOrderSingleList.length}");
// }

View File

@ -0,0 +1,28 @@
class AnnouncementModel {
final String id;
final String uniqueId;
final List<String> sentTo;
final String message;
final DateTime createdAt;
final DateTime updatedAt;
AnnouncementModel({
required this.id,
required this.uniqueId,
required this.sentTo,
required this.message,
required this.createdAt,
required this.updatedAt,
});
factory AnnouncementModel.fromJson(Map<String, dynamic> json) {
return AnnouncementModel(
id: json['_id']??"",
uniqueId: json['uniqueId']??"",
sentTo: List<String>.from(json['sentTo']),
message: json['message']??"",
createdAt: DateTime.parse(json['createdAt']),
updatedAt: DateTime.parse(json['updatedAt']),
);
}
}

View File

@ -1,243 +1,244 @@
class GetInvoiceModel { class GetInvoiceModel {
CourierStatusTimeline courierStatusTimeline; CourierStatusTimeline? courierStatusTimeline;
String id; String? id;
String invoiceId; String? invoiceId;
OrderId orderId; OrderId? orderId;
List<Item> items; List<Item>? items;
int subtotal; int? subtotal;
double gstTotal; double? gstTotal;
double invoiceAmount; double? invoiceAmount;
String courierStatus; String? courierStatus;
int v; int? v;
GetInvoiceModel({ GetInvoiceModel({
required this.courierStatusTimeline, this.courierStatusTimeline,
required this.id, this.id,
required this.invoiceId, this.invoiceId,
required this.orderId, this.orderId,
required this.items, this.items,
required this.subtotal, this.subtotal,
required this.gstTotal, this.gstTotal,
required this.invoiceAmount, this.invoiceAmount,
required this.courierStatus, this.courierStatus,
required this.v, this.v,
}); });
factory GetInvoiceModel.fromJson(Map<String, dynamic> json) { factory GetInvoiceModel.fromJson(Map<String, dynamic> json) {
return GetInvoiceModel( return GetInvoiceModel(
courierStatusTimeline: CourierStatusTimeline.fromJson( courierStatusTimeline: json['courierstatus_timeline'] != null
json['courierstatus_timeline']), ? CourierStatusTimeline.fromJson(json['courierstatus_timeline'])
id: json['_id'], : null,
invoiceId: json['invoiceId'], id: json['_id'].toString() ?? '',
orderId: OrderId.fromJson(json['orderId']), invoiceId: json['invoiceId'].toString() ?? '',
items: List<Item>.from(json['items'].map((item) => Item.fromJson(item))), orderId: json['orderId'] != null ? OrderId.fromJson(json['orderId']) : null,
subtotal: json['subtotal'], items: (json['items'] as List?)?.map((item) => Item.fromJson(item)).toList() ?? [],
gstTotal: json['gstTotal'].toDouble(), subtotal: json['subtotal']?? 0,
invoiceAmount: json['invoiceAmount'].toDouble(), gstTotal: json['gstTotal']?.toDouble() ?? 0.0,
courierStatus: json['courierStatus'], invoiceAmount: json['invoiceAmount']?.toDouble() ?? 0.0,
v: json['__v'], courierStatus: json['courierStatus'].toString() ?? 'processing',
v: json['__v'] ?? 0,
); );
} }
} }
class CourierStatusTimeline { class CourierStatusTimeline {
String processing; String? processing;
CourierStatusTimeline({ CourierStatusTimeline({
required this.processing, this.processing,
}); });
factory CourierStatusTimeline.fromJson(Map<String, dynamic> json) { factory CourierStatusTimeline.fromJson(Map<String, dynamic> json) {
return CourierStatusTimeline( return CourierStatusTimeline(
processing: json['processing'], processing: json['processing'] ?? '',
); );
} }
} }
class OrderId { class OrderId {
String id; String? id;
String paymentMode; String? paymentMode;
String shipTo; String? shipTo;
String billTo; String? billTo;
List<OrderItem> orderItems; List<OrderItem>? orderItems;
int subtotal; int? subtotal;
double gstTotal; double? gstTotal;
double grandTotal; double? grandTotal;
String status; String? status;
List<String> invoices; List<String>? invoices;
AddedBy addedBy; AddedBy? addedBy;
String pd; String? pd;
bool isCancelled; bool? isCancelled;
bool isDelivered; bool? isDelivered;
String deliveredDate; String? deliveredDate;
String statusUpdatedAt; String? statusUpdatedAt;
String uniqueId; String? uniqueId;
String createdAt; String? createdAt;
String updatedAt; String? updatedAt;
int v; int? v;
OrderId({ OrderId({
required this.id, this.id,
required this.paymentMode, this.paymentMode,
required this.shipTo, this.shipTo,
required this.billTo, this.billTo,
required this.orderItems, this.orderItems,
required this.subtotal, this.subtotal,
required this.gstTotal, this.gstTotal,
required this.grandTotal, this.grandTotal,
required this.status, this.status,
required this.invoices, this.invoices,
required this.addedBy, this.addedBy,
required this.pd, this.pd,
required this.isCancelled, this.isCancelled,
required this.isDelivered, this.isDelivered,
required this.deliveredDate, this.deliveredDate,
required this.statusUpdatedAt, this.statusUpdatedAt,
required this.uniqueId, this.uniqueId,
required this.createdAt, this.createdAt,
required this.updatedAt, this.updatedAt,
required this.v, this.v,
}); });
factory OrderId.fromJson(Map<String, dynamic> json) { factory OrderId.fromJson(Map<String, dynamic> json) {
return OrderId( return OrderId(
id: json['_id'], id: json['_id'].toString() ?? '',
paymentMode: json['paymentMode'], paymentMode: json['paymentMode'].toString() ?? '',
shipTo: json['shipTo'], shipTo: json['shipTo'].toString() ?? '',
billTo: json['billTo'], billTo: json['billTo'].toString() ?? '',
orderItems: List<OrderItem>.from(json['orderItem'].map((item) => OrderItem.fromJson(item))), orderItems: (json['orderItem'] as List?)?.map((item) => OrderItem.fromJson(item)).toList() ?? [],
subtotal: json['subtotal'], subtotal: json['subtotal'] ?? 0,
gstTotal: json['gstTotal'].toDouble(), gstTotal: json['gstTotal']?.toDouble() ?? 0.0,
grandTotal: json['grandTotal'].toDouble(), grandTotal: json['grandTotal']?.toDouble() ?? 0.0,
status: json['status'], status: json['status'].toString()?? '',
invoices: List<String>.from(json['invoices']), invoices: List<String>.from(json['invoices'] ?? []),
addedBy: AddedBy.fromJson(json['addedBy']), addedBy: json['addedBy'] != null ? AddedBy.fromJson(json['addedBy']) : null,
pd: json['pd'], pd: json['pd'].toString() ?? '',
isCancelled: json['iscancelled'], isCancelled: json['iscancelled'] ?? false,
isDelivered: json['isDelivered'], isDelivered: json['isDelivered'] ?? false,
deliveredDate: json['DeliveredDate'] ?? '', deliveredDate: json['DeliveredDate']?? '',
statusUpdatedAt: json['statusUpdatedAt'], statusUpdatedAt: json['statusUpdatedAt'] ?? '',
uniqueId: json['uniqueId'], uniqueId: json['uniqueId'].toString() ?? '',
createdAt: json['createdAt'], createdAt: json['createdAt'] ?? '',
updatedAt: json['updatedAt'], updatedAt: json['updatedAt'] ?? '',
v: json['__v'], v: json['__v'] ?? 0,
); );
} }
} }
class OrderItem { class OrderItem {
String productId; String? productId;
String sku; String? sku;
String name; String? name;
String categoryName; String? categoryName;
String brandName; String? brandName;
int price; int? price;
int gst; int? gst;
int hsnCode; int? hsnCode;
String description; String? description;
List<dynamic> image; List<dynamic>? image;
int quantity; int? quantity;
int remainingQuantity; int? remainingQuantity;
String id; String? id;
OrderItem({ OrderItem({
required this.productId, this.productId,
required this.sku, this.sku,
required this.name, this.name,
required this.categoryName, this.categoryName,
required this.brandName, this.brandName,
required this.price, this.price,
required this.gst, this.gst,
required this.hsnCode, this.hsnCode,
required this.description, this.description,
required this.image, this.image,
required this.quantity, this.quantity,
required this.remainingQuantity, this.remainingQuantity,
required this.id, this.id,
}); });
factory OrderItem.fromJson(Map<String, dynamic> json) { factory OrderItem.fromJson(Map<String, dynamic> json) {
return OrderItem( return OrderItem(
productId: json['productId'], productId: json['productId'].toString()?? '',
sku: json['SKU'], sku: json['SKU'].toString() ?? '',
name: json['name'], name: json['name'].toString()?? '',
categoryName: json['categoryName'], categoryName: json['categoryName'].toString() ?? '',
brandName: json['brandName'], brandName: json['brandName'].toString() ?? '',
price: json['price'], price: json['price'] ?? 0,
gst: json['GST'], gst: json['GST'] ?? 0,
hsnCode: json['HSN_Code'], hsnCode: json['HSN_Code'] ?? 0,
description: json['description'] ?? '', description: json['description'] ?? '',
image: List<dynamic>.from(json['image']), image: List<dynamic>.from(json['image'] ?? []),
quantity: json['quantity'], quantity: json['quantity'] ?? 0,
remainingQuantity: json['remainingQuantity'], remainingQuantity: json['remainingQuantity'] ?? 0,
id: json['_id'], id: json['_id'] ?? '',
); );
} }
} }
class Item { class Item {
String productId; String? productId;
String sku; String? sku;
String name; String? name;
String categoryName; String? categoryName;
String brandName; String? brandName;
int price; int? price;
int gst; int? gst;
int hsnCode; int? hsnCode;
int processQuantity; int? processQuantity;
String id; String? id;
Item({ Item({
required this.productId, this.productId,
required this.sku, this.sku,
required this.name, this.name,
required this.categoryName, this.categoryName,
required this.brandName, this.brandName,
required this.price, this.price,
required this.gst, this.gst,
required this.hsnCode, this.hsnCode,
required this.processQuantity, this.processQuantity,
required this.id, this.id,
}); });
factory Item.fromJson(Map<String, dynamic> json) { factory Item.fromJson(Map<String, dynamic> json) {
return Item( return Item(
productId: json['productId'], productId: json['productId'].toString() ?? '',
sku: json['SKU'], sku: json['SKU'].toString() ?? '',
name: json['name'], name: json['name'].toString() ?? '',
categoryName: json['categoryName'], categoryName: json['categoryName'].toString()?? '',
brandName: json['brandName'], brandName: json['brandName'].toString() ?? '',
price: json['price'], price: json['price'] ?? 0,
gst: json['GST'], gst: json['GST'] ?? 0,
hsnCode: json['HSN_Code'], hsnCode: json['HSN_Code'] ?? 0,
processQuantity: json['processquantity'], processQuantity: json['processquantity'] ?? 0,
id: json['_id'], id: json['_id'] ?? '',
); );
} }
} }
class AddedBy { class AddedBy {
String id; String? id;
String name; String? name;
String email; String? email;
String mobileNumber; String? mobileNumber;
dynamic fcmToken; dynamic fcmToken;
AddedBy({ AddedBy({
required this.id, this.id,
required this.name, this.name,
required this.email, this.email,
required this.mobileNumber, this.mobileNumber,
this.fcmToken, this.fcmToken,
}); });
factory AddedBy.fromJson(Map<String, dynamic> json) { factory AddedBy.fromJson(Map<String, dynamic> json) {
return AddedBy( return AddedBy(
id: json['_id'], id: json['_id'].toString() ?? '',
name: json['name'], name: json['name'].toString() ?? '',
email: json['email'], email: json['email'].toString()?? '',
mobileNumber: json['mobile_number'], mobileNumber: json['mobile_number']?? '',
fcmToken: json['fcm_token'], fcmToken: json['fcm_token']??"789789798798",
); );
} }
} }

View File

@ -26,12 +26,12 @@
required this.image, required this.image,
this.quantity, this.quantity,
this.remainingQuantity, this.remainingQuantity,
this.processquantity, this.processquantity = 1,
}); });
factory RDOrderItem.fromJson(Map<String, dynamic> json) { factory RDOrderItem.fromJson(Map<String, dynamic> json) {
return RDOrderItem( return RDOrderItem(
productId: json['productId'] ?? '', productId: json['productId'].toString()?? '',
sku: json['SKU'] ?? '', sku: json['SKU'] ?? '',
name: json['name'] ?? '', name: json['name'] ?? '',
categoryName: json['categoryName'] ?? '', categoryName: json['categoryName'] ?? '',

View File

@ -1,44 +1,46 @@
import 'package:cheminova/models/rd_order_item_model.dart';
class SingleGetOrderModel { class SingleGetOrderModel {
final String id; final String id;
final String paymentMode; String? paymentMode;
final String shipTo; String? shipTo;
final String billTo; String? billTo;
final List<OrderItem> orderItem; List<RDOrderItem>? orderItem;
final double subtotal; double? subtotal;
final double gstTotal; double? gstTotal;
final double grandTotal; double? grandTotal;
final String status; String? status;
final List<dynamic> invoices; List<dynamic>? invoices;
final AddedBy addedBy; AddedBy? addedBy;
final String pd; String? pd;
final bool isCancelled; bool? isCancelled;
final bool isDelivered; bool? isDelivered;
final String deliveredDate; String? deliveredDate;
final DateTime statusUpdatedAt; DateTime? statusUpdatedAt;
final String uniqueId; String? uniqueId;
final DateTime createdAt; DateTime? createdAt;
final DateTime updatedAt; DateTime? updatedAt;
SingleGetOrderModel({ SingleGetOrderModel({
required this.id, required this.id,
required this.paymentMode, this.paymentMode,
required this.shipTo, this.shipTo,
required this.billTo, this.billTo,
required this.orderItem, this.orderItem,
required this.subtotal, this.subtotal,
required this.gstTotal, this.gstTotal,
required this.grandTotal, this.grandTotal,
required this.status, this.status,
required this.invoices, this.invoices,
required this.addedBy, this.addedBy,
required this.pd, this.pd,
required this.isCancelled, this.isCancelled,
required this.isDelivered, this.isDelivered,
required this.deliveredDate, this.deliveredDate,
required this.statusUpdatedAt, this.statusUpdatedAt,
required this.uniqueId, this.uniqueId,
required this.createdAt, this.createdAt,
required this.updatedAt, this.updatedAt,
}); });
factory SingleGetOrderModel.fromJson(Map<String, dynamic> json) { factory SingleGetOrderModel.fromJson(Map<String, dynamic> json) {
@ -48,7 +50,7 @@ class SingleGetOrderModel {
shipTo: json['shipTo'] ?? '', shipTo: json['shipTo'] ?? '',
billTo: json['billTo'] ?? '', billTo: json['billTo'] ?? '',
orderItem: (json['orderItem'] as List<dynamic>?) orderItem: (json['orderItem'] as List<dynamic>?)
?.map((item) => OrderItem.fromJson(item)) ?.map((item) => RDOrderItem.fromJson(item))
.toList() ?? .toList() ??
[], [],
subtotal: (json['subtotal'] as num?)?.toDouble() ?? 0.0, subtotal: (json['subtotal'] as num?)?.toDouble() ?? 0.0,
@ -74,27 +76,27 @@ class SingleGetOrderModel {
'paymentMode': paymentMode, 'paymentMode': paymentMode,
'shipTo': shipTo, 'shipTo': shipTo,
'billTo': billTo, 'billTo': billTo,
'orderItem': orderItem.map((item) => item.toJson()).toList(), 'orderItem': orderItem?.map((item) => item.toJson()).toList(),
'subtotal': subtotal, 'subtotal': subtotal,
'gstTotal': gstTotal, 'gstTotal': gstTotal,
'grandTotal': grandTotal, 'grandTotal': grandTotal,
'status': status, 'status': status,
'invoices': invoices, 'invoices': invoices,
'addedBy': addedBy.toJson(), 'addedBy': addedBy?.toJson(),
'pd': pd, 'pd': pd,
'iscancelled': isCancelled, 'iscancelled': isCancelled,
'isDelivered': isDelivered, 'isDelivered': isDelivered,
'DeliveredDate': deliveredDate, 'DeliveredDate': deliveredDate,
'statusUpdatedAt': statusUpdatedAt.toIso8601String(), 'statusUpdatedAt': statusUpdatedAt?.toIso8601String(),
'uniqueId': uniqueId, 'uniqueId': uniqueId,
'createdAt': createdAt.toIso8601String(), 'createdAt': createdAt?.toIso8601String(),
'updatedAt': updatedAt.toIso8601String(), 'updatedAt': updatedAt?.toIso8601String(),
}; };
} }
@override @override
String toString() { String toString() {
return 'SingleOrder(id: $id, paymentMode: $paymentMode, shipTo: $shipTo, billTo: $billTo, ' return 'SingleGetOrderModel(id: $id, paymentMode: $paymentMode, shipTo: $shipTo, billTo: $billTo, '
'orderItem: $orderItem, subtotal: $subtotal, gstTotal: $gstTotal, grandTotal: $grandTotal, ' 'orderItem: $orderItem, subtotal: $subtotal, gstTotal: $gstTotal, grandTotal: $grandTotal, '
'status: $status, invoices: $invoices, addedBy: $addedBy, pd: $pd, ' 'status: $status, invoices: $invoices, addedBy: $addedBy, pd: $pd, '
'isCancelled: $isCancelled, isDelivered: $isDelivered, deliveredDate: $deliveredDate, ' 'isCancelled: $isCancelled, isDelivered: $isDelivered, deliveredDate: $deliveredDate, '
@ -108,14 +110,15 @@ class OrderItem {
final String name; final String name;
final String categoryName; final String categoryName;
final String brandName; final String brandName;
final double price; final int price; // Use int for price
final double gst; final int gst; // Use int for GST
final String hsnCode; final int hsnCode; // Use int for HSN Code
final String description; final String description;
final List<dynamic> image; final List<String> image; // Assuming images are stored as a list of strings
final int quantity; final int quantity;
final int remainingQuantity; final int remainingQuantity;
final String id; int? processQuantity;
final String id; // Use String for _id
OrderItem({ OrderItem({
required this.productId, required this.productId,
@ -130,6 +133,7 @@ class OrderItem {
required this.image, required this.image,
required this.quantity, required this.quantity,
required this.remainingQuantity, required this.remainingQuantity,
this.processQuantity = 1,
required this.id, required this.id,
}); });
@ -140,13 +144,14 @@ class OrderItem {
name: json['name'] ?? '', name: json['name'] ?? '',
categoryName: json['categoryName'] ?? '', categoryName: json['categoryName'] ?? '',
brandName: json['brandName'] ?? '', brandName: json['brandName'] ?? '',
price: (json['price'] as num?)?.toDouble() ?? 0.0, price: (json['price'] as num?)?.toInt() ?? 0, // Handle as num
gst: (json['GST'] as num?)?.toDouble() ?? 0.0, gst: (json['GST'] as num?)?.toInt() ?? 0, // Handle as num
hsnCode: json['HSN_Code'] ?? '', hsnCode: (json['HSN_Code'] as num?)?.toInt() ?? 0, // Handle as num
description: json['description'] ?? '', description: json['description'] ?? '',
image: json['image'] ?? [], image: List<String>.from(json['image'] ?? []),
quantity: json['quantity'] ?? 0, quantity: (json['quantity'] as num?)?.toInt() ?? 0, // Handle as num
remainingQuantity: json['remainingQuantity'] ?? 0, remainingQuantity: (json['remainingQuantity'] as num?)?.toInt() ?? 0, // Handle as num
processQuantity: (json['processQuantity']as num?)?.toInt()??0,
id: json['_id'] ?? '', id: json['_id'] ?? '',
); );
} }
@ -188,7 +193,7 @@ class AddedBy {
final String addedBy; final String addedBy;
final String userType; final String userType;
final String kyc; final String kyc;
final String? fcmToken; String? fcmToken;
final DateTime createdAt; final DateTime createdAt;
final DateTime updatedAt; final DateTime updatedAt;
final String mappedSC; final String mappedSC;
@ -224,7 +229,7 @@ class AddedBy {
addedBy: json['addedBy'] ?? '', addedBy: json['addedBy'] ?? '',
userType: json['userType'] ?? '', userType: json['userType'] ?? '',
kyc: json['kyc'] ?? '', kyc: json['kyc'] ?? '',
fcmToken: json['fcm_token'], fcmToken: json['fcm_token']?.toString(), // Handle null safely
createdAt: DateTime.parse(json['createdAt'] ?? DateTime.now().toString()), createdAt: DateTime.parse(json['createdAt'] ?? DateTime.now().toString()),
updatedAt: DateTime.parse(json['updatedAt'] ?? DateTime.now().toString()), updatedAt: DateTime.parse(json['updatedAt'] ?? DateTime.now().toString()),
mappedSC: json['mappedSC'] ?? '', mappedSC: json['mappedSC'] ?? '',
@ -257,8 +262,8 @@ class AddedBy {
String toString() { String toString() {
return 'AddedBy(id: $id, designation: $designation, name: $name, email: $email, ' return 'AddedBy(id: $id, designation: $designation, name: $name, email: $email, '
'mobileNumber: $mobileNumber, principalDistributor: $principalDistributor, ' 'mobileNumber: $mobileNumber, principalDistributor: $principalDistributor, '
'addedBy: $addedBy, userType: $userType, kyc: $kyc, fcmToken: $fcmToken, ' 'addedBy: $addedBy, userType: $userType, kyc: $kyc, '
'createdAt: $createdAt, updatedAt: $updatedAt, mappedSC: $mappedSC, ' 'fcmToken: $fcmToken, createdAt: $createdAt, updatedAt: $updatedAt, '
'uniqueId: $uniqueId, mappedTM: $mappedTM)'; 'mappedSC: $mappedSC, uniqueId: $uniqueId, mappedTM: $mappedTM)';
} }
} }

View File

@ -0,0 +1,105 @@
import 'package:cheminova/widgets/my_drawer.dart';
import 'package:flutter/material.dart';
import 'package:flutter_svg/svg.dart';
import 'package:get/get.dart';
import 'package:intl/intl.dart';
import '../../controller/annaucement_controller.dart';
import '../../widgets/comman_background.dart';
import '../../widgets/common_appbar.dart';
class AnnouncementScreen extends StatefulWidget {
AnnouncementScreen({super.key});
@override
State<AnnouncementScreen> createState() => _AnnouncementScreenState();
}
class _AnnouncementScreenState extends State<AnnouncementScreen> {
// Initialize the controller
final AnnouncementController _announcementController = Get.put(AnnouncementController());
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
}
@override
Widget build(BuildContext context) {
// Fetch announcements when the screen is built
_announcementController.fetchAnnouncements();
return CommonBackground(
child: Scaffold(
backgroundColor: Colors.transparent,
appBar: CommonAppBar(
actions: [
IconButton(
onPressed: () {
Navigator.pop(context);
},
icon: SvgPicture.asset('assets/svg/back_arrow.svg'),
padding: const EdgeInsets.only(right: 20),
),
],
title: const Text(
'Announcement',
style: TextStyle(
fontSize: 20,
color: Colors.black,
fontWeight: FontWeight.w400,
fontFamily: 'Anek',
),
),
backgroundColor: Colors.transparent,
elevation: 0,
),
drawer: MyDrawer(),
body: Obx(() {
// Show loading indicator while fetching announcements
if (_announcementController.isLoading.value) {
return Center(child: CircularProgressIndicator());
}
// Show error message if there was an error
if (_announcementController.errorMessage.isNotEmpty) {
return Center(
child: Text('Error: ${_announcementController.errorMessage}'),
);
}
// Display the list of announcements
return ListView.builder(
itemCount: _announcementController.announcements.length,
itemBuilder: (context, index) {
return Card(
child: ListTile(
//leading:Text(_announcementController.announcements[index].id),
title: Row(
children: [
Text("Message :",style: TextStyle(fontWeight: FontWeight.bold),),
Text(_announcementController.announcements[index].message),
],
),
subtitle: Row(
children: [
Text("UniqueID :" , style: TextStyle(fontWeight: FontWeight.bold),),
Text(_announcementController.announcements[index].uniqueId),
],
),
trailing: Text(formatDate(_announcementController.announcements[index].createdAt.toIso8601String())),
),
);
},
);
}),
),
);
}
}

View File

@ -1,4 +1,5 @@
import 'package:cheminova/controller/home_controller.dart'; import 'package:cheminova/controller/home_controller.dart';
import 'package:cheminova/screens/annauncement/annauncement.dart';
import 'package:cheminova/screens/inventory/inventory_management_screen.dart'; import 'package:cheminova/screens/inventory/inventory_management_screen.dart';
import 'package:cheminova/screens/kyc/kyc_screen.dart'; import 'package:cheminova/screens/kyc/kyc_screen.dart';
import 'package:cheminova/screens/notification/notification_screen.dart'; import 'package:cheminova/screens/notification/notification_screen.dart';
@ -187,12 +188,12 @@ class _HomeScreenState extends State<HomeScreen> {
() => RdOrderScreen(), () => RdOrderScreen(),
), ),
), ),
// HomeCard( HomeCard(
// title: 'Kyc', title: 'Announcement',
// onTap: () => Get.to( onTap: () => Get.to(
// () => KycRetailerInfoScreen(), () => AnnouncementScreen(),
// ), ),
// ), ),
], ],

View File

@ -3,6 +3,7 @@ import 'package:cheminova/models/rd_get_order_model.dart';
import 'package:cheminova/models/rd_order_item_model.dart'; import 'package:cheminova/models/rd_order_item_model.dart';
import 'package:cheminova/models/rd_placed_order_model.dart'; import 'package:cheminova/models/rd_placed_order_model.dart';
import 'package:cheminova/screens/order/checkout_screen.dart'; import 'package:cheminova/screens/order/checkout_screen.dart';
import 'package:cheminova/screens/rd%20orders/rd_pending_screen.dart';
import 'package:cheminova/widgets/my_drawer.dart'; import 'package:cheminova/widgets/my_drawer.dart';
import 'package:cheminova/widgets/product_card.dart'; import 'package:cheminova/widgets/product_card.dart';
import 'package:cheminova/widgets/product_card1.dart'; import 'package:cheminova/widgets/product_card1.dart';
@ -16,12 +17,14 @@ import '../../controller/rd_processing_order_controller.dart';
import '../../models/get_rd_pennding_model.dart'; import '../../models/get_rd_pennding_model.dart';
import '../../models/oder_place_model.dart'; import '../../models/oder_place_model.dart';
import '../../models/product_model1.dart'; import '../../models/product_model1.dart';
import '../../models/single_get_order_model.dart';
import '../../utils/show_snackbar.dart'; import '../../utils/show_snackbar.dart';
class PartialPendingDialogScreen extends StatefulWidget { class PartialPendingDialogScreen extends StatefulWidget {
// PlacedOrdersResponse? productModel; // PlacedOrdersResponse? productModel;
GetRdPendingModel? productpendingModel; //GetRdPendingModel? productpendingModel;
PartialPendingDialogScreen({super.key, this.productpendingModel}); SingleGetOrderModel? placedOrderList;
PartialPendingDialogScreen({super.key, this.placedOrderList});
@override @override
State<PartialPendingDialogScreen> createState() => _PartialPendingDialogScreenState(); State<PartialPendingDialogScreen> createState() => _PartialPendingDialogScreenState();
@ -38,7 +41,7 @@ class _PartialPendingDialogScreenState extends State<PartialPendingDialogScreen>
_separateProcessingAndPendingItems(); _separateProcessingAndPendingItems();
} }
void _separateProcessingAndPendingItems() { void _separateProcessingAndPendingItems() {
for (var item in widget.productpendingModel!.orderItem) { for (var item in widget.placedOrderList!.orderItem!.toList()) {
if (item.remainingQuantity! > 0) { if (item.remainingQuantity! > 0) {
// If remainingQuantity > 0, it is available for processing // If remainingQuantity > 0, it is available for processing
processingItems.add(item ); processingItems.add(item );
@ -87,7 +90,7 @@ class _PartialPendingDialogScreenState extends State<PartialPendingDialogScreen>
List<RDOrderItem> orderItems = orderItemMap.values.toList(); List<RDOrderItem> orderItems = orderItemMap.values.toList();
controller.placedOrder1.value = PlacedOrdersProcessing( controller.placedOrder1.value = PlacedOrdersProcessing(
orderId: widget.productpendingModel!.id, orderId: widget.placedOrderList!.id,
invoiceItems: orderItems, invoiceItems: orderItems,
); );
@ -95,7 +98,8 @@ class _PartialPendingDialogScreenState extends State<PartialPendingDialogScreen>
showSnackbar("Partial order processed successfully."); showSnackbar("Partial order processed successfully.");
Future.delayed(const Duration(seconds: 1), () { Future.delayed(const Duration(seconds: 1), () {
Navigator.of(context).pop(); Get.to(RdOrderPendingScreen());
//Navigator.of(context).pop();
}); });
setState(() {}); setState(() {});
@ -199,7 +203,7 @@ class _PartialPendingDialogScreenState extends State<PartialPendingDialogScreen>
fontWeight: FontWeight.bold, fontWeight: FontWeight.bold,
), ),
), ),
Text("${widget.productpendingModel!.subtotal ?? 0}"), Text("${widget.placedOrderList!.subtotal ?? 0}"),
], ],
), ),
Row( Row(
@ -213,7 +217,7 @@ class _PartialPendingDialogScreenState extends State<PartialPendingDialogScreen>
fontWeight: FontWeight.bold, fontWeight: FontWeight.bold,
), ),
), ),
Text("${widget.productpendingModel!.gstTotal ?? 0}"), Text("${widget.placedOrderList!.gstTotal ?? 0}"),
], ],
), ),
Row( Row(
@ -227,7 +231,7 @@ class _PartialPendingDialogScreenState extends State<PartialPendingDialogScreen>
fontWeight: FontWeight.bold, fontWeight: FontWeight.bold,
), ),
), ),
Text("${widget.productpendingModel!.grandTotal ?? 0}"), Text("${widget.placedOrderList!.grandTotal ?? 0}"),
], ],
), ),
], ],

View File

@ -17,6 +17,7 @@ import '../../controller/rd_processing_order_controller.dart';
import '../../models/get_rd_pennding_model.dart'; import '../../models/get_rd_pennding_model.dart';
import '../../models/oder_place_model.dart'; import '../../models/oder_place_model.dart';
import '../../models/product_model1.dart'; import '../../models/product_model1.dart';
import '../../models/single_get_order_model.dart';
import '../../utils/show_snackbar.dart'; import '../../utils/show_snackbar.dart';
// //
// class PartialProcessingDialogScreen extends StatefulWidget { // class PartialProcessingDialogScreen extends StatefulWidget {
@ -279,8 +280,8 @@ import '../../utils/show_snackbar.dart';
class PartialProcessingDialogScreen extends StatefulWidget { class PartialProcessingDialogScreen extends StatefulWidget {
final PlacedOrdersResponse? productModel; final PlacedOrdersResponse? productModel;
SingleGetOrderModel? placedOrderList;
PartialProcessingDialogScreen({super.key, this.productModel}); PartialProcessingDialogScreen({super.key, this.placedOrderList,this.productModel});
@override @override
State<PartialProcessingDialogScreen> createState() => _PartialProcessingDialogScreenState(); State<PartialProcessingDialogScreen> createState() => _PartialProcessingDialogScreenState();
@ -301,13 +302,13 @@ class _PartialProcessingDialogScreenState extends State<PartialProcessingDialogS
} }
void _separateProcessingAndPendingItems() { void _separateProcessingAndPendingItems() {
for (var item in widget.productModel!.orderItem) { for (var item in widget.placedOrderList!.orderItem!.toList()) {
if (item.remainingQuantity! > 0) { if (item.remainingQuantity! > 0) {
// If remainingQuantity > 0, it is available for processing // If remainingQuantity > 0, it is available for processing
processingItems.add(item); processingItems.add(item as RDOrderItem);
} else { } else {
// If remainingQuantity == 0, it should go into pending // If remainingQuantity == 0, it should go into pending
pendingItems.add(item); pendingItems.add(item as RDOrderItem);
} }
} }
} }
@ -351,13 +352,14 @@ class _PartialProcessingDialogScreenState extends State<PartialProcessingDialogS
List<RDOrderItem> orderItems = orderItemMap.values.toList(); List<RDOrderItem> orderItems = orderItemMap.values.toList();
controller.placedOrder1.value = PlacedOrdersProcessing( controller.placedOrder1.value = PlacedOrdersProcessing(
orderId: widget.productModel!.id, orderId: widget.placedOrderList!.id,
invoiceItems: orderItems, invoiceItems: orderItems,
); );
await controller.placeRDOrder(); await controller.placeRDOrder();
showSnackbar("Partial order processed successfully."); showSnackbar("Partial order processed successfully.");
Navigator.of(context).pop(); Get.to(RdOrderPendingScreen());
//Navigator.of(context).pop();
// Future.delayed(const Duration(seconds: 1), () { // Future.delayed(const Duration(seconds: 1), () {
// Get.to(RdOrderPendingScreen()); // Get.to(RdOrderPendingScreen());
// //Navigator.of(context).pop(); // //Navigator.of(context).pop();
@ -470,7 +472,7 @@ class _PartialProcessingDialogScreenState extends State<PartialProcessingDialogS
fontWeight: FontWeight.bold, fontWeight: FontWeight.bold,
), ),
), ),
Text("${widget.productModel!.subtotal ?? 0}"), Text("${widget.placedOrderList!.subtotal ?? 0}"),
], ],
), ),
Row( Row(
@ -484,7 +486,7 @@ class _PartialProcessingDialogScreenState extends State<PartialProcessingDialogS
fontWeight: FontWeight.bold, fontWeight: FontWeight.bold,
), ),
), ),
Text("${widget.productModel!.gstTotal ?? 0}"), Text("${widget.placedOrderList!.gstTotal ?? 0}"),
], ],
), ),
Row( Row(
@ -498,7 +500,7 @@ class _PartialProcessingDialogScreenState extends State<PartialProcessingDialogS
fontWeight: FontWeight.bold, fontWeight: FontWeight.bold,
), ),
), ),
Text("${widget.productModel!.grandTotal ?? 0}"), Text("${widget.placedOrderList!.grandTotal ?? 0}"),
], ],
), ),
], ],

View File

@ -572,7 +572,7 @@ class _RdCancelledDetailScreenState
fontWeight: FontWeight.bold, fontWeight: FontWeight.bold,
), ),
), ),
Text("${"VAIBHAV"}",maxLines: 4, Text("${" Roshan Garg"}",maxLines: 4,
overflow:TextOverflow.ellipsis,) overflow:TextOverflow.ellipsis,)
, ], , ],
) )
@ -593,7 +593,7 @@ class _RdCancelledDetailScreenState
fontWeight: FontWeight.bold, fontWeight: FontWeight.bold,
), ),
), ),
Text("${"vaibhav.gurjar20001@gmail.com"}",maxLines: 4, Text("${"roshangarg28@gmail.com"}",maxLines: 4,
overflow:TextOverflow.ellipsis,) overflow:TextOverflow.ellipsis,)
, ], , ],
) )
@ -614,7 +614,7 @@ class _RdCancelledDetailScreenState
fontWeight: FontWeight.bold, fontWeight: FontWeight.bold,
), ),
), ),
Text("${"7779797976"}",maxLines: 4, Text("${"8876785448"}",maxLines: 4,
overflow:TextOverflow.ellipsis,) overflow:TextOverflow.ellipsis,)
, ], , ],
) )
@ -785,33 +785,33 @@ class _RdCancelledDetailScreenState
children: [ children: [
const Text( const Text(
"CancelledReason: ", "CancelledReason: ",
style: TextStyle(fontWeight: FontWeight.bold), style: TextStyle(fontWeight: FontWeight.bold,),
), ),
SizedBox(width: 10), // Space between label and dropdown SizedBox(width: 10), // Space between label and dropdown
Text("${widget.placedOrderList!.orderCancelledReason}",maxLines: 4, Text("${widget.placedOrderList!.orderCancelledReason}",maxLines: 4,style: TextStyle(color: Colors.red,fontSize: 15),
overflow:TextOverflow.ellipsis,) overflow:TextOverflow.ellipsis,)
], ],
), ),
), ),
SizedBox( // SizedBox(
width: Get.width * 0.4, // width: Get.width * 0.4,
child: Padding( // child: Padding(
padding: const EdgeInsets.all(8.0), // padding: const EdgeInsets.all(8.0),
child: ElevatedButton( // child: ElevatedButton(
onPressed: (){}, // onPressed: (){},
// Get.to(() => // // Get.to(() =>
// RdOrderDetailScreen( // // RdOrderDetailScreen(
// placedOrderList: uniqueOrders[index])), // Navigate to detail screen // // placedOrderList: uniqueOrders[index])), // Navigate to detail screen
style: ElevatedButton.styleFrom( // style: ElevatedButton.styleFrom(
foregroundColor: Colors.white, // foregroundColor: Colors.white,
backgroundColor: const Color(0xFF004791), // backgroundColor: const Color(0xFF004791),
shape: RoundedRectangleBorder( // shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10)), // borderRadius: BorderRadius.circular(10)),
), // ),
child: Text("Update Status", style: GoogleFonts.roboto(fontSize: 14, fontWeight: FontWeight.w400)), // child: Text("Update Status", style: GoogleFonts.roboto(fontSize: 14, fontWeight: FontWeight.w400)),
), // ),
), // ),
) // )
], ],
), ),

View File

@ -196,14 +196,14 @@ class _RdCancelledScreenState extends State<RdCancelledScreen> {
SizedBox( SizedBox(
height: Get.height * 0.6, height: Get.height * 0.6,
child: Obx(() { child: Obx(() {
// if (_getRdProductController.productRDList.isEmpty) { if (_getRdProductController.productRDList.isEmpty) {
// return Center( return Center(
// child: Text( child: Text(
// 'No Orders Found', 'No Orders Found',
// style: GoogleFonts.roboto(fontSize: 14), style: GoogleFonts.roboto(fontSize: 14),
// ), ),
// ); );
// } }
final Set<String> uniqueOrderIds = {}; final Set<String> uniqueOrderIds = {};
final List<GetRdCancelledModel> uniqueOrders = []; final List<GetRdCancelledModel> uniqueOrders = [];

View File

@ -343,11 +343,12 @@ class _RdDeliveredDetailsScreenState
// placedOrderList: uniqueOrders[index])), // Navigate to detail screen // placedOrderList: uniqueOrders[index])), // Navigate to detail screen
style: ElevatedButton.styleFrom( style: ElevatedButton.styleFrom(
foregroundColor: Colors.white, foregroundColor: Colors.white,
backgroundColor: Colors.orange, backgroundColor: Colors.green,
shape: RoundedRectangleBorder( shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10)), borderRadius: BorderRadius.circular(10)),
), ),
child: Text(widget.placedOrderList!.courierStatus, style: GoogleFonts.roboto(fontSize: 14, fontWeight: FontWeight.w400)), child: Text(capitalizeFirstLetter( widget.placedOrderList!.courierStatus)
, style: GoogleFonts.roboto(fontSize: 14, fontWeight: FontWeight.w400)),
), ),
//Text("${widget.placedOrderList!.gstTotal}"), //Text("${widget.placedOrderList!.gstTotal}"),
], ],
@ -450,7 +451,7 @@ class _RdDeliveredDetailsScreenState
fontWeight: FontWeight.bold, fontWeight: FontWeight.bold,
), ),
), ),
Text("${"VAIBHAV"}",maxLines: 4, Text("${"Roshan Garg"}",maxLines: 4,
overflow:TextOverflow.ellipsis,) overflow:TextOverflow.ellipsis,)
, ], , ],
) )
@ -471,7 +472,7 @@ class _RdDeliveredDetailsScreenState
fontWeight: FontWeight.bold, fontWeight: FontWeight.bold,
), ),
), ),
Text("${"vaibhav.gurjar20001@gmail.com"}",maxLines: 4, Text("${"roshangarg28@gmail.com"}",maxLines: 4,
overflow:TextOverflow.ellipsis,) overflow:TextOverflow.ellipsis,)
, ], , ],
) )
@ -492,7 +493,7 @@ class _RdDeliveredDetailsScreenState
fontWeight: FontWeight.bold, fontWeight: FontWeight.bold,
), ),
), ),
Text("${"7779797976"}",maxLines: 4, Text("${"8876785448"}",maxLines: 4,
overflow:TextOverflow.ellipsis,) overflow:TextOverflow.ellipsis,)
, ], , ],
) )

View File

@ -500,7 +500,7 @@ class _RdDispatchedDetailsDetailScreenState
// placedOrderList: uniqueOrders[index])), // Navigate to detail screen // placedOrderList: uniqueOrders[index])), // Navigate to detail screen
style: ElevatedButton.styleFrom( style: ElevatedButton.styleFrom(
foregroundColor: Colors.white, foregroundColor: Colors.white,
backgroundColor: Colors.orange, backgroundColor: Colors.lightBlue,
shape: RoundedRectangleBorder( shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10)), borderRadius: BorderRadius.circular(10)),
), ),
@ -551,7 +551,7 @@ class _RdDispatchedDetailsDetailScreenState
fontWeight: FontWeight.bold, fontWeight: FontWeight.bold,
), ),
), ),
Text("${"VAIBHAV"}",maxLines: 4, Text("${"Roshan Garg"}",maxLines: 4,
overflow:TextOverflow.ellipsis,) overflow:TextOverflow.ellipsis,)
, ], , ],
) )
@ -572,7 +572,7 @@ class _RdDispatchedDetailsDetailScreenState
fontWeight: FontWeight.bold, fontWeight: FontWeight.bold,
), ),
), ),
Text("${"vaibhav.gurjar20001@gmail.com"}",maxLines: 4, Text("${"roshangarg28@gmail.com"}",maxLines: 4,
overflow:TextOverflow.ellipsis,) overflow:TextOverflow.ellipsis,)
, ], , ],
) )
@ -593,7 +593,7 @@ class _RdDispatchedDetailsDetailScreenState
fontWeight: FontWeight.bold, fontWeight: FontWeight.bold,
), ),
), ),
Text("${"7779797976"}",maxLines: 4, Text("${"8876785448"}",maxLines: 4,
overflow:TextOverflow.ellipsis,) overflow:TextOverflow.ellipsis,)
, ], , ],
) )

View File

@ -217,7 +217,7 @@ class _RdOrderDetailScreenState
} }
if (selectedStatus == "partial processing") { if (selectedStatus == "partial processing") {
Get.to(() => PartialProcessingDialogScreen(productModel: widget.placedOrderList)); // Get.to(() => PartialProcessingDialogScreen(productModel: widget.placedOrderList));
return; return;
} }
@ -468,9 +468,9 @@ class _RdOrderDetailScreenState
), ),
), ),
), ),
_buildRow("Name:", "VAIBHAV", Get.width * 0.04), _buildRow("Name:", " Roshan Garg", Get.width * 0.04),
_buildRow("Email:", "vaibhav.gurjar20001@gmail.com", Get.width * 0.04), _buildRow("Email:", "roshangarg28@gmail.com", Get.width * 0.04),
_buildRow("Mobile Number:", "7779797976", Get.width * 0.04), _buildRow("Mobile Number:", "8876785448", Get.width * 0.04),
], ],

View File

@ -0,0 +1,756 @@
import 'package:cheminova/controller/rd_single_order_controller.dart';
import 'package:cheminova/models/rd_order_item_model.dart';
import 'package:cheminova/models/rd_placed_order_model.dart';
import 'package:cheminova/models/single_get_order_model.dart';
import 'package:cheminova/screens/rd%20orders/partial_processing_dialog_screen.dart';
import 'package:cheminova/screens/rd%20orders/rd_cancelled_screen.dart';
import 'package:cheminova/screens/rd%20orders/rd_processing_screen.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 '../../controller/rd_get_order_controller.dart';
import '../../controller/rd_processing_order_controller.dart';
import '../../models/product_model1.dart';
import '../../utils/show_snackbar.dart';
class RdOrderDetailUpdateScreen extends StatefulWidget {
//final Product? productModel;
// PlacedOrderList and PlacedOrderModel are optional parameters passed to this screen
SingleGetOrderModel? placedOrderList;
final String orderId;
//final int orderIndex; // New parameter to receive the index
// PlacedOrderModel? placedOrderModel;
// Constructor for initializing the screen with placed order details
RdOrderDetailUpdateScreen({super.key,this.placedOrderList,required this.orderId});
@override
State<RdOrderDetailUpdateScreen> createState() =>
_RdOrderDetailUpdateScreenState();
}
class _RdOrderDetailUpdateScreenState
extends State<RdOrderDetailUpdateScreen> {
// Controllers for managing cart and placed orders
final RdSingleOrderController _getPlacedOrderController = Get.put(RdSingleOrderController());
final GetProductRDController _getProductRDController = Get.put(GetProductRDController());
final RDOrderPlacedController controller = Get.put(RDOrderPlacedController());
String? orderId;
final List<String> statusOptions = [
"new",
"pending",
"processing",
"dispatched",
"cancelled",
"delivered",
];
List<String> _statusList = ["new", "processing", "partial processing", "cancelled"]; // Default status list
// Define different status lists for different categories
final Map<String, List<String>> statusLists = {
"new": ["new", "processing", "partial processing", "cancelled"],
"pending": ["pending", "processing", "dispatched", "cancelled"],
"dispatched": ["dispatched", "delivered", "returned", "cancelled"],
"delivered": ["delivered", "returned", "cancelled"],
};
String selectedStatus = "new";
String _groupValue = "cheque";
// Function to format date from the API to a more readable format
// This function updates the dropdown list dynamically based on category selection
void updateStatusList(String category) {
setState(() {
_statusList = statusLists[category]!; // Update status list based on the selected category
selectedStatus = _statusList.first; // Set the default selection to the first item
});
}
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<SingleGetOrderModel> uniqueOrders = [];
// Loop through placed orders and add unique orders to the list
for (var order in _getPlacedOrderController.productRDOrderSingleList) {
if (uniqueOrderIds.add(order!.uniqueId.toString())) {
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();
//getOrder1();
selectedStatus= widget.placedOrderList!.status ?? 'new';
// controller.fetchOrderItems(widget.placedOrderList!.id);
// if (widget.orderId.isNotEmpty) {
// _getPlacedOrderController.fetchAllOrdersAndSingleOrder().then((_) {
// if (_getPlacedOrderController.productRDOrderSingleList.isNotEmpty) {
// // Update the UI with the fetched order data
// setState(() {
// var order = _getPlacedOrderController.productRDOrderSingleList.first;
// selectedStatus = order.status ?? 'new';
// widget.placedOrderList = order; // Update the placed order details
// });
// }
// });
// }
}
Future<void> getOrder1() async {
final order = await _getPlacedOrderController.fetchAllOrdersAndSingleOrder();
if (_getPlacedOrderController.productRDOrderSingleList.isEmpty) {
print("No orders found.");
} else {
print(" New Orders fetched successfully");
}
setState(() {
});
}
void _showConfirmationDialog() {
String dialogTitle;
String dialogContent;
TextEditingController reasonController = TextEditingController();
// Set dialog title and content based on selected status
switch (selectedStatus) {
case "processing":
dialogTitle = "Update Order Status";
dialogContent = "Are you sure you want to update the status to processing?";
break;
case "partial processing":
dialogTitle = "Update to Partial Processing";
dialogContent = "Are you sure you want to update the status to 'Partial Processing'?";
break;
case "cancelled":
dialogTitle = "Cancellation Reason";
dialogContent = "Please provide a reason for cancelling the order:";
break;
default:
dialogTitle = "Update Order Status";
dialogContent = "Are you sure you want to update the status to '$selectedStatus'?";
break;
}
showDialog(
context: context,
builder: (context) {
return AlertDialog(
title: Text(dialogTitle),
content: selectedStatus == "cancelled"
? Column(
mainAxisSize: MainAxisSize.min,
children: [
Text(dialogContent),
SizedBox(height: 10),
TextField(
controller: reasonController,
decoration: InputDecoration(
labelText: 'Cancellation Reason',
border: OutlineInputBorder(),
),
),
],
)
: Text(dialogContent),
actions: [
TextButton(
onPressed: () async {
if (selectedStatus == "cancelled") {
// Ensure the reason is provided for cancellation
if (reasonController.text.isEmpty) {
showSnackbar("Please provide a reason for cancelling the order.");
return; // Exit early if reason is empty
}
// Proceed with cancellation
await controller.CancleRDProduct(widget.placedOrderList!.id, reasonController.text);
// Notify user about successful cancellation
showSnackbar("Order cancelled successfully");
Get.to(RdCancelledScreen());
// Update the status in your UI or backend to reflect the cancelled state
setState(() {
// Update the status in the local model/UI
});
// Close the dialog after a short delay
Future.delayed(Duration(seconds: 1), () {
// Navigator.of(context).pop(); // Close the dialog
});
return; // Exit here to prevent further processing
}
if (selectedStatus == "partial processing") {
Get.to(() => PartialProcessingDialogScreen(placedOrderList: widget.placedOrderList));
return;
}
// Create a map to track products by their IDs and aggregate quantities
Map<String, RDOrderItem> orderItemMap = {};
// Populate the map with items and their quantities
for (var item in _getProductRDController.productRDList) {
var productId = item.orderItem[0].productId;
if (orderItemMap.containsKey(productId)) {
// If the product already exists, aggregate the quantity
var existingItem = orderItemMap[productId]!;
existingItem.quantity = (existingItem.quantity ?? 0) + (item.orderItem[0].quantity ?? 0);
existingItem.remainingQuantity = (existingItem.remainingQuantity ?? 0) + (item.orderItem[0].remainingQuantity ?? 0);
existingItem.processquantity = (existingItem.processquantity ?? 0) + (item.orderItem[0].processquantity ?? 0);
} else {
// If it's a new product, add it to the map
orderItemMap[productId] = RDOrderItem(
productId: productId,
sku: item.orderItem[0].sku,
name: item.orderItem[0].name,
categoryName: item.orderItem[0].categoryName,
brandName: item.orderItem[0].brandName,
price: item.orderItem[0].price,
gst: item.orderItem[0].gst.toInt(),
hsnCode: item.orderItem[0].hsnCode,
description: item.orderItem[0].description,
image: [], // Handle images appropriately
quantity: item.orderItem[0].quantity ?? 0,
remainingQuantity: item.orderItem[0].remainingQuantity ?? 0,
processquantity: item.orderItem[0].processquantity ?? 0,
);
}
}
// Convert the map to a list
List<RDOrderItem> orderItems = orderItemMap.values.toList();
// Ensure the placed order contains the correct orderId and items
controller.placedOrder1.value = PlacedOrdersProcessing(
orderId: widget.placedOrderList!.id,
invoiceItems: orderItems,
);
// Debugging: Print the JSON payload
print("Sending order payload: ${controller.placedOrder1.value.toJson()}");
// Place the order and catch any errors
await controller.placeRDOrder();
showSnackbar("Order processed and invoice created successfully");
Get.to(RdOrderProcessingScreen());
Navigator.of(context).pop();
// Close the dialog after a short delay
// Close the dialog
// Refresh the UI// Refresh the UI
},
child: Text("Confirm"),
),
TextButton(
onPressed: () {
Navigator.of(context).pop(); // Close the dialog
},
child: Text("Cancel"),
),
],
);
},
);
}
@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("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: [
_buildOrderSummary(),
const SizedBox(height: 8),
_buildOrderItems(),
const SizedBox(height: 8),
_buildCustomerDetails(),
const SizedBox(height: 8),
_buildBillingInfo(),
const SizedBox(height: 8),
_buildShippingInfo(),
const SizedBox(height: 8),
_buildPaymentInfo(),
const SizedBox(height: 8),
_buildOrderStatus(),
const SizedBox(height: 8),
_buildStatusDropdown(),
_buildUpdateStatusButton(),
],
),
),
),
SizedBox(height: Get.height * 0.04),
],
),
),
),
],
),
);
}
Widget _buildOrderSummary() {
return Card(
child: Column(
children: [
SizedBox(
width: Get.width,
child: Padding(
padding: const EdgeInsets.fromLTRB(8, 8, 8, 0),
child: Text(
"Order Summary",
style: GoogleFonts.roboto(
fontSize: Get.width * 0.05,
fontWeight: FontWeight.bold,
),
),
),
),
_buildRow("Order ID:", widget.placedOrderList!.uniqueId ?? "44564", Get.width * 0.04),
_buildRow("Order Date:", formatDate("${widget.placedOrderList!.createdAt}"), Get.width * 0.04),
_buildRow("Total Items:", "${widget.placedOrderList!.orderItem!.length}", Get.width * 0.04),
_buildRow("Sub Total:", "${widget.placedOrderList!.subtotal}", Get.width * 0.04),
_buildRow("GST:", "${widget.placedOrderList!.gstTotal}", Get.width * 0.04),
_buildRow("Total Amount:", "${widget.placedOrderList!.grandTotal}", Get.width * 0.04),
],
),
);
}
Widget _buildOrderItems() {
return Card(
child: SizedBox(
height: Get.height * 0.22,
child: Padding(
padding: EdgeInsets.all(Get.width * 0.02),
child: ListView.builder(
padding: EdgeInsets.zero,
itemCount: widget.placedOrderList!.orderItem!.length ?? 0,
itemBuilder: (context, index) {
final orderItem = widget.placedOrderList!.orderItem![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}"),
Text("Price: ₹${orderItem.price}"),
Text("GST: ${orderItem.gst}%"),
],
),
),
],
),
),
)
: const SizedBox.shrink();
},
),
),
),
);
}
Widget _buildCustomerDetails() {
return Card(
child: Column(
children: [
_buildSectionTitle("Customer Details"),
_buildRow("Name:", widget.placedOrderList!.addedBy!.name, Get.width * 0.04),
_buildRow("Email:", widget.placedOrderList!.addedBy!.email, Get.width * 0.04),
_buildRow("Mobile Number:", widget.placedOrderList!.addedBy!.mobileNumber, Get.width * 0.04),
],
),
);
}
Widget _buildBillingInfo() {
return Card(
child: Column(
children: [
_buildSectionTitle("Billing Information"),
_buildInfoRow("Address", widget.placedOrderList!.billTo.toString(), Get.width * 0.04),
],
),
);
}
Widget _buildShippingInfo() {
return Card(
child: Column(
children: [
_buildSectionTitle("Shipping Information"),
_buildInfoRow("Address", widget.placedOrderList!.shipTo.toString(), Get.width * 0.04),
],
),
);
}
Widget _buildPaymentInfo() {
return Card(
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Row(
children: [
Text(
"Payment Mode: ",
style: GoogleFonts.roboto(
fontSize: Get.width * 0.04,
fontWeight: FontWeight.w500,
),
),
Text(capitalizeFirstLetter(widget.placedOrderList!.paymentMode.toString())),
],
),
),
);
}
Widget _buildOrderStatus() {
return Card(
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Row(
children: [
Text(
"Order Status: ",
style: GoogleFonts.roboto(
fontSize: Get.width * 0.04,
fontWeight: FontWeight.w500,
),
),
Text(capitalizeFirstLetter(selectedStatus)),
],
),
),
);
}
Widget _buildStatusDropdown() {
return SizedBox(
height: Get.height * 0.05,
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
const Text(
"Status: ",
style: TextStyle(fontWeight: FontWeight.bold),
),
const SizedBox(width: 10),
Expanded(
child: DropdownButtonFormField<String>(
value: selectedStatus,
decoration: InputDecoration(
filled: true,
fillColor: Colors.white,
contentPadding: const EdgeInsets.symmetric(vertical: 10, horizontal: 12),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(10),
borderSide: const BorderSide(color: Colors.grey, width: 1),
),
),
items: _statusList.map((String status) {
return DropdownMenuItem<String>(
value: status,
child: Text(capitalizeFirstLetter(status)),
);
}).toList(),
onChanged: (newValue) {
setState(() {
selectedStatus = newValue!;
});
},
),
),
],
),
);
}
Widget _buildUpdateStatusButton() {
if (selectedStatus == "processing" || selectedStatus == "partial processing" || selectedStatus == "cancelled") {
return SizedBox(
width: Get.width * 0.4,
child: Padding(
padding: const EdgeInsets.all(8.0),
child: ElevatedButton(
onPressed: _showConfirmationDialog,
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),
),
),
),
);
}
return const SizedBox.shrink();
}
Widget _buildSectionTitle(String title) {
return SizedBox(
width: Get.width,
child: Padding(
padding: const EdgeInsets.fromLTRB(8, 8, 8, 0),
child: Text(
title,
style: GoogleFonts.roboto(fontSize: Get.width * 0.05, fontWeight: FontWeight.bold),
),
),
);
}
Widget _buildRow(String label, String value, double fontSize) {
return Padding(
padding: const EdgeInsets.fromLTRB(8, 2, 8, 2),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
label,
style: GoogleFonts.roboto(fontSize: fontSize),
),
Text(
value,
style: GoogleFonts.roboto(fontSize: fontSize),
),
],
),
);
}
Widget _buildInfoRow(String label, String value, double fontSize) {
return Padding(
padding: const EdgeInsets.all(8.0),
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
"$label: ",
style: GoogleFonts.roboto(fontSize: fontSize, fontWeight: FontWeight.w500),
),
Expanded(
child: Text(
value,
style: GoogleFonts.roboto(fontSize: fontSize),
),
),
],
),
);
}
}
Widget _buildRow(String label, String value, double fontSize) {
return SizedBox(
width: Get.width,
child: Padding(
padding: const EdgeInsets.fromLTRB(8, 8, 8, 0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
label,
style: GoogleFonts.roboto(
fontSize: fontSize,
fontWeight: FontWeight.bold,
),
),
Text(value),
],
),
),
);
}
Widget _buildInfoRow(String label, String value, double fontSize) {
return SizedBox(
width: Get.width,
child: Padding(
padding: const EdgeInsets.fromLTRB(8, 8, 8, 0),
child: Row(
children: [
Text(
"$label ",
style: GoogleFonts.roboto(
fontSize: fontSize,
fontWeight: FontWeight.bold,
),
),
Expanded(
child: Text(
value,
maxLines: 4,
overflow: TextOverflow.ellipsis,
),
),
],
),
),
);
}

View File

@ -1,10 +1,10 @@
import 'package:cheminova/controller/rd_get_order_controller.dart'; import 'package:cheminova/controller/rd_get_order_controller.dart';
import 'package:cheminova/models/rd_get_order_model.dart'; import 'package:cheminova/models/rd_get_order_model.dart';
import 'package:cheminova/screens/rd%20orders/rd_cancelled_screen.dart'; import 'package:cheminova/screens/rd%20orders/rd_cancelled_screen.dart';
import 'package:cheminova/screens/rd%20orders/rd_delivered_screen.dart'; import 'package:cheminova/screens/rd%20orders/rd_delivered_screen.dart';
import 'package:cheminova/screens/rd%20orders/rd_dispatched_scree.dart'; import 'package:cheminova/screens/rd%20orders/rd_dispatched_scree.dart';
import 'package:cheminova/screens/rd%20orders/rd_order_details_screen.dart'; import 'package:cheminova/screens/rd%20orders/rd_order_details_screen.dart';
import 'package:cheminova/screens/rd%20orders/rd_order_details_update.dart';
import 'package:cheminova/screens/rd%20orders/rd_pending_screen.dart'; import 'package:cheminova/screens/rd%20orders/rd_pending_screen.dart';
import 'package:cheminova/screens/rd%20orders/rd_processing_screen.dart'; import 'package:cheminova/screens/rd%20orders/rd_processing_screen.dart';
import 'package:cheminova/widgets/input_field.dart'; import 'package:cheminova/widgets/input_field.dart';
@ -14,7 +14,9 @@ import 'package:flutter_svg/svg.dart';
import 'package:get/get.dart'; import 'package:get/get.dart';
import 'package:google_fonts/google_fonts.dart'; import 'package:google_fonts/google_fonts.dart';
import 'package:intl/intl.dart'; import 'package:intl/intl.dart';
import 'package:shared_preferences/shared_preferences.dart';
import '../../controller/rd_get_single_service.dart';
import '../../controller/rd_single_order_controller.dart'; import '../../controller/rd_single_order_controller.dart';
import '../../models/single_get_order_model.dart'; import '../../models/single_get_order_model.dart';
import '../order_management/order_management_detail_screen.dart'; import '../order_management/order_management_detail_screen.dart';
@ -23,7 +25,7 @@ class RdOrderScreen extends StatefulWidget {
final PlacedOrdersResponse? getrdProduct; final PlacedOrdersResponse? getrdProduct;
SingleGetOrderModel? getSingleProduct; SingleGetOrderModel? getSingleProduct;
RdOrderScreen({super.key, this.getrdProduct,this.getSingleProduct}); RdOrderScreen({super.key, this.getrdProduct, this.getSingleProduct});
@override @override
State<RdOrderScreen> createState() => _RdOrderScreenState(); State<RdOrderScreen> createState() => _RdOrderScreenState();
@ -31,27 +33,33 @@ class RdOrderScreen extends StatefulWidget {
class _RdOrderScreenState extends State<RdOrderScreen> { class _RdOrderScreenState extends State<RdOrderScreen> {
final _searchController = TextEditingController(); final _searchController = TextEditingController();
final List<String> _filterList = [ "new", final List<String> _filterList = [
"new",
"pending", "pending",
"processing", "processing",
"dispatched", "dispatched",
"cancelled", "cancelled",
"delivered",]; "delivered",
];
int _selectedIndex = 0; int _selectedIndex = 0;
final GetProductRDController _getRdProductController = Get.put(GetProductRDController()); final GetProductRDController _getRdProductController =
final RdSingleOrderController _getrdSingleOrderController = Get.put(RdSingleOrderController()); Get.put(GetProductRDController());
final GlobalKey<RefreshIndicatorState> _refreshIndicatorKey = GlobalKey<RefreshIndicatorState>(); final RdSingleOrderController _getrdSingleOrderController =
Get.put(RdSingleOrderController());
final GlobalKey<RefreshIndicatorState> _refreshIndicatorKey =
GlobalKey<RefreshIndicatorState>();
@override @override
void initState() { void initState() {
super.initState(); super.initState();
getOrder1(); getOrder1();
getOrder3();
// getOrder3(_getrdSingleOrderController.productRDOrderSingleList[0].id); // getOrder3(_getrdSingleOrderController.productRDOrderSingleList[0].id);
} }
Future<void> _onRefresh() async { Future<void> _onRefresh() async {
await getOrder1(); await getOrder1();
await Future.delayed(Duration(seconds: 1)); await Future.delayed(Duration(seconds: 1));
} }
@ -62,22 +70,11 @@ class _RdOrderScreenState extends State<RdOrderScreen> {
} else { } else {
print(" New Orders fetched successfully"); print(" New Orders fetched successfully");
} }
} }
Future<void> getOrder3(String orderId) async { Future<void> getOrder3() async {
if (orderId != null && orderId.isNotEmpty) { //_getrdSingleOrderController.fetchAllOrdersAndSingleOrder();
await _getrdSingleOrderController.fetchRDSingleOrderProduct(orderId);
if (_getrdSingleOrderController.productRDOrderSingleList.isEmpty) {
print("No orders found.");
} else {
print("Single Order fetched successfully.");
} }
} else {
print("Order ID is invalid.");
}
}
String capitalizeFirstLetter(String text) { String capitalizeFirstLetter(String text) {
if (text.isEmpty) return text; if (text.isEmpty) return text;
@ -86,7 +83,8 @@ class _RdOrderScreenState extends State<RdOrderScreen> {
String formatDate(String apiDate) { String formatDate(String apiDate) {
// Parse the API date string into a DateTime object // Parse the API date string into a DateTime object
DateTime parsedDate = DateTime.parse(apiDate).toLocal(); // Convert to local time DateTime parsedDate =
DateTime.parse(apiDate).toLocal(); // Convert to local time
// Format the date and time according to your specified format // Format the date and time according to your specified format
String formattedDate = DateFormat('EEE MMM dd yyyy').format(parsedDate); String formattedDate = DateFormat('EEE MMM dd yyyy').format(parsedDate);
@ -95,6 +93,108 @@ class _RdOrderScreenState extends State<RdOrderScreen> {
} }
// void onOrderTap(int index) async {
// // Fetch orders and ensure you wait for it to complete
// await _getrdSingleOrderController.fetchAllOrdersAndSingleOrder();
//
// // Log the length of the list to help with debugging
// print('Fetched orders count: ${_getrdSingleOrderController.productRDOrderSingleList.length}');
//
// // Check if the productRDOrderSingleList is not empty
// if (_getrdSingleOrderController.productRDOrderSingleList.isNotEmpty) {
// // Ensure the index is within range
// if (index >= 0 && index < _getrdSingleOrderController.productRDOrderSingleList.length) {
// // Get the order ID from the list based on the index
// final orderId = _getrdSingleOrderController.productRDOrderSingleList[index].id;
//
// // Retrieve the token from SharedPreferences
// SharedPreferences prefs = await SharedPreferences.getInstance();
// String? token = prefs.getString('token');
//
// // Fetch the single order using the order ID
// final singleOrder = await GetSingleProductService().getSingleOrder(token!, orderId);
//
// // Check if the single order was fetched successfully
// if (singleOrder != null) {
// // Navigate to the details screen with the fetched order
// Get.to(() => RdOrderDetailUpdateScreen(placedOrderList: singleOrder, orderId: orderId,));
// } else {
// // Handle the case where the single order could not be fetched
// Get.snackbar("Error", "Unable to fetch order details.");
// }
// } else {
// // Handle the case when the index is out of bounds
// Get.snackbar("Error", "Invalid order selection.");
// }
// } else {
// // Handle the case when the list is empty
// Get.snackbar("Error", "No orders available to display.");
// }
// }
void onOrderTap(int index) async {
try {
// Fetch orders and ensure you wait for it to complete
await _getRdProductController.fetchRDProduct();
// Log the count of fetched orders
print('Fetched orders count: ${_getRdProductController.productRDList.length}');
// Check if the productRDList is populated
if (_getRdProductController.productRDList.isNotEmpty) {
// Ensure the index is valid
if (index >= 0 && index < _getRdProductController.productRDList.length) {
// Get the order ID from the list based on the index
final orderId = _getRdProductController.productRDList[index].id;
// Retrieve the token from SharedPreferences
SharedPreferences prefs = await SharedPreferences.getInstance();
String? token = prefs.getString('token');
// Check if the token is not null
if (token != null) {
// Fetch the single order using the order ID, and avoid caching issues
final singleOrder = await GetSingleProductService().getSingleOrder(token, orderId);
// Check if the single order was fetched successfully
if (singleOrder != null) {
// Navigate to the details screen with the fetched order
Get.to(() => RdOrderDetailUpdateScreen(
placedOrderList: singleOrder,
orderId: orderId,
));
} else {
// Handle the case where the single order could not be fetched
Get.snackbar("Error", "Unable to fetch order details.");
}
} else {
// Handle the case where the token is null
Get.snackbar("Error", "User not authenticated.");
}
} else {
// Handle the case when the index is out of bounds
Get.snackbar("Error", "Invalid order selection.");
}
} else {
// Handle the case when the list is empty
Get.snackbar("Error", "No orders available to display.");
}
} catch (e) {
// Log any errors that occur during the process
print('Error in onOrderTap: $e');
Get.snackbar("Error", "An unexpected error occurred.");
}
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Scaffold( return Scaffold(
@ -133,7 +233,8 @@ class _RdOrderScreenState extends State<RdOrderScreen> {
SafeArea( SafeArea(
child: SingleChildScrollView( child: SingleChildScrollView(
child: Padding( child: Padding(
padding: EdgeInsets.only(bottom: MediaQuery.of(context).viewInsets.bottom), padding: EdgeInsets.only(
bottom: MediaQuery.of(context).viewInsets.bottom),
child: RefreshIndicator( child: RefreshIndicator(
key: _refreshIndicatorKey, key: _refreshIndicatorKey,
onRefresh: _onRefresh, onRefresh: _onRefresh,
@ -167,11 +268,13 @@ class _RdOrderScreenState extends State<RdOrderScreen> {
scrollDirection: Axis.horizontal, scrollDirection: Axis.horizontal,
itemCount: _filterList.length, itemCount: _filterList.length,
itemBuilder: (context, index) => Padding( itemBuilder: (context, index) => Padding(
padding: const EdgeInsets.symmetric(horizontal: 4), padding: const EdgeInsets.symmetric(
horizontal: 4),
child: GestureDetector( child: GestureDetector(
onTap: () { onTap: () {
setState(() { setState(() {
_selectedIndex = index; // Update selected index _selectedIndex =
index; // Update selected index
}); });
// Navigate to different screens based on selected tab // Navigate to different screens based on selected tab
switch (_filterList[index]) { switch (_filterList[index]) {
@ -179,35 +282,47 @@ class _RdOrderScreenState extends State<RdOrderScreen> {
// Get.to(YourScreen1()); // Navigate to "new" orders screen // Get.to(YourScreen1()); // Navigate to "new" orders screen
break; break;
case "pending": case "pending":
Get.to(RdOrderPendingScreen()); // Navigate to "pending" orders screen Get.to(
RdOrderPendingScreen()); // Navigate to "pending" orders screen
break; break;
case "processing": case "processing":
Get.to(RdOrderProcessingScreen()); // Navigate to "processing" orders screen Get.to(
RdOrderProcessingScreen()); // Navigate to "processing" orders screen
break; break;
// Add more cases for other statuses // Add more cases for other statuses
case "dispatched": case "dispatched":
Get.to(RdDispatchedScreen()); // Navigate to dispatched orders Get.to(
RdDispatchedScreen()); // Navigate to dispatched orders
break; break;
case "cancelled": case "cancelled":
Get.to(RdCancelledScreen()); // Navigate to cancelled orders Get.to(
RdCancelledScreen()); // Navigate to cancelled orders
break; break;
case "delivered": case "delivered":
Get.to(RdDeliveredScreen()); // Navigate to delivered orders Get.to(
RdDeliveredScreen()); // Navigate to delivered orders
break; break;
default: default:
// Get.to(YourScreen1()); // Default screen // Get.to(YourScreen1()); // Default screen
} }
}, },
child: Chip( child: Chip(
label: Text(capitalizeFirstLetter( _filterList[index]) label: Text(
, capitalizeFirstLetter(
_filterList[index]),
style: GoogleFonts.roboto( style: GoogleFonts.roboto(
fontSize: 14, fontSize: 14,
fontWeight: FontWeight.w500, fontWeight: FontWeight.w500,
color: _selectedIndex == index ? Colors.white : Colors.black, // Change color when selected color: _selectedIndex == index
? Colors.white
: Colors
.black, // Change color when selected
), ),
), ),
backgroundColor: _selectedIndex == index ? const Color(0xFF004791) : Colors.grey[100], // Change color when selected backgroundColor: _selectedIndex == index
? const Color(0xFF004791)
: Colors.grey[
100], // Change color when selected
), ),
), ),
), ),
@ -216,19 +331,21 @@ class _RdOrderScreenState extends State<RdOrderScreen> {
SizedBox( SizedBox(
height: Get.height * 0.6, height: Get.height * 0.6,
child: Obx(() { child: Obx(() {
// if (_getRdProductController.productRDList.isEmpty) { if (_getRdProductController.productRDList.isEmpty) {
// return Center( return Center(
// child: Text( child: Text(
// 'No Orders Found', 'No Orders Found',
// style: GoogleFonts.roboto(fontSize: 14), style: GoogleFonts.roboto(fontSize: 14),
// ), ),
// ); );
// } }
final Set<String> uniqueOrderIds = {}; final Set<String> uniqueOrderIds = {};
final List<PlacedOrdersResponse> uniqueOrders = []; final List<PlacedOrdersResponse>
uniqueOrders = [];
for (var order in _getRdProductController.productRDList) { for (var order in _getRdProductController
.productRDList) {
if (uniqueOrderIds.add(order.id)) { if (uniqueOrderIds.add(order.id)) {
uniqueOrders.add(order); uniqueOrders.add(order);
} }
@ -252,47 +369,76 @@ class _RdOrderScreenState extends State<RdOrderScreen> {
// Combine product names into a single string // Combine product names into a single string
final productNames = order.orderItem final productNames = order.orderItem
.map((item) => capitalizeFirstLetter(item.name)) .map((item) =>
capitalizeFirstLetter(item.name))
.join(', '); .join(', ');
return Padding( return Padding(
padding: const EdgeInsets.symmetric(vertical: 8), padding: const EdgeInsets.symmetric(
vertical: 8),
child: Card( child: Card(
child: Column( child: Column(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment:
CrossAxisAlignment.start,
children: [ children: [
Padding( Padding(
padding: const EdgeInsets.fromLTRB(16, 8, 8, 0), padding:
const EdgeInsets.fromLTRB(
16, 8, 8, 0),
child: Row( child: Row(
mainAxisAlignment: MainAxisAlignment.start, mainAxisAlignment:
MainAxisAlignment.start,
children: [ children: [
Text("Order ID: ", style: GoogleFonts.roboto(fontSize: 14, fontWeight: FontWeight.bold)), Text("Order ID: ",
style:
GoogleFonts.roboto(
fontSize: 14,
fontWeight:
FontWeight
.bold)),
Text("${order.uniqueId}") Text("${order.uniqueId}")
], ],
), ),
), ),
Padding( Padding(
padding: const EdgeInsets.fromLTRB(16, 8, 8, 0), padding:
const EdgeInsets.fromLTRB(
16, 8, 8, 0),
child: Row( child: Row(
crossAxisAlignment: CrossAxisAlignment.start, // Aligns the Column to the top of the Text crossAxisAlignment:
CrossAxisAlignment
.start, // Aligns the Column to the top of the Text
children: [ children: [
Text( Text(
"Product Names: ", "Product Names: ",
style: GoogleFonts.roboto( style: GoogleFonts.roboto(
fontSize: 14, fontSize: 14,
fontWeight: FontWeight.bold, fontWeight:
FontWeight.bold,
), ),
), ),
Expanded( Expanded(
child: Column( child: Column(
crossAxisAlignment: CrossAxisAlignment.start, // Aligns text to the right within the Column crossAxisAlignment:
CrossAxisAlignment
.start, // Aligns text to the right within the Column
children: [ children: [
const SizedBox(height: 4), // Adds a small space between the label and the product names const SizedBox(
for (int i = 0; i < productNames.split(",").length; i++) height:
4), // Adds a small space between the label and the product names
for (int i = 0;
i <
productNames
.split(
",")
.length;
i++)
Text( Text(
'${i + 1}. ${productNames.split(",")[i].trim()}', // Adds index and trims whitespace '${i + 1}. ${productNames.split(",")[i].trim()}', // Adds index and trims whitespace
textAlign: TextAlign.left, // Aligns text to the right textAlign: TextAlign
style: GoogleFonts.roboto( .left, // Aligns text to the right
style: GoogleFonts
.roboto(
fontSize: 14, fontSize: 14,
), ),
), ),
@ -302,61 +448,100 @@ class _RdOrderScreenState extends State<RdOrderScreen> {
], ],
), ),
), ),
Padding( Padding(
padding: const EdgeInsets.fromLTRB(16, 8, 8, 0), padding:
const EdgeInsets.fromLTRB(
16, 8, 8, 0),
child: Row( child: Row(
mainAxisAlignment: MainAxisAlignment.start, mainAxisAlignment:
MainAxisAlignment.start,
children: [ children: [
Text("Order Value: ", style: GoogleFonts.roboto(fontSize: 14, fontWeight: FontWeight.bold)), Text("Order Value: ",
style:
GoogleFonts.roboto(
fontSize: 14,
fontWeight:
FontWeight
.bold)),
Text("${order.grandTotal}") Text("${order.grandTotal}")
], ],
), ),
), ),
Padding( Padding(
padding: const EdgeInsets.fromLTRB(16, 8, 8, 0), padding:
const EdgeInsets.fromLTRB(
16, 8, 8, 0),
child: Row( child: Row(
mainAxisAlignment: MainAxisAlignment.start, mainAxisAlignment:
MainAxisAlignment.start,
children: [ children: [
Text("Order Date: ", style: GoogleFonts.roboto(fontSize: 14, fontWeight: FontWeight.bold)), Text("Order Date: ",
Text(formatDate("${order.createdAt}")) style:
GoogleFonts.roboto(
fontSize: 14,
fontWeight:
FontWeight
.bold)),
Text(formatDate(
"${order.createdAt}"))
], ],
), ),
), ),
Padding( Padding(
padding: const EdgeInsets.fromLTRB(16, 8, 8, 8), padding:
const EdgeInsets.fromLTRB(
16, 8, 8, 8),
child: Row( child: Row(
mainAxisAlignment: MainAxisAlignment.start, mainAxisAlignment:
MainAxisAlignment.start,
children: [ children: [
Text("Status: ", style: GoogleFonts.roboto(fontSize: 14, fontWeight: FontWeight.bold)), Text("Status: ",
Text(capitalizeFirstLetter("${order.status}")) style:
GoogleFonts.roboto(
fontSize: 14,
fontWeight:
FontWeight
.bold)),
Text(capitalizeFirstLetter(
"${order.status}"))
], ],
), ),
), ),
SizedBox( SizedBox(
width: Get.width * 0.4, width: Get.width * 0.4,
child: Padding( child: Padding(
padding: const EdgeInsets.all(8.0), padding:
const EdgeInsets.all(8.0),
child: ElevatedButton( child: ElevatedButton(
onPressed: (){ onPressed: ()
Get.to(() => RdOrderDetailScreen( async {
placedOrderList: _getRdProductController.productRDList[index])); onOrderTap(index);
// getOrder3(_getRdProductController.productRDList[index].id).then((_) {
// // Navigate to the details screen only if the single order data is fetched
//
// });
}, },
// => // =>
// Get.to(() => // Get.to(() =>
// RdOrderDetailScreen( // RdOrderDetailScreen(
// placedOrderList: _getRdProductController.productRDList[index])), // Navigate to detail screen // placedOrderList: _getRdProductController.productRDList[index])), // Navigate to detail screen
style: ElevatedButton.styleFrom( style: ElevatedButton
foregroundColor: Colors.white, .styleFrom(
backgroundColor: const Color(0xFF004791), foregroundColor:
shape: RoundedRectangleBorder( Colors.white,
borderRadius: BorderRadius.circular(10)), backgroundColor:
const Color(
0xFF004791),
shape:
RoundedRectangleBorder(
borderRadius:
BorderRadius
.circular(
10)),
), ),
child: Text("View Details", style: GoogleFonts.roboto(fontSize: 14, fontWeight: FontWeight.w400)), child: Text("View Details",
style:
GoogleFonts.roboto(
fontSize: 14,
fontWeight:
FontWeight
.w400)),
), ),
), ),
) )
@ -383,4 +568,3 @@ class _RdOrderScreenState extends State<RdOrderScreen> {
); );
} }
} }

View File

@ -7,8 +7,10 @@ import 'package:cheminova/models/oder_place_model.dart';
import 'package:cheminova/models/order_item_model.dart'; import 'package:cheminova/models/order_item_model.dart';
import 'package:cheminova/models/place_order_list_model.dart'; import 'package:cheminova/models/place_order_list_model.dart';
import 'package:cheminova/models/rd_get_order_model.dart'; import 'package:cheminova/models/rd_get_order_model.dart';
import 'package:cheminova/models/single_get_order_model.dart';
import 'package:cheminova/screens/rd%20orders/partial_pending_dialog.dart'; import 'package:cheminova/screens/rd%20orders/partial_pending_dialog.dart';
import 'package:cheminova/screens/rd%20orders/partial_processing_dialog_screen.dart'; import 'package:cheminova/screens/rd%20orders/partial_processing_dialog_screen.dart';
import 'package:cheminova/screens/rd%20orders/rd_processing_screen.dart';
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
@ -19,7 +21,9 @@ import 'package:intl/intl.dart';
import 'package:shared_preferences/shared_preferences.dart'; import 'package:shared_preferences/shared_preferences.dart';
import '../../controller/cart_controller.dart'; import '../../controller/cart_controller.dart';
import '../../controller/get_single_invoice_controller.dart';
import '../../controller/rd_processing_order_controller.dart'; import '../../controller/rd_processing_order_controller.dart';
import '../../models/get_invoice_model.dart';
import '../../models/product_model1.dart'; import '../../models/product_model1.dart';
import '../../models/rd_order_item_model.dart'; import '../../models/rd_order_item_model.dart';
import '../../models/rd_placed_order_model.dart'; import '../../models/rd_placed_order_model.dart';
@ -28,11 +32,14 @@ import '../../utils/show_snackbar.dart';
class RdOrderPendingScreenDetailScreen extends StatefulWidget { class RdOrderPendingScreenDetailScreen extends StatefulWidget {
//final Product? productModel; //final Product? productModel;
// PlacedOrderList and PlacedOrderModel are optional parameters passed to this screen // PlacedOrderList and PlacedOrderModel are optional parameters passed to this screen
GetRdPendingModel? placedOrderList; SingleGetOrderModel? placedOrderList;
GetRdPendingModel? productpendingModel;
final String orderId;
GetInvoiceModel? placeInvoiceList;
// PlacedOrderModel? placedOrderModel; // PlacedOrderModel? placedOrderModel;
// Constructor for initializing the screen with placed order details // Constructor for initializing the screen with placed order details
RdOrderPendingScreenDetailScreen({super.key,this.placedOrderList}); RdOrderPendingScreenDetailScreen({super.key,this.placedOrderList,required this.orderId,this.placeInvoiceList});
@override @override
State<RdOrderPendingScreenDetailScreen> createState() => State<RdOrderPendingScreenDetailScreen> createState() =>
@ -44,8 +51,9 @@ class _RdOrderPendingScreenDetailScreenState
extends State<RdOrderPendingScreenDetailScreen> { extends State<RdOrderPendingScreenDetailScreen> {
// Controllers for managing cart and placed orders // Controllers for managing cart and placed orders
final CartController _cartController = Get.put(CartController()); final CartController _cartController = Get.put(CartController());
final GetRdPendingController _getPlacedOrderController = Get.put(GetRdPendingController()); final GetRdPendingController _getRdPendingController = Get.put(GetRdPendingController());
final GetProductRDController _getPlacedOrderController1 = Get.put(GetProductRDController()); final GetSingleInvoiceController _getSingleInvoiceController = Get.put(GetSingleInvoiceController());
final GetProductRDController _getProductRDController = Get.put(GetProductRDController());
final RDOrderPlacedController controller = Get.put(RDOrderPlacedController()); final RDOrderPlacedController controller = Get.put(RDOrderPlacedController());
final List<String> statusOptions = [ final List<String> statusOptions = [
@ -102,7 +110,7 @@ class _RdOrderPendingScreenDetailScreenState
final Set<String> uniqueOrderIds = {}; final Set<String> uniqueOrderIds = {};
final List<GetRdPendingModel> uniqueOrders = []; final List<GetRdPendingModel> uniqueOrders = [];
// Loop through placed orders and add unique orders to the list // Loop through placed orders and add unique orders to the list
for (var order in _getPlacedOrderController.productRDList) { for (var order in _getRdPendingController.productRDList) {
if (uniqueOrderIds.add(order.uniqueId)) { if (uniqueOrderIds.add(order.uniqueId)) {
uniqueOrders.add(order); uniqueOrders.add(order);
} }
@ -124,10 +132,18 @@ class _RdOrderPendingScreenDetailScreenState
void initState() { void initState() {
// TODO: implement initState // TODO: implement initState
super.initState(); super.initState();
//getOrder1();
selectedStatus= widget.placedOrderList?.status ?? 'new'; selectedStatus= widget.placedOrderList?.status ?? 'new';
} }
// Future<void> getOrder1() async {
// await _getSingleInvoiceController.fetchInvoice(widget.placedOrderList!.id);
// if (_getSingleInvoiceController.invoice.isEmpty) {
// print("No orders found.");
// } else {
// print(" New Orders fetched successfully");
// }
// }
void _showConfirmationDialog() { void _showConfirmationDialog() {
String dialogTitle; String dialogTitle;
@ -204,7 +220,7 @@ class _RdOrderPendingScreenDetailScreenState
} }
if (selectedStatus == "partial processing") { if (selectedStatus == "partial processing") {
Get.to(() => PartialPendingDialogScreen(productpendingModel: widget.placedOrderList)); Get.to(() => PartialPendingDialogScreen(placedOrderList: widget.placedOrderList));
return; return;
} }
@ -212,7 +228,7 @@ class _RdOrderPendingScreenDetailScreenState
Map<String, RDOrderItem> orderItemMap = {}; Map<String, RDOrderItem> orderItemMap = {};
// Populate the map with items and their quantities // Populate the map with items and their quantities
for (var item in _getPlacedOrderController1.productRDList) { for (var item in _getProductRDController.productRDList) {
var productId = item.orderItem[0].productId; var productId = item.orderItem[0].productId;
if (orderItemMap.containsKey(productId)) { if (orderItemMap.containsKey(productId)) {
@ -257,9 +273,9 @@ class _RdOrderPendingScreenDetailScreenState
await controller.placeRDOrder(); await controller.placeRDOrder();
showSnackbar("Order processed and invoice created successfully"); showSnackbar("Order processed and invoice created successfully");
Get.to(RdOrderProcessingScreen());
//Navigator.of(context).pop();
Navigator.of(context).pop();
// Close the dialog after a short delay // Close the dialog after a short delay
// Close the dialog // Close the dialog
@ -290,7 +306,7 @@ class _RdOrderPendingScreenDetailScreenState
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
int remainingQuantity = (widget.placedOrderList!.orderItem[0].quantity)! -(widget.placedOrderList!.orderItem[0].remainingQuantity!.toInt()); int remainingQuantity = (widget.placedOrderList!.orderItem![0].quantity)! -(widget.placedOrderList!.orderItem![0].remainingQuantity!.toInt());
return Scaffold( return Scaffold(
extendBodyBehindAppBar: true, extendBodyBehindAppBar: true,
appBar: AppBar( appBar: AppBar(
@ -381,7 +397,7 @@ class _RdOrderPendingScreenDetailScreenState
fontWeight: FontWeight.bold, fontWeight: FontWeight.bold,
), ),
), ),
Text(widget.placedOrderList!.uniqueId), Text(widget.placedOrderList!.uniqueId.toString()),
// Text(widget.placedOrderList!.uniqueId), // Text(widget.placedOrderList!.uniqueId),
], ],
), ),
@ -404,7 +420,7 @@ class _RdOrderPendingScreenDetailScreenState
), ),
SizedBox(height: 10), // Add spacing between the title and the list of items SizedBox(height: 10), // Add spacing between the title and the list of items
Column( Column(
children: widget.placedOrderList!.orderItem.map((item) { children: widget.placedOrderList!.orderItem!.map((item) {
return Padding( return Padding(
padding: const EdgeInsets.symmetric(vertical: 4.0), // Add some spacing between items padding: const EdgeInsets.symmetric(vertical: 4.0), // Add some spacing between items
@ -537,7 +553,9 @@ class _RdOrderPendingScreenDetailScreenState
shape: RoundedRectangleBorder( shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10)), borderRadius: BorderRadius.circular(10)),
), ),
child: Text(widget.placedOrderList!.status, style: GoogleFonts.roboto(fontSize: 14, fontWeight: FontWeight.w400)), child: Text("Processing"),
// Text(widget.placedOrderList!.status.toString())
//Text(widget.placedOrderList!.status, style: GoogleFonts.roboto(fontSize: 14, fontWeight: FontWeight.w400)),
), ),
//Text("${widget.placedOrderList!.gstTotal}"), //Text("${widget.placedOrderList!.gstTotal}"),
], ],
@ -573,9 +591,9 @@ class _RdOrderPendingScreenDetailScreenState
Expanded( Expanded(
child: ListView.builder( child: ListView.builder(
padding: EdgeInsets.zero, padding: EdgeInsets.zero,
itemCount: widget.placedOrderList?.orderItem.length ?? 0, itemCount: widget.placedOrderList?.orderItem!.length ?? 0,
itemBuilder: (context, index) { itemBuilder: (context, index) {
final orderItem = widget.placedOrderList!.orderItem[index]; final orderItem = widget.placedOrderList!.orderItem![index];
return orderItem != null return orderItem != null
? Card( ? Card(
margin: const EdgeInsets.symmetric(vertical: 5.0), margin: const EdgeInsets.symmetric(vertical: 5.0),
@ -645,7 +663,7 @@ class _RdOrderPendingScreenDetailScreenState
Padding( Padding(
padding: const EdgeInsets.symmetric(vertical: 8.0), // Adjust padding if needed padding: const EdgeInsets.symmetric(vertical: 8.0), // Adjust padding if needed
child: Text( child: Text(
"Order Itmes to processed", // Title text "Order Items to be processed", // Title text
style: GoogleFonts.roboto( style: GoogleFonts.roboto(
fontSize: Get.width * 0.05, // Adjust font size as needed fontSize: Get.width * 0.05, // Adjust font size as needed
fontWeight: FontWeight.bold, fontWeight: FontWeight.bold,
@ -655,11 +673,18 @@ class _RdOrderPendingScreenDetailScreenState
Expanded( Expanded(
child: ListView.builder( child: ListView.builder(
padding: EdgeInsets.zero, padding: EdgeInsets.zero,
itemCount: widget.placedOrderList?.orderItem.length ?? 0, itemCount: widget.placedOrderList?.orderItem
?.where((item) => item.remainingQuantity! > 0)
.length ?? 0,
itemBuilder: (context, index) { itemBuilder: (context, index) {
final orderItem = widget.placedOrderList!.orderItem[index]; // Filter items with non-zero quantities
return orderItem != null final filteredItems = widget.placedOrderList!.orderItem!
? Card( .where((item) => item.remainingQuantity! > 0)
.toList();
final orderItem = filteredItems[index];
return Card(
margin: const EdgeInsets.symmetric(vertical: 5.0), margin: const EdgeInsets.symmetric(vertical: 5.0),
shape: RoundedRectangleBorder( shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10), borderRadius: BorderRadius.circular(10),
@ -686,12 +711,7 @@ class _RdOrderPendingScreenDetailScreenState
fontWeight: FontWeight.bold, fontWeight: FontWeight.bold,
), ),
), ),
Text( Text("Quantity: ${orderItem.remainingQuantity}"),
"Quantity: ${orderItem.remainingQuantity}",
style: GoogleFonts.roboto(
fontSize: Get.width * 0.03,
),
),
Text("Price: ${orderItem.price}"), Text("Price: ${orderItem.price}"),
Text("Subtotal: ${widget.placedOrderList!.subtotal}"), Text("Subtotal: ${widget.placedOrderList!.subtotal}"),
Text("Gst: ${orderItem.gst}%"), Text("Gst: ${orderItem.gst}%"),
@ -703,8 +723,7 @@ class _RdOrderPendingScreenDetailScreenState
], ],
), ),
), ),
) );
: const SizedBox.shrink();
}, },
), ),
), ),
@ -713,6 +732,8 @@ class _RdOrderPendingScreenDetailScreenState
), ),
), ),
), ),
const SizedBox(height: 8), const SizedBox(height: 8),
SizedBox( SizedBox(
height: Get.height* 0.19, height: Get.height* 0.19,
@ -748,7 +769,7 @@ class _RdOrderPendingScreenDetailScreenState
fontWeight: FontWeight.bold, fontWeight: FontWeight.bold,
), ),
), ),
Text("${"VAIBHAV"}",maxLines: 4, Text("${"Roshan Garg"}",maxLines: 4,
overflow:TextOverflow.ellipsis,) overflow:TextOverflow.ellipsis,)
, ], , ],
) )
@ -769,7 +790,7 @@ class _RdOrderPendingScreenDetailScreenState
fontWeight: FontWeight.bold, fontWeight: FontWeight.bold,
), ),
), ),
Text("${"vaibhav.gurjar20001@gmail.com"}",maxLines: 4, Text("${"roshangarg28@gmail.com"}",maxLines: 4,
overflow:TextOverflow.ellipsis,) overflow:TextOverflow.ellipsis,)
, ], , ],
) )
@ -790,7 +811,7 @@ class _RdOrderPendingScreenDetailScreenState
fontWeight: FontWeight.bold, fontWeight: FontWeight.bold,
), ),
), ),
Text("${"7779797976"}",maxLines: 4, Text("${"8876785448"}",maxLines: 4,
overflow:TextOverflow.ellipsis,) overflow:TextOverflow.ellipsis,)
, ], , ],
) )
@ -909,7 +930,7 @@ class _RdOrderPendingScreenDetailScreenState
fontWeight: FontWeight.w500, fontWeight: FontWeight.w500,
), ),
), ),
Text(capitalizeFirstLetter(widget.placedOrderList!.paymentMode)), Text(capitalizeFirstLetter(widget.placedOrderList!.paymentMode.toString())),
// Text("${widget.placedOrderList!.paymentMode}",maxLines: 4, // Text("${widget.placedOrderList!.paymentMode}",maxLines: 4,
// overflow:TextOverflow.ellipsis,) // overflow:TextOverflow.ellipsis,)
], ],

View File

@ -4,6 +4,7 @@ import 'package:cheminova/controller/rd_get_order_controller.dart';
import 'package:cheminova/models/get_rd_pennding_model.dart'; import 'package:cheminova/models/get_rd_pennding_model.dart';
import 'package:cheminova/models/rd_get_order_model.dart'; import 'package:cheminova/models/rd_get_order_model.dart';
import 'package:cheminova/screens/rd%20orders/rd_order_details_screen.dart'; import 'package:cheminova/screens/rd%20orders/rd_order_details_screen.dart';
import 'package:cheminova/screens/rd%20orders/rd_order_details_update.dart';
import 'package:cheminova/screens/rd%20orders/rd_pending_deatils.dart'; import 'package:cheminova/screens/rd%20orders/rd_pending_deatils.dart';
import 'package:cheminova/widgets/input_field.dart'; import 'package:cheminova/widgets/input_field.dart';
import 'package:cheminova/widgets/my_drawer.dart'; import 'package:cheminova/widgets/my_drawer.dart';
@ -12,7 +13,10 @@ import 'package:flutter_svg/svg.dart';
import 'package:get/get.dart'; import 'package:get/get.dart';
import 'package:google_fonts/google_fonts.dart'; import 'package:google_fonts/google_fonts.dart';
import 'package:intl/intl.dart'; import 'package:intl/intl.dart';
import 'package:shared_preferences/shared_preferences.dart';
import '../../controller/get_single_invoice_Service.dart';
import '../../controller/rd_get_single_service.dart';
import '../order_management/order_management_detail_screen.dart'; import '../order_management/order_management_detail_screen.dart';
class RdOrderPendingScreen extends StatefulWidget { class RdOrderPendingScreen extends StatefulWidget {
@ -33,7 +37,9 @@ class _RdOrderPendingScreenState extends State<RdOrderPendingScreen> {
"cancelled", "cancelled",
"delivered",]; "delivered",];
int _selectedIndex = 0; int _selectedIndex = 0;
final GetRdPendingController _getRdProductController = Get.put(GetRdPendingController()); final GetRdPendingController _getRdPendingController = Get.put(GetRdPendingController());
// final GetProductRDController _getRdProductController =
// Get.put(GetProductRDController());
final GlobalKey<RefreshIndicatorState> _refreshIndicatorKey = GlobalKey<RefreshIndicatorState>(); final GlobalKey<RefreshIndicatorState> _refreshIndicatorKey = GlobalKey<RefreshIndicatorState>();
@override @override
@ -49,8 +55,8 @@ class _RdOrderPendingScreenState extends State<RdOrderPendingScreen> {
} }
Future<void> getOrder1() async { Future<void> getOrder1() async {
await _getRdProductController.getRDPendingProduct(); await _getRdPendingController.getRDPendingProduct();
if (_getRdProductController.productRDList.isEmpty) { if (_getRdPendingController.productRDList.isEmpty) {
print("No orders found."); print("No orders found.");
} else { } else {
print("Orders fetched successfully"); print("Orders fetched successfully");
@ -71,6 +77,66 @@ class _RdOrderPendingScreenState extends State<RdOrderPendingScreen> {
return formattedDate; // Return the formatted date string return formattedDate; // Return the formatted date string
} }
void onOrderTap(int index) async {
try {
// Fetch orders and ensure you wait for it to complete
await _getRdPendingController.getRDPendingProduct();
// Log the count of fetched orders
print('Fetched orders count: ${_getRdPendingController.productRDList.length}');
// Check if the productRDList is populated
if (_getRdPendingController.productRDList.isNotEmpty) {
// Ensure the index is valid
if (index >= 0 && index < _getRdPendingController.productRDList.length) {
// Get the order ID from the list based on the index
final orderId = _getRdPendingController.productRDList[index].id;
// Retrieve the token from SharedPreferences
SharedPreferences prefs = await SharedPreferences.getInstance();
String? token = prefs.getString('token');
// Check if the token is not null
if (token != null) {
// Fetch the single order using the order ID, and avoid caching issues
final singleOrder = await GetSingleProductService().getSingleOrder(token, orderId);
final singleInvoice = await GetSingleInvoiceService().fetchInvoice(token, orderId);
// Check if the single order was fetched successfully
if (singleOrder != null) {
// Navigate to the details screen with the fetched order
Get.to(() => RdOrderPendingScreenDetailScreen(
placedOrderList: singleOrder,
orderId: orderId,
placeInvoiceList: singleInvoice,
));
} else {
// Handle the case where the single order could not be fetched
Get.snackbar("Error", "Unable to fetch order details.");
}
} else {
// Handle the case where the token is null
Get.snackbar("Error", "User not authenticated.");
}
} else {
// Handle the case when the index is out of bounds
Get.snackbar("Error", "Invalid order selection.");
}
} else {
// Handle the case when the list is empty
Get.snackbar("Error", "No orders available to display.");
}
} catch (e) {
// Log any errors that occur during the process
print('Error in onOrderTap: $e');
Get.snackbar("Error", "An unexpected error occurred.");
}
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Scaffold( return Scaffold(
@ -141,7 +207,7 @@ class _RdOrderPendingScreenState extends State<RdOrderPendingScreen> {
SizedBox( SizedBox(
height: Get.height * 0.6, height: Get.height * 0.6,
child: Obx(() { child: Obx(() {
if (_getRdProductController.productRDList.isEmpty) { if (_getRdPendingController.productRDList.isEmpty) {
return Center( return Center(
child: Text( child: Text(
'No Orders Found', 'No Orders Found',
@ -153,7 +219,7 @@ class _RdOrderPendingScreenState extends State<RdOrderPendingScreen> {
final Set<String> uniqueOrderIds = {}; final Set<String> uniqueOrderIds = {};
final List<GetRdPendingModel> uniqueOrders = []; final List<GetRdPendingModel> uniqueOrders = [];
for (var order in _getRdProductController.productRDList) { for (var order in _getRdPendingController.productRDList) {
if (uniqueOrderIds.add(order.id)) { if (uniqueOrderIds.add(order.id)) {
uniqueOrders.add(order); uniqueOrders.add(order);
} }
@ -264,10 +330,12 @@ class _RdOrderPendingScreenState extends State<RdOrderPendingScreen> {
child: Padding( child: Padding(
padding: const EdgeInsets.all(8.0), padding: const EdgeInsets.all(8.0),
child: ElevatedButton( child: ElevatedButton(
onPressed: ()=> onPressed: (){
Get.to(() => onOrderTap(index);
RdOrderPendingScreenDetailScreen( },
placedOrderList: uniqueOrders[index])), // Navigate to detail screen // Get.to(() =>
// RdOrderPendingScreenDetailScreen(
// placedOrderList: uniqueOrders[index])), // Navigate to detail screen
style: ElevatedButton.styleFrom( style: ElevatedButton.styleFrom(
foregroundColor: Colors.white, foregroundColor: Colors.white,
backgroundColor: const Color(0xFF004791), backgroundColor: const Color(0xFF004791),

View File

@ -4,8 +4,10 @@ import 'package:get/get.dart';
import 'package:get/get_core/src/get_main.dart'; import 'package:get/get_core/src/get_main.dart';
import 'package:google_fonts/google_fonts.dart'; import 'package:google_fonts/google_fonts.dart';
import 'package:intl/intl.dart'; import 'package:intl/intl.dart';
import 'package:shared_preferences/shared_preferences.dart';
import '../../controller/get_dispatch_controller.dart'; import '../../controller/get_dispatch_controller.dart';
import '../../controller/get_single_invoice_Service.dart';
import '../../controller/get_single_invoice_controller.dart'; import '../../controller/get_single_invoice_controller.dart';
import '../../controller/rd_get_order_controller.dart'; import '../../controller/rd_get_order_controller.dart';
import '../../controller/rd_processing_invoice_controller.dart'; import '../../controller/rd_processing_invoice_controller.dart';
@ -14,9 +16,10 @@ import '../../models/get_invoice_model.dart';
import '../../models/rd_processing_invoice_model.dart'; import '../../models/rd_processing_invoice_model.dart';
import '../../utils/show_snackbar.dart'; import '../../utils/show_snackbar.dart';
class RdOrderProcessingDetailScreen extends StatefulWidget { class RdOrderProcessingDetailScreen extends StatefulWidget {
InvoiceResponseModel? placedOrderList; // InvoiceResponseModel? placedOrderList;
GetInvoiceModel? placeInvoiceList; GetInvoiceModel? placeInvoiceList;
RdOrderProcessingDetailScreen({super.key ,this.placedOrderList,this.placeInvoiceList}); //final String? orderId;
RdOrderProcessingDetailScreen({super.key ,this.placeInvoiceList,});
@override @override
State<RdOrderProcessingDetailScreen> createState() => _RdOrderProcessingDetailScreenState(); State<RdOrderProcessingDetailScreen> createState() => _RdOrderProcessingDetailScreenState();
@ -60,10 +63,15 @@ class _RdOrderProcessingDetailScreenState extends State<RdOrderProcessingDetailS
} }
getOrder1(){
_getSingleInvoiceController.fetchInvoice(widget.placedOrderList!.id);
print("dfdfdfg"'');
}
// getOrder1(){
// _getSingleInvoiceController.fetchInvoice(widget.placeInvoiceList!.id.toString());
// print("dfdfdfg"'');
// }
void _showDispatchDetailsDialog() { void _showDispatchDetailsDialog() {
// Only show the dialog if the selected status is "dispatch" // Only show the dialog if the selected status is "dispatch"
if (selectedStatus != "dispatch") { if (selectedStatus != "dispatch") {
@ -112,7 +120,7 @@ class _RdOrderProcessingDetailScreenState extends State<RdOrderProcessingDetailS
String courierTrackingId = _courierTrackingIdController.text; String courierTrackingId = _courierTrackingIdController.text;
// Call the API to submit data // Call the API to submit data
_getDispatchController.RDProcessingToDispatchProduct(widget.placedOrderList!.id, courierName, courierTrackingId); _getDispatchController.RDProcessingToDispatchProduct(widget.placeInvoiceList!.id.toString(), courierName, courierTrackingId);
showSnackbar("Order Status updated Order Dispatched"); showSnackbar("Order Status updated Order Dispatched");
Navigator.of(context).pop(); // Close the dialog after submission Navigator.of(context).pop(); // Close the dialog after submission
}, },
@ -128,11 +136,13 @@ class _RdOrderProcessingDetailScreenState extends State<RdOrderProcessingDetailS
void initState() { void initState() {
// TODO: implement initState // TODO: implement initState
super.initState(); super.initState();
getOrder1(); // getOrder1();
} }
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
// final invoiceOrder = _getSingleInvoiceController.invoice;
return Scaffold( return Scaffold(
extendBodyBehindAppBar: true, extendBodyBehindAppBar: true,
appBar: AppBar( appBar: AppBar(
@ -171,7 +181,27 @@ class _RdOrderProcessingDetailScreenState extends State<RdOrderProcessingDetailS
), ),
SafeArea( SafeArea(
child: SingleChildScrollView( child: SingleChildScrollView(
child: Column( child:
// if (invoiceOrder == null) {
// return Center(
// child: Text(
// "No invoice data available",
// style: GoogleFonts.roboto(fontSize: 16),
// ),
// );
// }
// // Check if the items list is empty before building the UI
// if (invoiceOrder[0]!.items == null || invoiceOrder[0]!.items!.isEmpty) {
// return Center(
// child: Text(
// "No items found in the invoice",
// style: GoogleFonts.roboto(fontSize: 16),
// ),
// );
// }
//final currentInvoice = invoiceOrder;
Column(
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.start, mainAxisAlignment: MainAxisAlignment.start,
children: [ children: [
@ -190,15 +220,13 @@ class _RdOrderProcessingDetailScreenState extends State<RdOrderProcessingDetailS
child: Column( child: Column(
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,
children: [ children: [
Card( Card(
child: Column( child: Column(
children: [ children: [
SizedBox( SizedBox(
width: Get.width, width: Get.width,
child: Padding( child: Padding(
padding: padding: const EdgeInsets.fromLTRB(8, 8, 8, 0),
const EdgeInsets.fromLTRB(8, 8, 8, 0),
child: Text( child: Text(
"Invoices", "Invoices",
style: GoogleFonts.roboto( style: GoogleFonts.roboto(
@ -208,11 +236,11 @@ class _RdOrderProcessingDetailScreenState extends State<RdOrderProcessingDetailS
), ),
), ),
), ),
SizedBox( SizedBox(
width: Get.width, width: Get.width,
child: Padding( child: Padding(
padding: padding: const EdgeInsets.fromLTRB(8, 8, 8, 0),
const EdgeInsets.fromLTRB(8, 8, 8, 0),
child: Row( child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween, mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [ children: [
@ -223,8 +251,7 @@ class _RdOrderProcessingDetailScreenState extends State<RdOrderProcessingDetailS
fontWeight: FontWeight.bold, fontWeight: FontWeight.bold,
), ),
), ),
Text(widget.placedOrderList!.invoiceId), Text(widget.placeInvoiceList!.invoiceId.toString()),
// Text(widget.placedOrderList!.uniqueId),
], ],
), ),
), ),
@ -243,24 +270,24 @@ class _RdOrderProcessingDetailScreenState extends State<RdOrderProcessingDetailS
fontWeight: FontWeight.bold, fontWeight: FontWeight.bold,
), ),
), ),
SizedBox(height: 10), // Add spacing between the title and the list of items SizedBox(height: 10),
Column( Column(
children: widget.placedOrderList!.items.map((item) { children: widget.placeInvoiceList!.items!.map((item) {
return Padding( return Padding(
padding: const EdgeInsets.symmetric(vertical: 4.0), // Add some spacing between items padding: const EdgeInsets.symmetric(vertical: 4.0),
child: Row( child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween, mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [ children: [
Expanded( Expanded(
child: Text( child: Text(
"${item.name.toString()} (${item.sku.toString()})", "${item.name} (${item.sku})",
style: GoogleFonts.roboto( style: GoogleFonts.roboto(
fontSize: Get.width * 0.03, fontSize: Get.width * 0.03,
), ),
overflow: TextOverflow.ellipsis, // Handle long text overflow: TextOverflow.ellipsis,
), ),
), ),
Text("x ${item.processQuantity.toString()}"), Text("x ${item.processQuantity}"),
], ],
), ),
); );
@ -270,45 +297,21 @@ class _RdOrderProcessingDetailScreenState extends State<RdOrderProcessingDetailS
), ),
), ),
), ),
SizedBox( SizedBox(
width: Get.width, width: Get.width,
child: Padding( child: Padding(
padding: padding: const EdgeInsets.fromLTRB(8, 8, 8, 0),
const EdgeInsets.fromLTRB(8, 8, 8, 0),
child: Row( child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween, mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [ children: [
Text( Text(
"Sub Total : ", "Sub Total: ",
style: GoogleFonts.roboto( style: GoogleFonts.roboto(
fontSize: Get.width * 0.04, fontSize: Get.width * 0.04,
fontWeight: FontWeight.bold, fontWeight: FontWeight.bold,
), ),
), ),
Text("${widget.placedOrderList!.subtotal}"), Text("${widget.placeInvoiceList!.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!.gstTotal}"),
], ],
), ),
), ),
@ -316,8 +319,26 @@ class _RdOrderProcessingDetailScreenState extends State<RdOrderProcessingDetailS
SizedBox( SizedBox(
width: Get.width, width: Get.width,
child: Padding( child: Padding(
padding: padding: const EdgeInsets.fromLTRB(8, 8, 8, 0),
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.placeInvoiceList!.gstTotal}"),
],
),
),
),
SizedBox(
width: Get.width,
child: Padding(
padding: const EdgeInsets.fromLTRB(8, 8, 8, 0),
child: Row( child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween, mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [ children: [
@ -328,7 +349,7 @@ class _RdOrderProcessingDetailScreenState extends State<RdOrderProcessingDetailS
fontWeight: FontWeight.bold, fontWeight: FontWeight.bold,
), ),
), ),
Text("${widget.placedOrderList!.invoiceAmount}"), Text("${widget.placeInvoiceList!.invoiceAmount}"),
], ],
), ),
), ),
@ -339,7 +360,8 @@ class _RdOrderProcessingDetailScreenState extends State<RdOrderProcessingDetailS
padding: padding:
const EdgeInsets.fromLTRB(8, 8, 8, 0), const EdgeInsets.fromLTRB(8, 8, 8, 0),
child: Row( child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween, mainAxisAlignment: MainAxisAlignment
.spaceBetween,
children: [ children: [
Text( Text(
"Courier Status : ", "Courier Status : ",
@ -349,7 +371,7 @@ class _RdOrderProcessingDetailScreenState extends State<RdOrderProcessingDetailS
), ),
), ),
ElevatedButton( ElevatedButton(
onPressed: (){}, onPressed: () {},
// Get.to(() => // Get.to(() =>
// RdOrderDetailScreen( // RdOrderDetailScreen(
// placedOrderList: uniqueOrders[index])), // Navigate to detail screen // placedOrderList: uniqueOrders[index])), // Navigate to detail screen
@ -357,10 +379,15 @@ class _RdOrderProcessingDetailScreenState extends State<RdOrderProcessingDetailS
foregroundColor: Colors.white, foregroundColor: Colors.white,
backgroundColor: Colors.orange, backgroundColor: Colors.orange,
shape: RoundedRectangleBorder( shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10)), borderRadius: BorderRadius
.circular(10)),
), ),
child: child:
Text(widget.placedOrderList!.courierStatus, style: GoogleFonts.roboto(fontSize: 14, fontWeight: FontWeight.w400)), Text(widget.placeInvoiceList!.courierStatus.toString(),
style: GoogleFonts.roboto(
fontSize: 14,
fontWeight: FontWeight
.w400)),
), ),
//Text("${widget.placedOrderList!.gstTotal}"), //Text("${widget.placedOrderList!.gstTotal}"),
], ],
@ -375,11 +402,9 @@ class _RdOrderProcessingDetailScreenState extends State<RdOrderProcessingDetailS
const SizedBox(height: 8), const SizedBox(height: 8),
const SizedBox(height: 8), const SizedBox(height: 8),
SizedBox( SizedBox(
height: Get.height* 0.19, height: Get.height * 0.19,
child: Card( child: Card(
child: Column( child: Column(
children: [ children: [
@ -412,9 +437,11 @@ class _RdOrderProcessingDetailScreenState extends State<RdOrderProcessingDetailS
fontWeight: FontWeight.bold, fontWeight: FontWeight.bold,
), ),
), ),
Text("${"VAIBHAV"}",maxLines: 4, Text("${widget.placeInvoiceList!.orderId!.addedBy!.name}", maxLines: 4,
overflow:TextOverflow.ellipsis,) overflow: TextOverflow
, ], .ellipsis,)
,
],
) )
), ),
), ),
@ -433,9 +460,13 @@ class _RdOrderProcessingDetailScreenState extends State<RdOrderProcessingDetailS
fontWeight: FontWeight.bold, fontWeight: FontWeight.bold,
), ),
), ),
Text("${"vaibhav.gurjar20001@gmail.com"}",maxLines: 4, Text(
overflow:TextOverflow.ellipsis,) "${widget.placeInvoiceList!.orderId!.addedBy!.email}",
, ], maxLines: 4,
overflow: TextOverflow
.ellipsis,)
,
],
) )
), ),
), ),
@ -454,9 +485,12 @@ class _RdOrderProcessingDetailScreenState extends State<RdOrderProcessingDetailS
fontWeight: FontWeight.bold, fontWeight: FontWeight.bold,
), ),
), ),
Text("${"7779797976"}",maxLines: 4, Text(
overflow:TextOverflow.ellipsis,) "${widget.placeInvoiceList!.orderId!.addedBy!.mobileNumber}", maxLines: 4,
, ], overflow: TextOverflow
.ellipsis,)
,
],
) )
), ),
) )
@ -485,12 +519,13 @@ class _RdOrderProcessingDetailScreenState extends State<RdOrderProcessingDetailS
), ),
SizedBox( SizedBox(
width: Get.width, width: Get.width,
height: Get.height*0.06, height: Get.height * 0.06,
child: Padding( child: Padding(
padding: padding:
const EdgeInsets.fromLTRB(8, 8, 8, 0), const EdgeInsets.fromLTRB(8, 8, 8, 0),
child: Wrap( child: Wrap(
crossAxisAlignment: WrapCrossAlignment.start, crossAxisAlignment: WrapCrossAlignment
.start,
children: [ children: [
Text( Text(
"Address: ", "Address: ",
@ -499,8 +534,10 @@ class _RdOrderProcessingDetailScreenState extends State<RdOrderProcessingDetailS
fontWeight: FontWeight.bold, fontWeight: FontWeight.bold,
), ),
), ),
Text("${"456, Park Street, Kolkata, West Bengal - 700016"}",maxLines: 4, Text(
overflow:TextOverflow.ellipsis,) "${widget.placeInvoiceList!.orderId!.billTo}",
maxLines: 4,
overflow: TextOverflow.ellipsis,)
], ],
), ),
), ),
@ -530,12 +567,13 @@ class _RdOrderProcessingDetailScreenState extends State<RdOrderProcessingDetailS
), ),
SizedBox( SizedBox(
width: Get.width, width: Get.width,
height: Get.height*0.06, height: Get.height * 0.06,
child: Padding( child: Padding(
padding: padding:
const EdgeInsets.fromLTRB(8, 8, 8, 0), const EdgeInsets.fromLTRB(8, 8, 8, 0),
child: Wrap( child: Wrap(
crossAxisAlignment: WrapCrossAlignment.start, crossAxisAlignment: WrapCrossAlignment
.start,
children: [ children: [
Text( Text(
"Address: ", "Address: ",
@ -544,8 +582,10 @@ class _RdOrderProcessingDetailScreenState extends State<RdOrderProcessingDetailS
fontWeight: FontWeight.bold, fontWeight: FontWeight.bold,
), ),
), ),
Text("${"456, Park Street, Kolkata, West Bengal - 700016"}",maxLines: 4, Text(
overflow:TextOverflow.ellipsis,) "${widget.placeInvoiceList!.orderId!.shipTo}",
maxLines: 4,
overflow: TextOverflow.ellipsis,)
], ],
), ),
), ),
@ -560,7 +600,7 @@ class _RdOrderProcessingDetailScreenState extends State<RdOrderProcessingDetailS
children: [ children: [
SizedBox( SizedBox(
width: Get.width, width: Get.width,
height: Get.height*0.05, height: Get.height * 0.05,
child: Padding( child: Padding(
padding: padding:
const EdgeInsets.fromLTRB(8, 8, 8, 0), const EdgeInsets.fromLTRB(8, 8, 8, 0),
@ -573,7 +613,8 @@ class _RdOrderProcessingDetailScreenState extends State<RdOrderProcessingDetailS
fontWeight: FontWeight.w500, fontWeight: FontWeight.w500,
), ),
), ),
Text(capitalizeFirstLetter("online-transfer")), Text(capitalizeFirstLetter(
widget.placeInvoiceList!.orderId!.paymentMode.toString())),
// Text("${widget.placedOrderList!.paymentMode}",maxLines: 4, // Text("${widget.placedOrderList!.paymentMode}",maxLines: 4,
// overflow:TextOverflow.ellipsis,) // overflow:TextOverflow.ellipsis,)
], ],
@ -591,7 +632,7 @@ class _RdOrderProcessingDetailScreenState extends State<RdOrderProcessingDetailS
children: [ children: [
SizedBox( SizedBox(
width: Get.width, width: Get.width,
height: Get.height*0.05, height: Get.height * 0.05,
child: Padding( child: Padding(
padding: padding:
const EdgeInsets.fromLTRB(8, 8, 8, 0), const EdgeInsets.fromLTRB(8, 8, 8, 0),
@ -604,10 +645,10 @@ class _RdOrderProcessingDetailScreenState extends State<RdOrderProcessingDetailS
fontWeight: FontWeight.w500, fontWeight: FontWeight.w500,
), ),
), ),
SizedBox(width: Get.width*0.01,), SizedBox(width: Get.width * 0.01,),
//Text(capitalizeFirstLetter(widget.placedOrderList!.status)), //Text(capitalizeFirstLetter(widget.placedOrderList!.status)),
Text("${widget.placedOrderList!.courierStatus}",maxLines: 4, Text("${widget.placeInvoiceList!.courierStatus}", maxLines: 4,
overflow:TextOverflow.ellipsis,) overflow: TextOverflow.ellipsis,)
], ],
), ),
), ),
@ -625,19 +666,23 @@ class _RdOrderProcessingDetailScreenState extends State<RdOrderProcessingDetailS
children: [ children: [
const Text( const Text(
"Status: ", "Status: ",
style: TextStyle(fontWeight: FontWeight.bold), style: TextStyle(
fontWeight: FontWeight.bold),
), ),
SizedBox(width: 10), // Space between label and dropdown SizedBox(width: 10),
// Space between label and dropdown
Expanded( Expanded(
child: DropdownButtonFormField<String>( child: DropdownButtonFormField<String>(
value: selectedStatus, value: selectedStatus,
decoration: InputDecoration( decoration: InputDecoration(
filled: true, filled: true,
fillColor: Colors.white, // White background fillColor: Colors.white,
// White background
contentPadding: EdgeInsets.symmetric( contentPadding: EdgeInsets.symmetric(
vertical: 10, horizontal: 12), vertical: 10, horizontal: 12),
border: OutlineInputBorder( border: OutlineInputBorder(
borderRadius: BorderRadius.circular(10), borderRadius: BorderRadius.circular(
10),
borderSide: BorderSide( borderSide: BorderSide(
color: Colors.grey, color: Colors.grey,
width: 1, width: 1,
@ -647,7 +692,8 @@ class _RdOrderProcessingDetailScreenState extends State<RdOrderProcessingDetailS
items: _statusList.map((String status) { items: _statusList.map((String status) {
return DropdownMenuItem<String>( return DropdownMenuItem<String>(
value: status, value: status,
child: Text(capitalizeFirstLetter(status)), child: Text(
capitalizeFirstLetter(status)),
); );
}).toList(), }).toList(),
onChanged: (newValue) { onChanged: (newValue) {
@ -665,7 +711,7 @@ class _RdOrderProcessingDetailScreenState extends State<RdOrderProcessingDetailS
child: Padding( child: Padding(
padding: const EdgeInsets.all(8.0), padding: const EdgeInsets.all(8.0),
child: ElevatedButton( child: ElevatedButton(
onPressed: (){ onPressed: () {
//_getDispatchController.RDProcessingToDispatchProduct(widget.placedOrderList!.invoiceId, widget.placedOrderList!., couriertrackingId) //_getDispatchController.RDProcessingToDispatchProduct(widget.placedOrderList!.invoiceId, widget.placedOrderList!., couriertrackingId)
_showDispatchDetailsDialog(); _showDispatchDetailsDialog();
}, },
@ -676,9 +722,12 @@ class _RdOrderProcessingDetailScreenState extends State<RdOrderProcessingDetailS
foregroundColor: Colors.white, foregroundColor: Colors.white,
backgroundColor: const Color(0xFF004791), backgroundColor: const Color(0xFF004791),
shape: RoundedRectangleBorder( shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10)), borderRadius: BorderRadius.circular(
10)),
), ),
child: Text("Update Status", style: GoogleFonts.roboto(fontSize: 14, fontWeight: FontWeight.w400)), child: Text("Update Status",
style: GoogleFonts.roboto(fontSize: 14,
fontWeight: FontWeight.w400)),
), ),
), ),
) )
@ -690,9 +739,11 @@ class _RdOrderProcessingDetailScreenState extends State<RdOrderProcessingDetailS
SizedBox(height: Get.height * 0.04), SizedBox(height: Get.height * 0.04),
], ],
)),
), ),
),
),
], ],
), ),
); );

View File

@ -1,4 +1,5 @@
import 'package:cheminova/controller/get_single_invoice_controller.dart';
import 'package:cheminova/controller/rd_get_order_controller.dart'; import 'package:cheminova/controller/rd_get_order_controller.dart';
import 'package:cheminova/controller/rd_processing_invoice_controller.dart'; import 'package:cheminova/controller/rd_processing_invoice_controller.dart';
import 'package:cheminova/models/rd_get_order_model.dart'; import 'package:cheminova/models/rd_get_order_model.dart';
@ -18,7 +19,9 @@ import 'package:flutter_svg/svg.dart';
import 'package:get/get.dart'; import 'package:get/get.dart';
import 'package:google_fonts/google_fonts.dart'; import 'package:google_fonts/google_fonts.dart';
import 'package:intl/intl.dart'; import 'package:intl/intl.dart';
import 'package:shared_preferences/shared_preferences.dart';
import '../../controller/get_single_invoice_Service.dart';
import '../order_management/order_management_detail_screen.dart'; import '../order_management/order_management_detail_screen.dart';
class RdOrderProcessingScreen extends StatefulWidget { class RdOrderProcessingScreen extends StatefulWidget {
@ -40,12 +43,14 @@ class _RdOrderProcessingScreenState extends State<RdOrderProcessingScreen> {
"delivered",]; "delivered",];
int _selectedIndex = 0; int _selectedIndex = 0;
final GetRDProcessingInvoiceController _getRdProductController = Get.put(GetRDProcessingInvoiceController()); final GetRDProcessingInvoiceController _getRdProductController = Get.put(GetRDProcessingInvoiceController());
final GetSingleInvoiceController _getSingleInvoiceController = Get.put(GetSingleInvoiceController());
final GlobalKey<RefreshIndicatorState> _refreshIndicatorKey = GlobalKey<RefreshIndicatorState>(); final GlobalKey<RefreshIndicatorState> _refreshIndicatorKey = GlobalKey<RefreshIndicatorState>();
@override @override
void initState() { void initState() {
super.initState(); super.initState();
getOrder1(); getOrder1();
} }
Future<void> _onRefresh() async { Future<void> _onRefresh() async {
@ -65,6 +70,10 @@ class _RdOrderProcessingScreenState extends State<RdOrderProcessingScreen> {
}); });
} }
String capitalizeFirstLetter(String text) { String capitalizeFirstLetter(String text) {
if (text.isEmpty) return text; if (text.isEmpty) return text;
return text[0].toUpperCase() + text.substring(1).toLowerCase(); return text[0].toUpperCase() + text.substring(1).toLowerCase();
@ -80,7 +89,60 @@ class _RdOrderProcessingScreenState extends State<RdOrderProcessingScreen> {
return formattedDate; // Return the formatted date string return formattedDate; // Return the formatted date string
} }
@override
void onOrderTap(int index) async {
try {
// Fetch orders and ensure you wait for it to complete
await _getRdProductController.getRDProcessingInvoiceProduct();
// Log the count of fetched orders
print('Fetched orders count: ${_getRdProductController.productProcessingRDList.length}');
if (_getRdProductController.productProcessingRDList.isNotEmpty) {
// Ensure the index is valid
if (index >= 0 && index < _getRdProductController.productProcessingRDList.length) {
// Get the order ID from the list based on the index
final orderId = _getRdProductController.productProcessingRDList[index].id;
// Retrieve the token from SharedPreferences
SharedPreferences prefs = await SharedPreferences.getInstance();
String? token = prefs.getString('token');
// Check if the token is not null
if (token != null) {
// Fetch the single order using the order ID, and avoid caching issues
final singleOrder = await GetSingleInvoiceService().fetchInvoice(token, orderId);
// Check if the single order was fetched successfully
if (singleOrder != null) {
// Navigate to the details screen with the fetched order
Get.to(() => RdOrderProcessingDetailScreen(
placeInvoiceList: singleOrder,
// orderId: orderId,
));
} } else {
// Handle the case where the single order could not be fetched
Get.snackbar("Error", "Unable to fetch order details.");
}
} else {
// Handle the case where the token is null
Get.snackbar("Error", "User not authenticated.");
}
} else {
// Handle the case when the index is out of bounds
Get.snackbar("Error", "Invalid order selection.");
}
} catch (e) {
// Log any errors that occur during the process
print('Error in onOrderTap: $e');
Get.snackbar("Error", "An unexpected error occurred.");
}
}
@override
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Scaffold( return Scaffold(
@ -258,8 +320,14 @@ class _RdOrderProcessingScreenState extends State<RdOrderProcessingScreen> {
child: Padding( child: Padding(
padding: const EdgeInsets.all(8.0), padding: const EdgeInsets.all(8.0),
child: ElevatedButton( child: ElevatedButton(
onPressed: () => onPressed: () async{
Get.to(() => RdOrderProcessingDetailScreen(placedOrderList: _getRdProductController.productProcessingRDList[index])), //await _getSingleInvoiceController.fetchInvoice(widget.getrdProduct!.id);
onOrderTap(index);
// Now navigate to the details screen
//Get.to(() => RdOrderProcessingDetailScreen());
},
//=>
// Get.to(() => RdOrderProcessingDetailScreen(placedOrderList:_getRdProductController.productProcessingRDList[index])),
style: ElevatedButton.styleFrom( style: ElevatedButton.styleFrom(
foregroundColor: Colors.white, foregroundColor: Colors.white,
backgroundColor: const Color(0xFF004791), backgroundColor: const Color(0xFF004791),

View File

@ -76,4 +76,9 @@ class ApiUrls {
//============================== RD dispatched to Delivered Order Details ==============================// //============================== RD dispatched to Delivered Order Details ==============================//
static const String RdDispatchtoDeliveredOrdergUrl = '/api/pd-invoice/delivered'; static const String RdDispatchtoDeliveredOrdergUrl = '/api/pd-invoice/delivered';
//============================== Annaouncement Details ==============================//
static const String AnnaouncementUrl = '${baseUrl}/api/announcement/PDs';
} }