Browse Source

perbaikan bug pada tambah data peminjaman perulangan list peti

master
unknown 11 months ago
parent
commit
2b79e50b17
  1. 113
      lib/pages/peminjaman_barang/create-finish.dart

113
lib/pages/peminjaman_barang/create-finish.dart

@ -279,84 +279,75 @@ class _InformasiDataEntryPageState extends State<InformasiDataEntryPage> {
String formattedDate = DateFormat('yyyy-MM-dd HH:mm:ss.SSS').format(now);
List<int?> savedPetiIds = [];
List<AssetStatusModel> assetAddModels = [];
for (PetiAssetModel selectedPeti in selectedPetis) {
// print("Checking conditions for Peti ID: ${selectedPeti.id}");
// print("Exit_atController: ${_exit_atController.text.isNotEmpty}");
// print("petiSqfliteApi: ${petiSqfliteApi != null}");
// print("warehouseSqfliteApi: ${warehouseSqfliteApi != null}");
print("Checking conditions for Peti ID: ${selectedPeti.id}");
print("Exit_atController: ${_exit_atController.text.isNotEmpty}");
print("warehouseSqfliteApi: ${warehouseSqfliteApi != null}");
if (selectedPeti == null) {
print("Selected Peti is null");
continue;
}
// Ensure that _valpeti is not null before trying to find the PetiAssetModel
if (_valpeti == null) {
print("_valpeti is null");
continue;
}
petiSqfliteApi =
PetiAssetModel? peti =
_valpeti?.firstWhereOrNull((peti) => peti.id == selectedPeti.id);
if (petiSqfliteApi == null) {
print("Peti not found for ID: ${selectedPeti.id}");
continue;
}
if (peti != null) {
if (_exit_atController.text.isNotEmpty &&
warehouseSqfliteApi != null) {
print("All conditions met. Preparing data...");
AssetStatusModel assetAddModel = AssetStatusModel(
id: null,
peti_id: selectedPeti.id,
customer_id: customerSqfliteApi?.id,
warehouse_id: warehouseSqfliteApi?.id,
exit_at: parseDateTime(_exit_atController.text),
exit_pic: _penanggungJawabController.text,
est_pengembalian: parseDateTime(_est_pengembalianController.text),
created_by: user.fullname,
created_at: parseDateTime(formattedDate),
mobile_id: uuid.v4(),
);
if (_exit_atController.text.isNotEmpty &&
petiSqfliteApi != null &&
warehouseSqfliteApi != null) {
print("All conditions met. Saving data...");
AssetStatusModel assetAddModel = AssetStatusModel(
id: null,
peti_id: selectedPeti.id,
customer_id: customerSqfliteApi?.id,
warehouse_id: warehouseSqfliteApi?.id,
exit_at: parseDateTime(_exit_atController.text),
exit_pic: _penanggungJawabController.text,
est_pengembalian: parseDateTime(_est_pengembalianController.text),
created_by: user.fullname,
created_at: parseDateTime(formattedDate),
mobile_id: uuid.v4(),
);
// Call addData function
int result = await Controller().addPeminjamanData(assetAddModel);
if (result > 0) {
assetAddModels.add(assetAddModel);
savedPetiIds.add(selectedPeti.id!);
if (mounted) {
setState(() {
_exit_atController.text = '';
_penanggungJawabController.text = '';
_est_pengembalianController.text = '';
warehouseSqfliteApi?.id = null;
customerSqfliteApi?.id = null;
});
}
print("Success Tambah data untuk Peti ID: ${selectedPeti.id}");
EasyLoading.showSuccess("Data Berhasil Disimpan");
// Reset controllers and make fields nullable
} else {
print("Failed untuk Peti ID: ${selectedPeti.id}");
print("Conditions not met. Unable to save data.");
if (_exit_atController.text.isEmpty) {
print("Exit_atController is empty");
}
if (warehouseSqfliteApi == null) {
print("warehouseSqfliteApi is null");
}
}
} else {
print("Conditions not met. Unable to save data.");
if (_exit_atController.text.isEmpty) {
print("Exit_atController is empty");
}
if (petiSqfliteApi == null) {
print("petiSqfliteApi is null");
}
if (warehouseSqfliteApi == null) {
print("warehouseSqfliteApi is null");
}
print("Peti not found for ID: ${selectedPeti.id}");
}
}
// Save all AssetStatusModels
for (AssetStatusModel assetAddModel in assetAddModels) {
int result = await Controller().addPeminjamanData(assetAddModel);
if (result <= 0) {
print("Failed untuk Peti ID: ${assetAddModel.peti_id}");
}
}
// Clear controllers and make fields nullable
if (mounted) {
setState(() {
_exit_atController.text = '';
_penanggungJawabController.text = '';
_est_pengembalianController.text = '';
warehouseSqfliteApi?.id = null;
customerSqfliteApi?.id = null;
});
}
// Hapus peti-peti yang baru saja disimpan dari SharedPreferences
for (PetiAssetModel selectedPeti in selectedPetis) {
if (selectedPeti != null) {
@ -364,7 +355,7 @@ class _InformasiDataEntryPageState extends State<InformasiDataEntryPage> {
}
}
// Jika Anda ingin pindah ke halaman setelah menyimpan data untuk semua peti
// Jika Anda ingin pindah ke halaman setelah menyimpan data untuk semua peti
Navigator.pushNamed(context, '/peminjaman-barang');
}

Loading…
Cancel
Save