Skip to content
This repository was archived by the owner on Jul 22, 2024. It is now read-only.

Commit f179c9e

Browse files
author
Isaiah Williams
authored
Simplifying the unbilled invoice line item operations (#242)
1 parent 4963f89 commit f179c9e

7 files changed

Lines changed: 225 additions & 61 deletions

ChangeLog.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@
2626
* Added the [Register-PartnerTokenCache](https://docs.microsoft.com/powershell/module/partnercenter/Register-PartnerTokenCache) to create, and delete, the control file that determines if a in-memory token cache should be used instead of the default persistent token cache
2727
* Addressed an issue where an InvalidOperationException exception was being encountering with the [Connect-PartnerCenter](https://docs.microsoft.com/powershell/module/partnercenter/New-PartnerAccessToken) and [New-PartnerAccessToken](https://docs.microsoft.com/powershell/module/partnercenter/New-PartnerAccessToken) commands when specifying an environment
2828
* Addressed issue [#234](https://github.com/microsoft/Partner-Center-PowerShell/issues/234) that was preventing the [New-PartnerAccessToken](https://docs.microsoft.com/powershell/module/partnercenter/New-PartnerAccessToken) command from executing successfully when being invoked through an Azure Function app
29+
* Invoice
30+
* Added the [Get-PartnerUnbilledInvoiceLineItem](https://docs.microsoft.com/powershell/module/partnercenter/Get-PartnerUnbilledInvoiceLineItem) command to get unbilled invoice line items
31+
* Removed the `Period` parameter from the [Get-PartnerInvoiceLineItem](https://docs.microsoft.com/powershell/module/partnercenter/Get-PartnerInvoiceLineItem) command because the functionality it enabled has been replaced with the [Get-PartnerUnbilledInvoiceLineItem](https://docs.microsoft.com/powershell/module/partnercenter/Get-PartnerUnbilledInvoiceLineItem) command
2932
* Product Upgrades
3033
* Addressed an issue with starting the upgrade process for an Azure Plan
3134
* Subscription

docs/help/Get-PartnerInvoiceLineItem.md

Lines changed: 9 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,11 @@ Gets the line items for the specified invoice.
1414

1515
## SYNTAX
1616

17-
### ByInvoice (Default)
1817
```powershell
1918
Get-PartnerInvoiceLineItem -BillingProvider <BillingProvider> [-CurrencyCode <String>] -InvoiceId <String>
2019
-LineItemType <InvoiceLineItemType> [<CommonParameters>]
2120
```
2221

23-
### ByBillingPeriod
24-
```powershell
25-
Get-PartnerInvoiceLineItem -BillingProvider <BillingProvider> [-CurrencyCode <String>] -InvoiceId <String>
26-
-LineItemType <InvoiceLineItemType> -Period <BillingPeriod> [<CommonParameters>]
27-
```
28-
2922
## DESCRIPTION
3023
Gets the line items for the specified invoice.
3124

@@ -102,22 +95,6 @@ Accept pipeline input: False
10295
Accept wildcard characters: False
10396
```
10497
105-
### -Period
106-
The billing period for the line items.
107-
108-
```yaml
109-
Type: BillingPeriod
110-
Parameter Sets: ByBillingPeriod
111-
Aliases:
112-
Accepted values: Current, Previous
113-
114-
Required: True
115-
Position: Named
116-
Default value: None
117-
Accept pipeline input: False
118-
Accept wildcard characters: False
119-
```
120-
12198
### CommonParameters
12299
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216).
123100
@@ -127,7 +104,15 @@ This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable
127104
128105
## OUTPUTS
129106
130-
### Microsoft.Store.PartnerCenter.PowerShell.Models.Invoices.PSInvoiceLineItem
107+
### Microsoft.Store.PartnerCenter.PowerShell.Models.Invoices.PSDailyRatedUsageLineItem
108+
109+
### Microsoft.Store.PartnerCenter.PowerShell.Models.Invoices.PSDailyUsageLineItem
110+
111+
### Microsoft.Store.PartnerCenter.PowerShell.Models.Invoices.PSLicenseBasedLineItem
112+
113+
### Microsoft.Store.PartnerCenter.PowerShell.Models.Invoices.PSOneTimeInvoiceLineItem
114+
115+
### Microsoft.Store.PartnerCenter.PowerShell.Models.Invoices.PSUsageBasedLineItem
131116
132117
## NOTES
133118
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
---
2+
content_git_url: https://github.com/Microsoft/Partner-Center-PowerShell/blob/master/docs/help/Get-PartnerUnbilledInvoiceLineItem.md
3+
external help file: Microsoft.Store.PartnerCenter.PowerShell.dll-Help.xml
4+
Module Name: PartnerCenter
5+
online version: https://docs.microsoft.com/powershell/module/partnercenter/Get-PartnerUnbilledInvoiceLineItem
6+
original_content_git_url: https://github.com/Microsoft/Partner-Center-PowerShell/blob/master/docs/help/Get-PartnerUnbilledInvoiceLineItem.md
7+
schema: 2.0.0
8+
---
9+
10+
# Get-PartnerUnbilledInvoiceLineItem
11+
12+
## SYNOPSIS
13+
Gets the unbilled invoice line items.
14+
15+
## SYNTAX
16+
17+
```powershell
18+
Get-PartnerUnbilledInvoiceLineItem -CurrencyCode <String> -LineItemType <InvoiceLineItemType>
19+
-Period <BillingPeriod> [<CommonParameters>]
20+
```
21+
22+
## DESCRIPTION
23+
Gets the unbilled invoice line items.
24+
25+
## EXAMPLES
26+
27+
### Example 1
28+
```powershell
29+
PS C:\> Get-PartnerUnbilledInvoiceLineItem -CurrencyCode USD -LineItemType BillingLineItems -Period Current
30+
```
31+
32+
Gets reconciliation line items for the current billing period that have not been billed. The current billing period is defined as the current month.
33+
34+
### Example 2
35+
```powershell
36+
PS C:\> Get-PartnerUnbilledInvoiceLineItem -CurrencyCode USD -LineItemType BillingLineItems -Period Pervious
37+
```
38+
39+
Gets reconciliation line items for the pervious billing period that have not been billed. The pervious billing period is defined as the pervious month.
40+
41+
### Example 3
42+
```powershell
43+
PS C:\> Get-PartnerUnbilledInvoiceLineItem -CurrencyCode USD -LineItemType UsageLineItems -Period Current
44+
```
45+
46+
Gets consumption line items for the current billing period that have not been billed. The current billing period is defined as the current month.
47+
48+
### Example 4
49+
```powershell
50+
PS C:\> Get-PartnerUnbilledInvoiceLineItem -CurrencyCode USD -LineItemType UsageLineItems -Period Pervious
51+
```
52+
53+
Gets consumption line items for the pervious billing period that have not been billed. The pervious billing period is defined as the pervious month.
54+
55+
## PARAMETERS
56+
57+
### -CurrencyCode
58+
The currency code for the unbilled line items.
59+
60+
```yaml
61+
Type: String
62+
Parameter Sets: (All)
63+
Aliases:
64+
65+
Required: True
66+
Position: Named
67+
Default value: None
68+
Accept pipeline input: False
69+
Accept wildcard characters: False
70+
```
71+
72+
### -LineItemType
73+
The type of invoice line items.
74+
75+
```yaml
76+
Type: InvoiceLineItemType
77+
Parameter Sets: (All)
78+
Aliases:
79+
Accepted values: BillingLineItems, UsageLineItems
80+
81+
Required: True
82+
Position: Named
83+
Default value: None
84+
Accept pipeline input: False
85+
Accept wildcard characters: False
86+
```
87+
88+
### -Period
89+
The billing period for the line items.
90+
91+
```yaml
92+
Type: BillingPeriod
93+
Parameter Sets: (All)
94+
Aliases:
95+
Accepted values: Current, Previous
96+
97+
Required: True
98+
Position: Named
99+
Default value: None
100+
Accept pipeline input: False
101+
Accept wildcard characters: False
102+
```
103+
104+
### CommonParameters
105+
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216).
106+
107+
## INPUTS
108+
109+
### None
110+
111+
## OUTPUTS
112+
113+
### Microsoft.Store.PartnerCenter.PowerShell.Models.Invoices.PSOneTimeInvoiceLineItem
114+
115+
### Microsoft.Store.PartnerCenter.PowerShell.Models.Invoices.PSDailyRatedUsageLineItem
116+
117+
## NOTES
118+
119+
## RELATED LINKS

docs/help/PartnerCenter.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,9 @@ Gets a list of service request topics.
245245
### [Get-PartnerSupportProfile](Get-PartnerSupportProfile.md)
246246
Gets the partner's support profile.
247247

248+
### [Get-PartnerUnbilledInvoiceLineItem](Get-PartnerUnbilledInvoiceLineItem.md)
249+
Gets the unbilled invoice line items.
250+
248251
### [Get-PartnerUser](Get-PartnerUser.md)
249252
Gets a list of users from the partner tenant
250253

src/PowerShell/Commands/GetPartnerInvoiceLineItem.cs

Lines changed: 12 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -3,72 +3,54 @@
33

44
namespace Microsoft.Store.PartnerCenter.PowerShell.Commands
55
{
6-
using System;
76
using System.Collections.Generic;
87
using System.Linq;
98
using System.Management.Automation;
109
using Models.Authentication;
10+
using Models.Invoices;
1111
using PartnerCenter.Enumerators;
1212
using PartnerCenter.Models;
1313
using PartnerCenter.Models.Invoices;
14-
using PartnerCenter.PowerShell.Models.Invoices;
1514

1615
/// <summary>
1716
/// Gets a list of line items for the specified invoice from Partner Center.
1817
/// </summary>
19-
[Cmdlet(VerbsCommon.Get, "PartnerInvoiceLineItem", DefaultParameterSetName = ByInvoiceParameterSet)]
20-
[OutputType(typeof(PSInvoiceLineItem))]
18+
[Cmdlet(VerbsCommon.Get, "PartnerInvoiceLineItem")]
19+
[OutputType(typeof(PSDailyRatedUsageLineItem))]
20+
[OutputType(typeof(PSDailyUsageLineItem))]
21+
[OutputType(typeof(PSLicenseBasedLineItem))]
22+
[OutputType(typeof(PSOneTimeInvoiceLineItem))]
23+
[OutputType(typeof(PSUsageBasedLineItem))]
2124
public class GetPartnerInvoiceLineItem : PartnerAsyncCmdlet
2225
{
23-
/// <summary>
24-
/// Name for the by invoice parameter set.
25-
/// </summary>
26-
private const string ByInvoiceParameterSet = "ByInvoice";
27-
28-
/// <summary>
29-
/// Name for the by billing period parameter set.
30-
/// </summary>
31-
private const string ByBillingPeriodParameterSet = "ByBillingPeriod";
32-
3326
/// <summary>
3427
/// Gets or sets the billing provider.
3528
/// </summary>
36-
[Parameter(HelpMessage = "The billing provide for the line items.", Mandatory = true, ParameterSetName = ByBillingPeriodParameterSet)]
37-
[Parameter(HelpMessage = "The billing provide for the line items.", Mandatory = true, ParameterSetName = ByInvoiceParameterSet)]
29+
[Parameter(HelpMessage = "The billing provide for the line items.", Mandatory = true)]
3830
[ValidateSet(nameof(BillingProvider.All), nameof(BillingProvider.Azure), nameof(BillingProvider.Office), nameof(BillingProvider.OneTime), nameof(BillingProvider.Marketplace))]
3931
public BillingProvider BillingProvider { get; set; }
4032

4133
/// <summary>
4234
/// Gets or sets the currenty code.
4335
/// </summary>
44-
[Parameter(HelpMessage = "The currency code for the unbilled line items.", Mandatory = false, ParameterSetName = ByBillingPeriodParameterSet)]
45-
[Parameter(HelpMessage = "The currency code for the unbilled line items.", Mandatory = false, ParameterSetName = ByInvoiceParameterSet)]
36+
[Parameter(HelpMessage = "The currency code for the unbilled line items.", Mandatory = false)]
4637
[ValidateNotNull]
4738
public string CurrencyCode { get; set; }
4839

4940
/// <summary>
5041
/// Gets or set the identifier for the invoice.
5142
/// </summary>
52-
[Parameter(HelpMessage = "The identifier corresponding to the invoice.", Mandatory = true, ParameterSetName = ByBillingPeriodParameterSet)]
53-
[Parameter(HelpMessage = "The identifier corresponding to the invoice.", Mandatory = true, ParameterSetName = ByInvoiceParameterSet)]
43+
[Parameter(HelpMessage = "The identifier corresponding to the invoice.", Mandatory = true)]
5444
[ValidateNotNullOrEmpty]
5545
public string InvoiceId { get; set; }
5646

5747
/// <summary>
5848
/// Gets or sets the invoice line item type.
5949
/// </summary>
60-
[Parameter(HelpMessage = "The type of invoice line items.", Mandatory = true, ParameterSetName = ByBillingPeriodParameterSet)]
61-
[Parameter(HelpMessage = "The type of invoice line items.", Mandatory = true, ParameterSetName = ByInvoiceParameterSet)]
50+
[Parameter(HelpMessage = "The type of invoice line items.", Mandatory = true)]
6251
[ValidateSet(nameof(InvoiceLineItemType.BillingLineItems), nameof(InvoiceLineItemType.UsageLineItems))]
6352
public InvoiceLineItemType LineItemType { get; set; }
6453

65-
/// <summary>
66-
/// Gets or sets the billing period.
67-
/// </summary>
68-
[Parameter(HelpMessage = "The billing period for the line items.", Mandatory = true, ParameterSetName = ByBillingPeriodParameterSet)]
69-
[ValidateSet(nameof(BillingPeriod.Current), nameof(BillingPeriod.Previous))]
70-
public BillingPeriod Period { get; set; }
71-
7254
/// <summary>
7355
/// Executes the operations associated with the cmdlet.
7456
/// </summary>
@@ -81,14 +63,7 @@ public override void ExecuteCmdlet()
8163
List<InvoiceLineItem> items;
8264
ResourceCollection<InvoiceLineItem> lineItems;
8365

84-
if (ParameterSetName.Equals(ByBillingPeriodParameterSet, StringComparison.InvariantCultureIgnoreCase))
85-
{
86-
lineItems = await partner.Invoices[InvoiceId].By(BillingProvider, LineItemType, CurrencyCode, Period).GetAsync().ConfigureAwait(false);
87-
}
88-
else
89-
{
90-
lineItems = await partner.Invoices[InvoiceId].By(BillingProvider, LineItemType).GetAsync().ConfigureAwait(false);
91-
}
66+
lineItems = await partner.Invoices[InvoiceId].By(BillingProvider, LineItemType).GetAsync().ConfigureAwait(false);
9267

9368
enumerator = partner.Enumerators.InvoiceLineItems.Create(lineItems);
9469
items = new List<InvoiceLineItem>();
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3+
4+
namespace Microsoft.Store.PartnerCenter.PowerShell.Commands
5+
{
6+
using System.Collections.Generic;
7+
using System.Linq;
8+
using System.Management.Automation;
9+
using Enumerators;
10+
using Models.Authentication;
11+
using Models.Invoices;
12+
using PartnerCenter.Models;
13+
using PartnerCenter.Models.Invoices;
14+
15+
/// <summary>
16+
/// Gets unbilled invoice line items from Partner Center.
17+
/// </summary>
18+
[Cmdlet(VerbsCommon.Get, "PartnerUnbilledInvoiceLineItem")]
19+
[OutputType(typeof(PSOneTimeInvoiceLineItem))]
20+
[OutputType(typeof(PSDailyRatedUsageLineItem))]
21+
public class GetPartnerUnbilledInvoiceLineItem : PartnerAsyncCmdlet
22+
{
23+
/// <summary>
24+
/// Gets or sets the currency code.
25+
/// </summary>
26+
[Parameter(HelpMessage = "The currency code for the unbilled line items.", Mandatory = true)]
27+
[ValidateNotNull]
28+
public string CurrencyCode { get; set; }
29+
30+
/// <summary>
31+
/// Gets or sets the type of invoice line items.
32+
/// </summary>
33+
[Parameter(HelpMessage = "The type of invoice line items.", Mandatory = true)]
34+
[ValidateSet(nameof(InvoiceLineItemType.BillingLineItems), nameof(InvoiceLineItemType.UsageLineItems))]
35+
public InvoiceLineItemType LineItemType { get; set; }
36+
37+
/// <summary>
38+
/// Gets or sets the billing period.
39+
/// </summary>
40+
[Parameter(HelpMessage = "The billing period for the line items.", Mandatory = true)]
41+
[ValidateSet(nameof(BillingPeriod.Current), nameof(BillingPeriod.Previous))]
42+
public BillingPeriod Period { get; set; }
43+
44+
/// <summary>
45+
/// Executes the operations associated with the cmdlet.
46+
/// </summary>
47+
public override void ExecuteCmdlet()
48+
{
49+
Scheduler.RunTask(async () =>
50+
{
51+
IPartner partner = await PartnerSession.Instance.ClientFactory.CreatePartnerOperationsAsync().ConfigureAwait(false);
52+
IResourceCollectionEnumerator<ResourceCollection<InvoiceLineItem>> enumerator;
53+
List<InvoiceLineItem> items;
54+
ResourceCollection<InvoiceLineItem> lineItems;
55+
56+
lineItems = await partner.Invoices["Unbilled"].By(BillingProvider.OneTime, LineItemType, CurrencyCode, Period).GetAsync().ConfigureAwait(false);
57+
enumerator = partner.Enumerators.InvoiceLineItems.Create(lineItems);
58+
items = new List<InvoiceLineItem>();
59+
60+
while (enumerator.HasValue)
61+
{
62+
items.AddRange(enumerator.Current.Items);
63+
await enumerator.NextAsync().ConfigureAwait(false);
64+
}
65+
66+
if (LineItemType == InvoiceLineItemType.BillingLineItems)
67+
{
68+
WriteObject(items.Select(i => new PSOneTimeInvoiceLineItem((OneTimeInvoiceLineItem)i)), true);
69+
}
70+
else
71+
{
72+
WriteObject(items.Select(i => new PSDailyRatedUsageLineItem((DailyRatedUsageLineItem)i)), true);
73+
}
74+
75+
}, true);
76+
}
77+
}
78+
}

src/PowerShell/PartnerCenter.psd1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@
173173
'Get-PartnerServiceRequest',
174174
'Get-PartnerServiceRequestTopic',
175175
'Get-PartnerSupportProfile',
176+
'Get-PartnerUnbilledInvoiceLineItem',
176177
'Get-PartnerUser',
177178
'Get-PartnerUserSignInActivity',
178179
'Get-PartnerValidationCode',

0 commit comments

Comments
 (0)