marco.pms.mobileapp/lib/model/expense/expense_list_model.dart
Vaibhav Surve af83d66390 feat: Add expense models and update expense detail screen
- Created ExpenseModel, Project, ExpenseType, PaymentMode, PaidBy, CreatedBy, and Status classes for expense management.
- Implemented JSON serialization and deserialization for expense models.
- Added ExpenseStatusModel and ExpenseTypeModel for handling status and type of expenses.
- Introduced PaymentModeModel for managing payment modes.
- Refactored ExpenseDetailScreen to utilize the new ExpenseModel structure.
- Enhanced UI components for better display of expense details.
- Added search and filter functionality in ExpenseMainScreen.
- Updated dependencies in pubspec.yaml to include geocoding package.
2025-07-25 10:45:21 +05:30

269 lines
7.0 KiB
Dart

import 'dart:convert';
List<ExpenseModel> expenseModelFromJson(String str) => List<ExpenseModel>.from(
json.decode(str).map((x) => ExpenseModel.fromJson(x)));
String expenseModelToJson(List<ExpenseModel> data) =>
json.encode(List<dynamic>.from(data.map((x) => x.toJson())));
class ExpenseModel {
final String id;
final Project project;
final ExpenseType expensesType;
final PaymentMode paymentMode;
final PaidBy paidBy;
final CreatedBy createdBy;
final DateTime transactionDate;
final DateTime createdAt;
final String supplerName;
final double amount;
final Status status;
final List<Status> nextStatus;
final bool preApproved;
ExpenseModel({
required this.id,
required this.project,
required this.expensesType,
required this.paymentMode,
required this.paidBy,
required this.createdBy,
required this.transactionDate,
required this.createdAt,
required this.supplerName,
required this.amount,
required this.status,
required this.nextStatus,
required this.preApproved,
});
factory ExpenseModel.fromJson(Map<String, dynamic> json) => ExpenseModel(
id: json["id"],
project: Project.fromJson(json["project"]),
expensesType: ExpenseType.fromJson(json["expensesType"]),
paymentMode: PaymentMode.fromJson(json["paymentMode"]),
paidBy: PaidBy.fromJson(json["paidBy"]),
createdBy: CreatedBy.fromJson(json["createdBy"]),
transactionDate: DateTime.parse(json["transactionDate"]),
createdAt: DateTime.parse(json["createdAt"]),
supplerName: json["supplerName"],
amount: (json["amount"] as num).toDouble(),
status: Status.fromJson(json["status"]),
nextStatus: List<Status>.from(
json["nextStatus"].map((x) => Status.fromJson(x))),
preApproved: json["preApproved"],
);
Map<String, dynamic> toJson() => {
"id": id,
"project": project.toJson(),
"expensesType": expensesType.toJson(),
"paymentMode": paymentMode.toJson(),
"paidBy": paidBy.toJson(),
"createdBy": createdBy.toJson(),
"transactionDate": transactionDate.toIso8601String(),
"createdAt": createdAt.toIso8601String(),
"supplerName": supplerName,
"amount": amount,
"status": status.toJson(),
"nextStatus": List<dynamic>.from(nextStatus.map((x) => x.toJson())),
"preApproved": preApproved,
};
}
class Project {
final String id;
final String name;
final String shortName;
final String projectAddress;
final String contactPerson;
final DateTime startDate;
final DateTime endDate;
final String projectStatusId;
Project({
required this.id,
required this.name,
required this.shortName,
required this.projectAddress,
required this.contactPerson,
required this.startDate,
required this.endDate,
required this.projectStatusId,
});
factory Project.fromJson(Map<String, dynamic> json) => Project(
id: json["id"],
name: json["name"],
shortName: json["shortName"],
projectAddress: json["projectAddress"],
contactPerson: json["contactPerson"],
startDate: DateTime.parse(json["startDate"]),
endDate: DateTime.parse(json["endDate"]),
projectStatusId: json["projectStatusId"],
);
Map<String, dynamic> toJson() => {
"id": id,
"name": name,
"shortName": shortName,
"projectAddress": projectAddress,
"contactPerson": contactPerson,
"startDate": startDate.toIso8601String(),
"endDate": endDate.toIso8601String(),
"projectStatusId": projectStatusId,
};
}
class ExpenseType {
final String id;
final String name;
final bool noOfPersonsRequired;
final String description;
ExpenseType({
required this.id,
required this.name,
required this.noOfPersonsRequired,
required this.description,
});
factory ExpenseType.fromJson(Map<String, dynamic> json) => ExpenseType(
id: json["id"],
name: json["name"],
noOfPersonsRequired: json["noOfPersonsRequired"],
description: json["description"],
);
Map<String, dynamic> toJson() => {
"id": id,
"name": name,
"noOfPersonsRequired": noOfPersonsRequired,
"description": description,
};
}
class PaymentMode {
final String id;
final String name;
final String description;
PaymentMode({
required this.id,
required this.name,
required this.description,
});
factory PaymentMode.fromJson(Map<String, dynamic> json) => PaymentMode(
id: json["id"],
name: json["name"],
description: json["description"],
);
Map<String, dynamic> toJson() => {
"id": id,
"name": name,
"description": description,
};
}
class PaidBy {
final String id;
final String firstName;
final String lastName;
final String photo;
final String jobRoleId;
final String? jobRoleName;
PaidBy({
required this.id,
required this.firstName,
required this.lastName,
required this.photo,
required this.jobRoleId,
this.jobRoleName,
});
factory PaidBy.fromJson(Map<String, dynamic> json) => PaidBy(
id: json["id"],
firstName: json["firstName"],
lastName: json["lastName"],
photo: json["photo"],
jobRoleId: json["jobRoleId"],
jobRoleName: json["jobRoleName"],
);
Map<String, dynamic> toJson() => {
"id": id,
"firstName": firstName,
"lastName": lastName,
"photo": photo,
"jobRoleId": jobRoleId,
"jobRoleName": jobRoleName,
};
}
class CreatedBy {
final String id;
final String firstName;
final String lastName;
final String photo;
final String jobRoleId;
final String? jobRoleName;
CreatedBy({
required this.id,
required this.firstName,
required this.lastName,
required this.photo,
required this.jobRoleId,
this.jobRoleName,
});
factory CreatedBy.fromJson(Map<String, dynamic> json) => CreatedBy(
id: json["id"],
firstName: json["firstName"],
lastName: json["lastName"],
photo: json["photo"],
jobRoleId: json["jobRoleId"],
jobRoleName: json["jobRoleName"],
);
Map<String, dynamic> toJson() => {
"id": id,
"firstName": firstName,
"lastName": lastName,
"photo": photo,
"jobRoleId": jobRoleId,
"jobRoleName": jobRoleName,
};
}
class Status {
final String id;
final String name;
final String description;
final bool isSystem;
Status({
required this.id,
required this.name,
required this.description,
required this.isSystem,
});
factory Status.fromJson(Map<String, dynamic> json) => Status(
id: json["id"],
name: json["name"],
description: json["description"],
isSystem: json["isSystem"],
);
Map<String, dynamic> toJson() => {
"id": id,
"name": name,
"description": description,
"isSystem": isSystem,
};
}