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. .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 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 -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()] [string]$Budget, [Parameter()] [string]$DataPath ) process { $resolvedPath = Resolve-DataPath -DataPath $DataPath -Budget $Budget if (-not $resolvedPath) { return } $biller = [Biller]::new($Name, $StartDate, $Frequency, $Amount) $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" return $biller } } } |