Browse Source

Save and Refresh List

main
padmanto 2 years ago
parent
commit
af71edf665
  1. 4
      lib/repository/mitra_repository.dart
  2. 2
      lib/widget/fx_data_mitra.dart
  3. 47
      lib/widget/fx_mitra_add_dialog.dart
  4. 4
      lib/widget/fx_text_field.dart
  5. 5
      lib/widget/provider/mitra_add_provider.dart
  6. 41
      php-api/mitra/Md.php

4
lib/repository/mitra_repository.dart

@ -17,6 +17,7 @@ class MitraRepository extends BaseRepository {
required String doctorID, required String doctorID,
required String doctorAddressID, required String doctorAddressID,
required String login, required String login,
required String password,
CancelToken? cancelToken, CancelToken? cancelToken,
}) async { }) async {
final param = { final param = {
@ -25,7 +26,8 @@ class MitraRepository extends BaseRepository {
"mouID": mouID, "mouID": mouID,
"doctorID": doctorID, "doctorID": doctorID,
"doctorAddressID": doctorAddressID, "doctorAddressID": doctorAddressID,
"login": login "login": login,
"password": password
}; };
final service = "${Constants.baseUrl}md/add"; final service = "${Constants.baseUrl}md/add";

2
lib/widget/fx_data_mitra.dart

@ -63,7 +63,7 @@ class FxDataMitra extends HookConsumerWidget {
await showDialog( await showDialog(
context: context, context: context,
builder: (context) { builder: (context) {
return FxMitraAddDialog(); return const FxMitraAddDialog();
}); });
}), }),
), ),

47
lib/widget/fx_mitra_add_dialog.dart

@ -30,11 +30,26 @@ class FxMitraAddDialog extends HookConsumerWidget {
final errorMou = useState<String?>(null); final errorMou = useState<String?>(null);
final errorLogin = useState<String?>(null); final errorLogin = useState<String?>(null);
final fcPassword = FocusNode();
final fcRePassword = FocusNode();
final errorPassword = useState<String?>(null);
final errorRePassword = useState<String?>(null);
final ctrlLogin = useTextEditingController(text: ""); final ctrlLogin = useTextEditingController(text: "");
final ctrlPassword = useTextEditingController(text: "");
final ctrlRePassword = useTextEditingController(text: "");
bool Function() validationError; bool Function() validationError;
validationError = () { validationError = () {
bool haveError = false; bool haveError = false;
if (ctrlPassword.text == "") {
errorPassword.value = "Password is mandatory";
haveError = true;
}
if (ctrlRePassword.text != ctrlPassword.text) {
errorRePassword.value = "Password confirmation error";
haveError = true;
}
if (company == null) { if (company == null) {
errorCompany.value = "Company is mandatory"; errorCompany.value = "Company is mandatory";
haveError = true; haveError = true;
@ -102,12 +117,31 @@ class FxMitraAddDialog extends HookConsumerWidget {
errorMessage: errorLogin.value, errorMessage: errorLogin.value,
), ),
const SizedBox(height: 10), const SizedBox(height: 10),
FxTextField(
ctrl: ctrlPassword,
fc: fcPassword,
hint: "Password",
label: "Password",
obscureText: true,
errorMessage: errorPassword.value,
),
const SizedBox(height: 10),
FxTextField(
ctrl: ctrlRePassword,
fc: fcRePassword,
hint: "Retype Password",
label: "Retype Password",
obscureText: true,
errorMessage: errorRePassword.value,
),
const SizedBox(height: 10),
const FxTextField( const FxTextField(
hint: "ID", hint: "ID",
label: "ID", label: "ID",
isReadOnly: true, isReadOnly: true,
isEnabled: false, isEnabled: false,
suffixText: "Auto Generated"), suffixText: "Auto Generated",
),
const SizedBox(height: 10), const SizedBox(height: 10),
Row( Row(
mainAxisAlignment: MainAxisAlignment.end, mainAxisAlignment: MainAxisAlignment.end,
@ -128,7 +162,10 @@ class FxMitraAddDialog extends HookConsumerWidget {
doctorAddressID: doctorAddressID:
doctorAddress!.mDoctorAddressID, doctorAddress!.mDoctorAddressID,
login: ctrlLogin.text, login: ctrlLogin.text,
password: ctrlPassword.text,
query: "",
); );
Navigator.of(context).pop();
} }
}, },
child: const Text("Save"), child: const Text("Save"),

4
lib/widget/fx_text_field.dart

@ -9,7 +9,7 @@ class FxTextField extends StatelessWidget {
final bool? isReadOnly; final bool? isReadOnly;
final bool? isEnabled; final bool? isEnabled;
final String? suffixText; final String? suffixText;
final bool obscureText;
const FxTextField({ const FxTextField({
Key? key, Key? key,
this.ctrl, this.ctrl,
@ -20,11 +20,13 @@ class FxTextField extends StatelessWidget {
this.isReadOnly, this.isReadOnly,
this.isEnabled, this.isEnabled,
this.suffixText, this.suffixText,
this.obscureText = false,
}) : super(key: key); }) : super(key: key);
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return TextField( return TextField(
obscureText: obscureText,
decoration: InputDecoration( decoration: InputDecoration(
border: OutlineInputBorder( border: OutlineInputBorder(
borderRadius: BorderRadius.circular(10), borderRadius: BorderRadius.circular(10),

5
lib/widget/provider/mitra_add_provider.dart

@ -6,6 +6,7 @@ import '../../provider/dio_provider.dart';
import '../../provider/local_auth_provider.dart'; import '../../provider/local_auth_provider.dart';
import '../../repository/base_repository.dart'; import '../../repository/base_repository.dart';
import '../../repository/mitra_repository.dart'; import '../../repository/mitra_repository.dart';
import '../../screen/md_lab_mitra/mitra_search_provider.dart';
final mitraAddProvider = StateNotifierProvider<MitraAddNotifier, MitraAddState>( final mitraAddProvider = StateNotifierProvider<MitraAddNotifier, MitraAddState>(
(ref) => MitraAddNotifier(ref: ref), (ref) => MitraAddNotifier(ref: ref),
@ -28,6 +29,8 @@ class MitraAddNotifier extends StateNotifier<MitraAddState> {
required String doctorID, required String doctorID,
required String doctorAddressID, required String doctorAddressID,
required String login, required String login,
required String password,
required String query,
}) async { }) async {
try { try {
state = MitraAddStateLoading(); state = MitraAddStateLoading();
@ -43,8 +46,10 @@ class MitraAddNotifier extends StateNotifier<MitraAddState> {
doctorID: doctorID, doctorID: doctorID,
doctorAddressID: doctorAddressID, doctorAddressID: doctorAddressID,
login: login, login: login,
password: password,
); );
state = MitraAddStateDone(); state = MitraAddStateDone();
ref.read(mitraSearchProvider.notifier).search(query: query);
} catch (e) { } catch (e) {
if (e is BaseRepositoryException) { if (e is BaseRepositoryException) {
state = MitraAddStateError(message: e.message); state = MitraAddStateError(message: e.message);

41
php-api/mitra/Md.php

@ -15,8 +15,45 @@ class Md extends MY_Controller
function add() function add()
{ {
$param = $this->sys_input; $param = $this->sys_input;
$sql = "insert into "; $user = $this->sys_user;
print_r($param); $userID = $user["M_UserID"];
$this->db->trans_begin();
$sql = "insert into mitra(MitraM_CompanyID, MitraM_DoctorID,
MitraM_DoctorAddressID,MitraUsername,
MitraPassword, MitraM_UserID,
MitraIDNo, MitraCommitment)
values(?,?, ?,?, ?,?, fn_generate_mitra_id(),'')";
$qry = $this->db->query($sql, [
$param["companyID"], $param["doctorID"],
$param["doctorAddressID"], $param["login"],
$param["password"], $userID
]);
if (!$qry) {
echo json_encode([
"status" => "ERR",
"message" => $this->db->error()["message"],
]);
exit();
}
$mitraID = $this->db->insert_id();
$sql = "insert into mitra_mou(MitraMouMitraID,MitraMouM_MouID,
MitraMouM_UserID)
values(?,?,?)";
foreach ($param["mouID"] as $mouID) {
$qry = $this->db->query($sql, [$mitraID, $mouID, $userID]);
if (!$qry) {
echo json_encode([
"status" => "ERR",
"message" => $this->db->error()["message"],
]);
$this->db->trans_rollback();
exit();
}
}
$this->db->trans_commit();
echo json_encode(["status" => "OK"]);
} }
function corss() function corss()

Loading…
Cancel
Save