Public/New-Biller.ps1
|
function New-Biller { <# .SYNOPSIS Creates a new biller entry. .DESCRIPTION Creates a new biller with specified name, start date, frequency, and amount. The biller is saved to the data store and associated with an account. .PARAMETER Name The name of the biller. .PARAMETER StartDate The date when the billing starts. .PARAMETER Frequency How often the bill occurs (Daily, Weekly, BiWeekly, Monthly, Quarterly, Yearly). .PARAMETER Amount The amount of the bill. .PARAMETER Account The account name to associate with this biller. If only one account exists, it will be auto-selected. If the account doesn't exist, it will be created. .PARAMETER Budget Optional budget name to target. Uses active budget if not specified. .PARAMETER DataPath Optional custom path for data storage. Overrides budget-based paths. .EXAMPLE New-Biller -Name "Electric Bill" -StartDate "2025-01-01" -Frequency Monthly -Amount 125.00 .EXAMPLE New-Biller -Name "Rent" -StartDate "2025-01-01" -Frequency Monthly -Amount 1200 -Account "Chase Checking" .EXAMPLE New-Biller -Name "Internet" -StartDate "2025-01-01" -Frequency Monthly -Amount 80 -Budget "daily-expenses" .OUTPUTS Biller object #> [CmdletBinding()] param( [Parameter(Mandatory, ValueFromPipelineByPropertyName)] [string]$Name, [Parameter(Mandatory, ValueFromPipelineByPropertyName)] [datetime]$StartDate, [Parameter(Mandatory, ValueFromPipelineByPropertyName)] [ValidateSet('Daily', 'Weekly', 'BiWeekly', 'Monthly', 'Bimonthly', 'Quarterly', 'Yearly')] [string]$Frequency, [Parameter(Mandatory, ValueFromPipelineByPropertyName)] [decimal]$Amount, [Parameter(ValueFromPipelineByPropertyName)] [string]$Account, [Parameter()] [string]$Budget, [Parameter()] [string]$DataPath ) process { $resolvedPath = Resolve-DataPath -DataPath $DataPath -Budget $Budget if (-not $resolvedPath) { return } # Resolve account parameter $accountId = Resolve-AccountParameter -Account $Account -DataPath $resolvedPath -CallingCmdlet $PSCmdlet if (-not $accountId) { return } $biller = [Biller]::new($Name, $StartDate, $Frequency, $Amount, $accountId) $existingBillers = Read-EntityData -EntityType 'Biller' -DataPath $resolvedPath $billersList = [System.Collections.ArrayList]@($existingBillers) $billersList.Add($biller.ToHashtable()) | Out-Null if (Write-EntityData -EntityType 'Biller' -Data $billersList -DataPath $resolvedPath) { Write-Verbose "Created biller: $Name (Account: $accountId)" return $biller } } } |