Requests and responses for sales receipts

The SDK has supported the ability to add sales receipts since the release of qbXML 1.0. Some key sales receipt features were added a little more recently, such as the ability to support credit card transactions (4.1) and the ability to modify sales receipts (5.0). This chapter provides information on using the sales receipt features in the SDK: namely how to add, modify, query, void, and delete sales receipts.

Adding a sales receipt in the UI

In the UI, you add a sales receipt by clicking on the Create Sales Receipts icon in the main QuickBooks navigator. This displays the Enter Sales Receipts form shown below:

../../../../_images/Image_335.jpg

If you compare the form with the API Reference page for SalesReceiptAddRq, most of what you see in the UI has easily identifiable counterparts in the request’s tags. Some of the less obvious UI-to-tag mappings are circled in the following excerpt from the API Reference and labeled with the corresponding tag name in the reference. These are mainly tax-related.

The reference page is quite lengthy, so we’ve broken it up in the following figures and provided some general commentary on each of these smaller pieces.

../../../../_images/Image_336.jpg

In the above excerpt, notice the customer Ref, the BillAddress aggregate, and the ShipAddress aggregate. If the customer has already been set up in QuickBooks with a billing address and a default shipping address, you can simply supply the customer Ref and omit the Bill and Ship Address. That information will be automatically added to the SalesReceipt from the referenced customer, and the Bill/Ship addresses will be returned in the SalesReceiptAdd response, unless you use IncludeRetElement to limit data returns.

Also notice the ClassRef. If you use classes to track categories of sales (for example, tracking transactions by departments), you need to set up your classes first, then reference the class that you want this sales receipt to be tracked under. This ClassRef is the transaction-level ClassRef. If you also want to track the individual line items in the transaction, you also need to specify the ClassRef at the line item level, as shown later. Notice that even if Class tracking is turned off in in a company’s Accounting preferences, the ClassRef data for the SalesReceipt transaction will be saved: the class data simply won’t be visible in QuickBooks unless class tracking is turned on in preferences.

You can add a TemplateRef if you want to use an existing template containing your customizations to the Sales Receipt form. Notice that the SDK does not enable you to change the template “on the fly” to show a different set of fields, columns, etc.

Finally, notice the TxnDate and RefNumber tags. If you omit the TxnDate tag, the current date is used for the transaction date. If you omit the RefNumber tag, QuickBooks will supply the reference number for you.

Let’s scroll down a bit more in to see more details of the reference page.

../../../../_images/Image_337.jpg

Notice the IsPending tag. You can set this to true if you want to keep the transaction from posting if you don’t want to finalize the sale for some reason, such as incomplete sale or for estimates. However, there are usually other preferable ways to support these kinds of activities, such as Estimates, SalesOrders and so forth. The default is false so you normally just omit this tag.

You should supply the PaymentMethodRef to indicate the method of payment. If you use the CreditCardTxnInfo aggregate and its sub-aggregates, you must specify the PaymentMethodRef to indicate the credit card type used.

The CheckNumber tag is used if you select Check as your payment method. The SDK (or the UI) won’t prevent you from specifying this even if you select other payment methods but this can confuse your customer. This value will show up in the UI in the Check Number text box.

DueDate is another tag like IsPending that supports the use of sales receipts in the unusual case where the transaction is non posting. Normally you wouldn’t use this tag.

The SalesRepRef tag can be supplied if you use Sales Reps. The data is visible in the SalesReceipt only if the template used for Sales Receipts has the Rep field turned on. This tag is tricky if you use FullNames in the ref. You can only supply a 5 character value: so if you try to supply a larger number, say “John Martin”, the request will fail validation at the parser level. If you supply simply “John” it will also fail. What you need to do in nearly all cases is to make sure the Sales Rep is created with initials and use those initials within the FullName tag for the SalesRepRef. (If you do a SalesRepQuery, those initials are returned in the response in the Initial tag.)

The ShipDate tag is automatically added with the current date when the SalesReceipt is created, whether you actually do any shipping or even if the customer has no shipping address. So you normally don’t need to supply this tag. However, if you need to indicate some other date for some reason, you can supply that date in this tag.

The ItemSalesTaxRef tag specifies the already set-up sales tax item that is to be applied to each taxable item in the sales receipt. This sales tax item already added in QuickBooks contains a single sales tax rate that applied to the items and it contains pay-to information (the agency to which the tax is paid.) Remember that the tax status specified in the CustomerSalesTaxCodeRef overrides the other tax settings in the SalesReceipt.

Notice the IsToBePrinted tag, corresponding to the “To be printed” checkbox in the UI. Notice also that the SDK currently does not support the “To be emailed” feature that the UI supports.

The CustomerSalesTaxCodeRef tag specifies the customer-related tax code that governs the sales tax on this transaction. The QuickBooks default codes are Tax and Non (tax), with Tax allowing any taxes specified in the other tax refs to be calculated and charged, and Non suspending any such taxes. This is a customer-related tax setting because it hinges on the customer’s tax status. For example, customers who are government agencies are usually Non taxable.

The DepositToAccountRef tag species the QuickBooks account that receives the funds from this transaction. Undeposited Funds is the default account and is normally used. Notice that if you don’t specify an account using the DepositToAccountRef tag the default is automatically used. It is probably a good practice to specify accounts, however, wherever you have the opportunity to do so.

The next excerpt from the reference page shows the tag listings for including credit card data in the SalesReceipt.

../../../../_images/Image_338.jpg

You cannot use the optional CreditCardTxnInfo aggregate unless the company is currently subscribed to the QuickBooks Merchant Service (QBMS) and has a valid Merchant account. If the company hasn’t been set up with QBMS, you’ll get a runtime error when you send a SalesReceiptAdd request containing this aggregate. How can you determine this with the SDK? Simply do a company query and check the SubscribedServices aggregate for the QBMS service.

If you do supply the CreditCardTxnInputInfo aggregate, you must supply the CreditCardTxnResultInfo and the CreditCardTxnInfo sub aggregates along with all their required elements, as shown in the API Reference. Notice that the CreditCardTxnType usually has the value Charge for a SalesReceipt, but VoiceAuthorization and Refund are also supported.

The InputInfo subaggregate is the data from the originating qbmsXML request that effected the credit card transaction. The ResultInfo subaggregate is the qbmsXML response to that request. You include all of this data in the SalesReceipt request if you want to save that QBMS transaction data within QuickBooks. For more information, see the Developer’s Guide for QuickBooks Merchant Services.

The CreditCardTxnInfo cannot be modified in the SalesReceipt, which is why that aggregate isn’t listed in the API Reference for SalesReceiptMod.

If the original QBMS transaction was a qbmsXML 2.0 or greater request, and the qbXML spec level of your SalesReceiptAdd request is 6.0 or greater, the credit card number must be masked, that is, all X, except for the last 4 digits.

Notice that including the QBMS transaction data in the request does not result in any interactions with QBMS or in any attempts to connect to QBMS.

The next excerpt shows the tags for the line items in the SalesReceipt.

../../../../_images/Image_339.jpg

Each line item to be added in the SalesReceipt is added under a separate SalesReceiptLineAdd aggregate. Within each SalesReceiptLineAdd aggregate, you must include an ItemRef , which specifies the QuickBooks item, and you must supply the Quantity .

Notice that you don’t have to supply a Rate (any of the available Rate-related tags) or an Amount . The rate is the price of the item and is taken directly from the item in the ItemRef, if the item is set up properly with price data. The Amount is then calculated from the Quantity and the Rate. If you do choose to supply a Rate or an Amount, remember that you can supply one or the other, but not both.

The SalesTaxCodeRef tag allows you to specify whether the line item is taxable or not. You override this value if you set a conflicting value (taxable or not taxable) in the CustomerSalesTaxRef for the entire sales receipt.

The OverrideItemAccountRef tag allows you to specify an account other than the DepositToAccountRef account for a specific line item.

Notice the DataExt tag, which is available for QuickBooks 2006 and later. This tag allows you to specify custom data at the line item level. It provides a tremendous performance enhancement over the former methods of using custom data in SalesReceipts.

For sake of completeness, we show the final set of tags in the API Reference listing for SalesReceiptAdd in the following figure:

../../../../_images/Image_340.jpg
Some expected data may be missing from the response

If the integrated application lacks authorization for sensitive data, that data is not returned in the response to Add, Modify, and Query requests. For example, although an integrated application does not need access to sensitive data permissions for submitting a SalesReceiptAddRq that contains credit card data, that credit card data won’t be returned in the response if the application doesn’t have the required authorization. The QuickBooks administrator can set these permissions in the Integrated Applications preferences in QuickBooks.

Adding a sales receipt in QBFC

The following example shows how to construct the sales receipt in QBFC. The sample takes the shipping address from the customer Ref, and the line item prices from the item Refs. The payment is a credit card payment effected previously with a qbmsXML interaction with QBMS.

 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
77
Public Sub QBFC_AddSalesReceipt()
Dim SessionManager As QBSessionManager Set SessionManager = New QBSessionManager
SessionManager.OpenConnection "", "IDN Add SalesReceipt Sample" SessionManager.BeginSession "",
omDontCare
Dim requestMsgSet As IMsgSetRequest
Set requestMsgSet = SessionManager.CreateMsgSetRequest("US", 5, 0)
' Initialize the message set request's attributes
requestMsgSet.Attributes.OnError = roeStop
' Add the request to the message set request object Dim SalesRecptAdd As ISalesReceiptAdd
Set SalesRecptAdd = requestMsgSet.AppendSalesReceiptAddRq
'Set the properties in the assembly object SalesRecptAdd.CustomerRef
.FullName.setValue ("Jack Williams")
SalesRecptAdd.TemplateRef.FullName.setValue ("Test") SalesRecptAdd.PaymentMethodRef
.FullName.setValue ("Visa")
SalesRecptAdd.SalesRepRef.FullName.setValue ("JM") SalesRecptAdd.ShipMethodRef
.FullName.setValue ("UPS")
SalesRecptAdd.ItemSalesTaxRef.FullName.setValue ("CA State Sales Tax") SalesRecptAdd
.CustomerMsgRef.FullName.setValue
("Thank you for your business.") SalesRecptAdd.DepositToAccountRef
.FullName.setValue ("Undeposited Funds")
‘Add credit card data from prior qbmsXML transaction with QBMS
SalesRecptAdd.CreditCardTxnInfo.CreditCardTxnInputInfo.CreditCardNumber.setValue
("4111111111111111")
SalesRecptAdd.CreditCardTxnInfo.CreditCardTxnInputInfo.ExpirationYear.setValue (2008)
SalesRecptAdd.CreditCardTxnInfo.CreditCardTxnInputInfo.ExpirationMonth.setValue (11)
SalesRecptAdd.CreditCardTxnInfo.CreditCardTxnInputInfo.NameOnCard.setValue ("H. Rezoner")
SalesRecptAdd.CreditCardTxnInfo.CreditCardTxnInputInfo.CreditCardAddress.setValue ("12
West St., Westlands")
SalesRecptAdd.CreditCardTxnInfo.CreditCardTxnInputInfo.CreditCardPostalCode.setValue
("96965")
SalesRecptAdd.CreditCardTxnInfo.CreditCardTxnInputInfo.CreditCardTxnType.setValue
ccttCharge
SalesRecptAdd.CreditCardTxnInfo.CreditCardTxnResultInfo.ResultCode.setValue (0)
SalesRecptAdd.CreditCardTxnInfo.CreditCardTxnResultInfo.ResultMessage.setValue
("STATUS OK")
SalesRecptAdd.CreditCardTxnInfo.CreditCardTxnResultInfo.CreditCardTransID.setValue
("V54A60275101")
SalesRecptAdd.CreditCardTxnInfo.CreditCardTxnResultInfo.MerchantAccountNumber.setValue
("4269281420247209")
SalesRecptAdd.CreditCardTxnInfo.CreditCardTxnResultInfo.AuthorizationCode.setValue
("185PNI")
SalesRecptAdd.CreditCardTxnInfo.CreditCardTxnResultInfo.ReconBatchID.setValue
("420050223 MC 2005-02-23 QBMS 15.0 pre-beta")
SalesRecptAdd.CreditCardTxnInfo.CreditCardTxnResultInfo.PaymentGroupingCode.setValue (4)
SalesRecptAdd.CreditCardTxnInfo.CreditCardTxnResultInfo.PaymentStatus.setValue
(pssCompleted)
SalesRecptAdd.CreditCardTxnInfo.CreditCardTxnResultInfo.TxnAuthorizationTime.setValue
"2005-11-01", False
SalesRecptAdd.CreditCardTxnInfo.CreditCardTxnResultInfo.TxnAuthorizationStamp.setValue
(1109192233)
‘Now add the first line item
Dim SalesRecLineItem As IORSalesReceiptLineAdd Dim SalesRecLineItem2 As IORSalesReceiptLineAdd
Set SalesRecLineItem = SalesRecptAdd.ORSalesReceiptLineAddList.Append
SalesRecLineItem.SalesReceiptLineAdd.ItemRef.FullName.setValue ("Metal Panel Assembly")
SalesRecLineItem.SalesReceiptLineAdd.Desc.setValue ("Metal Panel Assembly")
SalesRecLineItem.SalesReceiptLineAdd.Quantity.setValue (2)
SalesRecLineItem.SalesReceiptLineAdd.SalesTaxCodeRef.FullName.setValue ("Tax")
‘Add the second line item
Set SalesRecLineItem2 = SalesRecptAdd.ORSalesReceiptLineAddList.Append
SalesRecLineItem2.SalesReceiptLineAdd.ItemRef.FullName.setValue ("Screws")
SalesRecLineItem2.SalesReceiptLineAdd.Desc.setValue ("Large package of screws")
SalesRecLineItem2.SalesReceiptLineAdd.Quantity.setValue (6)
SalesRecLineItem2.SalesReceiptLineAdd.SalesTaxCodeRef.FullName.setValue ("Tax")
' Perform the request and obtain a response from QuickBooks Dim responseMsgSet
As IMsgSetResponse
Set responseMsgSet = SessionManager.DoRequests(requestMsgSet)
‘write the response to a file for grins
‘Need to use the Microsoft Scripting Runtime for this bit Dim fname As String
Dim xml As String
xml = requestMsgSet.ToXMLString fname = "XML_output.doc"
Dim fso As New FileSystemObject Dim ts As TextStream
Set ts = fso.CreateTextFile(fname, True) ts.Write (xml)
' Close the session and connection with QuickBooks.
SessionManager.EndSession
SessionManager.CloseConnection

End Sub
Adding a sales receipt in qbXML

The following example shows a SalesReceiptAddRq that uses a credit card payment previously obtained from qbmsXML requests interacting with QBMS. The request contains two line items, one that specifies an Amount and one that doesn’t specify an amount or rate, getting that info automatically from the item.

 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
<!--?xml version="1.0" ?-->
<!--?qbxml version="5.0"?-->
<qbxml>
    <qbxmlmsgsrq onerror="stopOnError">
        <salesreceiptaddrq requestid="0">
            <salesreceiptadd>
                <customerref>
                    <fullname>Kristie Abercrombie</fullname>
                </customerref>
                <templateref>
                    <fullname>Test</fullname>
                </templateref>
                <salesrepref>
                    <fullname>JM</fullname>
                </salesrepref>
                <itemsalestaxref>
                    <fullname>CA State Sales Tax</fullname>
                </itemsalestaxref>
                <customermsgref>
                    <fullname>Thank you for your business.</fullname>
                </customermsgref>
                <creditcardtxninfo>
                    <creditcardtxninputinfo>
                        <creditcardnumber>4111111111111111</creditcardnumber>
                        <expirationmonth>11</expirationmonth>
                        <expirationyear>2008</expirationyear>
                        <nameoncard>Harry Rezoner</nameoncard>
                        <creditcardaddress>12 West St., Westlands</creditcardaddress>
                        <creditcardpostalcode>96965</creditcardpostalcode>
                        <transactionmode>CardNotPresent</transactionmode>
                        <creditcardtxntype>Charge</creditcardtxntype>
                    </creditcardtxninputinfo>
                    <creditcardtxnresultinfo>
                        <resultcode>0
                        <resultmessage>STATUS OK
                        <creditcardtransid>V54A60275101
                        <merchantaccountnumber>4269281420247209
                        <authorizationcode>185PNI</authorizationcode>
                        <reconbatchid>
                          420050223 MC 2005-02-23 QBMS 15.0 pre-beta
                        </reconbatchid>
                        <paymentgroupingcode>4</paymentgroupingcode>
                        <paymentstatus>Completed</paymentstatus>
                        <txnauthorizationtime> 2005-11-01T00:00:00</txnauthorizationtime>
                        <txnauthorizationstamp>1109192233</txnauthorizationstamp>
                    </creditcardtxnresultinfo>
                </creditcardtxninfo>
                <salesreceiptlineadd>
                    <itemref>
                        <fullname>Metal Panel Assembly</fullname>
                    </itemref>
                    <desc>Metal Panel Assembly</desc>
                    <quantity>2</quantity>
                    <amount>120.00</amount>
                    <salestaxcoderef>
                        <fullname>Tax</fullname>
                    </salestaxcoderef>
                </salesreceiptlineadd>
                <salesreceiptlineadd>
                    <itemref>
                        <fullname>Screws</fullname>
                    </itemref>
                    <desc>Large Package of Screws</desc>
                    <quantity>10</quantity>
                    <salestaxcoderef>
                        <fullname>Tax</fullname>
                    </salestaxcoderef>
                </salesreceiptlineadd>
            </salesreceiptadd>
        </salesreceiptaddrq>
    </qbxmlmsgsrq>
</qbxml>
Modifying a sales receipt

The considerations and rules for modifying sales receipts is similar to modifying other transactions. Because you can easily produce undesired results if you aren’t careful, you need to become very familiar with the material on modifying transactions that is provided in Chapter 10, “Modifying and Deleting Transactions and List Objects.” In particular, if you modify any line items or group line items, be sure to follow the instructions on modifying these as described in that chapter.

Special limitations imposed by credit card payment method

If the payment method used in the original aales receipt is a credit card, with the credit card transaction data provided by QBMS via the qbmsXML requests and responses, you cannot change the customer, payment method, or the total transaction amount, including any line item changes that would change the total amount of the transaction.

Which sales receipt fields can be modified?

See the API Reference listing for SalesReceiptMod. This listing contains all the fields that are modifiable.

Which sales receipt fields can be cleared?

The following tables provide lists of the fields in the sales receipt’s main body and sales receipt’s line item fields, respectively, that can be cleared. If a field has a default value, clearing the field results in the use of the default. If there is no default value, clearing simply clears the field. Refer to the API Reference for information on defaults for field values.

SalesReceipt Field Modify Clear Clear behavior
BillingAddress (and its sub-aggregates) Yes Yes Cleared
CheckNumber Yes Yes Cleared
Class Yes Yes Cleared
Customer Yes No  
CustomerMessage Yes Yes Cleared
CustomerSalesTaxCode Yes Yes Cleared
DepositToAccount Yes No  
DueDate Yes No  
FOB Yes Yes Cleared
IsPending Yes No  
IsToBePrinted Yes No  
ItemSalesTax Yes No  
Memo Yes Yes Cleared
PaymentMethod Yes Yes Cleared
RefNumber Yes Yes Cleared
SalesRep Yes Yes Cleared
ShipAddress (and its sub-aggregates) Yes Yes Cleared
ShipDate Yes No  
ShipMethod Yes Yes Cleared
Template Yes No  
TxnDate Yes No  

The following table lists the line item and line item group fields and indicates whether they can be modified or cleared.

Line/Group Line Items Fields in SalesReceipt Modify Clear Clear behavior
Amount Yes No  
Class Yes Yes Cleared
Description Yes Yes Cleared
Item reference Yes No  
OverrideItemAccountRef Yes No  
Quantity Yes No  
Rate/Rate % Yes No  
Sales tax code Yes No  
Service date Yes Yes  
Modifying a sales receipt in qbXML

The next example shows a SalesReceiptMod request that clears the sales rep and memo data in the sales receipt specified, and inserts one line item between the existing two line items in the receipt. (If there were any other line items, they are not specified in this request, so they would be deleted from QuickBooks.)

Notice the use of the -1 in the TxnLineID tag for the new line item. The SDK uses recognizes this value and causes the insertion to be made. You specify the location of the new item within the sales receipt by placing it before or after one of the existing lines in the Mod request.

Constructing a SalesReceiptMod Request in QBXML

 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
<qbxml>
    <qbxmlmsgsrq onerror="stopOnError">
        <salesreceiptmodrq requestid="0">
            <salesreceiptmod>
                <txnid>90-1131042763</txnid>
                <editsequence>1131042763</editsequence>
                <txndate>2005-11-03</txndate>
                <salesrepref>
                    <fullname>
                </fullname></salesrepref>
                <memo>
                <salesreceiptlinemod>
                    <txnlineid>92-1131042763</txnlineid>
                </salesreceiptlinemod>
                <salesreceiptlinemod>
                    <txnlineid>-1</txnlineid>
                    <itemref>
                        <fullname>Metal Panel Assembly</fullname>
                    </itemref>
                    <quantity>2</quantity>
                </salesreceiptlinemod>
                <salesreceiptlinemod>
                    <txnlineid>93-1131042763</txnlineid>
                </salesreceiptlinemod>
            </memo></salesreceiptmod>
        </salesreceiptmodrq>
    </qbxmlmsgsrq>
</qbxml>
Modifying a sales receipt in QBFC

The next example shows a SalesReceiptMod construction where we query for a SalesReceipt by RefNumber range, grab the first one we find, then modify some of the fields in the main body, and then insert a new line item in the sales receipt after the first line. Because the insertion changes the total amount, this request couldn’t be used with sales receipts having a credit card payment method.

Some key things to notice in the sample 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
Public Sub QBFC_ModSalesReceipt()
Dim SessionManager As QBSessionManager Set SessionManager = New QBSessionManager
SessionManager.OpenConnection "", "IDN Mod SalesReceipt Sample" SessionManager.BeginSession ""
, omDontCare
Dim requestMsgSet As IMsgSetRequest
Set requestMsgSet = SessionManager.CreateMsgSetRequest("US", 5, 0) ' Initialize the
message set request's attributes
requestMsgSet.Attributes.OnError = roeStop
'First we query QB for sales receipt transactions within a date range Dim
SalesRecptQuery As ISalesReceiptQuery
Set SalesRecptQuery = requestMsgSet.AppendSalesReceiptQueryRq
'We just want to get the Txn ID and edit sequence so we can do the mod
SalesRecptQuery.IncludeRetElementList.Add ("TxnID")
SalesRecptQuery.IncludeRetElementList.Add ("EditSequence")
SalesRecptQuery.ORTxnQuery.TxnFilter.ORRefNumberFilter.RefNumberRangeFilter.FromRefNumber.
setValue ("23")
Dim responseMsgSet As IMsgSetResponse
Set responseMsgSet = SessionManager.DoRequests(requestMsgSet)
Dim response As IResponse
' Response list contains one response, corresponding to our single request Set
response = responseMsgSet.ResponseList.GetAt(0)
'This is a query, so the response detail is a ret list for sales receipt Dim
SalesRecptRetList As ISalesReceiptRetList
If response.Detail Is Nothing Then MsgBox "No Detail available"
Exit Sub End If
Set SalesRecptRetList = response.Detail
Dim SalesRecptRet As ISalesReceiptRet
'There are potentially many SalesReceipt txns in the retlist: we get the first one
'This is for our convenience: you'll do something
smarter or let the user pick
Set SalesRecptRet = SalesRecptRetList.GetAt(0)
'Save the TxnID: we need it for the followup query Dim TransID As String
TransID = SalesRecptRet.TxnID.getValue
requestMsgSet.ClearRequests
'Get the specific receipt we want complete with all line items Set SalesRecptQuery
 = requestMsgSet.AppendSalesReceiptQueryRq
SalesRecptQuery.ORTxnQuery.TxnIDList.Add (TransID) SalesRecptQuery.IncludeLineItems.setValue (True)
Set responseMsgSet = SessionManager.DoRequests(requestMsgSet)
' Response list contains one response, corresponding to our single request Set response
 = responseMsgSet.ResponseList.GetAt(0)
'Need to get the ret list first
If response.Detail Is Nothing Then MsgBox "No Detail available" Exit Sub
End If
Set SalesRecptRetList = response.Detail
'From this query, we expect only one SalesReceipt txns in the retlist 'Save the receipt:
 we'll need it later for its line item TxnIDs
Set SalesRecptRet = SalesRecptRetList.GetAt(0) requestMsgSet.ClearRequests
' Now build the mod request
Dim SalesRecptMod As ISalesReceiptMod
Set SalesRecptMod = requestMsgSet.AppendSalesReceiptModRq
'Set the properties in the SalesReceipt mod object using data 'from the sales receipt
 we just grabbed in the last query
SalesRecptMod.TxnID.setValue SalesRecptRet.TxnID.getValue
SalesRecptMod.EditSequence.setValue SalesRecptRet.EditSequence.getValue SalesRecptMod
.TxnDate.setValue ("2005-11-03")
SalesRecptMod.Memo.SetEmpty
SalesRecptMod.SalesRepRef.FullName.SetEmpty
Dim SalesRecptModLine As ISalesReceiptLineMod Dim SalesRecptLineRet As IORSalesReceiptLineRet Dim i As Integer
For i = 0 To SalesRecptRet.ORSalesReceiptLineRetList.Count - 1
Set SalesRecptLineRet = SalesRecptRet.ORSalesReceiptLineRetList.GetAt(i) Set SalesRecptModLine =
SalesRecptMod.ORSalesReceiptLineModList.Append.
SalesReceiptLineMod SalesRecptModLine.TxnLineID.setValue SalesRecptLineRet
.SalesReceiptLineRet.TxnLineID.
getValue
If i = 0 Then
Set SalesRecptModLine = SalesRecptMod.ORSalesReceiptLineModList.Append.
SalesReceiptLineMod
SalesRecptModLine.TxnLineID.setValue "-1" SalesRecptModLine.ItemRef
.FullName.setValue "Metal Panel Assembly" SalesRecptModLine.Quantity.setValue 2
End If Next i
' Perform the request and obtain a response from QuickBooks Set responseMsgSet
 = SessionManager.DoRequests(requestMsgSet)
'save full xml response for grins Dim fname As String
Dim xml As String
xml = responseMsgSet.ToXMLString fname = "XML_output.doc"
Dim fso As New FileSystemObject Dim ts As TextStream
Set ts = fso.CreateTextFile(fname, True) ts.Write (xml)
' Close the session and connection with QuickBooks. SessionManager
.EndSession SessionManager.CloseConnection
End Sub
Querying for SalesReceipts

The following example contains two sample queries are provided. The first gets a range of sales receipts, all whose ref number is greater than 23, and specifies that only the TxnID and EditSequence are to be returned. This query works hand-in-hand with the second query, which takes a TxnID and and EditSequence to get a full sales receipt record with all the line items.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
<qbxml>
    <qbxmlmsgsrq onerror="stopOnError">
        <salesreceiptqueryrq requestid="0">
            <refnumberrangefilter>
                <fromrefnumber>23</fromrefnumber>
            </refnumberrangefilter>
            <includeretelement>TxnID</includeretelement>
            <includeretelement>EditSequence</includeretelement>
        </salesreceiptqueryrq>
    </qbxmlmsgsrq>
</qbxml>

<qbxml>
    <qbxmlmsgsrq onerror="stopOnError">
        <salesreceiptqueryrq requestid="0">
            <txnid>90-1131042763
            <includelineitems>1
        </salesreceiptqueryrq>
   </qbxmlmsgsrq>
</qbxml>
Deleting and voiding sales receipts

To delete and void sales receipt transactions, you use TxnDelRq and TxnVoidRq, respectively, as described in Modify, delete, and void requests and responses.

Notice that this deletes any credit card information (CreditCardTxnInfo) in QuickBooks only. This does NOT delete any data at QBMS.