示例#1
0
def index():
    if not g.user.is_finance():
        abort(404)
    orders = list(searchAdClientOrder.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', '')
    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_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/searchAd_order/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)))
示例#2
0
def search_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 = 0
    year = int(request.values.get('year', now_date.year))
    now_year_start = datetime.datetime.strptime(
        str(year) + '-01-01', '%Y-%m-%d')
    now_year_end = datetime.datetime.strptime(str(year) + '-12-01', '%Y-%m-%d')
    client_params = {}
    now_monthes = get_monthes_pre_days(now_year_start, now_year_end)
    for k in now_monthes:
        client_params[k['month'].date()] = {
            'orders': [],
            'order_count': 0,
            'order_pre_money': 0
        }
    # 获取所有合同
    orders = searchAdClientOrder.all()
    for k in orders:
        if k.contract_status in [2, 4, 5, 10, 19, 20]:
            create_month = k.client_start.replace(day=1)
            if create_month in client_params:
                if location == 0:
                    client_params[create_month]['orders'].append(k)
                elif location in k.locations:
                    client_params[create_month]['orders'].append(k)
    client_params = sorted(client_params.iteritems(), key=lambda x: x[0])
    # 初始化highcharts数据
    data = []
    data.append({'name': u'客户成交数量', 'data': []})
    data.append({'name': u'客户平均成交额', 'data': []})
    # 根据时间组装合同
    for k, v in client_params:
        order_count = len(v['orders'])
        sum_order_money = sum(
            [_get_money_by_location(i, location) for i in v['orders']])
        if order_count:
            order_pre_money = sum_order_money / order_count
        else:
            order_pre_money = 0
        # 主装highcharts数据
        day_time_stamp = int(
            datetime.datetime.strptime(str(k),
                                       '%Y-%m-%d').strftime('%s')) * 1000
        data[0]['data'].append([day_time_stamp, order_count])
        data[1]['data'].append([day_time_stamp, order_pre_money])
    return jsonify({'data': data, 'title': u'搜索业务客户数量分析'})
示例#3
0
def search_excle_data():
    now_date = datetime.datetime.now()
    location = 0
    year = int(request.values.get('year', now_date.year))
    now_year_start = datetime.datetime.strptime(
        str(year) + '-01-01', '%Y-%m-%d')
    now_year_end = datetime.datetime.strptime(str(year) + '-12-01', '%Y-%m-%d')
    client_params = {}
    now_monthes = get_monthes_pre_days(now_year_start, now_year_end)
    for k in now_monthes:
        client_params[k['month'].date()] = {
            'orders': [],
            'order_count': 0,
            'order_pre_money': 0
        }
    # 获取所有合同
    orders = searchAdClientOrder.all()
    for k in orders:
        if k.contract_status in [2, 4, 5, 10, 19, 20]:
            create_month = k.client_start.replace(day=1)
            if create_month in client_params:
                if location == 0:
                    client_params[create_month]['orders'].append(k)
                elif location in k.locations:
                    client_params[create_month]['orders'].append(k)
    client_params = sorted(client_params.iteritems(), key=lambda x: x[0])

    headings = [u'月份', u'成单客户数', u'平均客户金额']
    data = []
    data.append([str(k + 1) + u'月' for k in range(len(client_params))])

    # 成单客户数
    count_client = []
    # 平均客户金额
    pre_money_client = []
    for k, v in client_params:
        order_count = len(v['orders'])
        sum_order_money = sum(
            [_get_money_by_location(i, location) for i in v['orders']])
        if order_count:
            order_pre_money = sum_order_money / order_count
        else:
            order_pre_money = 0
        count_client.append(order_count)
        pre_money_client.append(order_pre_money)
    data.append(count_client)
    data.append(pre_money_client)
    return {'data': data, 'title': u'搜索业务客户数量分析', 'headings': headings}
示例#4
0
def search_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 = 0
    year = int(request.values.get('year', now_date.year))
    now_year_start = datetime.datetime.strptime(
        str(year) + '-01-01', '%Y-%m-%d')
    now_year_end = datetime.datetime.strptime(str(year) + '-12-01', '%Y-%m-%d')
    client_params = {}
    now_monthes = get_monthes_pre_days(now_year_start, now_year_end)
    for k in now_monthes:
        client_params[k['month'].date()] = {'orders': [],
                                            'order_count': 0,
                                            'order_pre_money': 0}
    # 获取所有合同
    orders = searchAdClientOrder.all()
    for k in orders:
        if k.contract_status in [2, 4, 5, 10, 19, 20]:
            create_month = k.client_start.replace(day=1)
            if create_month in client_params:
                if location == 0:
                    client_params[create_month]['orders'].append(k)
                elif location in k.locations:
                    client_params[create_month]['orders'].append(k)
    client_params = sorted(
        client_params.iteritems(), key=lambda x: x[0])
    # 初始化highcharts数据
    data = []
    data.append({'name': u'客户成交数量',
                 'data': []})
    data.append({'name': u'客户平均成交额',
                 'data': []})
    # 根据时间组装合同
    for k, v in client_params:
        order_count = len(v['orders'])
        sum_order_money = sum([_get_money_by_location(i, location) for i in v['orders']])
        if order_count:
            order_pre_money = sum_order_money / order_count
        else:
            order_pre_money = 0
        # 主装highcharts数据
        day_time_stamp = int(datetime.datetime.strptime(
            str(k), '%Y-%m-%d').strftime('%s')) * 1000
        data[0]['data'].append([day_time_stamp, order_count])
        data[1]['data'].append([day_time_stamp, order_pre_money])
    return jsonify({'data': data, 'title': u'搜索业务客户数量分析'})
示例#5
0
def search_excle_data():
    now_date = datetime.datetime.now()
    location = 0
    year = int(request.values.get('year', now_date.year))
    now_year_start = datetime.datetime.strptime(
        str(year) + '-01-01', '%Y-%m-%d')
    now_year_end = datetime.datetime.strptime(str(year) + '-12-01', '%Y-%m-%d')
    client_params = {}
    now_monthes = get_monthes_pre_days(now_year_start, now_year_end)
    for k in now_monthes:
        client_params[k['month'].date()] = {'orders': [],
                                            'order_count': 0,
                                            'order_pre_money': 0}
    # 获取所有合同
    orders = searchAdClientOrder.all()
    for k in orders:
        if k.contract_status in [2, 4, 5, 10, 19, 20]:
            create_month = k.client_start.replace(day=1)
            if create_month in client_params:
                if location == 0:
                    client_params[create_month]['orders'].append(k)
                elif location in k.locations:
                    client_params[create_month]['orders'].append(k)
    client_params = sorted(
        client_params.iteritems(), key=lambda x: x[0])

    headings = [u'月份', u'成单客户数', u'平均客户金额']
    data = []
    data.append([str(k + 1) + u'月' for k in range(len(client_params))])

    # 成单客户数
    count_client = []
    # 平均客户金额
    pre_money_client = []
    for k, v in client_params:
        order_count = len(v['orders'])
        sum_order_money = sum([_get_money_by_location(i, location) for i in v['orders']])
        if order_count:
            order_pre_money = sum_order_money / order_count
        else:
            order_pre_money = 0
        count_client.append(order_count)
        pre_money_client.append(order_pre_money)
    data.append(count_client)
    data.append(pre_money_client)
    return {'data': data, 'title': u'搜索业务客户数量分析', 'headings': headings}
示例#6
0
def index():
    if not g.user.is_finance():
        abort(404)
    orders = list(searchAdClientOrder.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', '')
    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_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/searchAd_order/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)))
示例#7
0
def index_pass():
    if not g.user.is_finance():
        abort(404)
    orders = list(searchAdClientOrder.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_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 searchAdMediumRebateInvoice.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/searchAd_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)))
示例#8
0
                                                    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
        d.client_end_year = d.client_end.year
        d.save()
        _insert_zhiqu_executive_report(d, 'reload')