52 lines
No EOL
1.5 KiB
TypeScript
52 lines
No EOL
1.5 KiB
TypeScript
import { computed } from 'vue'
|
|
import { storeToRefs } from 'pinia'
|
|
import { allocatePayroll } from '~/types/members'
|
|
|
|
export function usePayrollAllocation() {
|
|
const membersStore = useMembersStore()
|
|
const policiesStore = usePoliciesStore()
|
|
const budgetStore = useBudgetStore()
|
|
|
|
const { members, payPolicy } = storeToRefs(membersStore)
|
|
const { equalHourlyWage, payrollOncostPct } = storeToRefs(policiesStore)
|
|
const { capacityTotals } = storeToRefs(membersStore)
|
|
|
|
// Calculate base payroll budget from hours and wage
|
|
const basePayrollBudget = computed(() => {
|
|
const totalHours = capacityTotals.value.targetHours || 0
|
|
const wage = equalHourlyWage.value || 0
|
|
return totalHours * wage
|
|
})
|
|
|
|
// Allocate payroll to members based on policy
|
|
const allocatedMembers = computed(() => {
|
|
if (members.value.length === 0 || basePayrollBudget.value === 0) {
|
|
return members.value
|
|
}
|
|
|
|
return allocatePayroll(
|
|
members.value,
|
|
payPolicy.value,
|
|
basePayrollBudget.value
|
|
)
|
|
})
|
|
|
|
// Total payroll with oncosts
|
|
const totalPayrollWithOncosts = computed(() => {
|
|
return basePayrollBudget.value * (1 + payrollOncostPct.value / 100)
|
|
})
|
|
|
|
// Update member planned pay when allocation changes
|
|
watchEffect(() => {
|
|
allocatedMembers.value.forEach(member => {
|
|
membersStore.setPlannedPay(member.id, member.monthlyPayPlanned || 0)
|
|
})
|
|
})
|
|
|
|
return {
|
|
basePayrollBudget,
|
|
allocatedMembers,
|
|
totalPayrollWithOncosts,
|
|
payPolicy
|
|
}
|
|
} |