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); String formattedDate = DateFormat('yyyy-MM-dd HH:mm:ss.SSS').format(now);
List<int?> savedPetiIds = []; List<int?> savedPetiIds = [];
List<AssetStatusModel> assetAddModels = [];
for (PetiAssetModel selectedPeti in selectedPetis) { for (PetiAssetModel selectedPeti in selectedPetis) {
// print("Checking conditions for Peti ID: ${selectedPeti.id}"); print("Checking conditions for Peti ID: ${selectedPeti.id}");
// print("Exit_atController: ${_exit_atController.text.isNotEmpty}"); print("Exit_atController: ${_exit_atController.text.isNotEmpty}");
// print("petiSqfliteApi: ${petiSqfliteApi != null}"); print("warehouseSqfliteApi: ${warehouseSqfliteApi != null}");
// print("warehouseSqfliteApi: ${warehouseSqfliteApi != null}");
if (selectedPeti == null) { if (selectedPeti == null) {
print("Selected Peti is null"); print("Selected Peti is null");
continue; continue;
} }
// Ensure that _valpeti is not null before trying to find the PetiAssetModel PetiAssetModel? peti =
if (_valpeti == null) {
print("_valpeti is null");
continue;
}
petiSqfliteApi =
_valpeti?.firstWhereOrNull((peti) => peti.id == selectedPeti.id); _valpeti?.firstWhereOrNull((peti) => peti.id == selectedPeti.id);
if (petiSqfliteApi == null) { if (peti != null) {
print("Peti not found for ID: ${selectedPeti.id}"); if (_exit_atController.text.isNotEmpty &&
continue; 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 && assetAddModels.add(assetAddModel);
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) {
savedPetiIds.add(selectedPeti.id!); 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 { } 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 { } else {
print("Conditions not met. Unable to save data."); print("Peti not found for ID: ${selectedPeti.id}");
if (_exit_atController.text.isEmpty) { }
print("Exit_atController is empty"); }
}
if (petiSqfliteApi == null) { // Save all AssetStatusModels
print("petiSqfliteApi is null"); for (AssetStatusModel assetAddModel in assetAddModels) {
} int result = await Controller().addPeminjamanData(assetAddModel);
if (warehouseSqfliteApi == null) {
print("warehouseSqfliteApi is null"); 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 // Hapus peti-peti yang baru saja disimpan dari SharedPreferences
for (PetiAssetModel selectedPeti in selectedPetis) { for (PetiAssetModel selectedPeti in selectedPetis) {
if (selectedPeti != null) { 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'); Navigator.pushNamed(context, '/peminjaman-barang');
} }

Loading…
Cancel
Save