getInvoiceOrReceiptForTransactionHistory method

Future<void> getInvoiceOrReceiptForTransactionHistory(
  1. String transactionId,
  2. List<String> attachmentType
)

Implementation

Future<void> getInvoiceOrReceiptForTransactionHistory(
    String transactionId, List<String> attachmentType) async {
  BuildContext context = Get.context!;

  Helper.progressDialog(context, "Please wait..");

  try {
    InvoiceGenerateModel model =
        await ApiClient(baseUrl: ApiConstant.posBaseUrl)
            .invoiceGenerateForTransactionHistory(
      transactionId: transactionId ?? "",
      xUserName: SingletonSotrage.secureStorageInterface.readSecureData(
            SecureStorageService.xUserId,
          ) ??
          "",
      xUserId: SingletonSotrage.secureStorageInterface.readSecureData(
            SecureStorageService.xUserId,
          ) ??
          "",
      xChannel: packageName.value
          ? Constants.xPosChannel
          : Constants.xDealerChannel,
    );
    Helper.close();
    if (model.status?.trim() == "POS200") {
      if (model.data != null) {
        for (var item in model.data!) {
          if (attachmentType.contains((item.attachmentType ?? "").trim())) {
            docUrl.value = item.fileStorageDetailsEntity?.downloadUrl ?? "";
            if (docUrl.value.isNotEmpty) {
              if (await canLaunchUrl(Uri.parse(docUrl.value))) {
                await launchUrl(
                  Uri.parse(docUrl.value),
                  mode: LaunchMode.inAppBrowserView,
                );
                return;
              } else {}
            }
          }
        }
      }
    } else {
      Helper.messageDialog(
          Get.context!,
          model.errors?.elementAtOrNull(0)?.code ?? "tryAgain".tr,
          model.errors?.elementAtOrNull(0)?.localeMessage ??
              'somethingWrong'.tr);
    }
  } catch (err, stacktrace) {
    Helper.close();
    Helper.messageDialog(Get.context!, "tryAgain".tr, 'somethingWrong'.tr);
  }
}