Beispiel #1
0
def index(order_id):
    order = searchAdRebateOrder.get(order_id)
    if not order:
        abort(404)
    invoices = searchAdInvoice.query.filter_by(rebate_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.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('/saler/searchAd_rebate_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)
Beispiel #2
0
def back_money(order_id):
    if not g.user.is_finance():
        abort(404)
    order = searchAdRebateOrder.get(order_id)
    if not order:
        abort(404)
    if request.method == 'POST':
        money = float(request.values.get('money', 0))
        back_time = request.values.get(
            'back_time', datetime.date.today().strftime('%Y-%m-%d'))
        back_money_status = request.values.get('back_money_status', '')
        if back_money_status != '':
            if int(back_money_status) == 0:
                order.back_money_status = int(back_money_status)
                order.save()
                flash(u'完成所有回款!', 'success')
                order.add_comment(g.user, u"完成所有回款", msg_channel=4)
        else:
            bm = searchAdBackMoney.add(
                rebate_order=order,
                money=money,
                back_time=back_time,
                create_time=datetime.date.today().strftime('%Y-%m-%d'))
            bm.save()
            flash(u'回款信息保存成功!', 'success')
            order.add_comment(
                g.user, u"更新了回款信息,回款金额: %s; 回款时间: %s;" % (money, back_time), msg_channel=4)
        return redirect(url_for("searchAd_finance_rebate_order_back_money.back_money", order_id=order.id))
    return tpl('/finance/searchAd_rebate_order/back_money/info.html', order=order)
Beispiel #3
0
def new_invoice(order_id):
    order = searchAdRebateOrder.get(order_id)
    if not order:
        abort(404)
    form = InvoiceForm(request.form)
    form.rebate_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_rebate_order_invoice.index", order_id=order_id))
        invoice = searchAdInvoice.add(rebate_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_rebate_order_invoice.index", order_id=order_id))
Beispiel #4
0
def back_invoice(order_id):
    if not (g.user.is_searchad_leader() or g.user.is_finance()):
        abort(404)
    order = searchAdRebateOrder.get(order_id)
    if not order:
        abort(404)
    if request.method == 'POST':
        money = float(request.values.get('money', 0))
        back_time = request.values.get(
            'back_time', datetime.date.today().strftime('%Y-%m-%d'))
        num = request.values.get('num', '')
        bm = searchAdBackInvoiceRebate.add(
            rebate_order=order,
            money=money,
            back_time=back_time,
            num=num,
            create_time=datetime.date.today().strftime('%Y-%m-%d'))
        bm.save()
        apply_context = {
            'order': order,
            'num': money,
            'type': 'invoice',
        }
        back_money_apply_signal.send(
            current_app._get_current_object(), apply_context=apply_context)
        flash(u'返点发票信息保存成功!', 'success')
        order.add_comment(
            g.user, u"更新了返点发票信息,发票金额: %s; 发票时间: %s; 发票号: %s;" % (money, back_time, num), msg_channel=4)
        return redirect(url_for("searchAd_saler_rebate_order_back_money.back_money", order_id=order.id))
    return tpl('/saler/searchAd_rebate_order/back_money/index.html', order=order)
Beispiel #5
0
def back_invoice(order_id):
    if not g.user.is_finance():
        abort(404)
    order = searchAdRebateOrder.get(order_id)
    if not order:
        abort(404)
    if request.method == 'POST':
        money = float(request.values.get('money', 0))
        back_time = request.values.get(
            'back_time',
            datetime.date.today().strftime('%Y-%m-%d'))
        num = request.values.get('num', '')
        bm = searchAdBackInvoiceRebate.add(
            rebate_order=order,
            money=money,
            back_time=back_time,
            num=num,
            create_time=datetime.date.today().strftime('%Y-%m-%d'))
        bm.save()
        flash(u'返点发票信息保存成功!', 'success')
        order.add_comment(g.user,
                          u"更新了返点发票信息,发票金额: %s; 发票时间: %s; 发票号: %s;" %
                          (money, back_time, num),
                          msg_channel=4)
        return redirect(
            url_for("searchAd_finance_rebate_order_back_money.back_money",
                    order_id=order.id))
    return tpl('/finance/searchAd_rebate_order/back_money/info.html',
               order=order)
Beispiel #6
0
def back_money(order_id):
    if not g.user.is_finance():
        abort(404)
    order = searchAdRebateOrder.get(order_id)
    if not order:
        abort(404)
    if request.method == 'POST':
        money = float(request.values.get('money', 0))
        back_time = request.values.get(
            'back_time',
            datetime.date.today().strftime('%Y-%m-%d'))
        back_money_status = request.values.get('back_money_status', '')
        if back_money_status != '':
            if int(back_money_status) == 0:
                order.back_money_status = int(back_money_status)
                order.save()
                flash(u'完成所有回款!', 'success')
                order.add_comment(g.user, u"完成所有回款", msg_channel=4)
        else:
            bm = searchAdBackMoney.add(
                rebate_order=order,
                money=money,
                back_time=back_time,
                create_time=datetime.date.today().strftime('%Y-%m-%d'))
            bm.save()
            flash(u'回款信息保存成功!', 'success')
            order.add_comment(g.user,
                              u"更新了回款信息,回款金额: %s; 回款时间: %s;" %
                              (money, back_time),
                              msg_channel=4)
        return redirect(
            url_for("searchAd_finance_rebate_order_back_money.back_money",
                    order_id=order.id))
    return tpl('/finance/searchAd_rebate_order/back_money/info.html',
               order=order)
Beispiel #7
0
def new_invoice(order_id):
    order = searchAdRebateOrder.get(order_id)
    if not order:
        abort(404)
    form = InvoiceForm(request.form)
    form.rebate_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_rebate_order_invoice.info", order_id=order_id))
        invoice = searchAdInvoice.add(rebate_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_rebate_order_invoice.info", order_id=order.id))
Beispiel #8
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)
Beispiel #9
0
def delete(order_id, bid):
    order = searchAdRebateOrder.get(order_id)
    bm = searchAdBackMoney.get(bid)
    order.add_comment(g.user, u"删除了回款信息,回款金额: %s; 回款时间: %s;" %
                      (bm.money, bm.back_time_cn), msg_channel=4)
    bm.delete()
    flash(u'删除成功!', 'success')
    return redirect(url_for("searchAd_finance_rebate_order_back_money.back_money", order_id=order.id))
Beispiel #10
0
def delete_invoice(order_id, bid):
    order = searchAdRebateOrder.get(order_id)
    bm = searchAdBackInvoiceRebate.get(bid)
    order.add_comment(g.user, u"删除了返点发票信息,发票金额: %s; 开票时间: %s; 发票号: %s;" % (
        bm.money, bm.back_time_cn, bm.num), msg_channel=4)
    bm.delete()
    flash(u'删除成功!', 'success')
    return redirect(url_for("searchAd_finance_rebate_order_back_money.back_money", order_id=order.id))
Beispiel #11
0
def delete_invoice(order_id, bid):
    order = searchAdRebateOrder.get(order_id)
    bm = searchAdBackInvoiceRebate.get(bid)
    order.add_comment(g.user, u"删除了返点发票信息,发票金额: %s; 开票时间: %s; 发票号: %s;" % (
        bm.money, bm.back_time_cn, bm.num), msg_channel=4)
    bm.delete()
    flash(u'删除成功!', 'success')
    return redirect(url_for("searchAd_saler_rebate_order_back_money.back_money", order_id=order.id))
Beispiel #12
0
def delete(order_id, bid):
    order = searchAdRebateOrder.get(order_id)
    bm = searchAdBackMoney.get(bid)
    order.add_comment(g.user, u"删除了回款信息,回款金额: %s; 回款时间: %s;" %
                      (bm.money, bm.back_time_cn), msg_channel=4)
    bm.delete()
    flash(u'删除成功!', 'success')
    return redirect(url_for("searchAd_saler_rebate_order_back_money.back_money", order_id=order.id))
Beispiel #13
0
def info(order_id):
    if not g.user.is_finance():
        abort(404)
    order = searchAdRebateOrder.get(order_id)
    if not order:
        abort(404)
    invoices = searchAdRebateAgentInvoice.query.filter_by(rebate_order=order)
    reminder_emails = [(u.id, u.name) for u in User.all_active()]
    new_invoice_form = AgentInvoiceForm()
    new_invoice_form.rebate_order.choices = [(order.id, order.name)]
    new_invoice_form.agent.choices = [(k.id, k.name) for k in order.agents]
    new_invoice_form.add_time.data = datetime.date.today()
    return tpl('/finance/searchAd_rebate_order/agent_pay/info.html',
               order=order, invoices=invoices, new_invoice_form=new_invoice_form,
               reminder_emails=reminder_emails, INVOICE_TYPE_CN=INVOICE_TYPE_CN)
Beispiel #14
0
def back_money(order_id):
    if not (g.user.is_searchad_leader() or g.user.is_finance()):
        abort(404)
    order = searchAdRebateOrder.get(order_id)
    if not order:
        abort(404)
    if request.method == 'POST':
        money = float(request.values.get('money', 0))
        back_time = request.values.get(
            'back_time', datetime.date.today().strftime('%Y-%m-%d'))
        back_money_status = request.values.get('back_money_status', '')
        if back_money_status != '':
            if int(back_money_status) == 0:
                order.back_money_status = int(back_money_status)
                order.save()
                flash(u'完成所有回款!', 'success')
                order.add_comment(g.user, u"完成所有回款", msg_channel=4)
                apply_context = {
                    'order': order,
                    'num': 0,
                    'type': 'end',
                }
                back_money_apply_signal.send(
                    current_app._get_current_object(), apply_context=apply_context)
        else:
            bm = searchAdBackMoney.add(
                rebate_order=order,
                money=money,
                back_time=back_time,
                create_time=datetime.date.today().strftime('%Y-%m-%d'))
            bm.save()
            apply_context = {
                'order': order,
                'num': money,
                'type': 'money',
            }
            back_money_apply_signal.send(
                current_app._get_current_object(), apply_context=apply_context)
            flash(u'回款信息保存成功!', 'success')
            order.add_comment(
                g.user, u"更新了回款信息,回款金额: %s; 回款时间: %s;" % (money, back_time), msg_channel=4)
        return redirect(url_for("searchAd_saler_rebate_order_back_money.back_money", order_id=order.id))
    return tpl('/saler/searchAd_rebate_order/back_money/index.html', order=order)
Beispiel #15
0
def back_invoice(order_id):
    if not g.user.is_finance():
        abort(404)
    order = searchAdRebateOrder.get(order_id)
    if not order:
        abort(404)
    if request.method == 'POST':
        money = float(request.values.get('money', 0))
        back_time = request.values.get(
            'back_time', datetime.date.today().strftime('%Y-%m-%d'))
        num = request.values.get('num', '')
        bm = searchAdBackInvoiceRebate.add(
            rebate_order=order,
            money=money,
            back_time=back_time,
            num=num,
            create_time=datetime.date.today().strftime('%Y-%m-%d'))
        bm.save()
        flash(u'返点发票信息保存成功!', 'success')
        order.add_comment(
            g.user, u"更新了返点发票信息,发票金额: %s; 发票时间: %s; 发票号: %s;" % (money, back_time, num), msg_channel=4)
        return redirect(url_for("searchAd_finance_rebate_order_back_money.back_money", order_id=order.id))
    return tpl('/finance/searchAd_rebate_order/back_money/info.html', order=order)
Beispiel #16
0
def rebate_order_files(order_id):
    fo = searchAdRebateOrder.get(order_id)
    return tpl("order_files.html", order=fo)
Beispiel #17
0
def index(order_id):
    order = searchAdRebateOrder.get(order_id)
    if not order:
        abort(404)
    return tpl('/saler/searchAd_rebate_order/back_money/index.html', order=order)
Beispiel #18
0
def searchAd_rebate_contract_upload():
    order_id = request.values.get('order')
    order = searchAdRebateOrder.get(order_id)
    return attachment_upload(order, FILE_TYPE_CONTRACT)
Beispiel #19
0
def searchAd_rebate_schedule_upload():
    order_id = request.values.get('order')
    order = searchAdRebateOrder.get(order_id)
    return attachment_upload(order, FILE_TYPE_SCHEDULE)
Beispiel #20
0
def rebate_order_files(order_id):
    fo = searchAdRebateOrder.get(order_id)
    return tpl("order_files.html", order=fo)
Beispiel #21
0
def finish_searchAd_rebate_order_upload():
    order_id = request.values.get('order')
    order = searchAdRebateOrder.get(order_id)
    return attachment_upload(order, FILE_TYPE_FINISH)
Beispiel #22
0
def searchAd_rebate_contract_upload():
    order_id = request.values.get('order')
    order = searchAdRebateOrder.get(order_id)
    return attachment_upload(order, FILE_TYPE_CONTRACT)
Beispiel #23
0
def searchAd_rebate_schedule_upload():
    order_id = request.values.get('order')
    order = searchAdRebateOrder.get(order_id)
    return attachment_upload(order, FILE_TYPE_SCHEDULE)
Beispiel #24
0
def finish_searchAd_rebate_order_upload():
    order_id = request.values.get('order')
    order = searchAdRebateOrder.get(order_id)
    return attachment_upload(order, FILE_TYPE_FINISH)