How to add a new sales order badge  Topic is solved

Discussions relating to plugin development, and the Jiwa API.

How to add a new sales order badge

Postby DannyC » Fri Nov 26, 2021 9:46 am

I've had a request to add a badge (like the Printed, emailed, processed indicators) to sales orders.

I've looked through old forums and scanned through various sections of the SalesOrderUI in JustDecompile but can't quite work it out.
Any tips or pointers?
User avatar
DannyC
Senpai
Senpai
 
Posts: 636
Joined: Fri Mar 22, 2013 12:23 pm
Topics Solved: 30

Re: How to add a new sales order badge  Topic is solved

Postby pricerc » Fri Nov 26, 2021 10:25 am

The Sales Order form has a table layout panel, making it a bit easier to add things than on some other forms.

This is (roughly) what I do:
Code: Select all
        Public Sub Setup(JiwaForm As IJiwaForm, Plugin As Plugin) Implements IJiwaFormPlugin.Setup
            Dim salesOrderForm = TryCast(JiwaForm, BaseSalesOrderEntryForm)
            If salesOrderForm Is Nothing Then Return

            AddLabel(salesOrderForm, "AerpWarningLabel", 3, 3) ' add new label in the middle of the header.
        End Sub

        Shared Function AddLabel(pluginForm As BaseSalesOrderEntryForm, name As String, column As Integer, row As Integer) As Label
            Dim result As New Label() With {
                              .Text = String.Empty,
                              .TextAlign = ContentAlignment.MiddleCenter,
                              .BorderStyle = BorderStyle.None,
                              .Name = name,
                              .Dock = DockStyle.Fill,
                              .BackColor = Color.Transparent
            }

            pluginForm.TableLayoutPanel1.Controls.Add(result, column, row)
            Return result
        End Function

        Shared Sub SetLabelText(sof As BaseSalesOrderEntryForm, controlName As String, text As String, backColor As Color, foreColor As Color)
            Dim label As Label = CType(sof.TableLayoutPanel1.Controls(controlName), Label) ' find the label in the header panel

            label.Text = text
            label.BackColor = backColor
            label.ForeColor = foreColor

            label.Visible = Not String.IsNullOrWhiteSpace(text)
        End Sub

        Private Sub SalesOrder_ReadEnd(ByVal sender As Object, ByVal e As EventArgs)
            Dim salesOrder As SalesOrder = TryCast(sender, SalesOrder)
            If salesOrder Is Nothing Then Return 'panic.

            SetLabelText(salesOrderForm, "AerpWarningLabel", Nothing, Color.Transparent, Color.Transparent) ' clear the label

            Dim haveObsoleteItems As Boolean = False
            For Each sol As SalesOrderLine In salesOrderForm.SalesOrder.SalesOrderLines
                Select Case sol.InventoryStatus
                    Case SalesOrder.SalesOrderInventoryStatuses.e_SalesOrderObsolete,
                            SalesOrder.SalesOrderInventoryStatuses.e_SalesOrderDeleted,
                            SalesOrder.SalesOrderInventoryStatuses.e_SalesOrderDiscontinued

                        haveObsoleteItems = True
                        SetLabelText(salesOrderForm, "AerpWarningLabel", "Order has obsolete products", Color.Brown, Color.White)
                End Select

                If haveObsoleteItems Then Exit For
            Next
        End Sub
/Ryan

ERP Consultant,
Advanced ERP Limited, NZ
https://aerp.co.nz
User avatar
pricerc
Senpai
Senpai
 
Posts: 504
Joined: Mon Aug 10, 2009 12:22 pm
Location: Auckland, NZ
Topics Solved: 20

Re: How to add a new sales order badge

Postby DannyC » Tue Nov 30, 2021 10:15 pm

That's awesome. That's given me a decent starting point.

I had to experiment with the column and row because pretty much each value I tried would push the other controls out of alignment.
Finally settled on a position 3, 6.

And I also did it in C#.
User avatar
DannyC
Senpai
Senpai
 
Posts: 636
Joined: Fri Mar 22, 2013 12:23 pm
Topics Solved: 30

Re: How to add a new sales order badge

Postby pricerc » Wed Dec 01, 2021 7:17 am

Glad to be of assistance.

DannyC wrote:And I also did it in C#.


I won't hold that against you :P

I use a mix of C# and VB, depending on the context.

But I will always choose VB if I'm going to be doing anything in XML, or if there's any likelihood that I'll need to guide someone through a remote edit - occasionally, with capable clients, instead of a whole plugin, I'll just send an email with a couple of lines of code and instructions on where to put them; this is much easier with VB than C#, because the keywords of VB are much easier to spot for a non-coder.
/Ryan

ERP Consultant,
Advanced ERP Limited, NZ
https://aerp.co.nz
User avatar
pricerc
Senpai
Senpai
 
Posts: 504
Joined: Mon Aug 10, 2009 12:22 pm
Location: Auckland, NZ
Topics Solved: 20

Re: How to add a new sales order badge

Postby SBarnes » Wed Dec 01, 2021 12:06 pm

Whilst this could start a debate over which language is better I say go with the one that works better for you as both largely can do the same job.

I prefer c# for two very honest reasons:

  • When looking for something I can usually find a c# example quicker on google
  • I will be honest and admit it means I have to type less
Regards
Stuart Barnes
SBarnes
Shihan
Shihan
 
Posts: 1619
Joined: Fri Aug 15, 2008 3:27 pm
Topics Solved: 175


Return to Technical and or Programming

Who is online

Users browsing this forum: No registered users and 10 guests