Create a zip file of all invoices generated with printRecord()
Hello,
I would like to create a zip file that includes all invoices from all records in the "Transactions" table.
Invoices are usually obtained individually by clicking on a button containing the printRecord(this, "Invoice_template_dynamic") function.
I would need code that generates all the invoices and then integrates them into a zip file before downloading the zip file directly to my computer (I don't want to save the zip file in Ninox).
Thanks for your help.
11 replies
-
Hello,
I am reviving the topic concerning the need to download all invoices for a given period in a zip file.
Here is my current code that downloads each pdf independently
let filterStart := 'Début du filtre'; let filterEnd := 'Fin du filtre'; let sample := (select Transactions); for loop in sample do if loop.date('Date de facturation') >= filterStart and loop.date('Date de facturation') <= filterEnd then printRecord(loop, "facture_dynamique") end end
Ideally, each pdf would be named "Invoice No." followed by the invoice number found at (select Transactions).'N° de transaction' and that the work is done in the background (so that it does not block Ninox during loading time which can be very long).
Thank you for your help.
-
The problem is that I can't manipulate printRecord() with createZipFile(). Either the files are downloaded directly to my machine without going through zip compression, or nothing happens.
-
First you need to create all your PDF's because of the lag between the actual PDF is created and the availability of this file. Then you need a second image field where you would put your .zip file in. Lets say I call this field "zipfile(ImageField)"
So you need 2 buttons , one to create all your PDF's and another to create your .zip file where you can add a filter in your select function (or create a dialog between the code to add some time). Be aware that these variables must be in the "do as server" area.
example:
do as server let strt := today(); let end := today()+10; let inv := (select Invoices where InvoiceDate >= strt and InvoiceDate <= end).Invoice(ImageField); zipfile(ImageField) := createZipFile(this, inv, "ZippedInvoices.zip") end
Following code won't work (the docs are a bit limited about this):
let strt := today(); let end := today()+10; let inv := (select Invoices where InvoiceDate >= strt and InvoiceDate <= end).Invoice(ImageField); do as server zipfile(ImageField) := createZipFile(this, inv, "ZippedInvoices.zip") end
-
If it can help someone, here is the code for each button:
Button to generate each invoice in a record of my 'Documents' table with the indicator "Type de document' := 18" which will later be used to delete all the records that have just been created.
let filterStart := 'Début du filtre'; let filterEnd := 'Fin du filtre'; let sample := (select Transactions); for loop in sample do let nomFacture := "Facture n°" + loop.'N° de transaction' + ".pdf"; if loop.date('Date de facturation') >= filterStart and loop.date('Date de facturation') <= filterEnd then let me := this; let newDocFacture := (create Documents); newDocFacture.(Compte := loop.Compte); newDocFacture.('Type de document' := 18); newDocFacture.('Date de création' := today()); newDocFacture.(Transactions := loop); newDocFacture.('Nom du document' := nomFacture); newDocFacture.(Document := importFile(this, printAndSaveRecord(loop, "facture_dynamique"), nomFacture)) end end; 'Documents générés en masse' := true; 'Fichier zip généré' := false
Button to create the zip in the 'Fichier zip' field.
do as server 'Fichier zip' := createZipFile(this, (select Documents where 'Type de document' = 18).Document, "Factures.zip") end; 'Fichier zip généré' := true
Button to download the zip file.
let i := fileMetadata(this, last(split(text('Fichier zip'), "/"))); i.name; downloadURL(text(shareFile('Fichier zip')), text(i.name)); 'Zip téléchargé' := true
Button to delete all records that were created for invoice download. They are separated from other documents with "Type de document' := 18"
'Fichier zip' := null; --- Suppression des documents ---; do as server delete (select Documents where 'Type de document' = 18) end; --- Fin ---; 'Documents générés en masse' := false; 'Zip téléchargé' := false; 'Fichier zip supprimé' := true
Please note however that the zip file is deleted from 'Fichier zip' and will be moved to the paperclip.
Content aside
- Status Answered
- 11 days agoLast active
- 11Replies
- 71Views
-
4
Following