Invoicing

qbo/docs/concepts/building-app-video23.jpg https://www.youtube.com/embed/HKFmulAj7tA?rel=0

How To Create An Invoice In QuickBooks

December 14, 2017

2:30

An invoice is a document that a business provides to its customers containing a list of goods and services, along with a statement of their cost for payment later. The list is organized as a series of lines. Invoices are required for sales made on credit. In other words, if a customer does not pay the business at the time of the sale then the business needs to keep track of what is owed to ensure a future payment is received at a later date. Invoices help businesses to manage their accounts receivable. Accounts receivable is the outstanding balance that is owed to a business by its customers.
Lines

Line items, or simply,lines in an Invoice represent individual line items of a transaction. Line items are used to provide customers an itemized description of the services provided and charges associated with it.

TYPE DESCRIPTION
Sale item This line type is used in two different contexts. - As a general sales line item, it holds information for a sales item, including the amount. - As an overarching transaction line, it holds shipping charges.
Group item Group items that are often sold together into bundles so they can be added all at once to a transaction.
Description only Holds annotation information. There is no amount or other data associated with this type of line.
Discount only Holds the discount applied to the entire transaction. The Sales Form Discounts company preference must be enabled for this type of line to be available.
Subtotal lines Holds the subtotal of all lines.
Items

Items are things that the business buys, sells, or re-sells, such as products and services. An item is shown as a line on an invoice or other sales form. Based on how the item is used, it has one of the following values:

TYPE DESCRIPTION
Inventory Used in transactions to track merchandise that your business purchases, stocks, and re-sells as inventory. QuickBooks tracks the current number of inventory items in stock, cost of goods sold, and the asses value of the inventory after the purchase and sale of every item.
Non-inventory Used for goods you buy but don’t track, like office supplies. Used in transactions for goods and materials for a specific job that you charge back to the customer and don’t track yourself.
Service Used in transactions to track services that you charge on the purchase. For example, specialized labor, consulting hours, and professional fees.
Bundle/Group

Used as a container for a bundle of items with a count for each items. For example, a Gift Basket with 2 apples, 5 pencils and 1 stack of paper. The bundle is the Gift Basket, the bundle items are apples, pencils, and paper.

  • Bundles can not contain other bundles.
  • Bundles can not contain categories.
  • An item can be listed more than once with same or different quantities.
  • Bundles can be added to transactions.
Customer

In QuickBooks Online, a customer is anyone who pays the business for goods or services.

qbo/docs/concepts/building-app-video23.jpg https://www.youtube.com/embed/FKaO7YjRSAE?rel=0

Adding Customers

August 22, 2017

1:51

Managing invoice and automated sales tax

As of November 10, 2017, all new US QuickBooks Online companies manage sales tax calculations via an automated sales tax (AST) engine. Sales tax is computed automatically on the sales transaction based upon the shipping address and the location of the company rather assigning sales tax manually. Read more about how QuickBooks Online implements automated sales tax here

Step by Step Guide
  1. Add a new customer
  2. Add a new Service item and set the Income Account i.e. where the payments for the services will be received
  3. Create an invoice that holds information for the amount charged for this service i.e. Sales Line Item details Invoice
  4. Send your customer an email with this invoice
  5. Create a linked transaction to make payment for this invoice
How to implement

.NET

Java

PHP

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/// <summary>
        /// This routine creates an Invoice object
        /// </summary>
        private void CreateInvoice()
        {
/// Step 1: Initialize OAuth2RequestValidator and ServiceContext
        OAuth2RequestValidator ouathValidator = new OAuth2RequestValidator(
            (string)Application["accessToken"]);
        ServiceContext serviceContext = new ServiceContext(
            (string)Application["realmId"],
            IntuitServicesType.QBO, ouathValidator);
/// Step 2: Initialize an Invoice object
        Invoice invoice = new Invoice();
        invoice.Deposit = new Decimal(0.00);
        invoice.DepositSpecified = true;

/// Step 3: Invoice is always created for a customer, so retrieve reference to a customer and set it in Invoice
        QueryService<Customer> querySvc =
            new QueryService<Customer>(serviceContext);
        Customer customer = querySvc.ExecuteIdsQuery
            ("SELECT * FROM Customer WHERE CompanyName like 'Amy%'").
            FirstOrDefault();
        invoice.CustomerRef = new ReferenceType()
        {
            Value = customer.Id
        };

/// Step 4: Invoice is always created for an item so the retrieve reference to an item and create a Line item to the invoice
        QueryService<Item> querySvcItem =
            new QueryService<Item>(serviceContext);
        Item item = querySvcItem.ExecuteIdsQuery(
            "SELECT * FROM Item WHERE Name = 'Lighting'");FirstOrDefault();
        List<Line> lineList = new List<Line>();
        Line line = new line();
        line.Description = "Description";
        line.Amount = new Decimal(100.00);
        line.AmountSpecified = true;
        lineList.Add(line);
        invoice.Line = lineList.ToArray();

        SalesItemLineDetail salesItemLineDeatil = new SalesItemLineDetail();
        salesItemLineDetail.Qty = new Decimal(1.0);
        salesItemLineDeatil.ItemRef = new ReferenceType
        {
            Value = item.Id
        };
        line.AnyIntuitObject = salesItemLineDetail;

        line.DetailType = LineDetailTypeEnum.SalesItemLineDetail;
        line.DetailTypeSpecified = true;

/// Step 5: Set other properties such as total amount, due date, email status, and transaction date
      invoice.DueDate = Datetime.UtcNow.Date;
      invoice.DueDateSpecified = true;

      invoice.TotalAmt = new Decimal(10.00);
      invoice.TotalAmtSpecified = true;

      invoice.EmailStatus = EmailStatusEnums.NotSet;
      invoice.EmailStatusSpecified = true;

      invoice.Balance = new Decimal(10.00);
      invoice.BalanceSpecified = true;

      invoice.TxnDate = DateTime.UtcNow.Date;
      invoice.TxnDateSpecified = true;
      invoice.TxnTaxDetail = new TxnTaxDetail()
      {
          TotalTax = Convert.ToDecimal(10),
          TotalTaxSpecified = true
      };

///Step 6: Initialize the service object and create Invoice
    DataService service = new DataService(serviceContext);
    Invoice addedInvoice = service.Add<Invoice>(invoice);
}

Note: Some methods like creating or querying accounts has been omitted for brevity, click here to view the complete code.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
//create oauth object
    OAuth2Authorizer oauth = new OAuth2Authorizer(accessToken);
//create context
    Context context = new Context(oauth, ServiceType.QBO, realmId);
//create DataService
    DataService service = new DataService(context);

//add customer
    Customer customer = new Customer();
    customer.setDisplayName(RandomStringUtils.randomAlphanumeric(6));
    EmailAddress emailAddr = new EmailAddress();
    emailAddr.setAddress("testconceptsample@mailinator.com");
    customer.setPrimaryEmailAddr(emailAddr);
    Customer savedCustomer = service.add(customer);

//add item
    Item item = new Item();
    item.setName("Item" + RandomStringUtils.randomAlphanumeric(5));
    item.setUnitPrice(new BigDecimal("200"));
    item.setType(ItemTypeEnum.SERVICE);
    Account incomeAccount = getIncomeBankAccount(service); //query or income account
    item.setIncomeAccountRef(createRef(incomeAccount));
    Item savedItem = service.add(item);

//create invoice using customer and item created above
    Invoice invoice = new Invoice();
    invoice.setCustomerRef(createRef(savedCustomer));
    Line line1 = new Line();
    line1.setAmount(new BigDecimal("300.00"));
    line1.setDetailType(LineDetailTypeEnum.SALES_ITEM_LINE_DETAIL);
    SalesItemLineDetail salesItemLineDetail1 = new SalesItemLineDetail();
    salesItemLineDetail1.setItemRef(createRef(savedItem));
    line1.setSalesItemLineDetail(salesItemLineDetail1);
    List<Line> lines1 = new ArrayList<>();
    lines1.add(line1);
    invoice.setLine(lines1);
    Invoice savedInvoice = service.add(invoice);

//send invoice email to customer
    service.sendEmail(savedInvoice, customer.getPrimaryEmailAddr().getAddress());

//receive payment for the invoice
    Payment payment = new Payment();
    payment.setCustomerRef(createRef(customer));
    payment.setTotalAmt(invoice.getTotalAmt());
    List<LinkedTxn> linkedTxnList = new ArrayList<LinkedTxn>();
    LinkedTxn linkedTxn = new LinkedTxn();
    linkedTxn.setTxnId(savedInvoice.getId());
    linkedTxn.setTxnType(TxnTypeEnum.TxnTypeEnum.INVOICE.value());
    linkedTxnList.add(linkedTxn);
    Line line1 = new Line();
    line1.setAmount(invoice.getTotalAmt());
    line1.setLinkedTxn(linkedTxnList);
    List<Line> lineList = new ArrayList<Line>();
    lineList.add(line1);
    payment.setLine(lineList);
    service.add(payment);

Note: Some methods like creating or querying accounts has been omitted for brevity, click here to view the complete code.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<?php
//create dataservice
    $dataService->updateOAuth2Token($accessToken);

//add customer
    $customerRequestObj = Customer::create(["DisplayName" => $customerName . getGUID()]);
    $customerRequestObj = $dataService->Add($customerRequestObj);

//add item
    $ItemObj = Item::create([
    "Name" => $itemName,
    "UnitPrice" => 25,
    "Type" => "Service",
    "IncomeAccountRef"=> ["value"=>  $incomeAccount->Id]
    ]);
    $resultingItemObj = $dataService->Add($ItemObj);

//create invoice using customer and item created above
    $invoiceObj = Invoice::create([
    "CustomerRef" => ["value" => $customerRequestObj>Id],
    "BillEmail" => ["Address" => "author@intuit.com"],
    "Line" => [
        "Amount" => 100.00,
        "DetailType" => "SalesItemLineDetail",
        "SalesItemLineDetail" => [
            "Qty" => 2,
            "ItemRef" => ["value" => $resultingItemObj>Id]
        ]

    ]);
    $resultingInvoiceObj = $dataService->Add($invoiceObj);

//send invoice email to customer
    $resultingMailObj = $dataService->sendEmail($resultingInvoiceObj,$resultingInvoiceObj->BillEmail->Address);

//receive payment for the invoice
    $paymentObj = Payment::create([
       "CustomerRef" => ["value" => $customerRequestObj>Id],
       "TotalAmt" => 100.00,
       "Line" => [
          "Amount" => 100.00,
          "LinkedTxn" => ["TxnId" => $invoiceId,"TxnType" => "Invoice"]
       ]
    ]);
    $dataService->Add($paymentObj);
 ?>

Note: Some methods like creating or querying accounts has been omitted for brevity, click here to view the complete code.

What’s next