API's implemented
parent
56252716b3
commit
e0ed594072
@ -0,0 +1,6 @@
|
|||||||
|
enum DemoRequestStepEnum {
|
||||||
|
qAuditorRejectAccept, // quality auditor accept reject
|
||||||
|
updateRequest, // quality auditor edit reject, // 5
|
||||||
|
extendDemoPeriod, // extent
|
||||||
|
viewOnly, // need to check when show view only
|
||||||
|
}
|
||||||
@ -0,0 +1,91 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:test_sa/extensions/context_extension.dart';
|
||||||
|
import 'package:test_sa/extensions/int_extensions.dart';
|
||||||
|
import 'package:test_sa/extensions/string_extensions.dart';
|
||||||
|
import 'package:test_sa/extensions/text_extensions.dart';
|
||||||
|
import 'package:test_sa/extensions/widget_extensions.dart';
|
||||||
|
import 'package:test_sa/models/all_requests_and_count_model.dart';
|
||||||
|
import 'package:test_sa/models/new_models/dashboard_detail.dart';
|
||||||
|
import 'package:test_sa/modules/asset_delivery_module/pages/asset_delivery_page.dart';
|
||||||
|
import 'package:test_sa/modules/asset_inventory_module/pages/asset_inventory_page.dart';
|
||||||
|
import 'package:test_sa/modules/demo_module/demo_detail_view_page.dart';
|
||||||
|
import 'package:test_sa/new_views/app_style/app_color.dart';
|
||||||
|
import 'package:test_sa/views/widgets/requests/request_status.dart';
|
||||||
|
|
||||||
|
class DemoRequestItemView extends StatelessWidget {
|
||||||
|
final Data? requestData;
|
||||||
|
final RequestsDetails? requestDetails;
|
||||||
|
final bool showShadow;
|
||||||
|
|
||||||
|
const DemoRequestItemView({Key? key, this.requestData, this.requestDetails, this.showShadow = true}) : super(key: key);
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
if (requestData != null) {
|
||||||
|
return Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
8.height,
|
||||||
|
// (requestData?.typeTransaction ?? 'Demo Request').heading5(context),
|
||||||
|
('Demo Request').heading5(context),
|
||||||
|
//TODO need to replace this with exact values need to show here..
|
||||||
|
infoWidget(label: 'PO Internal'.addTranslation, value: requestData?.poInternal ?? '-', context: context),
|
||||||
|
infoWidget(label: 'PO External'.addTranslation, value: requestData?.poExternal ?? '-', context: context),
|
||||||
|
// infoWidget(label: 'No of Sites'.addTranslation, value: requestData?.numberOfSites != null ? requestData?.numberOfSites.toString() : '-', context: context),
|
||||||
|
8.height,
|
||||||
|
Row(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
children: [
|
||||||
|
Text(
|
||||||
|
context.translation.viewDetails,
|
||||||
|
style: AppTextStyles.bodyText.copyWith(color: AppColor.blueStatus(context)),
|
||||||
|
),
|
||||||
|
4.width,
|
||||||
|
Icon(Icons.arrow_forward, color: AppColor.blueStatus(context), size: 14)
|
||||||
|
],
|
||||||
|
),
|
||||||
|
],
|
||||||
|
).toShadowContainer(context, withShadow: showShadow).onPress(() async {
|
||||||
|
Navigator.of(context).push(MaterialPageRoute(
|
||||||
|
builder: (_) => DemoDetailViewPage(
|
||||||
|
demoId: requestData!.id!,
|
||||||
|
)));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
8.height,
|
||||||
|
('Demo Request').heading5(context),
|
||||||
|
// (requestDetails?.nameOfType ?? 'Demo Request').heading5(context),
|
||||||
|
//TODO need to replace this with exact values need to show here..
|
||||||
|
infoWidget(label: 'PO Internal'.addTranslation, value: requestDetails?.poInternal ?? '-', context: context),
|
||||||
|
infoWidget(label: 'PO External'.addTranslation, value: requestDetails?.poExternal ?? '-', context: context),
|
||||||
|
8.height,
|
||||||
|
Row(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
children: [
|
||||||
|
Text(
|
||||||
|
context.translation.viewDetails,
|
||||||
|
style: AppTextStyles.bodyText.copyWith(color: AppColor.blueStatus(context)),
|
||||||
|
),
|
||||||
|
4.width,
|
||||||
|
Icon(Icons.arrow_forward, color: AppColor.blueStatus(context), size: 14)
|
||||||
|
],
|
||||||
|
),
|
||||||
|
],
|
||||||
|
).toShadowContainer(context, withShadow: showShadow).onPress(() async {
|
||||||
|
Navigator.of(context).push(MaterialPageRoute(
|
||||||
|
builder: (_) => DemoDetailViewPage(
|
||||||
|
demoId: requestDetails!.id!,
|
||||||
|
)));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget infoWidget({required String label, String? value, required BuildContext context}) {
|
||||||
|
if (value != null && value.isNotEmpty) {
|
||||||
|
return '$label: $value'.bodyText(context);
|
||||||
|
}
|
||||||
|
return const SizedBox();
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,27 @@
|
|||||||
|
class DemoAttachments {
|
||||||
|
int? id;
|
||||||
|
num? demoRequestId;
|
||||||
|
num? attachmentTypeId;
|
||||||
|
String? attachmentName;
|
||||||
|
String? originalName;
|
||||||
|
|
||||||
|
DemoAttachments({this.id, this.attachmentTypeId, this.attachmentName, this.demoRequestId, this.originalName});
|
||||||
|
|
||||||
|
DemoAttachments.fromJson(dynamic json) {
|
||||||
|
id = json['id'];
|
||||||
|
attachmentTypeId = json['attachmentTypeId'];
|
||||||
|
demoRequestId = json['demoRequestId'];
|
||||||
|
attachmentName = json['attachmentName'];
|
||||||
|
originalName = json['originalName'];
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<String, dynamic> toJson() {
|
||||||
|
final map = <String, dynamic>{};
|
||||||
|
map['id'] = id;
|
||||||
|
map['attachmentTypeId'] = attachmentTypeId;
|
||||||
|
map['attachmentName'] = attachmentName;
|
||||||
|
map['demoRequestId'] = demoRequestId;
|
||||||
|
map['originalName'] = originalName;
|
||||||
|
return map;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,157 +1,81 @@
|
|||||||
import 'package:test_sa/models/lookup.dart';
|
import 'package:test_sa/models/lookup.dart';
|
||||||
import 'package:test_sa/models/new_models/building.dart';
|
|
||||||
import 'package:test_sa/models/new_models/department.dart';
|
|
||||||
import 'package:test_sa/models/new_models/floor.dart';
|
|
||||||
import 'package:test_sa/models/new_models/site.dart';
|
import 'package:test_sa/models/new_models/site.dart';
|
||||||
|
import 'package:test_sa/models/service_request/supp_engineer_work_orders.dart';
|
||||||
|
import 'package:test_sa/models/service_request/supplier_details.dart';
|
||||||
|
import 'package:test_sa/modules/demo_module/models/demo_attachment_model.dart';
|
||||||
import 'package:test_sa/modules/loan_module/models/medical_department_model.dart';
|
import 'package:test_sa/modules/loan_module/models/medical_department_model.dart';
|
||||||
|
|
||||||
class DemoFormModel {
|
class DemoFormModel {
|
||||||
String? docName;
|
String? docName;
|
||||||
|
int? id;
|
||||||
String? docNumber;
|
String? docNumber;
|
||||||
String? docEmail;
|
String? docEmail;
|
||||||
String? itemDescription;
|
String? itemDescription;
|
||||||
String? requestDescription;
|
String? requestDescription;
|
||||||
String? model;
|
String? model;
|
||||||
|
String? assetName;
|
||||||
String? manufacturer;
|
String? manufacturer;
|
||||||
Lookup? loanProvided;
|
Lookup? demoPeriod;
|
||||||
String? vendorName;
|
|
||||||
String? vendorRepresentativeName;
|
String? vendorRepresentativeName;
|
||||||
String? vendorNumber;
|
String? vendorNumber;
|
||||||
String? vendorEmail;
|
String? vendorEmail;
|
||||||
Site? site;
|
Site? site;
|
||||||
|
SuppEngineerWorkOrders? supEngineer;
|
||||||
|
SupplierDetails? vendor;
|
||||||
MedicalDepartmentModel? department;
|
MedicalDepartmentModel? department;
|
||||||
List<DemoAttachments>? demoAttachment;
|
List<DemoAttachments>? demoAttachment;
|
||||||
|
|
||||||
DemoFormModel({
|
DemoFormModel({
|
||||||
|
this.id,
|
||||||
this.docName,
|
this.docName,
|
||||||
this.docNumber,
|
this.docNumber,
|
||||||
this.docEmail,
|
this.docEmail,
|
||||||
this.itemDescription,
|
this.itemDescription,
|
||||||
this.requestDescription,
|
this.requestDescription,
|
||||||
this.model,
|
this.model,
|
||||||
|
this.assetName,
|
||||||
this.manufacturer,
|
this.manufacturer,
|
||||||
this.loanProvided,
|
this.demoPeriod,
|
||||||
this.vendorName,
|
|
||||||
this.vendorRepresentativeName,
|
this.vendorRepresentativeName,
|
||||||
this.vendorNumber,
|
this.vendorNumber,
|
||||||
this.vendorEmail,
|
this.vendorEmail,
|
||||||
this.demoAttachment,
|
this.demoAttachment,
|
||||||
this.site,
|
this.site,
|
||||||
|
this.vendor,
|
||||||
|
this.supEngineer,
|
||||||
this.department,
|
this.department,
|
||||||
});
|
});
|
||||||
|
|
||||||
//{
|
|
||||||
// "id": 0,
|
|
||||||
// "employeeId": "fa29a9de-1337-4729-b823-68c6ecffdd33",
|
|
||||||
// "requestorUserID": "fa29a9de-1337-4729-b823-68c6ecffdd33",
|
|
||||||
// "employeeName": "engineer-dev",
|
|
||||||
// "employeeEmail": "Engineer_Dev@yahoo.com",
|
|
||||||
// "positionName": "High",
|
|
||||||
// "requesterExtensionNumber": "7726",
|
|
||||||
// "requesterContactNumber": "72132197",
|
|
||||||
// "siteId": 1,
|
|
||||||
// "departmentId": 5,
|
|
||||||
// "loanTypeId": 6448,
|
|
||||||
// "doctorName": "Doctor A",
|
|
||||||
// "doctorContact": "0561432451",
|
|
||||||
// "doctorEmail": "doctor@test.com",
|
|
||||||
// "itemDescription": "Test item",
|
|
||||||
// "requestDescription": "Test request",
|
|
||||||
// "loanPeriodId": 6453,
|
|
||||||
// "assetId": null,
|
|
||||||
// "assetNumber": "",
|
|
||||||
// "assetName": "",
|
|
||||||
// "assetSerialNumber": "",
|
|
||||||
// "model": "Model A",
|
|
||||||
// "manufacturer": "Siemens",
|
|
||||||
// "vendorName": "Vendor A",
|
|
||||||
// "vendorRepName": "Vendor Rep A",
|
|
||||||
// "vendorContact": "0561432455",
|
|
||||||
// "vendorEmail": "vendor@test.com",
|
|
||||||
// "loanStatusId": 1,
|
|
||||||
// "loanAttachments": [],
|
|
||||||
// "submittedAt": "2025-11-13T12:11:12.673Z",
|
|
||||||
// "updatedAt": null,
|
|
||||||
// "cMWOItemId": null
|
|
||||||
// }
|
|
||||||
|
|
||||||
Map<String, dynamic> toJson() {
|
Map<String, dynamic> toJson() {
|
||||||
var abc = {
|
|
||||||
"id": 0,
|
|
||||||
"siteId": 0,
|
|
||||||
"buildingId": 0,
|
|
||||||
"floorId": 0,
|
|
||||||
"departmentId": 0,
|
|
||||||
"assetName": "string",
|
|
||||||
"model": "string",
|
|
||||||
"manufacturer": "string",
|
|
||||||
"doctorName": "string",
|
|
||||||
"doctorContactNumber": "string",
|
|
||||||
"doctorContactEmail": "string",
|
|
||||||
"itemDescription": "string",
|
|
||||||
"requestDescription": "string",
|
|
||||||
"demoPeriodId": 0,
|
|
||||||
"supplierId": 0,
|
|
||||||
"suppPersonId": 0,
|
|
||||||
"isSubmit": true,
|
|
||||||
"demoAttachments": [
|
|
||||||
{
|
|
||||||
"id": 0,
|
|
||||||
"attachmentName": "string",
|
|
||||||
"originalName": "string",
|
|
||||||
"demoRequestId": 0,
|
|
||||||
"attachmentTypeId": 0
|
|
||||||
}
|
|
||||||
]
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
"id": 0,
|
||||||
|
'siteId': site?.id,
|
||||||
|
'departmentId': department?.id,
|
||||||
|
"buildingId": 0,
|
||||||
|
"floorId": 0,
|
||||||
|
"assetName": assetName,
|
||||||
|
"isSubmit": true,
|
||||||
"doctorName": docName,
|
"doctorName": docName,
|
||||||
"doctorContact": docNumber,
|
"doctorContactNumber": docNumber,
|
||||||
"doctorEmail": docEmail,
|
"doctorContactEmail": docEmail,
|
||||||
"itemDescription": itemDescription,
|
"itemDescription": itemDescription,
|
||||||
"requestDescription": requestDescription,
|
"requestDescription": requestDescription,
|
||||||
"model": model,
|
"model": model,
|
||||||
"manufacturer": manufacturer,
|
"manufacturer": manufacturer,
|
||||||
"demoPeriodId": loanProvided?.id,
|
"demoPeriodId": demoPeriod?.id,
|
||||||
"vendorName": vendorName,
|
"supplierId": vendor?.id,
|
||||||
"vendorRepresentativeName": vendorRepresentativeName,
|
"suppPersonId": supEngineer?.id,
|
||||||
"vendorRepName": vendorRepresentativeName,
|
// "vendorEmail": vendorEmail,
|
||||||
"vendorNumber": vendorNumber,
|
|
||||||
"vendorContact": vendorNumber,
|
|
||||||
"vendorEmail": vendorEmail,
|
|
||||||
'siteId': site?.id,
|
|
||||||
'departmentId': department?.id,
|
|
||||||
"demoAttachments": demoAttachment != null ? demoAttachment!.map((v) => v.toJson()).toList() : [],
|
"demoAttachments": demoAttachment != null ? demoAttachment!.map((v) => v.toJson()).toList() : [],
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
class DemoAttachments {
|
|
||||||
num? id;
|
|
||||||
num? demoRequestId;
|
|
||||||
num? attachmentTypeId;
|
|
||||||
String? attachmentName;
|
|
||||||
String? originalName;
|
|
||||||
|
|
||||||
DemoAttachments({this.id, this.attachmentTypeId, this.attachmentName, this.demoRequestId, this.originalName});
|
|
||||||
|
|
||||||
DemoAttachments.fromJson(dynamic json) {
|
|
||||||
id = json['id'];
|
|
||||||
attachmentTypeId = json['attachmentTypeId'];
|
|
||||||
demoRequestId = json['demoRequestId'];
|
|
||||||
attachmentName = json['attachmentName'];
|
|
||||||
originalName = json['originalName'];
|
|
||||||
}
|
|
||||||
|
|
||||||
Map<String, dynamic> toJson() {
|
Map<String, dynamic> toUpdateJson() {
|
||||||
final map = <String, dynamic>{};
|
return {
|
||||||
map['id'] = id;
|
"id": id,
|
||||||
map['attachmentTypeId'] = attachmentTypeId;
|
"supplierId": vendor?.id,
|
||||||
map['attachmentName'] = attachmentName;
|
"suppPersonId": supEngineer?.id,
|
||||||
map['demoRequestId'] = demoRequestId;
|
"demoAttachments": demoAttachment != null ? demoAttachment!.map((v) => v.toJson()).toList() : [],
|
||||||
map['originalName'] = originalName;
|
};
|
||||||
return map;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,127 @@
|
|||||||
|
import 'package:test_sa/models/device/asset_by_id_model.dart';
|
||||||
|
import 'package:test_sa/models/lookup.dart';
|
||||||
|
import 'package:test_sa/models/service_request/supp_engineer_work_orders.dart';
|
||||||
|
import 'package:test_sa/models/service_request/supplier_details.dart';
|
||||||
|
import 'package:test_sa/modules/demo_module/models/demo_attachment_model.dart';
|
||||||
|
import 'package:test_sa/modules/loan_module/models/medical_department_model.dart';
|
||||||
|
|
||||||
|
class DemoRequestModel {
|
||||||
|
int? id;
|
||||||
|
RequesterUserModel? requesterUser;
|
||||||
|
Site? site;
|
||||||
|
Lookup? building;
|
||||||
|
Lookup? floor;
|
||||||
|
MedicalDepartmentModel? department;
|
||||||
|
String? assetName;
|
||||||
|
String? model;
|
||||||
|
String? manufacturer;
|
||||||
|
String? doctorName;
|
||||||
|
String? doctorContactNumber;
|
||||||
|
String? doctorContactEmail;
|
||||||
|
String? itemDescription;
|
||||||
|
String? requestDescription;
|
||||||
|
Lookup? demoPeriod;
|
||||||
|
SupplierDetails? supplier;
|
||||||
|
SuppEngineerWorkOrders? suppPerson;
|
||||||
|
Lookup? status;
|
||||||
|
List<DemoAttachments>? demoAttachments;
|
||||||
|
dynamic demoAsset;
|
||||||
|
dynamic demoInstallationTaskJob;
|
||||||
|
dynamic demoPullOutTaskJob;
|
||||||
|
bool? isDemoPeriodExpired;
|
||||||
|
|
||||||
|
DemoRequestModel({
|
||||||
|
this.id,
|
||||||
|
this.requesterUser,
|
||||||
|
this.site,
|
||||||
|
this.building,
|
||||||
|
this.floor,
|
||||||
|
this.department,
|
||||||
|
this.assetName,
|
||||||
|
this.model,
|
||||||
|
this.manufacturer,
|
||||||
|
this.doctorName,
|
||||||
|
this.doctorContactNumber,
|
||||||
|
this.doctorContactEmail,
|
||||||
|
this.itemDescription,
|
||||||
|
this.requestDescription,
|
||||||
|
this.demoPeriod,
|
||||||
|
this.supplier,
|
||||||
|
this.suppPerson,
|
||||||
|
this.status,
|
||||||
|
this.demoAttachments,
|
||||||
|
this.demoAsset,
|
||||||
|
this.demoInstallationTaskJob,
|
||||||
|
this.demoPullOutTaskJob,
|
||||||
|
this.isDemoPeriodExpired,
|
||||||
|
});
|
||||||
|
|
||||||
|
DemoRequestModel.fromJson(Map<String, dynamic> json) {
|
||||||
|
id = json['id'];
|
||||||
|
requesterUser = json['requesterUser'] != null ? (RequesterUserModel()..fromJson(json['requesterUser'])) : null;
|
||||||
|
site = json['site'] != null ? (Site.fromJson(json['site'])) : null;
|
||||||
|
building = json['building'] != null ? (Lookup.fromJson(json['building'])) : null;
|
||||||
|
floor = json['floor'] != null ? (Lookup.fromJson(json['floor'])) : null;
|
||||||
|
department = json['department'] != null ? (MedicalDepartmentModel.fromJson(json['department'])) : null;
|
||||||
|
assetName = json['assetName'];
|
||||||
|
model = json['model'];
|
||||||
|
manufacturer = json['manufacturer'];
|
||||||
|
doctorName = json['doctorName'];
|
||||||
|
doctorContactNumber = json['doctorContactNumber'];
|
||||||
|
doctorContactEmail = json['doctorContactEmail'];
|
||||||
|
itemDescription = json['itemDescription'];
|
||||||
|
requestDescription = json['requestDescription'];
|
||||||
|
demoPeriod = json['demoPeriod'] != null ? (Lookup.fromJson(json['demoPeriod'])) : null;
|
||||||
|
supplier = json['supplier'] != null ? (SupplierDetails.fromJson(json['supplier'])) : null;
|
||||||
|
suppPerson = json['suppPerson'] != null ? (SuppEngineerWorkOrders.fromJson(json['suppPerson'])) : null;
|
||||||
|
status = json['status'] != null ? (Lookup.fromJson(json['status'])) : null;
|
||||||
|
demoAttachments = json['demoAttachments'] != null ? (json['demoAttachments'] as List).map((e) => DemoAttachments.fromJson(e)).toList() : null;
|
||||||
|
demoAsset = json['demoAsset'];
|
||||||
|
demoInstallationTaskJob = json['demoInstallationTaskJob'];
|
||||||
|
demoPullOutTaskJob = json['demoPullOutTaskJob'];
|
||||||
|
isDemoPeriodExpired = json['isDemoPeriodExpired'];
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<String, dynamic> toJson() {
|
||||||
|
return {
|
||||||
|
"id": 0,
|
||||||
|
'siteId': site?.id,
|
||||||
|
'departmentId': department?.id,
|
||||||
|
"buildingId": 0,
|
||||||
|
"floorId": 0,
|
||||||
|
"assetName": assetName,
|
||||||
|
"isSubmit": true,
|
||||||
|
"itemDescription": itemDescription,
|
||||||
|
"requestDescription": requestDescription,
|
||||||
|
"model": model,
|
||||||
|
"manufacturer": manufacturer,
|
||||||
|
"demoPeriodId": demoPeriod?.id,
|
||||||
|
"supplierId": supplier?.id,
|
||||||
|
"suppPersonId": suppPerson?.id,
|
||||||
|
"demoAttachments": demoAttachments != null ? demoAttachments!.map((v) => v.toJson()).toList() : [],
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class RequesterUserModel {
|
||||||
|
String? requesterUserId;
|
||||||
|
String? requesterName;
|
||||||
|
String? requesterEmail;
|
||||||
|
String? requesterMobile;
|
||||||
|
|
||||||
|
RequesterUserModel();
|
||||||
|
|
||||||
|
void fromJson(Map<String, dynamic> json) {
|
||||||
|
requesterUserId = json['requesterUserId'];
|
||||||
|
requesterName = json['requesterName'];
|
||||||
|
requesterEmail = json['requesterEmail'];
|
||||||
|
requesterMobile = json['requesterMobile'];
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<String, dynamic> toJson() => {
|
||||||
|
'requesterUserId': requesterUserId,
|
||||||
|
'requesterName': requesterName,
|
||||||
|
'requesterEmail': requesterEmail,
|
||||||
|
'requesterMobile': requesterMobile,
|
||||||
|
};
|
||||||
|
}
|
||||||
@ -0,0 +1,257 @@
|
|||||||
|
import 'dart:convert';
|
||||||
|
import 'dart:developer';
|
||||||
|
import 'dart:io';
|
||||||
|
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:provider/provider.dart';
|
||||||
|
import 'package:test_sa/controllers/providers/api/device_transfer_provider.dart';
|
||||||
|
import 'package:test_sa/controllers/validator/validator.dart';
|
||||||
|
import 'package:test_sa/dashboard_latest/dashboard_provider.dart';
|
||||||
|
import 'package:test_sa/extensions/context_extension.dart';
|
||||||
|
import 'package:test_sa/extensions/int_extensions.dart';
|
||||||
|
import 'package:test_sa/extensions/string_extensions.dart';
|
||||||
|
import 'package:test_sa/extensions/text_extensions.dart';
|
||||||
|
import 'package:test_sa/extensions/widget_extensions.dart';
|
||||||
|
import 'package:test_sa/helper/utils.dart';
|
||||||
|
import 'package:test_sa/models/device/asset.dart';
|
||||||
|
import 'package:test_sa/models/enums/user_types.dart';
|
||||||
|
import 'package:test_sa/models/generic_attachment_model.dart';
|
||||||
|
import 'package:test_sa/models/lookup.dart';
|
||||||
|
import 'package:test_sa/models/new_models/site.dart';
|
||||||
|
import 'package:test_sa/models/new_models/task_request/task_type_model.dart';
|
||||||
|
import 'package:test_sa/models/new_models/work_order_detail_model.dart';
|
||||||
|
import 'package:test_sa/models/service_request/supp_engineer_work_orders.dart';
|
||||||
|
import 'package:test_sa/models/service_request/supplier_details.dart';
|
||||||
|
import 'package:test_sa/modules/cm_module/cm_request_utils.dart';
|
||||||
|
import 'package:test_sa/modules/cm_module/views/components/action_button/footer_action_button.dart';
|
||||||
|
import 'package:test_sa/modules/demo_module/models/demo_attachment_model.dart';
|
||||||
|
import 'package:test_sa/modules/demo_module/models/demo_request_model.dart';
|
||||||
|
import 'package:test_sa/modules/demo_module/provider/demo_period_lookup_provider.dart';
|
||||||
|
import 'package:test_sa/modules/demo_module/provider/demo_provider.dart';
|
||||||
|
import 'package:test_sa/modules/loan_module/models/loan_form_model.dart';
|
||||||
|
import 'package:test_sa/modules/loan_module/models/medical_department_model.dart';
|
||||||
|
import 'package:test_sa/modules/loan_module/provider/loan_period_provider.dart';
|
||||||
|
import 'package:test_sa/modules/loan_module/provider/loan_provider.dart';
|
||||||
|
import 'package:test_sa/modules/loan_module/provider/loan_provider.dart';
|
||||||
|
import 'package:test_sa/modules/loan_module/provider/medical_department_provider.dart';
|
||||||
|
import 'package:test_sa/new_views/app_style/app_color.dart';
|
||||||
|
import 'package:test_sa/new_views/common_widgets/app_filled_button.dart';
|
||||||
|
import 'package:test_sa/new_views/common_widgets/app_text_form_field.dart';
|
||||||
|
import 'package:test_sa/new_views/common_widgets/single_item_drop_down_menu.dart';
|
||||||
|
import 'package:test_sa/providers/department_provider.dart';
|
||||||
|
import 'package:test_sa/providers/gas_request_providers/site_provider.dart';
|
||||||
|
import 'package:test_sa/providers/loading_list_notifier.dart';
|
||||||
|
import 'package:test_sa/providers/work_order/vendor_provider.dart';
|
||||||
|
import 'package:test_sa/views/widgets/images/multi_image_picker.dart';
|
||||||
|
import '../../../../../../new_views/common_widgets/default_app_bar.dart';
|
||||||
|
import 'demo_detail_view_page.dart';
|
||||||
|
import 'models/demo_form_model.dart';
|
||||||
|
|
||||||
|
class UpdateRequestView extends StatefulWidget {
|
||||||
|
static const String id = "/update-demo-request";
|
||||||
|
DemoRequestModel dataModel;
|
||||||
|
|
||||||
|
UpdateRequestView({Key? key, required this.dataModel}) : super(key: key);
|
||||||
|
|
||||||
|
@override
|
||||||
|
_UpdateRequestViewState createState() => _UpdateRequestViewState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _UpdateRequestViewState extends State<UpdateRequestView> with TickerProviderStateMixin {
|
||||||
|
final List<GenericAttachmentModel> attachments = [];
|
||||||
|
final GlobalKey<FormState> _formKey = GlobalKey<FormState>();
|
||||||
|
final GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey<ScaffoldState>();
|
||||||
|
final DemoFormModel _demoFormModel = DemoFormModel();
|
||||||
|
TextEditingController vendorEmailController = TextEditingController();
|
||||||
|
TextEditingController vendorPhoneController = TextEditingController();
|
||||||
|
|
||||||
|
@override
|
||||||
|
void dispose() {
|
||||||
|
vendorEmailController.dispose();
|
||||||
|
vendorPhoneController.dispose();
|
||||||
|
super.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
fillData();
|
||||||
|
}
|
||||||
|
|
||||||
|
void fillData() async {
|
||||||
|
final vendorProvider = Provider.of<VendorProvider>(context, listen: false);
|
||||||
|
if (vendorProvider.items.isEmpty) {
|
||||||
|
if (mounted) {
|
||||||
|
await vendorProvider.getData();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
final supplier = widget.dataModel.supplier;
|
||||||
|
_demoFormModel.vendor = supplier;
|
||||||
|
final selectedVendor = vendorProvider.items.firstWhere(
|
||||||
|
(element) => element.id == supplier?.id,
|
||||||
|
orElse: () => SupplierDetails(),
|
||||||
|
);
|
||||||
|
_demoFormModel.id = widget.dataModel.id;
|
||||||
|
_demoFormModel.vendor?.suppPersons = selectedVendor.suppPersons;
|
||||||
|
_demoFormModel.supEngineer = widget.dataModel.suppPerson;
|
||||||
|
_demoFormModel.vendorEmail = supplier?.email;
|
||||||
|
_demoFormModel.vendorNumber = supplier?.contact;
|
||||||
|
|
||||||
|
vendorEmailController.text = supplier?.email ?? '';
|
||||||
|
vendorPhoneController.text = supplier?.contact ?? '';
|
||||||
|
// ✅ PREFILL ATTACHMENTS
|
||||||
|
attachments.clear();
|
||||||
|
if (widget.dataModel.demoAttachments?.isNotEmpty ?? false) {
|
||||||
|
for (final item in widget.dataModel.demoAttachments!) {
|
||||||
|
if ((item.attachmentName ?? '').isNotEmpty) {
|
||||||
|
attachments.add(
|
||||||
|
GenericAttachmentModel(name: item.attachmentName, id: item.id ?? 0, originalName: item.originalName),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
setState(() {});
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Scaffold(
|
||||||
|
key: _scaffoldKey,
|
||||||
|
appBar: DefaultAppBar(title: 'Update Request'.addTranslation),
|
||||||
|
body: Form(
|
||||||
|
key: _formKey,
|
||||||
|
child: Column(
|
||||||
|
children: [
|
||||||
|
SingleChildScrollView(
|
||||||
|
padding: const EdgeInsets.all(16),
|
||||||
|
child: Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
children: [
|
||||||
|
...vendorDetailsSection(),
|
||||||
|
16.height,
|
||||||
|
AttachmentPicker(
|
||||||
|
label: context.translation.attachments,
|
||||||
|
attachment: attachments,
|
||||||
|
buttonColor: AppColor.black10,
|
||||||
|
onlyImages: false,
|
||||||
|
showAsListView: true,
|
||||||
|
buttonIcon: 'image-plus'.toSvgAsset(color: context.isDark ? AppColor.primary10 : AppColor.neutral120),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
).toShadowContainer(context, borderRadius: 20),
|
||||||
|
).expanded,
|
||||||
|
FooterActionButton.footerContainer(
|
||||||
|
context: context,
|
||||||
|
child: AppFilledButton(
|
||||||
|
buttonColor: AppColor.primary10,
|
||||||
|
label: context.translation.update,
|
||||||
|
onPressed: _update,
|
||||||
|
// buttonColor: AppColor.primary10,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
List<Widget> vendorDetailsSection() {
|
||||||
|
return [
|
||||||
|
'Vendor Details'.addTranslation.bodyText(context).custom(color: AppColor.black10),
|
||||||
|
8.height,
|
||||||
|
SingleItemDropDownMenu<SupplierDetails, VendorProvider>(
|
||||||
|
key: ValueKey(_demoFormModel.vendor?.id),
|
||||||
|
context: context,
|
||||||
|
title: 'Vendor Name'.addTranslation,
|
||||||
|
backgroundColor: AppColor.fieldBgColor(context),
|
||||||
|
initialValue: _demoFormModel.vendor,
|
||||||
|
showAsBottomSheet: true,
|
||||||
|
showShadow: false,
|
||||||
|
showCancel: true,
|
||||||
|
onSelect: (person) {
|
||||||
|
_demoFormModel.vendor = person;
|
||||||
|
_demoFormModel.supEngineer = null;
|
||||||
|
vendorPhoneController.text = person?.contact ?? '';
|
||||||
|
vendorEmailController.text = person?.email ?? '';
|
||||||
|
setState(() {});
|
||||||
|
},
|
||||||
|
),
|
||||||
|
8.height,
|
||||||
|
SingleItemDropDownMenu<SuppPersons, NullableLoadingProvider>(
|
||||||
|
key: ValueKey(_demoFormModel.supEngineer?.id),
|
||||||
|
context: context,
|
||||||
|
backgroundColor: _demoFormModel.vendor?.suppliername == null
|
||||||
|
? context.isDark
|
||||||
|
? AppColor.neutral20
|
||||||
|
: AppColor.neutral40
|
||||||
|
: AppColor.fieldBgColor(context),
|
||||||
|
title: "Representative Name".addTranslation,
|
||||||
|
showShadow: false,
|
||||||
|
enabled: _demoFormModel.vendor?.suppPersons?.isNotEmpty ?? false,
|
||||||
|
staticData: _demoFormModel.vendor?.suppPersons,
|
||||||
|
showAsBottomSheet: true,
|
||||||
|
initialValue: _demoFormModel.supEngineer == null ? null : SuppPersons.fromJson(_demoFormModel.supEngineer?.toJson()),
|
||||||
|
onSelect: (suppPerson) {
|
||||||
|
if (suppPerson != null) {
|
||||||
|
_demoFormModel.supEngineer = SuppEngineerWorkOrders.fromJson(suppPerson.toJson());
|
||||||
|
|
||||||
|
setState(() {});
|
||||||
|
}
|
||||||
|
},
|
||||||
|
),
|
||||||
|
8.height,
|
||||||
|
AppTextFormField(
|
||||||
|
controller: vendorPhoneController,
|
||||||
|
enable: false,
|
||||||
|
labelText: "Contact Number",
|
||||||
|
style: Theme.of(context).textTheme.titleMedium,
|
||||||
|
backgroundColor: AppColor.fieldBgColor(context),
|
||||||
|
labelStyle: AppTextStyles.textFieldLabelStyle.copyWith(color: AppColor.textColor(context)),
|
||||||
|
showShadow: false,
|
||||||
|
textInputType: TextInputType.phone,
|
||||||
|
textInputAction: TextInputAction.next,
|
||||||
|
onChange: (value) {
|
||||||
|
_demoFormModel.vendorNumber = value;
|
||||||
|
},
|
||||||
|
),
|
||||||
|
8.height,
|
||||||
|
AppTextFormField(
|
||||||
|
labelText: "Email",
|
||||||
|
controller: vendorEmailController,
|
||||||
|
enable: false,
|
||||||
|
style: Theme.of(context).textTheme.titleMedium,
|
||||||
|
backgroundColor: AppColor.fieldBgColor(context),
|
||||||
|
labelStyle: AppTextStyles.textFieldLabelStyle.copyWith(color: AppColor.textColor(context)),
|
||||||
|
showShadow: false,
|
||||||
|
textInputType: TextInputType.emailAddress,
|
||||||
|
textInputAction: TextInputAction.next,
|
||||||
|
onChange: (value) {
|
||||||
|
_demoFormModel.vendorEmail = value;
|
||||||
|
},
|
||||||
|
),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> _update() async {
|
||||||
|
FocusScope.of(context).unfocus();
|
||||||
|
if (_formKey.currentState!.validate()) {
|
||||||
|
_formKey.currentState!.save();
|
||||||
|
_demoFormModel.demoAttachment = [];
|
||||||
|
for (var item in attachments) {
|
||||||
|
String fileName = CMRequestUtils.isLocalUrl(item.name ?? '') ? ("${item.name ?? ''.split("/").last}|${base64Encode(File(item.name ?? '').readAsBytesSync())}") : item.name ?? '';
|
||||||
|
_demoFormModel.demoAttachment?.add(DemoAttachments(id: 0, attachmentName: fileName, demoRequestId: 0));
|
||||||
|
_demoFormModel.demoAttachment?.add(DemoAttachments(id: item.id, demoRequestId: _demoFormModel.id ?? 0, attachmentName: fileName));
|
||||||
|
}
|
||||||
|
Utils.showLoading(context);
|
||||||
|
DemoProvider demoProvider = Provider.of<DemoProvider>(context, listen: false);
|
||||||
|
bool isSuccess = await demoProvider.updateDemoRequest(_demoFormModel.toUpdateJson());
|
||||||
|
Utils.hideLoading(context);
|
||||||
|
if (isSuccess) {
|
||||||
|
Navigator.pop(context, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue