mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-05-24 02:14:21 -04:00
Template stubs
This commit is contained in:
parent
7281f0f281
commit
f655064fa5
@ -361,23 +361,23 @@ class PreviewController extends BaseController
|
||||
|
||||
$design_object = json_decode(json_encode(request()->input('design')),1);
|
||||
|
||||
$client_id = Invoice::whereHas('payments')->company()->where('is_deleted', 0)->orderBy('id','desc')->first()->client_id;
|
||||
$vendor_id = PurchaseOrder::query()->company()->where('is_deleted', 0)->orderBy('id', 'desc')->first()->vendor_id;
|
||||
// $client_id = Invoice::whereHas('payments')->company()->where('is_deleted', 0)->orderBy('id','desc')->first()->client_id;
|
||||
// $vendor_id = PurchaseOrder::query()->company()->where('is_deleted', 0)->orderBy('id', 'desc')->first()->vendor_id;
|
||||
|
||||
$data = [
|
||||
'invoices' => Invoice::whereHas('payments')->company()->with('client','payments')->where('client_id', $client_id)->orderBy('id','desc')->take(4)->get(),
|
||||
'quotes' => Quote::query()->company()->with('client')->where('client_id', $client_id)->orderBy('id','desc')->take(4)->get(),
|
||||
'credits' => Credit::query()->company()->with('client')->where('client_id', $client_id)->orderBy('id','desc')->take(4)->get(),
|
||||
'payments' => Payment::query()->company()->with('client')->where('client_id', $client_id)->orderBy('id','desc')->take(4)->get(),
|
||||
'purchase_orders' => PurchaseOrder::query()->company()->with('vendor')->where('vendor_id', $vendor_id)->orderBy('id','desc')->take(5)->get(),
|
||||
'tasks' => Task::query()->company()->with('client','invoice')->where('client_id', $client_id)->orderBy('id','desc')->take(2)->get(),
|
||||
'projects' => Project::query()->company()->with('tasks','client')->where('client_id', $client_id)->orderBy('id','desc')->take(2)->get(),
|
||||
];
|
||||
// $data = [
|
||||
// 'invoices' => Invoice::whereHas('payments')->company()->with('client','payments')->where('client_id', $client_id)->orderBy('id','desc')->take(4)->get(),
|
||||
// 'quotes' => Quote::query()->company()->with('client')->where('client_id', $client_id)->orderBy('id','desc')->take(4)->get(),
|
||||
// 'credits' => Credit::query()->company()->with('client')->where('client_id', $client_id)->orderBy('id','desc')->take(4)->get(),
|
||||
// 'payments' => Payment::query()->company()->with('client')->where('client_id', $client_id)->orderBy('id','desc')->take(4)->get(),
|
||||
// 'purchase_orders' => PurchaseOrder::query()->company()->with('vendor')->where('vendor_id', $vendor_id)->orderBy('id','desc')->take(5)->get(),
|
||||
// 'tasks' => Task::query()->company()->with('client','invoice')->where('client_id', $client_id)->orderBy('id','desc')->take(2)->get(),
|
||||
// 'projects' => Project::query()->company()->with('tasks','client')->where('client_id', $client_id)->orderBy('id','desc')->take(2)->get(),
|
||||
// ];
|
||||
|
||||
$ts = (new TemplateService());
|
||||
$ts->setCompany($company)
|
||||
->setTemplate($design_object)
|
||||
->build($data);
|
||||
->mock();
|
||||
|
||||
$html = $ts->getHtml();
|
||||
|
||||
|
@ -44,16 +44,14 @@ class TemplateMock
|
||||
return $this->createVariables($type);
|
||||
})->toArray();
|
||||
|
||||
$this->engines = [
|
||||
'invoices' => json_decode($this->invoice_data, true),
|
||||
'quotes' => json_decode($this->quote_data, true),
|
||||
'credits' => json_decode($this->credit_data, true),
|
||||
'tasks' => json_decode($this->task_data, true),
|
||||
'projects' => json_decode($this->project_data, true),
|
||||
'payments' => json_decode($this->payment_data, true),
|
||||
'purchase_orders' => json_decode($this->purchase_order_data, true),
|
||||
];
|
||||
|
||||
$this->engines['invoices'] = json_decode($this->invoice_data, true);
|
||||
$this->engines['quotes'] = json_decode($this->quote_data, true);
|
||||
$this->engines['credits'] = json_decode($this->credit_data, true);
|
||||
$this->engines['tasks'] = json_decode($this->task_data, true);
|
||||
$this->engines['projects'] = json_decode($this->project_data, true);
|
||||
$this->engines['payments'] = json_decode($this->payment_data, true);
|
||||
$this->engines['purchase_orders'] = json_decode($this->purchase_order_data, true);
|
||||
|
||||
return $this;
|
||||
|
||||
}
|
||||
|
@ -46,6 +46,8 @@ class TemplateService
|
||||
|
||||
private array $data = [];
|
||||
|
||||
private array $variables = [];
|
||||
|
||||
public ?Company $company;
|
||||
|
||||
public function __construct(public ?Design $template = null)
|
||||
@ -85,18 +87,28 @@ class TemplateService
|
||||
$this->compose()
|
||||
->processData($data)
|
||||
->parseNinjaBlocks()
|
||||
->parseVariables($data);
|
||||
->processVariables($data)
|
||||
->parseVariables();
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
private function processVariables($data): self
|
||||
{
|
||||
$this->variables = $this->resolveHtmlEngine($data);
|
||||
|
||||
return $this;
|
||||
}
|
||||
public function mock(): self
|
||||
{
|
||||
$tm = new TemplateMock($this->company);
|
||||
$tm->init();
|
||||
|
||||
$this->data = $tm->engines;
|
||||
$this->variables = $tm->variables[0];
|
||||
|
||||
$this->parseNinjaBlocks()
|
||||
->parseVariables($tm->variables);
|
||||
->parseVariables();
|
||||
|
||||
return $this;
|
||||
}
|
||||
@ -153,13 +165,12 @@ class TemplateService
|
||||
* @param array $data
|
||||
* @return self
|
||||
*/
|
||||
private function parseVariables(array $data): self
|
||||
private function parseVariables(): self
|
||||
{
|
||||
$variables = $this->resolveHtmlEngine($data);
|
||||
|
||||
$html = $this->getHtml();
|
||||
|
||||
foreach($variables as $key => $variable) {
|
||||
foreach($this->variables as $key => $variable) {
|
||||
|
||||
if(isset($variable['labels']) && isset($variable['values']))
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user