Skip to content

Commit eb6e1af

Browse files
committed
Fix various issues with the Get-HaloRecurringInvoice commandlet.
1 parent be0487d commit eb6e1af

File tree

1 file changed

+231
-147
lines changed

1 file changed

+231
-147
lines changed
Lines changed: 231 additions & 147 deletions
Original file line numberDiff line numberDiff line change
@@ -1,148 +1,232 @@
1-
#Requires -Version 7
2-
function Get-HaloRecurringInvoice {
3-
<#
4-
.SYNOPSIS
5-
Gets recurring invoices from the Halo API.
6-
.DESCRIPTION
7-
Retrieves recurring invoices from the Halo API - supports a variety of filtering parameters.
8-
.OUTPUTS
9-
A powershell object containing the response.
10-
#>
11-
[CmdletBinding( DefaultParameterSetName = 'Multi' )]
12-
[OutputType([Object])]
13-
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSReviewUnusedParameter', '', Justification = 'Uses dynamic parameter parsing.')]
14-
Param(
15-
# Invoice ID
16-
[Parameter( ParameterSetName = 'Single', Mandatory = $True )]
17-
[int64]$RecurringInvoiceID,
18-
# The number of invoices to return if not using pagination.
19-
[Parameter( ParameterSetName = 'Multi' )]
20-
[int32]$Count,
21-
# Return contracts matching the search term in the results.
22-
[Parameter( ParameterSetName = 'Multi' )]
23-
[string]$Search,
24-
# Paginate results
25-
[Parameter( ParameterSetName = 'Multi' )]
26-
[Alias('pageinate')]
27-
[switch]$Paginate,
28-
# Number of results per page.
29-
[Parameter( ParameterSetName = 'Multi' )]
30-
[Alias('page_size')]
31-
[int32]$PageSize,
32-
# Which page to return.
33-
[Parameter( ParameterSetName = 'Multi' )]
34-
[Alias('page_no')]
35-
[int32]$PageNo,
36-
# First field to order the results by.
37-
[Parameter( ParameterSetName = 'Multi' )]
38-
[string]$OrderBy,
39-
# Order results for the first field in descending order (respects the field choice in '-OrderBy')
40-
[Parameter( ParameterSetName = 'Multi' )]
41-
[switch]$OrderByDesc,
42-
# Second field to order the results by.
43-
[Parameter( ParameterSetName = 'Multi' )]
44-
[string]$OrderBy2,
45-
# Order results for the second field in descending order (respects the field choice in '-OrderBy2')
46-
[Parameter( ParameterSetName = 'Multi' )]
47-
[switch]$OrderByDesc2,
48-
# Third field to order the results by.
49-
[Parameter( ParameterSetName = 'Multi' )]
50-
[string]$OrderBy3,
51-
# Order results for the third field in descending order (respects the field choice in '-OrderBy3')
52-
[Parameter( ParameterSetName = 'Multi' )]
53-
[switch]$OrderByDesc3,
54-
# Fourth field to order the results by.
55-
[Parameter( ParameterSetName = 'Multi' )]
56-
[string]$OrderBy4,
57-
# Order results for the fourth field in descending order (respects the field choice in '-OrderBy4')
58-
[Parameter( ParameterSetName = 'Multi' )]
59-
[switch]$OrderByDesc4,
60-
# Fifth field to order the results by.
61-
[Parameter( ParameterSetName = 'Multi' )]
62-
[string]$OrderBy5,
63-
# Order results for the fifth field in descending order (respects the field choice in '-OrderBy5')
64-
[Parameter( ParameterSetName = 'Multi' )]
65-
[switch]$OrderByDesc5,
66-
# Include inactive records
67-
[Parameter( ParameterSetName = 'Multi' )]
68-
[switch]$includeinactive,
69-
# Include invoices
70-
[Parameter( ParameterSetName = 'Multi' )]
71-
[switch]$includeinvoices,
72-
# Include credit notes
73-
[Parameter( ParameterSetName = 'Multi' )]
74-
[switch]$includecredits,
75-
# Include invoice lines
76-
[Parameter( ParameterSetName = 'Multi' )]
77-
[switch]$includeLines,
78-
# Include invoice Details
79-
[Parameter( ParameterSetName = 'Single' )]
80-
[switch]$includeDetails,
81-
# Filter by the specified ticket ID.
82-
[Parameter( ParameterSetName = 'Multi' )]
83-
[Alias('ticket_id')]
84-
[int32]$TicketID,
85-
# Filter by the specified client ID.
86-
[Parameter( ParameterSetName = 'Multi' )]
87-
[Alias('client_id')]
88-
[int32]$ClientID,
89-
# Filter by the specified site ID.
90-
[Parameter( ParameterSetName = 'Multi' )]
91-
[Alias('site_id')]
92-
[int32]$SiteID,
93-
# Filter by the specified user ID.
94-
[Parameter( ParameterSetName = 'Multi' )]
95-
[Alias('user_id')]
96-
[int32]$UserID,
97-
# Parameter to return the complete objects.
98-
[Parameter( ParameterSetName = 'Multi' )]
99-
[switch]$FullObjects
100-
)
101-
Invoke-HaloPreFlightCheck
102-
$CommandName = $MyInvocation.MyCommand.Name
103-
$Parameters = (Get-Command -Name $CommandName).Parameters
104-
# Workaround to prevent the query string processor from adding a 'recurringinvoiceid=' parameter by removing it from the set parameters.
105-
if ($RecurringInvoiceID) {
106-
$Parameters.Remove('RecurringInvoiceID') | Out-Null
107-
}
108-
# Similarly we don't want a `fullobjects=` parameter
109-
if ($FullObjects) {
110-
$Parameters.Remove('FullObjects') | Out-Null
111-
}
112-
try {
113-
if ($RecurringInvoiceID) {
114-
Write-Verbose "Running in single-invoice mode because '-RecurringInvoiceID' was provided."
115-
$QSCollection = New-HaloQuery -CommandName $CommandName -Parameters $Parameters
116-
$Resource = "api/RecurringInvoice/$($RecurringInvoiceID)"
117-
$RequestParams = @{
118-
Method = 'GET'
119-
Resource = $Resource
120-
AutoPaginateOff = $True
121-
QSCollection = $QSCollection
122-
ResourceType = 'invoices'
123-
}
124-
} else {
125-
Write-Verbose 'Running in multi-invoice mode.'
126-
$QSCollection = New-HaloQuery -CommandName $CommandName -Parameters $Parameters -IsMulti
127-
$Resource = 'api/RecurringInvoice'
128-
$RequestParams = @{
129-
Method = 'GET'
130-
Resource = $Resource
131-
AutoPaginateOff = $Paginate
132-
QSCollection = $QSCollection
133-
ResourceType = 'invoices'
134-
}
135-
}
136-
$InvoiceResults = New-HaloGETRequest @RequestParams
137-
# Fetch the complete details for each ticket
138-
if ($FullObjects) {
139-
$AllTicketResults = $InvoiceResults | ForEach-Object {
140-
Get-HaloRecurringInvoice -RecurringInvoiceID $_.id
141-
}
142-
$InvoiceResults = $AllTicketResults
143-
}
144-
Return $InvoiceResults
145-
} catch {
146-
New-HaloError -ErrorRecord $_
147-
}
1+
#Requires -Version 7
2+
function Get-HaloRecurringInvoice {
3+
<#
4+
.SYNOPSIS
5+
Gets recurring invoices from the Halo API.
6+
.DESCRIPTION
7+
Retrieves recurring invoices from the Halo API - supports a variety of filtering parameters.
8+
.OUTPUTS
9+
A powershell object containing the response.
10+
#>
11+
[CmdletBinding( DefaultParameterSetName = 'Multi' )]
12+
[OutputType([Object])]
13+
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSReviewUnusedParameter', '', Justification = 'Uses dynamic parameter parsing.')]
14+
Param(
15+
# Invoice ID
16+
[Parameter( ParameterSetName = 'Single', Mandatory = $True )]
17+
[int64]$RecurringInvoiceID,
18+
# The advanced search query to use.
19+
[Parameter( ParameterSetName = 'Multi' )]
20+
[Alias('advanced_search')]
21+
[string]$AdvancedSearch,
22+
# Filter by an asset id.
23+
[Parameter( ParameterSetName = 'Multi' )]
24+
[Alias('asset_id')]
25+
[int32]$AssetId,
26+
# Filter for recurring invoices awaiting approval.
27+
[Parameter( ParameterSetName = 'Multi' )]
28+
[Alias('awaiting_approval')]
29+
[switch]$AwaitingApproval,
30+
# Filter by billing date.
31+
[Parameter( ParameterSetName = 'Multi' )]
32+
[Alias('billing_date')]
33+
[datetime]$BillingDate,
34+
# Filter by billing category ids.
35+
[Parameter( ParameterSetName = 'Multi' )]
36+
[Alias('billingcategory_ids')]
37+
[Int32[]]$BillingCategoryIds,
38+
# Filter by the specified client id.
39+
[Parameter( ParameterSetName = 'Multi' )]
40+
[Alias('client_id')]
41+
[int32]$ClientId,
42+
# Filter by the specified client ids.
43+
[Parameter( ParameterSetName = 'Multi' )]
44+
[Alias('client_ids')]
45+
[int32[]]$ClientIds,
46+
# Filter by contract id.
47+
[Parameter( ParameterSetName = 'Multi' )]
48+
[Alias('contract_id')]
49+
[int32]$ContractId,
50+
# The number of invoices to return if not using pagination.
51+
[Parameter( ParameterSetName = 'Multi' )]
52+
[int32]$Count,
53+
# Return recurring invoice ids only.
54+
[Parameter( ParameterSetName = 'Multi' )]
55+
[switch]$IdOnly,
56+
# Include credit notes
57+
[Parameter( ParameterSetName = 'Multi' )]
58+
[switch]$IncludeCredits,
59+
# Include invoices
60+
[Parameter( ParameterSetName = 'Multi' )]
61+
[switch]$IncludeInvoices,
62+
# Include invoice lines
63+
[Parameter( ParameterSetName = 'Multi' )]
64+
[switch]$IncludeLines,
65+
# Include PO invoices.
66+
[Parameter( ParameterSetName = 'Multi' )]
67+
[switch]$IncludePOInvoices,
68+
# Include the field `invoicedateend` in the results.
69+
[Parameter( ParameterSetName = 'Multi' )]
70+
[Alias('invoicedateend')]
71+
[switch]$IncludeInvoiceDateEnd,
72+
# Include the field `invoicedatestart` in the results.
73+
[Parameter( ParameterSetName = 'Multi' )]
74+
[Alias('invoicedatestart')]
75+
[switch]$IncludeInvoiceDateStart,
76+
# Filter by your approvals.
77+
[Parameter( ParameterSetName = 'Multi' )]
78+
[Alias('my_approvals')]
79+
[switch]$MyApprovals,
80+
# Filter for unposted invoices only.
81+
[Parameter( ParameterSetName = 'Multi' )]
82+
[switch]$NotPostedOnly,
83+
# First field to order the results by.
84+
[Parameter( ParameterSetName = 'Multi' )]
85+
[string]$Order,
86+
# Order results for the first field in descending order (respects the field choice in '-OrderBy')
87+
[Parameter( ParameterSetName = 'Multi' )]
88+
[switch]$OrderDesc,
89+
# Second field to order the results by.
90+
[Parameter( ParameterSetName = 'Multi' )]
91+
[string]$Order2,
92+
# Order results for the second field in descending order (respects the field choice in '-OrderBy2')
93+
[Parameter( ParameterSetName = 'Multi' )]
94+
[switch]$OrderDesc2,
95+
# Third field to order the results by.
96+
[Parameter( ParameterSetName = 'Multi' )]
97+
[string]$Order3,
98+
# Order results for the third field in descending order (respects the field choice in '-OrderBy3')
99+
[Parameter( ParameterSetName = 'Multi' )]
100+
[switch]$OrderDesc3,
101+
# Fourth field to order the results by.
102+
[Parameter( ParameterSetName = 'Multi' )]
103+
[string]$Order4,
104+
# Order results for the fourth field in descending order (respects the field choice in '-OrderBy4')
105+
[Parameter( ParameterSetName = 'Multi' )]
106+
[switch]$OrderDesc4,
107+
# Fifth field to order the results by.
108+
[Parameter( ParameterSetName = 'Multi' )]
109+
[string]$Order5,
110+
# Order results for the fifth field in descending order (respects the field choice in '-OrderBy5')
111+
[Parameter( ParameterSetName = 'Multi' )]
112+
[switch]$OrderDesc5,
113+
# Which page to return.
114+
[Parameter( ParameterSetName = 'Multi' )]
115+
[Alias('page_no')]
116+
[int32]$PageNo,
117+
# Number of results per page.
118+
[Parameter( ParameterSetName = 'Multi' )]
119+
[Alias('page_size')]
120+
[int32]$PageSize,
121+
# Paginate results
122+
[Parameter( ParameterSetName = 'Multi' )]
123+
[Alias('pageinate')]
124+
[switch]$Paginate,
125+
# Filter by the specified payment statuses.
126+
[Parameter( ParameterSetName = 'Multi' )]
127+
[int32[]]$PaymentStatuses,
128+
# Include posted invoices only.
129+
[Parameter( ParameterSetName = 'Multi' )]
130+
[switch]$PostedOnly,
131+
# Filter by the specified purchase order id.
132+
[Parameter( ParameterSetName = 'Multi' )]
133+
[Alias('purchaseorder_id')]
134+
[int32]$PurchaseOrderId,
135+
# Filter by the specified quote statuses.
136+
[Parameter( ParameterSetName = 'Multi' )]
137+
[Alias('quote_status')]
138+
[string[]]$QuoteStatuses,
139+
# Filter by whether the recurring invoice is marked 'ready for invoicing'.
140+
[Parameter( ParameterSetName = 'Multi' )]
141+
[Alias('ready_for_invoicing')]
142+
[switch]$ReadyForInvoicing,
143+
# Filter for invoices marked 'review required'.
144+
[Parameter( ParameterSetName = 'Multi' )]
145+
[switch]$ReviewRequired,
146+
# Filter by recurring invoice type. Valid values are 'contracts', 'invoices' or 'both'.
147+
[Parameter( ParameterSetName = 'Multi' )]
148+
[Alias('rinvoice_type')]
149+
[ValidateSet('contracts', 'invoices', 'both')]
150+
[string]$RecurringInvoiceType,
151+
# Filter by contract sales order id.
152+
[Parameter( ParameterSetName = 'Multi' )]
153+
[Alias('salesorder_id')]
154+
[int32]$SalesOrderId,
155+
# Filter using the specified search query.
156+
[Parameter( ParameterSetName = 'Multi' )]
157+
[string]$Search,
158+
# Filter by sent status.
159+
[Parameter( ParameterSetName = 'Multi' )]
160+
[Alias('sent_status')]
161+
[int]$SentStatus,
162+
# Filter by the specified site id.
163+
[Parameter( ParameterSetName = 'Multi' )]
164+
[Alias('site_id')]
165+
[int32]$SiteId,
166+
# Filter by invoices requiring stripe payment.
167+
[Parameter( ParameterSetName = 'Multi' )]
168+
[switch]$StripeAutoPaymentRequired,
169+
# Filter by the specified ticket id.
170+
[Parameter( ParameterSetName = 'Multi' )]
171+
[Alias('ticket_id')]
172+
[int32]$TicketId,
173+
# Filter by the specified top level id.
174+
[Parameter( ParameterSetName = 'Multi' )]
175+
[Alias('toplevel_id')]
176+
[int32]$TopLevelId,
177+
# Filter by the specified user ID.
178+
[Parameter( ParameterSetName = 'Multi' )]
179+
[Alias('user_id')]
180+
[int32]$UserId,
181+
# Parameter to return the complete objects.
182+
[Parameter( ParameterSetName = 'Multi' )]
183+
[switch]$FullObjects
184+
)
185+
Invoke-HaloPreFlightCheck
186+
$CommandName = $MyInvocation.MyCommand.Name
187+
$Parameters = (Get-Command -Name $CommandName).Parameters
188+
# Workaround to prevent the query string processor from adding a 'recurringinvoiceid=' parameter by removing it from the set parameters.
189+
if ($RecurringInvoiceID) {
190+
$Parameters.Remove('RecurringInvoiceID') | Out-Null
191+
}
192+
# Similarly we don't want a `fullobjects=` parameter
193+
if ($FullObjects) {
194+
$Parameters.Remove('FullObjects') | Out-Null
195+
}
196+
try {
197+
if ($RecurringInvoiceID) {
198+
Write-Verbose "Running in single-invoice mode because '-RecurringInvoiceID' was provided."
199+
$QSCollection = New-HaloQuery -CommandName $CommandName -Parameters $Parameters
200+
$Resource = "api/RecurringInvoice/$($RecurringInvoiceID)"
201+
$RequestParams = @{
202+
Method = 'GET'
203+
Resource = $Resource
204+
AutoPaginateOff = $True
205+
QSCollection = $QSCollection
206+
ResourceType = 'invoices'
207+
}
208+
} else {
209+
Write-Verbose 'Running in multi-invoice mode.'
210+
$QSCollection = New-HaloQuery -CommandName $CommandName -Parameters $Parameters -IsMulti
211+
$Resource = 'api/RecurringInvoice'
212+
$RequestParams = @{
213+
Method = 'GET'
214+
Resource = $Resource
215+
AutoPaginateOff = $Paginate
216+
QSCollection = $QSCollection
217+
ResourceType = 'invoices'
218+
}
219+
}
220+
$InvoiceResults = New-HaloGETRequest @RequestParams
221+
# Fetch the complete details for each ticket
222+
if ($FullObjects) {
223+
$AllTicketResults = $InvoiceResults | ForEach-Object {
224+
Get-HaloRecurringInvoice -RecurringInvoiceID $_.id
225+
}
226+
$InvoiceResults = $AllTicketResults
227+
}
228+
Return $InvoiceResults
229+
} catch {
230+
New-HaloError -ErrorRecord $_
231+
}
148232
}

0 commit comments

Comments
 (0)