mirror of
				https://github.com/invoiceninja/invoiceninja.git
				synced 2025-11-03 23:07:32 -05:00 
			
		
		
		
	Vendor documents
This commit is contained in:
		
							parent
							
								
									9bf603e584
								
							
						
					
					
						commit
						2942dfa528
					
				@ -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':
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										97
									
								
								app/Http/Controllers/VendorPortal/DocumentController.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										97
									
								
								app/Http/Controllers/VendorPortal/DocumentController.php
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,97 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Invoice Ninja (https://invoiceninja.com).
 | 
			
		||||
 *
 | 
			
		||||
 * @link https://github.com/invoiceninja/invoiceninja source repository
 | 
			
		||||
 *
 | 
			
		||||
 * @copyright Copyright (c) 2022. Invoice Ninja LLC (https://invoiceninja.com)
 | 
			
		||||
 *
 | 
			
		||||
 * @license https://www.elastic.co/licensing/elastic-license
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
namespace App\Http\Controllers\VendorPortal;
 | 
			
		||||
 | 
			
		||||
use App\Http\Controllers\Controller;
 | 
			
		||||
use App\Http\Requests\VendorPortal\Documents\ShowDocumentRequest;
 | 
			
		||||
use App\Http\Requests\Document\DownloadMultipleDocumentsRequest;
 | 
			
		||||
use App\Libraries\MultiDB;
 | 
			
		||||
use App\Models\Document;
 | 
			
		||||
use App\Utils\TempFile;
 | 
			
		||||
use App\Utils\Traits\MakesHash;
 | 
			
		||||
use Illuminate\Contracts\View\Factory;
 | 
			
		||||
use Illuminate\Support\Facades\Storage;
 | 
			
		||||
use Illuminate\View\View;
 | 
			
		||||
 | 
			
		||||
class DocumentController extends Controller
 | 
			
		||||
{
 | 
			
		||||
    use MakesHash;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @return Factory|View
 | 
			
		||||
     */
 | 
			
		||||
    public function index()
 | 
			
		||||
    {
 | 
			
		||||
        return render('documents.index');
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @param ShowDocumentRequest $request
 | 
			
		||||
     * @param Document $document
 | 
			
		||||
     * @return Factory|View
 | 
			
		||||
     */
 | 
			
		||||
    public function show(ShowDocumentRequest $request, Document $document)
 | 
			
		||||
    {
 | 
			
		||||
        return render('documents.show', [
 | 
			
		||||
            'document' => $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();
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@ -0,0 +1,44 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Invoice Ninja (https://invoiceninja.com).
 | 
			
		||||
 *
 | 
			
		||||
 * @link https://github.com/invoiceninja/invoiceninja source repository
 | 
			
		||||
 *
 | 
			
		||||
 * @copyright Copyright (c) 2022. Invoice Ninja LLC (https://invoiceninja.com)
 | 
			
		||||
 *
 | 
			
		||||
 * @license https://www.elastic.co/licensing/elastic-license
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
namespace App\Http\Requests\VendorPortal\Documents;
 | 
			
		||||
 | 
			
		||||
use App\Utils\Traits\MakesHash;
 | 
			
		||||
use Illuminate\Foundation\Http\FormRequest;
 | 
			
		||||
 | 
			
		||||
class ShowDocumentRequest extends FormRequest
 | 
			
		||||
{
 | 
			
		||||
    use MakesHash;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Determine if the user is authorized to make this request.
 | 
			
		||||
     *
 | 
			
		||||
     * @return bool
 | 
			
		||||
     */
 | 
			
		||||
    public function authorize()
 | 
			
		||||
    {
 | 
			
		||||
        return auth()->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 [
 | 
			
		||||
            //
 | 
			
		||||
        ];
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@ -41,12 +41,13 @@ class SendEmail
 | 
			
		||||
            $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();
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -6,9 +6,13 @@
 | 
			
		||||
                    <p class="text-lg leading-6 font-medium text-gray-900">{{ ctrans('texts.attachments') }}:</p>
 | 
			
		||||
                    @foreach ($entity->documents as $document)
 | 
			
		||||
                        <div class="inline-flex items-center space-x-1">
 | 
			
		||||
                            @if($entity instanceof App\Models\PurchaseOrder)
 | 
			
		||||
                            <a href="{{ route('vendor.documents.show', $document->hashed_id) }}" target="_blank"
 | 
			
		||||
                                class="block text-sm button-link text-primary">{{ Illuminate\Support\Str::limit($document->name, 40) }}</a>
 | 
			
		||||
                            @else
 | 
			
		||||
                            <a href="{{ route('client.documents.show', $document->hashed_id) }}" target="_blank"
 | 
			
		||||
                                class="block text-sm button-link text-primary">{{ Illuminate\Support\Str::limit($document->name, 40) }}</a> 
 | 
			
		||||
 | 
			
		||||
                            @endif
 | 
			
		||||
                            <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none"
 | 
			
		||||
                                stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"
 | 
			
		||||
                                class="text-primary h-6 w-4">
 | 
			
		||||
@ -25,9 +29,13 @@
 | 
			
		||||
 | 
			
		||||
                    @foreach ($entity->company->documents as $document)
 | 
			
		||||
                        <div class="inline-flex items-center space-x-1">
 | 
			
		||||
                            @if($entity instanceof App\Models\PurchaseOrder)
 | 
			
		||||
                            <a href="{{ route('vendor.documents.show', $document->hashed_id) }}" target="_blank"
 | 
			
		||||
                                class="block text-sm button-link text-primary">{{ Illuminate\Support\Str::limit($document->name, 40) }}</a>
 | 
			
		||||
                            @else
 | 
			
		||||
                            <a href="{{ route('client.documents.show', $document->hashed_id) }}" target="_blank"
 | 
			
		||||
                                class="block text-sm button-link text-primary">{{ Illuminate\Support\Str::limit($document->name, 40) }}</a>
 | 
			
		||||
 | 
			
		||||
                            @endif
 | 
			
		||||
                            <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none"
 | 
			
		||||
                                stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"
 | 
			
		||||
                                class="text-primary h-6 w-4">
 | 
			
		||||
 | 
			
		||||
@ -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');
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -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']);
 | 
			
		||||
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user