diff --git a/lib/models/single_get_order_model.dart b/lib/models/single_get_order_model.dart index 7d50440..4e93d40 100644 --- a/lib/models/single_get_order_model.dart +++ b/lib/models/single_get_order_model.dart @@ -1,72 +1,345 @@ +// import 'package:cheminova/models/rd_order_item_model.dart'; +// +// class SingleGetOrderModel { +// final String id; +// String? paymentMode; +// String? shipTo; +// String? billTo; +// List? orderItem; +// double? subtotal; +// double? gstTotal; +// double? grandTotal; +// String? status; +// List? invoices; +// AddedBy? addedBy; +// String? pd; +// bool? isCancelled; +// bool? isDelivered; +// String? deliveredDate; +// DateTime? statusUpdatedAt; +// String? uniqueId; +// DateTime? createdAt; +// DateTime? updatedAt; +// +// SingleGetOrderModel({ +// required this.id, +// this.paymentMode, +// this.shipTo, +// this.billTo, +// this.orderItem, +// this.subtotal, +// this.gstTotal, +// this.grandTotal, +// this.status, +// this.invoices, +// this.addedBy, +// this.pd, +// this.isCancelled, +// this.isDelivered, +// this.deliveredDate, +// this.statusUpdatedAt, +// this.uniqueId, +// this.createdAt, +// this.updatedAt, +// }); +// +// factory SingleGetOrderModel.fromJson(Map json) { +// return SingleGetOrderModel( +// id: json['_id'] ?? '', +// paymentMode: json['paymentMode'] ?? '', +// shipTo: json['shipTo'] ?? '', +// billTo: json['billTo'] ?? '', +// orderItem: (json['orderItem'] as List?) +// ?.map((item) => RDOrderItem.fromJson(item)) +// .toList() ?? +// [], +// subtotal: (json['subtotal'] as num?)?.toDouble() ?? 0.0, +// gstTotal: (json['gstTotal'] as num?)?.toDouble() ?? 0.0, +// grandTotal: (json['grandTotal'] as num?)?.toDouble() ?? 0.0, +// status: json['status'] ?? '', +// invoices: json['invoices'] ?? [], +// addedBy: AddedBy.fromJson(json['addedBy'] ?? {}), +// pd: json['pd'] ?? '', +// isCancelled: json['iscancelled'] ?? false, +// isDelivered: json['isDelivered'] ?? false, +// deliveredDate: json['DeliveredDate'] ?? '', +// statusUpdatedAt: DateTime.parse(json['statusUpdatedAt'] ?? DateTime.now().toString()), +// uniqueId: json['uniqueId'] ?? '', +// createdAt: DateTime.parse(json['createdAt'] ?? DateTime.now().toString()), +// updatedAt: DateTime.parse(json['updatedAt'] ?? DateTime.now().toString()), +// ); +// } +// +// Map toJson() { +// return { +// '_id': id, +// 'paymentMode': paymentMode, +// 'shipTo': shipTo, +// 'billTo': billTo, +// 'orderItem': orderItem?.map((item) => item.toJson()).toList(), +// 'subtotal': subtotal, +// 'gstTotal': gstTotal, +// 'grandTotal': grandTotal, +// 'status': status, +// 'invoices': invoices, +// 'addedBy': addedBy?.toJson(), +// 'pd': pd, +// 'iscancelled': isCancelled, +// 'isDelivered': isDelivered, +// 'DeliveredDate': deliveredDate, +// 'statusUpdatedAt': statusUpdatedAt?.toIso8601String(), +// 'uniqueId': uniqueId, +// 'createdAt': createdAt?.toIso8601String(), +// 'updatedAt': updatedAt?.toIso8601String(), +// }; +// } +// +// @override +// String toString() { +// return 'SingleGetOrderModel(id: $id, paymentMode: $paymentMode, shipTo: $shipTo, billTo: $billTo, ' +// 'orderItem: $orderItem, subtotal: $subtotal, gstTotal: $gstTotal, grandTotal: $grandTotal, ' +// 'status: $status, invoices: $invoices, addedBy: $addedBy, pd: $pd, ' +// 'isCancelled: $isCancelled, isDelivered: $isDelivered, deliveredDate: $deliveredDate, ' +// 'statusUpdatedAt: $statusUpdatedAt, uniqueId: $uniqueId, createdAt: $createdAt, updatedAt: $updatedAt)'; +// } +// } +// +// class OrderItem { +// final String productId; +// final String sku; +// final String name; +// final String categoryName; +// final String brandName; +// final int price; // Use int for price +// final int gst; // Use int for GST +// final int hsnCode; // Use int for HSN Code +// final String description; +// final List image; // Assuming images are stored as a list of strings +// final int quantity; +// final int remainingQuantity; +// int? processQuantity; +// final String id; // Use String for _id +// +// OrderItem({ +// required this.productId, +// required this.sku, +// required this.name, +// required this.categoryName, +// required this.brandName, +// required this.price, +// required this.gst, +// required this.hsnCode, +// required this.description, +// required this.image, +// required this.quantity, +// required this.remainingQuantity, +// this.processQuantity = 1, +// required this.id, +// }); +// +// factory OrderItem.fromJson(Map json) { +// return OrderItem( +// productId: json['productId'] ?? '', +// sku: json['SKU'] ?? '', +// name: json['name'] ?? '', +// categoryName: json['categoryName'] ?? '', +// brandName: json['brandName'] ?? '', +// price: (json['price'] as num?)?.toInt() ?? 0, // Handle as num +// gst: (json['GST'] as num?)?.toInt() ?? 0, // Handle as num +// hsnCode: (json['HSN_Code'] as num?)?.toInt() ?? 0, // Handle as num +// description: json['description'] ?? '', +// image: List.from(json['image'] ?? []), +// quantity: (json['quantity'] as num?)?.toInt() ?? 0, // Handle as num +// remainingQuantity: (json['remainingQuantity'] as num?)?.toInt() ?? 0, // Handle as num +// processQuantity: (json['processQuantity']as num?)?.toInt()??0, +// id: json['_id'] ?? '', +// ); +// } +// +// Map toJson() { +// return { +// 'productId': productId, +// 'SKU': sku, +// 'name': name, +// 'categoryName': categoryName, +// 'brandName': brandName, +// 'price': price, +// 'GST': gst, +// 'HSN_Code': hsnCode, +// 'description': description, +// 'image': image, +// 'quantity': quantity, +// 'remainingQuantity': remainingQuantity, +// '_id': id, +// }; +// } +// +// @override +// String toString() { +// return 'OrderItem(productId: $productId, SKU: $sku, name: $name, categoryName: $categoryName, ' +// 'brandName: $brandName, price: $price, GST: $gst, HSN_Code: $hsnCode, ' +// 'description: $description, image: $image, quantity: $quantity, ' +// 'remainingQuantity: $remainingQuantity, id: $id)'; +// } +// } +// +// class AddedBy { +// final String id; +// final String designation; +// final String name; +// final String email; +// final String mobileNumber; +// final String principalDistributor; +// final String addedBy; +// final String userType; +// final String kyc; +// String? fcmToken; +// final DateTime createdAt; +// final DateTime updatedAt; +// final String mappedSC; +// final String uniqueId; +// final String mappedTM; +// +// AddedBy({ +// required this.id, +// required this.designation, +// required this.name, +// required this.email, +// required this.mobileNumber, +// required this.principalDistributor, +// required this.addedBy, +// required this.userType, +// required this.kyc, +// this.fcmToken, +// required this.createdAt, +// required this.updatedAt, +// required this.mappedSC, +// required this.uniqueId, +// required this.mappedTM, +// }); +// +// factory AddedBy.fromJson(Map json) { +// return AddedBy( +// id: json['_id'] ?? '', +// designation: json['designation'] ?? '', +// name: json['name'] ?? '', +// email: json['email'] ?? '', +// mobileNumber: json['mobile_number'] ?? '', +// principalDistributor: json['principal_distributer'] ?? '', +// addedBy: json['addedBy'] ?? '', +// userType: json['userType'] ?? '', +// kyc: json['kyc'] ?? '', +// fcmToken: json['fcm_token']?.toString(), // Handle null safely +// createdAt: DateTime.parse(json['createdAt'] ?? DateTime.now().toString()), +// updatedAt: DateTime.parse(json['updatedAt'] ?? DateTime.now().toString()), +// mappedSC: json['mappedSC'] ?? '', +// uniqueId: json['uniqueId'] ?? '', +// mappedTM: json['mappedTM'] ?? '', +// ); +// } +// +// Map toJson() { +// return { +// '_id': id, +// 'designation': designation, +// 'name': name, +// 'email': email, +// 'mobile_number': mobileNumber, +// 'principal_distributer': principalDistributor, +// 'addedBy': addedBy, +// 'userType': userType, +// 'kyc': kyc, +// 'fcm_token': fcmToken, +// 'createdAt': createdAt.toIso8601String(), +// 'updatedAt': updatedAt.toIso8601String(), +// 'mappedSC': mappedSC, +// 'uniqueId': uniqueId, +// 'mappedTM': mappedTM, +// }; +// } +// +// @override +// String toString() { +// return 'AddedBy(id: $id, designation: $designation, name: $name, email: $email, ' +// 'mobileNumber: $mobileNumber, principalDistributor: $principalDistributor, ' +// 'addedBy: $addedBy, userType: $userType, kyc: $kyc, ' +// 'fcmToken: $fcmToken, createdAt: $createdAt, updatedAt: $updatedAt, ' +// 'mappedSC: $mappedSC, uniqueId: $uniqueId, mappedTM: $mappedTM)'; +// } +// } +import 'dart:convert'; + import 'package:cheminova/models/rd_order_item_model.dart'; +// Main model for the order class SingleGetOrderModel { - final String id; - String? paymentMode; - String? shipTo; - String? billTo; - List? orderItem; - double? subtotal; - double? gstTotal; - double? grandTotal; - String? status; - List? invoices; - AddedBy? addedBy; - String? pd; - bool? isCancelled; - bool? isDelivered; - String? deliveredDate; - DateTime? statusUpdatedAt; - String? uniqueId; - DateTime? createdAt; - DateTime? updatedAt; + String id; + String paymentMode; + String shipTo; + String billTo; + List orderItem; + double subtotal; + double gstTotal; + double grandTotal; + String status; + List invoices; + AddedBy addedBy; + String pd; + bool isCancelled; + bool isDelivered; + String deliveredDate; + String statusUpdatedAt; + String uniqueId; + String createdAt; + String updatedAt; SingleGetOrderModel({ required this.id, - this.paymentMode, - this.shipTo, - this.billTo, - this.orderItem, - this.subtotal, - this.gstTotal, - this.grandTotal, - this.status, - this.invoices, - this.addedBy, - this.pd, - this.isCancelled, - this.isDelivered, - this.deliveredDate, - this.statusUpdatedAt, - this.uniqueId, - this.createdAt, - this.updatedAt, + required this.paymentMode, + required this.shipTo, + required this.billTo, + required this.orderItem, + required this.subtotal, + required this.gstTotal, + required this.grandTotal, + required this.status, + required this.invoices, + required this.addedBy, + required this.pd, + required this.isCancelled, + required this.isDelivered, + required this.deliveredDate, + required this.statusUpdatedAt, + required this.uniqueId, + required this.createdAt, + required this.updatedAt, }); factory SingleGetOrderModel.fromJson(Map json) { return SingleGetOrderModel( - id: json['_id'] ?? '', - paymentMode: json['paymentMode'] ?? '', - shipTo: json['shipTo'] ?? '', - billTo: json['billTo'] ?? '', - orderItem: (json['orderItem'] as List?) - ?.map((item) => RDOrderItem.fromJson(item)) - .toList() ?? - [], - subtotal: (json['subtotal'] as num?)?.toDouble() ?? 0.0, - gstTotal: (json['gstTotal'] as num?)?.toDouble() ?? 0.0, - grandTotal: (json['grandTotal'] as num?)?.toDouble() ?? 0.0, - status: json['status'] ?? '', - invoices: json['invoices'] ?? [], - addedBy: AddedBy.fromJson(json['addedBy'] ?? {}), - pd: json['pd'] ?? '', - isCancelled: json['iscancelled'] ?? false, - isDelivered: json['isDelivered'] ?? false, - deliveredDate: json['DeliveredDate'] ?? '', - statusUpdatedAt: DateTime.parse(json['statusUpdatedAt'] ?? DateTime.now().toString()), - uniqueId: json['uniqueId'] ?? '', - createdAt: DateTime.parse(json['createdAt'] ?? DateTime.now().toString()), - updatedAt: DateTime.parse(json['updatedAt'] ?? DateTime.now().toString()), + id: json['_id']??"1", + paymentMode: json['paymentMode']??"2343", + shipTo: json['shipTo']??"abc", + billTo: json['billTo']??"xyz", + orderItem: (json['orderItem'] as List) + .map((i) => RDOrderItem.fromJson(i)) + .toList(), + subtotal: json['subtotal'].toDouble(), + gstTotal: json['gstTotal'].toDouble(), + grandTotal: json['grandTotal'].toDouble(), + status: json['status'], + invoices: (json['invoices'] as List) + .map((i) => Invoice.fromJson(i)) + .toList(), + addedBy: AddedBy.fromJson(json['addedBy']??""), + pd: json['pd']??"", + isCancelled: json['iscancelled']??"", + isDelivered: json['isDelivered']??"", + deliveredDate: json['DeliveredDate']??"", + statusUpdatedAt: json['statusUpdatedAt']??"", + uniqueId: json['uniqueId']??"", + createdAt: json['createdAt']??"", + updatedAt: json['updatedAt']??"", ); } @@ -76,51 +349,109 @@ class SingleGetOrderModel { 'paymentMode': paymentMode, 'shipTo': shipTo, 'billTo': billTo, - 'orderItem': orderItem?.map((item) => item.toJson()).toList(), + 'orderItem': orderItem.map((i) => i.toJson()).toList(), 'subtotal': subtotal, 'gstTotal': gstTotal, 'grandTotal': grandTotal, 'status': status, - 'invoices': invoices, - 'addedBy': addedBy?.toJson(), + 'invoices': invoices.map((i) => i.toJson()).toList(), + 'addedBy': addedBy.toJson(), 'pd': pd, 'iscancelled': isCancelled, 'isDelivered': isDelivered, 'DeliveredDate': deliveredDate, - 'statusUpdatedAt': statusUpdatedAt?.toIso8601String(), + 'statusUpdatedAt': statusUpdatedAt, 'uniqueId': uniqueId, - 'createdAt': createdAt?.toIso8601String(), - 'updatedAt': updatedAt?.toIso8601String(), + 'createdAt': createdAt, + 'updatedAt': updatedAt, }; } - - @override - String toString() { - return 'SingleGetOrderModel(id: $id, paymentMode: $paymentMode, shipTo: $shipTo, billTo: $billTo, ' - 'orderItem: $orderItem, subtotal: $subtotal, gstTotal: $gstTotal, grandTotal: $grandTotal, ' - 'status: $status, invoices: $invoices, addedBy: $addedBy, pd: $pd, ' - 'isCancelled: $isCancelled, isDelivered: $isDelivered, deliveredDate: $deliveredDate, ' - 'statusUpdatedAt: $statusUpdatedAt, uniqueId: $uniqueId, createdAt: $createdAt, updatedAt: $updatedAt)'; - } } -class OrderItem { - final String productId; - final String sku; - final String name; - final String categoryName; - final String brandName; - final int price; // Use int for price - final int gst; // Use int for GST - final int hsnCode; // Use int for HSN Code - final String description; - final List image; // Assuming images are stored as a list of strings - final int quantity; - final int remainingQuantity; - int? processQuantity; - final String id; // Use String for _id +// Model for individual order items - OrderItem({ + +// Model for invoices +class Invoice { + Map courierStatusTimeline; + String id; + String invoiceId; + String orderId; + List items; + double subtotal; + double gstTotal; + double invoiceAmount; + String courierStatus; + int v; + String courierName; + String courierTrackingId; + + Invoice({ + required this.courierStatusTimeline, + required this.id, + required this.invoiceId, + required this.orderId, + required this.items, + required this.subtotal, + required this.gstTotal, + required this.invoiceAmount, + required this.courierStatus, + required this.v, + required this.courierName, + required this.courierTrackingId, + }); + + factory Invoice.fromJson(Map json) { + return Invoice( + courierStatusTimeline: Map.from(json['courierstatus_timeline']??""), + id: json['_id']??"", + invoiceId: json['invoiceId']??"", + orderId: json['orderId']??"", + items: (json['items'] as List) + .map((i) => InvoiceItem.fromJson(i)) + .toList(), + subtotal: json['subtotal'].toDouble(), + gstTotal: json['gstTotal'].toDouble(), + invoiceAmount: json['invoiceAmount'].toDouble(), + courierStatus: json['courierStatus'], + v: json['__v'], + courierName: json['courier_name']??"", + courierTrackingId: json['courier_tracking_id']??"", + ); + } + + Map toJson() { + return { + 'courierstatus_timeline': courierStatusTimeline, + '_id': id, + 'invoiceId': invoiceId, + 'orderId': orderId, + 'items': items.map((i) => i.toJson()).toList(), + 'subtotal': subtotal, + 'gstTotal': gstTotal, + 'invoiceAmount': invoiceAmount, + 'courierStatus': courierStatus, + '__v': v, + 'courier_name': courierName, + 'courier_tracking_id': courierTrackingId, + }; + } +} + +// Model for items in an invoice +class InvoiceItem { + String productId; + String sku; + String name; + String categoryName; + String brandName; + double price; + double gst; + int hsnCode; + int processQuantity; + String id; + + InvoiceItem({ required this.productId, required this.sku, required this.name, @@ -129,30 +460,22 @@ class OrderItem { required this.price, required this.gst, required this.hsnCode, - required this.description, - required this.image, - required this.quantity, - required this.remainingQuantity, - this.processQuantity = 1, + required this.processQuantity, required this.id, }); - factory OrderItem.fromJson(Map json) { - return OrderItem( - productId: json['productId'] ?? '', - sku: json['SKU'] ?? '', - name: json['name'] ?? '', - categoryName: json['categoryName'] ?? '', - brandName: json['brandName'] ?? '', - price: (json['price'] as num?)?.toInt() ?? 0, // Handle as num - gst: (json['GST'] as num?)?.toInt() ?? 0, // Handle as num - hsnCode: (json['HSN_Code'] as num?)?.toInt() ?? 0, // Handle as num - description: json['description'] ?? '', - image: List.from(json['image'] ?? []), - quantity: (json['quantity'] as num?)?.toInt() ?? 0, // Handle as num - remainingQuantity: (json['remainingQuantity'] as num?)?.toInt() ?? 0, // Handle as num - processQuantity: (json['processQuantity']as num?)?.toInt()??0, - id: json['_id'] ?? '', + factory InvoiceItem.fromJson(Map json) { + return InvoiceItem( + productId: json['productId']??"", + sku: json['SKU']??"", + name: json['name']??"", + categoryName: json['categoryName']??"", + brandName: json['brandName']??"", + price: json['price'].toDouble(), + gst: json['GST'].toDouble(), + hsnCode: json['HSN_Code']??"", + processQuantity: json['processquantity']??"", + id: json['_id']??"", ); } @@ -166,23 +489,13 @@ class OrderItem { 'price': price, 'GST': gst, 'HSN_Code': hsnCode, - 'description': description, - 'image': image, - 'quantity': quantity, - 'remainingQuantity': remainingQuantity, + 'processquantity': processQuantity, '_id': id, }; } - - @override - String toString() { - return 'OrderItem(productId: $productId, SKU: $sku, name: $name, categoryName: $categoryName, ' - 'brandName: $brandName, price: $price, GST: $gst, HSN_Code: $hsnCode, ' - 'description: $description, image: $image, quantity: $quantity, ' - 'remainingQuantity: $remainingQuantity, id: $id)'; - } } +//Model for the user who added the order class AddedBy { final String id; final String designation; @@ -229,7 +542,8 @@ class AddedBy { addedBy: json['addedBy'] ?? '', userType: json['userType'] ?? '', kyc: json['kyc'] ?? '', - fcmToken: json['fcm_token']?.toString(), // Handle null safely + fcmToken: json['fcm_token']?.toString(), + // Handle null safely createdAt: DateTime.parse(json['createdAt'] ?? DateTime.now().toString()), updatedAt: DateTime.parse(json['updatedAt'] ?? DateTime.now().toString()), mappedSC: json['mappedSC'] ?? '', @@ -267,3 +581,8 @@ class AddedBy { 'mappedSC: $mappedSC, uniqueId: $uniqueId, mappedTM: $mappedTM)'; } } +// Function to parse the JSON string and create a SingleOrder object +SingleGetOrderModel parseSingleOrder(String jsonString) { + final jsonData = json.decode(jsonString); + return SingleGetOrderModel.fromJson(jsonData); +} diff --git a/lib/screens/home_screen.dart b/lib/screens/home_screen.dart index 6f3d14b..237f098 100644 --- a/lib/screens/home_screen.dart +++ b/lib/screens/home_screen.dart @@ -196,6 +196,27 @@ class _HomeScreenState extends State { ), + ], + ), + + const SizedBox(height: 10), + Row( + mainAxisAlignment: MainAxisAlignment.spaceEvenly, + children: [ + HomeCard( + title: 'Opening Inventory', + onTap: () => Get.to( + () => InventoryManagementScreen(), + ), + ), + // HomeCard( + // title: 'Announcement', + // onTap: () => Get.to( + // () => AnnouncementScreen(), + // ), + // ), + + ], ), ], diff --git a/lib/screens/product/product_catalog_screen.dart b/lib/screens/product/product_catalog_screen.dart index de25b61..5cded70 100644 --- a/lib/screens/product/product_catalog_screen.dart +++ b/lib/screens/product/product_catalog_screen.dart @@ -248,6 +248,19 @@ class _ProductCatalogScreenState extends State { _buildFilterDropdown(index), ), ), + SizedBox( + // height: Get.height * 0.1, + child:_products.isEmpty // Check if no products found + ? Center( + child: Padding( + padding: const EdgeInsets.all(40.0), + child: Text( + "No products found!", + style: TextStyle(fontSize: 16), + ), + ), + ) : SizedBox(), + ), SizedBox( height: Get.height * 0.6, child: ListView.builder( @@ -272,6 +285,7 @@ class _ProductCatalogScreenState extends State { }, ), ), + ], ), ), diff --git a/lib/screens/rd orders/partial_pending_dialog.dart b/lib/screens/rd orders/partial_pending_dialog.dart index 2a17c73..ab66edd 100644 --- a/lib/screens/rd orders/partial_pending_dialog.dart +++ b/lib/screens/rd orders/partial_pending_dialog.dart @@ -122,6 +122,11 @@ class _PartialPendingDialogScreenState extends State @override Widget build(BuildContext context) { + final order = widget.placedOrderList!.orderItem[0]; + final subTotalProcesssItem = order.price! * order.remainingQuantity!.toInt(); + final GstTotalAmounProcessItem = (order.price! * order.remainingQuantity!.toInt()) *(order.gst!/100 ); + final grandTotalProcessItem = subTotalProcesssItem + GstTotalAmounProcessItem; + return Scaffold( extendBodyBehindAppBar: true, appBar: AppBar( @@ -205,7 +210,7 @@ class _PartialPendingDialogScreenState extends State fontWeight: FontWeight.bold, ), ), - Text("₹ ${widget.placedOrderList!.subtotal ?? 0}"), + Text("₹ ${subTotalProcesssItem}"), ], ), Row( @@ -219,7 +224,7 @@ class _PartialPendingDialogScreenState extends State fontWeight: FontWeight.bold, ), ), - Text("₹ ${widget.placedOrderList!.gstTotal ?? 0}"), + Text("₹ ${GstTotalAmounProcessItem}"), ], ), Row( @@ -233,7 +238,7 @@ class _PartialPendingDialogScreenState extends State fontWeight: FontWeight.bold, ), ), - Text("₹ ${widget.placedOrderList!.grandTotal ?? 0}"), + Text("₹ ${grandTotalProcessItem}"), ], ), ], diff --git a/lib/screens/rd orders/partial_processing_dialog_screen.dart b/lib/screens/rd orders/partial_processing_dialog_screen.dart index b9aa64b..eb0c595 100644 --- a/lib/screens/rd orders/partial_processing_dialog_screen.dart +++ b/lib/screens/rd orders/partial_processing_dialog_screen.dart @@ -359,8 +359,6 @@ class _PartialProcessingDialogScreenState extends State createState() => +// _RdCancelledDetailScreenState(); +// } +// +// +// class _RdCancelledDetailScreenState +// extends State { +// // Controllers for managing cart and placed orders +// final CartController _cartController = Get.put(CartController()); +// final GetPlacedOrderController _getPlacedOrderController = Get.put(GetPlacedOrderController()); +// final GetRDCancleController _getRDCancleController = Get.put(GetRDCancleController()); +// final List statusOptions = [ +// "new", +// "pending", +// "processing", +// "dispatched", +// "cancelled", +// "delivered", +// ]; +// String selectedStatus = "All"; +// String _groupValue = "cheque"; +// // Function to format date from the API to a more readable format +// +// +// String formatDate(String apiDate) { +// // Parse the API date string into a DateTime object +// DateTime parsedDate = DateTime.parse(apiDate).toLocal(); // Convert to local time +// +// // Format the date and time according to your specified format +// String formattedDate = DateFormat('EEE MMM dd yyyy').format(parsedDate); +// +// return formattedDate; // Return the formatted date string +// } +// +// // Function to capitalize the first letter of a string +// String capitalizeFirstLetter(String text) { +// if (text.isEmpty) return text; +// return text[0].toUpperCase() + text.substring(1).toLowerCase(); +// } +// +// +// void _onPaymentModeChanged(String? value) { +// setState(() { +// _groupValue = value!; +// }); +// _saveSelectedPaymentMode(); +// } +// +// +// void _saveSelectedPaymentMode() async { +// SharedPreferences prefs = await SharedPreferences.getInstance(); +// await prefs.setString('selectedPaymentMode', _groupValue); +// } +// +// void _loadSelectedPaymentMode() async { +// SharedPreferences prefs = await SharedPreferences.getInstance(); +// setState(() { +// _groupValue = prefs.getString('selectedPaymentMode') ?? 'cheque'; +// }); +// } +// // Function to collect unique order IDs and corresponding order details +// // Future adduni()async { +// // final Set uniqueOrderIds = {}; +// // final List uniqueOrders = []; +// // // Loop through placed orders and add unique orders to the list +// // for (var order in _getPlacedOrderController.placedOrders) { +// // if (uniqueOrderIds.add(order.uniqueId)) { +// // uniqueOrders.add(order); +// // } +// // } +// // final order = uniqueOrders[0]; +// // +// // // Combine product names, categories, and quantities into strings +// // final productNames = order.orderItem +// // .map((item) => (item.name)) +// // .join(', '); +// // final categotyName = order.orderItem +// // .map((item) => (item.categoryName)) +// // .join(', '); +// // final quantity = order.orderItem +// // .map((item) => (item.quantity)) +// // .join(', '); +// // } +// @override +// void initState() { +// // TODO: implement initState +// super.initState(); +// selectedStatus= widget.placedOrderList?.status ?? 'new'; +// } +// +// @override +// Widget build(BuildContext context) { +// return Scaffold( +// extendBodyBehindAppBar: true, +// appBar: AppBar( +// backgroundColor: Colors.transparent, +// elevation: 0, +// leading: GestureDetector( +// onTap: () {}, +// child: Padding( +// padding: const EdgeInsets.all(16.0), +// child: SvgPicture.asset( +// 'assets/svg/menu.svg', +// ), +// ), +// ), +// actions: [ +// GestureDetector( +// onTap: () => Get.back(), +// child: Padding( +// padding: const EdgeInsets.all(8.0), +// child: SvgPicture.asset( +// 'assets/svg/back_arrow.svg', +// ), +// ), +// ), +// ], +// title: const Text( +// "RD Cancelled Order Detail", +// ), +// ), +// body: Stack( +// fit: StackFit.expand, +// children: [ +// Image.asset( +// 'assets/images/image_1.png', +// fit: BoxFit.cover, +// ), +// SafeArea( +// child: SingleChildScrollView( +// child: Column( +// mainAxisSize: MainAxisSize.min, +// mainAxisAlignment: MainAxisAlignment.start, +// children: [ +// SizedBox( +// height: Get.height * 0.02, +// ), +// Card( +// margin: const EdgeInsets.symmetric(horizontal: 18), +// shape: RoundedRectangleBorder( +// borderRadius: BorderRadius.circular(19), +// side: const BorderSide(color: Color(0xFFFDFDFD)), +// ), +// color: const Color(0xFFB4D1E5).withOpacity(0.9), +// child: Padding( +// padding: const EdgeInsets.all(12.0), +// child: Column( +// mainAxisSize: MainAxisSize.min, +// children: [ +// Card( +// child: Column( +// children: [ +// SizedBox( +// width: Get.width, +// child: Padding( +// padding: +// const EdgeInsets.fromLTRB(8, 8, 8, 0), +// child: Text( +// "Invoices", +// style: GoogleFonts.roboto( +// fontSize: Get.width * 0.05, +// fontWeight: FontWeight.bold, +// ), +// ), +// ), +// ), +// SizedBox( +// width: Get.width, +// child: Padding( +// padding: +// const EdgeInsets.fromLTRB(8, 8, 8, 0), +// child: Row( +// mainAxisAlignment: MainAxisAlignment.spaceBetween, +// children: [ +// Text( +// "Invoice ID:", +// style: GoogleFonts.roboto( +// fontSize: Get.width * 0.04, +// fontWeight: FontWeight.bold, +// ), +// ), +// Text(widget.placedOrderList!.uniqueId), +// // Text(widget.placedOrderList!.uniqueId), +// ], +// ), +// ), +// ), +// SizedBox( +// width: Get.width, +// child: Padding( +// padding: const EdgeInsets.fromLTRB(8, 8, 8, 0), +// child: Column( +// crossAxisAlignment: CrossAxisAlignment.start, +// children: [ +// Text( +// "Items: ", +// style: GoogleFonts.roboto( +// fontSize: Get.width * 0.04, +// fontWeight: FontWeight.bold, +// ), +// ), +// SizedBox(height: 10), // Add spacing between the title and the list of items +// Column( +// children: widget.placedOrderList!.orderItems.map((item) { +// return Padding( +// padding: const EdgeInsets.symmetric(vertical: 4.0), // Add some spacing between items +// child: Row( +// mainAxisAlignment: MainAxisAlignment.spaceBetween, +// children: [ +// Expanded( +// child: Text( +// "${item.name.toString()} (${item.sku.toString()})", +// style: GoogleFonts.roboto( +// fontSize: Get.width * 0.03, +// ), +// overflow: TextOverflow.ellipsis, // Handle long text +// ), +// ), +// Text("x ${item.remainingQuantity.toString()}"), +// ], +// ), +// ); +// }).toList(), +// ), +// ], +// ), +// ), +// ), +// SizedBox( +// width: Get.width, +// child: Padding( +// padding: +// const EdgeInsets.fromLTRB(8, 8, 8, 0), +// child: Row( +// mainAxisAlignment: MainAxisAlignment.spaceBetween, +// children: [ +// Text( +// "Sub Total : ", +// style: GoogleFonts.roboto( +// fontSize: Get.width * 0.04, +// fontWeight: FontWeight.bold, +// ), +// ), +// Text("₹ ${widget.placedOrderList!.subtotal}"), +// ], +// ), +// ), +// ), +// +// // SizedBox( +// // width: Get.width, +// // child: Padding( +// // padding: +// // const EdgeInsets.fromLTRB(8, 8, 8, 0), +// // child: Row( +// // mainAxisAlignment: MainAxisAlignment.spaceBetween, +// // children: [ +// // Text( +// // "Gst %: ", +// // style: GoogleFonts.roboto( +// // fontSize: Get.width * 0.04, +// // fontWeight: FontWeight.bold, +// // ), +// // ), +// // Text(" ${widget.placedOrderList!.orderItem[0].gst}%"), +// // ], +// // ), +// // ), +// // ), +// SizedBox( +// width: Get.width, +// child: Padding( +// padding: +// const EdgeInsets.fromLTRB(8, 8, 8, 0), +// child: Row( +// mainAxisAlignment: MainAxisAlignment.spaceBetween, +// children: [ +// Text( +// "GST : ", +// style: GoogleFonts.roboto( +// fontSize: Get.width * 0.04, +// fontWeight: FontWeight.bold, +// ), +// ), +// Text("₹ ${widget.placedOrderList!.gstTotal}"), +// ], +// ), +// ), +// ), +// SizedBox( +// width: Get.width, +// child: Padding( +// padding: +// const EdgeInsets.fromLTRB(8, 8, 8, 0), +// child: Row( +// mainAxisAlignment: MainAxisAlignment.spaceBetween, +// children: [ +// Text( +// "Invoice Amount: ", +// style: GoogleFonts.roboto( +// fontSize: Get.width * 0.04, +// fontWeight: FontWeight.bold, +// ), +// ), +// Text("₹ ${widget.placedOrderList!.grandTotal}"), +// ], +// ), +// ), +// ), +// SizedBox( +// width: Get.width, +// child: Padding( +// padding: +// const EdgeInsets.fromLTRB(8, 8, 8, 0), +// child: Row( +// mainAxisAlignment: MainAxisAlignment.spaceBetween, +// children: [ +// Text( +// "Courier Status : ", +// style: GoogleFonts.roboto( +// fontSize: Get.width * 0.04, +// fontWeight: FontWeight.bold, +// ), +// ), +// ElevatedButton( +// onPressed: (){}, +// // Get.to(() => +// // RdOrderDetailScreen( +// // placedOrderList: uniqueOrders[index])), // Navigate to detail screen +// style: ElevatedButton.styleFrom( +// foregroundColor: Colors.white, +// backgroundColor: Colors.orange, +// shape: RoundedRectangleBorder( +// borderRadius: BorderRadius.circular(10)), +// ), +// child: Text(widget.placedOrderList!.status, style: GoogleFonts.roboto(fontSize: 14, fontWeight: FontWeight.w400)), +// ), +// //Text("₹ ${widget.placedOrderList!.gstTotal}"), +// ], +// ), +// ), +// ), +// ], +// ), +// ), +// +// +// Card( +// child: SizedBox( +// height: Get.height * 0.35, // Adjust the height as per your requirement +// child: Padding( +// padding: EdgeInsets.all(Get.width * 0.02), +// child: Column( +// crossAxisAlignment: CrossAxisAlignment.start, +// children: [ +// // Add title here +// Padding( +// padding: const EdgeInsets.symmetric(vertical: 8.0), // Adjust padding if needed +// child: Text( +// "Order Summary", // Title text +// style: GoogleFonts.roboto( +// fontSize: Get.width * 0.05, // Adjust font size as needed +// fontWeight: FontWeight.bold, +// ), +// ), +// ), +// Expanded( +// child: ListView.builder( +// padding: EdgeInsets.zero, +// itemCount: widget.placedOrderList?.orderItems.length ?? 0, +// itemBuilder: (context, index) { +// final orderItem = widget.placedOrderList!.orderItems[index]; +// return orderItem != null +// ? Card( +// margin: const EdgeInsets.symmetric(vertical: 5.0), +// shape: RoundedRectangleBorder( +// borderRadius: BorderRadius.circular(10), +// ), +// child: Padding( +// padding: const EdgeInsets.all(8.0), +// child: Row( +// children: [ +// Image.asset( +// "assets/images/product.png", +// height: 50, +// width: 50, +// fit: BoxFit.cover, +// ), +// const SizedBox(width: 10), +// Expanded( +// child: Column( +// crossAxisAlignment: CrossAxisAlignment.end, +// children: [ +// Text( +// capitalizeFirstLetter(orderItem.name), +// style: GoogleFonts.roboto( +// fontSize: Get.width * 0.04, +// fontWeight: FontWeight.bold, +// ), +// ), +// Text( +// "Quantity: ${orderItem.quantity}", +// style: GoogleFonts.roboto( +// fontSize: Get.width * 0.03, +// ), +// ), +// Text("Price: ${orderItem.price}"), +// Text("Subtotal: ${widget.placedOrderList!.subtotal}"), +// Text("Gst: ${orderItem.gst}%"), +// Text("GST Total: ${widget.placedOrderList!.gstTotal}"), +// Text("Total Amount: ${widget.placedOrderList!.grandTotal}"), +// ], +// ), +// ), +// ], +// ), +// ), +// ) +// : const SizedBox.shrink(); +// }, +// ), +// ), +// ], +// ), +// ), +// ), +// ), +// +// const SizedBox(height: 8), +// Card( +// child: SizedBox( +// height: Get.height * 0.35, // Adjust the height as per your requirement +// child: Padding( +// padding: EdgeInsets.all(Get.width * 0.02), +// child: Column( +// crossAxisAlignment: CrossAxisAlignment.start, +// children: [ +// // Add title here +// Padding( +// padding: const EdgeInsets.symmetric(vertical: 8.0), // Adjust padding if needed +// child: Text( +// "Order Itmes to processed", // Title text +// style: GoogleFonts.roboto( +// fontSize: Get.width * 0.05, // Adjust font size as needed +// fontWeight: FontWeight.bold, +// ), +// ), +// ), +// Expanded( +// child: ListView.builder( +// padding: EdgeInsets.zero, +// itemCount: widget.placedOrderList?.orderItems.length ?? 0, +// itemBuilder: (context, index) { +// final orderItem = widget.placedOrderList!.orderItems[index]; +// return orderItem != null +// ? Card( +// margin: const EdgeInsets.symmetric(vertical: 5.0), +// shape: RoundedRectangleBorder( +// borderRadius: BorderRadius.circular(10), +// ), +// child: Padding( +// padding: const EdgeInsets.all(8.0), +// child: Row( +// children: [ +// Image.asset( +// "assets/images/product.png", +// height: 50, +// width: 50, +// fit: BoxFit.cover, +// ), +// const SizedBox(width: 10), +// Expanded( +// child: Column( +// crossAxisAlignment: CrossAxisAlignment.end, +// children: [ +// Text( +// capitalizeFirstLetter(orderItem.name), +// style: GoogleFonts.roboto( +// fontSize: Get.width * 0.04, +// fontWeight: FontWeight.bold, +// ), +// ), +// Text( +// "Quantity: ${orderItem.remainingQuantity}", +// style: GoogleFonts.roboto( +// fontSize: Get.width * 0.03, +// ), +// ), +// Text("Price: ${orderItem.price}"), +// Text("Subtotal: ${widget.placedOrderList!.subtotal}"), +// Text("Gst: ${orderItem.gst}%"), +// Text("GST Total: ${widget.placedOrderList!.gstTotal}"), +// Text("Total Amount: ${widget.placedOrderList!.grandTotal}"), +// ], +// ), +// ), +// ], +// ), +// ), +// ) +// : const SizedBox.shrink(); +// }, +// ), +// ), +// ], +// ), +// ), +// ), +// ), +// +// const SizedBox(height: 8), +// SizedBox( +// height: Get.height* 0.19, +// child: Card( +// child: Column( +// children: [ +// SizedBox( +// width: Get.width, +// child: Padding( +// padding: +// const EdgeInsets.fromLTRB(8, 8, 8, 0), +// child: Text( +// "Customer Details", +// style: GoogleFonts.roboto( +// fontSize: Get.width * 0.05, +// fontWeight: FontWeight.w500, +// ), +// ), +// ), +// ), +// SizedBox( +// width: Get.width, +// //height: Get.height*0.09, +// child: Padding( +// padding: +// const EdgeInsets.fromLTRB(8, 8, 8, 0), +// child: Row( +// children: [ +// Text( +// "Name: ", +// style: GoogleFonts.roboto( +// fontSize: Get.width * 0.04, +// fontWeight: FontWeight.bold, +// ), +// ), +// Text("${" Roshan Garg"}",maxLines: 4, +// overflow:TextOverflow.ellipsis,) +// , ], +// ) +// ), +// ), +// SizedBox( +// width: Get.width, +// // height: Get.height*0.09, +// child: Padding( +// padding: +// const EdgeInsets.fromLTRB(8, 8, 8, 0), +// child: Row( +// children: [ +// Text( +// "Email: ", +// style: GoogleFonts.roboto( +// fontSize: Get.width * 0.04, +// fontWeight: FontWeight.bold, +// ), +// ), +// Text("${"roshangarg28@gmail.com"}",maxLines: 4, +// overflow:TextOverflow.ellipsis,) +// , ], +// ) +// ), +// ), +// SizedBox( +// width: Get.width, +// // height: Get.height*0.09, +// child: Padding( +// padding: +// const EdgeInsets.fromLTRB(8, 8, 8, 0), +// child: Row( +// children: [ +// Text( +// "Mobile Number: ", +// style: GoogleFonts.roboto( +// fontSize: Get.width * 0.04, +// fontWeight: FontWeight.bold, +// ), +// ), +// Text("${"8876785448"}",maxLines: 4, +// overflow:TextOverflow.ellipsis,) +// , ], +// ) +// ), +// ) +// +// ], +// ), +// ), +// ), +// const SizedBox(height: 8), +// Card( +// child: Column( +// children: [ +// SizedBox( +// width: Get.width, +// child: Padding( +// padding: +// const EdgeInsets.fromLTRB(8, 8, 8, 0), +// child: Text( +// "Billing Information", +// style: GoogleFonts.roboto( +// fontSize: Get.width * 0.05, +// fontWeight: FontWeight.w500, +// ), +// ), +// ), +// ), +// SizedBox( +// width: Get.width, +// height: Get.height*0.06, +// child: Padding( +// padding: +// const EdgeInsets.fromLTRB(8, 8, 8, 0), +// child: Wrap( +// crossAxisAlignment: WrapCrossAlignment.start, +// children: [ +// Text( +// "Address: ", +// style: GoogleFonts.roboto( +// fontSize: Get.width * 0.04, +// fontWeight: FontWeight.bold, +// ), +// ), +// Text("${widget.placedOrderList!.billTo}",maxLines: 4, +// overflow:TextOverflow.ellipsis,) +// ], +// ), +// ), +// ), +// +// ], +// ), +// ), +// const SizedBox(height: 8), +// // Card for displaying shipping information +// Card( +// child: Column( +// children: [ +// SizedBox( +// width: Get.width, +// child: Padding( +// padding: +// const EdgeInsets.fromLTRB(8, 8, 8, 0), +// child: Text( +// "Shipping Information", +// style: GoogleFonts.roboto( +// fontSize: Get.width * 0.05, +// fontWeight: FontWeight.w500, +// ), +// ), +// ), +// ), +// SizedBox( +// width: Get.width, +// height: Get.height*0.06, +// child: Padding( +// padding: +// const EdgeInsets.fromLTRB(8, 8, 8, 0), +// child: Wrap( +// crossAxisAlignment: WrapCrossAlignment.start, +// children: [ +// Text( +// "Address: ", +// style: GoogleFonts.roboto( +// fontSize: Get.width * 0.04, +// fontWeight: FontWeight.bold, +// ), +// ), +// Text("${widget.placedOrderList!.shipTo}",maxLines: 4, +// overflow:TextOverflow.ellipsis,) +// ], +// ), +// ), +// ), +// +// ], +// ), +// ), +// const SizedBox(height: 8), +// Card( +// child: Column( +// children: [ +// SizedBox( +// width: Get.width, +// height: Get.height*0.05, +// child: Padding( +// padding: +// const EdgeInsets.fromLTRB(8, 8, 8, 0), +// child: Row( +// children: [ +// Text( +// "Payment Mode : ", +// style: GoogleFonts.roboto( +// fontSize: Get.width * 0.04, +// fontWeight: FontWeight.w500, +// ), +// ), +// Text(capitalizeFirstLetter(widget.placedOrderList!.paymentMode)), +// // Text("${widget.placedOrderList!.paymentMode}",maxLines: 4, +// // overflow:TextOverflow.ellipsis,) +// ], +// ), +// ), +// ), +// +// +// ], +// ), +// ), +// const SizedBox(height: 8), +// Card( +// child: Column( +// children: [ +// SizedBox( +// width: Get.width, +// height: Get.height*0.05, +// child: Padding( +// padding: +// const EdgeInsets.fromLTRB(8, 8, 8, 0), +// child: Row( +// children: [ +// Text( +// "Order Status :", +// style: GoogleFonts.roboto( +// fontSize: Get.width * 0.04, +// fontWeight: FontWeight.w500, +// ), +// ), +// SizedBox(width: Get.width*0.01,), +// //Text(capitalizeFirstLetter(widget.placedOrderList!.status)), +// Text("${widget.placedOrderList!.status}",maxLines: 4, +// overflow:TextOverflow.ellipsis,) +// ], +// ), +// ), +// ), +// +// +// ], +// ), +// ), +// const SizedBox(height: 8), +// SizedBox( +// height: Get.height * 0.05, +// child: Row( +// crossAxisAlignment: CrossAxisAlignment.center, +// children: [ +// const Text( +// "CancelledReason: ", +// style: TextStyle(fontWeight: FontWeight.bold,), +// ), +// SizedBox(width: 10), // Space between label and dropdown +// Text("${widget.placedOrderList!.orderCancelledReason}",maxLines: 4,style: TextStyle(color: Colors.red,fontSize: 15), +// overflow:TextOverflow.ellipsis,) +// ], +// ), +// ), +// // SizedBox( +// // width: Get.width * 0.4, +// // child: Padding( +// // padding: const EdgeInsets.all(8.0), +// // child: ElevatedButton( +// // onPressed: (){}, +// // // Get.to(() => +// // // RdOrderDetailScreen( +// // // placedOrderList: uniqueOrders[index])), // Navigate to detail screen +// // style: ElevatedButton.styleFrom( +// // foregroundColor: Colors.white, +// // backgroundColor: const Color(0xFF004791), +// // shape: RoundedRectangleBorder( +// // borderRadius: BorderRadius.circular(10)), +// // ), +// // child: Text("Update Status", style: GoogleFonts.roboto(fontSize: 14, fontWeight: FontWeight.w400)), +// // ), +// // ), +// // ) +// +// ], +// ), +// ), +// ), +// SizedBox(height: Get.height * 0.04), +// +// ], +// ), +// ), +// ), +// ], +// ), +// ); +// } +// } +// +// + + + import 'package:auto_size_text/auto_size_text.dart'; import 'package:cheminova/controller/get_order_placed_controller.dart'; import 'package:cheminova/controller/get_rd_cancle_controller.dart'; +import 'package:cheminova/controller/get_rd_pending_controller.dart'; +import 'package:cheminova/controller/rd_get_order_controller.dart'; import 'package:cheminova/models/get_rd_cancelled_model.dart'; +import 'package:cheminova/models/get_rd_pennding_model.dart'; import 'package:cheminova/models/oder_place_model.dart'; import 'package:cheminova/models/order_item_model.dart'; import 'package:cheminova/models/place_order_list_model.dart'; import 'package:cheminova/models/rd_get_order_model.dart'; +import 'package:cheminova/models/single_get_order_model.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/rd_cancelled_screen.dart'; +import 'package:cheminova/screens/rd%20orders/rd_processing_screen.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; @@ -16,28 +861,41 @@ import 'package:intl/intl.dart'; import 'package:shared_preferences/shared_preferences.dart'; import '../../controller/cart_controller.dart'; +import '../../controller/get_single_invoice_controller.dart'; +import '../../controller/rd_processing_order_controller.dart'; +import '../../models/get_invoice_model.dart'; import '../../models/product_model1.dart'; +import '../../models/rd_order_item_model.dart'; +import '../../models/rd_placed_order_model.dart'; +import '../../utils/show_snackbar.dart'; -class RdCancelledDetailScreen extends StatefulWidget { +class RdOrderCancelledScreenDetailScreen extends StatefulWidget { //final Product? productModel; // PlacedOrderList and PlacedOrderModel are optional parameters passed to this screen - GetRdCancelledModel? placedOrderList; + final SingleGetOrderModel? placedOrderList; + // GetRdPendingModel? productpendingModel; + final String orderId; +// GetInvoiceModel? placeInvoiceList; + // PlacedOrderModel? placedOrderModel; // Constructor for initializing the screen with placed order details - RdCancelledDetailScreen({super.key,this.placedOrderList}); + RdOrderCancelledScreenDetailScreen({super.key,this.placedOrderList,required this.orderId}); @override - State createState() => - _RdCancelledDetailScreenState(); + State createState() => + _RdOrderCancelledScreenDetailScreenState(); } -class _RdCancelledDetailScreenState - extends State { +class _RdOrderCancelledScreenDetailScreenState + extends State { // Controllers for managing cart and placed orders final CartController _cartController = Get.put(CartController()); - final GetPlacedOrderController _getPlacedOrderController = Get.put(GetPlacedOrderController()); final GetRDCancleController _getRDCancleController = Get.put(GetRDCancleController()); + final GetSingleInvoiceController _getSingleInvoiceController = Get.put(GetSingleInvoiceController()); + final GetProductRDController _getProductRDController = Get.put(GetProductRDController()); + final RDOrderPlacedController controller = Get.put(RDOrderPlacedController()); + final List statusOptions = [ "new", "pending", @@ -46,11 +904,11 @@ class _RdCancelledDetailScreenState "cancelled", "delivered", ]; - String selectedStatus = "All"; + String selectedStatus = "pending"; String _groupValue = "cheque"; // Function to format date from the API to a more readable format - + List _statusList = ["pending", "processing", "partial processing", "cancelled"]; String formatDate(String apiDate) { // Parse the API date string into a DateTime object DateTime parsedDate = DateTime.parse(apiDate).toLocal(); // Convert to local time @@ -88,37 +946,89 @@ class _RdCancelledDetailScreenState }); } // Function to collect unique order IDs and corresponding order details - // Future adduni()async { - // final Set uniqueOrderIds = {}; - // final List uniqueOrders = []; - // // Loop through placed orders and add unique orders to the list - // for (var order in _getPlacedOrderController.placedOrders) { - // if (uniqueOrderIds.add(order.uniqueId)) { - // uniqueOrders.add(order); - // } - // } - // final order = uniqueOrders[0]; - // - // // Combine product names, categories, and quantities into strings - // final productNames = order.orderItem - // .map((item) => (item.name)) - // .join(', '); - // final categotyName = order.orderItem - // .map((item) => (item.categoryName)) - // .join(', '); - // final quantity = order.orderItem - // .map((item) => (item.quantity)) - // .join(', '); - // } + Future adduni()async { + final Set uniqueOrderIds = {}; + final List uniqueOrders = []; + // Loop through placed orders and add unique orders to the list + for (var order in _getRDCancleController.productRDList) { + if (uniqueOrderIds.add(order.uniqueId)) { + uniqueOrders.add(order); + } + } + final order = uniqueOrders[0]; + + // Combine product names, categories, and quantities into strings + final productNames = order.orderItems + .map((item) => (item.name)) + .join(', '); + final categotyName = order.orderItems + .map((item) => (item.categoryName)) + .join(', '); + final quantity = order.orderItems + .map((item) => (item.quantity)) + .join(', '); + } + + + + + @override void initState() { // TODO: implement initState super.initState(); + //getOrder1(); selectedStatus= widget.placedOrderList?.status ?? 'new'; } + + // Future getOrder1() async { + // await _getSingleInvoiceController.fetchInvoice(widget.placedOrderList!.id); + // if (_getSingleInvoiceController.invoice.isEmpty) { + // print("No orders found."); + // } else { + // print(" New Orders fetched successfully"); + // } + // } + + + + Color _getCourierStatusColor(String status) { + switch (status.toLowerCase()) { + case 'processing': + return Colors.orange; + case 'dispatched': + return Colors.lightBlue; + case 'delivered': + return Colors.green; + default: + return Colors.grey; // Default color for unknown statuses + } + } @override Widget build(BuildContext context) { + if (widget.placedOrderList == null) { + return Center(child: Text('No order details available')); + } + +// Safely get the order and invoice list + final order = widget.placedOrderList!; + final invoices = order.invoices; + +// Check if the invoices list contains at least 4 items + List? invoiceIds; + if (invoices.isNotEmpty) { + // Ensure there are at least 4 invoices + if (invoices.length >= 4) { + // Get the ID of the 4th invoice (index 3) + invoiceIds = [invoices[3].invoiceId!]; // Assuming invoiceId is a String + } else { + invoiceIds = []; // Fallback if not enough invoices + } + } else { + invoiceIds = []; // Fallback if no invoices available + } + //int remainingQuantity = (widget.placedOrderList!.orderItem![0].quantity)! -(widget.placedOrderList!.orderItem![0].remainingQuantity!.toInt()); return Scaffold( extendBodyBehindAppBar: true, appBar: AppBar( @@ -145,7 +1055,7 @@ class _RdCancelledDetailScreenState ), ], title: const Text( - "RD Cancelled Order Detail", + "RD Cancelled Order Details", ), ), body: Stack( @@ -176,14 +1086,15 @@ class _RdCancelledDetailScreenState child: Column( mainAxisSize: MainAxisSize.min, children: [ + Card( - child: Column( + child: + Column( children: [ SizedBox( width: Get.width, child: Padding( - padding: - const EdgeInsets.fromLTRB(8, 8, 8, 0), + padding: const EdgeInsets.fromLTRB(8, 8, 8, 0), child: Text( "Invoices", style: GoogleFonts.roboto( @@ -193,186 +1104,152 @@ class _RdCancelledDetailScreenState ), ), ), - SizedBox( - width: Get.width, - child: Padding( - padding: - const EdgeInsets.fromLTRB(8, 8, 8, 0), - child: Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - Text( - "Invoice ID:", - style: GoogleFonts.roboto( - fontSize: Get.width * 0.04, - fontWeight: FontWeight.bold, - ), - ), - Text(widget.placedOrderList!.uniqueId), - // Text(widget.placedOrderList!.uniqueId), - ], - ), - ), - ), - SizedBox( - width: Get.width, - child: Padding( - padding: const EdgeInsets.fromLTRB(8, 8, 8, 0), - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Text( - "Items: ", - style: GoogleFonts.roboto( - fontSize: Get.width * 0.04, - fontWeight: FontWeight.bold, - ), - ), - SizedBox(height: 10), // Add spacing between the title and the list of items - Column( - children: widget.placedOrderList!.orderItems.map((item) { - return Padding( - padding: const EdgeInsets.symmetric(vertical: 4.0), // Add some spacing between items - child: Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - Expanded( - child: Text( - "${item.name.toString()} (${item.sku.toString()})", - style: GoogleFonts.roboto( - fontSize: Get.width * 0.03, + // Displaying each invoice in a separate card + if (widget.placedOrderList!.invoices.isNotEmpty) + ...widget.placedOrderList!.invoices.map((invoice) { + return Card( + margin: const EdgeInsets.symmetric(vertical: 8, horizontal: 8), + child: Padding( + padding: const EdgeInsets.all(8.0), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + // Invoice ID + Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Text( + "Invoice ID:", + style: GoogleFonts.roboto( + fontSize: Get.width * 0.04, + fontWeight: FontWeight.bold, + ), + ), + Text(invoice.invoiceId.toString()), + ], + ), + const SizedBox(height: 10), // Add spacing + + // Items for this invoice + Text( + "Items: ", + style: GoogleFonts.roboto( + fontSize: Get.width * 0.04, + fontWeight: FontWeight.bold, + ), + ), + const SizedBox(height: 10), // Add spacing between title and items + + // List of items in this invoice + Column( + children: invoice.items!.map((item) { + return Padding( + padding: const EdgeInsets.symmetric(vertical: 4.0), + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Expanded( + child: Text( + "${item.name.toString()} (${item.sku.toString()})", + style: GoogleFonts.roboto( + fontSize: Get.width * 0.03, + ), + overflow: TextOverflow.ellipsis, + ), ), - overflow: TextOverflow.ellipsis, // Handle long text + Text("x ${item.processQuantity.toString()}"), + ], + ), + ); + }).toList(), + ), + + const SizedBox(height: 10), // Add spacing between sections + + // Sub Total + Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Text( + "Sub Total:", + style: GoogleFonts.roboto( + fontSize: Get.width * 0.04, + fontWeight: FontWeight.bold, + ), + ), + Text("₹ ${invoice.subtotal}"), + ], + ), + + // GST + Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Text( + "GST:", + style: GoogleFonts.roboto( + fontSize: Get.width * 0.04, + fontWeight: FontWeight.bold, + ), + ), + Text("₹ ${invoice.gstTotal}"), + ], + ), + + // Invoice Amount + Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Text( + "Invoice Amount:", + style: GoogleFonts.roboto( + fontSize: Get.width * 0.04, + fontWeight: FontWeight.bold, + ), + ), + Text("₹ ${invoice.invoiceAmount}"), + ], + ), + + // Courier Status + Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Text( + "Courier Status:", + style: GoogleFonts.roboto( + fontSize: Get.width * 0.04, + fontWeight: FontWeight.bold, + ), + ), + ElevatedButton( + onPressed: () {}, + style: ElevatedButton.styleFrom( + foregroundColor: Colors.white, + backgroundColor: _getCourierStatusColor(invoice.courierStatus.toString()), + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(10), ), ), - Text("x ${item.remainingQuantity.toString()}"), - ], - ), - ); - }).toList(), + child: Text( + capitalizeFirstLetter(invoice.courierStatus.toString()), + ), + ), + ], + ), + ], ), - ], - ), - ), - ), - SizedBox( - width: Get.width, - child: Padding( - padding: - const EdgeInsets.fromLTRB(8, 8, 8, 0), - child: Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - Text( - "Sub Total : ", - style: GoogleFonts.roboto( - fontSize: Get.width * 0.04, - fontWeight: FontWeight.bold, - ), - ), - Text("₹ ${widget.placedOrderList!.subtotal}"), - ], - ), - ), - ), - - // SizedBox( - // width: Get.width, - // child: Padding( - // padding: - // const EdgeInsets.fromLTRB(8, 8, 8, 0), - // child: Row( - // mainAxisAlignment: MainAxisAlignment.spaceBetween, - // children: [ - // Text( - // "Gst %: ", - // style: GoogleFonts.roboto( - // fontSize: Get.width * 0.04, - // fontWeight: FontWeight.bold, - // ), - // ), - // Text(" ${widget.placedOrderList!.orderItem[0].gst}%"), - // ], - // ), - // ), - // ), - SizedBox( - width: Get.width, - child: Padding( - padding: - const EdgeInsets.fromLTRB(8, 8, 8, 0), - child: Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - Text( - "GST : ", - style: GoogleFonts.roboto( - fontSize: Get.width * 0.04, - fontWeight: FontWeight.bold, - ), - ), - Text("₹ ${widget.placedOrderList!.gstTotal}"), - ], - ), - ), - ), - SizedBox( - width: Get.width, - child: Padding( - padding: - const EdgeInsets.fromLTRB(8, 8, 8, 0), - child: Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - Text( - "Invoice Amount: ", - style: GoogleFonts.roboto( - fontSize: Get.width * 0.04, - fontWeight: FontWeight.bold, - ), - ), - Text("₹ ${widget.placedOrderList!.grandTotal}"), - ], - ), - ), - ), - SizedBox( - width: Get.width, - child: Padding( - padding: - const EdgeInsets.fromLTRB(8, 8, 8, 0), - child: Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - Text( - "Courier Status : ", - style: GoogleFonts.roboto( - fontSize: Get.width * 0.04, - fontWeight: FontWeight.bold, - ), - ), - ElevatedButton( - onPressed: (){}, - // Get.to(() => - // RdOrderDetailScreen( - // placedOrderList: uniqueOrders[index])), // Navigate to detail screen - style: ElevatedButton.styleFrom( - foregroundColor: Colors.white, - backgroundColor: Colors.orange, - shape: RoundedRectangleBorder( - borderRadius: BorderRadius.circular(10)), - ), - child: Text(widget.placedOrderList!.status, style: GoogleFonts.roboto(fontSize: 14, fontWeight: FontWeight.w400)), - ), - //Text("₹ ${widget.placedOrderList!.gstTotal}"), - ], - ), - ), - ), + ), + ); + }).toList(), ], ), + ), + const SizedBox(height: 8), + + const SizedBox(height: 8), Card( child: SizedBox( @@ -396,9 +1273,12 @@ class _RdCancelledDetailScreenState Expanded( child: ListView.builder( padding: EdgeInsets.zero, - itemCount: widget.placedOrderList?.orderItems.length ?? 0, + itemCount: order.orderItem!.length ?? 0, itemBuilder: (context, index) { - final orderItem = widget.placedOrderList!.orderItems[index]; + final orderItem =order.orderItem![index]; + final subTotal = orderItem.price * orderItem.quantity!.toInt(); + final GstTotalAmount = (orderItem.price * orderItem.quantity!.toInt()) *(orderItem.gst/100 ); + final grandTotal = subTotal + GstTotalAmount; return orderItem != null ? Card( margin: const EdgeInsets.symmetric(vertical: 5.0), @@ -418,10 +1298,11 @@ class _RdCancelledDetailScreenState const SizedBox(width: 10), Expanded( child: Column( + crossAxisAlignment: CrossAxisAlignment.end, children: [ Text( - capitalizeFirstLetter(orderItem.name), + capitalizeFirstLetter(orderItem.name.toString()), style: GoogleFonts.roboto( fontSize: Get.width * 0.04, fontWeight: FontWeight.bold, @@ -433,11 +1314,12 @@ class _RdCancelledDetailScreenState fontSize: Get.width * 0.03, ), ), + Text("Price: ${orderItem.price}"), - Text("Subtotal: ${widget.placedOrderList!.subtotal}"), - Text("Gst: ${orderItem.gst}%"), - Text("GST Total: ${widget.placedOrderList!.gstTotal}"), - Text("Total Amount: ${widget.placedOrderList!.grandTotal}"), + Text("Subtotal: ${subTotal}"), + Text("GSt: ${orderItem.gst}%"), + Text("GST Amount (₹): ${GstTotalAmount}"), + Text("Total Amount (₹): ${grandTotal}"), ], ), ), @@ -468,7 +1350,7 @@ class _RdCancelledDetailScreenState Padding( padding: const EdgeInsets.symmetric(vertical: 8.0), // Adjust padding if needed child: Text( - "Order Itmes to processed", // Title text + "Order Items to be processed", // Title text style: GoogleFonts.roboto( fontSize: Get.width * 0.05, // Adjust font size as needed fontWeight: FontWeight.bold, @@ -478,11 +1360,23 @@ class _RdCancelledDetailScreenState Expanded( child: ListView.builder( padding: EdgeInsets.zero, - itemCount: widget.placedOrderList?.orderItems.length ?? 0, + itemCount: order.orderItem + ?.where((item) => item.remainingQuantity! > 0) + .length ?? 0, itemBuilder: (context, index) { - final orderItem = widget.placedOrderList!.orderItems[index]; - return orderItem != null - ? Card( + + + // Filter items with non-zero quantities + final filteredItems =order!.orderItem! + .where((item) => item.remainingQuantity! > 0) + .toList(); + + final orderItem = filteredItems[index]; + final subTotalProcesssItem = orderItem.price! * orderItem.remainingQuantity!.toInt(); + final GstTotalAmounProcessItem = (orderItem.price! * orderItem.remainingQuantity!.toInt()) *(orderItem.gst!/100 ); + final grandTotalProcessItem = subTotalProcesssItem + GstTotalAmounProcessItem; + + return Card( margin: const EdgeInsets.symmetric(vertical: 5.0), shape: RoundedRectangleBorder( borderRadius: BorderRadius.circular(10), @@ -503,31 +1397,25 @@ class _RdCancelledDetailScreenState crossAxisAlignment: CrossAxisAlignment.end, children: [ Text( - capitalizeFirstLetter(orderItem.name), + capitalizeFirstLetter(orderItem.name.toString()), style: GoogleFonts.roboto( fontSize: Get.width * 0.04, fontWeight: FontWeight.bold, ), ), - Text( - "Quantity: ${orderItem.remainingQuantity}", - style: GoogleFonts.roboto( - fontSize: Get.width * 0.03, - ), - ), + Text("Quantity: ${orderItem.remainingQuantity}"), Text("Price: ${orderItem.price}"), - Text("Subtotal: ${widget.placedOrderList!.subtotal}"), + Text("Subtotal: ${subTotalProcesssItem}"), Text("Gst: ${orderItem.gst}%"), - Text("GST Total: ${widget.placedOrderList!.gstTotal}"), - Text("Total Amount: ${widget.placedOrderList!.grandTotal}"), + Text("GST Total: ${GstTotalAmounProcessItem}"), + Text("Total Amount: ${grandTotalProcessItem}"), ], ), ), ], ), ), - ) - : const SizedBox.shrink(); + ); }, ), ), @@ -537,183 +1425,19 @@ class _RdCancelledDetailScreenState ), ), + const SizedBox(height: 8), SizedBox( height: Get.height* 0.19, - child: Card( - child: Column( - children: [ - SizedBox( - width: Get.width, - child: Padding( - padding: - const EdgeInsets.fromLTRB(8, 8, 8, 0), - child: Text( - "Customer Details", - style: GoogleFonts.roboto( - fontSize: Get.width * 0.05, - fontWeight: FontWeight.w500, - ), - ), - ), - ), - SizedBox( - width: Get.width, - //height: Get.height*0.09, - child: Padding( - padding: - const EdgeInsets.fromLTRB(8, 8, 8, 0), - child: Row( - children: [ - Text( - "Name: ", - style: GoogleFonts.roboto( - fontSize: Get.width * 0.04, - fontWeight: FontWeight.bold, - ), - ), - Text("${" Roshan Garg"}",maxLines: 4, - overflow:TextOverflow.ellipsis,) - , ], - ) - ), - ), - SizedBox( - width: Get.width, - // height: Get.height*0.09, - child: Padding( - padding: - const EdgeInsets.fromLTRB(8, 8, 8, 0), - child: Row( - children: [ - Text( - "Email: ", - style: GoogleFonts.roboto( - fontSize: Get.width * 0.04, - fontWeight: FontWeight.bold, - ), - ), - Text("${"roshangarg28@gmail.com"}",maxLines: 4, - overflow:TextOverflow.ellipsis,) - , ], - ) - ), - ), - SizedBox( - width: Get.width, - // height: Get.height*0.09, - child: Padding( - padding: - const EdgeInsets.fromLTRB(8, 8, 8, 0), - child: Row( - children: [ - Text( - "Mobile Number: ", - style: GoogleFonts.roboto( - fontSize: Get.width * 0.04, - fontWeight: FontWeight.bold, - ), - ), - Text("${"8876785448"}",maxLines: 4, - overflow:TextOverflow.ellipsis,) - , ], - ) - ), - ) + child:_buildCustomerDetails(), - ], - ), - ), ), const SizedBox(height: 8), - Card( - child: Column( - children: [ - SizedBox( - width: Get.width, - child: Padding( - padding: - const EdgeInsets.fromLTRB(8, 8, 8, 0), - child: Text( - "Billing Information", - style: GoogleFonts.roboto( - fontSize: Get.width * 0.05, - fontWeight: FontWeight.w500, - ), - ), - ), - ), - SizedBox( - width: Get.width, - height: Get.height*0.06, - child: Padding( - padding: - const EdgeInsets.fromLTRB(8, 8, 8, 0), - child: Wrap( - crossAxisAlignment: WrapCrossAlignment.start, - children: [ - Text( - "Address: ", - style: GoogleFonts.roboto( - fontSize: Get.width * 0.04, - fontWeight: FontWeight.bold, - ), - ), - Text("${widget.placedOrderList!.billTo}",maxLines: 4, - overflow:TextOverflow.ellipsis,) - ], - ), - ), - ), + _buildBillingInfo(), - ], - ), - ), const SizedBox(height: 8), - // Card for displaying shipping information - Card( - child: Column( - children: [ - SizedBox( - width: Get.width, - child: Padding( - padding: - const EdgeInsets.fromLTRB(8, 8, 8, 0), - child: Text( - "Shipping Information", - style: GoogleFonts.roboto( - fontSize: Get.width * 0.05, - fontWeight: FontWeight.w500, - ), - ), - ), - ), - SizedBox( - width: Get.width, - height: Get.height*0.06, - child: Padding( - padding: - const EdgeInsets.fromLTRB(8, 8, 8, 0), - child: Wrap( - crossAxisAlignment: WrapCrossAlignment.start, - children: [ - Text( - "Address: ", - style: GoogleFonts.roboto( - fontSize: Get.width * 0.04, - fontWeight: FontWeight.bold, - ), - ), - Text("${widget.placedOrderList!.shipTo}",maxLines: 4, - overflow:TextOverflow.ellipsis,) - ], - ), - ), - ), + _buildShippingInfo(), - ], - ), - ), const SizedBox(height: 8), Card( child: Column( @@ -733,7 +1457,7 @@ class _RdCancelledDetailScreenState fontWeight: FontWeight.w500, ), ), - Text(capitalizeFirstLetter(widget.placedOrderList!.paymentMode)), + Text(capitalizeFirstLetter(widget.placedOrderList!.paymentMode.toString())), // Text("${widget.placedOrderList!.paymentMode}",maxLines: 4, // overflow:TextOverflow.ellipsis,) ], @@ -766,7 +1490,7 @@ class _RdCancelledDetailScreenState ), SizedBox(width: Get.width*0.01,), //Text(capitalizeFirstLetter(widget.placedOrderList!.status)), - Text("${widget.placedOrderList!.status}",maxLines: 4, + Text(capitalizeFirstLetter(order!.status.toString()),maxLines: 4, overflow:TextOverflow.ellipsis,) ], ), @@ -778,7 +1502,49 @@ class _RdCancelledDetailScreenState ), ), const SizedBox(height: 8), - SizedBox( + // SizedBox( + // height: Get.height * 0.05, + // child: Row( + // crossAxisAlignment: CrossAxisAlignment.center, + // children: [ + // const Text( + // "Status: ", + // style: TextStyle(fontWeight: FontWeight.bold), + // ), + // SizedBox(width: 10), // Space between label and dropdown + // Expanded( + // child: DropdownButtonFormField( + // value: selectedStatus, + // decoration: InputDecoration( + // filled: true, + // fillColor: Colors.white, // White background + // contentPadding: EdgeInsets.symmetric( + // vertical: 10, horizontal: 12), + // border: OutlineInputBorder( + // borderRadius: BorderRadius.circular(10), + // borderSide: BorderSide( + // color: Colors.grey, + // width: 1, + // ), + // ), + // ), + // items: _statusList.map((String status) { + // return DropdownMenuItem( + // value: status, + // child: Text(capitalizeFirstLetter(status)), + // ); + // }).toList(), + // onChanged: (newValue) { + // setState(() { + // selectedStatus = newValue!; + // }); + // }, + // ), + // ), + // ], + // ), + // ), + SizedBox( height: Get.height * 0.05, child: Row( crossAxisAlignment: CrossAxisAlignment.center, @@ -788,30 +1554,11 @@ class _RdCancelledDetailScreenState style: TextStyle(fontWeight: FontWeight.bold,), ), SizedBox(width: 10), // Space between label and dropdown - Text("${widget.placedOrderList!.orderCancelledReason}",maxLines: 4,style: TextStyle(color: Colors.red,fontSize: 15), + Text("${_getRDCancleController.productRDList[0].orderCancelledReason}",maxLines: 4,style: TextStyle(color: Colors.red,fontSize: 15), overflow:TextOverflow.ellipsis,) ], ), ), - // SizedBox( - // width: Get.width * 0.4, - // child: Padding( - // padding: const EdgeInsets.all(8.0), - // child: ElevatedButton( - // onPressed: (){}, - // // Get.to(() => - // // RdOrderDetailScreen( - // // placedOrderList: uniqueOrders[index])), // Navigate to detail screen - // style: ElevatedButton.styleFrom( - // foregroundColor: Colors.white, - // backgroundColor: const Color(0xFF004791), - // shape: RoundedRectangleBorder( - // borderRadius: BorderRadius.circular(10)), - // ), - // child: Text("Update Status", style: GoogleFonts.roboto(fontSize: 14, fontWeight: FontWeight.w400)), - // ), - // ), - // ) ], ), @@ -827,4 +1574,146 @@ class _RdCancelledDetailScreenState ), ); } + + + + 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 _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 _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 Padding( + padding: const EdgeInsets.fromLTRB(8, 2, 8, 2), + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Text( + label, + style: GoogleFonts.roboto(fontSize: fontSize,fontWeight: FontWeight.bold), + ), + Text( + value, + style: GoogleFonts.roboto(fontSize: fontSize), + ), + ], + ), + ); +} + +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), + ), + ), + ); +} + + +class simple extends State { + @override + Widget build(BuildContext context) { + return SizedBox( + width: Get.width, + child: Padding( + padding: const EdgeInsets.fromLTRB(8, 8, 8, 0), + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Text( + "Courier Status : ", + style: GoogleFonts.roboto( + fontSize: Get.width * 0.04, + fontWeight: FontWeight.bold, + ), + ), + ElevatedButton( + onPressed: () {}, + style: ElevatedButton.styleFrom( + foregroundColor: Colors.white, + backgroundColor: _getCourierStatusColor(widget.placedOrderList!.invoices[0]!.courierStatus.toString()), // Call the method here + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(10), + ), + ), + child: Text(widget.placedOrderList!.invoices[0]!.courierStatus.toString()), + ), + ], + ), + ), + ); + } + + // Method to get the color based on the status + Color _getCourierStatusColor(String status) { + switch (status.toLowerCase()) { + case 'processing': + return Colors.orange; // Orange for processing + case 'dispatched': + return Colors.lightBlue; // Light blue for dispatched + case 'delivered': + return Colors.green; // Green for delivered + default: + return Colors.grey; // Default color if status doesn't match + } + } } diff --git a/lib/screens/rd orders/rd_cancelled_screen.dart b/lib/screens/rd orders/rd_cancelled_screen.dart index fc8fa6d..257cb3e 100644 --- a/lib/screens/rd orders/rd_cancelled_screen.dart +++ b/lib/screens/rd orders/rd_cancelled_screen.dart @@ -1,13 +1,16 @@ +import 'package:cheminova/controller/get_rd_cancle_controller.dart'; +import 'package:cheminova/controller/get_rd_pending_controller.dart'; import 'package:cheminova/controller/rd_get_order_controller.dart'; +import 'package:cheminova/controller/rd_processing_invoice_controller.dart'; import 'package:cheminova/models/get_rd_cancelled_model.dart'; +import 'package:cheminova/models/get_rd_pennding_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/rd_cancelled_details_screen.dart'; -import 'package:cheminova/screens/rd%20orders/rd_dispatched_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_processing_details.dart'; import 'package:cheminova/widgets/input_field.dart'; import 'package:cheminova/widgets/my_drawer.dart'; import 'package:flutter/material.dart'; @@ -15,12 +18,15 @@ 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/get_rd_cancle_controller.dart'; +import '../../controller/get_single_invoice_Service.dart'; +import '../../controller/get_single_invoice_controller.dart'; +import '../../controller/rd_get_single_service.dart'; import '../order_management/order_management_detail_screen.dart'; class RdCancelledScreen extends StatefulWidget { - final PlacedOrdersResponse? getrdProduct; + final GetRdCancelledModel? getrdProduct; RdCancelledScreen({super.key, this.getrdProduct}); @@ -37,7 +43,11 @@ class _RdCancelledScreenState extends State { "cancelled", "delivered",]; int _selectedIndex = 0; - final GetRDCancleController _getRdProductController = Get.put(GetRDCancleController()); + final GetRDCancleController _getRDCancleController = Get.put(GetRDCancleController()); + // final GetSingleInvoiceController _getSingleInvoiceController = Get.put(GetSingleInvoiceController()); + // final GetRDProcessingInvoiceController _getRDProcessingInvoiceController = Get.put(GetRDProcessingInvoiceController()); + // // final GetProductRDController _getRdProductController = + // // Get.put(GetProductRDController()); final GlobalKey _refreshIndicatorKey = GlobalKey(); @override @@ -49,11 +59,12 @@ class _RdCancelledScreenState extends State { Future _onRefresh() async { await getOrder1(); await Future.delayed(Duration(seconds: 1)); + } Future getOrder1() async { - await _getRdProductController.getRDCancleProduct(); - if (_getRdProductController.productRDList.isEmpty) { + await _getRDCancleController.getRDCancleProduct(); + if (_getRDCancleController.productRDList.isEmpty) { print("No orders found."); } else { print("Orders fetched successfully"); @@ -70,11 +81,71 @@ class _RdCancelledScreenState extends State { 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); + String formattedDate = DateFormat('EEE MMM dd yyyy hh:mm a').format(parsedDate); return formattedDate; // Return the formatted date string } + + void onOrderTap(int index) async { + try { + // Fetch orders and ensure you wait for it to complete + await _getRDCancleController.getRDCancleProduct(); + + // Log the count of fetched orders + print('Fetched orders count: ${_getRDCancleController.productRDList.length}'); + + // Check if the productRDList is populated + if (_getRDCancleController.productRDList.isNotEmpty) { + // Ensure the index is valid + if (index >= 0 && index < _getRDCancleController.productRDList.length) { + // Get the order ID from the list based on the index + final orderId = _getRDCancleController.productRDList[index].id; + final invoiceId = _getRDCancleController.productRDList[index].invoices[0]; + + // 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 + final SingleGetOrderModel? 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(() => RdOrderCancelledScreenDetailScreen( + placedOrderList: singleOrder, // Pass the single order instance + 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 Widget build(BuildContext context) { return Scaffold( @@ -128,6 +199,7 @@ class _RdCancelledScreenState extends State { controller: _searchController, ), SizedBox(height: Get.height * 0.035), + SizedBox(height: Get.height * 0.035), Card( margin: const EdgeInsets.symmetric(horizontal: 18), shape: RoundedRectangleBorder( @@ -140,63 +212,11 @@ class _RdCancelledScreenState extends State { child: Column( mainAxisSize: MainAxisSize.min, children: [ - // SizedBox( - // height: Get.height * 0.05, - // child: ListView.builder( - // shrinkWrap: true, - // scrollDirection: Axis.horizontal, - // itemCount: _filterList.length, - // itemBuilder: (context, index) => Padding( - // padding: const EdgeInsets.symmetric(horizontal: 4), - // child: GestureDetector( - // onTap: () { - // setState(() { - // _selectedIndex = index; // Update selected index - // }); - // // Navigate to different screens based on selected tab - // switch (_filterList[index]) { - // case "new": - // // Get.to(YourScreen1()); // Navigate to "new" orders screen - // break; - // case "pending": - // // Get.to(YourScreen2()); // Navigate to "pending" orders screen - // break; - // case "processing": - // // Get.to(YourScreen3()); // Navigate to "processing" orders screen - // break; - // // Add more cases for other statuses - // case "dispatched": - // // Get.to(YourScreen4()); // Navigate to dispatched orders - // break; - // case "cancelled": - // // Get.to(YourScreen5()); // Navigate to cancelled orders - // break; - // case "delivered": - // //Get.to(YourScreen6()); // Navigate to delivered orders - // break; - // default: - // // Get.to(YourScreen1()); // Default screen - // } - // }, - // child: Chip( - // label: Text(capitalizeFirstLetter( _filterList[index]) - // , - // style: GoogleFonts.roboto( - // fontSize: 14, - // fontWeight: FontWeight.w500, - // color: _selectedIndex == index ? Colors.white : Colors.black, // Change color when selected - // ), - // ), - // backgroundColor: _selectedIndex == index ? Colors.blue : Colors.grey[300], // Change color when selected - // ), - // ), - // ), - // ), - // ), + SizedBox( height: Get.height * 0.6, child: Obx(() { - if (_getRdProductController.productRDList.isEmpty) { + if (_getRDCancleController.productRDList.isEmpty) { return Center( child: Text( 'No Orders Found', @@ -208,7 +228,7 @@ class _RdCancelledScreenState extends State { final Set uniqueOrderIds = {}; final List uniqueOrders = []; - for (var order in _getRdProductController.productRDList) { + for (var order in _getRDCancleController.productRDList) { if (uniqueOrderIds.add(order.id)) { uniqueOrders.add(order); } @@ -282,7 +302,16 @@ class _RdCancelledScreenState extends State { ], ), ), - + Padding( + padding: const EdgeInsets.fromLTRB(16, 8, 8, 0), + child: Row( + mainAxisAlignment: MainAxisAlignment.start, + children: [ + Text("Order Value: ", style: GoogleFonts.roboto(fontSize: 14, fontWeight: FontWeight.bold)), + Text("${order.grandTotal}") + ], + ), + ), Padding( padding: const EdgeInsets.fromLTRB(16, 8, 8, 0), @@ -310,10 +339,12 @@ class _RdCancelledScreenState extends State { child: Padding( padding: const EdgeInsets.all(8.0), child: ElevatedButton( - onPressed: ()=> - Get.to(() => - RdCancelledDetailScreen( - placedOrderList: uniqueOrders[index])), // Navigate to detail screen + onPressed: (){ + onOrderTap(index); + }, + // Get.to(() => + // RdOrderPendingScreenDetailScreen( + // placedOrderList: uniqueOrders[index])), // Navigate to detail screen style: ElevatedButton.styleFrom( foregroundColor: Colors.white, backgroundColor: const Color(0xFF004791), @@ -348,3 +379,5 @@ class _RdCancelledScreenState extends State { } } + + diff --git a/lib/screens/rd orders/rd_pending_deatils.dart b/lib/screens/rd orders/rd_pending_deatils.dart index 9594c7b..f2fcc1f 100644 --- a/lib/screens/rd orders/rd_pending_deatils.dart +++ b/lib/screens/rd orders/rd_pending_deatils.dart @@ -33,14 +33,14 @@ import '../../utils/show_snackbar.dart'; class RdOrderPendingScreenDetailScreen extends StatefulWidget { //final Product? productModel; // PlacedOrderList and PlacedOrderModel are optional parameters passed to this screen - SingleGetOrderModel? placedOrderList; - GetRdPendingModel? productpendingModel; + final SingleGetOrderModel? placedOrderList; + // GetRdPendingModel? productpendingModel; final String orderId; - GetInvoiceModel? placeInvoiceList; +// GetInvoiceModel? placeInvoiceList; // PlacedOrderModel? placedOrderModel; // Constructor for initializing the screen with placed order details - RdOrderPendingScreenDetailScreen({super.key,this.placedOrderList,required this.orderId,this.placeInvoiceList}); + RdOrderPendingScreenDetailScreen({super.key,this.placedOrderList,required this.orderId}); @override State createState() => @@ -214,7 +214,7 @@ class _RdOrderPendingScreenDetailScreenState // Notify user about successful cancellation showSnackbar("Order cancelled successfully"); - Get.to(RdCancelledScreen()); + Get.to(RdCancelledScreen()); // Update the status in your UI or backend to reflect the cancelled state setState(() {}); @@ -279,8 +279,8 @@ class _RdOrderPendingScreenDetailScreenState // Place the order and catch any errors await controller.placeRDOrder(); - showSnackbar("Order processed and invoice created successfully"); - Get.to(RdOrderProcessingScreen()); + showSnackbar("Order processed and invoice created successfully"); + Get.to(RdOrderProcessingScreen()); //Navigator.of(context).pop(); // Close the dialog after a short delay @@ -324,7 +324,28 @@ class _RdOrderPendingScreenDetailScreenState } @override Widget build(BuildContext context) { - // int remainingQuantity = (widget.placedOrderList!.orderItem![0].quantity)! -(widget.placedOrderList!.orderItem![0].remainingQuantity!.toInt()); + if (widget.placedOrderList == null) { + return Center(child: Text('No order details available')); + } + +// Safely get the order and invoice list + final order = widget.placedOrderList!; + final invoices = order.invoices; + +// Check if the invoices list contains at least 4 items + List? invoiceIds; + if (invoices.isNotEmpty) { + // Ensure there are at least 4 invoices + if (invoices.length >= 4) { + // Get the ID of the 4th invoice (index 3) + invoiceIds = [invoices[3].invoiceId!]; // Assuming invoiceId is a String + } else { + invoiceIds = []; // Fallback if not enough invoices + } + } else { + invoiceIds = []; // Fallback if no invoices available + } + //int remainingQuantity = (widget.placedOrderList!.orderItem![0].quantity)! -(widget.placedOrderList!.orderItem![0].remainingQuantity!.toInt()); return Scaffold( extendBodyBehindAppBar: true, appBar: AppBar( @@ -384,13 +405,13 @@ class _RdOrderPendingScreenDetailScreenState children: [ Card( - child: Column( + child: + Column( children: [ SizedBox( width: Get.width, child: Padding( - padding: - const EdgeInsets.fromLTRB(8, 8, 8, 0), + padding: const EdgeInsets.fromLTRB(8, 8, 8, 0), child: Text( "Invoices", style: GoogleFonts.roboto( @@ -400,171 +421,149 @@ class _RdOrderPendingScreenDetailScreenState ), ), ), - SizedBox( - width: Get.width, - child: Padding( - padding: - const EdgeInsets.fromLTRB(8, 8, 8, 0), - child: Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - Text( - "Invoice ID:", - style: GoogleFonts.roboto( - fontSize: Get.width * 0.04, - fontWeight: FontWeight.bold, - ), - ), - Text(widget.placeInvoiceList!.invoiceId.toString()), - // Text(widget.placedOrderList!.uniqueId), - ], - ), - ), - ), - SizedBox( - width: Get.width, - child: Padding( - padding: const EdgeInsets.fromLTRB(8, 8, 8, 0), - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ + // Displaying each invoice in a separate card + if (widget.placedOrderList!.invoices.isNotEmpty) + ...widget.placedOrderList!.invoices.map((invoice) { + return Card( + margin: const EdgeInsets.symmetric(vertical: 8, horizontal: 8), + child: Padding( + padding: const EdgeInsets.all(8.0), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + // Invoice ID + Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Text( + "Invoice ID:", + style: GoogleFonts.roboto( + fontSize: Get.width * 0.04, + fontWeight: FontWeight.bold, + ), + ), + Text(invoice.invoiceId.toString()), + ], + ), + const SizedBox(height: 10), // Add spacing - Text( - "Items: ", - style: GoogleFonts.roboto( - fontSize: Get.width * 0.04, - fontWeight: FontWeight.bold, - ), - ), - SizedBox(height: 10), // Add spacing between the title and the list of items - Column( - children: widget.placeInvoiceList!.items!.map((item) { + // Items for this invoice + Text( + "Items: ", + style: GoogleFonts.roboto( + fontSize: Get.width * 0.04, + fontWeight: FontWeight.bold, + ), + ), + const SizedBox(height: 10), // Add spacing between title and items - return Padding( - padding: const EdgeInsets.symmetric(vertical: 4.0), // Add some spacing between items - child: Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - Expanded( - child: Text( - "${item.name.toString()} (${item.sku.toString()})", - style: GoogleFonts.roboto( - fontSize: Get.width * 0.03, + // List of items in this invoice + Column( + children: invoice.items!.map((item) { + return Padding( + padding: const EdgeInsets.symmetric(vertical: 4.0), + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Expanded( + child: Text( + "${item.name.toString()} (${item.sku.toString()})", + style: GoogleFonts.roboto( + fontSize: Get.width * 0.03, + ), + overflow: TextOverflow.ellipsis, + ), ), - overflow: TextOverflow.ellipsis, // Handle long text + Text("x ${item.processQuantity.toString()}"), + ], + ), + ); + }).toList(), + ), + + const SizedBox(height: 10), // Add spacing between sections + + // Sub Total + Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Text( + "Sub Total:", + style: GoogleFonts.roboto( + fontSize: Get.width * 0.04, + fontWeight: FontWeight.bold, + ), + ), + Text("₹ ${invoice.subtotal}"), + ], + ), + + // GST + Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Text( + "GST:", + style: GoogleFonts.roboto( + fontSize: Get.width * 0.04, + fontWeight: FontWeight.bold, + ), + ), + Text("₹ ${invoice.gstTotal}"), + ], + ), + + // Invoice Amount + Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Text( + "Invoice Amount:", + style: GoogleFonts.roboto( + fontSize: Get.width * 0.04, + fontWeight: FontWeight.bold, + ), + ), + Text("₹ ${invoice.invoiceAmount}"), + ], + ), + + // Courier Status + Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Text( + "Courier Status:", + style: GoogleFonts.roboto( + fontSize: Get.width * 0.04, + fontWeight: FontWeight.bold, + ), + ), + ElevatedButton( + onPressed: () {}, + style: ElevatedButton.styleFrom( + foregroundColor: Colors.white, + backgroundColor: _getCourierStatusColor(invoice.courierStatus.toString()), + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(10), ), ), - Text("x ${item.processQuantity.toString()}"), - ], - ), - ); - }).toList(), + child: Text( + capitalizeFirstLetter(invoice.courierStatus.toString()), + ), + ), + ], + ), + ], ), - ], - ), - ), - ), - SizedBox( - width: Get.width, - child: Padding( - padding: - const EdgeInsets.fromLTRB(8, 8, 8, 0), - child: Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - Text( - "Sub Total : ", - style: GoogleFonts.roboto( - fontSize: Get.width * 0.04, - fontWeight: FontWeight.bold, - ), - ), - Text("₹ ${widget.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.placeInvoiceList!.gstTotal}"), - ], - ), - ), - ), - SizedBox( - width: Get.width, - child: Padding( - padding: - const EdgeInsets.fromLTRB(8, 8, 8, 0), - child: Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - Text( - "Invoice Amount: ", - style: GoogleFonts.roboto( - fontSize: Get.width * 0.04, - fontWeight: FontWeight.bold, - ), - ), - Text("₹ ${widget.placeInvoiceList!.invoiceAmount}"), - ], - ), - ), - ), - SizedBox( - width: Get.width, - child: Padding( - padding: - const EdgeInsets.fromLTRB(8, 8, 8, 0), - child: Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - Text( - "Courier Status : ", - style: GoogleFonts.roboto( - fontSize: Get.width * 0.04, - fontWeight: FontWeight.bold, - ), - ), - ElevatedButton( - onPressed: (){}, - // Get.to(() => - // RdOrderDetailScreen( - // placedOrderList: uniqueOrders[index])), // Navigate to detail screen - style: ElevatedButton.styleFrom( - foregroundColor: Colors.white, - backgroundColor:_getCourierStatusColor(widget.placeInvoiceList!.courierStatus.toString()), - shape: RoundedRectangleBorder( - borderRadius: BorderRadius.circular(10)), - ), - child: Text(capitalizeFirstLetter(widget.placeInvoiceList!.courierStatus.toString()), - // Text(widget.placedOrderList!.status.toString()) - //Text(widget.placedOrderList!.status, style: GoogleFonts.roboto(fontSize: 14, fontWeight: FontWeight.w400)), - ), - //Text("₹ ${widget.placedOrderList!.gstTotal}"), - )], - ), - ), - ), - + ), + ); + }).toList(), ], ), + ), + const SizedBox(height: 8), const SizedBox(height: 8), @@ -591,12 +590,12 @@ class _RdOrderPendingScreenDetailScreenState Expanded( child: ListView.builder( padding: EdgeInsets.zero, - itemCount: widget.placedOrderList?.orderItem!.length ?? 0, + itemCount: order.orderItem!.length ?? 0, itemBuilder: (context, index) { - final orderItem = widget.placedOrderList!.orderItem![index]; + final orderItem =order.orderItem![index]; final subTotal = orderItem.price * orderItem.quantity!.toInt(); - final GstTotalAmount = (orderItem.price * orderItem.quantity!.toInt()) *(orderItem.gst/100 ); - final grandTotal = subTotal + GstTotalAmount; + final GstTotalAmount = (orderItem.price * orderItem.quantity!.toInt()) *(orderItem.gst/100 ); + final grandTotal = subTotal + GstTotalAmount; return orderItem != null ? Card( margin: const EdgeInsets.symmetric(vertical: 5.0), @@ -678,14 +677,14 @@ class _RdOrderPendingScreenDetailScreenState Expanded( child: ListView.builder( padding: EdgeInsets.zero, - itemCount: widget.placedOrderList?.orderItem + itemCount: order.orderItem ?.where((item) => item.remainingQuantity! > 0) .length ?? 0, itemBuilder: (context, index) { // Filter items with non-zero quantities - final filteredItems = widget.placedOrderList!.orderItem! + final filteredItems =order!.orderItem! .where((item) => item.remainingQuantity! > 0) .toList(); @@ -775,7 +774,7 @@ class _RdOrderPendingScreenDetailScreenState fontWeight: FontWeight.w500, ), ), - Text(capitalizeFirstLetter(widget.placeInvoiceList!.orderId!.paymentMode.toString())), + Text(capitalizeFirstLetter(widget.placedOrderList!.paymentMode.toString())), // Text("${widget.placedOrderList!.paymentMode}",maxLines: 4, // overflow:TextOverflow.ellipsis,) ], @@ -808,7 +807,7 @@ class _RdOrderPendingScreenDetailScreenState ), SizedBox(width: Get.width*0.01,), //Text(capitalizeFirstLetter(widget.placedOrderList!.status)), - Text(capitalizeFirstLetter(widget.placedOrderList!.status.toString()),maxLines: 4, + Text(capitalizeFirstLetter(order!.status.toString()),maxLines: 4, overflow:TextOverflow.ellipsis,) ], ), @@ -1014,12 +1013,12 @@ class simple extends State { onPressed: () {}, style: ElevatedButton.styleFrom( foregroundColor: Colors.white, - backgroundColor: _getCourierStatusColor(widget.placeInvoiceList!.courierStatus.toString()), // Call the method here + backgroundColor: _getCourierStatusColor(widget.placedOrderList!.invoices[0]!.courierStatus.toString()), // Call the method here shape: RoundedRectangleBorder( borderRadius: BorderRadius.circular(10), ), ), - child: Text(widget.placeInvoiceList!.courierStatus.toString()), + child: Text(widget.placedOrderList!.invoices[0]!.courierStatus.toString()), ), ], ), diff --git a/lib/screens/rd orders/rd_pending_screen.dart b/lib/screens/rd orders/rd_pending_screen.dart index f11d957..91ad2e0 100644 --- a/lib/screens/rd orders/rd_pending_screen.dart +++ b/lib/screens/rd orders/rd_pending_screen.dart @@ -4,6 +4,7 @@ import 'package:cheminova/controller/rd_get_order_controller.dart'; import 'package:cheminova/controller/rd_processing_invoice_controller.dart'; import 'package:cheminova/models/get_rd_pennding_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/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'; @@ -88,9 +89,6 @@ class _RdOrderPendingScreenState extends State { // Fetch orders and ensure you wait for it to complete await _getRdPendingController.getRDPendingProduct(); - // await _getRDProcessingInvoiceController.getRDProcessingInvoiceProduct(); - - // await _getSingleInvoiceController.fetchInvoice(_getRDProcessingInvoiceController.productProcessingRDList[0].id); // Log the count of fetched orders print('Fetched orders count: ${_getRdPendingController.productRDList.length}'); @@ -100,23 +98,23 @@ class _RdOrderPendingScreenState extends State { if (index >= 0 && index < _getRdPendingController.productRDList.length) { // Get the order ID from the list based on the index final orderId = _getRdPendingController.productRDList[index].id; - final invoiceId = _getRdPendingController.productRDList[index].invoices[0]; + final invoiceId = _getRdPendingController.productRDList[index].invoices[0]; + // 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, invoiceId.toString()); + // Fetch the single order using the order ID + final SingleGetOrderModel? 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(() => RdOrderPendingScreenDetailScreen( - placedOrderList: singleOrder, + placedOrderList: singleOrder, // Pass the single order instance orderId: orderId, - placeInvoiceList: singleInvoice, )); } else { @@ -144,6 +142,7 @@ class _RdOrderPendingScreenState extends State { + @override Widget build(BuildContext context) { return Scaffold( diff --git a/lib/utils/api_urls.dart b/lib/utils/api_urls.dart index 6883dcf..a67463d 100644 --- a/lib/utils/api_urls.dart +++ b/lib/utils/api_urls.dart @@ -80,6 +80,14 @@ class ApiUrls { //============================== Annaouncement Details ==============================// static const String AnnaouncementUrl = '/api/announcement/PDs'; - //============================== Annaouncement Details ==============================// + //============================== shipto Billto Details ==============================// static const String ShiptoandBilltoAddressUrl = '/api/shipping/address/user/address'; + + + //============================== Product stock Details ==============================// + static const String ProductStockUrl = '/api/pd/stock'; + + //============================== Product Update stock Details ==============================// + static const String ProductUpdateStockUrl = '/api/pd/stock-update'; + } diff --git a/lib/widgets/my_drawer.dart b/lib/widgets/my_drawer.dart index b3e2505..8f7cf91 100644 --- a/lib/widgets/my_drawer.dart +++ b/lib/widgets/my_drawer.dart @@ -37,14 +37,14 @@ class _MyDrawerState extends State { mainAxisAlignment: MainAxisAlignment.start, children: [ Text( - user!.name ?? "username", + user?.name ?? "username", style: const TextStyle( color: Colors.white, fontSize: 18, ), ), Text( - user!.uniqueId ?? 'Employee ID', + user?.uniqueId ?? 'Employee ID', style: const TextStyle( color: Colors.white, fontSize: 20, diff --git a/lib/widgets/product_card1.dart b/lib/widgets/product_card1.dart index 96ae2b4..f0119e4 100644 --- a/lib/widgets/product_card1.dart +++ b/lib/widgets/product_card1.dart @@ -94,7 +94,7 @@ class _ProductCard1State extends State { ), ), Text( - " ${widget.productModel.quantity}", + " ${widget.productModel.remainingQuantity}", style: GoogleFonts.roboto( fontSize: 15, ),