示例#1
0
def incomecalcs():
    today = datetime.datetime.today().strftime('%m/%d/%Y')
    invodate = datetime.date.today().strftime('%m/%d/%Y')
    sdate = request.values.get('start')
    fdate = request.values.get('finish')
    start = datetime.datetime.strptime(sdate, '%Y-%m-%d')
    end = datetime.datetime.strptime(fdate, '%Y-%m-%d')
    incomedata = []

    idata = Invoices.query.filter((Invoices.Date >= start)
                                  & (Invoices.Date <= end)).order_by(
                                      Invoices.Date).all()
    for idat in idata:
        date = idat.Date
        date = date.strftime('%Y-%m-%d')
        pid = idat.Pid
        pdat = People.query.get(pid)
        if pdat is not None:
            customer = pdat.Company
        else:
            customer = 'Unknown'
        status = idat.Status
        try:
            bit2 = status[1]
        except:
            bit2 = 9
            srep = 'Unknown'
        srep = 'Unknown'
        if bit2 == 0:
            srep = 'Open, Uninvoiced'
        if bit2 == 1:
            srep = 'Open, Inv Created'
        if bit2 == 2:
            srep = 'Open, Inv Sent'
        if bit2 == 3:
            srep = 'Paid'

        incomedata.append([
            date, idat.Jo, customer, idat.Service, idat.Status,
            dollar(idat.Amount)
        ])
    return incomedata
示例#2
0
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
示例#3
0
def plcontents(file4, itemlist, blist, cache):

    details = request.values.get('dt3')
    indent1 = 50
    lastexp = 'D'
    today = datetime.datetime.today().strftime('%m/%d/%Y')
    invodate = datetime.date.today().strftime('%m/%d/%Y')
    sdate = request.values.get('start')
    fdate = request.values.get('finish')
    try:
        start = datetime.datetime.strptime(sdate, '%Y-%m-%d')
        end = datetime.datetime.strptime(fdate, '%Y-%m-%d')
    except:
        start = today
        end = today

    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)

    pages = [file4]
    page = 1
    c = canvas.Canvas(file4, pagesize=letter)
    c.setLineWidth(1)
    bottomy = n3

    mtop = n1

    p1 = ltm + 55
    p15 = ltm + 65
    p2 = ltm + 140
    p3 = ltm + 200
    p4 = ltm + 270
    p5 = rtm - 150
    p6 = rtm - 50
    #    p7=rtm-40

    #Set the Building Propration for Items shared between FEL and Other
    Fbp = .80
    prorate = [1.0, 1.0]
    inctotals = [0.0, 0.0, 0.0, 0.0]
    optype = ['Trucking', 'Overseas', 'Storage', 'Moving']
    keyval = ['Order', 'Booking', 'JO', 'JO']
    exptotals = [0.0, 0.0]
    i_categories = [
        'BldRent', 'BldRepMaint', 'Utilities', 'Adv-Mark', 'BankFees', 'Taxes',
        'OfficeSupp', 'Insurance', 'ProfFees', 'Other'
    ]
    d_categories = [
        'Container', 'Towing', 'Fuel', 'Payroll', 'Rentals', 'Other'
    ]
    catbp = [
        1.0, 1.0, 1.0, 1.0, 1.0, 1.0, Fbp, Fbp, Fbp, 1.0, 1.0, 1.0, Fbp, 1.0,
        1.0, 1.0
    ]
    extype = []
    exptotals = []
    for cat in d_categories:
        extype.append('D:' + cat)
        exptotals.append(0.0)
    for cat in i_categories:
        extype.append('I:' + cat)
        exptotals.append(0.0)

#___________Income_____________________________
    for kval in range(4):

        complete = 0
        while complete == 0 and page < 20:
            c, page, pages, mtop = newpagecheck(c, mtop, bottomy + 20, page,
                                                file4, pages)
            if details == 'on':
                hvec = [ltm, p1, p15, p2, p3, p4, p5, p6, rtm]
                headerlist = [
                    'InvoDate', 'L', 'Service', optype[kval], 'Container',
                    'From', 'To', 'Invoiced'
                ]
                justify = ['c', 'c', 'l', 'l', 'l', 'l', 'l', 'r']
                mtop = stripheader(c, 10, mtop, hvec, headerlist)
            elif mtop == n1:
                hvec = [ltm, rtm]
                headerlist = ['INCOME ALL SOURCES']
                justify = ['r']
                mtop = stripheader(c, 12, mtop, hvec, headerlist)
                mtop = mtop - dh * 1.5

            mtop, inctotals, rlist = pl_orderlisting(c, 9, mtop, hvec,
                                                     itemlist, justify,
                                                     inctotals, bottomy, kval,
                                                     optype, details)
            if mtop > 0:
                complete = 1
            else:
                c, page, pages, mtop = newpagecheck(c, mtop, bottomy + 20,
                                                    page, file4, pages)
                itemlist = rlist

        if details == 'on':
            mtop = mtop - dh
            indent = 0
        else:
            indent = indent1
        c.setFont('Helvetica-Bold', 11, leading=None)
        if kval == 0:
            c.drawString(ltm + indent, mtop, 'Income from:')
        c.drawRightString(rtm - bump - indent * 3, mtop,
                          optype[kval] + ' Operations:')
        c.drawRightString(rtm - bump - indent, mtop, dollar(inctotals[kval]))
        mtop = mtop - dh * 1.2

    inctotal = 0.0
    for i in inctotals:
        inctotal = inctotal + i

    c.setFont('Helvetica-Bold', 11, leading=None)
    #mtop=mtop-dh
    c.drawRightString(rtm - bump - indent * 2, mtop,
                      'Total for All Sources of Income:')
    c.drawRightString(rtm - bump, mtop, dollar(inctotal))
    mtop = mtop - dh

    p1 = ltm + 55
    p2 = ltm + 120
    p3 = ltm + 240
    p4 = ltm + 410
    p5 = rtm - 120
    p6 = rtm - 50
    #___________Expenses_____________________________
    for kval, exp in enumerate(extype):
        #blist.append([d1.strftime('%m/%d/%Y'),'COGS',company,desc,acct,nodollar(bamount)])
        complete = 0
        count = 0
        while complete == 0 and page < 20 and count < 5000:

            count += 1
            c, page, pages, mtop = newpagecheck(c, mtop, bottomy + 20, page,
                                                file4, pages)
            if details == 'on':
                hvec = [ltm, p1, p2, p3, p5, p6, rtm]
                headerlist = [
                    'BillDate', 'ExpType', 'Vendor', 'Description', 'Account',
                    'Expense'
                ]
                justify = ['c', 'c', 'l', 'l', 'l', 'r']
                mtop = stripheader(c, 10, mtop, hvec, headerlist)
            elif mtop == n1 or kval == 0:
                hvec = [ltm, rtm]
                headerlist = ['COSTS and EXPENSES']
                justify = ['r']
                mtop = stripheader(c, 12, mtop, hvec, headerlist)
                mtop = mtop - dh * 1.5

            mtop, exptotals, rlist = pl_explisting(c, 9, mtop, hvec, blist,
                                                   justify, exptotals, bottomy,
                                                   kval, exp, details, catbp)
            if mtop > 0:
                complete = 1
            else:
                c, page, pages, mtop = newpagecheck(c, mtop, bottomy + 20,
                                                    page, file4, pages)
                blist = rlist

        if details == 'on':
            mtop = mtop - dh
            indent = 0
        else:
            indent = indent1

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

        thisexp = extype[kval][0]
        if thisexp != lastexp:
            dtotals = exptotals[0:kval]
            print(kval, dtotals)
            dtotal = 0.0
            for tot in dtotals:
                dtotal = dtotal + tot
            mtop = mtop - dh * .5
            c.drawRightString(rtm - bump, mtop, dollar(dtotal))

            mtop = mtop - 2 * dh
            lastexp = thisexp
            c.drawString(ltm + indent, mtop, 'Indirect Costs (Overhead):')

        if kval == 0:
            c.drawString(ltm + indent, mtop, 'Direct Costs:')

        catname = extype[kval].replace('D:', '').replace('I:', '')
        c.drawRightString(rtm - bump - indent * 3, mtop, catname + ':')
        c.drawRightString(rtm - bump - indent, mtop, dollar(exptotals[kval]))
        mtop = mtop - dh

        if kval == len(extype) - 1:
            lastones = len(exptotals) - len(dtotals)
            itotals = exptotals[-lastones:]
            itotal = 0.0
            for tot in itotals:
                itotal = itotal + tot
            try:
                gapct = itotal / inctotal * 100
            except:
                gapct = 0.00
            mtop = mtop - dh * .5
            c.drawString(ltm + indent * 2, mtop,
                         'Overhead Rate: ' + d2s(gapct) + '%')
            c.drawRightString(rtm - bump, mtop, dollar(itotal))
            mtop = mtop - 2 * dh

    exptotal = 0.0
    for i in exptotals:
        exptotal = exptotal + i

    c.setFont('Helvetica-Bold', 11, leading=None)
    c.drawRightString(rtm - bump, mtop,
                      'Total for All Expenses: ' + dollar(exptotal))
    mtop = mtop - 2 * dh

    c.showPage()
    c.save()

    if len(pages) > 1:
        pdfcommand = ['pdfunite']
        for page in pages:
            pdfcommand.append(page)
        multioutput = addpath(f'tmp/{scac}/data/vreport/multioutput' +
                              str(cache) + '.pdf')
        pdfcommand.append(multioutput)
        tes = subprocess.check_output(pdfcommand)
    else:
        multioutput = ''

    return pages, multioutput
示例#4
0
def custcontents(file4, itemlist, headerlist, pstops, cache):

    today = datetime.datetime.today().strftime('%m/%d/%Y')
    invodate = datetime.date.today().strftime('%m/%d/%Y')
    sdate = request.values.get('start')
    fdate = request.values.get('finish')
    openbalrequest = request.values.get('dc6')
    print('itemlist=', itemlist)

    try:
        start = datetime.datetime.strptime(sdate, '%Y-%m-%d')
        end = datetime.datetime.strptime(fdate, '%Y-%m-%d')
    except:
        start = today
        end = today

    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)
    mtop = n1

    pages = [file4]
    page = 1
    c = canvas.Canvas(file4, pagesize=letter)
    c.setLineWidth(1)
    bottomy = n3
    complete = 0
    ptot = 0.0
    for p in pstops:
        ptot = ptot + p
    tofromavail = 220 - (ptot - 140)
    tfeach = tofromavail / 2.0

    pvec = [55] + pstops + [tfeach, tfeach, 40, 40]
    hvec = [ltm]
    base = ltm
    for p in pvec:
        base = base + p
        hvec.append(base)
    hvec.append(rtm)

    p1 = ltm + 55
    p2 = ltm + 120
    p3 = ltm + 190
    p4 = ltm + 300
    p5 = rtm - 120
    p6 = rtm - 80
    p7 = rtm - 40

    totals = [0.0, 0.0]

    while complete == 0 and page < 20:

        #hvec=[ltm,p1,p2,p3,p4,p5,p6,p7,rtm]
        #headerlist=['InvoDate', 'Order','Container','From','To','Invoiced','Paid','Open']
        keylen = 5 - (11 - len(headerlist))
        justify = ['c'] + ['l'] * keylen + ['l', 'l', 'r', 'r', 'r']
        mtop = stripheader(c, 10, mtop, hvec, headerlist)

        mtop, totals, rlist = orderlisting(c, 9, mtop, hvec, itemlist, justify,
                                           totals, bottomy)
        if mtop > 0:
            complete = 1
        else:
            c, page, pages, mtop = newpagecheck(c, mtop, bottomy + 20, page,
                                                file4, pages)
            itemlist = rlist

    if openbalrequest != 'on':
        c.setFont('Helvetica-Bold', 12, leading=None)
        c.drawRightString(rtm - bump, bottomy + dl * 1.2 + bump,
                          'Income Total: ' + dollar(totals[0]))

    c.setFont('Helvetica-Bold', 12, leading=None)
    c.drawRightString(rtm - bump, bottomy + bump,
                      'Open Balance Total: ' + dollar(totals[1]))

    c.showPage()
    c.save()

    if len(pages) > 1:
        pdfcommand = ['pdfunite']
        for page in pages:
            pdfcommand.append(page)
        multioutput = addpath(f'tmp/{scac}/data/vreport/multioutput' +
                              str(cache) + '.pdf')
        pdfcommand.append(multioutput)
        tes = subprocess.check_output(pdfcommand)
    else:
        multioutput = ''

    return pages, multioutput
示例#5
0
def jaycontents(file4, paiditems, servicelist, itemlist, bitemlist, total,
                btotal, nettotal, cache):

    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)
    pages = [file4]
    page = 1
    c = canvas.Canvas(file4, pagesize=letter)
    c.setLineWidth(1)
    bottomy = n3
    badd = 30

    p1 = ltm + 50
    p2 = p1 + 50
    p3 = p2 + 80
    p4 = p3 + 70
    p5 = rtm - 132
    p7 = rtm - 100
    p8 = rtm - 70
    p9 = rtm - 40

    total = 0.00

    hvec = [ltm, rtm]
    headerlist = ['Credits']
    mtop = stripheader(c, 12, n1, hvec, headerlist)

    hvec = [ltm, rtm]
    headerlist = ['Payments Made']
    mtop = stripheader(c, 11, mtop, hvec, headerlist)

    hvec = [ltm, p1, p2, p3, p4, p8, rtm]
    headerlist = [
        'Start', 'Finish', 'Booking', 'Container', 'Summary', 'Paid Amount'
    ]
    mtop = stripheader(c, 10, mtop, hvec, headerlist)

    mtop, total, rlist = paymentlisting(c, 9, mtop, hvec, paiditems, total,
                                        bottomy)

    hvec = [ltm, rtm]
    headerlist = ['Work Performed']
    mtop = stripheader(c, 11, mtop, hvec, headerlist)

    hvec = [ltm, p1, p2, p3, p4, p5, p7, p8, p9, rtm]
    headerlist = [
        'Start', 'Finish', 'Booking', 'Container', 'Summary', 'Gross', 'Days',
        'Fees', 'NetP'
    ]
    mtop = stripheader(c, 10, mtop, hvec, headerlist)

    mtop, total, rlist = itemlisting(c, 9, mtop, hvec, itemlist, total,
                                     bottomy)
    #See if we bottomed out on page:
    if mtop == 0:
        c.showPage()
        c.save()
        page = page + 1
        base = file4.replace('.pdf', '')
        newfile = base + 'page' + str(page) + '.pdf'
        c = canvas.Canvas(newfile, pagesize=letter)
        pages.append(newfile)

        hvec = [ltm, rtm]
        headerlist = ['Credits (continued)']
        mtop = stripheader(c, 12, n1, hvec, headerlist)
        hvec = [ltm, rtm]
        headerlist = ['Work Performed (continued)']
        mtop = stripheader(c, 11, mtop, hvec, headerlist)

        hvec = [ltm, p1, p2, p3, p4, p5, p7, p8, p9, rtm]
        headerlist = [
            'Start', 'Finish', 'Booking', 'Container', 'Summary', 'Gross',
            'Days', 'Fees', 'NetP'
        ]
        mtop = stripheader(c, 10, mtop, hvec, headerlist)

        mtop, total, rlist = itemlisting(c, 9, mtop, hvec, rlist, total,
                                         bottomy)

    mtop = mtop - dh * 1.2
    c.setFont('Helvetica-Bold', 12, leading=None)
    c.drawRightString(p8, mtop + bump, 'Credits Total:')
    c.drawRightString(rtm - bump, mtop + bump, dollar(total))

    credit_total = total

    mtop = mtop - dh
    c.line(ltm, mtop, rtm, mtop)
    mtop = mtop - .2 * dh
    c.line(ltm, mtop, rtm, mtop)

    debit_total = 0.0

    hvec = [ltm, rtm]
    headerlist = ['Debits']
    mtop = stripheader(c, 12, mtop, hvec, headerlist)

    c, page, pages, mtop = newpagecheck(c, mtop, bottomy + badd, page, file4,
                                        pages)

    hvec = [ltm, rtm]
    headerlist = ['Services Used']
    mtop = stripheader(c, 11, mtop, hvec, headerlist)

    c, page, pages, mtop = newpagecheck(c, mtop, bottomy + badd, page, file4,
                                        pages)

    hvec = [ltm, p1, p2, p3, p4, p8, rtm]
    headerlist = [
        'Start', 'Finish', 'Booking', 'Container', 'Summary', 'Amount Due'
    ]
    mtop = stripheader(c, 10, mtop, hvec, headerlist)

    mtop, debit_total, rlist = paymentlisting(c, 9, mtop, hvec, paiditems,
                                              debit_total, bottomy)

    #See if we bottomed out on page:
    if mtop == 0:
        c.showPage()
        c.save()
        page = page + 1
        base = file4.replace('.pdf', '')
        newfile = base + 'page' + str(page) + '.pdf'
        c = canvas.Canvas(newfile, pagesize=letter)
        pages.append(newfile)

        hvec = [ltm, rtm]
        headerlist = ['Debits (continued)']
        mtop = stripheader(c, 12, n1, hvec, headerlist)
        hvec = [ltm, rtm]
        headerlist = ['Services Used (continued)']
        mtop = stripheader(c, 11, mtop, hvec, headerlist)

        hvec = [ltm, p1, p2, p3, p4, p8, rtm]
        headerlist = [
            'Start', 'Finish', 'Booking', 'Container', 'Summary', 'Amount Due'
        ]
        mtop = stripheader(c, 10, mtop, hvec, headerlist)

        mtop, debit_total, rlist = paymentlisting(c, 9, mtop, hvec, rlist,
                                                  debit_total, bottomy)

    c, page, pages, mtop = newpagecheck(c, mtop, bottomy + badd, page, file4,
                                        pages)

    hvec = [ltm, rtm]
    headerlist = ['Bills to Jays Auto Account']
    mtop = stripheader(c, 11, mtop, hvec, headerlist)

    c, page, pages, mtop = newpagecheck(c, mtop, bottomy + badd, page, file4,
                                        pages)

    hvec = [ltm, p3, p7, rtm]
    headerlist = ['Date', 'Bill Summary', 'Amount']
    mtop = stripheader(c, 10, mtop, hvec, headerlist)

    c, page, pages, mtop = newpagecheck(c, mtop, bottomy + badd, page, file4,
                                        pages)

    mtop, debit_total, rlist = billitemlisting(c, 9, mtop, hvec, bitemlist,
                                               debit_total, bottomy)

    #See if we bottomed out on page:
    if mtop == 0:
        c.showPage()
        c.save()
        page = page + 1
        base = file4.replace('.pdf', '')
        newfile = base + 'page' + str(page) + '.pdf'
        c = canvas.Canvas(newfile, pagesize=letter)
        pages.append(newfile)

        hvec = [ltm, rtm]
        headerlist = ['Debits (continued)']
        mtop = stripheader(c, 12, n1, hvec, headerlist)
        hvec = [ltm, rtm]
        headerlist = ['Bills to Jays Auto Account (continued)']
        mtop = stripheader(c, 11, mtop, hvec, headerlist)

        hvec = [ltm, p3, p7, rtm]
        headerlist = ['Date', 'Bill Summary', 'Amount']
        mtop = stripheader(c, 10, mtop, hvec, headerlist)

        mtop, debit_total, rlist = billitemlisting(c, 9, mtop, hvec, rlist,
                                                   debit_total, bottomy)

    mtop = mtop - dh * 1.2
    c.setFont('Helvetica-Bold', 12, leading=None)
    c.drawRightString(p8, mtop + bump, 'Debits Total:')
    c.drawRightString(rtm - bump, mtop + bump, dollar(debit_total))

    net = credit_total - debit_total

    bottomline = n3 + bump
    c.setFont('Helvetica-Bold', 12, leading=None)
    c.drawRightString(300, bottomline, 'Balance Due:')
    c.drawString(300 + bump, bottomline, dollar(net))

    c.showPage()
    c.save()

    if len(pages) > 1:
        pdfcommand = ['pdfunite']
        for page in pages:
            pdfcommand.append(page)
        multioutput = addpath(f'tmp/{scac}/data/vreport/multioutput' +
                              str(cache) + '.pdf')
        pdfcommand.append(multioutput)
        tes = subprocess.check_output(pdfcommand)
    else:
        multioutput = ''

    return pages, multioutput
示例#6
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)
示例#7
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
示例#8
0
                              & (FELBills.bDate <= end)).filter(
                                  FELBills.bClass == 'JaysAuto').order_by(
                                      FELBills.bDate).all()
for data in bdata:
    print(data.bDate, data.Description, data.bAmount)
    bitemlist.append(
        [data.bDate.strftime('%Y-%m-%d'), data.Description, data.bAmount])

btotal = 0.00
l2 = len(bitemlist)
for i in range(l2):
    newlist = bitemlist[i]
    amount = newlist[2]
    btotal = btotal + float(amount)

print(dollar(btotal))

nettotal = total - btotal
print(dollar(nettotal))

#Now lets print the report out
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
from viewfuncs import nonone, nononef, nononestr, dollar, avg, comporname, fullname, address
import csv
import math

# All dates must begin in datetime format and will be converted to strings as required
示例#9
0
def jaycalcs():

    today = datetime.datetime.today().strftime('%m/%d/%Y')
    invodate = datetime.date.today().strftime('%m/%d/%Y')
    sdate = request.values.get('start')
    fdate = request.values.get('finish')
    start = datetime.datetime.strptime(sdate, '%Y-%m-%d')
    end = datetime.datetime.strptime(fdate, '%Y-%m-%d')
    startdate = start.date()

    itemlist = []
    truckjobs = []
    oceanjobs = []
    jayjobs = []
    partjobs = []
    jaypartjobs = []
    yardmoves = []
    conlist = []

    def get_take(con):
        take = 0
        type = 'J'
        move = 'deliver'
        cdata = Interchange.query.filter(Interchange.Container == con).all()
        for cdat in cdata:
            driver = cdat.Driver
            chassis = cdat.Chassis
            if "Khoder" in driver or "Jay" in driver:
                take = take + 1
                odat = Orders.query.filter(Orders.Container == con).first()
                if odat is not None:
                    type = 'T'
                ndat = OverSeas.query.filter(OverSeas.Container == con).first()
                if ndat is not None:
                    type = 'O'
                if 'toll' in chassis.lower():
                    type = 'Y'
                    if move == 'ym1toll1':
                        move = 'ym2toll2'
                    if move == 'ym1':
                        move = 'ym2toll1'
                    if move == 'deliver':
                        move = 'ym1toll1'
                if 'yard' in chassis.lower():
                    type = 'Y'
                    if move == 'ym1toll1':
                        move = 'ym2toll1'
                    if move == 'ym1':
                        move = 'ym2'
                    if move == 'deliver':
                        move = 'ym1'
                print(con, chassis, move)

        return take, type, move

    def get_chassisdays(con):
        d1 = None
        d2 = None
        ticket1 = Interchange.query.filter(
            Interchange.Container == con).first()
        try:
            ticket2 = Interchange.query.filter(
                (Interchange.Container == con)
                & (Interchange.id != ticket1.id)).first()
        except:
            ticket2 is None
            chassisdays = 0
        if ticket1 is not None and ticket2 is not None:
            date1 = ticket1.Date
            date2 = ticket2.Date
            if date1 > date2:
                d1 = date2
                d2 = date1
            else:
                d1 = date1
                d2 = date2
            delta = d2 - d1
            chassisdays = delta.days + 1

        return d1, d2, chassisdays

    def get_special(con):
        dispo = 'N'
        ticket = Interchange.query.filter(Interchange.Container == con).first()
        if ticket is not None:
            chassis = ticket.Chassis
            if 'yard' in chassis.lower():
                dispo = 'Y'
            if 'toll' in chassis.lower():
                dispo = 'T'
        return dispo

    def jay_special(con):
        dispo = 'N'
        booking = 'UNK'
        ticket = Interchange.query.filter(Interchange.Container == con).first()
        if ticket is not None:
            chassis = ticket.Chassis
            booking = ticket.Release
            if 'jay' in chassis.lower():
                dispo = 'J'
        return dispo, booking

    def jay_special2(con):
        dispo = 'N'
        booking = 'UNK'
        d1 = 'None'
        ticket = Interchange.query.filter(Interchange.Container == con).first()
        if ticket is not None:
            chassis = ticket.Chassis
            booking = ticket.Release
            d1 = ticket.Date
            if 'jay' in chassis.lower():
                dispo = 'J'
        return dispo, booking, d1

    idata = Interchange.query.filter(
        (Interchange.Date >= start) & (Interchange.Date <= end)).filter(
            (Interchange.Driver.contains("Khoder"))
            | (Interchange.Driver.contains("Jay"))).order_by(
                Interchange.Date).all()
    for idat in idata:
        if idat.Status == 'IO':
            con = idat.Container
            take, type, move = get_take(con)

            if move == 'deliver':
                if take == 2 and con not in conlist:
                    conlist.append(con)
                    if type == 'O':
                        oceanjobs.append(con)
                    if type == 'T':
                        truckjobs.append(con)
                    if type == 'J':
                        jayjobs.append(con)
                if take == 1:
                    if type != 'J':
                        partjobs.append(con)
                    else:
                        jaypartjobs.append(con)
            else:
                yardmoves.append(con)

    print('yard=', yardmoves)
    #Financial Calcs:Ocean containers
    total = 0.00
    for con in oceanjobs:
        odat = OverSeas.query.filter(OverSeas.Container == con).first()
        d1, d2, chassisdays = get_chassisdays(con)
        if d1 >= startdate:
            booking = odat.Booking
            explain = 'Ocean container warehouse + return'
            paytojay = 500.00
            fromjay = 0.00
            netpay = paytojay - fromjay
            total = total + netpay
            itemlist.append([
                d1.strftime('%m/%d/%Y'),
                d2.strftime('%m/%d/%Y'), booking, con, explain,
                nodollar(paytojay),
                str(chassisdays),
                nodollar(fromjay),
                nodollar(netpay)
            ])

#Financial Calcs:Trucking with containers
    for con in truckjobs:
        odat = Orders.query.filter(Orders.Container == con).first()
        d1, d2, chassisdays = get_chassisdays(con)
        if d1 >= startdate:
            order = odat.Order
            booking = odat.Booking
            company = odat.Shipper
            explain = 'Trucking job ' + company
            contractamt = float(odat.Amount)
            paytojay = .8 * contractamt
            if 'Global' not in explain:
                fromjay = 30.0 * chassisdays
            else:
                fromjay = 0.00
            netpay = paytojay - fromjay
            total = total + netpay
            itemlist.append([
                d1.strftime('%m/%d/%Y'),
                d2.strftime('%m/%d/%Y'), booking, con, explain,
                nodollar(paytojay),
                str(chassisdays),
                nodollar(fromjay),
                nodollar(netpay)
            ])

#Financial Calcs:Trucking with dry van
    odata = Orders.query.filter((Orders.Date >= start) & (Orders.Date <= end)
                                & (Orders.Driver.contains("Khoder"))
                                & (Orders.Container.contains('53DV'))).all()
    for odat in odata:
        d1 = odat.Date
        d2 = odat.Date2
        order = odat.Order
        booking = odat.Booking
        company = odat.Shipper
        explain = 'Dry van job ' + company
        contractamt = float(odat.Amount)
        paytojay = .8 * contractamt
        fromjay = 0.00
        netpay = paytojay - fromjay
        total = total + netpay
        itemlist.append([
            d1.strftime('%m/%d/%Y'),
            d2.strftime('%m/%d/%Y'), order, con, explain,
            nodollar(paytojay),
            str(chassisdays),
            nodollar(fromjay),
            nodollar(netpay)
        ])


#Financial Calcs:One way Items
    for con in partjobs:
        odat = Orders.query.filter(Orders.Container == con).first()
        if odat is not None:
            d1, d2, chassisdays = get_chassisdays(con)
            #d1=odat.Date
            #d2=odat.Date2
            if d1 >= startdate:
                chassisday = 'None'
                order = odat.Order
                booking = odat.Booking
                company = odat.Shipper
                contractamt = float(odat.Amount)

                dispo = get_special(con)
                if dispo == 'N':
                    explain = 'Half-trucking job'
                    paytojay = .5 * contractamt
                if dispo == 'Y':
                    explain = 'Move to Yard'
                    paytojay = 50.00
                if dispo == 'T':
                    explain = 'Reposition with Tolls'
                    paytojay = 100.00

                fromjay = 0.00
                netpay = paytojay - fromjay
                total = total + netpay
                itemlist.append([
                    d1.strftime('%m/%d/%Y'),
                    d2.strftime('%m/%d/%Y'), order, con, explain,
                    nodollar(paytojay),
                    str(chassisdays),
                    nodollar(fromjay),
                    nodollar(netpay)
                ])

        ndat = OverSeas.query.filter(OverSeas.Container == con).first()
        if ndat is not None:
            d1 = ndat.PuDate
            d2 = ndat.RetDate
            try:
                d1s = d1.strftime('%m/%d/%Y')
            except:
                d1s = 'None'
            try:
                d2s = d2.strftime('%m/%d/%Y')
            except:
                d2s = 'None'
            booking = ndat.Booking
            dispo = get_special(con)
            if dispo == 'N':
                explain = 'Half-warehouse job'
                paytojay = 250.00
            if dispo == 'Y':
                explain = 'Move to Yard'
                paytojay = 50.00
            if dispo == 'T':
                explain = 'Reposition with Tolls'
                paytojay = 100.00
            fromjay = 0.00
            netpay = paytojay - fromjay
            total = total + netpay
            itemlist.append([
                d1s, d2s, booking, con, explain,
                nodollar(paytojay),
                str(chassisdays),
                nodollar(fromjay),
                nodollar(netpay)
            ])

    #Financial Calcs: Jay containers
    for con in jayjobs:
        d1, d2, chassisdays = get_chassisdays(con)
        if d1 >= startdate:
            verify, booking = jay_special(con)
            explain = 'Jay job verified as: ' + verify
            paytojay = 0.00
            fromjay = 30.00 * chassisdays
            netpay = paytojay - fromjay
            total = total + netpay
            itemlist.append([
                d1.strftime('%m/%d/%Y'),
                d2.strftime('%m/%d/%Y'), booking, con, explain,
                nodollar(paytojay),
                str(chassisdays),
                nodollar(fromjay),
                nodollar(netpay)
            ])

    #Financial Calcs: Jay part containers
    for con in jaypartjobs:
        verify, booking, d1 = jay_special2(con)
        explain = 'Jay job missing ticket: ' + verify
        paytojay = 0.00
        chassisdays = 6
        fromjay = 30.00 * chassisdays
        netpay = paytojay - fromjay
        total = total + netpay
        itemlist.append([
            d1.strftime('%m/%d/%Y'),
            d1.strftime('%m/%d/%Y'), booking, con, explain,
            nodollar(paytojay),
            str(chassisdays),
            nodollar(fromjay),
            nodollar(netpay)
        ])

    for con in yardmoves:
        idat = Interchange.query.filter(Interchange.Container == con).first()
        booking = idat.Release
        take, type, move = get_take(con)
        d1, d2, chassisdays = get_chassisdays(con)
        if move == 'ym2toll2':
            explain = 'Two yard moves 2 tolls'
            paytojay = 150.00
        if move == 'ym2toll1':
            explain = 'Two yard moves 1 toll'
            paytojay = 125.00
        if move == 'ym2':
            explain = 'Two yard moves each'
            paytojay = 50.00
        if move == 'ym1toll1':
            explain = 'Yard move with toll'
            paytojay = 75.00
        if move == 'ym1':
            explain = 'Yard move'
            paytojay = 50.00
        chassisdays = 0
        fromjay = 0.00
        netpay = paytojay - fromjay
        total = total + netpay
        print('Here is:', booking, con, explain, move)
        itemlist.append([
            d1.strftime('%m/%d/%Y'),
            d1.strftime('%m/%d/%Y'), booking, con, explain,
            nodollar(paytojay),
            str(chassisdays),
            nodollar(fromjay),
            nodollar(netpay)
        ])

    bitemlist = []
    #Find expenses paid for Jay

    paymentlist = []
    servicelist = []
    #Financial Calcs:Income Credits to Jay, Items Jay Paid For
    odata = OverSeas.query.filter((OverSeas.PuDate >= start)
                                  & (OverSeas.RetDate <= end)
                                  & (OverSeas.BillTo.contains("Jays"))).all()
    for odat in odata:
        d1 = odat.PuDate
        d2 = odat.RetDate
        jo = odat.Jo
        booking = odat.Booking
        print('Booking', booking, jo)
        con = odat.Container
        chassisdays = ''
        explain = 'Credit for Payments made: Overseas Shipping'
        idat = Income.query.filter(Income.Jo == jo).first()
        print(idat)
        if idat is not None:
            print('Found Income')
            paytojay = float(idat.Amount)
            fromjay = 0.00
            netpay = paytojay - fromjay
            total = total + netpay
            paymentlist.append([
                d1.strftime('%m/%d/%Y'),
                d2.strftime('%m/%d/%Y'), booking, con, explain,
                nodollar(paytojay)
            ])

        indat = Invoices.query.filter(Invoices.Jo == jo).first()
        if indat is not None:
            print('Found Invoices')
            explain2 = 'Services Provided: Overseas Shipping'
            amount = float(indat.Total)
            servicelist.append([
                d1.strftime('%m/%d/%Y'),
                d2.strftime('%m/%d/%Y'), booking, con, explain2,
                nodollar(amount)
            ])
            print(bitemlist)

    bdata = FELBills.query.filter(
        (FELBills.bDate >= start) & (FELBills.bDate <= end)
        & ((FELBills.Co == 'J') | (FELBills.bCat == 'JaysAuto'))).order_by(
            FELBills.bDate).all()
    for data in bdata:
        print(data.bDate, data.Description, data.bAmount)
        bitemlist.append(
            [data.bDate.strftime('%Y-%m-%d'), data.Description, data.bAmount])

    btotal = 0.00
    l2 = len(bitemlist)
    print('l2=', l2)
    for i in range(l2):
        newlist = bitemlist[i]
        amount = newlist[2]
        btotal = btotal + float(amount)
        print(amount, btotal)

    print(dollar(btotal))

    nettotal = total - btotal
    print(dollar(nettotal))

    return paymentlist, servicelist, itemlist, bitemlist, total, btotal, nettotal
示例#10
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
示例#11
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
示例#12
0
def calendar7_weeks_all_old(lweeks):
    today = datetime.datetime.today()
    nweeks = lweeks[0] + lweeks[1]
    ndays = nweeks * 7
    day = today.day
    d = today
    nlist = ndays * 12
    caldays = list(range(ndays))
    caldt = list(range(ndays))
    daylist = list(range(nlist))
    shlst = list(range(nlist))
    days_ahead = [0] * nweeks
    calmon = [0] * nweeks
    next_weekday = [0] * nweeks
    datestr = [0] * nweeks

    for i in range(ndays):
        for j in range(12):
            k = 9 * i + j
            daylist[k] = 0

    for i in range(7):
        days_ahead1 = i - 7 - d.weekday()
        if days_ahead1 <= 0:
            days_ahead1 += 7
        day0 = days_ahead1 - 7 * lweeks[0]
        for m in range(nweeks):
            days_ahead[m] = day0 + 7 * m
            next_weekday[m] = d + datetime.timedelta(days_ahead[m])
            calmon[m] = str(next_weekday[m].month)
            caldays[i + 7 *
                    m] = calendar.day_abbr[i] + ' ' + calendar.month_abbr[int(
                        calmon[m])] + ' ' + str(next_weekday[m].day)
            datestr[m] = str(next_weekday[m].month) + '/' + str(
                next_weekday[m].day) + '/' + str(next_weekday[m].year)
            caldt[i + 7 * m] = datetime.datetime.strptime(
                datestr[m], '%m/%d/%Y')

        if next_weekday[lweeks[0]].day == day:
            caldays[i + 7 * lweeks[0]] = 'X' + calendar.day_abbr[
                i] + ' ' + calendar.month_abbr[int(
                    calmon[lweeks[0]])] + ' ' + str(
                        next_weekday[lweeks[0]].day)

    if 1 == 1:
        weeksum = 0
        j1 = 0
        j2 = 0
        j3 = 0
        j4 = 0
        j5 = 0
        for i in range(ndays):
            dloc = caldt[i]
            dloc2 = dloc + datetime.timedelta(days=1)

            #___Overseas Part________________________________________________________________

            odata = OverSeas.query.filter(OverSeas.PuDate == dloc).all()
            for j1, data in enumerate(odata):
                k = 12 * i + j1
                shipper = data.BillTo
                if len(shipper) > 8:
                    shipper = re.match(r'\W*(\w[^,. !?"]*)',
                                       shipper).groups()[0]

                pod = data.Pod
                pol = data.Pol
                if len(pod) > 8:
                    pod = re.match(r'\W*(\w[^,. !?"]*)', pod).groups()[0]
                if len(pol) > 8:
                    pol = re.match(r'\W*(\w[^,. !?"]*)', pol).groups()[0]

                container = data.Container
                book = data.Booking
                bdat = Bookings.query.filter(
                    Bookings.Booking == data.Booking).first()
                if bdat is not None:
                    doccut = bdat.PortCut.strftime('%m/%d/%Y')
                else:
                    doccut = ''
                cb = []
                comlist = ChalkBoard.query.filter(
                    ChalkBoard.Jo == data.Jo).all()
                for c in comlist:
                    addline = c.register_date.strftime(
                        '%m/%d/%Y'
                    ) + ' by ' + c.creator + ' at ' + c.register_date.strftime(
                        '%H:%M') + ': ' + c.comments
                    addline = parselinenoupper(addline, 85)
                    for a in addline:
                        cb.append(a)

                drv = Drivers.query.filter(Drivers.Name == data.Driver).first()
                if drv is not None:
                    phone = drv.Phone
                    trk = drv.Truck
                    plate = drv.Tag
                else:
                    phone = ''
                    trk = ''
                    plate = ''

                lt = data.Jo
                lt = lt[6:8]
                shlst[k] = [lt, 'O', 'blue darken-4']
                daylist[k] = [
                    data.id, shipper, book, container, pol, pod, data.Jo,
                    data.Status, data.Driver, phone, trk, plate, doccut, cb
                ]

#___Trucking Part________________________________________________________________
            tdata = Orders.query.filter((Orders.Date >= dloc)
                                        & (Orders.Date < dloc2)).all()
            for j2, data in enumerate(tdata):
                k = 12 * i + j1 + j2 + 1

                shipper = data.Shipper
                if len(shipper) > 8:
                    shipper = re.match(r'\W*(\w[^,. !?"]*)',
                                       shipper).groups()[0]
                loc1 = People.query.filter((People.Company == data.Company) & (
                    People.Ptype == 'Trucking')).first()
                loc2 = People.query.filter(
                    (People.Company == data.Company2)
                    & (People.Ptype == 'Trucking')).first()
                drv = Drivers.query.filter(Drivers.Name == data.Driver).first()

                if loc1 is not None:
                    addr11 = loc1.Addr1
                    addr21 = loc1.Addr2
                else:
                    addr11 = ''
                    addr21 = ''
                if loc2 is not None:
                    addr12 = loc2.Addr1
                    addr22 = loc2.Addr2
                else:
                    addr12 = ''
                    addr22 = ''
                if drv is not None:
                    phone = drv.Phone
                    trk = drv.Truck
                    plate = drv.Tag
                else:
                    phone = ''
                    trk = ''
                    plate = ''

                cb = []
                comlist = ChalkBoard.query.filter(
                    ChalkBoard.Jo == data.Jo).all()
                for c in comlist:
                    addline = c.register_date.strftime(
                        '%m/%d/%Y'
                    ) + ' by ' + c.creator + ' at ' + c.register_date.strftime(
                        '%H:%M') + ': ' + c.comments
                    addline = parselinenoupper(addline, 85)
                    for a in addline:
                        cb.append(a)

                lt = data.Jo
                lt = lt[6:8]
                shlst[k] = [lt, 'T', 'red darken-4']
                daylist[k] = [
                    data.Order, data.Pickup, data.Booking, data.Driver,
                    data.Time, data.Jo, data.Container, data.Status, shipper,
                    data.id, data.Company, addr11, addr21, data.Company2,
                    addr12, addr22, phone, trk, plate, cb
                ]

#___Horizon/Towing Part________________________________________________________________
            adata = db.session.query(
                Autos.TowCompany).distinct().filter(Autos.Date2 == dloc)
            for j3, data in enumerate(adata):

                adat = Autos.query.filter(
                    Autos.TowCompany == data.TowCompany).first()
                cb = []
                comlist = ChalkBoard.query.filter(
                    ChalkBoard.Jo == adat.Jo).all()
                for c in comlist:
                    addline = c.register_date.strftime(
                        '%m/%d/%Y'
                    ) + ' by ' + c.creator + ' at ' + c.register_date.strftime(
                        '%H:%M') + ': ' + c.comments
                    addline = parselinenoupper(addline, 85)
                    for a in addline:
                        cb.append(a)
                com = adat.TowCompany
                if com is None or com == '' or len(com) < 2:
                    com = 'FIX'

                if adat is not None:
                    autolist = []
                    allcars = Autos.query.filter(
                        Autos.TowCompany == adat.TowCompany).all()
                    for car in allcars:
                        autolist.append(
                            [car.Year, car.Make, car.Model, car.VIN])

                try:
                    amt = adat.TowCost
                    amt = nononef(amt)
                    ncars = len(autolist)
                    amteach = amt / ncars
                    amteach = dollar(amteach)
                except:
                    amteach = '0.00'
                    ncars = 0

                k = 12 * i + j1 + j2 + j3 + 2
                shlst[k] = [adat.TowCost, 'H', 'amber accent-4']
                daylist[k] = [
                    adat.id, com, adat.TowCost, adat.Status, autolist, cb,
                    adat.Jo, amteach, ncars
                ]
#___Moving Part________________________________________________________________

            mdata = Moving.query.filter(Moving.Date == dloc).all()
            for j4, data in enumerate(mdata):
                k = 12 * i + j1 + j2 + j3 + j4 + 3
                shipper = data.Shipper
                if len(shipper) > 8:
                    shipper = re.match(r'\W*(\w[^,. !?"]*)',
                                       shipper).groups()[0]
                loc1 = Drops.query.filter(Drops.Entity == data.Drop1).first()
                loc2 = Drops.query.filter(Drops.Entity == data.Drop2).first()
                drv = Drivers.query.filter(Drivers.Name == data.Driver).first()

                if loc1 is not None:
                    addr11 = loc1.Addr1
                    addr21 = loc1.Addr2
                else:
                    addr11 = ''
                    addr21 = ''
                if loc2 is not None:
                    addr12 = loc2.Addr1
                    addr22 = loc2.Addr2
                else:
                    addr12 = 'NF'
                    addr22 = 'NF'
                if drv is not None:
                    phone = drv.Phone
                    trk = drv.Truck
                    plate = drv.Tag
                else:
                    phone = ''
                    trk = ''
                    plate = ''

                cb = []
                comlist = ChalkBoard.query.filter(
                    ChalkBoard.Jo == data.Jo).all()
                for c in comlist:
                    addline = c.register_date.strftime(
                        '%m/%d/%Y'
                    ) + ' by ' + c.creator + ' at ' + c.register_date.strftime(
                        '%H:%M') + ': ' + c.comments
                    addline = parselinenoupper(addline, 85)
                    for a in addline:
                        cb.append(a)

                lt = data.Jo
                lt = lt[6:8]
                shlst[k] = [lt, 'M']
                daylist[k] = [
                    data.id, data.Jo, shipper, data.Drop1, addr11, addr21,
                    data.Time, data.Drop2, addr12, addr22, data.Time2,
                    data.Container, data.Driver, data.Status, phone, trk,
                    plate, cb, data.Amount
                ]

#___Billing Part________________________________________________________________
            adata = Accounts.query.all()
            bdata = FELBills.query.filter(FELBills.bDate == dloc)
            for j5, data in enumerate(bdata):
                k = 12 * i + j1 + j2 + j3 + j4 + j5 + 4

                billno = 'Bill' + str(data.id)
                cb = []
                comlist = ChalkBoard.query.filter(
                    ChalkBoard.Jo == billno).all()
                for c in comlist:
                    addline = c.register_date.strftime(
                        '%m/%d/%Y'
                    ) + ' by ' + c.creator + ' at ' + c.register_date.strftime(
                        '%H:%M') + ': ' + c.comments
                    addline = parselinenoupper(addline, 85)
                    for a in addline:
                        cb.append(a)

                shlst[k] = [data.bAmount, 'B', 'green darken-4']
                daylist[k] = [
                    data.id, data.Company, data.bAmount, data.Account,
                    data.Status, data.bType, data.bClass, cb
                ]

    return caldays, daylist, weeksum, shlst