示例#1
0
def apply_invoice(invoice_id):
    invoice = MediumInvoice.get(invoice_id)
    if not invoice:
        abort(404)
    invoices_ids = request.values.getlist('invoices')
    invoices = MediumInvoice.gets(invoices_ids)
    if not invoices:
        abort(403)
    emails = request.values.getlist('email')
    msg = request.values.get('msg', '')
    action = int(request.values.get('action', 0))
    to_users = [g.user] + User.medias() + User.media_leaders() + \
        User.super_leaders()
    to_emails = list(set(emails + [x.email for x in to_users]))

    send_type = "saler"
    if action == 2:
        invoice_status = MEDIUM_INVOICE_STATUS_APPLY
        action_msg = u'打款发票开具申请'
    if action != 10:
        for invoice in invoices:
            invoice.invoice_status = invoice_status
            invoice.save()
            flash(
                u' %s 打款发票申请,发票金额: %s, 发票号: %s  %s ' %
                (invoice.company, invoice.money, invoice.invoice_num,
                 action_msg), 'success')
            invoice.client_order.add_comment(
                g.user,
                u"%s,%s" %
                (action_msg, u'打款发票内容: %s; 发票金额: %s元; 发票号: %s' %
                 (invoice.detail, str(invoice.money), invoice.invoice_num)),
                msg_channel=3)
    else:
        action_msg = u'消息提醒'

    apply_context = {
        "sender": g.user,
        "to_other": emails,
        "title": action_msg,
        "to": to_emails,
        "action_msg": action_msg,
        "msg": msg,
        "order": invoice.client_order,
        "send_type": send_type,
        "invoices": invoices
    }
    medium_invoice_apply_signal.send(current_app._get_current_object(),
                                     apply_context=apply_context)
    flash(
        u'[%s 打款发票开具申请] 已发送邮件给 %s ' %
        (invoice.client_order, ', '.join(to_emails)), 'info')
    return redirect(
        url_for("saler_client_order_medium_invoice.index",
                order_id=invoice.client_order.id))
示例#2
0
def medium_invoice():
    if not (g.user.is_media() or g.user.is_media_leader() or g.user.is_contract()):
        abort(404)
    now_date = datetime.datetime.now()
    info = request.values.get('info', '').strip()
    location = int(request.values.get('location', 0))
    year = request.values.get('year', now_date.strftime('%Y'))
    month = request.values.get('month', now_date.strftime('%m'))

    if month != '00':
        search_date = datetime.datetime.strptime(
            str(year) + '-' + str(month), '%Y-%m')
        end_search_date = (
            search_date + datetime.timedelta(days=(search_date.max.day - search_date.day) + 1)).replace(day=1)
        orders = [k for k in MediumInvoice.query.filter(MediumInvoice.add_time >= search_date,
                                                        MediumInvoice.add_time < end_search_date)
                  if k.client_order.status == 1]
    else:
        orders = [k for k in MediumInvoice.all() if k.add_time.year == int(
            year) and k.client_order.status == 1]
    if location != 0:
        orders = [k for k in orders if location in k.client_order.locations]
    if info:
        orders = [k for k in orders if info in k.client_order.search_info]
    orders = sorted(list(orders), key=lambda x: x.add_time, reverse=False)
    if request.values.get('action', '') == 'download':
        response = write_order_excel(list(orders), 'medium_invoice')
        return response
    return tpl('/media/client_order/data_query/index.html',
               orders=orders, location=location,
               year=year, month=month, info=info,
               title=u"已收媒体发票金额", t_type='medium_invoice')
示例#3
0
def new_invoice_pay(invoice_id):
    money = float(request.values.get('money', 0))
    pay_time = request.values.get('pay_time', '')
    detail = request.values.get('detail', '')
    bank = request.values.get('bank', '')
    bank_num = request.values.get('bank_num', '')
    company = request.values.get('company', '')
    mi = MediumInvoice.get(invoice_id)
    # if mi.pay_invoice_money + money > mi.money:
    #     flash(u'付款金额大于发票金额,请重新填写!', 'danger')
    # return redirect(url_for('saler_client_order_medium_invoice.invoice',
    # invoice_id=invoice_id))
    pay = MediumInvoicePay.add(money=money,
                               medium_invoice=mi,
                               pay_time=pay_time,
                               detail=detail,
                               bank=bank,
                               bank_num=bank_num,
                               company=company)
    pay.save()
    flash(u'新建打款信息成功!', 'success')
    mi.client_order.add_comment(g.user, u"新建打款信息\n\n发票号:%s\n\n打款金额:%s元\n\n\
                                        打款时间:%s\n\n公司名称:%s\n\n开户行:%s\n\n银行账号:%s" %
                                (pay.medium_invoice.invoice_num, str(money),
                                 pay_time, company, bank, bank_num),
                                msg_channel=3)
    return redirect(url_for('saler_client_order_medium_invoice.invoice', invoice_id=invoice_id))
示例#4
0
def new_invoice_pay(invoice_id):
    if not g.user.is_finance():
        abort(404)
    invoice = MediumInvoice.get(invoice_id)
    if not invoice:
        abort(404)
    money = float(request.values.get('money', 0))
    pay_time = request.values.get('pay_time', '')
    detail = request.values.get('detail', '')
    bank = request.values.get('bank', '')
    bank_num = request.values.get('bank_num', '')
    company = request.values.get('company', '')
    pay = MediumInvoicePay.add(money=money,
                               pay_status=0,
                               medium_invoice=invoice,
                               pay_time=pay_time,
                               detail=detail,
                               bank=bank,
                               bank_num=bank_num,
                               company=company)
    pay.save()
    flash(u'新建付款信息成功!', 'success')
    invoice.client_order.add_comment(g.user, u"财务添加打款信息\n\n发票号:%s\n\n打款金额:%s元\n\n\
                                        打款时间:%s\n\n公司名称:%s\n\n开户行:%s\n\n银行账号:%s" %
                                     (invoice.invoice_num, str(money),
                                      pay_time, company, bank, bank_num),
                                     msg_channel=3)
    return redirect(url_for("finance_client_order_medium_pay.pay_info", invoice_id=invoice.id))
示例#5
0
def new_invoice_pay(invoice_id):
    money = float(request.values.get('money', 0))
    pay_time = request.values.get('pay_time', '')
    detail = request.values.get('detail', '')
    bank = request.values.get('bank', '')
    bank_num = request.values.get('bank_num', '')
    company = request.values.get('company', '')
    mi = MediumInvoice.get(invoice_id)
    # if mi.pay_invoice_money + money > mi.money:
    #     flash(u'付款金额大于发票金额,请重新填写!', 'danger')
    # return redirect(url_for('saler_client_order_medium_invoice.invoice',
    # invoice_id=invoice_id))
    pay = MediumInvoicePay.add(money=money,
                               medium_invoice=mi,
                               pay_time=pay_time,
                               detail=detail,
                               bank=bank,
                               bank_num=bank_num,
                               company=company)
    pay.save()
    flash(u'新建打款信息成功!', 'success')
    mi.client_order.add_comment(g.user,
                                u"新建打款信息\n\n发票号:%s\n\n打款金额:%s元\n\n\
                                        打款时间:%s\n\n公司名称:%s\n\n开户行:%s\n\n银行账号:%s"
                                % (pay.medium_invoice.invoice_num, str(money),
                                   pay_time, company, bank, bank_num),
                                msg_channel=3)
    return redirect(
        url_for('saler_client_order_medium_invoice.invoice',
                invoice_id=invoice_id))
示例#6
0
def invoice(invoice_id):
    invoice = MediumInvoice.get(invoice_id)
    if not invoice:
        abort(404)
    form = get_invoice_from(invoice)
    reminder_emails = [(u.name, u.email) for u in User.all_active()]
    return tpl('/saler/client_order/medium/invoice.html', form=form, invoice=invoice, reminder_emails=reminder_emails,
               INVOICE_TYPE_CN=INVOICE_TYPE_CN, MEDIUM_INVOICE_STATUS_CN=MEDIUM_INVOICE_STATUS_CN)
示例#7
0
def apply_invoice(invoice_id):
    invoice = MediumInvoice.get(invoice_id)
    if not invoice:
        abort(404)
    invoices_ids = request.values.getlist('invoices')
    invoices = MediumInvoice.gets(invoices_ids)
    if not invoices:
        abort(403)
    emails = request.values.getlist('email')
    msg = request.values.get('msg', '')
    action = int(request.values.get('action', 0))
    to_users = [g.user] + User.medias() + User.media_leaders() + \
        User.super_leaders()
    to_emails = list(set(emails + [x.email for x in to_users]))

    send_type = "saler"
    if action == 2:
        invoice_status = MEDIUM_INVOICE_STATUS_APPLY
        action_msg = u'打款发票开具申请'
    if action != 10:
        for invoice in invoices:
            invoice.invoice_status = invoice_status
            invoice.save()
            flash(u' %s 打款发票申请,发票金额: %s, 发票号: %s  %s ' %
                  (invoice.company, invoice.money, invoice.invoice_num, action_msg), 'success')
            invoice.client_order.add_comment(g.user, u"%s,%s" % (
                action_msg, u'打款发票内容: %s; 发票金额: %s元; 发票号: %s' %
                (invoice.detail, str(invoice.money), invoice.invoice_num)), msg_channel=3)
    else:
        action_msg = u'消息提醒'

    apply_context = {"sender": g.user,
                     "to_other": emails,
                     "title": action_msg,
                     "to": to_emails,
                     "action_msg": action_msg,
                     "msg": msg,
                     "order": invoice.client_order,
                     "send_type": send_type,
                     "invoices": invoices}
    medium_invoice_apply_signal.send(
        current_app._get_current_object(), apply_context=apply_context)
    flash(u'[%s 打款发票开具申请] 已发送邮件给 %s ' %
          (invoice.client_order, ', '.join(to_emails)), 'info')
    return redirect(url_for("saler_client_order_medium_invoice.index", order_id=invoice.client_order.id))
示例#8
0
def pay_info(invoice_id):
    if not g.user.is_finance():
        abort(404)
    invoice = MediumInvoice.get(invoice_id)
    form = get_invoice_from(invoice)
    reminder_emails = [(u.name, u.email) for u in User.all_active()]
    return tpl('/finance/client_order/medium_pay/pay_info.html',
               form=form, invoice=invoice, reminder_emails=reminder_emails,
               INVOICE_TYPE_CN=INVOICE_TYPE_CN)
示例#9
0
def invoice(invoice_id):
    invoice = MediumInvoice.get(invoice_id)
    if not invoice:
        abort(404)
    form = get_invoice_from(invoice)
    reminder_emails = [(u.name, u.email) for u in User.all_active()]
    return tpl('/saler/client_order/medium/invoice.html',
               form=form,
               invoice=invoice,
               reminder_emails=reminder_emails,
               INVOICE_TYPE_CN=INVOICE_TYPE_CN,
               MEDIUM_INVOICE_STATUS_CN=MEDIUM_INVOICE_STATUS_CN)
示例#10
0
def invoice_pay_delete(invoice_id, pid):
    if not g.user.is_finance():
        abort(404)
    invoice = MediumInvoice.get(invoice_id)
    invoice_pay = MediumInvoicePay.get(pid)
    flash(u'删除成功', 'success')
    invoice.client_order.add_comment(g.user, u"财务删除打款信息\n\n发票号:%s\n\n打款金额:%s元\n\n\
                                        打款时间:%s\n\n公司名称:%s\n\n开户行:%s\n\n银行账号:%s" %
                                     (invoice.invoice_num, str(invoice_pay.money),
                                      invoice_pay.pay_time, invoice_pay.company,
                                      invoice_pay.bank, invoice_pay.bank_num),
                                     msg_channel=3)
    invoice_pay.delete()
    return redirect(url_for("finance_client_order_medium_pay.pay_info", invoice_id=invoice_id))
示例#11
0
def invoice_pay_num(invoice_id):
    if not g.user.is_finance():
        abort(404)
    invoice = MediumInvoice.get(invoice_id)
    if not invoice:
        abort(404)
    pay_money = request.form.get('pay_money', 0)
    invoice.pay_money = pay_money
    invoice.save()
    flash(u'保存成功!', 'success')
    invoice.client_order.add_comment(g.user,
                                     u"更新了付款金额:\n\r%s" % invoice.pay_money,
                                     msg_channel=3)
    return redirect(url_for("finance_client_order_medium_pay.info", order_id=invoice.client_order.id))
示例#12
0
def update_invoice(
        invoice_id,
        redirect_endpoint='saler_client_order_medium_invoice.index'):
    invoice = MediumInvoice.get(invoice_id)
    if not invoice:
        abort(404)
    form = MediumInvoiceForm(request.form)
    form.client_order.choices = [(invoice.client_order.id,
                                  invoice.client_order.name)]
    form.medium.choices = [(invoice.medium.id, invoice.medium.name)]
    form.bool_invoice.bool_invoice = MEDIUM_INVOICE_BOOL_INVOICE_CN.items()
    # order = invoice.client_order
    # 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':
        if not form.invoice_num.data:
            flash(u"修改打款发票失败,发票号不能为空", 'danger')
        elif not form.money.data:
            flash(u"修改打款发票失败,发票金额不能为空", 'danger')
        else:
            invoice.company = form.company.data,
            invoice.tax_id = form.tax_id.data,
            invoice.address = form.address.data,
            invoice.phone = form.phone.data,
            invoice.bank_id = form.bank_id.data,
            invoice.bank = form.bank.data,
            invoice.detail = form.detail.data,
            invoice.money = form.money.data,
            invoice.pay_money = form.money.data,
            invoice.invoice_type = form.invoice_type.data,
            invoice.invoice_num = form.invoice_num.data,
            invoice.creator = g.user
            invoice.create_time = datetime.date.today()
            invoice.add_time = form.add_time.data
            invoice.bool_invoice = form.bool_invoice.data
            invoice.save()
            flash(u'修改打款发票(%s)成功!' % form.company.data, 'success')
            invoice.client_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=invoice.client_order.id))
示例#13
0
def invoice_pass(invoice_id):
    if not g.user.is_finance():
        abort(404)
    invoice = MediumInvoice.get(invoice_id)
    if not invoice:
        abort(404)
    invoices_ids = request.values.getlist('invoices')
    invoices_pay = MediumInvoicePay.gets(invoices_ids)
    if not invoices_pay:
        abort(403)
    emails = request.values.getlist('email')
    msg = request.values.get('msg', '')
    action = int(request.values.get('action', 0))

    to_users = [g.user] + \
        User.medias() + User.media_leaders() + User.super_leaders()
    to_emails = list(set(emails + [x.email for x in to_users]))

    if action != 10:
        invoice_status = MEDIUM_INVOICE_STATUS_PASS
        action_msg = u'媒体款项已打款'
        for invoice_pay in invoices_pay:
            invoice_pay.pay_status = invoice_status
            invoice_pay.save()
            flash(u'媒体订单款已打,名称:%s, 付款金额%s' % (
                invoice_pay.medium_invoice.client_order.name +
                '-' + invoice_pay.medium_invoice.medium.name,
                str(invoice_pay.money)), 'success')
            invoice_pay.medium_invoice.client_order.add_comment(
                g.user, u'媒体订单款已付款,名称%s, 付款金额%s ' % (
                    invoice_pay.medium_invoice.client_order.name +
                        '-' + invoice_pay.medium_invoice.medium.name,
                    str(invoice_pay.money)),
                msg_channel=3)
    else:
        action_msg = u'消息提醒'
    context = {"to_users": to_users,
               "action": 0,
               "action_msg": action_msg,
               "info": msg,
               "invoice": invoice,
               "order": invoice.client_order,
               "send_type": 'end',
               "invoice_pays": invoices_pay}
    medium_invoice_apply_signal.send(
        current_app._get_current_object(), context=context)
    flash(u'已发送邮件给 %s ' % (', '.join(to_emails)), 'info')
    return redirect(url_for("finance_client_order_medium_pay.pay_info", invoice_id=invoice_id))
示例#14
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))
示例#15
0
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))
示例#16
0
def update_invoice(invoice_id, redirect_endpoint='saler_client_order_medium_invoice.index'):
    invoice = MediumInvoice.get(invoice_id)
    if not invoice:
        abort(404)
    form = MediumInvoiceForm(request.form)
    form.client_order.choices = [
        (invoice.client_order.id, invoice.client_order.name)]
    form.medium.choices = [(invoice.medium.id, invoice.medium.name)]
    form.bool_invoice.bool_invoice = MEDIUM_INVOICE_BOOL_INVOICE_CN.items()
    # order = invoice.client_order
    # 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':
        if not form.invoice_num.data:
            flash(u"修改打款发票失败,发票号不能为空", 'danger')
        elif not form.money.data:
            flash(u"修改打款发票失败,发票金额不能为空", 'danger')
        else:
            invoice.company = form.company.data,
            invoice.tax_id = form.tax_id.data,
            invoice.address = form.address.data,
            invoice.phone = form.phone.data,
            invoice.bank_id = form.bank_id.data,
            invoice.bank = form.bank.data,
            invoice.detail = form.detail.data,
            invoice.money = form.money.data,
            invoice.pay_money = form.money.data,
            invoice.invoice_type = form.invoice_type.data,
            invoice.invoice_num = form.invoice_num.data,
            invoice.creator = g.user
            invoice.create_time = datetime.date.today()
            invoice.add_time = form.add_time.data
            invoice.bool_invoice = form.bool_invoice.data
            invoice.save()
            flash(u'修改打款发票(%s)成功!' % form.company.data, 'success')
            invoice.client_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=invoice.client_order.id))
示例#17
0
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))
示例#18
0
文件: order.py 项目: cash2one/braavos
def cost():
    client_invoices = list(Invoice.all())
    medium_invoices = list(MediumInvoice.all())
    medium_invoice_pays = list(MediumInvoicePay.all())
    medium_invoice_rebate_invoice = list(MediumRebateInvoice.all())
    agent_invoices = list(AgentInvoice.all())
    agent_invoice_pays = list(AgentInvoicePay.all())
    back_moneys = list(BackMoney.all())
    back_money_rebates = list(BackInvoiceRebate.all())

    now_date = datetime.datetime.now()
    info = request.values.get('info', '').strip()
    location = int(request.values.get('location', 0))
    year = request.values.get('year', now_date.strftime('%Y'))
    month = request.values.get('month', now_date.strftime('%m'))

    if month != '00':
        search_date = datetime.datetime.strptime(
            str(year) + '-' + str(month), '%Y-%m')
        orders = set([
            k.client_order for k in ClientOrderExecutiveReport.query.filter_by(
                month_day=search_date) if k.status == 1
        ])
    else:
        orders = [
            k for k in ClientOrder.all() if k.client_start.year == int(year)
            or k.client_end.year == int(year)
        ]
    if location != 0:
        orders = [k for k in orders if location in k.locations]
    if info:
        orders = [k for k in orders if info in k.search_info]

    orders = sorted(list(orders), key=lambda x: x.client_start, reverse=False)
    for order in orders:
        order.pass_invoice_sum = sum([
            k.money for k in client_invoices
            if k.invoice_status == 0 and k.client_order == order
        ])
        order.back_money_sum = sum(
            [k.money for k in back_moneys if k.client_order == order])
        order.back_money_rebate_sum = sum(
            [k.money for k in back_money_rebates if k.client_order == order])
        order.agent_invoice_sum = sum(
            [k.money for k in agent_invoices if k.client_order == order])

        agent_invoice_pay_sum = 0.0
        invoices = [k for k in agent_invoices if k.client_order == order]
        for invoice in invoices:
            agent_invoice_pay_sum += sum([
                k.money for k in agent_invoice_pays
                if k.pay_status == 0 and k.agent_invoice == invoice
            ])
        order.agent_invoice_pay_sum = agent_invoice_pay_sum

        order.medium_invoice_sum = sum(
            [k.money for k in medium_invoices if k.client_order == order])
        invoices = [k for k in medium_invoices if k.client_order == order]
        order.medium_invoice_pay_sum = sum([
            k.money for k in medium_invoice_pays
            if k.pay_status == 0 and k.medium_invoice in invoices
        ])
        order.medium_invoice_rebate_invoice_sum = sum([
            k.money for k in medium_invoice_rebate_invoice
            if k.client_order == order and k.invoice_status == 0
        ])
        for m in order.medium_orders:
            m.medium_invoice_sum = sum([
                k.money for k in medium_invoices
                if k.client_order == order and k.medium == m.medium
            ])
            m_invoices = [
                k for k in medium_invoices
                if k.client_order == order and k.medium == m.medium
            ]
            m.medium_invoice_pay_sum = sum([
                k.money for k in medium_invoice_pays
                if k.pay_status == 0 and k.medium_invoice in m_invoices
            ])
            m.medium_invoice_rebate_invoice_sum = sum([
                k.money for k in medium_invoice_rebate_invoice
                if k.client_order == order and k.invoice_status == 0
                and k.medium == m.medium
            ])
    if request.values.get('action', '') == 'download':
        response = write_order_excel(list(orders))
        return response
    return tpl('cost.html',
               orders=orders,
               location=location,
               year=year,
               month=month,
               info=info)
示例#19
0
def apply_pay(invoice_id):
    medium_invoice = MediumInvoice.get(invoice_id)
    if not medium_invoice:
        abort(404)
    invoice_pay_ids = request.values.getlist('invoices')
    invoice_pays = MediumInvoicePay.gets(invoice_pay_ids)
    if not invoice_pays:
        abort(403)
    emails = request.values.getlist('email')
    msg = request.values.get('msg', '')
    action = int(request.values.get('action', 0))
    to_users = [g.user] + User.medias() + User.media_leaders() + \
        User.super_leaders()
    if action == 2:
        action_msg = u'媒体打款申请'
        for invoice in invoice_pays:
            invoice.pay_status = MEDIUM_INVOICE_STATUS_APPLY
            invoice.save()
            flash(
                u'[%s媒体申请打款,打款金额: %s, 发票号: %s]  %s ' %
                (invoice.medium_invoice.company, invoice.money,
                 invoice.medium_invoice.invoice_num, invoice.detail),
                'success')

            invoice.medium_invoice.client_order.add_comment(
                g.user,
                u"%s,%s" %
                (action_msg, u' %s媒体申请打款,打款金额: %s, 发票号: %s  %s ' %
                 (invoice.medium_invoice.company, invoice.money,
                  invoice.medium_invoice.invoice_num, invoice.detail)),
                msg_channel=3)
        send_type = "saler"
    elif action == 3:
        action_msg = u'媒体打款申请'
        for invoice in invoice_pays:
            invoice.pay_status = MEDIUM_INVOICE_STATUS_F_AGREE
            invoice.save()
            flash(
                u'[副总裁同意%s媒体打款,打款金额: %s, 发票号: %s]  %s ' %
                (invoice.medium_invoice.company, invoice.money,
                 invoice.medium_invoice.invoice_num, invoice.detail),
                'success')

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

            invoice.medium_invoice.client_order.add_comment(
                g.user,
                u"%s,%s" %
                (action_msg, u' %s媒体同意打款,打款金额: %s, 发票号: %s  %s ' %
                 (invoice.medium_invoice.company, invoice.money,
                  invoice.medium_invoice.invoice_num, invoice.detail)),
                msg_channel=3)
        send_type = "finance"
    else:
        action_msg = u'消息提醒'

    context = {
        "to_users": to_users,
        "action": action,
        "to_other": emails,
        "action_msg": action_msg,
        "info": msg,
        "invoice": medium_invoice,
        "order": medium_invoice.client_order,
        "send_type": send_type,
        "invoice_pays": invoice_pays
    }
    medium_invoice_apply_signal.send(current_app._get_current_object(),
                                     context=context)
    return redirect(
        url_for('saler_client_order_medium_invoice.invoice',
                invoice_id=invoice_id))
示例#20
0
def cost():
    client_invoices = list(Invoice.all())
    medium_invoices = list(MediumInvoice.all())
    medium_invoice_pays = list(MediumInvoicePay.all())
    medium_invoice_rebate_invoice = list(MediumRebateInvoice.all())
    agent_invoices = list(AgentInvoice.all())
    agent_invoice_pays = list(AgentInvoicePay.all())
    back_moneys = list(BackMoney.all())
    back_money_rebates = list(BackInvoiceRebate.all())

    now_date = datetime.datetime.now()
    info = request.values.get('info', '').strip()
    location = int(request.values.get('location', 0))
    year = request.values.get('year', now_date.strftime('%Y'))
    month = request.values.get('month', now_date.strftime('%m'))

    if month != '00':
        search_date = datetime.datetime.strptime(
            str(year) + '-' + str(month), '%Y-%m')
        orders = set([k.client_order for k in ClientOrderExecutiveReport.query.filter_by(
            month_day=search_date) if k.status == 1])
    else:
        orders = [k for k in ClientOrder.all() if k.client_start.year == int(
            year) or k.client_end.year == int(year)]
    if location != 0:
        orders = [k for k in orders if location in k.locations]
    if info:
        orders = [k for k in orders if info in k.search_info]

    orders = sorted(list(orders), key=lambda x: x.client_start, reverse=False)
    for order in orders:
        order.pass_invoice_sum = sum(
            [k.money for k in client_invoices if k.invoice_status == 0 and k.client_order == order])
        order.back_money_sum = sum(
            [k.money for k in back_moneys if k.client_order == order])
        order.back_money_rebate_sum = sum(
            [k.money for k in back_money_rebates if k.client_order == order])
        order.agent_invoice_sum = sum(
            [k.money for k in agent_invoices if k.client_order == order])

        agent_invoice_pay_sum = 0.0
        invoices = [k for k in agent_invoices if k.client_order == order]
        for invoice in invoices:
            agent_invoice_pay_sum += sum(
                [k.money for k in agent_invoice_pays if k.pay_status == 0 and k.agent_invoice == invoice])
        order.agent_invoice_pay_sum = agent_invoice_pay_sum

        order.medium_invoice_sum = sum(
            [k.money for k in medium_invoices if k.client_order == order])
        invoices = [k for k in medium_invoices if k.client_order == order]
        order.medium_invoice_pay_sum = sum(
            [k.money for k in medium_invoice_pays if k.pay_status == 0 and k.medium_invoice in invoices])
        order.medium_invoice_rebate_invoice_sum = sum(
            [k.money for k in medium_invoice_rebate_invoice if k.client_order == order and k.invoice_status == 0])
        for m in order.medium_orders:
            m.medium_invoice_sum = sum(
                [k.money for k in medium_invoices if k.client_order == order and k.medium == m.medium])
            m_invoices = [
                k for k in medium_invoices if k.client_order == order and k.medium == m.medium]
            m.medium_invoice_pay_sum = sum(
                [k.money for k in medium_invoice_pays if k.pay_status == 0 and k.medium_invoice in m_invoices])
            m.medium_invoice_rebate_invoice_sum = sum(
                [k.money for k in medium_invoice_rebate_invoice if k.client_order == order and
                 k.invoice_status == 0 and k.medium == m.medium])
    if request.values.get('action', '') == 'download':
        response = write_order_excel(list(orders))
        return response
    return tpl('cost.html', orders=orders, location=location,
               year=year, month=month, info=info)
示例#21
0
def apply_pay(invoice_id):
    medium_invoice = MediumInvoice.get(invoice_id)
    if not medium_invoice:
        abort(404)
    invoice_pay_ids = request.values.getlist('invoices')
    invoice_pays = MediumInvoicePay.gets(invoice_pay_ids)
    if not invoice_pays:
        abort(403)
    emails = request.values.getlist('email')
    msg = request.values.get('msg', '')
    action = int(request.values.get('action', 0))
    to_users = [g.user] + User.medias() + User.media_leaders() + \
        User.super_leaders()
    if action == 2:
        action_msg = u'媒体打款申请'
        for invoice in invoice_pays:
            invoice.pay_status = MEDIUM_INVOICE_STATUS_APPLY
            invoice.save()
            flash(u'[%s媒体申请打款,打款金额: %s, 发票号: %s]  %s ' %
                  (invoice.medium_invoice.company, invoice.money,
                   invoice.medium_invoice.invoice_num, invoice.detail), 'success')

            invoice.medium_invoice.client_order.add_comment(g.user, u"%s,%s" % (
                action_msg, u' %s媒体申请打款,打款金额: %s, 发票号: %s  %s ' %
                (invoice.medium_invoice.company, invoice.money,
                    invoice.medium_invoice.invoice_num, invoice.detail)), msg_channel=3)
        send_type = "saler"
    elif action == 3:
        action_msg = u'媒体打款申请'
        for invoice in invoice_pays:
            invoice.pay_status = MEDIUM_INVOICE_STATUS_F_AGREE
            invoice.save()
            flash(u'[副总裁同意%s媒体打款,打款金额: %s, 发票号: %s]  %s ' %
                  (invoice.medium_invoice.company, invoice.money,
                   invoice.medium_invoice.invoice_num, invoice.detail), 'success')

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

            invoice.medium_invoice.client_order.add_comment(g.user, u"%s,%s" % (
                action_msg, u' %s媒体同意打款,打款金额: %s, 发票号: %s  %s ' %
                (invoice.medium_invoice.company, invoice.money,
                    invoice.medium_invoice.invoice_num, invoice.detail)), msg_channel=3)
        send_type = "finance"
    else:
        action_msg = u'消息提醒'

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