diff --git a/app/Http/Controllers/ActivityController.php b/app/Http/Controllers/ActivityController.php index 19c31d2aa453..f6e97b7e01f6 100644 --- a/app/Http/Controllers/ActivityController.php +++ b/app/Http/Controllers/ActivityController.php @@ -142,11 +142,11 @@ class ActivityController extends BaseController $pdf = $this->makePdf(null, null, $backup->html_backup); if (isset($activity->invoice_id)) { - $filename = $activity->invoice->number.'.pdf'; + $filename = $activity->invoice->numberFormatter().'.pdf'; } elseif (isset($activity->quote_id)) { - $filename = $activity->quote->number.'.pdf'; + $filename = $activity->quote->numberFormatter().'.pdf'; } elseif (isset($activity->credit_id)) { - $filename = $activity->credit->number.'.pdf'; + $filename = $activity->credit->numberFormatter().'.pdf'; } else { $filename = 'backup.pdf'; } diff --git a/app/Jobs/Entity/CreateEntityPdf.php b/app/Jobs/Entity/CreateEntityPdf.php index acf4331dbba2..03886ce5e402 100644 --- a/app/Jobs/Entity/CreateEntityPdf.php +++ b/app/Jobs/Entity/CreateEntityPdf.php @@ -115,7 +115,7 @@ class CreateEntityPdf implements ShouldQueue $entity_design_id = 'invoice_design_id'; } - $file_path = $path.$this->entity->number.'.pdf'; + $file_path = $path.$this->entity->numberFormatter().'.pdf'; $entity_design_id = $this->entity->design_id ? $this->entity->design_id : $this->decodePrimaryKey($this->entity->client->getSetting($entity_design_id)); diff --git a/app/Models/BaseModel.php b/app/Models/BaseModel.php index d8a087fb2aa7..8d818643d6bb 100644 --- a/app/Models/BaseModel.php +++ b/app/Models/BaseModel.php @@ -186,6 +186,15 @@ class BaseModel extends Model */ public function getFileName($extension = 'pdf') { - return $this->number.'.'.$extension; + return $this->numberFormatter().'.'.$extension; + } + + public function numberFormatter() + { + $formatted_number = mb_ereg_replace("([^\w\s\d\-_~,;\[\]\(\).])", '', $this->number); + // Remove any runs of periods (thanks falstro!) + $formatted_number = mb_ereg_replace("([\.]{2,})", '', $formatted_number); + + return $formatted_number; } } diff --git a/app/Models/Credit.php b/app/Models/Credit.php index 8acf5a3dd9eb..b6c67eeb1bc7 100644 --- a/app/Models/Credit.php +++ b/app/Models/Credit.php @@ -248,9 +248,9 @@ class Credit extends BaseModel public function pdf_file_path($invitation = null) { - $storage_path = Storage::url($this->client->credit_filepath().$this->number.'.pdf'); + $storage_path = Storage::url($this->client->credit_filepath().$this->numberFormatter().'.pdf'); - if (Storage::exists($this->client->credit_filepath().$this->number.'.pdf')) { + if (Storage::exists($this->client->credit_filepath().$this->numberFormatter().'.pdf')) { return $storage_path; } diff --git a/app/Models/CreditInvitation.php b/app/Models/CreditInvitation.php index affacbac4a89..8f5f9f7744f4 100644 --- a/app/Models/CreditInvitation.php +++ b/app/Models/CreditInvitation.php @@ -126,9 +126,9 @@ class CreditInvitation extends BaseModel public function pdf_file_path() { - $storage_path = Storage::url($this->credit->client->quote_filepath().$this->credit->number.'.pdf'); + $storage_path = Storage::url($this->credit->client->quote_filepath().$this->credit->numberFormatter().'.pdf'); - if (! Storage::exists($this->credit->client->credit_filepath().$this->credit->number.'.pdf')) { + if (! Storage::exists($this->credit->client->credit_filepath().$this->credit->numberFormatter().'.pdf')) { event(new CreditWasUpdated($this, $this->company, Ninja::eventVars())); CreateEntityPdf::dispatchNow($this); } diff --git a/app/Models/Invoice.php b/app/Models/Invoice.php index 22a9698a5bd4..ccfd120c35c8 100644 --- a/app/Models/Invoice.php +++ b/app/Models/Invoice.php @@ -388,9 +388,9 @@ class Invoice extends BaseModel $invitation = $this->invitations->first(); } - $storage_path = Storage::$type($this->client->invoice_filepath().$this->number.'.pdf'); + $storage_path = Storage::$type($this->client->invoice_filepath().$this->numberFormatter().'.pdf'); - if (! Storage::exists($this->client->invoice_filepath().$this->number.'.pdf')) { + if (! Storage::exists($this->client->invoice_filepath().$this->numberFormatter().'.pdf')) { event(new InvoiceWasUpdated($this, $this->company, Ninja::eventVars())); CreateEntityPdf::dispatchNow($invitation); } diff --git a/app/Models/InvoiceInvitation.php b/app/Models/InvoiceInvitation.php index 42b4ef11a36c..17417106e0bb 100644 --- a/app/Models/InvoiceInvitation.php +++ b/app/Models/InvoiceInvitation.php @@ -140,9 +140,9 @@ class InvoiceInvitation extends BaseModel public function pdf_file_path() { - $storage_path = Storage::url($this->invoice->client->invoice_filepath().$this->invoice->number.'.pdf'); + $storage_path = Storage::url($this->invoice->client->invoice_filepath().$this->invoice->numberFormatter().'.pdf'); - if (! Storage::exists($this->invoice->client->invoice_filepath().$this->invoice->number.'.pdf')) { + if (! Storage::exists($this->invoice->client->invoice_filepath().$this->invoice->numberFormatter().'.pdf')) { event(new InvoiceWasUpdated($this->invoice, $this->company, Ninja::eventVars())); CreateEntityPdf::dispatchNow($this); } diff --git a/app/Models/Quote.php b/app/Models/Quote.php index 2f0c414ec75b..23992250887e 100644 --- a/app/Models/Quote.php +++ b/app/Models/Quote.php @@ -208,11 +208,11 @@ class Quote extends BaseModel $invitation = $this->invitations->first(); } - $storage_path = Storage::$type($this->client->quote_filepath().$this->number.'.pdf'); + $storage_path = Storage::$type($this->client->quote_filepath().$this->numberFormatter().'.pdf'); nlog($storage_path); - if (! Storage::exists($this->client->quote_filepath().$this->number.'.pdf')) { + if (! Storage::exists($this->client->quote_filepath().$this->numberFormatter().'.pdf')) { event(new QuoteWasUpdated($this, $this->company, Ninja::eventVars())); CreateEntityPdf::dispatchNow($invitation); } diff --git a/app/Models/QuoteInvitation.php b/app/Models/QuoteInvitation.php index 14fb1cbd52d9..74871dd05da0 100644 --- a/app/Models/QuoteInvitation.php +++ b/app/Models/QuoteInvitation.php @@ -130,9 +130,9 @@ class QuoteInvitation extends BaseModel public function pdf_file_path() { - $storage_path = Storage::url($this->quote->client->quote_filepath().$this->quote->number.'.pdf'); + $storage_path = Storage::url($this->quote->client->quote_filepath().$this->quote->numberFormatter().'.pdf'); - if (! Storage::exists($this->quote->client->quote_filepath().$this->quote->number.'.pdf')) { + if (! Storage::exists($this->quote->client->quote_filepath().$this->quote->numberFormatter().'.pdf')) { event(new QuoteWasUpdated($this->quote, $this->company, Ninja::eventVars())); CreateEntityPdf::dispatchNow($this); } diff --git a/app/Observers/InvoiceObserver.php b/app/Observers/InvoiceObserver.php index 260629be76d5..db104603dbf6 100644 --- a/app/Observers/InvoiceObserver.php +++ b/app/Observers/InvoiceObserver.php @@ -52,7 +52,7 @@ class InvoiceObserver WebhookHandler::dispatch(Webhook::EVENT_UPDATE_INVOICE, $invoice, $invoice->company); } - // UnlinkFile::dispatchNow(config('filesystems.default'), $invoice->client->invoice_filepath() . $invoice->number.'.pdf'); + // UnlinkFile::dispatchNow(config('filesystems.default'), $invoice->client->invoice_filepath() . $invoice->numberFormatter().'.pdf'); } diff --git a/app/Services/Credit/CreditService.php b/app/Services/Credit/CreditService.php index 4af43a348363..a07e572eb295 100644 --- a/app/Services/Credit/CreditService.php +++ b/app/Services/Credit/CreditService.php @@ -140,7 +140,7 @@ class CreditService public function deletePdf() { - UnlinkFile::dispatchNow(config('filesystems.default'), $this->credit->client->credit_filepath() . $this->credit->number.'.pdf'); + UnlinkFile::dispatchNow(config('filesystems.default'), $this->credit->client->credit_filepath() . $this->credit->numberFormatter().'.pdf'); return $this; } diff --git a/app/Services/Credit/GetCreditPdf.php b/app/Services/Credit/GetCreditPdf.php index 50be6f6a4c16..96bb0f818e7d 100644 --- a/app/Services/Credit/GetCreditPdf.php +++ b/app/Services/Credit/GetCreditPdf.php @@ -38,7 +38,7 @@ class GetCreditPdf extends AbstractService $path = $this->credit->client->credit_filepath(); - $file_path = $path.$this->credit->number.'.pdf'; + $file_path = $path.$this->credit->numberFormatter().'.pdf'; $disk = config('filesystems.default'); diff --git a/app/Services/Invoice/GetInvoicePdf.php b/app/Services/Invoice/GetInvoicePdf.php index 4fe48bbaad22..96917d16f2d6 100644 --- a/app/Services/Invoice/GetInvoicePdf.php +++ b/app/Services/Invoice/GetInvoicePdf.php @@ -37,7 +37,7 @@ class GetInvoicePdf extends AbstractService $path = $this->invoice->client->invoice_filepath(); - $file_path = $path.$this->invoice->number.'.pdf'; + $file_path = $path.$this->invoice->numberFormatter().'.pdf'; $disk = config('filesystems.default'); diff --git a/app/Services/Invoice/InvoiceService.php b/app/Services/Invoice/InvoiceService.php index 66e5c176cad2..755291c8e572 100644 --- a/app/Services/Invoice/InvoiceService.php +++ b/app/Services/Invoice/InvoiceService.php @@ -274,8 +274,8 @@ class InvoiceService public function deletePdf() { - //UnlinkFile::dispatchNow(config('filesystems.default'), $this->invoice->client->invoice_filepath() . $this->invoice->number.'.pdf'); - Storage::disk(config('filesystems.default'))->delete($this->invoice->client->invoice_filepath() . $this->invoice->number.'.pdf'); + //UnlinkFile::dispatchNow(config('filesystems.default'), $this->invoice->client->invoice_filepath() . $this->invoice->numberFormatter().'.pdf'); + Storage::disk(config('filesystems.default'))->delete($this->invoice->client->invoice_filepath() . $this->invoice->numberFormatter().'.pdf'); return $this; } diff --git a/app/Services/Quote/GetQuotePdf.php b/app/Services/Quote/GetQuotePdf.php index 63eb15ef5dca..582664aaacd1 100644 --- a/app/Services/Quote/GetQuotePdf.php +++ b/app/Services/Quote/GetQuotePdf.php @@ -36,7 +36,7 @@ class GetQuotePdf extends AbstractService $path = $this->quote->client->quote_filepath(); - $file_path = $path.$this->quote->number.'.pdf'; + $file_path = $path.$this->quote->numberFormatter().'.pdf'; $disk = config('filesystems.default'); diff --git a/app/Services/Quote/QuoteService.php b/app/Services/Quote/QuoteService.php index 642b9c594992..b7684620827e 100644 --- a/app/Services/Quote/QuoteService.php +++ b/app/Services/Quote/QuoteService.php @@ -178,7 +178,7 @@ class QuoteService public function deletePdf() { - UnlinkFile::dispatchNow(config('filesystems.default'), $this->quote->client->quote_filepath() . $this->quote->number.'.pdf'); + UnlinkFile::dispatchNow(config('filesystems.default'), $this->quote->client->quote_filepath() . $this->quote->numberFormatter().'.pdf'); return $this; } diff --git a/app/Services/Recurring/RecurringService.php b/app/Services/Recurring/RecurringService.php index 00811fa404ff..65c80791ff0b 100644 --- a/app/Services/Recurring/RecurringService.php +++ b/app/Services/Recurring/RecurringService.php @@ -87,7 +87,7 @@ class RecurringService public function deletePdf() { - UnlinkFile::dispatchNow(config('filesystems.default'), $this->recurring_entity->client->recurring_invoice_filepath() . $this->recurring_entity->number.'.pdf'); + UnlinkFile::dispatchNow(config('filesystems.default'), $this->recurring_entity->client->recurring_invoice_filepath() . $this->recurring_entity->numberFormatter().'.pdf'); return $this; } diff --git a/app/Utils/PhantomJS/Phantom.php b/app/Utils/PhantomJS/Phantom.php index 4c605273227a..3f2945cfbb42 100644 --- a/app/Utils/PhantomJS/Phantom.php +++ b/app/Utils/PhantomJS/Phantom.php @@ -76,7 +76,7 @@ class Phantom $path = $entity_obj->client->recurring_invoice_filepath(); } - $file_path = $path.$entity_obj->number.'.pdf'; + $file_path = $path.$entity_obj->numberFormatter().'.pdf'; $url = config('ninja.app_url').'/phantom/'.$entity.'/'.$invitation->key.'?phantomjs_secret='.config('ninja.phantomjs_secret'); info($url); @@ -91,8 +91,8 @@ class Phantom $instance = Storage::disk(config('filesystems.default'))->put($file_path, $pdf); -nlog($instance); -nlog($file_path); +// nlog($instance); +// nlog($file_path); return $file_path; }