Exemplo n.º 1
0
def outs():
    user_id = int(request.values.get('user_id', 0))
    page = int(request.values.get('p', 1))
    status = int(request.values.get('status', 0))
    start = request.values.get('start', '')
    end = request.values.get('end', '')
    outs = [
        k for k in Out.all() if k.status > 0]

    if start and end:
        start_time = datetime.datetime.strptime(start, "%Y-%m-%d %H:%M")
        end_time = datetime.datetime.strptime(end, "%Y-%m-%d %H:%M")
        outs = [k for k in outs if k.start_time >=
                start_time and k.start_time < end_time]
    if status:
        outs = [k for k in outs if k.status == status]
    if user_id:
        outs = [k for k in outs if k.creator.id == user_id]
    outs = sorted(outs, key=lambda x: x.start_time, reverse=True)
    if request.values.get('action') == 'excel':
        return write_outs_excel(outs)
    paginator = Paginator(outs, 50)
    try:
        outs = paginator.page(page)
    except:
        outs = paginator.page(paginator.num_pages)
    return tpl('/account/out/outs.html', outs=outs, user_id=user_id, start=start,
               title=u'所有外出报备列表', status=status,
               params="&user_id=%s&start=%s&end=%s&status=%s" % (
                   user_id, start, end, status), end=end, page=page,
               under_users=[{'uid': k.id, 'name': k.name} for k in User.all()])
Exemplo n.º 2
0
def index(type):
    page = int(request.values.get('p', 1))
    industry = request.values.get('industry', '')
    medium = int(request.values.get('medium', 0))
    info = request.values.get('info', '')
    cases = list(Case.query.filter_by(type=type))
    if medium:
        cases = [case for case in cases if medium in case.mediums_id]
    if info:
        cases = [case for case in cases if info in case.info]
    if industry:
        cases = [case for case in cases if industry == case.industry]
    paginator = Paginator(cases, 50)
    try:
        cases = paginator.page(page)
    except:
        cases = paginator.page(paginator.num_pages)
    return tpl('/mediums/planning/index.html',
               title=CASE_TYPE_CN[int(type)],
               mediums=Medium.all(),
               medium=medium,
               cases=cases,
               type=type,
               info=info,
               params="&info=%s&medium=%s&industry=%s" %
               (info, str(medium), industry),
               INDUSTRY=INDUSTRY,
               page=page,
               tags=Tag.all(),
               industry=industry)
Exemplo n.º 3
0
def index():
    page = int(request.values.get('p', 1))
    medium_id = int(request.values.get('medium_id', 0))
    product_id = int(request.values.get('product_id', 0))
    type = int(request.values.get('type', 0))
    number = request.values.get('number', '')
    filters = {}
    if medium_id:
        filters['medium_id'] = medium_id
    if product_id:
        filters['product'] = product_id
    if type:
        filters['type'] = type
    if filters:
        resources = MediumResource.query.filter_by(**filters)
    else:
        resources = MediumResource.all()
    if number:
        resources = resources.filter(
            MediumResource.number.startswith(number.strip()))
    paginator = Paginator(list(resources), 50)
    try:
        resources = paginator.page(page)
    except:
        resources = paginator.page(paginator.num_pages)
    for k in resources.object_list:
        if k.type == 1:
            k.product_obj = MediumProductPC.get(k.product)
        elif k.type == 2:
            k.product_obj = MediumProductApp.get(k.product)
        elif k.type == 3:
            k.product_obj = MediumProductDown.get(k.product)
    return tpl('/mediums/resource/index.html', resources=resources, mediums=Medium.all(),
               type=type, product_id=product_id, number=number, medium_id=medium_id,
               params="&medium_id=%s&number=%s&type=%s&product_id=%s" % (medium_id, number, type, product_id))
Exemplo n.º 4
0
def index():
    brefs = list(Bref.all())
    if g.user.is_leader() or g.user.is_operater_leader():
        brefs = [k for k in brefs if k.creator.location == g.user.location and k.status != 1]
    elif g.user.is_planner():
        brefs = [k for k in brefs if k.status != 1]
    else:
        brefs = [k for k in brefs if k.creator == g.user]

    if g.user.team.type in [0, 14]:
        brefs = list(Bref.all())

    page = int(request.values.get('p', 1))
    location = int(request.values.get('location', 0))
    status = int(request.values.get('status', 100))
    info = request.values.get('info', '')

    if location != 0:
        brefs = [b for b in brefs if b.creator.location == location]
    if status != 100:
        brefs = [b for b in brefs if b.status == status]
    if info:
        brefs = [b for b in brefs if info in b.info]
    paginator = Paginator(brefs, 20)
    try:
        brefs = paginator.page(page)
    except:
        brefs = paginator.page(paginator.num_pages)
    return tpl('/planning/bref/index.html', brefs=brefs,
               BREF_STATUS_CN=BREF_STATUS_CN, status=status,
               location=location, info=info,
               params='&location=%s&status=%s&info=%s' % (str(location), str(status), info))
Exemplo n.º 5
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)))
Exemplo n.º 6
0
def index():
    page = int(request.values.get('page', 1))
    reports = PerformanceEvaluation.query.filter_by(creator=g.user)
    paginator = Paginator(list(reports), 20)
    try:
        reports = paginator.page(page)
    except:
        reports = paginator.page(paginator.num_pages)
    return tpl('/account/kpi/index.html', reports=reports)
Exemplo n.º 7
0
def index():
    page = int(request.values.get('p', 1))
    outs = list(Out.query.filter_by(creator=g.user))
    paginator = Paginator(outs, 50)
    try:
        outs = paginator.page(page)
    except:
        outs = paginator.page(paginator.num_pages)
    return tpl('/account/out/index.html', outs=outs, page=page)
Exemplo n.º 8
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))
Exemplo n.º 9
0
def underling():
    user_id = int(request.values.get('user_id', 0))
    page = int(request.values.get('p', 1))
    type = int(request.values.get('type', 0))
    status = int(request.values.get('status', 100))
    start = request.values.get('start', '')
    end = request.values.get('end', '')

    if g.user.is_super_leader():
        leaves = [
            k for k in Leave.all()
            if k.status in [LEAVE_STATUS_APPLY, LEAVE_STATUS_PASS]
        ]
        under_users = [{'uid': k.id, 'name': k.name} for k in User.all()]
    else:
        under_users = _get_all_under_users(g.user.id)
        if user_id:
            underling_user_ids = [user_id]
        else:
            underling_user_ids = list(set([k['uid'] for k in under_users]))
        leaves = [
            k for k in Leave.all() if k.creator.id in underling_user_ids
            and k.status in [LEAVE_STATUS_APPLY, LEAVE_STATUS_PASS]
        ]

    if start and end:
        start_time = datetime.datetime.strptime(start, "%Y-%m-%d")
        end_time = datetime.datetime.strptime(end, "%Y-%m-%d")
        leaves = [
            k for k in leaves
            if k.start_time >= start_time and k.start_time < end_time
        ]
    if type:
        leaves = [k for k in leaves if k.type == int(type)]
    if status != 100:
        leaves = [k for k in leaves if k.status == status]
    leaves = sorted(leaves, key=lambda x: x.start_time, reverse=True)
    paginator = Paginator(leaves, 50)
    try:
        leaves = paginator.page(page)
    except:
        leaves = paginator.page(paginator.num_pages)
    return tpl('/account/leave/leaves.html',
               leaves=leaves,
               user_id=user_id,
               type=type,
               start=start,
               title=u'下属的请假申请列表',
               under_users=under_users,
               status=status,
               params="&user_id=%s&type=%s&start=%s&end=%s&status=%s" %
               (user_id, type, start, end, str(status)),
               end=end,
               page=page)
Exemplo n.º 10
0
def leaves():
    if not (g.user.is_HR_leader() or g.user.is_OPS()
            or g.user.is_super_leader() or g.user.email in ['*****@*****.**']):
        flash(u'对不起您没有权限', 'danger')
        return redirect(url_for('account_leave.index', user_id=g.user.id))
    user_id = int(request.values.get('user_id', 0))
    page = int(request.values.get('p', 1))
    type = int(request.values.get('type', 0))
    status = int(request.values.get('status', 100))
    start = request.values.get('start', '')
    end = request.values.get('end', '')

    leaves = [
        k for k in Leave.all()
        if k.status in [LEAVE_STATUS_APPLY, LEAVE_STATUS_PASS]
    ]

    if start and end:
        start_time = datetime.datetime.strptime(start, "%Y-%m-%d")
        end_time = datetime.datetime.strptime(end, "%Y-%m-%d")
        leaves = [
            k for k in leaves
            if k.start_time >= start_time and k.start_time < end_time
        ]
    if type:
        leaves = [k for k in leaves if k.type == int(type)]
    if user_id:
        leaves = [k for k in leaves if k.creator.id == user_id]
    if status != 100:
        leaves = [k for k in leaves if k.status == status]

    leaves = sorted(leaves, key=lambda x: x.start_time, reverse=True)
    if request.values.get('action') == 'excel':
        return write_outs_excel(leaves)
    paginator = Paginator(leaves, 50)
    try:
        leaves = paginator.page(page)
    except:
        leaves = paginator.page(paginator.num_pages)
    return tpl('/account/leave/leaves.html',
               leaves=leaves,
               user_id=user_id,
               type=type,
               start=start,
               title=u'所有请假申请列表',
               under_users=[{
                   'uid': k.id,
                   'name': k.name
               } for k in User.all()],
               params="&user_id=%s&type=%s&start=%s&end=%s&status=%s" %
               (user_id, type, start, end, str(status)),
               status=status,
               end=end,
               page=page)
Exemplo n.º 11
0
def index(user_id):
    if g.user.id != int(user_id):
        flash(u'对不起您不能查看别人的请假申请表', 'danger')
        return redirect(url_for('account_leave.index', user_id=g.user.id))
    page = int(request.values.get('p', 1))
    leaves = [k for k in Leave.all() if k.creator.id == int(user_id)]
    paginator = Paginator(leaves, 50)
    try:
        leaves = paginator.page(page)
    except:
        leaves = paginator.page(paginator.num_pages)
    return tpl('/account/leave/index.html', leaves=leaves, page=page)
Exemplo n.º 12
0
def index(user_id):
    if g.user.id != int(user_id):
        flash(u'对不起您不能查看别人的请假申请表', 'danger')
        return redirect(url_for('account_leave.index', user_id=g.user.id))
    page = int(request.values.get('p', 1))
    leaves = [k for k in Leave.all() if k.creator.id == int(user_id)]
    paginator = Paginator(leaves, 50)
    try:
        leaves = paginator.page(page)
    except:
        leaves = paginator.page(paginator.num_pages)
    return tpl('/account/leave/index.html', leaves=leaves, page=page)
Exemplo n.º 13
0
def index():
    if not g.user.is_finance():
        abort(404)
    orders = list(ClientOrder.all())
    search_info = request.args.get('searchinfo', '').strip()
    location_id = int(request.args.get('selected_location', '-1'))
    page = int(request.args.get('p', 1))
    year = int(request.values.get('year', datetime.datetime.now().year))
    if location_id >= 0:
        orders = [o for o in orders if location_id in o.locations]
    orders = [
        k for k in orders
        if k.client_start.year == year or k.client_end.year == year
    ]
    if search_info != '':
        orders = [
            o for o in orders
            if search_info.lower() in o.search_invoice_info.lower()
        ]
    select_locations = TEAM_LOCATION_CN.items()
    select_locations.insert(0, (-1, u'全部区域'))
    select_statuses = CONTRACT_STATUS_CN.items()
    select_statuses.insert(0, (-1, u'全部合同状态'))
    paginator = Paginator(orders, ORDER_PAGE_NUM)
    try:
        orders = paginator.page(page)
    except:
        orders = paginator.page(paginator.num_pages)
    for i in orders.object_list:
        client_order = i
        agent_invoices = [
            k.id
            for k in AgentInvoice.query.filter_by(client_order=client_order)
        ]
        pays = [
            k for k in AgentInvoicePay.all()
            if k.agent_invoice_id in agent_invoices
        ]
        i.apply_num = len([k for k in pays if k.pay_status == 4])
        i.pay_num = len([k for k in pays if k.pay_status == 0])
    return tpl('/finance/client_order/agent_pay/index.html',
               orders=orders,
               title=u'全部客户付款',
               locations=select_locations,
               location_id=location_id,
               statuses=select_statuses,
               now_date=datetime.date.today(),
               search_info=search_info,
               page=page,
               year=year,
               params='&&searchinfo=%s&selected_location=%s&year=%s' %
               (search_info, location_id, str(year)))
Exemplo n.º 14
0
def index_pass():
    if not g.user.is_finance():
        abort(404)
    orders = list(ClientMediumOrder.all())
    search_info = request.args.get('searchinfo', '')
    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_medium_order for invoice in
            ClientMediumInvoice.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_medium_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)))
Exemplo n.º 15
0
def underling():
    page = int(request.values.get('p', 1))
    status = int(request.values.get('status', 0))
    version = int(request.values.get('version', 3))
    reports = PerformanceEvaluation.query.filter_by(version=version)
    if status != 0:
        reports = [k for k in reports if k.status == status]

    if g.user.is_HR_leader() or g.user.is_super_leader():
        reports = [k for k in reports if k.status > 1]
    else:
        underling_users = list(
            set([k['uid'] for k in _get_all_under_users(g.user.id)]))
        reports = [
            k for k in reports
            if k.status > 1 and k.creator.id in underling_users
        ]
    total_score = str(request.values.get('total_score', 0))
    if total_score != '0':
        total_score_p = total_score.split('-')
        if len(total_score) == 1:
            reports = [
                k for k in reports
                if float(k.total_score +
                         k.personnal_score) == float(total_score)
            ]
        else:
            start, end = float(total_score_p[0]), float(total_score_p[1])
            reports = [
                k for k in reports
                if float(k.total_score + k.personnal_score) >= start
                and float(k.total_score + k.personnal_score) < end
            ]

    if request.values.get('action') == 'excel':
        return write_simple_report_excel(reports)
    paginator = Paginator(list(reports), 20)
    try:
        reports = paginator.page(page)
    except:
        reports = paginator.page(paginator.num_pages)
    return tpl('/account/kpi/underling.html',
               reports=reports,
               status=status,
               params='&status=' + str(status) + '&total_score=' +
               str(total_score) + '&version=' + str(version),
               total_score=total_score,
               P_VERSION_CN=P_VERSION_CN,
               version=version)
Exemplo n.º 16
0
def personnal():
    status = int(request.values.get('status', 1))
    page = int(request.values.get('p', 1))
    if g.user.is_super_admin():
        personnal_objs = PerformanceEvaluationPersonnal.query.filter_by(
            status=status)
    else:
        personnal_objs = PerformanceEvaluationPersonnal.query.filter_by(
            user=g.user, status=status)
    paginator = Paginator(list(personnal_objs), 20)
    try:
        personnal_objs = paginator.page(page)
    except:
        personnal_objs = paginator.page(paginator.num_pages)
    return tpl('/account/kpi/personnal_index.html',
               personnal_objs=personnal_objs,
               status=status)
Exemplo n.º 17
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)))
Exemplo n.º 18
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)))
Exemplo n.º 19
0
def index_pass():
    if not g.user.is_finance():
        abort(404)
    orders = list(searchAdClientOrder.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_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 searchAdMediumRebateInvoice.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/searchAd_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)))
Exemplo n.º 20
0
def underling():
    user_id = int(request.values.get('user_id', 0))
    page = int(request.values.get('p', 1))
    type = int(request.values.get('type', 0))
    status = int(request.values.get('status', 100))
    start = request.values.get('start', '')
    end = request.values.get('end', '')

    if g.user.is_super_leader():
        leaves = [k for k in Leave.all() if k.status in [
            LEAVE_STATUS_APPLY, LEAVE_STATUS_PASS]]
        under_users = [{'uid': k.id, 'name': k.name}for k in User.all()]
    else:
        under_users = _get_all_under_users(g.user.id)
        if user_id:
            underling_user_ids = [user_id]
        else:
            underling_user_ids = list(set([k['uid'] for k in under_users]))
        leaves = [k for k in Leave.all() if k.creator.id in underling_user_ids and k.status in [
            LEAVE_STATUS_APPLY, LEAVE_STATUS_PASS]]

    if start and end:
        start_time = datetime.datetime.strptime(start, "%Y-%m-%d")
        end_time = datetime.datetime.strptime(end, "%Y-%m-%d")
        leaves = [k for k in leaves if k.start_time >=
                  start_time and k.start_time < end_time]
    if type:
        leaves = [k for k in leaves if k.type == int(type)]
    if status != 100:
        leaves = [k for k in leaves if k.status == status]
    leaves = sorted(leaves, key=lambda x: x.start_time, reverse=True)
    paginator = Paginator(leaves, 50)
    try:
        leaves = paginator.page(page)
    except:
        leaves = paginator.page(paginator.num_pages)
    return tpl('/account/leave/leaves.html', leaves=leaves, user_id=user_id, type=type, start=start,
               title=u'下属的请假申请列表', under_users=under_users, status=status,
               params="&user_id=%s&type=%s&start=%s&end=%s&status=%s" % (
                   user_id, type, start, end, str(status)),
               end=end, page=page)
Exemplo n.º 21
0
def index():
    if not g.user.is_finance():
        abort(404)
    orders = list(searchAdRebateOrder.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', '')
    location_id = int(request.args.get('selected_location', '-1'))
    page = int(request.args.get('p', 1))
    # 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]
    if search_info != '':
        orders = [
            o for o in orders if search_info.lower() in o.search_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/searchAd_rebate_order/agent_pay/index.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,
               params='&orderby=%s&searchinfo=%s&selected_location=%s&selected_status=%s' %
                      (orderby, search_info, location_id, status_id))
Exemplo n.º 22
0
def leaves():
    if not (g.user.is_HR_leader() or g.user.is_OPS() or g.user.is_super_leader()
            or g.user.email in ['*****@*****.**']):
        flash(u'对不起您没有权限', 'danger')
        return redirect(url_for('account_leave.index', user_id=g.user.id))
    user_id = int(request.values.get('user_id', 0))
    page = int(request.values.get('p', 1))
    type = int(request.values.get('type', 0))
    status = int(request.values.get('status', 100))
    start = request.values.get('start', '')
    end = request.values.get('end', '')

    leaves = [
        k for k in Leave.all() if k.status in [LEAVE_STATUS_APPLY, LEAVE_STATUS_PASS]]

    if start and end:
        start_time = datetime.datetime.strptime(start, "%Y-%m-%d")
        end_time = datetime.datetime.strptime(end, "%Y-%m-%d")
        leaves = [k for k in leaves if k.start_time >=
                  start_time and k.start_time < end_time]
    if type:
        leaves = [k for k in leaves if k.type == int(type)]
    if user_id:
        leaves = [k for k in leaves if k.creator.id == user_id]
    if status != 100:
        leaves = [k for k in leaves if k.status == status]

    leaves = sorted(leaves, key=lambda x: x.start_time, reverse=True)
    if request.values.get('action') == 'excel':
        return write_outs_excel(leaves)
    paginator = Paginator(leaves, 50)
    try:
        leaves = paginator.page(page)
    except:
        leaves = paginator.page(paginator.num_pages)
    return tpl('/account/leave/leaves.html', leaves=leaves, user_id=user_id, type=type, start=start,
               title=u'所有请假申请列表', under_users=[{'uid': k.id, 'name': k.name} for k in User.all()],
               params="&user_id=%s&type=%s&start=%s&end=%s&status=%s" % (
                   user_id, type, start, end, str(status)),
               status=status, end=end, page=page)
Exemplo n.º 23
0
def index():
    if not g.user.is_finance():
        abort(404)
    orders = list(DoubanOrder.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_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 DoubanOutsourceInvoice.query.filter_by(douban_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/douban_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, str(year)))
Exemplo n.º 24
0
def index(type):
    page = int(request.values.get('p', 1))
    industry = request.values.get('industry', '')
    medium = int(request.values.get('medium', 0))
    info = request.values.get('info', '')
    cases = list(Case.query.filter_by(type=type))
    if medium:
        cases = [case for case in cases if medium in case.mediums_id]
    if info:
        cases = [case for case in cases if info in case.info]
    if industry:
        cases = [case for case in cases if industry == case.industry]
    paginator = Paginator(cases, 50)
    try:
        cases = paginator.page(page)
    except:
        cases = paginator.page(paginator.num_pages)
    return tpl('/mediums/planning/index.html', title=CASE_TYPE_CN[int(type)],
               mediums=Medium.all(), medium=medium, cases=cases, type=type,
               info=info, params="&info=%s&medium=%s&industry=%s" % (
                   info, str(medium), industry), INDUSTRY=INDUSTRY,
               page=page, tags=Tag.all(), industry=industry)
Exemplo n.º 25
0
def underling():
    user_id = int(request.values.get('user_id', 0))
    page = int(request.values.get('p', 1))
    status = int(request.values.get('status', 0))
    start = request.values.get('start', '')
    end = request.values.get('end', '')

    if g.user.is_super_leader():
        outs = [k for k in Out.all() if k.status in [
            OUT_STATUS_APPLY, OUT_STATUS_PASS, OUT_STATUS_MEETED, OUT_STATUS_MEETED_NOT_PASS]]
        under_users = [{'uid': k.id, 'name': k.name} for k in User.all()]
    else:
        under_users = _get_all_under_users(g.user.id)
        if user_id:
            underling_user_ids = [user_id]
        else:
            underling_user_ids = list(set([k['uid'] for k in under_users]))
        outs = [k for k in Out.all() if k.creator.id in underling_user_ids and k.status in [
            OUT_STATUS_APPLY, OUT_STATUS_PASS, OUT_STATUS_MEETED, OUT_STATUS_MEETED_NOT_PASS]]

    if start and end:
        start_time = datetime.datetime.strptime(start, "%Y-%m-%d %H:%M")
        end_time = datetime.datetime.strptime(end, "%Y-%m-%d %H:%M")
        outs = [k for k in outs if k.start_time >=
                start_time and k.start_time < end_time]
    if status:
        outs = [k for k in outs if k.status == status]
    outs = sorted(outs, key=lambda x: x.start_time, reverse=True)
    paginator = Paginator(outs, 50)
    try:
        outs = paginator.page(page)
    except:
        outs = paginator.page(paginator.num_pages)
    return tpl('/account/out/outs.html', outs=outs, user_id=user_id, start=start,
               title=u'下属的外出报备列表', under_users=under_users, status=status,
               params="&user_id=%s&start=%s&end=%s&status=%s" % (
                   user_id, start, end, status),
               end=end, page=page)
Exemplo n.º 26
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)))
Exemplo n.º 27
0
def display_orders(orders, template, title, operaters):
    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'))
    status = request.args.get('status', '')
    page = int(request.args.get('p', 1))
    year = int(request.values.get('year', datetime.datetime.now().year))

    if g.user.team.type == TEAM_TYPE_LEADER:
        status = 'apply'
        location_id = g.user.team.location

    # Oscar的查看内容
    if int(g.user.id) == 16:
        status = 'apply_upper'
        location_id = TEAM_LOCATION_HUANAN

    if isinstance(location_id, list):
        orders = [o for o in orders if len(
            set(location_id) & set(o.locations)) > 0]
    elif 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 status_id >= 0:
        orders = [o for o in orders if o.contract_status == status_id]
    if search_info != '':
        orders = [
            o for o in orders if search_info.lower() in o.search_info.lower()]

    if status == 'apply':
        orders = [o for o in orders if o.get_outsources_by_status(1)]
    if status == 'apply_upper':
        orders = [o for o in orders if o.get_outsources_by_status(5)]
    if status == 'pass':
        orders = [o for o in orders if o.get_outsources_by_status(2)]
    if status == 'money':
        orders = [o for o in orders if o.get_outsources_by_status(3)]
    if status == 'pay':
        orders = [o for o in orders if o.get_outsources_by_status(4)]

    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(template, title=title, orders=orders, year=year,
               locations=select_locations, location_id=location_id,
               statuses=select_statuses, status_id=status_id,
               orderby=orderby or 'create_time', status=status,
               search_info=search_info, page=page, operaters=operaters,
               params='&orderby=%s&searchinfo=%s&selected_location=%s&selected_status=%s&year=%s' %
                      (orderby or 'create_time', search_info, location_id, status_id, year))
Exemplo n.º 28
0
def index(mtype):
    page = int(request.values.get('p', 1))
    medium_id = int(request.values.get('medium_id', 0))
    reg_count = request.values.get('reg_count', '') or 0
    active_count = request.values.get('active_count', '') or 0
    pv_count = request.values.get('pv_count', '') or 0
    time_count = request.values.get('time_count', '') or 0
    location = request.values.get('location', '')
    now_year_count = request.values.get('now_year_count', '') or 0
    filters = {}
    if medium_id:
        filters['medium_id'] = medium_id
    if mtype == 'pc':
        if filters:
            products = MediumProductPC.query.filter_by(**filters)
        else:
            products = MediumProductPC.all()
        if reg_count:
            products = products.filter(
                MediumProductPC.register_count >= int(reg_count))
        if active_count:
            products = products.filter(
                MediumProductPC.active_count_by_day >= int(active_count))
        if pv_count:
            products = products.filter(
                MediumProductPC.pv_by_day >= int(pv_count))
        if time_count:
            products = products.filter(
                MediumProductPC.access_time >= int(time_count))
    elif mtype == 'app':
        if filters:
            products = MediumProductApp.query.filter_by(**filters)
        else:
            products = MediumProductApp.all()
        if reg_count:
            products = products.filter(
                MediumProductApp.register_count >= int(reg_count))
        if active_count:
            products = products.filter(
                MediumProductApp.active_count_by_day >= int(active_count))
        if pv_count:
            products = products.filter(
                MediumProductApp.pv_by_day >= int(pv_count))
        if time_count:
            products = products.filter(
                MediumProductApp.access_time >= int(time_count))
    elif mtype == 'down':
        if location:
            filters['location'] = location
        if filters:
            products = MediumProductDown.query.filter_by(**filters)
        else:
            products = MediumProductDown.all()
        if now_year_count:
            products = products.filter(
                MediumProductDown.now_year_count >= int(now_year_count))
    paginator = Paginator(list(products), 50)
    try:
        products = paginator.page(page)
    except:
        products = paginator.page(paginator.num_pages)
    mediums = Medium.all()
    params = "&medium_id=%s" % (str(medium_id))
    if mtype in ['pc', 'app']:
        params += "&reg_count=%s&active_count=%s&pv_count=%s&time_count=%s" % (
            reg_count or '', active_count or '', pv_count or '', time_count
            or '')
    else:
        params += "&location=%s&now_year_count=%s" % (location, now_year_count
                                                      or '')
    return tpl('/mediums/product/index.html',
               mtype=mtype,
               products=products,
               mediums=mediums,
               medium_id=medium_id,
               params=params,
               reg_count=reg_count or '',
               active_count=active_count or '',
               pv_count=pv_count or '',
               time_count=time_count or '',
               location=location,
               now_year_count=now_year_count or '',
               MEDIUM_RESOURCE_TYPE_INT=MEDIUM_RESOURCE_TYPE_INT)