Esempio n. 1
0
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')
Esempio n. 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')
    orders = searchAdClientOrder.query.filter(
        searchAdClientOrder.status == 1,
        searchAdClientOrder.client_end <= now_year_end)

    client_params = {}
    now_monthes = get_monthes_pre_days(now_year_start, now_year_end)
    for k in now_monthes:
        client_params[k['month'].date()] = {
            'back_moneys': 0,
            'un_back_moneys': 0
        }
    # 回款
    back_moneys = list(searchAdBackMoney.all()) + \
        list(searchAdBackInvoiceRebate.all())
    back_moneys = _format_back_money(back_moneys, 'client', location)
    for k in back_moneys:
        if k['back_time'] in client_params:
            client_params[k['back_time']]['back_moneys'] += k['money']

    # 计算未回款金额累计
    orders = [
        _format_client_order(k, location) for k in orders
        if k.contract_status in [2, 4, 5, 10, 19, 20]
    ]
    for k in client_params:
        need_back_money = _need_back_money(orders, k)
        client_params[k]['un_back_moneys'] = need_back_money - _back_money(
            k, back_moneys)

    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:
        day_time_stamp = int(
            datetime.datetime.strptime(str(k),
                                       '%Y-%m-%d').strftime('%s')) * 1000
        data[0]['data'].append([day_time_stamp, v['back_moneys']])
        data[1]['data'].append([day_time_stamp, v['un_back_moneys']])
    return jsonify({'data': data, 'title': u'搜索业务回款分析(包含返点发票)'})
Esempio n. 3
0
def search_excle_data():
    now_date = datetime.datetime.now()
    location = int(request.values.get('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')
    orders = searchAdClientOrder.query.filter(
        searchAdClientOrder.status == 1,
        searchAdClientOrder.client_end <= now_year_end)

    client_params = {}
    now_monthes = get_monthes_pre_days(now_year_start, now_year_end)
    for k in now_monthes:
        client_params[k['month'].date()] = {
            'back_moneys': 0,
            'un_back_moneys': 0
        }
    # 回款
    back_moneys = list(searchAdBackMoney.all()) + \
        list(searchAdBackInvoiceRebate.all())
    back_moneys = _format_back_money(back_moneys, 'client', location)
    for k in back_moneys:
        if k['back_time'] in client_params:
            client_params[k['back_time']]['back_moneys'] += k['money']

    # 计算未回款金额累计
    orders = [
        _format_client_order(k, location) for k in orders
        if k.contract_status in [2, 4, 5, 10, 19, 20]
    ]
    for k in client_params:
        need_back_money = _need_back_money(orders, k)
        client_params[k]['un_back_moneys'] = need_back_money - _back_money(
            k, back_moneys)

    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))])

    # 成单客户数
    back_moneys = []
    # 平均客户金额
    un_back_moneys = []
    for k, v in client_params:
        back_moneys.append(v['back_moneys'])
        un_back_moneys.append(v['un_back_moneys'])
    data.append(back_moneys)
    data.append(un_back_moneys)
    return {'data': data, 'title': u'搜索业务回款分析(包含返点发票)', 'headings': headings}
Esempio n. 4
0
def _all_search_client_order_back_moneys():
    dict_back_money_data = [{
        'money': k.money,
        'order_id': k.client_order_id,
        'back_time': k.back_time,
        'type': 'money'
    } for k in searchAdBackMoney.all()]
    dict_back_money_data += [{
        'money': k.money,
        'order_id': k.client_order_id,
        'back_time': k.back_time,
        'type': 'invoice'
    } for k in searchAdBackInvoiceRebate.all()]
    return dict_back_money_data
Esempio n. 5
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')
    orders = searchAdClientOrder.query.filter(searchAdClientOrder.status == 1,
                                              searchAdClientOrder.client_end <= now_year_end)

    client_params = {}
    now_monthes = get_monthes_pre_days(now_year_start, now_year_end)
    for k in now_monthes:
        client_params[k['month'].date()] = {'back_moneys': 0,
                                            'un_back_moneys': 0}
    # 回款
    back_moneys = list(searchAdBackMoney.all()) + \
        list(searchAdBackInvoiceRebate.all())
    back_moneys = _format_back_money(back_moneys, 'client', location)
    for k in back_moneys:
        if k['back_time'] in client_params:
            client_params[k['back_time']]['back_moneys'] += k['money']

    # 计算未回款金额累计
    orders = [_format_client_order(k, location) for k in orders if k.contract_status in [
        2, 4, 5, 10, 19, 20]]
    for k in client_params:
        need_back_money = _need_back_money(orders, k)
        client_params[k][
            'un_back_moneys'] = need_back_money - _back_money(k, back_moneys)

    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:
        day_time_stamp = int(datetime.datetime.strptime(
            str(k), '%Y-%m-%d').strftime('%s')) * 1000
        data[0]['data'].append([day_time_stamp, v['back_moneys']])
        data[1]['data'].append([day_time_stamp, v['un_back_moneys']])
    return jsonify({'data': data, 'title': u'搜索业务回款分析(包含返点发票)'})
Esempio n. 6
0
def search_excle_data():
    now_date = datetime.datetime.now()
    location = int(request.values.get('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')
    orders = searchAdClientOrder.query.filter(searchAdClientOrder.status == 1,
                                              searchAdClientOrder.client_end <= now_year_end)

    client_params = {}
    now_monthes = get_monthes_pre_days(now_year_start, now_year_end)
    for k in now_monthes:
        client_params[k['month'].date()] = {'back_moneys': 0,
                                            'un_back_moneys': 0}
    # 回款
    back_moneys = list(searchAdBackMoney.all()) + \
        list(searchAdBackInvoiceRebate.all())
    back_moneys = _format_back_money(back_moneys, 'client', location)
    for k in back_moneys:
        if k['back_time'] in client_params:
            client_params[k['back_time']]['back_moneys'] += k['money']

    # 计算未回款金额累计
    orders = [_format_client_order(k, location) for k in orders if k.contract_status in [
        2, 4, 5, 10, 19, 20]]
    for k in client_params:
        need_back_money = _need_back_money(orders, k)
        client_params[k][
            'un_back_moneys'] = need_back_money - _back_money(k, back_moneys)

    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))])

    # 成单客户数
    back_moneys = []
    # 平均客户金额
    un_back_moneys = []
    for k, v in client_params:
        back_moneys.append(v['back_moneys'])
        un_back_moneys.append(v['un_back_moneys'])
    data.append(back_moneys)
    data.append(un_back_moneys)
    return {'data': data, 'title': u'搜索业务回款分析(包含返点发票)', 'headings': headings}
Esempio n. 7
0
def back_money():
    if not (g.user.is_searchad_leader() or g.user.is_finance()):
        abort(404)
    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('/saler/searchAd_order/data_query/index.html',
               orders=orders,
               year=year,
               month=month,
               info=info,
               title=u"客户回款金额",
               t_type='back_money')
Esempio n. 8
0
def _all_search_client_order_back_moneys():
    dict_back_money_data = [{'money': k.money, 'order_id': k.client_order_id,
                             'back_time': k.back_time, 'type': 'money'} for k in searchAdBackMoney.all()]
    dict_back_money_data += [{'money': k.money, 'order_id': k.client_order_id,
                              'back_time': k.back_time, 'type': 'invoice'} for k in searchAdBackInvoiceRebate.all()]
    return dict_back_money_data