Try
With Inv
.Add()
.CustomerID = Me.Job1.CustomerID
.SiteID = Me.Job1.InstallationID
.InvoiceDate = Date.Today
.OrderReference = Me.Job1.OrderReference
.InvoiceTotal = Me.Job1.TotalJobCost
.Status = 1 '
.Printed = False
.Terms = 1
.PaymentDue = Date.Today
.FreeForm = String.Empty
.Notes = "All goods remain the property of " & " until paid for in full." & ControlChars.CrLf
.InvoiceTotal = Me.Job1.TotalJobCost
' BusinessLayer.TransactionBegin("", Data.IsolationLevel.ReadCommitted)
.InvoiceNumber = GetNextInvoiceNumber(False)
' If .Save(True) = MicroFour.StrataFrame.Data.SaveUndoResult.Success Then
Try
Me.JobLine1.MoveFirst()
Do
With invline
.Add()
' .InvoiceID = Inv.ID
.Partcode = Me.JobLine1.PartCode
.Qty = Me.JobLine1.Qty
.LineTotal = Me.JobLine1.LineTotal
If AlarmInstallation1.NewBuild = True Then
.VATCode = "E" ' exempt
Else
.VATCode = 1 ' normal
Using vcode As New VATCodes
vcode.FillByPrimaryKey(.VATCode)
If vcode.CurrentRowIndex > -1 Then
vatrt += (.LineTotal * vcode.VATRate / 100)
Else
vatrt += 0 ' if the vatcode doesn't exist then we can't calculate it.
End If
End Using
End If
Select Case .Save(False)
Case MicroFour.StrataFrame.Data.SaveUndoResult.AbortedWithBrokenRules
System.Diagnostics.Debug.WriteLine("BR")
Case MicroFour.StrataFrame.Data.SaveUndoResult.Cancelled
System.Diagnostics.Debug.WriteLine("cancelled")
Case MicroFour.StrataFrame.Data.SaveUndoResult.CompletedWithExceptions
System.Diagnostics.Debug.WriteLine("CWR")
Case MicroFour.StrataFrame.Data.SaveUndoResult.FailedWithExceptions
System.Diagnostics.Debug.WriteLine("fwe")
Case MicroFour.StrataFrame.Data.SaveUndoResult.Success
System.Diagnostics.Debug.WriteLine("amazing!")
End Select
End With
Loop Until Me.JobLine1.MoveNext = False
Catch ex As Exception
Throw ex
End Try
'Else
'MessageForm.ShowMessage("Broken Rules:" & Inv.BrokenRules.ToString)
'End If
' BusinessLayer.TransactionCommit("")
' finally mark the job as invoiced so it can't be invoiced again.
With Me.Job1
.Edit()
.Invoiced = True
.Save()
End With
.Edit()
.VAT = vatrt
.Save()
End With
Me.tsbInvoiceJob.Enabled = Not Job1.Invoiced
Catch ex As Exception
MessageForm.ShowMessage("Alarm64 Job", "An unexpected issue has occurred. An email has been created and sent to Alarm64 Support" _
, "7001", MessageFunction.OK, MessagingIcon.Information, MessagingSounds.Notify)
SendemailException(ex, Me, "7001")
'BusinessLayer.TransactionRollback("")
End Try