Exemple #1
0
def update_invoice_pay(invoice_id, invoice_pay_id):
    money = float(request.values.get('money', 0))
    pay_time = request.values.get('pay_time', '')
    detail = request.values.get('detail', '')
    bank = request.values.get('bank', '')
    bank_num = request.values.get('bank_num', '')
    company = request.values.get('company', '')
    pay = AgentInvoicePay.get(invoice_pay_id)
    # mi = AgentInvoice.get(invoice_id)
    # if mi.pay_invoice_money - pay.money + money > mi.money:
    #     flash(u'付款金额大于发票金额,请重新填写!', 'danger')
    #     return redirect(url_for('saler_client_order_agent_invoice.invoice', invoice_id=invoice_id))
    pay.money = money
    pay.pay_time = pay_time
    pay.detail = detail
    pay.bank = bank
    pay.bank_num = bank_num
    pay.company = company
    pay.save()
    pay.agent_invoice.client_order.add_comment(
        g.user,
        u"更新打款信息\n\n发票号:%s\n\n打款金额:%s元\n\n\
                                                打款时间:%s\n\n公司名称:%s\n\n开户行:%s\n\n银行账号:%s"
        % (pay.agent_invoice.invoice_num, str(money), pay_time, company, bank,
           bank_num),
        msg_channel=5)
    return redirect(
        url_for('saler_client_order_agent_invoice.invoice',
                invoice_id=invoice_id))
Exemple #2
0
def apply():
    if not g.user.is_finance():
        abort(404)
    search_info = request.args.get('searchinfo', '').strip()
    location_id = int(request.args.get('selected_location', '-1'))
    orders = list(AgentInvoicePay.query.filter_by(pay_status=4))
    if location_id >= 0:
        orders = [o for o in orders if location_id in o.agent_invoice.client_order.locations]
    if search_info != '':
        orders = [
            o for o in orders if search_info.lower() in o.agent_invoice.client_order.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'全部合同状态'))
    for i in orders:
        client_order = i.agent_invoice.client_order
        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_pass.html', orders=orders, title=u'申请中的客户付款',
               locations=select_locations,
               location_id=location_id, statuses=select_statuses,
               now_date=datetime.date.today(), search_info=search_info,
               params='?&searchinfo=%s&selected_location=%s' %
                      (search_info, location_id))
Exemple #3
0
def pay_rebate_agent_invoice():
    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 AgentInvoicePay.query.filter(AgentInvoicePay.pay_time >= search_date,
                                                          AgentInvoicePay.pay_time < end_search_date)
                  if k.client_order.status == 1]
    else:
        orders = [k for k in AgentInvoicePay.all() if k.pay_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.pay_time, reverse=False)
    if request.values.get('action', '') == 'download':
        response = write_order_excel(list(orders), 'pay_rebate_agent_invoice')
        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='pay_rebate_agent_invoice')
Exemple #4
0
def index_pass():
    if not g.user.is_finance():
        abort(404)
    orders = list([
        invoicepay.agent_invoice.client_order for invoicepay in
        AgentInvoicePay.get_agent_invoices_status(AGENT_INVOICE_STATUS_PASS)])
    return tpl('/finance/client_order/agent_pay/index.html', orders=orders, title=u'已打的款媒体信息')
Exemple #5
0
def new_invoice_pay(invoice_id):
    money = float(request.values.get('money', 0))
    pay_time = request.values.get('pay_time', '')
    detail = request.values.get('detail', '')
    bank = request.values.get('bank', '')
    bank_num = request.values.get('bank_num', '')
    company = request.values.get('company', '')
    mi = AgentInvoice.get(invoice_id)
    # if mi.pay_invoice_money + money > mi.money:
    #     flash(u'付款金额大于发票金额,请重新填写!', 'danger')
    #     return redirect(url_for('saler_client_order_agent_invoice.invoice', invoice_id=invoice_id))
    pay = AgentInvoicePay.add(money=money,
                              agent_invoice=mi,
                              pay_time=pay_time,
                              detail=detail,
                              bank=bank,
                              bank_num=bank_num,
                              company=company)
    pay.save()
    mi.client_order.add_comment(g.user, u"新建打款信息\n\n发票号:%s\n\n打款金额:%s元\n\n\
                                        打款时间:%s\n\n公司名称:%s\n\n开户行:%s\n\n银行账号:%s" %
                                (pay.agent_invoice.invoice_num, str(money),
                                 pay_time, company, bank, bank_num),
                                msg_channel=5)
    flash(u'新建打款信息成功!', 'success')
    return redirect(url_for('saler_client_order_agent_invoice.invoice', invoice_id=invoice_id))
Exemple #6
0
def new_invoice_pay(invoice_id):
    money = float(request.values.get('money', 0))
    pay_time = request.values.get('pay_time', '')
    detail = request.values.get('detail', '')
    bank = request.values.get('bank', '')
    bank_num = request.values.get('bank_num', '')
    company = request.values.get('company', '')
    mi = AgentInvoice.get(invoice_id)
    if mi.pay_invoice_money + money > mi.money:
        flash(u'付款金额大于发票金额,请重新填写!', 'danger')
        return redirect(
            url_for('saler_client_order_agent_invoice.invoice',
                    invoice_id=invoice_id))
    pay = AgentInvoicePay.add(money=money,
                              agent_invoice=mi,
                              pay_time=pay_time,
                              pay_status=AGENT_INVOICE_STATUS_PASS,
                              detail=detail,
                              bank=bank,
                              bank_num=bank_num,
                              company=company)
    pay.save()
    flash(u'付款成功!', 'success')
    mi.client_order.add_comment(
        g.user,
        u"财务添加打款信息\n\n发票号:%s\n\n打款金额:%s元\n\n\
                                        打款时间:%s\n\n公司名称:%s\n\n开户行:%s\n\n银行账号:%s"
        % (mi.invoice_num, str(money), pay_time, company, bank, bank_num),
        msg_channel=5)
    return redirect(
        url_for("finance_client_order_agent_pay.pay_info",
                invoice_id=invoice_id))
Exemple #7
0
def _all_agent_rebate_pay():
    agent_rebate_pay_data = [{
        'order_id': k.agent_invoice.client_order_id,
        'money': k.money,
        'agent_id': k.agent_invoice.agent_id,
        'pay_time': k.pay_time
    } for k in AgentInvoicePay.all() if k.pay_status == 0]
    return agent_rebate_pay_data
Exemple #8
0
def index_pass():
    if not g.user.is_finance():
        abort(404)
    orders = list([
        invoicepay.agent_invoice.client_order for invoicepay in
        AgentInvoicePay.get_agent_invoices_status(AGENT_INVOICE_STATUS_PASS)
    ])
    return tpl('/finance/client_order/agent_pay/index.html',
               orders=orders,
               title=u'已打的款媒体信息')
Exemple #9
0
def invoice_pay_time_update(invoice_id):
    pay_time = request.values.get('pay_time', '')
    invoice = AgentInvoicePay.get(invoice_id)
    invoice.pay_time = pay_time
    invoice.save()
    flash(u'保存成功!', 'success')
    invoice.client_order.add_comment(g.user, u"财务更新了打款信息\n\n发票号:%s\n\n打款金额:%s元\n\n\
                                        打款时间:%s\n\n公司名称:%s\n\n开户行:%s\n\n银行账号:%s" %
                                     (invoice.agent_invoice.invoice_num, str(invoice.money),
                                      invoice.pay_time, invoice.company, invoice.bank, invoice.bank_num),
                                     msg_channel=5)
    return jsonify({'ret': True})
Exemple #10
0
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)))
Exemple #11
0
def invoice_pass(invoice_id):
    if not g.user.is_finance():
        abort(404)
    invoice = AgentInvoice.get(invoice_id)
    if not invoice:
        abort(404)
    invoices_ids = request.values.getlist('invoices')
    invoices_pay = AgentInvoicePay.gets(invoices_ids)
    if not invoices_pay:
        abort(403)
    msg = request.values.get('msg', '')
    action = int(request.values.get('action', 0))

    to_users = invoice.client_order.direct_sales + invoice.client_order.agent_sales + \
        [invoice.client_order.creator, g.user]

    if action != 10:
        invoice_status = AGENT_INVOICE_STATUS_PASS
        action_msg = u'代理返点已打款'
        for invoice_pay in invoices_pay:
            invoice_pay.pay_status = invoice_status
            invoice_pay.save()
            flash(
                u'代理订单款已打,名称:%s, 打款金额%s' %
                (invoice_pay.agent_invoice.client_order.name + '-' +
                 invoice_pay.agent_invoice.agent.name, str(invoice_pay.money)),
                'success')
            invoice_pay.agent_invoice.client_order.add_comment(
                g.user,
                u'代理订单款已打款,名称%s, 打款金额%s ' %
                (invoice_pay.agent_invoice.client_order.name + '-' +
                 invoice_pay.agent_invoice.agent.name, str(invoice_pay.money)),
                msg_channel=5)
    else:
        action_msg = u'消息提醒'
    context = {
        "to_users": to_users,
        "action": 0,
        "action_msg": action_msg,
        "info": msg,
        "invoice": invoice,
        "order": invoice.client_order,
        "send_type": 'end',
        "invoice_pays": invoices_pay
    }
    agent_invoice_apply_signal.send(current_app._get_current_object(),
                                    context=context)
    return redirect(
        url_for("finance_client_order_agent_pay.pay_info",
                invoice_id=invoice_id))
Exemple #12
0
def invoice_pay_time_update(invoice_id):
    pay_time = request.values.get('pay_time', '')
    invoice = AgentInvoicePay.get(invoice_id)
    invoice.pay_time = pay_time
    invoice.save()
    flash(u'保存成功!', 'success')
    invoice.client_order.add_comment(
        g.user,
        u"财务更新了打款信息\n\n发票号:%s\n\n打款金额:%s元\n\n\
                                        打款时间:%s\n\n公司名称:%s\n\n开户行:%s\n\n银行账号:%s"
        % (invoice.agent_invoice.invoice_num, str(invoice.money),
           invoice.pay_time, invoice.company, invoice.bank, invoice.bank_num),
        msg_channel=5)
    return jsonify({'ret': True})
Exemple #13
0
def invoice_pay_delete(invoice_id, pid):
    if not g.user.is_finance():
        abort(404)
    invoice = AgentInvoice.get(invoice_id)
    invoice_pay = AgentInvoicePay.get(pid)
    flash(u'删除成功', 'success')
    invoice.client_order.add_comment(g.user, u"财务删除打款信息\n\n发票号:%s\n\n打款金额:%s元\n\n\
                                        打款时间:%s\n\n公司名称:%s\n\n开户行:%s\n\n银行账号:%s" %
                                     (invoice.invoice_num, str(invoice_pay.money),
                                      invoice_pay.pay_time, invoice_pay.company,
                                      invoice_pay.bank, invoice_pay.bank_num),
                                     msg_channel=5)
    invoice_pay.delete()
    return redirect(url_for("finance_client_order_agent_pay.pay_info", invoice_id=invoice_id))
Exemple #14
0
def invoice_pay_delete(invoice_id, pid):
    if not g.user.is_finance():
        abort(404)
    invoice = AgentInvoice.get(invoice_id)
    invoice_pay = AgentInvoicePay.get(pid)
    flash(u'删除成功', 'success')
    invoice.client_order.add_comment(
        g.user,
        u"财务删除打款信息\n\n发票号:%s\n\n打款金额:%s元\n\n\
                                        打款时间:%s\n\n公司名称:%s\n\n开户行:%s\n\n银行账号:%s"
        % (invoice.invoice_num, str(invoice_pay.money), invoice_pay.pay_time,
           invoice_pay.company, invoice_pay.bank, invoice_pay.bank_num),
        msg_channel=5)
    invoice_pay.delete()
    return redirect(
        url_for("finance_client_order_agent_pay.pay_info",
                invoice_id=invoice_id))
Exemple #15
0
def invoice_pass(invoice_id):
    if not g.user.is_finance():
        abort(404)
    invoice = AgentInvoice.get(invoice_id)
    if not invoice:
        abort(404)
    invoices_ids = request.values.getlist('invoices')
    invoices_pay = AgentInvoicePay.gets(invoices_ids)
    if not invoices_pay:
        abort(403)
    msg = request.values.get('msg', '')
    action = int(request.values.get('action', 0))

    to_users = invoice.client_order.direct_sales + invoice.client_order.agent_sales + \
        [invoice.client_order.creator, g.user]

    if action != 10:
        invoice_status = AGENT_INVOICE_STATUS_PASS
        action_msg = u'代理返点已打款'
        for invoice_pay in invoices_pay:
            invoice_pay.pay_status = invoice_status
            invoice_pay.save()
            flash(u'代理订单款已打,名称:%s, 打款金额%s' % (
                invoice_pay.agent_invoice.client_order.name +
                '-' + invoice_pay.agent_invoice.agent.name,
                str(invoice_pay.money)), 'success')
            invoice_pay.agent_invoice.client_order.add_comment(
                g.user, u'代理订单款已打款,名称%s, 打款金额%s ' % (
                    invoice_pay.agent_invoice.client_order.name +
                        '-' + invoice_pay.agent_invoice.agent.name,
                    str(invoice_pay.money)),
                msg_channel=5)
    else:
        action_msg = u'消息提醒'
    context = {"to_users": to_users,
               "action": 0,
               "action_msg": action_msg,
               "info": msg,
               "invoice": invoice,
               "order": invoice.client_order,
               "send_type": 'end',
               "invoice_pays": invoices_pay}
    agent_invoice_apply_signal.send(
        current_app._get_current_object(), context=context)
    return redirect(url_for("finance_client_order_agent_pay.pay_info", invoice_id=invoice_id))
Exemple #16
0
def apply():
    if not g.user.is_finance():
        abort(404)
    search_info = request.args.get('searchinfo', '').strip()
    location_id = int(request.args.get('selected_location', '-1'))
    orders = list(AgentInvoicePay.query.filter_by(pay_status=4))
    if location_id >= 0:
        orders = [
            o for o in orders
            if location_id in o.agent_invoice.client_order.locations
        ]
    if search_info != '':
        orders = [
            o for o in orders if search_info.lower() in
            o.agent_invoice.client_order.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'全部合同状态'))
    for i in orders:
        client_order = i.agent_invoice.client_order
        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_pass.html',
               orders=orders,
               title=u'申请中的客户付款',
               locations=select_locations,
               location_id=location_id,
               statuses=select_statuses,
               now_date=datetime.date.today(),
               search_info=search_info,
               params='?&searchinfo=%s&selected_location=%s' %
               (search_info, location_id))
Exemple #17
0
def pay_rebate_agent_invoice():
    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 AgentInvoicePay.query.filter(
                AgentInvoicePay.pay_time >= search_date,
                AgentInvoicePay.pay_time < end_search_date)
            if k.client_order.status == 1
        ]
    else:
        orders = [
            k for k in AgentInvoicePay.all()
            if k.pay_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.pay_time, reverse=False)
    if request.values.get('action', '') == 'download':
        response = write_order_excel(list(orders), 'pay_rebate_agent_invoice')
        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='pay_rebate_agent_invoice')
Exemple #18
0
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)))
Exemple #19
0
def _all_agent_rebate_pay():
    agent_rebate_pay_data = [{'order_id': k.agent_invoice.client_order_id,
                              'money': k.money, 'agent_id': k.agent_invoice.agent_id,
                              'pay_time': k.pay_time} for k in AgentInvoicePay.all() if k.pay_status == 0]
    return agent_rebate_pay_data
Exemple #20
0
def apply_pay(invoice_id):
    agent_invoice = AgentInvoice.get(invoice_id)
    if not agent_invoice:
        abort(404)
    invoice_pay_ids = request.values.getlist('invoices')
    invoice_pays = AgentInvoicePay.gets(invoice_pay_ids)
    if not invoice_pays:
        abort(403)
    emails = request.values.getlist('email')
    msg = request.values.get('msg', '')
    action = int(request.values.get('action', 0))
    to_users = agent_invoice.client_order.direct_sales + agent_invoice.client_order.agent_sales + \
        [agent_invoice.client_order.creator, g.user] + \
        agent_invoice.client_order.leaders
    if action == 2:
        action_msg = u'代理返点打款申请'
        for invoice in invoice_pays:
            invoice.pay_status = AGENT_INVOICE_STATUS_APPLY
            invoice.save()
            flash(u'[%s代理申请打款,打款金额: %s, 发票号: %s]  %s ' %
                  (invoice.agent_invoice.company, invoice.money,
                   invoice.agent_invoice.invoice_num, invoice.detail), 'success')

            invoice.agent_invoice.client_order.add_comment(g.user, u"%s,%s" % (
                action_msg, u'[%s代理申请打款,打款金额: %s, 发票号: %s]  %s ' %
                (invoice.agent_invoice.company, invoice.money,
                    invoice.agent_invoice.invoice_num, invoice.detail)), msg_channel=5)
        send_type = "saler"
    elif action == 3:
        action_msg = u'代理返点打款申请'
        for invoice in invoice_pays:
            invoice.pay_status = AGENT_INVOICE_STATUS_F_AGREE
            invoice.save()
            flash(u'[副总裁同意%s代理订单打款申请,打款金额: %s, 发票号: %s]  %s ' %
                  (invoice.agent_invoice.company, invoice.money,
                   invoice.agent_invoice.invoice_num, invoice.detail), 'success')

            invoice.agent_invoice.client_order.add_comment(g.user, u"%s,%s" % (
                action_msg, u'[副总裁同意%s代理订单打款申请,打款金额: %s, 发票号: %s]  %s ' %
                (invoice.agent_invoice.company, invoice.money,
                    invoice.agent_invoice.invoice_num, invoice.detail)), msg_channel=5)
        send_type = "saler"
    elif action == 4:
        action_msg = u'黄亮已批准代理返点打款'
        to_users += User.finances()
        for invoice in invoice_pays:
            invoice.pay_status = AGENT_INVOICE_STATUS_AGREE
            invoice.save()
            flash(u'[同意%s代理订单打款申请,打款金额: %s, 发票号: %s]  %s ' %
                  (invoice.agent_invoice.company, invoice.money,
                   invoice.agent_invoice.invoice_num, invoice.detail), 'success')

            invoice.agent_invoice.client_order.add_comment(g.user, u"%s,%s" % (
                action_msg, u'[同意%s代理订单打款申请,打款金额: %s, 发票号: %s]  %s ' %
                (invoice.agent_invoice.company, invoice.money,
                    invoice.agent_invoice.invoice_num, invoice.detail)), msg_channel=5)
        send_type = "finance"
    else:
        action_msg = u'消息提醒'

    context = {"to_users": to_users,
               "action": action,
               "to_other": emails,
               "action_msg": action_msg,
               "info": msg,
               "invoice": agent_invoice,
               "order": agent_invoice.client_order,
               "send_type": send_type,
               "invoice_pays": invoice_pays}
    agent_invoice_apply_signal.send(
        current_app._get_current_object(), context=context)
    return redirect(url_for('saler_client_order_agent_invoice.invoice', invoice_id=invoice_id))
Exemple #21
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)
Exemple #22
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)
Exemple #23
0
def apply_pay(invoice_id):
    agent_invoice = AgentInvoice.get(invoice_id)
    if not agent_invoice:
        abort(404)
    invoice_pay_ids = request.values.getlist('invoices')
    invoice_pays = AgentInvoicePay.gets(invoice_pay_ids)
    if not invoice_pays:
        abort(403)
    emails = request.values.getlist('email')
    msg = request.values.get('msg', '')
    action = int(request.values.get('action', 0))
    to_users = agent_invoice.client_order.direct_sales + agent_invoice.client_order.agent_sales + \
        [agent_invoice.client_order.creator, g.user] + \
        agent_invoice.client_order.leaders
    if action == 2:
        action_msg = u'代理返点打款申请'
        for invoice in invoice_pays:
            invoice.pay_status = AGENT_INVOICE_STATUS_APPLY
            invoice.save()
            flash(
                u'[%s代理申请打款,打款金额: %s, 发票号: %s]  %s ' %
                (invoice.agent_invoice.company, invoice.money,
                 invoice.agent_invoice.invoice_num, invoice.detail), 'success')

            invoice.agent_invoice.client_order.add_comment(
                g.user,
                u"%s,%s" %
                (action_msg, u'[%s代理申请打款,打款金额: %s, 发票号: %s]  %s ' %
                 (invoice.agent_invoice.company, invoice.money,
                  invoice.agent_invoice.invoice_num, invoice.detail)),
                msg_channel=5)
        send_type = "saler"
    elif action == 3:
        action_msg = u'代理返点打款申请'
        for invoice in invoice_pays:
            invoice.pay_status = AGENT_INVOICE_STATUS_F_AGREE
            invoice.save()
            flash(
                u'[副总裁同意%s代理订单打款申请,打款金额: %s, 发票号: %s]  %s ' %
                (invoice.agent_invoice.company, invoice.money,
                 invoice.agent_invoice.invoice_num, invoice.detail), 'success')

            invoice.agent_invoice.client_order.add_comment(
                g.user,
                u"%s,%s" %
                (action_msg, u'[副总裁同意%s代理订单打款申请,打款金额: %s, 发票号: %s]  %s ' %
                 (invoice.agent_invoice.company, invoice.money,
                  invoice.agent_invoice.invoice_num, invoice.detail)),
                msg_channel=5)
        send_type = "saler"
    elif action == 4:
        action_msg = u'黄亮已批准代理返点打款'
        to_users += User.finances()
        for invoice in invoice_pays:
            invoice.pay_status = AGENT_INVOICE_STATUS_AGREE
            invoice.save()
            flash(
                u'[同意%s代理订单打款申请,打款金额: %s, 发票号: %s]  %s ' %
                (invoice.agent_invoice.company, invoice.money,
                 invoice.agent_invoice.invoice_num, invoice.detail), 'success')

            invoice.agent_invoice.client_order.add_comment(
                g.user,
                u"%s,%s" %
                (action_msg, u'[同意%s代理订单打款申请,打款金额: %s, 发票号: %s]  %s ' %
                 (invoice.agent_invoice.company, invoice.money,
                  invoice.agent_invoice.invoice_num, invoice.detail)),
                msg_channel=5)
        send_type = "finance"
    else:
        action_msg = u'消息提醒'

    context = {
        "to_users": to_users,
        "action": action,
        "to_other": emails,
        "action_msg": action_msg,
        "info": msg,
        "invoice": agent_invoice,
        "order": agent_invoice.client_order,
        "send_type": send_type,
        "invoice_pays": invoice_pays
    }
    agent_invoice_apply_signal.send(current_app._get_current_object(),
                                    context=context)
    return redirect(
        url_for('saler_client_order_agent_invoice.invoice',
                invoice_id=invoice_id))