Пример #1
0
def back_money():
    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 BackMoney.query.filter(BackMoney.back_time >= search_date,
                                                    BackMoney.back_time < end_search_date)
                  if k.client_order.status == 1]
    else:
        orders = [k for k in BackMoney.all() if k.back_time.year == int(
            year) and k.client_order.status == 1]
    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_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/client_order/data_query/index.html',
               orders=orders, location=location,
               year=year, month=month, info=info,
               title=u"客户回款金额", t_type='back_money')
Пример #2
0
def delete(order_id, bid):
    order = ClientOrder.get(order_id)
    bm = BackMoney.get(bid)
    order.add_comment(g.user, u"删除了回款信息,回款金额: %s; 回款时间: %s;" %
                      (bm.money, bm.back_time_cn), msg_channel=4)
    bm.delete()
    flash(u'删除成功!', 'success')
    return redirect(url_for("finance_client_order_back_money.back_money", order_id=order.id))
Пример #3
0
def delete(order_id, bid):
    order = ClientOrder.get(order_id)
    bm = BackMoney.get(bid)
    order.add_comment(g.user,
                      u"删除了回款信息,回款金额: %s; 回款时间: %s;" %
                      (bm.money, bm.back_time_cn),
                      msg_channel=4)
    bm.delete()
    flash(u'删除成功!', 'success')
    return redirect(
        url_for("finance_client_order_back_money.back_money",
                order_id=order.id))
Пример #4
0
def client_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))
    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 = ClientOrder.query.filter(ClientOrder.status == 1,
                                      ClientOrder.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(ClientBackMoney.all()) + \
        list(ClientBackInvoiceRebate.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'新媒体订单回款分析(包含返点发票)'})
Пример #5
0
def client_order_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 = ClientOrder.query.filter(ClientOrder.status == 1,
                                      ClientOrder.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(ClientBackMoney.all()) + \
        list(ClientBackInvoiceRebate.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}
Пример #6
0
def _all_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 ClientBackMoney.all()]
    dict_back_money_data += [{
        'money': k.money,
        'order_id': k.client_order_id,
        'back_time': k.back_time,
        'type': 'invoice'
    } for k in ClientBackInvoiceRebate.all()]
    return dict_back_money_data
Пример #7
0
def client_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))
    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 = ClientOrder.query.filter(ClientOrder.status == 1,
                                      ClientOrder.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(ClientBackMoney.all()) + \
        list(ClientBackInvoiceRebate.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'新媒体订单回款分析(包含返点发票)'})
Пример #8
0
def client_order_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 = ClientOrder.query.filter(ClientOrder.status == 1,
                                      ClientOrder.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(ClientBackMoney.all()) + \
        list(ClientBackInvoiceRebate.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}
Пример #9
0
def back_money():
    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 BackMoney.query.filter(
                BackMoney.back_time >= search_date,
                BackMoney.back_time < end_search_date)
            if k.client_order.status == 1
        ]
    else:
        orders = [
            k for k in BackMoney.all()
            if k.back_time.year == int(year) and k.client_order.status == 1
        ]
    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_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/client_order/data_query/index.html',
               orders=orders,
               location=location,
               year=year,
               month=month,
               info=info,
               title=u"客户回款金额",
               t_type='back_money')
Пример #10
0
def _all_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 BackMoney.all()]
    dict_back_money_data += [{'money': k.money, 'order_id': k.client_order_id,
                              'back_time': k.back_time, 'type': 'invoice'} for k in BackInvoiceRebate.all()]
    return dict_back_money_data
Пример #11
0
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)
Пример #12
0
def back_money(order_id):
    if not g.user.is_finance():
        abort(404)
    order = ClientOrder.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)
                apply_context = {
                    'order': order,
                    'num': 0,
                    'type': 'end',
                }
                back_money_apply_signal.send(current_app._get_current_object(),
                                             apply_context=apply_context)
                flash(u'更新了回款状态,回款已完成!', 'success')
                order.add_comment(g.user, u"更新了回款状态,回款已完成;", msg_channel=4)
            elif int(back_money_status) == -1:
                order.back_money_status = int(back_money_status)
                order.save()
                flash(u'该项目为划账!', 'success')
                order.add_comment(g.user, u"坏账项目", msg_channel=4)
                apply_context = {
                    'order': order,
                    'num': -1,
                    'type': 'end',
                }
                back_money_apply_signal.send(current_app._get_current_object(),
                                             apply_context=apply_context)
            else:
                order.back_money_status = int(back_money_status)
                order.save()
                apply_context = {
                    'order': order,
                    'num': 0,
                    'type': 'no_end',
                }
                back_money_apply_signal.send(current_app._get_current_object(),
                                             apply_context=apply_context)
                flash(u'更新了回款状态,回款未完成!', 'success')
                order.add_comment(g.user, u"更新了回款状态,回款未完成;", msg_channel=4)
        else:
            bm = BackMoney.add(
                client_order=order,
                money=money,
                back_time=back_time,
                create_time=datetime.date.today().strftime('%Y-%m-%d'))
            bm.save()
            apply_context = {
                'order': order,
                'num': money,
                'type': 'money',
            }
            back_money_apply_signal.send(current_app._get_current_object(),
                                         apply_context=apply_context)
            flash(u'回款信息保存成功!', 'success')
            order.add_comment(g.user,
                              u"更新了回款信息,回款金额: %s; 回款时间: %s;" %
                              (money, back_time),
                              msg_channel=4)
        return redirect(
            url_for("finance_client_order_back_money.back_money",
                    order_id=order.id))
    return tpl('/finance/client_order/back_money/info.html', order=order)
Пример #13
0
def back_money(order_id):
    if not g.user.is_finance():
        abort(404)
    order = ClientOrder.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)
                apply_context = {
                    'order': order,
                    'num': 0,
                    'type': 'end',
                }
                back_money_apply_signal.send(
                    current_app._get_current_object(), apply_context=apply_context)
                flash(u'更新了回款状态,回款已完成!', 'success')
                order.add_comment(
                    g.user, u"更新了回款状态,回款已完成;", msg_channel=4)
            elif int(back_money_status) == -1:
                order.back_money_status = int(back_money_status)
                order.save()
                flash(u'该项目为划账!', 'success')
                order.add_comment(g.user, u"坏账项目", msg_channel=4)
                apply_context = {
                    'order': order,
                    'num': -1,
                    'type': 'end',
                }
                back_money_apply_signal.send(
                    current_app._get_current_object(), apply_context=apply_context)
            else:
                order.back_money_status = int(back_money_status)
                order.save()
                apply_context = {
                    'order': order,
                    'num': 0,
                    'type': 'no_end',
                }
                back_money_apply_signal.send(
                    current_app._get_current_object(), apply_context=apply_context)
                flash(u'更新了回款状态,回款未完成!', 'success')
                order.add_comment(
                    g.user, u"更新了回款状态,回款未完成;", msg_channel=4)
        else:
            bm = BackMoney.add(
                client_order=order,
                money=money,
                back_time=back_time,
                create_time=datetime.date.today().strftime('%Y-%m-%d'))
            bm.save()
            apply_context = {
                'order': order,
                'num': money,
                'type': 'money',
            }
            back_money_apply_signal.send(
                current_app._get_current_object(), apply_context=apply_context)
            flash(u'回款信息保存成功!', 'success')
            order.add_comment(
                g.user, u"更新了回款信息,回款金额: %s; 回款时间: %s;" % (money, back_time), msg_channel=4)
        return redirect(url_for("finance_client_order_back_money.back_money", order_id=order.id))
    return tpl('/finance/client_order/back_money/info.html', order=order)
Пример #14
0
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)