def insert_portdata(datehere, portstart, portstop, porttime, custtime, thisunit, portmiles): pdat = Portlog.query.filter((Portlog.Date == datehere) & (Portlog.GPSin == portstart)).first() if pdat is None: if 1 == 1: pt = str(porttime) print(pt) if printif == 1 else 1 (hr, min, sec) = pt.split(':') portdec = round( float(int(hr) * 3600 + int(min) * 60 + int(sec)) / 3600.0, 2) try: ct = str(custtime) (hr, min, sec) = ct.split(':') custdec = round( float(int(hr) * 3600 + int(min) * 60 + int(sec)) / 3600.0, 2) except: custdec = 0 idata = Interchange.query.filter(Interchange.Date == datehere).all() cin = None cout = None pcheck = portstart - timedelta(minutes=10) for idat in idata: datehere_s = (datetime.date.today() - datetime.timedelta(thisback)).strftime("%d-%b-%Y") time = idat.Time try: dstring = datehere_s + 'T' + time dt_time = datetime.datetime.strptime(dstring, "%d-%b-%YT%H:%M") except: dt_time = datetime.datetime.strptime(datehere_s, "%d-%b-%Y") print('idat', time, dt_time) if printif == 1 else 1 type = idat.Type if dt_time >= pcheck and dt_time <= portstop: if 'In' in type: cin = idat.Container elif 'Out' in type: cout = idat.Container print(f'Adding to Portlog for Date:{datehere} in Unit:{thisunit}' ) if printlog == 1 else 1 input = Portlog(Date=datehere, Unit=thisunit, Driver=None, GPSin=portstart, GPSout=portstop, PortTime=d2s(portdec), CustTime=d2s(custdec), ConIn=cin, ConOut=cout, Status='0', Portmiles=d2s(portmiles)) db.session.add(input) db.session.commit()
def put_cost(item, m3, amt, dig): if dig == 2: amt = d2s(amt) elif dig == 1: amt = d1s(amt) elif dig == 0: amt = str(int(amt)) tcon = Truckcost.query.filter(Truckcost.Cost == item).first() ebase = f'tcon.{m3} = str({amt})' exec(ebase) db.session.commit()
C14=None, C15=None, C16=None, C17=None, C18=None, C19=None, C20=None, C21=None, C22=None, C23=None, C24=None) db.session.add(input) db.session.commit() idat = IEroll.query.filter((IEroll.Name == adat.Name) & (IEroll.Co == adat.Co)).first() setattr(idat, f'C{ix}', d2s(total / 100.)) gatotal = gatotal + total / 100. ganame = f'{divco} G-A Expense Totals' print( f'Total G-A Expenses for Company {divname} {ix} {df} to {dt} is {d2s(gatotal)}' ) #G-A Totals gdat = IEroll.query.filter((IEroll.Name == ganame) & (IEroll.Co == divco)).first() if gdat is None: input = IEroll(Name=ganame, Category=thiscat, Subcategory=thissub, Type='Expense',
ebase = f'tcon.{m3} = str({d2s(mtamt)})' print(ebase) exec(ebase) db.session.commit() ytavg = ytamt / float(ydays) yiavg = yiamt / float(ydays) print( f'Year Avg for Year:{thisyear} Chassis$:{d2s(ytamt)} Cons:{ynumc} ChasPay$/Day:{d2s(ytavg)} ChasPay$/Con:{d2s(ytamt/float(ynumc))} Days/Con:{d2s(ydays/ynumc)}' ) print( f'Year Avg for Year:{thisyear} ChasInc$:{d2s(yiamt)} Cons:{ynumc} ChasInc$/Day:{d2s(yiavg)} ChasInc$/Con:{d2s(yiamt/float(ynumc))}' ) tcon = Truckcost.query.filter(Truckcost.Cost == 'Containers').first() tcon.Ytd = d2s(ynumc) tcon.PerCon = '1' tcon.PerChasDay = d2s(float(ynumc) / float(ydays)) tcon.PerDay = d2s(float(ynumc) / float(numcalday)) db.session.commit() tcon = Truckcost.query.filter(Truckcost.Cost == 'ChassisDays').first() tcon.Ytd = d2s(ydays) tcon.PerCon = d2s(float(ydays) / float(ynumc)) tcon.PerChasDay = '1' tcon.PerDay = d2s(float(ydays) / float(numcalday)) db.session.commit() tcon = Truckcost.query.filter(Truckcost.Cost == 'Chassis').first() tcon.Ytd = d2s(ytamt) tcon.PerCon = d2s(ytamt / float(ynumc))
C16=None, C17=None, C18=None, C19=None, C20=None, C21=None, C22=None, C23=None, C24=None) db.session.add(input) db.session.commit() idatB = Broll.query.filter( (Broll.Name == company) & (Broll.Co == divco) & (Broll.Type == 'Expense-B')).first() setattr(idatB, f'C{ix}', d2s(tot)) idatG = Broll.query.filter( (Broll.Name == company) & (Broll.Co == divco) & (Broll.Type == 'Expense-G')).first() if idatG is None: input = Broll(Name=company, Category=bcat, Subcategory=bsub, Type='Expense-G', Co=divco, Tot=0, C1=None, C2=None, C3=None, C4=None,
total_optime = shift_time - downtime distance = dataret['Distance'] * .62137 if distance > 0: ostart, ostop = get_odometer(vid, distance) else: ostart = 0 ostop = 0 print( f'Adding to Trucklog for Date:{datehere} and Unit:{units[jid]}' ) input = Trucklog(Date=datehere, Unit=units[jid], Tag=tag, GPSin=timestart, GPSout=timelast, Shift=d2s(shift_time), Distance=d1s(distance), Gotime=d2s(total_optime), Rdist=d2s(rmax), Rloc=rlocmax, Odomstart=str(ostart), Odomstop=str(ostop), Odverify=None, DriverStart=None, Maintrecord='None', Locationstart=location_start, DriverEnd=None, Locationstop=location_stop, Maintid=None, Status='0') db.session.add(input)
except: earn = 0.00 try: empcost = float(nr[len(nr) - 1]) except: empcost = 0.00 if period != 'none': paydt = datetime.datetime.strptime( paydate, '%m/%d/%Y') pds, pde = period.split('-') pdsdt, pdedt = datetime.datetime.strptime( pds.strip(), '%m/%d/%Y'), datetime.datetime.strptime( pde.strip(), '%m/%d/%Y') try: emptaxes = d2s(empcost - earn) thours = d2s(hours + ot) hours = d2s(hours) ot = d2s(ot) empcost = d2s(empcost) earn = d2s(earn) except: print(empcost, earn, hours, ot) if fn in truckdriver: print(paydate, period) print( f'Driver Name:{fn} Hours:{hours} OT:{ot} Earnings:{earn} EmpCost:{empcost} EmpTaxes{emptaxes}' ) put_payroll('Driver', fn, earn, empcost, emptaxes, paydt, pdsdt, pdedt, hours, ot, thours)
def autofind(p5s, txtfile, srcfile): wt = None value = None fout = p5s + txtfile error = 1 vinlist = vinfind(fout) nvins = len(vinlist) # print(vinlist) carrier, addr1, addr2, phone = carrierfind(fout) # print(carrier,addr1,addr2,phone) pudate, deldate, payment = orderinfo(fout) pufrom = comefrom(fout) # print(pudate,deldate,payment,pufrom) ncars, carlist = dispatchfind(fout) # print(nvins,ncars,len(carlist)) try: date1 = datetime.datetime.strptime(pudate, "%m/%d/%Y") except: date1 = None try: date2 = datetime.datetime.strptime(deldate, "%m/%d/%Y") except: date2 = None payment = d2s(payment) try: total = float(payment) each = total / float(ncars) each = str(each) each = d2s(each) except: each = '0.00' adata = Autos.query.all() lauto = len(adata) - 1 for j, adat in enumerate(adata): if j == lauto: thisid = adat.id nextid = thisid + 1 newfile = 'DISP' + str(nextid) + '.pdf' original = 'tmp/vdispatch/' + newfile orderid = 'disp' + str(nextid) adat = Autos.query.filter(Autos.Orderid == orderid).first() if adat is None: print("This is a new tow order so we need to add it to the database") error = 0 for car in carlist: # carlist.append([year,make,model,color,vin]) vin = car[4] year = car[0] make = car[1] model = car[2] color = car[3] wt = '0' value = '0' if len(vin) == 17: try: year, make, model, wt, value, navg = vinscraper(vin) value = value.replace('$', '') except: wt = 'Bad Vin' value = 'Bad Vin' else: vin = 'NoVIN' bdat = Autos.query.filter(Autos.VIN == vin).first() if bdat is None or vin == 'NoVIN': print("Entering data in Autos database") input = Autos(Jo=orderid, Hjo=None, Year=year, Make=make, Model=model, Color=color, VIN=vin, Title=None, State=None, EmpWeight=wt, Dispatched='Horizon Motors', Value=value, TowCompany=carrier, TowCost=payment, TowCostEa=each, Original=original, Status='New', Date1=date1, Date2=date2, Pufrom=pufrom, Delto='FEL', Ncars=ncars, Orderid=orderid) db.session.add(input) db.session.commit() print('This auto not in database, adding to records...') print(orderid, year, make, model, color, vin, wt, value, carrier, payment, each, ncars, pufrom, original) print(' ') else: print('This auto already in the database') print('Modifying and updating records...') print(orderid, year, make, model, color, vin, wt, value, carrier, payment, each, ncars, pufrom, original) print(' ') bdat.EmpWeight = wt bdat.Value = value bdat.TowCompany = carrier bdat.TowCost = payment bdat.TowCostEa = each bdat.Ncars = ncars bdat.Pufrom = pufrom bdat.Delto = 'FEL' db.session.commit() pdat = People.query.filter((People.Ptype == 'TowCo') & (People.Company == carrier)).first() if pdat is None: input = People(Company=carrier, First='', Middle='', Last='', Addr1=addr1, Addr2=addr2, Addr3='', Idtype='', Idnumber='', Telephone=phone, Email='', Associate1='', Associate2='', Date1=today, Date2=None, Original='', Ptype='TowCo', Temp1='', Temp2='') db.session.add(input) db.session.commit() tunnel.stop() return newfile, error