|
|
@ -279,36 +279,25 @@ 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}"); |
|
|
|
|
|
|
|
continue; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (_exit_atController.text.isNotEmpty && |
|
|
|
if (_exit_atController.text.isNotEmpty && |
|
|
|
petiSqfliteApi != null && |
|
|
|
|
|
|
|
warehouseSqfliteApi != null) { |
|
|
|
warehouseSqfliteApi != null) { |
|
|
|
print("All conditions met. Saving data..."); |
|
|
|
print("All conditions met. Preparing data..."); |
|
|
|
|
|
|
|
|
|
|
|
AssetStatusModel assetAddModel = AssetStatusModel( |
|
|
|
AssetStatusModel assetAddModel = AssetStatusModel( |
|
|
|
id: null, |
|
|
|
id: null, |
|
|
@ -323,38 +312,40 @@ class _InformasiDataEntryPageState extends State<InformasiDataEntryPage> { |
|
|
|
mobile_id: uuid.v4(), |
|
|
|
mobile_id: uuid.v4(), |
|
|
|
); |
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
// Call addData function |
|
|
|
assetAddModels.add(assetAddModel); |
|
|
|
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 { |
|
|
|
|
|
|
|
print("Failed untuk Peti ID: ${selectedPeti.id}"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} else { |
|
|
|
} else { |
|
|
|
print("Conditions not met. Unable to save data."); |
|
|
|
print("Conditions not met. Unable to save data."); |
|
|
|
if (_exit_atController.text.isEmpty) { |
|
|
|
if (_exit_atController.text.isEmpty) { |
|
|
|
print("Exit_atController is empty"); |
|
|
|
print("Exit_atController is empty"); |
|
|
|
} |
|
|
|
} |
|
|
|
if (petiSqfliteApi == null) { |
|
|
|
|
|
|
|
print("petiSqfliteApi is null"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (warehouseSqfliteApi == null) { |
|
|
|
if (warehouseSqfliteApi == null) { |
|
|
|
print("warehouseSqfliteApi is null"); |
|
|
|
print("warehouseSqfliteApi is null"); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
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 |
|
|
|
// Hapus peti-peti yang baru saja disimpan dari SharedPreferences |
|
|
@ -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'); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|