Overview

The Pay Stub model extracts and structures information from pay stubs, including employee and employer information, pay period details, and financial calculations.

Schema Structure

Employee Information

FieldTypeDescription
EmployeeAddressstring?Address of the employee
EmployeeNamestring?Name of the employee
EmployeeSSNstring?Social security number

Employer Information

FieldTypeDescription
EmployerAddressstring?Address of the employer
EmployerNamestring?Name of the employer

Pay Period Information

FieldTypeDescription
PayDatestring?Date of salary payment
PayPeriodStartDatestring?Start date of the pay period
PayPeriodEndDatestring?End date of the pay period

Current Period Amounts

FieldTypeDescription
CurrentPeriodGrossPaynumber?Gross pay of the current period
CurrentPeriodTaxesnumber?Taxes of the current period
CurrentPeriodDeductionsnumber?Deductions of the current period
CurrentPeriodNetPaynumber?Net pay of the current period

Year to Date Amounts

FieldTypeDescription
YearToDateGrossPaynumber?Year-to-date gross pay
YearToDateTaxesnumber?Year-to-date taxes
YearToDateDeductionsnumber?Year-to-date deductions
YearToDateNetPaynumber?Year-to-date net pay

Type Definitions

import type {
  PeriodAmounts,
  PayStub,
  PayStubResponse,
  StrictPayStubResponse
} from '@your-package/models';

Validation Rules

Basic Validation

  • All fields are optional by default

Strict Validation

The following fields are required in strict mode:

  • EmployeeName
  • EmployerName
  • PayDate
  • CurrentPeriodGrossPay
  • CurrentPeriodNetPay

Example Usage

import { validatePayStub } from '@your-package/models';

// Example pay stub data
const payStubData = {
  EmployeeName: "John A. Doe",
  EmployerName: "Contoso Corporation",
  PayDate: "2024-02-26",
  CurrentPeriodGrossPay: 744.10,
  CurrentPeriodTaxes: 410.10,
  CurrentPeriodDeductions: 0,
  CurrentPeriodNetPay: 334.00,
  YearToDateGrossPay: 2744.10,
  YearToDateTaxes: 855.90,
  YearToDateDeductions: 0,
  YearToDateNetPay: 1888.20
};

// Validate the pay stub
const validatedPayStub = validatePayStub(payStubData);

// Access validated data through result property
console.log(validatedPayStub.result.CurrentPeriodNetPay);

Date Handling

The model accepts dates in multiple formats:

  • ISO 8601 datetime strings
  • YYYY-MM-DD format

All dates are converted to ISO format during validation.

Best Practices

  1. Always validate pay stubs:
const payStub = validatePayStub(payStubData);
  1. Access data through the result property:
const netPay = payStub.result.CurrentPeriodNetPay;
  1. Handle optional fields appropriately:
const taxes = payStub.result.CurrentPeriodTaxes || 0;
  1. Verify required fields in strict mode:
if (!payStub.result.EmployeeName || !payStub.result.PayDate) {
  // Handle missing required fields
}
  1. Calculate totals carefully:
const netPay = (payStub.result.CurrentPeriodGrossPay || 0) - 
               (payStub.result.CurrentPeriodTaxes || 0) - 
               (payStub.result.CurrentPeriodDeductions || 0);