Exemple #1
0
def new_invoice(order_id):
    order = searchAdClientOrder.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("searchAd_saler_client_order_invoice.index", order_id=order_id))
        invoice = searchAdInvoice.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,
                              invoice_status=INVOICE_STATUS_NORMAL,
                              creator=g.user,
                              invoice_num=" ",
                              back_time=form.back_time.data)
        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("searchAd_saler_client_order_invoice.index", order_id=order_id))
Exemple #2
0
def new_invoice(order_id):
    order = searchAdClientOrder.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("searchAd_finance_client_order_invoice.info", order_id=order_id))
        invoice = searchAdInvoice.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)
        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("searchAd_finance_client_order_invoice.info", order_id=order.id))
Exemple #3
0
def info(order_id):
    if not g.user.is_finance():
        abort(404)
    order = searchAdRebateOrder.get(order_id)
    if not order:
        abort(404)
    invoices_data = {
        'PASS': [{'invoice': x, 'form': get_invoice_from(x)} for x in
                 searchAdInvoice.query.filter_by(rebate_order=order) if x.invoice_status == INVOICE_STATUS_PASS],
        'APPLYPASS': [{'invoice': x, 'form': get_invoice_from(x)} for x in
                      searchAdInvoice.query.filter_by(rebate_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.rebate_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/searchAd_rebate_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)
Exemple #4
0
def update_invoice(invoice_id):
    invoice = searchAdInvoice.get(invoice_id)
    if not invoice:
        abort(404)
    form = InvoiceForm(request.form)
    form.client_order.choices = [(invoice.client_order.id,
                                  invoice.client_order.client.name)]
    if request.method == 'POST' and form.validate():
        back_time = request.values.get('back_time', datetime.date.today())
        if not form.tax_id.data:
            flash(u"修改发票失败,公司名称不能为空", 'danger')
        elif not form.detail.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.invoice_type = form.invoice_type.data,
            invoice.creator = g.user
            invoice.create_time = datetime.date.today()
            invoice.back_time = back_time
            invoice.save()
            flash(u'修改发票(%s)成功!' % form.company.data, 'success')
            invoice.client_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("searchAd_saler_client_order_invoice.index",
                order_id=invoice.client_order.id))
Exemple #5
0
def get_invoice_from(invoice):
    invoice_form = InvoiceForm()
    invoice_form.rebate_order.choices = [
        (invoice.rebate_order.id, invoice.rebate_order.client.name)]
    invoice_form.company.data = invoice.company
    invoice_form.bank.data = invoice.bank
    invoice_form.bank_id.data = invoice.bank_id
    invoice_form.address.data = invoice.address
    invoice_form.phone.data = invoice.phone
    invoice_form.tax_id.data = invoice.tax_id
    invoice_form.money.data = invoice.money
    invoice_form.detail.data = invoice.detail
    return invoice_form
Exemple #6
0
def update_invoice(invoice_id):
    invoice = searchAdInvoice.get(invoice_id)
    if not invoice:
        abort(404)
    form = InvoiceForm(request.form)
    form.client_order.choices = [
        (invoice.client_order.id, invoice.client_order.client.name)]
    if request.method == 'POST' and form.validate():
        back_time = request.values.get('back_time', datetime.date.today())
        if not form.tax_id.data:
            flash(u"修改发票失败,公司名称不能为空", 'danger')
        elif not form.detail.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.invoice_type = form.invoice_type.data,
            invoice.creator = g.user
            invoice.create_time = datetime.date.today()
            invoice.back_time = back_time
            invoice.save()
            flash(u'修改发票(%s)成功!' % form.company.data, 'success')
            invoice.client_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("searchAd_saler_client_order_invoice.index", order_id=invoice.client_order.id))
Exemple #7
0
def get_invoice_from(invoice):
    invoice_form = InvoiceForm()
    invoice_form.rebate_order.choices = [(invoice.rebate_order.id,
                                          invoice.rebate_order.client.name)]
    invoice_form.company.data = invoice.company
    invoice_form.bank.data = invoice.bank
    invoice_form.bank_id.data = invoice.bank_id
    invoice_form.address.data = invoice.address
    invoice_form.phone.data = invoice.phone
    invoice_form.tax_id.data = invoice.tax_id
    invoice_form.money.data = invoice.money
    invoice_form.detail.data = invoice.detail
    invoice_form.invoice_type.data = invoice.invoice_type
    if invoice.back_time:
        invoice_form.back_time.data = invoice.back_time.strftime('%Y-%m-%d')
    else:
        invoice_form.back_time.data = ''
    return invoice_form
Exemple #8
0
def index(order_id):
    order = searchAdClientOrder.get(order_id)
    if not order:
        abort(404)
    invoices = searchAdInvoice.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.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('/saler/searchAd_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)