86 lines
2.1 KiB
Dart
86 lines
2.1 KiB
Dart
class StockMovementItem {
|
|
final int? id;
|
|
final int? movementId;
|
|
final int? productId;
|
|
final double quantity;
|
|
final double? unitPrice;
|
|
|
|
StockMovementItem({
|
|
this.id,
|
|
this.movementId,
|
|
this.productId,
|
|
required this.quantity,
|
|
this.unitPrice,
|
|
});
|
|
|
|
factory StockMovementItem.fromJson(Map<String, dynamic> json) {
|
|
return StockMovementItem(
|
|
id: json['id'],
|
|
movementId: json['movementId'],
|
|
productId: json['productId'],
|
|
quantity: (json['quantity'] as num).toDouble(),
|
|
unitPrice: (json['unitPrice'] as num?)?.toDouble(),
|
|
);
|
|
}
|
|
|
|
Map<String, dynamic> toJson() {
|
|
return {
|
|
'id': id,
|
|
'movementId': movementId,
|
|
'productId': productId,
|
|
'quantity': quantity,
|
|
'unitPrice': unitPrice,
|
|
};
|
|
}
|
|
}
|
|
|
|
class StockMovement {
|
|
final int? id;
|
|
final int? userId;
|
|
final int? locationId;
|
|
final String type; // OPENING, ADDITION, REDUCTION, ADJUSTMENT, DAMAGE, SALE, RETURN
|
|
final int? referenceTransactionId;
|
|
final String? notes;
|
|
final DateTime? createdAt;
|
|
final List<StockMovementItem>? items;
|
|
|
|
StockMovement({
|
|
this.id,
|
|
this.userId,
|
|
this.locationId,
|
|
required this.type,
|
|
this.referenceTransactionId,
|
|
this.notes,
|
|
this.createdAt,
|
|
this.items,
|
|
});
|
|
|
|
factory StockMovement.fromJson(Map<String, dynamic> json) {
|
|
return StockMovement(
|
|
id: json['id'],
|
|
userId: json['userId'],
|
|
locationId: json['locationId'],
|
|
type: json['type'],
|
|
referenceTransactionId: json['referenceTransactionId'],
|
|
notes: json['notes'],
|
|
createdAt: json['createdAt'] != null ? DateTime.parse(json['createdAt']) : null,
|
|
items: json['items'] != null
|
|
? (json['items'] as List).map((i) => StockMovementItem.fromJson(i)).toList()
|
|
: null,
|
|
);
|
|
}
|
|
|
|
Map<String, dynamic> toJson() {
|
|
return {
|
|
'id': id,
|
|
'userId': userId,
|
|
'locationId': locationId,
|
|
'type': type,
|
|
'referenceTransactionId': referenceTransactionId,
|
|
'notes': notes,
|
|
if (createdAt != null) 'createdAt': createdAt!.toIso8601String(),
|
|
if (items != null) 'items': items!.map((i) => i.toJson()).toList(),
|
|
};
|
|
}
|
|
}
|