Commit c1b1af92 authored by Sai Srinivas's avatar Sai Srinivas
Browse files

12-08-2025 By Sai Srinivas

Order Module - Add
parent ad026e51
import 'dart:async';
import 'dart:convert';
import 'dart:io';
import 'package:flutter/cupertino.dart';
......@@ -54,6 +55,21 @@ class Addorderprovider extends ChangeNotifier {
List<TextEditingController> TotalPriceControllers = [];
List<TextEditingController> TaxableValueControllers = [];
TextEditingController ProductController = TextEditingController();
TextEditingController PriceController = TextEditingController();
TextEditingController QuantityController = TextEditingController(text: "1");
TextEditingController CGSTController = TextEditingController(text: "9");
TextEditingController SGSTController = TextEditingController(text: "9");
TextEditingController IGSTController = TextEditingController(text: "0");
TextEditingController TotalPriceController = TextEditingController();
TextEditingController TaxableValueController = TextEditingController();
List<Map<String, dynamic>> _productRows = []; // For backend
List<Map<String, dynamic>> get productRows => _productRows;
TextEditingController basicAmountReadOnlyController = TextEditingController();
TextEditingController cgstReadOnlyController = TextEditingController();
TextEditingController sgstReadOnlyController = TextEditingController();
......@@ -79,21 +95,26 @@ class Addorderprovider extends ChangeNotifier {
AccountDetails _accountDetails = AccountDetails();
String selectAccountError = "";
String orderDateError = "";
String billingNameError = "";
String billingAddressError = "";
String billingPincodeError = "";
String dispatchAddressError = "";
String dispatchPincodeError = "";
String tpcAmountError = "";
String gstError = "";
String selectedBillingStateError = "";
String selectedBillingDistrictError = "";
String selectedBillingSubLocError = "";
String selectedDispatchStateError = "";
String selectedDispatchDistrictError = "";
String selectedDispatchSubLocError = "";
String? selectAccountError;
String? orderDateError;
String? billingNameError;
String? billingAddressError;
String? billingPincodeError;
String? dispatchAddressError;
String? dispatchPincodeError;
String? tpcAmountError;
String? gstError;
String? selectedBillingStateError;
String? selectedBillingDistrictError;
String? selectedBillingSubLocError;
String? selectedDispatchStateError;
String? selectedDispatchDistrictError;
String? selectedDispatchSubLocError;
String? selectedTPCApplicableError;
String? selectedUnloadingScopeError;
String? selectedFreightScopeError;
String? selectedErectionScopeError;
String? selectedTPCAgentError;
AccountList? _selectedAccountList;
String? _selectedAccountID;
......@@ -131,6 +152,7 @@ class Addorderprovider extends ChangeNotifier {
List<String?> _selectedSaleProductID = [];
String? _selectedSaleProductName;
String? _selectedSingleSaleProductID;
String? _selectedUnloadingScope;
String? _selectedFreightScope;
......@@ -149,7 +171,6 @@ class Addorderprovider extends ChangeNotifier {
bool hasLocationPermission = false;
String? FileError;
String? dateError;
bool _isLoading = false;
int _imagePicked = 0;
File? _image;
......@@ -159,7 +180,7 @@ class Addorderprovider extends ChangeNotifier {
String? _formattedDate;
Timer? _debounce;
List<Map<String, String>> _selectedOrders = [];
String? productsEmptyError ;
List<Map<String, String>> get selectedOrders => _selectedOrders;
bool _submitClicked = false;
......@@ -175,7 +196,11 @@ class Addorderprovider extends ChangeNotifier {
_selectedOrders = selectedOrders;
notifyListeners();
}
set productRows(value) {
_productRows = value;
productsEmptyError = "";
notifyListeners();
}
bool get isLoading => _isLoading;
String? get formattedDate => _formattedDate;
......@@ -270,6 +295,7 @@ class Addorderprovider extends ChangeNotifier {
List<String?> get selectedSaleProductID => _selectedSaleProductID;
String? get selectedSaleProductName => _selectedSaleProductName;
String? get selectedSingleSaleProductID => _selectedSingleSaleProductID;
String? get selectedUnloadingScope => _selectedUnloadingScope;
......@@ -442,6 +468,7 @@ class Addorderprovider extends ChangeNotifier {
set selectedSaleProducts(SaleProducts? value) {
_selectedSaleProducts = value;
_selectedSingleSaleProductID = value!.id!;
// _selectedSaleProductID = value!.id!;
// _selectedSaleProductName = value!.prodName;
notifyListeners();
......@@ -451,6 +478,10 @@ class Addorderprovider extends ChangeNotifier {
_selectedSaleProductID = value;
notifyListeners();
}
set selectedSingleSaleProductID(String? value){
_selectedSingleSaleProductID = value;
notifyListeners();
}
set selectedSaleProductName(String? value) {
_selectedSaleProductName = value;
......@@ -459,21 +490,25 @@ class Addorderprovider extends ChangeNotifier {
set selectedUnloadingScope(String? value) {
_selectedUnloadingScope = value;
selectedUnloadingScopeError = "";
notifyListeners();
}
set selectedFreightScope(String? value) {
_selectedFreightScope = value;
selectedFreightScopeError = "";
notifyListeners();
}
set selectedErectionScope(String? value) {
_selectedErectionScope = value;
selectedErectionScopeError = "";
notifyListeners();
}
set selectedTpcStatus(String? value) {
_selectedTpcStatus = value;
selectedTPCApplicableError = "";
notifyListeners();
}
......@@ -481,6 +516,7 @@ class Addorderprovider extends ChangeNotifier {
_selectedTpcAgent = value;
_selectedTpcAgentID = value!.id;
_selectedTpcAgentValue = value!.text;
selectedTPCAgentError = "";
notifyListeners();
}
......@@ -501,6 +537,7 @@ class Addorderprovider extends ChangeNotifier {
set imagePath(File? value) {
_imageName = value;
FileError = null;
notifyListeners();
}
......@@ -517,7 +554,7 @@ class Addorderprovider extends ChangeNotifier {
set formattedDate(String? value) {
_formattedDate = value;
orderReceivedDateController.text = _formattedDate!;
dateError = null;
orderDateError = null;
notifyListeners();
}
......@@ -525,7 +562,7 @@ class Addorderprovider extends ChangeNotifier {
_date = newDate;
_formattedDate = DateFormat('yyyy-MM-dd').format(newDate);
orderReceivedDateController.text = _formattedDate!;
dateError = null;
orderDateError = null;
notifyListeners();
}
......@@ -580,6 +617,67 @@ class Addorderprovider extends ChangeNotifier {
return total!;
}
void addProduct(Map<String, dynamic> product) {
productRows.add(product);
notifyListeners();
}
void updateProduct(int index, Map<String, dynamic> updatedProduct) {
productRows[index] = updatedProduct;
notifyListeners();
}
void updateProductCalculations() {
final inclusivePrice =
double.tryParse(PriceController.text) ?? 0.0;
final quantity = double.tryParse(QuantityController.text) ?? 1.0;
final cgst = double.tryParse(CGSTController.text) ?? 0.0;
final sgst = double.tryParse(SGSTController.text) ?? 0.0;
final igst = double.tryParse(IGSTController.text) ?? 0.0;
final totalTaxRate = (cgst + sgst + igst) / 100;
// Calculate taxable value per unit
final taxableValuePerUnit = inclusivePrice / (1 + totalTaxRate);
// Total taxable value = taxable value per unit * quantity
final totalTaxableValue = taxableValuePerUnit * quantity;
TaxableValueController.text = totalTaxableValue.toStringAsFixed(
0,
);
notifyListeners();
}
void updateSelectedSingleProduct(SaleProducts? product) {
_selectedSaleProducts = product;
_selectedSingleSaleProductID= product!.id;
PriceController.text = product!.price!;
updateProductCalculations();
notifyListeners();
}
void prefillProductForEdit(int index) {
final product = productRows[index];
selectedSaleProducts = saleProducts.firstWhere(
(p) => p.id == product['product_id'],
orElse: () => SaleProducts(id: '', prodName: 'Unknown'),
);
selectedSingleSaleProductID = product['product_id'];
selectedSaleProductName = selectedSaleProducts?.prodName;
QuantityController.text = product['qty'] ?? '';
PriceController.text = product['price'] ?? '';
CGSTController.text = product['cgst_p'] ?? '';
SGSTController.text = product['sgst_p'] ?? '';
IGSTController.text = product['igst_p'] ?? '';
TaxableValueController.text = product['total_price'] ?? '';
notifyListeners();
}
String getJsonEncodedProducts() {
return jsonEncode(productRows);
}
void addNewRow() {
ProductControllers.add(TextEditingController());
PriceControllers.add(TextEditingController());
......@@ -646,8 +744,7 @@ class Addorderprovider extends ChangeNotifier {
notifyListeners();
}
}
///[{"product_id":"1","qty":"1","price":"500","cgst_p":"9","sgst_p":"9","igst_p":"0","total_price":"500"},
///{"product_id":"2","qty":"1","price":"1000","cgst_p":"9","sgst_p":"9","igst_p":"0","total_price":"1000"}]
Map<String, dynamic> getFormData() {
final List<Map<String, dynamic>> orders = [];
for (int i = 0; i < ProductControllers.length; i++) {
......@@ -672,150 +769,6 @@ class Addorderprovider extends ChangeNotifier {
};
}
//
//
// void updateSelectedOrderId(int index, SaleProducts? value) {
// if (index >= 0 && index < _selectedSaleProductID.length) {
// _selectedSaleProductID[index] = value!.id;
// ProductControllers[index].text = value!.prodName!;
// PriceControllers[index].text = value.price!;
// notifyListeners();
// } else {
// print("Invalid index: $index");
// }
// }
// void addNewRow() {
// // Create a unique TextEditingController for each field
// ProductControllers.add(TextEditingController());
// PriceControllers.add(TextEditingController());
// QuantityControllers.add(TextEditingController());
// CGSTControllers.add(TextEditingController(text: "9"));
// SGSTControllers.add(TextEditingController(text: "9"));
// IGSTControllers.add(TextEditingController());
// TotalPriceControllers.add(TextEditingController());
// _selectedSaleProductID.add(null); // Safe to add null since List<String?> allows nullable strings
// notifyListeners();
// }
//
// void removeRow(int index) {
// if (index >= 0 && index < ProductControllers.length) {
// ProductControllers[index].dispose();
// ProductControllers.removeAt(index);
// PriceControllers[index].dispose();
// PriceControllers.removeAt(index);
// QuantityControllers[index].dispose();
// QuantityControllers.removeAt(index);
// CGSTControllers[index].dispose();
// CGSTControllers.removeAt(index);
// SGSTControllers[index].dispose();
// SGSTControllers.removeAt(index);
// IGSTControllers[index].dispose();
// IGSTControllers.removeAt(index);
// TotalPriceControllers[index].dispose();
// TotalPriceControllers.removeAt(index);
// _selectedSaleProductID.removeAt(index);
// notifyListeners();
// } else {
// print("Invalid index: $index");
// }
// }
// double get basicAmount {
// double total = 0;
// for (int i = 0; i < TotalPriceControllers.length; i++) {
// total += double.tryParse(TotalPriceControllers[i].text) ?? 0.0;
// }
// return total;
// }
//
// double get cgstAmount {
// double total = 0;
// for (int i = 0; i < ProductControllers.length; i++) {
// final price = double.tryParse(PriceControllers[i].text) ?? 0.0;
// final quantity = double.tryParse(QuantityControllers[i].text) ?? 0.0;
// final cgst = double.tryParse(CGSTControllers[i].text) ?? 0.0;
// total += (price * quantity * cgst) / 100;
// }
// return total;
// }
//
// double get sgstAmount {
// double total = 0;
// for (int i = 0; i < ProductControllers.length; i++) {
// final price = double.tryParse(PriceControllers[i].text) ?? 0.0;
// final quantity = double.tryParse(QuantityControllers[i].text) ?? 0.0;
// final sgst = double.tryParse(SGSTControllers[i].text) ?? 0.0;
// total += (price * quantity * sgst) / 100;
// }
// return total;
// }
//
// double get igstAmount {
// double total = 0;
// for (int i = 0; i < ProductControllers.length; i++) {
// final price = double.tryParse(PriceControllers[i].text) ?? 0.0;
// final quantity = double.tryParse(QuantityControllers[i].text) ?? 0.0;
// final igst = double.tryParse(IGSTControllers[i].text) ?? 0.0;
// total += (price * quantity * igst) / 100;
// }
// return total;
// }
//
// double get totalAmount => basicAmount + cgstAmount + sgstAmount + igstAmount;
//
//
// // List<Map<String, String>> getFormData() {
// // _selectedOrders = [];
// //
// // // Iterate over rows
// // for (int i = 0; i < ProductControllers.length; i++) {
// // // Only include rows with a valid product ID
// // if (_selectedSaleProductID[i] != null &&
// // ProductControllers[i].text.isNotEmpty) {
// // // Create a map for the current row's data
// // final rowData = {
// // "product_id": _selectedSaleProductID[i]!,
// // "product_name": ProductControllers[i].text,
// // "price": PriceControllers[i].text.isNotEmpty ? PriceControllers[i].text : "0",
// // "qty": QuantityControllers[i].text.isNotEmpty ? QuantityControllers[i].text : "0",
// // "cgst_p": CGSTControllers[i].text.isNotEmpty ? CGSTControllers[i].text : "0",
// // "sgst_p": SGSTControllers[i].text.isNotEmpty ? SGSTControllers[i].text : "0",
// // "igst_p": IGSTControllers[i].text.isNotEmpty ? IGSTControllers[i].text : "0",
// // "total_price": TotalPriceControllers[i].text.isNotEmpty ? TotalPriceControllers[i].text : "0",
// // };
// // _selectedOrders.add(rowData);
// // }
// // }
// //
// // print("Form Data: $_selectedOrders");
// // notifyListeners();
// // return _selectedOrders;
// // }
//
// Map<String, dynamic> getFormData() {
// final List<Map<String, dynamic>> orders = [];
// for (int i = 0; i < ProductControllers.length; i++) {
// orders.add({
// 'product_id': selectedSaleProductID[i],
// 'product_name': ProductControllers[i].text,
// 'price': PriceControllers[i].text,
// 'quantity': QuantityControllers[i].text,
// 'cgst': CGSTControllers[i].text,
// 'sgst': SGSTControllers[i].text,
// 'igst': IGSTControllers[i].text,
// 'total_price': TotalPriceControllers[i].text,
// });
// }
// return {
// 'orders': orders,
// 'basic_amount': basicAmount.toStringAsFixed(2),
// 'cgst_amount': cgstAmount.toStringAsFixed(2),
// 'sgst_amount': sgstAmount.toStringAsFixed(2),
// 'igst_amount': igstAmount.toStringAsFixed(2),
// 'total_amount': totalAmount.toStringAsFixed(2),
// 'note': noteController.text,
// };
// }
Future<void> ordersAddOrderAPIViewFunction(context, mode) async {
try {
final provider = Provider.of<HomescreenNotifier>(context, listen: false);
......@@ -925,14 +878,27 @@ class Addorderprovider extends ChangeNotifier {
_accountDetails = data.accountDetails!;
data.accountDetails!.accManagerId!;
billingNameController.text = data.accountDetails!.name!;
_selectedBillingSubLocID = data.accountDetails!.subLocality!;
_selectedBillingDistrictID = data.accountDetails!.district!;
_selectedBillingStateID = data.accountDetails!.state!;
if(_selectedBillingStateID!=null){
getDistrictAPI(context,_selectedBillingStateID);
}
_selectedBillingDistrictID = data.accountDetails!.district!;
if(_selectedBillingDistrictID!=null){
getSubLocationAPI(context,_selectedBillingDistrictID);
}
_selectedBillingSubLocID = data.accountDetails!.subLocality!;
billingPincodeController.text = data.accountDetails!.pincode!;
billingAddressController.text = data.accountDetails!.address!;
orderReceivedDateController.text = data.accountDetails!.date!;
gstController.text = data.accountDetails!.gstNumber!;
orderDateError = null;
billingNameError = null;
billingPincodeError =null;
billingAddressError = null;
selectedBillingStateError = null;
selectedBillingDistrictError = null;
selectedBillingSubLocError = null;
notifyListeners();
} else {}
} else {}
......@@ -1268,6 +1234,9 @@ class Addorderprovider extends ChangeNotifier {
_image = File(galleryImage!.path);
_imageName = File(galleryImage!.name);
_imagePicked = 1;
if(_imagePicked==0){
FileError = "Please Select Attachment";
}
FileError = null;
notifyListeners();
} catch (e) {
......@@ -1290,6 +1259,9 @@ class Addorderprovider extends ChangeNotifier {
_image = File(galleryImage!.path);
_imageName = File(galleryImage!.name);
_imagePicked = 1;
if(_imagePicked==0){
FileError = "Please Select Attachment";
}
FileError = null;
notifyListeners();
// var file = FlutterImageCompress.compressWithFile(galleryImage!.path);
......@@ -1299,58 +1271,67 @@ class Addorderprovider extends ChangeNotifier {
}
void onChangedBillingName(value) {
billingNameError = "";
billingNameError =null;
notifyListeners();
}
void onChangeOrderDate(value) {
orderDateError = null;
notifyListeners();
}
void onChangedBillingAddress(value) {
billingAddressError = "";
billingAddressError = null;
notifyListeners();
}
void onChangedBillingPincode(value) {
billingPincodeError = "";
billingPincodeError = null;
notifyListeners();
}
void onChangedDispatchAddress(value) {
dispatchAddressError = "";
dispatchAddressError = null;
notifyListeners();
}
void onChangedDispatchPincode(value) {
dispatchPincodeError = "";
dispatchPincodeError = null;
notifyListeners();
}
void onChangedGst(value) {
gstError = "";
gstError = null;
notifyListeners();
}
void onChangeTpcAmount(value) {
tpcAmountError = "";
tpcAmountError = null;
notifyListeners();
}
bool validateAddOrder() {
bool isValid = true;
selectAccountError = "";
billingNameError = "";
orderDateError = "";
billingAddressError = "";
billingPincodeError = "";
dispatchAddressError = "";
dispatchPincodeError = "";
gstError = "";
tpcAmountError = "";
selectedBillingStateError = "";
selectedBillingDistrictError = "";
selectedBillingSubLocError = "";
selectedDispatchStateError = "";
selectedDispatchDistrictError = "";
selectedDispatchSubLocError = "";
selectAccountError = null;
billingNameError = null;
orderDateError =null;
billingAddressError = null;
billingPincodeError = null;
dispatchAddressError = null;
dispatchPincodeError = null;
gstError = null;
tpcAmountError = null;
selectedBillingStateError = null;
selectedBillingDistrictError = null;
selectedBillingSubLocError = null;
selectedDispatchStateError = null;
selectedDispatchDistrictError = null;
selectedDispatchSubLocError = null;
selectedUnloadingScopeError = null;
selectedFreightScopeError = null;
selectedErectionScopeError = null;
selectedTPCApplicableError = null;
selectedTPCAgentError = null;
if (_selectedAccountList == null || _selectedAccountID==null) {
selectAccountError = "Please select an Account";
......@@ -1394,53 +1375,230 @@ class Addorderprovider extends ChangeNotifier {
if (orderReceivedDateController.text.trim().isEmpty) {
orderDateError = "Please Enter Date";
orderDateError = "Please Enter Received Date";
isValid = false;
notifyListeners();
}
if (billingNameController.text.trim().isEmpty) {
isValid = false;
billingNameError = "Please Enter Your Name";
notifyListeners();
}
if (billingAddressController.text.trim().isEmpty) {
isValid = false;
billingAddressError = "Please Enter Address";
notifyListeners();
}
if (billingPincodeController.text.trim().isEmpty) {
isValid = false;
billingPincodeError = "Please Enter Pin Code";
notifyListeners();
}
if (dispatchAddressController.text.trim().isEmpty) {
dispatchAddressError = "Please Enter Dispatch Address";
isValid = false;
notifyListeners();
}
if (dispatchPincodeController.text.trim().isEmpty) {
dispatchPincodeError = "Please Enter Dispatch Pin Code";
isValid = false;
notifyListeners();
}
if (gstController.text.trim().isEmpty) {
gstError = "Please Enter GST Number";
isValid = false;
notifyListeners();
}
if (_selectedUnloadingScope == null) {
selectedUnloadingScopeError = "Please select a Scope";
isValid = false;
}
if (_selectedFreightScope == null) {
selectedFreightScopeError = "Please select a Scope";
isValid = false;
}
if (_selectedErectionScope == null) {
selectedErectionScopeError = "Please select a Scope";
isValid = false;
}
if (_selectedTpcStatus == null) {
selectedTPCApplicableError = "Please select TPC status";
isValid = false;
}
if (_selectedTpcStatus == "Yes") {
if (_selectedTpcAgent == null || _selectedTpcAgentID==null) {
selectedTPCAgentError = "Please select an Agent";
isValid = false;
}
if (tpcAmountController.text.trim().isEmpty) {
isValid = false;
tpcAmountError = "Please Enter Amount";
notifyListeners();
}
}
_submitClicked = false;
notifyListeners();
return isValid;
}
bool validateForm1() {
bool isValid = true;
selectAccountError = null;
billingNameError = null;
orderDateError = null;
billingAddressError = null;
billingPincodeError = null;
selectedBillingStateError = null;
selectedBillingDistrictError = null;
selectedBillingSubLocError = null;
if (_selectedAccountList == null || _selectedAccountID==null) {
selectAccountError = "Please select an Account";
isValid = false;
}
if (_selectedBillingStates == null || _selectedBillingStateID==null) {
selectedBillingStateError = "Please select a State";
isValid = false;
}
if (_selectedBillingDistricts == null || _selectedBillingDistrictID==null) {
selectedBillingDistrictError = "Please select a District";
isValid = false;
}
if (_selectedBillingSubLocations == null || _selectedBillingSubLocID==null) {
selectedBillingSubLocError = "Please select a Location";
isValid = false;
}
if (orderReceivedDateController.text.trim().isEmpty) {
isValid = false;
orderDateError = "Please Enter Received Date";
}
if (billingNameController.text.trim().isEmpty) {
isValid = false;
billingNameError = "Please Enter Your Name";
}
if (billingAddressController.text.trim().isEmpty) {
isValid = false;
billingAddressError = "Please Enter Address";
}
if (billingPincodeController.text.trim().isEmpty) {
isValid = false;
billingPincodeError = "Please Enter Pin Code";
}
if(billingPincodeController.text.length<6){
isValid = false;
billingPincodeError = "Please Enter a valid Pin Code";
}
_submitClicked = false;
notifyListeners();
return isValid;
}
bool validateForm2() {
bool isValid = true;
dispatchAddressError = null;
dispatchPincodeError = null;
gstError = null;
selectedDispatchStateError = null;
selectedDispatchDistrictError = null;
selectedDispatchSubLocError = null;
FileError = null;
if (_selectedDispatchStates == null || _selectedDispatchStateID==null) {
selectedDispatchStateError = "Please select a State";
isValid = false;
}
if (_selectedDispatchDistricts == null || _selectedDispatchDistrictID==null) {
selectedDispatchDistrictError = "Please select a District";
isValid = false;
}
if (_selectedDispatchSubLocations == null || _selectedDispatchSubLocID==null) {
selectedDispatchSubLocError = "Please select a Location";
isValid = false;
}
if (dispatchAddressController.text.trim().isEmpty) {
dispatchAddressError = "Please Enter Dispatch Address";
isValid = false;
}
if (dispatchPincodeController.text.trim().isEmpty) {
dispatchPincodeError = "Please Enter Dispatch Pin Code";
isValid = false;
}
if(dispatchPincodeController.text.length<6){
isValid = false;
dispatchPincodeError = "Please Enter a valid Pin Code";
}
if (gstController.text.trim().isEmpty) {
gstError = "Please Enter GST Number";
isValid = false;
}
if(_imagePicked==0){
FileError = "Please provide an Attachment";
isValid = false;
}
_submitClicked = false;
notifyListeners();
return isValid;
}
bool validateForm3() {
bool isValid = true;
tpcAmountError = null;
selectedUnloadingScopeError = null;
selectedFreightScopeError = null;
selectedErectionScopeError = null;
selectedTPCApplicableError = null;
selectedTPCAgentError = null;
if (_selectedUnloadingScope == null) {
selectedUnloadingScopeError = "Please select a Scope";
isValid = false;
}
if (_selectedFreightScope == null) {
selectedFreightScopeError = "Please select a Scope";
isValid = false;
}
if (_selectedErectionScope == null) {
selectedErectionScopeError = "Please select a Scope";
isValid = false;
}
if (_selectedTpcStatus == null) {
selectedTPCApplicableError = "Please select TPC status";
isValid = false;
}
if (_selectedTpcStatus == "Yes") {
if (_selectedTpcAgent == null || _selectedTpcAgentID==null) {
selectedTPCAgentError = "Please select an Agent";
isValid = false;
}
if (tpcAmountController.text.trim().isEmpty) {
tpcAmountError = "Please Enter Amount";
isValid = false;
}
}
_submitClicked = false;
notifyListeners();
return isValid;
}
bool validateForm4() {
bool isValid = true;
if(productRows.isEmpty || _productRows.isEmpty){
productsEmptyError = "Please Add min. one Product";
isValid = false;
}
_submitClicked = false;
notifyListeners();
return isValid;
}
void resetForm() {
_submitClicked = false;
_productRows.clear();
dropDownSearchController.clear();
dropDownTpcSearchController.clear();
billingNameController.clear();
......@@ -1448,20 +1606,31 @@ class Addorderprovider extends ChangeNotifier {
billingPincodeController.clear();
dispatchAddressController.clear();
dispatchPincodeController.clear();
ProductController.clear();
PriceController.clear();
QuantityController.clear();
CGSTController.clear();
SGSTController.clear();
IGSTController.clear();
QuantityController.text = "1";
CGSTController.text = "9";
SGSTController.text = "9";
IGSTController.text = "0";
TotalPriceController.clear();
TaxableValueController.clear();
billingStateSearchController.clear();
billingDistrictSearchController.clear();
billingSubLocSearchController.clear();
dispatchStateSearchController.clear();
dispatchDistrictSearchController.clear();
dispatchSubLocSearchController.clear();
_productRows = [];
gstController.clear();
orderReceivedDateController.clear();
tpcAmountController.clear();
orderReceivedDateController.clear();
noteController.clear();
selectedSingleSaleProductID = null;
ProductControllers.forEach((action) => action.dispose());
ProductControllers.clear();
PriceControllers.forEach((action) => action.dispose());
......@@ -1488,18 +1657,19 @@ class Addorderprovider extends ChangeNotifier {
_imageName = null;
_imagePicked = 0;
selectAccountError = "";
billingNameError = "";
billingAddressError = "";
billingPincodeError = "";
dispatchAddressError = "";
dispatchPincodeError = "";
selectedBillingStateError = "";
selectedBillingDistrictError = "";
selectedBillingSubLocError = "";
selectedDispatchStateError = "";
selectedDispatchDistrictError = "";
selectedDispatchSubLocError = "";
selectAccountError = null;
orderDateError = null;
billingNameError = null;
billingAddressError = null;
billingPincodeError = null;
dispatchAddressError = null;
dispatchPincodeError = null;
selectedBillingStateError = null;
selectedBillingDistrictError = null;
selectedBillingSubLocError = null;
selectedDispatchStateError = null;
selectedDispatchDistrictError = null;
selectedDispatchSubLocError = null;
_selectedAccountList = null;
_selectedEmployees = null;
_selectedBillingStates = null;
......@@ -1537,9 +1707,9 @@ class Addorderprovider extends ChangeNotifier {
_selectedTpcAgentID = "";
_selectedTpcAgentValue = "";
gstError = "";
gstError = null;
FileError = null;
dateError = null;
orderDateError = null;
checkDropdownselected();
notifyListeners();
}
......@@ -1587,6 +1757,7 @@ class Addorderprovider extends ChangeNotifier {
),
onPressed: () {
setDate(_date ?? DateTime.now() );
Navigator.pop(context);
},
),
......
This source diff could not be displayed because it is too large. You can view the blob instead.
import 'dart:io';
import 'package:connectivity_plus/connectivity_plus.dart';
import 'package:dropdown_button2/dropdown_button2.dart';
import 'package:flutter/material.dart';
import 'package:generp/Models/ordersModels/AddOrderViewResponse.dart';
import 'package:provider/provider.dart';
import '../../Notifiers/ordersProvider/addOrderProvider.dart';
import '../../Utils/app_colors.dart';
import '../../Utils/commonServices.dart';
import '../../Utils/commonWidgets.dart';
import '../../Utils/dropdownTheme.dart';
class Addorderaddproduct extends StatefulWidget {
final type;
final editIndex;
const Addorderaddproduct({super.key, this.type, this.editIndex});
@override
State<Addorderaddproduct> createState() => _AddorderaddproductState();
}
class _AddorderaddproductState extends State<Addorderaddproduct> {
Map _source = {ConnectivityResult.mobile: true};
final MyConnectivity _connectivity = MyConnectivity.instance;
Dropdowntheme ddtheme = Dropdowntheme();
@override
void initState() {
// TODO: implement initState
super.initState();
_connectivity.initialise();
_connectivity.myStream.listen((source) {
setState(() => _source = source);
});
WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
final provider = Provider.of<Addorderprovider>(
context,
listen: false,
);
if(widget.type == "Add"){
provider.selectedSaleProducts = null;
provider.selectedSingleSaleProductID = null;
provider.selectedSaleProductName = null;
provider.ProductController.clear();
provider.PriceController.clear();
provider.QuantityController.clear();
provider.CGSTController.clear();
provider.SGSTController.clear();
provider.IGSTController.clear();
provider.TotalPriceController.clear();
provider.TaxableValueController.clear();
provider.QuantityController.text = "1";
provider.CGSTController.text = "9";
provider.SGSTController.text = "9";
provider.IGSTController.text = "0";
}else{
provider.prefillProductForEdit(widget.editIndex!);
}
// provider.addEditInitializeForm(context);
});
}
@override
void dispose() {
// TODO: implement dispose
super.dispose();
_connectivity.disposeStream();
}
@override
Widget build(BuildContext context) {
switch (_source.keys.toList()[0]) {
case ConnectivityResult.mobile:
connection = 'Online';
break;
case ConnectivityResult.wifi:
connection = 'Online';
break;
case ConnectivityResult.none:
default:
connection = 'Offline';
}
return (connection == "Online")
? Platform.isAndroid
? WillPopScope(
onWillPop: () => onBackPressed(context),
child: SafeArea(
top: false,
bottom: true,
child: _scaffold(context),
),
)
: _scaffold(context)
: NoNetwork(context);
}
Widget _scaffold(BuildContext context) {
return Consumer<Addorderprovider>(
builder: (context, provider, child) {
return Scaffold(
resizeToAvoidBottomInset: true,
appBar: appbarNew(context, "Generate Quotation", 0xFFFFFFFF),
backgroundColor: AppColors.scaffold_bg_color,
body:SingleChildScrollView(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
// Product Rows (Horizontal ListView)
Container(
width: MediaQuery.of(context).size.width,
padding: const EdgeInsets.all(5.0),
decoration: BoxDecoration(
color: const Color(0xFFF5F5F5),
borderRadius: BorderRadius.circular(12),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const SizedBox(height: 8.0),
Container(
padding: const EdgeInsets.all(3.0),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(12),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
// Product Dropdown
Row(
children: [
Expanded(
child: DropdownButtonHideUnderline(
child: DropdownButton2<SaleProducts>(
isExpanded: true,
hint: Text(
'Select Product',
style: TextStyle(fontSize: 14),
overflow: TextOverflow.ellipsis,
),
items:
provider.saleProducts
.map(
(ord) => DropdownMenuItem<
SaleProducts
>(
value: ord,
child: Text(
"${ord.prodName}" ?? '',
style: const TextStyle(
fontSize: 14,
),
overflow:
TextOverflow.ellipsis,
),
),
)
.toList(),
value:
provider.selectedSingleSaleProductID !=
null
? provider.saleProducts.firstWhere(
(product) =>
product.id ==
provider
.selectedSingleSaleProductID,
)
: null,
onChanged: (SaleProducts? value) {
if (value != null) {
if (provider
.saleProducts
.isNotEmpty) {
provider.selectedSaleProducts =
value;
provider.PriceController.text = value.price!;
provider.notifyListeners();
provider.updateProductCalculations();
// provider.updateSelectedSingleProduct(
//
// provider.selectedSaleProducts,
// );
// provider.selectedOrderIds = value!.orderId!;
// provider.selectedOrderNumbers = value!.orderNumber!;
}
}
},
buttonStyleData:
ddtheme.buttonStyleData,
iconStyleData: ddtheme.iconStyleData,
menuItemStyleData:
ddtheme.menuItemStyleData,
dropdownStyleData:
ddtheme.dropdownStyleData,
),
),
),
],
),
const SizedBox(height: 8.0),
Row(
children: [
// Price TextField (Read-only)
Expanded(
child: textControllerWidget(
context,
provider.PriceController,
"Price",
"Enter Price",
(p0) {},
TextInputType.number,
false,
null,
null,
null,
TextInputAction.next,
),
),
const SizedBox(width: 8.0),
Expanded(
child: textControllerWidget(
context,
provider.QuantityController,
"Quantity",
"Enter Quantity",
(p0) {
provider.updateProductCalculations();
},
TextInputType.number,
false,
null,
null,
null,
TextInputAction.next,
),
),
],
),
const SizedBox(height: 8.0),
Row(
children: [
// CGST TextField
// Expanded(
// child: TextField(
// controller: provider.CGSTControllers[index],
// decoration: const InputDecoration(
// labelText: 'CGST %',
// border: OutlineInputBorder(),
// isDense: true,
// ),
// keyboardType: TextInputType.number,
// inputFormatters: [
// FilteringTextInputFormatter.digitsOnly
// ],
// onChanged: (value) {
// provider.updateRowCalculations(index);
// },
// ),
// ),
Expanded(
child: textControllerWidget(
context,
provider.CGSTController,
"CGST %",
"Enter CGST %",
(p0) {
provider.updateProductCalculations();
},
TextInputType.number,
false,
null,
null,
null,
TextInputAction.next,
),
),
const SizedBox(width: 8.0),
Expanded(
child: textControllerWidget(
context,
provider.SGSTController,
"SGST %",
"Enter SGST %",
(p0) {
provider.updateProductCalculations();
},
TextInputType.number,
false,
null,
null,
null,
TextInputAction.next,
),
),
const SizedBox(width: 8.0),
Expanded(
child: textControllerWidget(
context,
provider.IGSTController,
"IGST %",
"Enter IGST %",
(p0) {
provider.updateProductCalculations();
},
TextInputType.number,
false,
null,
null,
null,
TextInputAction.next,
),
),
],
),
const SizedBox(height: 8.0),
Row(
children: [
Expanded(
child: textControllerWidget(
context,
provider.TaxableValueController,
"Total Price",
"Enter Total Price",
(p0) {
provider.updateProductCalculations();
},
TextInputType.number,
true,
null,
null,
null,
TextInputAction.next,
),
),
],
),
],
),
),
],
),
),
const SizedBox(height: 20),
// Submit Button
],
),
),
floatingActionButtonLocation:
FloatingActionButtonLocation.centerFloat,
floatingActionButton: InkWell(
onTap: () {
if (provider.selectedSaleProducts != null) {
final productData = {
'product_id': provider.selectedSingleSaleProductID,
'qty': provider.QuantityController.text,
'price': provider.PriceController.text,
'cgst_p': provider.CGSTController.text,
'sgst_p': provider.SGSTController.text,
'igst_p': provider.IGSTController.text,
'total_price': provider.TaxableValueController.text,
};
if (widget.editIndex != null) {
provider.updateProduct(widget.editIndex!, productData);
} else {
provider.addProduct(productData);
}
print(provider.getJsonEncodedProducts());
Navigator.pop(context, provider.getJsonEncodedProducts());
}
},
child: Container(
alignment: Alignment.center,
height: 45,
decoration: BoxDecoration(
color: AppColors.app_blue, //1487C9
borderRadius: BorderRadius.circular(14.0),
),
margin: EdgeInsets.symmetric(horizontal: 10),
child: Center(
child: Text(
"Submit",
textAlign: TextAlign.center,
style: TextStyle(color: Colors.white),
),
),
),
),
);
},
);
}
}
......@@ -94,11 +94,12 @@ class _AddpaymentScreenState extends State<AddpaymentScreen> {
child: Scaffold(
resizeToAvoidBottomInset: true,
backgroundColor: AppColors.white,
appBar: appbar2(
appBar: appbar2New(
context,
"${widget.pageTitleName}",
provider.resetForm,
SizedBox(width: 0),
0xFFFFFFFF
),
body: Container(
padding: EdgeInsets.symmetric(horizontal: 10),
......
......@@ -67,11 +67,12 @@ class _AddtpcagentScreenState extends State<AddtpcagentScreen> {
bottom: Platform.isIOS?false:true,
child: Scaffold(
resizeToAvoidBottomInset: true,
appBar: appbar2(
appBar: appbar2New(
context,
"Add TPC Agent",
provider.resetAll,
SizedBox(width: 0),
0xFFFFFFFF
),
backgroundColor: AppColors.scaffold_bg_color,
body: Container(
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment