Skip to content

Commit

Permalink
Display pay modifier object on tab content
Browse files Browse the repository at this point in the history
  • Loading branch information
CaitBarnard committed Dec 12, 2024
1 parent bda4dc4 commit 8aa6f11
Show file tree
Hide file tree
Showing 7 changed files with 106 additions and 16 deletions.
18 changes: 17 additions & 1 deletion front_end/src/Apps/Payroll.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import EditPayModifier from "../Components/EditPayroll/EditPayModifier";

const initialPayrollState = [];
const initialVacanciesState = [];
const initialPayModifiersState = [];

export default function Payroll() {
const [allPayroll, dispatch] = useReducer(
Expand All @@ -23,6 +24,10 @@ export default function Payroll() {
vacanciesReducer,
initialVacanciesState,
);
const [payModifiers, dispatchPayModifiers] = useReducer(
payModifiersReducer,
initialPayModifiersState,
);
const [saveSuccess, setSaveSuccess] = useState(false);

useEffect(() => {
Expand All @@ -36,6 +41,9 @@ export default function Payroll() {
api
.getVacancyData()
.then((data) => dispatchVacancies({ type: "fetched", data }));
api
.getPayModifierData()
.then((data) => dispatchPayModifiers({ type: "fetched", data }));
}, []);

// Computed properties
Expand Down Expand Up @@ -116,7 +124,7 @@ export default function Payroll() {
</a>
</Tab>
<Tab label="Pay Modifiers" key="2">
<EditPayModifier />
<EditPayModifier data={payModifiers} />
</Tab>
</Tabs>
<button className="govuk-button" onClick={handleSavePayroll}>
Expand Down Expand Up @@ -151,5 +159,13 @@ const positionReducer = (data, action) => {
}
};

const payModifiersReducer = (data, action) => {
switch (action.type) {
case "fetched": {
return action.data;
}
}
};

const payrollReducer = (data, action) => positionReducer(data, action);
const vacanciesReducer = (data, action) => positionReducer(data, action);
42 changes: 27 additions & 15 deletions front_end/src/Components/EditPayroll/EditPayModifier/index.jsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,33 @@
import { monthsToTitleCase } from "../../../Util";

const EditPayModifier = ({ pay_modifier }) => {
const EditPayModifier = ({ data }) => {
return (
<table className="govuk-table">
<thead className="govuk-table__head">
<tr className="govuk-table__row">
{monthsToTitleCase.map((header) => {
return (
<th scope="col" className="govuk-table__header" key={header}>
{header}
</th>
);
})}
</tr>
</thead>
<tbody className="govuk-table__body"></tbody>
</table>
data.length > 0 && (
<table className="govuk-table">
<thead className="govuk-table__head">
<tr className="govuk-table__row">
{monthsToTitleCase.map((header) => {
return (
<th scope="col" className="govuk-table__header" key={header}>
{header}
</th>
);
})}
</tr>
</thead>
<tbody className="govuk-table__body">
<tr className="govuk-table__row">
{data[0].pay_modifiers.map((value, index) => {
return (
<td className="govuk-table__cell" key={index}>
{value}
</td>
);
})}
</tr>
</tbody>
</table>
)
);
};

Expand Down
10 changes: 10 additions & 0 deletions front_end/src/Components/EditPayroll/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,16 @@ export function postVacancyData(vacancyData) {
);
}

/**
* Fetch pay modifier data and return it as a promise.
* @returns {Promise<types.PayModifierData[]>} A promise resolving to an array of objects containing pay modifier information.
*/
export function getPayModifierData() {
return getData(getPayrollApiUrl() + "pay_modifiers/").then(
(data) => data.data,
);
}

/**
* Return the payroll API URL.
*
Expand Down
6 changes: 6 additions & 0 deletions front_end/src/Components/EditPayroll/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,10 @@
* @property {boolean[]} pay_periods - Whether the vacancy is being paid in periods.
*/

/**
* @typedef {Object} PayModifierData
* @property {string} id - The pay modifier's pk.
* @property {float[]} pay_modifiers - The pay modifier's monthly percentages
*/

export const Types = {};
33 changes: 33 additions & 0 deletions payroll/services/payroll.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,3 +329,36 @@ def update_vacancies_data(
)
pay_periods.periods = vacancy["pay_periods"]
pay_periods.save()


class PayModifiers(TypedDict):
id: int
pay_modifiers: list[float]


def get_pay_modifiers_data(
cost_centre: CostCentre,
financial_year: FinancialYear,
) -> Iterator[PayModifiers]:
qs = Attrition.objects.filter(
cost_centre=cost_centre,
financial_year=financial_year,
)
for obj in qs:
yield PayModifiers(
id=obj.pk,
pay_modifiers=[
obj.apr,
obj.may,
obj.jun,
obj.jul,
obj.aug,
obj.sep,
obj.oct,
obj.nov,
obj.dec,
obj.jan,
obj.feb,
obj.mar,
],
)
5 changes: 5 additions & 0 deletions payroll/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,9 @@
views.delete_vacancy_page,
name="delete_vacancy",
),
path(
"api/<str:cost_centre_code>/<int:financial_year>/pay_modifiers/",
views.PayModifierView.as_view(),
name="api_pay_modifiers",
),
]
8 changes: 8 additions & 0 deletions payroll/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,14 @@ def post_data(self, data):
)


class PayModifierView(PositionView):
def get_data(self):
return payroll_service.get_pay_modifiers_data(
self.cost_centre,
self.financial_year,
)


def redirect_edit_payroll(cost_centre_code, financial_year):
return redirect(
"payroll:edit",
Expand Down

0 comments on commit 8aa6f11

Please sign in to comment.