Using Ninja on PHP 7.4

So I turned app_debug=true on the old V4.5.19 prior to going through migration. I received the following error message in the laravel.log on the old version:

production.ERROR: ErrorException [0] : /var/www/tools/ninja/storage/framework/views/2dda033f1f1cc1b5912a4fbf9e6449082afd9145.php [Line 4] => Array to string conversion (View: /var/www/tools/ninja/resources/views/migration/includes/errors.blade.php) (View: /var/www/tools/ninja/resources/views/migration/includes/errors.blade.php) {“context”:“PHP”,“user_id”:1,“account_id”:1,“user_name”:“Curtis Fuller”,“method”:“GET”,“user_agent”:“Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.121 Safari/537.36”,“locale”:“en”,“ip”:“35.141.98.216”,“count”:2,“is_console”:“no”,“is_api”:“no”,“db_server”:“mysql”,“url”:“migration/auth”} []

I am not sure what to try next with that error.

I did receive a lot longer error log in the browser. I printed it and have posted it to DropBox, it can be accessed here: https://www.dropbox.com/s/s2xchogx8b3skog/ninja-error.pdf?dl=0 (Only available for the next two days).

What should I try next?

@cfullerbhope-org

the DB Connection error is the common theme here, there is something with your DB connection that is causing the failure

SQLSTATE[HY000] [1045] Access denied for user
‘ninja5_app’@‘10.0.0.245’ (

I have started over again, removed everything and changed the database user / password to the admin account and that seems to have helped. Apparently the database user must be the same between the two installations as well. Also, I had to select the “Force Migration” option on the v4.5.19 migration tool to get it to work.

I am now able to get into v5. All of the clients are listed, and their total due. However, there is no “Invoice” listed in the menu, and I can’t find any way of listing the actual invoices. When I switch back to the original “Unititled” business that was added during installation, invoices are listed there.

In the Laravel.log file during the migration an error was logged:

production.ERROR: Division by zero {"userId":1,"exception":"[object] (ErrorException(code: 0): Division by zero at /data/www/live/ninja5/app/Helpers/Invoice/InvoiceItemSum.php:233)

I looked back at the old database and we do have some invoices with either Amt $0 or Qty 0 which could have made the subtotal $0, which could have caused the divide by zero error on that line of the code.

Could this error have caused the invoice option to not be available in V5? Is there anything I can do to restore it?

I tried running php artistan optimize as well as php artisan ninja:check-data and they did not fix, but the later did create many errors which were: “balances do not match Invoice Amount”

Also, I don’t know if I’m missing it, but I can’t find a way to log out of V5.

Thank you!

After analyzing some of the errors and looking at the code, I was able to make two code changes to finally get the migration to work.

I changed /app/Helpers/Invoice/InvoiceItemSum.php line 233 from:

$amount = $this->item->line_total - ($this->item->line_total * ($this->invoice->discount / $this->sub_total)); 

to:

$amount = ( $this->sub_total > 0 ) ? $this->item->line_total - ($this->item->line_total * ($this->invoice->discount / $this->sub_total)) : 0;

And then I changed /app/Utils/Traits/MakesInvoiceValues.php line 216

$data['$view_link'] = ['value' => '<a href="'.$invitation->getLink().'">'.ctrans('texts.view_invoice').'</a>', 'label' => ctrans('texts.view_invoice')];

to:

if(is_object($invitation)) { $data['$view_link'] = ['value' => '<a href="'.$invitation->getLink().'">'.ctrans('texts.view_invoice').'</a>', 'label' => ctrans('texts.view_invoice')]; } else { $data['$view_link'] = ['value' => Null, 'label' => ctrans('texts.view_invoice')];  }

(The second change was because it was trying to do this on Null for something that wasn’t loaded correctly).

I then had to go in to Settings and account management, and then click on the “Modules” tab and turn on invoices and reoccurring invoices.

I am now having a problem that it will not generate the PDF invoices, but I’ll search the forum for others and if I can’t find anything I’ll start a new thread.

1 Like

@cfullerbhope-org

Thanks for the update! Yes, the div/0 looks like a bug picked up on your migration, i’ll add this into the backlog for fixes.

In regards to the PDF, does your system have NPM/Node installed? The most common issue we see in regards to PDF generation is either permissions issues, or NPM/puppeteer not installed correctly on the system, we do have a section for this in the install guide here:

https://invoiceninja.github.io/selfhost.html#pdfs-not-generating-timeouts

Regarding the PDF generation, I started new topic just for that issue since this one was getting long: Generating a PDF.

I’ll respond to your NPM/Node suggestion their.