def employer_account(request, preferences_form_class = RecruiterPreferencesForm, change_password_form_class = PasswordChangeForm, extra_context=None): context = {} recruiter = request.user.recruiter context['recruiter'] = recruiter employer = recruiter.employer context['employer'] = employer customer = request.META['customer'] has_at_least_premium = request.META['has_at_least_premium'] context['customer'] = customer subscription = customer.subscription if subscription: context['current_period_end'] = format_unix_time(customer.subscription.current_period_end) msg = request.GET.get('msg', None) if msg: page_messages = { 'payment-changed': messages.payment_changed, 'password-changed': messages.password_changed, 'subscription-cancelled' : messages.subscription_cancelled, 'upgraded_to_premium' : messages.upgraded_to_premium, 'changed_billing' : messages.changed_billing } if page_messages.has_key(msg): context["msg"] = page_messages[msg] context['other_recruiters'] = employer.recruiter_set.exclude(id=recruiter.id) context['preferences_form'] = preferences_form_class(instance=recruiter.recruiterpreferences) context['change_password_form'] = change_password_form_class(request.user) charges = get_charges(customer.id) context['charges'] = charges context['charge_total'] = sum_charges(charges) context['max_users_for_basic_users'] = s.MAX_USERS_FOR_BASIC_USERS context['can_create_more_accounts'] = has_at_least_premium or len(Recruiter.objects.filter(employer=employer)) < s.MAX_USERS_FOR_BASIC_USERS context.update(extra_context or {}) return context
def employer_account( request, preferences_form_class=RecruiterPreferencesForm, change_password_form_class=PasswordChangeForm, extra_context=None, ): context = {} recruiter = request.user.recruiter context["recruiter"] = recruiter employer = recruiter.employer context["employer"] = employer customer = request.META["customer"] has_at_least_premium = request.META["has_at_least_premium"] context["customer"] = customer subscription = customer.subscription if subscription: context["current_period_end"] = format_unix_time(customer.subscription.current_period_end) msg = request.GET.get("msg", None) if msg: page_messages = { "payment-changed": messages.payment_changed, "password-changed": messages.password_changed, "subscription-cancelled": messages.subscription_cancelled, "upgraded_to_premium": messages.upgraded_to_premium, "changed_billing": messages.changed_billing, } if page_messages.has_key(msg): context["msg"] = page_messages[msg] context["other_recruiters"] = employer.recruiter_set.exclude(id=recruiter.id) context["preferences_form"] = preferences_form_class(instance=recruiter.recruiterpreferences) context["change_password_form"] = change_password_form_class(request.user) charges = get_charges(customer.id) context["charges"] = charges context["charge_total"] = sum_charges(charges) context["max_users_for_basic_users"] = s.MAX_USERS_FOR_BASIC_USERS context["can_create_more_accounts"] = ( has_at_least_premium or len(Recruiter.objects.filter(employer=employer)) < s.MAX_USERS_FOR_BASIC_USERS ) context.update(extra_context or {}) return context
def get_or_create_receipt_pdf(charge, invoice, employer_name): pdf_name = "Umeqo-Receipt-%s-%s.pdf" % (format_unix_time( charge.created).replace("/", "-"), charge.id) path = "%semployer/receipts/" % (s.MEDIA_ROOT) if not os.path.exists(path): os.makedirs(path) pdf_path = "%s%s" % (path, pdf_name) if not os.path.exists(pdf_path): story = [] story.append(Spacer(3 * cm, 2 * cm)) story.append(Paragraph('Umeqo Receipt', styles['Heading1'])) story.append(Paragraph(employer_name, styles['Heading2'])) story.append(Paragraph("Charge ID: %s" % charge.id, styles['Heading3'])) story.append(Spacer(1 * cm, 1 * cm)) hitem = Paragraph('''<b>Item</b>''', styles["Normal"]) hdate = Paragraph('''<b>Date</b>''', styles["Normal"]) hamount = Paragraph('''<b>Amount</b>''', styles["Normal"]) data = [[hitem, hdate, hamount]] for subscription in invoice.lines.subscriptions: item = Paragraph(subscription.plan.name, styles["Normal"]) date = Paragraph( "%s-%s" % (format_unix_time(subscription.period.start), format_unix_time(subscription.period.end)), styles["Normal"]) amount = Paragraph(format_money(subscription.amount), right_align_style) data.append([item, date, amount]) for invoice_item in invoice.lines.invoiceitems: item = Paragraph(invoice_item.description, styles["Normal"]) date = Paragraph(format_unix_time(invoice_item.date), styles["Normal"]) amount = Paragraph(format_money(invoice_item.amount), right_align_style) data.append([item, date, amount]) for proration in invoice.lines.prorations: item = Paragraph(proration.description, styles["Normal"]) date = Paragraph(format_unix_time(proration.date), styles["Normal"]) amount = Paragraph(format_money(proration.amount), right_align_style) data.append([item, date, amount]) table = Table(data, colWidths=[8.5 * cm, 4.5 * cm, 2.5 * cm]) table.setStyle( TableStyle([ ('INNERGRID', (0, 0), (-1, -1), 0.25, colors.black), ('BOX', (0, 0), (-1, -1), 0.25, colors.black), ])) story.append(table) total_amount_style = ParagraphStyle(name='BodyText', parent=styles['Normal'], alignment=TA_RIGHT, spaceBefore=1) total_amount = Paragraph( "<strong>Total:</strong> %s" % format_money(charge.amount), total_amount_style) story.append(total_amount) story.append(Spacer(1 * cm, 3 * cm)) story.append(Paragraph('''Umeqo''', styles["Normal"])) story.append(Paragraph('''645 Harrison Suite 200''', styles["Normal"])) story.append(Paragraph('''San Francisco, CA 94107''', styles["Normal"])) story.append(Paragraph('''https://www.umeqo.com''', styles["Normal"])) story.append(Paragraph('''(650) 543-1400''', styles["Normal"])) doc = SimpleDocTemplate(pdf_path, pagesize=A4, topMargin=0) doc.build(story) return pdf_path
def get_or_create_receipt_pdf(charge, invoice, employer_name): pdf_name = "Umeqo-Receipt-%s-%s.pdf" % (format_unix_time(charge.created).replace("/", "-"), charge.id) path = "%semployer/receipts/" % (s.MEDIA_ROOT) if not os.path.exists(path): os.makedirs(path) pdf_path = "%s%s" % (path, pdf_name) if not os.path.exists(pdf_path): story = [] story.append(Spacer(3*cm, 2*cm)) story.append(Paragraph('Umeqo Receipt', styles['Heading1'])) story.append(Paragraph(employer_name, styles['Heading2'])) story.append(Paragraph("Charge ID: %s" % charge.id, styles['Heading3'])) story.append(Spacer(1*cm, 1*cm)) hitem = Paragraph('''<b>Item</b>''', styles["Normal"]) hdate = Paragraph('''<b>Date</b>''', styles["Normal"]) hamount = Paragraph('''<b>Amount</b>''', styles["Normal"]) data= [[hitem, hdate, hamount]] for subscription in invoice.lines.subscriptions: item = Paragraph(subscription.plan.name, styles["Normal"]) date = Paragraph("%s-%s" % (format_unix_time(subscription.period.start), format_unix_time(subscription.period.end)), styles["Normal"]) amount = Paragraph(format_money(subscription.amount), right_align_style) data.append([item, date, amount]) for invoice_item in invoice.lines.invoiceitems: item = Paragraph(invoice_item.description, styles["Normal"]) date = Paragraph(format_unix_time(invoice_item.date), styles["Normal"]) amount = Paragraph(format_money(invoice_item.amount), right_align_style) data.append([item, date, amount]) for proration in invoice.lines.prorations: item = Paragraph(proration.description, styles["Normal"]) date = Paragraph(format_unix_time(proration.date), styles["Normal"]) amount = Paragraph(format_money(proration.amount), right_align_style) data.append([item, date, amount]) table = Table(data, colWidths=[8.5 * cm, 4.5 * cm, 2.5 * cm]) table.setStyle(TableStyle([ ('INNERGRID', (0,0), (-1,-1), 0.25, colors.black), ('BOX', (0,0), (-1,-1), 0.25, colors.black), ])) story.append(table) total_amount_style = ParagraphStyle(name='BodyText', parent=styles['Normal'], alignment=TA_RIGHT, spaceBefore=1) total_amount = Paragraph("<strong>Total:</strong> %s" % format_money(charge.amount), total_amount_style) story.append(total_amount) story.append(Spacer(1*cm, 3*cm)) story.append(Paragraph('''Umeqo''', styles["Normal"])) story.append(Paragraph('''645 Harrison Suite 200''', styles["Normal"])) story.append(Paragraph('''San Francisco, CA 94107''', styles["Normal"])) story.append(Paragraph('''https://www.umeqo.com''', styles["Normal"])) story.append(Paragraph('''(650) 543-1400''', styles["Normal"])) doc = SimpleDocTemplate(pdf_path, pagesize = A4, topMargin=0) doc.build(story) return pdf_path