diff --git a/app/Http/Controllers/QuoteController.php b/app/Http/Controllers/QuoteController.php index 80fd8c67b93e..b89d9a77ade4 100644 --- a/app/Http/Controllers/QuoteController.php +++ b/app/Http/Controllers/QuoteController.php @@ -694,7 +694,6 @@ class QuoteController extends BaseController echo Storage::get($file); }, basename($file), ['Content-Type' => 'application/pdf']); - //return response()->download($file, basename($file), ['Cache-Control:' => 'no-cache'])->deleteFileAfterSend(true); break; case 'restore': diff --git a/app/Http/Controllers/VendorPortal/DocumentController.php b/app/Http/Controllers/VendorPortal/DocumentController.php new file mode 100644 index 000000000000..ab85e87f1c4c --- /dev/null +++ b/app/Http/Controllers/VendorPortal/DocumentController.php @@ -0,0 +1,97 @@ + $document, + 'settings' => auth()->guard('vendor')->user()->company->settings + ]); + } + + public function download(ShowDocumentRequest $request, Document $document) + { + return Storage::disk($document->disk)->download($document->url, $document->name); + } + + public function publicDownload(string $document_hash) + { + MultiDB::documentFindAndSetDb($document_hash); + + $document = Document::where('hash', $document_hash)->firstOrFail(); + + $headers = []; + + if (request()->input('inline') == 'true') { + $headers = array_merge($headers, ['Content-Disposition' => 'inline']); + } + + return Storage::disk($document->disk)->download($document->url, $document->name, $headers); + } + + public function downloadMultiple(DownloadMultipleDocumentsRequest $request) + { + $documents = Document::whereIn('id', $this->transformKeys($request->file_hash)) + ->where('company_id', auth()->guard('vendor')->user()->company_id) + ->get(); + + $zipFile = new \PhpZip\ZipFile(); + + try { + foreach ($documents as $document) { + $zipFile->addFile(TempFile::path($document->filePath()), $document->name); + } + + $filename = now().'-documents.zip'; + $filepath = sys_get_temp_dir().'/'.$filename; + + $zipFile->saveAsFile($filepath) // save the archive to a file + ->close(); // close archive + + return response()->download($filepath, $filename)->deleteFileAfterSend(true); + } catch (\PhpZip\Exception\ZipException $e) { + // handle exception + } finally { + $zipFile->close(); + } + } +} diff --git a/app/Http/Requests/VendorPortal/Documents/ShowDocumentRequest.php b/app/Http/Requests/VendorPortal/Documents/ShowDocumentRequest.php new file mode 100644 index 000000000000..f9594292f8fc --- /dev/null +++ b/app/Http/Requests/VendorPortal/Documents/ShowDocumentRequest.php @@ -0,0 +1,44 @@ +guard('vendor')->user()->client_id == $this->document->documentable_id + || $this->document->company_id == auth()->guard('vendor')->user()->company_id; + } + + /** + * Get the validation rules that apply to the request. + * + * @return array + */ + public function rules() + { + return [ + // + ]; + } +} diff --git a/app/Services/Quote/SendEmail.php b/app/Services/Quote/SendEmail.php index acaf4b2ce2a8..9c319325a48c 100644 --- a/app/Services/Quote/SendEmail.php +++ b/app/Services/Quote/SendEmail.php @@ -40,13 +40,14 @@ class SendEmail if (! $this->reminder_template) { $this->reminder_template = $this->quote->calculateTemplate('quote'); } + + $this->quote->service()->markSent()->save(); $this->quote->invitations->each(function ($invitation) { if (! $invitation->contact->trashed() && $invitation->contact->email) { - EmailEntity::dispatchSync($invitation, $invitation->company, $this->reminder_template); + EmailEntity::dispatch($invitation, $invitation->company, $this->reminder_template); } }); - $this->quote->service()->markSent(); } } diff --git a/resources/views/portal/ninja2020/components/entity-documents.blade.php b/resources/views/portal/ninja2020/components/entity-documents.blade.php index efe5e7415db5..b288e9c9209f 100644 --- a/resources/views/portal/ninja2020/components/entity-documents.blade.php +++ b/resources/views/portal/ninja2020/components/entity-documents.blade.php @@ -6,9 +6,13 @@

{{ ctrans('texts.attachments') }}:

@foreach ($entity->documents as $document)
- {{ Illuminate\Support\Str::limit($document->name, 40) }} - + @else + {{ Illuminate\Support\Str::limit($document->name, 40) }} + @endif @@ -25,9 +29,13 @@ @foreach ($entity->company->documents as $document)
+ @if($entity instanceof App\Models\PurchaseOrder) + {{ Illuminate\Support\Str::limit($document->name, 40) }} + @else {{ Illuminate\Support\Str::limit($document->name, 40) }} - + @endif diff --git a/routes/client.php b/routes/client.php index 5e4205327dda..c0d3e8492f37 100644 --- a/routes/client.php +++ b/routes/client.php @@ -94,7 +94,7 @@ Route::group(['middleware' => ['auth:contact', 'locale', 'domain_db','check_clie Route::post('documents/download_multiple', [App\Http\Controllers\ClientPortal\DocumentController::class, 'downloadMultiple'])->name('documents.download_multiple'); Route::get('documents/{document}/download', [App\Http\Controllers\ClientPortal\DocumentController::class, 'download'])->name('documents.download'); - Route::resource('documents', DocumentController::class)->only(['index', 'show']); + Route::resource('documents', App\Http\Controllers\ClientPortal\DocumentController::class)->only(['index', 'show']); Route::get('subscriptions/{recurring_invoice}/plan_switch/{target}', [App\Http\Controllers\ClientPortal\SubscriptionPlanSwitchController::class, 'index'])->name('subscription.plan_switch'); diff --git a/routes/vendor.php b/routes/vendor.php index b4b501391c33..94b958f528f4 100644 --- a/routes/vendor.php +++ b/routes/vendor.php @@ -10,6 +10,7 @@ | */ use App\Http\Controllers\Auth\VendorContactLoginController; +use App\Http\Controllers\VendorPortal\DocumentController; use App\Http\Controllers\VendorPortal\InvitationController; use App\Http\Controllers\VendorPortal\PurchaseOrderController; use App\Http\Controllers\VendorPortal\UploadController; @@ -41,6 +42,7 @@ Route::group(['middleware' => ['auth:vendor', 'vendor_locale', 'domain_db'], 'pr Route::post('purchase_orders/bulk', [PurchaseOrderController::class, 'bulk'])->name('purchase_orders.bulk'); Route::get('logout', [VendorContactLoginController::class, 'logout'])->name('logout'); Route::post('purchase_order/upload/{purchase_order}', [UploadController::class,'upload'])->name('upload.store'); + Route::resource('documents', DocumentController::class)->only(['index', 'show']); });