In this blog, I will explain how to send an invoice from .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.
An invoice will be sent to the email. if the email address already exists then it will be sent to this email else we have to give a particular email on which we have to send an invoice. or you can also give a particular email on which you want to send an invoice.
Below are a few steps to send an invoice,
public ActionResult SendInvoiceById(string InvoiceID) { 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_INVOICE_QUERYBYID = string.Format("select * from Invoice where id = '{0}'", InvoiceID); var queryService = new QueryService<Invoice>(serviceContext); Invoice objInvoiceFound = queryService.ExecuteIdsQuery(EXISTING_INVOICE_QUERYBYID).FirstOrDefault<Invoice>(); //If Invoice found on Quickbooks online if (objInvoiceFound != null) { DataService dataService = new DataService(serviceContext); if (objInvoiceFound.BillEmail != null) { var SentPDF = dataService.SendEmail<Invoice>(objInvoiceFound); ViewBag.IsSuccess = true; } else { //if you want to then, you can set ToEmail from database or somewhere else String ToEmail = "tabishzrangrej.vision@gmail.com"; var SentPDF = dataService.SendEmail<Invoice>(objInvoiceFound, ToEmail); ViewBag.IsSuccess = true; } } return View(); } catch (IdsException ex) { return View(); } catch (Exception ex) { return View(); } }
@{ ViewBag.Title = "SendInvoiceById"; } <h2>Send Invoice By Id</h2> @if (ViewBag.IsSuccess != null && ViewBag.IsSuccess == true) { <div class="row"> <label class="label label-success"> Invoice Sent Successfully </label> </div> }
You can also set a send email link in the list view of the invoice. if you don’t know how to get Invoices from Quickbooks Online you can find it here.
@model List<Intuit.Ipp.Data.Invoice> @{ ViewBag.Title = "GetAllInvoice"; } <h2>Quickbooks online Invoice List</h2> <div> <table class="table table-bordered"> <tr> <th>QBO ID</th> <th>Invoice Number</th> <th>Invoice Date</th> <th>Customer</th> <th>Total Amount</th> <th style="text-align:center;">Download</th> <th style="text-align:center;">Send Email</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("GetInvoicePdfById", "Home", new { InvoiceID = item.Id })" target="_blank"><img src="~/Content/Images/downloadICON.png" height="25" width="25" /></a></td> <td style="text-align:center;"><a href="@Url.Action("SendInvoiceById", "Home", new { InvoiceID = item.Id })" target="_blank"><img src="~/Content/Images/SendImageICON.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