Ejemplo n.º 1
0
 def __init__(self, *args, **kwargs):
     super(ClientMediumOrderForm, self).__init__(*args, **kwargs)
     self.agent.choices = [(m.id, m.name) for m in Agent.all()]
     self.client.choices = [(c.id, c.name) for c in Client.all()]
     self.direct_sales.choices = [(m.id, m.name) for m in User.sales()]
     self.agent_sales.choices = [(m.id, m.name) for m in User.sales()]
     self.assistant_sales.choices = [(m.id, m.name) for m in User.sales()]
     operaters = User.gets_by_team_type(
         TEAM_TYPE_OPERATER) + User.gets_by_team_type(
             TEAM_TYPE_OPERATER_LEADER)
     self.operaters.choices = [(m.id, m.name) for m in operaters]
     self.operaters.hidden = True
     self.designers.choices = [
         (m.id, m.name) for m in User.gets_by_team_type(TEAM_TYPE_DESIGNER)
     ]
     self.designers.hidden = True
     self.planers.choices = [
         (m.id, m.name) for m in User.gets_by_team_type(TEAM_TYPE_PLANNER)
     ]
     self.planers.hidden = True
     self.sale_CPM.hidden = True
     self.medium_CPM.hidden = True
     self.contract_type.choices = CONTRACT_TYPE_CN.items()
     self.resource_type.choices = RESOURCE_TYPE_CN.items()
     self.sale_type.choices = SALE_TYPE_CN.items()
     self.medium_group.choices = [(m.id, m.name) for m in MediumGroup.all()]
     self.medium.choices = [(m.id, m.name) for m in Medium.all()]
Ejemplo n.º 2
0
def douban_order_json():
    if not (g.user.is_super_leader() or g.user.is_aduit()
            or g.user.is_finance()):
        abort(403)
    now_date = datetime.datetime.now()
    location = int(request.values.get('location', 0))
    start_year = str(request.values.get('start_year', now_date.year))
    start_month = str(request.values.get('start_month', now_date.month))
    end_year = str(request.values.get('end_year', now_date.year - 1))
    end_month = str(request.values.get('end_month', now_date.month))

    start_date_month = datetime.datetime.strptime(
        start_year + '-' + start_month, '%Y-%m')
    end_date_month = datetime.datetime.strptime(end_year + '-' + end_month,
                                                '%Y-%m')
    douban_orders = DoubanOrderExecutiveReport.query.filter(
        DoubanOrderExecutiveReport.month_day >= start_date_month,
        DoubanOrderExecutiveReport.month_day <= end_date_month)
    medium_orders = MediumOrderExecutiveReport.query.filter(
        MediumOrderExecutiveReport.month_day >= start_date_month,
        MediumOrderExecutiveReport.month_day <= end_date_month)

    medium_orders = [_format_order(k) for k in medium_orders if k.status == 1]
    medium_date = [{
        'agent_name': k['agent'].name,
        'medium_id': k['medium_id'],
        'money': _get_money_by_location(k, location)
    } for k in medium_orders if k['medium_id'] in [3, 8]]
    douban_orders = [
        _format_order(k, 'douban') for k in douban_orders if k.status == 1
    ]
    douban_date = [{
        'agent_name': k['agent'].name,
        'money': _get_money_by_location(k, location)
    } for k in douban_orders]

    agent_params = {}
    for k in Agent.all():
        agent_params[k.name] = 0

    for k in douban_date + medium_date:
        if k['agent_name'] in agent_params:
            agent_params[k['agent_name']] += k['money']
    agent_params = sorted(agent_params.iteritems(), key=lambda x: x[1])
    agent_params.reverse()
    data = [{"name": u"占比", "data": []}]
    sum_saler_money = sum([v for k, v in agent_params])
    for k, v in agent_params:
        if v > 0:
            if sum_saler_money == 0:
                percent = u'0.00%'
            else:
                percent = v / sum_saler_money * 100
            data[0]['data'].append({'name': k, 'y': v, 'percent': percent})
    return jsonify({
        'data': data,
        'title': u'直签豆瓣订单(含:优力、无线)代理分析',
        'total': float(sum_saler_money)
    })
Ejemplo n.º 3
0
 def __init__(self, *args, **kwargs):
     super(FrameworkOrderForm, self).__init__(*args, **kwargs)
     self.agents.choices = [(a.id, a.name) for a in Agent.all()]
     self.group.choices = [(g.id, g.name) for g in Group.all()]
     self.direct_sales.choices = [(m.id, m.name) for m in User.sales()]
     self.agent_sales.choices = [(m.id, m.name) for m in User.sales()]
     self.assistant_sales.choices = [(m.id, m.name) for m in User.sales()]
     self.contract_type.choices = CONTRACT_TYPE_CN.items()
Ejemplo n.º 4
0
def agents():
    agents = Agent.all()
    agent_rebate = AgentRebate.all()
    agent_mediun_rebate = AgentMediumRebate.all()
    agent_rebate_data = {}
    for k in agent_rebate:
        if str(k.agent.id) + '_' + str(k.year.year) not in agent_rebate_data:
            agent_rebate_data[str(k.agent.id) + '_' + str(k.year.year)] = str(k.inad_rebate) + '%'
    agent_medium_rebate_data = {}
    for k in agent_mediun_rebate:
        if str(k.agent.id) + '_' + k.medium_name or '' + '_' + str(k.year.year) not in agent_rebate_data:
            agent_medium_rebate_data[str(k.agent.id) + '_' + k.medium_name + '_' +
                                     str(k.year.year)] = str(k.rebate) + '%'
    info = request.values.get('info', '')
    if info:
        agents = [k for k in agents if info in k.name]
    agent_data = []
    for agent in agents:
        dict_agent = {}
        dict_agent['id'] = agent.id
        dict_agent['name'] = agent.name
        dict_agent['group_name'] = agent.group.name
        dict_agent['group_id'] = agent.group.id
        if str(agent.id) + '_2014' in agent_rebate_data:
            dict_agent['rebate_2014'] = agent_rebate_data[str(agent.id) + '_2014']
        else:
            dict_agent['rebate_2014'] = u'无'
        if str(agent.id) + '_2015' in agent_rebate_data:
            dict_agent['rebate_2015'] = agent_rebate_data[str(agent.id) + '_2015']
        else:
            dict_agent['rebate_2015'] = u'无'
        if str(agent.id) + '_2016' in agent_rebate_data:
            dict_agent['rebate_2016'] = agent_rebate_data[str(agent.id) + '_2016']
        else:
            dict_agent['rebate_2016'] = u'无'
        dict_agent['mediums_rebate'] = []
        agent_mediums = set([k.medium_name for k in agent_mediun_rebate if k.agent == agent])
        for m in agent_mediums:
            m_dict = {}
            m_dict['name'] = m
            if str(agent.id) + '_' + m + '_2014' in agent_medium_rebate_data:
                m_dict['rebate_2014'] = agent_medium_rebate_data[str(agent.id) + '_' + m + '_2014']
            else:
                m_dict['rebate_2014'] = u'无'
            if str(agent.id) + '_' + m + '_2015' in agent_medium_rebate_data:
                m_dict['rebate_2015'] = agent_medium_rebate_data[str(agent.id) + '_' + m + '_2015']
            else:
                m_dict['rebate_2015'] = u'无'
            if str(agent.id) + '_' + m + '_2016' in agent_medium_rebate_data:
                m_dict['rebate_2016'] = agent_medium_rebate_data[str(agent.id) + '_' + m + '_2016']
            else:
                m_dict['rebate_2016'] = u'无'
            dict_agent['mediums_rebate'].append(m_dict)
        agent_data.append(dict_agent)
    if request.values.get('action') == 'excel':
        return write_client_excel(agents=agent_data)
    return tpl('/client/agent/index.html', agents=agent_data, info=info)
Ejemplo n.º 5
0
 def __init__(self, *args, **kwargs):
     super(ClientOrderForm, self).__init__(*args, **kwargs)
     self.agent.choices = [(m.id, m.name) for m in Agent.all()]
     self.client.choices = [(c.id, c.name) for c in Client.all()]
     self.direct_sales.choices = [(m.id, m.name) for m in User.sales()]
     self.agent_sales.choices = [(m.id, m.name) for m in User.sales()]
     self.assistant_sales.choices = [(m.id, m.name) for m in User.sales()]
     self.contract_type.choices = CONTRACT_TYPE_CN.items()
     self.resource_type.choices = RESOURCE_TYPE_CN.items()
     self.sale_type.choices = SALE_TYPE_CN.items()
Ejemplo n.º 6
0
def client_order_excle_data():
    now_date = datetime.datetime.now()
    location = int(request.values.get('location', 0))
    start_year = str(request.values.get('start_year', now_date.year))
    start_month = str(request.values.get('start_month', now_date.month))
    end_year = str(request.values.get('end_year', now_date.year - 1))
    end_month = str(request.values.get('end_month', now_date.month))

    start_date_month = datetime.datetime.strptime(
        start_year + '-' + start_month, '%Y-%m')
    end_date_month = datetime.datetime.strptime(end_year + '-' + end_month,
                                                '%Y-%m')
    medium_orders = MediumOrderExecutiveReport.query.filter(
        MediumOrderExecutiveReport.month_day >= start_date_month,
        MediumOrderExecutiveReport.month_day <= end_date_month)
    medium_orders = [_format_order(k) for k in medium_orders if k.status == 1]
    medium_date = [{
        'agent_name': k['agent'].name,
        'money': _get_money_by_location(k, location)
    } for k in medium_orders]

    agent_params = {}
    for k in Agent.all():
        agent_params[k.name] = 0

    for k in medium_date:
        if k['agent_name'] in agent_params:
            agent_params[k['agent_name']] += k['money']
    agent_params = sorted(agent_params.iteritems(), key=lambda x: x[1])
    agent_params = [(k, v) for k, v in agent_params if v > 0]
    agent_params.reverse()

    headings = ['#', u'代理名称', u'执行额', u'占比']
    data = []
    data.append([k + 1 for k in range(len(agent_params))])
    data.append([k for k, v in agent_params])
    data.append([v for k, v in agent_params])
    sum_saler_money = sum([v for k, v in agent_params])
    if sum_saler_money:
        data.append(
            ['%.2f%%' % (v / sum_saler_money * 100) for k, v in agent_params])
    else:
        data.append(['0.00%' for k, v in agent_params])
    return {
        'data': data,
        'title': u'新媒体订单代理分析',
        'total': float(sum_saler_money),
        'headings': headings
    }
Ejemplo n.º 7
0
def agents():
    clients = []
    for k in Agent.all():
        agent_licence_file = k.get_last_client_file(100)
        if agent_licence_file:
            licence_file = agent_licence_file.agent_path
        else:
            licence_file = ''
        agent_f_certifcate_file = k.get_last_client_file(101)
        if agent_f_certifcate_file:
            f_certifcate_file = agent_f_certifcate_file.agent_path
        else:
            f_certifcate_file = ''
        agent_o_certifcate_file = k.get_last_client_file(102)
        if agent_o_certifcate_file:
            o_certifcate_file = agent_o_certifcate_file.agent_path
        else:
            o_certifcate_file = ''
        agent_tax_certifcate_file = k.get_last_client_file(103)
        if agent_tax_certifcate_file:
            tax_certifcate_file = agent_tax_certifcate_file.agent_path
        else:
            tax_certifcate_file = ''
        agent_t_info_file = k.get_last_client_file(104)
        if agent_t_info_file:
            t_info_file = agent_t_info_file.agent_path
        else:
            t_info_file = ''
        agent_a_licence_file = k.get_last_client_file(105)
        if agent_a_licence_file:
            a_licence_file = agent_a_licence_file.agent_path
        else:
            a_licence_file = ''
        dict_agent = {}
        dict_agent['id'] = k.id
        dict_agent['name'] = k.name
        dict_agent['licence_file'] = licence_file
        dict_agent['f_certifcate_file'] = f_certifcate_file
        dict_agent['o_certifcate_file'] = o_certifcate_file
        dict_agent['tax_certifcate_file'] = tax_certifcate_file
        dict_agent['t_info_file'] = t_info_file
        dict_agent['a_licence_file'] = a_licence_file
        dict_agent['files'] = [f.agent_path for f in k.get_agent_attachments()]
        clients.append(dict_agent)
    return jsonify({'data': clients})
Ejemplo n.º 8
0
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)
Ejemplo n.º 9
0
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)