From 3bf7180b28796aa405d491934dbcf35d07f9eb3f Mon Sep 17 00:00:00 2001 From: Joe Eltgroth Date: Sun, 14 Jul 2019 20:00:53 -0500 Subject: [PATCH] Pull the pieces together in order to drive the invoice generation from the data --- build_invoices.py | 18 ++++++++++++++++++ main.py | 28 ++++++++++++++++++++++++++++ pilot.py | 9 +++++++-- pilot_log.py | 7 ++++++- 4 files changed, 59 insertions(+), 3 deletions(-) create mode 100644 main.py diff --git a/build_invoices.py b/build_invoices.py index cf360cb..a9152df 100644 --- a/build_invoices.py +++ b/build_invoices.py @@ -1,5 +1,6 @@ from fpdf import FPDF import os +import string X = 10 # Left side of the PDF page. @@ -251,6 +252,23 @@ def draw_table(pdf): draw_last_line(pdf, y) +def create_pdf_filename(pilot): + filename = pilot.name.replace(" ","_") + filename = pilot.id + "-" + filename + filename = filename + ".pdf" + return filename + + +def build_invoice_for_pilot(pilot_data): + pdf = FPDF(orientation='L', format='letter') + pdf.add_page() + draw_header_and_logo(pdf) + draw_statement_number_block(pdf) + draw_bill_to_block(pdf) + draw_table(pdf) + pdf.output(create_pdf_filename(pilot_data)) + + def main(): pdf = FPDF(orientation='L', format='letter') pdf.add_page() diff --git a/main.py b/main.py new file mode 100644 index 0000000..7b65254 --- /dev/null +++ b/main.py @@ -0,0 +1,28 @@ +import pilot as pilot_reader +import pilot_log as pilot_log_reader +import build_invoices as build + + +def get_logs_for_pilot(pilot, logs): + logs_to_return = [] + for l in logs: + if l.pilot == pilot.short_name: + logs_to_return.append(l) + return logs_to_return + + +def main(): + pilots = pilot_reader.get_pilot_objects("data/pilot.csv") + logs = pilot_log_reader.get_log_objects("data/pilot_log.csv") + + for p in pilots: + p.logs = get_logs_for_pilot(p, logs) + + print(pilots) + + for p in pilots: + build.build_invoice_for_pilot(p) + + +if __name__ == "__main__": + main() diff --git a/pilot.py b/pilot.py index 8dd0d20..dbd6e4a 100644 --- a/pilot.py +++ b/pilot.py @@ -42,9 +42,14 @@ def load_rows(rows): return pilots +def get_pilot_objects(filename): + data_rows = read_csv(filename) + pilots_array = load_rows(data_rows) + return pilots_array + + def main(): - data_rows = read_csv('data/pilot.csv') - pilots = load_rows(data_rows) + pilots = get_pilot_objects('data/pilot.csv') for p in pilots: print(p.id, p.name, p.short_name, p.amt_paid) diff --git a/pilot_log.py b/pilot_log.py index 4a53255..1bce8a3 100644 --- a/pilot_log.py +++ b/pilot_log.py @@ -44,9 +44,14 @@ def __init__(self, flight_date, pilot, plane, tach_in, tach_out, tach, self.misc = float(misc.strip("$")) -def main(): +def get_log_objects(filename): data_rows = read_csv('data/pilot_log.csv') log_entries = validate_rows(data_rows) + return log_entries + + +def main(): + log_entries = get_log_objects('data/pilot_log.csv') for r in log_entries: print(r.pilot, r.price, r.tach_in, r.fuel)