In this blog, I will explain to you how to get an estimate as PDF and download it in .NET MVC web application using SDK.
Before using any Quickbooks online API we need access token, if you don’t know how to get access token then you can find it here.
We will download estimate pdf by estimate Id.
For that, we have to get an “estimate” form Quickbooks Online and call GetPdf function. it will return a byte array of pdf, we have to convert byte array to a pdf file and return pdf file to a user.
Below are a few steps to get an estimate as PDF,
public FileResult GetEstimatePdfById(string EstimateID) { byte[] EstimatePdfByteArray; try { OAuth2RequestValidator oauthValidator = new OAuth2RequestValidator(Access_token); // Create a ServiceContext with Auth tokens and realmId ServiceContext serviceContext = new ServiceContext(RealmId, IntuitServicesType.QBO, oauthValidator); serviceContext.IppConfiguration.MinorVersion.Qbo = "23"; serviceContext.IppConfiguration.BaseUrl.Qbo = QboBaseUrl; string EXISTING_ESTIMATE_QUERYBYID = string.Format("select * from Estimate where id = '{0}'", EstimateID); var queryService = new QueryService<Estimate>(serviceContext); Estimate objEstimateFound = queryService.ExecuteIdsQuery(EXISTING_ESTIMATE_QUERYBYID).FirstOrDefault<Estimate>(); //If Estimate found on Quickbooks online if (objEstimateFound != null) { DataService dataService = new DataService(serviceContext); //it will return Byte Array of pdf EstimatePdfByteArray = dataService.GetPdf<Estimate>(objEstimateFound); if (EstimatePdfByteArray != null) { //This is for unique name format like-"ESTIMATE-148-11_05_2019_114648". var CurrentDate = DateTime.Now; var FileName = string.Format("{0}-{1}-{2}_{3}{4}{5}{6}", "ESTIMATE", EstimateID, CurrentDate.ToString("MM/dd/yyyy"), CurrentDate.ToString("HH"), CurrentDate.ToString("mm"), CurrentDate.ToString("ss"), ".pdf"); return File(EstimatePdfByteArray, "application/pdf", FileName); } } return null; } catch (IdsException ex) { return null; } catch (Exception ex) { return null; } }
You can set a download link in the list view of the estimate. if you don’t know how to get estimates from Quickbooks Online you can find it here.
@model List<Intuit.Ipp.Data.Estimate> @{ ViewBag.Title = "GetAllEstimate"; } <h2>Quickbooks online Estimate List</h2> <div> <table class="table table-bordered"> <tr> <th>QBO ID</th> <th>Estimate Number</th> <th>Due Date</th> <th>Customer</th> <th>Total Amount</th> <th style="text-align:center;">Download</th> </tr> @foreach (var item in Model) { <tr> <td>@item.Id</td> <td>@item.DocNumber</td> <td>@item.TxnDate.ToString("MM/dd/yyyy")</td> <td>@item.CustomerRef.name</td> <td>@item.TotalAmt</td> <td style="text-align:center;"><a href="@Url.Action("GetEstimatePdfById", "Home", new { EstimateID = item.Id })" target="_blank"><img src="~/Content/Images/downloadICON.png" height="25" width="25" /></a></td> </tr> } </table> </div>
OUTPUT:
In this article, we have to show Create and Used PIPE in angular
In this article, we have to show Create and Used PIPE in angular
In this article, we have to show Create and Used PIPE in angular