Skip to main content

PayrollGenerator

Struct PayrollGenerator 

Source
pub struct PayrollGenerator { /* private fields */ }
Expand description

Generates PayrollRun and PayrollLineItem records from employee data.

Implementations§

Source§

impl PayrollGenerator

Source

pub fn new(seed: u64) -> Self

Create a new payroll generator with default configuration.

Source

pub fn with_config(seed: u64, config: PayrollConfig) -> Self

Create a payroll generator with custom configuration.

Source

pub fn with_pools( self, employee_ids: Vec<String>, cost_center_ids: Vec<String>, ) -> Self

Set ID pools for cross-reference coherence.

When pools are non-empty, the generator selects approved_by and posted_by from employee_ids instead of fabricating placeholder IDs.

Source

pub fn set_country_pack(&mut self, pack: CountryPack)

Set the country pack for localized deduction labels.

When a country pack is set, generated PayrollLineItem records will carry localized deduction labels derived from the pack’s payroll.statutory_deductions and payroll.employer_contributions. The stored pack is also used by [generate] to resolve deduction rates, so callers no longer need to pass the pack explicitly.

Source

pub fn generate( &mut self, company_code: &str, employees: &[(String, Decimal, Option<String>, Option<String>)], period_start: NaiveDate, period_end: NaiveDate, currency: &str, ) -> (PayrollRun, Vec<PayrollLineItem>)

Generate a payroll run and line items for the given employees and period.

Uses tax rates from the PayrollConfig (defaults: 22% federal, 5% state, 7.65% FICA, 3% health, 5% retirement). If a country pack has been set via [set_country_pack], the stored pack is used to resolve both rates and localized deduction labels automatically.

§Arguments
  • company_code - Company code owning the payroll
  • employees - Slice of (employee_id, base_salary, cost_center, department)
  • period_start - Start of the pay period (inclusive)
  • period_end - End of the pay period (inclusive)
  • currency - ISO 4217 currency code
Source

pub fn generate_with_country_pack( &mut self, company_code: &str, employees: &[(String, Decimal, Option<String>, Option<String>)], period_start: NaiveDate, period_end: NaiveDate, currency: &str, pack: &CountryPack, ) -> (PayrollRun, Vec<PayrollLineItem>)

Generate a payroll run using statutory deduction rates from a country pack.

Iterates over pack.payroll.statutory_deductions to resolve rates by deduction code / English name. Any rate not found in the pack falls back to the corresponding value from the generator’s PayrollConfig.

§Deduction mapping
Pack code / name_en patternResolves to
FIT, LOHNST, or *Income Tax* (not state)federal income tax
SIT or *State Income Tax*state income tax
FICA or *Social Security*FICA / social security
*Health Insurance*health insurance
*Pension* or *Retirement*retirement / pension

For packs that have many small deductions (e.g. DE with pension, health, unemployment, long-term care, solidarity surcharge, church tax), the rates are summed into the closest category. Deductions not matching any category above are accumulated into the FICA/social-security bucket.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more