Batch error messages and identify period to which they apply.

This happens on the Monthly view, and it's possible to get multiple
error messages, even among other successful month adjustments. There was
no way of knowing which month was the offending one or if any had
succeeded when an error was shown.

This change collects all the error messages into one message with the
period so that it's more intuitive and less obtrusive.
This commit is contained in:
PhilRunninger 2023-08-31 17:07:58 -04:00
parent 7bd8cc2674
commit 3fa2cb07f5
9 changed files with 29 additions and 54 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -59,9 +59,8 @@ Private Sub butAdjust_Click()
Exit Sub
End If
Call handler.request_adjust(tbAPI.text, fail)
If fail Then
MsgBox "Adjustment was not made due to error.", vbOKOnly Or vbExclamation
If Not handler.request_adjust(tbAPI.text, msg) Then
MsgBox msg, vbOKOnly Or vbExclamation, "Adjustment was not made due to error."
Exit Sub
End If

Binary file not shown.

View File

@ -229,7 +229,7 @@ End Sub
Function request_adjust(doc As String, ByRef fail As Boolean) As Object
Function request_adjust(doc As String, ByRef msg As String) As Boolean
Dim req As New WinHttp.WinHttpRequest
Dim json As Object
@ -238,8 +238,10 @@ Function request_adjust(doc As String, ByRef fail As Boolean) As Object
Dim j As Long
Dim str() As String
request_adjust = False
If doc = "" Then
fail = True
msg = "No data was given to be processed."
Exit Function
End If
@ -263,35 +265,23 @@ Function request_adjust(doc As String, ByRef fail As Boolean) As Object
Debug.Print Timer - t; "sec): "; Left(wr, 200)
End With
If Mid(wr, 2, 5) = "error" Then
MsgBox (wr)
fail = True
Exit Function
End If
If Mid(wr, 1, 6) = "<body>" Then
MsgBox (wr)
fail = True
Exit Function
End If
If Mid(wr, 1, 6) = "<!DOCT" Then
MsgBox (wr)
fail = True
If Mid(wr, 2, 5) = "error" Or _
Mid(wr, 1, 6) = "<body>" Or _
Mid(wr, 1, 6) = "<!DOCT" _
Then
msg = wr
Exit Function
End If
If Mid(wr, 1, 6) = "null" Then
MsgBox ("API route not implemented")
fail = True
msg = "API route not implemented"
Exit Function
End If
Set json = JsonConverter.ParseJson(wr)
If IsNull(json("x")) Then
MsgBox ("No adjustment was made.")
fail = False
msg = "No adjustment was made."
Exit Function
End If
@ -335,32 +325,12 @@ Function request_adjust(doc As String, ByRef fail As Boolean) As Object
res(i, 34) = json("x")(i + 1)("pounds")
Next i
Set json = Nothing
ReDim str(UBound(res, 1), UBound(res, 2))
' For i = 0 To UBound(res, 1)
' For j = 0 To UBound(res, 2)
' If IsNull(res(i, j)) Then
' str(i, j) = ""
' Else
' str(i, j) = res(i, j)
' End If
' Next j
' Next i
i = 1
Do Until shData.Cells(i, 1) = ""
i = i + 1
Loop
request_adjust = True
i = shData.UsedRange.Rows.Count + 1
Call Utils.SHTp_DumpVar(res, shData.Name, i, 1, False, False, True)
'Call Utils.SHTp_Dump(str, shData.Name, CLng(i), 1, False, False, 28, 29, 30, 31, 32)
shOrders.PivotTables("ptOrders").PivotCache.Refresh
End Function
Sub load_config()
@ -543,7 +513,6 @@ Function list_changes(doc As String, ByRef fail As Boolean) As Variant()
Set json = JsonConverter.ParseJson(wr)
If IsNull(json("x")) Then
MsgBox ("No history.")
fail = True
Exit Function
End If

Binary file not shown.

Binary file not shown.

View File

@ -719,7 +719,6 @@ Sub post_adjust()
Exit Sub
End If
Dim fail As Boolean
Dim adjust As Object
Dim jdoc As String
@ -728,19 +727,27 @@ Sub post_adjust()
adjust("message") = shMonthView.Range("MonthComment").Value
adjust("tag") = shMonthView.Range("MonthTag").Value
jdoc = JsonConverter.ConvertToJson(adjust)
Call handler.request_adjust(jdoc, fail)
If fail Then Exit Sub
If Not handler.request_adjust(jdoc, msg) Then
MsgBox msg, vbOKOnly Or vbCritical, "Adjustment was not made."
Exit Sub
End If
Else
Dim allMsg As String
For i = 2 To 13
If shMonthUpdate.Cells(i, 16) <> "" Then
Set adjust = JsonConverter.ParseJson(shMonthUpdate.Cells(i, 16))
adjust("message") = shMonthView.Range("MonthComment").Value
adjust("tag") = shMonthView.Range("MonthTag").Value
jdoc = JsonConverter.ConvertToJson(adjust)
Call handler.request_adjust(jdoc, fail)
If fail Then Exit Sub
If Not handler.request_adjust(jdoc, msg) Then
Dim period As String
period = Format(i - 1, "00") & " - " & Format(DateSerial(2000, (i - 1) + 5, 1), "mmm")
allMsg = IIf(allMsg = "", "", vbNewLine) & period & ": " & msg
End If
End If
Next i
If allMsg <> "" Then MsgBox allMsg, vbOKOnly Or vbCritical, "Problems Loading Adjustments"
End If
shOrders.Select