コード例 #1
0
ファイル: invoice.py プロジェクト: giveme168/braavos
def index(order_id):
    order = ClientOrder.get(order_id)
    if not order:
        abort(404)
    invoices = Invoice.query.filter_by(client_order=order)
    invoices_data = {
        'PASS': [{'invoice': x, 'form': get_invoice_from(x)} for x in
                 invoices if x.invoice_status == INVOICE_STATUS_PASS],
        'NORMAL': [{'invoice': x, 'form': get_invoice_from(x)} for x in
                   invoices if x.invoice_status == INVOICE_STATUS_NORMAL],
        'APPLY': [{'invoice': x, 'form': get_invoice_from(x)} for x in
                  invoices if x.invoice_status == INVOICE_STATUS_APPLY],
        'APPLYPASS': [{'invoice': x, 'form': get_invoice_from(x)} for x in
                      invoices if x.invoice_status == INVOICE_STATUS_APPLYPASS],
        'FAIL': [{'invoice': x, 'form': get_invoice_from(x)} for x in
                 invoices if x.invoice_status == INVOICE_STATUS_FAIL],
    }
    reminder_emails = [(u.name, u.email) for u in User.all_active()]
    new_invoice_form = InvoiceForm()
    new_invoice_form.client_order.choices = [(order.id, order.client.name)]
    new_invoice_form.back_time.data = datetime.date.today()
    return tpl('/saler/client_order/invoice/index.html', order=order,
               invoices_data=invoices_data, new_invoice_form=new_invoice_form,
               INVOICE_STATUS_CN=INVOICE_STATUS_CN, reminder_emails=reminder_emails,
               INVOICE_TYPE_CN=INVOICE_TYPE_CN)
コード例 #2
0
ファイル: back_money.py プロジェクト: giveme168/braavos
def back_invoice(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'))
        num = request.values.get('num', '')
        bm = BackInvoiceRebate.add(
            client_order=order,
            money=money,
            back_time=back_time,
            num=num,
            create_time=datetime.date.today().strftime('%Y-%m-%d'))
        bm.save()
        flash(u'返点发票信息保存成功!', 'success')
        order.add_comment(
            g.user, u"更新了返点发票信息,发票金额: %s; 发票时间: %s; 发票号: %s;" % (money, back_time, num), msg_channel=4)

        apply_context = {
            'order': order,
            'num': money,
            'type': 'invoice',
        }
        back_money_apply_signal.send(
            current_app._get_current_object(), apply_context=apply_context)
        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)
コード例 #3
0
ファイル: invoice.py プロジェクト: giveme168/braavos
def info(order_id):
    if not g.user.is_finance():
        abort(404)
    order = ClientOrder.get(order_id)
    if not order:
        abort(404)
    invoices_data = {
        'PASS': [{'invoice': x, 'form': get_invoice_from(x)} for x in
                 Invoice.query.filter_by(client_order=order) if x.invoice_status == INVOICE_STATUS_PASS],
        'APPLYPASS': [{'invoice': x, 'form': get_invoice_from(x)} for x in
                      Invoice.query.filter_by(client_order=order) if x.invoice_status == INVOICE_STATUS_APPLYPASS],
    }
    reminder_emails = [(u.name, u.email) for u in User.all_active()]
    new_invoice_form = InvoiceForm()
    new_invoice_form.client_order.choices = [(order.id, order.client.name)]
    new_invoice_form.company.data = order.agent.name
    new_invoice_form.bank.data = order.agent.bank
    new_invoice_form.bank_id.data = order.agent.bank_num
    new_invoice_form.address.data = order.agent.address
    new_invoice_form.phone.data = order.agent.phone_num
    new_invoice_form.tax_id.data = order.agent.tax_num
    new_invoice_form.back_time.data = datetime.date.today()
    return tpl('/finance/client_order/invoice/info.html', order=order,
               invoices_data=invoices_data, INVOICE_STATUS_CN=INVOICE_STATUS_CN,
               reminder_emails=reminder_emails, INVOICE_TYPE_CN=INVOICE_TYPE_CN,
               new_invoice_form=new_invoice_form)
コード例 #4
0
ファイル: outsource.py プロジェクト: giveme168/braavos
def order_info():
    now_year = int(request.values.get('year', datetime.datetime.now().year))
    outsources = [_target_outsource_to_dict(
        k, 'client_order') for k in OutSource.all()]
    outsources += [_target_outsource_to_dict(k, 'douban_order')
                   for k in DoubanOutSource.all()]
    outsources = [k for k in outsources if k]
    orders = [k for k in ClientOrder.all() if (k.client_start.year ==
                                               now_year or k.client_end.year == now_year) and k.status == 1]
    orders += [k for k in DoubanOrder.all() if (k.client_start.year ==
                                                now_year or k.client_end.year == now_year) and k.status == 1]
    order_obj = []
    for k in orders:
        order_dict = {}
        if k.__tablename__ == 'bra_client_order':
            order_dict['outsource_obj'] = [o for o in outsources if o[
                'order_type'] == 'client_order' and o['order_id'] == k.id]
        else:
            order_dict['outsource_obj'] = [o for o in outsources if o[
                'order_type'] == 'douban_order' and o['order_id'] == k.id]
        order_dict['contract'] = k.contract
        order_dict['campaign'] = k.campaign
        order_dict['money'] = k.money
        order_dict['locations_cn'] = k.locations_cn
        order_dict['outsources_sum'] = k.outsources_sum
        order_dict['outsources_percent'] = k.outsources_percent
        order_dict['outsources_paied_sum'] = k.outsources_paied_sum_by_shenji('all')
        if order_dict['outsource_obj']:
            order_obj.append(order_dict)
    if request.values.get('action', '') == 'download':
        return write_outsource_order_info_excel(order_obj)
    return tpl('/data_query/outsource/order_info.html', orders=order_obj, now_year=now_year)
コード例 #5
0
ファイル: outsource.py プロジェクト: cash2one/braavos
def client_orders_distribute():
    if request.method == 'POST':
        order_id = request.values.get('order_id', '')
        operator = request.values.get('operater_ids', '')
        order = ClientOrder.get(order_id)
        if operator:
            operater_users = User.gets(operator.split(','))
            to_users = operater_users
            for k in order.medium_orders:
                k.operaters = operater_users
                k.save()
        else:
            for k in order.medium_orders:
                k.operaters = []
                k.save()
            to_users = []
        if to_users:
            context = {"to_users": to_users + [g.user],
                       "operater_users": operater_users,
                       "action_msg": u'分配执行人员',
                       "info": '',
                       "order": order}
            outsource_distribute_signal.send(
                current_app._get_current_object(), context=context)
        return redirect(url_for('outsource.client_orders_distribute'))

    orders = [k for k in ClientOrder.query.all() if k.medium_orders and k.contract != '']
    operaters = User.gets_by_team_type(
        TEAM_TYPE_OPERATER) + User.gets_by_team_type(TEAM_TYPE_OPERATER_LEADER)
    return display_orders(orders, 'client_orders_distribute.html', title=u"客户订单分配", operaters=operaters)
コード例 #6
0
def info(order_id):
    if not g.user.is_finance():
        abort(404)
    order = ClientOrder.get(order_id)
    outsources = order.get_outsources_by_status(4)
    apply_outsources = []
    for k in [1, 2, 3, 5]:
        apply_outsources += order.get_outsources_by_status(k)
    now_date = datetime.datetime.now().strftime('%Y-%m-%d')
    invoices = OutsourceInvoice.query.filter_by(client_order=order)
    if request.method == 'POST':
        OutsourceInvoice.add(client_order=order,
                             company=request.values.get('company', ''),
                             money=float(request.values.get('money', 0)),
                             ex_money=float(request.values.get('ex_money', 0)),
                             invoice_num=request.values.get('invoice_num', ''),
                             add_time=request.values.get('add_time', now_date),
                             create_time=datetime.datetime.now(),
                             creator=g.user)
        return redirect(
            url_for('finance_client_order_outsource_invoice.info',
                    order_id=order.id))
    return tpl('/finance/client_order/outsource/invoice_info.html',
               order=order,
               outsources=outsources,
               now_date=now_date,
               invoices=invoices,
               apply_outsources=apply_outsources)
コード例 #7
0
ファイル: turnover.py プロジェクト: cash2one/braavos
def index():
    if not g.user.is_super_leader():
        abort(403)
    salers = User.sales()
    if request.method == 'POST':
        f_saler = int(request.values.get('f_saler', 0))
        t_saler = int(request.values.get('t_saler', 0))
        if not f_saler or not t_saler:
            flash(u'请选择正确的员工', 'danger')
            return tpl('/account/turnover/index.html', salers=salers)
        f_user = User.get(f_saler)
        t_user = User.get(t_saler)
        client_orders = ClientOrder.all()
        douban_orders = DoubanOrder.all()
        for k in client_orders:
            if f_user in k.salers and t_user not in k.replace_sales:
                k.replace_sales = k.replace_sales + [t_user]
                k.save()
            if k.creator == f_user and t_user not in k.replace_sales:
                k.replace_sales = k.replace_sales + [t_user]
                k.save()
        for k in douban_orders:
            if f_user in k.salers and t_user not in k.replace_sales:
                k.replace_sales = k.replace_sales + [t_user]
                k.save()
            if k.creator == f_user and t_user not in k.replace_sales:
                k.replace_sales = k.replace_sales + [t_user]
                k.save()
        flash(u'成功', 'success')
    return tpl('/account/turnover/index.html', salers=salers)
コード例 #8
0
def info(order_id):
    if not g.user.is_finance():
        abort(404)
    order = ClientOrder.get(order_id)
    if not order:
        abort(404)
    invoices_data = {
        'PASS': [{
            'invoice': x,
            'form': get_invoice_from(x)
        } for x in Invoice.query.filter_by(client_order=order)
                 if x.invoice_status == INVOICE_STATUS_PASS],
        'APPLYPASS': [{
            'invoice': x,
            'form': get_invoice_from(x)
        } for x in Invoice.query.filter_by(client_order=order)
                      if x.invoice_status == INVOICE_STATUS_APPLYPASS],
    }
    reminder_emails = [(u.name, u.email) for u in User.all_active()]
    new_invoice_form = InvoiceForm()
    new_invoice_form.client_order.choices = [(order.id, order.client.name)]
    new_invoice_form.company.data = order.agent.name
    new_invoice_form.bank.data = order.agent.bank
    new_invoice_form.bank_id.data = order.agent.bank_num
    new_invoice_form.address.data = order.agent.address
    new_invoice_form.phone.data = order.agent.phone_num
    new_invoice_form.tax_id.data = order.agent.tax_num
    new_invoice_form.back_time.data = datetime.date.today()
    return tpl('/finance/client_order/invoice/info.html',
               order=order,
               invoices_data=invoices_data,
               INVOICE_STATUS_CN=INVOICE_STATUS_CN,
               reminder_emails=reminder_emails,
               INVOICE_TYPE_CN=INVOICE_TYPE_CN,
               new_invoice_form=new_invoice_form)
コード例 #9
0
ファイル: invoice.py プロジェクト: giveme168/braavos
def new_invoice(order_id):
    order = ClientOrder.get(order_id)
    if not order:
        abort(404)
    form = InvoiceForm(request.form)
    form.client_order.choices = [(order.id, order.client.name)]
    if request.method == 'POST' and form.validate():
        if int(form.money.data) > (int(order.money) - int(order.invoice_apply_sum) - int(order.invoice_pass_sum)):
            flash(u"新建发票失败,您申请的发票超过了合同总额", 'danger')
            return redirect(url_for("finance_client_order_invoice.info", order_id=order_id))
        invoice = Invoice.add(client_order=order,
                              company=form.company.data,
                              tax_id=form.tax_id.data,
                              address=form.address.data,
                              phone=form.phone.data,
                              bank_id=form.bank_id.data,
                              bank=form.bank.data,
                              detail=form.detail.data,
                              money=form.money.data,
                              invoice_type=form.invoice_type.data,
                              creator=g.user,
                              invoice_status=0,
                              invoice_num=request.values.get(
                                  'new_invoice_num', ''),
                              back_time=form.back_time.data,
                              create_time=request.values.get('create_time',
                                                             datetime.datetime.now().strftime('%Y-%m-%d')))
        invoice.save()
        flash(u'开发票(%s)成功!' % form.company.data, 'success')
        order.add_comment(g.user, u"已开发票信息:%s" % (
            u'发票内容: %s; 发票金额: %s元' % (invoice.detail, str(invoice.money))), msg_channel=1)
    else:
        for k in form.errors:
            flash(u"新建发票失败,%s" % (form.errors[k][0]), 'danger')
    return redirect(url_for("finance_client_order_invoice.info", order_id=order.id))
コード例 #10
0
ファイル: other_cost.py プロジェクト: cash2one/braavos
def update(order_id, oid):
    if not (g.user.is_super_leader() or g.user.is_finance()
            or g.user.is_operater_leader()):
        abort(403)
    order = ClientOrder.get(order_id)
    if not order:
        abort(404)
    company = request.values.get('company', '')
    money = request.values.get('money', 0)
    invoice = request.values.get('invoice', '')
    type = int(request.values.get('type', 1))
    on_time = request.values.get('on_time', datetime.datetime.today())
    other_cost = OtherCost.get(oid)
    other_cost.company = company
    other_cost.client_order = order
    other_cost.money = money
    other_cost.invoice = invoice
    other_cost.type = type
    other_cost.on_time = on_time
    other_cost.save()
    order.add_comment(
        g.user,
        u"更新了外包,公司:%s ; 金额:%s ; 发票:%s ; 类型:%s ; 发生时间:%s" %
        (other_cost.company, str(other_cost.money), other_cost.invoice,
         other_cost.type_cn, other_cost.on_time_cn),
        msg_channel=10)

    return redirect(
        url_for('saler_client_order_other_cost.index', order_id=order_id))
コード例 #11
0
ファイル: turnover.py プロジェクト: giveme168/braavos
def index():
    if not g.user.is_super_leader():
        abort(403)
    salers = User.sales()
    if request.method == 'POST':
        f_saler = int(request.values.get('f_saler', 0))
        t_saler = int(request.values.get('t_saler', 0))
        if not f_saler or not t_saler:
            flash(u'请选择正确的员工', 'danger')
            return tpl('/account/turnover/index.html', salers=salers)
        f_user = User.get(f_saler)
        t_user = User.get(t_saler)
        client_orders = ClientOrder.all()
        douban_orders = DoubanOrder.all()
        for k in client_orders:
            if f_user in k.salers and t_user not in k.replace_sales:
                k.replace_sales = k.replace_sales + [t_user]
                k.save()
            if k.creator == f_user and t_user not in k.replace_sales:
                k.replace_sales = k.replace_sales + [t_user]
                k.save()
        for k in douban_orders:
            if f_user in k.salers and t_user not in k.replace_sales:
                k.replace_sales = k.replace_sales + [t_user]
                k.save()
            if k.creator == f_user and t_user not in k.replace_sales:
                k.replace_sales = k.replace_sales + [t_user]
                k.save()
        flash(u'成功', 'success')
    return tpl('/account/turnover/index.html', salers=salers)
コード例 #12
0
ファイル: other.py プロジェクト: giveme168/braavos
def fix_data():
    if not g.user.is_super_leader():
        abort(403)
    year = int(request.values.get('year', 2015))
    year_date = datetime.datetime.strptime(str(year), '%Y')
    orders = [k for k in ClientOrder.all() if k.client_start.year ==
              year and k.contract_status not in [0, 7, 8, 9] and k.status == 1 and k.contract]
    for k in orders:
        for i in k.medium_orders:
            if int(k.self_agent_rebate.split('-')[0]) == 1:
                agent_rebate_value = float(k.self_agent_rebate.split('-')[1])
                if k.money:
                    i.medium_rebate_value = agent_rebate_value * i.sale_money / k.money
                else:
                    i.medium_rebate_value = 0
            else:
                medium_rebate = i.medium_rebate_by_year(year_date)
                i.medium_rebate_value = i.medium_money2 * medium_rebate / 100
        if int(k.self_agent_rebate.split('-')[0]) == 1:
            k.agent_rebate_value = float(k.self_agent_rebate.split('-')[1])
        else:
            agent_rebate = k.agent_rebate
            k.agent_rebate_value = k.money * agent_rebate / 100
    if request.values.get('action') == 'download':
        return write_fix_date(orders)
    return tpl('/fix_data.html', orders=orders, year=year)
コード例 #13
0
ファイル: other.py プロジェクト: cash2one/braavos
def fix_data():
    if not g.user.is_super_leader():
        abort(403)
    year = int(request.values.get('year', 2015))
    year_date = datetime.datetime.strptime(str(year), '%Y')
    orders = [
        k for k in ClientOrder.all() if k.client_start.year == year and
        k.contract_status not in [0, 7, 8, 9] and k.status == 1 and k.contract
    ]
    for k in orders:
        for i in k.medium_orders:
            if int(k.self_agent_rebate.split('-')[0]) == 1:
                agent_rebate_value = float(k.self_agent_rebate.split('-')[1])
                if k.money:
                    i.medium_rebate_value = agent_rebate_value * i.sale_money / k.money
                else:
                    i.medium_rebate_value = 0
            else:
                medium_rebate = i.medium_rebate_by_year(year_date)
                i.medium_rebate_value = i.medium_money2 * medium_rebate / 100
        if int(k.self_agent_rebate.split('-')[0]) == 1:
            k.agent_rebate_value = float(k.self_agent_rebate.split('-')[1])
        else:
            agent_rebate = k.agent_rebate
            k.agent_rebate_value = k.money * agent_rebate / 100
    if request.values.get('action') == 'download':
        return write_fix_date(orders)
    return tpl('/fix_data.html', orders=orders, year=year)
コード例 #14
0
def back_money(order_id):
    if not g.user.is_finance():
        abort(404)
    client_order = ClientOrder.get(order_id)
    back_moneys = MediumBackMoney.query.filter_by(client_order_id=order_id)
    if not client_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'))
        medium_id = request.values.get('medium')
        order = Order.get(medium_id)
        MediumBackMoney.add(client_order_id=order_id,
                            order_id=medium_id,
                            money=money,
                            back_time=back_time)
        client_order.add_comment(g.user, u"更新了媒体返点回款信息,所属媒体:%s; 回款金额: %s; 回款时间: %s;" % (
            order.medium.name, money, back_time), msg_channel=8)
        apply_context = {
            'order': client_order,
            'num': money,
            'type': 'money',
        }
        medium_back_money_apply_signal.send(
            current_app._get_current_object(), apply_context=apply_context)
        flash(u'回款信息保存成功!', 'success')
        return redirect(url_for('finance_client_order_medium_back_money.back_money', order_id=order_id))
    return tpl('/finance/client_order/medium_back_money/info.html', order=client_order, back_moneys=back_moneys)
コード例 #15
0
def outsource():
    if not (g.user.is_leader() or g.user.is_super_leader()):
        abort(403)
    orders = list(ClientOrder.all())
    orders += list(DoubanOrder.all())
    orders = [k for k in orders if k.status == 1]
    search_info = request.values.get('search_info', '')
    location = int(request.values.get('location', 0))
    if search_info:
        orders = [
            k for k in orders
            if search_info.lower().strip() in k.search_info.lower()
        ]
    if location:
        orders = [k for k in orders if location in k.locations]
    if g.user.team.type == TEAM_TYPE_LEADER:
        orders = [
            o for o in orders
            if g.user.location in o.locations and o.get_outsources_by_status(1)
        ]
    elif g.user.team.type == TEAM_TYPE_SUPER_LEADER:
        orders = [o for o in orders if o.get_outsources_by_status(5)]
    if g.user.is_super_admin():
        orders = [
            o for o in orders
            if o.get_outsources_by_status(5) or o.get_outsources_by_status(1)
        ]
    return tpl('/manage/apply/order.html',
               title=u'外包费用报备审批',
               orders=orders,
               search_info=search_info,
               location=location,
               a_type="outsource")
コード例 #16
0
ファイル: insert_orders.py プロジェクト: giveme168/braavos
def index():
    if not g.user.is_super_admin():
        abort(403)
    form = ClientOrderForm(request.form)
    mediums = [(m.id, m.name) for m in Medium.all()]
    if request.method == 'POST' and form.validate():
        if ClientOrder.query.filter_by(contract=request.values.get('contract')).count() > 0:
            flash(u'合同号已存在', 'danger')
            return redirect(url_for('util_insert_orders.index'))
        order = ClientOrder.add(agent=Agent.get(form.agent.data),
                                client=Client.get(form.client.data),
                                campaign=form.campaign.data,
                                money=int("%.0f" % (form.money.data or 0)),
                                client_start=form.client_start.data,
                                client_end=form.client_end.data,
                                reminde_date=form.reminde_date.data,
                                direct_sales=User.gets(form.direct_sales.data),
                                agent_sales=User.gets(form.agent_sales.data),
                                contract_type=form.contract_type.data,
                                resource_type=form.resource_type.data,
                                sale_type=form.sale_type.data,
                                contract=request.values.get('contract', ''),
                                creator=g.user,
                                contract_status=2,
                                create_time=datetime.now())
        order.add_comment(g.user,
                          u"导入了客户订单:%s - %s - %s" % (
                              order.agent.name,
                              order.client.name,
                              order.campaign
                          ))
        medium_ids = request.values.getlist('medium')
        medium_moneys = request.values.getlist('medium_money')
        medium_moneys2 = request.values.getlist('medium_money2')
        medium_contracts = request.values.getlist('medium_contract')
        if medium_ids and medium_moneys and len(medium_ids) == len(medium_moneys):
            for x in range(len(medium_ids)):
                medium = Medium.get(medium_ids[x])
                mo = Order.add(campaign=order.campaign,
                               medium=medium,
                               sale_money=int("%.0f" % (form.money.data or 0)),
                               medium_money=int(medium_moneys[x] or 0),
                               medium_money2=int(medium_moneys2[x] or 0),
                               medium_contract=medium_contracts[x],
                               medium_start=order.client_start,
                               medium_end=order.client_end,
                               creator=g.user)
                order.medium_orders = order.medium_orders + [mo]
                order.add_comment(g.user, u"导入了媒体订单: %s %s元" %
                                  (medium.name, mo.sale_money))
            order.save()
        flash(u'导入客户订单成功!', 'success')
        insert_executive_report(order, '')
        return redirect(order.info_path())
    else:
        form.client_start.data = datetime.now().date()
        form.client_end.data = datetime.now().date()
        form.reminde_date.data = datetime.now().date()
    return tpl('insert_order.html', form=form, mediums=mediums)
コード例 #17
0
ファイル: back_money.py プロジェクト: giveme168/braavos
def delete_invoice(order_id, bid):
    order = ClientOrder.get(order_id)
    bm = BackInvoiceRebate.get(bid)
    order.add_comment(g.user, u"删除了返点发票信息,发票金额: %s; 开票时间: %s; 发票号: %s;" % (
        bm.money, bm.back_time_cn, bm.num), msg_channel=4)
    bm.delete()
    flash(u'删除成功!', 'success')
    return redirect(url_for("finance_client_order_back_money.back_money", order_id=order.id))
コード例 #18
0
ファイル: other_cost.py プロジェクト: cash2one/braavos
def index(order_id):
    if not (g.user.is_super_leader() or g.user.is_finance()
            or g.user.is_aduit() or g.user.is_operater_leader()):
        abort(403)
    order = ClientOrder.get(order_id)
    if not order:
        abort(404)
    return tpl('/saler/client_order/other_cost/index.html', order=order)
コード例 #19
0
def delete(order_id, bid):
    order = ClientOrder.get(order_id)
    bm = MediumBackMoney.get(bid)
    order.add_comment(g.user, u"删除了媒体返点回款信息,所属媒体: %s; 回款金额: %s; 回款时间: %s;" %
                      (bm.order.medium.name, bm.money, bm.back_time_cn), msg_channel=8)
    bm.delete()
    flash(u'删除成功!', 'success')
    return redirect(url_for("finance_client_order_medium_back_money.back_money", order_id=order.id))
コード例 #20
0
ファイル: medium_back_money.py プロジェクト: cash2one/braavos
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()
        ]
    if orderby and len(orders):
        orders = sorted(orders,
                        key=lambda x: getattr(x, orderby),
                        reverse=True)
    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)

    return tpl(
        '/finance/client_order/medium_back_money/index.html',
        orders=orders,
        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)))
コード例 #21
0
ファイル: order.py プロジェクト: cash2one/braavos
def _get_order_by_type(type, id):
    if type == 'client_order':
        client_order = ClientOrder.get(id)
        if client_order:
            return _order_to_dict(client_order)
        return {}
    elif type == 'douban_order':
        douban_order = DoubanOrder.get(id)
        if douban_order:
            return _order_to_dict(douban_order)
        return {}
    elif type == 'ass_douban_order':
        client_order = ClientOrder.get(id)
        if client_order:
            return _order_to_dict(client_order,
                                  client_order.associated_douban_orders[0])
        return {}
    return {}
コード例 #22
0
ファイル: outsource.py プロジェクト: giveme168/braavos
def index(order_id):
    order = ClientOrder.get(order_id)
    if not order:
        abort(404)
    outsources = []
    for k in range(1, 6):
        outsources += order.get_outsources_by_status(k)
    invoices = OutsourceInvoice.query.filter_by(client_order=order)
    return tpl('/saler/client_order/outsource/index.html', order=order, outsources=outsources, invoices=invoices)
コード例 #23
0
def index():
    if not g.user.is_finance():
        abort(404)
    orders = list(ClientOrder.all())
    orderby = request.args.get('orderby', '')
    search_info = request.args.get('searchinfo', '')
    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()
        ]
    if orderby and len(orders):
        orders = sorted(orders,
                        key=lambda x: getattr(x, orderby),
                        reverse=True)
    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 k in orders.object_list:
        k.ex_money = sum([
            i.ex_money
            for i in OutsourceInvoice.query.filter_by(client_order=k)
        ])
        k.pay_num = sum([i.pay_num for i in k.get_outsources_by_status(4)])
        apply_outsources = []
        for i in [1, 2, 3, 5]:
            apply_outsources += k.get_outsources_by_status(i)
        k.apply_money = sum([j.pay_num for j in apply_outsources])
    return tpl(
        '/finance/client_order/outsource/invoice.html',
        orders=orders,
        locations=select_locations,
        location_id=location_id,
        statuses=select_statuses,
        orderby=orderby,
        now_date=datetime.date.today(),
        search_info=search_info,
        page=page,
        year=year,
        params='&orderby=%s&searchinfo=%s&selected_location=%s&year=%s' %
        (orderby, search_info, location_id, year))
コード例 #24
0
ファイル: outsource.py プロジェクト: cash2one/braavos
def client_outsources(order_id):
    order = ClientOrder.get(order_id)
    if not order:
        abort(404)
    new_outsource_form = OutsourceForm()
    new_outsource_form.medium_order.choices = [
        (mo.id, mo.medium.name) for mo in order.medium_orders]
    reminder_emails = [(u.name, u.email) for u in User.all_active()]
    context = {'new_outsource_form': new_outsource_form,
               'reminder_emails': reminder_emails,
               'order': order}
    return tpl('client_outsources.html', **context)
コード例 #25
0
ファイル: back_money.py プロジェクト: cash2one/braavos
def delete_invoice(order_id, bid):
    order = ClientOrder.get(order_id)
    bm = BackInvoiceRebate.get(bid)
    order.add_comment(g.user,
                      u"删除了返点发票信息,发票金额: %s; 开票时间: %s; 发票号: %s;" %
                      (bm.money, bm.back_time_cn, bm.num),
                      msg_channel=4)
    bm.delete()
    flash(u'删除成功!', 'success')
    return redirect(
        url_for("finance_client_order_back_money.back_money",
                order_id=order.id))
コード例 #26
0
def index(order_id):
    order = ClientOrder.get(order_id)
    if not order:
        abort(404)
    outsources = []
    for k in range(1, 6):
        outsources += order.get_outsources_by_status(k)
    invoices = OutsourceInvoice.query.filter_by(client_order=order)
    return tpl('/saler/client_order/outsource/index.html',
               order=order,
               outsources=outsources,
               invoices=invoices)
コード例 #27
0
ファイル: medium_back_money.py プロジェクト: cash2one/braavos
def delete(order_id, bid):
    order = ClientOrder.get(order_id)
    bm = MediumBackMoney.get(bid)
    order.add_comment(g.user,
                      u"删除了媒体返点回款信息,所属媒体: %s; 回款金额: %s; 回款时间: %s;" %
                      (bm.order.medium.name, bm.money, bm.back_time_cn),
                      msg_channel=8)
    bm.delete()
    flash(u'删除成功!', 'success')
    return redirect(
        url_for("finance_client_order_medium_back_money.back_money",
                order_id=order.id))
コード例 #28
0
def index_pass():
    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'))
    year = int(request.values.get('year', datetime.datetime.now().year))
    page = int(request.args.get('p', 1))
    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)
    type = request.args.get('type', '')
    if type == 'excel':
        orders = set([
            invoice.client_order
            for invoice in Invoice.get_invoices_status(INVOICE_STATUS_PASS)
        ])
        xls = write_excel(list(orders))
        response = get_download_response(
            xls,
            ("%s-%s.xls" %
             (u"申请过的发票信息", datetime.datetime.now().strftime('%Y%m%d%H%M%S'))
             ).encode('utf-8'))
        return response
    return tpl('/finance/client_order/invoice/index_pass.html',
               orders=orders,
               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)))
コード例 #29
0
ファイル: agent_pay.py プロジェクト: cash2one/braavos
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)))
コード例 #30
0
ファイル: outsource.py プロジェクト: cash2one/braavos
def client_orders():
    if any([g.user.is_super_leader(),
            g.user.is_operater_leader(),
            g.user.is_contract(),
            g.user.is_media()]):
        orders = [k for k in ClientOrder.query.all() if k.medium_orders and k.contract != '']
    elif g.user.is_leader():
        orders = [o for o in ClientOrder.query.all(
        ) if g.user.location in o.locations and o.medium_orders and o.contract != '']
    else:
        orders = [
            k for k in ClientOrder.get_order_by_user(g.user) if k.medium_orders]
    return display_orders(orders, 'client_orders.html', title=u"我的媒体外包", operaters=[])
コード例 #31
0
ファイル: agent_invoice.py プロジェクト: giveme168/braavos
def index(order_id):
    order = ClientOrder.get(order_id)
    if not order:
        abort(404)
    invoices = AgentInvoice.query.filter_by(client_order=order)
    reminder_emails = [(u.name, u.email) for u in User.all_active()]
    new_invoice_form = AgentInvoiceForm()
    new_invoice_form.client_order.choices = [(order.id, order.client.name)]
    new_invoice_form.agent.choices = [(k.id, k.name)for k in order.agents]
    new_invoice_form.add_time.data = datetime.date.today()
    return tpl('/saler/client_order/agent/index.html', order=order, reminder_emails=reminder_emails,
               new_invoice_form=new_invoice_form, invoices=invoices,
               AGENT_INVOICE_STATUS_CN=AGENT_INVOICE_STATUS_CN, INVOICE_TYPE_CN=INVOICE_TYPE_CN)
コード例 #32
0
def info(order_id):
    if not g.user.is_finance():
        abort(404)
    order = ClientOrder.get(order_id)
    if not order:
        abort(404)
    invoices = MediumInvoice.query.filter_by(client_order=order)
    reminder_emails = [(u.id, u.name) for u in User.all_active()]
    new_invoice_form = MediumInvoiceForm()
    new_invoice_form.client_order.choices = [(order.id, order.client.name)]
    new_invoice_form.medium.choices = [(k.id, k.name)for k in order.mediums]
    new_invoice_form.add_time.data = datetime.date.today()
    return tpl('/finance/client_order/medium_pay/info.html', order=order, invoices=invoices,
               new_invoice_form=new_invoice_form, reminder_emails=reminder_emails,
               MEDIUM_INVOICE_STATUS_CN=MEDIUM_INVOICE_STATUS_CN, INVOICE_TYPE_CN=INVOICE_TYPE_CN)
コード例 #33
0
ファイル: outsource.py プロジェクト: cash2one/braavos
def executive_report(order_id):
    otype = request.values.get('otype', 'ClientOrder')
    if otype == 'DoubanOrder':
        order = DoubanOrder.get(order_id)
    else:
        order = ClientOrder.get(order_id)
    if not order:
        abort(404)
    if not g.user.is_admin():
        abort(402)
    _insert_executive_report(order, request.values.get('rtype', None))
    if otype == 'ClientOrder':
        return redirect(url_for("outsource.client_orders"))
    else:
        return redirect(url_for("outsource.douban_orders"))
コード例 #34
0
def order_info():
    now_year = int(request.values.get('year', datetime.datetime.now().year))
    outsources = [
        _target_outsource_to_dict(k, 'client_order') for k in OutSource.all()
    ]
    outsources += [
        _target_outsource_to_dict(k, 'douban_order')
        for k in DoubanOutSource.all()
    ]
    outsources = [k for k in outsources if k]
    orders = [
        k for k in ClientOrder.all()
        if (k.client_start.year == now_year or k.client_end.year == now_year)
        and k.status == 1
    ]
    orders += [
        k for k in DoubanOrder.all()
        if (k.client_start.year == now_year or k.client_end.year == now_year)
        and k.status == 1
    ]
    order_obj = []
    for k in orders:
        order_dict = {}
        if k.__tablename__ == 'bra_client_order':
            order_dict['outsource_obj'] = [
                o for o in outsources
                if o['order_type'] == 'client_order' and o['order_id'] == k.id
            ]
        else:
            order_dict['outsource_obj'] = [
                o for o in outsources
                if o['order_type'] == 'douban_order' and o['order_id'] == k.id
            ]
        order_dict['contract'] = k.contract
        order_dict['campaign'] = k.campaign
        order_dict['money'] = k.money
        order_dict['locations_cn'] = k.locations_cn
        order_dict['outsources_sum'] = k.outsources_sum
        order_dict['outsources_percent'] = k.outsources_percent
        order_dict['outsources_paied_sum'] = k.outsources_paied_sum_by_shenji(
            'all')
        if order_dict['outsource_obj']:
            order_obj.append(order_dict)
    if request.values.get('action', '') == 'download':
        return write_outsource_order_info_excel(order_obj)
    return tpl('/data_query/outsource/order_info.html',
               orders=order_obj,
               now_year=now_year)
コード例 #35
0
def delete(order_id, invoice_id):
    if not g.user.is_finance():
        abort(404)
    order = ClientOrder.get(order_id)
    if not order:
        abort(404)
    invoice = MediumInvoice.get(invoice_id)
    pays = invoice.medium_invoice_pays
    if pays.count() > 0:
        flash(u'暂时不能删除,已有付款信息', 'danger')
        return redirect(url_for('finance_client_order_medium_pay.info', order_id=order_id))
    client_order = invoice.client_order
    client_order.add_comment(g.user, u"删除付款发票申请信息:%s" % (
        u'发票内容: %s; 发票金额: %s元; 发票号: %s' % (invoice.detail, str(invoice.money), invoice.invoice_num)), msg_channel=3)
    invoice.delete()
    return redirect(url_for('finance_client_order_medium_pay.info', order_id=order_id))
コード例 #36
0
def index(order_id):
    order = ClientOrder.get(order_id)
    if not order:
        abort(404)
    invoices = AgentInvoice.query.filter_by(client_order=order)
    reminder_emails = [(u.name, u.email) for u in User.all_active()]
    new_invoice_form = AgentInvoiceForm()
    new_invoice_form.client_order.choices = [(order.id, order.client.name)]
    new_invoice_form.agent.choices = [(k.id, k.name) for k in order.agents]
    new_invoice_form.add_time.data = datetime.date.today()
    return tpl('/saler/client_order/agent/index.html',
               order=order,
               reminder_emails=reminder_emails,
               new_invoice_form=new_invoice_form,
               invoices=invoices,
               AGENT_INVOICE_STATUS_CN=AGENT_INVOICE_STATUS_CN,
               INVOICE_TYPE_CN=INVOICE_TYPE_CN)
コード例 #37
0
ファイル: medium_pay.py プロジェクト: giveme168/braavos
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)))
コード例 #38
0
ファイル: medium_invoice.py プロジェクト: cash2one/braavos
def new_invoice(order_id,
                redirect_endpoint='saler_client_order_medium_invoice.index'):
    order = ClientOrder.get(order_id)
    if not order:
        abort(404)
    form = MediumInvoiceForm(request.form)
    form.client_order.choices = [(order.id, order.client.name)]
    form.medium.choices = [(order.id, order.client.name)
                           for k in order.mediums]
    form.bool_invoice.choices = MEDIUM_INVOICE_BOOL_INVOICE_CN.items()
    # if order.mediums_money2 < order.mediums_invoice_sum + float(form.money.data):
    #     flash(u'新建打款发票失败,发票超过媒体总金额!', 'danger')
    #     return redirect(url_for(redirect_endpoint, order_id=order_id))
    if request.method == 'POST':
        invoice = MediumInvoice.add(
            client_order=order,
            medium=Medium.get(form.medium.data),
            company=form.company.data,
            tax_id=form.tax_id.data,
            address=form.address.data,
            phone=form.phone.data,
            bank_id=form.bank_id.data,
            bank=form.bank.data,
            detail=form.detail.data,
            money=form.money.data,
            pay_money=form.money.data,
            invoice_type=form.invoice_type.data,
            invoice_status=MEDIUM_INVOICE_STATUS_NORMAL,
            creator=g.user,
            invoice_num=form.invoice_num.data,
            add_time=form.add_time.data,
            bool_invoice=form.bool_invoice.data)
        invoice.save()
        flash(u'新建打款发票(%s)成功!' % form.company.data, 'success')
        order.add_comment(
            g.user,
            u"添加打款发票申请信息:%s" %
            (u'发票内容: %s; 发票金额: %s元; 发票号: %s' %
             (invoice.detail, str(invoice.money), invoice.invoice_num)),
            msg_channel=3)
    else:
        for k in form.errors:
            flash(u"新建打款发票失败,%s" % (form.errors[k][0]), 'danger')
    return redirect(url_for(redirect_endpoint, order_id=order_id))
コード例 #39
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()]
    if orderby and len(orders):
        orders = sorted(
            orders, key=lambda x: getattr(x, orderby), reverse=True)
    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)

    return tpl('/finance/client_order/medium_back_money/index.html', orders=orders,
               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)))
コード例 #40
0
def new_invoice(order_id):
    order = ClientOrder.get(order_id)
    if not order:
        abort(404)
    form = InvoiceForm(request.form)
    form.client_order.choices = [(order.id, order.client.name)]
    if request.method == 'POST' and form.validate():
        if int(form.money.data) > (int(order.money) - int(
                order.invoice_apply_sum) - int(order.invoice_pass_sum)):
            flash(u"新建发票失败,您申请的发票超过了合同总额", 'danger')
            return redirect(
                url_for("finance_client_order_invoice.info",
                        order_id=order_id))
        invoice = Invoice.add(
            client_order=order,
            company=form.company.data,
            tax_id=form.tax_id.data,
            address=form.address.data,
            phone=form.phone.data,
            bank_id=form.bank_id.data,
            bank=form.bank.data,
            detail=form.detail.data,
            money=form.money.data,
            invoice_type=form.invoice_type.data,
            creator=g.user,
            invoice_status=0,
            invoice_num=request.values.get('new_invoice_num', ''),
            back_time=form.back_time.data,
            create_time=request.values.get(
                'create_time',
                datetime.datetime.now().strftime('%Y-%m-%d')))
        invoice.save()
        flash(u'开发票(%s)成功!' % form.company.data, 'success')
        order.add_comment(g.user,
                          u"已开发票信息:%s" %
                          (u'发票内容: %s; 发票金额: %s元' %
                           (invoice.detail, str(invoice.money))),
                          msg_channel=1)
    else:
        for k in form.errors:
            flash(u"新建发票失败,%s" % (form.errors[k][0]), 'danger')
    return redirect(
        url_for("finance_client_order_invoice.info", order_id=order.id))
コード例 #41
0
def info(order_id):
    if not g.user.is_finance():
        abort(404)
    order = ClientOrder.get(order_id)
    if not order:
        abort(404)
    invoices_data = {
        'PASS': [{'invoice': x, 'form': get_invoice_from(order, x)} for x in
                 MediumRebateInvoice.query.filter_by(client_order=order) if x.invoice_status == INVOICE_STATUS_PASS],
        'APPLYPASS': [{'invoice': x, 'form': get_invoice_from(order, x)} for x in
                      MediumRebateInvoice.query.filter_by(client_order=order)
                      if x.invoice_status == INVOICE_STATUS_APPLYPASS],
    }
    reminder_emails = [(u.name, u.email) for u in User.all_active()]
    new_invoice_form = get_invoice_from(order, invoice=None)
    return tpl('/finance/client_order/medium_rebate_invoice/info.html', order=order,
               invoices_data=invoices_data, INVOICE_STATUS_CN=INVOICE_STATUS_CN,
               reminder_emails=reminder_emails, INVOICE_TYPE_CN=INVOICE_TYPE_CN,
               new_invoice_form=new_invoice_form)
コード例 #42
0
def new_invoice(
        order_id,
        redirect_epoint='saler_client_order_medium_rebate_invoice.index'):
    order = ClientOrder.get(order_id)
    if not order:
        abort(404)
    form = MediumRebateInvoiceForm(request.form)
    form.client_order.choices = [(order.id, order.client.name)]
    form.medium.choices = [(medium.id, medium.name)
                           for medium in order.mediums]
    if request.method == 'POST' and form.validate():
        medium = Medium.get(form.medium.data)
        # if float(form.money.data) > float(order.get_medium_rebate_money(medium) -
        #                                   order.get_medium_rebate_invoice_apply_sum(medium) -
        #                                   order.get_medium_rebate_invoice_pass_sum(medium)):
        #     flash(u"新建发票失败,您申请的发票超过了媒体:%s 返点金额: %s" % (medium.name, order.get_medium_rebate_money(medium)), 'danger')
        #     return redirect(url_for(redirect_epoint, order_id=order_id))
        invoice = MediumRebateInvoice.add(client_order=order,
                                          medium=Medium.get(form.medium.data),
                                          company=form.company.data,
                                          tax_id=form.tax_id.data,
                                          address=form.address.data,
                                          phone=form.phone.data,
                                          bank_id=form.bank_id.data,
                                          bank=form.bank.data,
                                          detail=form.detail.data,
                                          money=form.money.data,
                                          invoice_type=form.invoice_type.data,
                                          invoice_status=INVOICE_STATUS_NORMAL,
                                          creator=g.user,
                                          invoice_num=" ",
                                          back_time=form.back_time.data)
        invoice.save()
        order.add_comment(g.user,
                          u"添加发票申请信息:%s" %
                          (u'发票内容: %s; 发票金额: %s元' %
                           (invoice.detail, str(invoice.money))),
                          msg_channel=6)
    else:
        for k in form.errors:
            flash(u"新建发票失败,%s" % (form.errors[k][0]), 'danger')
    return redirect(url_for(redirect_epoint, order_id=order_id))
コード例 #43
0
def index_pass():
    if not g.user.is_finance():
        abort(404)
    orders = list(ClientOrder.all())
    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))
    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()]
    if orderby and len(orders):
        orders = sorted(
            orders, key=lambda x: getattr(x, orderby), reverse=True)
    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)
    type = request.args.get('type', '')
    if type == 'excel':
        orders = set([invoice.client_order for invoice in MediumRebateInvoice.get_invoices_status(
            INVOICE_STATUS_PASS)])
        xls = write_medium_rebate_invoice_excel(list(orders))
        response = get_download_response(
            xls, ("%s-%s.xls" % (u"申请过的媒体返点发票信息", datetime.datetime.now().strftime('%Y%m%d%H%M%S'))).encode('utf-8'))
        return response
    return tpl('/finance/client_order/medium_rebate_invoice/index_pass.html', orders=orders, locations=select_locations,
               location_id=location_id, statuses=select_statuses, orderby=orderby,
               now_date=datetime.date.today(), search_info=search_info, page=page, year=year,
               params='&orderby=%s&searchinfo=%s&selected_location=%s&year=%s' %
                      (orderby, search_info, location_id, str(year)))
コード例 #44
0
ファイル: agent_total.py プロジェクト: cash2one/braavos
def index():
    if not (g.user.is_super_leader() or g.user.is_aduit() or g.user.is_finance()):
        abort(403)
    now_date = datetime.datetime.now()
    year = int(request.values.get('year', now_date.year))
    orders = [_format_order(k, year) for k in ClientOrder.all()]
    orders = [k for k in orders if k['client_start'].year == year]
    # 去掉撤单、申请中的合同
    orders = [k for k in orders if k['contract_status'] in [2, 4, 5, 10, 19, 20] and k['status'] == 1 and k['contract']]
    # 获取所有代理
    agents = [{'name': a.name, 'id': a.id, 'group_id': a.group.id} for a in Agent.all()]
    # 获取代理集团
    groups = [{'name': gp.name, 'agents': [p for p in agents if p['group_id'] == gp.id]} for gp in Group.all()]
    # xxx_count 用于html合并表单
    agent_obj = []
    total_is_sale_money = 0
    total_is_medium_money = 0
    for k in groups:
        if not k['agents']:
            html_order_count = 0
        else:
            html_order_count = 1
        excel_order_count = 0
        agent_data = []
        for a in k['agents']:
            order_data = [o for o in orders if o['agent_id'] == a['id']]
            if order_data:
                html_order_count += len(order_data) + 1
                excel_order_count += len(order_data)
                total_is_sale_money += sum([o['is_sale_money'] for o in order_data])
                total_is_medium_money += sum([o['is_medium_money'] for o in order_data])
                agent_data.append({'name': a['name'], 'orders': order_data, 'html_order_count': len(order_data)})
        if agent_data:
            agent_obj.append({'name': k['name'], 'agents': agent_data, 'html_order_count': html_order_count,
                              'excel_order_count': excel_order_count})
    action = request.values.get('action', '')
    if action == 'excel':
        return write_agent_total_excel(year=year, agent_obj=agent_obj, total_is_sale_money=total_is_sale_money,
                                       total_is_medium_money=total_is_medium_money)
    return tpl('/data_query/super_leader/agent_total.html', year=year, agent_obj=agent_obj,
               total_is_sale_money=total_is_sale_money, total_is_medium_money=total_is_medium_money)
コード例 #45
0
def index():
    if not g.user.is_finance():
        abort(404)
    orders = list(ClientOrder.all())
    orderby = request.args.get('orderby', '')
    search_info = request.args.get('searchinfo', '')
    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()]
    if orderby and len(orders):
        orders = sorted(
            orders, key=lambda x: getattr(x, orderby), reverse=True)
    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 k in orders.object_list:
        k.ex_money = sum(
            [i.ex_money for i in OutsourceInvoice.query.filter_by(client_order=k)])
        k.pay_num = sum([i.pay_num for i in k.get_outsources_by_status(4)])
        apply_outsources = []
        for i in [1, 2, 3, 5]:
            apply_outsources += k.get_outsources_by_status(i)
        k.apply_money = sum([j.pay_num for j in apply_outsources])
    return tpl('/finance/client_order/outsource/invoice.html', orders=orders, locations=select_locations,
               location_id=location_id, statuses=select_statuses, orderby=orderby,
               now_date=datetime.date.today(), search_info=search_info, page=page, year=year,
               params='&orderby=%s&searchinfo=%s&selected_location=%s&year=%s' %
                      (orderby, search_info, location_id, year))
コード例 #46
0
def new_invoice(order_id, redirect_epoint='finance_client_order_medium_rebate_invoice.info'):
    order = ClientOrder.get(order_id)
    if not order:
        abort(404)
    form = MediumRebateInvoiceForm(request.form)
    form.client_order.choices = [(order.id, order.client.name)]
    form.medium.choices = [(medium.id, medium.name)
                           for medium in order.mediums]
    if request.method == 'POST' and form.validate():
        medium = Medium.get(form.medium.data)
        # if float(form.money.data) > float(order.get_medium_rebate_money(medium) -
        #                                   order.get_medium_rebate_invoice_apply_sum(medium) -
        #                                   order.get_medium_rebate_invoice_pass_sum(medium)):
        #     flash(u"新建发票失败,您申请的发票超过了媒体:%s 返点金额: %s" % (medium.name, order.get_medium_rebate_money(medium)), 'danger')
        #     return redirect(url_for(redirect_epoint, order_id=order_id))
        invoice = MediumRebateInvoice.add(client_order=order,
                                          medium=Medium.get(form.medium.data),
                                          company=form.company.data,
                                          tax_id=form.tax_id.data,
                                          address=form.address.data,
                                          phone=form.phone.data,
                                          bank_id=form.bank_id.data,
                                          bank=form.bank.data,
                                          detail=form.detail.data,
                                          money=form.money.data,
                                          invoice_type=form.invoice_type.data,
                                          invoice_status=INVOICE_STATUS_PASS,
                                          creator=g.user,
                                          invoice_num=form.invoice_num.data,
                                          create_time=request.values.get(
                                              'create_time', datetime.datetime.now().strftime('%Y-%m-%d')),
                                          back_time=form.back_time.data)
        invoice.save()
        order.add_comment(g.user, u"添加发票申请信息:%s" % (
            u'发票内容: %s; 发票金额: %s元' % (invoice.detail, str(invoice.money))), msg_channel=6)
    else:
        for k in form.errors:
            flash(u"新建发票失败,%s" % (form.errors[k][0]), 'danger')
    return redirect(url_for(redirect_epoint, order_id=order_id))
コード例 #47
0
ファイル: invoice.py プロジェクト: cash2one/braavos
def index(order_id):
    order = ClientOrder.get(order_id)
    if not order:
        abort(404)
    invoices = Invoice.query.filter_by(client_order=order)
    invoices_data = {
        'PASS': [{
            'invoice': x,
            'form': get_invoice_from(x)
        } for x in invoices if x.invoice_status == INVOICE_STATUS_PASS],
        'NORMAL': [{
            'invoice': x,
            'form': get_invoice_from(x)
        } for x in invoices if x.invoice_status == INVOICE_STATUS_NORMAL],
        'APPLY': [{
            'invoice': x,
            'form': get_invoice_from(x)
        } for x in invoices if x.invoice_status == INVOICE_STATUS_APPLY],
        'APPLYPASS': [{
            'invoice': x,
            'form': get_invoice_from(x)
        } for x in invoices if x.invoice_status == INVOICE_STATUS_APPLYPASS],
        'FAIL': [{
            'invoice': x,
            'form': get_invoice_from(x)
        } for x in invoices if x.invoice_status == INVOICE_STATUS_FAIL],
    }
    reminder_emails = [(u.name, u.email) for u in User.all_active()]
    new_invoice_form = InvoiceForm()
    new_invoice_form.client_order.choices = [(order.id, order.client.name)]
    new_invoice_form.back_time.data = datetime.date.today()
    return tpl('/saler/client_order/invoice/index.html',
               order=order,
               invoices_data=invoices_data,
               new_invoice_form=new_invoice_form,
               INVOICE_STATUS_CN=INVOICE_STATUS_CN,
               reminder_emails=reminder_emails,
               INVOICE_TYPE_CN=INVOICE_TYPE_CN)
コード例 #48
0
ファイル: medium_invoice.py プロジェクト: giveme168/braavos
def new_invoice(order_id, redirect_endpoint='saler_client_order_medium_invoice.index'):
    order = ClientOrder.get(order_id)
    if not order:
        abort(404)
    form = MediumInvoiceForm(request.form)
    form.client_order.choices = [(order.id, order.client.name)]
    form.medium.choices = [(order.id, order.client.name)
                           for k in order.mediums]
    form.bool_invoice.choices = MEDIUM_INVOICE_BOOL_INVOICE_CN.items()
    # if order.mediums_money2 < order.mediums_invoice_sum + float(form.money.data):
    #     flash(u'新建打款发票失败,发票超过媒体总金额!', 'danger')
    #     return redirect(url_for(redirect_endpoint, order_id=order_id))
    if request.method == 'POST':
        invoice = MediumInvoice.add(client_order=order,
                                    medium=Medium.get(form.medium.data),
                                    company=form.company.data,
                                    tax_id=form.tax_id.data,
                                    address=form.address.data,
                                    phone=form.phone.data,
                                    bank_id=form.bank_id.data,
                                    bank=form.bank.data,
                                    detail=form.detail.data,
                                    money=form.money.data,
                                    pay_money=form.money.data,
                                    invoice_type=form.invoice_type.data,
                                    invoice_status=MEDIUM_INVOICE_STATUS_NORMAL,
                                    creator=g.user,
                                    invoice_num=form.invoice_num.data,
                                    add_time=form.add_time.data,
                                    bool_invoice=form.bool_invoice.data)
        invoice.save()
        flash(u'新建打款发票(%s)成功!' % form.company.data, 'success')
        order.add_comment(g.user, u"添加打款发票申请信息:%s" % (
            u'发票内容: %s; 发票金额: %s元; 发票号: %s' % (invoice.detail, str(invoice.money), invoice.invoice_num)), msg_channel=3)
    else:
        for k in form.errors:
            flash(u"新建打款发票失败,%s" % (form.errors[k][0]), 'danger')
    return redirect(url_for(redirect_endpoint, order_id=order_id))
コード例 #49
0
ファイル: apply.py プロジェクト: giveme168/braavos
def outsource():
    if not (g.user.is_leader() or g.user.is_super_leader()):
        abort(403)
    orders = list(ClientOrder.all())
    orders += list(DoubanOrder.all())
    orders = [k for k in orders if k.status == 1]
    search_info = request.values.get('search_info', '')
    location = int(request.values.get('location', 0))
    if search_info:
        orders = [k for k in orders if search_info.lower().strip()
                  in k.search_info.lower()]
    if location:
        orders = [k for k in orders if location in k.locations]
    if g.user.team.type == TEAM_TYPE_LEADER:
        orders = [
            o for o in orders if g.user.location in o.locations and o.get_outsources_by_status(1)]
    elif g.user.team.type == TEAM_TYPE_SUPER_LEADER:
        orders = [o for o in orders if o.get_outsources_by_status(5)]
    if g.user.is_super_admin():
        orders = [o for o in orders if o.get_outsources_by_status(
            5) or o.get_outsources_by_status(1)]
    return tpl('/manage/apply/order.html', title=u'外包费用报备审批', orders=orders,
               search_info=search_info, location=location, a_type="outsource")
コード例 #50
0
def info(order_id):
    if not g.user.is_finance():
        abort(404)
    order = ClientOrder.get(order_id)
    outsources = order.get_outsources_by_status(4)
    apply_outsources = []
    for k in [1, 2, 3, 5]:
        apply_outsources += order.get_outsources_by_status(k)
    now_date = datetime.datetime.now().strftime('%Y-%m-%d')
    invoices = OutsourceInvoice.query.filter_by(client_order=order)
    if request.method == 'POST':
        OutsourceInvoice.add(
            client_order=order,
            company=request.values.get('company', ''),
            money=float(request.values.get('money', 0)),
            ex_money=float(request.values.get('ex_money', 0)),
            invoice_num=request.values.get('invoice_num', ''),
            add_time=request.values.get('add_time', now_date),
            create_time=datetime.datetime.now(),
            creator=g.user
        )
        return redirect(url_for('finance_client_order_outsource_invoice.info', order_id=order.id))
    return tpl('/finance/client_order/outsource/invoice_info.html', order=order, outsources=outsources,
               now_date=now_date, invoices=invoices, apply_outsources=apply_outsources)
コード例 #51
0
ファイル: medium_back_money.py プロジェクト: cash2one/braavos
def back_money(order_id):
    if not g.user.is_finance():
        abort(404)
    client_order = ClientOrder.get(order_id)
    back_moneys = MediumBackMoney.query.filter_by(client_order_id=order_id)
    if not client_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'))
        medium_id = request.values.get('medium')
        order = Order.get(medium_id)
        MediumBackMoney.add(client_order_id=order_id,
                            order_id=medium_id,
                            money=money,
                            back_time=back_time)
        client_order.add_comment(g.user,
                                 u"更新了媒体返点回款信息,所属媒体:%s; 回款金额: %s; 回款时间: %s;" %
                                 (order.medium.name, money, back_time),
                                 msg_channel=8)
        apply_context = {
            'order': client_order,
            'num': money,
            'type': 'money',
        }
        medium_back_money_apply_signal.send(current_app._get_current_object(),
                                            apply_context=apply_context)
        flash(u'回款信息保存成功!', 'success')
        return redirect(
            url_for('finance_client_order_medium_back_money.back_money',
                    order_id=order_id))
    return tpl('/finance/client_order/medium_back_money/info.html',
               order=client_order,
               back_moneys=back_moneys)
コード例 #52
0
                er = MediumOrderExecutiveReport.add(client_order=order.client_order,
                                                    order=order,
                                                    medium_money=i[
                                                        'medium_money'],
                                                    medium_money2=i[
                                                        'medium_money2'],
                                                    sale_money=i[
                                                        'sale_money'],
                                                    month_day=i['month'],
                                                    days=i['days'],
                                                    create_time=None)
                er.save()
    return True

if __name__ == '__main__':
    client_orders = ClientOrder.all()
    douban_orders = DoubanOrder.all()
    framework_orders = FrameworkOrder.all()
    medium_framework_orders = MediumFrameworkOrder.all()
    search_client_orders = searchAdClientOrder.all()
    search_rebate_orders = searchAdRebateOrder.all()
    search_framework_orders = searchAdFrameworkOrder.all()

    for c in client_orders:
        c.client_start_year = c.client_start.year
        c.client_end_year = c.client_end.year
        c.save()
        _insert_zhiqu_executive_report(c, 'reload')

    for d in douban_orders:
        d.client_start_year = d.client_start.year