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 String?
|
||||
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 String? submissionError;
|
||||
final DateTime? submittedAt;
|
||||
|
|
@ -24,6 +26,8 @@ class LocalReceipt {
|
|||
this.destinationAccountName,
|
||||
required this.transactionDate,
|
||||
this.transactionDescription,
|
||||
this.fireflyTransactionId,
|
||||
this.fireflyTransactionUrl,
|
||||
this.isSubmitted = false,
|
||||
this.submissionError,
|
||||
this.submittedAt,
|
||||
|
|
@ -42,6 +46,8 @@ class LocalReceipt {
|
|||
'destinationAccountName': destinationAccountName,
|
||||
'transactionDate': transactionDate.toIso8601String(),
|
||||
'transactionDescription': transactionDescription,
|
||||
'fireflyTransactionId': fireflyTransactionId,
|
||||
'fireflyTransactionUrl': fireflyTransactionUrl,
|
||||
'isSubmitted': isSubmitted,
|
||||
'submissionError': submissionError,
|
||||
'submittedAt': submittedAt?.toIso8601String(),
|
||||
|
|
@ -61,6 +67,8 @@ class LocalReceipt {
|
|||
destinationAccountName: json['destinationAccountName'],
|
||||
transactionDate: DateTime.parse(json['transactionDate']),
|
||||
transactionDescription: json['transactionDescription'],
|
||||
fireflyTransactionId: json['fireflyTransactionId'],
|
||||
fireflyTransactionUrl: json['fireflyTransactionUrl'],
|
||||
isSubmitted: json['isSubmitted'] ?? false,
|
||||
submissionError: json['submissionError'],
|
||||
submittedAt: json['submittedAt'] != null
|
||||
|
|
@ -79,6 +87,8 @@ class LocalReceipt {
|
|||
String? destinationAccountName,
|
||||
DateTime? transactionDate,
|
||||
String? transactionDescription,
|
||||
String? fireflyTransactionId,
|
||||
String? fireflyTransactionUrl,
|
||||
bool? isSubmitted,
|
||||
String? submissionError,
|
||||
DateTime? submittedAt,
|
||||
|
|
@ -95,6 +105,9 @@ class LocalReceipt {
|
|||
transactionDate: transactionDate ?? this.transactionDate,
|
||||
transactionDescription:
|
||||
transactionDescription ?? this.transactionDescription,
|
||||
fireflyTransactionId: fireflyTransactionId ?? this.fireflyTransactionId,
|
||||
fireflyTransactionUrl:
|
||||
fireflyTransactionUrl ?? this.fireflyTransactionUrl,
|
||||
isSubmitted: isSubmitted ?? this.isSubmitted,
|
||||
submissionError: submissionError ?? this.submissionError,
|
||||
submittedAt: submittedAt ?? this.submittedAt,
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
|
|||
import 'package:cashumit/models/local_receipt.dart';
|
||||
import 'package:cashumit/services/local_receipt_service.dart';
|
||||
import 'package:cashumit/services/receipt_service.dart';
|
||||
import 'package:cashumit/screens/webview_screen.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
|
||||
class LocalReceiptsScreen extends StatefulWidget {
|
||||
|
|
@ -116,7 +117,13 @@ class _LocalReceiptsScreenState extends State<LocalReceiptsScreen> {
|
|||
symbol: 'Rp ',
|
||||
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
|
||||
|
|
@ -262,7 +269,23 @@ class _LocalReceiptsScreenState extends State<LocalReceiptsScreen> {
|
|||
itemCount: receipts.length,
|
||||
itemBuilder: (context, 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),
|
||||
child: ListTile(
|
||||
contentPadding: const EdgeInsets.all(16),
|
||||
|
|
@ -319,7 +342,8 @@ class _LocalReceiptsScreenState extends State<LocalReceiptsScreen> {
|
|||
],
|
||||
),
|
||||
subtitle: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
crossAxisAlignment:
|
||||
CrossAxisAlignment.start,
|
||||
children: [
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
|
|
@ -344,26 +368,26 @@ class _LocalReceiptsScreenState extends State<LocalReceiptsScreen> {
|
|||
),
|
||||
],
|
||||
),
|
||||
trailing: PopupMenuButton<String>(
|
||||
onSelected: (String action) {
|
||||
if (action == 'delete') {
|
||||
_showDeleteConfirmation(receipt.id);
|
||||
onTap: receipt.isSubmitted &&
|
||||
receipt.fireflyTransactionUrl != null
|
||||
? () {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) =>
|
||||
WebViewScreen(
|
||||
url: receipt
|
||||
.fireflyTransactionUrl!,
|
||||
title: 'Detail Transaksi',
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
},
|
||||
itemBuilder: (BuildContext context) {
|
||||
return [
|
||||
const PopupMenuItem<String>(
|
||||
value: 'delete',
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(Icons.delete, size: 18),
|
||||
SizedBox(width: 8),
|
||||
Text('Hapus'),
|
||||
],
|
||||
),
|
||||
),
|
||||
];
|
||||
},
|
||||
: null,
|
||||
tileColor: receipt.isSubmitted &&
|
||||
receipt.fireflyTransactionUrl != null
|
||||
? Colors.blue.shade50
|
||||
: null,
|
||||
),
|
||||
),
|
||||
);
|
||||
|
|
@ -376,27 +400,5 @@ class _LocalReceiptsScreenState extends State<LocalReceiptsScreen> {
|
|||
);
|
||||
}
|
||||
|
||||
Future<void> _showDeleteConfirmation(String receiptId) async {
|
||||
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);
|
||||
}
|
||||
}
|
||||
// Fungsi _showDeleteConfirmation dihapus karena sudah menggunakan swipe gesture
|
||||
}
|
||||
|
|
|
|||
|
|
@ -200,6 +200,18 @@ class LocalReceiptService {
|
|||
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;
|
||||
} catch (e) {
|
||||
print('Error submitting receipt to FireFly III: $e');
|
||||
|
|
|
|||
Loading…
Reference in New Issue