예제 #1
0
def reportmake(type):

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

    file1 = f'tmp/{scac}/data/vreport/pagestart.pdf'
    file2 = f'tmp/{scac}/data/vreport/background.pdf'
    file3 = f'tmp/{scac}/data/vreport/headers.pdf'
    file4 = f'tmp/{scac}/data/vreport/contents.pdf'
    today = datetime.datetime.today().strftime('%m/%d/%Y')
    invodate = datetime.date.today().strftime('%m/%d/%Y')

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

    if type == 'mtick':
        invo_background(file2)
        jayheaders(file3)
        itemlist = ticketcalcs()
        ticketcontents(file4, itemlist)

    if type == 'jay':
        invo_background(file2)
        jayheaders(file3)
        itemlist, bitemlist, total, btotal, nettotal = jaycalcs()
        jaycontents(file4, itemlist, bitemlist, total, btotal, nettotal)

    cache, docref = pagemerger([file1, file2, file3, file4], cache)
    return cache, docref
예제 #2
0
def isoAM():

    if request.method == 'POST':
# ____________________________________________________________________________________________________________________B.FormVariables.General

        from viewfuncs import parseline, popjo, jovec, newjo, timedata, nonone, nononef, stripper, check_shared, check_mirror_exp
        from viewfuncs import numcheck, numcheckv, viewbuttons, get_ints, numcheckvec, erud, hasinput, get_tmap, get_qmap

        #Zero and blank items for default
        username = session['username'].capitalize()
        cache=0
        modata=0
        modlink=0
        scdata=0
        tmap = None
        fmap = None
        qmap = None
        gmap = None

        today = datetime.date.today()
        now = datetime.datetime.now().strftime('%I:%M %p')

        modify   =  request.values.get('Qmod')
        shared = request.values.get('Shared')
        returnhit = request.values.get('Return')
        deletehit = request.values.get('Delete')


        # hidden values
        update   =  request.values.get('Update')
        newact=request.values.get('NewA')
        thisjob=request.values.get('ThisJob')
        oder=request.values.get('oder')
        modlink = request.values.get('modlink')
        companyon = request.values.get('actype')
        if companyon is None:
            companyon='Show All Accounts'

        oder=nonone(oder)
        modlink=nonone(modlink)

        leftscreen=1
        err=[]

        if returnhit is not None:
            modlink=0


# ____________________________________________________________________________________________________________________E.FormVariables.General
# ____________________________________________________________________________________________________________________B.DataUpdates.General

        if modlink==1:
            if oder > 0:
                modata=Accounts.query.get(oder)
                vals=['acctname','accttype','acctcat','acctsub','acctnumb','acctrout','acctpaye','acctdesc','accttax','acctco','qbmap']
                a=list(range(len(vals)))
                for i,v in enumerate(vals):
                    a[i]=request.values.get(v)


                modata.Name=a[0]
                modata.Type=a[1]
                if a[1] is not None:
                    adat = Accttypes.query.filter(Accttypes.Name==a[1]).first()
                    if adat is not None:
                        defcat = adat.Category
                        defsub = adat.Subcategory

                if a[2] is None:
                    modata.Category = defcat
                else:
                    modata.Category=a[2]

                if a[3] is None:
                    modata.Subcategory = defsub
                else:
                    modata.Subcategory=a[3]

                modata.AcctNumber=a[4]
                modata.Routing=a[5]
                modata.Payee=a[6]
                modata.Description=a[7]
                modata.Taxrollup=a[8]
                modata.Co=a[9]
                modata.QBmap = a[10]

                db.session.commit()
                err.append('Modification to Account id ' + str(modata.id) + ' completed.')

                # Narrow the selection boxes for company and type
                print('a[1]', a[1])
                print(hasinput(a[1]))
                if hasinput(a[1]):
                    fmap = Focusareas.query.filter(Focusareas.Co == a[9]).all()
                    gmap = Taxmap.query.filter(Taxmap.Category.contains('deductions')).all()
                    tmap = get_tmap(a[1], a[2])
                    qmap = get_qmap(a[1], a[2])


                if update is not None:
                    modlink=0
                    leftsize=10
                else:
                    leftsize=6
                    modata=Accounts.query.get(oder)

# ____________________________________________________________________________________________________________________B.GetData.General
        if companyon == 'Show All Accounts':
            odata = Accounts.query.all()
        elif companyon == 'Show Shared Accounts':
            odata = Accounts.query.filter(Accounts.Shared != None).all()
        elif ':' in companyon:
            comp,focus = companyon.split(':')
            print(comp,focus)
            odata = Accounts.query.filter( (Accounts.Co==comp) & (Accounts.Subcategory==focus) ).all()
        else:
            odata = Accounts.query.filter((Accounts.Co.contains(companyon))).all()
# ____________________________________________________________________________________________________________________B.Search.General

        if modlink==0:
            oder,numchecked=numcheck(1,odata,0,0,0,0,['oder'])
        else:
            numchecked = 0

# ____________________________________________________________________________________________________________________E.Search.General

        if shared is not None:
            if oder > 0 and numchecked == 1:
                odat = Accounts.query.get(oder)
                atype = odat.Type
                if atype == 'Expense':
                    co1 = odat.Co
                    thisdat = Divisions.query.filter(Divisions.Co == co1).first()
                    co1name = thisdat.Name
                    otherdat = Divisions.query.filter(Divisions.Co != co1).first()
                    sid = otherdat.id
                    co2 = otherdat.Co
                    co2name = otherdat.Name
                    err.append(f'Account **{odat.Name}** owned by code {odat.Co}')
                    err.append(f'Is now set up for share with {otherdat.Name} code {otherdat.Co}')

                    # Now check to see if the sharing accounts exist and if not create them
                    fromtoid, err = check_shared(co1,co2name, err)
                    tofromid, err = check_shared(co2,co1name, err)
                    mirrorexpid, err = check_mirror_exp(co2,odat.id,odat.Name,err)


                    slist = json.dumps([sid,fromtoid,tofromid,mirrorexpid])
                    odat.Shared = slist
                    db.session.commit()
                    mirrordat = Accounts.query.get(mirrorexpid)
                    mirrordat.Shared = slist
                    db.session.commit()

                    if companyon == 'Show All Accounts':
                        odata = Accounts.query.all()
                    elif companyon == 'Show Shared Accounts':
                        odata = Accounts.query.filter(Accounts.Shared != None).all()
                    else:
                        odata = Accounts.query.filter((Accounts.Co.contains(companyon))).all()

                else:
                    err.append(f'Cannot share: {odat.Name} of type {atype}')
                    err.append(f'Can only share and apportion **Expense** accounts')
            else:
                err.append(f'Must select one account to use this option')



# ____________________________________________________________________________________________________________________B.Modify.General
        if modify is not None and numchecked==1 :
            modlink=1
            leftsize=6

            if oder>0:
                modata=Accounts.query.get(oder)
                err.append(f'Modify {modata.Name}:{modata.Co}:{modata.Type}')

                if hasinput(modata.Type):
                    fmap = Focusareas.query.filter(Focusareas.Co == modata.Co).all()
                    gmap = Taxmap.query.filter(Taxmap.Category.contains('deductions')).all()
                    tmap = get_tmap(modata.Type, modata.Category)
                    qmap = get_qmap(modata.Type, modata.Category)

        if modify is not None and numchecked!=1:
            modlink=0
            err.append('Must check exactly one box to use this option')
# ____________________________________________________________________________________________________________________E.Modify.General

# ____________________________________________________________________________________________________________________B.Delete.General
        if deletehit is not None and numchecked==1:
            if oder>0:
                #This section is to determine if we can delete the source file along with the data.  If other data is pointing to this
                #file then we need to keep it.
                modata=Accounts.query.get(oder)

                Accounts.query.filter(Accounts.id == oder).delete()
                db.session.commit()
                if companyon == 'Show All Accounts':
                    odata = Accounts.query.all()
                elif companyon == 'Show Shared Accounts':
                    divdata = Divisions.query.all()
                    tester = ''
                    for div in divdata:
                        tester = tester + div.Co
                    odata = Accounts.query.filter(Accounts.Co.like(tester)).all()

                else:
                    odata = Accounts.query.filter((Accounts.Co.contains(companyon))).all()

        if deletehit is not None and numchecked != 1:
            err.append('Must have exactly one item checked to use this option')
# ____________________________________________________________________________________________________________________E.Delete.General

# ____________________________________________________________________________________________________________________B.Newjob.General
        if newact is not None:
            modlink=10
            leftsize=6
            modata=Accounts.query.get(1)
            if modata is not None:
                modata.Name=''
                modata.Type=None
                modata.Category=None
                modata.Subcategory=None
                modata.AcctNumber=''
                modata.Routing=''
                modata.Payee=''
                modata.Description=''
                modata.Taxrollup=None
                modata.Co=None
                modata.QBmap = None


        if newact is None and modlink==10:
            #Create the new database entry for the source document
            acctname=request.values.get('acctname')
            acctnumb=request.values.get('acctnumb')
            acctrout=request.values.get('acctrout')
            acctpaye=request.values.get('acctpaye')
            accttype=request.values.get('accttype')
            acctdesc=request.values.get('acctdesc')
            acctcat=request.values.get('acctcat')
            acctsub=request.values.get('acctsub')
            accttax=request.values.get('accttax')
            acctco=request.values.get('acctco')
            qbmap = request.values.get('qbmap')

            acctname = stripper(acctname)
            adat = Accounts.query.filter((Accounts.Name==acctname) & (Accounts.Co==acctco)).first()
            if adat is not None:
                err.append(f'Account with name {acctname} for {acctco} already exists')
            else:
                input = Accounts(Name=acctname,Balance=0.00,AcctNumber=acctnumb,Routing=acctrout,Payee=acctpaye,Type=accttype,
                                 Description=acctdesc,Category=acctcat,Subcategory=acctsub,Taxrollup=accttax,Co=acctco,QBmap=qbmap, Shared=None)
                db.session.add(input)
                db.session.commit()

                # Narrow the selection boxes for company and type
                if hasinput(accttype):
                    print('acctco',acctco)
                    fmap = Focusareas.query.filter(Focusareas.Co == acctco).all()
                    gmap = Taxmap.query.filter(Taxmap.Category.contains('deductions')).all()
                    tmap = get_tmap(accttype, 0)
                    qmap = get_qmap(accttype, 0)

                odata = Accounts.query.all()
                modata = odata[-1]
                oder=modata.id
                modlink=1

# ____________________________________________________________________________________________________________________E.Newjob.General

    #This is the else for 1st time through (not posting data from overseas.html)
    else:
        from viewfuncs import popjo, jovec, timedata, nonone, nononef, init_truck_zero, erud
        today = datetime.date.today()
        #today = datetime.datetime.today().strftime('%Y-%m-%d')
        now = datetime.datetime.now().strftime('%I:%M %p')
        oder=0
        cache=0
        modata=0
        modlink=0
        scdata=0
        odata = Accounts.query.all()
        companyon = 'Show All Accounts'
        leftscreen=1
        leftsize=10
        tmap = None
        fmap = None
        qmap = None
        gmap = None
        err = []

    scdata=[]
    for odat in odata:
        catitem=odat.Category
        additem=odat.Subcategory
        if additem is not None and catitem is not None:
            if catitem=='G-A' and additem not in scdata:
                scdata.append(additem)
    scdata.sort()
    leftsize = 8
    divdata = Divisions.query.all()
    colordict = {}
    for div in divdata:
        colordict.update({div.Co:div.Color})
    print(colordict)
    err = erud(err)
    atypes = Accttypes.query.all()
    if fmap is None: fmap = Focusareas.query.all()


    return odata,oder,err,modata,modlink,leftscreen,leftsize,today,now,scdata,companyon,divdata,atypes,tmap,fmap,qmap, gmap, colordict
예제 #3
0
def isoC():

    if request.method == 'POST':
        # ____________________________________________________________________________________________________________________B.FormVariables.Compliance

        from viewfuncs import parseline, popjo, jovec, newjo, timedata, nonone, nononef
        from viewfuncs import numcheck, numcheckv, viewbuttons, get_ints, numcheckvec

        #Zero and blank items for default
        username = session['username'].capitalize()
        cache = 0
        modata = 0
        modlink = 0
        fdata = 0
        filesel = ''
        docref = ''
        doctxt = ''
        longs = ''

        today = datetime.date.today()
        now = datetime.datetime.now().strftime('%I:%M %p')

        leftsize = 10

        match = request.values.get('Match')
        modify = request.values.get('Modify')
        vmod = request.values.get('Vmod')
        viewo = request.values.get('ViewO')
        print = request.values.get('Print')
        returnhit = request.values.get('Return')
        deletehit = request.values.get('Delete')
        delfile = request.values.get('DELF')
        # hidden values
        update = request.values.get('Update')
        newjob = request.values.get('NewJ')
        thisjob = request.values.get('ThisJob')
        oder = request.values.get('oder')
        modlink = request.values.get('modlink')
        longs = request.values.get(longs)
        searchfind = request.values.get('mastersearch')
        assemble = request.values.get('Assemble')

        oder = nonone(oder)
        modlink = nonone(modlink)
        actype = request.values.get('actype')

        leftscreen = 1
        err = ['All is well', ' ', ' ', ' ', ' ']

        if returnhit is not None:
            modlink = 0
            actype = 'Choose Compliance Subject'

        if searchfind is not None:
            modlink = 20

# ____________________________________________________________________________________________________________________E.FormVariables.Compliance
# ____________________________________________________________________________________________________________________B.DataUpdates.Compliance

        if update is not None and modlink == 1:
            if oder > 0:
                modata = Compliance.query.get(oder)
                vals = [
                    'subject', 'category', 'longs', 'item', 'date1', 'date2'
                ]
                a = list(range(len(vals)))
                for i, v in enumerate(vals):
                    a[i] = request.values.get(v)
                datedue = a[4]
                datefiled = a[5]

                if datedue == '':
                    newdate1 = None
                else:
                    newdate1 = datedue

                if datefiled == '':
                    newdate2 = None
                else:
                    newdate2 = datedue

                modata.Subject = a[0]
                modata.Category = a[1]
                modata.Textinfo = a[2]
                modata.Item = a[3]
                modata.Date1 = newdate1
                modata.Date2 = newdate2

                db.session.commit()
                err[3] = 'Modification to Compliance id ' + str(
                    modata.id) + ' completed.'
                modlink = 0

# ____________________________________________________________________________________________________________________B.GetData.Compliance
        if actype == 'Choose Compliance Subject' or actype is None:
            odata = Compliance.query.all()
        else:
            odata = Compliance.query.filter(Compliance.Subject == actype).all()

        if assemble is not None:
            avec = numcheckvec(odata, 'oder')
            scommand = ['pdfunite']
            if len(avec) > 0:
                for a in avec:
                    gdat = Compliance.query.get(a)
                    dot = gdat.File1
                    docref = f'tmp/{scac}/data/vcompliance/' + dot
                    scommand.append(docref)
                scommand.append(
                    f'tmp/{scac}/data/vunknown/assembledoutput.pdf')
                tes = subprocess.check_output(scommand)
# ____________________________________________________________________________________________________________________B.Search.Compliance

        if (newjob is None and modlink < 10) or modlink == 20:
            oder, numchecked = numcheck(1, odata, 0, 0, 0, 0, ['oder'])

# ____________________________________________________________________________________________________________________E.Search.Compliance

# ____________________________________________________________________________________________________________________B.Views.Compliance

        if viewo is not None and numchecked == 1:
            err = [
                ' ', ' ', 'There is no document available for this selection',
                ' ', ' '
            ]
            if oder > 0:
                modata = Compliance.query.get(oder)
                if modata.File1 is not None:
                    dot = modata.File1
                    txt = dot.split('.', 1)[0] + '.txt'
                    docref = f'tmp/{scac}/data/vcompliance/' + dot
                    doctxt = docref.replace('.pdf', '.txt').replace(
                        '.jpg', '.txt').replace('.jpeg', '.txt')
                    leftscreen = 0
                    leftsize = 10
                    modlink = 0
                    err = [' ', ' ', 'Viewing document ' + docref, ' ', ' ']

        if (viewo is not None) and numchecked != 1:
            err = [
                'Must check exactly one box to use this option', ' ', ' ', ' ',
                ' '
            ]

# ____________________________________________________________________________________________________________________E.Views.Compliance
# ____________________________________________________________________________________________________________________B.Modify.Compliance
        if (modify is not None or vmod is not None) and numchecked == 1:
            modlink = 1
            leftsize = 8

            if oder > 0:
                modata = Compliance.query.get(oder)
                if vmod is not None:
                    err = [
                        ' ', ' ',
                        'There is no document available for this selection',
                        ' ', ' '
                    ]
                    if modata.File1 is not None:
                        dot = modata.File1
                        docref = f'tmp/{scac}/data/vcompliance/' + dot
                        doctxt = docref.replace('.pdf', '.txt').replace(
                            '.jpg', '.txt').replace('.jpeg', '.txt')

                        leftscreen = 0

                        err = ['All is well', ' ', ' ', ' ', ' ']

        if (modify is not None or vmod is not None) and numchecked != 1:
            modlink = 0
            err[0] = ' '
            err[2] = 'Must check exactly one box to use this option'
# ____________________________________________________________________________________________________________________E.Modify.Compliance

# ____________________________________________________________________________________________________________________B.Delete.Compliance
        if deletehit is not None and numchecked == 1:
            if oder > 0:
                #This section is to determine if we can delete the source file along with the data.  If other data is pointing to this
                #file then we need to keep it.
                modata = Compliance.query.get(oder)
                if modata.File1 is not None:
                    dot = modata.File1
                    docref = f'tmp/{scac}/data/vcompliance/' + dot

                othdoc = Compliance.query.filter((Compliance.File1 == dot) & (
                    Compliance.File1 != modata.id)).first()
                if othdoc is None:
                    try:
                        os.remove(addpath(docref))
                        os.remove(addtxt(docref))
                    except:
                        err[0] = 'File already removed'

                Compliance.query.filter(Compliance.id == oder).delete()
                db.session.commit()
                odata = Compliance.query.all()

        if deletehit is not None and numchecked != 1:
            err = [
                ' ', ' ',
                'Must have exactly one item checked to use this option', ' ',
                ' '
            ]
# ____________________________________________________________________________________________________________________E.Delete.Compliance

# ____________________________________________________________________________________________________________________B.Newjob.Compliance
        if newjob is not None:
            err = ['Select Source Document from List']
            fdata = myoslist(f'tmp/{scac}/data/vunknown')
            fdata.sort()
            modlink = 10
            leftsize = 8
            leftscreen = 0
            docref = f'tmp/{scac}/data/vunknown/NewJob.pdf'

        if newjob is None and update is None and modlink == 10:
            filesel = request.values.get('FileSel')
            filetxt = filesel.replace('.pdf',
                                      '.txt').replace('.jpg', '.txt').replace(
                                          '.jpeg', '.txt')
            fdata = myoslist(f'tmp/{scac}/data/vunknown')
            fdata.sort()
            leftsize = 8
            leftscreen = 0
            docref = f'tmp/{scac}/data/vunknown/' + filesel
            doctxt = f'tmp/{scac}/data/vunknown/' + filetxt

            try:
                longs = open(addpath(doctxt)).read()
                longs = longs[0:999]
            except:
                doctxt = ''
                longs = ''

        if delfile is not None and modlink == 10:
            modlink = 0
            filesel = request.values.get('FileSel')
            if filesel != '1':
                dockill1 = f'tmp/{scac}/data/vunknown/' + filesel
                try:
                    os.remove(addpath(dockill1))
                except:
                    err[1] = 'Could not delete ...'
                try:
                    os.remove(addtxt(dockill1))
                except:
                    err[2] = 'Could not delete txt'

        if update is not None and modlink == 10:
            modlink = 0
            #Create the new database entry for the source document
            filesel = request.values.get('FileSel')

            if filesel != '1':
                docold = f'tmp/{scac}/data/vunknown/' + filesel
                docref = f'tmp/{scac}/data/vcompliance/' + filesel
                try:
                    shutil.move(addpath(docold), addpath(docref))
                except:
                    err[4] = 'File has been moved already'
                try:
                    shutil.move(addtxt(docold), addtxt(docref))
                except:
                    err[4] = 'File has been moved already'

            else:
                docref = ''
                doctxt = ''

            subject = request.values.get('subject')
            category = request.values.get('category')
            item = request.values.get('item')
            longs = request.values.get('longs')
            datedue = request.values.get('date1')
            datefiled = request.values.get('date2')
            docsave = ntpath.basename(docref)

            if datedue == '':
                newdate1 = None
            else:
                newdate1 = datedue

            if datefiled == '':
                newdate2 = None
            else:
                newdate2 = datedue

            input = Compliance(Subject=subject,
                               Category=category,
                               Item=item,
                               Textinfo=longs,
                               File1=docsave,
                               File2=None,
                               File3=None,
                               Date1=newdate1,
                               Date2=newdate2)
            db.session.add(input)
            db.session.commit()
            db.session.close()

            odata = Compliance.query.all()

            modlink = 0
            leftscreen = 1
            oder = 0
            leftsize = 10
            err = ['All is well', ' ', ' ', ' ', ' ']
# ____________________________________________________________________________________________________________________E.Newjob.Compliance

        if modlink == 20:
            odata = Compliance.query.filter(
                (Compliance.Textinfo.contains(searchfind))
                | (Compliance.Subject.contains(searchfind))
                | (Compliance.Category.contains(searchfind))).all()

    #This is the else for 1st time through (not posting data from overseas.html)
    else:
        from viewfuncs import popjo, jovec, timedata, nonone, nononef, init_truck_zero
        today = datetime.date.today()
        #today = datetime.datetime.today().strftime('%Y-%m-%d')
        now = datetime.datetime.now().strftime('%I:%M %p')
        oder = 0
        cache = 0
        modata = 0
        modlink = 0
        fdata = 0
        filesel = ''
        docref = ''
        doctxt = ''
        longs = ''
        odata = Compliance.query.all()
        leftscreen = 1
        leftsize = 10
        err = ['All is well', ' ', ' ', ' ', ' ']
        actype = ''

    fdata = myoslist('data/vunknown')
    fdata.sort()
    doctxt = os.path.splitext(docref)[0] + '.txt'
    leftsize = 8
    acdata = []
    for adat in db.session.query(Compliance.Subject).distinct():
        acdata.append(adat.Subject)
    return odata, oder, err, modata, modlink, leftscreen, docref, leftsize, fdata, filesel, today, now, doctxt, longs, acdata, actype
예제 #4
0
파일: iso_B.py 프로젝트: markwnixon/class8
def isoB(indat):

    if request.method == 'POST':

        from viewfuncs import nonone, numcheck, newjo
        from viewfuncs import calendar7_weeks, txtfile, numcheckvec, d2s, erud, dataget_B, hv_capture, docuploader, get_def_bank
        from gledger_write import gledger_write, gledger_app_write

        # Initialize variables used in the python code that require a value
        username, bill, peep, cache, modata, modlink, fdata, adata, cdat, pb, passdata, vdata, caldays, daylist,\
        weeksum, nweeks, filesel, docref, doctxt, bType, bClass, expdata, addjobselect, jobdata, modal, viewck, acceptthese,\
        assdata, monlvec = var_start()

        divdat = Divisions.query.all()

        todaydt = datetime.datetime.today()
        today = todaydt.strftime('%Y-%m-%d')
        docref = ' '
        doctxt = ' '
        if indat == 'stay' or indat == 0: indat = '0'

        # Get all the variables appearing on the html page including button pushes
        match, vmod, modify2, viewo, addE, addE2, paybill, paybill2, unpay, printck, returnhit, deletehit, \
        update, modlink, newbill, thisbill, newxfer, thisxfer, calendar, calupdate, incoming, datatable1, \
        datatable2, copy, copy12, qpay, bill, cache, peep, uploadS, thismuch, vendmuch, thisbox0, thisbox1, thisbox2, \
        thisbox3, thisbox4, thisbox5, thisbox6 = var_request()

        modlink, bill, peep = nonone(modlink), nonone(bill), nonone(peep)
        dlist = [datatable1, datatable2]
        leftscreen = 0
        oid = 0

        # Get varibles that may be selected from the selection boxes and dont override the button pushes
        hv, newbill, addE, copy, copy12, UploadS, newxfer, vmod, match, acceptthese, qpay, paybill, paybill2, printck, \
        viewo, viewbill, viewck, deletehit, unpay, lbox, holdvec, err \
        = get_selections(thismuch, vendmuch, thisbox0, thisbox1, thisbox2, thisbox3, thisbox4, thisbox5, thisbox6,
                         newbill, vmod, paybill, printck)

        #Key variables may need to be altered based on the type of selection container in modlink:

        #modlink = 1 initial selection of an item to modify with update

        #modlink = 4 part of sequence in creating a new bill
        #modlink = 8 creating a new vendor during new bill process

        #modlink = 6 paying multiple bills with one check
        #modlink = 14 paying one bill with one check

        #after modification is started, if it is a bill and selection boxes are updated with onchange:
        #modlink = 7 modification to a bill for continuous modification until update button is used

        #modlink = 11 paying a bill
        #modlink = 12 quickpay (pay using default values)

        #modlink = 70 controls process of document uploading to establish a bill

        leftscreen = alterations(modlink, leftscreen)

        if returnhit is not None: modlink, leftscreen, indat = cleanup()
        # ____________________________________________________________________________________________________________________B.QuickBillPayTowing
        if incoming is not None: incoming_setup()
        # ____________________________________________________________________________________________________________________E.QuickBillPayTowing
        # ____________________________________________________________________________________________________________________B.Uploading

        if modlink == 4 and (newbill is None and thisbill is None
                             and update is None):
            modlink, err, bill, docref = uploadsource(modlink, err, oid,
                                                      docref, username)

        if modlink == 70:
            err, oid = docuploader('bill')
            modlink = 0
# ____________________________________________________________________________________________________________________E.Uploading
# ____________________________________________________________________________________________________________________B.UpdateDatabasesSection
        if (
                update is not None and modlink == 1
        ) or modlink == 8 or modlink == 7 or modlink == 6 or modlink == 11 or modlink == 12 or modlink == 14:
            success = 1
            if bill > 0:
                modata = Bills.query.get(bill)
                # if paying a bill there could be multiple link items to capture
                if modlink == 6:
                    try:
                        links = json.loads(modata.Link)
                    except:
                        links = 0
                    if links != 0:
                        bill = links[0]
                        modata = Bills.query.get(bill)

                #Modifying only the billing information (but getting the billing information if paying the bill
                if modlink == 7:
                    err, docref, expdata, assdata, leftscreen, modlink, hv = modbill(
                        bill, update, err, docref, expdata, assdata,
                        leftscreen, modlink, hv)

                cdat = People.query.filter(
                    People.Company == modata.Company).first()
                if cdat is not None:
                    if cdat.Ptype == 'TowCo': hv[3] = '2'
                ifxfer = modata.bType

                if ifxfer == 'XFER':
                    run_xfer(update, err)

                if modlink == 11 or modlink == 12 or modlink == 14:
                    err, hv, docref, modlink = run_paybill(
                        bill, update, err, hv, docref, username, modlink)

                if modal == 1:
                    calendar = 1
                    modlink = 0

            # create return status
            if update is not None and modlink != 6 and success:
                modlink = 0
                leftscreen = 1
                indat = '0'

        if modlink == 9 or modlink == 8:
            err, expdata, modlink, peep = modpeeps(peep, update, err, modlink,
                                                   expdata)
            modata = People.query.get(peep)
            print(modata.Company)
# _____________________________________________________________________________________________________________B.UpdateDatabasesSection

        bdata, cdata = dataget_B(hv[1], hv[0], hv[3])
        # ____________________________________________________________________________________________________________________B.SearchFilters
        if acceptthese == 1:
            print('acceptthese', acceptthese)
            modlink = 0
            # Check to see if these are all new jobs ready to be updated to ready status
            odervec = numcheckvec(bdata, 'bill')
            print(odervec)
            if len(odervec) > 0:
                for ix in odervec:
                    bdat = Bills.query.get(ix)
                    bdat.Temp2 = None
                db.session.commit()
            else:
                err.append('Must check at least one box to use this option')

        if modlink < 5:
            bill, peep, numchecked = numcheck(2, bdata, cdata, 0, 0, 0,
                                              ['bill', 'peep'])
        else:
            numchecked = 0

        if uploadS is not None:
            print('Using uploadS')
            if bill > 0 and numchecked == 1:
                bdat = Bills.query.get(bill)
                jo = bdat.Jo
                cache = bdat.Cache
                filename2 = f'Source_{jo}_c{str(cache)}.pdf'
                err.append(f'File uploaded as {filename2}')
                #Provide a file name for the upload and store message:
                edat = LastMessage.query.filter(
                    LastMessage.User == username).first()
                if edat is not None:
                    edat.Err = json.dumps(err)
                    db.session.commit()
                else:
                    input = LastMessage(User=username, Err=json.dumps(err))
                    db.session.add(input)
                    db.session.commit()

                modlink = 70
                leftscreen = 1
                mm3 = 0
            else:
                err.append('No Bill Selected for Source Upload')
                err.append('Select One Box')
# ____________________________________________________________________________________________________________________E.SearchFilters

# ____________________________________________________________________________________________________________________B.Viewers
        if viewo == 1 and numchecked == 1:
            if bill > 0:
                modata = Bills.query.get(bill)
                viewtype = 'source'
                hv[2] = viewtype
                if modata.Original is not None:
                    if len(modata.Original) > 5:
                        docref = f'tmp/{scac}/data/vbills/{modata.Original}'
                        leftscreen = 0
                        leftsize = 8
                        modlink = 0
                        err.append('Viewing document ' + docref)

        if viewo == 1 and numchecked != 1:
            err.append('Must check exactly one box to view source file')

        if viewck == 1 and numchecked == 1:
            if bill > 0:
                modata = Bills.query.get(bill)
                viewtype = 'check'
                hv[2] = viewtype
                if modata.Code1 is not None:
                    if len(modata.Code1) > 5:
                        docref = f'tmp/{scac}/data/vchecks/{modata.Code1}'
                        leftscreen = 0
                        leftsize = 8
                        modlink = 0
                        err.append('Viewing check ' + docref)

        if viewck == 1 and numchecked != 1:
            err.append('Must check exactly one box to view checks')

# ____________________________________________________________________________________________________________________E.Viewers
# ____________________________________________________________________________________________________________________B.Modify Entries
        if vmod is not None and numchecked == 1:
            modlink, leftscreen, docref, expdata, modata = mod_init(
                err, bill, peep)

        # Modification coming from calendar
        if modify2 is not None:
            bill = nonone(modify2)
            modata = Bills.query.get(bill)
            modlink = 7
            leftsize = 8

# ____________________________________________________________________________________________________________________E.Modify Entries
# ____________________________________________________________________________________________________________________B.Add Entries

        if addE is not None:
            leftsize = 8
            modlink = 9
            # Remove any new starts that were not completed
            People.query.filter(People.Ptype == 'NewVendor').delete()
            # We will create a blank line and simply modify that by updating:
            input = People(Company='',
                           First=None,
                           Middle=None,
                           Last=None,
                           Addr1='',
                           Addr2='',
                           Addr3='',
                           Idtype=None,
                           Idnumber='',
                           Telephone='',
                           Email='',
                           Associate1=None,
                           Associate2=None,
                           Date1=today,
                           Date2=None,
                           Original=None,
                           Ptype='NewVendor',
                           Temp1=None,
                           Temp2=None,
                           Accountid=None)
            db.session.add(input)
            db.session.commit()
            modata = People.query.filter(People.Ptype == 'NewVendor').first()
            peep = modata.id
            err.append('Enter Data for New Entity')
            expdata = Accounts.query.filter(
                Accounts.Type == 'Expense').order_by(Accounts.Name).all()

        if addE2 is not None:
            leftsize = 8
            modlink = 8
            # We will create a blank line and simply modify that by updating:
            hlist = hv_capture([
                'thiscomp', 'ctype', 'billacct', 'bamt', 'bdate', 'ddate',
                'bdesc'
            ])
            hv = hv[0:2] + hlist
            print(hv)
            # We will create a blank line and simply modify that by updating:
            input = People(Company='',
                           First=None,
                           Middle=None,
                           Last=None,
                           Addr1='',
                           Addr2='',
                           Addr3='',
                           Idtype=None,
                           Idnumber='',
                           Telephone='',
                           Email='',
                           Associate1=None,
                           Associate2=None,
                           Date1=today,
                           Date2=None,
                           Original=None,
                           Ptype='NewVendor',
                           Temp1=None,
                           Temp2=None,
                           Accountid=None)
            db.session.add(input)
            db.session.commit()
            modata = People.query.filter(People.Ptype == 'NewVendor').first()
            peep = modata.id
            err.append('Enter Data for New Entity')
            expdata = Accounts.query.filter(
                Accounts.Type == 'Expense').order_by(Accounts.Name).all()

# ____________________________________________________________________________________________________________________E.Add Entries

# ____________________________________________________________________________________________________________________B.Delete an Entry
        if deletehit is not None and numchecked >= 1:
            if bill > 0:
                bdat = Bills.query.get(bill)
                try:
                    orderid = nonone(bdat.Temp2)
                    adat = Autos.query.get(orderid)
                    if adat is not None:
                        adata = Autos.query.filter(
                            Autos.Orderid == adat.Orderid).all()
                        for dat in adata:
                            dat.Status = 'Novo'
                except:
                    err.append('Delete problem')
                jo = bdat.Jo
                Gledger.query.filter(Gledger.Tcode == jo).delete()
                Bills.query.filter(Bills.id == bill).delete()
                db.session.commit()
            if peep > 0:
                peepvec = numcheckvec(cdata, 'peep')
                for peep in peepvec:
                    People.query.filter(People.id == peep).delete()
                    db.session.commit()

            bdata = Bills.query.order_by(Bills.bDate).all()
            cdata = People.query.filter((People.Ptype == 'Vendor')
                                        | (People.Ptype == 'TowCo')).order_by(
                                            People.Company).all()

        if deletehit is not None and numchecked == 0:
            err.append(
                'Must have at least one item checked to use this option')
# ____________________________________________________________________________________________________________________E.Delete an Entry
# ____________________________________________________________________________________________________________________B.NewXfer.Billing
        if newxfer == 1:
            modlink = 3
            err.append('Select Source Document from List')
            leftscreen = 0
            expdata = Accounts.query.filter(
                (Accounts.Type != 'Expense') & (Accounts.Type != 'Income')
                & (~Accounts.Type.contains('Accounts'))).order_by(
                    Accounts.Name).all()
            vdata = [today, today, '', '']

        if newxfer is None and modlink == 3:

            leftscreen = 0
            bdate = request.values.get('bdate')
            ddate = request.values.get('bdate')
            xamt = request.values.get('xamt')
            new_desc = request.values.get('desc')
            xferfrom = request.values.get('fromacct')
            xferto = request.values.get('toacct')
            if xamt is None:
                xamt = '0.00'
            vdata = [bdate, ddate, xamt, new_desc, xferfrom, xferto]
            print(vdata)
            expdata = Accounts.query.filter(
                (Accounts.Type != 'Expense') & (Accounts.Type != 'Income')
                & (~Accounts.Type.contains('Accounts'))).order_by(
                    Accounts.Name).all()

        if thisxfer is not None:
            modlink = 0

            sdate = request.values.get('bdate')
            if sdate is None or sdate == '':
                sdate = today

            fromacct = request.values.get('fromacct')
            toacct = request.values.get('toacct')
            adat = Accounts.query.filter(Accounts.Name == toacct).first()
            if adat is not None:
                cat = adat.Category
                sub = adat.Subcategory
            else:
                cat = None
                sub = None
            xamt = request.values.get('xamt')
            xamt = d2s(xamt)
            xdesc = request.values.get('xdesc')
            btype = 'XFER'
            nextjo = newjo(billxfrcode, today)
            co = nextjo[0]

            input = Bills(Jo=nextjo,
                          Pid=0,
                          Company=toacct,
                          Memo=None,
                          Description=xdesc,
                          bAmount=xamt,
                          Status='Paid',
                          Cache=0,
                          Original=None,
                          Ref=None,
                          bDate=sdate,
                          pDate=sdate,
                          pAmount=xamt,
                          pMulti=None,
                          pAccount=fromacct,
                          bAccount=toacct,
                          bType=btype,
                          bCat=cat,
                          bSubcat=sub,
                          Link=None,
                          User=username,
                          Co=co,
                          Temp1=None,
                          Temp2=None,
                          Recurring=0,
                          dDate=today,
                          pAmount2='0.00',
                          pDate2=None,
                          Code1=None,
                          Code2=None,
                          CkCache=0,
                          QBi=0,
                          iflag=0,
                          PmtList=None,
                          PacctList=None,
                          RefList=None,
                          MemoList=None,
                          PdateList=None,
                          CheckList=None,
                          MethList=None)

            db.session.add(input)
            db.session.commit()

            modata = Bills.query.filter(Bills.Jo == nextjo).first()
            err = gledger_write('xfer', nextjo, toacct, fromacct)
            bill = modata.id
            leftscreen = 1
            err.append('All is well')
            bdata = Bills.query.order_by(Bills.bDate).all()
        # ____________________________________________________________________________________________________________________E.NewXfer.Billing
        if copy == 1:
            if bill > 0 and numchecked == 1:
                # sdate=today.strftime('%Y-%m-%d')
                bdat = Bills.query.get(bill)
                thisdate = bdat.bDate
                nextdate = thisdate + datetime.timedelta(days=30)
                nextjo = newjo(billexpcode, today)
                input = Bills(Jo=nextjo,
                              Pid=bdat.Pid,
                              Company=bdat.Company,
                              Memo=bdat.Memo,
                              Description=bdat.Description,
                              bAmount=bdat.bAmount,
                              Status=bdat.Status,
                              Cache=0,
                              Original=bdat.Original,
                              Ref=bdat.Ref,
                              bDate=nextdate,
                              pDate=None,
                              pAmount='0.00',
                              pMulti=None,
                              pAccount=bdat.pAccount,
                              bAccount=bdat.bAccount,
                              bType=bdat.bType,
                              bCat=bdat.bCat,
                              bSubcat=bdat.bSubcat,
                              Link=None,
                              User=username,
                              Co=bdat.Co,
                              Temp1=None,
                              Temp2='Copy',
                              Recurring=0,
                              dDate=today,
                              pAmount2='0.00',
                              pDate2=None,
                              Code1=None,
                              Code2=None,
                              CkCache=0,
                              QBi=0,
                              iflag=0,
                              PmtList=None,
                              PacctList=None,
                              RefList=None,
                              MemoList=None,
                              PdateList=None,
                              CheckList=None,
                              MethList=None)
                db.session.add(input)
                db.session.commit()

                err = gledger_write('newbill', nextjo, bdat.bAccount,
                                    bdat.pAccount)

            elif peep > 0 and numchecked == 1:
                # sdate=today.strftime('%Y-%m-%d')
                pdat = People.query.get(peep)
                input = People(Company=pdat.Company,
                               First=pdat.First,
                               Middle='Copy',
                               Last=None,
                               Addr1=pdat.Addr1,
                               Addr2=pdat.Addr2,
                               Addr3=pdat.Addr3,
                               Idtype=pdat.Idtype,
                               Idnumber=pdat.Idnumber,
                               Telephone=pdat.Telephone,
                               Email=pdat.Email,
                               Associate1=pdat.Associate1,
                               Associate2=pdat.Associate2,
                               Date1=today,
                               Date2=None,
                               Original=None,
                               Ptype='Vendor',
                               Temp1=pdat.Temp1,
                               Temp2=pdat.Temp2,
                               Accountid=pdat.Accountid)
                db.session.add(input)
                db.session.commit()

            else:
                err.append('Must select one item to use this function')

        if copy12 is not None:
            if bill > 0 and numchecked == 1:
                # sdate=today.strftime('%Y-%m-%d')
                bdat = Bills.query.get(bill)
                thisdate = bdat.bDate
                year = thisdate.year
                month = thisdate.month
                day = thisdate.day
                while month < 12:
                    month = month + 1
                    nextdate = datetime.datetime(year, month, day)
                    nextjo = newjo(billexptype, today)
                    input = Bills(Jo=nextjo,
                                  Pid=bdat.Pid,
                                  Company=bdat.Company,
                                  Memo=bdat.Memo,
                                  Description=bdat.Description,
                                  bAmount=bdat.bAmount,
                                  Status=bdat.Status,
                                  Cache=0,
                                  Original=bdat.Original,
                                  Ref=bdat.Ref,
                                  bDate=nextdate,
                                  pDate=None,
                                  pAmount='0.00',
                                  pMulti=None,
                                  pAccount=bdat.pAccount,
                                  bAccount=bdat.bAccount,
                                  bType=bdat.bType,
                                  bCat=bdat.bCat,
                                  bSubcat=bdat.bSubcat,
                                  Link=None,
                                  User=username,
                                  Co=bdat.Co,
                                  Temp1=None,
                                  Temp2='Copy',
                                  Recurring=0,
                                  dDate=today,
                                  pAmount2='0.00',
                                  pDate2=None,
                                  Code1=None,
                                  Code2=None,
                                  CkCache=0,
                                  QBi=0,
                                  iflag=0,
                                  PmtList=None,
                                  PacctList=None,
                                  RefList=None,
                                  MemoList=None,
                                  PdateList=None,
                                  CheckList=None,
                                  MethList=None)
                    db.session.add(input)
                    db.session.commit()

                    err = gledger_write('newbill', nextjo, bdat.bAccount,
                                        bdat.pAccount)

        if qpay is not None:
            if bill > 0 and numchecked == 1:
                print('qpay entered!!')
                bdat = Bills.query.get(bill)
                bdat.pDate = bdat.bDate
                bdat.pAmount = bdat.bAmount
                bdat.Temp2 = ''
                bdat.Status = 'Paid'
                pacct = bdat.pAccount
                if pacct is None:
                    pacct = get_def_bank(bdat)
                elif pacct == '0' or pacct == '1' or pacct == 0 or pacct == 1:
                    pacct = get_def_bank(bdat)
                bdat.pAccount = pacct
                db.session.commit()

# ____________________________________________________________________________________________________________________B.NewJob
        if newbill is not None:
            err, modlink, leftscreen, hv, expdata, vdata = newbill_init(
                err, hv)

        if newbill is None and modlink == 4:
            err, modlink, leftscreen, hv, expdata, vdata, assdata = newbill_passthru(
                err, hv, modlink)

        if thisbill is not None:
            err, modlink, leftscreen, bill = newbill_update(
                err, hv, modlink, username)
            bdata = Bills.query.order_by(Bills.bDate).all()
# ____________________________________________________________________________________________________________________E.New Bill
        if unpay == 1:
            if numchecked == 1 and bill > 0:
                myb = Bills.query.get(bill)
                iflag = myb.iflag
                if iflag is None: iflag = 0
                if iflag > 0:
                    undolastpayment(bill)
                    err.append(
                        f'Unpaid Last Payment on Bill {myb.Jo} and removed from register'
                    )
                else:
                    myb.Status = 'Unpaid'
                    myb.pAmount = '0.00'
                    db.session.commit()
                    Gledger.query.filter((Gledger.Tcode == myb.Jo)
                                         & (Gledger.Type == 'PD')).delete()
                    Gledger.query.filter((Gledger.Tcode == myb.Jo)
                                         & (Gledger.Type == 'PC')).delete()
                    Gledger.query.filter((Gledger.Tcode == myb.Jo)
                                         & (Gledger.Type == 'XD')).delete()
                    Gledger.query.filter((Gledger.Tcode == myb.Jo)
                                         & (Gledger.Type == 'XC')).delete()
                    db.session.commit()
                    err.append(f'Unpay Bill {myb.Jo} and remove from register')
            else:
                err.append('Must select one Bill to Unpay')

        if paybill is not None or paybill2 is not None or viewbill == 1:
            print('paybill', numchecked, modlink, bill)
            if numchecked == 1 and bill > 0:
                myb = Bills.query.get(bill)
                if viewbill == 1 and myb.Status == 'Paid': modlink = 15

                if myb.iflag is None: myb.iflag = 0
                if myb.iflag > 0:
                    err, modlink, leftscreen, docref, prevpayvec = install_pay_init(
                        bill, err, modlink)
                    hv[19] = prevpayvec
                else:
                    err, modlink, leftscreen, docref = pay_init(
                        bill, err, modlink)
                modata = Bills.query.get(bill)

            if numchecked > 1 and bill > 0:
                err, modlink, lefscreen, docref = multi_pay_init(
                    bill, err, modlink)
                modata = Bills.query.get(bill)

            if numchecked == 0 or bill == 0:
                err.append('Must check at least one bill for this selection')
                err.append(f'Numchecked = {numchecked}')

            bdata = Bills.query.order_by(Bills.bDate).all()

        if printck is not None or modlink == 6 or modlink == 14 or indat != '0':
            from viewfuncs import check_prep

            def multi_prep(bill):
                if bdat.Status == 'Paid-M':
                    linkcode = bdat.Link
                    sbdata = Bills.query.filter(Bills.Link == linkcode)
                    link = linkcode.replace('Link+', '')
                    items = link.split('+')
                    links = []
                    [links.append(int(item)) for item in items]
                else:
                    links = 0
                    sbdata = 0

            if printck is not None and numchecked == 1:
                modlink = 14
            elif printck is not None and numchecked > 1:
                modlink = 6

            if indat != '0':
                bdat = Bills.query.filter(Bills.Jo == indat).first()
                bill = bdat.id
                modlink = 6
                if numchecked == 1: modlink = 14

            if (numchecked >= 1 and bill > 0
                ) or modlink == 6 or modlink == 12 or modlink == 14:

                if modlink == 6 or modlink == 12 or modlink == 14:
                    bdat = Bills.query.get(bill)
                    try:
                        bill_list = json.loads(bdat.Link)
                    except:
                        bill_list = [bill]
                    billready, err, linkcode = check_prep(bill_list)

                else:
                    bill_list = numcheckvec(bdata, 'bill')
                    billready, err, linkcode = check_prep(bill_list)

                if billready == 1:
                    from viewfuncs import check_inputs
                    sbdata = Bills.query.filter(Bills.Link == linkcode).all()
                    links = json.loads(linkcode)
                    bdat = Bills.query.get(links[0])
                    pdat = People.query.get(bdat.Pid)

                    ckcache = bdat.CkCache
                    if ckcache is None or ckcache == 0:
                        ckcache = 1
                    last_ckfile = f'Check_{bdat.Jo}_{bdat.Ref}_c{str(ckcache-1)}.pdf'
                    ckfile = f'Check_{bdat.Jo}_{bdat.Ref}_c{str(ckcache)}.pdf'
                    docref = f'tmp/{scac}/data/vchecks/{ckfile}'
                    bdat.Code1 = ckfile
                    ckcache = ckcache + 1
                    bdat.CkCache = ckcache
                    pamount = bdat.pAmount
                    if pamount == '0.00':
                        bdat.pAmount = bdat.bAmount
                    db.session.commit()

                    ckstyle = request.values.get('ckstyle')
                    if ckstyle is not None:
                        hv[21] = ckstyle
                        ckstyle = nonone(ckstyle)
                    else:
                        ckstyle = 1

                    err = check_inputs(bill_list)
                    co = bdat.Co
                    expdata = Accounts.query.filter((
                        (Accounts.Type == 'Expense') & (Accounts.Co == co)) | (
                            (Accounts.Type == 'Credit Card')
                            & (Accounts.Co == co))).order_by(
                                Accounts.Name).all()
                    #modlink = 6
                    leftscreen = 0
                    modata = Bills.query.get(links[0])
                    pb = 1
                    if err[0] != 'All is Well':
                        err.append(
                            'Check will not be displayed until above input items input or corrected'
                        )

                    else:
                        from writechecks import writechecks
                        if pdat is not None:
                            writechecks(bdat, pdat, docref, sbdata, links,
                                        ckstyle)

                            ck_check = bdat.bType

                            db.session.commit()
                            pacct = bdat.pAccount
                            #Only write to the ledger on update
                            if update is not None:
                                if pacct is not None and pacct != '0':
                                    print('check is', ck_check)
                                    if ck_check == 'Credit Card' or ck_check == 'XFER':
                                        print('Doing the Transfer')
                                        err = err = gledger_write(
                                            'xfer', bdat.Jo, bdat.bAccount,
                                            bdat.pAccount)
                                        err.append(
                                            f'Ledger xfer for {bdat.Jo} to {bdat.bAccount} from {bdat.pAccount}'
                                        )
                                    else:
                                        print('Paying the Bill')
                                        err = gledger_write(
                                            'paybill', bdat.Jo, bdat.bAccount,
                                            bdat.pAccount)
                                        err.append(
                                            f'Ledger paid {bdat.Jo} to {bdat.bAccount} from {bdat.pAccount}'
                                        )
                                else:
                                    err.append(
                                        'No Account for Fund Withdrawal')

                        #Attempt to remove the previous cache copy:
                        try:
                            last_file = addpath(
                                f'tmp/{scac}/data/vchecks/{last_ckfile}')
                            os.remove(last_file)
                        except:
                            print(f'Could nor remove {last_file}')

            else:
                err.append(
                    'Must select exactly 1 Bill box to use this option.')

# ____________________________________________________________________________________________________________________B.Matching
        if match is not None:
            if bill > 0 and peep > 0 and numchecked == 2:
                myo = Bills.query.get(bill)
                myp = People.query.get(peep)
                myo.Pid = peep
                myo.Company = myp.Company
                myo.Description = myp.Associate1
                db.session.commit()
            if numchecked != 2:
                err.append('Must select exactly 2 boxes to use this option.')
# ____________________________________________________________________________________________________________________E.Matching
# ____________________________________________________________________________________________________________________B.Calendar.Billing
        if calendar is not None or calupdate is not None:
            leftscreen = 2
            if calupdate is not None:
                waft = request.values.get('waft')
                wbef = request.values.get('wbef')
                waft = nonone(waft)
                wbef = nonone(wbef)
                nweeks = [wbef, waft]
            else:
                nweeks = [2, 2]
            caldays, daylist, weeksum = calendar7_weeks('Billing', nweeks)

            if calupdate is not None:
                for j in range(len(daylist)):
                    ilist = daylist[j]
                    if ilist:
                        tid = ilist[0]
                        fnum = 'note' + str(tid)
                        fput = request.values.get(fnum)
                        if len(fput) > 3:
                            billno = f'{scac}_Bill_{str(tid)}'
                            input = ChalkBoard(Jo=billno,
                                               creator=username,
                                               comments=fput,
                                               status=1)
                            db.session.add(input)
                            db.session.commit()

                caldays, daylist, weeksum = calendar7_weeks('Billing', nweeks)
# ____________________________________________________________________________________________________________________E.Calendar.Billing

        if (modlink > 0 and bill > 0) or (modlink > 0
                                          and peep > 0) or leftscreen == 0:
            leftsize = 8
        elif leftscreen == 2:
            leftsize = 10
        else:
            leftsize = 10
    else:
        username, bill, peep, cache, modata, modlink, fdata, adata, cdat, pb, passdata, vdata, caldays, daylist,\
        weeksum, nweeks, filesel, docref, doctxt, bType, bClass, expdata, addjobselect, jobdata, modal, viewck, acceptthese,\
        assdata, monlvec = var_start()
        err = []
        hv = [0] * 25
        hv[0] = 'X'
        hv[1] = '1'
        from viewfuncs import nonone, erud, dataget_B
        leftscreen = 1
        leftsize = 10
        addjobselect = 0
        dlist = ['on'] * 2
        dlist[1] = 'off'
        jobdata = 0
        modal = 0
        expdata = 0
        assdata = [0]
        divdat = Divisions.query.all()
        err.append('All is well')

    leftsize = 8
    rightsize = 12 - leftsize
    today = datetime.date.today()
    critday = datetime.date.today() + datetime.timedelta(days=7)
    bdata, cdata = dataget_B(hv[1], hv[0], hv[3])
    hv[23] = assdata
    acdata = Accounts.query.filter(
        (Accounts.Type == 'Bank') | (Accounts.Type == 'Credit Card')
        | (Accounts.Type == 'Current Liability')).order_by(
            Accounts.Name).all()
    err = erud(err)
    if expdata == 0:
        expdata = Accounts.query.filter(Accounts.Type == 'Expense').order_by(
            Accounts.Name).all()

    return username, divdat, hv, bdata, cdata, bill, peep, err, modata, adata, acdata, expdata, modlink, caldays, daylist, weeksum, nweeks, addjobselect, jobdata, modal, dlist, fdata, today, cdat, pb, critday, vdata, leftscreen, docref, doctxt, leftsize, cache, filesel
예제 #5
0
def isoBank():

    if request.method == 'POST':
        # ____________________________________________________________________________________________________________________B.FormVariables.General

        from viewfuncs import parseline, popjo, jovec, newjo, timedata, nonone, nononef, enter_bk_charges
        from viewfuncs import numcheck, numcheckv, viewbuttons, get_ints, numcheckvec, numcheckv, d2s, erud

        today = datetime.date.today()
        today_str = today.strftime('%Y-%m-%d')
        hv = [0] * 9

        #Zero and blank items for default
        username = session['username'].capitalize()
        cache = request.values.get('cache')
        cache = nonone(cache)

        modata = 0
        modlink = 0
        docref = ''
        oderstring = ''
        acname = request.values.get('acname')

        today = datetime.date.today()
        now = datetime.datetime.now().strftime('%I:%M %p')
        err = []

        leftsize = 10

        match = request.values.get('Match')
        modify = request.values.get('Qmod')
        vmod = request.values.get('Vmod')
        viewo = request.values.get('View')
        returnhit = request.values.get('Return')
        deletehit = request.values.get('Delete')
        delfile = request.values.get('DELF')
        # hidden values
        update = request.values.get('Update')
        newact = request.values.get('NewA')
        thisjob = request.values.get('ThisJob')
        oder = request.values.get('oder')
        modlink = request.values.get('modlink')
        depositmake = request.values.get('depositmake')
        recdeposit = request.values.get('recdeposit')
        unrecord = request.values.get('unrecord')
        thismuch = request.values.get('thismuch')
        recothese = request.values.get('recothese')
        finalize = request.values.get('finalize')
        undothese = request.values.get('undothese')
        rdate = request.values.get('rdate')
        if rdate is None:
            rdate = today_str
        hv[0] = rdate
        hv[1] = [0]
        endbal = request.values.get('endbal')
        begbal = request.values.get('begbal')
        recready = 1
        try:
            endbal = float(endbal)
        except:
            endbal = 0.00
            err.append('No Statement Balance Entered for Reconciliation')
            recready = 0
        try:
            begbal = float(begbal)
        except:
            endbal = 0.00
            err.append('No Statement Ending Entered for Reconciliation')
            recready = 0

        oder = nonone(oder)
        modlink = nonone(modlink)

        leftscreen = 1
        err = ['All is well', ' ', ' ', ' ', ' ']

        if returnhit is not None:
            modlink = 0
            depojo = 0

# ____________________________________________________________________________________________________________________E.FormVariables.General
# ____________________________________________________________________________________________________________________B.DataUpdates.General

        if modlink == 1:
            if oder > 0:
                modata = Income.query.get(oder)
                vals = [
                    'jo', 'subjo', 'pid', 'description', 'amount', 'ref',
                    'pdate', 'original'
                ]
                a = list(range(len(vals)))
                for i, v in enumerate(vals):
                    a[i] = request.values.get(v)

                modata.Jo = a[0]
                modata.Account = a[1]
                modata.Pid = a[2]
                modata.Description = a[3]
                modata.Amount = a[4]
                modata.Ref = a[5]
                modata.Date = a[6]
                modata.Original = a[7]
                db.session.commit()
                err[3] = 'Modification to Income id ' + str(
                    modata.id) + ' completed.'
                if update is not None:
                    modlink = 0
                    leftsize = 10
                else:
                    leftsize = 6
                    leftscreen = 0
                    modata = Income.query.get(oder)

# ____________________________________________________________________________________________________________________B.GetData.General
#odata = Income.query.all()
        print('acname=', acname)
        odata = dataget_Bank(thismuch, acname)
        acctinfo = banktotals(acname)
        # ____________________________________________________________________________________________________________________B.Search.General

        if modlink == 0:
            oder, numchecked = numcheck(1, odata, 0, 0, 0, 0, ['oder'])

# ____________________________________________________________________________________________________________________E.Search.General
        if (recothese is not None or finalize is not None) and recready == 1:

            if numchecked > -1:

                reset_trial(0)
                #Get date of reconciliation and bank charges for month
                rdate = request.values.get('rdate')
                recdate = datetime.datetime.strptime(rdate, "%Y-%m-%d")
                recmo = recdate.month
                #if recothese is not None: recmo = 25 #Do not record month until reconciliation final
                bkcharges = request.values.get('bkcharges')
                bkcharges = d2s(bkcharges)
                bkchargeid = 0
                try:
                    bkf = float(bkcharges)
                    print('bkf=', bkf)
                    if bkf > 0.0:
                        bank_jo = enter_bk_charges(acname, bkcharges, rdate,
                                                   username)
                        gdat = Gledger.query.filter(
                            (Gledger.Tcode == bank_jo)
                            & (Gledger.Type == 'PC')).first()
                        if gdat is not None:
                            bkchargeid = gdat.id
                except:
                    bkf = 0.00

                odervec = numcheckv(odata)
                print('bkid=', bkchargeid)
                if bkchargeid > 0 and bkchargeid not in odervec:
                    odervec.append(bkchargeid)
                hv[1] = odervec
                print('hv[1]', hv[1])
                for oder in odervec:
                    gdat = Gledger.query.get(oder)
                    gdat.Reconciled = 25
                db.session.commit()
                acctinfo = banktotals(acname)
                hv[2], hv[3], hv[4], dlist, wlist = recon_totals(acname)
                print(hv[2], hv[3])
                odata = dataget_Bank(thismuch, acname)

                if finalize is not None:
                    reset_trial(recmo)
                    hv[1] = [0]
                    rdat = Reconciliations.query.filter(
                        (Reconciliations.Rdate == hv[0])
                        & (Reconciliations.Account == acname)).first()
                    try:
                        dlists = json.dumps(dlist)
                    except:
                        dlists = None
                    try:
                        wlists = json.dumps(wlist)
                    except:
                        wlists = None
                    if rdat is None:
                        input = Reconciliations(Account=acname,
                                                Rdate=hv[0],
                                                Bbal=acctinfo[9],
                                                Ebal=acctinfo[4],
                                                Deposits=hv[2],
                                                Withdraws=hv[3],
                                                Servicefees=hv[4],
                                                DepositList=dlists,
                                                WithdrawList=wlists,
                                                Status=1,
                                                Diff=acctinfo[5])
                        db.session.add(input)
                        db.session.commit()
                    else:
                        print('diff', acctinfo[5])
                        rdat.Account = acname
                        rdat.Bbal = acctinfo[9]
                        rdat.Ebal = acctinfo[4]
                        rdat.Servicefees = hv[4]
                        rdat.Deposits = hv[2]
                        rdat.Withdraws = hv[3]
                        rdat.DepositList = dlists
                        rdat.WithdrawList = wlists
                        rdat.Status = 1
                        rdat.Rdate = hv[0]
                        rdat.Diff = acctinfo[5]
                        db.session.commit()
                    err.append(
                        f'Reconciliation data saved for Account {acname} Date: {hv[0]}'
                    )

            else:
                err.append('No items checked for reconciliation')

        if undothese is not None:

            odervec = numcheckv(odata)
            for oder in odervec:
                gdat = Gledger.query.get(oder)
                gdat.Reconciled = 0
                db.session.commit()
                acctinfo = banktotals(acname)
# ____________________________________________________________________________________________________________________B.Modify.General
        if (modify is not None or vmod is not None) and numchecked == 1:
            modlink = 1
            leftsize = 6
            if vmod is not None:
                leftscreen = 0

            if oder > 0:
                modata = Income.query.get(oder)
                docref = modata.Original

        if (modify is not None or vmod is not None) and numchecked != 1:
            modlink = 0
            err[0] = ' '
            err[2] = 'Must check exactly one box to use this option'
# ____________________________________________________________________________________________________________________E.Modify.General

# ____________________________________________________________________________________________________________________B.Delete.General
        if deletehit is not None and numchecked == 1:
            if oder > 0:
                #This section is to determine if we can delete the source file along with the data.  If other data is pointing to this
                #file then we need to keep it.
                modata = Income.query.get(oder)

                Income.query.filter(Income.id == oder).delete()
                db.session.commit()

        if deletehit is not None and numchecked != 1:
            err = [
                ' ', ' ',
                'Must have exactly one item checked to use this option', ' ',
                ' '
            ]

# ____________________________________________________________________________________________________________________E.Delete.General
        if (depositmake is not None
                or recdeposit is not None) and depojo is not None:
            err = [
                'Must have exactly one item checked to use this option', ' ',
                ' '
            ]

            odervec = numcheckv(odata)
            if len(odervec) > 0:
                oderstring = json.dumps(odervec)
            else:
                udat = users.query.filter(users.name == 'cache').first()
                oderstring = udat.email
                odervec = json.loads(oderstring)

            if odervec is not None:
                cache = request.values.get('cache')
                if cache is None:
                    cache = 2

                if recdeposit is not None:
                    cache, docref = reportmaker('recdeposit', odervec)
                    for oder in odervec:
                        idat = Income.query.get(oder)
                        subjo = idat.SubJo
                        ref = idat.Ref
                        idata = Income.query.filter((Income.SubJo == subjo) &
                                                    (Income.Ref == ref)).all()
                        for data in idata:
                            data.SubJo = depojo
                            db.session.commit()

                    from gledger_write import gledger_write
                    gledger_write('deposit', depojo, acctsel, 0)

                else:
                    cache, docref = reportmaker('deposit', odervec)

                leftscreen = 0

        if viewo is not None and numchecked == 1:
            if oder > 0:
                modata = Income.query.get(oder)
                depojo = modata.SubJo
                docref = f'tmp/{scac}/data/vdeposits/' + depojo + '.pdf'
                leftscreen = 0

        if unrecord is not None and numchecked != 1:
            modlink = 0
            err[0] = ' '
            err[2] = 'Must check exactly one box to use this option'

        if cache is not None:
            #Save the current cache so we do not start from bad place in future
            udat = users.query.filter(users.name == 'cache').first()
            udat.username = str(cache)
            udat.email = oderstring
            db.session.commit()

    #This is the else for 1st time through (not posting data from overseas.html)
    else:
        from viewfuncs import popjo, jovec, timedata, nonone, nononef, init_truck_zero, d2s, erud
        today = datetime.date.today()
        today_str = today.strftime('%Y-%m-%d')
        hv = [0] * 9
        hv[0] = today_str
        hv[1] = [0]
        now = datetime.datetime.now().strftime('%I:%M %p')
        reset_trial(0)
        oder = 0
        modata = 0
        modlink = 0
        odata = Income.query.all()
        leftscreen = 1
        leftsize = 10
        docref = ''
        err = ['All is well', ' ', ' ', ' ', ' ']
        thismuch = '1'
        udat = users.query.filter(users.name == 'Cache').first()
        cache = udat.username
        cache = nonone(cache)
        adat = Accounts.query.filter(Accounts.Type == 'Bank').first()
        bankacct = adat.Name
        acctinfo = banktotals(bankacct)
        odata = dataget_Bank(thismuch, bankacct)

    leftsize = 8
    acdata = Accounts.query.filter(Accounts.Type == 'Bank').all()
    err = erud(err)

    return odata, oder, err, modata, modlink, leftscreen, leftsize, today, now, docref, cache, acdata, thismuch, acctinfo, hv
예제 #6
0
def isoInvM():

    if request.method == 'POST':
        # ____________________________________________________________________________________________________________________B.FormVariables.General

        from viewfuncs import parseline, popjo, jovec, newjo, timedata, nonone, nononef
        from viewfuncs import numcheck, numcheckv, viewbuttons, get_ints, numcheckvec

        # Zero and blank items for default
        username = session['username'].capitalize()
        cache = 0
        modata = 0
        modlink = 0
        docref = ''

        today = datetime.date.today()
        now = datetime.datetime.now().strftime('%I:%M %p')

        leftsize = 10

        match = request.values.get('Match')
        modify = request.values.get('Qmod')
        vmod = request.values.get('Vmod')
        viewo = request.values.get('ViewO')
        returnhit = request.values.get('Return')
        deletehit = request.values.get('Delete')
        delfile = request.values.get('DELF')
        # hidden values
        update = request.values.get('Update')
        newact = request.values.get('NewA')
        thisjob = request.values.get('ThisJob')
        oder = request.values.get('oder')
        modlink = request.values.get('modlink')

        oder = nonone(oder)
        modlink = nonone(modlink)

        leftscreen = 1
        err = ['All is well', ' ', ' ', ' ', ' ']

        if returnhit is not None:
            modlink = 0

# ____________________________________________________________________________________________________________________E.FormVariables.General
# ____________________________________________________________________________________________________________________B.DataUpdates.General

        if modlink == 1:
            if oder > 0:
                modata = Invoices.query.get(oder)
                vals = [
                    'jo', 'subjo', 'pid', 'service', 'description', 'each',
                    'qty', 'amount', 'total', 'idate', 'original', 'status'
                ]
                a = list(range(len(vals)))
                for i, v in enumerate(vals):
                    a[i] = request.values.get(v)

                modata.Jo = a[0]
                modata.Subjo = a[1]
                modata.Pid = a[2]
                modata.Service = a[3]
                modata.Description = a[4]
                modata.Ea = a[5]
                modata.Qty = a[6]
                modata.Amount = a[7]
                modata.Total = a[8]
                modata.Date = a[9]
                modata.Original = a[10]
                modata.Status = a[11]
                db.session.commit()

                updateinvo(modata.Jo, modata.Date)

                err[3] = 'Modification to Invoices id ' + str(
                    modata.id) + ' completed.'
                # if update is not None:
                #modlink = 0
                #leftsize = 10
                # else:
                leftsize = 6
                leftscreen = 0
                modata = Invoices.query.get(oder)
                fname = os.path.basename(modata.Original)
                docref = tpath('invo', fname)

# ____________________________________________________________________________________________________________________B.GetData.General
        odata = Invoices.query.all()
        # ____________________________________________________________________________________________________________________B.Search.General

        if modlink == 0:
            oder, numchecked = numcheck(1, odata, 0, 0, 0, 0, ['oder'])

# ____________________________________________________________________________________________________________________E.Search.General

# ____________________________________________________________________________________________________________________B.Modify.General
        if (modify is not None or vmod is not None) and numchecked == 1:
            modlink = 1
            leftsize = 6
            if vmod is not None:
                leftscreen = 0

            if oder > 0:
                modata = Invoices.query.get(oder)
                if modata.Original is not None:
                    fname = os.path.basename(modata.Original)
                else:
                    fname = ''
                print('oder=', oder)
                print('jo=', modata.Jo)
                print('fname=', fname)

                # print('fname=',modata.Original)
                # fname=os.path.basename(modata.Original)

                docref = tpath('invo', fname)

        if (modify is not None or vmod is not None) and numchecked != 1:
            modlink = 0
            err[0] = ' '
            err[2] = 'Must check exactly one box to use this option'
# ____________________________________________________________________________________________________________________E.Modify.General

# ____________________________________________________________________________________________________________________B.Delete.General
        if deletehit is not None and numchecked >= 1:
            oderlist = numcheckv(odata)
            for oder in oderlist:
                modata = Invoices.query.get(oder)
                jo = modata.Jo
                Invoices.query.filter(Invoices.id == oder).delete()
                db.session.commit()
                updateinvo(jo, modata.Date)
            odata = Invoices.query.all()
        if deletehit is not None and numchecked != 1:
            err = [
                ' ', ' ',
                'Must have exactly one item checked to use this option', ' ',
                ' '
            ]
# ____________________________________________________________________________________________________________________E.Delete.General

# This is the else for 1st time through (not posting data from overseas.html)
    else:
        from viewfuncs import popjo, jovec, timedata, nonone, nononef, init_truck_zero
        today = datetime.date.today()
        #today = datetime.datetime.today().strftime('%Y-%m-%d')
        now = datetime.datetime.now().strftime('%I:%M %p')
        oder = 0
        cache = 0
        modata = 0
        modlink = 0
        odata = Invoices.query.all()
        leftscreen = 1
        leftsize = 10
        docref = ''
        err = ['All is well', ' ', ' ', ' ', ' ']
    leftsize = 8

    return odata, oder, err, modata, modlink, leftscreen, leftsize, today, now, docref
예제 #7
0
def reportmaker(type,thiscomp):

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

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

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

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

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

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

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

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

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

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


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

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

    return cache,docref
예제 #8
0
파일: iso_Q.py 프로젝트: markwnixon/class8
def isoQuote():
    username = session['username'].capitalize()
    quot = 0
    tbox = [0] * 4
    qdat = None
    from viewfuncs import dataget_Q, nonone, numcheck
    if request.method == 'POST':
        emailgo = request.values.get('Email')
        updatego = request.values.get('GetQuote')
        updatebid = request.values.get('Update')
        updateE = request.values.get('UpdateE')
        returnhit = request.values.get('Return')
        bidname = request.values.get('bidname')
        bidthis = request.values.get('bidthis')
        bidthis = d2s(bidthis)
        locfrom = request.values.get('locfrom')
        thismuch = request.values.get('thismuch')
        taskbox = request.values.get('taskbox')
        taskbox = nonone(taskbox)
        quotbut = request.values.get('optradio')

        qdata = dataget_Q(thismuch)
        #quot, numchecked = numcheck(1, qdata, 0, 0, 0, 0, ['quot'])

        if quotbut is not None:
            quot = nonone(quotbut)
        if quot == 0:
            quot = request.values.get('quotpass')
            quot = nonone(quot)
        qdat = Quotes.query.get(quot)
        print(quot, quotbut, username)

        if returnhit is not None:
            taskbox = 0
            quot = 0

        if taskbox == 2:
            qdat.Status = -1
            db.session.commit()
            taskbox = 0

        if taskbox == 3:
            qdat.Status = 0
            db.session.commit()
            taskbox = 0

        if taskbox == 4:
            qdat.Status = 3
            db.session.commit()
            taskbox = 0

        if taskbox == 6:
            add_quote_emails()

        if taskbox == 1 or taskbox == 5:
            if quot > 0 and qdat is not None:
                locto = qdat.Location
                if locto is None:
                    locto = get_place(qdat.Body)
                    qdat.Location = locto
                    db.session.commit()
                emailto = qdat.From
                if emailto is None:
                    emailto = qdat.From
                    qdat.From = emailto
                    db.session.commit()
            else:
                comdata = companydata()
                locto = comdata[6]
                emailto = usernames['expo']

            if quot > 0 or taskbox == 5:
                if qdat is not None:
                    locfrom = qdat.Start
                    if locfrom is None:
                        locfrom = 'Seagirt Marine Terminal, Baltimore, MD 21224'
                else:
                    locfrom = 'Seagirt Marine Terminal, Baltimore, MD 21224'

                if updatego is not None or updatebid is not None or emailgo is not None or updateE is not None:
                    locto = request.values.get('locto')
                    if locto is None:
                        locto = 'Capitol Heights, MD  20743'
                    locfrom = request.values.get('locfrom')
                    emailto = request.values.get('edat2')
                    respondnow = datetime.datetime.now()
                    if taskbox == 1:
                        qdat.Start = locfrom
                        qdat.Location = locto
                        qdat.From = emailto
                        qdat.Amount = bidthis
                        qdat.Person = bidname
                        qdat.Responder = username
                        qdat.RespDate = respondnow
                        qdat.Status = 1
                        db.session.commit()

                if emailgo is not None:
                    if taskbox == 1:
                        qdat.Status = 2
                        db.session.commit()
                    emaildata = sendquote(bidthis)
                    taskbox = 0
                    quot = 0

                print('Running Directions:', locfrom, locto, bidthis, bidname,
                      taskbox, quot)
                try:
                    ####################################  Directions Section  ######################################
                    miles, hours, lats, lons, dirdata, tot_dist, tot_dura = get_directions(
                        locfrom, locto)
                    #print(f'Total distance {d1s(tot_dist)} miles and total duration {d1s(tot_dura)} hours')

                    #Calculate road tolls
                    tollroadlist = ['I-76', 'NJ Tpke']
                    tollroadcpm = [.784, .275]
                    legtolls = len(dirdata) * [0.0]
                    legcodes = len(dirdata) * ['None']
                    for lx, mi in enumerate(miles):
                        for nx, tollrd in enumerate(tollroadlist):
                            if tollrd in dirdata[lx]:
                                legtolls[lx] = tollroadcpm[nx] * mi
                                legcodes[lx] = tollrd

                    #Calculate plaza tolls
                    fm_tollbox = [39.267757, -76.610192, 39.261248, -76.563158]
                    bht_tollbox = [
                        39.259962, -76.566240, 39.239063, -76.603324
                    ]
                    fsk_tollbox = [
                        39.232770, -76.502453, 39.202279, -76.569906
                    ]
                    bay_tollbox = [
                        39.026893, -76.417512, 38.964938, -76.290104
                    ]
                    sus_tollbox = [
                        39.585193, -76.142883, 39.552328, -76.033975
                    ]
                    new_tollbox = [
                        39.647121, -75.774523, 39.642613, -75.757187
                    ]  #Newark Delaware Toll Center
                    dmb_tollbox = [
                        39.702146, -75.553479, 39.669730, -75.483284
                    ]
                    tollcodes = [
                        'FM', 'BHT', 'FSK', 'BAY', 'SUS', 'NEW', 'DMB'
                    ]
                    tollboxes = [
                        fm_tollbox, bht_tollbox, fsk_tollbox, bay_tollbox,
                        sus_tollbox, new_tollbox, dmb_tollbox
                    ]

                    for jx, lat in enumerate(lats):
                        stat1 = 'ok'
                        stat2 = 'ok'
                        stat3 = 0
                        stat4 = 0
                        tollcode = 'None'
                        la = float(lat)
                        lo = float(lons[jx])
                        for kx, tollbox in enumerate(tollboxes):
                            lah = max([tollbox[0], tollbox[2]])
                            lal = min([tollbox[0], tollbox[2]])
                            loh = max([tollbox[1], tollbox[3]])
                            lol = min([tollbox[1], tollbox[3]])
                            if la > lal and la < lah:
                                stat1 = 'toll'
                                if lo > lol and lo < loh:
                                    stat2 = 'toll'
                                    tollcode = tollcodes[kx]
                                    legtolls[jx] = 24.00
                                    legcodes[jx] = tollcode
                            if jx > 0:
                                lam = (lah + lal) / 2.0
                                lom = (loh + lol) / 2.0
                                la_last = float(lats[jx - 1])
                                lo_last = float(lons[jx - 1])
                                stat3, stat4 = checkcross(
                                    lam, la_last, la, lom, lo_last, lo)
                                if stat3 == 1 and stat4 == 1:
                                    tollcode = tollcodes[kx]
                                    legtolls[jx] = 24.00
                                    legcodes[jx] = tollcode
                        ##print(lat,lons[jx],stat1, stat2, stat3, stat4, tollcode)

                    tot_tolls = 0.00
                    ex_drv = 27.41
                    ex_fuel = .48
                    ex_toll = 24.00
                    ex_insur = 4.00
                    ex_rm = .22
                    ex_misc = .04
                    ex_ga = 15
                    expdata = [
                        d2s(ex_drv),
                        d2s(ex_fuel),
                        d2s(ex_toll),
                        d2s(ex_insur),
                        d2s(ex_rm),
                        d2s(ex_misc),
                        d2s(ex_ga)
                    ]

                    porttime = 1.4
                    loadtime = 2.0
                    triptime = tot_dura * 2.0
                    glidetime = 1.0 + triptime * .01
                    tottime = porttime + loadtime + triptime + glidetime
                    timedata = [
                        d1s(triptime),
                        d1s(porttime),
                        d1s(loadtime),
                        d1s(glidetime),
                        d1s(tottime)
                    ]

                    tripmiles = tot_dist * 2.0
                    portmiles = .4
                    glidemiles = 10 + .005 * tripmiles
                    totmiles = tripmiles + portmiles + glidemiles
                    distdata = [
                        d1s(tripmiles),
                        d1s(portmiles), '0.0',
                        d1s(glidemiles),
                        d1s(totmiles)
                    ]

                    newdirdata = []
                    for lx, aline in enumerate(dirdata):
                        tot_tolls += legtolls[lx]
                        aline = aline.replace(
                            '<div style="font-size:0.9em">Toll road</div>', '')
                        aline = aline.strip()
                        #print(aline)
                        #print(f'Dist:{d1s(miles[lx])}, Time:{d1s(hours[lx])}, ')
                        if legtolls[lx] < .000001:
                            newdirdata.append(
                                f'{d1s(miles[lx])} MI {d2s(hours[lx])} HRS {aline}'
                            )
                        else:
                            newdirdata.append(
                                f'{d1s(miles[lx])} MI {d2s(hours[lx])} HRS {aline} Tolls:${d2s(legtolls[lx])}, TollCode:{legcodes[lx]}'
                            )

                    # Cost Analysis:
                    cost_drv = tottime * ex_drv
                    cost_fuel = totmiles * ex_fuel
                    cost_tolls = 2.0 * tot_tolls

                    cost_insur = tottime * ex_insur
                    cost_rm = totmiles * ex_rm
                    cost_misc = totmiles * ex_misc

                    cost_direct = cost_drv + cost_fuel + cost_tolls + cost_insur + cost_rm + cost_misc
                    cost_ga = cost_direct * ex_ga / 100.0
                    cost_total = cost_direct + cost_ga
                    costdata = [
                        d2s(cost_drv),
                        d2s(cost_fuel),
                        d2s(cost_tolls),
                        d2s(cost_insur),
                        d2s(cost_rm),
                        d2s(cost_misc),
                        d2s(cost_ga),
                        d2s(cost_direct),
                        d2s(cost_total)
                    ]

                    bid = cost_total * 1.2
                    cma_bid = bid / 1.13
                    std_bid = 250. + 2.1 * totmiles

                    biddata = [
                        d2s(roundup(bid)),
                        d2s(roundup(std_bid)),
                        d2s(roundup(cma_bid))
                    ]
                    if updatego is not None or quotbut is not None or (
                            taskbox == 5 and updatebid is None):
                        bidthis = d2s(roundup(bid))

                except:
                    costdata = None
                    biddata = None
                    newdirdata = None
                    bidthis = None
                    bidname = None
                    ex_drv = 27.41
                    ex_fuel = .48
                    ex_toll = 24.00
                    ex_insur = 4.00
                    ex_rm = .22
                    ex_misc = .04
                    ex_ga = 15
                    expdata = [
                        d2s(ex_drv),
                        d2s(ex_fuel),
                        d2s(ex_toll),
                        d2s(ex_insur),
                        d2s(ex_rm),
                        d2s(ex_misc),
                        d2s(ex_ga)
                    ]
                    timedata = []
                    distdata = []

                if quotbut is not None:
                    #Set the email data:
                    etitle = f'{cdata[0]} Quote to {locto} from {locfrom}'
                    if qdat is not None:
                        customer = qdat.Person
                        if customer is None:
                            customer = friendly(emailto)
                    else:
                        customer = friendly(emailto)
                    qdat.Person = customer
                    bidname = customer
                    db.session.commit()
                    ebody, tbox = bodymaker(bidname, cdata, bidthis, locto,
                                            tbox)
                    ebody = ebody + maketable()
                    emailin1 = request.values.get('edat2')
                    if updatego is None:
                        emailin1 = emailonly(emailto)
                    emailin2 = ''
                    emailcc1 = usernames['info']
                    emailcc2 = usernames['expo']
                    emaildata = [
                        etitle, ebody, emailin1, emailin2, emailcc1, emailcc2
                    ]
                else:
                    #Set the email data:
                    if updatebid is not None or updatego is not None:
                        etitle = f'{cdata[0]} Quote to {locto} from {locfrom}'
                        ebody, tbox = bodymaker(bidname, cdata, bidthis, locto,
                                                tbox)
                        ebody = ebody + maketable()
                    else:
                        etitle = request.values.get('edat0')
                        ebody = request.values.get('edat1')
                    emailin1 = request.values.get('edat2')
                    emailin2 = request.values.get('edat3')
                    emailcc1 = request.values.get('edat4')
                    emailcc2 = request.values.get('edat5')
                    emaildata = [
                        etitle, ebody, emailin1, emailin2, emailcc1, emailcc2
                    ]
                    #qdat.Response = ebody
                    db.session.commit()

        else:
            qdata = dataget_Q(thismuch)
            quot = request.values.get('optradio')
            if quot is not None:
                qdat = Quotes.query.get(quot)
            locto = 'Capitol Heights, MD  20743'
            locfrom = 'Baltimore Seagirt'
            etitle = f'{cdata[0]} Quote for Drayage to {locto} from {locfrom}'
            if qdat is not None:
                ebody = qdat.Body
            else:
                ebody = f'Regirgitation from the input'
            efrom = usernames['quot']
            eto1 = 'unknown'
            eto2 = ''
            ecc1 = usernames['expo']
            ecc2 = usernames['info']
            emaildata = [etitle, ebody, eto1, eto2, ecc1, ecc2, efrom]
            costdata = None
            biddata = None
            newdirdata = None
            bidthis = None
            bidname = None

            ex_drv = 27.41
            ex_fuel = .48
            ex_toll = 24.00
            ex_insur = 4.00
            ex_rm = .22
            ex_misc = .04
            ex_ga = 15
            expdata = [
                d2s(ex_drv),
                d2s(ex_fuel),
                d2s(ex_toll),
                d2s(ex_insur),
                d2s(ex_rm),
                d2s(ex_misc),
                d2s(ex_ga)
            ]
            timedata = []
            distdata = []

    else:
        print('Entering Quotes1', flush=True)
        username = session['username'].capitalize()
        tbox = []
        qdat = None
        locto = 'Upper Marlboro, MD  20772'
        locfrom = 'Baltimore Seagirt'
        etitle = f'{cdata[0]} Quote for Drayage to {locto} from {locfrom}'
        ebody = f'Regirgitation from the input'
        efrom = usernames['quot']
        eto1 = 'unknown'
        eto2 = ''
        ecc1 = usernames['expo']
        ecc2 = usernames['info']
        emaildata = [etitle, ebody, eto1, eto2, ecc1, ecc2, efrom]
        costdata = None
        biddata = None
        newdirdata = None
        bidthis = None
        bidname = None

        print('Entering Quotes2', flush=True)

        ex_drv = 27.41
        ex_fuel = .48
        ex_toll = 24.00
        ex_insur = 4.00
        ex_rm = .22
        ex_misc = .04
        ex_ga = 15
        expdata = [
            d2s(ex_drv),
            d2s(ex_fuel),
            d2s(ex_toll),
            d2s(ex_insur),
            d2s(ex_rm),
            d2s(ex_misc),
            d2s(ex_ga)
        ]
        timedata = []
        distdata = []
        add_quote_emails()
        thismuch = '1'
        taskbox = 0
        quot = 0
        print('Entering Quotes3', flush=True)

    print('Getting qdata', flush=True)
    qdata = dataget_Q(thismuch)
    print(quot)
    return bidname, costdata, biddata, expdata, timedata, distdata, emaildata, locto, locfrom, newdirdata, qdata, bidthis, taskbox, thismuch, quot, qdat, tbox
예제 #9
0
def updateinvo(jo, thisdate):
    idata = Invoices.query.filter(Invoices.Jo == jo).all()
    total = 0.0
    for idat in idata:
        each = float(idat.Qty)
        amtea = float(idat.Ea)
        amount = each * amtea
        idat.Amount = nodollar(amount)
        db.session.commit()
        total = total + amount
    for idat in idata:
        idat.Date = thisdate
        idat.Total = nodollar(total)
        db.session.commit()
    if jo[1] == 'T':
        ldata = Invoices.query.filter(Invoices.Jo == jo).order_by(
            Invoices.Ea.desc()).all()
        myo = Orders.query.filter(Orders.Jo == jo).first()
        cache = myo.Storage + 1
        pdata1 = People.query.filter(People.id == myo.Bid).first()
        pdata2 = Drops.query.filter(Drops.id == myo.Lid).first()
        pdata3 = Drops.query.filter(Drops.id == myo.Did).first()

        from make_T_invoice import T_invoice
        T_invoice(myo, ldata, pdata1, pdata2, pdata3, cache, thisdate, 0)

        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'

        for ldatl in ldata:
            ldatl.Pid = pdata1.id
            ldatl.Original = docref
            db.session.commit()

        myo.Path = docref
        myo.Storage = cache
        db.session.commit()

    if jo[1] == 'O':
        odat = OverSeas.query.filter(OverSeas.Jo == jo).first()
        invooder = odat.id
        cache = nonone(odat.Cache) + 1
        from invoices import invoiceO
        invo, err, leftscreen, leftsize, docref, invodate = invoiceO(
            invooder, 0)

        if cache > 1:
            docref = f'tmp/{scac}/data/vinvoice/INV' + jo + 'c' + str(
                cache) + '.pdf'
            # Store for future use
        else:
            docref = f'tmp/{scac}/data/vinvoice/INV' + jo + '.pdf'
        odat.Cache = cache
        modata = OverSeas.query.get(invooder)
        jo = modata.Jo
        booking = modata.Booking
        ldata = Invoices.query.filter(Invoices.Jo == jo).order_by(
            Invoices.Jo).all()
예제 #10
0
파일: iso_R.py 프로젝트: markwnixon/class8
def isoR():

    if request.method == 'POST':
# ____________________________________________________________________________________________________________________B.FormVariables.General

        from viewfuncs import parseline, popjo, jovec, newjo, timedata, nonone, nononef
        from viewfuncs import numcheck, numcheckv, viewbuttons, get_ints, numcheckvec, erud

        #Zero and blank items for default
        username = session['username'].capitalize()
        cache= request.values.get('cache')
        err=[]
        docref=''
        doctxt=''
        fyear=2019
        oceantype=request.values.get('dt1')
        trucktype=request.values.get('dt2')
        detailtype=request.values.get('dt3')
        c1=request.values.get('dc1')
        c2=request.values.get('dc2')
        c3=request.values.get('dc3')
        c4=request.values.get('dc4')
        c5=request.values.get('dc5')
        c6=request.values.get('dc6')
        c7=request.values.get('dc7')
        clist=[oceantype,trucktype,detailtype,c1,c2,c3,c4,c5,c6,c7]

        today = datetime.date.today()
        now = datetime.datetime.now().strftime('%I:%M %p')

        leftsize=8
        leftscreen=0

        interreport =  request.values.get('mtick')
        jayreport   =  request.values.get('jaystuff')
        increport   =  request.values.get('income')
        custreport  =  request.values.get('customer')
        thiscomp    =  request.values.get('thiscompany')
        PLreport    =  request.values.get('PL')

        sdate=request.values.get('start')
        fdate=request.values.get('finish')

        #This sequence will reset hv while collecting the new plot accounts
        # hv[0] and hv[11] store the number of bars and their labels of the plot
        # This provide hv[1-10] as the bar chart data available
        hv = [request.values.get(f'act{ix}') for ix in range(0,13)]
        for ix, est in enumerate(hv):
            if est is None: hv[ix] = '0'

        #If the first 3 selections are all '0' make sure remaining are turned off:
        if hv[1] == '0' and hv[2] == '0' and hv[3] == '0' and hv[4] == '0': hv = ['0']*13

        # If no accts selected to plot then switch off the plot section of page
        if all(h=='0' for h in hv):
            plotswitch = 0
            plotthese = []
        else:
            plotswitch=1
            plotthese = [h for h in hv if h != '0' ]
        hv[0] = len(plotthese)
        hv[11] = plotthese
        hv[12] = request.values.get('timestyle')
        if hv[12] is None:
            hv[12] = '12'

        print('plotstuff',plotswitch,plotthese)

        monvec=['jan', 'feb', 'mar', 'apr', 'may', 'jun', 'jul', 'aug', 'sep', 'oct', 'nov', 'dec']
        for j, mon in enumerate(monvec):
            a=request.values.get(mon)
            if a is not None:
                b=request.values.get('focusyear')
                if b is not None:
                    fyear=2018
                jmonth=j+1
                leapyears=[2020,2024,2028,2032,2036]
                if fyear in leapyears:
                    enddays = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
                else:
                    enddays = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
                endday=enddays[j]
                start= datetime.date(fyear, jmonth, 1)
                end= datetime.date(fyear, jmonth, endday)
                sdate=start.strftime('%Y-%m-%d')
                fdate=end.strftime('%Y-%m-%d')

        if interreport is not None:
            cache,docref=reportmaker('mtick','')

        if jayreport is not None:
            cache,docref=reportmaker('jay','')

        if increport is not None:
            cache,docref=reportmaker('income','')

        if custreport is not None and thiscomp != '1':
            cache,docref=reportmaker('customer',thiscomp)

        if PLreport is not None:
            cache,docref=reportmaker('pl','')


        if cache is not None:
            #Save the current cache so we do not start from bad place in future
            udat=users.query.filter(users.name=='cache').first()
            udat.username=str(cache)
            db.session.commit()


    else:
        from viewfuncs import popjo, jovec, timedata, nonone, nononef, init_truck_zero, erud
        today = datetime.date.today()
        err=[]
        hv = ['0'] * 12
        hv[0] = 0
        #today = datetime.datetime.today().strftime('%Y-%m-%d')
        now = datetime.datetime.now().strftime('%I:%M %p')
        docref=''
        doctxt=''
        thiscomp=''
        leftscreen=0
        leftsize=8
        udat=users.query.filter(users.name=='Cache').first()
        cache=udat.username
        cache=nonone(cache)
        sdate=today
        fdate=today
        fyear=2020
        clist=['off']*12
        clist[1] = 'on'

    customerlist=[]
    if clist[0]=='on':
        odata=OverSeas.query.all()
        for odat in odata:
            cust=odat.BillTo
            if cust not in customerlist:
                customerlist.append(cust)
    if clist[1]=='on':
        odata=Orders.query.all()
        for odat in odata:
            cust=odat.Shipper
            if cust is not None and cust not in customerlist:
                customerlist.append(cust)

    customerlist.sort()
    idata1 = IEroll.query.filter(IEroll.Name.contains('Totals')).order_by(IEroll.Name).all()
    idata2 = IEroll.query.filter(~(IEroll.Name.contains('Totals')) & (IEroll.Type == 'Expense')).order_by(IEroll.Name).all()
    idata3 = IEroll.query.filter(~(IEroll.Name.contains('Totals')) & (IEroll.Type == 'Income')).order_by(IEroll.Name).all()
    idata4 = Broll.query.filter(Broll.Type == 'Expense-B').order_by(Broll.Tot.desc()).all()
    err = erud(err)


    return idata1, idata2, idata3, idata4, hv, cache, err, leftscreen, docref, leftsize, today, now, doctxt, sdate, fdate, fyear, customerlist, thiscomp, clist
예제 #11
0
def isoS():

    if request.method == 'POST':

        monsel, oder, peep, serv, invo, inco, cache, modata, modlink, fdata, invooder = init_storage_zero(
        )
        invojo, filesel, docref, search11, search12, search21, search31 = init_storage_blank(
        )
        leftscreen = 1
        docref = ' '
        err = ['All is well', ' ', ' ', ' ', ' ']
        ldata = None
        #today = datetime.datetime.today().strftime('%Y-%m-%d')
        today = datetime.date.today()
        invodate = datetime.date.today()
        leftsize = 10
        monvec = [
            'Month', 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug',
            'Sep', 'Oct', 'Nov', 'Dec'
        ]
        monlvec = [
            'January', 'February', 'March', 'April', 'May', 'June', 'July',
            'August', 'September', 'October', 'November', 'December'
        ]

        match = request.values.get('Match')
        modify = request.values.get('Modify')
        vmod = request.values.get('Vmod')
        minvo = request.values.get('MakeI')
        mpack = request.values.get('MakeP')
        viewo = request.values.get('ViewO')
        viewi = request.values.get('ViewI')
        viewp = request.values.get('ViewP')
        analyze = request.values.get('Analyze')
        print = request.values.get('Print')
        addE = request.values.get('addentity')
        addS = request.values.get('addservice')
        recpay = request.values.get('RecPay')
        hispay = request.values.get('HisPay')
        monsel = request.values.get('monsel')

        returnhit = request.values.get('Return')
        deletehit = request.values.get('Delete')
        # hidden values
        update = request.values.get('Update')
        invoupdate = request.values.get('invoUpdate')
        recupdate = request.values.get('recUpdate')
        modlink = request.values.get('passmodlink')
        emailnow = request.values.get('emailnow')
        emailinvo = request.values.get('emailInvo')
        newjob = request.values.get('NewJ')
        thisjob = request.values.get('ThisJob')

        oder = request.values.get('oder')
        invo = request.values.get('invo')
        invooder = request.values.get('invooder')
        cache = request.values.get('cache')
        peep = request.values.get('peep')
        serv = request.values.get('serv')
        inco = request.values.get('inco')

        modlink = nonone(modlink)
        oder = nonone(oder)
        invo = nonone(invo)
        invooder = nonone(invooder)
        peep = nonone(peep)
        serv = nonone(serv)
        monsel = nonone(monsel)
        inco = nonone(inco)
        modal = 0

        if returnhit is not None:
            modlink = 0
            invo = 0
            invooder = 0
            inco = 0
# ____________________________________________________________________________________________________________________B.UpdateDatabases.Storage
        if update is not None and modlink == 1:
            if oder > 0:
                modata = Storage.query.get(oder)
                desc = request.values.get('desc')
                amount = request.values.get('amount')
                thiscomp = request.values.get('thiscomp')
                dstart = request.values.get('dstart')
                balfwd = request.values.get('pybal')
                modata.Description = desc
                modata.Amount = amount
                modata.Date = dstart
                modata.BalFwd = balfwd
                ldat = People.query.filter(People.Company == thiscomp).first()
                if ldat is not None:
                    acomp = ldat.Company
                    aid = ldat.id
                else:
                    acomp = None
                    aid = None
                modata.Company = acomp
                modata.Pid = aid
                modata.Label = modata.Jo + ' ' + thiscomp + ' ' + amount
                db.session.commit()
                err[3] = 'Modification to Storage JO ' + modata.Jo + ' completed.'
                modlink = 0
            if peep > 0:
                modata = People.query.get(peep)
                modata.Ptype = 'Storage'
                vals = [
                    'company', 'fname', 'mnames', 'lname', 'addr1', 'addr2',
                    'addr3', 'idtype', 'tid', 'tel', 'email', 'assoc1',
                    'assoc2', 'date1'
                ]
                a = list(range(len(vals)))
                i = 0
                for v in vals:
                    a[i] = request.values.get(v)
                    i = i + 1
                modata.Company = a[0]
                modata.First = a[1]
                modata.Middle = a[2]
                modata.Last = a[3]
                modata.Addr1 = a[4]
                modata.Addr2 = a[5]
                modata.Addr3 = a[6]
                modata.Idtype = a[7]
                modata.Idnumber = a[8]
                modata.Telephone = a[9]
                modata.Email = a[10]
                modata.Associate1 = a[11]
                modata.Associate2 = a[12]
                modata.Date1 = a[13]
                db.session.commit()
                err = [
                    ' ', ' ', 'Modification to Entity ID ' + str(modata.id) +
                    ' completed.', ' ', ' '
                ]
                modlink = 0
                # And now update the crossover to Storage in case the Company info changed:
                cross = Storage.query.filter(Storage.Pid == peep)
                for cros in cross:
                    cros.Company = a[0]
                db.session.commit()

            if serv > 0:
                modata = Services.query.get(serv)
                vals = ['service', 'price']
                a = list(range(len(vals)))
                i = 0
                for v in vals:
                    a[i] = request.values.get(v)
                    i = i + 1
                modata.Service = a[0]
                modata.Price = a[1]
                db.session.commit()
                err = [
                    ' ', ' ', 'Modification to Services Data with ID ' +
                    str(modata.id) + ' completed.', ' ', ' '
                ]
                modlink = 0

            if inco > 0:
                modata = Income.query.get(inco)
                vals = ['desc', 'recamount', 'custref', 'recdate']
                i = 0
                for v in vals:
                    a[i] = request.values.get(v)
                    i = i + 1
                modata.Description = a[0]
                modata.Amount = a[1]
                modata.Ref = a[2]
                modata.Date = a[3]
                db.session.commit()
                err = [
                    ' ', ' ', 'Modification to Income Data with ID ' +
                    str(modata.id) + ' completed.', ' ', ' '
                ]
# ____________________________________________________________________________________________________________________E.UpdateDatabases.Storage
# ____________________________________________________________________________________________________________________B.UpdateInvoice.Storage
        if invoupdate is not None and monsel != 0:
            leftsize = 8
            odata1 = Storage.query.get(invooder)
            invojo = popjo(invooder, monsel)
            ldata = Invoices.query.filter(Invoices.SubJo == invojo).all()
            invodate = request.values.get('invodate')
            total = 0
            for data in ldata:
                iqty = request.values.get('qty' + str(data.id))
                iqty = nononef(iqty)
                data.Description = request.values.get('desc' + str(data.id))
                deach = request.values.get('cost' + str(data.id))
                if deach is not None:
                    deach = "{:.2f}".format(float(deach))
                    amount = iqty * float(deach)
                else:
                    deach = "{:.2f}".format(0.00)
                    amount = 0.00
                total = total + amount
                amount = "{:.2f}".format(amount)
                data.Qty = iqty
                data.Ea = deach
                data.Amount = amount
                data.Total = 0.00
                data.Date = invodate
                db.session.commit()

            if total > 0 and ldata is not None:
                for data in ldata:
                    data.Total = "%0.2f" % total
                    db.session.commit()
                odata1.Amount = "%0.2f" % total
                db.session.commit()

            #Remove zeros from invoice in case a zero was the mod
            Invoices.query.filter(Invoices.Qty == 0).delete()
            db.session.commit()

            #Create invoice code for order
            err = [
                ' ', ' ', 'Invoice created for Storage JO: ' + invojo, ' ', ' '
            ]
            ldata = Invoices.query.filter(Invoices.SubJo == invojo).all()
# ____________________________________________________________________________________________________________________E.UpdateInvoice.Storage

        odata = Storage.query.order_by(Storage.Jo).all()
        cdata = People.query.filter(People.Ptype == 'Storage').order_by(
            People.Company).all()
        sdata = Services.query.all()

        oder, peep, serv, numchecked = numcheck(3, odata, cdata, sdata, 0, 0,
                                                ['oder', 'peep', 'serv'])

        # ____________________________________________________________________________________________________________________E.SearchFilters.Storage

        # ____________________________________________________________________________________________________________________B.EmailInvoice.Storage
        if emailinvo is not None:
            leftsize = 10
            leftscreen = 1
            modlink = 0
            modata = Storage.query.get(invooder)
            invojo = popjo(invooder, monsel)
            ldata = Invoices.query.filter(Invoices.SubJo == invojo).order_by(
                Invoices.Ea.desc()).all()
            pdata1 = People.query.filter(People.id == modata.Pid).first()
            ldat = Invoices.query.filter(Invoices.SubJo == invojo).first()
            if pdata1 is None:
                err = [
                    ' ', ' ',
                    'There is no Billing information for this selection', ' ',
                    ' '
                ]
            else:
                email = pdata1.Email
                company = pdata1.Company
            docref = ldat.Original
            if 'vinvoice' not in docref:
                err = [
                    ' ', ' ',
                    'There is no document available for this selection', ' ',
                    ' '
                ]
            else:
                if email is not None:
                    import invoice_mimemail_S
                    invoice_mimemail_S.main(invojo, docref, email, monsel,
                                            inco, company)
                    if inco == 0:
                        for data in ldata:
                            data.Status = "E"
                            db.session.commit()
                    else:
                        for data in ldata:
                            data.Status = "P"
                            db.session.commit()
            invooder = 0
            invo = 0
            inco = 0

# ____________________________________________________________________________________________________________________E.EmailInvoice.Storage
# ____________________________________________________________________________________________________________________B.Viewers.Storage
        if viewo is not None and numchecked == 1:
            err = [
                ' ', ' ', 'There is no document available for this selection',
                ' ', ' '
            ]
            if oder > 0:
                modata = Storage.query.get(oder)
                if modata.Original is not None:
                    if len(modata.Original) > 5:
                        docref = modata.Original
                        leftscreen = 0
                        leftsize = 8
                        modlink = 0
                        err = [
                            ' ', ' ', 'Viewing document ' + docref, ' ', ' '
                        ]

        if (viewo is not None or viewi is not None
                or viewp is not None) and numchecked != 1:
            err = [
                'Must check exactly one box to use this option', ' ', ' ', ' ',
                ' '
            ]

        if viewi is not None and numchecked == 1:
            err = [
                'There is no document available for this selection', ' ', ' ',
                ' ', ' '
            ]
            if monsel == 0:
                err[1] = 'Need to select the month'
            if oder > 0 and monsel > 0:
                invooder = oder
                modata = Storage.query.get(oder)
                invojo = popjo(oder, monsel)
                ldat = Invoices.query.filter(Invoices.SubJo == invojo).first()
                if ldat.Original is not None:
                    docref = ldat.Original
                    leftscreen = 0
                    leftsize = 8
                    modlink = 5
                    err = [' ', ' ', 'Viewing document ' + docref, ' ', ' ']
# ____________________________________________________________________________________________________________________E.Viewers.Storage
# ____________________________________________________________________________________________________________________B.ModifyEntries.Storage
        if (modify is not None or vmod is not None) and numchecked == 1:
            modlink = 1
            leftsize = 8

            if oder > 0:
                modata = Storage.query.get(oder)
                if vmod is not None:
                    err = [
                        ' ', ' ',
                        'There is no document available for this selection',
                        ' ', ' '
                    ]
                    if modata.Original is not None:
                        if len(modata.Original) > 5:
                            leftscreen = 0
                            docref = modata.Original
                            err = ['All is well', ' ', ' ', ' ', ' ']

            if serv > 0:
                modata = Services.query.get(serv)
                if vmod is not None:
                    err = [
                        ' ', ' ',
                        'There is no document available for this selection',
                        ' ', ' '
                    ]

            if peep > 0:
                modata = People.query.get(peep)
                if vmod is not None:
                    err = [
                        ' ', ' ',
                        'There is no document available for this selection',
                        ' ', ' '
                    ]

        if (modify is not None or vmod is not None) and numchecked != 1:
            modlink = 0
            err[0] = ' '
            err[2] = 'Must check exactly one box to use this option'
# ____________________________________________________________________________________________________________________E.ModifyEntries.Storage
# ____________________________________________________________________________________________________________________B.AddEntries.Storage

        if addS is not None and serv > 0 and numchecked == 1:
            leftsize = 8
            modlink = 2
            modata = Services.query.get(serv)

        if addS is not None and numchecked == 0:
            leftsize = 8
            modlink = 1
            #We will create a blank line and simply modify that by updating:
            input = Services(Service='New', Price=0.00)
            db.session.add(input)
            db.session.commit()
            modata = Services.query.filter(Services.Service == 'New').first()
            serv = modata.id
            err = [' ', ' ', 'Enter Data for New Service', ' ', ' ']

        if addS is not None and numchecked > 1:
            modlink = 0
            err[0] = ' '
            err[2] = 'Must check exactly one box to use this option'

        if addE is not None and peep > 0 and numchecked == 1:
            leftsize = 8
            modlink = 3
            modata = People.query.get(peep)

        if addE is not None and numchecked == 0:
            leftsize = 8
            modlink = 1
            #We will create a blank line and simply modify that by updating:
            input = People(Company='New',
                           First='',
                           Middle='',
                           Last='',
                           Addr1='',
                           Addr2='',
                           Addr3='',
                           Idtype='',
                           Idnumber='',
                           Telephone='',
                           Email='',
                           Associate1='',
                           Associate2='',
                           Date1=today,
                           Date2=None,
                           Original=None,
                           Ptype='Storage',
                           Temp1=None,
                           Temp2=None)
            db.session.add(input)
            db.session.commit()
            modata = People.query.filter((People.Company == 'New') &
                                         (People.Ptype == 'Storage')).first()
            peep = modata.id
            modata.Company = ''
            db.session.commit()
            modata = People.query.get(peep)
            err = [' ', ' ', 'Enter Data for New Company', ' ', ' ']

        if addE is not None and numchecked > 1:
            modlink = 0
            err[0] = ' '
            err[2] = 'Must check exactly one box to use this option'
# ____________________________________________________________________________________________________________________E.AddEntries.Storage
# ____________________________________________________________________________________________________________________B.ReceivePayment.Storage

        if (recpay is not None and oder > 0 and numchecked == 1
                and monsel > 0) or recupdate is not None:
            leftsize = 8
            if recpay is not None:
                invooder = oder
            odat = Storage.query.get(invooder)
            invojo = popjo(invooder, monsel)
            ldat = Invoices.query.filter(Invoices.SubJo == invojo).first()
            err = ['Have no Invoice to Receive Against', ' ', ' ', ' ', ' ']
            if ldat is not None:
                invodate = ldat.Date
                if ldat.Original is not None:
                    docref = ldat.Original
                    leftscreen = 0
                    leftsize = 8

                incdat = Income.query.filter(Income.SubJo == invojo).first()
                if incdat is None:
                    err = ['Creating New Payment on SubJo', ' ', ' ', ' ', ' ']
                    paydesc = 'Received payment on Invoice ' + invojo + ' for month of ' + monvec[
                        monsel]
                    recamount = str(ldat.Amount)
                    custref = 'ChkNo'
                    recdate = datetime.date(today.year, monsel, 28)
                    input = Income(Jo=odat.Jo,
                                   SubJo=invojo,
                                   Pid=odat.Pid,
                                   Description=paydesc,
                                   Amount=recamount,
                                   Ref=custref,
                                   Date=recdate,
                                   Original=None)
                    db.session.add(input)
                    payment = 0
                else:
                    recamount = request.values.get('recamount')
                    custref = request.values.get('custref')
                    desc = request.values.get('desc')
                    recdate = request.values.get('recdate')
                    incdat.Amount = recamount
                    incdat.Ref = custref
                    incdat.Description = desc
                    incdat.Date = recdate
                db.session.commit()
                payment = [recamount, custref, recdate]

                modata = Income.query.filter(Income.SubJo == invojo).first()
                inco = modata.id
                err = [' ', ' ', 'Amend Payment for Invoice', ' ', ' ']

                ldata = Invoices.query.filter(
                    Invoices.SubJo == invojo).order_by(
                        Invoices.Ea.desc()).all()
                pdata1 = People.query.filter(People.id == odat.Pid).first()
                cache = nonone(odat.Cache) + 1

                basejo = odat.Jo
                involine, paidline, refline, balline = money12(basejo)

                balduenow = balline[monsel]
                try:
                    balduenow = float[balduenow]
                except:
                    balduenow = 0.00
                if balduenow < .001:
                    for data in ldata:
                        data.Status = "P"
                        db.session.commit()

                import make_S_invoice
                make_S_invoice.main(odat, ldata, pdata1, invojo, involine,
                                    paidline, refline, balline, invodate,
                                    cache, payment)

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

                odat.Cache = cache
                idat = Invoices.query.filter(Invoices.SubJo == invojo).first()
                idat.Original = docref
                db.session.commit()
                leftscreen = 0
                err[4] = 'Viewing ' + docref

        if recpay is not None and (oder == 0 or numchecked != 1
                                   or monsel == 0):
            err = ['Invalid selections:', '', '', '', '']
            if oder == 0:
                err[1] = 'Must select a Storage Job'
            if numchecked != 1:
                err[2] = 'Must select exactly one Storage Job'
            if monsel == 0:
                err[3] = 'Must select a month to apply payment'
# ____________________________________________________________________________________________________________________E.ReceivePayment.Storage
# ____________________________________________________________________________________________________________________B.PaymentHistory.Storage
        if hispay is not None or modlink == 7:
            if oder == 0 and invooder == 0:
                err[1] = 'Must select a Storage Job'
            else:
                if oder != 0:
                    invooder = oder
                modata = Storage.query.get(invooder)
                ldata = Invoices.query.filter(
                    Invoices.Jo == modata.Jo).order_by(Invoices.SubJo).all()
                fdata = Income.query.filter(Income.Jo == modata.Jo).order_by(
                    Income.SubJo).all()
                #Check to see if we need to delete anything from history
                killthis = request.values.get('killthis')
                if killthis is not None and modlink == 7:
                    for data in ldata:
                        testone = request.values.get('bill' + str(data.id))
                        if testone:
                            kill = int(testone)
                            Invoices.query.filter(Invoices.id == kill).delete()
                            db.session.commit()
                    for data in fdata:
                        testone = request.values.get('pay' + str(data.id))
                        if testone:
                            kill = int(testone)
                            Income.query.filter(Income.id == kill).delete()
                            db.session.commit()
                    ldata = Invoices.query.filter(
                        Invoices.Jo == modata.Jo).order_by(
                            Invoices.SubJo).all()
                    fdata = Income.query.filter(
                        Income.Jo == modata.Jo).order_by(Income.SubJo).all()

                leftsize = 8
                modlink = 7
# ____________________________________________________________________________________________________________________E.PaymentHistory.Storage
# ____________________________________________________________________________________________________________________B.Delete.Storage
        if deletehit is not None and numchecked == 1:
            if oder > 0:
                Storage.query.filter(Storage.id == oder).delete()
                odata = Storage.query.all()
            if peep > 0:
                People.query.filter(People.id == peep).delete()
                cdata = People.query.filter(
                    People.Ptype == 'Storage').order_by(People.Company).all()
            if serv > 0:
                Services.query.filter(Services.id == serv).delete()
                sdata = Services.query.all()
            db.session.commit()
        if deletehit is not None and numchecked != 1:
            err = [
                ' ', ' ',
                'Must have exactly one item checked to use this option', ' ',
                ' '
            ]
# ____________________________________________________________________________________________________________________E.Delete.Storage
# ____________________________________________________________________________________________________________________B.Invoicing.Storage
        if ((minvo is not None and oder > 0)
                or invoupdate is not None) and monsel > 0:
            err = ['Could not create invoice', ' ', ' ', ' ', ' ']
            # First time through: have an order to invoice
            if oder > 0:
                invooder = oder
            myo = Storage.query.get(invooder)
            fee = myo.Amount
            #Check to see if we have the required data to make an invoice:
            invojo = popjo(invooder, monsel)
            thismonth = calendar.month_name[monsel]
            invodate = request.values.get('invodate')

            invo = 1
            leftsize = 8
            cache = nonone(myo.Cache) + 1
            mys = Services.query.get(serv)
            if mys is not None:
                addserv = mys.Service
                price = mys.Price
                qty = 1
                d = datetime.date(today.year, monsel, 1)
                descript = 'Monthly Storage Fee for Month of ' + thismonth
                input = Invoices(Jo=myo.Jo,
                                 SubJo=invojo,
                                 Pid=myo.Pid,
                                 Service=addserv,
                                 Description=descript,
                                 Ea=price,
                                 Qty=qty,
                                 Amount=price,
                                 Total=price,
                                 Date=d,
                                 Original=None,
                                 Status='New')
                db.session.add(input)
                db.session.commit()

            ldata = Invoices.query.filter(Invoices.SubJo == invojo).first()
            if ldata is None:
                invodate = datetime.date(today.year, monsel, 1)
                #See if there is an invoice from previous month to copy from
                try:
                    invojoprev = popjo(invooder, monsel - 1)
                    invodate = datetime.date(today.year, monsel, 1)
                    ldata2 = Invoices.query.filter(
                        Invoices.SubJo == invojoprev).all()
                    for data in ldata2:
                        mydescript = data.Description
                        newdescript = data.Description
                        for i in range(12):
                            if monlvec[i] in newdescript:
                                j = i + 1
                                if j == 12:
                                    j = 0
                                mydescript = newdescript.replace(
                                    monlvec[i], monlvec[j])

                        input = Invoices(Jo=myo.Jo,
                                         SubJo=invojo,
                                         Pid=myo.Pid,
                                         Service=data.Service,
                                         Description=mydescript,
                                         Ea=data.Ea,
                                         Qty=data.Qty,
                                         Amount=data.Amount,
                                         Date=invodate,
                                         Total=data.Total,
                                         Original=None,
                                         Status='New')
                        db.session.add(input)
                        db.session.commit()
                except:
                    if mys is None:
                        addserv = 'Monthly Storage'
                        price = fee
                    else:
                        addserv = mys.Service
                        price = mys.Price

                    qty = 1
                    invodate = datetime.date(today.year, monsel, 1)
                    descript = 'Monthly Storage Fee for Month of ' + thismonth
                    input = Invoices(Jo=myo.Jo,
                                     SubJo=invojo,
                                     Pid=myo.Pid,
                                     Service=addserv,
                                     Description=descript,
                                     Ea=price,
                                     Qty=qty,
                                     Amount=price,
                                     Date=invodate,
                                     Total=price,
                                     Original=None,
                                     Status='New')
                    db.session.add(input)
                    db.session.commit()
                else:
                    ldat = Invoices.query.filter(
                        Invoices.SubJo == invojo).first()
                    if ldat is None:
                        if mys is None:
                            addserv = 'Monthly Storage'
                            price = fee
                        else:
                            addserv = mys.Service
                            price = mys.Price

                        qty = 1
                        invodate = datetime.date(today.year, monsel, 1)
                        descript = 'Monthly Storage Fee for Month of ' + thismonth
                        input = Invoices(Jo=myo.Jo,
                                         SubJo=invojo,
                                         Pid=myo.Pid,
                                         Service=addserv,
                                         Description=descript,
                                         Ea=price,
                                         Qty=qty,
                                         Amount=price,
                                         Date=invodate,
                                         Total=price,
                                         Original=None,
                                         Status='New')
                        db.session.add(input)
                        db.session.commit()
                    ldat = Invoices.query.filter(
                        Invoices.SubJo == invojo).first()
                    invodate = ldat.Date

            # If have ldata:
            err = [' ', ' ', 'Created invoice for JO= ' + invojo, ' ', ' ']

            ldata = Invoices.query.filter(Invoices.SubJo == invojo).order_by(
                Invoices.Ea.desc()).all()
            pdata1 = People.query.filter(People.id == myo.Pid).first()

            odat = Storage.query.get(invooder)
            basejo = odat.Jo
            involine, paidline, refline, balline = money12(basejo)

            import make_S_invoice
            make_S_invoice.main(odat, ldata, pdata1, invojo, involine,
                                paidline, refline, balline, invodate, cache, 0)

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

            odat.Path = docref
            odat.Cache = cache
            idat = Invoices.query.filter(Invoices.SubJo == invojo).first()
            idat.Original = docref
            db.session.commit()
            leftscreen = 0
            err[4] = 'Viewing ' + docref
            modata = Storage.query.get(invooder)
        elif minvo is not None and monsel == 0:
            err = [' ', ' ', 'Choose a Month for the Invoice', ' ', ' ']
        elif minvo is not None:
            err = [
                ' ', ' ', 'Must select at least 1 Job for this selection', ' ',
                ' '
            ]
# ____________________________________________________________________________________________________________________E.Invoicing.Storage

# ____________________________________________________________________________________________________________________B.NewJob.Storage
        if newjob is not None:
            err = ['Select Source Document from List']
            fdata = myoslist(f'tmp/{scac}/data/vunknown')
            modlink = 4
            leftsize = 8
            leftscreen = 0
            docref = f'tmp/{scac}/data/vunknown/NewJob.pdf'

        if newjob is None and modlink == 4:
            filesel = request.values.get('FileSel')
            if filesel != '1':
                fdata = myoslist(f'tmp/{scac}/data/vunknown')
                leftsize = 8
                leftscreen = 0
                docref = f'tmp/{scac}/data/vunknown/' + filesel

        if thisjob is not None:
            modlink = 0
            #Create the new database entry for the source document
            filesel = request.values.get('FileSel')
            if filesel != '1':
                docold = f'tmp/{scac}/data/vunknown/' + filesel
                docref = f'tmp/{scac}/data/vorders/' + filesel
                shutil.move(addpath(docold), addpath(docref))
            else:
                docref = ''
            sdate = request.values.get('dstart')
            if sdate is None:
                sdate = today

            jtype = 'S'
            nextjo = newjo(jtype, sdate)

            thisdesc = request.values.get('thisdesc')
            thisamt = request.values.get('thisamt')
            thiscomp = request.values.get('thiscomp')
            pybal = request.values.get('pybal')
            ldat = People.query.filter(People.Company == thiscomp).first()
            if ldat is not None:
                acomp = ldat.Company
                aid = ldat.id
            else:
                acomp = None
                aid = None
            label = nextjo + ' ' + thiscomp + ' ' + thisamt
            input = Storage(Jo=nextjo,
                            Description=thisdesc,
                            BalFwd=pybal,
                            Amount=thisamt,
                            Status='New',
                            Cache=1,
                            Original=docref,
                            Path=None,
                            Pid=aid,
                            Company=thiscomp,
                            Date=sdate,
                            Label=label)

            db.session.add(input)
            db.session.commit()
            modata = Storage.query.filter(Storage.Jo == nextjo).first()
            csize = People.query.filter(People.Ptype == 'Storage').order_by(
                People.Company).all()
            oder = modata.id
            leftscreen = 1
            err = ['All is well', ' ', ' ', ' ', ' ']
            odata = Storage.query.all()
# ____________________________________________________________________________________________________________________E.New Job.Storage
# ____________________________________________________________________________________________________________________B.Matching.Storage
        if match is not None:
            if oder > 0 and peep > 0 and numchecked == 2:
                myo = Storage.query.get(oder)
                myp = People.query.get(peep)
                myo.Pid = peep
                myo.Company = myp.Company
                db.session.commit()
            if numchecked != 2:
                err[1] = 'Must select exactly 2 boxes to use this option.'
                err[0] = ' '
# ____________________________________________________________________________________________________________________E.Matching.Storage

# Create the time oriented data for the columns
        bm, cm = timedata(odata)
    #This is the else for 1st time through
    else:
        # ____________________________________________________________________________________________________________________B.STORAGEnotPost

        odata = Storage.query.order_by(Storage.Jo).all()
        cdata = People.query.filter(People.Ptype == 'Storage').order_by(
            People.Company).all()
        sdata = Services.query.all()
        ldata = None
        today = datetime.datetime.today().strftime('%Y-%m-%d')
        invodate = today
        monsel, oder, peep, serv, invo, inco, cache, modata, modlink, fdata, invooder = init_storage_zero(
        )
        invojo, filesel, docref, search11, search12, search21, search31 = init_storage_blank(
        )
        monvec = [
            'All', 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug',
            'Sep', 'Oct', 'Nov', 'Dec'
        ]
        leftscreen = 1
        leftsize = 10
        docref = ' '
        err = ['All is well', ' ', ' ', ' ', ' ']
        bm, cm = timedata(odata)
    docref = docref.replace('tmp/vinvoice', f'tmp/{scac}/data/vinvoice')
    return odata, cdata, sdata, oder, peep, serv, err, modata, modlink, fdata, today, inco, leftscreen, docref, leftsize, ldata, monsel, monvec, invo, invooder, invojo, cache, filesel, bm, cm, invodate
예제 #12
0
def isoDriver():

    if request.method == 'POST':
# ____________________________________________________________________________________________________________________B.FormVariables.General

        from viewfuncs import parseline, popjo, jovec, newjo, timedata, nonone, nononef
        from viewfuncs import numcheck, numcheckv, viewbuttons, get_ints, numcheckvec, numcheckv

        #Zero and blank items for default
        username = session['username'].capitalize()
        cache=request.values.get('cache')
        cache=nonone(cache)

        modata=0
        modlink=0
        docref=''
        oderstring=''
        today = datetime.date.today()
        now = datetime.datetime.now().strftime('%I:%M %p')

        leftsize=10

        match    =  request.values.get('Match')
        modify   =  request.values.get('Qmod')
        vmod   =  request.values.get('Vmod')
        viewo     =  request.values.get('View')
        print    =  request.values.get('Print')
        returnhit = request.values.get('Return')
        deletehit = request.values.get('Delete')
        delfile = request.values.get('DELF')
        # hidden values
        update   =  request.values.get('Update')
        newact=request.values.get('NewA')
        thisjob=request.values.get('ThisJob')
        oder=request.values.get('oder')
        modlink = request.values.get('modlink')
        thismuch = request.values.get('thismuch')

        oder=nonone(oder)
        modlink=nonone(modlink)

        leftscreen=1
        err=['All is well', ' ', ' ', ' ', ' ']

        if returnhit is not None:
            modlink=0
            depojo=0
            depdata=[0,0,0]


# ____________________________________________________________________________________________________________________E.FormVariables.General
# ____________________________________________________________________________________________________________________B.DataUpdates.General

        if modlink==1:
            if oder > 0:
                modata=Driverlog.query.get(oder)
                vals=['cn', 'co', 'gi', 'go', 'ostr', 'osto', 'over', 'tstr', 'tstp', 'drv', 'locstr', 'locstp']
                a=list(range(len(vals)))
                for i,v in enumerate(vals):
                    a[i]=request.values.get(v)

                modata.Clockin=a[0]
                modata.Clockout=a[1]
                modata.GPSin=a[2]
                modata.GPSout=a[3]
                modata.Odomstart=a[4]
                modata.Odomstop=a[5]
                modata.Odverify=a[6]
                modata.Truckstart=a[7]
                modata.Truckstop = a[8]
                modata.Driver = a[9]
                modata.Locationstart = a[10]
                modata.Locationstop = a[11]
                db.session.commit()
                err[3]= 'Modification to Driverlog' + str(modata.id) + ' completed.'
                if update is not None:
                    modlink=0
                    leftsize=10
                else:
                    leftsize=6
                    leftscreen=0
                    modata=Driverlog.query.get(oder)

# ____________________________________________________________________________________________________________________B.GetData.General
        #odata = Driverlog.query.all()
        odata = dataget_Driverlog(thismuch)
# ____________________________________________________________________________________________________________________B.Search.General

        if modlink==0:
            oder,numchecked=numcheck(1,odata,0,0,0,0,['oder'])

# ____________________________________________________________________________________________________________________E.Search.General

# ____________________________________________________________________________________________________________________B.Modify.General
        if (modify is not None or vmod is not None) and numchecked==1 :
            modlink=1
            leftsize=6
            if vmod is not None:
                leftscreen=0

            if oder>0:
                modata=Driverlog.query.get(oder)
                docref=modata.Maintrecord

        if (modify is not None or vmod is not None) and numchecked!=1:
            modlink=0
            err[0]=' '
            err[2]='Must check exactly one box to use this option'
# ____________________________________________________________________________________________________________________E.Modify.General

# ____________________________________________________________________________________________________________________B.Delete.General
        if deletehit is not None and numchecked==1:
            if oder>0:
                #This section is to determine if we can delete the source file along with the data.  If other data is pointing to this
                #file then we need to keep it.
                modata=Driverlog.query.get(oder)

                Driverlog.query.filter(Driverlog.id == oder).delete()
                db.session.commit()
                odata = dataget_Driverlog(thismuch)


        if deletehit is not None and numchecked != 1:
            err=[' ', ' ', 'Must have exactly one item checked to use this option', ' ',  ' ']



        if viewo is not None and numchecked == 1:
            if oder>0:
                modata=Driverlog.query.get(oder)
                docref = f'tmp/{scac}/data/vmaint/' + str(modata.id) + '.pdf'
                leftscreen = 0


        if cache is not None:
            #Save the current cache so we do not start from bad place in future
            udat=users.query.filter(users.name=='cache').first()
            udat.username=str(cache)
            udat.email=oderstring
            db.session.commit()

    else:
        from viewfuncs import popjo, jovec, timedata, nonone, nononef, init_truck_zero
        today = datetime.date.today()
        #today = datetime.datetime.today().strftime('%Y-%m-%d')
        now = datetime.datetime.now().strftime('%I:%M %p')
        oder=0
        modata=0
        modlink=0
        odata = Driverlog.query.all()
        leftscreen=1
        leftsize=10
        docref=''
        err=['All is well', ' ', ' ', ' ',  ' ']
        thismuch = '2'
        udat=users.query.filter(users.name=='Cache').first()
        cache=udat.username
        cache=nonone(cache)
        depdata = [0,0,0]
        odata = dataget_Driverlog(thismuch)

    leftsize = 8


    return odata,oder,err,modata,modlink,leftscreen,leftsize,today,now,docref,cache,thismuch
예제 #13
0
def isoIncM():

    if request.method == 'POST':
        # ____________________________________________________________________________________________________________________B.FormVariables.General

        from viewfuncs import parseline, popjo, jovec, newjo, timedata, nonone, nononef, erud, hasinput
        from viewfuncs import numcheck, numcheckv, viewbuttons, get_ints, numcheckvec, numcheckv

        #Zero and blank items for default
        username = session['username'].capitalize()
        cache = request.values.get('cache')
        cache = nonone(cache)

        modata = 0
        modlink = 0
        docref = ''
        oderstring = ''
        acdeposit = request.values.get('acdeposit')
        if acdeposit is None:
            acdeposit = request.values.get('actype')
        depojo = request.values.get('depojo')
        cofor = request.values.get('cofor')
        depdate = request.values.get('depdate')
        print(depdate, hasinput(depdate))
        if not hasinput(depdate):
            depdate = datetime.datetime.today().strftime('%Y-%m-%d')
        depdata = [acdeposit, cofor, depojo, depdate]
        print(depdata)

        today = datetime.date.today()
        now = datetime.datetime.now().strftime('%I:%M %p')

        leftsize = 10

        match = request.values.get('Match')
        modify = request.values.get('Qmod')
        vmod = request.values.get('Vmod')
        viewo = request.values.get('View')
        returnhit = request.values.get('Return')
        deletehit = request.values.get('Delete')
        delfile = request.values.get('DELF')
        # hidden values
        update = request.values.get('Update')
        newact = request.values.get('NewA')
        thisjob = request.values.get('ThisJob')
        oder = request.values.get('oder')
        modlink = request.values.get('modlink')
        depositmake = request.values.get('depositmake')
        recdeposit = request.values.get('recdeposit')
        unrecord = request.values.get('unrecord')
        thismuch = request.values.get('thismuch')

        oder = nonone(oder)
        modlink = nonone(modlink)

        leftscreen = 1
        err = []

        if returnhit is not None:
            modlink = 0
            depojo = 0
            depdata = [0, 0, 0, depdate]

# ____________________________________________________________________________________________________________________E.FormVariables.General
# ____________________________________________________________________________________________________________________B.DataUpdates.General

        if modlink == 1:
            if oder > 0:
                modata = Income.query.get(oder)
                vals = [
                    'jo', 'account', 'from', 'description', 'amount', 'ref',
                    'pdate', 'original', 'bank', 'depdate', 'depositnum'
                ]
                a = list(range(len(vals)))
                for i, v in enumerate(vals):
                    a[i] = request.values.get(v)

                modata.Jo = a[0]
                modata.Account = a[1]
                modata.From = a[2]
                modata.Description = a[3]
                modata.Amount = a[4]
                modata.Ref = a[5]
                modata.Date = a[6]
                modata.Original = a[7]
                modata.Bank = a[8]
                if a[9] == '': modata.Date2 = None
                else: modata.Date2 = a[9]
                modata.Depositnum = a[10]
                db.session.commit()
                err.append('Modification to Income id ' + str(modata.id) +
                           ' completed.')
                if update is not None:
                    modlink = 0
                    leftsize = 10
                else:
                    leftsize = 6
                    leftscreen = 0
                    modata = Income.query.get(oder)

# ____________________________________________________________________________________________________________________B.GetData.General
#odata = Income.query.all()
        odata = dataget_Inc(thismuch)
        # ____________________________________________________________________________________________________________________B.Search.General

        if modlink == 0:
            oder, numchecked = numcheck(1, odata, 0, 0, 0, 0, ['oder'])

# ____________________________________________________________________________________________________________________E.Search.General

# ____________________________________________________________________________________________________________________B.Modify.General
        if (modify is not None or vmod is not None) and numchecked == 1:
            modlink = 1
            leftsize = 6
            if vmod is not None:
                leftscreen = 0

            if oder > 0:
                modata = Income.query.get(oder)
                docref = modata.Original

        if (modify is not None or vmod is not None) and numchecked != 1:
            modlink = 0
            err.append('Must check exactly one box to use this option')
# ____________________________________________________________________________________________________________________E.Modify.General

# ____________________________________________________________________________________________________________________B.Delete.General
        if deletehit is not None and numchecked == 1:
            if oder > 0:
                #This section is to determine if we can delete the source file along with the data.  If other data is pointing to this
                #file then we need to keep it.
                modata = Income.query.get(oder)

                Income.query.filter(Income.id == oder).delete()
                db.session.commit()
                odata = dataget_Inc(thismuch)

        if deletehit is not None and numchecked != 1:
            err.append('Must have exactly one item checked to use this option')

        acctsel = request.values.get('actype')
        if acctsel is not None and not hasinput(depojo):
            print(f'Getting depojo acctsel {acctsel}')
            cofor = 0
            if oder > 0:
                inc = Income.query.get(oder)
                jo = inc.Jo
                cofor = jo[0] + 'D'
            else:
                acdat = Accounts.query.filter(Accounts.Name == acctsel).first()
                if acdat is not None:
                    cofor = acdat.Co + 'D'
            if cofor != 0:
                todayyf = datetime.datetime.today().strftime('%Y-%m-%d')
                depojo = newjo(cofor, todayyf)
                depdata = [acctsel, cofor, depojo, depdate]

# ____________________________________________________________________________________________________________________E.Delete.General
        if (depositmake is not None
                or recdeposit is not None) and depojo is not None:
            err.append('Must have exactly one item checked to use this option')

            odervec = numcheckv(odata)
            if len(odervec) > 0:
                oderstring = json.dumps(odervec)
            else:
                udat = users.query.filter(users.name == 'cache').first()
                oderstring = udat.email
                odervec = json.loads(oderstring)

            if odervec is not None:
                cache = request.values.get('cache')
                if cache is None:
                    cache = 2

                if recdeposit is not None:
                    cache, docref = reportmaker('recdeposit', odervec)
                    depojo = request.values.get('depojo')
                    sourcelist = []
                    for oder in odervec:
                        idat = Income.query.get(oder)
                        fromco = idat.From
                        if fromco is None:
                            cdat = People.query.get(idat.Pid)
                            if cdat is not None:
                                fromco = cdat.Company
                            else:
                                fromco = 'Unknown Source'
                        if fromco not in sourcelist: sourcelist.append(fromco)
                        ref = idat.Ref
                        acct = idat.Account
                        bank = request.values.get('acdeposit')
                        date2 = request.values.get('depdate')
                        if len(ref) > 2 and ref != 'ChkNo':
                            idata = Income.query.filter(
                                (Income.Account == acct)
                                & (Income.Ref == ref)).all()
                            for data in idata:
                                data.Depositnum = depojo
                                data.Bank = bank
                                data.Date2 = date2
                                data.From = fromco
                                data.Original = os.path.basename(docref)
                                db.session.commit()
                        else:
                            idat.Bank = bank
                            idat.Date2 = date2
                            idat.Depositnum = depojo
                            idat.From = fromco
                            idat.Original = os.path.basename(docref)
                            db.session.commit()

                    print('Here', depojo, acctsel)
                    if len(sourcelist) == 1:
                        sendsource = sourcelist[0]
                    else:
                        sendsource = json.dumps(sourcelist)
                        if len(sendsource) > 49:
                            sendsource = 'Multiple Sources'

                    from gledger_write import gledger_write
                    gledger_write('deposit', depojo, acctsel, sendsource)

                else:
                    print(odervec)
                    cache, docref = reportmaker('deposit', odervec)

                leftscreen = 0

        if unrecord is not None and numchecked == 1:
            if oder > 0:
                modata = Income.query.get(oder)
                subjo = modata.SubJo
                idata = Income.query.filter(Income.SubJo == subjo).all()
                for idat in idata:
                    idat.SubJo = 'Mremit'
                    db.session.commit()
                jdat = JO.query.filter(JO.jo == subjo).first()
                if jdat is not None:
                    jdat.dinc = '0.00'
                    db.session.commit()
                Gledger.query.filter(Gledger.Tcode == subjo).delete()
                db.session.commit()

        if viewo is not None and numchecked == 1:
            if oder > 0:
                modata = Income.query.get(oder)
                filename = modata.Depositnum
                docref = f'tmp/{scac}/data/vdeposits/' + filename + '.pdf'
                leftscreen = 0

        if unrecord is not None and numchecked != 1:
            modlink = 0
            err.append('Must check exactly one box to use this option')

        if cache is not None:
            #Save the current cache so we do not start from bad place in future
            udat = users.query.filter(users.name == 'cache').first()
            udat.username = str(cache)
            udat.email = oderstring
            db.session.commit()

    #This is the else for 1st time through (not posting data from overseas.html)
    else:
        from viewfuncs import popjo, jovec, timedata, nonone, nononef, init_truck_zero, erud
        today = datetime.date.today()
        today_str = datetime.datetime.today().strftime('%Y-%m-%d')
        now = datetime.datetime.now().strftime('%I:%M %p')
        oder = 0
        modata = 0
        modlink = 0
        odata = Income.query.all()
        leftscreen = 1
        leftsize = 10
        docref = ''
        err = ['Ready to make and review account deposits']
        thismuch = '2'
        udat = users.query.filter(users.name == 'Cache').first()
        cache = udat.username
        cache = nonone(cache)
        depdata = [0, 0, 0, today_str]
        odata = dataget_Inc(thismuch)

    leftsize = 8
    acdata = Accounts.query.filter(Accounts.Type == 'Bank').all()
    err = erud(err)

    return odata, oder, err, modata, modlink, leftscreen, leftsize, today, now, docref, cache, acdata, thismuch, depdata
예제 #14
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
예제 #15
0
def isoDeposit():

    if request.method == 'POST':
        # ____________________________________________________________________________________________________________________B.FormVariables.General

        from viewfuncs import parseline, popjo, jovec, newjo, timedata, nonone, nononef, erud, hasinput
        from viewfuncs import numcheck, numcheckv, viewbuttons, get_ints, numcheckvec, numcheckv, d2s

        #Zero and blank items for default
        username = session['username'].capitalize()
        cache = request.values.get('cache')
        cache = nonone(cache)

        modata = 0
        modlink = 0
        docref = ''
        oderstring = ''
        acdeposit = request.values.get('acdeposit')
        if acdeposit is None:
            acdeposit = request.values.get('actype')
        depojo = request.values.get('depojo')
        cofor = request.values.get('cofor')
        depdate = request.values.get('depdate')
        print(depdate, hasinput(depdate))
        if not hasinput(depdate):
            depdate = datetime.datetime.today().strftime('%Y-%m-%d')
        depdata = [acdeposit, cofor, depojo, depdate]
        print(depdata)

        today = datetime.date.today()
        now = datetime.datetime.now().strftime('%I:%M %p')

        leftsize = 10

        match = request.values.get('Match')
        modify = request.values.get('Qmod')
        vmod = request.values.get('Vmod')
        viewo = request.values.get('View')
        returnhit = request.values.get('Return')
        deletehit = request.values.get('Delete')
        delfile = request.values.get('DELF')
        # hidden values
        update = request.values.get('Update')
        newact = request.values.get('NewA')
        thisjob = request.values.get('ThisJob')
        oder = request.values.get('oder')
        modlink = request.values.get('modlink')
        depositmake = request.values.get('depositmake')
        recdeposit = request.values.get('recdeposit')
        unrecord = request.values.get('unrecord')
        thismuch = request.values.get('thismuch')

        oder = nonone(oder)
        modlink = nonone(modlink)

        leftscreen = 1
        err = []

        if returnhit is not None:
            modlink = 0
            depojo = 0
            depdata = [0, 0, 0, depdate]

# ____________________________________________________________________________________________________________________E.FormVariables.General
# ____________________________________________________________________________________________________________________B.DataUpdates.General

# ____________________________________________________________________________________________________________________B.GetData.General
        odata = dataget_Dep(thismuch)
        gdata = undeposited(thismuch)
        # ____________________________________________________________________________________________________________________B.Search.General

        if modlink == 0:
            oder, numchecked = numcheck(1, gdata, 0, 0, 0, 0, ['oder'])

# ____________________________________________________________________________________________________________________E.Search.General

        acctsel = request.values.get('actype')
        if acctsel is not None and not hasinput(depojo):
            print(f'Getting depojo acctsel {acctsel}')
            cofor = 0
            if oder > 0:
                inc = Gledger.query.get(oder)
                jo = inc.Tcode
                cofor = jo[0] + 'D'
            else:
                acdat = Accounts.query.filter(Accounts.Name == acctsel).first()
                if acdat is not None:
                    cofor = acdat.Co + 'D'
            if cofor != 0:
                todayyf = datetime.datetime.today().strftime('%Y-%m-%d')
                depojo = newjo(cofor, todayyf)
                depdata = [acctsel, cofor, depojo, depdate]

# ____________________________________________________________________________________________________________________E.Delete.General
        if (depositmake is not None
                or recdeposit is not None) and depojo is not None:
            odervec = numcheckv(gdata)
            print('odervec', odervec)
            if len(odervec) > 0:
                try:
                    oderstring = json.dumps(odervec)
                except:
                    oderstring = ''
            else:
                udat = users.query.filter(users.name == 'cache').first()
                oderstring = udat.email
                odervec = json.loads(oderstring)

            if odervec is not None:
                cache = request.values.get('cache')
                if cache is None:
                    cache = 2

                if recdeposit is not None:
                    cache, docref = reportmaker('recdeposit', odervec)
                    depojo = request.values.get('depojo')
                    sourcelist = []
                    total = 0.00
                    for oder in odervec:
                        idat = Gledger.query.get(oder)
                        amount = float(idat.Debit) / 100.
                        total = total + amount

                    for oder in odervec:
                        idat = Gledger.query.get(oder)
                        fromco = idat.Source
                        amount = d2s(float(idat.Debit) / 100.)
                        sid = idat.Sid
                        jo = idat.Tcode
                        ref = idat.Ref

                        if fromco is None:
                            cdat = People.query.get(idat.Sid)
                            if cdat is not None:
                                fromco = cdat.Company
                            else:
                                fromco = 'Unknown Source'
                        if fromco not in sourcelist: sourcelist.append(fromco)

                        acct = idat.Account
                        bank = request.values.get('acdeposit')
                        date2 = request.values.get('depdate')
                        ddat = Deposits.query.filter(
                            Deposits.Jo == idat.Tcode).first()
                        if ddat is None:
                            input = Deposits(Jo=jo,
                                             Account=acct,
                                             Pid=sid,
                                             Amount=amount,
                                             Total=d2s(total),
                                             Ref=ref,
                                             Date=date2,
                                             Original=os.path.basename(docref),
                                             From=fromco,
                                             Bank=bank,
                                             Date2=today,
                                             Depositnum=depojo)
                            db.session.add(input)
                            db.session.commit()
                        else:
                            ddat.Depositnum = depojo
                            ddat.Bank = bank
                            ddat.Date2 = date2
                            ddat.From = fromco
                            ddat.Original = os.path.basename(docref)
                            db.session.commit()

                    print('Here', depojo, acctsel)
                    if len(sourcelist) == 1:
                        sendsource = sourcelist[0]
                    else:
                        sendsource = json.dumps(sourcelist)
                        if len(sendsource) > 49:
                            sendsource = 'Multiple Sources'

                    from gledger_write import gledger_write
                    gledger_write('deposit', depojo, acctsel, sendsource)

                else:
                    print(odervec)
                    cache, docref = reportmaker('deposit', odervec)

                leftscreen = 0

        if unrecord is not None and numchecked == 1:
            if oder > 0:
                modata = Income.query.get(oder)
                subjo = modata.SubJo
                idata = Income.query.filter(Income.SubJo == subjo).all()
                for idat in idata:
                    idat.SubJo = 'Mremit'
                    db.session.commit()
                jdat = JO.query.filter(JO.jo == subjo).first()
                if jdat is not None:
                    jdat.dinc = '0.00'
                    db.session.commit()
                Gledger.query.filter(Gledger.Tcode == subjo).delete()
                db.session.commit()

        if viewo is not None and numchecked == 1:
            if oder > 0:
                modata = Income.query.get(oder)
                filename = modata.Depositnum
                docref = f'tmp/{scac}/data/vdeposits/' + filename + '.pdf'
                leftscreen = 0

        if unrecord is not None and numchecked != 1:
            modlink = 0
            err.append('Must check exactly one box to use this option')

        if cache is not None:
            #Save the current cache so we do not start from bad place in future
            udat = users.query.filter(users.name == 'cache').first()
            udat.username = str(cache)
            udat.email = oderstring
            db.session.commit()

    #This is the else for 1st time through (not posting data from overseas.html)
    else:
        from viewfuncs import popjo, jovec, timedata, nonone, nononef, init_truck_zero, erud
        today = datetime.date.today()
        today_str = datetime.datetime.today().strftime('%Y-%m-%d')
        now = datetime.datetime.now().strftime('%I:%M %p')
        oder = 0
        modata = 0
        modlink = 0
        leftscreen = 1
        leftsize = 10
        docref = ''
        err = ['Ready to make and review account deposits']
        thismuch = '2'
        udat = users.query.filter(users.name == 'Cache').first()
        cache = udat.username
        cache = nonone(cache)
        depdata = [0, 0, 0, today_str]
        gdata = undeposited(thismuch)
        odata = dataget_Dep(thismuch)

    leftsize = 8
    acdata = Accounts.query.filter(Accounts.Type == 'Bank').all()
    err = erud(err)

    return odata, gdata, oder, err, modata, modlink, leftscreen, leftsize, today, now, docref, cache, acdata, thismuch, depdata
예제 #16
0
def isoH():

    if request.method == 'POST':
        username = session['username'].capitalize()
        from viewfuncs import d2s, newjo, popjo, jovec, timedata, nonone, nononef, GetCo, init_horizon_zero, numcheck, sdiff, calendar7_weeks, GetCo3
        cars, auto, peep, invo, cache, modata, modlink, invooder, stamp, fdata, csize, invodate, inco, cdat, pb, passdata, vdata, caldays, daylist, weeksum, nweeks = init_horizon_zero(
        )
        filesel = ''
        docref = ''
        doctxt = ''
        displdata = 0
        err = ['All is well', ' ', ' ', ' ', ' ']

        # ____________________________________________________________________________________________________________________B.FormVariables.Dealer
        leftsize = 10
        today = datetime.date.today()
        jobdate = datetime.date.today()

        match = request.values.get('Match')
        modify = request.values.get('Modify')
        vmod = request.values.get('Vmod')
        minvo = request.values.get('MakeI')
        mbill = request.values.get('MakeB')
        viewo = request.values.get('ViewO')
        viewi = request.values.get('ViewI')
        addE = request.values.get('addentity')
        addA = request.values.get('addauto')
        returnhit = request.values.get('Return')
        deletehit = request.values.get('Delete')
        datatable1 = request.values.get('datatable1')
        datatable2 = request.values.get('datatable2')
        datatable3 = request.values.get('datatable3')
        dlist = [datatable1, datatable2, datatable3]

        # hidden values
        update = request.values.get('Update')
        invoupdate = request.values.get('invoUpdate')
        modlink = request.values.get('passmodlink')
        emailnow = request.values.get('emailnow')
        emailinvo = request.values.get('emailInvo')
        newjob = request.values.get('NewJ')
        thisjob = request.values.get('ThisJob')
        recpay = request.values.get('RecPay')
        hispay = request.values.get('HisPay')
        recupdate = request.values.get('recUpdate')

        calendar = request.values.get('Calendar')
        calupdate = request.values.get('calupdate')

        cars = request.values.get('cars')
        peep = request.values.get('peep')
        auto = request.values.get('auto')

        invo = request.values.get('invo')
        invooder = request.values.get('invooder')
        cache = request.values.get('cache')

        modata = 0
        idata = 0
        leftscreen = 1
        docref = ''
        ldata = None

        modlink = nonone(modlink)
        cars = nonone(cars)
        peep = nonone(peep)
        auto = nonone(auto)

        invo = nonone(invo)
        invooder = nonone(invooder)
        cache = nonone(cache)

        if returnhit is not None:
            modlink = 0
            invooder = 0
            cars = 0
            invo = 0

# ____________________________________________________________________________________________________________________E.FormVariables.Dealer
# ____________________________________________________________________________________________________________________B.DataModifications.Dealer

        if update is not None and modlink == 2:
            modata = People.query.get(peep)
            vals = [
                'company', 'fname', 'mnames', 'lname', 'addr1', 'addr2',
                'addr3', 'idtype', 'tid', 'tel', 'email', 'assoc1', 'assoc2',
                'date1', 'ptype'
            ]
            a = list(range(len(vals)))
            i = 0
            for v in vals:
                a[i] = request.values.get(v)
                i = i + 1

            try:
                sdate1dt = datetime.datetime.strptime(a[13], "%Y-%m-%d")
            except:
                a[13] = datetime.datetime.today().strftime('%Y-%m-%d')

            input = People(Company=a[0],
                           First=a[1],
                           Middle=a[2],
                           Last=a[3],
                           Addr1=a[4],
                           Addr2=a[5],
                           Addr3=a[6],
                           Idtype=a[7],
                           Idnumber=a[8],
                           Telephone=a[9],
                           Email=a[10],
                           Associate1=a[11],
                           Associate2=a[12],
                           Date1=a[13],
                           Ptype=a[14],
                           Date2=None,
                           Original=None,
                           Temp1=None,
                           Temp2=None)
            db.session.add(input)
            db.session.commit()
            err = [' ', ' ', 'New Entity Added to Database.', ' ', ' ']
            modlink = 0

        if (update is not None and modlink == 1) or (update is not None
                                                     and modlink == 10):
            if cars > 0:
                modata = Dealer.query.get(cars)
                vals = [
                    'cost', 'sale', 'bfee', 'tow', 'repair', 'oitem', 'ocost',
                    'modelyear', 'make', 'model', 'color', 'vin', 'dfee',
                    'thiscompany'
                ]
                a = list(range(len(vals)))
                i = 0
                for v in vals:
                    a[i] = request.values.get(v)
                    i = i + 1
                modata.Cost = a[0]
                modata.Sale = a[1]
                modata.Bfee = a[2]
                modata.Tow = a[3]
                modata.Repair = a[4]
                modata.Oitem = a[5]
                modata.Ocost = a[6]
                modata.Year = a[7]
                modata.Make = a[8]
                modata.Model = a[9]
                modata.Color = a[10]
                modata.Vin = a[11]
                modata.DocumentFee = a[12]
                modata.Company = a[13]
                pdat = People.query.filter(People.Company == a[13]).first()
                if pdat is not None:
                    modata.Pid = pdat.id
                try:
                    modata.Label = modata.Jo + ' ' + a[13]
                except:
                    err[4] = 'Cannot create Label with missing information (company, Year, Make, Model)'
                db.session.commit()
                err = [
                    ' ', ' ', 'Modification to Auto Sale JO ' + modata.Jo +
                    ' completed.', ' ', ' '
                ]
                modlink = 0

            if peep > 0:
                modata = People.query.get(peep)
                vals = [
                    'company', 'fname', 'mnames', 'lname', 'addr1', 'addr2',
                    'addr3', 'idtype', 'tid', 'tel', 'email', 'assoc1',
                    'assoc2', 'date1', 'role'
                ]
                a = list(range(len(vals)))
                i = 0
                for v in vals:
                    a[i] = request.values.get(v)
                    i = i + 1

                modata.First = a[1]
                modata.Middle = a[2]
                modata.Last = a[3]
                modata.Addr1 = a[4]
                modata.Addr2 = a[5]
                modata.Addr3 = a[6]
                modata.Idtype = a[7]
                modata.Idnumber = a[8]
                modata.Telephone = a[9]
                modata.Email = a[10]
                modata.Associate1 = a[11]
                modata.Associate2 = a[12]
                modata.Date1 = a[13]
                modata.Ptype = a[14]
                #Need to infuse change into Autos if it is a Tow Company:
                if modata.Ptype == 'TowCo' or a[14] == 'TowCo':
                    adat = Autos.query.filter(
                        Autos.TowCompany == modata.Company).first()
                    if adat is not None:
                        adat.TowCompany = a[0]

                modata.Company = a[0]

                db.session.commit()
                err = [
                    ' ', ' ', 'Modification to Entity ID ' + str(modata.id) +
                    ' completed.', ' ', ' '
                ]
                modlink = 0

            if auto > 0 or modlink == 10:

                if modlink == 10:
                    filesel = request.values.get('FileSel')
                    if filesel != '1':
                        oldref = f'tmp/{scac}/data/vunknown/' + filesel
                        oldtxt = oldref.split('.', 1)[0] + '.txt'
                    else:
                        oldref = ''
                        oldtxt = ''
                    modata = Autos.query.filter(Autos.Status == 'New').first()
                    auto = modata.id
                    docref = f'tmp/{scac}/data/vdispatch/DISP' + str(
                        auto) + '.pdf'
                    doctxt = f'tmp/{scac}/data/vdispatch/DISP' + str(
                        auto) + '.txt'
                    try:
                        shutil.move(addpath(oldref), addpath(docref))
                    except:
                        err[3] = '.pdf file already moved'
                    try:
                        shutil.move(addpath(oldtxt), addpath(doctxt))
                    except:
                        err[4] = '.txt file already moved'
                    modata.Original = docref
                    modlink = 0
                else:
                    modata = Autos.query.get(auto)

                vals = [
                    'modelyear', 'make', 'model', 'color', 'vin', 'title',
                    'state', 'empweight', 'dispatched', 'owner', 'towcompany',
                    'towcost', 'delto', 'orderid', 'newtowcompany',
                    'towcostea', 'pufrom', 'cvalue', 'ncars'
                ]
                a = list(range(len(vals)))
                for i, v in enumerate(vals):
                    a[i] = request.values.get(v)
                modata.Year = a[0]
                modata.Make = a[1]
                modata.Model = a[2]
                modata.Color = a[3]
                modata.VIN = a[4]
                modata.Title = a[5]
                modata.State = a[6]
                modata.EmpWeight = a[7]
                modata.Dispatched = a[8]
                modata.Owner = a[9]
                company = a[10]
                if company == '1':
                    modata.TowCompany = a[14]
                    input = People(Company=a[14],
                                   First='',
                                   Middle='',
                                   Last='',
                                   Addr1='',
                                   Addr2='',
                                   Addr3='',
                                   Idtype='',
                                   Idnumber='',
                                   Telephone='',
                                   Email='',
                                   Associate1='',
                                   Associate2='',
                                   Date1=today,
                                   Date2=None,
                                   Original='',
                                   Ptype='TowCo',
                                   Temp1='',
                                   Temp2='')
                    db.session.add(input)
                    modata.TowCompany = a[14]
                else:
                    modata.TowCompany = company
                modata.TowCost = d2s(a[11])
                modata.Delto = a[12]
                modata.Pufrom = a[16]
                modata.Value = d2s(a[17])
                ncars = a[18]
                try:
                    ncars = int(a[18])
                    towcost = float(d2s(a[11]))
                    towcostea = towcost / float(ncars)
                    towcostea = str(towcostea)
                    towcostea = d2s(towcostea)
                    modata.TowCostEa = towcostea
                except:
                    modata.TowCostEa = a[15]
                    ncars = 0
                modata.Ncars = ncars
                sdate1 = request.values.get('date1')
                try:
                    sdate1dt = datetime.datetime.strptime(sdate1, "%Y-%m-%d")
                except:
                    sdate1 = today.strftime('%Y-%m-%d')

                sdate2 = request.values.get('date2')
                try:
                    sdate2dt = datetime.datetime.strptime(sdate2, "%Y-%m-%d")
                except:
                    sdate2 = today.strftime('%Y-%m-%d')
                modata.Date1 = sdate1
                modata.Date2 = sdate2
                modata.Orderid = a[13]
                modata.Status = 'Novo'

                db.session.commit()
                err = [
                    ' ', ' ', 'Modification to Auto Data ' + str(modata.id) +
                    ' completed.', ' ', ' '
                ]
                modlink = 0

# ____________________________________________________________________________________________________________________E.DataModifications.Dealer
# ____________________________________________________________________________________________________________________B.InvoiceUpdate.Dealer

        if invoupdate is not None:
            leftsize = 8
            hdata1 = Dealer.query.get(invooder)
            invodate = request.values.get('invodate')
            #if invodate is None:
            #invodate=today
            idata = Invoices.query.filter(Invoices.Jo == hdata1.Jo).all()
            for data in idata:
                iqty = request.values.get('qty' + str(data.id))
                iqty = nononef(iqty)
                data.Description = request.values.get('desc' + str(data.id))
                deach = request.values.get('cost' + str(data.id))
                if deach is not None:
                    deach = "{:.2f}".format(float(deach))
                else:
                    deach = "{:.2f}".format(0.00)
                data.Qty = iqty
                data.Ea = deach
                data.Date = invodate
                db.session.commit()
            #Remove zeros from invoice in case a zero was the mod
            Invoices.query.filter(Invoices.Qty == 0).delete()
            db.session.commit()
            #Create invoice code for order
            err = [' ', ' ', 'Invoice created for JO: ' + hdata1.Jo, ' ', ' ']
            idat = Invoices.query.filter(Invoices.Jo == hdata1.Jo).first()
            invodate = idat.Date

            idata = Invoices.query.filter(Invoices.Jo == hdata1.Jo).all()
            amt = 0.0
            for data in idata:
                amt = amt + float(data.Qty) * float(data.Ea)
            hdata1.Charge = "%0.2f" % amt
            hdata1.Status = 'Invoiced'
            db.session.commit()
            invo = 1
            # Regenerate invoice with new data
            idata = Invoices.query.filter(Invoices.Jo == hdata1.Jo).order_by(
                Invoices.Ea.desc()).all()
            pdat = People.query.filter(People.id == hdata1.Pid).first()
            cache = cache + 1

            import make_H_invoice
            make_H_invoice.main(hdata1, idata, pdat, cache, invodate, 0)

            if cache > 0:
                docref = f'tmp/{scac}/data/vinvoice/INV' + hdata1.Jo + 'c' + str(
                    cache) + '.pdf'
            else:
                docref = f'tmp/{scac}/data/vinvoice/INV' + hdata1.Jo + '.pdf'
            hdata1.Ipath = docref
            hdata1.Cache = cache
            db.session.commit()
            leftscreen = 0
            err[3] = 'invooder=' + str(invooder)
            err[4] = 'Viewing ' + docref
            modata = Dealer.query.get(invooder)
# ____________________________________________________________________________________________________________________E.InvoiceUpdate.Dealer
# ____________________________________________________________________________________________________________________B.SetBaseData.Dealer

        hdata = Dealer.query.all()
        adata = Autos.query.all()
        pdata = People.query.filter((People.Ptype == 'Jays')
                                    | (People.Ptype == 'TowCo')).all()
        # ____________________________________________________________________________________________________________________E.SetBaseData.Dealer
        # ____________________________________________________________________________________________________________________B.Numcheck.Dealer

        try:
            cars, auto, peep, numchecked = numcheck(3, hdata, adata, pdata, 0,
                                                    0,
                                                    ['cars', 'auto', 'peep'])
        except:
            cars = 0
            auto = 0
            peep = 0
            numchecked = 0

# ____________________________________________________________________________________________________________________E.Numcheck.Dealer
# ____________________________________________________________________________________________________________________B.Views.Dealer

        if (viewo is not None or viewi is not None) and numchecked == 1:
            err = [
                ' ', ' ', 'There is no document available for this selection',
                ' ', ' '
            ]

            if cars > 0 and viewi is not None:
                modata = Dealer.query.get(cars)
                if modata.Ipath is not None:
                    docref = modata.Ipath

            if cars > 0 and viewo is not None:
                modata = Dealer.query.get(cars)
                if modata.Apath is not None:
                    docref = modata.Apath

            if auto > 0:
                modata = Autos.query.get(auto)
                if modata.Original is not None:
                    docref = modata.Original

            if (auto > 0 or cars > 0) and docref:
                if len(docref) > 5:
                    leftscreen = 0
                    leftsize = 10
                    modlink = 0
                    err = ['All is well', ' ', ' ', ' ', ' ']

        if (viewo is not None or viewi is not None) and numchecked != 1:
            err = [
                'Must check exactly one box to use this option', ' ', ' ', ' ',
                ' '
            ]
# ____________________________________________________________________________________________________________________E.Views.Dealer
# ____________________________________________________________________________________________________________________B.ModifySetup.Dealer

        if (modify is not None or vmod is not None) and numchecked == 1:
            modlink = 1
            leftsize = 8
            if cars > 0:
                fdata = myoslist(f'tmp/{scac}/data/vunknown')
                fdata.sort()
                modata = Dealer.query.get(cars)
                jobdate = modata.Date
                if vmod is not None:
                    err = [
                        ' ', ' ',
                        'There is no document available for this selection',
                        ' ', ' '
                    ]
                    if modata.Apath is not None:
                        if len(modata.Apath) > 5:
                            leftscreen = 0
                            docref = f'tmp/{scac}/data/vcarbuy/' + modata.Apath
                            err = ['All is well', ' ', ' ', ' ', ' ']

            if peep > 0:
                modata = People.query.get(peep)
                if vmod is not None:
                    err = [
                        ' ', ' ',
                        'There is no document available for this selection',
                        ' ', ' '
                    ]
                    if modata.Original is not None:
                        if len(modata.Original) > 5:
                            leftscreen = 0
                            docref = f'tmp/{scac}/data/vpersons/' + modata.Original
                            err = ['All is well', ' ', ' ', ' ', ' ']
            if auto > 0:
                modata = Autos.query.get(auto)
                if vmod is not None:
                    err = [
                        ' ', ' ',
                        'There is no document available for this selection',
                        ' ', ' '
                    ]
                    if modata.Original is not None:
                        if len(modata.Original) > 5:
                            leftscreen = 0
                            leftsize = 8
                            docref = modata.Original
                            doctxt = docref.split('.', 1)[0] + '.txt'
                            err = ['All is well', ' ', ' ', ' ', ' ']

        if (modify is not None or vmod is not None) and numchecked != 1:
            modlink = 0
            err[0] = ' '
            err[2] = 'Must check exactly one box to use this option'
# ____________________________________________________________________________________________________________________E.ModifySetup.Dealer
# ____________________________________________________________________________________________________________________B.AddItemsSetup.Dealer

        if addE is not None and peep > 0 and numchecked == 1:
            modlink = 2
            modata = People.query.get(peep)

        if addE is not None:
            leftsize = 8
            modlink = 1
            #We will create a blank line and simply modify that by updating:
            input = People(Company='New',
                           First=None,
                           Middle=None,
                           Last=None,
                           Addr1=None,
                           Addr2=None,
                           Addr3=None,
                           Idtype=None,
                           Idnumber=None,
                           Telephone=None,
                           Email=None,
                           Associate1=None,
                           Associate2=None,
                           Date1=None,
                           Date2=None,
                           Original=None,
                           Ptype='Dealer',
                           Temp1=None,
                           Temp2=None,
                           Accountid=None)
            db.session.add(input)
            db.session.commit()
            modata = People.query.filter((People.Company == 'New')
                                         & (People.Ptype == 'Dealer')).first()
            if modata is not None:
                peep = modata.id
            else:
                peep = 0
            err = [' ', ' ', 'Enter Data for New Entity', ' ', ' ']

        if addA is not None or modlink == 10:
            leftscreen = 0
            leftsize = 8
            if modlink == 10:
                titledata = General.query.filter(
                    (General.Subject.contains('title'))
                    & (General.Category.contains('1'))).all()
                fdata = []
                displdata = []
                for title in titledata:
                    fdata.append(title.Path)
                    displdata.append(title.Category)
                filesel = request.values.get('FileSel')
                docref = f'tmp/{scac}/data/vgeneral/' + filesel
                doctxt = docref.split('.', 1)[0] + '.txt'

            if modlink != 10:
                titledata = General.query.filter(
                    (General.Subject.contains('title'))
                    & (General.Category.contains('1'))).all()
                fdata = []
                displdata = []
                for title in titledata:
                    file1 = f'tmp/{scac}/data/vgeneral/' + title.Path
                    fdata.append(title.Path)
                    displdata.append(title.Category)

                docref = f'tmp/{scac}/data/vgeneral/' + fdata[0]
                doctxt = ''
                #We will create a blank line and simply modify that by updating:
                input = Autos(Jo=None,
                              Hjo=None,
                              Year=None,
                              Make=None,
                              Model=None,
                              Color=None,
                              VIN=None,
                              Title=None,
                              State=None,
                              EmpWeight=None,
                              Dispatched=None,
                              Value=None,
                              TowCompany=None,
                              TowCost=None,
                              TowCostEa=None,
                              Original=None,
                              Status='New',
                              Date1=None,
                              Date2=None,
                              Pufrom=None,
                              Delto=None,
                              Ncars=None,
                              Orderid=None)
                db.session.add(input)
                db.session.commit()
                modata = Autos.query.filter(Autos.Status == 'New').first()
                if modata is not None:
                    auto = modata.id
                else:
                    auto = 0
                modlink = 10

            err = [' ', ' ', 'Enter Data for New Auto', ' ', ' ']
# ____________________________________________________________________________________________________________________E.AddItemsSetup.Dealer
# ____________________________________________________________________________________________________________________B.Email.Dealer

        if emailinvo is not None:
            leftsize = 8
            leftscreen = 0
            modlink = 0
            modata = Dealerquery.get(invooder)
            ldata = Invoices.query.filter(Invoices.Jo == modata.Jo).order_by(
                Invoices.Ea.desc()).all()
            jo = modata.Jo
            pdat = People.query.filter(People.id == modata.Pid).first()
            if pdat is None:
                err = [
                    ' ', ' ',
                    'There is no Billing information for this selection', ' ',
                    ' '
                ]
            else:
                email = pdat.Email
            docref = modata.Ipath
            modata.Status = 'EmlInvo'
            db.session.commit()

            if 'vinvoice' not in docref:
                err = [
                    ' ', ' ',
                    'There is no document available for this selection', ' ',
                    ' '
                ]
            else:
                if email is not None:
                    import invoice_mimemail2
                    invoice_mimemail2.main(jo, docref, email)
# ____________________________________________________________________________________________________________________E.Email.Dealer
# ____________________________________________________________________________________________________________________B.Delete.Dealer

        if deletehit is not None and numchecked == 1:
            if cars > 0:
                Dealer.query.filter(Dealer.id == cars).delete()
            if peep > 0:
                People.query.filter(People.id == peep).delete()
            if auto > 0:
                Autos.query.filter(Autos.id == auto).delete()
            db.session.commit()

            pdata = GetCo('Jays', 'All')
            hdata = Dealer.query.order_by(Dealer.Jo).all()
            adata = Autos.query.all()

        if deletehit is not None and numchecked != 1:
            err = [
                ' ', ' ',
                'Must have exactly one item checked to use this option', ' ',
                ' '
            ]
# ____________________________________________________________________________________________________________________E.Delete.Dealer
# ____________________________________________________________________________________________________________________B.ReceivePayment.Dealer

        if (recpay is not None and cars > 0
                and numchecked == 1) or recupdate is not None:
            leftsize = 8
            if recpay is not None:
                invooder = cars
            hdat = Dealer.query.get(invooder)
            invojo = hdat.Jo
            ldat = Invoices.query.filter(Invoices.Jo == invojo).first()
            err = ['Have no Invoice to Receive Against', ' ', ' ', ' ', ' ']
            if ldat is not None:
                idate = ldat.Date
                if ldat.Original is not None:
                    docref = ldat.Original
                    leftscreen = 0
                    leftsize = 8

                incdat = Income.query.filter(Income.Jo == invojo).first()
                if incdat is None:
                    err = ['Creating New Payment on Jo', ' ', ' ', ' ', ' ']
                    paydesc = 'Receive payment on Invoice ' + invojo
                    recamount = str(ldat.Amount)
                    custref = 'ChkNo'
                    recdate = today
                    input = Income(Jo=hdat.Jo,
                                   SubJo=None,
                                   Pid=hdat.Pid,
                                   Description=paydesc,
                                   Amount=recamount,
                                   Ref=custref,
                                   Date=recdate,
                                   Original=None)
                    db.session.add(input)
                    payment = 0
                else:
                    recamount = request.values.get('recamount')
                    custref = request.values.get('custref')
                    desc = request.values.get('desc')
                    recdate = request.values.get('recdate')
                    incdat.Amount = recamount
                    incdat.Ref = custref
                    incdat.Description = desc
                    incdat.Date = recdate
                db.session.commit()
                payment = [recamount, custref, recdate]

                modata = Income.query.filter(Income.Jo == invojo).first()
                inco = modata.id
                err = [' ', ' ', 'Amend Payment for Invoice', ' ', ' ']

                ldata = Invoices.query.filter(Invoices.Jo == invojo).order_by(
                    Invoices.Ea.desc()).all()
                pdat = People.query.filter(People.id == hdat.Pid).first()
                cache = nonone(hdat.Cache) + 1

                import make_H_invoice
                make_H_invoice.main(hdat, ldata, pdat, cache, invodate,
                                    payment)

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

                hdat.Cache = cache
                hdat.Status = 'Paid'
                idat = Invoices.query.filter(Invoices.Jo == invojo).first()
                idat.Original = docref
                db.session.commit()
                leftscreen = 0
                err[4] = 'Viewing ' + docref

        if recpay is not None and (cars == 0 or numchecked != 1):
            err = ['Invalid selections:', '', '', '', '']
            if cars == 0:
                err[1] = 'Must select a Dealer Job'
            if numchecked != 1:
                err[2] = 'Must select exactly one Dealer Job'
# ____________________________________________________________________________________________________________________E.Receive Payment.Dealer
# ____________________________________________________________________________________________________________________B.Payment History.Dealer
        if hispay is not None or modlink == 7:
            if cars == 0 and invooder == 0:
                err[1] = 'Must select an Dealer Job'
            else:
                if cars != 0:
                    invooder = cars
                modata = Dealer.query.get(invooder)
                idata = Invoices.query.filter(
                    Invoices.Jo == modata.Jo).order_by(Invoices.Jo).all()
                fdata = Income.query.filter(Income.Jo == modata.Jo).order_by(
                    Income.Jo).all()
                #Check to see if we need to delete anything from history
                killthis = request.values.get('killthis')
                if killthis is not None and modlink == 7:
                    for data in idata:
                        testone = request.values.get('bill' + str(data.id))
                        if testone:
                            kill = int(testone)
                            Invoices.query.filter(Invoices.id == kill).delete()
                            db.session.commit()
                    for data in fdata:
                        testone = request.values.get('pay' + str(data.id))
                        if testone:
                            kill = int(testone)
                            Income.query.filter(Income.id == kill).delete()
                            db.session.commit()
                    idata = Invoices.query.filter(
                        Invoices.Jo == modata.Jo).order_by(Invoices.Jo).all()
                    fdata = Income.query.filter(
                        Income.Jo == modata.Jo).order_by(Income.Jo).all()

                leftsize = 8
                modlink = 7
# ____________________________________________________________________________________________________________________E.PaymentHistory.Dealer

# ____________________________________________________________________________________________________________________B.Invoice.Dealer

        if (minvo is not None and cars > 0):
            err = ['Could not create invoice', ' ', ' ', ' ', ' ']
            # First time through: have an order to invoice
            if cars > 0:
                invooder = cars
            myo = Dealer.query.get(invooder)
            #Check to see if we have the required data to make an invoice:
            bid = myo.Pid

            if bid is None:
                err[1] = 'No Billing Data'

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

                hdata = Dealer.query.filter(Dealer.Jo == myo.Jo).all()
                total = 0
                #Delete previous invoices created for this Jo
                killdata = Invoices.query.filter(
                    Invoices.Jo == myo.Jo).delete()
                for data in hdata:
                    qty = 1
                    towcost = nononef(data.Tow)
                    repaircost = nononef(data.Repair)
                    othercost = nononef(data.Ocost)
                    buyerfee = nononef(data.Bfee)
                    carcost = nononef(data.Sale)
                    docfee = nononef(data.DocumentFee)

                    total = total + towcost + repaircost + othercost + buyerfee + carcost + docfee
                    if carcost > 0:
                        descript = data.Year + ' ' + data.Make + ' ' + data.Model + ' VIN:' + data.Vin
                        input = Invoices(Jo=myo.Jo,
                                         SubJo=None,
                                         Pid=bid,
                                         Service='Car Purchase',
                                         Description=descript,
                                         Ea=carcost,
                                         Qty=qty,
                                         Amount=carcost,
                                         Total=total,
                                         Date=today,
                                         Original=None,
                                         Status='New')
                        db.session.add(input)
                        db.session.commit()
                    if buyerfee > 0:
                        descript = 'Buyer fee for VIN: ' + data.Vin
                        input = Invoices(Jo=myo.Jo,
                                         SubJo=None,
                                         Pid=bid,
                                         Service='Buyer Fee',
                                         Description=descript,
                                         Ea=buyerfee,
                                         Qty=qty,
                                         Amount=buyerfee,
                                         Total=total,
                                         Date=today,
                                         Original=None,
                                         Status='New')
                        db.session.add(input)
                        db.session.commit()
                    if towcost > 0:
                        descript = 'Towing cost for VIN: ' + data.Vin
                        input = Invoices(Jo=myo.Jo,
                                         SubJo=None,
                                         Pid=bid,
                                         Service='Towing',
                                         Description=descript,
                                         Ea=towcost,
                                         Qty=qty,
                                         Amount=towcost,
                                         Total=total,
                                         Date=today,
                                         Original=None,
                                         Status='New')
                        db.session.add(input)
                        db.session.commit()
                    if repaircost > 0:
                        descript = 'Repair cost for VIN: ' + data.Vin
                        input = Invoices(Jo=myo.Jo,
                                         SubJo=None,
                                         Pid=bid,
                                         Service='Repairs',
                                         Description=descript,
                                         Ea=repaircost,
                                         Qty=qty,
                                         Amount=repaircost,
                                         Total=total,
                                         Date=today,
                                         Original=None,
                                         Status='New')
                        db.session.add(input)
                        db.session.commit()
                    if docfee > 0:
                        descript = 'Dealer document fee for VIN: ' + data.Vin
                        input = Invoices(Jo=myo.Jo,
                                         SubJo=None,
                                         Pid=bid,
                                         Service='Document Fee',
                                         Description=descript,
                                         Ea=docfee,
                                         Qty=qty,
                                         Amount=docfee,
                                         Total=total,
                                         Date=today,
                                         Original=None,
                                         Status='New')
                        db.session.add(input)
                        db.session.commit()
                    if othercost > 0:
                        descript = data.Oitem + ' for VIN: ' + data.Vin
                        input = Invoices(Jo=myo.Jo,
                                         SubJo=None,
                                         Pid=bid,
                                         Service=data.Oitem,
                                         Description=descript,
                                         Ea=othercost,
                                         Qty=qty,
                                         Amount=othercost,
                                         Total=total,
                                         Date=today,
                                         Original=None,
                                         Status='New')
                        db.session.add(input)
                        db.session.commit()

                #Cycle through again so all the line items have the correct total amount
                idata = Invoices.query.filter(Invoices.Jo == myo.Jo).all()
                if idata is not None:
                    for data in idata:
                        data.Total = 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
                    invodate = ldat.Date
                    err = [
                        ' ', ' ', 'Created invoice for JO= ' + myo.Jo, ' ', ' '
                    ]
                    ldata = Invoices.query.filter(
                        Invoices.Jo == myo.Jo).order_by(
                            Invoices.Ea.desc()).all()
                    pdat = People.query.filter(People.id == myo.Pid).first()

                    import make_H_invoice
                    make_H_invoice.main(myo, ldata, pdat, cache, invodate, 0)

                    if cache > 0:
                        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'
                    myo.Ipath = docref
                    myo.Cache = cache
                    db.session.commit()
                    leftscreen = 0
                    err[3] = 'invooder=' + str(invooder)
                    err[4] = 'Viewing ' + docref
                    modata = Dealer.query.get(invooder)

        elif minvo is not None:
            err = [
                ' ', ' ', 'Must select at least 1 Job for this selection', ' ',
                ' '
            ]
# ____________________________________________________________________________________________________________________E.Invoice.Dealer
# ____________________________________________________________________________________________________________________B.Newjob.Dealer
        if newjob is not None:
            err = ['Select Source Document from List']
            jobdate = datetime.date.today()
            modlink = 4
            leftsize = 8
            leftscreen = 0
            docref = f'tmp/{scac}/data/vunknown/NewJob.pdf'
            doctxt = ''

        if newjob is None and modlink == 4:
            filesel = request.values.get('FileSel')
            fdata = myoslist(f'tmp/{scac}/data/vunknown')
            fdata.sort()
            jobdate = request.values.get('dstart')
            leftsize = 8
            leftscreen = 0
            if filesel != '1':
                docref = f'tmp/{scac}/data/vunknown/' + filesel
                doctxt = docref.split('.', 1)[0] + '.txt'
            else:
                docref = ''
                doctxt = ''

        if thisjob is not None:
            modlink = 0
            #Create the new database entry for the source document
            filesel = request.values.get('FileSel')
            if filesel != '1':
                docold = f'tmp/{scac}/data/vunknown/' + filesel
                docref = f'tmp/{scac}/data/vcarbuy/' + filesel
                try:
                    shutil.move(addpath(docold), addpath(docref))
                except:
                    err[0] = 'File moved'
            else:
                docref = ''
            sdate = request.values.get('dstart')
            if sdate is None:
                sdate = today

            jtype = 'J'
            nextjo = newjo(jtype, sdate)

            company = request.values.get('thiscompany')
            bid = People.query.filter(People.Company == company).first()
            if bid is not None:
                idb = bid.id
            else:
                idb = 0

            input = Dealer(Jo=nextjo,
                           Pid=idb,
                           Company=company,
                           Aid=0,
                           Make=None,
                           Model=None,
                           Year=None,
                           Vin=None,
                           Cost=None,
                           Sale=None,
                           Bfee=None,
                           Tow=None,
                           Repair=None,
                           Oitem=None,
                           Ocost=None,
                           Ipath=None,
                           Apath=filesel,
                           Cache=0,
                           Status='New',
                           Label=None,
                           Date=sdate,
                           DocumentFee='')

            db.session.add(input)
            db.session.commit()
            modata = Dealer.query.filter(Dealer.Jo == nextjo).first()
            cars = modata.id
            leftscreen = 0
            err = ['All is well', ' ', ' ', ' ', ' ']
# ____________________________________________________________________________________________________________________E.Newjob.Dealer
# ____________________________________________________________________________________________________________________B.Match.Dealer

        if match is not None:

            if cars > 0 and peep > 0 and numchecked == 2:
                mys = Dealer.query.get(cars)
                myp = People.query.get(peep)
                mys.Pid = myp.id
                mys.Company = myp.Company

                db.session.commit()

            if cars > 0 and auto > 0 and numchecked == 2:
                mys = Dealer.query.get(cars)
                mya = Autos.query.get(auto)
                thisjo = mys.Jo
                mya.Hjo = thisjo
                # Check to see if we need a new JO line because we already have a car assigned
                if mys.Aid > 0 and mys.Aid != auto:
                    #We need a new line item
                    input = Dealer(Jo=thisjo,
                                   Pid=mys.Pid,
                                   Company=mys.Company,
                                   Aid=0,
                                   Make=None,
                                   Model=None,
                                   Year=None,
                                   Vin=None,
                                   Cost=None,
                                   Sale=None,
                                   Bfee=None,
                                   Tow=None,
                                   Repair=None,
                                   Oitem=None,
                                   Ocost=None,
                                   Ipath=None,
                                   Apath=None,
                                   Cache=0,
                                   Status='New',
                                   Label=None,
                                   DocumentFee='')
                    db.session.add(input)
                    db.session.commit()
                    mys = Dealer.query.filter((Dealer.Jo == thisjo)
                                              & (Dealer.Aid == 0)).first()

                mys.Aid = auto
                mys.Make = mya.Make
                mys.Model = mya.Model
                mys.Year = mya.Year
                mys.Vin = mya.VIN
                mys.Status = 'Car'
                mya.Status = 'M'
                db.session.commit()

            if numchecked != 2:
                err[1] = 'Must select exactly 2 boxes to use this option.'
                err[0] = ' '

# ____________________________________________________________________________________________________________________E.Match.Dealer
# ____________________________________________________________________________________________________________________B.Calendar.Dealer
        if calendar is not None or calupdate is not None:
            leftscreen = 2
            if calupdate is not None:
                waft = request.values.get('waft')
                wbef = request.values.get('wbef')
                waft = nonone(waft)
                wbef = nonone(wbef)
                nweeks = [wbef, waft]
            else:
                nweeks = [2, 3]
            caldays, daylist, weeksum = calendar7_weeks('Dealer', nweeks)

# ____________________________________________________________________________________________________________________E.Calendar.Dealer

#This is the else for 1st time through (not posting data from Dealer.html)
    else:
        from viewfuncs import GetCo, popjo, jovec, timedata, nonone, nononef, init_horizon_zero, GetCo3
        #today = datetime.date.today().strftime('%Y-%m-%d')
        #now = datetime.datetime.now().strftime('%I:%M %p')
        jobdate = datetime.date.today()
        idata = 0
        leftscreen = 1
        cars, auto, peep, invo, cache, modata, modlink, invooder, stamp, fdata, csize, invodate, inco, cdat, pb, passdata, vdata, caldays, daylist, weeksum, nweeks = init_horizon_zero(
        )
        leftscreen = 1
        dlist = ['off'] * 3
        dlist[1] = 'on'
        filesel = ''
        docref = ''
        doctxt = ''
        leftsize = 10
        err = ['All is well', ' ', ' ', ' ', ' ']
        displdata = 0

    if fdata == 0:
        fdata = myoslist('data/vunknown')
        fdata.sort()
    pdata = GetCo('Jays', 'All')
    sdata = Services.query.all()
    hdata = Dealer.query.all()
    adata = Autos.query.all()
    leftsize = 8

    return hdata, adata, pdata, idata, fdata, displdata, cars, invooder, auto, peep, err, modata, caldays, daylist, nweeks, invodate, doctxt, sdata, dlist, modlink, inco, invo, cache, filesel, leftscreen, docref, leftsize, jobdate