1、增:
newfirm = bdqf(pno = form1.pno.data,
com = form1.comcode.data,
risk =form1.riskcode.data,
bf = form1.bf.data,
commissions = form1.commissions.data,
deskdate = form1.deskdate.data,
tjdate = pd.datetime.today().strftime("%Y-%m-%d")
)
db.session.add(newfirm)
db.session.commit()
flash('记录增加成功!')
2、删:
def delbd():
form = Delqf()
if form.validate_on_submit():
delit = db.session.query(bdqf).filter(bdqf.policyno == form.policyno.data).all()
if delit is not None:
for i in delit:
db.session.delete(i)
db.session.commit()
flash('记录被删除!')
else:
flash('不存在,无需删除!')
return render_template('main/addqf.html', form=form,tablename=tablename)
3、改:
def modyqf(policyno):
tablename = '请修改'+ policyno + '的清分信息'
form=Modqf()
qf = db.session.query(bdqf).filter_by(policyno = policyno).first()
if form.validate_on_submit():
qf.bf = form.bf.data,
qf.commissions = form.commissions.data,
qf.saler = form.saler.data,
qf.agent2 = form.agent2.data,
qf.tjdate = pd.datetime.today().strftime("%Y-%m-%d")
db.session.commit()
db.session.close()
flash('记录修改成功!')
return render_template('main/addqf.html', form=form,tablename = tablename)
4、查:
@login_required
def qftzcx():
tablename = '清分台帐查询'
form = Comdate()
df = pd.DataFrame()
if form.validate_on_submit():
comcode = getjg(current_user.comcode)
sdate = str(form.sdate.data)
edate = str(form.edate.data)
df = db.session.query(bdqf).filter(and_(bdqf.comcode.like(comcode),bdqf.deskdate<= edate,bdqf.deskdate>=sdate )).all()
return render_template('main/showzl.html', cop=df )
return render_template('main/addqf.html', form=form, tablename=tablename)
5、汇总查询:
df = pd.DataFrame()
if form.validate_on_submit():
comcode = getjg(current_user.comcode)
saler = form.saler.data
sdate = str(form.startdate.data)
edate = str(form.enddate.data)
from sqlalchemy import func
df = db.session.query(bdqf.saler,bdqf.agent2,bdqf.riskkind,bdqf.transxb,bdqf.transxbyear,func.sum(bdqf.bf).label('bf')).filter(
and_(bdqf.comcode.like(comcode),bdqf.saler==saler,bdqf.deskdate<= edate,bdqf.deskdate>=sdate )).group_by(
bdqf.saler,bdqf.agent2,bdqf.riskkind,bdqf.transxb,bdqf.transxbyear).all()
df = pd.DataFrame(df)