added user page, pimpinan page, e signature

This commit is contained in:
kicap
2023-08-03 17:58:40 +08:00
parent 30131e5ffe
commit 914e24706b
35 changed files with 2341 additions and 327 deletions

View File

@ -1,9 +1,9 @@
import 'package:flutter/material.dart';
import 'package:panti_asuhan/app/themes/app_colors.dart';
import 'package:panti_asuhan/services/other_function.dart';
import 'package:stacked/stacked.dart';
import '../../../../app/themes/app_colors.dart';
import '../../../../app/themes/app_text.dart';
import '../../../../services/other_function.dart';
import './dana_sosial_admin_view_model.dart';
class DanaSosialAdminView extends StatelessWidget {
@ -24,54 +24,80 @@ class DanaSosialAdminView extends StatelessWidget {
return Scaffold(
body: Column(
children: [
Container(
padding:
const EdgeInsets.symmetric(horizontal: 15, vertical: 10),
width: double.infinity,
decoration: BoxDecoration(
color: mainColor,
borderRadius: BorderRadius.circular(10),
boxShadow: [
BoxShadow(
color: mainGrey.withOpacity(0.5),
spreadRadius: 5,
blurRadius: 7,
offset: const Offset(0, 3), // changes position of shadow
),
],
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'Dana Sosial Bulan Ini',
style: boldTextStyle.copyWith(
color: Colors.white,
fontSize: 20,
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Expanded(
child: Container(
padding: const EdgeInsets.symmetric(
horizontal: 15, vertical: 10),
width: double.infinity,
decoration: BoxDecoration(
color: mainColor,
borderRadius: BorderRadius.circular(10),
boxShadow: [
BoxShadow(
color: mainGrey.withOpacity(0.5),
spreadRadius: 5,
blurRadius: 7,
offset: const Offset(
0, 3), // changes position of shadow
),
],
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'Dana Sosial Bulan Ini',
style: boldTextStyle.copyWith(
color: Colors.white,
fontSize: 20,
),
),
const SizedBox(height: 10),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
'Total Dana Sosial',
style: regularTextStyle.copyWith(
color: Colors.white,
fontSize: 15,
),
),
Text(
'Rp. 1.000.000',
style: regularTextStyle.copyWith(
color: Colors.white,
fontSize: 15,
),
),
],
),
],
),
),
const SizedBox(height: 10),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
'Total Dana Sosial',
style: regularTextStyle.copyWith(
color: Colors.white,
fontSize: 15,
),
),
Text(
'Rp. 1.000.000',
style: regularTextStyle.copyWith(
color: Colors.white,
fontSize: 15,
),
),
],
),
const SizedBox(width: 10),
Container(
width: 50,
height: 50,
decoration: const BoxDecoration(
shape: BoxShape.circle,
color: mainColor,
),
],
),
child: IconButton(
icon: const Icon(
Icons.filter_list,
color: Colors.white,
),
onPressed: () {
model.filterDialog(context);
},
),
),
],
),
const SizedBox(height: 25),
Expanded(
@ -98,65 +124,93 @@ class DanaSosialAdminView extends StatelessWidget {
),
),
)
: ListView.builder(
padding: const EdgeInsets.symmetric(
horizontal: 15, vertical: 10),
itemCount: model.danaSosialModelList.length,
itemBuilder: (context, index) {
String jumlahDonasi = OtherFunction().commaFormat(
int.parse(
model.danaSosialModelList[index].jumlah ??
'0'));
return Card(
child: ListTile(
title: Text(
model.danaSosialModelList[index].tanggal ??
'',
style: boldTextStyle.copyWith(
fontSize: 13, color: mainColor)),
subtitle: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
model.danaSosialModelList[index].nama ??
'',
style: regularTextStyle.copyWith(
fontSize: 13, color: mainColor)),
Text('Rp. $jumlahDonasi',
style: regularTextStyle.copyWith(
fontSize: 13, color: mainColor)),
],
),
trailing: Container(
width: 50,
height: 50,
decoration: BoxDecoration(
color: mainColor,
borderRadius: BorderRadius.circular(50),
),
child: IconButton(
onPressed: () {
// model.goToTambahDanaSosial();
},
icon: const Icon(
Icons.edit,
color: Colors.white,
),
),
),
),
);
},
),
: const TheData(),
),
),
],
),
floatingActionButton: FloatingActionButton(
onPressed: () {
model.goToTambahDanaSosial();
},
child: const Icon(Icons.add),
floatingActionButton: model.role == 'admin'
? FloatingActionButton(
onPressed: () {
model.goToTambahDanaSosial();
},
child: const Icon(Icons.add),
)
: null,
);
},
);
}
}
class TheData extends ViewModelWidget<DanaSosialAdminViewModel> {
const TheData({
super.key,
});
@override
Widget build(BuildContext context, DanaSosialAdminViewModel viewModel) {
return ListView.builder(
padding: const EdgeInsets.symmetric(horizontal: 15, vertical: 10),
itemCount: viewModel.danaSosialModelList.length,
itemBuilder: (context, index) {
String jumlahDonasi = viewModel
.danaSosialModelList[index].jenisDonasi !=
'Barang'
? OtherFunction().commaFormat(
int.parse(viewModel.danaSosialModelList[index].jumlah ?? '0'))
: '0';
return Card(
child: ListTile(
title: Text(viewModel.danaSosialModelList[index].tanggal ?? '',
style: boldTextStyle.copyWith(fontSize: 13, color: mainColor)),
subtitle: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(viewModel.danaSosialModelList[index].nama ?? '',
style: regularTextStyle.copyWith(
fontSize: 13, color: mainColor)),
Text(
viewModel.danaSosialModelList[index].jenisDonasi == 'Uang'
? (viewModel.isLogin == true ? 'Rp. $jumlahDonasi' : '-')
: 'Donasi Barang',
style:
regularTextStyle.copyWith(fontSize: 13, color: mainColor),
),
Text(
viewModel.danaSosialModelList[index].status ?? '',
style: regularTextStyle.copyWith(
fontSize: 13,
color: viewModel.danaSosialModelList[index].status ==
'Belum Dikonfirmasi'
? Colors.red
: Colors.green,
),
),
],
),
trailing: viewModel.isLogin == null
? null
: (viewModel.isLogin == true
? Container(
width: 50,
height: 50,
decoration: BoxDecoration(
color: mainColor,
borderRadius: BorderRadius.circular(50),
),
child: IconButton(
onPressed: () {
viewModel.goToEditDanaSosial(int.parse(viewModel
.danaSosialModelList[index].idDanaSosial!));
},
icon: const Icon(
Icons.edit,
color: Colors.white,
),
),
)
: null),
),
);
},

View File

@ -1,3 +1,8 @@
import 'package:dio/dio.dart';
import 'package:flutter/material.dart';
import 'package:shared_preferences/shared_preferences.dart';
import '../../../../app/app.dialogs.dart';
import '../../../../app/app.locator.dart';
import '../../../../app/app.logger.dart';
import '../../../../app/app.router.dart';
@ -5,6 +10,7 @@ import '../../../../app/core/custom_base_view_model.dart';
import '../../../../model/dana_sosial_model.dart';
import '../../../../services/http_services.dart';
import '../../../../services/my_easyloading.dart';
import '../../../../services/other_function.dart';
class DanaSosialAdminViewModel extends CustomBaseViewModel {
final log = getLogger('DanaSosialAdminViewModel');
@ -13,8 +19,15 @@ class DanaSosialAdminViewModel extends CustomBaseViewModel {
List<DanaSosialModel> danaSosialModelList = [];
String? role;
bool? isLogin;
Future<void> init() async {
await getData();
prefs.then((SharedPreferences prefs) {
role = prefs.getString('role');
isLogin = prefs.getBool('isLogin');
});
}
getData() async {
@ -47,4 +60,93 @@ class DanaSosialAdminViewModel extends CustomBaseViewModel {
goToTambahDanaSosial() {
navigationService.navigateTo(Routes.tambahDanaSosialView);
}
getFilter(String sql) async {
setBusy(true);
easyLoading.showLoading();
FormData formData = FormData.fromMap({
'sql': sql,
});
try {
var response = await _httpService.postWithFormData(
'filter_dana',
formData,
);
log.i(response.data);
danaSosialModelList = [];
var datanya = response.data['data'];
// log.i(datanya.length);
if (datanya.length > 0) {
for (var item in datanya) {
danaSosialModelList.add(DanaSosialModel.fromJson(item));
}
}
setBusy(false);
notifyListeners();
log.i(danaSosialModelList);
} catch (e) {
log.e(e);
setBusy(false);
} finally {
easyLoading.dismissLoading();
}
}
filterDialog(BuildContext context) async {
// create a dialog
final res = await dialogService.showCustomDialog(
variant: DialogType.filterDialogView,
);
if (res!.confirmed) {
String jenisDonasi = res.data['jenisDonasi'] == 'Semua'
? ''
: "jenis = '${res.data['jenisDonasi']}' and ";
String bulan = res.data['bulan'] == 'Semua'
? ''
: "tanggal like '%-${OtherFunction().changeMonth(res.data['bulan'])}-%' and ";
String tahun = res.data['tahun'] == 'Semua'
? ''
: 'tanggal like "%${res.data['tahun']}-%" and ';
String status = res.data['status'] == 'Semua'
? ''
: (res.data['status'] == 'Belum Dikonfirmasi')
? 'status = 0'
: 'status = 1';
if (jenisDonasi == 'Semua' &&
bulan == 'Semua' &&
tahun == 'Semua' &&
status == 'Semua') {
getData();
return;
}
String sql =
'Select * from tb_dana_sosial where $jenisDonasi$bulan$tahun$status';
// check the last 3 character if it is 'or ' then remove it
// if (sql.substring(sql.length - 3) == 'or ') {
// sql = sql.substring(0, sql.length - 3);
// }
if (sql.substring(sql.length - 4) == 'and ') {
sql = sql.substring(0, sql.length - 4);
}
log.i(sql);
getFilter(sql);
}
}
goToEditDanaSosial(int id) async {
navigationService.navigateTo(
Routes.detailDanaSosialView,
arguments: DetailDanaSosialViewArguments(
id: id,
),
);
}
}