def reference_pdf(request, reference_id): reference = get_object_or_404( JobReference.objects.select_related("assignment__drudge__user"), pk=reference_id ) if not request.user.is_staff: if reference.assignment.drudge.user != request.user: return HttpResponseForbidden("<h1>Access forbidden</h1>") drudge = reference.assignment.drudge pdf, response = pdf_response("reference-%s" % reference.pk) pdf.init_letter(page_fn=create_stationery_fn(NaturnetzStationery())) pdf.p(drudge.user.get_full_name()) pdf.p(drudge.address) pdf.p(u"%s %s" % (drudge.zip_code, drudge.city)) pdf.next_frame() pdf.p("Kloster Fahr, %s" % reference.created.strftime("%d.%m.%Y")) pdf.h1("ARBEITSZEUGNIS") pdf.spacer() pdf.p(reference.text) pdf.spacer(10 * mm) pdf.p(u"Dr. Marco Sacchi\nGeschäftsführer") pdf.generate() return response
def packing_slip_pdf(request, order_id): """ Returns the packing slip PDF """ order = get_object_or_404(plata.shop_instance().order_model, pk=order_id) pdf, response = pdf_response('packing-slip-%09d' % order.id) plata.reporting.order.packing_slip_pdf(pdf, order) return response
def invoice_pdf(request, order_id): """ Returns the invoice PDF """ order = get_object_or_404(plata.shop_instance().order_model, pk=order_id) pdf, response = pdf_response('invoice-%09d' % order.id) plata.reporting.order.invoice_pdf(pdf, order) return response
def invoice(request, order_id): """ Returns the invoice PDF """ order = get_object_or_404(plata.shop_instance().order_model, pk=order_id) if order in request.user.orders.all(): pdf, response = pdf_response("invoice-%09d" % order.id) plata.reporting.order.invoice_pdf(pdf, order) return response else: raise Http404
def render_pdf(self): pdf, response = pdf_response(self.event.title + " attendees") pdf.init_report() pdf.p(self.event.title, style=create_paragraph_style(font_size=18)) pdf.spacer(10) pdf.p( self.event.event_start.strftime("%d. %B %Y"), create_paragraph_style(font_size=9), ) pdf.spacer(height=25) pdf.p("Påmeldte", style=create_paragraph_style(font_size=14)) pdf.spacer(height=20) pdf.table( self.attendee_table_data, self.attendee_column_widths(), style=get_table_style(self.full_span_attendee_lines), ) pdf.spacer(height=25) if self.waiters.count() > 0: pdf.p("Venteliste", style=create_paragraph_style(font_size=14)) pdf.spacer(height=20) pdf.table( self.waiters_table_data, self.attendee_column_widths(), style=get_table_style(self.full_span_waiters_lines), ) pdf.spacer(height=25) if self.reservees and self.reservees.count() > 0: pdf.p("Reservasjoner", style=create_paragraph_style(font_size=14)) pdf.spacer(height=20) pdf.table( self.reservee_table_data, self.reservee_column_widths(), style=get_table_style(), ) pdf.spacer(height=25) if self.allergies_table_data: pdf.p("Allergier", style=create_paragraph_style(font_size=14)) pdf.spacer(height=20) pdf.table( self.allergies_table_data, self.allergies_column_widths(), style=get_table_style(), ) pdf.spacer(height=25) pdf.generate() return response
def receipt_pdf(request, order_id): """ Returns the invoice PDF """ order = get_object_or_404(plata.shop_instance().order_model, pk=order_id) if order in request.user.orders.all(): pdf, response = pdf_response('invoice-%09d' % order.id) plata.reporting.order.invoice_pdf(pdf, order) return response else: raise Http404
def get(self, request): self.object_list = self.get_queryset() search_form = AssignmentSearchForm(request.GET, request=request) if not search_form.is_valid(): messages.error(request, _("The search query was invalid.")) return redirect("zivinetz_assignment_list") self.object_list = safe_queryset_and( self.object_list, search_form.queryset(self.model) ) pdf, response = pdf_response("phones") pdf.init_report() specification = None for assignment in self.object_list.order_by("specification", "drudge"): drudge = assignment.drudge if specification != assignment.specification: pdf.h2("%s" % assignment.specification) specification = assignment.specification pdf.table( [ ( u"%s" % drudge, drudge.user.email, u"%s - %s" % ( assignment.date_from.strftime("%d.%m.%y"), assignment.determine_date_until().strftime("%d.%m.%y"), ), ), (drudge.phone_home, drudge.phone_office, drudge.mobile), ( u"%s, %s %s" % (drudge.address, drudge.zip_code, drudge.city), "", drudge.education_occupation, ), ], (6.4 * cm, 5 * cm, 5 * cm), ) pdf.hr_mini() pdf.generate() return response
def expense_report_pdf(request, expense_report_id): report = get_object_or_404( ExpenseReport.objects.select_related("assignment__drudge__user"), pk=expense_report_id, ) if not request.user.is_staff: if report.assignment.drudge.user != request.user: return HttpResponseForbidden("<h1>Access forbidden</h1>") table, additional, total = report.compensations() if not all((t is not None) for t in (table, additional, total)): messages.error(request, _("No expense data, cannot generate report.")) return redirect(report.assignment) assignment = report.assignment drudge = assignment.drudge scope_statement = assignment.specification.scope_statement pdf, response = pdf_response("expense-report-%s" % report.pk) pdf.init_report() pdf.h1("Spesenrapport") pdf.h2( "Einsatzbetrieb %s - %s, %s, %s %s" % ( scope_statement.branch_no, scope_statement.company_name, scope_statement.company_address, scope_statement.company_zip_code, scope_statement.company_city, ) ) pdf.spacer() pdf.table( [ (u"Pflichtenheft:", u"%s" % report.assignment.specification), (u"Name, Vorname:", u"%s" % drudge.user.get_full_name()), ( u"Adresse:", u"%s, %s %s" % (drudge.address, drudge.zip_code, drudge.city), ), (u"ZDP:", drudge.zdp_no), ( u"Gesamteinsatz:", u"%s - %s" % ( assignment.date_from.strftime("%d.%m.%Y"), assignment.date_until.strftime("%d.%m.%Y"), ), ), ( u"Meldeperiode:", u"%s - %s" % ( report.date_from.strftime("%d.%m.%Y"), report.date_until.strftime("%d.%m.%Y"), ), ), ], (4 * cm, 12.4 * cm), pdf.style.tableLLR, ) pdf.spacer() def notes(from_): return ( ("FONT", (0, from_), (-1, from_), "Helvetica-Oblique", 8), # ('LEFTPADDING', (0, from_), (-1, from_), 3 * mm), ) pdf.table( table, (4 * cm, 2 * cm, 2 * cm, 2 * cm, 2 * cm, 2 * cm, 2.4 * cm), pdf.style.tableHead + tuple(reduce(operator.add, (notes(i) for i in range(2, 12, 2)))), ) pdf.table( additional, (14 * cm, 2.4 * cm), pdf.style.table + notes(1) + notes(3) + notes(5), ) pdf.spacer(1 * mm) pdf.table([(_("Total"), total)], (14 * cm, 2.4 * cm), pdf.style.tableHead) pdf.spacer() pdf.table( [(_("bank account") + ":", drudge.bank_account)], (4 * cm, 12.4 * cm), pdf.style.tableLLR, ) pdf.bottom_table( [(_("Place, Date"), "", _("Jobholder"), "", _("Employer"))], (44 * mm, 10 * mm, 50 * mm, 10 * mm, 50 * mm), style=pdf.style.table + ( ("TOPPADDING", (0, 0), (-1, -1), 1 * mm), ("LINEABOVE", (0, 0), (0, 0), 0.2, colors.black), ("LINEABOVE", (2, 0), (2, 0), 0.2, colors.black), ("LINEABOVE", (4, 0), (4, 0), 0.2, colors.black), ("ALIGN", (0, 0), (-1, -1), "LEFT"), ), ) pdf.generate() return response
def generate_expense_statistics_pdf(reports): pdf, response = pdf_response("expense-statistics") pdf.doc.addPageTemplates( [ PageTemplate( id="First", frames=[ Frame( 0.5 * cm, 0.5 * cm, 19.8 * cm, 28.5 * cm, showBoundary=0, leftPadding=0, rightPadding=0, topPadding=0, bottomPadding=0, ) ], ) ] ) pdf.generate_style(font_size=6) pdf.h1("Spesenstatistik") table_head = ( "ZDP", "Name", "Periode", "", "Arbeitstage", "", "Freitage", "", "Krankheit", "", "Ferien", "", "Urlaub", "Anreise", "Kleider", "Extra", "", "Total", ) table_cols = ( 1 * cm, 3 * cm, 2.2 * cm, 0.6 * cm, 1.1 * cm, 0.6 * cm, 1.1 * cm, 0.6 * cm, 1.1 * cm, 0.6 * cm, 1.1 * cm, 0.6 * cm, 1.1 * cm, 1 * cm, 1 * cm, 1 * cm, 0.85 * cm, 1.25 * cm, ) data = OrderedDict() for report in reports.order_by("date_from", "assignment__drudge").select_related( "assignment__specification__scope_statement", "assignment__drudge__user" ): compensation = report.compensation_data() if not compensation: # Attention! Using current date instead of real mobilization date compensation = report.compensation_data(date.today()) if not compensation: continue def add(keys): return sum(compensation[k] for k in keys.split()) tpl = ( "spending_money accomodation_%(t)s breakfast_%(t)s lunch_%(t)s" " supper_%(t)s" ) working_day = add(tpl % {"t": "working"}) free_day = add(tpl % {"t": "free"}) sick_day = add(tpl % {"t": "sick"}) line = [ report.assignment.drudge.zdp_no, report.assignment.drudge.user.get_full_name(), u"%s - %s" % ( report.date_from.strftime("%d.%m.%y"), report.date_until.strftime("%d.%m.%y"), ), report.working_days, report.working_days * working_day, report.free_days, report.free_days * free_day, report.sick_days, report.sick_days * sick_day, report.holi_days, report.holi_days * free_day, report.forced_leave_days, Decimal("0.00"), # forced leave day -- always zero report.transport_expenses, report.clothing_expenses, report.miscellaneous, report.total_days, report.total, ] data.setdefault( report.assignment.specification.scope_statement, OrderedDict() ).setdefault((report.date_from.year, report.date_from.month), []).append(line) def _add_sum(reports, title=""): transposed = list(zip(*reports)) total = ["Total %s" % title, "", ""] + [ sum(transposed[i], 0) for i in range(3, 18) ] pdf.table([total], table_cols, pdf.style.tableHead) pdf.spacer() return total totals = [] for scope_statement, ss_data in data.items(): pdf.h2(u"%s" % scope_statement) complete = [] for year_month, reports in ss_data.items(): title = date(year_month[0], year_month[1], 1).strftime("%B %Y") pdf.h3(title) pdf.spacer(2 * mm) pdf.table([table_head] + reports, table_cols, pdf.style.tableHead) _add_sum(reports, title) pdf.spacer() complete.extend(reports) totals.append(_add_sum(complete, u"%s" % scope_statement)) pdf.pagebreak() pdf.h2("Zusammenfassung") pdf.table([table_head] + totals, table_cols, pdf.style.tableHead) _add_sum(totals, "Total") pdf.generate() return response