feat: tambahan fitur swipe untuk hapus item dan tap untuk webview transaksi
parent
eece292526
commit
d64d3716c3
|
|
@ -10,6 +10,8 @@ class LocalReceipt {
|
||||||
final DateTime transactionDate;
|
final DateTime transactionDate;
|
||||||
final String?
|
final String?
|
||||||
transactionDescription; // Deskripsi transaksi untuk tampilan di daftar
|
transactionDescription; // Deskripsi transaksi untuk tampilan di daftar
|
||||||
|
final String? fireflyTransactionId; // ID transaksi di FireFly III
|
||||||
|
final String? fireflyTransactionUrl; // URL transaksi di FireFly III
|
||||||
final bool isSubmitted;
|
final bool isSubmitted;
|
||||||
final String? submissionError;
|
final String? submissionError;
|
||||||
final DateTime? submittedAt;
|
final DateTime? submittedAt;
|
||||||
|
|
@ -24,6 +26,8 @@ class LocalReceipt {
|
||||||
this.destinationAccountName,
|
this.destinationAccountName,
|
||||||
required this.transactionDate,
|
required this.transactionDate,
|
||||||
this.transactionDescription,
|
this.transactionDescription,
|
||||||
|
this.fireflyTransactionId,
|
||||||
|
this.fireflyTransactionUrl,
|
||||||
this.isSubmitted = false,
|
this.isSubmitted = false,
|
||||||
this.submissionError,
|
this.submissionError,
|
||||||
this.submittedAt,
|
this.submittedAt,
|
||||||
|
|
@ -42,6 +46,8 @@ class LocalReceipt {
|
||||||
'destinationAccountName': destinationAccountName,
|
'destinationAccountName': destinationAccountName,
|
||||||
'transactionDate': transactionDate.toIso8601String(),
|
'transactionDate': transactionDate.toIso8601String(),
|
||||||
'transactionDescription': transactionDescription,
|
'transactionDescription': transactionDescription,
|
||||||
|
'fireflyTransactionId': fireflyTransactionId,
|
||||||
|
'fireflyTransactionUrl': fireflyTransactionUrl,
|
||||||
'isSubmitted': isSubmitted,
|
'isSubmitted': isSubmitted,
|
||||||
'submissionError': submissionError,
|
'submissionError': submissionError,
|
||||||
'submittedAt': submittedAt?.toIso8601String(),
|
'submittedAt': submittedAt?.toIso8601String(),
|
||||||
|
|
@ -61,6 +67,8 @@ class LocalReceipt {
|
||||||
destinationAccountName: json['destinationAccountName'],
|
destinationAccountName: json['destinationAccountName'],
|
||||||
transactionDate: DateTime.parse(json['transactionDate']),
|
transactionDate: DateTime.parse(json['transactionDate']),
|
||||||
transactionDescription: json['transactionDescription'],
|
transactionDescription: json['transactionDescription'],
|
||||||
|
fireflyTransactionId: json['fireflyTransactionId'],
|
||||||
|
fireflyTransactionUrl: json['fireflyTransactionUrl'],
|
||||||
isSubmitted: json['isSubmitted'] ?? false,
|
isSubmitted: json['isSubmitted'] ?? false,
|
||||||
submissionError: json['submissionError'],
|
submissionError: json['submissionError'],
|
||||||
submittedAt: json['submittedAt'] != null
|
submittedAt: json['submittedAt'] != null
|
||||||
|
|
@ -79,6 +87,8 @@ class LocalReceipt {
|
||||||
String? destinationAccountName,
|
String? destinationAccountName,
|
||||||
DateTime? transactionDate,
|
DateTime? transactionDate,
|
||||||
String? transactionDescription,
|
String? transactionDescription,
|
||||||
|
String? fireflyTransactionId,
|
||||||
|
String? fireflyTransactionUrl,
|
||||||
bool? isSubmitted,
|
bool? isSubmitted,
|
||||||
String? submissionError,
|
String? submissionError,
|
||||||
DateTime? submittedAt,
|
DateTime? submittedAt,
|
||||||
|
|
@ -95,6 +105,9 @@ class LocalReceipt {
|
||||||
transactionDate: transactionDate ?? this.transactionDate,
|
transactionDate: transactionDate ?? this.transactionDate,
|
||||||
transactionDescription:
|
transactionDescription:
|
||||||
transactionDescription ?? this.transactionDescription,
|
transactionDescription ?? this.transactionDescription,
|
||||||
|
fireflyTransactionId: fireflyTransactionId ?? this.fireflyTransactionId,
|
||||||
|
fireflyTransactionUrl:
|
||||||
|
fireflyTransactionUrl ?? this.fireflyTransactionUrl,
|
||||||
isSubmitted: isSubmitted ?? this.isSubmitted,
|
isSubmitted: isSubmitted ?? this.isSubmitted,
|
||||||
submissionError: submissionError ?? this.submissionError,
|
submissionError: submissionError ?? this.submissionError,
|
||||||
submittedAt: submittedAt ?? this.submittedAt,
|
submittedAt: submittedAt ?? this.submittedAt,
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
|
||||||
import 'package:cashumit/models/local_receipt.dart';
|
import 'package:cashumit/models/local_receipt.dart';
|
||||||
import 'package:cashumit/services/local_receipt_service.dart';
|
import 'package:cashumit/services/local_receipt_service.dart';
|
||||||
import 'package:cashumit/services/receipt_service.dart';
|
import 'package:cashumit/services/receipt_service.dart';
|
||||||
|
import 'package:cashumit/screens/webview_screen.dart';
|
||||||
import 'package:intl/intl.dart';
|
import 'package:intl/intl.dart';
|
||||||
|
|
||||||
class LocalReceiptsScreen extends StatefulWidget {
|
class LocalReceiptsScreen extends StatefulWidget {
|
||||||
|
|
@ -116,7 +117,13 @@ class _LocalReceiptsScreenState extends State<LocalReceiptsScreen> {
|
||||||
symbol: 'Rp ',
|
symbol: 'Rp ',
|
||||||
decimalDigits: 0,
|
decimalDigits: 0,
|
||||||
);
|
);
|
||||||
return formatter.format(amount).replaceAll('.00', '');
|
// Jangan hapus .00 karena ini penting untuk format rupiah
|
||||||
|
String formatted = formatter.format(amount);
|
||||||
|
// Hapus .00 hanya jika muncul di akhir
|
||||||
|
if (formatted.endsWith('.00')) {
|
||||||
|
formatted = formatted.substring(0, formatted.length - 3);
|
||||||
|
}
|
||||||
|
return formatted;
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
|
@ -262,7 +269,23 @@ class _LocalReceiptsScreenState extends State<LocalReceiptsScreen> {
|
||||||
itemCount: receipts.length,
|
itemCount: receipts.length,
|
||||||
itemBuilder: (context, index) {
|
itemBuilder: (context, index) {
|
||||||
final receipt = receipts[index];
|
final receipt = receipts[index];
|
||||||
return Card(
|
return Dismissible(
|
||||||
|
key: Key(receipt.id),
|
||||||
|
direction: DismissDirection.endToStart,
|
||||||
|
onDismissed: (direction) {
|
||||||
|
_deleteReceipt(receipt.id);
|
||||||
|
},
|
||||||
|
background: Container(
|
||||||
|
color: Colors.red,
|
||||||
|
alignment: Alignment.centerRight,
|
||||||
|
padding: const EdgeInsets.only(right: 16),
|
||||||
|
child: const Icon(
|
||||||
|
Icons.delete,
|
||||||
|
color: Colors.white,
|
||||||
|
size: 24,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
child: Card(
|
||||||
margin: const EdgeInsets.only(bottom: 8),
|
margin: const EdgeInsets.only(bottom: 8),
|
||||||
child: ListTile(
|
child: ListTile(
|
||||||
contentPadding: const EdgeInsets.all(16),
|
contentPadding: const EdgeInsets.all(16),
|
||||||
|
|
@ -319,7 +342,8 @@ class _LocalReceiptsScreenState extends State<LocalReceiptsScreen> {
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
subtitle: Column(
|
subtitle: Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment:
|
||||||
|
CrossAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
const SizedBox(height: 4),
|
const SizedBox(height: 4),
|
||||||
Text(
|
Text(
|
||||||
|
|
@ -344,26 +368,26 @@ class _LocalReceiptsScreenState extends State<LocalReceiptsScreen> {
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
trailing: PopupMenuButton<String>(
|
onTap: receipt.isSubmitted &&
|
||||||
onSelected: (String action) {
|
receipt.fireflyTransactionUrl != null
|
||||||
if (action == 'delete') {
|
? () {
|
||||||
_showDeleteConfirmation(receipt.id);
|
Navigator.push(
|
||||||
|
context,
|
||||||
|
MaterialPageRoute(
|
||||||
|
builder: (context) =>
|
||||||
|
WebViewScreen(
|
||||||
|
url: receipt
|
||||||
|
.fireflyTransactionUrl!,
|
||||||
|
title: 'Detail Transaksi',
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
},
|
: null,
|
||||||
itemBuilder: (BuildContext context) {
|
tileColor: receipt.isSubmitted &&
|
||||||
return [
|
receipt.fireflyTransactionUrl != null
|
||||||
const PopupMenuItem<String>(
|
? Colors.blue.shade50
|
||||||
value: 'delete',
|
: null,
|
||||||
child: Row(
|
|
||||||
children: [
|
|
||||||
Icon(Icons.delete, size: 18),
|
|
||||||
SizedBox(width: 8),
|
|
||||||
Text('Hapus'),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
];
|
|
||||||
},
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
@ -376,27 +400,5 @@ class _LocalReceiptsScreenState extends State<LocalReceiptsScreen> {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _showDeleteConfirmation(String receiptId) async {
|
// Fungsi _showDeleteConfirmation dihapus karena sudah menggunakan swipe gesture
|
||||||
final result = await showDialog<bool>(
|
|
||||||
context: context,
|
|
||||||
builder: (context) => AlertDialog(
|
|
||||||
title: const Text('Konfirmasi Hapus'),
|
|
||||||
content: const Text('Apakah Anda yakin ingin menghapus nota ini?'),
|
|
||||||
actions: [
|
|
||||||
TextButton(
|
|
||||||
onPressed: () => Navigator.pop(context, false),
|
|
||||||
child: const Text('Batal'),
|
|
||||||
),
|
|
||||||
TextButton(
|
|
||||||
onPressed: () => Navigator.pop(context, true),
|
|
||||||
child: const Text('Hapus'),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
if (result == true) {
|
|
||||||
_deleteReceipt(receiptId);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -200,6 +200,18 @@ class LocalReceiptService {
|
||||||
amount: receipt.total.toStringAsFixed(2),
|
amount: receipt.total.toStringAsFixed(2),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Jika transaksi berhasil dikirim, simpan transactionId dan URL
|
||||||
|
if (transactionId != null) {
|
||||||
|
// Update receipt dengan transactionId dan URL
|
||||||
|
final updatedReceipt = receipt.copyWith(
|
||||||
|
fireflyTransactionId: transactionId,
|
||||||
|
fireflyTransactionUrl: '$baseUrl/transactions/show/$transactionId',
|
||||||
|
);
|
||||||
|
|
||||||
|
// Simpan kembali receipt yang diperbarui ke storage
|
||||||
|
await saveReceipt(updatedReceipt);
|
||||||
|
}
|
||||||
|
|
||||||
return transactionId;
|
return transactionId;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
print('Error submitting receipt to FireFly III: $e');
|
print('Error submitting receipt to FireFly III: $e');
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue