Skip to content

Instantly share code, notes, and snippets.

@RobertWaiteREPAY
Last active November 18, 2020 00:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RobertWaiteREPAY/58835830b6ef68b803f929d10363ed46 to your computer and use it in GitHub Desktop.
Save RobertWaiteREPAY/58835830b6ef68b803f929d10363ed46 to your computer and use it in GitHub Desktop.
Function Create-Invoice
{
param(
[Parameter(Mandatory=$true)]
[Microsoft.PowerShell.Commands.WebRequestSession]$WebSession,
$EndPoint = $env:AcumaticaTestEndPoint,
$Body,
[switch]$release)
$Uri = "$EndPoint/entity/default/18.200.001/Invoice"
$HashArguments = @{
Uri = "$AcumaticaEndPoint/entity/default/18.200.001/Invoice"
Method = 'PUT'
Headers = $headers
Body = $body
WebSession = $WebSession}
$response = Invoke-RestMethod @HashArguments
$InvoiceAsPSObject = $response | ConvertTo-Json | ConvertFrom-Json
$ReferenceNbr = $InvoiceAsPSObject.ReferenceNbr.value
$EntityID = $InvoiceAsPSObject.id
"Invoice $ReferenceNbr Created"
if($release)
{
"Releasing Invoice $ReferenceNbr"
$body = @"
{
`"entity`":{`"id`": `"$EntityID`"}
}
$body
"@
$HashArguments = @{
Uri = "$AcumaticaEndPoint/entity/default/18.200.001/Invoice/ReleaseInvoice"
Method = 'POST'
Headers = $headers
Body = $body
WebSession = $WebSession}
$response = Invoke-RestMethod @HashArguments
$Counter = 0
$MaxLoops = 5
do
{
if ($Counter -eq $MaxLoops)
{
Logout-Acumatica -WebSession
throw "The Invoice was never released as the loop counter has exceeded its threshold"
}
$Counter += 1
sleep 1
$InvoiceAsPSObject = Get-Invoice -WebSession $WebSession -ReferenceNbr $ReferenceNbr | ConvertTo-Json | ConvertFrom-Json
"Status Check for Invoice#$ReferenceNbr returned $($InvoiceAsPSObject.Status.value)"
}While ($InvoiceAsPSObject.Status.value -ne 'Open')
}
return $InvoiceAsPSObject
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment