Skip to content
This repository has been archived by the owner on May 23, 2024. It is now read-only.

Commit

Permalink
move comment to the bottom, handle newlines and set max characters
Browse files Browse the repository at this point in the history
  • Loading branch information
Xtrah committed May 30, 2023
1 parent ec0b530 commit 3591da0
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 15 deletions.
10 changes: 8 additions & 2 deletions kaaf/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ class UnsupportedFileException(Exception):
"distance": "Antall kilometer:",
"team": "Reisefølge:",
"numberOfTravelers": "Antall reisende:",
"comment": "Kommentar:",
"accountNumber": "Kontonummer:",
"amount": "Beløp:",
"maxRefund": "(Autogenerert) Maks HS støtte:",
"comment": "Kommentar:",
}

temporary_files = []
Expand Down Expand Up @@ -145,7 +145,7 @@ def create_pdf(data, signature=None, images=None):
fitz.Point(50, 150), left_text, fontname="Helvetica-Bold", fontsize=11
)
page.insert_text(
fitz.Point(250, 150), right_text, fontname="Helvetica", fontsize=11
fitz.Point(240, 150), right_text, fontname="Helvetica", fontsize=11
)

# Add the signature image
Expand Down Expand Up @@ -246,6 +246,12 @@ def handle(data):

data["amount"] = data["amount"].replace(".", ",") # Norwegian standard is comma as decimal separator
data["maxRefund"] = calculate_traveling_refund(data)
data["comment"] = data["comment"].replace("\n", " ") # Strip newlines from comment
# If comment is longer than 50 characters, add newline after every 50 characters to avoid overflowing the pdf
if len(data["comment"]) > 50:
data["comment"] = "\n".join(
data["comment"][i : i + 50] for i in range(0, len(data["comment"]), 50)
)

try:
file = create_pdf(data, data["signature"], data["images"])
Expand Down
4 changes: 2 additions & 2 deletions kaaf/mail.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@ def create_mail(msg, body):
text += f'Antall kilometer: {body.get("distance", "")}\n'
text += f'Reisefølge: {body.get("team", "")}\n'
text += f'Antall reisende: {body.get("numberOfTravelers", "")}\n'
text += f'Kommentar: {body.get("comment", "")}\n'
text += f'Kontonummer: {body.get("accountNumber", "")}\n'
text += f'Beløp: {body.get("amount", "")}\n'
text += f'(Autogenerert) Maks HS støtte: {body.get("maxRefund", "")}\n'
text += f'Kommentar: {body.get("comment", "")}\n'
text += f'\n'
text += f"Reiseregning er generert og vedlagt. Ved spørsmål ta kontakt med [email protected]!"
text += f"Reiseregning er generert og vedlagt. Ved spørsmål, ta kontakt med [email protected]!"

msg.attach(MIMEText(text))

Expand Down
23 changes: 12 additions & 11 deletions webapp/components/Form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ const Form = (): JSX.Element => {
value={mailfrom}
required
updateForm={setMailfrom}
helperText="Din kopi av skjema går hit"
helperText="Din kopi av skjema sendes hit"
/>
<Input
name="Gruppe/utvalg"
Expand Down Expand Up @@ -156,38 +156,31 @@ const Form = (): JSX.Element => {
name="Antall kilometer"
required
value={distance}
type="number"
updateForm={setDistance}
adornment={'km'}
helperText="Uavhengig av reisemetode"
/>
<Input
name="Reisefølge"
multiline
required
value={team}
updateForm={setTeam}
helperText="Lag og/eller personer som har reist"
/>
<Input
name="Antall reisende"
multiline
required
type="number"
value={numberOfTravelers}
updateForm={setNumberOfTravelers}
helperText="Hvor mange i reisefølget"
/>
<Input
name="Kommentar"
multiline
fullWidth
value={comment}
updateForm={setComment}
/>
<Input
name="Kontonummer"
value={accountNumber}
required
type="number"
maxChars={32}
updateForm={setAccountNumber}
helperText="Refusjon overføres til denne kontoen"
/>
Expand All @@ -200,6 +193,14 @@ const Form = (): JSX.Element => {
adornment={'kr'}
helperText="Totalsum av utlegg"
/>
<Input
name="Kommentar"
fullWidth
multiline
value={comment}
updateForm={setComment}
maxChars={300}
/>
<SignatureUpload updateForm={setSignature} setSignature={setSignature} />
<PictureUpload updateForm={setImages} />
<Response />
Expand Down

0 comments on commit 3591da0

Please sign in to comment.