Skip to content

Instantly share code, notes, and snippets.

@kylechase
Created August 1, 2014 19:50
Show Gist options
  • Save kylechase/7a549d098b0d21d65542 to your computer and use it in GitHub Desktop.
Save kylechase/7a549d098b0d21d65542 to your computer and use it in GitHub Desktop.
import zipfile
zile = system.file.saveFile("temp.zip")
myzip = zipfile.ZipFile(zile,'w')
invoiceId = event.source.parent.getComponent('Container').getComponent('tblInvoices').selectedInvoice
invoiceFile = system.file.getTempFile("pdf")
bytes = event.source.parent.getComponent('Report Viewer Labour').getBytesPDF()
system.file.writeFile(invoiceFile,bytes)
invoiceName = "000000" + str(invoiceId)
invoiceName = invoiceName[-6:]
invoiceName = "Invoice " + invoiceName + ".pdf"
myzip.write(invoiceFile,invoiceName)
receipts = system.db.runPrepQuery("SELECT `receipt_file_name`,`receipt_blob` FROM `expenses` WHERE invoice_id = ?",[invoiceId])
i = 1
for row in receipts:
tFile = system.file.getTempFile(".tmp")
system.file.writeFile(tFile,row[1])
myzip.write(tFile,row[0])
myzip.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment