Attachments handled in transactions list mowadhafi

development_aamir
haroon amjad 2 years ago
parent b9fcf399c4
commit fc3c1c057a

@ -1,3 +1,5 @@
import 'dart:convert';
import 'package:mohem_flutter_app/api/api_client.dart';
import 'package:mohem_flutter_app/app_state/app_state.dart';
import 'package:mohem_flutter_app/classes/consts.dart';
@ -10,6 +12,7 @@ import 'package:mohem_flutter_app/models/mowadhafhi/get_ticket_details.dart';
import 'package:mohem_flutter_app/models/mowadhafhi/get_ticket_transactions.dart';
import 'package:mohem_flutter_app/models/mowadhafhi/get_ticket_types.dart';
import 'package:mohem_flutter_app/models/mowadhafhi/get_tickets_list.dart';
import 'package:mohem_flutter_app/models/mowadhafhi/get_transaction_attachment_model.dart';
class MowadhafhiApiClient {
static final MowadhafhiApiClient _instance = MowadhafhiApiClient._internal();
@ -51,6 +54,18 @@ class MowadhafhiApiClient {
}, url, postParams);
}
Future<GetTransactionAttachmentModel> getTransactionAttachments(int? attachmentID) async {
String url = "${ApiConsts.cocRest}Mohemm_ITG_GetTicketAttachment";
Map<String, dynamic> postParams = {"EmployeeNumber": AppState().memberInformationList?.eMPLOYEENUMBER, "ItgAttachmentId": attachmentID};
postParams.addAll(AppState().postParamsJson);
return await ApiClient().postJsonForObject((json) {
GenericResponseModel? responseData = GenericResponseModel.fromJson(json);
var jsonDecodedData = jsonDecode(responseData.mohemmITGResponseItem!);
return GetTransactionAttachmentModel.fromJson(jsonDecodedData);
}, url, postParams);
}
Future<List<GetTicketTypes>> getTicketTypes() async {
String url = "${ApiConsts.cocRest}Mohemm_ITG_GetTicketTypes";
Map<String, dynamic> postParams = {"EmployeeNumber": AppState().memberInformationList?.eMPLOYEENUMBER};

@ -3,8 +3,8 @@ import 'package:mohem_flutter_app/ui/marathon/widgets/question_card.dart';
class ApiConsts {
//static String baseUrl = "http://10.200.204.20:2801/"; // Local server
// static String baseUrl = "https://erptstapp.srca.org.sa"; // SRCA server
// static String baseUrl = "https://uat.hmgwebservices.com"; // UAT ser343622ver
static String baseUrl = "https://hmgwebservices.com"; // Live server
static String baseUrl = "https://uat.hmgwebservices.com"; // UAT ser343622ver
// static String baseUrl = "https://hmgwebservices.com"; // Live server
static String baseUrlServices = baseUrl + "/Services/"; // server
// static String baseUrlServices = "https://api.cssynapses.com/tangheem/"; // Live server
static String utilitiesRest = baseUrlServices + "Utilities.svc/REST/";

@ -1,24 +1,24 @@
class GetTicketTransactions {
String? actionBy;
String? actionDate;
List<Attachments>? attachments;
String? comments;
String? statusDisplayText;
String? statusName;
String? ticketId;
int? ticketTransactionId;
GetTicketTransactions(
{this.actionBy,
this.actionDate,
this.comments,
this.statusDisplayText,
this.statusName,
this.ticketId,
this.ticketTransactionId});
GetTicketTransactions({this.actionBy, this.actionDate, this.attachments, this.comments, this.statusDisplayText, this.statusName, this.ticketId, this.ticketTransactionId});
GetTicketTransactions.fromJson(Map<String, dynamic> json) {
actionBy = json['actionBy'];
actionDate = json['actionDate'];
if (json['attachments'] != null) {
attachments = <Attachments>[];
json['attachments'].forEach((v) {
attachments!.add(new Attachments.fromJson(v));
});
}
comments = json['comments'];
statusDisplayText = json['statusDisplayText'];
statusName = json['statusName'];
@ -27,9 +27,12 @@ class GetTicketTransactions {
}
Map<String, dynamic> toJson() {
Map<String, dynamic> data = new Map<String, dynamic>();
Map<String, dynamic> data = Map<String, dynamic>();
data['actionBy'] = this.actionBy;
data['actionDate'] = this.actionDate;
if (this.attachments != null) {
data['attachments'] = this.attachments!.map((v) => v.toJson()).toList();
}
data['comments'] = this.comments;
data['statusDisplayText'] = this.statusDisplayText;
data['statusName'] = this.statusName;
@ -38,3 +41,22 @@ class GetTicketTransactions {
return data;
}
}
class Attachments {
int? attachmentId;
String? fileName;
Attachments({this.attachmentId, this.fileName});
Attachments.fromJson(Map<String, dynamic> json) {
attachmentId = json['attachmentId'];
fileName = json['fileName'];
}
Map<String, dynamic> toJson() {
Map<String, dynamic> data = Map<String, dynamic>();
data['attachmentId'] = this.attachmentId;
data['fileName'] = this.fileName;
return data;
}
}

@ -0,0 +1,52 @@
class GetTransactionAttachmentModel {
int? attachmentId;
String? fileName;
String? contentType;
dynamic attachFileStream;
String? base64String;
dynamic isActive;
dynamic referenceItemId;
dynamic content;
dynamic filePath;
int? languageId;
GetTransactionAttachmentModel(
{this.attachmentId,
this.fileName,
this.contentType,
this.attachFileStream,
this.base64String,
this.isActive,
this.referenceItemId,
this.content,
this.filePath,
this.languageId});
GetTransactionAttachmentModel.fromJson(Map<String, dynamic> json) {
attachmentId = json['attachmentId'];
fileName = json['fileName'];
contentType = json['contentType'];
attachFileStream = json['attachFileStream'];
base64String = json['base64String'];
isActive = json['isActive'];
referenceItemId = json['referenceItemId'];
content = json['content'];
filePath = json['filePath'];
languageId = json['languageId'];
}
Map<String, dynamic> toJson() {
Map<String, dynamic> data = Map<String, dynamic>();
data['attachmentId'] = this.attachmentId;
data['fileName'] = this.fileName;
data['contentType'] = this.contentType;
data['attachFileStream'] = this.attachFileStream;
data['base64String'] = this.base64String;
data['isActive'] = this.isActive;
data['referenceItemId'] = this.referenceItemId;
data['content'] = this.content;
data['filePath'] = this.filePath;
data['languageId'] = this.languageId;
return data;
}
}

@ -1,3 +1,8 @@
import 'dart:convert';
import 'dart:io';
import 'dart:io' as Io;
import 'dart:typed_data';
import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/material.dart';
import 'package:mohem_flutter_app/api/mowadhafhi/mowadhafhi_api_client.dart';
@ -6,9 +11,13 @@ import 'package:mohem_flutter_app/classes/utils.dart';
import 'package:mohem_flutter_app/extensions/int_extensions.dart';
import 'package:mohem_flutter_app/extensions/string_extensions.dart';
import 'package:mohem_flutter_app/generated/locale_keys.g.dart';
import 'package:mohem_flutter_app/main.dart';
import 'package:mohem_flutter_app/models/mowadhafhi/get_ticket_details.dart';
import 'package:mohem_flutter_app/models/mowadhafhi/get_ticket_transactions.dart';
import 'package:mohem_flutter_app/models/mowadhafhi/get_transaction_attachment_model.dart';
import 'package:mohem_flutter_app/ui/screens/mowadhafhi/view_transaction_attachment.dart';
import 'package:mohem_flutter_app/widgets/app_bar_widget.dart';
import 'package:path_provider/path_provider.dart';
class MowadhafhiRequestDetails extends StatefulWidget {
const MowadhafhiRequestDetails({Key? key}) : super(key: key);
@ -21,6 +30,9 @@ class _RequestDetailsState extends State<MowadhafhiRequestDetails> {
String? itgTicketID;
List<GetTicketDetailsByEmployee> getTicketsByEmployeeList = [];
List<GetTicketTransactions> getTicketTransactionsList = [];
GetTransactionAttachmentModel? getTransactionAttachmentModel;
late File imageFile;
@override
void initState() {
@ -43,7 +55,7 @@ class _RequestDetailsState extends State<MowadhafhiRequestDetails> {
backgroundColor: Colors.white,
appBar: AppBarWidget(
context,
title: LocaleKeys.mowadhafhiRequest.tr(),
title: LocaleKeys.mowadhafhiRequest.tr(),
),
body: SingleChildScrollView(
child: getTicketsByEmployeeList.length != 0
@ -76,16 +88,16 @@ class _RequestDetailsState extends State<MowadhafhiRequestDetails> {
],
),
8.height,
LocaleKeys.ticketReference.tr().toText12(color: MyColors.grey98Color),
LocaleKeys.ticketReference.tr().toText12(color: MyColors.grey98Color),
getTicketsByEmployeeList![0].ticketReferenceNo!.toText14(color: MyColors.grey57Color),
8.height,
LocaleKeys.section.tr().toText12(color: MyColors.grey98Color),
LocaleKeys.section.tr().toText12(color: MyColors.grey98Color),
getTicketsByEmployeeList![0].sectionName!.toText14(color: MyColors.grey57Color),
8.height,
LocaleKeys.topic.tr().toText12(color: MyColors.grey98Color),
LocaleKeys.topic.tr().toText12(color: MyColors.grey98Color),
getTicketsByEmployeeList![0].topicName!.toText14(color: MyColors.grey57Color),
8.height,
LocaleKeys.description.tr().toText12(color: MyColors.grey98Color),
LocaleKeys.description.tr().toText12(color: MyColors.grey98Color),
getTicketsByEmployeeList![0].description!.toText14(color: MyColors.grey57Color),
],
),
@ -128,15 +140,31 @@ class _RequestDetailsState extends State<MowadhafhiRequestDetails> {
Row(
children: [
LocaleKeys.actionBy.tr().toText14(color: MyColors.grey57Color),
": ".toText14(),
getTicketTransactionsList![index].actionBy!.toText14(color: MyColors.grey57Color),
],
),
Row(
children: [
LocaleKeys.actions.tr().toText14(color: MyColors.grey57Color),
": ".toText14(),
getTicketTransactionsList![index].statusDisplayText!.toText14(color: MyColors.grey57Color),
],
),
getTicketTransactionsList![index].comments!.toText14(color: MyColors.grey98Color),
12.height,
if (getTicketTransactionsList[index].attachments != null)
InkWell(
onTap: () {
print(getTicketTransactionsList[index].attachments![0].attachmentId);
getTransactionAttachment(getTicketTransactionsList[index].attachments![0].attachmentId!);
},
child: LocaleKeys.attachments.tr().toText14(color: MyColors.gradiantEndColor, isUnderLine: true),
),
Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
getTicketTransactionsList![0].actionDate!.split(" ")[0].toText12(color: MyColors.grey70Color),
getTicketTransactionsList![index].actionDate!.split(" ")[0].toText12(color: MyColors.grey70Color),
],
),
],
@ -212,4 +240,47 @@ class _RequestDetailsState extends State<MowadhafhiRequestDetails> {
Utils.handleException(ex, context, null);
}
}
void getTransactionAttachment(int attachmentID) async {
try {
Utils.showLoading(context);
getTransactionAttachmentModel = await MowadhafhiApiClient().getTransactionAttachments(attachmentID);
debugPrint(getTransactionAttachmentModel?.fileName);
Utils.hideLoading(context);
setState(() {});
handleTransactionAttachment();
} catch (ex) {
Utils.hideLoading(context);
Utils.handleException(ex, context, null);
}
}
void handleTransactionAttachment() async {
String ext = '';
String? rFile = getTransactionAttachmentModel!.base64String;
String? rFileExt = getTransactionAttachmentModel!.fileName;
ext = "." + rFileExt!.split(".").last.toLowerCase();
if (ext == ".png" || ext == ".jpg" || ext == ".jpeg" || ext == ".gif" || ext == ".tiff") {
try {
Uint8List decodedBytes = base64Decode(rFile!.split("base64,").last);
Directory appDocumentsDirectory = await getApplicationDocumentsDirectory(); // 1
imageFile = Io.File("${appDocumentsDirectory.path}/addImage$ext");
imageFile.writeAsBytesSync(decodedBytes);
Navigator.push(
context,
MaterialPageRoute(
builder: (BuildContext context) => ViewTransactionAttachment(
imageFile: imageFile,
),
),
);
} catch (e) {
logger.d(e);
}
} else {
Utils.showErrorDialog(context: context, onOkTapped: () {}, message: "Unable to view attachment");
}
}
}

@ -0,0 +1,34 @@
import 'dart:io';
import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/material.dart';
import 'package:mohem_flutter_app/extensions/int_extensions.dart';
import 'package:mohem_flutter_app/generated/locale_keys.g.dart';
import 'package:mohem_flutter_app/widgets/app_bar_widget.dart';
class ViewTransactionAttachment extends StatelessWidget {
final File imageFile;
const ViewTransactionAttachment({Key? key, required this.imageFile}) : super(key: key);
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.white,
appBar: AppBarWidget(
context,
title: LocaleKeys.mowadhafhiRequest.tr(),
),
body: SingleChildScrollView(
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: [
Image.file(imageFile),
50.height,
],
),
),
);
}
}

@ -167,10 +167,14 @@ class ActionsFragment extends StatelessWidget {
Duration duration = DateTime.now().difference(dateTimeFrom);
return "Action duration: " + DateUtil.formatDuration(duration);
} else {
DateTime dateTimeTo = DateUtil.convertSimpleStringDateToDate(actionHistoryList[index].nOTIFICATIONDATE!);
DateTime dateTimeFrom = DateUtil.convertSimpleStringDateToDate(actionHistoryList[index + 1].nOTIFICATIONDATE!);
Duration duration = dateTimeTo.difference(dateTimeFrom);
return "Action duration: " + DateUtil.formatDuration(duration);
if (actionHistoryList[index + 1].nOTIFICATIONDATE!.isEmpty) {
return "";
} else {
DateTime dateTimeTo = DateUtil.convertSimpleStringDateToDate(actionHistoryList[index].nOTIFICATIONDATE!);
DateTime dateTimeFrom = DateUtil.convertSimpleStringDateToDate(actionHistoryList[index + 1].nOTIFICATIONDATE!);
Duration duration = dateTimeTo.difference(dateTimeFrom);
return "Action duration: " + DateUtil.formatDuration(duration);
}
}
}

Loading…
Cancel
Save