Exemple #1
0
def pay_medium_invoice():
    if not (g.user.is_media() or g.user.is_media_leader() or g.user.is_contract()):
        abort(404)
    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 MediumInvoicePay.query.filter(MediumInvoicePay.pay_time >= search_date,
                                                           MediumInvoicePay.pay_time < end_search_date)
                  if k.client_order.status == 1 and k.pay_status == 0]
    else:
        orders = [k for k in MediumInvoicePay.all() if k.pay_time.year == int(
            year) and k.client_order.status == 1 and k.pay_status == 0]
    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_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_medium_invoice')
        return response
    return tpl('/media/client_order/data_query/index.html',
               orders=orders, location=location,
               year=year, month=month, info=info,
               title=u"付款给媒体金额", t_type='pay_medium_invoice')
Exemple #2
0
def index():
    if not g.user.is_finance():
        abort(404)
    orders = list(ClientOrder.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', '').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))
    # 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_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
        medium_invoices = [k.id for k in MediumInvoice.query.filter_by(client_order=client_order)]
        pays = [k for k in MediumInvoicePay.all() if k.medium_invoice_id in medium_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/medium_pay/index_pass.html', orders=orders, title=u'申请中的媒体付款',
               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)))
Exemple #3
0
def apply():
    if not g.user.is_finance():
        abort(404)
    medium_id = int(request.args.get('medium_id', 0))
    search_info = request.args.get('searchinfo', '').strip()
    location_id = int(request.args.get('selected_location', '-1'))
    page = int(request.args.get('p', 1))

    orders = list(MediumInvoicePay.query.filter_by(pay_status=4))
    if location_id >= 0:
        orders = [
            o for o in orders if location_id in o.medium_invoice.client_order.locations]
    if search_info != '':
        orders = [
            o for o in orders if search_info.lower() in o.medium_invoice.client_order.search_invoice_info.lower()]
    if medium_id:
        orders = [o for o in orders if medium_id == o.medium_invoice.medium_id]
    select_locations = TEAM_LOCATION_CN.items()
    select_locations.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.medium_invoice.client_order
        medium_invoices = [k.id for k in MediumInvoice.query.filter_by(client_order=client_order)]
        pays = [k for k in MediumInvoicePay.all() if k.medium_invoice_id in medium_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/medium_pay/index.html', orders=orders, title=u'申请中的媒体付款',
               locations=select_locations, location_id=location_id,
               now_date=datetime.date.today(),
               search_info=search_info, page=page,
               mediums=[(k.id, k.name) for k in Medium.all()], medium_id=medium_id,
               params='&searchinfo=%s&selected_location=%s&medium_id=%s' %
                      (search_info, location_id, str(medium_id)))
Exemple #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)
Exemple #5
0
 def back_moneys(self):
     medium_invoices = MediumInvoice.query.filter_by(
         client_order=self.client_order, medium_id=self.medium_id)
     return sum([k.money for k in MediumInvoicePay.all() if
                 k.pay_status == 0 and k.medium_invoice in medium_invoices])
Exemple #6
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)