first commit
This commit is contained in:
75
lib/repository/auth_repository.dart
Normal file
75
lib/repository/auth_repository.dart
Normal file
@@ -0,0 +1,75 @@
|
||||
import '../app/constant.dart';
|
||||
import '../model/auth_model.dart';
|
||||
import 'base_repository.dart';
|
||||
|
||||
class AuthRepository extends BaseRepository {
|
||||
AuthRepository({required super.dio});
|
||||
|
||||
Future<AuthModel> login({
|
||||
required String username,
|
||||
required String password,
|
||||
// required String company_id,
|
||||
// required String regional_id,
|
||||
}) async {
|
||||
final param = {
|
||||
"username": username,
|
||||
"password": password,
|
||||
// "company_id": company_id,
|
||||
// "regional_id": regional_id
|
||||
|
||||
// "username": "alhadad1",
|
||||
// "doctor_id": "2891",
|
||||
// "password": "3"
|
||||
};
|
||||
final service = "${Constant.baseUrl}auth/login";
|
||||
final resp = await post(param: param, service: service);
|
||||
final result = AuthModel.fromJson(resp['data']['user']);
|
||||
result.token = resp['data']['token'];
|
||||
return result;
|
||||
}
|
||||
|
||||
Future<String> logout({
|
||||
required String M_UserID,
|
||||
required String M_UserUsername,
|
||||
}) async {
|
||||
final param = {
|
||||
"M_UserID": M_UserID,
|
||||
"username": M_UserUsername
|
||||
// "username": "alhadad",
|
||||
// "doctor_id": "3101210841",
|
||||
// "password": "riau123"
|
||||
};
|
||||
|
||||
final service = "${Constant.baseUrl}auth/logout";
|
||||
final resp = await post(param: param, service: service);
|
||||
|
||||
if (resp["status"] == "OK") {
|
||||
return resp['status'];
|
||||
} else {
|
||||
return resp['message'];
|
||||
}
|
||||
}
|
||||
|
||||
Future<String> changePassword({
|
||||
required String token,
|
||||
required String current_password,
|
||||
required String new_password,
|
||||
required String password_confirmation,
|
||||
}) async {
|
||||
final param = {
|
||||
"token": token,
|
||||
"current_password": current_password,
|
||||
"new_password": new_password,
|
||||
"password_confirmation": password_confirmation
|
||||
};
|
||||
|
||||
final service = "${Constant.baseUrl}auth/changepassword";
|
||||
final resp = await post(param: param, service: service);
|
||||
|
||||
if (resp["status"] == "OK") {
|
||||
return resp['data'];
|
||||
} else {
|
||||
return resp['data'];
|
||||
}
|
||||
}
|
||||
}
|
||||
100
lib/repository/base_repository.dart
Normal file
100
lib/repository/base_repository.dart
Normal file
@@ -0,0 +1,100 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:dio/dio.dart';
|
||||
|
||||
abstract class BaseRepository {
|
||||
final Dio dio;
|
||||
BaseRepository({required this.dio});
|
||||
|
||||
Future<Map<String, dynamic>> post({
|
||||
required Map<String, dynamic> param,
|
||||
required String service,
|
||||
String? token,
|
||||
}) async {
|
||||
try {
|
||||
final response = await dio.post(
|
||||
service,
|
||||
data: jsonEncode(param),
|
||||
options: Options(
|
||||
headers: token != null
|
||||
? {
|
||||
HttpHeaders.contentTypeHeader: "application/json",
|
||||
HttpHeaders.authorizationHeader: "Bearer $token",
|
||||
}
|
||||
: {
|
||||
HttpHeaders.contentTypeHeader: "application/json",
|
||||
},
|
||||
contentType: "application/json",
|
||||
),
|
||||
);
|
||||
if (response.statusCode != 200) {
|
||||
throw BaseRepositoryException(
|
||||
message: "Invalid Http Response ${response.statusCode}",
|
||||
);
|
||||
}
|
||||
Map<String, dynamic> jsonData = jsonDecode(response.data);
|
||||
if (jsonData["status"] != "OK") {
|
||||
throw BaseRepositoryException(
|
||||
message: jsonData["message"],
|
||||
);
|
||||
} else {
|
||||
return jsonData;
|
||||
}
|
||||
} on DioException catch (e) {
|
||||
throw BaseRepositoryException(message: e.message);
|
||||
} on SocketException catch (e) {
|
||||
throw BaseRepositoryException(message: e.message);
|
||||
} on BaseRepositoryException catch (e) {
|
||||
throw BaseRepositoryException(message: e.message);
|
||||
}
|
||||
}
|
||||
|
||||
Future<Map<String, dynamic>> get({
|
||||
required String service,
|
||||
String? token,
|
||||
}) async {
|
||||
try {
|
||||
final response = await dio.get(
|
||||
service,
|
||||
options: Options(
|
||||
headers: token != null
|
||||
? {
|
||||
HttpHeaders.contentTypeHeader: "application/json",
|
||||
HttpHeaders.authorizationHeader: "Bearer $token",
|
||||
}
|
||||
: {
|
||||
HttpHeaders.contentTypeHeader: "application/json",
|
||||
},
|
||||
contentType: "application/json",
|
||||
),
|
||||
);
|
||||
if (response.statusCode != 200) {
|
||||
throw BaseRepositoryException(
|
||||
message: "Invalid Http Response ${response.statusCode}",
|
||||
);
|
||||
}
|
||||
Map<String, dynamic> jsonData = jsonDecode(response.data);
|
||||
if (jsonData["status"] != "OK") {
|
||||
throw BaseRepositoryException(
|
||||
message: jsonData["message"],
|
||||
);
|
||||
} else {
|
||||
return jsonData;
|
||||
}
|
||||
} on DioException catch (e) {
|
||||
throw BaseRepositoryException(message: e.message);
|
||||
} on SocketException catch (e) {
|
||||
throw BaseRepositoryException(message: e.message);
|
||||
} on BaseRepositoryException catch (e) {
|
||||
throw BaseRepositoryException(message: e.message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class BaseRepositoryException implements Exception {
|
||||
final String? message;
|
||||
BaseRepositoryException({
|
||||
required this.message,
|
||||
});
|
||||
}
|
||||
43
lib/repository/dashboard_repository.dart
Normal file
43
lib/repository/dashboard_repository.dart
Normal file
@@ -0,0 +1,43 @@
|
||||
import 'package:mitra_corporate/model/chart_data_model.dart';
|
||||
import 'package:mitra_corporate/model/surat_jalan_model.dart';
|
||||
|
||||
import '../app/constant.dart';
|
||||
import 'base_repository.dart';
|
||||
|
||||
class DashboardRepository extends BaseRepository {
|
||||
DashboardRepository({required super.dio});
|
||||
|
||||
Future<ChartDataModel> getChartData({
|
||||
required String token,
|
||||
required String filter,
|
||||
required String company_id,
|
||||
}) async {
|
||||
final param = {"token": token, "filter": filter, "company_id": company_id};
|
||||
// print(param);
|
||||
final service = "${Constant.baseUrl}dashboard/chartdata";
|
||||
final resp = await post(param: param, service: service);
|
||||
final result = ChartDataModel.fromJson(resp['data']);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
Future<List<SuratJalanModel>> getOrder(
|
||||
{required String token, required String companyID}) async {
|
||||
final param = {"token": token, "company_id": companyID};
|
||||
// print(param);
|
||||
final service = "${Constant.baseUrl}dashboard/getdelivery";
|
||||
final resp = await post(param: param, service: service);
|
||||
// print(resp);
|
||||
List<SuratJalanModel> data = List.empty(growable: true);
|
||||
if (resp['status'] == 'OK') {
|
||||
resp['data'].forEach((e) {
|
||||
final model = SuratJalanModel.fromJson(e);
|
||||
data.add(model);
|
||||
});
|
||||
} else {
|
||||
data = [];
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
}
|
||||
72
lib/repository/order_repository.dart
Normal file
72
lib/repository/order_repository.dart
Normal file
@@ -0,0 +1,72 @@
|
||||
import 'package:mitra_corporate/model/search_order_model.dart';
|
||||
|
||||
import '../app/constant.dart';
|
||||
import '../model/registration_model.dart';
|
||||
import 'base_repository.dart';
|
||||
|
||||
class OrderRepository extends BaseRepository {
|
||||
OrderRepository({required super.dio});
|
||||
|
||||
Future<SearchOrderModel> searchOrder(
|
||||
{required String token,
|
||||
required String page,
|
||||
required String keyword,
|
||||
required String rpp,
|
||||
required String startDate,
|
||||
required String endDate,
|
||||
required String companyID}) async {
|
||||
final param = {
|
||||
"token": token,
|
||||
"keyword": keyword,
|
||||
"page": page,
|
||||
"rpp": rpp,
|
||||
"company_id": companyID,
|
||||
"start_date": startDate,
|
||||
"end_date": endDate
|
||||
};
|
||||
// print(param);
|
||||
final service = "${Constant.baseUrl}order/getorder";
|
||||
final resp = await post(param: param, service: service);
|
||||
SearchOrderModel data;
|
||||
// print(resp);
|
||||
if (resp['status'] == 'OK') {
|
||||
data = SearchOrderModel.fromJson(resp['data']);
|
||||
} else {
|
||||
data = SearchOrderModel();
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
Future<String> editOrder({required RegistrationModel prm}) async {
|
||||
final url = "${Constant.baseUrl}order/editorder";
|
||||
final resp = await post(param: prm.toJson(), service: url);
|
||||
String number;
|
||||
// print(resp['data']);
|
||||
if (resp['status'] == 'OK') {
|
||||
number = resp['data'];
|
||||
} else {
|
||||
number = "";
|
||||
}
|
||||
|
||||
return number;
|
||||
}
|
||||
|
||||
Future<String> cancelOrder({
|
||||
required String token,
|
||||
required String orderID,
|
||||
}) async {
|
||||
var param = {"token": token, "id": orderID};
|
||||
final url = "${Constant.baseUrl}order/cancel";
|
||||
final resp = await post(param: param, service: url);
|
||||
String data;
|
||||
// print(resp['data']);
|
||||
if (resp['status'] == 'OK') {
|
||||
data = resp['data'];
|
||||
} else {
|
||||
data = "";
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
}
|
||||
66
lib/repository/patient_repository.dart
Normal file
66
lib/repository/patient_repository.dart
Normal file
@@ -0,0 +1,66 @@
|
||||
import 'package:mitra_corporate/model/search_patient_model.dart';
|
||||
|
||||
import '../app/constant.dart';
|
||||
import '../model/registration_model.dart';
|
||||
import 'base_repository.dart';
|
||||
|
||||
class PatientRepository extends BaseRepository {
|
||||
PatientRepository({required super.dio});
|
||||
|
||||
Future<SearchPatientModel> search(
|
||||
{required String token,
|
||||
required String page,
|
||||
required String keyword,
|
||||
required String rpp,
|
||||
required String companyID}) async {
|
||||
final param = {
|
||||
"token": token,
|
||||
"keyword": keyword,
|
||||
"page": page,
|
||||
"rpp": rpp,
|
||||
"company_id": companyID
|
||||
};
|
||||
// print(param);
|
||||
final service = "${Constant.baseUrl}patient/search";
|
||||
final resp = await post(param: param, service: service);
|
||||
SearchPatientModel data;
|
||||
// print(resp);
|
||||
if (resp['status'] == 'OK') {
|
||||
data = SearchPatientModel.fromJson(resp['data']);
|
||||
} else {
|
||||
data = SearchPatientModel();
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
Future<String> editPatient({required RegistrationModel prm}) async {
|
||||
final url = "${Constant.baseUrl}Patient/editpatient";
|
||||
final resp = await post(param: prm.toJson(), service: url);
|
||||
String msg;
|
||||
// print(resp['data']);
|
||||
if (resp['status'] == 'OK') {
|
||||
msg = resp['data'];
|
||||
} else {
|
||||
msg = "";
|
||||
}
|
||||
|
||||
return msg;
|
||||
}
|
||||
|
||||
Future<String> deletePatient(
|
||||
{required String patient_id, required String token}) async {
|
||||
final prm = {"patient_id": patient_id, "token": token};
|
||||
final url = "${Constant.baseUrl}Patient/deletePatient";
|
||||
final resp = await post(param: prm, service: url);
|
||||
String msg;
|
||||
// print(resp['data']);
|
||||
if (resp['status'] == 'OK') {
|
||||
msg = resp['data'];
|
||||
} else {
|
||||
msg = "";
|
||||
}
|
||||
|
||||
return msg;
|
||||
}
|
||||
}
|
||||
86
lib/repository/registration_repository.dart
Normal file
86
lib/repository/registration_repository.dart
Normal file
@@ -0,0 +1,86 @@
|
||||
import 'package:mitra_corporate/model/registration_filter_model.dart';
|
||||
import 'package:mitra_corporate/model/registration_model.dart';
|
||||
import 'package:mitra_corporate/model/test_model.dart';
|
||||
|
||||
import '../app/constant.dart';
|
||||
import 'base_repository.dart';
|
||||
|
||||
class RegistrationRepository extends BaseRepository {
|
||||
RegistrationRepository({required super.dio});
|
||||
|
||||
Future<List<TestModel>> getFPP({
|
||||
required String mouID,
|
||||
required String token,
|
||||
}) async {
|
||||
var param = {"mou_id": mouID, "token": token};
|
||||
// print(param);
|
||||
final url = "${Constant.baseUrl}fpp/load";
|
||||
final resp = await post(param: param, service: url);
|
||||
List<TestModel> data;
|
||||
// print(resp['data']);
|
||||
if (resp['status'] == 'OK') {
|
||||
data = [];
|
||||
resp['data'].forEach((e) {
|
||||
final model = TestModel.fromJson(e);
|
||||
data.add(model);
|
||||
});
|
||||
} else {
|
||||
data = [];
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
Future<RegistrationFilterModel> getFilter({
|
||||
required String token,
|
||||
}) async {
|
||||
var param = {"token": token};
|
||||
final url = "${Constant.baseUrl}Registration/getfilter";
|
||||
final resp = await post(param: param, service: url);
|
||||
RegistrationFilterModel data;
|
||||
// print(resp['data']);
|
||||
if (resp['status'] == 'OK') {
|
||||
data = RegistrationFilterModel.fromJson(resp['data']);
|
||||
} else {
|
||||
data = RegistrationFilterModel();
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
Future<List<GetSpecimenModel>> getSpecimen({
|
||||
required String token,
|
||||
required List<Map<String, String>> arrTest,
|
||||
}) async {
|
||||
var param = {"token": token, "arr_test": arrTest};
|
||||
final url = "${Constant.baseUrl}Registration/getsampletype";
|
||||
final resp = await post(param: param, service: url);
|
||||
List<GetSpecimenModel> data;
|
||||
// print(resp['data']);
|
||||
if (resp['status'] == 'OK') {
|
||||
data = [];
|
||||
resp['data'].forEach((e) {
|
||||
final model = GetSpecimenModel.fromJson(e);
|
||||
data.add(model);
|
||||
});
|
||||
} else {
|
||||
data = [];
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
Future<String> addOrder({required RegistrationModel prm}) async {
|
||||
final url = "${Constant.baseUrl}Registration/addpatient";
|
||||
final resp = await post(param: prm.toJson(), service: url);
|
||||
String number;
|
||||
// print(resp['data']);
|
||||
if (resp['status'] == 'OK') {
|
||||
number = resp['data']['orderNumber'];
|
||||
} else {
|
||||
number = "";
|
||||
}
|
||||
|
||||
return number;
|
||||
}
|
||||
}
|
||||
222
lib/repository/surat_jalan_repository.dart
Normal file
222
lib/repository/surat_jalan_repository.dart
Normal file
@@ -0,0 +1,222 @@
|
||||
import 'package:mitra_corporate/model/create_surat_jalan_model.dart';
|
||||
import 'package:mitra_corporate/model/delivery_type_model.dart';
|
||||
import 'package:mitra_corporate/model/destination_model.dart';
|
||||
import 'package:mitra_corporate/model/order_model.dart';
|
||||
import 'package:mitra_corporate/model/registration_filter_model.dart';
|
||||
import 'package:mitra_corporate/model/surat_jalan_detail_model.dart';
|
||||
|
||||
import '../app/constant.dart';
|
||||
import '../model/surat_jalan_model.dart';
|
||||
import 'base_repository.dart';
|
||||
|
||||
class SuratJalanRepository extends BaseRepository {
|
||||
SuratJalanRepository({required super.dio});
|
||||
|
||||
Future<List<DeliveryTypeModel>> getDeliveryType({
|
||||
required String token,
|
||||
}) async {
|
||||
var param = {"token": token};
|
||||
final url = "${Constant.baseUrl}deliveryorder/getdeliverytype";
|
||||
final resp = await post(param: param, service: url);
|
||||
List<DeliveryTypeModel> data;
|
||||
// print(resp['data']);
|
||||
if (resp['status'] == 'OK') {
|
||||
data = [];
|
||||
resp['data'].forEach((e) {
|
||||
final model = DeliveryTypeModel.fromJson(e);
|
||||
data.add(model);
|
||||
});
|
||||
} else {
|
||||
data = [];
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
Future<List<OrderModel>> getOrder({
|
||||
required String token,
|
||||
required String company_id,
|
||||
required String regional_id,
|
||||
}) async {
|
||||
var param = {
|
||||
"token": token,
|
||||
"company_id": company_id,
|
||||
"regional_id": regional_id
|
||||
};
|
||||
final url = "${Constant.baseUrl}deliveryorder/getorder";
|
||||
final resp = await post(param: param, service: url);
|
||||
List<OrderModel> data;
|
||||
// print(resp['data']);
|
||||
if (resp['status'] == 'OK') {
|
||||
data = [];
|
||||
resp['data'].forEach((e) {
|
||||
final model = OrderModel.fromJson(e);
|
||||
data.add(model);
|
||||
});
|
||||
} else {
|
||||
data = [];
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
Future<String> createSuratJalan({required CreateSuratJalanModel prm}) async {
|
||||
final url = "${Constant.baseUrl}deliveryorder/addDelivery";
|
||||
final resp = await post(param: prm.toJson(), service: url);
|
||||
String number;
|
||||
// print(resp['data']);
|
||||
if (resp['status'] == 'OK') {
|
||||
number = resp['data']['orderNumber'];
|
||||
} else {
|
||||
number = "";
|
||||
}
|
||||
|
||||
return number;
|
||||
}
|
||||
|
||||
Future<SearchSuratJalanModel> getSuratJalan({
|
||||
required String token,
|
||||
required String company_id,
|
||||
required String rpp,
|
||||
required String keyword,
|
||||
required String page,
|
||||
required String startDate,
|
||||
required String endDate,
|
||||
required String dateType,
|
||||
}) async {
|
||||
var param = {
|
||||
"token": token,
|
||||
"page": page,
|
||||
"keyword": keyword,
|
||||
"rpp": rpp,
|
||||
"company_id": company_id,
|
||||
"start_date": startDate,
|
||||
"end_date": endDate,
|
||||
"date_type": dateType
|
||||
};
|
||||
final url = "${Constant.baseUrl}deliveryorder/getdelivery";
|
||||
final resp = await post(param: param, service: url);
|
||||
SearchSuratJalanModel data;
|
||||
// print(resp);
|
||||
if (resp['status'] == 'OK') {
|
||||
data = SearchSuratJalanModel.fromJson(resp['data']);
|
||||
} else {
|
||||
data = SearchSuratJalanModel();
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
Future<List<SuratJalanDetailModel>> getSuratJalanSetail({
|
||||
required String token,
|
||||
required String deliveryID,
|
||||
}) async {
|
||||
var param = {"token": token, "id": deliveryID};
|
||||
final url = "${Constant.baseUrl}deliveryorder/detaildelivery";
|
||||
final resp = await post(param: param, service: url);
|
||||
List<SuratJalanDetailModel> data;
|
||||
// print(resp['data']);
|
||||
if (resp['status'] == 'OK') {
|
||||
data = [];
|
||||
resp['data'].forEach((e) {
|
||||
final model = SuratJalanDetailModel.fromJson(e);
|
||||
data.add(model);
|
||||
});
|
||||
} else {
|
||||
data = [];
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
Future<String> cancelSuratJalan({
|
||||
required String token,
|
||||
required String deliveryID,
|
||||
}) async {
|
||||
var param = {"token": token, "id": deliveryID};
|
||||
final url = "${Constant.baseUrl}deliveryorder/cancel";
|
||||
final resp = await post(param: param, service: url);
|
||||
String data;
|
||||
// print(resp['data']);
|
||||
if (resp['status'] == 'OK') {
|
||||
data = resp['data'];
|
||||
} else {
|
||||
data = "";
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
Future<String> sendSuratJalan({
|
||||
required String token,
|
||||
required String deliveryID,
|
||||
}) async {
|
||||
var param = {"token": token, "id": deliveryID};
|
||||
final url = "${Constant.baseUrl}deliveryorder/send";
|
||||
final resp = await post(param: param, service: url);
|
||||
String data;
|
||||
// print(resp['data']);
|
||||
if (resp['status'] == 'OK') {
|
||||
data = resp['data'];
|
||||
} else {
|
||||
data = "";
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
Future<List<DestinationModel>> getDestination({
|
||||
required String token,
|
||||
}) async {
|
||||
var param = {"token": token};
|
||||
final url = "${Constant.baseUrl}deliveryorder/getdestination";
|
||||
final resp = await post(param: param, service: url);
|
||||
List<DestinationModel> data = List.empty(growable: true);
|
||||
if (resp['status'] == 'OK') {
|
||||
data = [];
|
||||
resp['data'].forEach((e) {
|
||||
final model = DestinationModel.fromJson(e);
|
||||
data.add(model);
|
||||
});
|
||||
} else {
|
||||
data = [];
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
Future<List<RegionalModel>> getRegional({
|
||||
required String token,
|
||||
}) async {
|
||||
var param = {"token": token};
|
||||
final url = "${Constant.baseUrl}deliveryorder/getregional";
|
||||
final resp = await post(param: param, service: url);
|
||||
List<RegionalModel> data = List.empty(growable: true);
|
||||
if (resp['status'] == 'OK') {
|
||||
data = [];
|
||||
resp['data'].forEach((e) {
|
||||
final model = RegionalModel.fromJson(e);
|
||||
data.add(model);
|
||||
});
|
||||
} else {
|
||||
data = [];
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
Future<String> sendQrCode(
|
||||
{required String token, required List<String> arrOrderID}) async {
|
||||
var param = {"token": token, 'arr_order_id': arrOrderID};
|
||||
final url = "${Constant.baseUrl}deliveryorder/sendqrcode";
|
||||
final resp = await post(param: param, service: url);
|
||||
String data = "";
|
||||
if (resp['status'] == 'OK') {
|
||||
data = "OK";
|
||||
} else {
|
||||
data = "ERROR";
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user