Profit Margin and % on Sales Order Lines  Topic is solved

Discussions relating to plugin development, and the Jiwa API.

Profit Margin and % on Sales Order Lines

Postby Ernst » Mon Apr 08, 2024 9:55 am

On a Sales Order, customer wanted the Margin and Margin%, though this would a standard column, but alas, no.
Has anybody created plugin with Margin and Margin %.

Which cost would we use Cost on line(LCost) or average Cost on Line Details? Average sound more accurate, if available.
User avatar
Ernst
Kohai
Kohai
 
Posts: 219
Joined: Tue Feb 19, 2008 3:43 pm
Topics Solved: 12

Re: Profit Margin and % on Sales Order Lines  Topic is solved

Postby DannyC » Mon Apr 08, 2024 10:50 am

I've done a plugin which works out the gross profit %.
It's quite easy. Just created a custom field on the line. This is the crux of the code:

Code: Select all
   private void SalesOrderLineChanged(object sender, JiwaFinancials.Jiwa.JiwaSales.SalesOrder.SalesOrderLine line, System.ComponentModel.PropertyChangedEventArgs e)
   {
      if (!line.CommentLine && line.CostIn != 0)
      {
         decimal GP = (line.DiscountedPrice - line.CostIn)/line.DiscountedPrice * 100;
         line.CustomFieldValues.get_ItemFromSettingName("SOGP%").Contents = GP.ToString();
      }      
   }


and (for the whole order)

Code: Select all
   private void ShowOrderGP(object sender, System.EventArgs e)
   {
      JiwaFinancials.Jiwa.JiwaSales.SalesOrder.SalesOrder salesorder = (JiwaFinancials.Jiwa.JiwaSales.SalesOrder.SalesOrder)sender;
      decimal GP = 0;
      decimal totalcost = 0;
      
      foreach(JiwaFinancials.Jiwa.JiwaSales.SalesOrder.SalesOrderLine line in salesorder.SalesOrderLines)
      {
         totalcost += line.LastCost*line.QuantityThisDelivery;
      }
      
      GP = (salesorder.SalesOrderLines.ExGSTTotal-totalcost)/salesorder.SalesOrderLines.ExGSTTotal * 100;
}


After the GP has been calculated, you can chuck it in a custom field, or maybe on the Reference, or where ever you want.
User avatar
DannyC
Senpai
Senpai
 
Posts: 636
Joined: Fri Mar 22, 2013 12:23 pm
Topics Solved: 30

Re: Profit Margin and % on Sales Order Lines

Postby Ernst » Mon Apr 08, 2024 11:07 am

Thanks Danny, Will give that a go..
User avatar
Ernst
Kohai
Kohai
 
Posts: 219
Joined: Tue Feb 19, 2008 3:43 pm
Topics Solved: 12

Re: Profit Margin and % on Sales Order Lines

Postby Mike.Sheen » Mon Apr 08, 2024 4:30 pm

instead of:

Code: Select all
line.CustomFieldValues.get_ItemFromSettingName("SOGP%").Contents = GP.ToString();


You can do:

Code: Select all
line.CustomFieldValues.SetValue<decimal>)("SOGP%", GP);


We also have a helper method to get the value:

Code: Select all
decimal GP = line.CustomFieldValues.GetValue<decimal>)("SOGP%", 0);


Make the code a bit cleaner and uses strong typing, which is always a good thing.
Mike Sheen
Chief Software Engineer
Jiwa Financials

If I do answer your question to your satisfaction, please mark it as the post solving the topic so others with the same issue can readily identify the solution
User avatar
Mike.Sheen
Overflow Error
Overflow Error
 
Posts: 2444
Joined: Tue Feb 12, 2008 11:12 am
Location: Perth, Republic of Western Australia
Topics Solved: 756

Re: Profit Margin and % on Sales Order Lines

Postby Ernst » Mon Apr 08, 2024 6:55 pm

OK Ive done this. Tried to lock column so it wasn't really changeable. Both custom fields are Text.
Kinda works. But if no stock, then no calc. Will see if customers wants me to use Lcost in that case... Any comments?

Code: Select all
   Public Sub SalesOrder_ReadEnd(sender As Object, e As System.EventArgs)
         Dim salesOrderObject As JiwaFinancials.Jiwa.JiwaSales.SalesOrder.SalesOrder = DirectCast(sender, JiwaFinancials.Jiwa.JiwaSales.SalesOrder.SalesOrder)
         If Not salesOrderObject.Client Is Nothing AndAlso TypeOf(salesOrderObject.Client) Is JiwaFinancials.Jiwa.JiwaSalesUI.SalesOrder.BaseSalesOrderEntryForm Then
            Dim salesOrderForm As JiwaFinancials.Jiwa.JiwaSalesUI.SalesOrder.BaseSalesOrderEntryForm = DirectCast(salesOrderObject.Client, JiwaFinancials.Jiwa.JiwaSalesUI.SalesOrder.BaseSalesOrderEntryForm)
            salesOrderForm.grdLines.LockColumn(True, "PLuginName.GP", -1)
               salesOrderForm.grdLines.LockColumn(True, "PLuginName.GPPerc", -1)


   Private Sub SalesOrderLines_Changed(ByVal Item As JiwaSales.SalesOrder.SalesOrderLine, e As System.ComponentModel.PropertyChangedEventArgs)
   Dim salesOrder As JiwaSales.SalesOrder.SalesOrder = DirectCast(item.SalesOrderLines.SalesOrder, JiwaSales.SalesOrder.SalesOrder)
   Dim salesOrderObject As JiwaFinancials.Jiwa.JiwaSales.SalesOrder.SalesOrder = DirectCast(salesOrder, JiwaFinancials.Jiwa.JiwaSales.SalesOrder.SalesOrder)
   Dim salesOrderForm As JiwaFinancials.Jiwa.JiwaSalesUI.SalesOrder.BaseSalesOrderEntryForm = DirectCast(salesOrderObject.Client, JiwaFinancials.Jiwa.JiwaSalesUI.SalesOrder.BaseSalesOrderEntryForm)   
   Dim SalesOrderH As JiwaSales.SalesOrder.SalesOrderHistory = Item.SalesOrderLines.SalesOrder.SalesOrderHistorys(Item.SalesOrderLines.SalesOrder.CurrentHistoryNo)

   If Not item.CommentLine AndAlso item.CostIn <> 0 Then
           Dim GPP As Decimal = (item.DiscountedPrice - item.CostIn) / item.DiscountedPrice * 100
      Dim GPD As Decimal = (item.DiscountedPrice - item.CostIn)
      item.CustomFieldValues.SetValue(Of String)("GPPerc",System.Math.Round(GPP,2) & "%")
      item.CustomFieldValues.SetValue(Of Decimal)("GP",System.Math.Round(GPD,2))
      salesOrderForm.grdLines.LockColumn(True, "PLuginName.GP", -1)
      salesOrderForm.grdLines.LockColumn(True, "PLuginName.GPPerc", -1)
    End If

Capture.PNG
Capture.PNG (35.54 KiB) Viewed 1174 times
User avatar
Ernst
Kohai
Kohai
 
Posts: 219
Joined: Tue Feb 19, 2008 3:43 pm
Topics Solved: 12


Return to Technical and or Programming

Who is online

Users browsing this forum: No registered users and 21 guests