Skip to content

Commit

Permalink
Add admin payment list page
Browse files Browse the repository at this point in the history
  • Loading branch information
Serious-senpai committed Dec 20, 2024
1 parent 3785fb1 commit 9f31f43
Show file tree
Hide file tree
Showing 18 changed files with 591 additions and 61 deletions.
4 changes: 3 additions & 1 deletion app/resident_manager/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ import "src/widgets/login.dart";
import "src/widgets/payment.dart";
import "src/widgets/personal_info.dart";
import "src/widgets/register.dart";
import "src/widgets/admin/fees.dart";
import "src/widgets/admin/payments.dart";
import "src/widgets/admin/reg_queue.dart";
import "src/widgets/admin/residents.dart";
import "src/widgets/admin/rooms.dart";
import "src/widgets/admin/fees.dart";

class MainApplication extends StateAwareWidget {
const MainApplication({super.key, required super.state});
Expand Down Expand Up @@ -49,6 +50,7 @@ class _MainApplicationState extends AbstractCommonState<MainApplication> {
ApplicationRoute.adminResidentsPage: (context) => ResidentsPage(state: state),
ApplicationRoute.adminRoomsPage: (context) => RoomsPage(state: state),
ApplicationRoute.adminFeesPage: (context) => FeeListPage(state: state),
ApplicationRoute.adminPaymentsPage: (context) => PaymentListPage(state: state),
},
initialRoute: initialRoute,
localizationsDelegates: state.localization.localizationsDelegates,
Expand Down
35 changes: 35 additions & 0 deletions app/resident_manager/lib/src/models/payment_status.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@ class PaymentStatus {
final double lowerBound;
final double upperBound;
final Payment? payment;
final int room;

PaymentStatus({
required this.fee,
required this.lowerBound,
required this.upperBound,
required this.payment,
required this.room,
});

PaymentStatus.fromJson(dynamic data)
Expand All @@ -24,6 +26,7 @@ class PaymentStatus {
lowerBound: data["lower_bound"] as double,
upperBound: data["upper_bound"] as double,
payment: data["payment"] == null ? null : Payment.fromJson(data["payment"]),
room: data["room"] as int,
);

static Future<Result<int?>> count({
Expand Down Expand Up @@ -74,4 +77,36 @@ class PaymentStatus {

return Result(result["code"], null);
}

static Future<Result<List<PaymentStatus>?>> adminQuery({
required ApplicationState state,
required int? room,
required bool? paid,
required int offset,
required DateTime createdAfter,
required DateTime createdBefore,
}) async {
if (!state.loggedInAsAdmin) {
return Result(-1, null);
}

final response = await state.get(
"/api/v1/admin/fees/payments",
queryParameters: {
if (room != null) "room": room.toString(),
if (paid != null) "paid": paid.toString(),
"offset": offset.toString(),
"created_after": createdAfter.toUtc().toIso8601String(),
"created_before": createdBefore.toUtc().toIso8601String(),
},
);
final result = json.decode(utf8.decode(response.bodyBytes));

if (result["code"] == 0) {
final data = result["data"] as List<dynamic>;
return Result(0, List<PaymentStatus>.from(data.map(PaymentStatus.fromJson)));
}

return Result(result["code"], null);
}
}
1 change: 1 addition & 0 deletions app/resident_manager/lib/src/routes.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ class ApplicationRoute {
static const String adminResidentsPage = "/admin/residents";
static const String adminRoomsPage = "/admin/rooms";
static const String adminFeesPage = "/admin/fees";
static const String adminPaymentsPage = "/admin/payments";
}
6 changes: 6 additions & 0 deletions app/resident_manager/lib/src/translations.dart
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ class AppLocale {
static const String FeePerMotorbike = "FeePerMotorbike";
static const String FeePerCar = "FeePerCar";
static const String OK = "OK";
static const String PaidTimestamp = "PaidTimestamp";
static const String PaymentList = "PaymentList";

// Error codes
static const String Error0 = "Error0";
Expand Down Expand Up @@ -273,6 +275,8 @@ class AppLocale {
FeePerMotorbike: "Fee per motorbike",
FeePerCar: "Fee per car",
OK: "OK",
PaidTimestamp: "Paid timestamp",
PaymentList: "Payment list",

// Error codes
Error0: "Operation completed successfully.",
Expand Down Expand Up @@ -425,6 +429,8 @@ class AppLocale {
FeePerMotorbike: "Phí theo số lượng xe máy",
FeePerCar: "Phí theo số lượng ô tô",
OK: "OK",
PaidTimestamp: "Thời gian thanh toán",
PaymentList: "Danh sách thanh toán",

// Error codes
Error0: "Thao tác thành công.",
Expand Down
14 changes: 14 additions & 0 deletions app/resident_manager/lib/src/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,20 @@ DateTime snowflakeTime(int id) => fromEpoch(Duration(milliseconds: id >> 16));

String formatDateTime(DateTime time) => "${time.day}/${time.month}/${time.year} ${time.hour}:${time.minute}:${time.second}";

String formatVND(num value) {
final str = value.round().toString();
final buffer = StringBuffer();

for (int i = 0; i < str.length; i++) {
if (i > 0 && (str.length - i) % 3 == 0) {
buffer.write(",");
}
buffer.write(str[i]);
}

return buffer.toString();
}

String? nameValidator(BuildContext context, {required bool required, required String? value}) {
if (value == null || value.isEmpty) {
if (required) {
Expand Down
10 changes: 5 additions & 5 deletions app/resident_manager/lib/src/widgets/admin/fees.dart
Original file line number Diff line number Diff line change
Expand Up @@ -646,11 +646,11 @@ class _FeeListPageState extends AbstractCommonState<FeeListPage> with CommonScaf
formatDateTime(f.createdAt.toLocal()),
f.deadline.format("dd/mm/yyyy"),
f.description,
f.lower.round().toString(),
f.upper.round().toString(),
f.perArea.round().toString(),
f.perMotorbike.round().toString(),
f.perCar.round().toString(),
formatVND(f.lower),
formatVND(f.upper),
formatVND(f.perArea),
formatVND(f.perMotorbike),
formatVND(f.perCar),
];

return DataRow2(
Expand Down
Loading

0 comments on commit 9f31f43

Please sign in to comment.