mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-05-31 06:34:34 -04:00
Create route for invoice/credit/quote PDF download (#3441)
This commit is contained in:
parent
2bc8064eeb
commit
7c00c68bf3
@ -541,6 +541,8 @@ class CreateTestData extends Command
|
|||||||
$credit = $invoice_calc->getCredit();
|
$credit = $invoice_calc->getCredit();
|
||||||
|
|
||||||
$credit->save();
|
$credit->save();
|
||||||
|
$credit->service()->markSent()->save();
|
||||||
|
$credit->service()->createInvitations();
|
||||||
|
|
||||||
event(new CreateCreditInvitation($credit));
|
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 =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->date = $faker->date();
|
||||||
|
|
||||||
|
$quote->setRelation('client', $client);
|
||||||
|
|
||||||
$quote->line_items = $this->buildLineItems(rand(1,10));
|
$quote->line_items = $this->buildLineItems(rand(1,10));
|
||||||
$quote->uses_inclusive_taxes = false;
|
$quote->uses_inclusive_taxes = false;
|
||||||
|
|
||||||
@ -581,7 +585,11 @@ class CreateTestData extends Command
|
|||||||
$quote_calc->build();
|
$quote_calc->build();
|
||||||
|
|
||||||
$quote = $quote_calc->getQuote();
|
$quote = $quote_calc->getQuote();
|
||||||
|
|
||||||
|
$quote->save();
|
||||||
|
|
||||||
$quote->service()->markSent()->save();
|
$quote->service()->markSent()->save();
|
||||||
|
$quote->service()->createInvitations();
|
||||||
|
|
||||||
CreateQuoteInvitations::dispatch($quote, $quote->company);
|
CreateQuoteInvitations::dispatch($quote, $quote->company);
|
||||||
}
|
}
|
||||||
|
@ -114,9 +114,9 @@ class CompanySettings extends BaseSettings {
|
|||||||
public $quote_terms = '';
|
public $quote_terms = '';
|
||||||
public $invoice_taxes = 0;
|
public $invoice_taxes = 0;
|
||||||
public $enabled_item_tax_rates = 0;
|
public $enabled_item_tax_rates = 0;
|
||||||
public $invoice_design_id = '1';
|
public $invoice_design_id = 'VolejRejNm';
|
||||||
public $quote_design_id = '1';
|
public $quote_design_id = 'VolejRejNm';
|
||||||
public $credit_design_id = '1';
|
public $credit_design_id = 'VolejRejNm';
|
||||||
public $invoice_footer = '';
|
public $invoice_footer = '';
|
||||||
public $credit_footer = '';
|
public $credit_footer = '';
|
||||||
public $credit_terms = '';
|
public $credit_terms = '';
|
||||||
|
@ -32,11 +32,13 @@ class InvitationController extends Controller
|
|||||||
public function router(string $entity, string $invitation_key)
|
public function router(string $entity, string $invitation_key)
|
||||||
{
|
{
|
||||||
$key = $entity.'_id';
|
$key = $entity.'_id';
|
||||||
|
|
||||||
$entity_obj = 'App\Models\\'.ucfirst($entity).'Invitation';
|
$entity_obj = 'App\Models\\'.ucfirst($entity).'Invitation';
|
||||||
|
|
||||||
$invitation = $entity_obj::whereRaw("BINARY `key`= ?", [$invitation_key])->first();
|
$invitation = $entity_obj::whereRaw("BINARY `key`= ?", [$invitation_key])->first();
|
||||||
|
|
||||||
if ($invitation) {
|
if ($invitation) {
|
||||||
|
|
||||||
if ((bool)$invitation->contact->client->getSetting('enable_client_portal_password') !== false) {
|
if ((bool)$invitation->contact->client->getSetting('enable_client_portal_password') !== false) {
|
||||||
$this->middleware('auth:contact');
|
$this->middleware('auth:contact');
|
||||||
} else {
|
} else {
|
||||||
@ -52,9 +54,15 @@ class InvitationController extends Controller
|
|||||||
}
|
}
|
||||||
|
|
||||||
return redirect()->route('client.'.$entity.'.show', [$entity => $this->encodePrimaryKey($invitation->{$key})]);
|
return redirect()->route('client.'.$entity.'.show', [$entity => $this->encodePrimaryKey($invitation->{$key})]);
|
||||||
} else {
|
|
||||||
|
} else
|
||||||
abort(404);
|
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)
|
public function routerForIframe(string $entity, string $client_hash, string $invitation_key)
|
||||||
|
@ -571,4 +571,17 @@ class CreditController extends BaseController
|
|||||||
break;
|
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);
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -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);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -33,7 +33,14 @@ class SetInviteDb
|
|||||||
/*
|
/*
|
||||||
* Use the host name to set the active DB
|
* 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) {
|
if (request()->json) {
|
||||||
return response()->json($error, 403);
|
return response()->json($error, 403);
|
||||||
} else {
|
} else {
|
||||||
|
@ -66,11 +66,11 @@ class StoreCompanyRequest extends Request
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$company_settings->invoice_design_id = $this->encodePrimaryKey(1);
|
// $company_settings->invoice_design_id = $this->encodePrimaryKey(1);
|
||||||
$company_settings->quote_design_id = $this->encodePrimaryKey(1);
|
// $company_settings->quote_design_id = $this->encodePrimaryKey(1);
|
||||||
$company_settings->credit_design_id = $this->encodePrimaryKey(1);
|
// $company_settings->credit_design_id = $this->encodePrimaryKey(1);
|
||||||
|
|
||||||
$input['settings'] = $company_settings;
|
// $input['settings'] = $company_settings;
|
||||||
|
|
||||||
|
|
||||||
$this->replace($input);
|
$this->replace($input);
|
||||||
|
@ -19,9 +19,10 @@ use App\Models\ClientContact;
|
|||||||
use App\Models\Company;
|
use App\Models\Company;
|
||||||
use App\Models\Design;
|
use App\Models\Design;
|
||||||
use App\Models\Invoice;
|
use App\Models\Invoice;
|
||||||
use App\Utils\Traits\Pdf\PdfMaker;
|
use App\Utils\Traits\MakesHash;
|
||||||
use App\Utils\Traits\MakesInvoiceHtml;
|
use App\Utils\Traits\MakesInvoiceHtml;
|
||||||
use App\Utils\Traits\NumberFormatter;
|
use App\Utils\Traits\NumberFormatter;
|
||||||
|
use App\Utils\Traits\Pdf\PdfMaker;
|
||||||
use Illuminate\Bus\Queueable;
|
use Illuminate\Bus\Queueable;
|
||||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||||
use Illuminate\Foundation\Bus\Dispatchable;
|
use Illuminate\Foundation\Bus\Dispatchable;
|
||||||
@ -33,7 +34,7 @@ use Spatie\Browsershot\Browsershot;
|
|||||||
|
|
||||||
class CreateCreditPdf implements ShouldQueue {
|
class CreateCreditPdf implements ShouldQueue {
|
||||||
|
|
||||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels, NumberFormatter, MakesInvoiceHtml, PdfMaker;
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels, NumberFormatter, MakesInvoiceHtml, PdfMaker, MakesHash;
|
||||||
|
|
||||||
public $credit;
|
public $credit;
|
||||||
|
|
||||||
|
@ -74,7 +74,7 @@ class CreateInvoicePdf implements ShouldQueue {
|
|||||||
$path = $this->invoice->client->invoice_filepath();
|
$path = $this->invoice->client->invoice_filepath();
|
||||||
|
|
||||||
$file_path = $path . $this->invoice->number . '.pdf';
|
$file_path = $path . $this->invoice->number . '.pdf';
|
||||||
|
|
||||||
$design = Design::find($this->decodePrimaryKey($this->invoice->client->getSetting('invoice_design_id')));
|
$design = Design::find($this->decodePrimaryKey($this->invoice->client->getSetting('invoice_design_id')));
|
||||||
|
|
||||||
if($design->is_custom){
|
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)->put($file_path, $pdf);
|
||||||
|
|
||||||
//$instance= Storage::disk($this->disk)->path($file_path);
|
|
||||||
//
|
|
||||||
return $file_path;
|
return $file_path;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -19,9 +19,10 @@ use App\Models\ClientContact;
|
|||||||
use App\Models\Company;
|
use App\Models\Company;
|
||||||
use App\Models\Design;
|
use App\Models\Design;
|
||||||
use App\Models\Invoice;
|
use App\Models\Invoice;
|
||||||
use App\Utils\Traits\Pdf\PdfMaker;
|
use App\Utils\Traits\MakesHash;
|
||||||
use App\Utils\Traits\MakesInvoiceHtml;
|
use App\Utils\Traits\MakesInvoiceHtml;
|
||||||
use App\Utils\Traits\NumberFormatter;
|
use App\Utils\Traits\NumberFormatter;
|
||||||
|
use App\Utils\Traits\Pdf\PdfMaker;
|
||||||
use Illuminate\Bus\Queueable;
|
use Illuminate\Bus\Queueable;
|
||||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||||
use Illuminate\Foundation\Bus\Dispatchable;
|
use Illuminate\Foundation\Bus\Dispatchable;
|
||||||
@ -33,7 +34,7 @@ use Spatie\Browsershot\Browsershot;
|
|||||||
|
|
||||||
class CreateQuotePdf implements ShouldQueue {
|
class CreateQuotePdf implements ShouldQueue {
|
||||||
|
|
||||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels, NumberFormatter, MakesInvoiceHtml, PdfMaker;
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels, NumberFormatter, MakesInvoiceHtml, PdfMaker, MakesHash;
|
||||||
|
|
||||||
public $quote;
|
public $quote;
|
||||||
|
|
||||||
|
@ -2,7 +2,10 @@
|
|||||||
|
|
||||||
namespace App\Services\Credit;
|
namespace App\Services\Credit;
|
||||||
|
|
||||||
|
use App\Jobs\Credit\CreateCreditPdf;
|
||||||
use App\Jobs\Invoice\CreateInvoicePdf;
|
use App\Jobs\Invoice\CreateInvoicePdf;
|
||||||
|
use App\Models\ClientContact;
|
||||||
|
use App\Models\Credit;
|
||||||
use App\Services\AbstractService;
|
use App\Services\AbstractService;
|
||||||
use Illuminate\Support\Facades\Storage;
|
use Illuminate\Support\Facades\Storage;
|
||||||
|
|
||||||
@ -25,16 +28,19 @@ class GetCreditPdf extends AbstractService
|
|||||||
$this->contact = $this->credit->client->primary_contact()->first();
|
$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';
|
$file_path = $path . $this->credit->number . '.pdf';
|
||||||
|
|
||||||
$disk = config('filesystems.default');
|
$disk = config('filesystems.default');
|
||||||
|
|
||||||
$file = Storage::disk($disk)->exists($file_path);
|
$file = Storage::disk($disk)->exists($file_path);
|
||||||
|
|
||||||
if (!$file) {
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -14,9 +14,7 @@ class CreateInvitations
|
|||||||
public function run($quote)
|
public function run($quote)
|
||||||
{
|
{
|
||||||
|
|
||||||
$contacts = $quote->client->contacts;
|
$quote->client->contacts->each(function ($contact) use($quote){
|
||||||
|
|
||||||
$contacts->each(function ($contact) use($quote){
|
|
||||||
$invitation = QuoteInvitation::whereCompanyId($quote->company_id)
|
$invitation = QuoteInvitation::whereCompanyId($quote->company_id)
|
||||||
->whereClientContactId($contact->id)
|
->whereClientContactId($contact->id)
|
||||||
->whereQuoteId($quote->id)
|
->whereQuoteId($quote->id)
|
||||||
@ -32,6 +30,6 @@ class CreateInvitations
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return $quote;
|
return $quote->fresh();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,6 +13,20 @@
|
|||||||
|
|
||||||
Route::get('/', 'BaseController@flutterRoute')->middleware('guest');
|
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::get('signup', 'AccountController@index')->name('signup');
|
||||||
// Route::post('signup', 'AccountController@store')->name('signup.submit');
|
// Route::post('signup', 'AccountController@store')->name('signup.submit');
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user