def aplinvoice(mfile, mtext, mdate, invoco, sendto): fileToSend = ntpath.basename(mfile) shutil.copy(mfile, fileToSend) print(f'file to send is:{fileToSend}') if invoco == 'apl' and sendto == 'aplnow': emailfrom = usernames['mnix'] #emailto = '*****@*****.**' emailto = '*****@*****.**' #emailto = '*****@*****.**' emailcc = usernames['info'] elif invoco == 'cma' and sendto == 'cmanow': emailfrom = usernames['mnix'] emailto = '*****@*****.**' #emailto = '*****@*****.**' emailcc = usernames['info'] else: emailfrom = usernames['mnix'] emailto = usernames['mnix'] emailcc = usernames['expo'] # fileToSend = tfile username = usernames['mnix'] password = passwords['mnix'] msg = MIMEMultipart() msg["From"] = emailfrom msg["To"] = emailto msg["Cc"] = emailcc if invoco == 'apl': msg["Subject"] = f'Account Payable Dept - SSINV to EDI -- First Eagle Logistics {mdate}' body = 'APL LARA Spreadsheet is Attached.' + mtext if invoco == 'cma': msg["Subject"] = f'Account Payable Dept CMA CMG - SSINV to EDI from First Eagle Logistics {mdate}' body = 'CMA LARA Spreadsheet is Attached.' + mtext cdata = companydata() body = body + f'<br>_________________<br>{cdata[2]}<br>{cdata[5]}<br>{cdata[6]}<br>{cdata[7]}' msg.attach(MIMEText(body, 'html')) attachment = open(fileToSend, "rb") part = MIMEBase('application', 'octet-stream') part.set_payload((attachment).read()) encoders.encode_base64(part) part.add_header('Content-Disposition', f'attachment; filename= "{fileToSend}"') msg.attach(part) server = smtplib.SMTP(websites['mailserver']) # server.starttls() server.login(username, password) emailto = [emailto, emailcc] server.sendmail(emailfrom, emailto, msg.as_string()) server.quit()
def report_headers(file3, item): cdata = companydata() today = datetime.today().strftime('%m/%d/%Y') invodate = datetime.today().strftime('%m/%d/%Y') ltm, rtm, bump, tb, ctrall, left_ctr, right_ctr, dl, dh, tdl, hls, m1, m2, m3, m4, m5, m6, m7, n1, n2, n3 = reportsettings( 1) dateline = m1 + 8.2 * dl mtmp = dateline - 3.5 * dl level1 = mtmp + 3.5 * dl c = canvas.Canvas(file3, pagesize=letter) c.setLineWidth(1) c.setFont('Helvetica-Bold', 24, leading=None) c.drawCentredString(rtm - 75, dateline + 1.5 * dl, 'Report') c.setFont('Helvetica-Bold', 12, leading=None) c.drawString(ltm + bump * 3, level1 + bump * 2, f'{item.upper()} Report') c.setFont('Helvetica', 12, leading=None) c.drawCentredString(rtm - 50, dateline + bump, 'Created') #c.drawCentredString(rtm - 37.7, dateline + bump, 'Type') vdat = Vehicles.query.filter(Vehicles.DOTNum != None).first() dh = 13 top = level1 - dh lft = ltm + bump * 3 header = list(range(5)) header[0] = f'This Report Page is the {item.upper()}' header[1] = 'Information List for' header[2] = f'{cdata[0]}' header[3] = f'DOT #{vdat.DOTNum}' header[4] = '' for ix in header: c.drawString(lft, top, ix) top = top - dh x = avg(rtm - 75, rtm) y = dateline - dh - bump #c.drawCentredString(x, y, f'{item.upper()}') x = avg(rtm - 75, rtm - 150) c.drawCentredString(rtm - 50, y, invodate) c.showPage() c.save()
from runmain import app, db from models import Vehicles, Invoices, JO, Income, Bills, Accounts, OverSeas, Orders, Gledger, Adjusting from models import Autos, People, Interchange, Drivers, ChalkBoard, Services, Drops, Divisions, LastMessage from flask import session, logging, request import datetime import calendar import re import os import shutil import json from CCC_system_setup import myoslist, addpath, addtxt, scac, companydata from iso_B_worker import var_start, var_request, get_selections, cleanup, alterations, incoming_setup, modbill, \ run_paybill, run_xfer, uploadsource, modpeeps, pay_init, multi_pay_init, install_pay_init, mod_init, newbill_init,\ newbill_passthru, newbill_update, undolastpayment compdata = companydata() billexpcode = compdata[10] + 'B' billxfrcode = compdata[10] + 'X' print(billexpcode) def isoB(indat): if request.method == 'POST': from viewfuncs import nonone, numcheck, newjo from viewfuncs import calendar7_weeks, txtfile, numcheckvec, d2s, erud, dataget_B, hv_capture, docuploader, get_def_bank from gledger_write import gledger_write, gledger_app_write # Initialize variables used in the python code that require a value username, bill, peep, cache, modata, modlink, fdata, adata, cdat, pb, passdata, vdata, caldays, daylist,\
def writechecks(bdat, pdat, file1, sbdata, links, style): today = datetime.datetime.today().strftime('%m/%d/%Y') nbills = 1 file1 = addpath(file1) if links == 0: amt = bdat.pAmount amt = amt.replace(',', '') amount = float(amt) else: amt = bdat.pMulti amt = amt.replace(',', '') amount = float(amt) #billno = 'Bk:'+bdat.bCat billno = bdat.Jo # Create the Check Date: billdate = bdat.pDate print(billdate) try: datestr = billdate.strftime('%m/%d/%Y') except: datestr = datetime.datetime.today().strftime('%m/%d/%Y') if bdat.Memo is None: memo = ' ' else: memo = bdat.Memo if bdat.Description is None: desc = ' ' else: desc = bdat.Description payref = bdat.Ref # Check to see if we have the required data to make an invoice: company = pdat.Company addr1 = pdat.Addr1 addr2 = pdat.Addr2 email = pdat.Email phone = pdat.Telephone payee = company amount_num = "{:.2f}".format(amount) # amount_num=145.23 bank = bdat.pAccount type = bdat.bType if links != 0: memo = '' nbills = 0 for sb in sbdata: nbills = nbills + 1 if len(memo) > 45: memo = memo + '\n' memo = memo + sb.Memo + ', ' lm = len(memo) memo = memo[0:lm - 2] one = [ '', 'One', 'Two', 'Three', 'Four', 'Five', 'Six', 'Seven', 'Eight', 'Nine' ] tenp = [ 'Ten', 'Eleven', 'Twelve', 'Thirteen', 'Fourteen', 'Fifteen', 'Sixteen', 'Seventeen', 'Eighteen', 'Nineteen' ] tenp2 = [ '', '', 'Twenty', 'Thirty', 'Forty', 'Fifty', 'Sixty', 'Seventy', 'Eighty', 'Ninety' ] def avg(in1, in2): out = (in1 + in2) / 2 return out def once(num): one = [ '', 'One', 'Two', 'Three', 'Four', 'Five', 'Six', 'Seven', 'Eight', 'Nine' ] word = '' word = one[int(num)] word = word.strip() return word def ten(num): tenp = [ 'Ten', 'Eleven', 'Twelve', 'Thirteen', 'Fourteen', 'Fifteen', 'Sixteen', 'Seventeen', 'Eighteen', 'Nineteen' ] tenp2 = [ '', '', 'Twenty', 'Thirty', 'Forty', 'Fifty', 'Sixty', 'Seventy', 'Eighty', 'Ninety' ] word = '' if num[0] == '1': word = tenp[int(num[1])] else: text = once(num[1]) word = tenp2[int(num[0])] word = word + "-" + text word = word.strip() return word def hundred(num): one = [ '', 'One', 'Two', 'Three', 'Four', 'Five', 'Six', 'Seven', 'Eight', 'Nine' ] word = '' text = ten(num[1:]) word = one[int(num[0])] if num[0] != '0': word = word + "-Hundred " word = word + text word = word.strip() return word def thousand(num): word = '' pref = '' text = '' length = len(num) if length == 6: text = hundred(num[3:]) pref = hundred(num[:3]) if length == 5: text = hundred(num[2:]) pref = ten(num[:2]) if length == 4: text = hundred(num[1:]) word = one[int(num[0])] if num[0] != '0' or num[1] != '0' or num[2] != '0': word = word + "-Thousand " word = word + text if length == 6 or length == 5: word = pref + word word = word.strip() return word def million(num): word = '' pref = '' text = '' length = len(num) if length == 9: text = thousand(num[3:]) pref = hundred(num[:3]) if length == 8: text = thousand(num[2:]) pref = ten(num[:2]) if length == 7: text = thousand(num[1:]) word = one[int(num[0])] if num[0] != '0' or num[1] != '0' or num[2] != '0': word = word + " Million " word = word + text if length == 9 or length == 8: word = pref + word word = word.strip() return word val1 = float(amount_num) val2 = math.floor(val1) print(val2) val3 = val1 - val2 val3 = round(val3 * 100) print(val3) a = str(val2) leng = len(a) if leng == 1: if a == '0': num = 'Zero' else: num = once(a) if leng == 2: num = ten(a) if leng == 3: num = hundred(a) if leng > 3 and leng < 7: num = thousand(a) if leng > 6 and leng < 10: num = million(a) lnum = len(num) # print(num[lnum-1]) if num[lnum - 1] == '-': num = num[0:lnum - 1] tval3 = "{0:0=2d}".format(val3) amount_text = num + ' and ' + tval3 + '/100 ' # print(amount_text) # We need to add '*******' to back of this enough to fill up the rest of the block atlen = len(amount_text) # Guess that we need 120 chars total atremain = 90 - atlen b = '*' for i in range(atremain): b = b + '*' # print(atlen,atremain,b) amount_text = amount_text + b # print(amount_text) c = canvas.Canvas(file1, pagesize=letter) c.setFont('Helvetica', 12, leading=None) c.drawString(515, 720, datestr) c.drawString(70, 685, payee) # ____________________________________________________________________________ c.drawString(500, 686, amount_num) c.drawString(30, 660, amount_text) image = addpath(f'tmp/{scac}/pics/ck_sigfile.png') c.drawImage(image, 374, 587, width=200, height=40) c.setFont('Helvetica', 12, leading=None) ltm = 15 rtm = 590 ctrall = 310 left_ctr = 170 right_ctr = 480 dl = 17.6 tdl = dl * 2 hls = 530 m1 = 510 m2 = m1 - dl m3 = m2 - dl m4 = m3 - 10 m5 = m4 - dl m6 = m5 - dl m7 = 265 m8 = m7 - dl m9 = m8 - dl m10 = m9 - 10 m11 = m10 - dl m12 = m11 - dl n1 = ltm + 90 n2 = n1 + 150 n3 = n2 + 80 n4 = n3 + 80 n5 = rtm - 90 bump = 3 btype = bdat.bType bcat = bdat.bCat bsubcat = bdat.bSubcat item11 = [ 'Date', 'Ck No.| Pay Ref', 'Type', 'Category', 'Subcategory', 'Amount Paid' ] item12 = [datestr, payref, btype, bcat, bsubcat, amount_num] item21 = ['BillNo', 'Check Made Out To', 'From Acct'] item22 = [billno, payee, bank] item3 = 'Memo on Check:' item41 = ['Address of Company:'] if style == 1: fulllinesat = [m1, m2, m3, m4, m5, m6, m7, m8, m9, m10, m11, m12] for i in fulllinesat: c.line(ltm, i, rtm, i) vlines1at = [ltm, n1, n2 - 40, n3 - 40, n4 - 40, n5, rtm] for i in vlines1at: c.line(i, m1, i, m3) c.line(i, m7, i, m9) p1 = n1 p2 = n5 - 60 vlines2at = [ltm, n1, p2 - 20, rtm] for i in vlines2at: c.line(i, m4, i, m6) c.line(i, m10, i, m12) else: fulllinesat = [m7, m8, m9, m10, m11, m12] for i in fulllinesat: c.line(ltm, i, rtm, i) vlines1at = [ltm, n1, n2 - 40, n3 - 40, n4 - 40, n5, rtm] for i in vlines1at: c.line(i, m7, i, m9) p1 = n1 p2 = n5 - 60 vlines2at = [ltm, n1, p2 - 20, rtm] for i in vlines2at: c.line(i, m10, i, m12) dx = 80 xoff = 18 stretch = [0, -5, 15, 10, 10, 0] if style == 1: for i in range(6): x = avg(vlines1at[i], vlines1at[i + 1]) c.drawCentredString(x, m2 + bump, item11[i]) c.drawCentredString(x, m3 + bump, str(item12[i])) c.drawCentredString(x, m8 + bump, item11[i]) c.drawCentredString(x, m9 + bump, str(item12[i])) for i in range(3): x = avg(vlines2at[i], vlines2at[i + 1]) c.drawCentredString(x, m5 + bump, item21[i]) c.drawCentredString(x, m6 + bump, str(item22[i])) c.drawCentredString(x, m11 + bump, item21[i]) c.drawCentredString(x, m12 + bump, str(item22[i])) else: for i in range(6): x = avg(vlines1at[i], vlines1at[i + 1]) c.drawCentredString(x, m8 + bump, item11[i]) c.drawCentredString(x, m9 + bump, str(item12[i])) for i in range(3): x = avg(vlines2at[i], vlines2at[i + 1]) c.drawCentredString(x, m11 + bump, item21[i]) c.drawCentredString(x, m12 + bump, str(item22[i])) mlev11 = m6 - dl mlev12 = mlev11 - dl mlev13 = mlev12 - dl * 1.5 mlev14 = mlev13 - dl mlev15 = mlev14 - dl mlev21 = m12 - dl mlev22 = mlev21 - dl mlev23 = mlev22 - dl * 1.5 mlev24 = mlev23 - dl mlev25 = mlev24 - dl c.setFont('Helvetica', 10, leading=None) if links != 0: memo2 = memo.splitlines() nlines = len(memo2) memoline = 592 + 13 * (nlines - 1) memoline2 = mlev12 memoline3 = mlev22 for line in memo2: c.setFont('Helvetica', 12, leading=None) c.drawString(52, memoline, line) memoline = memoline - 13 c.setFont('Helvetica', 10, leading=None) if style == 1: c.drawString(ltm + 20, memoline2, line) memoline2 = memoline2 - 10 c.drawString(ltm + 20, memoline3, line) memoline3 = memoline3 - 10 else: c.drawString(52, 592, memo) c.setFont('Helvetica', 12, leading=None) if style == 1: c.drawString(ltm + 20, mlev11, item3) c.drawString(ltm + 20, mlev21, item3) c.setFont('Helvetica', 10, leading=None) if links == 0: if style == 1: c.drawString(ltm + 20, mlev12, memo) c.drawString(ltm + 20, mlev22, memo) memoline2 = mlev12 memoline3 = mlev22 try: pufrom = 'Pickup: ' + bdat.Link except: pufrom = 'Pickup: Unknown' c.setFont('Helvetica', 12, leading=None) if style == 1: c.drawString(ltm + 20, memoline2 - dl, 'Payee Address:') c.drawString(ltm + 20, memoline3 - dl, 'Payee Address:') c.setFont('Helvetica', 10, leading=None) if addr1 is None: addr1 = '' if addr2 is None: addr2 = '' if pufrom is None: pufrom = '' if style == 1: c.drawString(ltm + 20, memoline2 - dl * 2, company) c.drawString(ltm + 20, memoline2 - dl * 2 - 11, addr1) c.drawString(ltm + 20, memoline2 - dl * 2 - 22, addr2) c.drawString(ltm + 20, memoline2 - dl * 2 - 44, pufrom) else: cdata = companydata() c.setFont('Helvetica', 12, leading=None) offup = 5 c.drawString(50, m2 + offup, cdata[2]) c.drawString(50, m2 + offup - 14, cdata[5]) c.drawString(50, m2 + offup - 28, cdata[6]) memoline2 = memoline2 + 1 c.drawString(ltm + 70, memoline2, company) c.drawString(ltm + 70, memoline2 - 14, addr1) c.drawString(ltm + 70, memoline2 - 28, addr2) zip = getzip(addr2) print('myzipcode is', zip) if zip != 0: barcode_usps = usps.POSTNET(zip) barcode_usps.drawOn(c, ltm + 70, memoline2 - 42) c.setFont('Helvetica', 10, leading=None) c.drawString(ltm + 20, memoline3 - dl * 2, company) c.drawString(ltm + 20, memoline3 - dl * 2 - 11, addr1) c.drawString(ltm + 20, memoline3 - dl * 2 - 22, addr2) c.drawString(ltm + 20, memoline3 - dl * 2 - 44, pufrom) acct = bdat.bAccount comp = bdat.Co if acct is None: acct = ' ' if comp is None: comp = ' ' if nbills == 0: if btype == 'Expense': if style == 1: c.drawString( ltm + 230, mlev11, 'Expensed Account Name: ' + acct + ' (' + comp + ')') c.drawString(ltm + 230, mlev21, 'Expensed Account Name: ' + acct + ' (' + comp + ')') mlev21 = mlev21 - 2 * dl mlev11 = mlev11 - 2 * dl if style == 1: c.drawString(ltm + 230, mlev11, 'Full Description:') c.drawString(ltm + 230, mlev21, 'Full Description:') for i, line in enumerate(desc.splitlines()): mlev21 = mlev21 - dl mlev11 = mlev11 - dl if style == 1: c.drawString(ltm + 230, mlev11, line) c.drawString(ltm + 230, mlev21, line) if nbills > 1: dl = .9 * dl if nbills > 5: dl = .9 * dl mlevtop = mlev14 + 80 - dl - dl mlevbot = mlev24 + 80 - dl - dl if links != 0: s1 = ltm + 200 s2 = ltm + 240 s3 = ltm + 310 s4 = ltm + 480 if btype == 'Expense': if style == 1: c.drawString( ltm + 230, mlev11, 'Expensed Account Name: ' + acct + ' (' + comp + ')') c.drawString(ltm + 230, mlev21, 'Expensed Account Name: ' + acct + ' (' + comp + ')') mlevtop = mlev11 - 2 * dl mlevbot = mlev21 - 2 * dl c.setFont('Helvetica-Bold', 10, leading=None) if style == 1: c.drawString(s1, mlevtop, 'ID') c.drawString(s2, mlevtop, 'Bill No') c.drawString(s3, mlevtop, 'Reference/BkNo.') c.drawString(s4, mlevtop, 'Amount') c.drawString(s1, mlevbot, 'ID') c.drawString(s2, mlevbot, 'Bill No') c.drawString(s3, mlevbot, 'Reference/BkNo.') c.drawString(s4, mlevbot, 'Amount') c.setFont('Helvetica', 10, leading=None) for data in sbdata: mlevtop = mlevtop - dl mlevbot = mlevbot - dl id = str(data.id) billno = data.Jo ref = data.Memo # if memo long ref = ref.replace('For booking ', '') amt = dollar(float(data.pAmount)) if style == 1: c.drawString(s1, mlevtop, id) c.drawString(s1, mlevbot, id) try: if style == 1: c.drawString(s2, mlevtop, billno) c.drawString(s2, mlevbot, billno) except: err = '1' if style == 1: c.drawString(s3, mlevtop, ref) if style == 1: c.drawString(s4, mlevtop, amt) c.drawString(s3, mlevbot, ref) c.drawString(s4, mlevbot, amt) c.showPage() c.save() return
def email_app_exporter(pdata): ourserver = websites['mailserver'] cdat = companydata() for pdat in pdata: ptype = pdat.Ptype if ptype == 'exporter': emailin = pdat.Email print('Eporter email=', emailin) exporter = pdat.First + ' ' + pdat.Middle + ' ' + pdat.Last exporter = exporter.replace(' ', ' ') idn = pdat.id if emailin is None or emailin == 'None' or len( emailin) < 5 or '@' not in emailin: emailin = usernames['expo'] code = 'Either no email or a bad email was provided' #emailto = "*****@*****.**" emailfrom = emails['expo'] emailto = emailin #emailcc = "*****@*****.**" emailcc1 = emails['info'] emailcc2 = emails['serv'] #fileToSend = absdocref username = emails[2] password = passwords['expo'] msg = MIMEMultipart() msg["From"] = emailfrom msg["To"] = emailto msg["Cc"] = emailcc1 msg["Cc"] = emailcc2 msg["Subject"] = f'{cdat[0]} Application Received' body = 'Dear ' + exporter + ':\n\nThis email confirms receipt of your international shipping application with confirmation code Fapp' + str( idn) body = body + ', and the following summarizes the information we received from you:\n\n' for pdat in pdata: ptype = pdat.Ptype if ptype == 'exporter': body = body + 'Exporter: ' + pdat.First + ' ' + pdat.Middle + ' ' + pdat.Last + '\n' body = body + 'Address:' + pdat.Addr1 + ' ' + pdat.Addr2 + ' ' + pdat.Addr3 + '\n' body = body + 'ID:' + pdat.Idtype + ' ' + pdat.Idnumber + '\n' body = body + 'Telephone:' + pdat.Telephone + '\n' body = body + 'Email: ' + pdat.Email + '\n\n' if ptype == 'consignee': body = body + 'Consignee: ' + pdat.First + ' ' + pdat.Middle + ' ' + pdat.Last + '\n' body = body + 'Address:' + pdat.Addr1 + ' ' + pdat.Addr2 + ' ' + pdat.Addr3 + '\n' body = body + 'Telephone:' + pdat.Telephone + '\n' body = body + 'Email: ' + pdat.Email + '\n\n' if ptype == 'notify': body = body + 'Notify Party: ' + pdat.First + ' ' + pdat.Middle + ' ' + pdat.Last + '\n' body = body + 'Address:' + pdat.Addr1 + ' ' + pdat.Addr2 + ' ' + pdat.Addr3 + '\n' body = body + 'Telephone:' + pdat.Telephone + '\n' body = body + 'Email: ' + pdat.Email + '\n\n' body = body + '\n\nSincerely,\n\nNorma Ghanem\nFirst Eagle Logistics, Inc.\n505 Hampton Park Blvd Unit O\nCapitol Heights,MD 20743\n301 516 3000' msg.attach(MIMEText(body, 'plain')) #attachment = open(fileToSend, "rb") #part = MIMEBase('application', 'octet-stream') #part.set_payload((attachment).read()) #encoders.encode_base64(part) #part.add_header('Content-Disposition', "attachment; filename= %s" % fileToSend) #msg.attach(part) server = smtplib.SMTP(ourserver) #server.starttls() server.login(username, password) emailto = [emailto, emailcc1, emailcc2] server.sendmail(emailfrom, emailto, msg.as_string()) server.quit()
def etemplate_truck(viewtype, eprof, odat): cdata = companydata() bid = odat.Bid jo = odat.Jo order = odat.Order signature = cdata[2] + '\n' + cdata[5] + '\n' + cdata[6] + '\n' + cdata[7] print('templated to:', viewtype, eprof) od, bol, con, bk = odat.Order, odat.BOL, odat.Container, odat.Booking od, bol, con, bk = stripper(od), stripper(bol), stripper(con), stripper(bk) if bol is None: keyval = bk else: if len(bol) < 5: keyval = bk else: keyval = bol dblk = odat.Dropblock2 if dblk is not None: dblk = dblk.splitlines() else: dblk = ['', '', '', '', ''] pdat = People.query.get(bid) estatus, epod, eaccts = pdat.Email, pdat.Associate1, pdat.Associate2 estatus, epod, eaccts = stripper(estatus), stripper(epod), stripper(eaccts) if eprof == 'eprof1': etitle = f'Update on Order: {od} | {keyval} | {con}' ebody = f'Dear {odat.Shipper},\n\nOur trucker is at the delivery site:\n\t\t{dblk[0]}\n\t\t{dblk[1]}\n\t\t{dblk[2]}\nWe will send a POD as soon as one can be obtained.\n\nSincerely,\n\n{signature}' aname = 'none' emailin1 = estatus emailin2 = '' emailcc1 = em['info'] emailcc2 = '' emaildata = [ etitle, ebody, emailin1, emailin2, emailcc1, emailcc2, aname ] return emaildata elif eprof == 'eprof2': etitle = f'Update on Order: {od} | {keyval} | {con}' ebody = f'Dear {odat.Shipper},\n\nThe subject container has been pulled from the port. Delivery is scheduled for {odat.Date2} to:\n\t\t{dblk[0]}\n\t\t{dblk[1]}\n\t\t{dblk[2]}\nWe will send a POD as soon as delivery is complete.\n\nSincerely,\n\n{signature}' aname = odat.Gate emailin1 = estatus emailin2 = '' emailcc1 = em['info'] emailcc2 = '' emaildata = [ etitle, ebody, emailin1, emailin2, emailcc1, emailcc2, aname ] return emaildata elif eprof == 'eprof3': etitle = f'Invoice for Completed Order: {od} | {keyval} | {con}' ebody = f'Dear {odat.Shipper},\n\nThe subject order has been completed, and your invoice for services is attached.\n\nWe greatly appreciate your business.\n\nSincerely,\n\n{signature}' aname = odat.Invoice aname = aname.replace('INV', 'Invoice_') emailin1 = estatus emailin2 = eaccts emailcc1 = em['info'] emailcc2 = em['expo'] emaildata = [ etitle, ebody, emailin1, emailin2, emailcc1, emailcc2, aname ] return emaildata elif eprof == 'eprof4': etitle = f'Proof for Completed Order: {od} | {keyval} | {con}' ebody = f'Dear {odat.Shipper},\n\nThe subject order has been completed, and your proof of delivery is attached.\n\nPlease do not hesitate to respond if you have any questions.\n\nSincerely,\n\n{signature}' aname = odat.Proof emailin1 = estatus emailin2 = epod emailcc1 = em['info'] emailcc2 = em['expo'] emaildata = [ etitle, ebody, emailin1, emailin2, emailcc1, emailcc2, aname ] return emaildata elif eprof == 'eprof5': etitle = f'Invoice & Proof for Completed Order: {od} | {keyval} | {con}' ebody = f'Dear {odat.Shipper},\n\nThe subject order has been completed, and your invoice with proof of delivery is attached.\n\nPlease do not hesitate to respond if you have any questions.\n\nSincerely,\n\n{signature}' aname = f'Package_{odat.Jo}.pdf' emailin1 = estatus emailin2 = eaccts emailcc1 = em['info'] emailcc2 = em['expo'] emaildata = [ etitle, ebody, emailin1, emailin2, emailcc1, emailcc2, aname ] return emaildata elif eprof == 'eprof6': etitle = f'Invoice Package for Completed Order: {od} | {keyval} | {con}' ebody = f'Dear {odat.Shipper},\n\nThe subject order has been completed, and your invoice package is attached.\n\nPlease do not hesitate to respond if you have any questions.\n\nSincerely,\n\n{signature}' aname = f'Package_{odat.Jo}.pdf' emailin1 = estatus emailin2 = eaccts emailcc1 = em['info'] emailcc2 = em['expo'] emaildata = [ etitle, ebody, emailin1, emailin2, emailcc1, emailcc2, aname ] return emaildata elif viewtype == 'invoice': etitle = f'Invoice for Completed Order: {od} | {keyval} | {con}' ebody = f'Dear {odat.Shipper},\n\nThe subject order has been completed, and your invoice for services is attached.\n\nWe greatly appreciate your business.\n\nSincerely,\n\n{signature}' aname = odat.Invoice aname = aname.replace('INV', 'Invoice_') emailin1 = estatus emailin2 = eaccts emailcc1 = em['info'] emailcc2 = em['expo'] emaildata = [ etitle, ebody, emailin1, emailin2, emailcc1, emailcc2, aname ] return emaildata elif viewtype == 'paidinvoice': etitle = f'Payment Received on Invoice {odat.Jo} for Completed Order: {od} | {keyval} | {con}' ebody = f'Dear {odat.Shipper},\n\nYour payment has been received, and your stamped invoice is attached.\n\nWe greatly appreciate your business.\n\nSincerely,\n\n{signature}' aname = odat.Invoice aname = aname.replace('INV', 'Paid_Invoice_') emailin1 = estatus emailin2 = eaccts emailcc1 = em['info'] emailcc2 = em['expo'] emaildata = [ etitle, ebody, emailin1, emailin2, emailcc1, emailcc2, aname ] return emaildata elif viewtype == 'packages': etitle = f'{scac} Invoice Package for Completed Orders: {od} | {keyval} | {con}' ebody = f'Dear {odat.Shipper},\n\nAn invoice package is enclosed for your review.\nWe greatly appreciate your business.\n\nSincerely,\n\n{signature}' aname = f'Package_{odat.Jo}.pdf' emailin1 = estatus emailin2 = eaccts emailcc1 = em['info'] emailcc2 = em['expo'] emaildata = [ etitle, ebody, emailin1, emailin2, emailcc1, emailcc2, aname ] return emaildata elif viewtype == 'invopackage': etitle = f'{scac} Invoice Package {odat.Package}' ebody = f'Dear {odat.Shipper},\n\nAn invoice package is enclosed for your review.\nWe greatly appreciate your business.\n\nSincerely,\n\n{signature}' aname = odat.Package emailin1 = estatus emailin2 = eaccts emailcc1 = em['info'] emailcc2 = em['expo'] emaildata = [ etitle, ebody, emailin1, emailin2, emailcc1, emailcc2, aname ] return emaildata elif viewtype == 'quote': etitle = cdata[2] + ' Quote: ' + jo ebody = 'Dear Customer:\n\nYour quote is attached. Please sign and return at your earliest convenience.\n\nWe look forward to doing business with you.\n\nSincerely,\n\n' + \ cdata[3] + '\n\n\n' + cdata[4] + '\n' + cdata[2] + '\n' + cdata[5] + '\n' + cdata[6] + '\n' + cdata[7] else: etitle = 'Unknown' ebody = 'Could not determine the type of package being emailed here.' try: pdat = People.query.get(bid) emailin1 = str(pdat.Email) except: emailin1 = 'Not Found' emailin2 = '' emailcc1 = em['info'] emailcc2 = em['serv'] emaildata = [etitle, ebody, emailin1, emailin2, emailcc1, emailcc2, ''] return emaildata
# These are dictionary setups that control the look, feel, and functionality of the class8 view screens from CCC_system_setup import companydata co = companydata() genre = 'Trucking' jobcode = co[10] + genre[0] Trucking_genre = {'table': 'Orders', 'genre_tables': ['Orders', 'Interchange', 'Customers', 'Services'], 'genre_tables_on': ['on', 'off', 'off', 'off'], 'quick_buttons': ['New', 'Mod', 'Inv', 'Rec'], 'table_filters': [{'Date Filter': ['Last 60 Days', 'Last 120 Days', 'Last 180 Days', 'Show All']}, {'Pay Filter': ['Uninvoiced', 'Unrecorded', 'Unpaid', 'Show All']}, {'Haul Filter': ['Not Started', 'In-Progress', 'Incomplete', 'Completed', 'Show All']}, {'Color Filter': ['Haul', 'Invoice', 'Both']}], 'task_boxes': [{'Add Items': ['New Job', 'New Customer', 'New Interchange', 'New Service', 'New From Copy', 'Upload Source', 'Upload Proof', 'Make Manifest']}, {'Edit Items': ['Edit', 'Match', 'Accept', 'Haul+1', 'Haul-1', 'Haul Done', 'Inv+1', 'Inv-1', 'Inv Emailed', 'Set Col To']}, {'Money Items': ['Inv Edit', 'Quote Edit', 'Package Send', 'Rec Payment', 'Rec by Acct']}, {'View Docs': ['Source', 'Proof', 'Manifest', 'Interchange', 'Invoice', 'Paid Invoice']}, {'Undo': ['Delete Item', 'Undo Invoice', 'Undo Payment']}, {'Tasks': ['Street Turn', 'Unpulled Containers', 'Assign Drivers', 'Driver Hours', 'Driver Payroll', 'Truck Logs', 'Text Output']}], 'container_types': ['40\' GP 9\'6\"', '40\' RS 9\'6\"', '40\' GP 8\'6\"', '40\' RS 8\'6\"', '20\' GP 8\'6\"', '20\' VH 8\'6\"', '45\' GP 9\'6\"', '45\' VH 9\'6\"', '53\' Dry', 'LCL', 'RORO'], 'load_types': ['Load In', 'Load Out', 'Empty In', 'Empty Out'], 'task_mapping': {'Job':'Orders', 'Customer':'Customers', 'Service':'Services', 'Interchange':'Interchange'}
def isoQuote(): username = session['username'].capitalize() quot = 0 tbox = [0] * 4 qdat = None from viewfuncs import dataget_Q, nonone, numcheck if request.method == 'POST': emailgo = request.values.get('Email') updatego = request.values.get('GetQuote') updatebid = request.values.get('Update') updateE = request.values.get('UpdateE') returnhit = request.values.get('Return') bidname = request.values.get('bidname') bidthis = request.values.get('bidthis') bidthis = d2s(bidthis) locfrom = request.values.get('locfrom') thismuch = request.values.get('thismuch') taskbox = request.values.get('taskbox') taskbox = nonone(taskbox) quotbut = request.values.get('optradio') qdata = dataget_Q(thismuch) #quot, numchecked = numcheck(1, qdata, 0, 0, 0, 0, ['quot']) if quotbut is not None: quot = nonone(quotbut) if quot == 0: quot = request.values.get('quotpass') quot = nonone(quot) qdat = Quotes.query.get(quot) print(quot, quotbut, username) if returnhit is not None: taskbox = 0 quot = 0 if taskbox == 2: qdat.Status = -1 db.session.commit() taskbox = 0 if taskbox == 3: qdat.Status = 0 db.session.commit() taskbox = 0 if taskbox == 4: qdat.Status = 3 db.session.commit() taskbox = 0 if taskbox == 6: add_quote_emails() if taskbox == 1 or taskbox == 5: if quot > 0 and qdat is not None: locto = qdat.Location if locto is None: locto = get_place(qdat.Body) qdat.Location = locto db.session.commit() emailto = qdat.From if emailto is None: emailto = qdat.From qdat.From = emailto db.session.commit() else: comdata = companydata() locto = comdata[6] emailto = usernames['expo'] if quot > 0 or taskbox == 5: if qdat is not None: locfrom = qdat.Start if locfrom is None: locfrom = 'Seagirt Marine Terminal, Baltimore, MD 21224' else: locfrom = 'Seagirt Marine Terminal, Baltimore, MD 21224' if updatego is not None or updatebid is not None or emailgo is not None or updateE is not None: locto = request.values.get('locto') if locto is None: locto = 'Capitol Heights, MD 20743' locfrom = request.values.get('locfrom') emailto = request.values.get('edat2') respondnow = datetime.datetime.now() if taskbox == 1: qdat.Start = locfrom qdat.Location = locto qdat.From = emailto qdat.Amount = bidthis qdat.Person = bidname qdat.Responder = username qdat.RespDate = respondnow qdat.Status = 1 db.session.commit() if emailgo is not None: if taskbox == 1: qdat.Status = 2 db.session.commit() emaildata = sendquote(bidthis) taskbox = 0 quot = 0 print('Running Directions:', locfrom, locto, bidthis, bidname, taskbox, quot) try: #################################### Directions Section ###################################### miles, hours, lats, lons, dirdata, tot_dist, tot_dura = get_directions( locfrom, locto) #print(f'Total distance {d1s(tot_dist)} miles and total duration {d1s(tot_dura)} hours') #Calculate road tolls tollroadlist = ['I-76', 'NJ Tpke'] tollroadcpm = [.784, .275] legtolls = len(dirdata) * [0.0] legcodes = len(dirdata) * ['None'] for lx, mi in enumerate(miles): for nx, tollrd in enumerate(tollroadlist): if tollrd in dirdata[lx]: legtolls[lx] = tollroadcpm[nx] * mi legcodes[lx] = tollrd #Calculate plaza tolls fm_tollbox = [39.267757, -76.610192, 39.261248, -76.563158] bht_tollbox = [ 39.259962, -76.566240, 39.239063, -76.603324 ] fsk_tollbox = [ 39.232770, -76.502453, 39.202279, -76.569906 ] bay_tollbox = [ 39.026893, -76.417512, 38.964938, -76.290104 ] sus_tollbox = [ 39.585193, -76.142883, 39.552328, -76.033975 ] new_tollbox = [ 39.647121, -75.774523, 39.642613, -75.757187 ] #Newark Delaware Toll Center dmb_tollbox = [ 39.702146, -75.553479, 39.669730, -75.483284 ] tollcodes = [ 'FM', 'BHT', 'FSK', 'BAY', 'SUS', 'NEW', 'DMB' ] tollboxes = [ fm_tollbox, bht_tollbox, fsk_tollbox, bay_tollbox, sus_tollbox, new_tollbox, dmb_tollbox ] for jx, lat in enumerate(lats): stat1 = 'ok' stat2 = 'ok' stat3 = 0 stat4 = 0 tollcode = 'None' la = float(lat) lo = float(lons[jx]) for kx, tollbox in enumerate(tollboxes): lah = max([tollbox[0], tollbox[2]]) lal = min([tollbox[0], tollbox[2]]) loh = max([tollbox[1], tollbox[3]]) lol = min([tollbox[1], tollbox[3]]) if la > lal and la < lah: stat1 = 'toll' if lo > lol and lo < loh: stat2 = 'toll' tollcode = tollcodes[kx] legtolls[jx] = 24.00 legcodes[jx] = tollcode if jx > 0: lam = (lah + lal) / 2.0 lom = (loh + lol) / 2.0 la_last = float(lats[jx - 1]) lo_last = float(lons[jx - 1]) stat3, stat4 = checkcross( lam, la_last, la, lom, lo_last, lo) if stat3 == 1 and stat4 == 1: tollcode = tollcodes[kx] legtolls[jx] = 24.00 legcodes[jx] = tollcode ##print(lat,lons[jx],stat1, stat2, stat3, stat4, tollcode) tot_tolls = 0.00 ex_drv = 27.41 ex_fuel = .48 ex_toll = 24.00 ex_insur = 4.00 ex_rm = .22 ex_misc = .04 ex_ga = 15 expdata = [ d2s(ex_drv), d2s(ex_fuel), d2s(ex_toll), d2s(ex_insur), d2s(ex_rm), d2s(ex_misc), d2s(ex_ga) ] porttime = 1.4 loadtime = 2.0 triptime = tot_dura * 2.0 glidetime = 1.0 + triptime * .01 tottime = porttime + loadtime + triptime + glidetime timedata = [ d1s(triptime), d1s(porttime), d1s(loadtime), d1s(glidetime), d1s(tottime) ] tripmiles = tot_dist * 2.0 portmiles = .4 glidemiles = 10 + .005 * tripmiles totmiles = tripmiles + portmiles + glidemiles distdata = [ d1s(tripmiles), d1s(portmiles), '0.0', d1s(glidemiles), d1s(totmiles) ] newdirdata = [] for lx, aline in enumerate(dirdata): tot_tolls += legtolls[lx] aline = aline.replace( '<div style="font-size:0.9em">Toll road</div>', '') aline = aline.strip() #print(aline) #print(f'Dist:{d1s(miles[lx])}, Time:{d1s(hours[lx])}, ') if legtolls[lx] < .000001: newdirdata.append( f'{d1s(miles[lx])} MI {d2s(hours[lx])} HRS {aline}' ) else: newdirdata.append( f'{d1s(miles[lx])} MI {d2s(hours[lx])} HRS {aline} Tolls:${d2s(legtolls[lx])}, TollCode:{legcodes[lx]}' ) # Cost Analysis: cost_drv = tottime * ex_drv cost_fuel = totmiles * ex_fuel cost_tolls = 2.0 * tot_tolls cost_insur = tottime * ex_insur cost_rm = totmiles * ex_rm cost_misc = totmiles * ex_misc cost_direct = cost_drv + cost_fuel + cost_tolls + cost_insur + cost_rm + cost_misc cost_ga = cost_direct * ex_ga / 100.0 cost_total = cost_direct + cost_ga costdata = [ d2s(cost_drv), d2s(cost_fuel), d2s(cost_tolls), d2s(cost_insur), d2s(cost_rm), d2s(cost_misc), d2s(cost_ga), d2s(cost_direct), d2s(cost_total) ] bid = cost_total * 1.2 cma_bid = bid / 1.13 std_bid = 250. + 2.1 * totmiles biddata = [ d2s(roundup(bid)), d2s(roundup(std_bid)), d2s(roundup(cma_bid)) ] if updatego is not None or quotbut is not None or ( taskbox == 5 and updatebid is None): bidthis = d2s(roundup(bid)) except: costdata = None biddata = None newdirdata = None bidthis = None bidname = None ex_drv = 27.41 ex_fuel = .48 ex_toll = 24.00 ex_insur = 4.00 ex_rm = .22 ex_misc = .04 ex_ga = 15 expdata = [ d2s(ex_drv), d2s(ex_fuel), d2s(ex_toll), d2s(ex_insur), d2s(ex_rm), d2s(ex_misc), d2s(ex_ga) ] timedata = [] distdata = [] if quotbut is not None: #Set the email data: etitle = f'{cdata[0]} Quote to {locto} from {locfrom}' if qdat is not None: customer = qdat.Person if customer is None: customer = friendly(emailto) else: customer = friendly(emailto) qdat.Person = customer bidname = customer db.session.commit() ebody, tbox = bodymaker(bidname, cdata, bidthis, locto, tbox) ebody = ebody + maketable() emailin1 = request.values.get('edat2') if updatego is None: emailin1 = emailonly(emailto) emailin2 = '' emailcc1 = usernames['info'] emailcc2 = usernames['expo'] emaildata = [ etitle, ebody, emailin1, emailin2, emailcc1, emailcc2 ] else: #Set the email data: if updatebid is not None or updatego is not None: etitle = f'{cdata[0]} Quote to {locto} from {locfrom}' ebody, tbox = bodymaker(bidname, cdata, bidthis, locto, tbox) ebody = ebody + maketable() else: etitle = request.values.get('edat0') ebody = request.values.get('edat1') emailin1 = request.values.get('edat2') emailin2 = request.values.get('edat3') emailcc1 = request.values.get('edat4') emailcc2 = request.values.get('edat5') emaildata = [ etitle, ebody, emailin1, emailin2, emailcc1, emailcc2 ] #qdat.Response = ebody db.session.commit() else: qdata = dataget_Q(thismuch) quot = request.values.get('optradio') if quot is not None: qdat = Quotes.query.get(quot) locto = 'Capitol Heights, MD 20743' locfrom = 'Baltimore Seagirt' etitle = f'{cdata[0]} Quote for Drayage to {locto} from {locfrom}' if qdat is not None: ebody = qdat.Body else: ebody = f'Regirgitation from the input' efrom = usernames['quot'] eto1 = 'unknown' eto2 = '' ecc1 = usernames['expo'] ecc2 = usernames['info'] emaildata = [etitle, ebody, eto1, eto2, ecc1, ecc2, efrom] costdata = None biddata = None newdirdata = None bidthis = None bidname = None ex_drv = 27.41 ex_fuel = .48 ex_toll = 24.00 ex_insur = 4.00 ex_rm = .22 ex_misc = .04 ex_ga = 15 expdata = [ d2s(ex_drv), d2s(ex_fuel), d2s(ex_toll), d2s(ex_insur), d2s(ex_rm), d2s(ex_misc), d2s(ex_ga) ] timedata = [] distdata = [] else: print('Entering Quotes1', flush=True) username = session['username'].capitalize() tbox = [] qdat = None locto = 'Upper Marlboro, MD 20772' locfrom = 'Baltimore Seagirt' etitle = f'{cdata[0]} Quote for Drayage to {locto} from {locfrom}' ebody = f'Regirgitation from the input' efrom = usernames['quot'] eto1 = 'unknown' eto2 = '' ecc1 = usernames['expo'] ecc2 = usernames['info'] emaildata = [etitle, ebody, eto1, eto2, ecc1, ecc2, efrom] costdata = None biddata = None newdirdata = None bidthis = None bidname = None print('Entering Quotes2', flush=True) ex_drv = 27.41 ex_fuel = .48 ex_toll = 24.00 ex_insur = 4.00 ex_rm = .22 ex_misc = .04 ex_ga = 15 expdata = [ d2s(ex_drv), d2s(ex_fuel), d2s(ex_toll), d2s(ex_insur), d2s(ex_rm), d2s(ex_misc), d2s(ex_ga) ] timedata = [] distdata = [] add_quote_emails() thismuch = '1' taskbox = 0 quot = 0 print('Entering Quotes3', flush=True) print('Getting qdata', flush=True) qdata = dataget_Q(thismuch) print(quot) return bidname, costdata, biddata, expdata, timedata, distdata, emaildata, locto, locfrom, newdirdata, qdata, bidthis, taskbox, thismuch, quot, qdat, tbox