You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
206 lines
6.9 KiB
206 lines
6.9 KiB
import 'dart:convert'; |
|
|
|
import 'package:flutter/material.dart'; |
|
import 'package:http/http.dart' as http; |
|
import 'package:intl/intl.dart'; |
|
import 'package:siopas/connection/connection.dart'; |
|
|
|
class DetailPengembalianBarangPage extends StatefulWidget { |
|
final int pengembalianId; |
|
const DetailPengembalianBarangPage({Key? key, required this.pengembalianId}) |
|
: super(key: key); |
|
|
|
@override |
|
_DetailPengembalianBarangPageState createState() => |
|
_DetailPengembalianBarangPageState(); |
|
} |
|
|
|
class _DetailPengembalianBarangPageState |
|
extends State<DetailPengembalianBarangPage> { |
|
Map<String, dynamic>? assetStatusData; |
|
|
|
String _formatDate(String date) { |
|
try { |
|
DateTime parsedDate = DateTime.parse(date); |
|
String formattedDate = |
|
DateFormat('EEEE, dd MMMM yyyy', 'id_ID').format(parsedDate); |
|
return formattedDate; |
|
} catch (e) { |
|
// Handle the case where the date string is not valid |
|
return 'Invalid date format'; |
|
} |
|
} |
|
|
|
@override |
|
void initState() { |
|
super.initState(); |
|
_fetchAssetStatusDataPengembalian(); |
|
} |
|
|
|
Future<void> _fetchAssetStatusDataPengembalian() async { |
|
try { |
|
final response = await http.get( |
|
Uri.parse( |
|
'$baseUrl/asset-status/pengembalian/show/${widget.pengembalianId}'), |
|
headers: { |
|
'Content-Type': 'application/json', |
|
}, |
|
); |
|
|
|
if (response.statusCode == 200) { |
|
setState(() { |
|
assetStatusData = json.decode(response.body)['data']['asset_status']; |
|
}); |
|
} else { |
|
throw Exception('Failed to load data'); |
|
} |
|
} catch (e) { |
|
print('Error fetching data: $e'); |
|
} |
|
} |
|
|
|
@override |
|
Widget build(BuildContext context) { |
|
return Scaffold( |
|
backgroundColor: Colors.grey[200], |
|
appBar: AppBar( |
|
backgroundColor: Colors.indigo[700], |
|
elevation: 0, |
|
title: Text('Detail Pengembalian Barang', |
|
style: TextStyle( |
|
color: Colors.white, |
|
fontSize: 16, |
|
)), |
|
leading: IconButton( |
|
icon: Icon(Icons.arrow_back, color: Colors.white), |
|
onPressed: () { |
|
Navigator.pushNamed(context, '/pengembalian-barang'); |
|
}, |
|
), |
|
), |
|
body: Padding( |
|
padding: EdgeInsets.all(16.0), |
|
child: Card( |
|
shape: RoundedRectangleBorder( |
|
borderRadius: BorderRadius.circular(15.0), |
|
), |
|
elevation: 5, |
|
child: Column( |
|
children: [ |
|
Card( |
|
shape: RoundedRectangleBorder( |
|
borderRadius: |
|
BorderRadius.vertical(top: Radius.circular(15.0)), |
|
), |
|
elevation: 0, |
|
margin: EdgeInsets.all(0), |
|
color: Colors.indigo[700], |
|
child: Padding( |
|
padding: const EdgeInsets.all(16.0), |
|
child: Row( |
|
children: [ |
|
Icon(Icons.article, |
|
size: 40, |
|
color: Colors.white), // Ganti ikon sesuai kebutuhan |
|
SizedBox(width: 10), |
|
Text( |
|
'ID: ${widget.pengembalianId}', |
|
style: TextStyle( |
|
fontSize: 20, |
|
fontWeight: FontWeight.bold, |
|
color: Colors.white, |
|
), |
|
), |
|
], |
|
), |
|
), |
|
), |
|
SizedBox(height: 10), |
|
if (assetStatusData != null) ...[ |
|
_buildDetailItem( |
|
'Kode Peti', |
|
assetStatusData!['peti']['customer']['code_customer'] + |
|
' - ' + |
|
assetStatusData!['peti']['tipe_peti']['type'], |
|
), |
|
Divider(thickness: 1), |
|
_buildDetailItem( |
|
'Nama Customer', |
|
assetStatusData!['peti']['customer']['name'] != null |
|
? assetStatusData!['peti']['customer']['name'] |
|
.toString() |
|
: '-'), |
|
Divider(thickness: 1), |
|
_buildDetailItem( |
|
'Tgl Peminjaman', |
|
_formatDate(assetStatusData!['exit_at'] != null |
|
? assetStatusData!['exit_at'] |
|
: '-')), |
|
Divider(thickness: 1), |
|
_buildDetailItem( |
|
'PJ Peminjaman', |
|
assetStatusData!['exit_pic'] != null |
|
? assetStatusData!['exit_pic'].toString() |
|
: '-'), |
|
Divider(thickness: 1), |
|
_buildDetailItem( |
|
'Asal WH Peminjaman', |
|
assetStatusData!['warehouse']['name'] != null |
|
? assetStatusData!['warehouse']['name'].toString() |
|
: '-'), |
|
Divider(thickness: 1), |
|
_buildDetailItem( |
|
'Tgl Pengembalian', |
|
assetStatusData!['enter_at'] != null && |
|
assetStatusData!['enter_at'] != '0000-00-00 00:00:00' |
|
? _formatDate(assetStatusData!['enter_at']) |
|
: '-', |
|
), |
|
Divider(thickness: 1), |
|
_buildDetailItem( |
|
'PJ Pengembalian', |
|
assetStatusData!['enter_pic'] != null |
|
? assetStatusData!['enter_pic'].toString() |
|
: '-'), |
|
Divider(thickness: 1), |
|
_buildDetailItem( |
|
'Tujuan WH Pengembalian', |
|
assetStatusData!['warehouse_enter'] != null |
|
? assetStatusData!['warehouse_enter']['name'].toString() |
|
: '-'), |
|
Divider(thickness: 1), |
|
_buildDetailItem( |
|
'Kondisi Peti', |
|
assetStatusData!['kondisi_peti'] != null |
|
? assetStatusData!['kondisi_peti'].toString() |
|
: '-'), |
|
Divider(thickness: 1), |
|
_buildDetailItem( |
|
'Status', |
|
assetStatusData!['warehouse_enter'] != null |
|
? assetStatusData!['warehouse_enter']['name'].toString() |
|
: '-'), |
|
], |
|
], |
|
), |
|
), |
|
), |
|
); |
|
} |
|
|
|
Widget _buildDetailItem(String label, String value) { |
|
return Padding( |
|
padding: const EdgeInsets.symmetric(vertical: 8.0, horizontal: 16.0), |
|
child: Row( |
|
mainAxisAlignment: MainAxisAlignment.spaceBetween, |
|
children: [ |
|
Text( |
|
label, |
|
style: TextStyle(fontSize: 14, fontWeight: FontWeight.bold), |
|
), |
|
Text(value), |
|
], |
|
), |
|
); |
|
} |
|
}
|
|
|