Skip to content

Commit

Permalink
Work on getting log data into the invoice
Browse files Browse the repository at this point in the history
  • Loading branch information
joeeltgroth committed Jul 16, 2019
1 parent e299b09 commit 65f37ea
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 34 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,7 @@ each pilot in data/pilot.csv.
- Virtual Environments: https://virtualenv.pypa.io/en/latest/
- Pip Requirements: https://pip.pypa.io/en/stable/user_guide/
- Various techniques: https://stackoverflow.com
- Dates: https://www.w3schools.com/python/python_datetime.asp
- Currency: https://stackoverflow.com/questions/21208376/converting-float-to-dollars-and-cents


77 changes: 48 additions & 29 deletions invoice.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
from fpdf import FPDF
import os
import pilot as pilot_obj
import club as club_obj
import datetime
import pilot_log


class Invoice:
Expand All @@ -27,32 +30,44 @@ def draw_box(self, pdf_obj, x, y, w, h, line_width, text_lines):

def draw_header_and_logo(self, pdf):
pdf.set_font("helvetica", size=18, style='B')
pdf.cell(280, 10, txt="Litchfield Flying Club", ln=1, align="C")
pdf.cell(280, 10, txt=self.pilot.club.club_name, ln=1, align="C")
pdf.set_font("helvetica", size=10)
pdf.cell(280, 5, txt="Litchfield Municipal Airport", ln=1, align="C")
pdf.cell(280, 5, txt="23980 628th Avenue", ln=1, align="C")
pdf.cell(280, 5, txt="Litchfield, MN 55355", ln=1, align="C")
pdf.cell(280, 5, txt=self.pilot.club.club_addr1, ln=1, align="C")
pdf.cell(280, 5, txt=self.pilot.club.club_addr2, ln=1, align="C")
csz = self.pilot.club.club_city + ", " + self.pilot.club.club_state + " " + self.pilot.club.club_zip
pdf.cell(280, 5, txt=csz, ln=1, align="C")
if os.path.exists('plane_icon.jpg'):
pdf.image("plane_icon.jpg", x=123, w=50)

def compute_statement_number(self):
d = datetime.datetime.now()
month = d.strftime("%m")
year = d.strftime("%y")
return month + year + self.pilot.id

def compute_statement_date(self):
d = datetime.datetime.now()
return d.strftime("%x")

def draw_statement_number_block(self, pdf):
pdf.set_font("helvetica", size=10, style='B')
self.draw_box(pdf, 20, 35, 22, pdf.font_size + 1.5, 0, ["Statement #:"])
self.draw_box(pdf, 32.4, 40, 10, pdf.font_size + 1.5, 0, ["Date:"])
self.draw_box(pdf, 19, 45, 23, pdf.font_size + 1.5, 0, ["Member ID# :"])
pdf.set_font("helvetica", size=10)
self.draw_box(pdf, 45, 35, 12, pdf.font_size + 1.5, 0, ["71936"])
self.draw_box(pdf, 45, 40, 12, pdf.font_size + 1.5, 0, ["07/05/19"])
self.draw_box(pdf, 45, 45, 12, pdf.font_size + 1.5, 0, ["36"])
self.draw_box(pdf, 45, 35, 12, pdf.font_size + 1.5, 0, [self.compute_statement_number()])
self.draw_box(pdf, 45, 40, 12, pdf.font_size + 1.5, 0, [self.compute_statement_date()])
self.draw_box(pdf, 45, 45, 12, pdf.font_size + 1.5, 0, [self.pilot.id])

def draw_bill_to_block(self, pdf):
pdf.set_font("helvetica", size=10, style='B')
self.draw_box(pdf, 195, 35, 22, pdf.font_size + 1.5, 0, ["Bill To:"])
pdf.set_font("helvetica", size=10)
self.draw_box(pdf, 210, 35, 12, pdf.font_size + 1.5, 0, ["Mr. Joe Eltgroth"])
self.draw_box(pdf, 210, 40, 12, pdf.font_size + 1.5, 0, ["3100 Jefferson Street"])
self.draw_box(pdf, 210, 45, 12, pdf.font_size + 1.5, 0, ["Hutchinson, MN 55350"])
self.draw_box(pdf, 210, 51.5, 12, pdf.font_size + 1.5, 0, ["[email protected]"])
self.draw_box(pdf, 210, 35, 12, pdf.font_size + 1.5, 0, [self.pilot.name])
self.draw_box(pdf, 210, 40, 12, pdf.font_size + 1.5, 0, [self.pilot.addr1])
csz = self.pilot.city + ", " + self.pilot.state + " " + self.pilot.zip
self.draw_box(pdf, 210, 45, 12, pdf.font_size + 1.5, 0, [csz])
self.draw_box(pdf, 210, 51.5, 12, pdf.font_size + 1.5, 0, [self.pilot.email])

def draw_table_header(self, pdf):
"""
Expand All @@ -75,14 +90,10 @@ def draw_table_header(self, pdf):
return y + row_height

def draw_table_log_rows(self, pdf, y):
log_entries = [
[['6/13/19'], ['265'], ['90.57'], ['92.36'], ['114.8'], ['116.9'], ['92'], ['1.79'], ['2.1'], ['$164.68'],
['25.13'], ['4.31'],
['$108.31'], ['']],
[['6/13/19'], ['265'], [''], [''], [''], [''], ['92'], ['0'], ['0'], ['$0.00'], ['15.07'], ['4.31'],
['$64.95'], ['']],
[[''], [''], [''], [''], [''], [''], [''], [''], [''], [''], [''], [''], [''], ['']],
]
log_entries = []
for l in self.pilot.logs:
log_entries.append(l.get_log_as_array())

pdf.set_font("helvetica", size=8)
cell_width = (pdf.w - 20) / 14
row_height = pdf.font_size + 1.5
Expand Down Expand Up @@ -168,7 +179,7 @@ def draw_make_checks_to_row(self, pdf, y):
row_height = pdf.font_size + 1.5
self.draw_box(pdf, self.X, y, cell_width * 4, row_height, 0, ["Previous Balance:"])
self.draw_box(pdf, self.X + cell_width * 2, y, cell_width, row_height, .25, ["-516.85"])
self.draw_box(pdf, self.X + cell_width * 7, y, cell_width * 3, row_height, 0, ["Litchfield Flying Club, Inc."])
self.draw_box(pdf, self.X + cell_width * 7, y, cell_width * 3, row_height, 0, [self.pilot.club.club_name])
return y + row_height

def draw_prev_bal_subtotal_row(self, pdf, y):
Expand All @@ -195,11 +206,7 @@ def draw_please_include_row(self, pdf, y):
pdf.set_font("helvetica", size=8, style='B')
self.draw_box(pdf, self.X, y, cell_width * 3, row_height, 0, ["Please Include Statement"])
pdf.set_font("helvetica", size=8)
self.draw_box(pdf, self.X + cell_width * 7, y, cell_width * 2, row_height, 0, ["Litchfield Flying Club"])
pdf.set_font("helvetica", size=8, style='B')
self.draw_box(pdf, self.X + cell_width * 10, y, cell_width * 2, row_height, 0, ["Check Number:"])
pdf.set_font("helvetica", size=8)
self.draw_box(pdf, self.X + cell_width * 12, y, cell_width, row_height, 0, ["12345"])
self.draw_box(pdf, self.X + cell_width * 7, y, cell_width * 2, row_height, 0, [self.pilot.club.bill_name])
return y + row_height

def draw_balance_forward_row(self, pdf, y):
Expand All @@ -208,7 +215,7 @@ def draw_balance_forward_row(self, pdf, y):
pdf.set_font("helvetica", size=8, style='B')
self.draw_box(pdf, self.X, y, cell_width * 3, row_height, 0, ["Number On Your Check"])
pdf.set_font("helvetica", size=8)
self.draw_box(pdf, self.X + cell_width * 7, y, cell_width * 2, row_height, 0, ["PO Box 112"])
self.draw_box(pdf, self.X + cell_width * 7, y, cell_width * 2, row_height, 0, [self.pilot.club.bill_addr1])
pdf.set_font("helvetica", size=8, style='B')
self.draw_box(pdf, self.X + cell_width * 10, y, cell_width * 2, row_height, 0, ["Balance Forward:"])
pdf.set_font("helvetica", size=8)
Expand All @@ -220,7 +227,8 @@ def draw_last_line(self, pdf, y):
row_height = pdf.font_size + 1.5
pdf.set_font("helvetica", size=8)
self.draw_box(pdf, self.X, y, cell_width * 3, row_height, 0, ["Terms: Full Payment by End of Billing Month"])
self.draw_box(pdf, self.X + cell_width * 7, y, cell_width * 2, row_height, 0, ["Litchfield, MN 55355"])
csz = self.pilot.club.bill_city + ", " + self.pilot.club.bill_state + " " + self.pilot.club.bill_zip
self.draw_box(pdf, self.X + cell_width * 7, y, cell_width * 2, row_height, 0, [csz])
return y + row_height

def draw_table(self, pdf):
Expand Down Expand Up @@ -258,8 +266,19 @@ def main():
pdf = FPDF(orientation='L', format='letter')
pdf.add_page()

pilot_data = pilot_obj.Pilot("1", "Joe Smith", "Joe", "1010 Clay Street", "", "Somecity", "MN", "55355", "[email protected]",
"100", "40")
pilot_data = pilot_obj.Pilot("1", "Joe Smith", "Joe", "1010 Clay Street", "", "Somecity", "MN", "55355",
"[email protected]",
"100", "40")

club = club_obj.Club("Flying Club Name", "club_addr1", "club_addr2", "club city", "MN", "55555", "Club Bill Name",
"bill addr1", "bill_addr2", "Bill City", "WI", "66666")
pilot_data.club = club

a_log = pilot_log.Log("6/13/19", "Joe", "29265", "92.36", "90.57", "1.79", "116.9", "114.8", "2.1", "25.13", "4.31",
"108.31", "")
log_entries = [a_log]

pilot_data.logs = log_entries

invoice = Invoice(pilot_data)
invoice.build_invoice_for_pilot("output")
Expand Down
26 changes: 21 additions & 5 deletions pilot_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def validate_rows(rows):
pilot_logs = []
for row in rows:
pilot_log = Log(row[0], row[1], row[2], row[3], row[4], row[5],
row[6], row[7], row[8], row[9], row[10], row[11], row[12])
row[6], row[7], row[8], row[9], row[10], row[11], row[12])
pilot_logs.append(pilot_log)
return pilot_logs

Expand All @@ -33,19 +33,35 @@ def __init__(self, flight_date, pilot, plane, tach_in, tach_out, tach,
self.hobbs_in = float(hobbs_in)
self.hobbs_out = float(hobbs_out)
self.hobbs = float(hobbs)
self.gallons = 0
if len(gallons) > 0:
self.gallons = float(gallons)
self.price = 0
if len(price) > 0:
self.price = float(price)
else:
self.price = 0
self.fuel = float(fuel.strip("$"))
self.fuel = 0
if len(fuel) > 0:
self.fuel = float(fuel.strip("$"))
self.misc = 0
if len(misc) > 0:
self.misc = float(misc.strip("$"))

def get_log_as_array(self):
rate = 0
if self.plane == "29265":
rate = 92
if self.plane == "741T":
rate = 46
due = self.hobbs * rate
log = [[self.flight_date.strftime("%x")], [self.plane], [str(self.tach_out)], [str(self.tach_in)],
[str(self.hobbs_out)], [str(self.hobbs_in)],
[str(rate)], [str(self.tach)], [str(self.hobbs)], ['${:,.2f}'.format(due)], [str(self.gallons)],
[str(self.price)], [str(self.fuel)], [str(self.misc)]]
return log


def get_log_objects(filename):
data_rows = read_csv('data/pilot_log.csv')
data_rows = read_csv(filename)
log_entries = validate_rows(data_rows)
return log_entries

Expand Down

0 comments on commit 65f37ea

Please sign in to comment.