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.
Sourcepub fn generate_with_changes(
&mut self,
company_code: &str,
employees: &[(String, Decimal, Option<String>, Option<String>)],
period_start: NaiveDate,
period_end: NaiveDate,
currency: &str,
changes: &[EmployeeChangeEvent],
) -> (PayrollRun, Vec<PayrollLineItem>)
pub fn generate_with_changes( &mut self, company_code: &str, employees: &[(String, Decimal, Option<String>, Option<String>)], period_start: NaiveDate, period_end: NaiveDate, currency: &str, changes: &[EmployeeChangeEvent], ) -> (PayrollRun, Vec<PayrollLineItem>)
Generate a payroll run, adjusting each employee’s salary based on
EmployeeChangeEvent records before delegating to generate.
For each employee, all SalaryAdjustment events whose effective_date
falls on or before period_end are examined. The most recent such
event determines the effective annual salary for the period (prorated
when the effective date falls mid-period).
§Arguments
company_code- Company code owning the payrollemployees- Slice of (employee_id, base_annual_salary, cost_center, department)period_start- Start of the pay period (inclusive)period_end- End of the pay period (inclusive)currency- ISO 4217 currency codechanges- Employee change history to apply
Auto Trait Implementations§
impl !Freeze for PayrollGenerator
impl RefUnwindSafe for PayrollGenerator
impl Send for PayrollGenerator
impl Sync for PayrollGenerator
impl Unpin for PayrollGenerator
impl UnsafeUnpin for PayrollGenerator
impl UnwindSafe for PayrollGenerator
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.