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