1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 13:12:50 +01:00

Merge pull request #6343 from turbo124/v5-develop

Live Preview
This commit is contained in:
David Bomba 2021-07-27 19:51:34 +10:00 committed by GitHub
commit 1f5ac908ee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 38 additions and 4 deletions

View File

@ -11,15 +11,24 @@
namespace App\Http\Controllers;
use App\Factory\CreditFactory;
use App\Factory\InvoiceFactory;
use App\Factory\QuoteFactory;
use App\Factory\RecurringInvoiceFactory;
use App\Http\Requests\Invoice\StoreInvoiceRequest;
use App\Http\Requests\Preview\PreviewInvoiceRequest;
use App\Jobs\Util\PreviewPdf;
use App\Models\Client;
use App\Models\ClientContact;
use App\Models\Credit;
use App\Models\Invoice;
use App\Models\InvoiceInvitation;
use App\Models\Quote;
use App\Models\RecurringInvoice;
use App\Repositories\CreditRepository;
use App\Repositories\InvoiceRepository;
use App\Repositories\QuoteRepository;
use App\Repositories\RecurringInvoiceRepository;
use App\Services\PdfMaker\Design as PdfMakerDesign;
use App\Services\PdfMaker\Design;
use App\Services\PdfMaker\PdfMaker;
@ -156,15 +165,40 @@ class PreviewController extends BaseController
public function live(PreviewInvoiceRequest $request)
{
if(request()->input('entity') == 'invoice'){
if($request->input('entity') == 'invoice'){
$repo = new InvoiceRepository();
$factory = InvoiceFactory::create(auth()->user()->company()->id, auth()->user()->id);
$class = Invoice::class;
}
elseif($request->input('entity') == 'quote'){
$repo = new QuoteRepository();
$factory = QuoteFactory::create(auth()->user()->company()->id, auth()->user()->id);
$class = Quote::class;
}
elseif($request->input('entity') == 'credit'){
$repo = new CreditRepository();
$factory = CreditFactory::create(auth()->user()->company()->id, auth()->user()->id);
$class = Credit::class;
}
elseif($request->input('entity') == 'recurring_invoice'){
$repo = new RecurringInvoiceRepository();
$factory = RecurringInvoiceFactory::create(auth()->user()->company()->id, auth()->user()->id);
$class = RecurringInvoice::class;
}
DB::connection(config('database.default'))->beginTransaction();
$entity = ucfirst(request()->input('entity'));
$entity_obj = $repo->save(request()->all(), $factory);
if($request->has('entity_id')){
$entity_obj = $class::whereId($this->decodePrimaryKey($request->input('entity_id')))->company()->first();
$entity_obj = $repo->save($request->all(), $entity_obj);
}
else {
$entity_obj = $repo->save($request->all(), $factory);
}
$entity_obj->load('client');
App::forgetInstance('translator');

View File

@ -53,7 +53,7 @@ class PreviewInvoiceRequest extends Request
$input['line_items'] = isset($input['line_items']) ? $this->cleanItems($input['line_items']) : [];
$input['amount'] = 0;
$input['balance'] = 0;
$input['number'] = null;
$input['number'] = ctrans('texts.live_preview') . " #". rand(0,1000);
$this->replace($input);
}