def info(order_id): if not g.user.is_finance(): abort(404) order = ClientOrder.get(order_id) if not order: abort(404) invoices_data = { 'PASS': [{ 'invoice': x, 'form': get_invoice_from(x) } for x in Invoice.query.filter_by(client_order=order) if x.invoice_status == INVOICE_STATUS_PASS], 'APPLYPASS': [{ 'invoice': x, 'form': get_invoice_from(x) } for x in Invoice.query.filter_by(client_order=order) if x.invoice_status == INVOICE_STATUS_APPLYPASS], } reminder_emails = [(u.name, u.email) for u in User.all_active()] new_invoice_form = InvoiceForm() new_invoice_form.client_order.choices = [(order.id, order.client.name)] new_invoice_form.company.data = order.agent.name new_invoice_form.bank.data = order.agent.bank new_invoice_form.bank_id.data = order.agent.bank_num new_invoice_form.address.data = order.agent.address new_invoice_form.phone.data = order.agent.phone_num new_invoice_form.tax_id.data = order.agent.tax_num new_invoice_form.back_time.data = datetime.date.today() return tpl('/finance/client_order/invoice/info.html', order=order, invoices_data=invoices_data, INVOICE_STATUS_CN=INVOICE_STATUS_CN, reminder_emails=reminder_emails, INVOICE_TYPE_CN=INVOICE_TYPE_CN, new_invoice_form=new_invoice_form)
def new_invoice(order_id): order = ClientOrder.get(order_id) if not order: abort(404) form = InvoiceForm(request.form) form.client_order.choices = [(order.id, order.client.name)] if request.method == 'POST' and form.validate(): if int(form.money.data) > (int(order.money) - int(order.invoice_apply_sum) - int(order.invoice_pass_sum)): flash(u"新建发票失败,您申请的发票超过了合同总额", 'danger') return redirect(url_for("finance_client_order_invoice.info", order_id=order_id)) invoice = Invoice.add(client_order=order, company=form.company.data, tax_id=form.tax_id.data, address=form.address.data, phone=form.phone.data, bank_id=form.bank_id.data, bank=form.bank.data, detail=form.detail.data, money=form.money.data, invoice_type=form.invoice_type.data, creator=g.user, invoice_status=0, invoice_num=request.values.get( 'new_invoice_num', ''), back_time=form.back_time.data, create_time=request.values.get('create_time', datetime.datetime.now().strftime('%Y-%m-%d'))) invoice.save() flash(u'开发票(%s)成功!' % form.company.data, 'success') order.add_comment(g.user, u"已开发票信息:%s" % ( u'发票内容: %s; 发票金额: %s元' % (invoice.detail, str(invoice.money))), msg_channel=1) else: for k in form.errors: flash(u"新建发票失败,%s" % (form.errors[k][0]), 'danger') return redirect(url_for("finance_client_order_invoice.info", order_id=order.id))
def info(order_id): if not g.user.is_finance(): abort(404) order = ClientOrder.get(order_id) outsources = order.get_outsources_by_status(4) apply_outsources = [] for k in [1, 2, 3, 5]: apply_outsources += order.get_outsources_by_status(k) now_date = datetime.datetime.now().strftime('%Y-%m-%d') invoices = OutsourceInvoice.query.filter_by(client_order=order) if request.method == 'POST': OutsourceInvoice.add(client_order=order, company=request.values.get('company', ''), money=float(request.values.get('money', 0)), ex_money=float(request.values.get('ex_money', 0)), invoice_num=request.values.get('invoice_num', ''), add_time=request.values.get('add_time', now_date), create_time=datetime.datetime.now(), creator=g.user) return redirect( url_for('finance_client_order_outsource_invoice.info', order_id=order.id)) return tpl('/finance/client_order/outsource/invoice_info.html', order=order, outsources=outsources, now_date=now_date, invoices=invoices, apply_outsources=apply_outsources)
def info(order_id): if not g.user.is_finance(): abort(404) order = ClientOrder.get(order_id) if not order: abort(404) invoices_data = { 'PASS': [{'invoice': x, 'form': get_invoice_from(x)} for x in Invoice.query.filter_by(client_order=order) if x.invoice_status == INVOICE_STATUS_PASS], 'APPLYPASS': [{'invoice': x, 'form': get_invoice_from(x)} for x in Invoice.query.filter_by(client_order=order) if x.invoice_status == INVOICE_STATUS_APPLYPASS], } reminder_emails = [(u.name, u.email) for u in User.all_active()] new_invoice_form = InvoiceForm() new_invoice_form.client_order.choices = [(order.id, order.client.name)] new_invoice_form.company.data = order.agent.name new_invoice_form.bank.data = order.agent.bank new_invoice_form.bank_id.data = order.agent.bank_num new_invoice_form.address.data = order.agent.address new_invoice_form.phone.data = order.agent.phone_num new_invoice_form.tax_id.data = order.agent.tax_num new_invoice_form.back_time.data = datetime.date.today() return tpl('/finance/client_order/invoice/info.html', order=order, invoices_data=invoices_data, INVOICE_STATUS_CN=INVOICE_STATUS_CN, reminder_emails=reminder_emails, INVOICE_TYPE_CN=INVOICE_TYPE_CN, new_invoice_form=new_invoice_form)
def back_invoice(order_id): if not g.user.is_finance(): abort(404) order = ClientOrder.get(order_id) if not order: abort(404) if request.method == 'POST': money = float(request.values.get('money', 0)) back_time = request.values.get( 'back_time', datetime.date.today().strftime('%Y-%m-%d')) num = request.values.get('num', '') bm = BackInvoiceRebate.add( client_order=order, money=money, back_time=back_time, num=num, create_time=datetime.date.today().strftime('%Y-%m-%d')) bm.save() flash(u'返点发票信息保存成功!', 'success') order.add_comment( g.user, u"更新了返点发票信息,发票金额: %s; 发票时间: %s; 发票号: %s;" % (money, back_time, num), msg_channel=4) apply_context = { 'order': order, 'num': money, 'type': 'invoice', } back_money_apply_signal.send( current_app._get_current_object(), apply_context=apply_context) return redirect(url_for("finance_client_order_back_money.back_money", order_id=order.id)) return tpl('/finance/client_order/back_money/info.html', order=order)
def client_orders_distribute(): if request.method == 'POST': order_id = request.values.get('order_id', '') operator = request.values.get('operater_ids', '') order = ClientOrder.get(order_id) if operator: operater_users = User.gets(operator.split(',')) to_users = operater_users for k in order.medium_orders: k.operaters = operater_users k.save() else: for k in order.medium_orders: k.operaters = [] k.save() to_users = [] if to_users: context = {"to_users": to_users + [g.user], "operater_users": operater_users, "action_msg": u'分配执行人员', "info": '', "order": order} outsource_distribute_signal.send( current_app._get_current_object(), context=context) return redirect(url_for('outsource.client_orders_distribute')) orders = [k for k in ClientOrder.query.all() if k.medium_orders and k.contract != ''] operaters = User.gets_by_team_type( TEAM_TYPE_OPERATER) + User.gets_by_team_type(TEAM_TYPE_OPERATER_LEADER) return display_orders(orders, 'client_orders_distribute.html', title=u"客户订单分配", operaters=operaters)
def update(order_id, oid): if not (g.user.is_super_leader() or g.user.is_finance() or g.user.is_operater_leader()): abort(403) order = ClientOrder.get(order_id) if not order: abort(404) company = request.values.get('company', '') money = request.values.get('money', 0) invoice = request.values.get('invoice', '') type = int(request.values.get('type', 1)) on_time = request.values.get('on_time', datetime.datetime.today()) other_cost = OtherCost.get(oid) other_cost.company = company other_cost.client_order = order other_cost.money = money other_cost.invoice = invoice other_cost.type = type other_cost.on_time = on_time other_cost.save() order.add_comment( g.user, u"更新了外包,公司:%s ; 金额:%s ; 发票:%s ; 类型:%s ; 发生时间:%s" % (other_cost.company, str(other_cost.money), other_cost.invoice, other_cost.type_cn, other_cost.on_time_cn), msg_channel=10) return redirect( url_for('saler_client_order_other_cost.index', order_id=order_id))
def back_money(order_id): if not g.user.is_finance(): abort(404) client_order = ClientOrder.get(order_id) back_moneys = MediumBackMoney.query.filter_by(client_order_id=order_id) if not client_order: abort(404) if request.method == 'POST': money = float(request.values.get('money', 0)) back_time = request.values.get( 'back_time', datetime.date.today().strftime('%Y-%m-%d')) medium_id = request.values.get('medium') order = Order.get(medium_id) MediumBackMoney.add(client_order_id=order_id, order_id=medium_id, money=money, back_time=back_time) client_order.add_comment(g.user, u"更新了媒体返点回款信息,所属媒体:%s; 回款金额: %s; 回款时间: %s;" % ( order.medium.name, money, back_time), msg_channel=8) apply_context = { 'order': client_order, 'num': money, 'type': 'money', } medium_back_money_apply_signal.send( current_app._get_current_object(), apply_context=apply_context) flash(u'回款信息保存成功!', 'success') return redirect(url_for('finance_client_order_medium_back_money.back_money', order_id=order_id)) return tpl('/finance/client_order/medium_back_money/info.html', order=client_order, back_moneys=back_moneys)
def index(order_id): order = ClientOrder.get(order_id) if not order: abort(404) invoices = Invoice.query.filter_by(client_order=order) invoices_data = { 'PASS': [{'invoice': x, 'form': get_invoice_from(x)} for x in invoices if x.invoice_status == INVOICE_STATUS_PASS], 'NORMAL': [{'invoice': x, 'form': get_invoice_from(x)} for x in invoices if x.invoice_status == INVOICE_STATUS_NORMAL], 'APPLY': [{'invoice': x, 'form': get_invoice_from(x)} for x in invoices if x.invoice_status == INVOICE_STATUS_APPLY], 'APPLYPASS': [{'invoice': x, 'form': get_invoice_from(x)} for x in invoices if x.invoice_status == INVOICE_STATUS_APPLYPASS], 'FAIL': [{'invoice': x, 'form': get_invoice_from(x)} for x in invoices if x.invoice_status == INVOICE_STATUS_FAIL], } reminder_emails = [(u.name, u.email) for u in User.all_active()] new_invoice_form = InvoiceForm() new_invoice_form.client_order.choices = [(order.id, order.client.name)] new_invoice_form.back_time.data = datetime.date.today() return tpl('/saler/client_order/invoice/index.html', order=order, invoices_data=invoices_data, new_invoice_form=new_invoice_form, INVOICE_STATUS_CN=INVOICE_STATUS_CN, reminder_emails=reminder_emails, INVOICE_TYPE_CN=INVOICE_TYPE_CN)
def delete_invoice(order_id, bid): order = ClientOrder.get(order_id) bm = BackInvoiceRebate.get(bid) order.add_comment(g.user, u"删除了返点发票信息,发票金额: %s; 开票时间: %s; 发票号: %s;" % ( bm.money, bm.back_time_cn, bm.num), msg_channel=4) bm.delete() flash(u'删除成功!', 'success') return redirect(url_for("finance_client_order_back_money.back_money", order_id=order.id))
def index(order_id): if not (g.user.is_super_leader() or g.user.is_finance() or g.user.is_aduit() or g.user.is_operater_leader()): abort(403) order = ClientOrder.get(order_id) if not order: abort(404) return tpl('/saler/client_order/other_cost/index.html', order=order)
def delete(order_id, bid): order = ClientOrder.get(order_id) bm = MediumBackMoney.get(bid) order.add_comment(g.user, u"删除了媒体返点回款信息,所属媒体: %s; 回款金额: %s; 回款时间: %s;" % (bm.order.medium.name, bm.money, bm.back_time_cn), msg_channel=8) bm.delete() flash(u'删除成功!', 'success') return redirect(url_for("finance_client_order_medium_back_money.back_money", order_id=order.id))
def _get_order_by_type(type, id): if type == 'client_order': client_order = ClientOrder.get(id) if client_order: return _order_to_dict(client_order) return {} elif type == 'douban_order': douban_order = DoubanOrder.get(id) if douban_order: return _order_to_dict(douban_order) return {} elif type == 'ass_douban_order': client_order = ClientOrder.get(id) if client_order: return _order_to_dict(client_order, client_order.associated_douban_orders[0]) return {} return {}
def index(order_id): order = ClientOrder.get(order_id) if not order: abort(404) outsources = [] for k in range(1, 6): outsources += order.get_outsources_by_status(k) invoices = OutsourceInvoice.query.filter_by(client_order=order) return tpl('/saler/client_order/outsource/index.html', order=order, outsources=outsources, invoices=invoices)
def client_outsources(order_id): order = ClientOrder.get(order_id) if not order: abort(404) new_outsource_form = OutsourceForm() new_outsource_form.medium_order.choices = [ (mo.id, mo.medium.name) for mo in order.medium_orders] reminder_emails = [(u.name, u.email) for u in User.all_active()] context = {'new_outsource_form': new_outsource_form, 'reminder_emails': reminder_emails, 'order': order} return tpl('client_outsources.html', **context)
def delete_invoice(order_id, bid): order = ClientOrder.get(order_id) bm = BackInvoiceRebate.get(bid) order.add_comment(g.user, u"删除了返点发票信息,发票金额: %s; 开票时间: %s; 发票号: %s;" % (bm.money, bm.back_time_cn, bm.num), msg_channel=4) bm.delete() flash(u'删除成功!', 'success') return redirect( url_for("finance_client_order_back_money.back_money", order_id=order.id))
def delete(order_id, bid): order = ClientOrder.get(order_id) bm = MediumBackMoney.get(bid) order.add_comment(g.user, u"删除了媒体返点回款信息,所属媒体: %s; 回款金额: %s; 回款时间: %s;" % (bm.order.medium.name, bm.money, bm.back_time_cn), msg_channel=8) bm.delete() flash(u'删除成功!', 'success') return redirect( url_for("finance_client_order_medium_back_money.back_money", order_id=order.id))
def index(order_id): order = ClientOrder.get(order_id) if not order: abort(404) invoices = AgentInvoice.query.filter_by(client_order=order) reminder_emails = [(u.name, u.email) for u in User.all_active()] new_invoice_form = AgentInvoiceForm() new_invoice_form.client_order.choices = [(order.id, order.client.name)] new_invoice_form.agent.choices = [(k.id, k.name)for k in order.agents] new_invoice_form.add_time.data = datetime.date.today() return tpl('/saler/client_order/agent/index.html', order=order, reminder_emails=reminder_emails, new_invoice_form=new_invoice_form, invoices=invoices, AGENT_INVOICE_STATUS_CN=AGENT_INVOICE_STATUS_CN, INVOICE_TYPE_CN=INVOICE_TYPE_CN)
def info(order_id): if not g.user.is_finance(): abort(404) order = ClientOrder.get(order_id) if not order: abort(404) invoices = MediumInvoice.query.filter_by(client_order=order) reminder_emails = [(u.id, u.name) for u in User.all_active()] new_invoice_form = MediumInvoiceForm() new_invoice_form.client_order.choices = [(order.id, order.client.name)] new_invoice_form.medium.choices = [(k.id, k.name)for k in order.mediums] new_invoice_form.add_time.data = datetime.date.today() return tpl('/finance/client_order/medium_pay/info.html', order=order, invoices=invoices, new_invoice_form=new_invoice_form, reminder_emails=reminder_emails, MEDIUM_INVOICE_STATUS_CN=MEDIUM_INVOICE_STATUS_CN, INVOICE_TYPE_CN=INVOICE_TYPE_CN)
def executive_report(order_id): otype = request.values.get('otype', 'ClientOrder') if otype == 'DoubanOrder': order = DoubanOrder.get(order_id) else: order = ClientOrder.get(order_id) if not order: abort(404) if not g.user.is_admin(): abort(402) _insert_executive_report(order, request.values.get('rtype', None)) if otype == 'ClientOrder': return redirect(url_for("outsource.client_orders")) else: return redirect(url_for("outsource.douban_orders"))
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))
def index(order_id): order = ClientOrder.get(order_id) if not order: abort(404) invoices = AgentInvoice.query.filter_by(client_order=order) reminder_emails = [(u.name, u.email) for u in User.all_active()] new_invoice_form = AgentInvoiceForm() new_invoice_form.client_order.choices = [(order.id, order.client.name)] new_invoice_form.agent.choices = [(k.id, k.name) for k in order.agents] new_invoice_form.add_time.data = datetime.date.today() return tpl('/saler/client_order/agent/index.html', order=order, reminder_emails=reminder_emails, new_invoice_form=new_invoice_form, invoices=invoices, AGENT_INVOICE_STATUS_CN=AGENT_INVOICE_STATUS_CN, INVOICE_TYPE_CN=INVOICE_TYPE_CN)
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))
def new_invoice(order_id): order = ClientOrder.get(order_id) if not order: abort(404) form = InvoiceForm(request.form) form.client_order.choices = [(order.id, order.client.name)] if request.method == 'POST' and form.validate(): if int(form.money.data) > (int(order.money) - int( order.invoice_apply_sum) - int(order.invoice_pass_sum)): flash(u"新建发票失败,您申请的发票超过了合同总额", 'danger') return redirect( url_for("finance_client_order_invoice.info", order_id=order_id)) invoice = Invoice.add( client_order=order, company=form.company.data, tax_id=form.tax_id.data, address=form.address.data, phone=form.phone.data, bank_id=form.bank_id.data, bank=form.bank.data, detail=form.detail.data, money=form.money.data, invoice_type=form.invoice_type.data, creator=g.user, invoice_status=0, invoice_num=request.values.get('new_invoice_num', ''), back_time=form.back_time.data, create_time=request.values.get( 'create_time', datetime.datetime.now().strftime('%Y-%m-%d'))) invoice.save() flash(u'开发票(%s)成功!' % form.company.data, 'success') order.add_comment(g.user, u"已开发票信息:%s" % (u'发票内容: %s; 发票金额: %s元' % (invoice.detail, str(invoice.money))), msg_channel=1) else: for k in form.errors: flash(u"新建发票失败,%s" % (form.errors[k][0]), 'danger') return redirect( url_for("finance_client_order_invoice.info", order_id=order.id))
def info(order_id): if not g.user.is_finance(): abort(404) order = ClientOrder.get(order_id) if not order: abort(404) invoices_data = { 'PASS': [{'invoice': x, 'form': get_invoice_from(order, x)} for x in MediumRebateInvoice.query.filter_by(client_order=order) if x.invoice_status == INVOICE_STATUS_PASS], 'APPLYPASS': [{'invoice': x, 'form': get_invoice_from(order, x)} for x in MediumRebateInvoice.query.filter_by(client_order=order) if x.invoice_status == INVOICE_STATUS_APPLYPASS], } reminder_emails = [(u.name, u.email) for u in User.all_active()] new_invoice_form = get_invoice_from(order, invoice=None) return tpl('/finance/client_order/medium_rebate_invoice/info.html', order=order, invoices_data=invoices_data, INVOICE_STATUS_CN=INVOICE_STATUS_CN, reminder_emails=reminder_emails, INVOICE_TYPE_CN=INVOICE_TYPE_CN, new_invoice_form=new_invoice_form)
def new_invoice( order_id, redirect_epoint='saler_client_order_medium_rebate_invoice.index'): order = ClientOrder.get(order_id) if not order: abort(404) form = MediumRebateInvoiceForm(request.form) form.client_order.choices = [(order.id, order.client.name)] form.medium.choices = [(medium.id, medium.name) for medium in order.mediums] if request.method == 'POST' and form.validate(): medium = Medium.get(form.medium.data) # if float(form.money.data) > float(order.get_medium_rebate_money(medium) - # order.get_medium_rebate_invoice_apply_sum(medium) - # order.get_medium_rebate_invoice_pass_sum(medium)): # flash(u"新建发票失败,您申请的发票超过了媒体:%s 返点金额: %s" % (medium.name, order.get_medium_rebate_money(medium)), 'danger') # return redirect(url_for(redirect_epoint, order_id=order_id)) invoice = MediumRebateInvoice.add(client_order=order, medium=Medium.get(form.medium.data), company=form.company.data, tax_id=form.tax_id.data, address=form.address.data, phone=form.phone.data, bank_id=form.bank_id.data, bank=form.bank.data, detail=form.detail.data, money=form.money.data, invoice_type=form.invoice_type.data, invoice_status=INVOICE_STATUS_NORMAL, creator=g.user, invoice_num=" ", back_time=form.back_time.data) invoice.save() order.add_comment(g.user, u"添加发票申请信息:%s" % (u'发票内容: %s; 发票金额: %s元' % (invoice.detail, str(invoice.money))), msg_channel=6) else: for k in form.errors: flash(u"新建发票失败,%s" % (form.errors[k][0]), 'danger') return redirect(url_for(redirect_epoint, order_id=order_id))
def new_invoice(order_id, redirect_epoint='finance_client_order_medium_rebate_invoice.info'): order = ClientOrder.get(order_id) if not order: abort(404) form = MediumRebateInvoiceForm(request.form) form.client_order.choices = [(order.id, order.client.name)] form.medium.choices = [(medium.id, medium.name) for medium in order.mediums] if request.method == 'POST' and form.validate(): medium = Medium.get(form.medium.data) # if float(form.money.data) > float(order.get_medium_rebate_money(medium) - # order.get_medium_rebate_invoice_apply_sum(medium) - # order.get_medium_rebate_invoice_pass_sum(medium)): # flash(u"新建发票失败,您申请的发票超过了媒体:%s 返点金额: %s" % (medium.name, order.get_medium_rebate_money(medium)), 'danger') # return redirect(url_for(redirect_epoint, order_id=order_id)) invoice = MediumRebateInvoice.add(client_order=order, medium=Medium.get(form.medium.data), company=form.company.data, tax_id=form.tax_id.data, address=form.address.data, phone=form.phone.data, bank_id=form.bank_id.data, bank=form.bank.data, detail=form.detail.data, money=form.money.data, invoice_type=form.invoice_type.data, invoice_status=INVOICE_STATUS_PASS, creator=g.user, invoice_num=form.invoice_num.data, create_time=request.values.get( 'create_time', datetime.datetime.now().strftime('%Y-%m-%d')), back_time=form.back_time.data) invoice.save() order.add_comment(g.user, u"添加发票申请信息:%s" % ( u'发票内容: %s; 发票金额: %s元' % (invoice.detail, str(invoice.money))), msg_channel=6) else: for k in form.errors: flash(u"新建发票失败,%s" % (form.errors[k][0]), 'danger') return redirect(url_for(redirect_epoint, order_id=order_id))
def index(order_id): order = ClientOrder.get(order_id) if not order: abort(404) invoices = Invoice.query.filter_by(client_order=order) invoices_data = { 'PASS': [{ 'invoice': x, 'form': get_invoice_from(x) } for x in invoices if x.invoice_status == INVOICE_STATUS_PASS], 'NORMAL': [{ 'invoice': x, 'form': get_invoice_from(x) } for x in invoices if x.invoice_status == INVOICE_STATUS_NORMAL], 'APPLY': [{ 'invoice': x, 'form': get_invoice_from(x) } for x in invoices if x.invoice_status == INVOICE_STATUS_APPLY], 'APPLYPASS': [{ 'invoice': x, 'form': get_invoice_from(x) } for x in invoices if x.invoice_status == INVOICE_STATUS_APPLYPASS], 'FAIL': [{ 'invoice': x, 'form': get_invoice_from(x) } for x in invoices if x.invoice_status == INVOICE_STATUS_FAIL], } reminder_emails = [(u.name, u.email) for u in User.all_active()] new_invoice_form = InvoiceForm() new_invoice_form.client_order.choices = [(order.id, order.client.name)] new_invoice_form.back_time.data = datetime.date.today() return tpl('/saler/client_order/invoice/index.html', order=order, invoices_data=invoices_data, new_invoice_form=new_invoice_form, INVOICE_STATUS_CN=INVOICE_STATUS_CN, reminder_emails=reminder_emails, INVOICE_TYPE_CN=INVOICE_TYPE_CN)
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))
def index(order_id): client_order = ClientOrder.get(order_id) if not client_order: abort(404) invoices = MediumRebateInvoice.query.filter_by(client_order=client_order) invoices_data = { 'PASS': [{ 'invoice': x, 'form': get_invoice_from(client_order, x) } for x in invoices if x.invoice_status == INVOICE_STATUS_PASS], 'NORMAL': [{ 'invoice': x, 'form': get_invoice_from(client_order, x) } for x in invoices if x.invoice_status == INVOICE_STATUS_NORMAL], 'APPLY': [{ 'invoice': x, 'form': get_invoice_from(client_order, x) } for x in invoices if x.invoice_status == INVOICE_STATUS_APPLY], 'APPLYPASS': [{ 'invoice': x, 'form': get_invoice_from(client_order, x) } for x in invoices if x.invoice_status == INVOICE_STATUS_APPLYPASS], 'FAIL': [{ 'invoice': x, 'form': get_invoice_from(client_order, 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 = get_invoice_from(client_order, invoice=None) return tpl('/saler/client_order/medium_rebate_invoice/index.html', order=client_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)
def info(order_id): if not g.user.is_finance(): abort(404) order = ClientOrder.get(order_id) outsources = order.get_outsources_by_status(4) apply_outsources = [] for k in [1, 2, 3, 5]: apply_outsources += order.get_outsources_by_status(k) now_date = datetime.datetime.now().strftime('%Y-%m-%d') invoices = OutsourceInvoice.query.filter_by(client_order=order) if request.method == 'POST': OutsourceInvoice.add( client_order=order, company=request.values.get('company', ''), money=float(request.values.get('money', 0)), ex_money=float(request.values.get('ex_money', 0)), invoice_num=request.values.get('invoice_num', ''), add_time=request.values.get('add_time', now_date), create_time=datetime.datetime.now(), creator=g.user ) return redirect(url_for('finance_client_order_outsource_invoice.info', order_id=order.id)) return tpl('/finance/client_order/outsource/invoice_info.html', order=order, outsources=outsources, now_date=now_date, invoices=invoices, apply_outsources=apply_outsources)
def back_money(order_id): if not g.user.is_finance(): abort(404) client_order = ClientOrder.get(order_id) back_moneys = MediumBackMoney.query.filter_by(client_order_id=order_id) if not client_order: abort(404) if request.method == 'POST': money = float(request.values.get('money', 0)) back_time = request.values.get( 'back_time', datetime.date.today().strftime('%Y-%m-%d')) medium_id = request.values.get('medium') order = Order.get(medium_id) MediumBackMoney.add(client_order_id=order_id, order_id=medium_id, money=money, back_time=back_time) client_order.add_comment(g.user, u"更新了媒体返点回款信息,所属媒体:%s; 回款金额: %s; 回款时间: %s;" % (order.medium.name, money, back_time), msg_channel=8) apply_context = { 'order': client_order, 'num': money, 'type': 'money', } medium_back_money_apply_signal.send(current_app._get_current_object(), apply_context=apply_context) flash(u'回款信息保存成功!', 'success') return redirect( url_for('finance_client_order_medium_back_money.back_money', order_id=order_id)) return tpl('/finance/client_order/medium_back_money/info.html', order=client_order, back_moneys=back_moneys)
def back_invoice(order_id): if not g.user.is_finance(): abort(404) order = ClientOrder.get(order_id) if not order: abort(404) if request.method == 'POST': money = float(request.values.get('money', 0)) back_time = request.values.get( 'back_time', datetime.date.today().strftime('%Y-%m-%d')) num = request.values.get('num', '') bm = BackInvoiceRebate.add( client_order=order, money=money, back_time=back_time, num=num, create_time=datetime.date.today().strftime('%Y-%m-%d')) bm.save() flash(u'返点发票信息保存成功!', 'success') order.add_comment(g.user, u"更新了返点发票信息,发票金额: %s; 发票时间: %s; 发票号: %s;" % (money, back_time, num), msg_channel=4) apply_context = { 'order': order, 'num': money, 'type': 'invoice', } back_money_apply_signal.send(current_app._get_current_object(), apply_context=apply_context) return redirect( url_for("finance_client_order_back_money.back_money", order_id=order.id)) return tpl('/finance/client_order/back_money/info.html', order=order)
def client_schedule_upload(): order_id = request.values.get('order') order = ClientOrder.get(order_id) return attachment_upload(order, FILE_TYPE_SCHEDULE)
def client_contract_upload(): order_id = request.values.get('order') order = ClientOrder.get(order_id) return attachment_upload(order, FILE_TYPE_CONTRACT)
def index(order_id): order = ClientOrder.get(order_id) back_moneys = MediumBackMoney.query.filter_by(client_order_id=order_id) if not order: abort(404) return tpl('/saler/client_order/medium_back_money/index.html', order=order, back_moneys=back_moneys)
def back_money(order_id): if not g.user.is_finance(): abort(404) order = ClientOrder.get(order_id) if not order: abort(404) if request.method == 'POST': money = float(request.values.get('money', 0)) back_time = request.values.get( 'back_time', datetime.date.today().strftime('%Y-%m-%d')) 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) flash(u'更新了回款状态,回款已完成!', 'success') order.add_comment( g.user, u"更新了回款状态,回款已完成;", msg_channel=4) elif int(back_money_status) == -1: 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': -1, 'type': 'end', } back_money_apply_signal.send( current_app._get_current_object(), apply_context=apply_context) else: order.back_money_status = int(back_money_status) order.save() apply_context = { 'order': order, 'num': 0, 'type': 'no_end', } back_money_apply_signal.send( current_app._get_current_object(), apply_context=apply_context) flash(u'更新了回款状态,回款未完成!', 'success') order.add_comment( g.user, u"更新了回款状态,回款未完成;", msg_channel=4) else: bm = BackMoney.add( client_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("finance_client_order_back_money.back_money", order_id=order.id)) return tpl('/finance/client_order/back_money/info.html', order=order)
def client_order_files(order_id): co = ClientOrder.get(order_id) return tpl("order_files.html", order=co)
def index(order_id): order = ClientOrder.get(order_id) if not order: abort(404) return tpl('/saler/client_order/back_money/index.html', order=order)
def index(order_id): order = ClientOrder.get(order_id) return tpl('/saler/client_order/money/index.html', order=order)
def client_others_upload(): order_id = request.values.get('order') order = ClientOrder.get(order_id) return attachment_upload(order, FILE_TYPE_OTHERS)
def outsource_client_order_upload(): order_id = request.values.get('order') order = ClientOrder.get(order_id) return attachment_upload(order, FILE_TYPE_OUTSOURCE)
def outsource_status(order_id): type = request.values.get('type', '') if type == 'douban': order = DoubanOrder.get(order_id) else: order = ClientOrder.get(order_id) if not order: abort(404) outsource_ids = request.values.getlist('outsources') action = int(request.values.get('action', 0)) # emails = request.values.getlist('email') msg = request.values.get('msg', '') to_users = order.direct_sales + order.agent_sales + \ [order.creator, g.user] + order.operater_users try: outsource_apply_user = User.outsource_leaders_email( (order.agent_sales + order.direct_sales)[0]) except: outsource_apply_user = [] outsources_ids = set(outsource_ids) | set( [str(k.id) for k in order.apply_outsources()]) if type == 'douban': total_outsources = DoubanOutSource.gets(outsources_ids) outsources = DoubanOutSource.gets(outsource_ids) else: total_outsources = OutSource.gets(outsources_ids) outsources = OutSource.gets(outsource_ids) if not outsources: abort(403) if order.money: outsource_percent = sum( [k.pay_num for k in total_outsources]) / float(order.money) else: outsource_percent = sum([k.pay_num for k in total_outsources]) / 1 if action == 0: if outsource_percent >= 0.02: next_status = OUTSOURCE_STATUS_EXCEED action_msg = u'外包费用超过2%,申请审批' else: next_status = OUTSOURCE_STATUS_APPLY_LEADER action_msg = u'外包费用申请审批' # to_users_name = ','.join( # [k.name for k in outsource_apply_user] + [k.name for k in order.operater_users]) elif action == 1: next_status = OUTSOURCE_STATUS_PASS action_msg = u'外包费用审批通过' # to_users_name = ','.join( # [k.name for k in order.agent_sales] + [k.name for k in order.operater_users]) elif action == 2: next_status = OUTSOURCE_STATUS_NEW action_msg = u'外包费用拒绝通过' # to_users_name = ','.join( # [k.name for k in order.agent_sales] + [k.name for k in order.operater_users]) elif action == 3: next_status = OUTSOURCE_STATUS_APPLY_MONEY action_msg = u'外包费用申请打款' # to_users_name = ','.join([k.name for k in User.operater_leaders()]) elif action == 100: # to_users_name = ','.join([k.name for k in outsource_apply_user] + [k.name for k in order.operater_users]) outsources_json = json.loads( request.values.get('outsource_json', '[]')) outsources = [] # 先修改外包金额 for k in outsources_json: if type == 'douban': outsource = DoubanOutSource.get(k['id']) else: outsource = OutSource.get(k['id']) outsource.num = float(k['num']) outsource.target = OutSourceTarget.get(k['target']) outsource.type = k['type'] outsource.subtype = k['subtype'] outsource.remark = k['remark'] outsource.pay_num = float(k['num']) # outsource.status = next_status outsource.save() outsources.append(outsource) # 根据修改后的金额,计算是否超过占比 outsource_percent = float(order.outsources_percent) / 100 if outsource_percent >= 0.02: action_msg = u'外包费用超过2%,修改并申请审批' next_status = OUTSOURCE_STATUS_EXCEED else: action_msg = u'外包费用修改并重新申请审批' next_status = OUTSOURCE_STATUS_APPLY_LEADER for k in outsources_json: if type == 'douban': outsource = DoubanOutSource.get(k['id']) else: outsource = OutSource.get(k['id']) outsource.status = next_status outsource.save() else: action_msg = u'外包费用消息提醒' if action < 4: for outsource in outsources: outsource.status = next_status outsource.save() if action == 1: _insert_executive_report(order, rtype='reload') order.add_comment(g.user, u"%s:\n\r%s\n\r%s" % ( action_msg, "\n\r".join([o.name for o in outsources]), msg), msg_channel=2) # to_emails = list(set(emails + [x.email for x in to_users] + [k.email for k in outsource_apply_user])) apply_context = {"to_users": to_users + outsource_apply_user, "outsource_apply_user": outsource_apply_user, "action_msg": action_msg, "info": msg, "order": order, "action": action, "outsource_percent": outsource_percent, "outsources": outsources} outsource_apply_signal.send( current_app._get_current_object(), context=apply_context) if type == 'douban': return redirect(url_for("outsource.douban_outsources", order_id=order.id)) else: return redirect(url_for("outsource.client_outsources", order_id=order.id))
def finish_client_order_upload(): order_id = request.values.get('order') order = ClientOrder.get(order_id) return attachment_upload(order, FILE_TYPE_FINISH)
def back_money(order_id): if not g.user.is_finance(): abort(404) order = ClientOrder.get(order_id) if not order: abort(404) if request.method == 'POST': money = float(request.values.get('money', 0)) back_time = request.values.get( 'back_time', datetime.date.today().strftime('%Y-%m-%d')) 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) flash(u'更新了回款状态,回款已完成!', 'success') order.add_comment(g.user, u"更新了回款状态,回款已完成;", msg_channel=4) elif int(back_money_status) == -1: 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': -1, 'type': 'end', } back_money_apply_signal.send(current_app._get_current_object(), apply_context=apply_context) else: order.back_money_status = int(back_money_status) order.save() apply_context = { 'order': order, 'num': 0, 'type': 'no_end', } back_money_apply_signal.send(current_app._get_current_object(), apply_context=apply_context) flash(u'更新了回款状态,回款未完成!', 'success') order.add_comment(g.user, u"更新了回款状态,回款未完成;", msg_channel=4) else: bm = BackMoney.add( client_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("finance_client_order_back_money.back_money", order_id=order.id)) return tpl('/finance/client_order/back_money/info.html', order=order)