84 lines
1.9 KiB
Dart
84 lines
1.9 KiB
Dart
import 'package:marco/model/inventory/requisition_item_model.dart';
|
|
|
|
class MaterialRequisition {
|
|
int? mrId;
|
|
String? title;
|
|
int? projectId;
|
|
String? projectName;
|
|
String? status;
|
|
String? createdBy;
|
|
DateTime? createdAt;
|
|
List<RequisitionItem>? items;
|
|
|
|
// ✅ Add backward-compatible aliases
|
|
int? get id => mrId;
|
|
int? get requisitionId => mrId;
|
|
|
|
MaterialRequisition({
|
|
this.mrId,
|
|
this.title,
|
|
this.projectId,
|
|
this.projectName,
|
|
this.status,
|
|
this.createdBy,
|
|
this.createdAt,
|
|
this.items,
|
|
});
|
|
|
|
factory MaterialRequisition.fromJson(Map<String, dynamic> json) {
|
|
return MaterialRequisition(
|
|
mrId: json['mrId'] ?? json['id'] ?? json['requisitionId'],
|
|
title: json['title'],
|
|
projectId: json['projectId'] is String
|
|
? int.tryParse(json['projectId'])
|
|
: json['projectId'],
|
|
projectName: json['projectName'],
|
|
status: json['status'],
|
|
createdBy: json['createdBy'],
|
|
createdAt: json['createdAt'] != null
|
|
? DateTime.tryParse(json['createdAt'])
|
|
: null,
|
|
items: json['items'] != null
|
|
? (json['items'] as List)
|
|
.map((e) => RequisitionItem.fromJson(e))
|
|
.toList()
|
|
: [],
|
|
);
|
|
}
|
|
|
|
Map<String, dynamic> toJson() {
|
|
return {
|
|
'mrId': mrId,
|
|
'title': title,
|
|
'projectId': projectId,
|
|
'projectName': projectName,
|
|
'status': status,
|
|
'createdBy': createdBy,
|
|
'createdAt': createdAt?.toIso8601String(),
|
|
'items': items?.map((e) => e.toJson()).toList(),
|
|
};
|
|
}
|
|
}
|
|
|
|
class Project {
|
|
int? id;
|
|
String? name;
|
|
String? code;
|
|
|
|
Project({this.id, this.name, this.code});
|
|
|
|
factory Project.fromJson(Map<String, dynamic> json) {
|
|
return Project(
|
|
id: json['id'],
|
|
name: json['name'] ?? json['projectName'],
|
|
code: json['code'] ?? json['projectCode'],
|
|
);
|
|
}
|
|
|
|
Map<String, dynamic> toJson() => {
|
|
'id': id,
|
|
'name': name,
|
|
'code': code,
|
|
};
|
|
}
|