getInvoice method

Future<void> getInvoice(
  1. String tnxId
)

Implementation

Future<void> getInvoice(String tnxId) async {
  BuildContext context = Get.context!;
  Helper.progressDialog(context, "Please wait..");
  try {
    InvoiceGenerateModel model =
        await ApiClient(baseUrl: ApiConstant.posBaseUrl).invoiceGenerate(
      transactionId: tnxId ?? "",
      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 ((item.attachmentType ?? "").trim() == "INVOICE") {
            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();
    log(err.toString());
    print(stacktrace);
    Helper.messageDialog(Get.context!, "Try Again!!", err.toString());
  }
}