Commit 94df616d authored by Sai Srinivas's avatar Sai Srinivas
Browse files

16-05-2025 By Sai Srinivas

Finance Module requisition Lists and Details
parent 6a825b3f
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
<uses-permission android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS" /> <uses-permission android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS" />
<uses-permission android:name="com.google.android.gms.permission.AD_ID" /> <uses-permission android:name="com.google.android.gms.permission.AD_ID" />
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" /> <uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<application <application
android:name="${applicationName}" android:name="${applicationName}"
android:icon="@mipmap/ic_launcher" android:icon="@mipmap/ic_launcher"
......
package `in`.webgrid.generp package `in`.webgrid.generp
import android.app.DownloadManager
import android.content.Context
import android.net.Uri
import android.os.Build
import android.os.Environment
import android.webkit.CookieManager
import android.widget.Toast
import io.flutter.embedding.android.FlutterActivity import io.flutter.embedding.android.FlutterActivity
import io.flutter.embedding.engine.FlutterEngine
import io.flutter.plugin.common.MethodChannel
class MainActivity : FlutterActivity(){
private val CHANNEL = "in.webgrid.generp/download"
override fun configureFlutterEngine(flutterEngine: FlutterEngine) {
super.configureFlutterEngine(flutterEngine)
MethodChannel(flutterEngine.dartExecutor.binaryMessenger, CHANNEL).setMethodCallHandler { call, result ->
if (call.method == "startDownload") {
val url = call.argument<String>("url")
val userAgent = call.argument<String>("userAgent")
val contentDisposition = call.argument<String>("contentDisposition")
val mimeType = call.argument<String>("mimeType")
val suggestedFilename = call.argument<String>("suggestedFilename")
if (url != null && userAgent != null && mimeType != null) {
val success = startDownload(url, userAgent, contentDisposition ?: "", mimeType,suggestedFilename ?: "")
if (success) {
result.success("Download started")
} else {
result.error("DOWNLOAD_FAILED", "Failed to start download", null)
}
} else {
result.error("INVALID_ARGUMENTS", "Missing required arguments", null)
}
} else {
result.notImplemented()
}
}
}
private fun startDownload(url: String, userAgent: String, contentDisposition: String, mimeType: String, suggestedFilename: String): Boolean {
return try {
// Show toast
Toast.makeText(this, "File is being downloaded", Toast.LENGTH_SHORT).show()
// Initialize download request
val request = DownloadManager.Request(Uri.parse(url.trim()))
// Get cookies
val cookies = CookieManager.getInstance().getCookie(url) ?: ""
request.addRequestHeader("Cookie", cookies)
request.addRequestHeader("User-Agent", userAgent)
// Set description
request.setDescription("Downloading requested file....")
// Set MIME type
request.setMimeType(mimeType)
// Allow scanning by media scanner
request.allowScanningByMediaScanner()
// Set notification visibility
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED)
// Map MIME type to file extension
val extension = when (mimeType.lowercase()) {
"application/pdf" -> ".pdf"
"image/jpeg" -> ".jpg"
"image/png" -> ".png"
"application/msword" -> ".doc"
"application/vnd.openxmlformats-officedocument.wordprocessingml.document" -> ".docx"
"application/vnd.ms-excel" -> ".xls"
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" -> ".xlsx"
else -> ".bin" // Fallback for unknown types
}
// Guess file name
// val fileName = contentDisposition.takeIf { it.isNotEmpty() }?.let {
// // Parse contentDisposition to extract filename if needed
// it.split(";").find { it.trim().startsWith("filename=") }
// ?.substringAfter("filename=")?.trim('"')
// } ?: url.split("/").last()
var fileName = contentDisposition.takeIf { it.isNotEmpty() }?.let {
// Parse Content-Disposition header (e.g., attachment; filename="Genesis_Quote_70772_16_May_2025_03_17.pdf")
val regex = Regex("filename=\"?([^\"\\s;]+)\"?")
regex.find(it)?.groupValues?.get(1)
} ?: suggestedFilename.takeIf { it.isNotEmpty() } ?: url.split("/").last()
// Ensure the file name has the correct extension
if (!fileName.endsWith(extension, ignoreCase = true)) {
fileName = if (fileName.contains(".")) {
fileName.substringBeforeLast(".") + extension
} else {
fileName + extension
}
}
// Sanitize file name to avoid invalid characters
fileName = fileName.replace("[^a-zA-Z0-9._-]".toRegex(), "_")
// Log for debugging
println("Download File: $fileName, ContentDisposition: $contentDisposition, SuggestedFilename: $suggestedFilename, MimeType: $mimeType")
// Set destination
request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, fileName)
// Set title
request.setTitle(fileName)
// Additional settings
request.setAllowedOverMetered(true)
request.setAllowedOverRoaming(false)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
request.setRequiresCharging(false)
request.setRequiresDeviceIdle(false)
}
request.setVisibleInDownloadsUi(true)
class MainActivity : FlutterActivity() // Enqueue download
val downloadManager = getSystemService(Context.DOWNLOAD_SERVICE) as DownloadManager
downloadManager.enqueue(request)
true
} catch (e: Exception) {
false
}
}
}
<svg width="16" height="19" viewBox="0 0 16 19" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M11.0833 0H1.58333C0.708542 0 0 0.745833 0 1.66667V13.3333H1.58333V1.66667H11.0833V0ZM13.4583 3.33333H4.75C3.87521 3.33333 3.16667 4.07917 3.16667 5V16.6667C3.16667 17.5875 3.87521 18.3333 4.75 18.3333H13.4583C14.3331 18.3333 15.0417 17.5875 15.0417 16.6667V5C15.0417 4.07917 14.3331 3.33333 13.4583 3.33333ZM13.4583 16.6667H4.75V5H13.4583V16.6667Z" fill="#2D2D2D"/>
</svg>
<svg width="21" height="23" viewBox="0 0 21 23" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M16.6262 14.8612C15.3984 14.8612 14.2985 15.4496 13.6079 16.3448L7.39225 12.7382C7.77593 11.7918 7.77593 10.7431 7.39225 9.79665L13.6079 6.19005C14.2985 7.08531 15.3984 7.67362 16.6262 7.67362C18.7492 7.67362 20.463 5.95984 20.463 3.83681C20.463 1.71377 18.7492 0 16.6262 0C14.5031 0 12.7894 1.71377 12.7894 3.83681C12.7894 4.34838 12.8917 4.85996 13.0707 5.2948L6.8551 8.92697C6.13889 8.03172 5.06459 7.44341 3.83681 7.44341C1.71377 7.44341 0 9.15718 0 11.2802C0 13.4033 1.71377 15.117 3.83681 15.117C5.06459 15.117 6.16447 14.5287 6.8551 13.6335L13.0707 17.2401C12.8917 17.6749 12.7894 18.1865 12.7894 18.698C12.7894 20.8211 14.5031 22.5349 16.6262 22.5349C18.7492 22.5349 20.463 20.8211 20.463 18.698C20.463 16.575 18.7492 14.8612 16.6262 14.8612ZM16.6262 1.04873C18.1865 1.04873 19.4398 2.30209 19.4398 3.86239C19.4398 5.42269 18.1865 6.67605 16.6262 6.67605C15.0659 6.67605 13.8125 5.42269 13.8125 3.86239C13.8125 2.30209 15.0659 1.04873 16.6262 1.04873ZM3.83681 14.0939C2.27651 14.0939 1.02315 12.8405 1.02315 11.2802C1.02315 9.71992 2.27651 8.46656 3.83681 8.46656C5.39711 8.46656 6.65047 9.71992 6.65047 11.2802C6.65047 12.8405 5.39711 14.0939 3.83681 14.0939ZM16.6262 21.5117C15.0659 21.5117 13.8125 20.2584 13.8125 18.698C13.8125 17.1377 15.0659 15.8844 16.6262 15.8844C18.1865 15.8844 19.4398 17.1377 19.4398 18.698C19.4398 20.2584 18.1865 21.5117 16.6262 21.5117Z" fill="white"/>
</svg>
class paymentRequesitionListsResponse {
List<RequistionList>? requistionList;
String? error;
String? message;
paymentRequesitionListsResponse(
{this.requistionList, this.error, this.message});
paymentRequesitionListsResponse.fromJson(Map<String, dynamic> json) {
if (json['requistion_list'] != null) {
requistionList = <RequistionList>[];
json['requistion_list'].forEach((v) {
requistionList!.add(new RequistionList.fromJson(v));
});
}
error = json['error'];
message = json['message'];
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
if (this.requistionList != null) {
data['requistion_list'] =
this.requistionList!.map((v) => v.toJson()).toList();
}
data['error'] = this.error;
data['message'] = this.message;
return data;
}
}
class RequistionList {
String? id;
String? isProcessedPaymentRequest;
String? accountId;
String? accountName;
String? branch;
String? requestingPurpose;
String? transDis;
String? description;
String? amount;
String? requestMode;
String? status;
String? createdEmployee;
String? level1Employee;
String? level2Employee;
String? level1ApprovalRemarks;
String? level2ApprovalRemarks;
String? attachmentViewFileName;
String? attachmentDirFilePath;
String? date;
String? createdDatetime;
String? proposedAccount;
String? proposedAccountId;
RequistionList(
{this.id,
this.isProcessedPaymentRequest,
this.accountId,
this.accountName,
this.branch,
this.requestingPurpose,
this.transDis,
this.description,
this.amount,
this.requestMode,
this.status,
this.createdEmployee,
this.level1Employee,
this.level2Employee,
this.level1ApprovalRemarks,
this.level2ApprovalRemarks,
this.attachmentViewFileName,
this.attachmentDirFilePath,
this.date,
this.createdDatetime,
this.proposedAccount,
this.proposedAccountId});
RequistionList.fromJson(Map<String, dynamic> json) {
id = json['id'];
isProcessedPaymentRequest = json['is_processed_payment_request'];
accountId = json['account_id'];
accountName = json['account_name'];
branch = json['branch'];
requestingPurpose = json['requesting_purpose'];
transDis = json['trans_dis'];
description = json['description'];
amount = json['amount'];
requestMode = json['request_mode'];
status = json['status'];
createdEmployee = json['created_employee'];
level1Employee = json['level1_employee'];
level2Employee = json['level2_employee'];
level1ApprovalRemarks = json['level_1_approval_remarks'];
level2ApprovalRemarks = json['level_2_approval_remarks'];
attachmentViewFileName = json['attachment_view_file_name'];
attachmentDirFilePath = json['attachment_dir_file_path'];
date = json['date'];
createdDatetime = json['created_datetime'];
proposedAccount = json['proposed_account'];
proposedAccountId = json['proposed_account_id'];
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
data['id'] = this.id;
data['is_processed_payment_request'] = this.isProcessedPaymentRequest;
data['account_id'] = this.accountId;
data['account_name'] = this.accountName;
data['branch'] = this.branch;
data['requesting_purpose'] = this.requestingPurpose;
data['trans_dis'] = this.transDis;
data['description'] = this.description;
data['amount'] = this.amount;
data['request_mode'] = this.requestMode;
data['status'] = this.status;
data['created_employee'] = this.createdEmployee;
data['level1_employee'] = this.level1Employee;
data['level2_employee'] = this.level2Employee;
data['level_1_approval_remarks'] = this.level1ApprovalRemarks;
data['level_2_approval_remarks'] = this.level2ApprovalRemarks;
data['attachment_view_file_name'] = this.attachmentViewFileName;
data['attachment_dir_file_path'] = this.attachmentDirFilePath;
data['date'] = this.date;
data['created_datetime'] = this.createdDatetime;
data['proposed_account'] = this.proposedAccount;
data['proposed_account_id'] = this.proposedAccountId;
return data;
}
}
class paymentRequisitionDetailsResponse {
RequestDetails? requestDetails;
PaymentDetails? paymentDetails;
String? error;
String? message;
paymentRequisitionDetailsResponse(
{this.requestDetails, this.paymentDetails, this.error, this.message});
paymentRequisitionDetailsResponse.fromJson(Map<String, dynamic> json) {
requestDetails = json['request_details'] != null
? new RequestDetails.fromJson(json['request_details'])
: null;
paymentDetails = json['payment_details'] != null
? new PaymentDetails.fromJson(json['payment_details'])
: null;
error = json['error'];
message = json['message'];
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
if (this.requestDetails != null) {
data['request_details'] = this.requestDetails!.toJson();
}
if (this.paymentDetails != null) {
data['payment_details'] = this.paymentDetails!.toJson();
}
data['error'] = this.error;
data['message'] = this.message;
return data;
}
}
class RequestDetails {
String? id;
String? isProcessedPaymentRequest;
String? accountId;
String? accountName;
String? branch;
String? requestingPurpose;
String? transDis;
String? description;
String? amount;
String? requestedAmount;
String? requestMode;
String? status;
String? createdEmployee;
String? level1Employee;
String? level2Employee;
String? level1ApprovalRemarks;
String? level2ApprovalRemarks;
String? attachmentViewFileName;
String? attachmentDirFilePath;
String? date;
String? createdDatetime;
String? updatedDatetime;
String? proposedAccount;
String? proposedAccountId;
RequestDetails(
{this.id,
this.isProcessedPaymentRequest,
this.accountId,
this.accountName,
this.branch,
this.requestingPurpose,
this.transDis,
this.description,
this.amount,
this.requestedAmount,
this.requestMode,
this.status,
this.createdEmployee,
this.level1Employee,
this.level2Employee,
this.level1ApprovalRemarks,
this.level2ApprovalRemarks,
this.attachmentViewFileName,
this.attachmentDirFilePath,
this.date,
this.createdDatetime,
this.updatedDatetime,
this.proposedAccount,
this.proposedAccountId});
RequestDetails.fromJson(Map<String, dynamic> json) {
id = json['id'];
isProcessedPaymentRequest = json['is_processed_payment_request'];
accountId = json['account_id'];
accountName = json['account_name'];
branch = json['branch'];
requestingPurpose = json['requesting_purpose'];
transDis = json['trans_dis'];
description = json['description'];
amount = json['amount'];
requestedAmount = json['requested_amount'];
requestMode = json['request_mode'];
status = json['status'];
createdEmployee = json['created_employee'];
level1Employee = json['level1_employee'];
level2Employee = json['level2_employee'];
level1ApprovalRemarks = json['level_1_approval_remarks'];
level2ApprovalRemarks = json['level_2_approval_remarks'];
attachmentViewFileName = json['attachment_view_file_name'];
attachmentDirFilePath = json['attachment_dir_file_path'];
date = json['date'];
createdDatetime = json['created_datetime'];
updatedDatetime = json['updated_datetime'];
proposedAccount = json['proposed_account'];
proposedAccountId = json['proposed_account_id'];
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
data['id'] = this.id;
data['is_processed_payment_request'] = this.isProcessedPaymentRequest;
data['account_id'] = this.accountId;
data['account_name'] = this.accountName;
data['branch'] = this.branch;
data['requesting_purpose'] = this.requestingPurpose;
data['trans_dis'] = this.transDis;
data['description'] = this.description;
data['amount'] = this.amount;
data['requested_amount'] = this.requestedAmount;
data['request_mode'] = this.requestMode;
data['status'] = this.status;
data['created_employee'] = this.createdEmployee;
data['level1_employee'] = this.level1Employee;
data['level2_employee'] = this.level2Employee;
data['level_1_approval_remarks'] = this.level1ApprovalRemarks;
data['level_2_approval_remarks'] = this.level2ApprovalRemarks;
data['attachment_view_file_name'] = this.attachmentViewFileName;
data['attachment_dir_file_path'] = this.attachmentDirFilePath;
data['date'] = this.date;
data['created_datetime'] = this.createdDatetime;
data['updated_datetime'] = this.updatedDatetime;
data['proposed_account'] = this.proposedAccount;
data['proposed_account_id'] = this.proposedAccountId;
return data;
}
}
class PaymentDetails {
String? id;
String? refType;
String? refId;
String? paymentAccountId;
String? accountId;
String? paymentModeId;
String? amount;
String? bankName;
String? bankBranchName;
String? bankIfscCode;
String? bankAccountHolderName;
String? bankAccountNumber;
String? bankUpiId;
String? attachmentDirFilePath;
String? attachmentViewFileName;
String? description;
String? paymentReferenceNumber;
String? createdEmployeeId;
String? paymentDate;
String? paymentRemarks;
String? isExists;
String? createdDatetime;
String? updatedDatetime;
String? accountName;
String? paymentAccountName;
String? paymentEmployeeName;
String? mode;
PaymentDetails(
{this.id,
this.refType,
this.refId,
this.paymentAccountId,
this.accountId,
this.paymentModeId,
this.amount,
this.bankName,
this.bankBranchName,
this.bankIfscCode,
this.bankAccountHolderName,
this.bankAccountNumber,
this.bankUpiId,
this.attachmentDirFilePath,
this.attachmentViewFileName,
this.description,
this.paymentReferenceNumber,
this.createdEmployeeId,
this.paymentDate,
this.paymentRemarks,
this.isExists,
this.createdDatetime,
this.updatedDatetime,
this.accountName,
this.paymentAccountName,
this.paymentEmployeeName,
this.mode});
PaymentDetails.fromJson(Map<String, dynamic> json) {
id = json['id'];
refType = json['ref_type'];
refId = json['ref_id'];
paymentAccountId = json['payment_account_id'];
accountId = json['account_id'];
paymentModeId = json['payment_mode_id'];
amount = json['amount'];
bankName = json['bank_name'];
bankBranchName = json['bank_branch_name'];
bankIfscCode = json['bank_ifsc_code'];
bankAccountHolderName = json['bank_account_holder_name'];
bankAccountNumber = json['bank_account_number'];
bankUpiId = json['bank_upi_id'];
attachmentDirFilePath = json['attachment_dir_file_path'];
attachmentViewFileName = json['attachment_view_file_name'];
description = json['description'];
paymentReferenceNumber = json['payment_reference_number'];
createdEmployeeId = json['created_employee_id'];
paymentDate = json['payment_date'];
paymentRemarks = json['payment_remarks'];
isExists = json['is_exists'];
createdDatetime = json['created_datetime'];
updatedDatetime = json['updated_datetime'];
accountName = json['account_name'];
paymentAccountName = json['payment_account_name'];
paymentEmployeeName = json['payment_employee_name'];
mode = json['mode'];
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
data['id'] = this.id;
data['ref_type'] = this.refType;
data['ref_id'] = this.refId;
data['payment_account_id'] = this.paymentAccountId;
data['account_id'] = this.accountId;
data['payment_mode_id'] = this.paymentModeId;
data['amount'] = this.amount;
data['bank_name'] = this.bankName;
data['bank_branch_name'] = this.bankBranchName;
data['bank_ifsc_code'] = this.bankIfscCode;
data['bank_account_holder_name'] = this.bankAccountHolderName;
data['bank_account_number'] = this.bankAccountNumber;
data['bank_upi_id'] = this.bankUpiId;
data['attachment_dir_file_path'] = this.attachmentDirFilePath;
data['attachment_view_file_name'] = this.attachmentViewFileName;
data['description'] = this.description;
data['payment_reference_number'] = this.paymentReferenceNumber;
data['created_employee_id'] = this.createdEmployeeId;
data['payment_date'] = this.paymentDate;
data['payment_remarks'] = this.paymentRemarks;
data['is_exists'] = this.isExists;
data['created_datetime'] = this.createdDatetime;
data['updated_datetime'] = this.updatedDatetime;
data['account_name'] = this.accountName;
data['payment_account_name'] = this.paymentAccountName;
data['payment_employee_name'] = this.paymentEmployeeName;
data['mode'] = this.mode;
return data;
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment