From 5451bbf877eee50258457fc7a8772d6f25fc601e Mon Sep 17 00:00:00 2001 From: yaso Date: Fri, 29 Nov 2024 11:39:12 +0200 Subject: [PATCH] add practice and vat no to set up and update business --- .../manage_business/business_details.dart | 71 +++--- .../manage_business/profile_business_add.dart | 231 +++--------------- 2 files changed, 80 insertions(+), 222 deletions(-) diff --git a/Frontend/lib/mih_packages/manage_business/business_details.dart b/Frontend/lib/mih_packages/manage_business/business_details.dart index 82265f68..a0654f30 100644 --- a/Frontend/lib/mih_packages/manage_business/business_details.dart +++ b/Frontend/lib/mih_packages/manage_business/business_details.dart @@ -48,14 +48,13 @@ class _BusinessDetailsState extends State { final contactController = TextEditingController(); final emailController = TextEditingController(); final locationController = TextEditingController(); + final practiceNoController = TextEditingController(); + final vatNoController = TextEditingController(); late PlatformFile? selectedLogo = null; late PlatformFile? selectedSignature = null; - // late Future futureBusinessUser; - // BusinessUser? businessUser; - // late Future futureBusiness; - // Business? business; + final ValueNotifier busType = ValueNotifier(""); late String business_id; late String oldLogoPath; @@ -79,32 +78,6 @@ class _BusinessDetailsState extends State { } } - // Future getBusinessUserDetails() async { - // var response = await http - // .get(Uri.parse("$baseAPI/business-user/${widget.signedInUser.app_id}")); - // if (response.statusCode == 200) { - // String body = response.body; - // var decodedData = jsonDecode(body); - // BusinessUser business_User = BusinessUser.fromJson(decodedData); - // return business_User; - // } else { - // return null; - // } - // } - - // Future getBusinessDetails() async { - // var response = await http.get( - // Uri.parse("$baseAPI/business/app_id/${widget.signedInUser.app_id}")); - // if (response.statusCode == 200) { - // String body = response.body; - // var decodedData = jsonDecode(body); - // Business business = Business.fromJson(decodedData); - // return business; - // } else { - // return null; - // } - // } - Future uploadSelectedFile( PlatformFile? file, TextEditingController controller) async { //to-do delete file when changed @@ -183,6 +156,8 @@ class _BusinessDetailsState extends State { "contact_no": contactController.text, "bus_email": emailController.text, "gps_location": locationController.text, + "practice_no": practiceNoController.text, + "vat_no": vatNoController.text, }), ); if (response.statusCode == 200) { @@ -275,6 +250,14 @@ class _BusinessDetailsState extends State { } } + void typeSelected() { + if (typeController.text.isNotEmpty) { + busType.value = typeController.text; + } else { + busType.value = ""; + } + } + @override void dispose() { nameController.dispose(); @@ -289,12 +272,15 @@ class _BusinessDetailsState extends State { contactController.dispose(); emailController.dispose(); locationController.dispose(); + practiceNoController.dispose(); + vatNoController.dispose(); _focusNode.dispose(); super.dispose(); } @override void initState() { + typeController.addListener(typeSelected); setState(() { //businessUser = results; titleController.text = widget.arguments.businessUser!.title; @@ -316,6 +302,8 @@ class _BusinessDetailsState extends State { contactController.text = widget.arguments.business!.contact_no; emailController.text = widget.arguments.business!.bus_email; locationController.text = widget.arguments.business!.gps_location; + practiceNoController.text = widget.arguments.business!.practice_no; + vatNoController.text = widget.arguments.business!.vat_no; }); super.initState(); @@ -374,6 +362,29 @@ class _BusinessDetailsState extends State { editable: true, ), const SizedBox(height: 10.0), + ValueListenableBuilder( + valueListenable: busType, + builder: + (BuildContext context, String value, Widget? child) { + return Visibility( + visible: value == "Doctors Office", + child: MIHTextField( + controller: practiceNoController, + hintText: "Practice Number", + editable: true, + required: true, + ), + ); + }, + ), + const SizedBox(height: 10.0), + MIHTextField( + controller: vatNoController, + hintText: "VAT Number", + editable: true, + required: true, + ), + const SizedBox(height: 10.0), MIHTextField( controller: contactController, hintText: "Contact Number", diff --git a/Frontend/lib/mih_packages/manage_business/profile_business_add.dart b/Frontend/lib/mih_packages/manage_business/profile_business_add.dart index fd496307..76052b74 100644 --- a/Frontend/lib/mih_packages/manage_business/profile_business_add.dart +++ b/Frontend/lib/mih_packages/manage_business/profile_business_add.dart @@ -52,10 +52,14 @@ class _ProfileBusinessAddState extends State { final contactController = TextEditingController(); final emailController = TextEditingController(); final locationController = TextEditingController(); + final practiceNoController = TextEditingController(); + final vatNoController = TextEditingController(); late PlatformFile selectedLogo; late PlatformFile selectedSignature; + final ValueNotifier busType = ValueNotifier(""); + Future uploadSelectedFile( PlatformFile file, TextEditingController controller) async { var token = await SuperTokens.getAccessToken(); @@ -125,6 +129,8 @@ class _ProfileBusinessAddState extends State { "contact_no": contactController.text, "bus_email": emailController.text, "gps_location": locationController.text, + "practice_no": practiceNoController.text, + "vat_no": vatNoController.text, }), ); if (response.statusCode == 201) { @@ -205,6 +211,14 @@ class _ProfileBusinessAddState extends State { return regex.hasMatch(text); } + void typeSelected() { + if (typeController.text.isNotEmpty) { + busType.value = typeController.text; + } else { + busType.value = ""; + } + } + MIHAction getActionButton() { return MIHAction( icon: const Icon(Icons.arrow_back), @@ -281,6 +295,28 @@ class _ProfileBusinessAddState extends State { editable: true, ), const SizedBox(height: 10.0), + ValueListenableBuilder( + valueListenable: busType, + builder: (BuildContext context, String value, Widget? child) { + return Visibility( + visible: value == "Doctors Office", + child: MIHTextField( + controller: practiceNoController, + hintText: "Practice Number", + editable: true, + required: true, + ), + ); + }, + ), + const SizedBox(height: 10.0), + MIHTextField( + controller: vatNoController, + hintText: "VAT Number", + editable: true, + required: true, + ), + const SizedBox(height: 10.0), MIHTextField( controller: contactController, hintText: "Contact Number", @@ -462,12 +498,15 @@ class _ProfileBusinessAddState extends State { contactController.dispose(); emailController.dispose(); locationController.dispose(); + practiceNoController.dispose(); + vatNoController.dispose(); _focusNode.dispose(); super.dispose(); } @override void initState() { + typeController.addListener(typeSelected); setState(() { fnameController.text = widget.signedInUser.fname; lnameController.text = widget.signedInUser.lname; @@ -489,197 +528,5 @@ class _ProfileBusinessAddState extends State { pullDownToRefresh: false, onPullDown: () async {}, ); - - // return Scaffold( - // // appBar: const MIHAppBar( - // // barTitle: "Add Business", - // // propicFile: null, - // // ), - // //drawer: MIHAppDrawer(signedInUser: widget.signedInUser), - // body: SafeArea( - // child: Stack( - // children: [ - // KeyboardListener( - // focusNode: _focusNode, - // autofocus: true, - // onKeyEvent: (event) async { - // if (event is KeyDownEvent && - // event.logicalKey == LogicalKeyboardKey.enter) { - // submitForm(); - // } - // }, - // child: SingleChildScrollView( - // padding: const EdgeInsets.all(15), - // child: Column( - // children: [ - // //const SizedBox(height: 15), - // const Text( - // "Add Business Profile", - // style: TextStyle( - // fontWeight: FontWeight.bold, - // fontSize: 25, - // ), - // ), - // const SizedBox(height: 25.0), - // MIHTextField( - // controller: regController, - // hintText: "Registration No.", - // editable: true, - // required: true, - // ), - // const SizedBox(height: 10.0), - // MIHTextField( - // controller: nameController, - // hintText: "Business Name", - // editable: true, - // required: true, - // ), - // const SizedBox(height: 10.0), - // MIHDropdownField( - // controller: typeController, - // hintText: "Business Type", - // dropdownOptions: const ["Doctors Office", "Other"], - // required: true, - // editable: true, - // ), - // const SizedBox(height: 10.0), - // MIHTextField( - // controller: contactController, - // hintText: "Contact Number", - // editable: true, - // required: true, - // ), - // const SizedBox(height: 10.0), - // MIHTextField( - // controller: emailController, - // hintText: "Email", - // editable: true, - // required: true, - // ), - // const SizedBox(height: 10.0), - // MIHFileField( - // controller: logonameController, - // hintText: "Logo", - // editable: false, - // required: true, - // onPressed: () async { - // FilePickerResult? result = - // await FilePicker.platform.pickFiles( - // type: FileType.custom, - // allowedExtensions: ['jpg', 'png', 'pdf'], - // ); - // if (result == null) return; - // final selectedFile = result.files.first; - // setState(() { - // selectedLogo = selectedFile; - // }); - // setState(() { - // logonameController.text = selectedFile.name; - // }); - // }, - // ), - // const SizedBox(height: 15.0), - // Divider( - // color: MzanziInnovationHub.of(context) - // ?.theme - // .secondaryColor(), - // ), - // //const SizedBox(height: 15.0), - // const Text( - // "My Business User", - // style: TextStyle( - // fontWeight: FontWeight.bold, - // fontSize: 25, - // ), - // ), - // const SizedBox(height: 25.0), - // MIHDropdownField( - // controller: titleController, - // hintText: "Title", - // dropdownOptions: const ["Doctor", "Assistant"], - // required: true, - // editable: true, - // ), - // const SizedBox(height: 10.0), - // MIHTextField( - // controller: fnameController, - // hintText: "Name", - // editable: false, - // required: true, - // ), - // const SizedBox(height: 10.0), - // MIHTextField( - // controller: lnameController, - // hintText: "Surname", - // editable: false, - // required: true, - // ), - // const SizedBox(height: 10.0), - // MIHFileField( - // controller: signtureController, - // hintText: "Signature", - // editable: false, - // required: true, - // onPressed: () async { - // FilePickerResult? result = - // await FilePicker.platform.pickFiles( - // type: FileType.custom, - // allowedExtensions: ['jpg', 'png', 'pdf'], - // ); - // if (result == null) return; - // final selectedFile = result.files.first; - // setState(() { - // selectedSignature = selectedFile; - // }); - // setState(() { - // signtureController.text = selectedFile.name; - // }); - // }, - // ), - // const SizedBox(height: 15.0), - // MIHDropdownField( - // controller: accessController, - // hintText: "Access", - // dropdownOptions: const ["Full", "Partial"], - // required: true, - // editable: false, - // ), - // const SizedBox(height: 30.0), - // SizedBox( - // width: 500.0, - // height: 50.0, - // child: MIHButton( - // buttonText: "Add", - // buttonColor: MzanziInnovationHub.of(context)! - // .theme - // .secondaryColor(), - // textColor: MzanziInnovationHub.of(context)! - // .theme - // .primaryColor(), - // onTap: () { - // submitForm(); - // }, - // ), - // ), - // ], - // ), - // ), - // ), - // Positioned( - // top: 10, - // left: 5, - // width: 50, - // height: 50, - // child: IconButton( - // onPressed: () { - // Navigator.of(context).pop(); - // }, - // icon: const Icon(Icons.arrow_back), - // ), - // ) - // ], - // ), - // ), - // ); } }