import 'package:inventory_app/models/product.dart'; class InventoryLine { int? id; int? version; final int inventoryId; final int productId; final String productName; final double currentQty; final double realQty; final int unitId; final String? description; final String? observation; final String ticketId; final String? rack; final int? trackingNumberId; final int countingTypeSelect; final int stockLocationId; double? firstCounting; double? secondCounting; double? thirdCounting; String? firstCountingDate; String? secondCountingDate; String? thirdCountingDate; Map? firstCountingByUser; Map? secondCountingByUser; Map? thirdCountingByUser; Product? product; InventoryLine({ this.id, this.version, required this.inventoryId, required this.productId, required this.productName, required this.currentQty, required this.realQty, required this.unitId, this.description, this.observation, required this.ticketId, this.rack, this.trackingNumberId, required this.countingTypeSelect, required this.stockLocationId, required this.firstCounting, required this.secondCounting, required this.thirdCounting, this.firstCountingDate, this.secondCountingDate, this.thirdCountingDate, this.firstCountingByUser, this.secondCountingByUser, this.thirdCountingByUser, this.product }); factory InventoryLine.fromJson(Map json) { double parseDouble(dynamic value) { if (value == null) return 0.0; if (value is num) return value.toDouble(); if (value is String) return double.tryParse(value) ?? 0.0; return 0.0; } return InventoryLine( id: json['id'], version: json['version'], inventoryId: json['inventory']?['id'] ?? 0, productId: json['product']?['id'] ?? 0, productName: json['productName'] ?? '', currentQty: parseDouble(json['currentQty']), realQty: parseDouble(json['realQty']), unitId: json['unit']?['id'] ?? 0, description: json['description'], observation: json['observation'], ticketId: json['ticketId'] ?? '', rack: json['rack'], trackingNumberId: json['trackingNumber']?['id'], countingTypeSelect: json['countingTypeSelect'] ?? 0, stockLocationId: json['stockLocation']?['id'] ?? 0, firstCounting: parseDouble(json['firstCounting']), secondCounting: parseDouble(json['secondCounting']), thirdCounting: parseDouble(json['thirdCounting']), firstCountingDate: json['firstCountingDate'], secondCountingDate: json['secondCountingDate'], thirdCountingDate: json['thirdCountingDate'], firstCountingByUser: json['firstCountingByUser'] != null ? Map.from(json['firstCountingByUser']) : null, secondCountingByUser: json['secondCountingByUser'] != null ? Map.from(json['secondCountingByUser']) : null, thirdCountingByUser: json['thirdCountingByUser'] != null ? Map.from(json['thirdCountingByUser']) : null, product: json['product'] != null ? Product.fromJson(json['product']) : null ); } Map toJson() { final Map map = { if (id != null) "id": id, if (version != null) "version": version, "inventory": {"id": inventoryId}, "product": {"id": productId}, "productName": productName, "currentQty": currentQty, "realQty": realQty, "unit": {"id": unitId}, "description": description, "observation": observation, "ticketId": ticketId, "rack": rack, if (trackingNumberId != null) "trackingNumber": {"id": trackingNumberId}, "countingTypeSelect": countingTypeSelect, "stockLocation": {"id": stockLocationId}, "firstCounting": firstCounting, "secondCounting": secondCounting, "thirdCounting": thirdCounting, }; if (firstCountingDate != null) map['firstCountingDate'] = firstCountingDate; if (secondCountingDate != null) map['secondCountingDate'] = secondCountingDate; if (thirdCountingDate != null) map['thirdCountingDate'] = thirdCountingDate; if (firstCountingByUser != null) map['firstCountingByUser'] = firstCountingByUser; if (secondCountingByUser != null) map['secondCountingByUser'] = secondCountingByUser; if (thirdCountingByUser != null) map['thirdCountingByUser'] = thirdCountingByUser; return map; } @override String toString() { return 'InventoryLine{id: $id, version: $version, inventoryId: $inventoryId, productId: $productId, productName: $productName, currentQty: $currentQty, realQty: $realQty, unitId: $unitId, description: $description, observation: $observation, ticketId: $ticketId, rack: $rack, trackingNumberId: $trackingNumberId, countingTypeSelect: $countingTypeSelect, stockLocationId: $stockLocationId, firstCounting: $firstCounting, secondCounting: $secondCounting, thirdCounting: $thirdCounting, firstCountingDate: $firstCountingDate, secondCountingDate: $secondCountingDate, thirdCountingDate: $thirdCountingDate, firstCountingByUser: $firstCountingByUser, secondCountingByUser: $secondCountingByUser, thirdCountingByUser: $thirdCountingByUser}'; } }