mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-05-30 22:24:32 -04:00
Working on templates
This commit is contained in:
parent
c460287356
commit
fc624682ba
@ -14,6 +14,7 @@ namespace App\Http\Controllers;
|
|||||||
use App\DataMapper\Analytics\LivePreview;
|
use App\DataMapper\Analytics\LivePreview;
|
||||||
use App\Http\Requests\Preview\DesignPreviewRequest;
|
use App\Http\Requests\Preview\DesignPreviewRequest;
|
||||||
use App\Http\Requests\Preview\PreviewInvoiceRequest;
|
use App\Http\Requests\Preview\PreviewInvoiceRequest;
|
||||||
|
use App\Http\Requests\Preview\ShowPreviewRequest;
|
||||||
use App\Jobs\Util\PreviewPdf;
|
use App\Jobs\Util\PreviewPdf;
|
||||||
use App\Models\Client;
|
use App\Models\Client;
|
||||||
use App\Models\ClientContact;
|
use App\Models\ClientContact;
|
||||||
@ -131,9 +132,9 @@ class PreviewController extends BaseController
|
|||||||
* Used in the Custom Designer to preview design changes
|
* Used in the Custom Designer to preview design changes
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
public function show()
|
public function show(ShowPreviewRequest $request)
|
||||||
{
|
{
|
||||||
if(request()->has('template')) {
|
if($request->input('design.is_template')) {
|
||||||
return $this->template();
|
return $this->template();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -238,7 +239,6 @@ class PreviewController extends BaseController
|
|||||||
|
|
||||||
private function liveTemplate(array $request_data)
|
private function liveTemplate(array $request_data)
|
||||||
{
|
{
|
||||||
nlog($request_data['entity_type']);
|
|
||||||
|
|
||||||
/** @var \App\Models\User $user */
|
/** @var \App\Models\User $user */
|
||||||
$user = auth()->user();
|
$user = auth()->user();
|
||||||
@ -292,8 +292,6 @@ class PreviewController extends BaseController
|
|||||||
->setTemplate($design_object)
|
->setTemplate($design_object)
|
||||||
->mock();
|
->mock();
|
||||||
} catch(SyntaxError $e) {
|
} catch(SyntaxError $e) {
|
||||||
|
|
||||||
// return response()->json(['message' => 'Twig syntax is invalid.', 'errors' => new \stdClass], 422);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (request()->query('html') == 'true') {
|
if (request()->query('html') == 'true') {
|
||||||
|
45
app/Http/Requests/Preview/ShowPreviewRequest.php
Normal file
45
app/Http/Requests/Preview/ShowPreviewRequest.php
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Invoice Ninja (https://invoiceninja.com).
|
||||||
|
*
|
||||||
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
||||||
|
*
|
||||||
|
* @copyright Copyright (c) 2023. Invoice Ninja LLC (https://invoiceninja.com)
|
||||||
|
*
|
||||||
|
* @license https://www.elastic.co/licensing/elastic-license
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace App\Http\Requests\Preview;
|
||||||
|
|
||||||
|
use App\Http\Requests\Request;
|
||||||
|
use App\Utils\Traits\MakesHash;
|
||||||
|
|
||||||
|
class ShowPreviewRequest extends Request
|
||||||
|
{
|
||||||
|
use MakesHash;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determine if the user is authorized to make this request.
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function authorize(): bool
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function rules()
|
||||||
|
{
|
||||||
|
$rules = [
|
||||||
|
];
|
||||||
|
|
||||||
|
return $rules;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function prepareForValidation()
|
||||||
|
{
|
||||||
|
$input = $this->all();
|
||||||
|
|
||||||
|
$this->replace($input);
|
||||||
|
}
|
||||||
|
}
|
@ -80,18 +80,29 @@ class PdfMaker
|
|||||||
$replacements = [];
|
$replacements = [];
|
||||||
$contents = $this->document->getElementsByTagName('ninja');
|
$contents = $this->document->getElementsByTagName('ninja');
|
||||||
|
|
||||||
$ts = new TemplateService();
|
$ts = new TemplateService();
|
||||||
|
|
||||||
if(isset($this->data['template']['entity'])) {
|
if(isset($this->options['client'])) {
|
||||||
|
$client = $this->options['client'];
|
||||||
try {
|
try {
|
||||||
$entity = $this->data['template']['entity'];
|
$ts->setCompany($client->company);
|
||||||
$ts->setCompany($entity->company);
|
$ts->addGlobal(['currency_code' => $client->company->currency()->code]);
|
||||||
} catch(\Exception $e) {
|
} catch(\Exception $e) {
|
||||||
|
nlog($e->getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(isset($this->options['vendor'])) {
|
||||||
|
$vendor = $this->options['vendor'];
|
||||||
|
try {
|
||||||
|
$ts->setCompany($vendor->company);
|
||||||
|
$ts->addGlobal(['currency_code' => $vendor->company->currency()->code]);
|
||||||
|
} catch(\Exception $e) {
|
||||||
|
nlog($e->getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$data = $ts->processData($this->options)->getData();
|
$data = $ts->processData($this->options)->setGlobals()->getData();
|
||||||
$twig = $ts->twig;
|
$twig = $ts->twig;
|
||||||
|
|
||||||
foreach ($contents as $content) {
|
foreach ($contents as $content) {
|
||||||
|
@ -79,7 +79,7 @@ class TemplateAction implements ShouldQueue
|
|||||||
*/
|
*/
|
||||||
public function handle()
|
public function handle()
|
||||||
{
|
{
|
||||||
// nlog("inside template action");
|
nlog("inside template action");
|
||||||
|
|
||||||
MultiDB::setDb($this->db);
|
MultiDB::setDb($this->db);
|
||||||
|
|
||||||
@ -108,7 +108,14 @@ class TemplateAction implements ShouldQueue
|
|||||||
->where('company_id', $this->company->id)
|
->where('company_id', $this->company->id)
|
||||||
->get();
|
->get();
|
||||||
|
|
||||||
// nlog($result->toArray());
|
$first_entity = $result->first();
|
||||||
|
|
||||||
|
if($first_entity->client)
|
||||||
|
$currency_code = $first_entity->client->currency()->code;
|
||||||
|
elseif($first_entity instanceof Client)
|
||||||
|
$currency_code = $first_entity->currency()->code;
|
||||||
|
else
|
||||||
|
$currency_code = $this->company->currency()->code;
|
||||||
|
|
||||||
if($result->count() <= 1) {
|
if($result->count() <= 1) {
|
||||||
$data[$key] = collect($result);
|
$data[$key] = collect($result);
|
||||||
@ -118,10 +125,9 @@ class TemplateAction implements ShouldQueue
|
|||||||
|
|
||||||
$ts = $template_service
|
$ts = $template_service
|
||||||
->setCompany($this->company)
|
->setCompany($this->company)
|
||||||
|
->addGlobal(['currency_code' => $currency_code])
|
||||||
->build($data);
|
->build($data);
|
||||||
|
|
||||||
// nlog($ts->getHtml());
|
|
||||||
|
|
||||||
if($this->send_email) {
|
if($this->send_email) {
|
||||||
$pdf = $ts->getPdf();
|
$pdf = $ts->getPdf();
|
||||||
$this->sendEmail($pdf, $template);
|
$this->sendEmail($pdf, $template);
|
||||||
|
@ -157,9 +157,9 @@ class TemplateService
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function setGlobals(): self
|
public function setGlobals(): self
|
||||||
{
|
{
|
||||||
|
|
||||||
foreach($this->global_vars as $key => $value) {
|
foreach($this->global_vars as $key => $value) {
|
||||||
$this->twig->addGlobal($key, $value);
|
$this->twig->addGlobal($key, $value);
|
||||||
}
|
}
|
||||||
@ -241,8 +241,6 @@ class TemplateService
|
|||||||
public function getPdf(): string
|
public function getPdf(): string
|
||||||
{
|
{
|
||||||
|
|
||||||
// nlog($this->getHtml());
|
|
||||||
|
|
||||||
if (config('ninja.invoiceninja_hosted_pdf_generation') || config('ninja.pdf_generator') == 'hosted_ninja') {
|
if (config('ninja.invoiceninja_hosted_pdf_generation') || config('ninja.pdf_generator') == 'hosted_ninja') {
|
||||||
$pdf = (new NinjaPdf())->build($this->compiled_html);
|
$pdf = (new NinjaPdf())->build($this->compiled_html);
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user