2023-11-02 21:57:28 +00:00
|
|
|
from fpdf import FPDF
|
2023-11-03 17:42:30 +00:00
|
|
|
|
|
|
|
def create_start_list(event, file_path):
|
2023-11-02 21:57:28 +00:00
|
|
|
pdf = FPDF()
|
2023-11-03 17:42:30 +00:00
|
|
|
|
2023-11-02 21:57:28 +00:00
|
|
|
pdf.add_page()
|
2023-11-03 17:42:30 +00:00
|
|
|
pdf.add_font("LiberationSans", fname="../../otime/data/fonts/LiberationSans-Regular.ttf")
|
2023-11-02 21:57:28 +00:00
|
|
|
pdf.set_font("LiberationSans", size=10)
|
2023-11-03 17:42:30 +00:00
|
|
|
line_height = pdf.font_size * 1.5
|
2023-11-02 21:57:28 +00:00
|
|
|
col_width = pdf.epw / 4 # distribute content evenly
|
2023-11-03 17:42:30 +00:00
|
|
|
for runner in event.runners:
|
2023-11-02 21:57:28 +00:00
|
|
|
pdf.multi_cell(col_width, line_height, runner.fullname(), border=1, ln=3, max_line_height=pdf.font_size, align='L')
|
2023-11-03 17:42:30 +00:00
|
|
|
pdf.multi_cell(col_width, line_height, runner.o_class, border=1, ln=3, max_line_height=pdf.font_size)
|
|
|
|
pdf.multi_cell(col_width, line_height, str(runner.card_id), border=1, ln=3, max_line_height=pdf.font_size)
|
2023-11-02 21:57:28 +00:00
|
|
|
if runner.start_time is not None:
|
|
|
|
pdf.multi_cell(col_width, line_height, str(runner.start_time), border=1, ln=3, max_line_height=pdf.font_size)
|
|
|
|
else:
|
|
|
|
pdf.multi_cell(col_width, line_height, '', border=1, ln=3, max_line_height=pdf.font_size)
|
|
|
|
pdf.ln(line_height)
|
2023-11-03 17:42:30 +00:00
|
|
|
pdf.output(file_path)
|
|
|
|
|
|
|
|
def create_all_invoices(self, filename_prefix):
|
|
|
|
clubs = [x.club for x in self.runners if x.club != self.runners[self.runners.index(x)-1].club and x.club is not None]
|
|
|
|
for club in clubs:
|
|
|
|
self.create_club_invoice(club, filename_prefix + club + '.pdf')
|
|
|
|
|
|
|
|
def create_club_invoice(self, club, file_name):
|
|
|
|
# Get only runners in specified club
|
|
|
|
runners_ic = [x for x in self.runners if x.club == club]
|
|
|
|
payments = [x.fee.amount for x in runners_ic]
|
|
|
|
subtotal = sum(payments)
|
|
|
|
|
|
|
|
# Dict of runners in each fee
|
|
|
|
fee_dict = {}
|
|
|
|
for fee in self.fees:
|
|
|
|
fee_dict.update({fee.name: [x for x in runners_ic if x.fee.name == fee.name]})
|
|
|
|
if len(fee_dict[fee.name]) == 0:
|
|
|
|
fee_dict.pop(fee.name)
|
|
|
|
|
|
|
|
pdf = PDF()
|
|
|
|
|
|
|
|
pdf.set_title(f'Faktura {self.name} {club}')
|
|
|
|
pdf.set_producer('oTime 0.0.1')
|
|
|
|
pdf.set_creator('oTime 0.0.1')
|
|
|
|
pdf.set_creation_date()
|
|
|
|
|
|
|
|
pdf.add_page()
|
|
|
|
pdf.add_font("LiberationSans", fname="data/fonts/LiberationSans-Regular.ttf")
|
|
|
|
pdf.add_font("LiberationSans-Bold", fname="data/fonts/LiberationSans-Bold.ttf")
|
|
|
|
pdf.set_font("LiberationSans", size=10)
|
|
|
|
line_height = pdf.font_size * 1.5
|
|
|
|
|
|
|
|
# Topp venstre:
|
|
|
|
pdf.set_font("LiberationSans-Bold", size=10)
|
|
|
|
pdf.multi_cell(pdf.epw / 2, line_height, self.name, align='L')
|
|
|
|
pdf.ln(0.2)
|
|
|
|
pdf.set_font("LiberationSans", size=10)
|
|
|
|
pdf.multi_cell(pdf.epw / 2, line_height, self.organiser, align='L')
|
|
|
|
pdf.ln(14)
|
|
|
|
pdf.multi_cell(pdf.epw / 2, line_height, club, align='L')
|
|
|
|
pdf.ln()
|
|
|
|
|
|
|
|
# Topp høyre:
|
|
|
|
pdf.set_xy(-pdf.epw / 3, 10)
|
|
|
|
pdf.set_font("LiberationSans-Bold", size=20)
|
|
|
|
pdf.multi_cell(pdf.epw, line_height, 'Faktura', align='L')
|
|
|
|
pdf.set_xy(-pdf.epw / 3, 20)
|
|
|
|
|
|
|
|
# Dato
|
|
|
|
pdf.set_font("LiberationSans-Bold", size=10)
|
|
|
|
pdf.multi_cell(0, line_height, 'Dato:', align='L')
|
|
|
|
pdf.set_xy(-pdf.epw / 3, 20)
|
|
|
|
pdf.set_font("LiberationSans", size=10)
|
|
|
|
pdf.multi_cell(0, line_height, datetime.date.today().strftime('%d.%m.%Y'), align='R')
|
|
|
|
|
|
|
|
# Nummer
|
|
|
|
pdf.set_xy(-pdf.epw / 3, 20 + line_height)
|
|
|
|
pdf.set_font("LiberationSans-Bold", size=10)
|
|
|
|
pdf.multi_cell(0, line_height, 'Nummer:', align='L')
|
|
|
|
pdf.set_xy(-pdf.epw / 3, 20 + line_height)
|
|
|
|
pdf.multi_cell(0, line_height, '1', align='R')
|
|
|
|
|
|
|
|
# Kundeid
|
|
|
|
pdf.set_xy(-pdf.epw / 3, 20 + line_height*2)
|
|
|
|
pdf.set_font("LiberationSans-Bold", size=10)
|
|
|
|
pdf.multi_cell(0, line_height, 'Kundeid:', align='L')
|
|
|
|
pdf.set_xy(-pdf.epw / 3, 20 + line_height*2)
|
|
|
|
pdf.set_font("LiberationSans", size=10)
|
|
|
|
pdf.multi_cell(0, line_height, '123', align='R')
|
|
|
|
|
|
|
|
# Forfall
|
|
|
|
pdf.set_xy(-pdf.epw / 3, 20 + line_height*3)
|
|
|
|
pdf.set_font("LiberationSans-Bold", size=10)
|
|
|
|
pdf.multi_cell(0, line_height, 'Forfall:', align='L')
|
|
|
|
pdf.set_xy(-pdf.epw / 3, 20 + line_height*3)
|
|
|
|
pdf.set_font("LiberationSans", size=10)
|
|
|
|
pdf.multi_cell(0, line_height, datetime.date.today().strftime('%d.08.%Y'), align='R')
|
|
|
|
|
|
|
|
pdf.set_xy(-pdf.epw, 20 + line_height*5)
|
|
|
|
pdf.set_font("LiberationSans-Bold", size=10)
|
|
|
|
date = self.start_time.strftime('%d.%m.%Y')
|
|
|
|
pdf.multi_cell(0, line_height, f'Kontingentliste {self.name} dato: {date}', align='R')
|
|
|
|
|
|
|
|
pdf.ln()
|
|
|
|
|
|
|
|
pdf.set_font("LiberationSans", size=10)
|
|
|
|
# Tabell
|
|
|
|
line_height = pdf.font_size * 2
|
|
|
|
col_width = pdf.epw / 8 # distribute content evenly
|
|
|
|
# Top row
|
|
|
|
pdf.set_fill_color(191, 191, 191)
|
|
|
|
pdf.set_draw_color(191, 191, 191)
|
|
|
|
pdf.set_font("LiberationSans-Bold", size=10)
|
|
|
|
pdf.multi_cell(col_width, line_height, 'Startnr', border=1, ln=3, max_line_height=pdf.font_size, align='L', fill=True)
|
|
|
|
pdf.multi_cell(col_width*2, line_height, 'Navn', border=1, ln=3, max_line_height=pdf.font_size, align='L', fill=True)
|
|
|
|
pdf.multi_cell(col_width, line_height, 'Klasse', border=1, ln=3, max_line_height=pdf.font_size, align='L', fill=True)
|
|
|
|
pdf.multi_cell(col_width, line_height, 'Brikke', border=1, ln=3, max_line_height=pdf.font_size, align='L', fill=True)
|
|
|
|
# pdf.multi_cell(col_width, line_height, 'Starttid', border=1, ln=3,max_line_height=pdf.font_size, align='L', fill=True)
|
|
|
|
pdf.multi_cell(col_width, line_height, 'Resultat', border=1, ln=3, max_line_height=pdf.font_size, align='L', fill=True)
|
|
|
|
pdf.multi_cell(col_width, line_height, 'Plass', border=1, ln=3, max_line_height=pdf.font_size, align='L', fill=True)
|
|
|
|
pdf.multi_cell(col_width, line_height, 'Kontigent', border=1, ln=3, max_line_height=pdf.font_size, align='L', fill=True)
|
|
|
|
pdf.ln()
|
|
|
|
pdf.set_draw_color(0, 0, 0)
|
|
|
|
for runners in fee_dict.values():
|
|
|
|
pdf.set_font("LiberationSans-Bold", size=11)
|
|
|
|
pdf.multi_cell(len(runners[0].fee.name)*2.3, pdf.font_size * 1.1, runners[0].fee.name, border='B', align='L')
|
|
|
|
pdf.set_font("LiberationSans", size=8)
|
|
|
|
line_height = pdf.font_size * 1.6
|
2023-11-02 21:57:28 +00:00
|
|
|
pdf.ln()
|
2023-11-03 17:42:30 +00:00
|
|
|
for runner in runners:
|
|
|
|
pdf.multi_cell(col_width, line_height, runner.id, ln=3, max_line_height=pdf.font_size, align='L') # Start Number
|
|
|
|
pdf.multi_cell(col_width*2, line_height, f'{runner.last}, {runner.first}', ln=3, max_line_height=pdf.font_size, align='L') # Name
|
|
|
|
pdf.multi_cell(col_width, line_height, runner.o_class_str, ln=3, max_line_height=pdf.font_size, align='L') # Class
|
|
|
|
pdf.multi_cell(col_width, line_height, str(runner.card), ln=3, max_line_height=pdf.font_size) # card
|
|
|
|
# Starttime:
|
|
|
|
#if runner.start_time != None:
|
|
|
|
# pdf.multi_cell(col_width, line_height, str(runner.start_time), ln=3, max_line_height=pdf.font_size)
|
|
|
|
#else:
|
|
|
|
# pdf.multi_cell(col_width, line_height, 'Fristart', ln=3, max_line_height=pdf.font_size)
|
|
|
|
# Time used:
|
|
|
|
if runner.status() == 'OK':
|
|
|
|
pdf.multi_cell(col_width, line_height, str(datetime.timedelta(seconds=runner.totaltime())), ln=3, max_line_height=pdf.font_size)
|
|
|
|
elif runner.status() == 'Disqualified':
|
|
|
|
pdf.multi_cell(col_width, line_height, 'DSQ', ln=3, max_line_height=pdf.font_size)
|
|
|
|
elif runner.status() == 'Active':
|
|
|
|
pdf.multi_cell(col_width, line_height, 'DNS', ln=3, max_line_height=pdf.font_size)
|
|
|
|
else:
|
|
|
|
pdf.multi_cell(col_width, line_height, runner.status(), ln=3, max_line_height=pdf.font_size)
|
2023-11-02 21:57:28 +00:00
|
|
|
|
2023-11-03 17:42:30 +00:00
|
|
|
# Rank:
|
|
|
|
if runner.status() == 'OK':
|
|
|
|
pdf.multi_cell(col_width, line_height, str(runner.rank(self.runners)) + '.', ln=3, max_line_height=pdf.font_size)
|
|
|
|
else:
|
|
|
|
pdf.multi_cell(col_width, line_height, '', ln=3, max_line_height=pdf.font_size)
|
2023-11-02 21:57:28 +00:00
|
|
|
|
2023-11-03 17:42:30 +00:00
|
|
|
pdf.multi_cell(col_width, line_height, str(runner.fee.amount), ln=3, max_line_height=pdf.font_size, align='R')
|
|
|
|
pdf.ln(line_height)
|
2023-11-02 21:57:28 +00:00
|
|
|
|
2023-11-03 17:42:30 +00:00
|
|
|
pdf.set_draw_color(0, 0, 0)
|
|
|
|
# sum
|
|
|
|
pdf.set_font("LiberationSans-Bold", size=10)
|
|
|
|
pdf.set_x(col_width*8)
|
|
|
|
pdf.cell(0, line_height, 'Sum ' + str(subtotal), border='TB', align='R')
|
|
|
|
|
|
|
|
pdf.set_font("LiberationSans", size=10)
|
|
|
|
line_height = pdf.font_size * 1.5
|
|
|
|
pdf.ln(20)
|
|
|
|
pdf.multi_cell(0, line_height, 'Antall løpere ' + str(len(runners_ic)), ln=3, max_line_height=pdf.font_size, align='L')
|
|
|
|
|
|
|
|
pdf.set_x(col_width*7)
|
|
|
|
pdf.multi_cell(col_width, line_height, 'Total sum', ln=3, max_line_height=pdf.font_size, align='L')
|
|
|
|
pdf.multi_cell(0, line_height, str(subtotal), ln=3, max_line_height=pdf.font_size, align='R')
|
|
|
|
pdf.ln()
|
|
|
|
pdf.set_x(col_width*7)
|
|
|
|
pdf.multi_cell(col_width, line_height, 'Betalt', ln=3, max_line_height=pdf.font_size, align='L')
|
|
|
|
pdf.multi_cell(0, line_height, '0', ln=3, max_line_height=pdf.font_size, align='R')
|
|
|
|
pdf.ln()
|
|
|
|
pdf.set_font("LiberationSans-Bold", size=10)
|
|
|
|
pdf.set_x(col_width*7)
|
|
|
|
pdf.multi_cell(col_width, line_height, 'Skyldig', border='B', ln=3, max_line_height=pdf.font_size, align='L')
|
|
|
|
pdf.multi_cell(0, line_height, str(subtotal), border='B',ln=3, max_line_height=pdf.font_size, align='R')
|
|
|
|
|
|
|
|
|
|
|
|
pdf.output(file_name)
|
2023-11-02 21:57:28 +00:00
|
|
|
"""
|
|
|
|
class PDF(FPDF):
|
|
|
|
def footer(self):
|
|
|
|
self.set_y(-15)
|
|
|
|
self.set_font("LiberationSans", size=10)
|
|
|
|
self.set_fill_color(191, 191, 191)
|
|
|
|
self.set_draw_color(191, 191, 191)
|
|
|
|
col_width = self.epw / 3
|
|
|
|
self.cell(col_width, 7, 'oTime', border=1, align='L', fill=True)
|
|
|
|
self.cell(col_width, 7, datetime.datetime.now().strftime('%d.%m.%Y %H:%M:%S'), border=1, align='C', fill=True)
|
|
|
|
self.cell(col_width, 7, f"Side {self.page_no()} av {{nb}}", border=1, align='R', fill=True)
|
|
|
|
"""
|