confirmWeight method

dynamic confirmWeight()

Implementation

confirmWeight() async {
  wtMismatchCmt = '';
  wtFtNotFoundCmt = '';
  wtVehicleNoMismatchCmt = '';
  tblTRLoadingWeighingTO.wtMismatchCmt = null;
  tblTRLoadingWeighingTO.wtFtNotFoundCmt = null;
  tblTRLoadingWeighingTO.wtVehicleNoMismatchCmt = null;

  final String vehicleNo = removeSpaceFromString(selectVehicleNo.value!.text);

  final Map<String, dynamic> params = {
    'ipAddr': tblTRLoadingWeighingTO.machineIP,
    'machineId': tblTRLoadingWeighingTO.weighingMachineId,
    'ShowWeightOrFullTIcket': 1,
    'vehicleNo': vehicleNo,
  };

  try {
    final response = await _apiService
        .getData(AppUrls.getLatestWeightByMachineIp, queryParams: params);

    if (response.statusCode == 200 && response.data != null) {
      WBAutoWeighingTO = WeighingTO.fromJson(response.data);
      WbForWeigingComplate = WeighingTO.fromJson(response.data);
      isConfirmButtonEnabled.value = false;
      isConfirmButtonEnabled.value = true;

      if (WBAutoWeighingTO.rstNo == null &&
          WBAutoWeighingTO.wbVehicleNo == null) {
        isConfirmed.value =
            (finalTblTRLoadingWeighingTO.value.netWeight != 0 &&
                    finalTblTRLoadingWeighingTO.value.netWeight != null)
                ? true
                : false;

        final bool? userConfirmed = await showConfirmationDialog(
            'WB Full Ticket data is not found against this vehicle.');

        if (userConfirmed == true || userConfirmed == null) {
          isConfirmButtonEnabled.value = true;
          increaseRetryCount();
          return;
        } else {
          wtFtNotFoundCmt =
              'WB Full Ticket data is not found against this vehicle.';
        }
      } else {
        if (WBAutoWeighingTO.wbFTVehicleNoMatchRes != 1) {
          final bool? userConfirmed = await showConfirmationDialog(
              'We found RSTNo ${WBAutoWeighingTO.rstNo} with vehicle NO ${WBAutoWeighingTO.wbVehicleNo} in full ticket. So selected vehicle and Full ticket details vehicle no are mismatch. Are you sure want to continue?');

          if (userConfirmed == true) {
            isConfirmButtonEnabled.value = true;
            WBAutoWeighingTO = WeighingTO();
            increaseRetryCount();
            return;
          } else {
            wtVehicleNoMismatchCmt =
                'We found RSTNo ${WBAutoWeighingTO.rstNo} with vehicle NO ${WBAutoWeighingTO.wbVehicleNo} in full ticket. So selected vehicle and Full ticket details vehicle no are mismatch.';
            await Future.delayed(const Duration(milliseconds: 1000));
          }
        }
        print(tblTRLoadingWeighingTO.actualWeight);
        if (tblTRLoadingWeighingTO.actualWeight != null &&
            tblTRLoadingWeighingTO.actualWeight != 0 &&
            tblTRLoadingWeighingTO.actualWeight! > 0 &&
            WBAutoWeighingTO.wbFTVehicleNoMatchRes == 1) {
          if (tblTRLoadingWeighingTO.actualWeight !=
              WBAutoWeighingTO.measurement) {
            isConfirmed.value =
                (finalTblTRLoadingWeighingTO.value.netWeight != 0 &&
                        finalTblTRLoadingWeighingTO.value.netWeight != null)
                    ? true
                    : false;

            final bool? mismatchConfirmed = await showConfirmationDialog(
                'Weighing full ticket and weighing data are mismatched');

            if (mismatchConfirmed == true || mismatchConfirmed == null) {
              WBAutoWeighingTO = WeighingTO();
              isConfirmButtonEnabled.value = true;
              increaseRetryCount();
              return;
            } else {
              wtMismatchCmt =
                  'Weighing full ticket and weighing data are mismatched';
            }
          }
        }
      }
    } else {
      final bool? userConfirmed = await showConfirmationDialog(
          'WB Full Ticket data is not found against this vehicle.');

      if (userConfirmed == true || userConfirmed == null) {
        isConfirmButtonEnabled.value = true;
        increaseRetryCount();
        return;
      } else {
        wtFtNotFoundCmt =
            'WB Full Ticket data is not found against this vehicle.';
      }
    }
    handleWeighingStatus();
  } catch (e) {
    print(e);

    final bool? userConfirmed = await showConfirmationDialog(
        'WB Full Ticket data is not found against this vehicle.');

    if (userConfirmed == true || userConfirmed == null) {
      isConfirmButtonEnabled.value = true;
      increaseRetryCount();
      return;
    } else {
      wtFtNotFoundCmt =
          'WB Full Ticket data is not found against this vehicle.';
    }

    handleWeighingStatus();
    AppUtils.showSnackBar('Server Error - Failed to Confirm Weight');
  } finally {}
}