Individual and Jwellery Account Setup done
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import '../../../core/network/dio_client.dart';
|
||||
import '../domain/inventory_item.dart';
|
||||
|
||||
final inventoryItemsProvider = FutureProvider<List<InventoryItem>>((ref) async {
|
||||
try {
|
||||
final response = await DioClient().dio.get('/inventory/items');
|
||||
if (response.statusCode == 200) {
|
||||
final List<dynamic> data = response.data;
|
||||
return data.map((json) => InventoryItem.fromJson(json)).toList();
|
||||
}
|
||||
return [];
|
||||
} catch (e) {
|
||||
return [];
|
||||
}
|
||||
});
|
||||
@@ -0,0 +1,17 @@
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import '../../../core/network/dio_client.dart';
|
||||
|
||||
final inventoryValuationProvider = FutureProvider<double>((ref) async {
|
||||
try {
|
||||
final response = await DioClient().dio.get('/inventory/items/total-value');
|
||||
if (response.statusCode == 200) {
|
||||
if (response.data is num) {
|
||||
return (response.data as num).toDouble();
|
||||
}
|
||||
return double.tryParse(response.data.toString()) ?? 0.0;
|
||||
}
|
||||
return 0.0;
|
||||
} catch (e) {
|
||||
return 0.0;
|
||||
}
|
||||
});
|
||||
@@ -7,20 +7,32 @@ class ProductCategory {
|
||||
final int? userId;
|
||||
final String name;
|
||||
final int? parentCategoryId;
|
||||
final bool isCommodity;
|
||||
final bool hasChild;
|
||||
final String? defaultHsn;
|
||||
final double? defaultGst;
|
||||
final bool huidRequired;
|
||||
final double? defaultMakingCharge;
|
||||
final String? makingChargeType;
|
||||
final String calculationMethod;
|
||||
final String baseUnit;
|
||||
final double? dailyRate;
|
||||
final bool isActive;
|
||||
final int sortOrder;
|
||||
|
||||
ProductCategory({
|
||||
this.id,
|
||||
this.userId,
|
||||
required this.name,
|
||||
this.parentCategoryId,
|
||||
this.isCommodity = false,
|
||||
this.hasChild = false,
|
||||
this.defaultHsn,
|
||||
this.defaultGst,
|
||||
this.huidRequired = false,
|
||||
this.defaultMakingCharge,
|
||||
this.makingChargeType,
|
||||
this.calculationMethod = 'UNIT',
|
||||
this.baseUnit = 'pcs',
|
||||
this.dailyRate,
|
||||
this.isActive = true,
|
||||
this.sortOrder = 0,
|
||||
});
|
||||
|
||||
factory ProductCategory.fromJson(Map<String, dynamic> json) {
|
||||
@@ -29,10 +41,16 @@ class ProductCategory {
|
||||
userId: json['userId'],
|
||||
name: json['name'],
|
||||
parentCategoryId: json['parentCategoryId'],
|
||||
isCommodity: json['isCommodity'] ?? false,
|
||||
hasChild: json['hasChild'] ?? false,
|
||||
defaultHsn: json['defaultHsn'],
|
||||
defaultGst: (json['defaultGst'] as num?)?.toDouble(),
|
||||
huidRequired: json['huidRequired'] ?? false,
|
||||
defaultMakingCharge: (json['defaultMakingCharge'] as num?)?.toDouble(),
|
||||
makingChargeType: json['makingChargeType'],
|
||||
calculationMethod: json['calculationMethod'] ?? 'UNIT',
|
||||
baseUnit: json['baseUnit'] ?? 'pcs',
|
||||
dailyRate: (json['dailyRate'] as num?)?.toDouble(),
|
||||
isActive: json['isActive'] ?? true,
|
||||
sortOrder: json['sortOrder'] ?? 0,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -42,10 +60,16 @@ class ProductCategory {
|
||||
'userId': userId,
|
||||
'name': name,
|
||||
'parentCategoryId': parentCategoryId,
|
||||
'isCommodity': isCommodity,
|
||||
'hasChild': hasChild,
|
||||
'defaultHsn': defaultHsn,
|
||||
'defaultGst': defaultGst,
|
||||
'huidRequired': huidRequired,
|
||||
'defaultMakingCharge': defaultMakingCharge,
|
||||
'makingChargeType': makingChargeType,
|
||||
'calculationMethod': calculationMethod,
|
||||
'baseUnit': baseUnit,
|
||||
'dailyRate': dailyRate,
|
||||
'isActive': isActive,
|
||||
'sortOrder': sortOrder,
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -77,55 +101,7 @@ class ProductCategoriesNotifier extends AsyncNotifier<List<ProductCategory>> {
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> updateCategoryRate(int categoryId, double rate) async {
|
||||
try {
|
||||
final category = state.value?.firstWhere((c) => c.id == categoryId);
|
||||
if (category == null) return;
|
||||
|
||||
final updatedCategory = ProductCategory(
|
||||
id: category.id,
|
||||
userId: category.userId,
|
||||
name: category.name,
|
||||
parentCategoryId: category.parentCategoryId,
|
||||
isCommodity: category.isCommodity,
|
||||
calculationMethod: category.calculationMethod,
|
||||
baseUnit: category.baseUnit,
|
||||
dailyRate: rate,
|
||||
);
|
||||
|
||||
await DioClient().dio.put(
|
||||
'/inventory/categories/$categoryId',
|
||||
data: updatedCategory.toJson(),
|
||||
);
|
||||
state = AsyncValue.data(await _fetchCategories());
|
||||
} catch (e) {
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
|
||||
Future<int> syncRates(int categoryId) async {
|
||||
try {
|
||||
final response = await DioClient().dio.post('/inventory/categories/$categoryId/sync-rates');
|
||||
if (response.statusCode == 200 && response.data != null) {
|
||||
return response.data['syncedCount'] ?? 0;
|
||||
}
|
||||
return 0;
|
||||
} catch (e) {
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
|
||||
Future<List<dynamic>> fetchRateHistory(int categoryId) async {
|
||||
try {
|
||||
final response = await DioClient().dio.get('/inventory/categories/$categoryId/rate-history');
|
||||
if (response.statusCode == 200) {
|
||||
return response.data as List<dynamic>;
|
||||
}
|
||||
return [];
|
||||
} catch (e) {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
final productCategoriesProvider = AsyncNotifierProvider<ProductCategoriesNotifier, List<ProductCategory>>(() {
|
||||
|
||||
Reference in New Issue
Block a user