From 37682d6f305e7efb5160e6309d685ea3da0a8c12 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Mon, 31 Oct 2022 07:50:29 +1100 Subject: [PATCH] Merge PDFs --- app/Http/Controllers/CreditController.php | 15 +++++++++++++++ app/Http/Controllers/InvoiceController.php | 1 - app/Http/Controllers/PurchaseOrderController.php | 15 +++++++++++++++ app/Http/Controllers/QuoteController.php | 15 +++++++++++++++ 4 files changed, 45 insertions(+), 1 deletion(-) diff --git a/app/Http/Controllers/CreditController.php b/app/Http/Controllers/CreditController.php index 55a1d03aad..30104c8c9f 100644 --- a/app/Http/Controllers/CreditController.php +++ b/app/Http/Controllers/CreditController.php @@ -33,6 +33,7 @@ use App\Models\Client; use App\Models\Credit; use App\Models\Invoice; use App\Repositories\CreditRepository; +use App\Services\PdfMaker\PdfMerge; use App\Transformers\CreditTransformer; use App\Utils\Ninja; use App\Utils\TempFile; @@ -534,6 +535,20 @@ class CreditController extends BaseController return response()->json(['message' => ctrans('texts.sent_message')], 200); } + if($action == 'merge' && auth()->user()->can('view', $credits->first())){ + + $paths = $credits->map(function ($credit){ + return $credit->service()->getCreditPdf($credit->invitations->first()); + }); + + $merge = (new PdfMerge($paths->toArray()))->run(); + + return response()->streamDownload(function () use ($merge) { + echo ($merge); + }, 'print.pdf', ['Content-Type' => 'application/pdf']); + + } + $credits->each(function ($credit, $key) use ($action) { if (auth()->user()->can('edit', $credit)) { $this->performAction($credit, $action, true); diff --git a/app/Http/Controllers/InvoiceController.php b/app/Http/Controllers/InvoiceController.php index 5aec198f38..8e61ae7fdb 100644 --- a/app/Http/Controllers/InvoiceController.php +++ b/app/Http/Controllers/InvoiceController.php @@ -597,7 +597,6 @@ class InvoiceController extends BaseController $merge = (new PdfMerge($paths->toArray()))->run(); - return response()->streamDownload(function () use ($merge) { echo ($merge); }, 'print.pdf', ['Content-Type' => 'application/pdf']); diff --git a/app/Http/Controllers/PurchaseOrderController.php b/app/Http/Controllers/PurchaseOrderController.php index 83d8c9cd55..e417027f1b 100644 --- a/app/Http/Controllers/PurchaseOrderController.php +++ b/app/Http/Controllers/PurchaseOrderController.php @@ -32,6 +32,7 @@ use App\Models\Client; use App\Models\Expense; use App\Models\PurchaseOrder; use App\Repositories\PurchaseOrderRepository; +use App\Services\PdfMaker\PdfMerge; use App\Transformers\ExpenseTransformer; use App\Transformers\PurchaseOrderTransformer; use App\Utils\Ninja; @@ -515,6 +516,20 @@ class PurchaseOrderController extends BaseController return response()->json(['message' => ctrans('texts.sent_message')], 200); } + if($action == 'merge' && auth()->user()->can('view', $purchase_orders->first())){ + + $paths = $purchase_orders->map(function ($purchase_order){ + return $purchase_order->service()->getPurchaseOrderPdf(); + }); + + $merge = (new PdfMerge($paths->toArray()))->run(); + + return response()->streamDownload(function () use ($merge) { + echo ($merge); + }, 'print.pdf', ['Content-Type' => 'application/pdf']); + + } + /* * Send the other actions to the switch */ diff --git a/app/Http/Controllers/QuoteController.php b/app/Http/Controllers/QuoteController.php index a42c9c09c8..fc8f631932 100644 --- a/app/Http/Controllers/QuoteController.php +++ b/app/Http/Controllers/QuoteController.php @@ -35,6 +35,7 @@ use App\Models\Invoice; use App\Models\Project; use App\Models\Quote; use App\Repositories\QuoteRepository; +use App\Services\PdfMaker\PdfMerge; use App\Transformers\InvoiceTransformer; use App\Transformers\ProjectTransformer; use App\Transformers\QuoteTransformer; @@ -561,6 +562,20 @@ class QuoteController extends BaseController return $this->listResponse(Quote::withTrashed()->whereIn('id', $this->transformKeys($ids))->company()); } + if($action == 'merge' && auth()->user()->can('view', $quotes->first())){ + + $paths = $quotes->map(function ($quote){ + return $quote->service()->getQuotePdf(); + }); + + $merge = (new PdfMerge($paths->toArray()))->run(); + + return response()->streamDownload(function () use ($merge) { + echo ($merge); + }, 'print.pdf', ['Content-Type' => 'application/pdf']); + + } + if($action == 'convert_to_project') {