Exemplo n.º 1
0
def email_invoice(inv):
	print(current_user.userid)
	print(inv)
	invoice = getInvoice(inv).get_json()
	if(invoice['success']):
		payee = User.query.filter_by(userid=invoice['invoice']['receiverid']).first()
		sender = User.query.filter_by(userid=invoice['invoice']['senderid']).first()

		if payee.email:
			print('payee email: ', payee.email)
			if current_user.phone:
				
				username=current_user.username
				swish_qr_base64=swishQRbase64(sender.phone, invoice['invoice']['amount'], invoice['invoice']['description'])
				html = HTML(string=render_template('invoice_pdf_template.html', username=sender.username, invoice=invoice['invoice'], qrCode_base64=swish_qr_base64, css1=url_for('static', filename='invoice_pdf/boilerplate.css'), css2=url_for('static', filename='invoice_pdf/main.css'), css3=url_for('static', filename='invoice_pdf/normalize.css')))
				pdf = io.BytesIO(html.write_pdf())
				msg = Message("Du har blivit fakkad :)",
			                  sender="*****@*****.**",
			                  recipients=[payee.email])
				msg.body = "Du har blivit fakkad, se bifogat" 
				msg.attach('invoice.pdf', 'application/pdf', data=pdf.read())
				mail.send(msg)
				return {'message' : "Email sent!"}
			else:
				return {'message' : "You have no phone number registred which is needed to genarate swish QRcode :("}
		else:
			return {'message' : "Payee has no email address registered :("}
	else:

		return {'message' : invoice['message']}	
Exemplo n.º 2
0
def view_invoice_site(invoice_id):

    invoice = Invoice.query.filter_by(invoiceid=invoice_id).first()
    swish_qr_base64 = swishQRbase64(invoice.sender.phone, invoice.amount,
                                    invoice.description)
    print(swish_qr_base64)

    return render_template('invoice2.html',
                           title='Fakturor',
                           invoice=invoice,
                           qr_code=swish_qr_base64)
Exemplo n.º 3
0
def view_open_invoice_site(invoice_token):

    package = load_invoice_token(invoice_token)
    #print(package)

    invoice = Invoice.query.filter_by(invoiceid=package[0]).first()
    if not invoice:
        return "ingen faktura hittad."

    swish_qr_base64 = swishQRbase64(invoice.sender.phone, invoice.amount,
                                    invoice.description)
    #print(swish_qr_base64)

    #return render_template('invoice2.html', title='Fakturor',invoice=invoice, qr_code=swish_qr_base64)
    return render_template('view_invoice.html',
                           title='Faktura',
                           invoice=invoice,
                           qr_code=swish_qr_base64)
Exemplo n.º 4
0
def renderpdf(inv):
	username=current_user.username
	invoice = getInvoice(inv).get_json()
	payee = User.query.filter_by(userid=invoice['invoice']['receiverid']).first()
	sender = User.query.filter_by(userid=invoice['invoice']['senderid']).first()
	#print('invoice_json: ', invoice)
	#print('payee: ', payee)
	#print('sender: ', sender)
	if(invoice['success']):
		

		swish_qr_base64=swishQRbase64(sender.phone, invoice['invoice']['amount'], invoice['invoice']['description'])
		print_html = render_template('invoice_pdf_template.html', username=sender.username, invoice=invoice['invoice'], qrCode_base64=swish_qr_base64, css1=url_for('static', filename='invoice_pdf/boilerplate.css'), css2=url_for('static', filename='invoice_pdf/main.css'), css3=url_for('static', filename='invoice_pdf/normalize.css'))
		
		
		return render_pdf(HTML(string=print_html), download_filename='invoice'+str(invoice['invoice']['invoiceid'])+'.pdf')
	else:

		return {'message' : invoice['message']}
Exemplo n.º 5
0
def renderpdf(inv):
    username = current_user.username
    invoice = Invoice.query.filter_by(invoiceid=inv).first()
    payee = User.query.filter_by(userid=invoice.frienduserid).first()
    sender = User.query.filter_by(userid=invoice.userid).first()
    #print('invoice_json: ', invoice)
    #print('payee: ', payee)
    #print('sender: ', sender)

    swish_qr_base64 = swishQRbase64(sender.phone, invoice.amount,
                                    invoice.description)
    print_html = render_template(
        'invoice_pdf_template.html',
        username=sender.username,
        invoice=invoice,
        qrCode_base64=swish_qr_base64,
        css1=url_for('static', filename='invoice_pdf/boilerplate.css'),
        css2=url_for('static', filename='invoice_pdf/main.css'),
        css3=url_for('static', filename='invoice_pdf/normalize.css'))

    return render_pdf(HTML(string=print_html),
                      download_filename='invoice' + str(invoice.invoiceid) +
                      '.pdf')