Siopas Inventory PETI for ISTW Mobile
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.

158 lines
4.8 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 DetailPeminjamanBarangPage extends StatefulWidget {
final int assetId;
const DetailPeminjamanBarangPage({Key? key, required this.assetId})
: super(key: key);
@override
_DetailPeminjamanBarangPageState createState() =>
_DetailPeminjamanBarangPageState();
}
class _DetailPeminjamanBarangPageState
extends State<DetailPeminjamanBarangPage> {
Map<String, dynamic>? assetStatusData;
String _formatDate(String date) {
DateTime parsedDate = DateTime.parse(date);
String formattedDate =
DateFormat('EEEE, dd MMMM yyyy', 'id_ID').format(parsedDate);
return formattedDate;
}
@override
void initState() {
super.initState();
_fetchAssetStatusData();
}
Future<void> _fetchAssetStatusData() async {
try {
final response = await http.get(
Uri.parse('$baseUrl/asset-status/show/${widget.assetId}'),
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 Peminjaman Barang',
style: TextStyle(
color: Colors.white,
fontSize: 16,
)),
leading: IconButton(
icon: Icon(Icons.arrow_back, color: Colors.white),
onPressed: () {
Navigator.pushNamed(context, '/peminjaman-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.assetId}',
style: TextStyle(
fontSize: 20,
fontWeight: FontWeight.bold,
color: Colors.white,
),
),
],
),
),
),
SizedBox(height: 10),
if (assetStatusData != null) ...[
_buildDetailItem(
'Peti Nama',
assetStatusData!['peti']['customer']['code_customer'] +
' - ' +
assetStatusData!['peti']['tipe_peti']['type'],
),
// _buildDetailItem(
// 'Peti Nama', assetStatusData!['peti']['fix_lot']),
Divider(thickness: 1),
_buildDetailItem('Nama Customer',
assetStatusData!['peti']['customer']['name']),
Divider(thickness: 1),
_buildDetailItem(
'Tgl Peminjaman', _formatDate(assetStatusData!['exit_at'])),
Divider(thickness: 1),
_buildDetailItem('PJ Peminjaman', assetStatusData!['exit_pic']),
Divider(thickness: 1),
_buildDetailItem(
'Exit Warehouse', assetStatusData!['warehouse']['name']),
// ... tambahkan data lainnya sesuai kebutuhan
],
],
),
),
),
);
}
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: 16, fontWeight: FontWeight.bold),
),
Text(value),
],
),
);
}
}