Home › Forums › CoreObjX / DB › Invoice line item with negative rate and amount
This topic contains 2 replies, has 2 voices, and was last updated by Yudel Rosales 11 months, 3 weeks ago.
I need to create an invoice line item with a negative rate/amount. I can do it manually in quickbooks, but I cannot figure out how to do it using CoreObjx.
For example:
iLine = inv.ItemLines.Add();
iLine.Cost = -100;
iLine.Item = “Credit”;
iLine.Description = “Prorated First Invoice”;
This yields an entry in quickbooks with item of “Credit”, quantity blank, Description “Prorated First Invoice”, rate 0.00 and amount 0.00. I can then manually edit the invoice and make the rate -100 as I need it to be.
Bumping this…
Public Class Form1
Inherits System.Windows.Forms.Form
Private qb As New CoreObjX70.QBConnection()
Dim Inv As CoreObjX70.Invoice
#Region ” Windows Form Designer generated code ”
Public Sub New()
MyBase.New()
‘This call is required by the Windows Form Designer.
InitializeComponent()
‘Add any initialization after the InitializeComponent() call
End Sub
‘Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
‘Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
‘NOTE: The following procedure is required by the Windows Form Designer
‘It can be modified using the Windows Form Designer.
‘Do not modify it using the code editor.
Friend WithEvents cmdQuery As System.Windows.Forms.Button
Friend WithEvents cmdAdd As System.Windows.Forms.Button
Friend WithEvents cmdSave As System.Windows.Forms.Button
Friend WithEvents cmdAddLine As System.Windows.Forms.Button
Friend WithEvents Label1 As System.Windows.Forms.Label
Friend WithEvents Label2 As System.Windows.Forms.Label
Friend WithEvents Label3 As System.Windows.Forms.Label
Friend WithEvents lblName As System.Windows.Forms.Label
Friend WithEvents txtInv As System.Windows.Forms.TextBox
Friend WithEvents txtdate As System.Windows.Forms.TextBox
Friend WithEvents cmdExit As System.Windows.Forms.Button
Friend WithEvents Label4 As System.Windows.Forms.Label
Friend WithEvents Label5 As System.Windows.Forms.Label
Friend WithEvents lstInv As System.Windows.Forms.ListBox
Friend WithEvents lstInvLines As System.Windows.Forms.ListBox
Me.cmdQuery = New System.Windows.Forms.Button()
Me.cmdAdd = New System.Windows.Forms.Button()
Me.cmdSave = New System.Windows.Forms.Button()
Me.cmdAddLine = New System.Windows.Forms.Button()
Me.lstInv = New System.Windows.Forms.ListBox()
Me.lstInvLines = New System.Windows.Forms.ListBox()
Me.Label1 = New System.Windows.Forms.Label()
Me.Label2 = New System.Windows.Forms.Label()
Me.Label3 = New System.Windows.Forms.Label()
Me.lblName = New System.Windows.Forms.Label()
Me.txtInv = New System.Windows.Forms.TextBox()
Me.txtdate = New System.Windows.Forms.TextBox()
Me.cmdExit = New System.Windows.Forms.Button()
Me.Label4 = New System.Windows.Forms.Label()
Me.Label5 = New System.Windows.Forms.Label()
Me.SuspendLayout()
‘
‘cmdQuery
‘
Me.cmdQuery.Location = New System.Drawing.Point(8, 40)
Me.cmdQuery.Name = “cmdQuery”
Me.cmdQuery.Size = New System.Drawing.Size(80, 24)
Me.cmdQuery.TabIndex = 0
Me.cmdQuery.Text = “Query”
‘
‘cmdAdd
‘
Me.cmdAdd.Location = New System.Drawing.Point(8, 72)
Me.cmdAdd.Name = “cmdAdd”
Me.cmdAdd.Size = New System.Drawing.Size(80, 24)
Me.cmdAdd.TabIndex = 1
Me.cmdAdd.Text = “Add”
‘
‘cmdSave
‘
Me.cmdSave.Location = New System.Drawing.Point(8, 104)
Me.cmdSave.Name = “cmdSave”
Me.cmdSave.Size = New System.Drawing.Size(80, 24)
Me.cmdSave.TabIndex = 2
Me.cmdSave.Text = “Save”
‘
‘cmdAddLine
‘
Me.cmdAddLine.Location = New System.Drawing.Point(384, 144)
Me.cmdAddLine.Name = “cmdAddLine”
Me.cmdAddLine.Size = New System.Drawing.Size(80, 24)
Me.cmdAddLine.TabIndex = 3
Me.cmdAddLine.Text = “Add Line”
‘
‘lstInv
‘
Me.lstInv.Location = New System.Drawing.Point(112, 40)
Me.lstInv.Name = “lstInv”
Me.lstInv.Size = New System.Drawing.Size(168, 95)
Me.lstInv.TabIndex = 4
‘
‘lstInvLines
‘
Me.lstInvLines.Location = New System.Drawing.Point(112, 144)
Me.lstInvLines.Name = “lstInvLines”
Me.lstInvLines.Size = New System.Drawing.Size(264, 95)
Me.lstInvLines.TabIndex = 5
‘
‘Label1
‘
Me.Label1.Font = New System.Drawing.Font(“Microsoft Sans Serif”, 8.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.Label1.ForeColor = System.Drawing.SystemColors.ActiveCaption
Me.Label1.Location = New System.Drawing.Point(288, 37)
Me.Label1.Name = “Label1”
Me.Label1.Size = New System.Drawing.Size(56, 16)
Me.Label1.TabIndex = 6
Me.Label1.Text = “Customer”
‘
‘Label2
‘
Me.Label2.Location = New System.Drawing.Point(288, 90)
Me.Label2.Name = “Label2”
Me.Label2.Size = New System.Drawing.Size(88, 16)
Me.Label2.TabIndex = 7
Me.Label2.Text = “Invoice #”
‘
‘Label3
‘
Me.Label3.Location = New System.Drawing.Point(288, 114)
Me.Label3.Name = “Label3”
Me.Label3.Size = New System.Drawing.Size(88, 16)
Me.Label3.TabIndex = 8
Me.Label3.Text = “Date”
‘
‘lblName
‘
Me.lblName.Location = New System.Drawing.Point(288, 55)
Me.lblName.Name = “lblName”
Me.lblName.Size = New System.Drawing.Size(192, 32)
Me.lblName.TabIndex = 9
‘
‘txtInv
‘
Me.txtInv.Location = New System.Drawing.Point(344, 90)
Me.txtInv.Name = “txtInv”
Me.txtInv.Size = New System.Drawing.Size(88, 20)
Me.txtInv.TabIndex = 10
Me.txtInv.Text = “”
‘
‘txtdate
‘
Me.txtdate.Location = New System.Drawing.Point(344, 114)
Me.txtdate.Name = “txtdate”
Me.txtdate.Size = New System.Drawing.Size(88, 20)
Me.txtdate.TabIndex = 11
Me.txtdate.Text = “”
‘
‘cmdExit
‘
Me.cmdExit.Location = New System.Drawing.Point(8, 256)
Me.cmdExit.Name = “cmdExit”
Me.cmdExit.Size = New System.Drawing.Size(80, 24)
Me.cmdExit.TabIndex = 12
Me.cmdExit.Text = “Exit”
‘
‘Label4
‘
Me.Label4.Location = New System.Drawing.Point(8, 5)
Me.Label4.Name = “Label4”
Me.Label4.Size = New System.Drawing.Size(432, 24)
Me.Label4.TabIndex = 13
Me.Label4.Text = “Click on the Query button to fetch Invoice.”
‘
‘Label5
‘
Me.Label5.Location = New System.Drawing.Point(112, 264)
Me.Label5.Name = “Label5”
Me.Label5.Size = New System.Drawing.Size(344, 24)
Me.Label5.TabIndex = 14
Me.Label5.Text = “Label5”
‘
‘Form1
‘
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(488, 293)
Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.Label5, Me.Label4, Me.cmdExit, Me.txtdate, Me.txtInv, Me.lblName, Me.Label3, Me.Label2, Me.Label1, Me.lstInvLines, Me.lstInv, Me.cmdAddLine, Me.cmdSave, Me.cmdAdd, Me.cmdQuery})
Me.Name = “Form1”
Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
Me.Text = “Invoice”
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim obj As Object
On Error GoTo erh
qb.Connect(“”, “SampleApp”, CoreObjX70.qbEnumFileOpenMode.qbOpenModeDontCare, “”)
Label5.Text = “Not Connected”
If qb.Company.Name <> “Rock Castle Construction” Then
MsgBox(“This sample is designed to work with the QuickBooks Sample Product Company.” & vbCrLf & “Running it against other company files will produce errors.”)
End If
Label5.Text = “Connected to ” & qb.Company.Name
Exit Sub
erh:
MsgBox(Err.Description)
End Sub
Private Sub cmdQuery_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdQuery.Click
Dim Inv As CoreObjX70.Invoice
Dim nMax As Integer
‘ Get first 50 Invoices
nMax = 50
qb.Company.Invoices.GetAll(True, nMax)
‘ Put them in the list box
lstInv.Items.Clear()
For Each Inv In qb.Company.Invoices
lstInv.Items.Add(Inv.RefNumber & ” ” & Inv.Customer & ” ” & Inv.TxnDate)
Next
‘ Clear the LineItem list
lstInvLines.Items.Clear()
End Sub
Private Sub cmdExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdExit.Click
On Error Resume Next
If Not qb Is Nothing Then
qb.CloseConnection()
qb = Nothing
End If
Me.Dispose()
End Sub
Private Sub lstInv_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lstInv.SelectedIndexChanged
Dim i As Integer
On Error GoTo errh
lstInvLines.Items.Clear()
i = lstInv.SelectedIndex + 1
Inv = qb.Company.Invoices.Item(i) ‘.GetByTxnID(sTxnID)
lblName.Text = Inv.Customer
txtInv.Text = Inv.RefNumber
txtdate.Text = Inv.TxnDate
PaintLines()
Exit Sub
errh:
MsgBox(Err.Description)
End Sub
Private Sub PaintLines()
Dim oLine As CoreObjX70.txnItemLine
lstInvLines.Items.Clear()
For Each oLine In Inv.ItemLines
lstInvLines.Items.Add(oLine.Item & ” ” & oLine.Description & ” ” & Format(oLine.Amount, “Currency”))
Next
End Sub
Private Sub cmdAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdAdd.Click
Dim oInv As CoreObjX70.Invoice
Dim oLine As CoreObjX70.txnItemLine
Dim Erc As CoreObjX70.qcError
Dim Erc2 As CoreObjX70.qcError
‘ Create the Invoice
oInv = qb.Company.Invoices.Add()
oInv.Customer = “Baker, Chris”
oInv.TxnDate = “1/1/2003”
oInv.RefNumber = “999”
‘ Add some line items
oLine = Inv.ItemLines.Add
oLine.Item = “Framing”
oLine.Amount = 100
oLine = oInv.ItemLines.Add
oLine.Item = “Wood Door:Exterior”
qb.Company.Invoices.Commit(oInv)
MsgBox(“Invoice Added for ” & oInv.Customer)
Exit Sub
ErrorHandler:
For Each Erc In oInv.Errors
lstInvLines.Items.Add(Erc.Description & ” ” & Erc.Field)
‘ Check or a line item validate failure. The Field property will contain the index of the Line item
If Erc.Number = CoreObjX70.qoEnumErrors.qErrorValidateFailed Then
For Each Erc2 In oInv.ItemLines.Errors
lstInvLines.Items.Add(” LINE ERROR: ” & Erc2.Description & ” ” & Erc2.Field)
Next
End If
Next
End Sub
Private Sub cmdSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSave.Click
Dim i As Integer
Dim Erc As CoreObjX70.qcError
Dim Erc2 As CoreObjX70.qcError
On Error GoTo errh
If Val(qb.qbXMLVersion) < 2.1 Then MsgBox("Your version of QuickBooks does not support Invoice modification") Exit Sub End If If Inv Is Nothing Then MsgBox("Please select an invoice to modify") Exit Sub End If qb.Company.Invoices.Commit(Inv) MsgBox("Invoice " & Inv.RefNumber & " updated successfully.") Exit Sub Errh: For Each Erc In Inv.Errors lstInvLines.Items.Add(Erc.Description & " " & Erc.Field) ' Check or a line item validate failure. The Field property will contain the index of the Line item If Erc.Number = CoreObjX70.qoEnumErrors.qErrorValidateFailed Then For Each Erc2 In Inv.ItemLines.Errors lstInvLines.Items.Add(" LINE ERROR: " & Erc2.Description & " " & Erc2.Field) Next End If Next Exit Sub End Sub Private Sub cmdAddLine_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdAddLine.Click Dim oLine As CoreObjX70.txnItemLine On Error GoTo errh If Val(qb.qbXMLVersion) < 2.1 Then MsgBox("Your version of QuickBooks does not support Invoice modification") Exit Sub End If If Inv Is Nothing Then Exit Sub ' Add a new line item Inv.ItemLines.Add("Wood Door:Exterior") PaintLines() Exit Sub errh: MsgBox(Err.Description) End Sub End Class
You must be logged in to reply to this topic.