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 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 outsource(): if not (g.user.is_leader() or g.user.is_super_leader()): abort(403) orders = list(ClientOrder.all()) orders += list(DoubanOrder.all()) orders = [k for k in orders if k.status == 1] search_info = request.values.get('search_info', '') location = int(request.values.get('location', 0)) if search_info: orders = [ k for k in orders if search_info.lower().strip() in k.search_info.lower() ] if location: orders = [k for k in orders if location in k.locations] if g.user.team.type == TEAM_TYPE_LEADER: orders = [ o for o in orders if g.user.location in o.locations and o.get_outsources_by_status(1) ] elif g.user.team.type == TEAM_TYPE_SUPER_LEADER: orders = [o for o in orders if o.get_outsources_by_status(5)] if g.user.is_super_admin(): orders = [ o for o in orders if o.get_outsources_by_status(5) or o.get_outsources_by_status(1) ] return tpl('/manage/apply/order.html', title=u'外包费用报备审批', orders=orders, search_info=search_info, location=location, a_type="outsource")
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 order_info(): now_year = int(request.values.get('year', datetime.datetime.now().year)) outsources = [_target_outsource_to_dict( k, 'client_order') for k in OutSource.all()] outsources += [_target_outsource_to_dict(k, 'douban_order') for k in DoubanOutSource.all()] outsources = [k for k in outsources if k] orders = [k for k in ClientOrder.all() if (k.client_start.year == now_year or k.client_end.year == now_year) and k.status == 1] orders += [k for k in DoubanOrder.all() if (k.client_start.year == now_year or k.client_end.year == now_year) and k.status == 1] 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] else: order_dict['outsource_obj'] = [o for o in outsources if o[ 'order_type'] == 'douban_order' and o['order_id'] == k.id] order_dict['contract'] = k.contract order_dict['campaign'] = k.campaign order_dict['money'] = k.money order_dict['locations_cn'] = k.locations_cn order_dict['outsources_sum'] = k.outsources_sum order_dict['outsources_percent'] = k.outsources_percent order_dict['outsources_paied_sum'] = k.outsources_paied_sum_by_shenji('all') if order_dict['outsource_obj']: order_obj.append(order_dict) if request.values.get('action', '') == 'download': return write_outsource_order_info_excel(order_obj) return tpl('/data_query/outsource/order_info.html', orders=order_obj, now_year=now_year)
def index(): if not g.user.is_finance(): abort(404) orders = list(ClientOrder.all()) if request.args.get('selected_status'): status_id = int(request.args.get('selected_status')) else: status_id = -1 orderby = request.args.get('orderby', '') search_info = request.args.get('searchinfo', '').strip() location_id = int(request.args.get('selected_location', '-1')) page = int(request.args.get('p', 1)) year = int(request.values.get('year', datetime.datetime.now().year)) # page = max(1, page) # start = (page - 1) * ORDER_PAGE_NUM if location_id >= 0: orders = [o for o in orders if location_id in o.locations] if status_id >= 0: orders = [o for o in orders if o.contract_status == status_id] 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() ] if orderby and len(orders): orders = sorted(orders, key=lambda x: getattr(x, orderby), reverse=True) select_locations = TEAM_LOCATION_CN.items() select_locations.insert(0, (-1, u'全部区域')) select_statuses = CONTRACT_STATUS_CN.items() select_statuses.insert(0, (-1, u'全部合同状态')) paginator = Paginator(orders, ORDER_PAGE_NUM) try: orders = paginator.page(page) except: orders = paginator.page(paginator.num_pages) return tpl( '/finance/client_order/medium_back_money/index.html', orders=orders, locations=select_locations, location_id=location_id, statuses=select_statuses, status_id=status_id, orderby=orderby, now_date=datetime.date.today(), search_info=search_info, page=page, year=year, params= '&orderby=%s&searchinfo=%s&selected_location=%s&selected_status=%s&year=%s' % (orderby, search_info, location_id, status_id, str(year)))
def index(): if not g.user.is_finance(): abort(404) orders = list(ClientOrder.all()) orderby = request.args.get('orderby', '') search_info = request.args.get('searchinfo', '') location_id = int(request.args.get('selected_location', '-1')) page = int(request.args.get('p', 1)) year = int(request.values.get('year', datetime.datetime.now().year)) 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() ] if orderby and len(orders): orders = sorted(orders, key=lambda x: getattr(x, orderby), reverse=True) select_locations = TEAM_LOCATION_CN.items() select_locations.insert(0, (-1, u'全部区域')) select_statuses = CONTRACT_STATUS_CN.items() select_statuses.insert(0, (-1, u'全部合同状态')) paginator = Paginator(orders, ORDER_PAGE_NUM) try: orders = paginator.page(page) except: orders = paginator.page(paginator.num_pages) for k in orders.object_list: k.ex_money = sum([ i.ex_money for i in OutsourceInvoice.query.filter_by(client_order=k) ]) k.pay_num = sum([i.pay_num for i in k.get_outsources_by_status(4)]) apply_outsources = [] for i in [1, 2, 3, 5]: apply_outsources += k.get_outsources_by_status(i) k.apply_money = sum([j.pay_num for j in apply_outsources]) return tpl( '/finance/client_order/outsource/invoice.html', orders=orders, locations=select_locations, location_id=location_id, statuses=select_statuses, orderby=orderby, now_date=datetime.date.today(), search_info=search_info, page=page, year=year, params='&orderby=%s&searchinfo=%s&selected_location=%s&year=%s' % (orderby, search_info, location_id, year))
def index_pass(): if not g.user.is_finance(): abort(404) orders = list(ClientOrder.all()) search_info = request.args.get('searchinfo', '').strip() location_id = int(request.args.get('selected_location', '-1')) year = int(request.values.get('year', datetime.datetime.now().year)) page = int(request.args.get('p', 1)) 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'全部合同状态')) paginator = Paginator(orders, ORDER_PAGE_NUM) try: orders = paginator.page(page) except: orders = paginator.page(paginator.num_pages) type = request.args.get('type', '') if type == 'excel': orders = set([ invoice.client_order for invoice in Invoice.get_invoices_status(INVOICE_STATUS_PASS) ]) xls = write_excel(list(orders)) response = get_download_response( xls, ("%s-%s.xls" % (u"申请过的发票信息", datetime.datetime.now().strftime('%Y%m%d%H%M%S')) ).encode('utf-8')) return response return tpl('/finance/client_order/invoice/index_pass.html', orders=orders, locations=select_locations, location_id=location_id, statuses=select_statuses, now_date=datetime.date.today(), search_info=search_info, page=page, year=year, params='&searchinfo=%s&selected_location=%s&year=%s' % (search_info, location_id, str(year)))
def index(): if not g.user.is_finance(): abort(404) orders = list(ClientOrder.all()) search_info = request.args.get('searchinfo', '').strip() location_id = int(request.args.get('selected_location', '-1')) page = int(request.args.get('p', 1)) year = int(request.values.get('year', datetime.datetime.now().year)) 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'全部合同状态')) paginator = Paginator(orders, ORDER_PAGE_NUM) try: orders = paginator.page(page) except: orders = paginator.page(paginator.num_pages) for i in orders.object_list: client_order = i agent_invoices = [ k.id for k in AgentInvoice.query.filter_by(client_order=client_order) ] pays = [ k for k in AgentInvoicePay.all() if k.agent_invoice_id in agent_invoices ] i.apply_num = len([k for k in pays if k.pay_status == 4]) i.pay_num = len([k for k in pays if k.pay_status == 0]) return tpl('/finance/client_order/agent_pay/index.html', orders=orders, title=u'全部客户付款', locations=select_locations, location_id=location_id, statuses=select_statuses, now_date=datetime.date.today(), search_info=search_info, page=page, year=year, params='&&searchinfo=%s&selected_location=%s&year=%s' % (search_info, location_id, str(year)))
def order_info(): now_year = int(request.values.get('year', datetime.datetime.now().year)) outsources = [ _target_outsource_to_dict(k, 'client_order') for k in OutSource.all() ] outsources += [ _target_outsource_to_dict(k, 'douban_order') for k in DoubanOutSource.all() ] outsources = [k for k in outsources if k] orders = [ k for k in ClientOrder.all() if (k.client_start.year == now_year or k.client_end.year == now_year) and k.status == 1 ] orders += [ k for k in DoubanOrder.all() if (k.client_start.year == now_year or k.client_end.year == now_year) and k.status == 1 ] 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 ] else: order_dict['outsource_obj'] = [ o for o in outsources if o['order_type'] == 'douban_order' and o['order_id'] == k.id ] order_dict['contract'] = k.contract order_dict['campaign'] = k.campaign order_dict['money'] = k.money order_dict['locations_cn'] = k.locations_cn order_dict['outsources_sum'] = k.outsources_sum order_dict['outsources_percent'] = k.outsources_percent order_dict['outsources_paied_sum'] = k.outsources_paied_sum_by_shenji( 'all') if order_dict['outsource_obj']: order_obj.append(order_dict) if request.values.get('action', '') == 'download': return write_outsource_order_info_excel(order_obj) return tpl('/data_query/outsource/order_info.html', orders=order_obj, now_year=now_year)
def index(): if not g.user.is_finance(): abort(404) orders = list(ClientOrder.all()) if request.args.get('selected_status'): status_id = int(request.args.get('selected_status')) else: status_id = -1 orderby = request.args.get('orderby', '') search_info = request.args.get('searchinfo', '').strip() location_id = int(request.args.get('selected_location', '-1')) page = int(request.args.get('p', 1)) year = int(request.values.get('year', datetime.datetime.now().year)) # page = max(1, page) # start = (page - 1) * ORDER_PAGE_NUM if location_id >= 0: orders = [o for o in orders if location_id in o.locations] if status_id >= 0: orders = [o for o in orders if o.contract_status == status_id] 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'全部合同状态')) paginator = Paginator(orders, ORDER_PAGE_NUM) try: orders = paginator.page(page) except: orders = paginator.page(paginator.num_pages) for i in orders.object_list: client_order = i medium_invoices = [k.id for k in MediumInvoice.query.filter_by(client_order=client_order)] pays = [k for k in MediumInvoicePay.all() if k.medium_invoice_id in medium_invoices] i.apply_num = len([k for k in pays if k.pay_status == 4]) i.pay_num = len([k for k in pays if k.pay_status == 0]) return tpl('/finance/client_order/medium_pay/index_pass.html', orders=orders, title=u'申请中的媒体付款', locations=select_locations, location_id=location_id, statuses=select_statuses, status_id=status_id, orderby=orderby, now_date=datetime.date.today(), search_info=search_info, page=page, year=year, params='&orderby=%s&searchinfo=%s&selected_location=%s&selected_status=%s&year=%s' % (orderby, search_info, location_id, status_id, str(year)))
def index(): if not g.user.is_finance(): abort(404) orders = list(ClientOrder.all()) if request.args.get('selected_status'): status_id = int(request.args.get('selected_status')) else: status_id = -1 orderby = request.args.get('orderby', '') search_info = request.args.get('searchinfo', '').strip() location_id = int(request.args.get('selected_location', '-1')) page = int(request.args.get('p', 1)) year = int(request.values.get('year', datetime.datetime.now().year)) # page = max(1, page) # start = (page - 1) * ORDER_PAGE_NUM if location_id >= 0: orders = [o for o in orders if location_id in o.locations] if status_id >= 0: orders = [o for o in orders if o.contract_status == status_id] 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()] if orderby and len(orders): orders = sorted( orders, key=lambda x: getattr(x, orderby), reverse=True) select_locations = TEAM_LOCATION_CN.items() select_locations.insert(0, (-1, u'全部区域')) select_statuses = CONTRACT_STATUS_CN.items() select_statuses.insert(0, (-1, u'全部合同状态')) paginator = Paginator(orders, ORDER_PAGE_NUM) try: orders = paginator.page(page) except: orders = paginator.page(paginator.num_pages) return tpl('/finance/client_order/medium_back_money/index.html', orders=orders, locations=select_locations, location_id=location_id, statuses=select_statuses, status_id=status_id, orderby=orderby, now_date=datetime.date.today(), search_info=search_info, page=page, year=year, params='&orderby=%s&searchinfo=%s&selected_location=%s&selected_status=%s&year=%s' % (orderby, search_info, location_id, status_id, str(year)))
def index_pass(): if not g.user.is_finance(): abort(404) orders = list(ClientOrder.all()) orderby = request.args.get('orderby', '') search_info = request.args.get('searchinfo', '').strip() location_id = int(request.args.get('selected_location', '-1')) page = int(request.args.get('p', 1)) year = int(request.values.get('year', datetime.datetime.now().year)) 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()] if orderby and len(orders): orders = sorted( orders, key=lambda x: getattr(x, orderby), reverse=True) select_locations = TEAM_LOCATION_CN.items() select_locations.insert(0, (-1, u'全部区域')) select_statuses = CONTRACT_STATUS_CN.items() select_statuses.insert(0, (-1, u'全部合同状态')) paginator = Paginator(orders, ORDER_PAGE_NUM) try: orders = paginator.page(page) except: orders = paginator.page(paginator.num_pages) type = request.args.get('type', '') if type == 'excel': orders = set([invoice.client_order for invoice in MediumRebateInvoice.get_invoices_status( INVOICE_STATUS_PASS)]) xls = write_medium_rebate_invoice_excel(list(orders)) response = get_download_response( xls, ("%s-%s.xls" % (u"申请过的媒体返点发票信息", datetime.datetime.now().strftime('%Y%m%d%H%M%S'))).encode('utf-8')) return response return tpl('/finance/client_order/medium_rebate_invoice/index_pass.html', orders=orders, locations=select_locations, location_id=location_id, statuses=select_statuses, orderby=orderby, now_date=datetime.date.today(), search_info=search_info, page=page, year=year, params='&orderby=%s&searchinfo=%s&selected_location=%s&year=%s' % (orderby, search_info, location_id, str(year)))
def index(): if not (g.user.is_super_leader() or g.user.is_aduit() or g.user.is_finance()): abort(403) now_date = datetime.datetime.now() year = int(request.values.get('year', now_date.year)) orders = [_format_order(k, year) for k in ClientOrder.all()] orders = [k for k in orders if k['client_start'].year == year] # 去掉撤单、申请中的合同 orders = [k for k in orders if k['contract_status'] in [2, 4, 5, 10, 19, 20] and k['status'] == 1 and k['contract']] # 获取所有代理 agents = [{'name': a.name, 'id': a.id, 'group_id': a.group.id} for a in Agent.all()] # 获取代理集团 groups = [{'name': gp.name, 'agents': [p for p in agents if p['group_id'] == gp.id]} for gp in Group.all()] # xxx_count 用于html合并表单 agent_obj = [] total_is_sale_money = 0 total_is_medium_money = 0 for k in groups: if not k['agents']: html_order_count = 0 else: html_order_count = 1 excel_order_count = 0 agent_data = [] for a in k['agents']: order_data = [o for o in orders if o['agent_id'] == a['id']] if order_data: html_order_count += len(order_data) + 1 excel_order_count += len(order_data) total_is_sale_money += sum([o['is_sale_money'] for o in order_data]) total_is_medium_money += sum([o['is_medium_money'] for o in order_data]) agent_data.append({'name': a['name'], 'orders': order_data, 'html_order_count': len(order_data)}) if agent_data: agent_obj.append({'name': k['name'], 'agents': agent_data, 'html_order_count': html_order_count, 'excel_order_count': excel_order_count}) action = request.values.get('action', '') if action == 'excel': return write_agent_total_excel(year=year, agent_obj=agent_obj, total_is_sale_money=total_is_sale_money, total_is_medium_money=total_is_medium_money) return tpl('/data_query/super_leader/agent_total.html', year=year, agent_obj=agent_obj, total_is_sale_money=total_is_sale_money, total_is_medium_money=total_is_medium_money)
def index(): if not g.user.is_finance(): abort(404) orders = list(ClientOrder.all()) orderby = request.args.get('orderby', '') search_info = request.args.get('searchinfo', '') location_id = int(request.args.get('selected_location', '-1')) page = int(request.args.get('p', 1)) year = int(request.values.get('year', datetime.datetime.now().year)) 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()] if orderby and len(orders): orders = sorted( orders, key=lambda x: getattr(x, orderby), reverse=True) select_locations = TEAM_LOCATION_CN.items() select_locations.insert(0, (-1, u'全部区域')) select_statuses = CONTRACT_STATUS_CN.items() select_statuses.insert(0, (-1, u'全部合同状态')) paginator = Paginator(orders, ORDER_PAGE_NUM) try: orders = paginator.page(page) except: orders = paginator.page(paginator.num_pages) for k in orders.object_list: k.ex_money = sum( [i.ex_money for i in OutsourceInvoice.query.filter_by(client_order=k)]) k.pay_num = sum([i.pay_num for i in k.get_outsources_by_status(4)]) apply_outsources = [] for i in [1, 2, 3, 5]: apply_outsources += k.get_outsources_by_status(i) k.apply_money = sum([j.pay_num for j in apply_outsources]) return tpl('/finance/client_order/outsource/invoice.html', orders=orders, locations=select_locations, location_id=location_id, statuses=select_statuses, orderby=orderby, now_date=datetime.date.today(), search_info=search_info, page=page, year=year, params='&orderby=%s&searchinfo=%s&selected_location=%s&year=%s' % (orderby, search_info, location_id, year))
def outsource(): if not (g.user.is_leader() or g.user.is_super_leader()): abort(403) orders = list(ClientOrder.all()) orders += list(DoubanOrder.all()) orders = [k for k in orders if k.status == 1] search_info = request.values.get('search_info', '') location = int(request.values.get('location', 0)) if search_info: orders = [k for k in orders if search_info.lower().strip() in k.search_info.lower()] if location: orders = [k for k in orders if location in k.locations] if g.user.team.type == TEAM_TYPE_LEADER: orders = [ o for o in orders if g.user.location in o.locations and o.get_outsources_by_status(1)] elif g.user.team.type == TEAM_TYPE_SUPER_LEADER: orders = [o for o in orders if o.get_outsources_by_status(5)] if g.user.is_super_admin(): orders = [o for o in orders if o.get_outsources_by_status( 5) or o.get_outsources_by_status(1)] return tpl('/manage/apply/order.html', title=u'外包费用报备审批', orders=orders, search_info=search_info, location=location, a_type="outsource")
def order(): sn = request.values.get('sn', '') client_order = [ _order_to_dict(k) for k in ClientOrder.all() if k.contract.lower().strip() == sn.lower().strip() ] douban_order = [ _order_to_dict(k) for k in DoubanOrder.all() if k.contract.lower().strip() == sn.lower().strip() ] client_order += [ _order_to_dict(k.client_order) for k in Order.all() if k.medium_contract.lower().strip() == sn.lower().strip() ] client_order += [ _order_to_dict(k.client_order, k) for k in AssociatedDoubanOrder.all() if k.contract.lower().strip() == sn.lower().strip() ] if client_order: return jsonify({'ret': True, 'data': client_order[0]}) elif douban_order: return jsonify({'ret': True, 'data': douban_order[0]}) else: return jsonify({'ret': False, 'data': {}})
def cost(): client_invoices = list(Invoice.all()) medium_invoices = list(MediumInvoice.all()) medium_invoice_pays = list(MediumInvoicePay.all()) medium_invoice_rebate_invoice = list(MediumRebateInvoice.all()) agent_invoices = list(AgentInvoice.all()) agent_invoice_pays = list(AgentInvoicePay.all()) back_moneys = list(BackMoney.all()) back_money_rebates = list(BackInvoiceRebate.all()) 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') orders = set([ k.client_order for k in ClientOrderExecutiveReport.query.filter_by( month_day=search_date) if k.status == 1 ]) else: orders = [ k for k in ClientOrder.all() if k.client_start.year == int(year) or k.client_end.year == int(year) ] if location != 0: orders = [k for k in orders if location in k.locations] if info: orders = [k for k in orders if info in k.search_info] orders = sorted(list(orders), key=lambda x: x.client_start, reverse=False) for order in orders: order.pass_invoice_sum = sum([ k.money for k in client_invoices if k.invoice_status == 0 and k.client_order == order ]) order.back_money_sum = sum( [k.money for k in back_moneys if k.client_order == order]) order.back_money_rebate_sum = sum( [k.money for k in back_money_rebates if k.client_order == order]) order.agent_invoice_sum = sum( [k.money for k in agent_invoices if k.client_order == order]) agent_invoice_pay_sum = 0.0 invoices = [k for k in agent_invoices if k.client_order == order] for invoice in invoices: agent_invoice_pay_sum += sum([ k.money for k in agent_invoice_pays if k.pay_status == 0 and k.agent_invoice == invoice ]) order.agent_invoice_pay_sum = agent_invoice_pay_sum order.medium_invoice_sum = sum( [k.money for k in medium_invoices if k.client_order == order]) invoices = [k for k in medium_invoices if k.client_order == order] order.medium_invoice_pay_sum = sum([ k.money for k in medium_invoice_pays if k.pay_status == 0 and k.medium_invoice in invoices ]) order.medium_invoice_rebate_invoice_sum = sum([ k.money for k in medium_invoice_rebate_invoice if k.client_order == order and k.invoice_status == 0 ]) for m in order.medium_orders: m.medium_invoice_sum = sum([ k.money for k in medium_invoices if k.client_order == order and k.medium == m.medium ]) m_invoices = [ k for k in medium_invoices if k.client_order == order and k.medium == m.medium ] m.medium_invoice_pay_sum = sum([ k.money for k in medium_invoice_pays if k.pay_status == 0 and k.medium_invoice in m_invoices ]) m.medium_invoice_rebate_invoice_sum = sum([ k.money for k in medium_invoice_rebate_invoice if k.client_order == order and k.invoice_status == 0 and k.medium == m.medium ]) if request.values.get('action', '') == 'download': response = write_order_excel(list(orders)) return response return tpl('cost.html', orders=orders, location=location, year=year, month=month, info=info)
def index(): query_type = int(request.args.get('query_type', 4)) query_month = request.args.get('query_month', '') page = int(request.args.get('page', 1)) if query_month: query_month = datetime.datetime.strptime(query_month, '%Y-%m') else: query_month = datetime.datetime.strptime( datetime.datetime.now().strftime('%Y-%m'), '%Y-%m') # 全部客户订单 if query_type == 1: query_orders = [ o for o in ClientOrder.all() if o.client_end.strftime('%Y-%m') >= query_month.strftime('%Y-%m') and o.contract_status in ECPM_CONTRACT_STATUS_LIST ] orders = [{ 'agent_name': o.agent.name, 'client_name': o.client.name, 'campaign': o.campaign, 'start': o.client_start, 'end': o.client_end, 'money': o.money } for o in query_orders] # 全部媒体订单 elif query_type == 2: query_orders = [ o for o in Order.all() if o.medium_end.strftime('%Y-%m') >= query_month.strftime('%Y-%m') and o.contract_status in ECPM_CONTRACT_STATUS_LIST ] orders = [{ 'medium_name': o.medium.name, 'campaign': o.campaign, 'start': o.medium_start, 'end': o.medium_end, 'money': o.medium_money } for o in query_orders] # 全部关联豆瓣订单 elif query_type == 3: query_orders = [ o for o in AssociatedDoubanOrder.all() if o.end_date.strftime('%Y-%m') >= query_month.strftime('%Y-%m') and o.contract_status in ECPM_CONTRACT_STATUS_LIST ] orders = [{ 'jiafang_name': o.jiafang_name, 'client_name': o.client.name, 'campaign': o.campaign, 'start': o.start_date, 'end': o.end_date, 'money': o.money } for o in query_orders] # 全部直签豆瓣订单 else: query_orders = [ o for o in DoubanOrder.all() if o.client_end.strftime('%Y-%m') >= query_month.strftime('%Y-%m') and o.contract_status in ECPM_CONTRACT_STATUS_LIST ] orders = [{ 'agent_name': o.agent.name, 'client_name': o.client.name, 'campaign': o.campaign, 'start': o.client_start, 'end': o.client_end, 'money': o.money } for o in query_orders] th_count = 0 th_obj = [] for order in orders: if order['money']: pre_money = float(order['money']) / \ ((order['end'] - order['start']).days + 1) else: pre_money = 0 monthes_pre_days = get_monthes_pre_days( query_month, datetime.datetime.fromordinal(order['start'].toordinal()), datetime.datetime.fromordinal(order['end'].toordinal())) order['order_pre_money'] = [{ 'month': k['month'].strftime('%Y-%m'), 'money': '%.2f' % (pre_money * k['days']) } for k in monthes_pre_days] if len(monthes_pre_days) > th_count: th_obj = [{ 'month': k['month'].strftime('%Y-%m') } for k in monthes_pre_days] th_count = len(monthes_pre_days) if 'excel' == request.args.get('extype', ''): if query_type == 1: filename = ( "%s-%s.xls" % (u"月度客户订单金额", datetime.datetime.now().strftime('%Y%m%d%H%M%S')) ).encode('utf-8') elif query_type == 2: filename = ( "%s-%s.xls" % (u"月度媒体订单金额", datetime.datetime.now().strftime('%Y%m%d%H%M%S')) ).encode('utf-8') elif query_type == 3: filename = ("%s-%s.xls" % (u"月度关联豆瓣订单金额", datetime.datetime.now().strftime('%Y%m%d%H%M%S')) ).encode('utf-8') else: filename = ("%s-%s.xls" % (u"月度直签豆瓣订单金额", datetime.datetime.now().strftime('%Y%m%d%H%M%S')) ).encode('utf-8') xls = write_excel(orders, query_type, th_obj) response = get_download_response(xls, filename) return response return tpl('/data_query/order/index.html', orders=orders, page=page, query_type=query_type, query_month=query_month.strftime('%Y-%m'), th_obj=th_obj)
er = MediumOrderExecutiveReport.add(client_order=order.client_order, order=order, medium_money=i[ 'medium_money'], medium_money2=i[ 'medium_money2'], sale_money=i[ 'sale_money'], month_day=i['month'], days=i['days'], create_time=None) er.save() return True if __name__ == '__main__': client_orders = ClientOrder.all() douban_orders = DoubanOrder.all() framework_orders = FrameworkOrder.all() medium_framework_orders = MediumFrameworkOrder.all() search_client_orders = searchAdClientOrder.all() search_rebate_orders = searchAdRebateOrder.all() search_framework_orders = searchAdFrameworkOrder.all() for c in client_orders: c.client_start_year = c.client_start.year c.client_end_year = c.client_end.year c.save() _insert_zhiqu_executive_report(c, 'reload') for d in douban_orders: d.client_start_year = d.client_start.year
def cost(): client_invoices = list(Invoice.all()) medium_invoices = list(MediumInvoice.all()) medium_invoice_pays = list(MediumInvoicePay.all()) medium_invoice_rebate_invoice = list(MediumRebateInvoice.all()) agent_invoices = list(AgentInvoice.all()) agent_invoice_pays = list(AgentInvoicePay.all()) back_moneys = list(BackMoney.all()) back_money_rebates = list(BackInvoiceRebate.all()) 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') orders = set([k.client_order for k in ClientOrderExecutiveReport.query.filter_by( month_day=search_date) if k.status == 1]) else: orders = [k for k in ClientOrder.all() if k.client_start.year == int( year) or k.client_end.year == int(year)] if location != 0: orders = [k for k in orders if location in k.locations] if info: orders = [k for k in orders if info in k.search_info] orders = sorted(list(orders), key=lambda x: x.client_start, reverse=False) for order in orders: order.pass_invoice_sum = sum( [k.money for k in client_invoices if k.invoice_status == 0 and k.client_order == order]) order.back_money_sum = sum( [k.money for k in back_moneys if k.client_order == order]) order.back_money_rebate_sum = sum( [k.money for k in back_money_rebates if k.client_order == order]) order.agent_invoice_sum = sum( [k.money for k in agent_invoices if k.client_order == order]) agent_invoice_pay_sum = 0.0 invoices = [k for k in agent_invoices if k.client_order == order] for invoice in invoices: agent_invoice_pay_sum += sum( [k.money for k in agent_invoice_pays if k.pay_status == 0 and k.agent_invoice == invoice]) order.agent_invoice_pay_sum = agent_invoice_pay_sum order.medium_invoice_sum = sum( [k.money for k in medium_invoices if k.client_order == order]) invoices = [k for k in medium_invoices if k.client_order == order] order.medium_invoice_pay_sum = sum( [k.money for k in medium_invoice_pays if k.pay_status == 0 and k.medium_invoice in invoices]) order.medium_invoice_rebate_invoice_sum = sum( [k.money for k in medium_invoice_rebate_invoice if k.client_order == order and k.invoice_status == 0]) for m in order.medium_orders: m.medium_invoice_sum = sum( [k.money for k in medium_invoices if k.client_order == order and k.medium == m.medium]) m_invoices = [ k for k in medium_invoices if k.client_order == order and k.medium == m.medium] m.medium_invoice_pay_sum = sum( [k.money for k in medium_invoice_pays if k.pay_status == 0 and k.medium_invoice in m_invoices]) m.medium_invoice_rebate_invoice_sum = sum( [k.money for k in medium_invoice_rebate_invoice if k.client_order == order and k.invoice_status == 0 and k.medium == m.medium]) if request.values.get('action', '') == 'download': response = write_order_excel(list(orders)) return response return tpl('cost.html', orders=orders, location=location, year=year, month=month, info=info)
def index(): query_type = int(request.args.get('query_type', 4)) query_month = request.args.get('query_month', '') page = int(request.args.get('page', 1)) if query_month: query_month = datetime.datetime.strptime(query_month, '%Y-%m') else: query_month = datetime.datetime.strptime( datetime.datetime.now().strftime('%Y-%m'), '%Y-%m') # 全部客户订单 if query_type == 1: query_orders = [o for o in ClientOrder.all() if o.client_end.strftime('%Y-%m') >= query_month.strftime('%Y-%m') and o.contract_status in ECPM_CONTRACT_STATUS_LIST] orders = [{'agent_name': o.agent.name, 'client_name': o.client.name, 'campaign': o.campaign, 'start': o.client_start, 'end': o.client_end, 'money': o.money} for o in query_orders] # 全部媒体订单 elif query_type == 2: query_orders = [o for o in Order.all() if o.medium_end.strftime('%Y-%m') >= query_month.strftime('%Y-%m') and o.contract_status in ECPM_CONTRACT_STATUS_LIST] orders = [{'medium_name': o.medium.name, 'campaign': o.campaign, 'start': o.medium_start, 'end': o.medium_end, 'money': o.medium_money} for o in query_orders] # 全部关联豆瓣订单 elif query_type == 3: query_orders = [o for o in AssociatedDoubanOrder.all() if o.end_date.strftime('%Y-%m') >= query_month.strftime('%Y-%m') and o.contract_status in ECPM_CONTRACT_STATUS_LIST] orders = [{'jiafang_name': o.jiafang_name, 'client_name': o.client.name, 'campaign': o.campaign, 'start': o.start_date, 'end': o.end_date, 'money': o.money} for o in query_orders] # 全部直签豆瓣订单 else: query_orders = [o for o in DoubanOrder.all() if o.client_end.strftime('%Y-%m') >= query_month.strftime('%Y-%m') and o.contract_status in ECPM_CONTRACT_STATUS_LIST] orders = [{'agent_name': o.agent.name, 'client_name': o.client.name, 'campaign': o.campaign, 'start': o.client_start, 'end': o.client_end, 'money': o.money} for o in query_orders] th_count = 0 th_obj = [] for order in orders: if order['money']: pre_money = float(order['money']) / \ ((order['end'] - order['start']).days + 1) else: pre_money = 0 monthes_pre_days = get_monthes_pre_days(query_month, datetime.datetime.fromordinal(order['start'].toordinal()), datetime.datetime.fromordinal(order['end'].toordinal())) order['order_pre_money'] = [{'month': k['month'].strftime('%Y-%m'), 'money': '%.2f' % (pre_money * k['days'])} for k in monthes_pre_days] if len(monthes_pre_days) > th_count: th_obj = [ {'month': k['month'].strftime('%Y-%m')}for k in monthes_pre_days] th_count = len(monthes_pre_days) if 'excel' == request.args.get('extype', ''): if query_type == 1: filename = ( "%s-%s.xls" % (u"月度客户订单金额", datetime.datetime.now().strftime('%Y%m%d%H%M%S'))).encode('utf-8') elif query_type == 2: filename = ( "%s-%s.xls" % (u"月度媒体订单金额", datetime.datetime.now().strftime('%Y%m%d%H%M%S'))).encode('utf-8') elif query_type == 3: filename = ("%s-%s.xls" % (u"月度关联豆瓣订单金额", datetime.datetime.now().strftime('%Y%m%d%H%M%S'))).encode('utf-8') else: filename = ("%s-%s.xls" % (u"月度直签豆瓣订单金额", datetime.datetime.now().strftime('%Y%m%d%H%M%S'))).encode('utf-8') xls = write_excel(orders, query_type, th_obj) response = get_download_response(xls, filename) return response return tpl('/data_query/order/index.html', orders=orders, page=page, query_type=query_type, query_month=query_month.strftime('%Y-%m'), th_obj=th_obj)