Jump to content

automatically generate invoices in a folder


agm65

Recommended Posts

Hello,

 

is there a way to automatically generate invoices and make them available in a folder for FTP access by other sw?

 

If yes, can I force the file name? For example, instead of the invoice number to use <ORDER_NUMBER> .pdf?

 

Thank you

  • Like 1
Link to comment
Share on other sites

Do you want to bulk generate them for all your orders or setup an automatic job for the next ones?

To make it automatic to save all your orders' pdfs, you need to edit root/tools/tcpdf/tcpdf.php:

protected function sendOutputData($data, $length) {
    if (!isset($_SERVER['HTTP_ACCEPT_ENCODING']) OR empty($_SERVER['HTTP_ACCEPT_ENCODING'])) {
        // the content length may vary if the server is using compression
        header('Content-Length: '.$length);
    }
              
    //save to disk if it is a PDF about an order  
    $id_order = Tools::getValue('id_order');
    if ($id_order)
        file_put_contents(_PS_ROOT_DIR_."your/path/to/pdfs/order-{$id_order}.pdf", $data);

    echo $data;
}
Edited by SimoneS93 (see edit history)
  • Like 1
Link to comment
Share on other sites

 

Do you want to bulk generate them for all your orders or setup an automatic job for the next ones?

To make it automatic to save all your orders' pdfs, you need to edit root/tools/tcpdf/tcpdf.php:

protected function sendOutputData($data, $length) {
    if (!isset($_SERVER['HTTP_ACCEPT_ENCODING']) OR empty($_SERVER['HTTP_ACCEPT_ENCODING'])) {
        // the content length may vary if the server is using compression
        header('Content-Length: '.$length);
    }
              
    //save to disk if it is a PDF about an order  
    $id_order = Tools::getValue('id_order');
    if ($id_order)
        file_put_contents(_PS_ROOT_DIR_."your/path/to/pdfs/order-{$id_order}.pdf", $data);

    echo $data;
}

Thank you SimoneS93,

 

yes I want an automatic job that generates invoices when an order is ok (and not when an user clicks on pdf icons)

I've a cron process that gets (by FTP) all orders (CSV files) and I want to make available all invoices also.

 

ex

/docs_folder/

- orders.csv

- invoice-0001.pdf

- invoice-0003.pdf

...

- invoice-<order_number>.pdf

...

Link to comment
Share on other sites

To generate pdf when order is ok you must override PaymentModule::validateOrder, something like this:

public function validateOrder($function_arguments_here) {
    $ret = parent::validateOrder($function_arguments_here);

    //call AdminPdfController as if you clicked the PDF icon
    //you may need to copy-paste here the code and pass a different parameter to $pdf->render()
    //to prevent downloading the PDF. Cant test now
    if ($this->currentOrder) {
        $_GET['id_order'] = $this->currentOrder->id;
        AdminPdfController::processGenerateInvoicePdf();
    }

    return $ret;
}
  • Like 1
Link to comment
Share on other sites

 

To generate pdf when order is ok you must override PaymentModule::validateOrder, something like this:

public function validateOrder($function_arguments_here) {
    $ret = parent::validateOrder($function_arguments_here);

    //call AdminPdfController as if you clicked the PDF icon
    //you may need to copy-paste here the code and pass a different parameter to $pdf->render()
    //to prevent downloading the PDF. Cant test now
    if ($this->currentOrder) {
        $_GET['id_order'] = $this->currentOrder->id;
        AdminPdfController::processGenerateInvoicePdf();
    }

    return $ret;
}

Oh, thank you!

 

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...