locked
GST, VAT Tax Percentage, Compound Update? RRS feed

  • Question

  • Hi All,

    I am trying to add Australian GST (10% of total added on to the total figure of my quote). I was told to do it with a compound update?

    Does anyone know where i can find documentation? I have some sample code just running on quote update message, it doesn’t work because it keeps calling update web service and never finishes, because it keeps firing the code Smile, (I have left out the update line where it loops Smile )

    Public Class QuoteGST
        Implements IPlugin

        ''' <summary>
        ''' Updates Total Tax(totaltax) From 10% (totallineitemamount)
        ''' ----------------------------------------------------------
        ''' We Need To Query For The GUID And ReQuery It, Don't Have The Right Data On Save...
        ''' </summary>
        ''' <remarks>Post Compound Update, Create, Update</remarks>
        Public Sub Execute(ByVal context As IPluginExecutionContext) Implements IPlugin.Execute

            ''Module Settings
            Dim TotalID As String = "totallineitemamount"
            Dim GSTID As String = "new_gst"
            Dim UpdatedTotalID As String = "totalamount"

            ' Verify we have an entity to work with
            If context.InputParameters.Properties.Contains("Target") Then

                ''Grab The ID To Query, To Get Full Amount Of Data
                Dim entity As DynamicEntity = DirectCast(context.InputParameters.Properties("Target"), DynamicEntity)

                If entity.Name = "quote" Then

                    Dim QuoteID As Guid = entity.Properties("quoteid").value

                    ''Create The Service
                    Dim service As ICrmService = CType(context.CreateCrmService(False), ICrmService)

                    ''Quote Entity
                    Dim QuoteEnt As quote = service.Retrieve("quote", QuoteID, New AllColumns)
                    If QuoteEnt Is Nothing Then
                        Throw New InvalidPluginExecutionException("No Quote Returned")
                    End If

                    Dim Total As Decimal = QuoteEnt.totallineitemamount.Value
                    Dim GST As Decimal = Total * 0.1
                    Dim TotalGST As Decimal = Total + GST

                    ''Save Totals
                    QuoteEnt.totalamount.Value = TotalGST
                    QuoteEnt.totaltax.Value = GST

                Else
                    Throw New InvalidPluginExecutionException("Invalid Entity Type, Please Register Under Quotes")
                End If


            End If
        End Sub
    End Class

    Thanks In Advance
    Beachnerd

    Tuesday, April 29, 2008 11:19 PM

All replies

  • Hi,

     

    I would recommend to change this to be a pre-plugin, because in that way you can increment the total value with the VAT without any call to the web services and therefore avoid infite loops.

     

    Anyway, in your plugin context you several attributes are available that let you know if your code it's running as a result of another plugin execution. Check this entry on the SDK http://msdn.microsoft.com/en-us/library/cc151077.aspx and the Event Execution Pipeline http://msdn.microsoft.com/en-us/library/cc151078.aspx

     

    Hope it helps,

     

    Marco Amoedo 

     

    Thursday, May 1, 2008 2:48 PM
    Moderator
  • If i do a pre-plugin, crm system wont get the right prices from the quote products. (vat is 10% of linetotals)

    is there a method, message or somthing that i can call to stop it?

    Beachnerd
    Thursday, May 8, 2008 11:49 PM
  • see

    use plugins for this.

     

    http://code.msdn.microsoft.com/crmplugin

     

    Regards,

    Imran

     

     

    Monday, May 12, 2008 2:10 PM
    Moderator