mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-05-24 02:14:21 -04:00
Fixes for previews
This commit is contained in:
parent
aa0072eb20
commit
53a2d7a269
@ -11,33 +11,34 @@
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\DataMapper\Analytics\LivePreview;
|
||||
use App\Http\Requests\Preview\DesignPreviewRequest;
|
||||
use App\Http\Requests\Preview\PreviewInvoiceRequest;
|
||||
use App\Jobs\Util\PreviewPdf;
|
||||
use App\Models\Client;
|
||||
use App\Models\ClientContact;
|
||||
use App\Models\Invoice;
|
||||
use App\Models\InvoiceInvitation;
|
||||
use App\Services\Pdf\PdfMock;
|
||||
use App\Services\PdfMaker\Design;
|
||||
use App\Services\PdfMaker\Design as PdfDesignModel;
|
||||
use App\Services\PdfMaker\Design as PdfMakerDesign;
|
||||
use App\Services\PdfMaker\PdfMaker;
|
||||
use App\Services\Template\TemplateService;
|
||||
use App\Utils\HostedPDF\NinjaPdf;
|
||||
use App\Utils\HtmlEngine;
|
||||
use App\Utils\Ninja;
|
||||
use App\Utils\PhantomJS\Phantom;
|
||||
use App\Models\Client;
|
||||
use App\Models\Invoice;
|
||||
use App\Utils\HtmlEngine;
|
||||
use Twig\Error\SyntaxError;
|
||||
use App\Jobs\Util\PreviewPdf;
|
||||
use App\Models\ClientContact;
|
||||
use App\Services\Pdf\PdfMock;
|
||||
use App\Utils\Traits\MakesHash;
|
||||
use App\Utils\Traits\MakesInvoiceHtml;
|
||||
use App\Utils\Traits\Pdf\PageNumbering;
|
||||
use App\Services\Pdf\PdfService;
|
||||
use App\Utils\PhantomJS\Phantom;
|
||||
use App\Models\InvoiceInvitation;
|
||||
use App\Services\PdfMaker\Design;
|
||||
use App\Utils\HostedPDF\NinjaPdf;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use App\Services\PdfMaker\PdfMaker;
|
||||
use Illuminate\Support\Facades\App;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Response;
|
||||
use App\Utils\Traits\MakesInvoiceHtml;
|
||||
use Turbo124\Beacon\Facades\LightLogs;
|
||||
use Twig\Error\SyntaxError;
|
||||
use App\Utils\Traits\Pdf\PageNumbering;
|
||||
use Illuminate\Support\Facades\Response;
|
||||
use App\DataMapper\Analytics\LivePreview;
|
||||
use App\Services\Template\TemplateService;
|
||||
use App\Http\Requests\Preview\DesignPreviewRequest;
|
||||
use App\Services\PdfMaker\Design as PdfDesignModel;
|
||||
use App\Services\PdfMaker\Design as PdfMakerDesign;
|
||||
use App\Http\Requests\Preview\PreviewInvoiceRequest;
|
||||
|
||||
class PreviewController extends BaseController
|
||||
{
|
||||
@ -49,12 +50,59 @@ class PreviewController extends BaseController
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
private function purgeCache()
|
||||
{
|
||||
Cache::pull("preview_".auth()->user()->id);
|
||||
}
|
||||
|
||||
public function live(PreviewInvoiceRequest $request): mixed
|
||||
{
|
||||
|
||||
if (Ninja::isHosted() && !in_array($request->getHost(), ['preview.invoicing.co','staging.invoicing.co'])) {
|
||||
return response()->json(['message' => 'This server cannot handle this request.'], 400);
|
||||
}
|
||||
|
||||
$start = microtime(true);
|
||||
|
||||
/** Build models */
|
||||
$invitation = $request->resolveInvitation();
|
||||
$client = $request->getClient();
|
||||
$settings = $client->getMergedSettings();
|
||||
$entity_prop = str_replace("recurring_", "", $request->entity);
|
||||
$entity_obj = $invitation->{$request->entity};
|
||||
$entity_obj->fill($request->all());
|
||||
|
||||
if(!$entity_obj->id) {
|
||||
$entity_obj->design_id = intval($this->decodePrimaryKey($settings->{$entity_prop."_design_id"}));
|
||||
$entity_obj->footer = empty($entity_obj->footer) ? $settings->{$entity_prop."_footer"} : $entity_obj->footer;
|
||||
$entity_obj->terms = empty($entity_obj->terms) ? $settings->{$entity_prop."_terms"} : $entity_obj->terms;
|
||||
$entity_obj->public_notes = empty($entity_obj->public_notes) ? $request->getClient()->public_notes : $entity_obj->public_notes;
|
||||
$invitation->setRelation($request->entity, $entity_obj);
|
||||
}
|
||||
|
||||
$ps = new PdfService($invitation, 'product', [
|
||||
'client' => $client ?? false,
|
||||
// 'vendor' => $vendor ?? false,
|
||||
"{$entity_prop}s" => [$entity_obj],
|
||||
]);
|
||||
|
||||
$pdf = $ps->boot()->getPdf();
|
||||
|
||||
|
||||
if (Ninja::isHosted()) {
|
||||
LightLogs::create(new LivePreview())
|
||||
->increment()
|
||||
->batch();
|
||||
}
|
||||
|
||||
/** Return PDF */
|
||||
return response()->streamDownload(function () use ($pdf) {
|
||||
echo $pdf;
|
||||
}, 'preview.pdf', [
|
||||
'Content-Disposition' => 'inline',
|
||||
'Content-Type' => 'application/pdf',
|
||||
'Cache-Control:' => 'no-cache',
|
||||
'Server-Timing' => microtime(true)-$start
|
||||
]);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Refactor - 2023-10-19
|
||||
*
|
||||
@ -63,7 +111,7 @@ class PreviewController extends BaseController
|
||||
* @param PreviewInvoiceRequest $request
|
||||
* @return mixed
|
||||
*/
|
||||
public function live(PreviewInvoiceRequest $request): mixed
|
||||
public function livexx(PreviewInvoiceRequest $request): mixed
|
||||
{
|
||||
|
||||
if (Ninja::isHosted() && !in_array($request->getHost(), ['preview.invoicing.co','staging.invoicing.co'])) {
|
||||
|
@ -171,22 +171,27 @@ class PreviewPurchaseOrderController extends BaseController
|
||||
|
||||
public function live(PreviewPurchaseOrderRequest $request)
|
||||
{
|
||||
|
||||
$start = microtime(true);
|
||||
|
||||
/** @var \App\Models\User $user */
|
||||
$user = auth()->user();
|
||||
|
||||
$invitation = $request->resolveInvitation();
|
||||
$vendor = $request->getVendor();
|
||||
$settings = $user->company()->settings;
|
||||
|
||||
/** Set translations */
|
||||
App::forgetInstance('translator');
|
||||
$t = app('translator');
|
||||
App::setLocale($invitation->contact->preferredLocale());
|
||||
$t->replace(Ninja::transformTranslations($settings));
|
||||
|
||||
$entity_obj = $invitation->purchase_order;
|
||||
$entity_obj->fill($request->all());
|
||||
|
||||
if(!$entity_obj->id) {
|
||||
$entity_obj->design_id = intval($this->decodePrimaryKey($settings->{"purchase_order_design_id"}));
|
||||
$entity_obj->footer = empty($entity_obj->footer) ? $settings->{"purchase_order_footer"} : $entity_obj->footer;
|
||||
$entity_obj->terms = empty($entity_obj->terms) ? $settings->{"purchase_order_terms"} : $entity_obj->terms;
|
||||
$entity_obj->public_notes = empty($entity_obj->public_notes) ? $request->getVendor()->public_notes : $entity_obj->public_notes;
|
||||
$invitation->setRelation($request->entity, $entity_obj);
|
||||
|
||||
}
|
||||
|
||||
$ps = new PdfService($invitation, 'purchase_order', [
|
||||
'client' => $entity_obj->client ?? false,
|
||||
'vendor' => $vendor ?? false,
|
||||
@ -194,7 +199,23 @@ class PreviewPurchaseOrderController extends BaseController
|
||||
]);
|
||||
|
||||
$pdf = $ps->boot()->getPdf();
|
||||
return $pdf;
|
||||
|
||||
if (Ninja::isHosted()) {
|
||||
LightLogs::create(new LivePreview())
|
||||
->increment()
|
||||
->batch();
|
||||
}
|
||||
|
||||
/** Return PDF */
|
||||
return response()->streamDownload(function () use ($pdf) {
|
||||
echo $pdf;
|
||||
}, 'preview.pdf', [
|
||||
'Content-Disposition' => 'inline',
|
||||
'Content-Type' => 'application/pdf',
|
||||
'Cache-Control:' => 'no-cache',
|
||||
'Server-Timing' => microtime(true)-$start
|
||||
]);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user