Browse Source

Delete Mitra

main
padmanto 2 years ago
parent
commit
c1f854bc68
  1. 15
      lib/repository/mitra_repository.dart
  2. 49
      lib/widget/fx_data_mitra.dart
  3. 75
      lib/widget/provider/mitra_delete_provider.dart
  4. 41
      php-api/mitra/Md.php

15
lib/repository/mitra_repository.dart

@ -10,6 +10,21 @@ import 'base_repository.dart';
class MitraRepository extends BaseRepository { class MitraRepository extends BaseRepository {
MitraRepository({required super.dio}); MitraRepository({required super.dio});
Future<bool> delete({
required String token,
required String mitraID,
CancelToken? cancelToken,
}) async {
final param = {
"token": token,
"mitraID": mitraID,
};
final service = "${Constants.baseUrl}md/delete";
await post(service: service, jsonParam: param, cancelToken: cancelToken);
return true;
}
Future<bool> add({ Future<bool> add({
required String token, required String token,
required String companyID, required String companyID,

49
lib/widget/fx_data_mitra.dart

@ -5,11 +5,10 @@ import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart'; import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:onemd/model/ac_company_response_model.dart'; import 'package:onemd/model/ac_company_response_model.dart';
import 'package:onemd/model/ac_doctor_model.dart'; import 'package:onemd/model/ac_doctor_model.dart';
import 'package:onemd/widget/provider/mitra_delete_provider.dart';
import '../model/ac_mou_response_model.dart'; import '../model/ac_mou_response_model.dart';
import '../model/mitra_response_model.dart'; import '../model/mitra_response_model.dart';
import '../provider/dio_provider.dart';
import '../repository/mitra_repository.dart';
import '../screen/md_lab_mitra/mitra_lookup_mou_provider.dart'; import '../screen/md_lab_mitra/mitra_lookup_mou_provider.dart';
import '../screen/md_lab_mitra/mitra_search_provider.dart'; import '../screen/md_lab_mitra/mitra_search_provider.dart';
import 'fx_error_text.dart'; import 'fx_error_text.dart';
@ -89,6 +88,44 @@ class FxDataMitra extends HookConsumerWidget {
totalRow: list.value.length, totalRow: list.value.length,
list: list.value, list: list.value,
pageWidth: pageWidth, pageWidth: pageWidth,
onDelete: (model) async {
await showDialog(
context: context,
builder: (context) {
return AlertDialog(
title: const Text("Delete Mitra"),
content: Text(
"Confirm delete ${model.mitraUsername} , ${model.mCompanyName} ?"),
actions: [
TextButton(
onPressed: () {
ref
.read(mitraDeleteProvider.notifier)
.delete(mitraID: model.mitraID, query: "");
Navigator.of(context).pop();
},
style: ButtonStyle(
backgroundColor: MaterialStateColor.resolveWith(
(state) => Colors.red),
),
child: const Text("Delete",
style: TextStyle(color: Colors.white)),
),
TextButton(
style: ButtonStyle(
backgroundColor: MaterialStateColor.resolveWith(
(state) => Colors.green),
),
onPressed: () {
Navigator.of(context).pop();
},
child: const Text("Cancel",
style: TextStyle(color: Colors.white)),
)
],
);
});
},
onEdit: (model) async { onEdit: (model) async {
ref.read(selectedMouProvider.notifier).state = model.aggrementID ref.read(selectedMouProvider.notifier).state = model.aggrementID
.map((id) => AcMouResponseModel( .map((id) => AcMouResponseModel(
@ -179,11 +216,13 @@ class _MitraDataSource extends DataTableSource {
final int totalRow; final int totalRow;
final double pageWidth; final double pageWidth;
final void Function(MitraResponseModel)? onEdit; final void Function(MitraResponseModel)? onEdit;
final void Function(MitraResponseModel)? onDelete;
_MitraDataSource({ _MitraDataSource({
required this.list, required this.list,
required this.totalRow, required this.totalRow,
required this.pageWidth, required this.pageWidth,
this.onEdit, this.onEdit,
this.onDelete,
}); });
@override @override
DataRow? getRow(int index) { DataRow? getRow(int index) {
@ -223,7 +262,11 @@ class _MitraDataSource extends DataTableSource {
), ),
), ),
InkWell( InkWell(
onTap: () {}, onTap: () async {
if (onDelete != null) {
onDelete!(model);
}
},
child: Icon( child: Icon(
Icons.delete_rounded, Icons.delete_rounded,
size: 24, size: 24,

75
lib/widget/provider/mitra_delete_provider.dart

@ -0,0 +1,75 @@
import 'package:dio/dio.dart';
import 'package:equatable/equatable.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import '../../provider/dio_provider.dart';
import '../../provider/local_auth_provider.dart';
import '../../repository/base_repository.dart';
import '../../repository/mitra_repository.dart';
import '../../screen/md_lab_mitra/mitra_search_provider.dart';
final mitraDeleteProvider =
StateNotifierProvider<MitraDeleteNotifier, MitraDeleteState>(
(ref) => MitraDeleteNotifier(ref: ref),
);
class MitraDeleteNotifier extends StateNotifier<MitraDeleteState> {
final Ref ref;
CancelToken? cancelToken;
MitraDeleteNotifier({
required this.ref,
}) : super(MitraDeleteStateInit());
void reset() {
state = MitraDeleteStateInit();
}
void delete({
required String mitraID,
required String query,
}) async {
try {
state = MitraDeleteStateLoading();
final dio = ref.read(dioProvider);
final localAuth = ref.read(localAuthProvider);
if (localAuth?.token == null) {
throw BaseRepositoryException(message: "Invalid Token");
}
await MitraRepository(dio: dio).delete(
mitraID: mitraID,
token: localAuth!.token!,
);
state = MitraDeleteStateDone();
ref.read(mitraSearchProvider.notifier).search(query: query);
} catch (e) {
if (e is BaseRepositoryException) {
state = MitraDeleteStateError(message: e.message);
} else {
state = MitraDeleteStateError(message: "Unknown Error ");
}
}
}
}
abstract class MitraDeleteState extends Equatable {
final DateTime date;
MitraDeleteState() : date = DateTime.now();
@override
List<Object?> get props => throw [date];
}
class MitraDeleteStateInit extends MitraDeleteState {}
class MitraDeleteStateLoading extends MitraDeleteState {}
class MitraDeleteStateError extends MitraDeleteState {
final String message;
MitraDeleteStateError({
required this.message,
});
}
class MitraDeleteStateDone extends MitraDeleteState {
MitraDeleteStateDone();
}

41
php-api/mitra/Md.php

@ -12,6 +12,47 @@ class Md extends MY_Controller
{ {
echo "Mitra:MD:API"; echo "Mitra:MD:API";
} }
function delete()
{
$param = $this->sys_input;
$user = $this->sys_user;
$userID = $user["M_UserID"];
$this->db->trans_begin();
$sql = "update mitra
set MitraIsActive = 'Y',
MitraM_UserID=?
where MitraID = ?";
$qry = $this->db->query($sql, [
$userID, $param["mitraID"]
]);
if (!$qry) {
echo json_encode([
"status" => "ERR",
"message" => $this->db->error()["message"],
]);
exit();
}
$mitraID = $param["mitraID"];
$sql = "update mitra_mou set MitraMouIsActive ='N',
MitraMouM_UserID = ?
where
MitraMouMitraID = ? ";
$qry = $this->db->query($sql, [$userID, $param["mitraID"]]);
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 edit() function edit()
{ {
$param = $this->sys_input; $param = $this->sys_input;

Loading…
Cancel
Save