feat: Add inventory management feature with CRUD operations
- Implemented inventory screen to display items with details. - Added create, edit, and consume inventory screens for managing items. - Introduced consumption history screen to track item usage. - Created inventory repository and providers for API interactions. - Enhanced routing to include inventory-related paths. - Added necessary models for inventory items and consumption history. - Integrated error handling and loading states for better user experience.
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
class InventoryConsumption {
|
||||
final int id;
|
||||
final int inventoryItemId;
|
||||
final double amountUsed;
|
||||
final String unit;
|
||||
final String? comment;
|
||||
final DateTime createdAt;
|
||||
|
||||
const InventoryConsumption({
|
||||
required this.id,
|
||||
required this.inventoryItemId,
|
||||
required this.amountUsed,
|
||||
required this.unit,
|
||||
this.comment,
|
||||
required this.createdAt,
|
||||
});
|
||||
|
||||
factory InventoryConsumption.fromJson(Map<String, dynamic> json) {
|
||||
final itemMap = json['inventoryItem'] as Map<String, dynamic>?;
|
||||
return InventoryConsumption(
|
||||
id: json['id'] as int,
|
||||
inventoryItemId: json['inventoryItemId'] as int,
|
||||
amountUsed: double.tryParse(json['amountUsed']?.toString() ?? '0') ?? 0,
|
||||
unit: itemMap?['unit'] as String? ?? '',
|
||||
comment: json['comment'] as String?,
|
||||
createdAt: DateTime.tryParse(json['createdAt']?.toString() ?? '') ?? DateTime.now(),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
class InventoryItem {
|
||||
final int id;
|
||||
final int productId;
|
||||
final String productName;
|
||||
final double quantity;
|
||||
final String unit;
|
||||
final String? location;
|
||||
final String? brand;
|
||||
final String? purchaseDate;
|
||||
final String? bestBeforeDate;
|
||||
final bool opened;
|
||||
final String? comment;
|
||||
|
||||
const InventoryItem({
|
||||
required this.id,
|
||||
required this.productId,
|
||||
required this.productName,
|
||||
required this.quantity,
|
||||
required this.unit,
|
||||
this.location,
|
||||
this.brand,
|
||||
this.purchaseDate,
|
||||
this.bestBeforeDate,
|
||||
required this.opened,
|
||||
this.comment,
|
||||
});
|
||||
|
||||
factory InventoryItem.fromJson(Map<String, dynamic> json) {
|
||||
return InventoryItem(
|
||||
id: json['id'] as int,
|
||||
productId: json['productId'] as int,
|
||||
productName: (json['product'] as Map<String, dynamic>?)?['name'] as String? ?? '',
|
||||
quantity: double.tryParse(json['quantity']?.toString() ?? '0') ?? 0,
|
||||
unit: json['unit'] as String? ?? '',
|
||||
location: json['location'] as String?,
|
||||
brand: json['brand'] as String?,
|
||||
purchaseDate: json['purchaseDate'] as String?,
|
||||
bestBeforeDate: json['bestBeforeDate'] as String?,
|
||||
opened: json['opened'] as bool? ?? false,
|
||||
comment: json['comment'] as String?,
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user