diff --git a/lib/cdTransactionDetails.dart b/lib/cdTransactionDetails.dart index d847a9f..b0c5ca4 100644 --- a/lib/cdTransactionDetails.dart +++ b/lib/cdTransactionDetails.dart @@ -9,6 +9,7 @@ import 'package:google_fonts/google_fonts.dart'; import 'package:http/http.dart' as http; import 'package:intl/intl.dart'; import 'package:nhancepolicy/service/api_service.dart'; +import 'package:shared_preferences/shared_preferences.dart'; import 'package:universal_html/html.dart' as html; import '../../models/environment.dart'; @@ -31,9 +32,7 @@ class cdTransactionDetails extends StatefulWidget { required this.insurerId, required this.cd_ac_pk, required this.empClientId, - required this.postToken - } - ); + required this.postToken}); @override State createState() => _cdTransactionDetailsState(); @@ -70,7 +69,7 @@ class _cdTransactionDetailsState extends State { List get _paginatedData { final startIndex = (_currentPage - 1) * _rowsPerPage; final endIndex = - (_currentPage * _rowsPerPage).clamp(0, filteredData.length); + (_currentPage * _rowsPerPage).clamp(0, filteredData.length); return filteredData.sublist(startIndex, endIndex); } @@ -93,14 +92,15 @@ class _cdTransactionDetailsState extends State { }); try { print('10'); - final response = await apiService.getCdTransactionData( - widget.empClientId, widget.insurerId,widget.cd_ac_pk, widget.postToken); + final response = await apiService.getCdTransactionData(widget.empClientId, + widget.insurerId, widget.cd_ac_pk, widget.postToken); if (response['status'] == 'success') { setState(() { isLoading = false; }); setState(() { - getCDTransData = List>.from(response['data']['deposit_data']); + getCDTransData = + List>.from(response['data']['deposit_data']); originalData = getCDTransData; filteredData = List.from(originalData); total_deposit = response['data']['total_deposit']; @@ -204,7 +204,19 @@ class _cdTransactionDetailsState extends State { List> rows = []; // Header - rows.add(['Date', 'Record Date', 'Unit','Policy','Endorsement No','Sub Type','Credit','Debit','Balance','Description','User']); + rows.add([ + 'Date', + 'Record Date', + 'Unit', + 'Policy', + 'Endorsement No', + 'Sub Type', + 'Credit', + 'Debit', + 'Balance', + 'Description', + 'User' + ]); // Data rows for (var item in data) { @@ -212,8 +224,10 @@ class _cdTransactionDetailsState extends State { item['created_at'] ?? '', item['record_date'] ?? '', item['unit'] ?? '', - item['policy_type'] != null && item['policy_type'].toString().trim().isNotEmpty && - item['policy_no'] != null && item['policy_no'].toString().trim().isNotEmpty + item['policy_type'] != null && + item['policy_type'].toString().trim().isNotEmpty && + item['policy_no'] != null && + item['policy_no'].toString().trim().isNotEmpty ? '${item['policy_type']} - ${item['policy_no']}' : '-', item['endorsement_no'] ?? '', @@ -237,6 +251,35 @@ class _cdTransactionDetailsState extends State { ..setAttribute("download", "CD_Policies.csv") ..click(); html.Url.revokeObjectUrl(url); + handleExportAction(); + } + + Future handleExportAction() async { + print('handleExportAction'); + + final SharedPreferences prefs = await SharedPreferences.getInstance(); + final postId = prefs.getString('empHrId'); + final preId = prefs.getString('enrollmentEmpPrimaryId'); + var activity = "export_cdsummary"; + + print('postId - $postId'); + print('preId - $preId'); + print('activity - $activity'); + + try { + print('10'); + final response = await apiService.getPostLogHrActivity( + postId!, preId!, widget.postToken, activity); + if (response['status'] == 'success') { + print('Request success'); + } else { + // ToastHelper.showWarningToast( + // context, 'Request failed with status: ${response.statusCode}'); + print('Request failed with status: ${response['code']}'); + } + } catch (e) { + print('Exception occurred: $e'); + } } String formatDate(String? dateString) { @@ -263,31 +306,31 @@ class _cdTransactionDetailsState extends State { } } - @override Widget build(BuildContext context) { // TODO: implement build return Scaffold( appBar: CustomAppBar(), backgroundColor: Color(0xFFEFF3F6), - body: Stack( - children: [ - SingleChildScrollView( - child: Container( - padding: - EdgeInsets.only(top: 30, bottom: 200, left: 50, right: 50), + body: Stack(children: [ + SingleChildScrollView( + child: Container( + padding: EdgeInsets.only( + top: 30, bottom: 200, left: 50, right: 50), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ MouseRegion( - cursor: SystemMouseCursors.click, // 👈 shows pointer on hover + cursor: SystemMouseCursors + .click, // 👈 shows pointer on hover child: GestureDetector( onTap: () { Navigator.pop(context); // or your desired action }, child: Row( children: [ - Icon(Icons.arrow_back_ios_new_outlined, color: Color(0xFF707070)), + Icon(Icons.arrow_back_ios_new_outlined, + color: Color(0xFF707070)), SizedBox(width: 8), Expanded( child: Text( @@ -307,18 +350,22 @@ class _cdTransactionDetailsState extends State { Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ - _buildInfoCard('Deposits', '₹$total_deposit', Color(0xFF39D45B), Icons.arrow_upward), - _buildInfoCard('Consumed', '₹$total_consumed', Color(0xFFED1D24), Icons.arrow_downward), - _buildInfoCard('Refund', '₹$total_refund', Color(0xFF39D45B), Icons.arrow_upward), - _buildInfoCard('Current Balance', '₹$currect_balance', Colors.black, null), + _buildInfoCard('Deposits', '₹$total_deposit', + Color(0xFF39D45B), Icons.arrow_upward), + _buildInfoCard('Consumed', '₹$total_consumed', + Color(0xFFED1D24), Icons.arrow_downward), + _buildInfoCard('Refund', '₹$total_refund', + Color(0xFF39D45B), Icons.arrow_upward), + _buildInfoCard('Current Balance', '₹$currect_balance', + Colors.black, null), ], ), SizedBox(height: 16), Container( decoration: BoxDecoration( color: Colors.white, - borderRadius: - BorderRadius.circular(10), // 👈 set your desired radius + borderRadius: BorderRadius.circular( + 10), // 👈 set your desired radius ), // height: 400, padding: const EdgeInsets.all(16.0), @@ -340,7 +387,8 @@ class _cdTransactionDetailsState extends State { child: TextField( decoration: InputDecoration( hintText: 'Search', - prefixIcon: Icon(Icons.search, size: 18), + prefixIcon: + Icon(Icons.search, size: 18), contentPadding: EdgeInsets.symmetric( horizontal: 12, vertical: 8), border: InputBorder @@ -348,7 +396,8 @@ class _cdTransactionDetailsState extends State { ), controller: searchController, onChanged: search, - style: GoogleFonts.poppins(fontSize: 14), + style: + GoogleFonts.poppins(fontSize: 14), ), ), ), @@ -368,10 +417,12 @@ class _cdTransactionDetailsState extends State { }, style: ElevatedButton.styleFrom( backgroundColor: Color(0xFFE26728), - padding: EdgeInsets.all(10), // Internal padding + padding: EdgeInsets.all( + 10), // Internal padding shape: RoundedRectangleBorder( borderRadius: - BorderRadius.circular(10), // Border radius + BorderRadius.circular( + 10), // Border radius side: BorderSide( color: Colors .transparent, // Optional border color @@ -409,33 +460,30 @@ class _cdTransactionDetailsState extends State { ), ) ], - ) - ) - ), - if (isLoading) - Container( - color: Color(0x98FFFCE5), // Semi-transparent background - child: Center( - child: // Your GIF loader widget + ))), + if (isLoading) + Container( + color: Color(0x98FFFCE5), // Semi-transparent background + child: Center( + child: // Your GIF loader widget Image.asset( height: 60, width: 60, 'assets/nhance-loader.gif'), // Adjust path to your GIF loader - ), - ), - Align( - alignment: Alignment.bottomCenter, - child: Container( - width: double.infinity, // Make the footer full width - child: CustomFooter(), - ), ), - ] - ) - ); + ), + Align( + alignment: Alignment.bottomCenter, + child: Container( + width: double.infinity, // Make the footer full width + child: CustomFooter(), + ), + ), + ])); } - Widget _buildInfoCard(String label, String value, Color iconColor, IconData? icon) { + Widget _buildInfoCard( + String label, String value, Color iconColor, IconData? icon) { return Expanded( child: Container( margin: EdgeInsets.symmetric(horizontal: 4), @@ -454,23 +502,26 @@ class _cdTransactionDetailsState extends State { child: Column( children: [ Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, // label left, value right + mainAxisAlignment: + MainAxisAlignment.spaceBetween, // label left, value right children: [ Text( label, - style: GoogleFonts.poppins(color: Color(0xFF737373), fontSize: 14,fontWeight: FontWeight.w400), + style: GoogleFonts.poppins( + color: Color(0xFF737373), + fontSize: 14, + fontWeight: FontWeight.w400), textAlign: TextAlign.left, ), Row( children: [ - if (icon != null) - Icon(icon, size: 20, color: iconColor), + if (icon != null) Icon(icon, size: 20, color: iconColor), if (icon != null) SizedBox(width: 4), Text( value, style: GoogleFonts.poppins( fontSize: 14, - fontWeight: FontWeight.w400 , + fontWeight: FontWeight.w400, color: Color(0xFF000000), ), ), @@ -484,7 +535,6 @@ class _cdTransactionDetailsState extends State { ); } - Widget _buildCDDataTable(BuildContext context) { if (filteredData.isEmpty) { return const SizedBox( @@ -622,7 +672,7 @@ class _cdTransactionDetailsState extends State { border: Border( bottom: BorderSide( color: Color(0xFFD7E9EB), // 👈 Bottom border color - width: 1, // 👈 Optional: thickness + width: 1, // 👈 Optional: thickness ), ), ), @@ -657,8 +707,10 @@ class _cdTransactionDetailsState extends State { flex: 3, child: Text( // 'Motor - 3001/379707905/00/000', - item['policy_type'] != null && item['policy_type'].toString().trim().isNotEmpty && - item['policy_no'] != null && item['policy_no'].toString().trim().isNotEmpty + item['policy_type'] != null && + item['policy_type'].toString().trim().isNotEmpty && + item['policy_no'] != null && + item['policy_no'].toString().trim().isNotEmpty ? '${item['policy_type']} - ${item['policy_no']}' : '-', textAlign: TextAlign.left, @@ -684,7 +736,9 @@ class _cdTransactionDetailsState extends State { Expanded( flex: 2, child: Text( - item['transaction_type'] == 'Credit' ? '₹${item['amount']}' : '-', + item['transaction_type'] == 'Credit' + ? '₹${item['amount']}' + : '-', textAlign: TextAlign.left, style: GoogleFonts.poppins(color: Color(0xFF000000)), ), @@ -692,7 +746,9 @@ class _cdTransactionDetailsState extends State { Expanded( flex: 2, child: Text( - item['transaction_type'] == 'Debit' ? '₹${item['amount']}' : '-', + item['transaction_type'] == 'Debit' + ? '₹${item['amount']}' + : '-', textAlign: TextAlign.left, style: GoogleFonts.poppins(color: Color(0xFF000000)), ), @@ -755,16 +811,16 @@ class _cdTransactionDetailsState extends State { IconButton( onPressed: _currentPage > 1 ? () { - setState(() { - _currentPage--; - }); - } + setState(() { + _currentPage--; + }); + } : null, icon: Icon(Icons.chevron_left), ), for (int i = 1; - i <= (filteredData.length / _rowsPerPage).ceil(); - i++) + i <= (filteredData.length / _rowsPerPage).ceil(); + i++) Padding( padding: const EdgeInsets.symmetric(horizontal: 4), child: ElevatedButton( @@ -773,7 +829,7 @@ class _cdTransactionDetailsState extends State { ? Color(0xFF00A6A6) : Colors.grey[300], foregroundColor: - _currentPage == i ? Colors.white : Colors.black, + _currentPage == i ? Colors.white : Colors.black, minimumSize: Size(36, 36), padding: EdgeInsets.zero, ), @@ -787,12 +843,12 @@ class _cdTransactionDetailsState extends State { ), IconButton( onPressed: _currentPage < - (filteredData.length / _rowsPerPage).ceil() + (filteredData.length / _rowsPerPage).ceil() ? () { - setState(() { - _currentPage++; - }); - } + setState(() { + _currentPage++; + }); + } : null, icon: Icon(Icons.chevron_right), ), @@ -806,8 +862,6 @@ class _cdTransactionDetailsState extends State { } } - - // Sample Data class representing each element in the array class Data { final dynamic value; diff --git a/lib/hrPolicyDetails.dart b/lib/hrPolicyDetails.dart index 4100a7a..a1b67b3 100755 --- a/lib/hrPolicyDetails.dart +++ b/lib/hrPolicyDetails.dart @@ -279,6 +279,45 @@ class _HrPolicyDetailsState extends State ..setAttribute("download", "CD_Policies.csv") ..click(); html.Url.revokeObjectUrl(url); + handleExportAction(); + } + + Future handleExportAction() async { + print('handleExportAction'); + + final SharedPreferences prefs = await SharedPreferences.getInstance(); + final postId = prefs.getString('empHrId'); + final preId = prefs.getString('enrollmentEmpPrimaryId'); + var activity = "export_empdata"; + + var activityPre = "export_preempdata"; + dynamic response; + + print('postId - $postId'); + print('preId - $preId'); + print('activity - $activity'); + + try { + print('10'); + + if (widget.TokenType == 'pre') { + response = await apiService.getPreLogHrActivity( + postId!, preId!, widget.Token, activityPre); + } else if (widget.TokenType == 'post') { + response = await apiService.getPostLogHrActivity( + postId!, preId!, widget.Token, activity); + } + + if (response['status'] == 'success') { + print('Request success'); + } else { + // ToastHelper.showWarningToast( + // context, 'Request failed with status: ${response.statusCode}'); + print('Request failed with status: ${response['code']}'); + } + } catch (e) { + print('Exception occurred: $e'); + } } String _capitalize(String? value) { @@ -359,8 +398,9 @@ class _HrPolicyDetailsState extends State ), ), Text( - widget.TokenType == 'pre' ? "${widget.cardPolicy_name} (${widget.cardPolicy_ExpDate})" : - "${widget.cardInsurer_name} - ${widget.cardPolicy_name} (${widget.cardPolicy_ExpDate})", + widget.TokenType == 'pre' + ? "${widget.cardPolicy_name} (${widget.cardPolicy_ExpDate})" + : "${widget.cardInsurer_name} - ${widget.cardPolicy_name} (${widget.cardPolicy_ExpDate})", style: GoogleFonts.poppins( color: Colors.grey, fontSize: 12, diff --git a/lib/service/api_service.dart b/lib/service/api_service.dart index 0f86db3..4504e41 100755 --- a/lib/service/api_service.dart +++ b/lib/service/api_service.dart @@ -461,6 +461,81 @@ class ApiService { return response; } + Future> getPostLogHrActivity( + String? postId, String? preId, String token, String activity) async { + print("getCashDepositDetailsToApi1"); + + print('postId1 - $postId'); + print('preId1 - $preId'); + print('activity1 - $activity'); + + // final url = Uri.parse( + // '${Environment.apiUrlPost}logHrActivity?user_id=$postId&pre_hr_id=$preId&user_type=hr&activity=$activity'); + + final url = Uri.parse('${Environment.apiUrlPost}logHrActivity'); + + final headers = { + 'Authorization': 'Bearer $token' ?? '', + }; + + final body = { + 'user_id': postId, + 'pre_hr_id': preId, + 'user_type': 'hr', + 'activity': activity, + }; + + final response = await http.post( + url, + headers: headers, + body: jsonEncode(body), + ); + + // final response = await _makeGetRequest(url, headers); + if (response.statusCode == 200) { + return jsonDecode(response.body); + } else { + throw Exception( + 'Failed to log HR activity: ${response.statusCode} ${response.body}'); + } + } + + Future> getPreLogHrActivity( + String? postId, String? preId, String token, String activity) async { + print("getCashDepositDetailsToApi1"); + + print('postId1 - $postId'); + print('preId1 - $preId'); + print('activity1 - $activity'); + + final url = Uri.parse('${Environment.apiUrl}logHrActivity'); + + final headers = { + 'Authorization': 'Bearer $token' ?? '', + }; + + final body = { + 'user_id': postId, + 'pre_hr_id': preId, + 'user_type': 'hr', + 'activity': activity, + }; + + final response = await http.post( + url, + headers: headers, + body: jsonEncode(body), + ); + + // final response = await _makeGetRequest(url, headers); + if (response.statusCode == 200) { + return jsonDecode(response.body); + } else { + throw Exception( + 'Failed to log HR activity: ${response.statusCode} ${response.body}'); + } + } + Future> getClaimPoliciesToApi(String token) async { print("getgetClaimPoliciesToApii1"); final url = Uri.parse('${Environment.apiUrlPost}claimsSearch'); diff --git a/lib/service/hrDashboardTabs/cd.dart b/lib/service/hrDashboardTabs/cd.dart index 766bc9a..91e55ea 100644 --- a/lib/service/hrDashboardTabs/cd.dart +++ b/lib/service/hrDashboardTabs/cd.dart @@ -7,6 +7,7 @@ import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:google_fonts/google_fonts.dart'; import 'package:http/http.dart' as http; +import 'package:shared_preferences/shared_preferences.dart'; import 'package:universal_html/html.dart' as html; import '../../cdTransactionDetails.dart'; @@ -182,6 +183,35 @@ class _CdPolicieState extends State { ..setAttribute("download", "CD_Policies.csv") ..click(); html.Url.revokeObjectUrl(url); + handleExportAction(); + } + + Future handleExportAction() async { + print('handleExportAction'); + + final SharedPreferences prefs = await SharedPreferences.getInstance(); + final postId = prefs.getString('empHrId'); + final preId = prefs.getString('enrollmentEmpPrimaryId'); + var activity = "export_cddata"; + + print('postId - $postId'); + print('preId - $preId'); + print('activity - $activity'); + + try { + print('10'); + final response = await apiService.getPostLogHrActivity( + postId!, preId!, widget.postToken, activity); + if (response['status'] == 'success') { + print('Request success'); + } else { + // ToastHelper.showWarningToast( + // context, 'Request failed with status: ${response.statusCode}'); + print('Request failed with status: ${response['code']}'); + } + } catch (e) { + print('Exception occurred: $e'); + } } @override