diff --git a/app/Helpers/Invoice/InvoiceItemSum.php b/app/Helpers/Invoice/InvoiceItemSum.php index 96d1e6157937..12b9878b4775 100644 --- a/app/Helpers/Invoice/InvoiceItemSum.php +++ b/app/Helpers/Invoice/InvoiceItemSum.php @@ -88,9 +88,11 @@ class InvoiceItemSum return $this; } + /* Don't round the cost x qty - will allow us to use higher precision costs */ private function sumLineItem() { //todo need to support quantities less than the precision amount - $this->setLineTotal($this->formatValue($this->item->cost, $this->currency->precision) * $this->formatValue($this->item->quantity, $this->currency->precision)); + // $this->setLineTotal($this->formatValue($this->item->cost, $this->currency->precision) * $this->formatValue($this->item->quantity, $this->currency->precision)); + $this->setLineTotal($this->item->cost * $this->item->quantity); return $this; } @@ -112,8 +114,8 @@ class InvoiceItemSum { $item_tax = 0; - // info(print_r($this->item,1)); - // info(print_r($this->invoice,1)); + // nlog(print_r($this->item,1)); + // nlog(print_r($this->invoice,1)); $amount = $this->item->line_total - ($this->item->line_total * ($this->invoice->discount / 100)); $item_tax_rate1_total = $this->calcAmountLineTax($this->item->tax_rate1, $amount); diff --git a/app/Jobs/Util/SystemLogger.php b/app/Jobs/Util/SystemLogger.php index 788c0da466ee..74e467b023fe 100644 --- a/app/Jobs/Util/SystemLogger.php +++ b/app/Jobs/Util/SystemLogger.php @@ -33,7 +33,7 @@ class SystemLogger implements ShouldQueue protected $client; - public function __construct($log, $category_id, $event_id, $type_id, Client $client) + public function __construct($log, $category_id, $event_id, $type_id, ?Client $client) { $this->log = $log; $this->category_id = $category_id; diff --git a/app/Jobs/Util/WebhookHandler.php b/app/Jobs/Util/WebhookHandler.php index 60550ed9daef..60a5261b8a64 100644 --- a/app/Jobs/Util/WebhookHandler.php +++ b/app/Jobs/Util/WebhookHandler.php @@ -10,7 +10,9 @@ */ namespace App\Jobs\Util; +use App\Jobs\Util\SystemLogger; use App\Libraries\MultiDB; +use App\Models\SystemLog; use App\Models\Webhook; use App\Transformers\ArraySerializer; use GuzzleHttp\Client; @@ -113,6 +115,15 @@ class WebhookHandler implements ShouldQueue if ($response->getStatusCode() == 410 || $response->getStatusCode() == 200) { $subscription->delete(); } + + SystemLogger::dispatch( + $e->getMessage(), + SystemLog::CATEGORY_WEBHOOK, + SystemLog::EVENT_WEBHOOK_RESPONSE, + SystemLog::TYPE_WEBHOOK_RESPONSE, + $this->company->clients->first(), + ); + } public function failed($exception) diff --git a/app/Models/Presenters/CompanyPresenter.php b/app/Models/Presenters/CompanyPresenter.php index ed58bf40b35b..6cf7a76bf449 100644 --- a/app/Models/Presenters/CompanyPresenter.php +++ b/app/Models/Presenters/CompanyPresenter.php @@ -36,7 +36,7 @@ class CompanyPresenter extends EntityPresenter $settings = $this->entity->settings; } - return (strlen($settings->company_logo) > 0) ? url($settings->company_logo) : 'https://www.invoiceninja.com/wp-content/uploads/2019/01/InvoiceNinja-Logo-Round-300x300.png'; + return (strlen($settings->company_logo) > 0) ? url('') . $settings->company_logo : 'https://www.invoiceninja.com/wp-content/uploads/2019/01/InvoiceNinja-Logo-Round-300x300.png'; } public function address($settings = null) diff --git a/app/Models/SystemLog.php b/app/Models/SystemLog.php index 4e54d16ddd06..0be18903a7d6 100644 --- a/app/Models/SystemLog.php +++ b/app/Models/SystemLog.php @@ -33,6 +33,8 @@ class SystemLog extends Model /* Category IDs */ const CATEGORY_GATEWAY_RESPONSE = 1; const CATEGORY_MAIL = 2; + const CATEGORY_WEBHOOK = 3; + const CATEGORY_PDF = 3; /* Event IDs*/ const EVENT_PAYMENT_RECONCILIATION_FAILURE = 10; @@ -45,6 +47,9 @@ class SystemLog extends Model const EVENT_MAIL_SEND = 30; const EVENT_MAIL_RETRY_QUEUE = 31; //we use this to queue emails that are spooled and not sent due to the email queue quota being exceeded. + const EVENT_WEBHOOK_RESPONSE = 40; + const EVENT_PDF_RESPONSE = 50; + /*Type IDs*/ const TYPE_PAYPAL = 300; const TYPE_STRIPE = 301; @@ -56,6 +61,10 @@ class SystemLog extends Model const TYPE_QUOTA_EXCEEDED = 400; const TYPE_UPSTREAM_FAILURE = 401; + const TYPE_WEBHOOK_RESPONSE = 500; + const TYPE_PDF_FAILURE = 600; + const TYPE_PDF_SUCCESS = 601; + protected $fillable = [ 'client_id', 'company_id', diff --git a/app/Utils/PhantomJS/Phantom.php b/app/Utils/PhantomJS/Phantom.php index b3c10a274c94..50796ab5d381 100644 --- a/app/Utils/PhantomJS/Phantom.php +++ b/app/Utils/PhantomJS/Phantom.php @@ -11,10 +11,12 @@ namespace App\Utils\PhantomJS; +use App\Jobs\Util\SystemLogger; use App\Models\CreditInvitation; use App\Models\Design; use App\Models\InvoiceInvitation; use App\Models\QuoteInvitation; +use App\Models\SystemLog; use App\Services\PdfMaker\Design as PdfDesignModel; use App\Services\PdfMaker\Design as PdfMakerDesign; use App\Services\PdfMaker\PdfMaker as PdfMakerService; @@ -77,7 +79,7 @@ class Phantom $phantom_url = "https://phantomjscloud.com/api/browser/v2/{$key}/?request=%7Burl:%22{$url}%22,renderType:%22pdf%22%7D"; $pdf = CurlUtils::get($phantom_url); - // Storage::makeDirectory($path, 0775); + $this->checkMime($pdf, $invitation, $entity); $instance = Storage::disk(config('filesystems.default'))->put($file_path, $pdf); @@ -101,6 +103,36 @@ class Phantom return $response; } + /* Check if the returning PDF is valid. */ + private function checkMime($pdf, $invitation, $entity) + { + + $finfo = new \finfo(FILEINFO_MIME); + + if($finfo->buffer($pdf) != 'application/pdf; charset=binary') + { + SystemLogger::dispatch( + $pdf, + SystemLog::CATEGORY_PDF, + SystemLog::EVENT_PDF_RESPONSE, + SystemLog::TYPE_PDF_FAILURE, + $invitation->contact->client + ); + } + else { + + SystemLogger::dispatch( + "Entity PDF generated sucessfully => " . $invitation->{$entity}->number, + SystemLog::CATEGORY_PDF, + SystemLog::EVENT_PDF_RESPONSE, + SystemLog::TYPE_PDF_SUCCESS, + $invitation->contact->client + ); + + } + + } + public function displayInvitation(string $entity, string $invitation_key) { $key = $entity.'_id'; diff --git a/app/Utils/TemplateEngine.php b/app/Utils/TemplateEngine.php index f464de2b32e3..898a3044650c 100644 --- a/app/Utils/TemplateEngine.php +++ b/app/Utils/TemplateEngine.php @@ -150,11 +150,8 @@ class TemplateEngine private function entityValues($contact) { - //$data = $this->entity_obj->buildLabelsAndValues($contact); $data = (new HtmlEngine($this->entity_obj->invitations->first()))->generateLabelsAndValues(); - // $arrKeysLength = array_map('strlen', array_keys($data)); - // array_multisort($arrKeysLength, SORT_DESC, $data); $this->body = strtr($this->body, $data['labels']); $this->body = strtr($this->body, $data['values']); diff --git a/resources/views/email/partials/company_logo.blade.php b/resources/views/email/partials/company_logo.blade.php index d0bf15cde2dc..e842646897e2 100644 --- a/resources/views/email/partials/company_logo.blade.php +++ b/resources/views/email/partials/company_logo.blade.php @@ -3,7 +3,7 @@ @endif - + @if ($settings->website) diff --git a/resources/views/email/template/dark.blade.php b/resources/views/email/template/dark.blade.php index 5ebfe46d5a35..1ffda38a1533 100644 --- a/resources/views/email/template/dark.blade.php +++ b/resources/views/email/template/dark.blade.php @@ -1,7 +1,7 @@ @component('email.template.master', ['design' => 'dark', 'settings' => $settings, 'whitelabel' => $whitelabel]) @slot('header') - @component('email.components.header', ['p' => $body, 'logo' => $settings->company_logo ?: 'https://www.invoiceninja.com/wp-content/uploads/2019/01/InvoiceNinja-Logo-Round-300x300.png']) + @component('email.components.header', ['p' => $body, 'logo' => (strlen($settings->company_logo) > 1) ? url('') . $settings->company_logo : 'https://www.invoiceninja.com/wp-content/uploads/2019/01/InvoiceNinja-Logo-Round-300x300.png']) @if(isset($title)) {{$title}} diff --git a/resources/views/email/template/light.blade.php b/resources/views/email/template/light.blade.php index a95799e9e282..3fcfa139405c 100644 --- a/resources/views/email/template/light.blade.php +++ b/resources/views/email/template/light.blade.php @@ -1,7 +1,7 @@ @component('email.template.master', ['design' => 'light', 'settings' => $settings, 'whitelabel' => $whitelabel]) @slot('header') - @component('email.components.header', ['p' => $body, 'logo' => $settings->company_logo ?: 'https://www.invoiceninja.com/wp-content/uploads/2019/01/InvoiceNinja-Logo-Round-300x300.png']) + @component('email.components.header', ['p' => $body, 'logo' => (strlen($settings->company_logo) > 1) ? url('') . $settings->company_logo : 'https://www.invoiceninja.com/wp-content/uploads/2019/01/InvoiceNinja-Logo-Round-300x300.png']) @if(isset($title)) {{$title}} diff --git a/resources/views/header.blade.php b/resources/views/header.blade.php deleted file mode 100644 index f584d1bee202..000000000000 --- a/resources/views/header.blade.php +++ /dev/null @@ -1,137 +0,0 @@ - - -
\ No newline at end of file diff --git a/resources/views/portal/ninja2020/components/general/sidebar/desktop.blade.php b/resources/views/portal/ninja2020/components/general/sidebar/desktop.blade.php index cd8b6854ae24..acb371424aaf 100644 --- a/resources/views/portal/ninja2020/components/general/sidebar/desktop.blade.php +++ b/resources/views/portal/ninja2020/components/general/sidebar/desktop.blade.php @@ -2,7 +2,7 @@
- {{ config('app.name') }} + {{ config('app.name') }}