Support collected invoice economic PDF downloads
This commit is contained in:
+33
-5
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user