Public/Set-Earning.ps1
|
function Set-Earning { <# .SYNOPSIS Updates an existing earning entry. .DESCRIPTION Modifies properties of an existing earning identified by ID. .PARAMETER Id The ID of the earning to update. .PARAMETER Name New name for the earning. .PARAMETER StartDate New start date for the earning. .PARAMETER Frequency New frequency for the earning. .PARAMETER Amount New amount for the earning. .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 Set-Earning -Id "abc123" -Amount 2750.00 .OUTPUTS Updated Earning object #> [CmdletBinding()] param( [Parameter(Mandatory, ValueFromPipelineByPropertyName)] [string]$Id, [Parameter()] [string]$Name, [Parameter()] [datetime]$StartDate, [Parameter()] [ValidateSet('Daily', 'Weekly', 'BiWeekly', 'Monthly', 'Bimonthly', 'Quarterly', 'Yearly')] [string]$Frequency, [Parameter()] [decimal]$Amount, [Parameter()] [string]$Budget, [Parameter()] [string]$DataPath ) process { $resolvedPath = Resolve-DataPath -DataPath $DataPath -Budget $Budget if (-not $resolvedPath) { return } $earnings = Read-EntityData -EntityType 'Earning' -DataPath $resolvedPath $earning = $earnings | Where-Object { $_.Id -eq $Id } if (-not $earning) { Write-Error "Earning with ID '$Id' not found." return } if ($PSBoundParameters.ContainsKey('Name')) { $earning.Name = $Name } if ($PSBoundParameters.ContainsKey('StartDate')) { $earning.StartDate = $StartDate } if ($PSBoundParameters.ContainsKey('Frequency')) { $earning.Frequency = $Frequency } if ($PSBoundParameters.ContainsKey('Amount')) { $earning.Amount = $Amount } if (Write-EntityData -EntityType 'Earning' -Data $earnings -DataPath $resolvedPath) { Write-Verbose "Updated earning: $($earning.Name)" return $earning } } } |