The xAssets API - Method : SpecialAccountingProcess

Summary

Run a period end depreciation calculation, create journals and close a financial accounting period

Parameters

Parameter : sXML

XML In the form :<AccountingProcess_T><AccountingProcess_R><APS1ID>AccountingPeriodSetID</APS1ID><A8>AccountingPeriodSetDesc</A8><D6>FORWARD</D6><FromStatus>ProcessStatus</FromStatus><ToStatus>ToStatus</ToStatus><F11>ActualAccountingPeriodID</F11><T25>ForecastAccountingPeriodID</T25><FromStartDate>FromStartDate</FromStartDate><ToStartDate>ToStartDate</ToStartDate><FromEndDate>FromEndDate</FromEndDate><ToEndDate>ToEndDate</ToEndDate><AdditionsJournal>0</AdditionsJournal><DepreciationJournal>1</DepreciationJournal><DisposalJournal>1</DisposalJournal><TransferJournal>1</TransferJournal><AID>0</AID><ADPID>0</ADPID></AccountingProcess_R></AccountingProcess_T>

AccountingPeriodSetID = The ID of the accounting period set being calculated

AccountingPeriodSetDesc = The description of the accounting period set being calculated (optional)

FORWARD or BACKWARD = the direction of the calculation. To rewind, use "BACKWARD", to calculate normally, use "FORWARD"

ProcessStatus = NEW to close the last journalled period and open the next period for future calculation, CALCULATED to perform a depreciation calculation and move from a new period to a journalled period, JOURNALLED to write the journal files and then move from a calculated period to a journalled period. It is only possible to move one step at a time, (e.g. from NEW to CALCULATED, from CALCULATED to JOURNALLED, or from JOURNALLED to NEW) but multiple periods can be processed in a single run.

ActualAccountingPeriodID = The accounting period ID you wish to calculate actuals for

ForecastAccountingPeriodiD = The last accounting period ID you wish to calculate budgets for

FromStartDate = the start date of the period we are calculating from

ToStartDate = the start date of the period we are calculating to

FromEndDate = the end date of the period we are calculating from

ToEndDate = the end date of the period we are calculating to

AdditionsJournal = 0 or 1 flag to determine whether to write an additions journal. This journal will contain acquisition amounts related to asset additions

DepreciationJournal = 0 or 1 flag to determine whether to write a depreciation journal. This journal will contain depreciation calculations

DisposalJournal = 0 or 1 flag to determine whether to write a disposal journal. This journal will contain asset disposals

TransferJournal = 0 or 1 flag to determine whether to write a transfer journal. This journal will contain asset transfers

AID and ADPID are not used in this version

Parameter : sArguments

This parameter is not used

Returns

An empty string or a string starting with "special=" if the batch job was launched successfully. If the launch failed, an error message will be returned

Remarks

This command launches an accounting period calculation run as a batch job. Since the calculation operates as a batch job, this method returns to the caller before the process has completed, so the result is not known at the time the method returns.

Syntax and Examples

Restful syntax with Microsoft Visual Basic

Example 1


    Imports System.Text
    Imports Newtonsoft.Json.Linq
    Public Module Module1

        Public Sub Main()

            Try

                '   Enter your API key and company database name in these variables

                Dim _db As String = "mycompany"
                Dim apikey As String = "YOURAPIKEY"

                '   Open a web client to login

                Dim web As New System.Net.WebClient()

                Dim urlroot as String = "https://" & _db & ".yourxassetsplatform.xassets.net/api"
                Dim json As String = web.DownloadString(urlroot & "/api.ashx?apikey=" & apikey & "&database=" & _db & "&command=apilogon")

                '   Check the login for errors

                Dim o As JObject = JObject.Parse(json)
                Dim e As String = GetResultFromJson(o, "error")
                If e <> "" Then
                    Throw New Exception(e)
                End If

                '   Store the login hash, nonce and noncedate

                Dim hash As String = GetResultFromJson(o, "hash")
                Dim nonce As String = GetResultFromJson(o, "nonce")
                Dim noncedate As Date = CDate(GetResultFromJson(o, "noncetime"))

                If hash = "" Then
                    Throw New Exception("Unexpected error - a hash was not returned from the API logon process")
                End If

                Console.WriteLine("Logged on OK")

                '   Open a new web client to perform the API call

                web = New System.Net.WebClient()

                '   Add the authorization header

                web.Headers.Add("Authorization", "Bearer " & hash)
                web.Headers.Add("Sec", _db & "|" & nonce & "|" & Format(noncedate, "dd-MMM-yyyy HH:mm:ss") & "|" & Format(noncedate, "fff"))

                '   Perform the actual API call

                Dim url as String = urlroot & "/api.ashx?command=SpecialAccountingProcess
                Dim data As String = web.DownloadString(url.ToString)

                '   Parse and output the data

                Dim ob As JObject = JObject.Parse(data)
                Dim err As String = GetResultFromJson(ob, "error")
                If err <> "" Then
                    Throw New Exception(err)
                End If
            
                Dim xml As String = GetResultFromJson(ob, "returncode")

                Console.WriteLine(xml)
                Console.WriteLine("Finished - Press enter to close")
            
                Catch ex As Exception
                Console.WriteLine("Error:" & ex.Message & " - Press enter to close")
            End Try

            Console.ReadLine()

        End Sub

        Private Function GetResultFromJson(o As JObject, sFind As String) As String

            For Each res As JObject In o.SelectTokens("data[*]")
                If res("type").Value(Of String) = sFind Then
                    Return res("value").ToString
                End If
            Next

            Return ""

        End Function
    End Module
                

SOAP Syntax with Microsoft Visual Basic

Example 1


    Try

        ErrorMessage = ""

        Return w.WebSaveSpecial(_hash, _username, _db, _ip, "", "SpecialAccountingProcess", {}, False, _dns, _port, _scheme, _nonce, _noncedate)

    Catch ex As Exception
        ErrorMessage = ex.Message
        Return "
    End Try

                            

AMSX Syntax

Example 1


    SaveSpecial "SpecialAccountingProcess",""
                        

XCS Syntax

Example 1


    Dim ret as String = Server.SaveSpecial("SpecialAccountingProcess","")
    If ret = " Or ret.Substring(0, 8) = "special=" Then
        MsgBox("Save operation completed.", vbInformation, "Save Data")
    Else
        MsgBox("Save operation failed:" & ret, vbExclamation, "Save Data")
    End If
                        

Download the Visual Studio API Samples Project

Return to the API Index Page

© xAssets 2024 All rights reserved.