Whoops, looks like something went wrong after sending invoice by email

Hi all,

I have a problem, everytime I send a Invoice by email I get this nice ;( errror

Whoops, looks like something went wrong

I get e notification that the invoce is send but i’m not sure if this is correct.
I try to use smtp, send mail but both give me the same error. Can anybode help me ?

There should be more details about the error in the logs in storage/logs/

Hi Hillen,

There is a lot of info in the logfiles.
There are three files error, info and warnings. Can i clear the files and run a test, see if there is a error that i can understand.

That’s a good plan, the relevant info should be in the error file.

BTW, the email is send and attachment is oke but the link is not working.

From the error it looks like it’s related to the iOS notifications.

I’ve reached out to our iOS developer for more info.

Can you try adding return false; at the top of the sendNotification function in app/Services/PushService.php

Don’t Know where you meen,

// start paul

<?php

namespace App\Services;

use Illuminate\Http\Request;
use App\Ninja\Notifications\PushFactory;
/**

  • Class PushService
  • @package App\Ninja\Notifications
    */

/**

  • $account->devices Definition
  • @param string token (push notification device token)
  • @param string email (user email address - required for use as key)
  • @param string device (ios, gcm etc etc)
  • @param bool notify_sent
  • @param bool notify_paid
  • @param bool notify_approved
  • @param bool notify_viewed
    */

class PushService
{
protected $pushFactory;

/**
 * @param PushFactory $pushFactory
 */
public function __construct(PushFactory $pushFactory)
{
    $this-&gt;pushFactory = $pushFactory;
}

/**
 * @param $invoice - Invoice object
 * @param $type - Type of notification, ie. Quote APPROVED, Invoice PAID, Invoice/Quote SENT, Invoice/Quote VIEWED
 */

public function sendNotification($invoice, $type)
{
    //check user has registered for push notifications
    if(!$this-&gt;checkDeviceExists($invoice-&gt;account))
        return;

    //Harvest an array of devices that are registered for this notification type
    $devices = json_decode($invoice-&gt;account-&gt;devices, TRUE);

    foreach($devices as $device)
    {
        if(($device["notify_{$type}"] == TRUE) &amp;&amp; ($device['device'] == 'ios'))
            $this-&gt;pushMessage($invoice, $device['token'], $type);
    }


}


/**
 * pushMessage function
 *
 * method to dispatch iOS notifications
 *
 * @param $invoice
 * @param $token
 * @param $type
 */
private function pushMessage($invoice, $token, $type)
{
    $this-&gt;pushFactory-&gt;message($token, $this-&gt;messageType($invoice, $type));
}


/**
 * checkDeviceExists function
 *
 * Returns a boolean if this account has devices registered for PUSH notifications
 *
 * @param $account
 * @return bool
 */
private function checkDeviceExists($account)
{
    $devices = json_decode($account-&gt;devices, TRUE);

    if(count($devices) &gt;= 1)
        return TRUE;
    else
        return FALSE;
}

/**
 * messageType function
 *
 * method which formats an appropriate message depending on message type
 *
 * @param $invoice
 * @param $type
 * @return string
 */
private function messageType($invoice, $type)
{
    switch($type)
    {
        case 'sent':
            return $this-&gt;entitySentMessage($invoice);
            break;

        case 'paid':
            return $this-&gt;invoicePaidMessage($invoice);
            break;

        case 'approved':
            return $this-&gt;quoteApprovedMessage($invoice);
            break;

        case 'viewed':
            return $this-&gt;entityViewedMessage($invoice);
            break;
    }
}

/**
 * @param $invoice
 * @return string
 */
private function entitySentMessage($invoice)
{
    if($invoice-&gt;is_quote)
        return trans("texts.notification_quote_sent_subject", ['invoice' =&gt; $invoice-&gt;invoice_number, 'client' =&gt; $invoice-&gt;client-&gt;name]);
    else
        return trans("texts.notification_invoice_sent_subject", ['invoice' =&gt; $invoice-&gt;invoice_number, 'client' =&gt; $invoice-&gt;client-&gt;name]);

}

/**
 * @param $invoice
 * @return string
 */
private function invoicePaidMessage($invoice)
{
    return trans("texts.notification_invoice_paid_subject", ['invoice' =&gt; $invoice-&gt;invoice_number, 'client' =&gt; $invoice-&gt;client-&gt;name]);
}

/**
 * @param $invoice
 * @return string
 */
private function quoteApprovedMessage($invoice)
{
    return trans("texts.notification_quote_approved_subject", ['invoice' =&gt; $invoice-&gt;invoice_number, 'client' =&gt; $invoice-&gt;client-&gt;name]);
}

/**
 * @param $invoice
 * @return string
 */
private function entityViewedMessage($invoice)
{
    if($invoice-&gt;is_quote)
        return trans("texts.notification_quote_viewed_subject", ['invoice' =&gt; $invoice-&gt;invoice_number, 'client' =&gt; $invoice-&gt;client-&gt;name]);
    else
        return trans("texts.notification_invoice_viewed_subject", ['invoice' =&gt; $invoice-&gt;invoice_number, 'client' =&gt; $invoice-&gt;client-&gt;name]);

}

}

//end paul

BTW can you delete reply #2916 this post is become monster long :))

Try changing

public function sendNotification($invoice, $type)
{
//check user has registered for push notifications
if(!$this->checkDeviceExists($invoice->account))
return;
//Harvest an array of devices that are registered for this notification type
$devices = json_decode($invoice->account->devices, TRUE);
foreach($devices as $device)
{
if(($device[“notify_{$type}”] == TRUE) && ($device[‘device’] == ‘ios’))
$this->pushMessage($invoice, $device[‘token’], $type);
}
}

To

public function sendNotification($invoice, $type)
{
return false;
//check user has registered for push notifications
if(!$this->checkDeviceExists($invoice->account))
return;
//Harvest an array of devices that are registered for this notification type
$devices = json_decode($invoice->account->devices, TRUE);
foreach($devices as $device)
{
if(($device[“notify_{$type}”] == TRUE) && ($device[‘device’] == ‘ios’))
$this->pushMessage($invoice, $device[‘token’], $type);
}
}

yeyeeeeeaaahee, that did the trick, Your great Hillel :wink: thx

Thanks for letting us know, we’ll include this fix with our next release.

I have one last quetion,

[2016-05-17 10:24:29] production.WARNING: Entity not set in client repo save [] []

What is this?

It can be ignored. We’re working to refactor some code and are using these warnings to help ensure we don’t miss any code paths.