mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-06-01 01:54:40 -04:00
Update ClientStatementController
This commit is contained in:
parent
139ede5db0
commit
745a81d3c8
@ -110,8 +110,11 @@ class ClientStatementController extends BaseController
|
|||||||
|
|
||||||
public function statement(CreateStatementRequest $request)
|
public function statement(CreateStatementRequest $request)
|
||||||
{
|
{
|
||||||
$pdf = $this->createStatement($request);
|
$pdf = $request->client()->service()->statement([
|
||||||
|
'start_date' => $request->start_date,
|
||||||
|
'end_date' => $request->end_date,
|
||||||
|
]);
|
||||||
|
|
||||||
if ($pdf) {
|
if ($pdf) {
|
||||||
return response()->streamDownload(function () use ($pdf) {
|
return response()->streamDownload(function () use ($pdf) {
|
||||||
echo $pdf;
|
echo $pdf;
|
||||||
@ -120,88 +123,4 @@ class ClientStatementController extends BaseController
|
|||||||
|
|
||||||
return response()->json(['message' => 'Something went wrong. Please check logs.']);
|
return response()->json(['message' => 'Something went wrong. Please check logs.']);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function createStatement(CreateStatementRequest $request): ?string
|
|
||||||
{
|
|
||||||
$invitation = false;
|
|
||||||
|
|
||||||
if ($request->getInvoices()->count() >= 1) {
|
|
||||||
$this->entity = $request->getInvoices()->first();
|
|
||||||
$invitation = $this->entity->invitations->first();
|
|
||||||
}
|
|
||||||
else if ($request->getPayments()->count() >= 1) {
|
|
||||||
$this->entity = $request->getPayments()->first()->invoices->first()->invitations->first();
|
|
||||||
$invitation = $this->entity->invitations->first();
|
|
||||||
}
|
|
||||||
|
|
||||||
$entity_design_id = 1;
|
|
||||||
|
|
||||||
$entity_design_id = $this->entity->design_id
|
|
||||||
? $this->entity->design_id
|
|
||||||
: $this->decodePrimaryKey($this->entity->client->getSetting('invoice_design_id'));
|
|
||||||
|
|
||||||
|
|
||||||
$design = Design::find($entity_design_id);
|
|
||||||
|
|
||||||
if (!$design) {
|
|
||||||
$design = Design::find($entity_design_id);
|
|
||||||
}
|
|
||||||
|
|
||||||
$html = new HtmlEngine($invitation);
|
|
||||||
|
|
||||||
$options = [
|
|
||||||
'start_date' => $request->start_date,
|
|
||||||
'end_date' => $request->end_date,
|
|
||||||
'show_payments_table' => $request->show_payments_table,
|
|
||||||
'show_aging_table' => $request->show_aging_table,
|
|
||||||
];
|
|
||||||
|
|
||||||
if ($design->is_custom) {
|
|
||||||
$options['custom_partials'] = \json_decode(\json_encode($design->design), true);
|
|
||||||
$template = new PdfMakerDesign(PdfDesignModel::CUSTOM, $options);
|
|
||||||
} else {
|
|
||||||
$template = new PdfMakerDesign(strtolower($design->name), $options);
|
|
||||||
}
|
|
||||||
|
|
||||||
$variables = $html->generateLabelsAndValues();
|
|
||||||
|
|
||||||
$state = [
|
|
||||||
'template' => $template->elements([
|
|
||||||
'client' => $this->entity->client,
|
|
||||||
'entity' => $this->entity,
|
|
||||||
'pdf_variables' => (array)$this->entity->company->settings->pdf_variables,
|
|
||||||
'$product' => $design->design->product,
|
|
||||||
'variables' => $variables,
|
|
||||||
'invoices' => $request->getInvoices(),
|
|
||||||
'payments' => $request->getPayments(),
|
|
||||||
'aging' => $request->getAging(),
|
|
||||||
], \App\Services\PdfMaker\Design::STATEMENT),
|
|
||||||
'variables' => $variables,
|
|
||||||
'options' => [],
|
|
||||||
'process_markdown' => $this->entity->client->company->markdown_enabled,
|
|
||||||
];
|
|
||||||
|
|
||||||
$maker = new PdfMakerService($state);
|
|
||||||
|
|
||||||
$maker
|
|
||||||
->design($template)
|
|
||||||
->build();
|
|
||||||
|
|
||||||
$pdf = null;
|
|
||||||
|
|
||||||
try {
|
|
||||||
if (config('ninja.phantomjs_pdf_generation') || config('ninja.pdf_generator') == 'phantom') {
|
|
||||||
$pdf = (new Phantom)->convertHtmlToPdf($maker->getCompiledHTML(true));
|
|
||||||
}
|
|
||||||
else if (config('ninja.invoiceninja_hosted_pdf_generation') || config('ninja.pdf_generator') == 'hosted_ninja') {
|
|
||||||
$pdf = (new NinjaPdf())->build($maker->getCompiledHTML(true));
|
|
||||||
} else {
|
|
||||||
$pdf = $this->makePdf(null, null, $maker->getCompiledHTML(true));
|
|
||||||
}
|
|
||||||
} catch (\Exception $e) {
|
|
||||||
nlog(print_r($e->getMessage(), 1));
|
|
||||||
}
|
|
||||||
|
|
||||||
return $pdf;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user