fetchOrders method

void fetchOrders(
  1. BuildContext context,
  2. String? merchantID
)

Implementation

void fetchOrders(BuildContext context, String? merchantID) async {
  tempItems.clear();
  items.clear();
  try {
    isLoading(true);
    var request = {
      'api_key': await Constants.apiKey(),
      'merchant_id': merchantID ?? Storage.getValue(Constants.merchantID)
    };
    var response = await DioClient().request(
        context: context,
        api: '/merchant/orders/get',
        method: Method.POST,
        params: request);

    AllOrdersResponse allOrdersResponse =
        AllOrdersResponse.fromJson(response);
    if (allOrdersResponse.status == Strings.success) {
      tempItems.addAll(allOrdersResponse.data!.obs);
      items.addAll(tempItems);
      totalOrders = items.length.obs;
      double totalSales = 0.00;
      if (items.isNotEmpty) {
        for (var val in items) {
          totalSales += double.parse(val.amount!.replaceAll(',', ''));
        }
      }
      var tt = (totalSales).toStringAsFixed(2).split(".")[0];
      totalSalesWhole =
          tt.toString()=='0' ? '0' :formatter.format(double.parse(tt)).toString();
      totalSalesDecimal = totalSales.toStringAsFixed(2).split(".")[1];
    } else {
      isError(true);
      errorMessage.value = response['message'].toString().toTitleCase();
      return Utils.showSnackbar(context, Strings.error,
          response['message'].toString().toTitleCase(), AppColors.red);
    }
  } finally {
    isLoading(false);
  }
  update();
}