Skip to content

Commit

Permalink
tidy up
Browse files Browse the repository at this point in the history
  • Loading branch information
SamDudley committed Oct 22, 2024
1 parent 7a56f3e commit 45ce6e1
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 42 deletions.
10 changes: 9 additions & 1 deletion front_end/src/Components/EditPayroll/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,20 @@ export function getPayrollData() {
* Post modified payroll data.
*
* @param {types.PayrollData[]} payrollData - Payroll data to be sent.
* @returns {import("../../Util").PostDataResponse} - Updated payroll data received.
* @returns {import("../../Util").PostDataResponse} Updated payroll data received.
*/
export function postPayrollData(payrollData) {
return postData(getPayrollApiUrl(), JSON.stringify(payrollData));
}

/**
* Return the payroll API URL.
*
* This function relies on the `costCentreCode` and `financialYear` being available on
* the `window` object.
*
* @returns {string} The payroll API URL.
*/
function getPayrollApiUrl() {
const costCentreCode = window.costCentreCode;
const financialYear = window.financialYear;
Expand Down
1 change: 0 additions & 1 deletion front_end/src/Components/EditPayroll/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ export default function EditPayroll({
];
return (
<>
<h1>Edit payroll</h1>
<PayrollTable
headers={headers}
payroll={payroll}
Expand Down
6 changes: 6 additions & 0 deletions front_end/src/Util.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ export const formatValue = (value) => {
return nfObject.format(pounds);
}

/**
* Make a HTTP request to fetch JSON data.
*
* @param {string} url The HTTP request URL for the API.
* @returns JSON response data.
*/
export async function getData(url) {
const request = new Request(
url,
Expand Down
18 changes: 12 additions & 6 deletions makefile
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ exec = docker compose exec
web := ${if $(shell docker ps -q -f name=web),$(exec) web,$(run) web}
db := ${if $(shell docker ps -q -f name=db),$(exec) db,$(run) db}

run-host = poetry run

manage = python manage.py

create-stub-data: # Create stub data for testing
Expand Down Expand Up @@ -83,26 +85,30 @@ superuser: # Create superuser

# Formatting
black-check: # Run black-check
$(run-no-deps) web black --check .
$(run-host) black --check .

black: # Run black
$(web) black .
$(run-host) black .

isort-check: # Run isort-check
$(web) isort --check .
$(run-host) isort --check .

isort: # Run isort
$(web) isort .
$(run-host) isort .

ruff-check: # Run ruff in check mode
$(run-host) ruff check

ruff: # Run ruff
$(web) ruff check
$(run-host) ruff check --fix .

check: # Run formatters to see if there are any errors
make ruff
make ruff-check
make black-check
make isort-check

fix: # Run formatters to fix any issues that can be fixed automatically
make ruff
make black
make isort

Expand Down
14 changes: 11 additions & 3 deletions payroll/services/payroll.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@ def create_employee_pay_periods(employee: Employee) -> None:
EmployeePayPeriods.objects.get_or_create(employee=employee, year=financial_year)


def payroll_forecast_report(
cost_centre: CostCentre, financial_year: FinancialYear
) -> None:
def payroll_forecast_report(cost_centre: CostCentre, financial_year: FinancialYear):

period_sum_annotations = {
f"period_{i+1}_sum": Sum(
Expand Down Expand Up @@ -82,6 +80,16 @@ def update_payroll_data(
financial_year: FinancialYear,
payroll_data: list[EmployeePayroll],
) -> None:
"""Update a cost centre payroll for a given year using the provided list.
This function is wrapped with a transaction, so if any of the payroll updates fail,
the whole batch will be rolled back.
Raises:
ValueError: If an employee_no is empty.
ValueError: If there are not 12 items in the pay_periods list.
ValueError: If any of the pay_periods are not of type bool.
"""
for payroll in payroll_data:
if not payroll["employee_no"]:
raise ValueError("employee_no is empty")
Expand Down
63 changes: 33 additions & 30 deletions payroll/templates/payroll/page/edit_payroll.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,39 +9,42 @@
{% endblock breadcrumbs %}

{% block content %}
<h1 class="govuk-heading-l">Edit payroll</h1>
<div id="payroll-app"></div>

<h1>Forecast</h1>


<h1 class="govuk-heading-l">Forecast</h1>
<p class="govuk-body-s">
This is a temporary table to demostrate the forecast figures. Eventually these
figures would end up in the "Edit forecast" table.
</p>
<table class="govuk-table">
<thead class="govuk-table__head">
<tr class="govuk-table__row">
<th scope="col" class="govuk-table__header">Pay type</th>
{% for month in months %}
<th scope="col" class="govuk-table__header">{{ month }}</th>
{% endfor %}
</tr>
</thead>
<tbody class="govuk-table__body">
{% for row in payroll_forecast_report %}
<tr class="govuk-table__row">
<th scope="row" class="govuk-table__header">{{ row.pay_element__type__group__name }}</th>
<td class="govuk-table__cell">{{ row.period_1_sum }}</td>
<td class="govuk-table__cell">{{ row.period_2_sum }}</td>
<td class="govuk-table__cell">{{ row.period_3_sum }}</td>
<td class="govuk-table__cell">{{ row.period_4_sum }}</td>
<td class="govuk-table__cell">{{ row.period_5_sum }}</td>
<td class="govuk-table__cell">{{ row.period_6_sum }}</td>
<td class="govuk-table__cell">{{ row.period_7_sum }}</td>
<td class="govuk-table__cell">{{ row.period_8_sum }}</td>
<td class="govuk-table__cell">{{ row.period_9_sum }}</td>
<td class="govuk-table__cell">{{ row.period_10_sum }}</td>
<td class="govuk-table__cell">{{ row.period_11_sum }}</td>
<td class="govuk-table__cell">{{ row.period_12_sum }}</td>
</tr>
{% endfor %}
</tbody>
<thead class="govuk-table__head">
<tr class="govuk-table__row">
<th scope="col" class="govuk-table__header">Pay type</th>
{% for month in months %}
<th scope="col" class="govuk-table__header">{{ month }}</th>
{% endfor %}
</tr>
</thead>
<tbody class="govuk-table__body">
{% for row in payroll_forecast_report %}
<tr class="govuk-table__row">
<th scope="row" class="govuk-table__header">{{ row.pay_element__type__group__name }}</th>
<td class="govuk-table__cell">{{ row.period_1_sum }}</td>
<td class="govuk-table__cell">{{ row.period_2_sum }}</td>
<td class="govuk-table__cell">{{ row.period_3_sum }}</td>
<td class="govuk-table__cell">{{ row.period_4_sum }}</td>
<td class="govuk-table__cell">{{ row.period_5_sum }}</td>
<td class="govuk-table__cell">{{ row.period_6_sum }}</td>
<td class="govuk-table__cell">{{ row.period_7_sum }}</td>
<td class="govuk-table__cell">{{ row.period_8_sum }}</td>
<td class="govuk-table__cell">{{ row.period_9_sum }}</td>
<td class="govuk-table__cell">{{ row.period_10_sum }}</td>
<td class="govuk-table__cell">{{ row.period_11_sum }}</td>
<td class="govuk-table__cell">{{ row.period_12_sum }}</td>
</tr>
{% endfor %}
</tbody>
</table>
{% endblock content %}

Expand Down
6 changes: 5 additions & 1 deletion payroll/views.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import json

from django.contrib.auth.mixins import UserPassesTestMixin
from django.core.exceptions import PermissionDenied
from django.http import HttpRequest, HttpResponse, JsonResponse
from django.shortcuts import get_object_or_404
Expand All @@ -13,7 +14,10 @@


# TODO: check user has access to cost centre
class PayrollView(View):
class PayrollView(UserPassesTestMixin, View):
def test_func(self) -> bool | None:
return self.request.user.is_superuser

def setup(self, request, *args, **kwargs) -> None:
super().setup(request, *args, **kwargs)
self.cost_centre = get_object_or_404(
Expand Down

0 comments on commit 45ce6e1

Please sign in to comment.