#![recursion_limit = "1024"]
#![allow(unused_imports)]
pub mod domain;
pub mod infrastructure;
pub mod application;
pub mod presentation;
pub mod seeders;
pub mod exports;
pub use domain::entity::*;
pub use infrastructure::persistence::*;
pub use application::service::CompensationChangeService;
pub use application::service::PayrollEntryService;
pub use application::service::SalarySlipService;
pub use application::service::SalarySlipLineService;
pub use application::service::SalaryStructureService;
pub use application::service::SalaryComponentService;
pub mod request_pool;
pub use application::service::{
bpjs_kesehatan, bpjs_ketenagakerjaan, compute_statutory, overtime_pay, pph21, pph21_ter, thr,
AccountingPostEnvelope, ComputedSlipRequest, EmployeeStatutory, EmployeeStatutoryInputs,
GlPostAck, GlPostLine, GlPostRejected, GlPostSink, LoggingSink, NewComponent, NewPayrollEntry,
NewSalarySlip, NewStructure, OvertimeInputs, PayrollError, PayrollEvent, PayrollEventError,
PayrollEventSink, PayrollPayable, PayrollPosted, PayrollWriteService, PoolEmployeeStatutoryInputs,
PoolOvertimeInputs, PostOutcome, Pph21Method, RemitAck, RemitOutcome, RemittanceInstruction,
RemittanceSeamError, RemittanceSink, StatutoryAccounts, StatutoryConfig, StatutoryError,
UnwiredGlSink, UnwiredRemittance,
};
pub use presentation::http::create_guarded_payroll_routes;
use std::sync::Arc;
use axum::Router;
use sqlx::PgPool;
pub struct PayrollModule {
pub(crate) compensation_change_service: Arc<CompensationChangeService>,
pub(crate) payroll_entry_service: Arc<PayrollEntryService>,
pub(crate) salary_slip_service: Arc<SalarySlipService>,
pub(crate) salary_slip_line_service: Arc<SalarySlipLineService>,
pub(crate) salary_structure_service: Arc<SalaryStructureService>,
pub(crate) salary_component_service: Arc<SalaryComponentService>,
pub(crate) payroll_write_service: Arc<PayrollWriteService>,
}
impl PayrollModule {
pub fn builder() -> PayrollModuleBuilder {
PayrollModuleBuilder::new()
}
pub fn all_crud_routes(&self) -> Router {
use presentation::http::{
create_compensation_change_read_routes,
create_payroll_entry_routes,
create_salary_slip_routes,
create_salary_slip_line_routes,
create_salary_structure_routes,
create_salary_component_routes,
};
Router::new()
.merge(create_compensation_change_read_routes(self.compensation_change_service.clone()))
.merge(create_payroll_entry_routes(self.payroll_entry_service.clone()))
.merge(create_salary_slip_routes(self.salary_slip_service.clone()))
.merge(create_salary_slip_line_routes(self.salary_slip_line_service.clone()))
.merge(create_salary_structure_routes(self.salary_structure_service.clone()))
.merge(create_salary_component_routes(self.salary_component_service.clone()))
}
#[deprecated(note = "mounts unvalidated generic CRUD; prefer readonly_routes() + validated writes, or all_crud_routes() for the full/unguarded surface")]
pub fn routes(&self) -> Router {
self.all_crud_routes()
}
pub fn readonly_routes(&self) -> Router {
use presentation::http::{
create_compensation_change_read_routes,
create_payroll_entry_read_routes,
create_salary_slip_read_routes,
create_salary_slip_line_read_routes,
create_salary_structure_read_routes,
create_salary_component_read_routes,
};
Router::new()
.merge(create_compensation_change_read_routes(self.compensation_change_service.clone()))
.merge(create_payroll_entry_read_routes(self.payroll_entry_service.clone()))
.merge(create_salary_slip_read_routes(self.salary_slip_service.clone()))
.merge(create_salary_slip_line_read_routes(self.salary_slip_line_service.clone()))
.merge(create_salary_structure_read_routes(self.salary_structure_service.clone()))
.merge(create_salary_component_read_routes(self.salary_component_service.clone()))
}
pub fn payroll_write_service(&self) -> Arc<PayrollWriteService> {
self.payroll_write_service.clone()
}
pub fn with_payroll_write_service(mut self, svc: Arc<PayrollWriteService>) -> Self {
self.payroll_write_service = svc;
self
}
}
pub struct PayrollModuleBuilder {
db_pool: Option<PgPool>,
}
impl PayrollModuleBuilder {
pub fn new() -> Self {
Self {
db_pool: None,
}
}
pub fn with_database(mut self, pool: PgPool) -> Self {
self.db_pool = Some(pool);
self
}
pub fn build(self) -> anyhow::Result<PayrollModule> {
let db_pool = self.db_pool
.ok_or_else(|| anyhow::anyhow!("Database pool not configured"))?;
let compensation_change_repository = Arc::new(CompensationChangeRepository::new(db_pool.clone()));
let compensation_change_service = Arc::new(CompensationChangeService::with_repository(compensation_change_repository.clone()));
let payroll_entry_repository = Arc::new(PayrollEntryRepository::new(db_pool.clone()));
let payroll_entry_service = Arc::new(PayrollEntryService::with_repository(payroll_entry_repository.clone()));
let salary_slip_repository = Arc::new(SalarySlipRepository::new(db_pool.clone()));
let salary_slip_service = Arc::new(SalarySlipService::with_repository(salary_slip_repository.clone()));
let salary_slip_line_repository = Arc::new(SalarySlipLineRepository::new(db_pool.clone()));
let salary_slip_line_service = Arc::new(SalarySlipLineService::with_repository(salary_slip_line_repository.clone()));
let salary_structure_repository = Arc::new(SalaryStructureRepository::new(db_pool.clone()));
let salary_structure_service = Arc::new(SalaryStructureService::with_repository(salary_structure_repository.clone()));
let salary_component_repository = Arc::new(SalaryComponentRepository::new(db_pool.clone()));
let salary_component_service = Arc::new(SalaryComponentService::with_repository(salary_component_repository.clone()));
let payroll_write_service = Arc::new(PayrollWriteService::new(db_pool.clone()));
Ok(PayrollModule {
compensation_change_service,
payroll_entry_service,
salary_slip_service,
salary_slip_line_service,
salary_structure_service,
salary_component_service,
payroll_write_service,
})
}
}
impl Default for PayrollModuleBuilder {
fn default() -> Self {
Self::new()
}
}