mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-05-24 02:14:21 -04:00
Fixes for invoice previews (#3485)
* Remove stale css * Working on previewing designs * Fixes for design previews * fixes for preview controller
This commit is contained in:
parent
82ace70a4c
commit
a151789d9c
@ -18,8 +18,6 @@ class Designer {
|
||||
|
||||
public $design;
|
||||
|
||||
public $design_name;
|
||||
|
||||
protected $input_variables;
|
||||
|
||||
protected $exported_variables;
|
||||
@ -59,8 +57,6 @@ class Designer {
|
||||
|
||||
$this->design = $design->design;
|
||||
|
||||
$this->design_name = property_exists($design, 'name') ? lcfirst($design->name) : 'custom';
|
||||
|
||||
$this->input_variables = (array) $input_variables;
|
||||
|
||||
$this->entity_string = $entity_string;
|
||||
|
@ -94,13 +94,11 @@ class PreviewController extends BaseController
|
||||
request()->has('body'))
|
||||
{
|
||||
|
||||
$design_object = json_decode(json_encode(request()->all()));
|
||||
$design_object = json_decode(json_encode(request()->input('body')));
|
||||
|
||||
if(!is_object($design_object))
|
||||
return response()->json(['message' => 'Invalid custom design object'], 400);
|
||||
|
||||
$invoice_design = new Custom($design_object->design);
|
||||
|
||||
$entity = ucfirst(request()->input('entity'));
|
||||
|
||||
$class = "App\Models\\$entity";
|
||||
@ -114,9 +112,9 @@ class PreviewController extends BaseController
|
||||
|
||||
$entity_obj->load('client');
|
||||
|
||||
$designer = new Designer($entity_obj, $invoice_design, $entity_obj->client->getSetting('pdf_variables'), lcfirst($entity));
|
||||
$designer = new Designer($entity_obj, $design_object, $entity_obj->client->getSetting('pdf_variables'), lcfirst($entity));
|
||||
|
||||
$html = $this->generateInvoiceHtml($designer->build()->getHtml(), $entity_obj);
|
||||
$html = $this->generateEntityHtml($designer, $entity_obj);
|
||||
|
||||
$file_path = PreviewPdf::dispatchNow($html, auth()->user()->company());
|
||||
|
||||
@ -153,16 +151,14 @@ class PreviewController extends BaseController
|
||||
$invoice->setRelation('company', auth()->user()->company());
|
||||
$invoice->load('client');
|
||||
|
||||
$design_object = json_decode(json_encode(request()->all()));
|
||||
$design_object = json_decode(json_encode(request()->input('body')));
|
||||
|
||||
if(!is_object($design_object))
|
||||
return response()->json(['message' => 'Invalid custom design object'], 400);
|
||||
|
||||
$invoice_design = new Custom($design_object->design);
|
||||
$designer = new Designer($invoice, $design_object, $invoice->client->getSetting('pdf_variables'), lcfirst(request()->has('entity')));
|
||||
|
||||
$designer = new Designer($invoice, $invoice_design, $invoice->client->getSetting('pdf_variables'), lcfirst(request()->has('entity')));
|
||||
|
||||
$html = $this->generateInvoiceHtml($designer->build()->getHtml(), $invoice);
|
||||
$html = $this->generateEntityHtml($designer, $invoice, $contact);
|
||||
|
||||
$file_path = PreviewPdf::dispatchNow($html, auth()->user()->company());
|
||||
|
||||
@ -171,9 +167,6 @@ class PreviewController extends BaseController
|
||||
$client->forceDelete();
|
||||
|
||||
return response()->file($file_path, array('content-type' => 'application/pdf'));
|
||||
//return response()->download($file_path)->deleteFileAfterSend(true);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
@ -67,23 +67,18 @@ trait MakesInvoiceHtml
|
||||
$labels = $entity->makeLabels();
|
||||
$values = $entity->makeValues($contact);
|
||||
|
||||
$css_url = url('').'/css/design/'.$designer->design_name.'.css';
|
||||
$css_url = "<link href=\"{$css_url}\" rel=\"stylesheet\">";
|
||||
|
||||
$data = [];
|
||||
$data['entity'] = $entity;
|
||||
$data['lang'] = $client->preferredLocale();
|
||||
$data['includes'] = $this->parseLabelsAndValues($labels, $values, $designer->init()->getIncludes()->getHtml());
|
||||
$data['includes'] = str_replace('$css_url', $css_url, $data['includes']);
|
||||
$data['header'] = $this->parseLabelsAndValues($labels, $values, $designer->init()->getHeader()->getHtml());
|
||||
$data['body'] = $this->parseLabelsAndValues($labels, $values, $designer->init()->getBody()->getHtml());
|
||||
$data['product'] = $this->parseLabelsAndValues($labels, $values, $designer->init()->getProductTable());
|
||||
$data['task'] = $this->parseLabelsAndValues($labels, $values, $designer->init()->getTaskTable());
|
||||
$data['footer'] = $this->parseLabelsAndValues($labels, $values, $designer->init()->getFooter()->getHtml());
|
||||
|
||||
|
||||
|
||||
return view('pdf.stub', $data)->render();
|
||||
|
||||
}
|
||||
|
||||
private function parseLabelsAndValues($labels, $values, $section) :string
|
||||
|
1
public/css/design/bold.css
vendored
1
public/css/design/bold.css
vendored
File diff suppressed because one or more lines are too long
1
public/css/design/business.css
vendored
1
public/css/design/business.css
vendored
File diff suppressed because one or more lines are too long
1
public/css/design/clean.css
vendored
1
public/css/design/clean.css
vendored
File diff suppressed because one or more lines are too long
1
public/css/design/creative.css
vendored
1
public/css/design/creative.css
vendored
File diff suppressed because one or more lines are too long
0
public/css/design/custom.css
vendored
0
public/css/design/custom.css
vendored
1
public/css/design/elegant.css
vendored
1
public/css/design/elegant.css
vendored
File diff suppressed because one or more lines are too long
1
public/css/design/hipster.css
vendored
1
public/css/design/hipster.css
vendored
File diff suppressed because one or more lines are too long
1
public/css/design/modern.css
vendored
1
public/css/design/modern.css
vendored
File diff suppressed because one or more lines are too long
1
public/css/design/photo.css
vendored
1
public/css/design/photo.css
vendored
File diff suppressed because one or more lines are too long
2
public/css/design/plain.css
vendored
2
public/css/design/plain.css
vendored
File diff suppressed because one or more lines are too long
1
public/css/design/playful.css
vendored
1
public/css/design/playful.css
vendored
File diff suppressed because one or more lines are too long
96
tests/Feature/PreviewTest.php
Normal file
96
tests/Feature/PreviewTest.php
Normal file
@ -0,0 +1,96 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Designs\Designer;
|
||||
use App\Jobs\Account\CreateAccount;
|
||||
use App\Models\Account;
|
||||
use App\Models\Client;
|
||||
use App\Models\Design;
|
||||
use App\Models\User;
|
||||
use App\Utils\Traits\MakesHash;
|
||||
use App\Utils\Traits\UserSessionAttributes;
|
||||
use Faker\Factory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Foundation\Testing\WithFaker;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Session;
|
||||
use Tests\MockAccountData;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @covers App\Http\Controllers\PreviewController
|
||||
*/
|
||||
|
||||
class PreviewTest extends TestCase
|
||||
{
|
||||
use MakesHash;
|
||||
use DatabaseTransactions;
|
||||
use MockAccountData;
|
||||
|
||||
public function setUp() :void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->makeTestData();
|
||||
|
||||
Session::start();
|
||||
|
||||
$this->faker = \Faker\Factory::create();
|
||||
|
||||
Model::reguard();
|
||||
}
|
||||
|
||||
|
||||
public function testPreviewDesign()
|
||||
{
|
||||
$design = Design::find(3);
|
||||
|
||||
// $designer = new Designer($this->invoice, $design, $this->company->settings->pdf_variables, 'invoice');
|
||||
|
||||
$data = [
|
||||
'entity' => 'invoice',
|
||||
'entity_id' => $this->invoice->hashed_id,
|
||||
'body' => $design,
|
||||
];
|
||||
|
||||
|
||||
$response = $this->withHeaders([
|
||||
'X-API-SECRET' => config('ninja.api_secret'),
|
||||
'X-API-TOKEN' => $this->token
|
||||
])->post('/api/v1/preview', $data);
|
||||
|
||||
|
||||
$response->assertStatus(200);
|
||||
|
||||
// $arr = $response->json();
|
||||
|
||||
// \Log::error($arr);
|
||||
}
|
||||
|
||||
|
||||
public function testBlankEntityPreviewDesign()
|
||||
{
|
||||
$design = Design::find(3);
|
||||
|
||||
$data = [
|
||||
'body' => $design,
|
||||
];
|
||||
|
||||
|
||||
$response = $this->withHeaders([
|
||||
'X-API-SECRET' => config('ninja.api_secret'),
|
||||
'X-API-TOKEN' => $this->token
|
||||
])->post('/api/v1/preview', $data);
|
||||
|
||||
|
||||
$response->assertStatus(200);
|
||||
|
||||
// $arr = $response->json();
|
||||
|
||||
// \Log::error($arr);
|
||||
}
|
||||
}
|
@ -101,7 +101,7 @@ class DesignTest extends TestCase
|
||||
|
||||
$instance = Storage::disk('local')->put('invoice.pdf', $pdf);
|
||||
|
||||
exec('xdg-open ~/Code/invoiceninja/storage/app/invoice.pdf');
|
||||
//exec('xdg-open ~/Code/invoiceninja/storage/app/invoice.pdf');
|
||||
}
|
||||
|
||||
// public function testQuoteDesignWithRepeatingHeader()
|
||||
|
Loading…
x
Reference in New Issue
Block a user