step 20 : delete transaksi, bug icon svg from server, date convert tgl trans

This commit is contained in:
sindhu
2024-01-16 22:06:42 +07:00
parent 178dd3b509
commit f915ed2c10
4 changed files with 451 additions and 164 deletions

View File

@@ -121,4 +121,34 @@ class TransaksiRepository extends BaseRepository {
}); });
return result; return result;
} }
// delete transaksi
Future<String> deleteTransaksi(
String id,
String userid,
) async {
final service =
"${Constant.baseUrlDevone}transaction/deletetransaction/?id=$id&userid=$userid";
final resp = await get(
// param: {
// "": "",
// },
service: service,
);
print("url delete transaksi : $service");
// final result = List<ListCategory>.empty(growable: true);
// resp['data'].forEach((e) {
// final model = ListCategory.fromJson(e);
// result.add(model);
// });
if(resp['status'] != "OK"){
return resp['message'];
}
return resp['status'];
}
} }

View File

@@ -0,0 +1,84 @@
import 'package:equatable/equatable.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import '../../repository/transaksi_repository.dart';
import '../../provider/dio_provider.dart';
import '../../repository/base_repository.dart';
import 'search_history_transaksi_provider.dart';
abstract class DeleteTransaksiState extends Equatable {
final DateTime date;
const DeleteTransaksiState(this.date);
@override
List<Object?> get props => [date];
}
class DeleteTransaksiStateInit extends DeleteTransaksiState {
DeleteTransaksiStateInit() : super(DateTime.now());
}
class DeleteTransaksiStateLoading extends DeleteTransaksiState {
DeleteTransaksiStateLoading() : super(DateTime.now());
}
class DeleteTransaksiStateError extends DeleteTransaksiState {
final String message;
DeleteTransaksiStateError({
required this.message,
}) : super(DateTime.now());
}
class DeleteTransaksiStateDone extends DeleteTransaksiState {
// final List<ListType> model;
final String resp;
DeleteTransaksiStateDone({
required this.resp,
}) : super(DateTime.now());
}
//notifier
class DeleteTransaksiNotifier extends StateNotifier<DeleteTransaksiState> {
final Ref ref;
DeleteTransaksiNotifier({
required this.ref,
}) : super(DeleteTransaksiStateInit());
void deleteTransaksi(
String id,
String userid,
String companyid,
String tglAwal,
String tglAkhir,
String categoryid,
) async {
try {
state = DeleteTransaksiStateLoading();
final dio = ref.read(dioProvider);
final resp = await TransaksiRepository(dio: dio).deleteTransaksi(
id,
userid,
);
state = DeleteTransaksiStateDone(resp: resp);
// search lagi buat get data
ref.read(searchHistoryTransaksiProvider.notifier).searchHistoryTransaksi(
companyid,
tglAwal,
tglAkhir,
categoryid,
);
} catch (e) {
if (e is BaseRepositoryException) {
state = DeleteTransaksiStateError(message: e.message.toString());
} else {
state = DeleteTransaksiStateError(message: e.toString());
}
}
}
}
//provider
final deleteTransaksiProvider =
StateNotifierProvider<DeleteTransaksiNotifier, DeleteTransaksiState>(
(ref) => DeleteTransaksiNotifier(ref: ref),
);

View File

@@ -1,5 +1,6 @@
import 'dart:convert'; import 'dart:convert';
import 'package:app_petty_cash/screen/transaksi/delete_transaksi_provider.dart';
import 'package:app_petty_cash/screen/transaksi/search_history_transaksi_provider.dart'; import 'package:app_petty_cash/screen/transaksi/search_history_transaksi_provider.dart';
import 'package:dropdown_button2/dropdown_button2.dart'; import 'package:dropdown_button2/dropdown_button2.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
@@ -41,7 +42,8 @@ class HistoryTransaksiScreen extends HookConsumerWidget {
), ),
); );
String M_CompanyID = "0"; // String M_CompanyID = "0";
final M_CompanyID = useState<String>("0");
String formattedDate = DateFormat('dd-MM-yyyy').format(DateTime.now()); String formattedDate = DateFormat('dd-MM-yyyy').format(DateTime.now());
final ctrlTglAwal = useTextEditingController(text: formattedDate); final ctrlTglAwal = useTextEditingController(text: formattedDate);
@@ -138,6 +140,27 @@ class HistoryTransaksiScreen extends HookConsumerWidget {
}, },
); );
// delete transaksi
ref.listen(
deleteTransaksiProvider,
(previous, next) {
if (next is DeleteTransaksiStateLoading) {
searchHistoryIsLoading.value = true;
} else if (next is DeleteTransaksiStateError) {
// print(next.message);
searchHistoryIsLoading.value = false;
SanckbarWidget(context, next.message, snackbarType.error);
} else if (next is DeleteTransaksiStateDone) {
// print(jsonEncode(next.model));
// print(next.model.length);
// listSearchHistory.value = next.model;
SanckbarWidget(
context, 'Data Berhasil Dihapus', snackbarType.success);
searchHistoryIsLoading.value = false;
}
},
);
Future<String> getCompanyID() async { Future<String> getCompanyID() async {
final shared = await SharedPreferences.getInstance(); final shared = await SharedPreferences.getInstance();
String M_CompanyID = "0"; String M_CompanyID = "0";
@@ -180,7 +203,7 @@ class HistoryTransaksiScreen extends HookConsumerWidget {
// list category provider // list category provider
ref.read(listCategoryProvider.notifier).getListCategory(); ref.read(listCategoryProvider.notifier).getListCategory();
M_CompanyID = await getCompanyID(); M_CompanyID.value = await getCompanyID();
DateTime parsedDate = DateFormat('dd-MM-yyyy').parse( DateTime parsedDate = DateFormat('dd-MM-yyyy').parse(
ctrlTglAwal.value.text.toString(), ctrlTglAwal.value.text.toString(),
@@ -199,11 +222,100 @@ class HistoryTransaksiScreen extends HookConsumerWidget {
ref ref
.read(searchHistoryTransaksiProvider.notifier) .read(searchHistoryTransaksiProvider.notifier)
.searchHistoryTransaksi( .searchHistoryTransaksi(
M_CompanyID, formattedDateAwal, formattedDateAkhir, categoryid); M_CompanyID.value,
formattedDateAwal,
formattedDateAkhir,
categoryid,
);
}); });
return () {}; return () {};
}, []); }, []);
// delete alert
Future<void> showDeleteConfirmationDialog(
BuildContext context,
String id,
String userid,
String companyid,
String tglAwal,
String tglAkhir,
String categoryid,
) async {
return showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(
title: Text('Konfirmasi Hapus'),
content: Text('Apakah anda yakin menghapus data ini?'),
actions: <Widget>[
TextButton(
onPressed: () {
Navigator.of(context).pop(); // Tutup dialog
},
child: Text('Batal'),
),
ElevatedButton(
onPressed: () {
print('Deleted id $id , userid $userid');
DateTime parsedDate = DateFormat('dd-MM-yyyy').parse(
ctrlTglAwal.value.text.toString(),
);
String formattedDateAwal =
DateFormat('yyyy-MM-dd').format(parsedDate);
DateTime parsedDateAkhir = DateFormat('dd-MM-yyyy').parse(
ctrlTglAkhir.value.text.toString(),
);
String formattedDateAkhir =
DateFormat('yyyy-MM-dd').format(parsedDateAkhir);
ref.read(deleteTransaksiProvider.notifier).deleteTransaksi(
id,
userid,
companyid,
formattedDateAwal,
formattedDateAkhir,
categoryid,
);
Navigator.of(context).pop();
},
child: Text(
'Hapus Data',
style: Constant.body1_600(context: context).copyWith(
fontWeight: FontWeight.w600,
color: Constant.textWhite,
),
),
style: ButtonStyle(
backgroundColor:
MaterialStateColor.resolveWith((st) => Constant.textRed),
shape: MaterialStateProperty.all<RoundedRectangleBorder>(
RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8),
side: BorderSide(
color: Constant.textRed,
),
),
),
shadowColor: MaterialStateProperty.all(Color(0xffff48423d)),
elevation: MaterialStateProperty.all(4.0),
),
),
],
);
},
);
}
void _closeKeyboard() {
FocusManager.instance.primaryFocus?.unfocus();
}
final FocusNode focusNodetglAwal = useFocusNode();
final tglAwalHasFocus = useState(false);
final FocusNode focusNodetglAkhir = useFocusNode();
final tglAkhirHasFocus = useState(false);
return Padding( return Padding(
padding: EdgeInsets.only( padding: EdgeInsets.only(
top: Constant.getActualYPhone(context: context, y: 30), top: Constant.getActualYPhone(context: context, y: 30),
@@ -238,80 +350,91 @@ class HistoryTransaksiScreen extends HookConsumerWidget {
children: [ children: [
// Tanggal Awal // Tanggal Awal
Expanded( Expanded(
child: TextField( child: GestureDetector(
controller: ctrlTglAwal, onTap: () {
decoration: InputDecoration( focusNodetglAwal.unfocus();
hintStyle: // _closeKeyboard();
Constant.body2_400(context: context).copyWith(
color: Constant.textGreyv2,
),
labelStyle:
Constant.body2_400(context: context).copyWith(
color: Constant.textGreyv2,
),
border: OutlineInputBorder(
borderSide: BorderSide(
color: Colors.orange,
width: 1,
),
),
focusedBorder: OutlineInputBorder(
borderSide: BorderSide(
color: Constant.textGreyv2,
width: 1,
),
),
labelText: "Tanggal Awal",
hintText: 'Tanggal Awal',
// suffixIcon: isLoadingFilterScope.value
// ? SizedBox(
// width: Constant.getActualXPhone(
// context: context,
// x: 4,
// ),
// height: Constant.getActualYPhone(
// context: context,
// y: 4,
// ),
// child: CircularProgressIndicator(
// color: Constant.textRed,
// ),
// )
// : Icon(
// Icons.calendar_month_sharp,
// color: Constant.colorIconDate,
// ),
),
onTap: () async {
final selectedDateAwal = await showDatePicker(
// locale: const Locale("en-CA"),
// locale: ,
context: context,
initialEntryMode:
DatePickerEntryMode.calendarOnly,
firstDate: DateTime(2000),
lastDate: DateTime(2100),
initialDate: (ctrlTglAwal.text.isEmpty)
? DateTime.now()
: tglAwal.value,
);
if (selectedDateAwal != null) {
String formattedDate = DateFormat('dd-MM-yyyy')
.format(selectedDateAwal);
// ctrlTglAwal.text =
// selectedDateAwal.toString().split(' ')[0];
ctrlTglAwal.text = formattedDate;
tglAwal.value = selectedDateAwal;
tglAwalTmp.value = selectedDateAwal.toString();
}
if (selectedDateAwal == null) {
print('cancel button');
return;
}
}, },
child: TextField(
enableInteractiveSelection: false,
showCursor: (tglAwalHasFocus.value) ? true : false,
controller: ctrlTglAwal,
decoration: InputDecoration(
hintStyle:
Constant.body2_400(context: context).copyWith(
color: Constant.textGreyv2,
),
labelStyle:
Constant.body2_400(context: context).copyWith(
color: Constant.textGreyv2,
),
border: OutlineInputBorder(
borderSide: BorderSide(
color: Colors.orange,
width: 1,
),
),
focusedBorder: OutlineInputBorder(
borderSide: BorderSide(
color: Constant.textGreyv2,
width: 1,
),
),
labelText: "Tanggal Awal",
hintText: 'Tanggal Awal',
// suffixIcon: isLoadingFilterScope.value
// ? SizedBox(
// width: Constant.getActualXPhone(
// context: context,
// x: 4,
// ),
// height: Constant.getActualYPhone(
// context: context,
// y: 4,
// ),
// child: CircularProgressIndicator(
// color: Constant.textRed,
// ),
// )
// : Icon(
// Icons.calendar_month_sharp,
// color: Constant.colorIconDate,
// ),
),
onTap: () async {
final selectedDateAwal = await showDatePicker(
// locale: const Locale("en-CA"),
// locale: ,
context: context,
initialEntryMode:
DatePickerEntryMode.calendarOnly,
firstDate: DateTime(2000),
lastDate: DateTime(2100),
initialDate: (ctrlTglAwal.text.isEmpty)
? DateTime.now()
: tglAwal.value,
);
if (selectedDateAwal != null) {
String formattedDate = DateFormat('dd-MM-yyyy')
.format(selectedDateAwal);
// ctrlTglAwal.text =
// selectedDateAwal.toString().split(' ')[0];
ctrlTglAwal.text = formattedDate;
tglAwal.value = selectedDateAwal;
tglAwalTmp.value = selectedDateAwal.toString();
}
if (selectedDateAwal == null) {
print('cancel button');
return;
}
// focusNodetglAwal.unfocus();
// _closeKeyboard();
},
),
), ),
), ),
@@ -321,80 +444,89 @@ class HistoryTransaksiScreen extends HookConsumerWidget {
), ),
// Tanggal Akhir // Tanggal Akhir
Expanded( Expanded(
child: TextField( child: GestureDetector(
controller: ctrlTglAkhir, onTap: () {
decoration: InputDecoration( focusNodetglAkhir.unfocus();
hintStyle: // _closeKeyboard();
Constant.body2_400(context: context).copyWith(
color: Constant.textGreyv2,
),
labelStyle:
Constant.body2_400(context: context).copyWith(
color: Constant.textGreyv2,
),
border: OutlineInputBorder(
borderSide: BorderSide(
color: Colors.orange,
width: 1,
),
),
focusedBorder: OutlineInputBorder(
borderSide: BorderSide(
color: Constant.textGreyv2,
width: 1,
),
),
labelText: "Tanggal Akhir",
hintText: 'Tanggal Akhir',
// suffixIcon: isLoadingFilterScope.value
// ? SizedBox(
// width: Constant.getActualXPhone(
// context: context,
// x: 4,
// ),
// height: Constant.getActualYPhone(
// context: context,
// y: 4,
// ),
// child: CircularProgressIndicator(
// color: Constant.textRed,
// ),
// )
// : Icon(
// Icons.calendar_month_sharp,
// color: Constant.colorIconDate,
// ),
),
onTap: () async {
final selectedDateAkhir = await showDatePicker(
// locale: const Locale("en-CA"),
// locale: ,
context: context,
initialEntryMode:
DatePickerEntryMode.calendarOnly,
firstDate: DateTime(2000),
lastDate: DateTime(2100),
initialDate: (ctrlTglAkhir.text.isEmpty)
? DateTime.now()
: tglAkhir.value,
);
if (selectedDateAkhir != null) {
String formattedDate = DateFormat('dd-MM-yyyy')
.format(selectedDateAkhir);
// ctrlTglAkhir.text =
// selectedDateAkhir.toString().split(' ')[0];
ctrlTglAkhir.text = formattedDate;
tglAkhir.value = selectedDateAkhir;
tglAkhirTmp.value = selectedDateAkhir.toString();
}
if (selectedDateAkhir == null) {
print('cancel button');
return;
}
}, },
child: TextField(
enableInteractiveSelection: false,
showCursor: (tglAwalHasFocus.value) ? true : false,
controller: ctrlTglAkhir,
decoration: InputDecoration(
hintStyle:
Constant.body2_400(context: context).copyWith(
color: Constant.textGreyv2,
),
labelStyle:
Constant.body2_400(context: context).copyWith(
color: Constant.textGreyv2,
),
border: OutlineInputBorder(
borderSide: BorderSide(
color: Colors.orange,
width: 1,
),
),
focusedBorder: OutlineInputBorder(
borderSide: BorderSide(
color: Constant.textGreyv2,
width: 1,
),
),
labelText: "Tanggal Akhir",
hintText: 'Tanggal Akhir',
// suffixIcon: isLoadingFilterScope.value
// ? SizedBox(
// width: Constant.getActualXPhone(
// context: context,
// x: 4,
// ),
// height: Constant.getActualYPhone(
// context: context,
// y: 4,
// ),
// child: CircularProgressIndicator(
// color: Constant.textRed,
// ),
// )
// : Icon(
// Icons.calendar_month_sharp,
// color: Constant.colorIconDate,
// ),
),
onTap: () async {
final selectedDateAkhir = await showDatePicker(
// locale: const Locale("en-CA"),
// locale: ,
context: context,
initialEntryMode:
DatePickerEntryMode.calendarOnly,
firstDate: DateTime(2000),
lastDate: DateTime(2100),
initialDate: (ctrlTglAkhir.text.isEmpty)
? DateTime.now()
: tglAkhir.value,
);
if (selectedDateAkhir != null) {
String formattedDate = DateFormat('dd-MM-yyyy')
.format(selectedDateAkhir);
// ctrlTglAkhir.text =
// selectedDateAkhir.toString().split(' ')[0];
ctrlTglAkhir.text = formattedDate;
tglAkhir.value = selectedDateAkhir;
tglAkhirTmp.value =
selectedDateAkhir.toString();
}
if (selectedDateAkhir == null) {
print('cancel button');
return;
}
},
),
), ),
), ),
], ],
@@ -588,11 +720,11 @@ class HistoryTransaksiScreen extends HookConsumerWidget {
], ],
), ),
onPressed: () async { onPressed: () async {
M_CompanyID = await getCompanyID(); M_CompanyID.value = await getCompanyID();
ref ref
.read(searchHistoryTransaksiProvider.notifier) .read(searchHistoryTransaksiProvider.notifier)
.searchHistoryTransaksi( .searchHistoryTransaksi(
M_CompanyID, M_CompanyID.value,
ctrlTglAwal.text, ctrlTglAwal.text,
ctrlTglAkhir.text, ctrlTglAkhir.text,
selectedListCategory.value.categoryid ?? "0", selectedListCategory.value.categoryid ?? "0",
@@ -754,6 +886,7 @@ class HistoryTransaksiScreen extends HookConsumerWidget {
tipe: listSearchHistory tipe: listSearchHistory
.value[idx].tipe .value[idx].tipe
.toString(), .toString(),
// searchHistoryIsLoading.value
), ),
// bawah // bawah
@@ -774,15 +907,15 @@ class HistoryTransaksiScreen extends HookConsumerWidget {
), ),
shape: RoundedRectangleBorder( shape: RoundedRectangleBorder(
side: BorderSide( side: BorderSide(
color: color: Constant
Constant.bgChipConfirmed), .bgTextChipConfirmed),
borderRadius: borderRadius:
BorderRadius.circular( BorderRadius.circular(
50, 50,
), ),
), ),
backgroundColor: backgroundColor: Constant
Constant.bgChipConfirmed, .bgTextChipConfirmed,
), ),
], ],
), ),
@@ -799,8 +932,28 @@ class HistoryTransaksiScreen extends HookConsumerWidget {
MainAxisAlignment.end, MainAxisAlignment.end,
children: [ children: [
InkWell( InkWell(
onTap: () { onTap: () async {
print('Deleted'); final userID = ref
.read(
currentUserProvider)
?.model
.M_UserID ??
"0";
// print('Deleted');
showDeleteConfirmationDialog(
context,
listSearchHistory
.value[idx].id
.toString(),
userID,
M_CompanyID.value,
ctrlTglAwal.text.toString(),
ctrlTglAkhir.text
.toString(),
selectedListCategory
.value.categoryid
.toString(),
);
}, },
child: Chip( child: Chip(
label: Text( label: Text(
@@ -811,8 +964,8 @@ class HistoryTransaksiScreen extends HookConsumerWidget {
), ),
shape: RoundedRectangleBorder( shape: RoundedRectangleBorder(
side: BorderSide( side: BorderSide(
color: color: Constant
Constant.bgTextChipDelete), .bgTextChipDelete),
borderRadius: borderRadius:
BorderRadius.circular( BorderRadius.circular(
50, 50,

View File

@@ -3,6 +3,7 @@ import 'package:dio/dio.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart'; import 'package:flutter_svg/flutter_svg.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart'; import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:intl/intl.dart';
import '../app/constant.dart'; import '../app/constant.dart';
@@ -12,6 +13,7 @@ class HistoryRowAtasWidget extends HookConsumerWidget {
final String amount; final String amount;
final String tipe; final String tipe;
final String tglTransaksi; final String tglTransaksi;
// final ValueNotifier<bool> searchHistoryIsLoading;
const HistoryRowAtasWidget({ const HistoryRowAtasWidget({
Key? key, Key? key,
@@ -20,11 +22,11 @@ class HistoryRowAtasWidget extends HookConsumerWidget {
required this.amount, required this.amount,
required this.tipe, required this.tipe,
required this.tglTransaksi, required this.tglTransaksi,
// required this.searchHistoryIsLoading,
}) : super(key: key); }) : super(key: key);
@override @override
Widget build(BuildContext context, WidgetRef ref) { Widget build(BuildContext context, WidgetRef ref) {
// check file exist // check file exist
Future<Widget> checkFileExistence(String fileUrl) async { Future<Widget> checkFileExistence(String fileUrl) async {
try { try {
@@ -62,6 +64,24 @@ class HistoryRowAtasWidget extends HookConsumerWidget {
} }
} }
// fungsi tanggal
String formatDateString(String inputDate) {
try {
// Parsing tanggal dari string input
DateTime date = DateFormat('dd-MM-yyyy').parse(inputDate);
// Format tanggal ke '30 Des 2023'
String formattedDate = DateFormat('dd MMM yyyy', 'id').format(date);
return formattedDate;
} catch (e) {
// Tangkap kesalahan jika format tanggal tidak sesuai
print('Error parsing date: $e');
// return 'Format Tanggal Salah';
return inputDate;
}
}
return Row( return Row(
children: [ children: [
// kiri // kiri
@@ -76,7 +96,8 @@ class HistoryRowAtasWidget extends HookConsumerWidget {
), ),
// child: Text('s'), // child: Text('s'),
child: FutureBuilder<Widget>( child: FutureBuilder<Widget>(
future: checkFileExistence('https://devone.aplikasi.web.id/pettycash-media/icon/icon_$icon_category_id.svg'), future: checkFileExistence(
'https://devone.aplikasi.web.id/pettycash-media/icon/icon_$icon_category_id.svg'),
builder: (context, snapshot) { builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.waiting) { if (snapshot.connectionState == ConnectionState.waiting) {
return CircularProgressIndicator(); return CircularProgressIndicator();
@@ -86,8 +107,7 @@ class HistoryRowAtasWidget extends HookConsumerWidget {
color: Colors.red, color: Colors.red,
); );
} else { } else {
return snapshot.data ?? return snapshot.data ?? Container();
Container();
} }
}, },
), ),
@@ -163,7 +183,7 @@ class HistoryRowAtasWidget extends HookConsumerWidget {
), ),
), ),
Text( Text(
tglTransaksi, formatDateString(tglTransaksi),
style: Constant.body1_600(context: context).copyWith( style: Constant.body1_600(context: context).copyWith(
fontWeight: FontWeight.w600, color: Constant.textGreyv2), fontWeight: FontWeight.w600, color: Constant.textGreyv2),
), ),