def new_medium_group(): if not (g.user.is_contract() or g.user.is_super_leader()): abort(403) if request.method == 'POST': name = request.values.get('name', "") tax_num = request.values.get('tax_num', "") address = request.values.get("address", "") phone_num = request.values.get("phone_num", "") bank = request.values.get('bank', "") bank_num = request.values.get("bank_num", "") level = int(request.values.get("level", 100)) db_medium_name = MediumGroup.name_exist(name) if not db_medium_name: medium_group = MediumGroup.add( name=name, tax_num=tax_num, address=address, phone_num=phone_num, bank=bank, bank_num=bank_num, level=level) medium_group.save() medium_group.add_comment(g.user, u"新建了媒体供应商: %s\n\n税号:%s\n\n地址:%s\n\n电话:%s\n\n开户行:%s\n\n银行账号:%s\n\n" % (medium_group.name, medium_group.tax_num, medium_group.address, medium_group.phone_num, medium_group.bank, medium_group.bank_num), msg_channel=14) flash(u'新建(%s)媒体供应商成功!' % medium_group.name, 'success') else: flash(u'新建(%s)媒体供应商失败, 名称已经被占用!' % name, 'danger') return tpl('/client/medium/group/create.html') return redirect(url_for("client.medium_group_detail", medium_group_id=medium_group.id)) return tpl('/client/medium/group/create.html')
def index(): if not g.user.is_super_leader(): abort(403) salers = User.sales() if request.method == 'POST': f_saler = int(request.values.get('f_saler', 0)) t_saler = int(request.values.get('t_saler', 0)) if not f_saler or not t_saler: flash(u'请选择正确的员工', 'danger') return tpl('/account/turnover/index.html', salers=salers) f_user = User.get(f_saler) t_user = User.get(t_saler) client_orders = ClientOrder.all() douban_orders = DoubanOrder.all() for k in client_orders: if f_user in k.salers and t_user not in k.replace_sales: k.replace_sales = k.replace_sales + [t_user] k.save() if k.creator == f_user and t_user not in k.replace_sales: k.replace_sales = k.replace_sales + [t_user] k.save() for k in douban_orders: if f_user in k.salers and t_user not in k.replace_sales: k.replace_sales = k.replace_sales + [t_user] k.save() if k.creator == f_user and t_user not in k.replace_sales: k.replace_sales = k.replace_sales + [t_user] k.save() flash(u'成功', 'success') return tpl('/account/turnover/index.html', salers=salers)
def final_evaluate(user_id, lid): okr = Okr.query.get(lid) okrlist = json.loads(okr.o_kr) if request.method == 'POST': # 拿到评价的数据以及insert的查询字段 okr_json = request.values.get('okr_json') o_kr = json.loads(okr_json) status = int(o_kr['status']) summary = o_kr['summary'] okrtext = json.dumps(o_kr['okrs']) okr_update = Okr.query.get(lid) okr_update.status = status okr_update.summary = summary okr_update.o_kr = okrtext okr_update.save() if int(status) == OKR_STATUS_EVALUATION_APPLY: flash(u'已发送申请', 'success') account_okr_apply_signal.send( current_app._get_current_object(), okr=okr_update) else: flash(u'修改成功', 'success') return redirect(url_for('account_okr.index')) if okr.status == 6: return tpl('/account/okr/final_evaluate.html', okrlist=okrlist, okr=okr, priority_list=PRIORITY_LIST) else: return tpl('/account/okr/update_final_eval.html', okrlist=okrlist, okr=okr, )
def new_agent(): if not (g.user.is_contract() or g.user.is_super_leader()): abort(403) form = NewAgentForm(request.form) if request.method == 'POST' and form.validate(): db_agent_name = Agent.name_exist(form.name.data) if not db_agent_name: agent = Agent.add(form.name.data, Group.get(form.group.data), form.tax_num.data, form.address.data, form.phone_num.data, form.bank.data, form.bank_num.data, form.contact.data, form.contact_phone.data) flash(u'新建代理/直客(%s)成功!' % agent.name, 'success') else: flash(u'新建代理/直客(%s)失败, 名称已经被占用!' % form.name.data, 'danger') return tpl('/client/agent/info.html', form=form, title=u"新建代理公司", status='news') agent.add_comment(g.user, u"新建了代理: %s\n\n税号:%s\n\n地址:%s\n\n电话:%s\n\n开户行:%s\n\n\ 银行账号:%s\n\n内部联系人:%s\n\n内部联系人电话:%s\n\n" % (agent.name, agent.tax_num, agent.address, agent.phone_num, agent.bank, agent.bank_num, agent.contact, agent.contact_phone), msg_channel=13) return redirect(url_for("client.agents")) return tpl('/client/agent/info.html', form=form, status='news', title=u"新建代理/直客")
def update(user_id, lid): okr_old = Okr.query.get(lid) if request.method == 'POST': okr_json = request.values.get('okr_json') o_kr = json.loads(okr_json) quarter = int(o_kr['quarter']) status = int(o_kr['status']) year = int(o_kr['year']) okrtext = json.dumps(o_kr['okrs']) if quarter == okr_old.quarter and year == okr_old.year: okr_update = Okr.query.get(lid) okr_update.year = year okr_update.quarter = quarter okr_update.status = status okr_update.o_kr = okrtext okr_update.creator_id = user_id okr_update.save() if int(status) == OKR_STATUS_APPLY: flash(u'已发送申请', 'success') account_okr_apply_signal.send( current_app._get_current_object(), okr=okr_update) else: flash(u'修改成功', 'success') return redirect(url_for('account_okr.index')) elif Okr.query.filter_by(quarter=quarter, year=year, creator=g.user).first(): flash(u'您已经填写过该季度的OKR表了!', 'danger') return tpl('/account/okr/update_new.html', okrlist=o_kr['okrs'], year=year, quarter=quarter, year_list=YEAR_LIST, quarters=OKR_QUARTER_CN, priority_list=PRIORITY_LIST) okr_update = Okr.query.get(lid) okr_update.year = year okr_update.quarter = quarter okr_update.status = status okr_update.o_kr = okrtext okr_update.creator_id = user_id okr_update.save() if int(status) == OKR_STATUS_APPLY: flash(u'已发送申请', 'success') account_okr_apply_signal.send( current_app._get_current_object(), okr=okr_update) else: flash(u'修改成功', 'success') return redirect(url_for('account_okr.index')) okr = Okr.query.get(lid) okrlist = json.loads(okr.o_kr) return tpl('/account/okr/update_new.html', okr=okr, okrlist=okrlist, year=str(okr.year), quarter=okr.quarter, year_list=YEAR_LIST, quarters=OKR_QUARTER_CN, priority_list=PRIORITY_LIST)
def new_client(): form = NewClientForm(request.form) if request.method == 'POST' and form.validate(): db_client_name = searchAdClient.name_exist(form.name.data) if not db_client_name: client = searchAdClient.add(form.name.data, form.industry.data) flash(u'新建客户(%s)成功!' % client.name, 'success') else: flash(u'新建客户(%s)失败,名称被占用!' % form.name.data, 'danger') return tpl('searchAd_client.html', form=form, title=u"新建客户") return redirect(url_for("searchAd_client.clients")) return tpl('searchAd_client.html', form=form, title=u"新建客户")
def new_group(): form = NewGroupForm(request.form) if request.method == 'POST' and form.validate(): db_group_name = searchAdGroup.name_exist(form.name.data) if not db_group_name: group = searchAdGroup.add(form.name.data) flash(u'新建代理集团(%s)成功!' % group.name, 'success') else: flash(u'新建代理集团(%s)失败, 名称已经被占用!' % form.name.data, 'danger') return tpl('searchAd_group.html', form=form, group=None, title=u"新建代理集团") return redirect(url_for("searchAd_client.groups")) return tpl('searchAd_group.html', form=form, group=None, title=u"新建代理集团")
def new_agent(): form = NewAgentForm(request.form) if request.method == 'POST' and form.validate(): db_agent_name = searchAdAgent.name_exist(form.name.data) if not db_agent_name: agent = searchAdAgent.add(form.name.data, searchAdGroup.get(form.group.data), form.tax_num.data, form.address.data, form.phone_num.data, form.bank.data, form.bank_num.data) flash(u'新建代理/直客(%s)成功!' % agent.name, 'success') else: flash(u'新建代理/直客(%s)失败, 名称已经被占用!' % form.name.data, 'danger') return tpl('/searchAdclient/agent/searchAd_info.html', form=form, title=u"新建代理/直客") return redirect(url_for("searchAd_client.agents")) return tpl('/searchAdclient/agent/searchAd_info.html', form=form, title=u"新建代理/直客")
def back_money(): now_date = datetime.datetime.now() info = request.values.get('info', '').strip() year = request.values.get('year', now_date.strftime('%Y')) month = request.values.get('month', now_date.strftime('%m')) if month != '00': search_date = datetime.datetime.strptime( str(year) + '-' + str(month), '%Y-%m') end_search_date = ( search_date + datetime.timedelta(days=(search_date.max.day - search_date.day) + 1)).replace(day=1) orders = [k for k in searchAdBackMoney.query.filter(searchAdBackMoney.back_time >= search_date, searchAdBackMoney.back_time < end_search_date) if k.client_order.status == 1] else: orders = [k for k in searchAdBackMoney.all() if k.back_time.year == int( year) and k.client_order.status == 1] if info: orders = [k for k in orders if info in k.client_order.search_invoice_info] orders = sorted(list(orders), key=lambda x: x.back_time, reverse=False) if request.values.get('action', '') == 'download': response = write_order_excel(list(orders), 'back_money') return response return tpl('/finance/searchAd_order/data_query/index.html', orders=orders, year=year, month=month, info=info, title=u"客户回款金额", t_type='back_money')
def target_detail(target_id): target = OutSourceTarget.get(target_id) if not target: abort(404) form = OutSourceTargetForm(request.form) if request.method == 'POST' and form.validate(): if OutSourceTarget.query.filter_by(name=form.name.data).first() and target.name != form.name.data: flash(u'修改失败,已存在该收款方!', 'danger') return redirect(url_for("outsource.target_detail", target_id=target_id)) target.name = form.name.data target.bank = form.bank.data target.card = form.card.data target.alipay = form.alipay.data target.contract = form.contract.data target.remark = form.remark.data target.type = form.type.data target.otype = form.otype.data target.save() flash(u'保存成功', 'success') else: form.name.data = target.name form.bank.data = target.bank form.card.data = target.card form.alipay.data = target.alipay form.contract.data = target.contract form.remark.data = target.remark form.type.data = target.type form.otype.data = target.otype or 1 return tpl('target.html', form=form, title=u"收款方-" + target.name)
def pay_medium_invoice(): if not (g.user.is_media() or g.user.is_media_leader() or g.user.is_contract()): abort(404) now_date = datetime.datetime.now() info = request.values.get('info', '').strip() location = int(request.values.get('location', 0)) year = request.values.get('year', now_date.strftime('%Y')) month = request.values.get('month', now_date.strftime('%m')) if month != '00': search_date = datetime.datetime.strptime( str(year) + '-' + str(month), '%Y-%m') end_search_date = ( search_date + datetime.timedelta(days=(search_date.max.day - search_date.day) + 1)).replace(day=1) orders = [k for k in MediumInvoicePay.query.filter(MediumInvoicePay.pay_time >= search_date, MediumInvoicePay.pay_time < end_search_date) if k.client_order.status == 1 and k.pay_status == 0] else: orders = [k for k in MediumInvoicePay.all() if k.pay_time.year == int( year) and k.client_order.status == 1 and k.pay_status == 0] if location != 0: orders = [k for k in orders if location in k.client_order.locations] if info: orders = [k for k in orders if info in k.client_order.search_info] orders = sorted(list(orders), key=lambda x: x.pay_time, reverse=False) if request.values.get('action', '') == 'download': response = write_order_excel(list(orders), 'pay_medium_invoice') return response return tpl('/media/client_order/data_query/index.html', orders=orders, location=location, year=year, month=month, info=info, title=u"付款给媒体金额", t_type='pay_medium_invoice')
def order_info(): now_year = int(request.values.get('year', datetime.datetime.now().year)) outsources = [_cost_outsource_to_dict(k) for k in ClientOtherCost.all()] outsources += [_cost_outsource_to_dict(k) for k in DoubanOtherCost.all()] orders = list(set([s['order'] for s in outsources if s['on_time'].year == now_year])) order_obj = [] for k in orders: order_dict = {} if k.__tablename__ == 'bra_client_order': order_dict['outsource_obj'] = [o for o in outsources if o[ 'order_type'] == 'client_order' and o['order_id'] == k.id and o['on_time'].year == now_year] else: order_dict['outsource_obj'] = [o for o in outsources if o[ 'order_type'] == 'douban_order' and o['order_id'] == k.id and o['on_time'].year == now_year] order_dict['contract'] = k.contract order_dict['campaign'] = k.campaign order_dict['money'] = k.money order_dict['locations_cn'] = k.locations_cn order_dict['__tablename__'] = k.__tablename__ order_dict['id'] = k.id order_dict['campaign'] = k.campaign if order_dict['outsource_obj']: order_obj.append(order_dict) if request.values.get('action', '') == 'download': return write_cost_outsource_order_info_excel(order_obj) return tpl('/data_query/outsource/cost_order_info.html', orders=order_obj, now_year=now_year)
def agent_detail(agent_id): agent = searchAdAgent.get(agent_id) if not agent: abort(404) form = NewAgentForm(request.form) if request.method == 'POST' and form.validate(): agent.name = form.name.data agent.group = searchAdGroup.get(form.group.data) agent.tax_num = form.tax_num.data agent.address = form.address.data agent.phone_num = form.phone_num.data agent.bank = form.bank.data agent.bank_num = form.bank_num.data agent.save() flash(u'保存成功', 'success') else: form.name.data = agent.name form.group.data = agent.group.id if agent.group else None form.tax_num.data = agent.tax_num form.address.data = agent.address form.phone_num.data = agent.phone_num form.bank.data = agent.bank form.bank_num.data = agent.bank_num return tpl('/searchAdclient/agent/searchAd_info.html', form=form, title=u"代理/直客-" + agent.name, agent=agent, FILE_TYPE_CN=FILE_TYPE_CN, status="update")
def douban_order(): now_date = datetime.datetime.now() year = str(request.values.get('year', now_date.year)) month = str(request.values.get('month', now_date.month)) now_month = datetime.datetime.strptime(year + '-' + month, '%Y-%m') all_back_moneys = _all_douban_order_back_moneys() all_client_back_moneys = _all_client_order_back_moneys() all_agent_rebate = _all_agent_rebate() douban_orders = list(set([k.douban_order for k in DoubanOrderExecutiveReport.query.filter_by( month_day=now_month) if k.douban_order.status == 1])) douban_order_data = [_douban_order_to_dict( k, all_back_moneys, all_agent_rebate, now_month) for k in douban_orders] medium_orders = list(set([k.order for k in MediumOrderExecutiveReport.query.filter_by( month_day=now_month) if k.status == 1 and k.order.associated_douban_order])) douban_order_data += [_order_to_dict( k, all_client_back_moneys, all_agent_rebate, now_month) for k in medium_orders] douban_order_data = [k for k in douban_order_data if k[ 'contract_status'] not in [0, 7, 8, 81, 9]] if douban_order_data: douban_order_data = sorted( douban_order_data, key=operator.itemgetter('start_date_cn'), reverse=False) if request.values.get('action', '') == 'download': response = write_douban_order_excel(douban_order_data, year, month) return response return tpl('/data_query/profit/douban_order.html', year=int(year), month=int(month), douban_orders=douban_order_data)
def client_order(): now_date = datetime.datetime.now() year = str(request.values.get('year', now_date.year)) month = str(request.values.get('month', now_date.month)) now_month = datetime.datetime.strptime(year + '-' + month, '%Y-%m') client_orders = list(set([k.client_order for k in ClientOrderExecutiveReport.query.filter_by( month_day=now_month) if k.status == 1])) all_back_moneys = _all_client_order_back_moneys() all_agent_rebate = _all_agent_rebate() all_agent_rebate_pay = _all_agent_rebate_pay() all_medium_rebate = _all_medium_rebate() all_medium_rebate_invoice = _all_medium_rebate_invoice() client_order_data = [_client_order_to_dict(k, all_back_moneys, all_agent_rebate, all_agent_rebate_pay, all_medium_rebate, all_medium_rebate_invoice, now_month ) for k in client_orders] client_order_data = [k for k in client_order_data if k[ 'contract_status'] not in [0, 7, 8, 81, 9]] if client_order_data: client_order_data = sorted( client_order_data, key=operator.itemgetter('start_date_cn'), reverse=False) if request.values.get('action', '') == 'download': response = write_order_excel(client_order_data, year, month) return response return tpl('/data_query/profit/client_order.html', year=int(year), month=int(month), client_orders=client_order_data)
def info(order_id): if not g.user.is_finance(): abort(404) order = ClientMediumOrder.get(order_id) if not order: abort(404) invoices_data = { 'PASS': [{'invoice': x, 'form': get_invoice_from(x)} for x in ClientMediumInvoice.query.filter_by(client_medium_order=order) if x.invoice_status == INVOICE_STATUS_PASS], 'APPLYPASS': [{'invoice': x, 'form': get_invoice_from(x)} for x in ClientMediumInvoice.query.filter_by(client_medium_order=order) if x.invoice_status == INVOICE_STATUS_APPLYPASS], } reminder_emails = [(u.name, u.email) for u in User.all_active()] new_invoice_form = ClientMediumInvoiceForm() new_invoice_form.client_medium_order.choices = [(order.id, order.medium.name)] new_invoice_form.company.data = order.agent.name new_invoice_form.bank.data = order.agent.bank new_invoice_form.bank_id.data = order.agent.bank_num new_invoice_form.address.data = order.agent.address new_invoice_form.phone.data = order.agent.phone_num new_invoice_form.tax_id.data = order.agent.tax_num new_invoice_form.back_time.data = datetime.date.today() return tpl('/finance/client_medium_order/invoice/info.html', order=order, invoices_data=invoices_data, INVOICE_STATUS_CN=INVOICE_STATUS_CN, reminder_emails=reminder_emails, INVOICE_TYPE_CN=INVOICE_TYPE_CN, new_invoice_form=new_invoice_form)
def info(): now_year = int(request.values.get('year', datetime.datetime.now().year)) outsources = [_cost_outsource_to_dict(k) for k in ClientOtherCost.all()] outsources += [_cost_outsource_to_dict(k) for k in DoubanOtherCost.all()] outsources = [k for k in outsources if int(k['month_day'].year) == int(now_year)] r_outsource_pay = sum([k['money'] for k in outsources]) # 每季度月份数 Q1_monthes = [datetime.datetime.strptime( str(now_year) + '-' + k, '%Y-%m') for k in check_Q_get_monthes('Q1')] Q2_monthes = [datetime.datetime.strptime( str(now_year) + '-' + k, '%Y-%m') for k in check_Q_get_monthes('Q2')] Q3_monthes = [datetime.datetime.strptime( str(now_year) + '-' + k, '%Y-%m') for k in check_Q_get_monthes('Q3')] Q4_monthes = [datetime.datetime.strptime( str(now_year) + '-' + k, '%Y-%m') for k in check_Q_get_monthes('Q4')] total = 0 orders = list(set([s['order'] for s in outsources if s['on_time'].year == now_year])) for i in orders: o_money = [] o_money += [float(sum([o['money'] for o in outsources if o['month_day'] >= Q1_monthes[0] and o[ 'month_day'] <= Q1_monthes[2] and o['type'] == t and o['order'] == i])) for t in range(1, 6)] o_money += [float(sum([o['money'] for o in outsources if o['month_day'] >= Q2_monthes[0] and o[ 'month_day'] <= Q2_monthes[2] and o['type'] == t and o['order'] == i])) for t in range(1, 6)] o_money += [float(sum([o['money'] for o in outsources if o['month_day'] >= Q3_monthes[0] and o[ 'month_day'] <= Q3_monthes[2] and o['type'] == t and o['order'] == i])) for t in range(1, 6)] o_money += [float(sum([o['money'] for o in outsources if o['month_day'] >= Q4_monthes[0] and o[ 'month_day'] <= Q4_monthes[2] and o['type'] == t and o['order'] == i])) for t in range(1, 6)] i.o_money = o_money total += sum(o_money) if request.values.get('action', '') == 'download': return write_cost_outsource_info_excel(now_year, orders, total, r_outsource_pay) return tpl('/data_query/outsource/cost_info.html', now_year=now_year, orders=orders, total=total, r_outsource_pay=r_outsource_pay)
def index(): if not g.user.is_super_admin(): abort(403) form = FrameworkOrderForm(request.form) if request.method == 'POST' and form.validate(): order = FrameworkOrder.add(group=Group.get(form.group.data), agents=Agent.gets(form.agents.data), description=form.description.data, money=int( round(float(form.money.data or 0))), client_start=form.client_start.data, client_end=form.client_end.data, reminde_date=form.reminde_date.data, direct_sales=User.gets( form.direct_sales.data), agent_sales=User.gets(form.agent_sales.data), contract_type=form.contract_type.data, creator=g.user, contract_status=2, contract=request.values.get('contract'), create_time=datetime.now()) order.add_comment(g.user, u"导入了框架订单") flash(u'导入框架订单成功', 'success') return redirect(order.info_path()) else: form.client_start.data = datetime.now().date() form.client_end.data = datetime.now().date() form.reminde_date.data = datetime.now().date() return tpl('insert_framework_order.html', form=form)
def back_money(order_id): if not g.user.is_finance(): abort(404) client_order = ClientOrder.get(order_id) back_moneys = MediumBackMoney.query.filter_by(client_order_id=order_id) if not client_order: abort(404) if request.method == 'POST': money = float(request.values.get('money', 0)) back_time = request.values.get( 'back_time', datetime.date.today().strftime('%Y-%m-%d')) medium_id = request.values.get('medium') order = Order.get(medium_id) MediumBackMoney.add(client_order_id=order_id, order_id=medium_id, money=money, back_time=back_time) client_order.add_comment(g.user, u"更新了媒体返点回款信息,所属媒体:%s; 回款金额: %s; 回款时间: %s;" % ( order.medium.name, money, back_time), msg_channel=8) apply_context = { 'order': client_order, 'num': money, 'type': 'money', } medium_back_money_apply_signal.send( current_app._get_current_object(), apply_context=apply_context) flash(u'回款信息保存成功!', 'success') return redirect(url_for('finance_client_order_medium_back_money.back_money', order_id=order_id)) return tpl('/finance/client_order/medium_back_money/info.html', order=client_order, back_moneys=back_moneys)
def index_pass(): if not g.user.is_finance(): abort(404) orders = set([ invoicepay.medium_invoice.client_order for invoicepay in MediumInvoicePay.get_medium_invoices_status(MEDIUM_INVOICE_STATUS_PASS)]) return tpl('/finance/client_order/medium_pay/index.html', orders=orders, title=u'已打的款媒体信息')
def back_invoice(): now_date = datetime.datetime.now() info = request.values.get('info', '').strip() location = int(request.values.get('location', 0)) year = request.values.get('year', now_date.strftime('%Y')) month = request.values.get('month', now_date.strftime('%m')) if month != '00': search_date = datetime.datetime.strptime( str(year) + '-' + str(month), '%Y-%m') end_search_date = ( search_date + datetime.timedelta(days=(search_date.max.day - search_date.day) + 1)).replace(day=1) orders = [k for k in BackInvoiceRebate.query.filter(BackInvoiceRebate.back_time >= search_date, BackInvoiceRebate.back_time < end_search_date) if k.douban_order.status == 1] else: orders = [k for k in BackInvoiceRebate.all() if k.back_time.year == int( year) and k.douban_order.status == 1] if location != 0: orders = [k for k in orders if location in k.douban_order.locations] if info: orders = [k for k in orders if info in k.douban_order.search_invoice_info] orders = sorted(list(orders), key=lambda x: x.back_time, reverse=False) if request.values.get('action', '') == 'download': response = write_order_excel(list(orders), 'douban_back_invoice') return response return tpl('/saler/douban_order/data_query/index.html', orders=orders, location=location, year=year, month=month, info=info, title=u"已收客户返点发票", t_type='douban_back_invoice')
def back_money(order_id): if not g.user.is_finance(): abort(404) order = searchAdRebateOrder.get(order_id) if not order: abort(404) if request.method == 'POST': money = float(request.values.get('money', 0)) back_time = request.values.get( 'back_time', datetime.date.today().strftime('%Y-%m-%d')) back_money_status = request.values.get('back_money_status', '') if back_money_status != '': if int(back_money_status) == 0: order.back_money_status = int(back_money_status) order.save() flash(u'完成所有回款!', 'success') order.add_comment(g.user, u"完成所有回款", msg_channel=4) else: bm = searchAdBackMoney.add( rebate_order=order, money=money, back_time=back_time, create_time=datetime.date.today().strftime('%Y-%m-%d')) bm.save() flash(u'回款信息保存成功!', 'success') order.add_comment( g.user, u"更新了回款信息,回款金额: %s; 回款时间: %s;" % (money, back_time), msg_channel=4) return redirect(url_for("searchAd_finance_rebate_order_back_money.back_money", order_id=order.id)) return tpl('/finance/searchAd_rebate_order/back_money/info.html', order=order)
def index(): if not g.user.is_finance(): abort(404) search_info = request.args.get('searchinfo', '') location_id = int(request.args.get('selected_location', '-1')) year = int(request.values.get('year', datetime.datetime.now().year)) orders = set([ invoice.client_medium_order for invoice in ClientMediumInvoice.get_invoices_status(INVOICE_STATUS_APPLYPASS)]) if location_id >= 0: orders = [o for o in orders if location_id in o.locations] orders = [k for k in orders if k.client_start.year == year or k.client_end.year == year] if search_info != '': orders = [ o for o in orders if search_info.lower() in o.search_invoice_info.lower()] select_locations = TEAM_LOCATION_CN.items() select_locations.insert(0, (-1, u'全部区域')) select_statuses = CONTRACT_STATUS_CN.items() select_statuses.insert(0, (-1, u'全部合同状态')) for k in orders: k.apply_count = len(k.get_invoice_by_status(3)) return tpl('/finance/client_medium_order/invoice/index.html', orders=orders, locations=select_locations, location_id=location_id, statuses=select_statuses, now_date=datetime.date.today(), search_info=search_info, year=year, params='?&searchinfo=%s&selected_location=%s&year=%s' % (search_info, location_id, str(year)))
def nianhui(): if request.method == 'POST': ids = request.values.get('ids', '') if NianHui.query.filter_by(user=g.user).count() > 0: return jsonify({'status': -1, 'msg': u'您已经投过票了'}) NianHui.add(user=g.user, create_time=datetime.datetime.now(), ids=ids) return jsonify({'status': 0, 'msg': '1123'}) ids = '|'.join([k.ids for k in NianHui.all()]) jm_count = {} total_count = 0 for k, v in JM.items(): jm_count[k] = 0 for k in ids.split('|'): total_count += 1 if int(k) in jm_count: jm_count[int(k)] += 1 jm_count = sorted(jm_count.iteritems(), key=lambda x: x[1]) jm_count.reverse() res = [] for k in jm_count: res.append({'name': JM[k[0]], 'count': k[1], 'percent': float(k[1]) / total_count * 100}) return tpl('/other/nhs.html', res=res, total_count=total_count)
def info(order_id): if not g.user.is_finance(): abort(404) order = FrameworkOrder.get(order_id) if not order or order.status == 0: abort(404) return tpl('/finance/framework_order/info.html', order=order)
def index(order_id): if not (g.user.is_super_leader() or g.user.is_finance() or g.user.is_aduit() or g.user.is_operater_leader()): abort(403) order = DoubanOrder.get(order_id) if not order: abort(404) return tpl('/saler/douban_order/other_cost/index.html', order=order)
def fix_data(): if not g.user.is_super_leader(): abort(403) year = int(request.values.get('year', 2015)) year_date = datetime.datetime.strptime(str(year), '%Y') orders = [k for k in ClientOrder.all() if k.client_start.year == year and k.contract_status not in [0, 7, 8, 9] and k.status == 1 and k.contract] for k in orders: for i in k.medium_orders: if int(k.self_agent_rebate.split('-')[0]) == 1: agent_rebate_value = float(k.self_agent_rebate.split('-')[1]) if k.money: i.medium_rebate_value = agent_rebate_value * i.sale_money / k.money else: i.medium_rebate_value = 0 else: medium_rebate = i.medium_rebate_by_year(year_date) i.medium_rebate_value = i.medium_money2 * medium_rebate / 100 if int(k.self_agent_rebate.split('-')[0]) == 1: k.agent_rebate_value = float(k.self_agent_rebate.split('-')[1]) else: agent_rebate = k.agent_rebate k.agent_rebate_value = k.money * agent_rebate / 100 if request.values.get('action') == 'download': return write_fix_date(orders) return tpl('/fix_data.html', orders=orders, year=year)
def index(order_id): order = ClientMediumOrder.get(order_id) if not order: abort(404) invoices = ClientMediumInvoice.query.filter_by(client_medium_order=order) invoices_data = { 'PASS': [{'invoice': x, 'form': get_invoice_from(x)} for x in invoices if x.invoice_status == INVOICE_STATUS_PASS], 'NORMAL': [{'invoice': x, 'form': get_invoice_from(x)} for x in invoices if x.invoice_status == INVOICE_STATUS_NORMAL], 'APPLY': [{'invoice': x, 'form': get_invoice_from(x)} for x in invoices if x.invoice_status == INVOICE_STATUS_APPLY], 'APPLYPASS': [{'invoice': x, 'form': get_invoice_from(x)} for x in invoices if x.invoice_status == INVOICE_STATUS_APPLYPASS], 'FAIL': [{'invoice': x, 'form': get_invoice_from(x)} for x in invoices if x.invoice_status == INVOICE_STATUS_FAIL], } reminder_emails = [(u.name, u.email) for u in User.all_active()] new_invoice_form = ClientMediumInvoiceForm() new_invoice_form.client_medium_order.choices = [(order.id, order.medium.name)] new_invoice_form.back_time.data = datetime.date.today() return tpl('/saler/client_medium_order/invoice/index.html', order=order, invoices_data=invoices_data, new_invoice_form=new_invoice_form, INVOICE_STATUS_CN=INVOICE_STATUS_CN, reminder_emails=reminder_emails, INVOICE_TYPE_CN=INVOICE_TYPE_CN)
def merger_douban_target(): targets = [k for k in OutSourceTarget.all() if k.otype in [1, None]] personal_targets = [k for k in OutSourceTarget.all() if k.otype == 2] return tpl('merger_douban_target.html', targets=targets, personal_targets=personal_targets, OUTSOURCE_STATUS_APPLY_MONEY=OUTSOURCE_STATUS_APPLY_MONEY, OUTSOURCE_STATUS_PAIED=OUTSOURCE_STATUS_PAIED, OUTSOURCE_STATUS_PASS=OUTSOURCE_STATUS_PASS)
def index(order_id): order = searchAdClientOrder.get(order_id) if not order: abort(404) invoices = searchAdInvoice.query.filter_by(client_order=order) invoices_data = { 'PASS': [{'invoice': x, 'form': get_invoice_from(x)} for x in invoices if x.invoice_status == INVOICE_STATUS_PASS], 'NORMAL': [{'invoice': x, 'form': get_invoice_from(x)} for x in invoices if x.invoice_status == INVOICE_STATUS_NORMAL], 'APPLY': [{'invoice': x, 'form': get_invoice_from(x)} for x in invoices if x.invoice_status == INVOICE_STATUS_APPLY], 'APPLYPASS': [{'invoice': x, 'form': get_invoice_from(x)} for x in invoices if x.invoice_status == INVOICE_STATUS_APPLYPASS], 'FAIL': [{'invoice': x, 'form': get_invoice_from(x)} for x in invoices if x.invoice_status == INVOICE_STATUS_FAIL], } reminder_emails = [(u.name, u.email) for u in User.all_active()] new_invoice_form = InvoiceForm() new_invoice_form.client_order.choices = [(order.id, order.client.name)] new_invoice_form.company.data = order.agent.name new_invoice_form.bank.data = order.agent.bank new_invoice_form.bank_id.data = order.agent.bank_num new_invoice_form.address.data = order.agent.address new_invoice_form.phone.data = order.agent.phone_num new_invoice_form.tax_id.data = order.agent.tax_num new_invoice_form.back_time.data = datetime.date.today() return tpl('/saler/searchAd_order/invoice/index.html', order=order, invoices_data=invoices_data, new_invoice_form=new_invoice_form, INVOICE_STATUS_CN=INVOICE_STATUS_CN, reminder_emails=reminder_emails, INVOICE_TYPE_CN=INVOICE_TYPE_CN)
def client_order_files(order_id): co = ClientOrder.get(order_id) return tpl("order_files.html", order=co)
def searchAd_client_order_files(order_id): order = searchAdClientOrder.get(order_id) return tpl("search_order_files.html", order=order)
def index(): now_year = request.values.get('year', '') now_Q = request.values.get('Q', '') location_id = int(request.values.get('location_id', 0)) if not now_year and not now_Q: now_date = datetime.date.today() now_year = now_date.strftime('%Y') now_month = now_date.strftime('%m') now_Q = check_month_get_Q(now_month) Q_monthes = check_Q_get_monthes(now_Q) start_Q_month = datetime.datetime(int(now_year), int(Q_monthes[0]), 1) # 获取下季度的第一天为本季度的结束时间 d = cal.monthrange(int(now_year), int(Q_monthes[-1])) end_Q_month = datetime.datetime(int(now_year), int(Q_monthes[-1]), d[1]) + datetime.timedelta(days=1) # 获取该季度及之前所有回款 client_back_moneys = [ _dict_back_money(k) for k in BackMoney.query.filter(BackMoney.back_time < end_Q_month) ] douban_back_moneys = [ _dict_back_money(k) for k in DoubanBackMoney.query.filter( BackMoney.back_time < end_Q_month) ] # ####################获取相关订单执行额,用于计算销售季度完成率################## client_continue_time = [] for k in client_back_moneys: client_continue_time += [k['order_start'], k['order_end']] douban_countinue_time = [] for k in douban_back_moneys: douban_countinue_time += [k['order_start'], k['order_end']] client_continue_time.sort() douban_countinue_time.sort() if client_continue_time: client_continue_start = client_continue_time[0].replace(day=1) client_continue_end = client_continue_time[-1].replace(day=1) client_report = list( ClientOrderExecutiveReport.query.filter( ClientOrderExecutiveReport.month_day >= client_continue_start, ClientOrderExecutiveReport.month_day <= client_continue_end)) else: client_report = [] if douban_countinue_time: douban_countinue_start = douban_countinue_time[0].replace(day=1) douban_countinue_end = douban_countinue_time[-1].replace(day=1) douban_report = list( DoubanOrderExecutiveReport.query.filter( DoubanOrderExecutiveReport.month_day >= douban_countinue_start, DoubanOrderExecutiveReport.month_day <= douban_countinue_end)) else: douban_report = [] # ####################获取相关订单执行额,用于计算销售季度完成率################## # 获取当前季度所有回款 now_Q_client_back_moneys = [ k for k in client_back_moneys if k['back_time'] >= start_Q_month ] now_Q_douban_back_moneys = [ k for k in douban_back_moneys if k['back_time'] >= start_Q_month ] # 回去当季度回款的所有合同 client_orders = list(set([k['order'] for k in now_Q_client_back_moneys])) douban_orders = list(set([k['order'] for k in now_Q_douban_back_moneys])) orders = [ _order_to_dict(k, start_Q_month, client_back_moneys, now_Q_client_back_moneys, client_report) for k in client_orders if k.contract_status not in [7, 8, 81, 9] and k.status == 1 and k.contract ] orders += [ _order_to_dict(k, start_Q_month, douban_back_moneys, now_Q_douban_back_moneys, douban_report) for k in douban_orders if k.contract_status not in [7, 8, 81, 9] and k.status == 1 and k.contract ] if g.user.is_super_leader() or g.user.is_finance(): orders = orders elif g.user.is_leader(): orders = [k for k in orders if g.user.location in k['locations']] else: orders = [k for k in orders if g.user.id in k['salers_ids']] if location_id: orders = [k for k in orders if location_id in k['locations']] return tpl('/data_query/commission/index.html', orders=orders, Q=now_Q, now_year=now_year, Q_monthes=Q_monthes, location_id=location_id)
def info(): now_year = int(request.values.get('year', datetime.datetime.now().year)) outsources = [_cost_outsource_to_dict(k) for k in ClientOtherCost.all()] outsources += [_cost_outsource_to_dict(k) for k in DoubanOtherCost.all()] outsources = [ k for k in outsources if int(k['month_day'].year) == int(now_year) ] r_outsource_pay = sum([k['money'] for k in outsources]) # 每季度月份数 Q1_monthes = [ datetime.datetime.strptime(str(now_year) + '-' + k, '%Y-%m') for k in check_Q_get_monthes('Q1') ] Q2_monthes = [ datetime.datetime.strptime(str(now_year) + '-' + k, '%Y-%m') for k in check_Q_get_monthes('Q2') ] Q3_monthes = [ datetime.datetime.strptime(str(now_year) + '-' + k, '%Y-%m') for k in check_Q_get_monthes('Q3') ] Q4_monthes = [ datetime.datetime.strptime(str(now_year) + '-' + k, '%Y-%m') for k in check_Q_get_monthes('Q4') ] total = 0 orders = list( set([s['order'] for s in outsources if s['on_time'].year == now_year])) for i in orders: o_money = [] o_money += [ float( sum([ o['money'] for o in outsources if o['month_day'] >= Q1_monthes[0] and o['month_day'] <= Q1_monthes[2] and o['type'] == t and o['order'] == i ])) for t in range(1, 6) ] o_money += [ float( sum([ o['money'] for o in outsources if o['month_day'] >= Q2_monthes[0] and o['month_day'] <= Q2_monthes[2] and o['type'] == t and o['order'] == i ])) for t in range(1, 6) ] o_money += [ float( sum([ o['money'] for o in outsources if o['month_day'] >= Q3_monthes[0] and o['month_day'] <= Q3_monthes[2] and o['type'] == t and o['order'] == i ])) for t in range(1, 6) ] o_money += [ float( sum([ o['money'] for o in outsources if o['month_day'] >= Q4_monthes[0] and o['month_day'] <= Q4_monthes[2] and o['type'] == t and o['order'] == i ])) for t in range(1, 6) ] i.o_money = o_money total += sum(o_money) if request.values.get('action', '') == 'download': return write_cost_outsource_info_excel(now_year, orders, total, r_outsource_pay) return tpl('/data_query/outsource/cost_info.html', now_year=now_year, orders=orders, total=total, r_outsource_pay=r_outsource_pay)
def notice_index(): notices = Notice.all() return tpl('/account/data/notice/index.html', notices=notices)
def index(): if not g.user.is_finance(): abort(404) orders = set([ invoice.client_order for invoice in searchAdInvoice.get_invoices_status(INVOICE_STATUS_APPLYPASS)]) return tpl('/finance/searchAd_order/invoice/index.html', orders=orders)
def framework_order_files(order_id): fo = FrameworkOrder.get(order_id) return tpl("order_files.html", order=fo)
def searchAd_medium_order_files(order_id): order = searchAdOrder.get(order_id) return tpl('search_order_files.html', order=order)
def index(order_id): order = DoubanOrder.get(order_id) if not order: abort(404) return tpl('/saler/douban_order/back_money/index.html', order=order)
def medium_order_files(order_id): co = Order.get(order_id) return tpl("order_files.html", order=co)
def info(oid): out = Out.get(oid) return tpl('/account/out/info.html', out=out)
def index(order_id): order = searchAdRebateOrder.get(order_id) if not order: abort(404) return tpl('/saler/searchAd_rebate_order/back_money/index.html', order=order)
def index(order_id): order = DoubanOrder.get(order_id) return tpl('/saler/douban_order/money/index.html', order=order)
def update(oid): out = Out.get(oid) joiners_form = JoinersForm(request.form) joiners_form.joiners.data = [u.id for u in out.joiners] m_persions = [] if g.user.is_out_saler: m_persions += [{'key': '1' + '-' + str(k.id) + '-' + k.name, 'name': k.name} for k in Client.all()] m_persions += [{'key': '2' + '-' + str(k.id) + '-' + k.name, 'name': k.name} for k in Agent.all()] m_persions += [{'key': '3' + '-' + str(k.id) + '-' + k.name, 'name': k.name} for k in Medium.all()] m_persions.append({'key': 100, 'name': u'其他'}) if request.method == 'POST': if g.user.is_out_saler: creator_type = 1 else: creator_type = 2 start_time = request.values.get('start_time', '') end_time = request.values.get('end_time', '') # m_person有两种类型,一种是其他所以填写,一种是代理+客户+媒体组合而成,例如:1-1,2-1,3-1(具体请查看m_persions) m_persion = request.values.get('m_persion', '') m_persion_type = int(request.values.get('m_persion_type', 1)) reason = request.values.get('reason', '') persions = request.values.get('persions', '') address = request.values.get('address', '') joiners = User.gets(request.values.getlist('joiners')) out.start_time = datetime.datetime.strptime( start_time, '%Y-%m-%d %H:%M') out.end_time = datetime.datetime.strptime(end_time, '%Y-%m-%d %H:%M') out.reason = reason out.joiners = joiners out.persions = persions out.address = address out.m_persion = m_persion out.m_persion_type = m_persion_type out.creator_type = creator_type out.status = int(request.values.get('action', 0)) out.create_time = datetime.datetime.now() out.save() # 先删除外出报表,在从新添加 OutReport.query.filter_by(out_id=oid).delete() for k in list(set(joiners + [out.creator])): OutReport.add( start_time=datetime.datetime.strptime( start_time, '%Y-%m-%d %H:%M'), end_time=datetime.datetime.strptime( end_time, '%Y-%m-%d %H:%M'), reason=reason, out=out, meeting_s='', persions=persions, address=address, m_persion=m_persion, m_persion_type=m_persion_type, creator_type=creator_type, status=int(request.values.get('action', 0)), creator=k, create_time=datetime.datetime.now() ) if int(int(request.values.get('action', 0))) == OUT_STATUS_APPLY: flash(u'已发送申请', 'success') account_out_apply_signal.send( current_app._get_current_object(), out=out, status=1) else: flash(u'添加成功,请及时申请外出报备', 'success') return redirect(url_for('account_out.index')) return tpl('/account/out/update.html', out=out, m_persions=m_persions, joiners_form=joiners_form)
def teams(): teams = Team.all() return tpl('teams.html', teams=teams)
def info(lid): leave = Leave.get(lid) return tpl('/account/leave/info.html', leave=leave)
def contact(): if g.user.is_super_leader() or g.user.is_leader() or g.user.is_HR() or g.user.is_OPS(): users = User.all_active() else: abort(403) return tpl('contact.html', users=users)
def users(): users = User.all() return tpl('users.html', users=users)
def saler(): if not (g.user.is_super_leader() or g.user.is_finance()): abort(403) now_year = request.values.get('year', '') now_Q = request.values.get('Q', '') location_id = int(request.values.get('location_id', 0)) if not now_year and not now_Q: now_date = datetime.date.today() now_year = now_date.strftime('%Y') now_month = now_date.strftime('%m') now_Q = check_month_get_Q(now_month) Q_monthes = check_Q_get_monthes(now_Q) start_Q_month = datetime.datetime(int(now_year), int(Q_monthes[0]), 1) # 获取下季度的第一天为本季度的结束时间 d = cal.monthrange(int(now_year), int(Q_monthes[-1])) end_Q_month = datetime.datetime(int(now_year), int(Q_monthes[-1]), d[1]) + datetime.timedelta(days=1) # 获取该季度及之前所有回款及返点发票 client_back_moneys = [ _dict_back_money(k, 'money') for k in BackMoney.query.filter(BackMoney.back_time < end_Q_month) ] client_back_moneys += [ _dict_back_money(k, 'invoice') for k in BackInvoiceRebate.query.filter( BackInvoiceRebate.back_time < end_Q_month) ] douban_back_moneys = [ _dict_back_money(k, 'money') for k in DoubanBackMoney.query.filter( DoubanBackMoney.back_time < end_Q_month) ] douban_back_moneys += [ _dict_back_money(k, 'invoice') for k in DoubanBackInvoiceRebate.query.filter( DoubanBackInvoiceRebate.back_time < end_Q_month) ] # 获取当前季度所有回款 now_Q_client_back_moneys = [ k for k in client_back_moneys if k['back_time'] >= start_Q_month ] now_Q_douban_back_moneys = [ k for k in douban_back_moneys if k['back_time'] >= start_Q_month ] # 获取当季度回款的所有合同 client_orders = list(set([k['order'] for k in now_Q_client_back_moneys])) douban_orders = list(set([k['order'] for k in now_Q_douban_back_moneys])) orders = [ _order_to_dict(k, start_Q_month, end_Q_month, client_back_moneys, now_Q_client_back_moneys) for k in client_orders if k.contract_status not in [7, 8, 9] and k.status == 1 and k.contract ] orders += [ _order_to_dict(k, start_Q_month, end_Q_month, douban_back_moneys, now_Q_douban_back_moneys) for k in douban_orders if k.contract_status not in [7, 8, 9] and k.status == 1 and k.contract ] if location_id: orders = [k for k in orders if location_id in k['locations']] orders = sorted(orders, key=operator.itemgetter('client_start'), reverse=False) if request.values.get('action') == 'download': return write_report_excel(Q=now_Q, now_year=now_year, orders=orders) return tpl('/account/commission/saler.html', Q=now_Q, now_year=now_year, Q_monthes=Q_monthes, location_id=location_id, orders=orders)
def info(): now_year = int(request.values.get('year', datetime.datetime.now().year)) outsources = OutSourceExecutiveReport.all() outsources = [ outsource_to_dict(k) for k in outsources if int(k.month_day.year) == int(now_year) ] # 踢掉删除的合同 outsources = [k for k in outsources if k['order_status'] == 1] r_outsource_pay = sum([k['pay_num'] for k in outsources]) # pre_monthes = get_monthes_pre_days(start_date, end_date) # 季度月份数 Q1_monthes = [ datetime.datetime.strptime(str(now_year) + '-' + k, '%Y-%m') for k in check_Q_get_monthes('Q1') ] Q2_monthes = [ datetime.datetime.strptime(str(now_year) + '-' + k, '%Y-%m') for k in check_Q_get_monthes('Q2') ] Q3_monthes = [ datetime.datetime.strptime(str(now_year) + '-' + k, '%Y-%m') for k in check_Q_get_monthes('Q3') ] Q4_monthes = [ datetime.datetime.strptime(str(now_year) + '-' + k, '%Y-%m') for k in check_Q_get_monthes('Q4') ] total = 0 orders = list(set([s['order'] for s in outsources])) for i in orders: o_money = [] o_money += [ float( sum([ o['pay_num'] for o in outsources if o['month_day'] >= Q1_monthes[0] and o['month_day'] <= Q1_monthes[2] and o['type'] == t and o['order'] == i ])) for t in range(1, 10) ] o_money += [ float( sum([ o['pay_num'] for o in outsources if o['month_day'] >= Q2_monthes[0] and o['month_day'] <= Q2_monthes[2] and o['type'] == t and o['order'] == i ])) for t in range(1, 10) ] o_money += [ float( sum([ o['pay_num'] for o in outsources if o['month_day'] >= Q3_monthes[0] and o['month_day'] <= Q3_monthes[2] and o['type'] == t and o['order'] == i ])) for t in range(1, 10) ] o_money += [ float( sum([ o['pay_num'] for o in outsources if o['month_day'] >= Q4_monthes[0] and o['month_day'] <= Q4_monthes[2] and o['type'] == t and o['order'] == i ])) for t in range(1, 10) ] i.o_money = o_money total += sum(o_money) if request.values.get('action', '') == 'download': return write_outsource_info_excel(now_year, orders, total, r_outsource_pay) return tpl('/data_query/outsource/info.html', now_year=now_year, orders=orders, total=total, r_outsource_pay=r_outsource_pay)
def info(user_id): if not (g.user.is_super_leader() or g.user.is_finance()): return abort(404) user = User.get(user_id) comp = Completion.query.filter_by(user_id=user_id) return tpl('/account/completion/info.html', user=user, comp=comp)
def index(): now_year = request.values.get('year', '') now_Q = request.values.get('Q', '') if not now_year and not now_Q: now_date = datetime.date.today() now_year = now_date.strftime('%Y') now_month = now_date.strftime('%m') now_Q = check_month_get_Q(now_month) Q_monthes = check_Q_get_monthes(now_Q) start_month_day = datetime.datetime.strptime( now_year + '-' + str(Q_monthes[0]), '%Y-%m') end_month_day = datetime.datetime.strptime( now_year + '-' + str(Q_monthes[-1]), '%Y-%m') outsources = OutSourceExecutiveReport.all() if now_Q == '00': outsources = [ k for k in outsources if int(k.month_day.year) == int(now_year) ] else: outsources = [ k for k in outsources if k.month_day >= start_month_day and k.month_day <= end_month_day ] # 踢掉删除的合同 outsources = [outsource_to_dict(k) for k in outsources] outsources = [k for k in outsources if k['order_status'] == 1] # 所有外包分类 types = [1, 2, 3, 4, 5, 6, 7, 8, 9] monthes_data = {} for k in types: monthes_data[str(k)] = [] monthes_data['t_locataion'] = [] monthes_data['t_month'] = [] for k in Q_monthes: month_day = datetime.datetime.strptime(now_year + '-' + str(k), '%Y-%m') t_huabei_num = 0 t_huadong_num = 0 t_huanan_num = 0 for i in types: num_data = {} num_data['huabei'] = sum([ j['l_pre_pay_num'] for j in outsources if j['month_day'] == month_day and j['type'] == i and 1 in j['locations'] ]) num_data['huadong'] = sum([ j['l_pre_pay_num'] for j in outsources if j['month_day'] == month_day and j['type'] == i and 2 in j['locations'] ]) num_data['huanan'] = sum([ j['l_pre_pay_num'] for j in outsources if j['month_day'] == month_day and j['type'] == i and 3 in j['locations'] ]) t_huabei_num += num_data['huabei'] t_huadong_num += num_data['huadong'] t_huanan_num += num_data['huanan'] monthes_data[str(i)].append(num_data) monthes_data['t_locataion'].append({ 'huabei': t_huabei_num, 'huadong': t_huadong_num, 'huanan': t_huanan_num }) monthes_data['t_month'].append(t_huabei_num + t_huadong_num + t_huanan_num) if request.values.get('action', '') == 'download': return write_outsource_excel(Q_monthes, monthes_data) return tpl('/data_query/outsource/index.html', Q=now_Q, now_year=now_year, Q_monthes=Q_monthes, monthes_data=monthes_data)
def info_last(mid, type): medium = Medium.get(mid) reminder_emails = [(u.name, u.email) for u in User.all_active()] return tpl('/mediums/files/info_last.html', medium=medium, type=int(type), title=ATTACHMENT_TYPE[int(type)], reminder_emails=reminder_emails)
def update(pid): resource = MediumResource.get(pid) form = NewMediumResourceForm(request.form) form.medium.data = resource.medium.id form.type.data = resource.type form.number.data = resource.number form.shape.data = resource.shape form.product.data = resource.product form.resource_type.data = resource.resource_type form.page_postion.data = resource.page_postion form.ad_position.data = resource.ad_position form.cpm.data = resource.cpm form.b_click.data = resource.b_click form.click_rate.data = resource.click_rate form.buy_unit.data = resource.buy_unit form.buy_threshold.data = resource.buy_threshold form.money.data = resource.money form.b_directional.data = resource.b_directional form.directional_type.data = resource.directional_type form.directional_money.data = resource.directional_money form.discount.data = resource.discount form.ad_size.data = resource.ad_size form.materiel_format.data = resource.materiel_format form.less_buy.data = resource.less_buy form.b_give.data = resource.b_give form.give_desc.data = resource.give_desc form.b_check_exposure.data = resource.b_check_exposure form.b_check_click.data = resource.b_check_click form.b_out_link.data = resource.b_out_link form.b_in_link.data = resource.b_in_link form.description.data = resource.description resource.c_body = json.loads(resource.body) if request.method == 'POST' and form.validate(): body = [] custom_ids = request.values.get('custom_ids', '') for x in custom_ids.split('|'): key = request.values.get('custom_key_' + str(x), '') value = request.values.get('custom_value_' + str(x), '') body.append({'c_key': key, 'c_value': value}) form = NewMediumResourceForm(request.form) if resource.number != form.number.data and MediumResource.query.filter_by(number=form.number.data).count() > 0: flash(u'资源编号已存在', 'danger') return tpl('/mediums/resource/update.html', form=form, resource=resource) resource.medium = Medium.get(form.medium.data) resource.type = form.type.data resource.number = form.number.data resource.shape = form.shape.data resource.product = form.product.data resource.resource_type = form.resource_type.data resource.page_postion = form.page_postion.data resource.ad_position = form.ad_position.data resource.cpm = form.cpm.data resource.b_click = form.b_click.data resource.click_rate = form.click_rate.data resource.buy_unit = form.buy_unit.data resource.buy_threshold = form.buy_threshold.data resource.money = form.money.data resource.b_directional = form.b_directional.data resource.directional_type = form.directional_type.data resource.directional_money = form.directional_money.data resource.discount = form.discount.data resource.ad_size = form.ad_size.data resource.materiel_format = form.materiel_format.data resource.less_buy = form.less_buy.data resource.b_give = form.b_give.data resource.give_desc = form.give_desc.data resource.b_check_exposure = form.b_check_exposure.data resource.b_check_click = form.b_check_click.data resource.b_out_link = form.b_out_link.data resource.b_in_link = form.b_in_link.data resource.description = form.description.data resource.body = json.dumps(body) resource.update_time = datetime.datetime.now() resource.save() flash(u'修改成功', 'success') return redirect(url_for('mediums_resource.update', pid=resource.id)) return tpl('/mediums/resource/update.html', resource=resource, form=form)