Пример #1
0
def 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 Invoice.query.filter(Invoice.create_time >= search_date,
                                                  Invoice.create_time < end_search_date,
                                                  Invoice.invoice_status == 0) if k.client_order.status == 1]
    else:
        orders = [k for k in Invoice.all() if k.create_time.year == int(
            year) and k.invoice_status == 0 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.create_time, reverse=False)
    if request.values.get('action', '') == 'download':
        response = write_order_excel(list(orders), '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='agent_invoice')
Пример #2
0
def 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 Invoice.query.filter(
                Invoice.create_time >= search_date, Invoice.create_time <
                end_search_date, Invoice.invoice_status == 0)
            if k.client_order.status == 1
        ]
    else:
        orders = [
            k for k in Invoice.all() if k.create_time.year == int(year)
            and k.invoice_status == 0 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.create_time, reverse=False)
    if request.values.get('action', '') == 'download':
        response = write_order_excel(list(orders), '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='agent_invoice')
Пример #3
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)
Пример #4
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)