Skip to content

Commit fdf94dc

Browse files
committed
fix bonus allocation
1 parent 7afee5e commit fdf94dc

3 files changed

Lines changed: 20 additions & 9 deletions

File tree

src/components/IncomeAllocationCalendar.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,9 @@ export const IncomeAllocationCalendar: React.FC<IncomeAllocationCalendarProps> =
9696
// Calculate regular income for this day
9797
regularIncome = dailyRegularRate;
9898

99-
// Add any bonuses for this specific date
99+
// Add any bonuses for this specific date (bonuses go to whatever state person was working in)
100100
formData.bonuses.forEach(bonus => {
101-
if (bonus.date === dateStr && bonus.state === dayState) {
101+
if (bonus.date === dateStr) {
102102
bonusIncome += parseFloat(String(bonus.amount || 0));
103103
}
104104
});

src/components/ResultsPanel.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,9 @@ const generatePDF = (results: ResultData[] | null, mnSettings: TaxSettings, form
8181

8282
income = dailyRegularRate;
8383

84-
// Add bonuses for this date
84+
// Add bonuses for this date (bonuses go to whatever state person was working in)
8585
formData.bonuses.forEach(bonus => {
86-
if (bonus.date === dateStr && bonus.state === dayState) {
86+
if (bonus.date === dateStr) {
8787
income += parseFloat(String(bonus.amount || 0));
8888
}
8989
});

src/utils.ts

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -111,13 +111,24 @@ export function calculateAllocation(
111111
allocations[state].regularPay = (allocations[state].days || 0) * dailyRate;
112112
}
113113

114-
// Each bonus is its own gross pay, allocated to the state for its date
114+
// Each bonus is allocated to the state the person was working in on that date
115115
periodBonuses.forEach(bonus => {
116-
if (bonus.state) {
117-
if (!allocations[bonus.state]) {
118-
allocations[bonus.state] = { days: 0, regularPay: 0, bonus: 0, total: 0 };
116+
const bonusDate = new Date(bonus.date + 'T00:00:00');
117+
const dateStr = bonusDate.toISOString().split('T')[0];
118+
119+
// Determine which state the person was working in on this date
120+
let workingState = '';
121+
if (otherStateDaysMap.has(dateStr)) {
122+
workingState = otherStateDaysMap.get(dateStr)!;
123+
} else if (bonusDate >= primaryVisitStart && bonusDate <= primaryVisitEnd) {
124+
workingState = primaryState;
125+
}
126+
127+
if (workingState) {
128+
if (!allocations[workingState]) {
129+
allocations[workingState] = { days: 0, regularPay: 0, bonus: 0, total: 0 };
119130
}
120-
allocations[bonus.state].bonus += parseFloat(String(bonus.amount || 0));
131+
allocations[workingState].bonus += parseFloat(String(bonus.amount || 0));
121132
}
122133
});
123134

0 commit comments

Comments
 (0)