Client Statement Download PDF error function getTimestamp()

First of all, thank you for the great program. Secondly Sorry for posting in the wrong post @M4rt1n.

Ok, First I have searched the forum but could not get any answers I was looking for.
My Invoice Plane version is 1.5.10
PHP Version is 7.2
PHP Extensions are apcu, bcmath, dom, gd, imagick, imap, json, mbstring, mysqli, mysalnd, opcache, pdo, pdo_mysql, pdo_sqlite, pgsql, phar, posix, soap, sockets, tidy, timezondb, uploadprogress, wddx, xmlreader, xmlrpc, xmlwriter,xsl,zip

error Log ERRORS

<?php defined('BASEPATH') OR exit('No direct script access allowed'); ?>

ERROR - 2020-02-03 01:28:45 --> Could not find the language line “statement_password”
ERROR - 2020-02-03 01:28:45 --> Could not find the language line “statement_password”
ERROR - 2020-02-03 01:28:45 --> Could not find the language line “refresh”
ERROR - 2020-02-03 01:28:45 --> Could not find the language line “refresh”
ERROR - 2020-02-03 01:28:45 --> Could not find the language line “invoice_total”
ERROR - 2020-02-03 01:28:45 --> Could not find the language line “invoice_total”
ERROR - 2020-02-03 01:28:51 --> Severity: error --> Exception: Call to a member function getTimestamp() on boolean /application/modules/statements/controllers/Statements.php 328
ERROR - 2020-02-03 01:28:51 --> 404 Page Not Found: /index
ERROR - 2020-02-03 01:31:15 --> Could not find the language line “statement_password”
ERROR - 2020-02-03 01:31:15 --> Could not find the language line “statement_password”
ERROR - 2020-02-03 01:31:15 --> Could not find the language line “refresh”
ERROR - 2020-02-03 01:31:15 --> Could not find the language line “refresh”
ERROR - 2020-02-03 01:31:15 --> Could not find the language line “invoice_total”
ERROR - 2020-02-03 01:31:15 --> Could not find the language line “invoice_total”
ERROR - 2020-02-03 01:31:16 --> Could not find the language line “statement_password”
ERROR - 2020-02-03 01:31:16 --> Could not find the language line “statement_password”
ERROR - 2020-02-03 01:31:16 --> Could not find the language line “refresh”
ERROR - 2020-02-03 01:31:16 --> Could not find the language line “refresh”
ERROR - 2020-02-03 01:31:16 --> Could not find the language line “invoice_total”
ERROR - 2020-02-03 01:31:16 --> Could not find the language line “invoice_total”
ERROR - 2020-02-03 01:32:54 --> Severity: error --> Exception: Call to a member function getTimestamp() on boolean /application/modules/statements/controllers/Statements.php 69
ERROR - 2020-02-03 04:43:27 --> Could not find the language line “statement_password”
ERROR - 2020-02-03 04:43:27 --> Could not find the language line “statement_password”
ERROR - 2020-02-03 04:43:27 --> Could not find the language line “refresh”
ERROR - 2020-02-03 04:43:27 --> Could not find the language line “refresh”
ERROR - 2020-02-03 04:43:27 --> Could not find the language line “invoice_total”
ERROR - 2020-02-03 04:43:27 --> Could not find the language line “invoice_total”
ERROR - 2020-02-03 04:43:30 --> Could not find the language line “statement_password”
ERROR - 2020-02-03 04:43:30 --> Could not find the language line “statement_password”
ERROR - 2020-02-03 04:43:30 --> Could not find the language line “refresh”
ERROR - 2020-02-03 04:43:30 --> Could not find the language line “refresh”
ERROR - 2020-02-03 04:43:30 --> Could not find the language line “invoice_total”
ERROR - 2020-02-03 04:43:30 --> Could not find the language line “invoice_total”
ERROR - 2020-02-03 04:43:45 --> Severity: error --> Exception: Call to a member function getTimestamp() on boolean /application/modules/statements/controllers/Statements.php 328
ERROR - 2020-02-03 13:36:15 --> 404 Page Not Found:

There are two options that could be the case here.

  1. permission error (pls tell us the exact permission of the folder where IP is located in
  2. missing/uncomplete language files

Pretty sure its not part 2 but pls provide all infos.
Also pls turn on debug in ipconfig and try to run in the same error again for getting a more detailed error log.

Pls also tell us which langauge you are using and if you use InvoicePlane in stock version or any own templates?

@M4rt1n.

  1. permission on folders are as follows 0755
    Files they are 0644.
  2. The missing language I have fixed that problem, I’m using eng language.

the debug is enabled

Does that mean the problem is solved?

@M4rt1n, Sorry for the confusion. I have fixed the problem in the language file

any feedback on the solution on the problem. @M4rt1n. this would be a big plus for invoice plane if this could be fixed

What is a Statement?

I just downloaded the v1.5.10 zip and looked for the file it’s complaining about and there’s no folder called application/modules/statements in the zip.

My guess is that a statement is the same as an invoice, but you call it a statement for legal or taxation requirements in your country?

I checked the application/modules/invoice/controllers/Invoice.php file but it doesn’t contain a call to getTimestamp() anywhere, so I don’t know how to help with this until I know what a Statement is and how a folder for it gets into the application/modules folder.

Refer to this post.

https://community2.invoiceplane.com/t/topic/5156/12

The code in question is this :+1:

$date_time   = date_create_from_format("d M,Y", $this->input->post('statement_date_created'));
$statement_date   = $date_time->getTimestamp();  

$date_time returns a DateTime object. It is possible that the value supplied to first statement above was either incorrect on in a different format than expected. This will cause the built in PHP function date_create_from_format() to return false.

I should probably add a check for this.

@crafter, thanks for the explanation to @Cabji.

I have been trying to get a solution for this but I just cannot get it. Search the forum, Search Google. but with no luck. I have noticed that a lot of people have been requesting this. as this will make invoice plane a more rounded product for a lot of small to medium companies.

one thing is for sure they are doing a good job with invoice plane. if I get the script right will post my findings here. or should I say the solution here?

@M4rt1n, @Cabji, @crafter

Ok, so I started working on this again. in the statment.php file where this code is

$date_time = date_create_from_format(“d M,Y”, $this->input->post(‘statement_date_created’));
$statement_date = $date_time->getTimestamp();

around line 330 I changed it to the following

$date_time = date_create_from_format(‘Y-m-d H:i:s’, $this->input->post(‘statement_date_created’));
//$statement_date = $date_time->getTimestamp();
if ($date_time instanceof DateTime)
$statement_date = $date_time->getTimestamp();

as per the error, its a boolean and that got me thinking, boolean has if statment’s in it.

Well with that out of the way! I ran into a new error message :face_with_raised_eyebrow:
it stats that this function greate_pdf does not exist.
on line 351 generate_statement_pdf($client, $statement, $notes);

but function is there on line 306 till 353 see

public function generate_pdf()
{
    $this->load->model('clients/mdl_clients');
    $this->load->helper('country');
    $this->load->helper('pdf');

    $client_id              = $this->input->post('cid');
    $statement_number       = $this->input->post('statement_number');

    if (!empty($this->input->post('statement_start_date'))) {
        $statement_start_date   = strtotime($this->input->post('statement_start_date'));
        //$date_time   = date_create_from_format("d M,Y", $this->input->post('statement_start_date'));
        //$statement_start_date   = $date_time->getTimestamp();
  	

    } else {
        $statement_start_date   = strtotime($this->input->post('sdate'));
    }
    $statement_end_date     = strtotime($this->input->post('edate'));

    // BUG : strtotime is not recognising the date format d M,Y" and changing the date
    // $statement_date         = strtotime($this->input->post('statement_date_created'));
    //$date_time   = date_create_from_format("d M,Y", $this->input->post('statement_date_created'));
    $date_time   = date_create_from_format('Y-m-d H:i:s', $this->input->post('statement_date_created'));
    //$statement_date   = $date_time->getTimestamp();
  if ($date_time instanceof DateTime)

$statement_date = $date_time->getTimestamp();

    $notes                  = $this->input->post('notes');

    /*
     * Load the client
     */
    $client = $this->mdl_clients
        ->where('ip_clients.client_id', $client_id)
        ->get()->row();

    if (!$client) {
        show_404();
    }

    $statement = $this->build_statement($client->client_id, $statement_start_date, $statement_end_date);

    $this->load->helper('pdf');

    generate_statement_pdf($client, $statement, $notes);
}

This is fixed now pdf is generating, under pdf_helper.php I added the following code

function generate_quote_pdf($quote_id, $stream = true, $quote_template = null)
{
$CI = &get_instance();

$CI->load->model('quotes/mdl_quotes');
$CI->load->model('quotes/mdl_quote_items');
$CI->load->model('quotes/mdl_quote_tax_rates');
$CI->load->model('custom_fields/mdl_custom_fields');
$CI->load->helper('country');
$CI->load->helper('client');

$quote = $CI->mdl_quotes->get_by_id($quote_id);

// Override language with system language
set_language($quote->client_language);

if (!$quote_template) {
    $quote_template = $CI->mdl_settings->setting('pdf_quote_template');
}

// Determine if discounts should be displayed
$items = $CI->mdl_quote_items->where('quote_id', $quote_id)->get()->result();

$show_item_discounts = false;
foreach ($items as $item) {
    if ($item->item_discount != '0.00') {
        $show_item_discounts = true;
    }
}

// Get all custom fields
$custom_fields = array(
    'quote' => $CI->mdl_custom_fields->get_values_for_fields('mdl_quote_custom', $quote->quote_id),
    'client' => $CI->mdl_custom_fields->get_values_for_fields('mdl_client_custom', $quote->client_id),
    'user' => $CI->mdl_custom_fields->get_values_for_fields('mdl_user_custom', $quote->user_id),
);

$data = array(
    'quote' => $quote,
    'quote_tax_rates' => $CI->mdl_quote_tax_rates->where('quote_id', $quote_id)->get()->result(),
    'items' => $items,
    'output_type' => 'pdf',
    'show_item_discounts' => $show_item_discounts,
    'custom_fields' => $custom_fields,
);

$html = $CI->load->view('quote_templates/pdf/' . $quote_template, $data, true);

$CI->load->helper('mpdf');

return pdf_create($html, trans('quote') . '_' . str_replace(array('\\', '/'), '_', $quote->quote_number), $stream, $quote->quote_password);

}

And Now It Works :+1:

3 Likes

Wonderful work @Rhino13.

You should push a PR to the dev branch I created. I will pull this into my own dev branch and test. If all is well I can merge your changes into the branch.

1 Like

@Rhino13 if possible, in your code that you post here, if you can bold the parts that you alter it makes it a lot easier to see what needs to be altered.

EDIT: Also, great work!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.