completed the mobile app for he boss to review the stock report

This commit is contained in:
kicap1992
2022-01-30 05:31:17 +08:00
parent 6150dba920
commit c1016ae5c2
153 changed files with 9006 additions and 0 deletions

View File

@ -0,0 +1,206 @@
// ignore_for_file: non_constant_identifier_names
import 'dart:convert';
import 'package:boss_app2/global.dart' as globals;
import 'package:flutter/cupertino.dart';
// ignore: unused_import
import 'package:http/http.dart' as http;
import 'package:shared_preferences/shared_preferences.dart';
//create class LoginController extends ChangeNotifier
class BossController extends ChangeNotifier {
//create future string login , parameter is String username and password
Future<Map> ambilLaporan(
String tanggal, String bulan, String tahun, String filter) async {
//create string result
Map<String, dynamic> result;
try {
final response = await http.get(
Uri.parse(
"${globals.http_to_server}api/ambil_laporan?tanggal=$tanggal&bulan=$bulan&tahun=$tahun&filter=$filter"),
headers: {
"Accept": "application/json",
"authorization":
"Basic ${base64Encode(utf8.encode("Kicap_karan:bb10c6d9f01ec0cb16726b59e36c2f73"))}",
"crossDomain": "true"
});
final data = jsonDecode(response.body);
result = data;
} catch (e) {
result = {"status": "error", "message": e.toString()};
}
return result;
}
Future<Map> ambilLaporanDetail(String no_log) async {
//create string result
Map<String, dynamic> result;
try {
final response = await http.get(
Uri.parse(
"${globals.http_to_server}api/ambil_laporan_detail?no_log=$no_log"),
headers: {
"Accept": "application/json",
"authorization":
"Basic ${base64Encode(utf8.encode("Kicap_karan:bb10c6d9f01ec0cb16726b59e36c2f73"))}",
"crossDomain": "true"
});
final data = jsonDecode(response.body);
result = data;
} catch (e) {
result = {"status": "error", "message": e.toString()};
}
return result;
}
Future<Map> ambilProdukAll(
int pageNumber, String filter, String cekFilter) async {
Map<String, dynamic> result;
try {
final response = await http.get(
Uri.parse(
"${globals.http_to_server}api/ambil_produk_all?page=$pageNumber&filter=$filter&cekfilter=$cekFilter"),
headers: {
"Accept": "application/json",
"authorization":
"Basic ${base64Encode(utf8.encode("Kicap_karan:bb10c6d9f01ec0cb16726b59e36c2f73"))}",
"crossDomain": "true"
});
final data = jsonDecode(response.body);
result = data;
} catch (e) {
result = {"status": "error", "message": e.toString()};
}
return result;
}
Future<Map> ambilLaporanProdukDetail(
int no_barang, int pageNumber, String filter, String cek_filter) async {
Map<String, dynamic> result;
try {
final response = await http.get(
Uri.parse(
"${globals.http_to_server}api/ambil_log_produk_detail?no_barang=$no_barang&page=$pageNumber&haha=$cek_filter&filter=$filter"),
headers: {
"Accept": "application/json",
"authorization":
"Basic ${base64Encode(utf8.encode("Kicap_karan:bb10c6d9f01ec0cb16726b59e36c2f73"))}",
"crossDomain": "true"
});
final data = jsonDecode(response.body);
result = data;
} catch (e) {
result = {"status": "error", "message": e.toString()};
}
return result;
}
Future<Map> ambilProdukDetail(int no_barang) async {
Map<String, dynamic> result;
try {
final response = await http.get(
Uri.parse(
"${globals.http_to_server}api/ambil_produk_detail?no_barang=$no_barang"),
headers: {
"Accept": "application/json",
"authorization":
"Basic ${base64Encode(utf8.encode("Kicap_karan:bb10c6d9f01ec0cb16726b59e36c2f73"))}",
"crossDomain": "true"
});
final data = jsonDecode(response.body);
result = data;
} catch (e) {
result = {"status": "error", "message": e.toString()};
}
return result;
}
Future<Map> ambilLaporanAll(
int pageNumber, String filter, String cek_filter) async {
Map<String, dynamic> result;
try {
final response = await http.get(
Uri.parse(
"${globals.http_to_server}api/ambil_laporan_all?page=$pageNumber&haha=$cek_filter&filter=$filter"),
headers: {
"Accept": "application/json",
"authorization":
"Basic ${base64Encode(utf8.encode("Kicap_karan:bb10c6d9f01ec0cb16726b59e36c2f73"))}",
"crossDomain": "true"
});
final data = jsonDecode(response.body);
result = data;
} catch (e) {
result = {"status": "error", "message": e.toString()};
}
return result;
}
Future<void> laporanRead(String no_log) async {
final sharedPreference = await SharedPreferences.getInstance();
// sharedPreference.remove('notif');
try {
await http.get(
Uri.parse("${globals.http_to_server}api/laporan_read?no_log=$no_log"),
headers: {
"Accept": "application/json",
"authorization":
"Basic ${base64Encode(utf8.encode("Kicap_karan:bb10c6d9f01ec0cb16726b59e36c2f73"))}",
"crossDomain": "true"
});
// final data = jsonDecode(response.body);
final String? _notif = sharedPreference.getString('notif');
if (_notif != null) {
final List<dynamic> _notifList = jsonDecode(_notif);
_notifList
.removeWhere((element) => element.toString() == no_log.toString());
sharedPreference.setString(
'notif', (_notifList.isNotEmpty) ? jsonEncode(_notifList) : "");
}
} catch (e) {
// result = {"status": "error", "message": e.toString()};
}
}
Future<void> laporanReadAll() async {
final sharedPreference = await SharedPreferences.getInstance();
// sharedPreference.remove('notif');
try {
await http.get(Uri.parse("${globals.http_to_server}api/laporan_read_all"),
headers: {
"Accept": "application/json",
"authorization":
"Basic ${base64Encode(utf8.encode("Kicap_karan:bb10c6d9f01ec0cb16726b59e36c2f73"))}",
"crossDomain": "true"
});
sharedPreference.remove('notif');
} catch (e) {
// result = {"status": "error", "message": e.toString()};
}
}
}

View File

@ -0,0 +1,30 @@
import 'dart:math';
import 'package:flutter/material.dart';
class MyData extends DataTableSource {
// Generate some made-up data
final List<Map<String, dynamic>> _data = List.generate(
200,
(index) => {
"id": index,
"title": "Item $index",
"price": Random().nextInt(10000),
},
);
@override
bool get isRowCountApproximate => false;
@override
int get rowCount => _data.length;
@override
int get selectedRowCount => 0;
@override
DataRow getRow(int index) {
return DataRow(cells: [
DataCell(Text(_data[index]['id'].toString())),
DataCell(Text(_data[index]["title"])),
DataCell(Text(_data[index]["price"].toString())),
]);
}
}

View File

@ -0,0 +1,107 @@
import 'dart:convert';
import 'package:boss_app2/global.dart' as globals;
import 'package:flutter/cupertino.dart';
import 'package:http/http.dart' as http;
import 'package:shared_preferences/shared_preferences.dart';
//create class LoginController extends ChangeNotifier
class LoginController extends ChangeNotifier {
//create future string login , parameter is String username and password
Future<String> login(String username, String password) async {
late String _returnString;
try {
//create final sharedPreferences
final sharedPreferences = await SharedPreferences.getInstance();
//create http get wih basic auth
final response = await http.get(
Uri.parse(
"${globals.http_to_server}api/login_user?username=$username&password=$password"),
headers: {
"Accept": "application/json",
"authorization":
"Basic ${base64Encode(utf8.encode("Kicap_karan:bb10c6d9f01ec0cb16726b59e36c2f73"))}",
"crossDomain": "true"
});
final data = jsonDecode(response.body);
if (response.statusCode == 200) {
if (data['data']['level'] == '0') {
sharedPreferences.setString('level', 'Superadmin');
} else if (data['data']['level'] == '1') {
sharedPreferences.setString('level', 'Boss');
}
_returnString = "1";
sharedPreferences.setString('data', jsonEncode(data['data']));
} else if (response.statusCode == 401) {
_returnString = "2";
}
} catch (e) {
_returnString = "3";
}
//return result
return _returnString;
}
Future<int> getNotif() async {
int result;
final sharedPreferences = await SharedPreferences.getInstance();
try {
final response = await http
.get(Uri.parse("${globals.http_to_server}api/cek_datanya"), headers: {
"Accept": "application/json",
"authorization":
"Basic ${base64Encode(utf8.encode("Kicap_karan:bb10c6d9f01ec0cb16726b59e36c2f73"))}",
"crossDomain": "true"
});
final data = jsonDecode(response.body);
final List datanya = data['data'];
final String? _notif = sharedPreferences.getString('notif');
List<dynamic> _arrayNotif;
if (_notif == null) {
_arrayNotif = [];
} else {
_arrayNotif = jsonDecode(_notif);
}
int jumlah = datanya.length;
bool cek = false;
for (var i = 0; i < datanya.length; i++) {
cek = false;
for (var j = 0; j < _arrayNotif.length; j++) {
if (_arrayNotif[j].toString() == datanya[i]['no_log'].toString()) {
jumlah = jumlah - 1;
cek = true;
break;
}
}
if (cek == false) {
_arrayNotif.add(int.parse(datanya[i]['no_log']));
}
cek = false;
}
sharedPreferences.setString('notif', jsonEncode(_arrayNotif));
// // if (jumlah > 0) {
// // NotificationApi.showNotification(
// // title: 'Laporan Baru',
// // body: 'Ada $jumlah laporan baru',
// // payload: 'Laporan Baru',
// // );
// // }
result = jumlah;
// result = datanya;
} catch (e) {
// result = [];
result = 0;
}
return result;
}
}

View File

@ -0,0 +1,98 @@
import 'package:boss_app2/page/login.dart';
import 'package:flutter/material.dart';
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
import 'package:flutter_native_timezone/flutter_native_timezone.dart';
import 'package:rxdart/rxdart.dart';
import 'package:timezone/timezone.dart' as tz;
// import 'package:timezone/tzdata.dart' as tz;
// ignore: avoid_classes_with_only_static_members
class NotificationApi {
// Below is the code for initializing the plugin using var _notificationPlugin
static final _notifications = FlutterLocalNotificationsPlugin();
static final onNotifications = BehaviorSubject<String?>();
static Future showNotification({
int id = 0,
String? title,
String? body,
String? payload,
}) async =>
_notifications.show(
id,
title,
body,
await _notificanDetails(),
payload: payload,
);
static Future showScheduleNotification() async =>
_notifications.zonedSchedule(
0,
'Cek Laporan',
"Laporan Baru Mungkin Ada, Sila Cek Di Aplikasi",
// tz.TZDateTime.from(scheduledDate, tz.local),
_scheduleDaily(const Time(18)),
await _notificanDetails(),
payload: "Laporan Baru Mungkin Ada, Sila Cek Di Aplikasi",
androidAllowWhileIdle: true,
uiLocalNotificationDateInterpretation:
UILocalNotificationDateInterpretation.absoluteTime,
matchDateTimeComponents: DateTimeComponents.time,
);
static Future _notificanDetails() async {
const AndroidNotificationDetails androidPlatformChannelSpecifics =
AndroidNotificationDetails(
'your channel id',
'your channel name',
channelDescription: 'your channel description',
importance: Importance.max,
// priority: Priority.high,
// ticker: 'ticker',
);
return const NotificationDetails(
android: androidPlatformChannelSpecifics,
iOS: IOSNotificationDetails(),
);
}
static Future init(
{bool initScheduled = false, BuildContext? context}) async {
const android = AndroidInitializationSettings('app_icon');
const iOS = IOSInitializationSettings();
const settings = InitializationSettings(android: android, iOS: iOS);
final details = await _notifications.getNotificationAppLaunchDetails();
if (details != null && details.didNotificationLaunchApp) {
onNotifications.add(details.payload);
}
await _notifications.initialize(
settings,
onSelectNotification: (payload) async {
Navigator.push(
context!,
MaterialPageRoute(builder: (context) => Login()),
);
},
);
if (initScheduled) {
final locationName = await FlutterNativeTimezone.getLocalTimezone();
tz.setLocalLocation(tz.getLocation(locationName));
}
}
static tz.TZDateTime _scheduleDaily(Time time) {
final tz.TZDateTime now = tz.TZDateTime.now(tz.local);
final scheduledDate = tz.TZDateTime(tz.local, now.year, now.month, now.day,
time.hour, time.minute, time.second);
// if (scheduledDate.isBefore(now)) {
// scheduledDate = scheduledDate.add(const Duration(days: 1));
// }
return scheduledDate.isBefore(now)
? scheduledDate.add(const Duration(days: 1))
: scheduledDate;
}
}