# -*- coding: utf-8 -*-
from django.http import HttpResponse
from django.shortcuts import render, get_object_or_404
from coin.billing.models import Invoice
from coin.members.models import Member
from coin.html2pdf import render_as_pdf


def invoice_pdf(request, pk):

    invoice = get_object_or_404(Invoice, pk=pk)
    member = invoice.member

    context = {"invoice": invoice, 'member':member}
    
    pdf = render_as_pdf('billing/invoice.html', context)
    
    response = HttpResponse(content_type='application/pdf')
    #response['Content-Disposition'] = 'attachment; filename="facture.pdf"'

    response.write(pdf)

    #response.write(process_latex('billing/invoice.html', context))
    return response
