Skip to content

Instantly share code, notes, and snippets.

#CSV file is in this format:
#CustomerNbr,Description,Qty,UnitPrice,PaymentMethod
#CUST1,Services for June 2020,1,100,UPSUSD
#CUST2,Services for May 2020,2,200,UPSUSD
#CUST3,Services for April 2020,3,300,UPSUSD
$WebSession = New-Object Microsoft.PowerShell.Commands.WebRequestSession
Login-Acumatica -WebSession $WebSession
Function Check-Invoice
{
param(
[Parameter(Mandatory=$true)]
[Microsoft.PowerShell.Commands.WebRequestSession]$WebSession,
$EndPoint = $env:AcumaticaTestEndPoint,
[Parameter(Mandatory=$true)]
$DocDesc,
[Parameter(Mandatory=$true)]
$CustomerNbr)
Function Pay-Invoice
{
param(
[Parameter(Mandatory=$true)]
[Microsoft.PowerShell.Commands.WebRequestSession]$WebSession,
$EndPoint = $env:AcumaticaTestEndPoint,
[Parameter(Mandatory=$true)]
[string]$ReferenceNbr,
[Parameter(Mandatory=$true)]
[string]$PaymentMethod)
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"
Function Get-Invoice
{
param(
[Parameter(Mandatory=$true)]
[Microsoft.PowerShell.Commands.WebRequestSession]$WebSession,
$EndPoint = $env:AcumaticaTestEndPoint,
[Parameter(Mandatory=$true)]
$ReferenceNbr)
$HashArguments = @{
Function Logout-Acumatica
{
param(
[Parameter(Mandatory=$true)]
[Microsoft.PowerShell.Commands.WebRequestSession]$WebSession,
$EndPoint = $env:AcumaticaTestEndPoint
)
$Uri = "$EndPoint/entity/auth/logout"
$response = Invoke-RestMethod $Uri -Method 'POST' -Headers $headers -WebSession $WebSession
Function Login-Acumatica
{
#This OutputType allows you to strongly type the return object from this function
#In this case we are going to encapsulate the WebRequestSession object initialization and return it
#to the calling process as to be used in other functions. This is needed as to pass the authentication
#State to other functions that need it. Don’t forget to use the Logout-Acumatica function else you will incur
#unnecessary User Logins if they are left open.
[OutputType([Microsoft.PowerShell.Commands.WebRequestSession])]
param(
$User = $Null,
"Create A payment for invoice $ReferenceNbr"
$body = @"
{
`"Type`": {`"value`": `"Payment`"},
`"CustomerID`": {`"value`": `"$CustomerNbr`"},
`"PaymentMethod`": {`"value`": `"$PaymentMethod`"},
`"PaymentAmount`": {`"value`": $UnitPrice},
`"DocumentsToApply`": [{`"ReferenceNbr`": {`"value`": `"$ReferenceNbr`"}}]
}
"@
"Releasing Invoice $ReferenceNbr"
$body = @"
{
`"entity`":{`"id`": `"$EntityID`"}
}
$body
"@
$HashArguments = @{
Uri = "$AcumaticaEndPoint/entity/default/18.200.001/Invoice/ReleaseInvoice"
Method = 'POST'
$CustomerNbr = "ABARTENDE"
$Description = "This was auto created with PowerShell"
$InventoryID = "CONSULTING"
$Qty = "1.000000"
$UnitPrice = "100.000000"
$UOM = "HOUR"
#The @" and "@ tags declare a here string which allows you to have string declarations that run multiple lines
$body = @"
{