Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfixes/reports #12

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions firebase.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"flutter":{"platforms":{"android":{"default":{"projectId":"dev-pratikm-project","appId":"1:1089445798939:android:74f628c1ed52d3d33344be","fileOutput":"android/app/google-services.json"}},"dart":{"lib/firebase_options.dart":{"projectId":"dev-pratikm-project","configurations":{"android":"1:1089445798939:android:74f628c1ed52d3d33344be","ios":"1:1089445798939:ios:0b966a6f94d1d7e63344be","macos":"1:1089445798939:ios:0b966a6f94d1d7e63344be","web":"1:1089445798939:web:54a17f777992b8893344be","windows":"1:1089445798939:web:8a7550a05168a5813344be"}}}}}}
4 changes: 4 additions & 0 deletions lib/common/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ class AppUtils {
return "${dt.day}-${AppConstants.cEnMonthsStr[dt.month - 1]}-${dt.year}";
}

static String getHumanReadableMonthDt(DateTime dt) {
return "${AppConstants.cEnMonthsStr[dt.month - 1]} ${dt.year}";
}

static String getReadableTrxPeriod(DateTime dt) {
return "${dt.day}-${AppConstants.cEnMonthsStr[dt.month - 1]}-${dt.year}";
}
Expand Down
50 changes: 47 additions & 3 deletions lib/features/groups/dao/groups_dao.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
* Proprietary and confidential
* Author: Pratik Mohite <[email protected]>
*/
import 'dart:async';

import 'package:bachat_gat/common/constants.dart';
import 'package:bachat_gat/common/utils.dart';

Expand Down Expand Up @@ -46,6 +48,12 @@ class GroupsDao {
return groups;
}

// Future<List<MemberList>?> getMemberList() async {
// var query = await dbService.read("select * from $memberTableName");
// var members = query.map((e) => MemberList.fromJson(e)).toList();
// return members;
// }

Future<int> addGroupMember(GroupMember member) async {
var row = await dbService.insert(memberTableName, member.toJson());
return row;
Expand All @@ -68,6 +76,12 @@ class GroupsDao {
return transactions;
}

Future<List<TransactionList>> getTransactionList() async {
var rows = await dbService.read("select * from $transactionTableName");
var tranasctions = rows.map((e) => TransactionList.fromJson(e)).toList();
return tranasctions;
}

Future<int> addTransaction(Transaction trx) async {
var row = await dbService.insert(transactionTableName, trx.toJson());
if (trx.trxType == AppConstants.ttLoan ||
Expand Down Expand Up @@ -116,6 +130,7 @@ class GroupsDao {
"paidLoanAmount = ($trxQuery), "
"paidInterestAmount = ($trxQuery) "
"where id = ?";

List<String> pars = [
AppConstants.ttLoan,
AppConstants.sLoan,
Expand All @@ -125,7 +140,15 @@ class GroupsDao {
loanId,
loanId
];

var row = await dbService.write(query, pars);

var updateStatus = "update $loanTableName set "
" status = case when paidLoanAmount >= loanAmount then '${AppConstants.lsComplete}' else '${AppConstants.lsActive}' end "
" where id= ? ";

var row1 = await dbService.write(updateStatus, [loanId]);

return row;
}

Expand All @@ -150,16 +173,17 @@ class GroupsDao {

Future<int> updateLoanPaid(Loan loan) async {
String updateQuery = "update loans set "
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is not going to work check query params

"paidLoanAmount = paidLoanAmount + ?, "
"note = ?, "
"paidInterestAmount = paidInterestAmount + ?, "
"status = case when paidLoanAmount>=loanAmount then ${AppConstants.lsComplete} else ${AppConstants.lsActive} end"
// "status = iif(paidLoanAmount >= loanAmount, '${AppConstants.lsComplete}', '${AppConstants.lsActive}') "
"status = case when paidLoanAmount+?>=loanAmount then ${AppConstants.lsComplete} else ${AppConstants.lsActive} end "
"where id = ?";

var row = await dbService.write(
updateQuery,
[
loan.paidLoanAmount,
loan.paidInterestAmount,
loan.paidLoanAmount,
loan.id,
],
);
Expand All @@ -186,6 +210,12 @@ class GroupsDao {
return members;
}

Future<List<Loan>> getLoans() async {
var rows = await dbService.read("select * from ${loanTableName};");
var loans = rows.map((e) => Loan.fromJson(e)).toList();
return loans;
}

Future<List<Loan>> getMemberLoans(MemberLoanFilter filter) async {
String selectClause = "select * "
"from $loanTableName ";
Expand Down Expand Up @@ -389,6 +419,20 @@ class GroupsDao {
return 0.0; // Default value if no result
}

Future<String?> getLastLoanInterestDate(GroupMemberDetails filter) async {
var query = """
SELECT trxPeriod from transactions where memberId=? and groupId=? order by trxPeriod desc limit 1 ;
""";
var result = await dbService.read(query, [filter.memberId, filter.groupId]);
DateTime currentMonth = DateTime.now();
String date = AppUtils.getTrxPeriodFromDt(currentMonth);
if (result.isNotEmpty) {
String? dateFinal = (result.first["trxPeriod"] as String?)?.toString();
return dateFinal;
}
return date;
}

String getAmountQuery(String trxType, String trxPeriod,
[String mode = "cr"]) {
String column = "t.cr";
Expand Down
6 changes: 0 additions & 6 deletions lib/features/groups/models/common/com_fields.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 0 additions & 6 deletions lib/features/groups/models/common/group.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 0 additions & 6 deletions lib/features/groups/models/common/group_members.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 0 additions & 6 deletions lib/features/groups/models/common/loan.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

79 changes: 79 additions & 0 deletions lib/features/groups/models/common/loans.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*
* Copyright (C) 2024-present Pratik Mohite, Inc - All Rights Reserved
* Unauthorized copying of this file, via any medium is strictly prohibited
* Proprietary and confidential
* Author: Pratik Mohite <[email protected]>
*/
import 'package:json_annotation/json_annotation.dart';

import 'com_fields.dart';

part 'loans.g.dart';

@JsonSerializable()
class LoansList extends ComFields {
String id = "";
String memberId = "";
String groupId = "";
double loanAmount = 0.0;
double interestPercentage = 0.0;
double paidLoanAmount = 0.0;
double paidInterestAmount = 0.0;
String note = "";
String status = "";
String addedBy = "";
DateTime loanDate = DateTime(2024, 1, 1);
late DateTime sysCreated;
late DateTime sysUpdated;

LoansList({
required this.id,
required this.memberId,
required this.groupId,
required this.loanAmount,
required this.interestPercentage,
required this.paidLoanAmount,
required this.paidInterestAmount,
required this.status,
required this.addedBy,
this.note = "",
DateTime? loanDate,
DateTime? sysCreated,
DateTime? sysUpdated,
}) {
this.loanDate = loanDate ?? DateTime.now();
this.sysCreated = sysCreated ?? DateTime.now();
this.sysUpdated = sysUpdated ?? DateTime.now();
}

LoansList.withEmpty() {
loanDate = DateTime.now();
sysCreated = DateTime.now();
sysUpdated = DateTime.now();
}

LoansList.withDefault({
required this.id,
required this.memberId,
required this.groupId,
required this.loanAmount,
required this.interestPercentage,
required this.paidInterestAmount,
required this.status,
this.addedBy = "Admin",
this.note = "",
DateTime? laonDate,
DateTime? sysCreated,
DateTime? sysUpdated,
}) {
this.loanDate = loanDate ?? DateTime.now();
sysCreated = DateTime.now();
sysUpdated = DateTime.now();
}

factory LoansList.fromJson(Map<String, dynamic> json) =>
_$LoansListFromJson(json);

@override
Map<String, dynamic> toJson() => _$LoansListToJson(this);
}
45 changes: 45 additions & 0 deletions lib/features/groups/models/common/loans.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 0 additions & 6 deletions lib/features/groups/models/common/transaction.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

84 changes: 84 additions & 0 deletions lib/features/groups/models/common/transaction_list.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/*
* Copyright (C) 2024-present Pratik Mohite, Inc - All Rights Reserved
* Unauthorized copying of this file, via any medium is strictly prohibited
* Proprietary and confidential
* Author: Pratik Mohite <[email protected]>
*/
import 'package:bachat_gat/common/common_index.dart';
import 'package:json_annotation/json_annotation.dart';

import 'com_fields.dart';

part 'transaction_list.g.dart';

@JsonSerializable()
class TransactionList extends ComFields {
String memberId = "";
String groupId = "";
String trxType = "";
late DateTime trxDt;
String trxPeriod = "";
double cr = 0;
double dr = 0;
String sourceType = "";
String sourceId = "";
String addedBy = "";
String note = "";
String id = "";
late DateTime sysCreated;
late DateTime sysUpdated;

TransactionList({
required this.id,
required this.memberId,
required this.groupId,
required this.trxType,
required this.trxPeriod,
required this.cr,
required this.dr,
required this.sourceType,
required this.sourceId,
required this.addedBy,
this.note = "",
DateTime? trxDt,
DateTime? sysCreated,
DateTime? sysUpdated,
}) {
this.trxDt = trxDt ?? DateTime.now();
this.sysCreated = sysCreated ?? DateTime.now();
this.sysUpdated = sysUpdated ?? DateTime.now();
}

TransactionList.withEmpty() {
trxDt = DateTime.now();
sysCreated = DateTime.now();
sysUpdated = DateTime.now();
trxPeriod = AppUtils.getTrxPeriodFromDt(trxDt);
}

TransactionList.withDefault({
required this.memberId,
required this.groupId,
required this.trxType,
required this.trxPeriod,
this.cr = 0,
this.dr = 0,
this.sourceId = "",
this.sourceType = AppConstants.sUser,
this.addedBy = "Admin",
this.note = "",
DateTime? trxDt,
DateTime? sysCreated,
DateTime? sysUpdated,
}) {
this.trxDt = trxDt ?? DateTime.now();
sysCreated = DateTime.now();
sysUpdated = DateTime.now();
}

factory TransactionList.fromJson(Map<String, dynamic> json) =>
_$TransactionListFromJson(json);

@override
Map<String, dynamic> toJson() => _$TransactionListToJson(this);
}
Loading