From 8ec47921aafd260d5c8a2812a4a7de5f9038ed6b Mon Sep 17 00:00:00 2001 From: David Bomba Date: Sun, 5 Jul 2020 21:39:59 +1000 Subject: [PATCH] Fixes for Invoice PDF Preview --- app/Http/Controllers/PreviewController.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/app/Http/Controllers/PreviewController.php b/app/Http/Controllers/PreviewController.php index 750a76476e..af98d00b76 100644 --- a/app/Http/Controllers/PreviewController.php +++ b/app/Http/Controllers/PreviewController.php @@ -18,6 +18,7 @@ use App\Jobs\Invoice\CreateInvoicePdf; use App\Jobs\Util\PreviewPdf; use App\Utils\Traits\MakesHash; use App\Utils\Traits\MakesInvoiceHtml; +use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Response; use Illuminate\Support\Facades\Storage; @@ -127,6 +128,8 @@ class PreviewController extends BaseController private function blankEntity() { + DB::beginTransaction(); + $client = factory(\App\Models\Client::class)->create([ 'user_id' => auth()->user()->id, 'company_id' => auth()->user()->company()->id, @@ -156,15 +159,13 @@ class PreviewController extends BaseController return response()->json(['message' => 'Invalid custom design object'], 400); } - $designer = new Designer($invoice, $design_object, auth()->user()->company()->settings->pdf_variables, lcfirst(request()->has('entity'))); + $designer = new Designer($invoice, $design_object, auth()->user()->company()->settings->pdf_variables, lcfirst(request()->input('entity'))); $html = $this->generateEntityHtml($designer, $invoice, $contact); $file_path = PreviewPdf::dispatchNow($html, auth()->user()->company()); - $invoice->forceDelete(); - $contact->forceDelete(); - $client->forceDelete(); + DB::rollBack(); $response = Response::make($file_path, 200); $response->header('Content-Type', 'application/pdf');