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.
 
 
 
 
 
 

274 lines
8.7 KiB

import 'package:flutter/material.dart';
import 'package:siopas/models/asset_status_model.dart';
import 'package:siopas/models/condition_peti_model.dart';
import 'package:siopas/models/customer_model.dart';
import 'package:siopas/models/m_asset_status_model.dart';
import 'package:siopas/pages/pengembalian_barang/controller/pengembalian_controller.dart';
import 'package:intl/date_symbol_data_local.dart';
import 'package:intl/intl.dart';
import 'package:collection/collection.dart';
import '../../models/warehouse_mode.dart';
import '../../services/controllerApi.dart';
class DetailPengembalianBarangPage extends StatefulWidget {
final String pengembalianId;
const DetailPengembalianBarangPage({Key? key, required this.pengembalianId})
: super(key: key);
@override
_DetailPengembalianBarangPageState createState() =>
_DetailPengembalianBarangPageState();
}
class _DetailPengembalianBarangPageState
extends State<DetailPengembalianBarangPage> {
AssetStatusModel? pengembalianInfo;
WarehouseModel? warehouseInfo;
List<PetiAssetModel>? petiData;
List<CustomerModel>? customerData;
List<WarehouseModel>? warehouseData;
List<ConditionPetiModel>? _valconditionPeti;
bool loading = true;
@override
void initState() {
super.initState();
getPengembalianIdData();
customerListAPI();
petiListAPI();
warehouseListAPI();
kondisiPetiListAPI();
initializeDateFormatting('id_ID', null);
}
Future customerListAPI() async {
if (mounted) {
await ControllerApi().fetchCustomerDataAPI().then((value) {
setState(() {
customerData = (value as List<dynamic>)
.map((item) => CustomerModel.fromJson(item))
.toList();
loading = false;
});
});
}
}
Future petiListAPI() async {
if (mounted) {
await ControllerApi().fetchPetiDataAPI().then((value) {
setState(() {
petiData = (value as List<dynamic>)
.map((item) => PetiAssetModel.fromJson(item))
.toList();
loading = false;
});
});
}
}
Future kondisiPetiListAPI() async {
if (mounted) {
await ControllerApi().fetchKondisiPetiDataAPI().then((value) {
setState(() {
_valconditionPeti = (value as List<dynamic>)
.map((item) => ConditionPetiModel.fromJson(item))
.toList();
loading = false;
});
});
}
}
Future warehouseListAPI() async {
if (mounted) {
await ControllerApi().fetchWarehouseDataAPI().then((value) {
setState(() {
warehouseData = (value as List<dynamic>)
.map((item) => WarehouseModel.fromJson(item))
.toList();
loading = false;
});
});
}
}
Future<void> getPengembalianIdData() async {
List<AssetStatusModel> pengembalians =
await ControllerPengembalian().fetchPengembalianDataId();
pengembalianInfo = pengembalians.firstWhereOrNull(
(pengembalian) => pengembalian.id.toString() == widget.pengembalianId,
);
setState(() {});
}
String _formatDate(String? date) {
if (date != null) {
DateTime parsedDate = DateTime.parse(date);
String formattedDate =
DateFormat('EEEE, dd MMMM yyyy', 'id_ID').format(parsedDate);
return formattedDate;
} else {
return '';
}
}
@override
Widget build(BuildContext context) {
PetiAssetModel? petiSqfliteApi;
petiSqfliteApi = petiData?.firstWhereOrNull(
(peti) => peti.id == pengembalianInfo!.peti_id,
);
CustomerModel? customerSqfliteApi;
customerSqfliteApi = customerData?.firstWhereOrNull(
(customer) => customer.id == pengembalianInfo?.customer_id,
);
WarehouseModel? warehouseSqfliteApi;
warehouseSqfliteApi = warehouseData?.firstWhereOrNull(
(warehouse) => warehouse.id == pengembalianInfo!.enter_warehouse,
);
ConditionPetiModel? conditionPetiSqfliteApi;
conditionPetiSqfliteApi = _valconditionPeti?.firstWhereOrNull(
(conditionPeti) => conditionPeti.id == pengembalianInfo!.kondisi_peti_id,
);
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: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
Icon(Icons.article, size: 30, color: Colors.white),
SizedBox(width: 10),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'ID:',
style: TextStyle(
fontSize: 12,
fontWeight: FontWeight.bold,
color: Colors.white,
),
),
SizedBox(height: 5),
Text(
petiSqfliteApi != null &&
petiSqfliteApi.fix_lot != null
? petiSqfliteApi!.fix_lot.toString()
: '-',
style: TextStyle(
fontSize: 12,
fontWeight: FontWeight.bold,
color: Colors.white,
),
),
],
),
],
),
],
),
),
),
SizedBox(height: 10),
if (pengembalianInfo != null) ...[
_buildDetailItem(
'Kode Peti',
petiSqfliteApi != null && petiSqfliteApi.fix_lot != null
? petiSqfliteApi!.fix_lot.toString()
: '-',
),
Divider(thickness: 1),
_buildDetailItem('Tgl Pengembalian',
_formatDate(pengembalianInfo!.enter_at.toString())),
Divider(thickness: 1),
_buildDetailItem(
'PJ Pengembalian', pengembalianInfo!.enter_pic.toString()),
Divider(thickness: 1),
_buildDetailItem(
'Gudang',
warehouseSqfliteApi != null &&
warehouseSqfliteApi.name != null
? warehouseSqfliteApi!.name.toString()
: '-'),
Divider(thickness: 1),
_buildDetailItem(
'Kondisi Peti',
conditionPetiSqfliteApi != null &&
conditionPetiSqfliteApi.nama_kondisi != null
? conditionPetiSqfliteApi!.nama_kondisi.toString()
: '-',
),
Divider(thickness: 1),
// ... 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: 12.5, fontWeight: FontWeight.bold),
),
Text(value),
],
),
);
}
}