Support collected invoice economic PDF downloads

This commit is contained in:
Jeppe B
2026-07-14 15:39:39 +02:00
parent 69b3bf83c4
commit 0feb705059
23 changed files with 3253 additions and 136 deletions
@@ -9,21 +9,49 @@ class economic_invoices_pdf_endpoint
use economic_endpoint_t;
/**
* Get a PDF of a booked invoice
* Get a PDF of a booked invoice.
*
* Kept as the legacy alias used by existing invoice download flows.
* @param int $id
* @return string
*/
public function get(int $id): string
{
return $this->getBooked($id);
}
/**
* Get a PDF of a booked invoice.
* @param int $id
* @return string
*/
public function getBooked(int $id): string
{
return $this->downloadPdf('/invoices/booked/' . $id . '/pdf', 'booked_invoice_');
}
/**
* Get a PDF of a draft invoice.
* @param int $id
* @return string
*/
public function getDraft(int $id): string
{
return $this->downloadPdf('/invoices/drafts/' . $id . '/pdf', 'draft_invoice_');
}
private function downloadPdf(string $path, string $prefix): string
{
$unique_id = uniqid();
$file_path = '/tmp/' . $prefix . $unique_id . '.pdf';
$this->send_file_download_request(
'/invoices/booked/' . $id . '/pdf',
$path,
'GET',
'',
false,
'/tmp/invoice_' . $unique_id . '.pdf'
$file_path
);
return '/tmp/invoice_' . $unique_id . '.pdf';
return $file_path;
}
}
}