111 lines
2.7 KiB
Dart
111 lines
2.7 KiB
Dart
class StockMovementItem {
|
|
final int? id;
|
|
final int? movementId;
|
|
final int? productId;
|
|
final double quantity;
|
|
final double? unitPrice;
|
|
|
|
final String? huid;
|
|
final double? weight;
|
|
final String? photoUrl;
|
|
final double? purchaseAmount;
|
|
|
|
StockMovementItem({
|
|
this.id,
|
|
this.movementId,
|
|
this.productId,
|
|
required this.quantity,
|
|
this.unitPrice,
|
|
|
|
this.huid,
|
|
this.weight,
|
|
this.photoUrl,
|
|
this.purchaseAmount,
|
|
});
|
|
|
|
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(),
|
|
|
|
huid: json['huid'],
|
|
weight: json['weight'] != null ? (json['weight'] as num).toDouble() : null,
|
|
photoUrl: json['photoUrl'],
|
|
purchaseAmount: json['purchaseAmount'] != null ? (json['purchaseAmount'] as num).toDouble() : null,
|
|
);
|
|
}
|
|
|
|
Map<String, dynamic> toJson() {
|
|
return {
|
|
'id': id,
|
|
'movementId': movementId,
|
|
'productId': productId,
|
|
'quantity': quantity,
|
|
'unitPrice': unitPrice,
|
|
|
|
'huid': huid,
|
|
'weight': weight,
|
|
'photoUrl': photoUrl,
|
|
'purchaseAmount': purchaseAmount,
|
|
};
|
|
}
|
|
}
|
|
|
|
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(),
|
|
};
|
|
}
|
|
}
|