pub struct PayrollGenerator { /* private fields */ }Expand description
Generates PayrollRun and PayrollLineItem records from employee data.
Implementations§
Source§impl PayrollGenerator
impl PayrollGenerator
Sourcepub fn with_config(seed: u64, config: PayrollConfig) -> Self
pub fn with_config(seed: u64, config: PayrollConfig) -> Self
Create a payroll generator with custom configuration.
Sourcepub fn with_pools(
self,
employee_ids: Vec<String>,
cost_center_ids: Vec<String>,
) -> Self
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.
Sourcepub fn set_country_pack(&mut self, pack: CountryPack)
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.
Sourcepub 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>)
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 payrollemployees- 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
Sourcepub 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>)
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 pattern | Resolves 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.