Skip to content

Commit

Permalink
Merge pull request #30 from greenlighttec/develop
Browse files Browse the repository at this point in the history
Added some helper cmdlets
  • Loading branch information
homotechsual authored Dec 11, 2023
2 parents f5ff3e1 + 1e048b7 commit 58fd76d
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 0 deletions.
3 changes: 3 additions & 0 deletions HaloAPI.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@
'Get-HaloSoftwareLicence',
'Get-HaloStatus',
'Get-HaloSupplier',
'Get-HaloSuppliersFromQBO',
'Get-HaloTeam',
'Get-HaloTicket',
'Get-HaloTicketRules',
Expand All @@ -116,7 +117,9 @@
'Get-HaloWorkday',
'Get-HaloWorkflow',
'Get-HaloWorkflows',
'Import-HaloSuppliersFromAccountingPackage',
'Invoke-HaloRequest',
'Invoke-HaloSQL',
'New-HaloAction',
'New-HaloActionBatch',
'New-HaloAgent',
Expand Down
19 changes: 19 additions & 0 deletions Public/Helpers/Get-HaloSuppliersFromQBO.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
function Get-HaloSuppliersFromQBO {
param[
[int32]$ConnectionID,
[string]$datatype = 'vendor'
]

$QSCollection = New-HaloQuery -CommandName $CommandName -Parameters $Parameters -IsMulti
$Resource = 'api/integrationdata/get/quickbooksonline'
$RequestParams = @{
Method = 'GET'
Resource = $Resource
AutoPaginateOff = $Paginate
QSCollection = $QSCollection
ResourceType = 'releases'
}

$QBOVendors = New-HaloGETRequest @RequestParams
Return $QBOVendors
}
35 changes: 35 additions & 0 deletions Public/Helpers/Import-HaloSuppliersFromAccountingPackage.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
function Import-HaloSupplierFromQBO {
[CmdletBinding()]
param (
[Parameter()]
[System.Object]
$APSupplier,
[Parameter()]
[string]
$ImportType = 'quickbooksonline',
[Parameter()]
[string]
$APCompanyID
)
[PSCustomObject]$returnData = @{
_isimport = $true
_importtype = $ImportType
accounts_id = $APSupplier.id
details_id = 1
qbo_company_id = $APCompanyID
name = $APSupplier.companyName
address = "$($APSupplier.billAddr.line1)`n$($APSupplier.billAddr.city)`n$($APSupplier.billAddr.countrySubDivisionCode)`n$($APSupplier.billAddr.postalCode)"
}

if ($Email = $APSupplier.primaryEmailAddr.address) {
Add-Member -InputObject $returnData -Name email_address -Value $Email -MemberType NoteProperty -Force
}
if ($PhoneNumber = $APSupplier.printOnCheckName.freeFormNumber) {
Add-Member -InputObject $returnData -Name phone_number -Value $PhoneNumber -MemberType NoteProperty -Force
}

if (($FirstName = $APSupplier.givenName) -or ($LastName = $APSupplier.familyName)) {
Add-Member -InputObject $returnData -Name contact_name -Value ("$($FirstName) $($LastName)".trim()) -MemberType NoteProperty -Force
}
return $returnData
}
47 changes: 47 additions & 0 deletions Public/Invoke/Invoke-HaloSQL.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
Function Invoke-HaloSQL {
<#
.SYNOPSIS
Uses the Reports API endpoint to run arbitrary SQL.
.DESCRIPTION
Function to run a report preview with a SQL query parameter. Use -IncludeFullReport to get the entire report object instead of just the results
.OUTPUTS
Outputs an object containing the response from the web request.
#>
[CmdletBinding( SupportsShouldProcess = $True )]
[OutputType([Object[]])]
Param (
# String or Here String for SQL Statement
[Parameter( Mandatory = $True, ValueFromPipeline )]
[String]$SQLQuery,
# Return Full Report Object.
[Parameter()]
[Switch]$IncludeFullReport
)
Invoke-HaloPreFlightCheck
try {
$Payload = @(@{id = 0; name= ''; sql = $SQLQuery; apiquery_id = 0; "_testonly" = $false; "_loadreportonly" = $true})
if ($PSCmdlet.ShouldProcess($Payload -is [Array] ? 'Reports' : 'Report', 'Execute')) {
$Report = New-HaloPOSTRequest -Object $Payload -Endpoint 'report'
if (-not $Report.report.load_error) {

if ($Report.report.rows.count -eq 0) {
throw "No results were returned"
}

else {
if ($IncludeFullReport) {
return $Report
}
else {
return $Report.report.rows
}
}
} else {
Throw $Report.report.load_error
}
}

} catch {
New-HaloError -ErrorRecord $_
}
}

0 comments on commit 58fd76d

Please sign in to comment.