Faktura pdf eksport er ferdig
This commit is contained in:
		
							parent
							
								
									b138ae8c60
								
							
						
					
					
						commit
						d3c6b6977a
					
				
							
								
								
									
										103
									
								
								otime.py
									
									
									
									
									
								
							
							
						
						
									
										103
									
								
								otime.py
									
									
									
									
									
								
							| @ -307,15 +307,33 @@ class Event: | ||||
|             pdf.ln(line_height) | ||||
|         pdf.output(file_name) | ||||
| 
 | ||||
|     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] | ||||
|         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 = FPDF() | ||||
|         pdf.add_page() | ||||
|         pdf.add_font("LiberationSans", fname="data/fonts/LiberationSans-Regular.ttf") | ||||
|         pdf.add_font("LiberationSans-Bold", fname="data/fonts/LiberationSans-Bold.ttf") | ||||
| @ -325,11 +343,11 @@ class Event: | ||||
|         # Topp venstre: | ||||
|         pdf.set_font("LiberationSans-Bold", size=10) | ||||
|         pdf.multi_cell(pdf.epw / 2, line_height, self.name, align='L') | ||||
|         pdf.ln() | ||||
|         pdf.ln(0.2) | ||||
|         pdf.set_font("LiberationSans", size=10) | ||||
|         pdf.multi_cell(pdf.epw / 2, line_height, 'Kristiansand OK', align='L') | ||||
|         pdf.ln(10) | ||||
|         pdf.multi_cell(pdf.epw / 2, line_height, 'CLUB', align='L') | ||||
|         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: | ||||
| @ -392,26 +410,80 @@ class Event: | ||||
|         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=12) | ||||
|             pdf.multi_cell(0, line_height, runners[0].fee.name, border='B', align='L') | ||||
|             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 | ||||
|             pdf.ln() | ||||
|             pdf.set_font("LiberationSans", size=10) | ||||
|             for runner in runners: | ||||
|                 pdf.multi_cell(col_width, line_height, runner.id, ln=3,max_line_height=pdf.font_size, align='L') | ||||
|                 pdf.multi_cell(col_width*2, line_height, f'{runner.last}, {runner.first}', ln=3, max_line_height=pdf.font_size, align='L') | ||||
|                 pdf.multi_cell(col_width, line_height, runner.o_class_str, ln=3, max_line_height=pdf.font_size, align='L') | ||||
|                 pdf.multi_cell(col_width, line_height, str(runner.card), ln=3, max_line_height=pdf.font_size) | ||||
|                 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) | ||||
|                 pdf.multi_cell(col_width, line_height, str(datetime.timedelta(seconds=runner.totaltime())), ln=3, max_line_height=pdf.font_size) | ||||
|                 pdf.multi_cell(col_width, line_height, str(runner.rank(self.runners)), ln=3, max_line_height=pdf.font_size) | ||||
|                 pdf.multi_cell(col_width, line_height, str(runner.fee.amount), 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) | ||||
| 
 | ||||
|                 # 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) | ||||
| 
 | ||||
|                 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) | ||||
| 
 | ||||
|         pdf.set_draw_color(0, 0, 0) | ||||
|         # sum | ||||
|         pdf.set_font("LiberationSans-Bold", size=10) | ||||
|         pdf.set_x(col_width*8) | ||||
|         pdf.multi_cell(0, line_height, 'Sum    ' + str(subtotal), border='TB', ln=3, max_line_height=pdf.font_size, 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) | ||||
| 
 | ||||
| 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) | ||||
| 
 | ||||
| # The runner object stores all the data specific to a runner. | ||||
| class Runner: | ||||
|     def __init__(self, runner_id, first, last, **kwargs): | ||||
| @ -913,3 +985,4 @@ def rank_runners(allrunners, o_class): | ||||
| def xml_child(parent, tag, content): | ||||
|     e = ET.SubElement(parent, tag) | ||||
|     e.text = str(content) | ||||
| 
 | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user