|
|
|
@ -279,36 +279,25 @@ 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 && |
|
|
|
|
petiSqfliteApi != null && |
|
|
|
|
warehouseSqfliteApi != null) { |
|
|
|
|
print("All conditions met. Saving data..."); |
|
|
|
|
print("All conditions met. Preparing data..."); |
|
|
|
|
|
|
|
|
|
AssetStatusModel assetAddModel = AssetStatusModel( |
|
|
|
|
id: null, |
|
|
|
@ -323,38 +312,40 @@ class _InformasiDataEntryPageState extends State<InformasiDataEntryPage> {
|
|
|
|
|
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}"); |
|
|
|
|
} |
|
|
|
|
} 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"); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} 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 |
|
|
|
|