Create route for invoice/credit/quote PDF download (#3441)

This commit is contained in:
David Bomba 2020-03-07 00:41:15 +11:00 committed by GitHub
parent 2bc8064eeb
commit 7c00c68bf3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 92 additions and 24 deletions

View File

@ -541,6 +541,8 @@ class CreateTestData extends Command
$credit = $invoice_calc->getCredit();
$credit->save();
$credit->service()->markSent()->save();
$credit->service()->createInvitations();
event(new CreateCreditInvitation($credit));
@ -557,6 +559,8 @@ class CreateTestData extends Command
$quote =factory(\App\Models\Quote::class)->create(['user_id' => $client->user->id, 'company_id' => $client->company->id, 'client_id' => $client->id]);
$quote->date = $faker->date();
$quote->setRelation('client', $client);
$quote->line_items = $this->buildLineItems(rand(1,10));
$quote->uses_inclusive_taxes = false;
@ -581,7 +585,11 @@ class CreateTestData extends Command
$quote_calc->build();
$quote = $quote_calc->getQuote();
$quote->save();
$quote->service()->markSent()->save();
$quote->service()->createInvitations();
CreateQuoteInvitations::dispatch($quote, $quote->company);
}

View File

@ -114,9 +114,9 @@ class CompanySettings extends BaseSettings {
public $quote_terms = '';
public $invoice_taxes = 0;
public $enabled_item_tax_rates = 0;
public $invoice_design_id = '1';
public $quote_design_id = '1';
public $credit_design_id = '1';
public $invoice_design_id = 'VolejRejNm';
public $quote_design_id = 'VolejRejNm';
public $credit_design_id = 'VolejRejNm';
public $invoice_footer = '';
public $credit_footer = '';
public $credit_terms = '';

View File

@ -32,11 +32,13 @@ class InvitationController extends Controller
public function router(string $entity, string $invitation_key)
{
$key = $entity.'_id';
$entity_obj = 'App\Models\\'.ucfirst($entity).'Invitation';
$invitation = $entity_obj::whereRaw("BINARY `key`= ?", [$invitation_key])->first();
if ($invitation) {
if ((bool)$invitation->contact->client->getSetting('enable_client_portal_password') !== false) {
$this->middleware('auth:contact');
} else {
@ -52,9 +54,15 @@ class InvitationController extends Controller
}
return redirect()->route('client.'.$entity.'.show', [$entity => $this->encodePrimaryKey($invitation->{$key})]);
} else {
} else
abort(404);
}
}
public function routerForDownload(string $entity, string $invitation_key)
{
return redirect('/'.$entity.'/'.$invitation_key.'/download_pdf');
}
public function routerForIframe(string $entity, string $client_hash, string $invitation_key)

View File

@ -571,4 +571,17 @@ class CreditController extends BaseController
break;
}
}
public function downloadPdf($invitation_key)
{
$invitation = $this->credit_repository->getInvitationByKey($invitation_key);
$contact = $invitation->contact;
$credit = $invitation->credit;
$file_path = $credit->service()->getCreditPdf($contact);
return response()->download($file_path);
}
}

View File

@ -680,4 +680,17 @@ class QuoteController extends BaseController
}
}
public function downloadPdf($invitation_key)
{
$invitation = $this->quote_repo->getInvitationByKey($invitation_key);
$contact = $invitation->contact;
$quote = $invitation->quote;
$file_path = $quote->service()->getQuotePdf($contact);
return response()->download($file_path);
}
}

View File

@ -33,7 +33,14 @@ class SetInviteDb
/*
* Use the host name to set the active DB
**/
if ($request->getSchemeAndHttpHost() && config('ninja.db.multi_db_enabled') && ! MultiDB::findAndSetDbByInvitation($request->route('entity'), $request->route('invitation_key'))) {
$entity = null;
if(!$request->route('entity'))
$entity = $request->segment(1);
else
$entity = $request->route('entity');
if ($request->getSchemeAndHttpHost() && config('ninja.db.multi_db_enabled') && ! MultiDB::findAndSetDbByInvitation($entity, $request->route('invitation_key'))) {
if (request()->json) {
return response()->json($error, 403);
} else {

View File

@ -66,11 +66,11 @@ class StoreCompanyRequest extends Request
}
$company_settings->invoice_design_id = $this->encodePrimaryKey(1);
$company_settings->quote_design_id = $this->encodePrimaryKey(1);
$company_settings->credit_design_id = $this->encodePrimaryKey(1);
// $company_settings->invoice_design_id = $this->encodePrimaryKey(1);
// $company_settings->quote_design_id = $this->encodePrimaryKey(1);
// $company_settings->credit_design_id = $this->encodePrimaryKey(1);
$input['settings'] = $company_settings;
// $input['settings'] = $company_settings;
$this->replace($input);

View File

@ -19,9 +19,10 @@ use App\Models\ClientContact;
use App\Models\Company;
use App\Models\Design;
use App\Models\Invoice;
use App\Utils\Traits\Pdf\PdfMaker;
use App\Utils\Traits\MakesHash;
use App\Utils\Traits\MakesInvoiceHtml;
use App\Utils\Traits\NumberFormatter;
use App\Utils\Traits\Pdf\PdfMaker;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
@ -33,7 +34,7 @@ use Spatie\Browsershot\Browsershot;
class CreateCreditPdf implements ShouldQueue {
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels, NumberFormatter, MakesInvoiceHtml, PdfMaker;
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels, NumberFormatter, MakesInvoiceHtml, PdfMaker, MakesHash;
public $credit;

View File

@ -74,7 +74,7 @@ class CreateInvoicePdf implements ShouldQueue {
$path = $this->invoice->client->invoice_filepath();
$file_path = $path . $this->invoice->number . '.pdf';
$design = Design::find($this->decodePrimaryKey($this->invoice->client->getSetting('invoice_design_id')));
if($design->is_custom){
@ -98,9 +98,8 @@ class CreateInvoicePdf implements ShouldQueue {
$instance = Storage::disk($this->disk)->put($file_path, $pdf);
//$instance= Storage::disk($this->disk)->path($file_path);
//
return $file_path;
}

View File

@ -19,9 +19,10 @@ use App\Models\ClientContact;
use App\Models\Company;
use App\Models\Design;
use App\Models\Invoice;
use App\Utils\Traits\Pdf\PdfMaker;
use App\Utils\Traits\MakesHash;
use App\Utils\Traits\MakesInvoiceHtml;
use App\Utils\Traits\NumberFormatter;
use App\Utils\Traits\Pdf\PdfMaker;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
@ -33,7 +34,7 @@ use Spatie\Browsershot\Browsershot;
class CreateQuotePdf implements ShouldQueue {
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels, NumberFormatter, MakesInvoiceHtml, PdfMaker;
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels, NumberFormatter, MakesInvoiceHtml, PdfMaker, MakesHash;
public $quote;

View File

@ -2,7 +2,10 @@
namespace App\Services\Credit;
use App\Jobs\Credit\CreateCreditPdf;
use App\Jobs\Invoice\CreateInvoicePdf;
use App\Models\ClientContact;
use App\Models\Credit;
use App\Services\AbstractService;
use Illuminate\Support\Facades\Storage;
@ -25,16 +28,19 @@ class GetCreditPdf extends AbstractService
$this->contact = $this->credit->client->primary_contact()->first();
}
$path = 'public/' . $this->credit->client->id . '/credits/';
$path = $this->credit->client->credit_filepath();
$file_path = $path . $this->credit->number . '.pdf';
$disk = config('filesystems.default');
$file = Storage::disk($disk)->exists($file_path);
if (!$file) {
$file_path = CreateInvoicePdf::dispatchNow($this->credit, $this->credit->company, $this->contact);
$file_path = CreateCreditPdf::dispatchNow($this->credit, $this->credit->company, $this->contact);
}
return Storage::disk($disk)->url($file_path);
return Storage::disk($disk)->path($file_path);
}
}

View File

@ -14,9 +14,7 @@ class CreateInvitations
public function run($quote)
{
$contacts = $quote->client->contacts;
$contacts->each(function ($contact) use($quote){
$quote->client->contacts->each(function ($contact) use($quote){
$invitation = QuoteInvitation::whereCompanyId($quote->company_id)
->whereClientContactId($contact->id)
->whereQuoteId($quote->id)
@ -32,6 +30,6 @@ class CreateInvitations
}
});
return $quote;
return $quote->fresh();
}
}

View File

@ -13,6 +13,20 @@
Route::get('/', 'BaseController@flutterRoute')->middleware('guest');
Route::group(['middleware' => ['invite_db'], 'prefix' => '', 'as' => ''], function () {
/*Invitation catches*/
Route::get('{entity}/{invitation_key}/download', 'ClientPortal\InvitationController@routerForDownload');
Route::get('invoice/{invitation_key}/download_pdf', 'InvoiceController@downloadPdf')->name('invoice.download_pdf');
Route::get('quote/{invitation_key}/download_pdf', 'QuoteController@downloadPdf')->name('quote.download_pdf');
Route::get('credit/{invitation_key}/download_pdf', 'CreditController@downloadPdf')->name('credit.download_pdf');
});
// Route::get('signup', 'AccountController@index')->name('signup');
// Route::post('signup', 'AccountController@store')->name('signup.submit');