Member Login

Username
Password
Forget Password
New Sign Up
Search Forum

Buy Support
Incidents

If you can't find your answer in the FREE PUBLIC QDeveloper Forum, require URGENT Priority Support, or you need to send us private or confidential information:

Click Here
If you can't login and post questions or you are having trouble viewing forum posts:
Click Here
Callback
Support

If you live in USA, UK, Canada, Australia or New Zealand, you can leave us details on your question and request us to call you back and discuss them with you personally  (charges apply).

Click Here
 
Buy Support
Incidents
If you can't find your answer in the FREE PUBLIC QDeveloper Forum, require URGENT Priority Support, or you need to send us private or confidential information:
Click Here

Forum : Cannot Insert Multiple Invoice Line Items Using AlphaFive V9Search Forum

Forum Home > QODBC - ODBC Driver for QuickBooks > QODBC v9 Forum

 New Topic 
 
 Post Reply 
[1]  
 Cannot Insert Multiple Invoice Line Items Using AlphaFive V9 
 Author   Message 
  James 
  
 Group: Members 
 Posts: 3 
 Joined: 2008-07-05 
 Profile
 Posted : 2008-12-25 15:25:28

The code shown below is designed to enter an invoice with 11 Line Items into QBES V8 using Alpha Five V9. The table  "multi_invoices" is filtered by refnumber 2811 and is sorted so that "Fqsavetocache" is set to 1 for the first 10 records and 0 for the last record. When I run the code I get 11 "Record was created" messages and no errors, but when I look at the invoice in QBES it shows one invoice with 1 line item - the last one in the series.
The following quote is directly from this Forum:

"Multi-line invoices require a series of SQL statements to complete a single invoice. In the example below we are creating a 3 line invoice using 3 SQL INSERT commands in sequence. The key to this process is the field named "FQSaveToCache". This field is not part of the table, but is used as a flag to the QODBC driver. In the sequence below, you should note that the value of "FQSaveToCache" is set to 1 or TRUE for the first two line item insert statements, and then it is set to 0 or FALSE for the final statement.

A TRUE setting of "FQSaveToCache" instructs QODBC to take the values from your INSERT statement and hold them for later processing, but not to save them to QuickBooks yet. When QODBC receives the final transaction where the cache is set to 0 or FALSE, the contents of the current INSERT statement will be combined with all of the previous INSERT statements held in the cache for this connection, and saved as a batch into QuickBooks."

It seems to me that my code adheres to the method described above
I would really appreciate it if someone could please show me what I'm doing wrong here.

THANKS
JAS

code = UI_YES_NO+UI_ATTENTION_SYMBOL + UI_SECOND_BUTTON_DEFAULT
result = ui_msg_box("","This action will EXPORT ALL OPEN INVOICES TO QBES. CONTINUE?",code)
IF result = UI_NO_SELECTED THEN
 goto finish2
 end
END IF

Dim Shared  vCustomerreflistid as C
Dim Shared  vCustomerreffullname as C
Dim Shared  vTxndate as D
Dim Shared  vRefnumber as C
Dim Shared  vBilladdressaddr1 as C
Dim Shared  vBilladdressaddr2 as C
Dim Shared  vBilladdressaddr3 as C
Dim Shared  vBilladdressaddr4 as C
Dim Shared  vBilladdressaddr5 as C
Dim Shared  vBilladdresscity as C
Dim Shared  vBilladdressstate as C
Dim Shared  vBilladdresspostalcode as C
Dim Shared  vBilladdresscountry as C
Dim Shared  vShipaddressaddr1 as C
Dim Shared  vShipaddressaddr2 as C
Dim Shared  vShipaddressaddr3 as C
Dim Shared  vShipaddressaddr4 as C
Dim Shared  vShipaddressaddr5 as C
Dim Shared  vShipaddresscity as C
Dim Shared  vShipaddressstate as C
Dim Shared  vShipaddresspostalcode as C
Dim Shared  vShipaddresscountry as C
Dim Shared  vInvoicelineitemreflistid as C
Dim Shared  vInvoicelineitemreffullname as C
Dim Shared  vInvoicelinedesc as C
Dim Shared  vInvoicelinequantity as N
Dim Shared  vInvoicelinerate as N
Dim Shared  vInvoicelineamount as N
Dim Shared  vFqsavetocache as N
dim total_records as N
dim iterations as N = 0

dim t as p
t=table.open("multi_invoices")
query.order="Txnid+Cache_order"
query.filter="refnumber=\"2811\""
indx=t.query_create()
total_records =indx.records_get()
t.fetch_first()
WHILE .not. t.fetch_eof()
 iterations = iterations + 1
 statusbar.SET_text("Working - records processed: " + alltrim(str(iterations,5,0))+" of"+alltrim(str(total_records,5,0)))

 vCustomerreflistid = t.CUSTOMERMSGREFLISTID
 vCustomerreffullname  = t.CUSTOMERREFFULLNAME
 vTxndate  = t.TXNDATE
 vRefnumber  = t.REFNUMBER
 vBilladdressaddr1  = t.BILLADDRESSADDR1
 vBilladdressaddr2  = t.BILLADDRESSADDR2
 vBilladdressaddr3  = t.BILLADDRESSADDR3
 vBilladdressaddr4  = t.BILLADDRESSADDR4
 vBilladdressaddr5  = t.BILLADDRESSADDR5
 vBilladdresscity  = t.Billaddresscity
 vBilladdressstate  = t.Billaddressstate
 vBilladdresspostalcode  = t.Billaddresspostalcode
 vBilladdresscountry  = t.Billaddresscountry
 vShipaddressaddr1  = t.SHIPADDRESSADDR1
 vShipaddressaddr2  = t.SHIPADDRESSADDR2
 vShipaddressaddr3  = t.SHIPADDRESSADDR3
 vShipaddressaddr4  = t.SHIPADDRESSADDR4
 vShipaddressaddr5  = t.SHIPADDRESSADDR5
 vShipaddresscity  = t.Shipaddresscity
 vShipaddressstate  = t.Shipaddressstate
 vShipaddresspostalcode  = t.Shipaddresspostalcode
 vShipaddresscountry  = t.Shipaddresscountry
 vInvoicelineitemreflistid  = t.Invoicelineitemreflistid
 vInvoicelineitemreffullname  = t.Invoicelineitemreffullname
 vInvoicelinedesc  = t.Invoicelinedesc
 vInvoicelinequantity  = t.Invoicelinequantity
 vInvoicelinerate  = t.Invoicelinerate
 vInvoicelineamount  = t.Invoicelineamount
 vFqsavetocache  = t.FQSAVETOCACHE
  
 'Insert a new record into a remote SQL database.
 'DIM a connection variable
 DIM cn as SQL::Connection
 dim flagResult as l
 flagResult = cn.open("::Name::QB_Test")
 IF flagResult = .f. THEN
  ui_msg_box("Error","Could not connect to database. Error reported was: " + crlf() + cn.CallResult.text)
  end
 END IF
 
 'Specify that we are using Portable SQL syntax
 cn.PortableSQLEnabled = .t.
 
 'Dim a SQL arguments object, create arguments and set their values
 DIM args as sql::arguments
 
 IF a5_eval_valid_expression("=Var->vCustomerreflistid",local_variables()) THEN
  args.add("CustomerRefListID",convert_type(a5_eval_expression("=Var->vCustomerreflistid",local_variables()),"C"))
 END IF
 IF a5_eval_valid_expression("=Var->vCustomerreffullname",local_variables()) THEN
  args.add("CustomerRefFullName",convert_type(a5_eval_expression("=Var->vCustomerreffullname",local_variables()),"C"))
 END IF
 IF a5_eval_valid_expression("=Var->vTxndate",local_variables()) THEN
  args.add("TxnDate",convert_type(a5_eval_expression("=Var->vTxndate",local_variables()),"D"))
 END IF
 IF a5_eval_valid_expression("=Var->vRefnumber",local_variables()) THEN
  args.add("RefNumber",convert_type(a5_eval_expression("=Var->vRefnumber",local_variables()),"C"))
 END IF
 IF a5_eval_valid_expression("=Var->vBilladdressaddr1",local_variables()) THEN
  args.add("BillAddressAddr1",convert_type(a5_eval_expression("=Var->vBilladdressaddr1",local_variables()),"C"))
 END IF
 IF a5_eval_valid_expression("=Var->vBilladdressaddr2",local_variables()) THEN
  args.add("BillAddressAddr2",convert_type(a5_eval_expression("=Var->vBilladdressaddr2",local_variables()),"C"))
 END IF
 IF a5_eval_valid_expression("=Var->vBilladdressaddr3",local_variables()) THEN
  args.add("BillAddressAddr3",convert_type(a5_eval_expression("=Var->vBilladdressaddr3",local_variables()),"C"))
 END IF
 IF a5_eval_valid_expression("=Var->vBilladdressaddr4",local_variables()) THEN
  args.add("BillAddressAddr4",convert_type(a5_eval_expression("=Var->vBilladdressaddr4",local_variables()),"C"))
 END IF
 IF a5_eval_valid_expression("=Var->vBilladdressaddr5",local_variables()) THEN
  args.add("BillAddressAddr5",convert_type(a5_eval_expression("=Var->vBilladdressaddr5",local_variables()),"C"))
 END IF
 IF a5_eval_valid_expression("=Var->vBilladdresscity",local_variables()) THEN
  args.add("BillAddressCity",convert_type(a5_eval_expression("=Var->vBilladdresscity",local_variables()),"C"))
 END IF
 IF a5_eval_valid_expression("=Var->vBilladdressstate",local_variables()) THEN
  args.add("BillAddressState",convert_type(a5_eval_expression("=Var->vBilladdressstate",local_variables()),"C"))
 END IF
 IF a5_eval_valid_expression("=Var->vBilladdresspostalcode",local_variables()) THEN
  args.add("BillAddressPostalCode",convert_type(a5_eval_expression("=Var->vBilladdresspostalcode",local_variables()),"C"))
 END IF
 IF a5_eval_valid_expression("=Var->vBilladdresscountry",local_variables()) THEN
  args.add("BillAddressCountry",convert_type(a5_eval_expression("=Var->vBilladdresscountry",local_variables()),"C"))
 END IF
 IF a5_eval_valid_expression("=Var->vShipaddressaddr1",local_variables()) THEN
  args.add("ShipAddressAddr1",convert_type(a5_eval_expression("=Var->vShipaddressaddr1",local_variables()),"C"))
 END IF
 IF a5_eval_valid_expression("=Var->vShipaddressaddr2",local_variables()) THEN
  args.add("ShipAddressAddr2",convert_type(a5_eval_expression("=Var->vShipaddressaddr2",local_variables()),"C"))
 END IF
 IF a5_eval_valid_expression("=Var->vShipaddressaddr3",local_variables()) THEN
  args.add("ShipAddressAddr3",convert_type(a5_eval_expression("=Var->vShipaddressaddr3",local_variables()),"C"))
 END IF
 IF a5_eval_valid_expression("=Var->vShipaddressaddr4",local_variables()) THEN
  args.add("ShipAddressAddr4",convert_type(a5_eval_expression("=Var->vShipaddressaddr4",local_variables()),"C"))
 END IF
 IF a5_eval_valid_expression("=Var->vShipaddressaddr5",local_variables()) THEN
  args.add("ShipAddressAddr5",convert_type(a5_eval_expression("=Var->vShipaddressaddr5",local_variables()),"C"))
 END IF
 IF a5_eval_valid_expression("=Var->vShipaddresscity",local_variables()) THEN
  args.add("ShipAddressCity",convert_type(a5_eval_expression("=Var->vShipaddresscity",local_variables()),"C"))
 END IF
 IF a5_eval_valid_expression("=Var->vShipaddressstate",local_variables()) THEN
  args.add("ShipAddressState",convert_type(a5_eval_expression("=Var->vShipaddressstate",local_variables()),"C"))
 END IF
 IF a5_eval_valid_expression("=Var->vShipaddresspostalcode",local_variables()) THEN
  args.add("ShipAddressPostalCode",convert_type(a5_eval_expression("=Var->vShipaddresspostalcode",local_variables()),"C"))
 END IF
 IF a5_eval_valid_expression("=Var->vShipaddresscountry",local_variables()) THEN
  args.add("ShipAddressCountry",convert_type(a5_eval_expression("=Var->vShipaddresscountry",local_variables()),"C"))
 END IF
 IF a5_eval_valid_expression("=Var->vInvoicelineitemreflistid",local_variables()) THEN
  args.add("InvoiceLineItemRefListID",convert_type(a5_eval_expression("=Var->vInvoicelineitemreflistid",local_variables()),"C"))
 END IF
 IF a5_eval_valid_expression("=Var->vInvoicelineitemreffullname",local_variables()) THEN
  args.add("InvoiceLineItemRefFullName",convert_type(a5_eval_expression("=Var->vInvoicelineitemreffullname",local_variables()),"C"))
 END IF
 IF a5_eval_valid_expression("=Var->vInvoicelinedesc",local_variables()) THEN
  args.add("InvoiceLineDesc",convert_type(a5_eval_expression("=Var->vInvoicelinedesc",local_variables()),"M"))
 END IF
 IF a5_eval_valid_expression("=Var->vInvoicelinequantity",local_variables()) THEN
  args.add("InvoiceLineQuantity",convert_type(a5_eval_expression("=Var->vInvoicelinequantity",local_variables()),"N"))
 END IF
 IF a5_eval_valid_expression("=Var->vInvoicelinerate",local_variables()) THEN
  args.add("InvoiceLineRate",convert_type(a5_eval_expression("=Var->vInvoicelinerate",local_variables()),"N"))
 END IF
 IF a5_eval_valid_expression("=Var->vInvoicelineamount",local_variables()) THEN
  args.add("InvoiceLineAmount",convert_type(a5_eval_expression("=Var->vInvoicelineamount",local_variables()),"N"))
 END IF
 IF a5_eval_valid_expression("=Var->vFqsavetocache",local_variables()) THEN
  args.add("FQSaveToCache",convert_type(a5_eval_expression("=Var->vFqsavetocache",local_variables()),"N"))
 END IF
 
 
 dim sqlInsertStatement as c
 sqlInsertStatement = <<%txt%
INSERT INTO InvoiceLine  (CustomerRefListID, CustomerRefFullName, TxnDate, RefNumber, BillAddressAddr1, BillAddressAddr2, BillAddressAddr3, BillAddressAddr4, BillAddressAddr5, BillAddressCity, BillAddressState, BillAddressPostalCode, BillAddressCountry, ShipAddressAddr1, ShipAddressAddr2, ShipAddressAddr3, ShipAddressAddr4, ShipAddressAddr5, ShipAddressCity, ShipAddressState, ShipAddressPostalCode, ShipAddressCountry, Invoicelineitemreflistid, Invoicelineitemreffullname,InvoiceLineDesc, InvoiceLineQuantity, InvoiceLineRate, InvoiceLineAmount, FQSaveToCache) VALUES (:CustomerRefListID, :CustomerRefFullName, :TxnDate, :RefNumber, :BillAddressAddr1, :BillAddressAddr2, :BillAddressAddr3, :BillAddressAddr4, :BillAddressAddr5, :BillAddressCity, :BillAddressState, :BillAddressPostalCode, :BillAddressCountry, :ShipAddressAddr1, :ShipAddressAddr2, :ShipAddressAddr3, :ShipAddressAddr4, :ShipAddressAddr5, :ShipAddressCity, :ShipAddressState, :ShipAddressPostalCode, :ShipAddressCountry, :Invoicelineitemreflistid, :Invoicelineitemreffullname, :InvoiceLineDesc, :InvoiceLineQuantity, :InvoiceLineRate, :InvoiceLineAmount, :FQSaveToCache)
%txt%
 dim flag as l
 flag = cn.Execute(sqlInsertStatement,args)

 IF flag = .f. THEN
  ui_msg_box("Error","Record was not inserted. Error reported was: " + crlf(2) + cn.CallResult.text,UI_STOP_SYMBOL)
 ELSE
  IF cn.AffectedRows() = 1 THEN
   'ui_msg_box("Notice","Record was created.",UI_INFORMATION_SYMBOL)
  ELSE
   ui_msg_box("Error","Record was not inserted." ,UI_STOP_SYMBOL)
  END IF
 END IF
 
 'Now, close the connection
 cn.close()
 t.fetch_next()
END WHILE
finish:
indx.drop()
t.close()
ui_msg_box("","Operation Complete!")

END
finish2:

ui_msg_box("","Operation Cancelled!")[/CODE]

 

  Top 
  Tom 
  6c3c1_sdk-qodbc.gif
 Group: Administrator 
 Posts: 5510 
 Joined: 2006-02-17 
 Profile
 Posted : 2008-12-26 10:41:30
Your code clearly opens the connection to QB_Test within the WHILE loop for each line. Just open the connection to QB_Test and leave it open until the end. 

  Top 
  James 
  
 Group: Members 
 Posts: 3 
 Joined: 2008-07-05 
 Profile
 Posted : 2008-12-26 14:12:55

Thanks Tom:

I figured that out about 3:00 this afternoon. I went back and read and kept reading your instructions for inserting multiple line items over and over to make absolutely sure I wasn't misssing something when finally I realised you were talking about a single connection. So I rearranged the code to utilize a single connection for each invoice and to enter just the line item information for all but the last item.  It worked of course. I'm ashamed to tell you how many hours I've wasted just because I did not focus on the details when first reading your instructions!

Anyway, thanks for the prompt reply. The Forum is an invaluable resource.

I'd like to wish you and those important to you a very Happy and Healthy Holiday Season and New Year!

Jim

 

  Top 
 New Topic 
 
 Post Reply 
[1]  

Jump to