first commit
This commit is contained in:
28
lib/Repository/API/business_category_repo.dart
Normal file
28
lib/Repository/API/business_category_repo.dart
Normal file
@@ -0,0 +1,28 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:http/http.dart' as http;
|
||||
|
||||
import '../../Const/api_config.dart';
|
||||
import '../../http_client/customer_http_client_get.dart';
|
||||
import '../../model/business_category_model.dart';
|
||||
import '../constant_functions.dart';
|
||||
|
||||
class BusinessCategoryRepository {
|
||||
Future<List<BusinessCategory>> getBusinessCategories() async {
|
||||
try {
|
||||
CustomHttpClientGet clientGet = CustomHttpClientGet(client: http.Client());
|
||||
final response = await clientGet.get(
|
||||
url: Uri.parse('${APIConfig.url}${APIConfig.businessCategoriesUrl}'),
|
||||
);
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
final data = jsonDecode(response.body)['data'] as List;
|
||||
return data.map((category) => BusinessCategory.fromJson(category)).toList();
|
||||
} else {
|
||||
throw Exception('Failed to fetch business categories');
|
||||
}
|
||||
} catch (error) {
|
||||
throw Exception('Error fetching business categories: $error');
|
||||
}
|
||||
}
|
||||
}
|
||||
98
lib/Repository/API/business_info_repo.dart
Normal file
98
lib/Repository/API/business_info_repo.dart
Normal file
@@ -0,0 +1,98 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:intl/intl.dart';
|
||||
import 'package:mobile_pos/Const/api_config.dart';
|
||||
import 'package:mobile_pos/model/dashboard_overview_model.dart';
|
||||
import 'package:mobile_pos/model/todays_summary_model.dart';
|
||||
|
||||
import '../../http_client/customer_http_client_get.dart';
|
||||
import '../../http_client/subscription_expire_provider.dart';
|
||||
import '../../model/business_info_model.dart';
|
||||
import '../../model/business_info_model_new.dart';
|
||||
import '../constant_functions.dart';
|
||||
|
||||
class BusinessRepository {
|
||||
CustomHttpClientGet clientGet = CustomHttpClientGet(client: http.Client());
|
||||
Future<BusinessInformationModel> fetchBusinessData() async {
|
||||
final uri = Uri.parse('${APIConfig.url}/business');
|
||||
|
||||
final response = await clientGet.get(url: uri);
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
final parsedData = jsonDecode(response.body);
|
||||
return BusinessInformationModel.fromJson(parsedData);
|
||||
} else {
|
||||
throw Exception('Failed to fetch business data');
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> fetchSubscriptionExpireDate({required WidgetRef ref}) async {
|
||||
final uri = Uri.parse('${APIConfig.url}/business');
|
||||
|
||||
final response = await clientGet.get(url: uri);
|
||||
if (response.statusCode == 200) {
|
||||
final parsedData = jsonDecode(response.body);
|
||||
final BusinessInformationModel businessInformation = BusinessInformationModel.fromJson(parsedData);
|
||||
ref.read(subscriptionProvider.notifier).updateSubscription(businessInformation.data?.willExpire);
|
||||
// ref.read(subscriptionProvider.notifier).updateSubscription("2025-01-05");
|
||||
} else {
|
||||
throw Exception('Failed to fetch business data');
|
||||
}
|
||||
}
|
||||
|
||||
Future<BusinessInformationModel?> checkBusinessData() async {
|
||||
CustomHttpClientGet clientGet = CustomHttpClientGet(client: http.Client());
|
||||
final uri = Uri.parse('${APIConfig.url}/business');
|
||||
|
||||
final response = await clientGet.get(url: uri);
|
||||
if (response.statusCode == 200) {
|
||||
final parsedData = jsonDecode(response.body);
|
||||
return BusinessInformationModel.fromJson(parsedData); // Extract the "data" object from the response
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
Future<TodaysSummaryModel> fetchTodaySummaryData() async {
|
||||
CustomHttpClientGet clientGet = CustomHttpClientGet(client: http.Client());
|
||||
String date = DateFormat('yyyy-MM-dd').format(DateTime.now());
|
||||
final uri = Uri.parse('${APIConfig.url}/summary?date=$date');
|
||||
|
||||
final response = await clientGet.get(url: uri);
|
||||
print('------------dashboard------${response.statusCode}--------------');
|
||||
if (response.statusCode == 200) {
|
||||
print(response.body);
|
||||
return TodaysSummaryModel.fromJson(jsonDecode(response.body)); // Extract the "data" object from the response
|
||||
} else {
|
||||
// await LogOutRepo().signOut();
|
||||
|
||||
throw Exception('Failed to fetch business data');
|
||||
}
|
||||
}
|
||||
|
||||
Future<DashboardOverviewModel> dashboardData(String type) async {
|
||||
CustomHttpClientGet clientGet = CustomHttpClientGet(client: http.Client());
|
||||
|
||||
Uri uri;
|
||||
|
||||
if (type.startsWith('custom_date&')) {
|
||||
final uriParams = Uri.splitQueryString(type.replaceFirst('custom_date&', ''));
|
||||
final fromDate = uriParams['from_date'];
|
||||
final toDate = uriParams['to_date'];
|
||||
|
||||
uri = Uri.parse('${APIConfig.url}/dashboard?duration=custom_date&from_date=$fromDate&to_date=$toDate');
|
||||
} else {
|
||||
uri = Uri.parse('${APIConfig.url}/dashboard?duration=$type');
|
||||
}
|
||||
|
||||
final response = await clientGet.get(url: uri);
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
return DashboardOverviewModel.fromJson(jsonDecode(response.body));
|
||||
} else {
|
||||
throw Exception('Failed to fetch business data ${response.statusCode}');
|
||||
}
|
||||
}
|
||||
}
|
||||
144
lib/Repository/API/business_info_update_repo.dart
Normal file
144
lib/Repository/API/business_info_update_repo.dart
Normal file
@@ -0,0 +1,144 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter_easyloading/flutter_easyloading.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:mobile_pos/Const/api_config.dart';
|
||||
import '../../http_client/custome_http_client.dart';
|
||||
import '../constant_functions.dart';
|
||||
|
||||
class BusinessUpdateRepository {
|
||||
Future<bool> updateProfile({
|
||||
required String id,
|
||||
String? name,
|
||||
required String categoryId,
|
||||
required BuildContext context,
|
||||
required WidgetRef ref,
|
||||
String? phone,
|
||||
String? address,
|
||||
String? email,
|
||||
String? vatNumber,
|
||||
String? vatTitle,
|
||||
String? invoiceNoteLevel,
|
||||
String? invoiceNote,
|
||||
String? gratitudeMessage,
|
||||
String? warrantyLabelVoid,
|
||||
String? warrantyVoid,
|
||||
String? saleRoundingOption,
|
||||
String? invoiceSize,
|
||||
String? invoiceLanguage,
|
||||
Map<String, int>? invoiceVisibilityMeta,
|
||||
File? image,
|
||||
File? invoiceLogo,
|
||||
File? a4InvoiceLogo,
|
||||
File? thermalInvoiceLogo,
|
||||
File? invoiceScannerLogo,
|
||||
}) async {
|
||||
final uri = Uri.parse('${APIConfig.url}/business/$id');
|
||||
|
||||
final customHttpClient = CustomHttpClient(
|
||||
client: http.Client(),
|
||||
context: context,
|
||||
ref: ref,
|
||||
);
|
||||
|
||||
/// ---------- BASE FIELDS ----------
|
||||
final fields = <String, String>{
|
||||
'_method': 'PUT',
|
||||
'business_category_id': categoryId,
|
||||
'companyName': name ?? '',
|
||||
'phoneNumber': phone ?? '',
|
||||
'address': address ?? '',
|
||||
'email': email ?? '',
|
||||
'vat_no': vatNumber ?? '',
|
||||
'vat_name': vatTitle ?? '',
|
||||
'note_label': invoiceNoteLevel ?? '',
|
||||
'note': invoiceNote ?? '',
|
||||
'warranty_void_label': warrantyLabelVoid ?? '',
|
||||
'warranty_void': warrantyVoid ?? '',
|
||||
'gratitude_message': gratitudeMessage ?? '',
|
||||
'sale_rounding_option': saleRoundingOption ?? 'none',
|
||||
'invoice_size': invoiceSize ?? '2_inch_58mm',
|
||||
'invoice_language': invoiceLanguage ?? 'english',
|
||||
};
|
||||
|
||||
/// ---------- META FIELDS (numeric 0/1) ----------
|
||||
fields['show_company_name'] = (invoiceVisibilityMeta?['show_company_name'] ?? 1).toString();
|
||||
fields['show_phone_number'] = (invoiceVisibilityMeta?['show_phone_number'] ?? 1).toString();
|
||||
fields['show_address'] = (invoiceVisibilityMeta?['show_address'] ?? 1).toString();
|
||||
fields['show_email'] = (invoiceVisibilityMeta?['show_email'] ?? 1).toString();
|
||||
fields['show_vat'] = (invoiceVisibilityMeta?['show_vat'] ?? 1).toString();
|
||||
|
||||
/// ---------- ROOT FIELDS (numeric 0/1) ----------
|
||||
fields['show_note'] = (invoiceVisibilityMeta?['show_note'] ?? 1).toString();
|
||||
fields['show_gratitude_msg'] = (invoiceVisibilityMeta?['show_gratitude_msg'] ?? 1).toString();
|
||||
fields['show_invoice_scanner_logo'] = (invoiceVisibilityMeta?['show_invoice_scanner_logo'] ?? 1).toString();
|
||||
fields['show_a4_invoice_logo'] = (invoiceVisibilityMeta?['show_a4_invoice_logo'] ?? 1).toString();
|
||||
fields['show_thermal_invoice_logo'] = (invoiceVisibilityMeta?['show_thermal_invoice_logo'] ?? 1).toString();
|
||||
fields['show_warranty'] = (invoiceVisibilityMeta?['show_warranty'] ?? 1).toString();
|
||||
|
||||
/// ---------- FILES ----------
|
||||
final files = <String, File>{};
|
||||
if (image != null) files['pictureUrl'] = image;
|
||||
if (invoiceLogo != null) files['invoice_logo'] = invoiceLogo;
|
||||
if (a4InvoiceLogo != null) files['a4_invoice_logo'] = a4InvoiceLogo;
|
||||
if (thermalInvoiceLogo != null) files['thermal_invoice_logo'] = thermalInvoiceLogo;
|
||||
if (invoiceScannerLogo != null) files['invoice_scanner_logo'] = invoiceScannerLogo;
|
||||
|
||||
try {
|
||||
final response = await customHttpClient.uploadMultipleFiles(
|
||||
url: uri,
|
||||
fields: fields,
|
||||
files: files,
|
||||
);
|
||||
|
||||
final body = await response.stream.bytesToString();
|
||||
final decoded = json.decode(body);
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
EasyLoading.showSuccess(decoded['message'] ?? 'Updated successfully');
|
||||
return true;
|
||||
} else {
|
||||
EasyLoading.showError(decoded['message'] ?? 'Update failed. Status: ${response.statusCode}');
|
||||
return false;
|
||||
}
|
||||
} catch (e, stackTrace) {
|
||||
print('Error updating profile: $e');
|
||||
print('Stack trace: $stackTrace');
|
||||
EasyLoading.showError('Update failed: $e');
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Future<bool> updateSalesSettings({
|
||||
required String id,
|
||||
required BuildContext context,
|
||||
required WidgetRef ref,
|
||||
String? saleRoundingOption,
|
||||
}) async {
|
||||
final uri = Uri.parse('${APIConfig.url}/business/$id');
|
||||
CustomHttpClient customHttpClient = CustomHttpClient(client: http.Client(), context: context, ref: ref);
|
||||
|
||||
var request = http.MultipartRequest('POST', uri)
|
||||
..headers['Accept'] = 'application/json'
|
||||
..headers['Authorization'] = await getAuthToken();
|
||||
|
||||
request.fields['_method'] = 'put';
|
||||
if (saleRoundingOption != null) request.fields['sale_rounding_option'] = saleRoundingOption;
|
||||
final response = await customHttpClient.uploadFile(
|
||||
url: uri,
|
||||
fields: request.fields,
|
||||
);
|
||||
var da = await response.stream.bytesToString();
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
EasyLoading.showSuccess(json.decode(da)['message']);
|
||||
return true; // Update successful
|
||||
} else {
|
||||
EasyLoading.showError(json.decode(da)['message']);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
146
lib/Repository/API/business_setup_repo.dart
Normal file
146
lib/Repository/API/business_setup_repo.dart
Normal file
@@ -0,0 +1,146 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_easyloading/flutter_easyloading.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:mobile_pos/Const/api_config.dart';
|
||||
import 'package:mobile_pos/Repository/constant_functions.dart';
|
||||
|
||||
import '../../Screens/Home/home.dart';
|
||||
|
||||
class BusinessSetupRepo {
|
||||
Future<void> businessSetup({
|
||||
required String name,
|
||||
String? phone,
|
||||
required String categoryId,
|
||||
String? address,
|
||||
String? openingBalance,
|
||||
String? vatGstTitle,
|
||||
String? vatGstNumber,
|
||||
File? image,
|
||||
required BuildContext context,
|
||||
}) async {
|
||||
EasyLoading.show(status: 'Loading...', dismissOnTap: false);
|
||||
|
||||
final uri = Uri.parse('${APIConfig.url}/business');
|
||||
|
||||
var request = http.MultipartRequest('POST', uri)
|
||||
..headers['Authorization'] = await getAuthToken()
|
||||
..headers['Accept'] = 'application/json'
|
||||
..fields['companyName'] = name
|
||||
..fields['business_category_id'] = categoryId;
|
||||
|
||||
// Only add fields if they're not null
|
||||
_addFieldIfNotNull(request, 'address', address);
|
||||
_addFieldIfNotNull(request, 'phoneNumber', phone);
|
||||
_addFieldIfNotNull(request, 'shopOpeningBalance', openingBalance);
|
||||
_addFieldIfNotNull(request, 'vat_name', vatGstTitle);
|
||||
_addFieldIfNotNull(request, 'vat_no', vatGstNumber);
|
||||
|
||||
// Add image file if present
|
||||
if (image != null) {
|
||||
try {
|
||||
var picturePart = await _createImageFile(image);
|
||||
request.files.add(picturePart);
|
||||
} catch (e) {
|
||||
EasyLoading.dismiss();
|
||||
ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text('Failed to upload image: $e')));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
var response = await request.send();
|
||||
await _handleResponse(response, context);
|
||||
} catch (e) {
|
||||
EasyLoading.dismiss();
|
||||
ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text('Request failed: $e')));
|
||||
}
|
||||
}
|
||||
|
||||
// Helper method to add fields if they're not null
|
||||
void _addFieldIfNotNull(http.MultipartRequest request, String field, String? value) {
|
||||
if (value != null && value.isNotEmpty) {
|
||||
request.fields[field] = value;
|
||||
}
|
||||
}
|
||||
|
||||
// Helper method to create a MultipartFile from an image
|
||||
Future<http.MultipartFile> _createImageFile(File image) async {
|
||||
var imageBytes = await image.readAsBytes();
|
||||
return http.MultipartFile.fromBytes('pictureUrl', imageBytes, filename: image.path);
|
||||
}
|
||||
|
||||
// Handle HTTP response and show appropriate messages
|
||||
Future<void> _handleResponse(http.StreamedResponse response, BuildContext context) async {
|
||||
EasyLoading.dismiss();
|
||||
print('response: ${response.statusCode}');
|
||||
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(const SnackBar(content: Text('Profile setup successful!')));
|
||||
Navigator.push(context, MaterialPageRoute(builder: (context) => const Home()));
|
||||
} else {
|
||||
var responseData = await response.stream.bytesToString();
|
||||
print('response: $responseData');
|
||||
ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text('Profile setup failed: $responseData')));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// import 'dart:io';
|
||||
// import 'package:flutter/material.dart';
|
||||
// import 'package:flutter_easyloading/flutter_easyloading.dart';
|
||||
// import 'package:http/http.dart' as http;
|
||||
// import 'package:mobile_pos/Const/api_config.dart';
|
||||
// import 'package:mobile_pos/Repository/constant_functions.dart';
|
||||
// import '../../Screens/Home/home.dart';
|
||||
//
|
||||
// class BusinessSetupRepo {
|
||||
// Future<void> businessSetup({
|
||||
// required String name,
|
||||
// String? phone,
|
||||
// required String categoryId,
|
||||
// String? address,
|
||||
// String? openingBalance,
|
||||
// String? vatGstTitle,
|
||||
// String? vatGstNumber,
|
||||
// File? image,
|
||||
// required BuildContext context,
|
||||
// }) async {
|
||||
// EasyLoading.show(status: 'Loading...', dismissOnTap: false);
|
||||
//
|
||||
// final uri = Uri.parse('${APIConfig.url}/business');
|
||||
//
|
||||
// var request = http.MultipartRequest('POST', uri);
|
||||
// request.headers['Authorization'] = await getAuthToken();
|
||||
// request.headers['Accept'] = 'application/json';
|
||||
// request.fields['companyName'] = name;
|
||||
// request.fields['phoneNumber'] = phone ?? '';
|
||||
// request.fields['business_category_id'] = categoryId;
|
||||
// if (address != null) request.fields['address'] = address;
|
||||
// if (openingBalance != null) request.fields['shopOpeningBalance'] = openingBalance;
|
||||
// if (vatGstTitle != null) request.fields['shopOpeningBalance'] = vatGstTitle;
|
||||
// if (vatGstNumber != null) request.fields['shopOpeningBalance'] = vatGstNumber;
|
||||
// if (image != null) {
|
||||
// var picturePart = http.MultipartFile.fromBytes('pictureUrl', image.readAsBytesSync(), filename: image.path);
|
||||
// request.files.add(picturePart);
|
||||
// }
|
||||
//
|
||||
// var response = await request.send();
|
||||
// // final responseData = await response.stream.bytesToString();
|
||||
// // print('Profile setup failed: ${response.statusCode}');
|
||||
// // print(responseData);
|
||||
//
|
||||
// EasyLoading.dismiss();
|
||||
//
|
||||
// if (response.statusCode == 200) {
|
||||
// ScaffoldMessenger.of(context).showSnackBar(const SnackBar(content: Text('Profile setup successful!')));
|
||||
// Navigator.push(context, MaterialPageRoute(builder: (context) => const Home()));
|
||||
// } else {
|
||||
// ScaffoldMessenger.of(context).showSnackBar(const SnackBar(content: Text('Profile setup failed')));
|
||||
//
|
||||
// // Handle error response
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
24
lib/Repository/API/future_invoice.dart
Normal file
24
lib/Repository/API/future_invoice.dart
Normal file
@@ -0,0 +1,24 @@
|
||||
import 'package:http/http.dart' as http;
|
||||
|
||||
import '../../Const/api_config.dart';
|
||||
import '../../http_client/customer_http_client_get.dart';
|
||||
import '../constant_functions.dart';
|
||||
|
||||
class FutureInvoice {
|
||||
Future<String> getFutureInvoice({required String tag}) async {
|
||||
CustomHttpClientGet clientGet = CustomHttpClientGet(client: http.Client());
|
||||
try {
|
||||
final response = await clientGet.get(
|
||||
url: Uri.parse('${APIConfig.url}/new-invoice?platform=$tag'),
|
||||
);
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
return response.body;
|
||||
} else {
|
||||
return '';
|
||||
}
|
||||
} catch (error) {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
}
|
||||
39
lib/Repository/API/register_repo.dart
Normal file
39
lib/Repository/API/register_repo.dart
Normal file
@@ -0,0 +1,39 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
|
||||
import '../../Const/api_config.dart';
|
||||
|
||||
class RegisterRepo {
|
||||
Future<bool> registerRepo({required String email, required String password, required String confirmPassword, required BuildContext context}) async {
|
||||
final url = Uri.parse('${APIConfig.url}${APIConfig.registerUrl}');
|
||||
final body = {
|
||||
'email': email,
|
||||
'password': password,
|
||||
'password_confirmation': confirmPassword,
|
||||
};
|
||||
final headers = {
|
||||
'Accept': 'application/json',
|
||||
};
|
||||
|
||||
try {
|
||||
final response = await http.post(url, headers: headers, body: body);
|
||||
|
||||
final responseData = jsonDecode(response.body);
|
||||
if (response.statusCode == 200) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text(responseData['message'])));
|
||||
// await saveUserData(userData: responseData['data']);
|
||||
|
||||
return true;
|
||||
} else {
|
||||
ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text(responseData['message'])));
|
||||
}
|
||||
} catch (error) {
|
||||
print(error);
|
||||
ScaffoldMessenger.of(context).showSnackBar(const SnackBar(content: Text('Network error: Please try again')));
|
||||
} finally {}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
35
lib/Repository/check_addon_providers.dart
Normal file
35
lib/Repository/check_addon_providers.dart
Normal file
@@ -0,0 +1,35 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
|
||||
import '../Const/api_config.dart';
|
||||
import '../http_client/customer_http_client_get.dart';
|
||||
|
||||
final socialLoginCheckProvider = FutureProvider.autoDispose<bool>((ref) async {
|
||||
CustomHttpClientGet clientGet = CustomHttpClientGet(client: http.Client());
|
||||
final url = Uri.parse('${APIConfig.url}/module-check?module_name=SocialLoginAddon');
|
||||
final headers = {
|
||||
"Accept": "application/json",
|
||||
};
|
||||
final response = await clientGet.get(url: url);
|
||||
if (response.statusCode == 200) {
|
||||
final data = jsonDecode(response.body);
|
||||
return data['status'];
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
final invoice80mmAddonCheckProvider = FutureProvider.autoDispose<bool>((ref) async {
|
||||
final url = Uri.parse('${APIConfig.url}/module-check?module_name=ThermalPrinterAddon');
|
||||
final headers = {
|
||||
"Accept": "application/json",
|
||||
};
|
||||
final response = await http.get(url, headers: headers);
|
||||
if (response.statusCode == 200) {
|
||||
final data = jsonDecode(response.body);
|
||||
return data['status'];
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
17
lib/Repository/constant_functions.dart
Normal file
17
lib/Repository/constant_functions.dart
Normal file
@@ -0,0 +1,17 @@
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
import '../core/constant_variables/local_data_saving_keys.dart';
|
||||
|
||||
Future<String> getAuthToken() async {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
|
||||
print("AUTHToken: Bearer ${prefs.getString(LocalDataBaseSavingKey.tokenKey)}");
|
||||
return "Bearer ${prefs.getString(LocalDataBaseSavingKey.tokenKey) ?? ''}";
|
||||
}
|
||||
|
||||
Future<void> saveUserData({required String token}) async {
|
||||
print(token);
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
await prefs.setString(LocalDataBaseSavingKey.tokenKey, token);
|
||||
await prefs.setBool(LocalDataBaseSavingKey.skipOnBodingKey, true);
|
||||
}
|
||||
94
lib/Repository/report_repository.dart
Normal file
94
lib/Repository/report_repository.dart
Normal file
@@ -0,0 +1,94 @@
|
||||
// import 'dart:convert';
|
||||
// import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
// import 'package:mobile_pos/Const/api_config.dart';
|
||||
// import 'package:http/http.dart' as http;
|
||||
// import 'package:mobile_pos/model/due_model.dart';
|
||||
// import 'package:mobile_pos/model/purchase_model.dart';
|
||||
// import 'package:mobile_pos/model/sale_model.dart';
|
||||
//
|
||||
// import '../constant_functions.dart';
|
||||
//
|
||||
// class ReportRepository {
|
||||
// //---------sales report repo---------------
|
||||
// Future<SaleModel> sale({String? type}) async {
|
||||
// final headers = {
|
||||
// 'Accept': 'application/json',
|
||||
// 'Authorization': await getAuthToken(),
|
||||
// };
|
||||
// Uri uri;
|
||||
//
|
||||
// if (type!.startsWith("custom_date")) {
|
||||
// final uriParams = Uri.splitQueryString(type.replaceFirst('custom_date', ''));
|
||||
// final fromDate = uriParams['from_date'];
|
||||
// final toDate = uriParams['to_date'];
|
||||
// uri = Uri.parse('${APIConfig.url}/sales?duration=custom_date&from_date=$fromDate&to_date=$toDate');
|
||||
// } else {
|
||||
// uri = Uri.parse('${APIConfig.url}/sales?duration=$type');
|
||||
// }
|
||||
// final response = await http.get(uri, headers: headers);
|
||||
// if (response.statusCode == 200) {
|
||||
// final parsedData = jsonDecode(response.body);
|
||||
// return SaleModel.fromJson(parsedData);
|
||||
// } else {
|
||||
// throw Exception('Failed to fetch Sales List');
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// //----------purchase report repo----------------
|
||||
// Future<PurchaseModel> purchase({String? type}) async {
|
||||
// final headers = {
|
||||
// 'Accept': 'application/json',
|
||||
// 'Authorization': await getAuthToken(),
|
||||
// };
|
||||
// Uri uri;
|
||||
//
|
||||
// if (type!.startsWith("custom_date")) {
|
||||
// final uriParams = Uri.splitQueryString(type.replaceFirst('custom_date', ''));
|
||||
// final fromDate = uriParams['from_date'];
|
||||
// final toDate = uriParams['to_date'];
|
||||
// uri = Uri.parse('${APIConfig.url}/purchase?duration=custom_date&from_date=$fromDate&to_date=$toDate');
|
||||
// } else {
|
||||
// uri = Uri.parse('${APIConfig.url}/purchase?duration=$type');
|
||||
// }
|
||||
// final response = await http.get(uri, headers: headers);
|
||||
// print('-------${response.statusCode}------');
|
||||
// if (response.statusCode == 200) {
|
||||
// final parsedData = jsonDecode(response.body);
|
||||
// return PurchaseModel.fromJson(parsedData);
|
||||
// } else {
|
||||
// throw Exception('Failed to fetch Sales List');
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// //---------- report repo----------------
|
||||
// Future<DueModel> due({String? type}) async {
|
||||
// final headers = {
|
||||
// 'Accept': 'application/json',
|
||||
// 'Authorization': await getAuthToken(),
|
||||
// };
|
||||
// Uri uri;
|
||||
//
|
||||
// if (type!.startsWith("custom_date")) {
|
||||
// final uriParams = Uri.splitQueryString(type.replaceFirst('custom_date', ''));
|
||||
// final fromDate = uriParams['from_date'];
|
||||
// final toDate = uriParams['to_date'];
|
||||
// uri = Uri.parse('${APIConfig.url}/dues?duration=custom_date&from_date=$fromDate&to_date=$toDate');
|
||||
// } else {
|
||||
// uri = Uri.parse('${APIConfig.url}/dues?duration=$type');
|
||||
// print('------$uri------------------');
|
||||
// }
|
||||
// final response = await http.get(uri, headers: headers);
|
||||
// print('-------${response.statusCode}------');
|
||||
// if (response.statusCode == 200) {
|
||||
// final parsedData = jsonDecode(response.body);
|
||||
// return DueModel.fromJson(parsedData);
|
||||
// } else {
|
||||
// throw Exception('Failed to fetch Sales List');
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// final reportRepo = ReportRepository();
|
||||
// final saleReportProvider = FutureProvider.family.autoDispose<SaleModel, String>((ref, type) => reportRepo.sale(type: type));
|
||||
// final purchaseReportProvider = FutureProvider.family.autoDispose<PurchaseModel, String>((ref, type) => reportRepo.purchase(type: type));
|
||||
// final dueReportProvider = FutureProvider.family.autoDispose<DueModel, String>((ref, type) => reportRepo.due(type: type));
|
||||
Reference in New Issue
Block a user