Beispiel #1
0
def main(odata, ldata, pdata1, cache, invodate, payment):
    # pdata1:Bid (Bill To)
    # pdata2:Lid (Load At)
    # pdata3:Did (Delv To)

    from reportlab.pdfgen import canvas
    from reportlab.lib.pagesizes import letter
    from reportlab.lib.pagesizes import landscape
    from reportlab.platypus import Image
    from reportlab.lib.units import inch
    import csv
    import math
    import datetime
    import shutil
    from CCC_system_setup import bankdata, scac

    joborder = odata.Jo
    file1 = f'tmp/{scac}/data/vinvoice/INV'+joborder+'.pdf'
    file2 = f'tmp/{scac}/data/vinvoice/INV'+joborder+'c'+str(cache)+'.pdf'
    today = datetime.datetime.today().strftime('%m/%d/%Y')
    type = joborder[1]
    if invodate is None or invodate == 0:
        invodate = today
    else:
        invodate = invodate.strftime('%m/%d/%Y')

    def dollar(infloat):
        outstr = '$'+"%0.2f" % infloat
        return outstr

    def avg(in1, in2):
        out = (in1+in2)/2
        return out

    def comporname(company, name):
        if company is None or company == '':
            nameout = name
        else:
            if len(company) < 4:
                nameout = name
            else:
                nameout = company
        return nameout

    def fullname(first, middle, last):
        if first is not None:
            nameout = first
        else:
            nameout = ''
        if middle is not None:
            nameout = nameout+' '+middle
        if last is not None:
            nameout = nameout+' '+last
        if len(nameout) > 55:
            nameout = first + ' ' + last
        return nameout

    def address(addr1, addr2, addr3):
        street = addr1
        if addr3 is None or addr3 == '':
            cityst = addr2
        else:
            if len(addr3) < 5:
                cityst = addr2
        if addr2 is None or addr2 == '':
            cityst = addr3
            if len(addr2) < 3:
                cityst = addr3
        if addr2 and addr3:
            if len(addr2) > 3 and len(addr3) > 3:
                street = addr1 + ' ' + addr2
                cityst = addr3
        return street, cityst

    def nononestr(input):
        if input is None or input == 'None':
            input = ''
        return input

    def nonone(input):
        if input is None:
            input = 0
        return input

    if payment != 0:
        try:
            paydate = payment[2].strftime('%m/%d/%Y')
        except:
            paydate = payment[2]

    billto = list(range(5))
    if pdata1 is not None:
        billto[0] = comporname(pdata1.Company, fullname(pdata1.First, pdata1.Middle, pdata1.Last))
        billto[1] = nononestr(pdata1.Addr1)
        billto[2] = nononestr(pdata1.Addr2)
        billto[3] = nononestr(pdata1.Telephone)
        billto[4] = nononestr(pdata1.Email)
    else:
        for i in range(5):
            billto[i] = ' '

    us = list(range(4))
    us[0] = 'HORIZON MOTORS INC'
    us[1] = '505 HAMPTON PARK BLVD UNIT N'
    us[2] = 'CAPITOL HEIGHTS MD  20743'
    us[3] = '301-909-1819  [email protected]'

    line1 = ['Quantity', 'Item Code', 'Description', 'Price Each', 'Amount']

    note = list(range(2))
    note[0] = '*Horizon Motors Auto License# X800013003087'
    note[1] = '*Hoizon Motors Car Sales Terms and Conditions'

    lab1 = 'Balance Due'
    lab2 = 'Add $39.00 for all international wires'

    nonote, bank = bankdata('HC')

# ___________________________________________________________

    ltm = 36
    rtm = 575
    ctrall = 310
    left_ctr = 170
    right_ctr = 480
    dl = 17.6
    tdl = dl*2
    hls = 530
    m1 = hls-dl
    m2 = hls-2*dl
    m3 = hls-3*dl
    m4 = hls-4*dl
    m5 = hls-18*dl
    m6 = hls-23*dl
    m7 = hls-27*dl
    fulllinesat = [m3, m4, m5, m6, m7]
    p1 = ltm+87
    p2 = ltm+180
    p3 = ctrall-25
    p4 = rtm-220
    p5 = rtm-120
    sds1 = [p1, p2, p3, p4, p5]
    n1 = ltm+58
    n2 = ltm+128
    n3 = rtm-140
    n4 = rtm-70
    sds2 = [n1, n2, n3, n4]
    q1 = ltm+180
    q2 = rtm-180
    sds3 = [q1, q2]
    bump = 2.5
    tb = bump*2

    c = canvas.Canvas(file2, pagesize=letter)
    c.setLineWidth(1)

    logo = "tmp/felpics/hm.jpg"
    c.drawImage(logo, 220, 580, mask='auto', width=180, preserveAspectRatio=True)

    # Date and JO boxes
    dateline = m1+8.2*dl
    c.rect(rtm-150, m1+7*dl, 150, 2*dl, stroke=1, fill=0)
    c.line(rtm-150, dateline, rtm, dateline)
    c.line(rtm-75, m1+7*dl, rtm-75, m1+9*dl)

    # Address boxes
    ctm = 218
    c.rect(ltm, m1+dl, 250, 5*dl, stroke=1, fill=0)
    #c.rect(ctm, m1+dl,175,5*dl, stroke=1, fill=0)
    #c.rect(rtm-175, m1+dl,175,5*dl, stroke=1, fill=0)
    level1 = m1+5*dl
    c.line(ltm, level1, ltm+250, level1)
    # c.line(ctm,level1,ctm+175,level1)
    # c.line(rtm-175,level1,rtm,level1)

    for i in fulllinesat:
        c.line(ltm, i, rtm, i)
    # for k in sds1:
        # c.line(k,m1,k,m3)
    for l in sds2:
        c.line(l, m3, l, m5)
    for m in sds3:
        c.line(m, m6, m, m7)
    c.line(ltm, m3, ltm, m7)
    c.line(rtm, m3, rtm, m7)
    h1 = avg(m6, m7)-3
    c.line(q2, h1, rtm, h1)

    c.setFont('Helvetica-Bold', 24, leading=None)
    c.drawCentredString(rtm-75, dateline+1.5*dl, 'Invoice')

    c.setFont('Helvetica', 12, leading=None)

    c.drawCentredString(rtm-112.5, dateline+bump, 'Date')
    c.drawCentredString(rtm-37.7, dateline+bump, 'Invoice #')

    c.drawString(ltm+bump*3, m1+5*dl+bump*2, 'Bill To')

#    ctr=[avg(ltm,p1),avg(p1,p2),avg(p2,p3),avg(p3,p4),avg(p4,p5),avg(p5,rtm)]
#    for j,i in enumerate(line1):
#        c.drawCentredString(ctr[j],m2+tb,i)

    ctr = [avg(ltm, n1), avg(n1, n2), avg(n2, n3), avg(n3, n4), avg(n4, rtm)]
    for j, i in enumerate(line1):
        c.drawCentredString(ctr[j], m4+tb, i)

    dh = 12
    ct = 305
    top = m6-1.5*dh
    for i in bank:
        c.drawCentredString(ct, top, i)
        top = top-dh

    top = m1+9*dl-5
    for i in us:
        c.drawString(ltm+bump, top, i)
        top = top-dh

    bottomline = m6-23
    c.setFont('Helvetica-Bold', 12, leading=None)
    c.drawString(q2+tb, bottomline, 'Balance Due:')

    c.setFont('Helvetica', 10, leading=None)
    c.drawCentredString(avg(q2, rtm), m7+12, 'Add $39.00 for all international wires')

    c.setFont('Times-Roman', 9, leading=None)
    j = 0
    dh = 9.95
    top = m5-dh
    for i in note:
        c.drawString(ltm+tb, top, note[j])
        j = j+1
        top = top-dh


# _______________________________________________________________________
    # Insert data here
# _______________________________________________________________________

    c.setFont('Helvetica', 12, leading=None)

    dh = 13
    top = level1-dh
    lft = ltm+bump*3
    for i in billto:
        c.drawString(lft, top, i)
        top = top-dh

    x = avg(rtm-75, rtm)
    y = dateline-dh-bump
    c.drawCentredString(x, y, joborder)
    x = avg(rtm-75, rtm-150)
    c.drawCentredString(x, y, invodate)

    c.setFont('Helvetica', 9, leading=None)

    total = 0
    top = m4-dh
    for data in ldata:
        qty = int(nonone(data.Qty))
        each = float(nonone(data.Ea))
        subtotal = qty*each
        total = total+subtotal
        line4 = [str(qty), data.Service]
        line5 = nononestr(data.Description)
        line6 = [each, subtotal]
        ctr = [avg(ltm, n1), avg(n1, n2)]
        for j, i in enumerate(line4):
            c.drawCentredString(ctr[j], top, i)

        c.drawString(n2+tb, top, line5)

        ctr = [n4-tb*2, rtm-tb*2]
        for j, i in enumerate(line6):
            c.drawRightString(ctr[j], top, dollar(i))

        top = top-dh

    if payment != 0:
        c.setFont('Helvetica-Bold', 18, leading=None)
        c.drawCentredString(ct, top-2*dh, 'Payment Received')

    if payment != 0:
        c.setFont('Helvetica-Bold', 12, leading=None)
        try:
            thispay = float(payment[0])
        except:
            thispay = 0.00
        top = top-4*dh
        try:
            c.drawString(n2+bump, top, 'Your payment of ' +
                         dollar(float(payment[0]))+', Ref No. '+payment[1])
        except:
            c.drawString(ct, top, 'There is no payment data as of yet')
        try:
            c.drawString(n2+bump, top-dh, 'was applied on ' + paydate)
        except:
            c.drawString(ct, top-dh, 'There is a problem with the date')

        else:
            thispay = 0.00

        total = total-thispay

    c.setFont('Helvetica-Bold', 12, leading=None)
    c.drawRightString(rtm-tb*2, bottomline, dollar(total))

    c.showPage()
    c.save()
    #
    # Now make a cache copy
    shutil.copy(file2, file1)
Beispiel #2
0
def main(file1, keydata, grandtotal, pdata1, date1, date2):
    # pdata1:Bid (Bill To)
    # pdata2:Lid (Load At)
    # pdata3:Did (Delv To)

    from reportlab.pdfgen import canvas
    from reportlab.lib.pagesizes import letter
    from reportlab.lib.pagesizes import landscape
    from reportlab.platypus import Image
    from reportlab.lib.units import inch
    import csv
    import math
    import datetime
    import shutil
    from viewfuncs import parseline
    from CCC_system_setup import addpath, bankdata

    file1 = addpath(file1)
    print(file1)

    date1 = date1.strftime('%m/%d/%Y')
    date2 = date2.strftime('%m/%d/%Y')

    # ___________________________________________________________

    def dollar(infloat):
        outstr = '$' + "%0.2f" % infloat
        return outstr

    def avg(in1, in2):
        out = (in1 + in2) / 2
        return out

    def comporname(company, name):
        if company is None or company == '':
            nameout = name
        else:
            if len(company) < 4:
                nameout = name
            else:
                nameout = company
        return nameout

    def fullname(first, middle, last):
        if first is not None:
            nameout = first
        else:
            nameout = ''
        if middle is not None:
            nameout = nameout + ' ' + middle
        if last is not None:
            nameout = nameout + ' ' + last
        if len(nameout) > 55:
            nameout = first + ' ' + last
        return nameout

    def address(addr1, addr2, addr3):
        street = addr1
        if addr3 is None or addr3 == '':
            cityst = addr2
        else:
            if len(addr3) < 5:
                cityst = addr2
        if addr2 is None or addr2 == '':
            cityst = addr3
            if len(addr2) < 3:
                cityst = addr3
        if addr2 and addr3:
            if len(addr2) > 3 and len(addr3) > 3:
                street = addr1 + ' ' + addr2
                cityst = addr3
        return street, cityst

    def nononestr(input):
        if input is None or input == 'None':
            output = ' '
        else:
            output = input
        return output

    def nonone(input):
        if input is None:
            input = 0
        return input

    billto = list(range(5))
    if pdata1 is not None:
        billto[0] = comporname(
            pdata1.Company, fullname(pdata1.First, pdata1.Middle, pdata1.Last))
        billto[1] = nononestr(pdata1.Addr1)
        billto[2] = nononestr(pdata1.Addr2)
        billto[3] = nononestr(pdata1.Telephone)
        billto[4] = nononestr(pdata1.Email)
    else:
        for i in range(5):
            billto[i] = ' '

    line2 = ['Invoice', 'Booking', 'Container', 'Description', 'Amount']

    qnote, note, bank, us, lab, logoi = bankdata('FC')

    ltm = 36
    rtm = 575
    ctrall = 310
    left_ctr = 170
    right_ctr = 480
    dl = 17.6
    tdl = dl * 2

    hls = 530
    # m1=hls-dl
    # m2=hls-2*dl
    m3 = hls - dl
    m4 = hls - 2 * dl
    m5 = hls - 18 * dl
    m6 = hls - 23 * dl
    m7 = hls - 27 * dl

    fulllinesat = [m3, m4, m5, m6, m7]
    p1 = ltm + 87
    p2 = ltm + 180
    p3 = ctrall
    p4 = rtm - 180
    p5 = rtm - 100
    # sds1   =[p1,p2,p3,p4,p5]
    n1 = ltm + 60
    n2 = ltm + 150
    n3 = ltm + 240
    n4 = rtm - 70
    sds2 = [n1, n2, n3, n4]
    q1 = ltm + 180
    q2 = rtm - 180
    sds3 = [q1, q2]
    bump = 2.5
    tb = bump * 2
    bottomline = m6 - 23

    print('file1 is', file1)
    c = canvas.Canvas(file1, pagesize=letter)
    c.setLineWidth(1)

    #logo = addpath("tmp/pics/onestop.png")
    c.drawImage(logoi, 185, 680, mask='auto')

    # Date and JO boxes
    dateline = m3 + 8.2 * dl
    c.rect(rtm - 150, m3 + 7 * dl, 150, 2 * dl, stroke=1, fill=0)
    c.line(rtm - 150, dateline, rtm, dateline)
    # c.line(rtm-75,m3+7*dl,rtm-75,m3+8*dl)
    c.drawCentredString(rtm - 75, dateline - 13 - bump, 'to')

    ctm = 218
    c.rect(ltm, m3 + dl, 175, 5 * dl, stroke=1, fill=0)
    #c.rect(ctm, m3+dl,175,5*dl, stroke=1, fill=0)
    #c.rect(rtm-175, m3+dl,175,5*dl, stroke=1, fill=0)
    level1 = m3 + 5 * dl
    c.line(ltm, level1, ltm + 175, level1)
    # c.line(ctm,level1,ctm+175,level1)
    # c.line(rtm-175,level1,rtm,level1)

    # All full horizontal lines
    for i in fulllinesat:
        c.line(ltm, i, rtm, i)

# for k in sds1:
# c.line(k,m1,k,m3)

    for l in sds2:
        c.line(l, m3, l, m5)

    for m in sds3:
        c.line(m, m6, m, m7)

    c.line(ltm, m3, ltm, m7)
    c.line(rtm, m3, rtm, m7)

    h1 = m6 - 3
    c.line(q2, h1, rtm, h1)

    c.setFont('Helvetica-Bold', 24, leading=None)
    c.drawCentredString(rtm - 75, dateline + 3 * dl, 'Invoice')
    c.drawCentredString(rtm - 75, dateline + 1.5 * dl, 'Summary')

    c.setFont('Helvetica', 12, leading=None)

    c.drawCentredString(rtm - 112.5, dateline + bump, 'Date')
    c.drawCentredString(rtm - 37.7, dateline + bump, 'Range')

    c.drawString(ltm + bump * 3, m3 + 5 * dl + bump * 2, 'Bill To')
    #c.drawString(ctm+bump*3,m1+5*dl+bump*2,'Load At')
    #c.drawString(rtm-170+bump*2,m1+5*dl+bump*2,'Delv To')
    dh = 13
    top = level1 - dh
    lft = ltm + bump * 3
    c.setFont('Helvetica', 10, leading=None)
    for i in billto:
        c.drawString(lft, top, i)
        top = top - dh
    c.setFont('Helvetica', 12, leading=None)

    x = avg(rtm - 75, rtm) + 3
    y = dateline - dh - bump
    c.drawCentredString(x, y, date2)
    x = avg(rtm - 75, rtm - 150) - 3
    c.drawCentredString(x, y, date1)

    c.drawRightString(rtm - tb * 2, bottomline, dollar(grandtotal))

    ctr = [avg(ltm, n1), avg(n1, n2), avg(n2, n3), avg(n3, n4), avg(n4, rtm)]
    for j, i in enumerate(line2):
        c.drawCentredString(ctr[j], m4 + tb, i)

    c.setFont('Helvetica', 10, leading=None)
    ctr = [avg(ltm, n1), avg(n1, n2), avg(n2, n3), avg(n4, rtm), avg(n3, n4)]
    top = m4 - dl
    for k, data in enumerate(keydata):
        dataline = keydata[k]
        print(dataline)
        for j, i in enumerate(dataline):
            if j == 4:
                dlen = len(i)
                if dlen > 35:
                    pline = parseline(i, 32)
                    for myline in pline:
                        if 'STORE' in myline: myline = 'WAREHOUSE STORAGE'
                        if 'None' in myline: myline = ''
                        if 'TBD' in myline: myline = ''
                        c.drawString(n3 + 5, top, myline)
                        top = top - .6 * dl
                else:
                    c.drawString(n3 + 5, top, i)
                    top = top - .6 * dl
            else:
                if 'None' in str(i): i = ''
                if 'TBD' in str(i): i = ''
                c.drawCentredString(ctr[j], top, str(i))
        top = top - .6 * dl

    c.setFont('Helvetica', 12, leading=None)
    dh = 12
    ct = 305
    top = m6 - 1.5 * dh
    for i in bank:
        c.drawCentredString(ct, top, i)
        top = top - dh

    top = m3 + 9 * dl - 5
    for i in us:
        c.drawString(ltm + bump, top, i)
        top = top - dh

    c.setFont('Helvetica-Bold', 12, leading=None)
    c.drawString(q2 + tb, bottomline, 'Balance Due:')

    c.setFont('Helvetica', 10, leading=None)
    c.drawCentredString(avg(q2, rtm), m7 + 12,
                        'Add $39.00 for all international wires')

    c.setFont('Times-Roman', 9, leading=None)

    dh = 9.95
    top = m5 - dh
    for j, i in enumerate(note):
        c.drawString(ltm + tb, top, note[j])
        top = top - dh

    c.showPage()
    c.save()
Beispiel #3
0
def makemanifestT(odata, pdata1, pdata2, pdata3, tdata, drvdata, cache, jtype, commodity, packing, bol):
    #pdata1:Bid (Bill To)
    #pdata2:Lid (Load At)
    #pdata3:Did (Delv To)

    from reportlab.pdfgen import canvas
    from reportlab.lib.pagesizes import letter
    from reportlab.lib.pagesizes import landscape
    from reportlab.platypus import Image
    from reportlab.lib.units import inch
    import csv
    import math
    import datetime
    import shutil
    from viewfuncs import parseline, parselinenoupper
    from CCC_system_setup import manfile, addpath, bankdata, scac


    joborder=odata.Jo
    #file1='tmp/vmanifest/Manifest'+joborder+'.pdf'
    #file2='tmp/vmanifest/Manifest'+joborder+'c'+str(cache)+'.pdf'
    file1, file2 ,file3 = manfile(joborder,cache)
    today = datetime.datetime.today().strftime('%m/%d/%Y')
    type=joborder[1]
    try:
        invodate = request.values.get('sigdate')
        invodate = datetime.datetime.strptime(invodate,'%Y-%m-%d')
        invodate = invodate.strftime('%m/%d/%Y')
        if invodate is None:
            invodate=today
    except:
        invodate = today

    qnote, note, bank, us, lab, logoi = bankdata('FC')


    def dollar(infloat):
        outstr='$'+"%0.2f" % infloat
        return outstr

    def catline(instring,j):
        if len(instring)>j:
            instring=instring[0:j-1]
        return instring


    def avg(in1,in2):
        out=(in1+in2)/2
        return out

    def comporname(company,name):
        if company is None or company=='':
            nameout=name
        else:
            if len(company)<3:
                nameout=name
            else:
                nameout=company
        return nameout

    def fullname(first,middle,last):
        if first is not None:
            nameout=first
        else:
            nameout=''
        if middle is not None:
            nameout=nameout+' '+middle
        if last is not None:
            nameout=nameout+' '+last
        if len(nameout)>55:
            nameout=first + ' ' + last
        return nameout

    def address(addr1,addr2,addr3):
        street=addr1
        if addr3 is None or addr3=='':
            cityst=addr2
        else:
            if len(addr3)<5:
                cityst=addr2
        if addr2 is None or addr2=='':
            cityst=addr3
            if len(addr2)<3:
                cityst=addr3
        if addr2 and addr3:
            if len(addr2)>3 and len(addr3)>3:
                street=addr1 + ' ' + addr2
                cityst=addr3
        return street,cityst

    def nononestr(input):
        if input is None or input=='None':
            input=''
        return input

    def nonone(input):
        if input is None:
            input=0
        return input

    billto=list(range(5))
    if pdata1 is not None:
        billto[0]=comporname(pdata1.Company, fullname(pdata1.First, pdata1.Middle, pdata1.Last))
        billto[1]=nononestr(pdata1.Addr1)
        billto[2]=nononestr(pdata1.Addr2)
        billto[3]=nononestr(pdata1.Telephone)
        billto[4]=nononestr(pdata1.Email).lower()
    else:
        for i in range(5):
            billto[i]=' '

    for j,bill in enumerate(billto):
        billto[j]=catline(bill,25)

    if jtype=='Overseas':
        loadat=list(range(5))
        if pdata2 is not None:
            loadat[0]=comporname(pdata2.Company, fullname(pdata2.First, pdata2.Middle, pdata2.Last))
            loadat[1]=nononestr(pdata2.Addr1)
            loadat[2]=nononestr(pdata2.Addr2)
            loadat[3]=nononestr(pdata2.Telephone)
            loadat[4]=nononestr(pdata2.Email)
        else:
            for i in range(5):
                loadat[i]=' '

        shipto=list(range(5))
        if pdata3 is not None:
            shipto[0]=comporname(pdata3.Company, fullname(pdata3.First, pdata3.Middle, pdata3.Last))
            shipto[1]=nononestr(pdata3.Addr1)
            shipto[2]=nononestr(pdata3.Addr2)
            shipto[3]=nononestr(pdata3.Telephone)
            shipto[4]=nononestr(pdata3.Email)
        else:
            for i in range(5):
                shipto[i]=' '

    elif jtype=='Moving' or jtype=='Trucking':
        loadat=[' ']*5
        p2=odata.Dropblock1
        p2=p2.splitlines()
        for j,p in enumerate(p2):
            if j<5:
                loadat[j]=p.title()

        shipto=[' ']*5
        p2=odata.Dropblock2
        p2=p2.splitlines()
        for j,p in enumerate(p2):
            if j<5:
                shipto[j]=p.title()

    for j,bill in enumerate(shipto):
        shipto[j]=catline(bill,25)

    for j,bill in enumerate(loadat):
        loadat[j]=catline(bill,25)


    driver=str(drvdata.Name)
    truck=str(tdata.Unit)
    tag=str(tdata.Plate)

    container=str(odata.Container)
    book=str(odata.Booking)

    if jtype=='Trucking' or jtype=='Moving':
        order=str(odata.Order)
        pickup=str(odata.Pickup)
        date1=odata.Date
        date2=odata.Date2
        type=odata.Type
    else:
        order=str(odata.Booking)
        pickup=''
        date1=odata.PuDate
        date2=odata.RetDate
        type=odata.ContainerType

    seal=str(odata.Seal)

    try:
        date1s=date1.strftime('%m/%d/%Y')
    except:
        date1s='Nodate'
    try:
        date2s=date2.strftime('%m/%d/%Y')
    except:
        date2s='Nodate'

    #chassis='S019762'
    type=str(type)
    #deliver='82890104'
    loaddatetime=date1s
    deliverdatetime=date2s

    if '53' in type:
        labc='Trailer No.'
    else:
        labc='Container No.'


    line1=['SCAC', 'Driver', 'Truck #', 'Tag #', 'Size/Type', labc, 'Bill of Lading', 'Seal']
    line1a=[scac, driver, truck, tag, type, container, bol, seal]
    for j,item in enumerate(line1a):
        if item is None:
            line1a[j]=' '

    line2=['Biller Load/Order','Booking', 'Pickup/ShipperID', 'PU Date/Time', 'DEL Date/Time']
    line2a=[order, book, pickup, loaddatetime, deliverdatetime]
    line3=['Commodity and Units', 'Packaging and Description']
    line3a=[str(commodity), str(packing)]

    desclines = odata.Description
    if desclines is None:
        desclines = 'No description provided'

    note=list(range(4))
    note[0]='All appointments must be met.  If late the load may be refused or worked in without detention.'
    note[1]='If shipper and receiver addresses do not match BOL contact office immediately'
    note[2]='Dates for arrivals and departures are local.'
    note[3]='Dates, times, and estimates are given without any gurantee and are subject to change without prior notice.'

#___________________________________________________________


    ltm=36
    rtm=575
    ctrall=310
    left_ctr=170
    right_ctr=480
    dl=17.6
    tdl=dl*2
    hls=500
    t1=765
    t2=735
    m1=hls-dl
    m2=hls-2*dl
    m3=hls-3*dl
    m4=hls-4*dl
    m5=hls-5*dl
    m6=hls-6*dl
    m7=hls-7*dl

    m8=hls-18*dl
    m9=hls-23*dl
    m10=hls-27*dl
    fulllinesat=[m1, m2, m3, m4, m5, m6, m7, m8, m9, m10]
    width=rtm-ltm
    delta1=width/8
    p1=ltm+delta1-25
    p2=ltm+2*delta1+5
    p3=ltm+3*delta1-20
    p4=ltm+4*delta1-25
    p5=ltm+5*delta1-25
    p6=ltm+6*delta1
    p7=rtm-delta1+18
    sds1   =[p1,p2,p3,p4,p5,p6,p7]
    delta2=width/5
    n1=ltm+delta2
    n2=ltm+2*delta2
    n3=ltm+3*delta2
    n4=rtm-delta2
    sds2    =[n1,n2,n3,n4]
    bump=2.5
    tb=bump*2

    c=canvas.Canvas(file1, pagesize=letter)
    c.setLineWidth(1)

    c.drawImage(logoi, 185, 650, mask='auto')

    #Date and JO boxes
    dateline=m1+8.2*dl
    c.rect(rtm-150,m1+7*dl,150,2*dl,stroke=1,fill=0)
    c.line(rtm-150,dateline,rtm,dateline)
    c.line(rtm-75,m1+7*dl,rtm-75,m1+9*dl)

    #Top Box
    c.setLineWidth(1.5)
    c.rect(rtm,t2,ltm-rtm,30,stroke=1,fill=0)
    c.setFont('Helvetica-Bold',24,leading=None)
    c.drawCentredString(avg(rtm,ltm),t2+8,'Straight Bill of Lading')



    #Address boxes
    c.setLineWidth(1)
    ctm=218
    c.rect(ltm, m1+dl,175,5*dl, stroke=1, fill=0)
    c.rect(ctm, m1+dl,175,5*dl, stroke=1, fill=0)
    c.rect(rtm-175, m1+dl,175,5*dl, stroke=1, fill=0)
    level1=m1+5*dl
    c.line(ltm,level1,ltm+175,level1)
    c.line(ctm,level1,ctm+175,level1)
    c.line(rtm-175,level1,rtm,level1)

    cl1=m7-dl
    cl2=cl1-dl
    cl3=cl2-dl
    cl4=cl3-dl
    cl5=cl4-dl
    commfulllines=[cl1,cl2,cl3,cl4,cl5]

    for i in fulllinesat:
        c.line(ltm,i,rtm,i)
    for i in commfulllines:
        c.line(ltm,i,rtm,i)
    for k in sds1:
        c.line(k,m1,k,m3)
    for l in sds2:
        c.line(l,m3,l,m5)

    c.line(ctrall,m5,ctrall,cl1)

    c.line(ltm,t1,ltm,m10)
    c.line(rtm,t1,rtm,m10)

    #h1=avg(m6,m7)-3
    #c.line(q2,h1,rtm,h1)



    c.setFont('Helvetica',12,leading=None)

    c.drawCentredString(rtm-112.5,dateline+bump,'Date')
    c.drawCentredString(rtm-37.7,dateline+bump,'Job Order')


    c.drawString(ltm+bump*3,m1+5*dl+bump*2,'Bill To')
    c.drawString(ctm+bump*3,m1+5*dl+bump*2,'Load At')
    c.drawString(rtm-170+bump*2,m1+5*dl+bump*2,'Delv To')

    c.setFont('Helvetica',10,leading=None)

    ctr=[avg(ltm,p1),avg(p1,p2),avg(p2,p3),avg(p3,p4),avg(p4,p5),avg(p5,p6),avg(p6,p7),avg(p7,rtm)]
    for j, i in enumerate(line1):
        c.setFont('Helvetica-Bold',10,leading=None)
        c.drawCentredString(ctr[j],m2+tb,i)
        c.setFont('Helvetica',10,leading=None)
        c.drawCentredString(ctr[j],m3+tb,line1a[j])

    ctr=[avg(ltm,n1),avg(n1,n2),avg(n2,n3),avg(n3,n4),avg(n4,rtm)]
    for j, i in enumerate(line2):
        c.setFont('Helvetica-Bold',10,leading=None)
        c.drawCentredString(ctr[j],m4+tb,i)
        c.setFont('Helvetica',10,leading=None)
        c.drawCentredString(ctr[j],m5+tb,line2a[j])

    ctr=[avg(ltm,ctrall),avg(ctrall,rtm)]
    for j, i in enumerate(line3):
        c.setFont('Helvetica-Bold',10,leading=None)
        c.drawCentredString(ctr[j],m6+tb,i)
        c.setFont('Helvetica',10,leading=None)
        c.drawCentredString(ctr[j],m7+tb,line3a[j])
    dh=12
    ycoor = m7+tb - 2*dl
    xcoor = 40
    c.setFont('Helvetica-Bold',10,leading=None)
    c.drawString(xcoor,ycoor,'Special Instructions:')
    ycoor=ycoor-dl
    for desc in desclines.splitlines():
        c.drawString(xcoor,ycoor,desc)
        ycoor=ycoor-dl



    dh=12
    ct=305

    top=m1+9*dl-5
    for i in us:
        c.drawString(ltm+bump,top,i)
        top=top-dh

    bottomline=m9-23
    c.setFont('Helvetica-Bold',10,leading=None)
    j=0
    dh=11
    top=m8-dh
    c.drawString(ltm+tb,top,'Driver Notes:')
    c.setFont('Helvetica',10,leading=None)
    top=top-dh
    for i in note:
        c.drawString(ltm+tb,top,note[j])
        j=j+1
        top=top-dh



#_______________________________________________________________________
    #Insert data here
#_______________________________________________________________________

    c.setFont('Helvetica',11,leading=None)



    dh=13
    top=level1-dh
    lft=ltm+bump*3
    for i in billto:
        c.drawString(lft,top,i)
        top=top-dh

    top=level1-dh
    lft=ctm+bump*3
    for i in loadat:
        thisstr=parselinenoupper(i,35)
        for j in thisstr:
            c.drawString(lft,top,j)
            top=top-dh

    top=level1-dh
    lft=rtm-175+bump*3
    for i in shipto:
        c.drawString(lft,top,i)
        top=top-dh

    x=avg(rtm-75,rtm)
    y=dateline-dh-bump
    c.drawCentredString(x,y,joborder)
    x=avg(rtm-75,rtm-150)
    c.drawCentredString(x,y,invodate)


    total=0
    top=m4-dh

    x=ctrall+110
    y = cl5 - 2 * dl
    c.drawRightString(x,y,'Date:')
    c.drawString(x+20, y+bump, invodate)
    c.line(x+4,y,x+150,y)

    y=y-dl*1.5
    c.drawRightString(x,y,'   Arrival Time:')
    c.line(x+4,y,x+150,y)
    y=y-dl*1.5
    c.drawRightString(x,y,'Depart Time:')
    c.line(x+4,y,x+150,y)

    x=ltm+5
    c.drawString(x,y,'Received By:')
    c.line(x + 75, y, ctrall + 35, y)

    c.showPage()
    c.save()
    #
    #Now make a cache copy
    shutil.copy(file1,file2)
    print('returning file',file3)
    return file3
Beispiel #4
0
def reportmaker(type,thiscomp):

    cache = request.values.get('cache')
    cache=nonone(cache)

    file2=addpath(f'tmp/{scac}/data/vreport/background.pdf')
    file3=addpath(f'tmp/{scac}/data/vreport/headers.pdf')
    file4=addpath(f'tmp/{scac}/data/vreport/contents.pdf')
    qnote, note, bank, us, lab, logoi = bankdata('FC')
    file1=addpath(f'tmp/{scac}/data/vreport/pagestart.pdf')

    c=canvas.Canvas(file1, pagesize=letter)
    c.setLineWidth(1)
    #logo = addpath("tmp/pics/logo3.jpg")
    c.drawImage(logoi, 185, 680, mask='auto')
    c.showPage()
    c.save()

    if type=='mtick':
        ticketbackground(file2)
        ticketheaders(file3)
        itemlist=ticketcalcs()
        ticketcontents(file4,itemlist)
        cache,docref=pagemerger([file1,file2,file3,file4],cache)

    if type=='jay':
        invobackground(file2)
        jayheaders(file3)
        paiditems,servicelist,itemlist,bitemlist,total,btotal,nettotal=jaycalcs()
        pages,multioutput=jaycontents(file4,paiditems,servicelist,itemlist,bitemlist,total,btotal,nettotal,cache)
        if len(pages)>1:
            cache,docref=pagemergermp([file1,file2,file3],cache,pages,multioutput)
        else:
            cache,docref=pagemerger([file1,file2,file3,file4],cache)

    if type=='income':
        ticketbackground(file2)
        ticketheaders(file3)
        itemlist=incomecalcs()
        pages,multioutput=incomecontents(file4,itemlist,cache)
        if len(pages)>1:
            cache,docref=pagemergermp([file1,file2,file3],cache,pages,multioutput)
        else:
            cache,docref=pagemerger([file1,file2,file3,file4],cache)

    if type=='expenses':
        ticketbackground(file2)
        ticketheaders(file3)
        itemlist=incomecalcs()
        pages,multioutput=incomecontents(file4,itemlist,cache)
        if len(pages)>1:
            cache,docref=pagemergermp([file1,file2,file3],cache,pages,multioutput)
        else:
            cache,docref=pagemerger([file1,file2,file3,file4],cache)

    if type=='customer':
        custbackground(file2)
        custheaders(file3,thiscomp)
        print('thiscompany=',thiscomp)
        itemlist,headerlist,pstops=custcalcs(thiscomp)
        pages,multioutput=custcontents(file4,itemlist,headerlist,pstops,cache)
        if len(pages)>1:
            cache,docref=pagemergermp([file1,file2,file3],cache,pages,multioutput)
        else:
            cache,docref=pagemerger([file1,file2,file3,file4],cache)

    if type=='pl':
        custbackground(file2)
        plheaders(file3)
        itemlist,blist=plcalcs()
        pages,multioutput=plcontents(file4,itemlist,blist,cache)
        if len(pages)>1:
            cache,docref=pagemergermp([file1,file2,file3],cache,pages,multioutput)
        else:
            cache,docref=pagemerger([file1,file2,file3,file4],cache)

    if type=='deposit' or type=='recdeposit':


        if type=='recdeposit':
            stamp=1
        else:
            stamp=0
        file2=addpath(f'tmp/{scac}/data/vreport/depositslip.pdf')
        print('thiscomp=',thiscomp)
        itemlist=depositcalcs(thiscomp)
        # We are creating a deposit for review so get the account to deposit into
        depojo = request.values.get('depojo')
        acdeposit = request.values.get('acdeposit')
        print(itemlist,depojo)
        pages,multioutput=depositcontents(file4,itemlist,cache,depojo,acdeposit,stamp)
        cache,docref=pagemerger([file4,file2,file1],cache)

        if stamp == 1:
            savefile = addpath(f'tmp/{scac}/data/vdeposits/' + depojo + '.pdf')
            shutil.copyfile(addpath(docref), savefile)

    return cache,docref
Beispiel #5
0
def main(odata, ldata, pdata1, invojo, involine, paidline, refline, balline, invodate, cache, payment):
    # pdata1:Bid (Bill To)
    # pdata2:Lid (Load At)
    # pdata3:Did (Delv To)

    from reportlab.pdfgen import canvas
    from reportlab.lib.pagesizes import letter
    from reportlab.lib.pagesizes import landscape
    from reportlab.platypus import Image
    from reportlab.lib.units import inch
    import csv
    import math
    import datetime
    import shutil
    from viewfuncs import sdiff, sadd, dollar, nodollar, nononef
    from CCC_system_setup import myoslist, addpath, bankdata, scac

    joborder = invojo
    file1 = addpath(f'tmp/{scac}/data/vinvoice/INV'+joborder+'.pdf')
    file2 = addpath(f'tmp/{scac}/data/vinvoice/INV'+joborder+'c'+str(cache)+'.pdf')
    type = joborder[1]

    #today = datetime.datetime.today().strftime('%m/%d/%Y')
   # if invodate is None or invodate==0:
    # invodate=today
    # else:
    try:
        invodate = invodate.strftime('%m/%d/%Y')
    except:
        err = 'ivodate already a string'

    billhistory = involine
    payhistory = paidline
    openbalance = balline
    custref = refline
    pyopenbal = odata.BalFwd
    pyopenbal = nononef(pyopenbal)
    pyopenbal = nodollar(pyopenbal)

    a = pyopenbal
    for j, i in enumerate(openbalance):
        if billhistory[j] != '' or payhistory[j] != '':
            openbalance[j] = sadd(a, i)
            a = openbalance[j]
            if j > 0:
                b = openbalance[j-1]
            else:
                b = pyopenbal

    # 'a' is the last open balance and should be added to the bill
    try:
        prevbal = float(b)
    except:
        prevbal = 0.00

    def avg(in1, in2):
        out = (in1+in2)/2
        return out

    def comporname(company, name):
        if company is None or company == '':
            nameout = name
        else:
            if len(company) < 4:
                nameout = name
            else:
                nameout = company
        return nameout

    def fullname(first, middle, last):
        if first is not None:
            nameout = first
        else:
            nameout = ''
        if middle is not None:
            nameout = nameout+' '+middle
        if last is not None:
            nameout = nameout+' '+last
        if len(nameout) > 55:
            nameout = first + ' ' + last
        return nameout

    def address(addr1, addr2, addr3):
        street = addr1
        if addr3 is None or addr3 == '':
            cityst = addr2
        else:
            if len(addr3) < 5:
                cityst = addr2
        if addr2 is None or addr2 == '':
            cityst = addr3
            if len(addr2) < 3:
                cityst = addr3
        if addr2 and addr3:
            if len(addr2) > 3 and len(addr3) > 3:
                street = addr1 + ' ' + addr2
                cityst = addr3
        return street, cityst

    def nononestr(input):
        if input is None or input == 'None':
            input = ''
        return input

    def nonone(input):
        if input is None:
            input = 0
        return input

    billto = list(range(5))
    if pdata1 is not None:
        billto[0] = comporname(pdata1.Company, fullname(pdata1.First, pdata1.Middle, pdata1.Last))
        billto[1] = nononestr(pdata1.Addr1)
        billto[2] = nononestr(pdata1.Addr2)
        billto[3] = nononestr(pdata1.Telephone)
        billto[4] = nononestr(pdata1.Email)
    else:
        for i in range(5):
            billto[i] = ' '

    us = list(range(4))
    us[0] = 'FIRST EAGLE LOGISTICS INC'
    us[1] = '505 HAMPTON PARK BLVD UNIT O'
    us[2] = 'CAPITOL HEIGHTS MD  20743'
    us[3] = '301-516-3000  [email protected]'

    line1 = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
    line2 = ['Quantity', 'Item Code', 'Description', 'Price Each', 'Amount']
    line3 = billhistory
    line41 = payhistory
    line42 = custref
    line5 = openbalance

    note = list(range(3))
    note[0] = '*All invoices that are 15 days past due will incurr a $35.00 late fee.'
    note[1] = '*After 60 days an additional late fee will be assessed in the amount of $100.00.'
    note[2] = '*If your account reaches 90 days past due it will be submitted for collection.'

    lab1 = 'Balance Due'
    lab2 = 'Add $39.00 for all international wires'

    nonote, bank = bankdata('FC')

# ___________________________________________________________

    ltm = 36
    rtm = 575
    ctrall = 310
    left_ctr = 170
    right_ctr = 480
    dl = 17.6
    tdl = dl*2
    hls = 530
    m1 = hls-dl
    m2 = hls-2*dl
    m3 = hls-3*dl
    m4 = hls-4*dl
    m5 = hls-5*dl
    m61 = hls-6*dl
    m62 = hls-7*dl
    m63 = hls-8*dl

    m7 = hls-20*dl
    m8 = hls-23*dl
    m9 = hls-27*dl
    fulllinesat = [m1, m2, m3, m4, m5, m61, m62, m63, m7, m8, m9]

    p = [0]*13
    p[0] = ltm+87
    for i in range(1, 13):
        p[i] = p[i-1]+37.7

    n1 = ltm+58
    n2 = ltm+128
    n3 = rtm-140
    n4 = rtm-70
    sds2 = [n1, n2, n3, n4]
    q1 = ltm+180
    q2 = rtm-180
    sds3 = [q1, q2]
    bump = 2.5
    tb = bump*2

    c = canvas.Canvas(file1, pagesize=letter)
    c.setLineWidth(1)

    logo = addpath("tmp/felpics/logo3.jpg")
    c.drawImage(logo, 185, 680, mask='auto')

    # Date and JO boxes
    dateline = m1+8.2*dl
    c.rect(rtm-150, m1+7*dl, 150, 2*dl, stroke=1, fill=0)
    c.line(rtm-150, dateline, rtm, dateline)
    c.line(rtm-75, m1+7*dl, rtm-75, m1+9*dl)

    if type == 'S':
        # Address boxes
        ctm = 218
        c.rect(ltm, m1+dl, 175, 5*dl, stroke=1, fill=0)
        #c.rect(ctm, m1+dl,175,5*dl, stroke=1, fill=0)
        #c.rect(rtm-175, m1+dl,175,5*dl, stroke=1, fill=0)
        level1 = m1+5*dl
        c.line(ltm, level1, ltm+175, level1)
        # c.line(ctm,level1,ctm+175,level1)
        # c.line(rtm-175,level1,rtm,level1)

    for i in fulllinesat:
        c.line(ltm, i, rtm, i)
    for k in p[0:12]:
        c.line(k, m1, k, m61)
    for l in sds2:
        c.line(l, m62, l, m7)
    for m in sds3:
        c.line(m, m8, m, m9)
    c.line(ltm, m1, ltm, m9)
    c.line(rtm, m1, rtm, m9)
    h1 = avg(m8, m9)-3
    c.line(q2, h1, rtm, h1)

    c.setFont('Helvetica-Bold', 24, leading=None)
    c.drawCentredString(rtm-75, dateline+1.5*dl, 'Invoice')
    if payment != 0:
        c.setFont('Helvetica-Bold', 18, leading=None)
        c.drawCentredString(rtm-75, dateline-50, 'Payment Received')

    c.setFont('Helvetica', 12, leading=None)

    c.drawCentredString(rtm-112.5, dateline+bump, 'Date')
    c.drawCentredString(rtm-37.7, dateline+bump, 'Invoice #')

    c.drawString(ltm+bump*3, m1+5*dl+bump*2, 'Bill To')
    # c.drawString(ctm+bump*3,m1+5*dl+bump*2,'Load At')
    # c.drawString(rtm-170+bump*2,m1+5*dl+bump*2,'Delv To')

    dh = 12
    ct = 305

    if payment != 0:
        try:
            thispay = float(payment[0])
        except:
            thispay = 0.00
        top = m1+4*dl-5
        try:
            c.drawString(ct, top, 'Your payment of '+payment[0]+', Ref No. '+payment[1])
            c.drawString(ct, top-dh, 'was applied on '+payment[2])
        except:
            c.drawString(ct, top, 'There is no payment data as of yet')
    else:
        thispay = 0.00

    c.drawString(ct, m1+dl, 'Balance Fwd from 2018: $'+pyopenbal)

    j = 0
    ctr = [avg(ltm, n1), avg(n1, n2), avg(n2, n3), avg(n3, n4), avg(n4, rtm)]
    for i in line2:
        c.drawCentredString(ctr[j], m63+tb, i)
        j = j+1

    top = m8-1.5*dh
    for i in bank:
        c.drawCentredString(ct, top, i)
        top = top-dh

    top = m1+9*dl-5
    for i in us:
        c.drawString(ltm+bump, top, i)
        top = top-dh

    bottomline = m8-23
    c.setFont('Helvetica-Bold', 12, leading=None)
    c.drawString(q2+tb, bottomline, 'Balance Due:')

    c.setFont('Helvetica', 10, leading=None)
    c.drawCentredString(avg(q2, rtm), m9+12, 'Add $39.00 for all international wires')

    c.setFont('Times-Roman', 9, leading=None)
    j = 0
    dh = 9.95
    top = m7-dh
    for i in note:
        c.drawString(ltm+tb, top, note[j])
        j = j+1
        top = top-dh


# _______________________________________________________________________
    # Insert data here
# _______________________________________________________________________

    c.setFont('Helvetica', 12, leading=None)

    dh = 13
    top = level1-dh
    lft = ltm+bump*3
    for i in billto:
        c.drawString(lft, top, i)
        top = top-dh

    x = avg(rtm-75, rtm)
    y = dateline-dh-bump
    c.drawCentredString(x, y, joborder)
    x = avg(rtm-75, rtm-150)
    try:
        c.drawCentredString(x, y, invodate)
    except:
        err = 'Date not set yet'

    c.setFont('Helvetica', 9, leading=None)
    c.drawCentredString(avg(ltm, p[0]), m2+tb, '2019 by Month:')
    c.drawCentredString(avg(ltm, p[0]), m3+tb, 'Bill History')
    c.drawCentredString(avg(ltm, p[0]), m4+tb, 'Pay History')
    c.drawCentredString(avg(ltm, p[0]), m5+tb, 'Cust Ref No.')
    c.drawCentredString(avg(ltm, p[0]), m61+tb, 'Open Balances')
    for j, i in enumerate(line1):
        ctr = avg(p[j], p[j+1])
        c.drawCentredString(ctr, m2+tb, i)
        c.drawCentredString(ctr, m3+tb, line3[j])
        c.drawCentredString(ctr, m4+tb, line41[j])
        c.drawCentredString(ctr, m5+tb, line42[j])
        c.drawCentredString(ctr, m61+tb, line5[j])

    total = 0
    top = m63-dh
    for data in ldata:
        qty = int(nonone(data.Qty))
        each = float(nonone(data.Ea))
        subtotal = qty*each
        total = total+subtotal
        line4 = [str(qty), data.Service]
        line5 = nononestr(data.Description)
        line6 = [each, subtotal]

        ctr = [avg(ltm, n1), avg(n1, n2)]
        for j, i in enumerate(line4):
            c.drawCentredString(ctr[j], top, i)

        ctr = [n4-tb*2, rtm-tb*2]
        for j, i in enumerate(line6):
            c.drawRightString(ctr[j], top, dollar(i))

        line5a = line5.splitlines()
        for line in line5a:
            c.drawString(n2+tb, top, line)
            top = top-dh

        top = top-dh

    if prevbal > 0:
        c.drawString(n2+tb, top, 'Open balance from previous month')
        c.drawRightString(rtm-tb*2, top, dollar(prevbal))

    total = total+prevbal-thispay

    c.drawRightString(rtm-tb*2, bottomline, dollar(total))

    c.showPage()
    c.save()
    #
    # Now make a cache copy
    shutil.copy(file1, file2)
Beispiel #6
0
def T_invoice(odata, ldata, pdata1, pdata2, pdata3, cache, invodate, payment):

    # pdata1:Bid (Bill To)
    # pdata2:Lid (Load At)
    # pdata3:Did (Delv To)

    # All dates must begin in datetime format and will be converted to strings as required

    joborder = odata.Jo
    file1 = addpath(f'tmp/{scac}/data/vinvoice/INV' + joborder + '.pdf')
    file2 = addpath(f'tmp/{scac}/data/vinvoice/INV' + joborder + 'c' +
                    str(cache) + '.pdf')
    today = datetime.datetime.today().strftime('%m/%d/%Y')
    type = joborder[1]
    if invodate is None or invodate == 0:
        invodate = today
    else:
        invodate = invodate.strftime('%m/%d/%Y')

    date1 = odata.Date.strftime('%m/%d/%Y')
    date2 = odata.Date2.strftime('%m/%d/%Y')

    if payment != 0:
        try:
            paydate = payment[2].strftime('%m/%d/%Y')
        except:
            paydate = payment[2]

    billto = list(range(5))
    if pdata1 is not None:
        billto[0] = comporname(
            pdata1.Company, fullname(pdata1.First, pdata1.Middle, pdata1.Last))
        billto[1] = nononestr(pdata1.Addr1)
        billto[2] = nononestr(pdata1.Addr2)
        billto[3] = nononestr(pdata1.Telephone)
        # billto[4]=nononestr(pdata1.Email)
        billto[4] = ' '
    else:
        for i in range(5):
            billto[i] = ' '

    loadat = list(range(5))
    if pdata2 is not None:
        loadat[0] = pdata2.Entity.title()
        loadat[1] = nononestr(pdata2.Addr1).title()
        loadat[2] = nononestr(pdata2.Addr2).title()
        loadat[3] = ''
        loadat[4] = ''
    else:
        for i in range(5):
            loadat[i] = ' '

    shipto = list(range(5))
    if pdata3 is not None:
        shipto[0] = pdata3.Entity.title()
        shipto[1] = nononestr(pdata3.Addr1).title()
        shipto[2] = nononestr(pdata3.Addr2).title()
        shipto[3] = ''
        shipto[4] = ''
    else:
        for i in range(5):
            shipto[i] = ' '

    if type == 'T':
        line1 = [
            'Order #', 'Booking #', 'Job Start', 'Job Finish',
            'Bill of Lading', 'Container No.'
        ]
    line2 = ['Quantity', 'Item Code', 'Description', 'Price Each', 'Amount']

    if type == 'T':
        chassis = ' '
        try:
            line3 = [
                odata.Order, odata.Booking, date1, date2, odata.BOL,
                odata.Container
            ]
        except:
            line3 = [odata.Order, odata.Booking, date1, date2, ' ', ' ']

    qnote, note, bank, us, lab, logoi = bankdata('FC')
    lab1 = lab[0]
    lab2 = lab[1]

    # ___________________________________________________________

    ltm = 36
    rtm = 575
    ctrall = 310
    left_ctr = 170
    right_ctr = 480
    dl = 17.6
    tdl = dl * 2
    hls = 530
    m1 = hls - dl
    m2 = hls - 2 * dl
    m3 = hls - 3 * dl
    m4 = hls - 4 * dl
    m5 = hls - 18 * dl
    m6 = hls - 23 * dl
    m7 = hls - 27 * dl
    fulllinesat = [m1, m2, m3, m4, m5, m6, m7]
    p1 = ltm + 87
    p2 = ltm + 180
    p3 = ctrall
    p4 = rtm - 180
    p5 = rtm - 100
    sds1 = [p1, p2, p3, p4, p5]
    n1 = ltm + 58
    n2 = ltm + 128
    n3 = rtm - 140
    n4 = rtm - 70
    sds2 = [n1, n2, n3, n4]
    q1 = ltm + 180
    q2 = rtm - 180
    sds3 = [q1, q2]
    bump = 2.5
    tb = bump * 2

    c = canvas.Canvas(file1, pagesize=letter)
    c.setLineWidth(1)

    c.drawImage(logoi, 180, 670, mask='auto')

    # Date and JO boxes
    dateline = m1 + 8.2 * dl
    c.rect(rtm - 150, m1 + 7 * dl, 150, 2 * dl, stroke=1, fill=0)
    c.line(rtm - 150, dateline, rtm, dateline)
    c.line(rtm - 75, m1 + 7 * dl, rtm - 75, m1 + 9 * dl)

    if type == 'T':
        # Address boxes
        ctm = 218
        c.rect(ltm, m1 + dl, 175, 5 * dl, stroke=1, fill=0)
        c.rect(ctm, m1 + dl, 175, 5 * dl, stroke=1, fill=0)
        c.rect(rtm - 175, m1 + dl, 175, 5 * dl, stroke=1, fill=0)
        level1 = m1 + 5 * dl
        c.line(ltm, level1, ltm + 175, level1)
        c.line(ctm, level1, ctm + 175, level1)
        c.line(rtm - 175, level1, rtm, level1)

    for i in fulllinesat:
        c.line(ltm, i, rtm, i)
    for k in sds1:
        c.line(k, m1, k, m3)
    for l in sds2:
        c.line(l, m3, l, m5)
    for m in sds3:
        c.line(m, m6, m, m7)
    c.line(ltm, m1, ltm, m7)
    c.line(rtm, m1, rtm, m7)
    h1 = avg(m6, m7) - 3
    c.line(q2, h1, rtm, h1)

    c.setFont('Helvetica-Bold', 24, leading=None)
    c.drawCentredString(rtm - 75, dateline + 1.5 * dl, 'Invoice')

    c.setFont('Helvetica', 11, leading=None)

    c.drawCentredString(rtm - 112.5, dateline + bump, 'Date')
    c.drawCentredString(rtm - 37.7, dateline + bump, 'Invoice #')

    c.drawString(ltm + bump * 3, m1 + 5 * dl + bump * 2, 'Bill To')
    c.drawString(ctm + bump * 3, m1 + 5 * dl + bump * 2, 'Load At')
    c.drawString(rtm - 170 + bump * 2, m1 + 5 * dl + bump * 2, 'Deliver To')

    ctr = [
        avg(ltm, p1),
        avg(p1, p2),
        avg(p2, p3),
        avg(p3, p4),
        avg(p4, p5),
        avg(p5, rtm)
    ]
    for j, i in enumerate(line1):
        c.drawCentredString(ctr[j], m2 + tb, i)

    ctr = [avg(ltm, n1), avg(n1, n2), avg(n2, n3), avg(n3, n4), avg(n4, rtm)]
    for j, i in enumerate(line2):
        c.drawCentredString(ctr[j], m4 + tb, i)

    dh = 12
    ct = 305

    top = m6 - 1.5 * dh
    for i in bank:
        c.drawCentredString(ct, top, i)
        top = top - dh

    top = m1 + 9 * dl - 5
    for i in us:
        c.drawString(ltm + bump, top, i)
        top = top - dh

    bottomline = m6 - 23
    c.setFont('Helvetica-Bold', 12, leading=None)
    c.drawString(q2 + tb, bottomline, 'Balance Due:')

    c.setFont('Helvetica', 10, leading=None)
    c.drawCentredString(avg(q2, rtm), m7 + 12,
                        'Add $39.00 for all international wires')

    c.setFont('Times-Roman', 9, leading=None)
    j = 0
    dh = 9.95
    top = m5 - dh
    for i in note:
        c.drawString(ltm + tb, top, note[j])
        j = j + 1
        top = top - dh

# _______________________________________________________________________
# Insert data here
# _______________________________________________________________________

    c.setFont('Helvetica', 10, leading=None)

    if type == 'T':
        dh = 13
        top = level1 - dh
        lft = ltm + bump * 3
        for i in billto:
            c.drawString(lft, top, i)
            top = top - dh

        top = level1 - dh
        lft = ctm + bump * 3
        for i in loadat:
            c.drawString(lft, top, i)
            top = top - dh

        top = level1 - dh
        lft = rtm - 175 + bump * 3
        for i in shipto:
            c.drawString(lft, top, i)
            top = top - dh

    x = avg(rtm - 75, rtm)
    y = dateline - dh - bump
    c.drawCentredString(x, y, joborder)
    x = avg(rtm - 75, rtm - 150)
    c.drawCentredString(x, y, invodate)

    c.setFont('Helvetica', 9, leading=None)

    j = 0
    for i in line3:
        ctr = [
            avg(ltm, p1),
            avg(p1, p2),
            avg(p2, p3),
            avg(p3, p4),
            avg(p4, p5),
            avg(p5, rtm)
        ]
        i = nononestr(i)
        c.drawCentredString(ctr[j], m3 + tb, i)
        j = j + 1

    total = 0
    top = m4 - dh
    for data in ldata:
        qty = float(float(data.Qty))
        each = float(float(data.Ea))
        subtotal = qty * each
        total = total + subtotal
        line4 = [str(qty), data.Service]
        line5 = nononestr(data.Description)
        line6 = [each, subtotal]

        j = 0
        for i in line4:
            ctr = [avg(ltm, n1), avg(n1, n2)]
            c.drawCentredString(ctr[j], top, i)
            j = j + 1

        c.drawString(n2 + tb, top, line5)

        j = 0
        for i in line6:
            ctr = [n4 - tb * 2, rtm - tb * 2]
            c.drawRightString(ctr[j], top, dollar(i))
            j = j + 1
        top = top - dh

    if payment != 0:
        c.setFont('Helvetica-Bold', 18, leading=None)
        c.drawCentredString(ct, top - 2 * dh, 'Payment Received')

    if payment != 0:
        c.setFont('Helvetica-Bold', 12, leading=None)
        try:
            thispay = float(payment[0])
        except:
            thispay = 0.00
        top = top - 4 * dh
        try:
            c.drawString(
                n2 + bump, top,
                'Your payment of ' + payment[0] + ', Ref No. ' + payment[1])
        except:
            c.drawString(ct, top, 'There is no payment data as of yet')
        try:
            c.drawString(n2 + bump, top - dh, 'was applied on ' + paydate)
        except:
            c.drawString(ct, top - dh, 'There is a problem with the date')
    else:
        thispay = 0.00

    total = total - thispay

    c.drawRightString(rtm - tb * 2, bottomline, dollar(total))

    c.showPage()
    c.save()
    #
    # Now make a cache copy
    shutil.copy(file1, file2)

    return file2
Beispiel #7
0
def invoiceM(oder, payment):

    myo = Moving.query.get(oder)
    today = datetime.datetime.today()
    # Check to see if we have the required data to make an invoice:
    pdata1 = People.query.filter((People.Company == myo.Shipper)
                                 & (People.Ptype == 'Moving')).first()
    if pdata1 is not None:
        invo = 1
        leftsize = 8
        cache = myo.Cache + 1

        # These are the services we wish to add to the invoice
        sdata = Services.query.order_by(Services.Price.desc()).all()
        total = 0
        for data in sdata:
            testone = request.values.get('serv' + str(data.id))
            if testone:
                servid = int(testone)
                mys = Services.query.get(servid)
                qty = 1
                total = total + mys.Price
                input = Invoices(Jo=myo.Jo,
                                 SubJo=None,
                                 Pid=0,
                                 Service=mys.Service,
                                 Description=' ',
                                 Ea=mys.Price,
                                 Qty=qty,
                                 Amount=myo.Amount,
                                 Total=myo.Amount,
                                 Date=today,
                                 Original=None,
                                 Status='New')
                db.session.add(input)
                db.session.commit()

        idat = Invoices.query.filter(Invoices.Jo == myo.Jo).first()
        if idat is None:
            descript = 'Job Order ' + myo.Jo + ' Moving from ' + myo.Drop1 + ' to ' + myo.Drop2
            total = myo.Amount
            input = Invoices(Jo=myo.Jo,
                             SubJo=None,
                             Pid=0,
                             Service='Moving Services',
                             Description=descript,
                             Ea=myo.Amount,
                             Qty=1,
                             Amount=myo.Amount,
                             Total=myo.Amount,
                             Date=today,
                             Original=None,
                             Status='New')
            db.session.add(input)
            db.session.commit()

        ldat = Invoices.query.filter(Invoices.Jo == myo.Jo).first()
        if ldat is None:
            invo = 0
            leftsize = 10
            err = [
                ' ', ' ', 'No services on invoice yet and none selected', ' ',
                ' '
            ]
        else:
            invo = 1
            leftsize = 8
            invodate = ldat.Date
            dt = ldat.Date
            err = [' ', ' ', 'Created invoice for JO= ' + myo.Jo, ' ', ' ']
            ldata = Invoices.query.filter(Invoices.Jo == myo.Jo).order_by(
                Invoices.Ea.desc()).all()
            pdata1 = People.query.filter(People.Company == myo.Shipper).first()

        joborder = myo.Jo
        file1 = addpath(f'tmp/{scac}/data/vinvoice/INV' + joborder + 'c0.pdf')
        file2 = addpath(f'tmp/{scac}/data/vinvoice/INV' + joborder + 'c' +
                        str(cache) + '.pdf')
        file3 = addpath(f'tmp/{scac}/data/vinvoice/INV' + joborder + 'c' +
                        str(cache - 1) + '.pdf')
        today = datetime.datetime.today().strftime('%m/%d/%Y')
        type = joborder[1]
        if invodate is None or invodate == 0:
            invodate = today
        else:
            invodate = invodate.strftime('%m/%d/%Y')

        date1 = myo.Date.strftime('%m/%d/%Y')
        date2 = myo.Date2.strftime('%m/%d/%Y')

        if payment != 0:
            try:
                paydate = payment[2].strftime('%m/%d/%Y')
            except:
                paydate = payment[2]

        billto = list(range(5))
        if pdata1 is not None:
            billto[0] = comporname(
                pdata1.Company,
                fullname(pdata1.First, pdata1.Middle, pdata1.Last))
            billto[1] = nononestr(pdata1.Addr1)
            billto[2] = nononestr(pdata1.Addr2)
            billto[3] = nononestr(pdata1.Telephone)
            billto[4] = nononestr(pdata1.Email)
        else:
            for i in range(5):
                billto[i] = ' '

        loadat = [' '] * 5
        p2 = myo.Dropblock1
        p2 = p2.splitlines()
        for j, p in enumerate(p2):
            if j < 5:
                loadat[j] = p.title()

        shipto = [' '] * 5
        p2 = myo.Dropblock2
        p2 = p2.splitlines()
        for j, p in enumerate(p2):
            if j < 5:
                shipto[j] = p.title()

        us = list(range(4))
        us[0] = 'FIRST EAGLE LOGISTICS INC'
        us[1] = '505 HAMPTON PARK BLVD UNIT O'
        us[2] = 'CAPITOL HEIGHTS MD  20743'
        us[3] = '301-516-3000  [email protected]'

        line1 = [
            'No. Stops', 'Terms', 'Job Start', 'Job Finish', 'Bill of Lading',
            'Container No.'
        ]
        line2 = [
            'Quantity', 'Item Code', 'Description', 'Price Each', 'Amount'
        ]
        due = 'Due Upon Receipt'
        bol = myo.BOL
        if len(bol) < 2:
            bol = myo.Jo

        line3 = [myo.Booking, due, date1, date2, bol, myo.Container]

        note, bank = bankdata('FC')

        lab1 = 'Balance Due'
        lab2 = 'Add $39.00 for all international wires'

        ltm = 36
        rtm = 575
        ctrall = 310
        left_ctr = 170
        right_ctr = 480
        dl = 17.6
        tdl = dl * 2
        hls = 530
        m1 = hls - dl
        m2 = hls - 2 * dl
        m3 = hls - 3 * dl
        m4 = hls - 4 * dl
        m5 = hls - 18 * dl
        m6 = hls - 23 * dl
        m7 = hls - 27 * dl
        fulllinesat = [m1, m2, m3, m4, m5, m6, m7]
        p1 = ltm + 87
        p2 = ltm + 180
        p3 = ctrall
        p4 = rtm - 180
        p5 = rtm - 100
        sds1 = [p1, p2, p3, p4, p5]
        n1 = ltm + 58
        n2 = ltm + 128
        n3 = rtm - 140
        n4 = rtm - 70
        sds2 = [n1, n2, n3, n4]
        q1 = ltm + 180
        q2 = rtm - 180
        sds3 = [q1, q2]
        bump = 2.5
        tb = bump * 2

        c = canvas.Canvas(file1, pagesize=letter)
        c.setLineWidth(1)

        logo = addpath("tmp/pics/logo3.jpg")
        c.drawImage(logo, 185, 680, mask='auto')

        # Date and JO boxes
        dateline = m1 + 8.2 * dl
        c.rect(rtm - 150, m1 + 7 * dl, 150, 2 * dl, stroke=1, fill=0)
        c.line(rtm - 150, dateline, rtm, dateline)
        c.line(rtm - 75, m1 + 7 * dl, rtm - 75, m1 + 9 * dl)

        # Address boxes
        ctm = 218
        c.rect(ltm, m1 + dl, 175, 5 * dl, stroke=1, fill=0)
        c.rect(ctm, m1 + dl, 175, 5 * dl, stroke=1, fill=0)
        c.rect(rtm - 175, m1 + dl, 175, 5 * dl, stroke=1, fill=0)
        level1 = m1 + 5 * dl
        c.line(ltm, level1, ltm + 175, level1)
        c.line(ctm, level1, ctm + 175, level1)
        c.line(rtm - 175, level1, rtm, level1)

        for i in fulllinesat:
            c.line(ltm, i, rtm, i)
        for k in sds1:
            c.line(k, m1, k, m3)
        for l in sds2:
            c.line(l, m3, l, m5)
        for m in sds3:
            c.line(m, m6, m, m7)
        c.line(ltm, m1, ltm, m7)
        c.line(rtm, m1, rtm, m7)
        h1 = avg(m6, m7) - 3
        c.line(q2, h1, rtm, h1)

        c.setFont('Helvetica-Bold', 24, leading=None)
        c.drawCentredString(rtm - 75, dateline + 1.5 * dl, 'Invoice')

        c.setFont('Helvetica', 11, leading=None)

        c.drawCentredString(rtm - 112.5, dateline + bump, 'Date')
        c.drawCentredString(rtm - 37.7, dateline + bump, 'Invoice #')

        c.drawString(ltm + bump * 3, m1 + 5 * dl + bump * 2, 'Bill To')
        c.drawString(ctm + bump * 3, m1 + 5 * dl + bump * 2, 'Load At')
        c.drawString(rtm - 170 + bump * 2, m1 + 5 * dl + bump * 2, 'Delv To')

        ctr = [
            avg(ltm, p1),
            avg(p1, p2),
            avg(p2, p3),
            avg(p3, p4),
            avg(p4, p5),
            avg(p5, rtm)
        ]
        for j, i in enumerate(line1):
            c.drawCentredString(ctr[j], m2 + tb, i)

        ctr = [
            avg(ltm, n1),
            avg(n1, n2),
            avg(n2, n3),
            avg(n3, n4),
            avg(n4, rtm)
        ]
        for j, i in enumerate(line2):
            c.drawCentredString(ctr[j], m4 + tb, i)

        dh = 12
        ct = 305

        top = m6 - 1.5 * dh
        for i in bank:
            c.drawCentredString(ct, top, i)
            top = top - dh

        top = m1 + 9 * dl - 5
        for i in us:
            c.drawString(ltm + bump, top, i)
            top = top - dh

        bottomline = m6 - 23
        c.setFont('Helvetica-Bold', 12, leading=None)
        c.drawString(q2 + tb, bottomline, 'Balance Due:')

        c.setFont('Helvetica', 10, leading=None)
        c.drawCentredString(avg(q2, rtm), m7 + 12,
                            'Add $39.00 for all international wires')

        c.setFont('Times-Roman', 9, leading=None)
        j = 0
        dh = 9.95
        top = m5 - dh
        for i in note:
            c.drawString(ltm + tb, top, note[j])
            j = j + 1
            top = top - dh

# _______________________________________________________________________
# Insert data here
# _______________________________________________________________________

        c.setFont('Helvetica', 12, leading=None)

        dh = 13
        top = level1 - dh
        lft = ltm + bump * 3
        for i in billto:
            c.drawString(lft, top, i)
            top = top - dh

        top = level1 - dh
        lft = ctm + bump * 3
        for i in loadat:
            c.drawString(lft, top, i)
            top = top - dh

        top = level1 - dh
        lft = rtm - 175 + bump * 3
        for i in shipto:
            c.drawString(lft, top, i)
            top = top - dh

        x = avg(rtm - 75, rtm)
        y = dateline - dh - bump
        c.drawCentredString(x, y, joborder)
        x = avg(rtm - 75, rtm - 150)
        c.drawCentredString(x, y, invodate)

        c.setFont('Helvetica', 9, leading=None)

        j = 0
        for i in line3:
            ctr = [
                avg(ltm, p1),
                avg(p1, p2),
                avg(p2, p3),
                avg(p3, p4),
                avg(p4, p5),
                avg(p5, rtm)
            ]
            c.drawCentredString(ctr[j], m3 + tb, i)
            j = j + 1

        total = 0
        top = m4 - dh
        for data in ldata:
            qty = float(data.Qty)
            each = float(data.Ea)
            subtotal = qty * each
            total = total + subtotal
            line4 = [str(qty), data.Service]
            line5 = nononestr(data.Description)
            line5lines = line5.splitlines()
            line6 = [each, subtotal]

            j = 0
            for i in line4:
                ctr = [avg(ltm, n1), avg(n1, n2)]
                c.drawCentredString(ctr[j], top, i)
                j = j + 1

            j = 0
            for i in line6:
                ctr = [n4 - tb * 2, rtm - tb * 2]
                c.drawRightString(ctr[j], top, dollar(i))
                j = j + 1

            for line in line5lines:
                c.drawString(n2 + tb, top, line)
                top = top - dh

            #top = top-dh

        if payment != 0:
            c.setFont('Helvetica-Bold', 18, leading=None)
            c.drawCentredString(ct, top - 2 * dh, 'Payment Received')

        if payment != 0:
            c.setFont('Helvetica-Bold', 12, leading=None)

            try:
                thispay = nononef(payment[0])
            except:
                thispay = 0.00

            top = top - 4 * dh
            try:
                c.drawString(
                    n2 + bump, top, 'Your payment of ' + payment[0] +
                    ', Ref No. ' + payment[1])
            except:
                c.drawString(ct, top, 'There is no payment data as of yet')
            try:
                c.drawString(n2 + bump, top - dh, 'was applied on ' + paydate)
            except:
                c.drawString(ct, top - dh, 'There is a problem with the date')
        else:
            thispay = 0.00

        total = total - thispay

        c.drawRightString(rtm - tb * 2, bottomline, dollar(total))

        c.showPage()
        c.save()
        #
        try:
            # Now make a cache copy
            shutil.copy(file1, file2)
        except:
            print('Could not find', file1, file2)
            # Remove old cache company
        try:
            shutil.move(file3, file1)
        except:
            print('Could not find', file3, file1)

        if cache > 1:
            docref = f'tmp/{scac}/data/vinvoice/INV' + myo.Jo + 'c' + str(
                cache) + '.pdf'
            # Store for future use
        else:
            docref = f'tmp/{scac}/data/vinvoice/INV' + myo.Jo + 'c0.pdf'

        if payment == 0:
            for ldatl in ldata:
                ldatl.Pid = pdata1.id
                ldatl.Original = docref
                db.session.commit()
            myo.Path = docref

        myo.Cache = cache
        db.session.commit()

    return invo, err, docref, leftsize, dt
Beispiel #8
0
def invoiceO(ship, payment):
    today = datetime.datetime.today()
    myo = OverSeas.query.get(ship)
    # Check to see if we have the required data to make an invoice:
    pdat = People.query.get(myo.Pid)

    if pdat is not None:
        invo = 1
        leftsize = 8
        if myo.Cache is not None:
            cache = myo.Cache + 1
        else:
            cache = 1

        # if no invoice has been created add all the basics:
        idat = Invoices.query.filter(Invoices.Jo == myo.Jo).first()
        if idat is None:
            descript = 'Job ' + myo.Jo + ': ' + myo.Pol + ' to ' + myo.Pod
            try:
                total = myo.Charge.replace('$', '').replace(',', '')
                total = float(total)
            except:
                total = 0.00
            input = Invoices(Jo=myo.Jo,
                             SubJo=None,
                             Pid=0,
                             Service='Overseas Shipping',
                             Description=descript,
                             Ea=total,
                             Qty=1,
                             Amount=total,
                             Total=total,
                             Date=today,
                             Original=None,
                             Status='New')
            db.session.add(input)
            db.session.commit()

        # These are the services we wish to add to the invoice
        sdata = Services.query.order_by(Services.Price.desc()).all()
        total = 0
        for data in sdata:
            testone = request.values.get('serv' + str(data.id))
            if testone:
                servid = int(testone)
                mys = Services.query.get(servid)
                qty = 1
                total = total + mys.Price
                input = Invoices(Jo=myo.Jo,
                                 SubJo=None,
                                 Pid=myo.Pid,
                                 Service=mys.Service,
                                 Description='',
                                 Ea=mys.Price,
                                 Qty=qty,
                                 Amount=mys.Price,
                                 Total=None,
                                 Date=today,
                                 Original=None,
                                 Status='New')
                db.session.add(input)
                db.session.commit()

        adata = Autos.query.filter(Autos.Jo == myo.Jo).all()
        for data in adata:
            ihave = Invoices.query.filter(
                Invoices.SubJo == str(data.id)).first()
            if ihave is None:
                qty = 1
                towcost = data.TowCostEa

                if towcost is None:
                    data.TowCostEa = '0.00'
                    towcost = '0.00'

                towcharge = nononef(towcost)
                total = total + towcharge
                descript = data.Year + ' ' + data.Color + ' ' + data.Make + ' ' + data.Model + ' VIN:' + data.VIN
                input = Invoices(Jo=myo.Jo,
                                 SubJo=str(data.id),
                                 Pid=myo.Pid,
                                 Service='Towing',
                                 Description=descript,
                                 Ea=towcharge,
                                 Qty=qty,
                                 Amount=towcharge,
                                 Total=None,
                                 Date=today,
                                 Original=None,
                                 Status='New')
                db.session.add(input)
                db.session.commit()

        total = 0.0
        ldata = Invoices.query.filter(Invoices.Jo == myo.Jo).all()
        for ldat in ldata:
            qty = float(ldat.Qty)
            each = float(ldat.Ea)
            amount = qty * each
            total = total + amount
            ldat.Amount = d2s(amount)
            db.session.commit()
        for ldat in ldata:
            ldat.Total = d2s(total)
            db.session.commit()

        ldat = Invoices.query.filter(Invoices.Jo == myo.Jo).first()
        if ldat is None:
            invo = 0
            leftsize = 10
            err = [
                ' ', ' ', 'No services on invoice yet and none selected', ' ',
                ' '
            ]
        else:
            invo = 1
            leftsize = 8
            dt = ldat.Date
            invodate = ldat.Date.strftime('%m/%d/%Y')
            err = [' ', ' ', 'Created invoice for JO= ' + myo.Jo, ' ', ' ']
            ldata = Invoices.query.filter(Invoices.Jo == myo.Jo).order_by(
                Invoices.Ea.desc()).all()
            pdata1 = People.query.get(myo.Pid)
            pdata2 = People.query.get(myo.ExportID)
            pdata3 = People.query.get(myo.ConsigID)
            pdata4 = People.query.get(myo.NotifyID)

            # _______________________________________________________________________________________________________________
            joborder = myo.Jo
            file1 = addpath(f'tmp/{scac}/data/vinvoice/INV' + joborder +
                            '.pdf')
            file2 = addpath(f'tmp/{scac}/data/vinvoice/INV' + joborder + 'c' +
                            str(cache) + '.pdf')
            file3 = addpath(f'tmp/{scac}/data/vinvoice/INV' + joborder + 'c' +
                            str(cache - 1) + '.pdf')
            today = datetime.datetime.today().strftime('%m/%d/%Y')
            type = joborder[1]
            myb = Bookings.query.filter(
                myo.Booking == Bookings.Booking).first()
            if myb is not None:
                loadat1 = myo.Pol
                saildate = myb.SailDate.strftime('%m/%d/%Y')
                shipto1 = myo.Pod
                arrival = myb.EstArr.strftime('%m/%d/%Y')
                theline = myb.Line
                vessel = myb.Vessel
            else:
                loadat1 = myo.Pol
                saildate = 'TBD'
                shipto1 = myo.Pod
                arrival = 'TBD'
                theline = ' '
                vessel = ' '

            if payment != 0:
                try:
                    paydate = payment[2].strftime('%m/%d/%Y')
                except:
                    paydate = payment[2]

            billto = list(range(5))
            if pdata1 is not None:
                billto[0] = comporname(
                    pdata1.Company,
                    fullname(pdata1.First, pdata1.Middle, pdata1.Last))
                billto[1] = nononestr(pdata1.Addr1)
                billto[2] = nononestr(pdata1.Addr2)
                billto[3] = nononestr(pdata1.Telephone)
                billto[4] = nononestr(pdata1.Email)
            else:
                for i in range(5):
                    billto[i] = ' '

            loadat = list(range(5))
            if pdata2 is not None:
                loadat[0] = parselinenoupper(loadat1, 34)
                loadat[1] = parselinenoupper('Depart Date: ' + saildate, 28)
                loadat[2] = ' '
                loadat[3] = parselinenoupper(shipto1, 28)
                loadat[4] = parselinenoupper('Est. Arrival Date: ' + arrival,
                                             28)
            else:
                for i in range(5):
                    loadat[i] = ' '

            shipto = list(range(5))
            if pdata3 is not None:
                shipto[0] = comporname(
                    pdata3.Company,
                    fullname(pdata3.First, pdata3.Middle, pdata3.Last))
                shipto[0] = shipto[0].title()
                shipto[1] = nononestr(pdata3.Addr1).title()
                shipto[2] = nononestr(pdata3.Addr2).title()
                shipto[3] = nononestr(pdata3.Telephone)
                shipto[4] = nononestr(pdata3.Email).lower()
            else:
                for i in range(5):
                    shipto[i] = ' '

            us = list(range(4))
            us[0] = 'FIRST EAGLE LOGISTICS INC'
            us[1] = '505 HAMPTON PARK BLVD UNIT O'
            us[2] = 'CAPITOL HEIGHTS MD  20743'
            us[3] = '301-516-3000  [email protected]'

            line1 = [
                'Booking #', 'Container No.', 'Ship', 'Via', 'Vessel', 'Terms'
            ]
            line2 = [
                'Quantity', 'Item Code', 'Description', 'Price Each', 'Amount'
            ]
            line3 = [
                myo.Booking, myo.Container, theline, myo.MoveType, vessel,
                'Due Upon Receipt'
            ]

            note, bank = bankdata('FC')

            lab1 = 'Balance Due'
            lab2 = 'Add $39.00 for all international wires'

            ltm = 36
            rtm = 575
            ctrall = 310
            left_ctr = 170
            right_ctr = 480
            dl = 17.6
            tdl = dl * 2
            hls = 530
            m1 = hls - dl
            m2 = hls - 2 * dl
            m3 = hls - 3 * dl
            m4 = hls - 4 * dl
            m5 = hls - 18 * dl
            m6 = hls - 23 * dl
            m7 = hls - 27 * dl
            fulllinesat = [m1, m2, m3, m4, m5, m6, m7]
            p1 = ltm + 87
            p2 = ltm + 168
            p3 = ctrall - 25
            p4 = rtm - 220
            p5 = rtm - 120
            sds1 = [p1, p2, p3, p4, p5]
            n1 = ltm + 50
            n2 = ltm + 130
            n3 = rtm - 140
            n4 = rtm - 70
            sds2 = [n1, n2, n3, n4]
            q1 = ltm + 180
            q2 = rtm - 180
            sds3 = [q1, q2]
            bump = 2.5
            tb = bump * 2

            c = canvas.Canvas(file1, pagesize=letter)
            c.setLineWidth(1)

            logo = addpath("tmp/pics/logo3.jpg")
            c.drawImage(logo, 185, 680, mask='auto')

            # Date and JO boxes
            dateline = m1 + 8.2 * dl
            c.rect(rtm - 150, m1 + 7 * dl, 150, 2 * dl, stroke=1, fill=0)
            c.line(rtm - 150, dateline, rtm, dateline)
            c.line(rtm - 75, m1 + 7 * dl, rtm - 75, m1 + 9 * dl)

            ctm = 218
            c.rect(ltm, m1 + dl, 175, 5 * dl, stroke=1, fill=0)
            c.rect(ctm, m1 + dl, 150, 5 * dl, stroke=1, fill=0)
            c.rect(rtm - 200, m1 + dl, 200, 5 * dl, stroke=1, fill=0)
            level1 = m1 + 5 * dl
            c.line(ltm, level1, ltm + 175, level1)
            c.line(ctm, level1, ctm + 150, level1)
            c.line(rtm - 200, level1, rtm, level1)

            for i in fulllinesat:
                c.line(ltm, i, rtm, i)
            for k in sds1:
                c.line(k, m1, k, m3)
            for l in sds2:
                c.line(l, m3, l, m5)
            for m in sds3:
                c.line(m, m6, m, m7)
            c.line(ltm, m1, ltm, m7)
            c.line(rtm, m1, rtm, m7)
            h1 = avg(m6, m7) - 3
            c.line(q2, h1, rtm, h1)

            c.setFont('Helvetica-Bold', 24, leading=None)
            c.drawCentredString(rtm - 75, dateline + 1.5 * dl, 'Invoice')

            c.setFont('Helvetica', 12, leading=None)

            c.drawCentredString(rtm - 112.5, dateline + bump, 'Date')
            c.drawCentredString(rtm - 37.7, dateline + bump, 'Invoice #')

            c.drawString(ltm + bump * 3, m1 + 5 * dl + bump * 2, 'Bill To')
            c.drawString(ctm + bump * 3, m1 + 5 * dl + bump * 2,
                         'Port to Port')
            c.drawString(rtm - 200 + bump * 2, m1 + 5 * dl + bump * 2,
                         'Customer/Consignee')

            ctr = [
                avg(ltm, p1),
                avg(p1, p2),
                avg(p2, p3),
                avg(p3, p4),
                avg(p4, p5),
                avg(p5, rtm)
            ]
            for j, i in enumerate(line1):
                c.drawCentredString(ctr[j], m2 + tb, i)

            ctr = [
                avg(ltm, n1),
                avg(n1, n2),
                avg(n2, n3),
                avg(n3, n4),
                avg(n4, rtm)
            ]
            for j, i in enumerate(line2):
                c.drawCentredString(ctr[j], m4 + tb, i)

            dh = 12
            ct = 305
            top = m6 - 1.5 * dh
            for i in bank:
                c.drawCentredString(ct, top, i)
                top = top - dh

            top = m1 + 9 * dl - 5
            for i in us:
                c.drawString(ltm + bump, top, i)
                top = top - dh

            bottomline = m6 - 23
            c.setFont('Helvetica-Bold', 12, leading=None)
            c.drawString(q2 + tb, bottomline, 'Balance Due:')

            c.setFont('Helvetica', 10, leading=None)
            c.drawCentredString(avg(q2, rtm), m7 + 12,
                                'Add $39.00 for all international wires')

            c.setFont('Times-Roman', 9, leading=None)
            dh = 9.95
            top = m5 - dh
            for j, i in enumerate(note):
                c.drawString(ltm + tb, top, note[j])
                top = top - dh

# _______________________________________________________________________
# Insert data here
# _______________________________________________________________________

            c.setFont('Helvetica', 10, leading=None)

            dh = 13
            top = level1 - dh
            lft = ltm + bump * 3
            for i in billto:
                i = i.title()
                c.drawString(lft, top, i)
                top = top - dh

            top = level1 - dh
            lft = ctm + bump * 3
            for i in loadat:
                for k in i:
                    c.drawString(lft, top, k)
                    top = top - dh

            top = level1 - dh
            lft = rtm - 205 + bump * 3
            for i in shipto:
                c.drawString(lft, top, i)
                top = top - dh

            x = avg(rtm - 75, rtm)
            y = dateline - dh - bump
            c.drawCentredString(x, y, joborder)
            x = avg(rtm - 75, rtm - 150)
            c.drawCentredString(x, y, invodate)

            c.setFont('Helvetica', 9, leading=None)

            ctr = [
                avg(ltm, p1),
                avg(p1, p2),
                avg(p2, p3),
                avg(p3, p4),
                avg(p4, p5),
                avg(p5, rtm)
            ]
            for j, i in enumerate(line3):
                c.drawCentredString(ctr[j], m3 + tb, i)

            total = 0
            top = m4 - dh
            for data in ldata:
                qty = data.Qty
                if qty != -1:
                    qty = int(nonone(data.Qty))
                    each = float(nonone(data.Ea))
                    subtotal = qty * each
                    if subtotal == 0:
                        sqty = ''
                        theservice = 'Included/NoTow'
                        theeach = ''
                        thesubtotal = ''
                    else:
                        sqty = str(qty)
                        theservice = data.Service
                        theeach = dollar(each)
                        thesubtotal = dollar(subtotal)

                    total = total + subtotal
                    line4 = [sqty, theservice]
                    line5 = nononestr(data.Description)
                    line6 = [theeach, thesubtotal]

                    ctr = [avg(ltm, n1), avg(n1, n2)]
                    for j, i in enumerate(line4):
                        c.drawCentredString(ctr[j], top, i)

                    c.drawString(n2 + tb, top, line5)

                    ctr = [n4 - tb * 2, rtm - tb * 2]
                    for j, i in enumerate(line6):
                        c.drawRightString(ctr[j], top, i)

                    top = top - dh

            if payment != 0:
                c.setFont('Helvetica-Bold', 18, leading=None)
                c.drawCentredString(ct, top - 2 * dh, 'Payment Received')

            if payment != 0:
                c.setFont('Helvetica-Bold', 12, leading=None)

                try:
                    thispay = dollar(float(payment[0]))
                except:
                    thispay = '$0.00'

                # dollar(float(payment[0]))

                top = top - 4 * dh
                try:
                    c.drawString(
                        n2 + bump, top, 'Your payment of ' + thispay +
                        ', Ref No. ' + payment[1])
                except:
                    c.drawString(ct, top, 'There is no payment data as of yet')
                try:
                    c.drawString(n2 + bump, top - dh,
                                 'was applied on ' + paydate)
                except:
                    c.drawString(ct, top - dh,
                                 'There is a problem with the date')

                thispay = nononef(thispay)

            else:
                thispay = 0.00

            baldue = total - thispay

            c.drawRightString(rtm - tb * 2, bottomline, dollar(baldue))

            c.showPage()
            c.save()
            #
            # Now make a cache copy
            shutil.copy(file1, file2)
            try:
                shutil.move(file3, file1)
            except:
                err = 'No file there'

# _______________________________________________________________________________________________________________
            if cache > 1:
                docref = f'tmp/{scac}/data/vinvoice/INV' + myo.Jo + 'c' + str(
                    cache) + '.pdf'
                # Store for future use
            else:
                docref = f'tmp/{scac}/data/vinvoice/INV' + myo.Jo + '.pdf'

            if payment == 0:
                for ldatl in ldata:
                    ldatl.Pid = pdata1.id
                    ldatl.Original = docref
                    db.session.commit()
                myo.Ipath = docref

            myo.Cache = cache
            db.session.commit()
            leftscreen = 0
            #err[4]='Viewing '+docref

    return invo, err, leftscreen, leftsize, docref, dt