mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-05-24 02:14:21 -04:00
Merging designer changes
This commit is contained in:
parent
8dcc3c4cbd
commit
2a9fe02546
@ -32,6 +32,7 @@ use App\Repositories\CreditRepository;
|
||||
use App\Repositories\InvoiceRepository;
|
||||
use App\Repositories\QuoteRepository;
|
||||
use App\Repositories\RecurringInvoiceRepository;
|
||||
use App\Services\Pdf\PdfMock;
|
||||
use App\Services\PdfMaker\Design;
|
||||
use App\Services\PdfMaker\Design as PdfDesignModel;
|
||||
use App\Services\PdfMaker\Design as PdfMakerDesign;
|
||||
@ -182,13 +183,7 @@ class PreviewController extends BaseController
|
||||
return response()->json(['message' => 'This server cannot handle this request.'], 400);
|
||||
}
|
||||
|
||||
$stub = new StubBuilder(auth()->user()->company(), auth()->user());
|
||||
$stub->setEntityType($request->entity_type)
|
||||
->setSettings($request->settings)
|
||||
->setSettingsType($request->settings_type)
|
||||
->build();
|
||||
|
||||
$pdf = $stub->getPdf();
|
||||
$pdf = (new PdfMock(Invoice::class))->build()->getPdf();
|
||||
|
||||
$response = Response::make($pdf, 200);
|
||||
$response->header('Content-Type', 'application/pdf');
|
||||
|
@ -14,26 +14,69 @@ namespace App\Services\Pdf;
|
||||
use App\Models\Quote;
|
||||
use App\Models\Client;
|
||||
use App\Models\Credit;
|
||||
use App\Models\Design;
|
||||
use App\Models\Vendor;
|
||||
use App\Models\Account;
|
||||
use App\Models\Company;
|
||||
use App\Models\Country;
|
||||
use App\Models\Invoice;
|
||||
use App\Models\Currency;
|
||||
use App\Models\PurchaseOrder;
|
||||
use App\Services\Pdf\PdfBuilder;
|
||||
use App\Services\Pdf\PdfService;
|
||||
use App\Models\InvoiceInvitation;
|
||||
use App\Services\Pdf\PdfDesigner;
|
||||
use App\Services\Pdf\PdfConfiguration;
|
||||
|
||||
class PdfMock
|
||||
{
|
||||
|
||||
private mixed $mock;
|
||||
|
||||
|
||||
public function __construct(public mixed $entity_type)
|
||||
{}
|
||||
|
||||
public function build()
|
||||
public function getPdf(): mixed
|
||||
{
|
||||
|
||||
$mock = $this->initEntity();
|
||||
$pdf_service = new PdfService($this->mock->invitation);
|
||||
|
||||
$pdf_config = (new PdfConfiguration($pdf_service));
|
||||
$pdf_config->entity = $this->mock;
|
||||
$pdf_config->setTaxMap($this->mock->tax_map);
|
||||
$pdf_config->setTotalTaxMap($this->mock->total_tax_map);
|
||||
$pdf_config->setCurrency(Currency::find(1));
|
||||
$pdf_config->setCountry(Country::find(840));
|
||||
$pdf_config->client = $this->mock->client;
|
||||
$pdf_config->entity_design_id = 'invoice_design_id';
|
||||
$pdf_config->settings_object = $this->mock->client;
|
||||
$pdf_config->entity_string = 'invoice';
|
||||
$pdf_config->settings = (object)$pdf_config->service->company->settings;
|
||||
$pdf_config->setPdfVariables();
|
||||
$pdf_config->design = Design::find(2);
|
||||
$pdf_config->currency_entity = $this->mock->client;
|
||||
|
||||
$pdf_service->config = $pdf_config;
|
||||
|
||||
return $mock;
|
||||
$pdf_designer = (new PdfDesigner($pdf_service))->build();
|
||||
$pdf_service->designer = $pdf_designer;
|
||||
|
||||
$pdf_service->html_variables = $this->getStubVariables();
|
||||
|
||||
$pdf_builder = (new PdfBuilder($pdf_service))->build();
|
||||
$pdf_service->builder = $pdf_builder;
|
||||
|
||||
$html = $pdf_service->getHtml();
|
||||
|
||||
return $pdf_service->resolvePdfEngine($html);
|
||||
}
|
||||
|
||||
public function build(): self
|
||||
{
|
||||
|
||||
$this->mock = $this->initEntity();
|
||||
|
||||
return $this;
|
||||
|
||||
}
|
||||
|
||||
|
@ -79,7 +79,7 @@ class PdfService
|
||||
{
|
||||
try {
|
||||
|
||||
$pdf = $this->resolvePdfEngine();
|
||||
$pdf = $this->resolvePdfEngine($this->getHtml());
|
||||
|
||||
$numbered_pdf = $this->pageNumbering($pdf, $this->company);
|
||||
|
||||
@ -140,15 +140,15 @@ class PdfService
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
private function resolvePdfEngine(): mixed
|
||||
public function resolvePdfEngine(string $html): mixed
|
||||
{
|
||||
|
||||
if (config('ninja.phantomjs_pdf_generation') || config('ninja.pdf_generator') == 'phantom') {
|
||||
$pdf = (new Phantom)->convertHtmlToPdf($this->getHtml());
|
||||
$pdf = (new Phantom)->convertHtmlToPdf($html);
|
||||
} elseif (config('ninja.invoiceninja_hosted_pdf_generation') || config('ninja.pdf_generator') == 'hosted_ninja') {
|
||||
$pdf = (new NinjaPdf())->build($this->getHtml());
|
||||
$pdf = (new NinjaPdf())->build($html);
|
||||
} else {
|
||||
$pdf = $this->makePdf(null, null, $this->getHtml());
|
||||
$pdf = $this->makePdf(null, null, $html);
|
||||
}
|
||||
|
||||
return $pdf;
|
||||
|
@ -92,7 +92,6 @@ class PdfmockTest extends TestCase
|
||||
|
||||
$html = $pdf_service->getHtml();
|
||||
|
||||
nlog($html);
|
||||
$this->assertNotNull($html);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user