prepareWeighingDiffScreen method
void
prepareWeighingDiffScreen()
Implementation
void prepareWeighingDiffScreen() {
if (tempTblTRLoadingWeighingTOList.isNotEmpty) {
tempTblTRLoadingTO.value = TblTRLoadingTO();
loadingWeightTO.value = TblTRLoadingWeighingTO();
unloadingWeightTO.value = TblTRLoadingWeighingTO();
diffWeightTO.value = TblTRLoadingWeighingTO();
tempTblTRLoadingTO.value.idLoading =
tempTblTRLoadingWeighingTOList[0].loadingId;
tempTblTRLoadingTO.value.weighingRemark = '';
// Loading Gross Weight
final loadingGross = tempTblTRLoadingWeighingTOList.firstWhere(
(f) =>
f.loadingTypeId == LoadingTypeIdE.loading.value &&
f.weighingMeasureTypeId == WeighingMeasureTypeIdE.grossWeight.value,
orElse: TblTRLoadingWeighingTO.new,
);
loadingWeightTO.value.grossWeight = loadingGross.grossWeight ?? 0;
// Loading Net Weight (sum of intermediate weights)
final loadingIntermediates = tempTblTRLoadingWeighingTOList.where(
(f) =>
f.loadingTypeId == LoadingTypeIdE.loading.value &&
f.weighingMeasureTypeId ==
WeighingMeasureTypeIdE.intermediateWeight.value,
);
loadingWeightTO.value.netWeight = loadingIntermediates.fold<double>(
0, (sum, obj) => sum + (obj.netWeight ?? 0));
// Loading Tare Weight
final loadingTare = tempTblTRLoadingWeighingTOList.firstWhere(
(f) =>
f.loadingTypeId == LoadingTypeIdE.loading.value &&
f.weighingMeasureTypeId == WeighingMeasureTypeIdE.tareWeight.value,
orElse: TblTRLoadingWeighingTO.new,
);
loadingWeightTO.value.tareWeight = loadingTare.grossWeight ?? 0;
// Unloading Gross Weight
final unloadingGross = tempTblTRLoadingWeighingTOList.firstWhere(
(f) =>
f.loadingTypeId == LoadingTypeIdE.unloading.value &&
f.weighingMeasureTypeId == WeighingMeasureTypeIdE.grossWeight.value,
orElse: TblTRLoadingWeighingTO.new,
);
unloadingWeightTO.value.grossWeight = unloadingGross.grossWeight ?? 0;
// Unloading Net Weight (sum of intermediate weights)
final unloadingIntermediates = tempTblTRLoadingWeighingTOList.where(
(f) =>
f.loadingTypeId == LoadingTypeIdE.unloading.value &&
f.weighingMeasureTypeId ==
WeighingMeasureTypeIdE.intermediateWeight.value,
);
unloadingWeightTO.value.netWeight = unloadingIntermediates.fold<double>(
0, (sum, obj) => sum + (obj.netWeight ?? 0));
// Unloading Tare Weight
final unloadingTare = tempTblTRLoadingWeighingTOList.firstWhere(
(f) =>
f.loadingTypeId == LoadingTypeIdE.unloading.value &&
f.weighingMeasureTypeId == WeighingMeasureTypeIdE.tareWeight.value,
orElse: TblTRLoadingWeighingTO.new,
);
unloadingWeightTO.value.tareWeight = unloadingTare.grossWeight ?? 0;
// Calculate differences
diffWeightTO.value.grossWeight = (loadingWeightTO.value.grossWeight! -
unloadingWeightTO.value.grossWeight!)
.abs();
diffWeightTO.value.tareWeight = (loadingWeightTO.value.tareWeight! -
unloadingWeightTO.value.tareWeight!)
.abs();
diffWeightTO.value.netWeight = (loadingWeightTO.value.netWeight! -
unloadingWeightTO.value.netWeight!)
.abs();
// Show dialog instead of jQuery modal
showWeighingDiffDialog();
} else {
resetData();
}
}