mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Template Service
This commit is contained in:
parent
dc871af5eb
commit
91bd2e18f5
@ -11,11 +11,27 @@
|
|||||||
|
|
||||||
namespace App\Services\Template;
|
namespace App\Services\Template;
|
||||||
|
|
||||||
|
use App\Models\Task;
|
||||||
|
use App\Models\Quote;
|
||||||
|
use App\Models\Credit;
|
||||||
use App\Models\Design;
|
use App\Models\Design;
|
||||||
|
use App\Models\Invoice;
|
||||||
|
use App\Models\Payment;
|
||||||
|
use App\Models\Project;
|
||||||
use App\Utils\HtmlEngine;
|
use App\Utils\HtmlEngine;
|
||||||
|
use League\Fractal\Manager;
|
||||||
|
use App\Models\PurchaseOrder;
|
||||||
use App\Utils\VendorHtmlEngine;
|
use App\Utils\VendorHtmlEngine;
|
||||||
use App\Utils\PaymentHtmlEngine;
|
use App\Utils\PaymentHtmlEngine;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
|
use App\Transformers\TaskTransformer;
|
||||||
|
use App\Transformers\QuoteTransformer;
|
||||||
|
use App\Transformers\CreditTransformer;
|
||||||
|
use App\Transformers\InvoiceTransformer;
|
||||||
|
use App\Transformers\PaymentTransformer;
|
||||||
|
use App\Transformers\ProjectTransformer;
|
||||||
|
use App\Transformers\PurchaseOrderTransformer;
|
||||||
|
use League\Fractal\Serializer\ArraySerializer;
|
||||||
|
|
||||||
class TemplateService
|
class TemplateService
|
||||||
{
|
{
|
||||||
@ -232,80 +248,81 @@ nlog($data);
|
|||||||
})->toArray();
|
})->toArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
private function processInvoices($invoices): Collection
|
private function processInvoices($invoices): array
|
||||||
{
|
{
|
||||||
return $invoices->map(function($invoice){
|
$it = new InvoiceTransformer();
|
||||||
return $invoice->makeHidden($this->standard_excludes);
|
$it->setDefaultIncludes(['client']);
|
||||||
});
|
$manager = new Manager();
|
||||||
|
$resource = new \League\Fractal\Resource\Collection($invoices, $it, Invoice::class);
|
||||||
|
$i = $manager->createData($resource)->toArray();
|
||||||
|
return $i['data'];
|
||||||
}
|
}
|
||||||
|
|
||||||
private function processQuotes($quotes): Collection
|
private function processQuotes($quotes): Collection
|
||||||
{
|
{
|
||||||
return $quotes->makeHidden($this->standard_excludes);
|
$it = new QuoteTransformer();
|
||||||
// return $quotes->map(function ($quote){
|
$it->setDefaultIncludes(['client']);
|
||||||
// })->toArray();
|
$manager = new Manager();
|
||||||
|
$resource = new \League\Fractal\Resource\Collection($quotes, $it, Quote::class);
|
||||||
|
$i = $manager->createData($resource)->toArray();
|
||||||
|
return $i['data'];
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private function processCredits($credits): Collection
|
private function processCredits($credits): Collection
|
||||||
{
|
{
|
||||||
return $credits->makeHidden($this->standard_excludes);
|
$it = new CreditTransformer();
|
||||||
// return $credits->map(function ($credit){
|
$it->setDefaultIncludes(['client']);
|
||||||
// })->toArray();
|
$manager = new Manager();
|
||||||
|
$resource = new \League\Fractal\Resource\Collection($credits, $it, Credit::class);
|
||||||
|
$i = $manager->createData($resource)->toArray();
|
||||||
|
return $i['data'];
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private function processPayments($payments): Collection
|
private function processPayments($payments): Collection
|
||||||
{
|
{
|
||||||
return $payments->makeHidden([
|
$it = new PaymentTransformer();
|
||||||
'id',
|
$it->setDefaultIncludes(['client','invoices','paymentables']);
|
||||||
'user_id',
|
$manager = new Manager();
|
||||||
'assigned_user_id',
|
$resource = new \League\Fractal\Resource\Collection($payments, $it, Payment::class);
|
||||||
'client_id',
|
$i = $manager->createData($resource)->toArray();
|
||||||
'company_id',
|
return $i['data'];
|
||||||
'project_id',
|
|
||||||
'vendor_id',
|
|
||||||
'client_contact_id',
|
|
||||||
'invitation_id',
|
|
||||||
'company_gateway_id',
|
|
||||||
'transaction_id',
|
|
||||||
]);
|
|
||||||
// return $payments->map(function ($payment){
|
|
||||||
// })->toArray();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private function processTasks($tasks): Collection
|
private function processTasks($tasks): Collection
|
||||||
{
|
{
|
||||||
return $tasks->makeHidden([
|
$it = new TaskTransformer();
|
||||||
'id',
|
$it->setDefaultIncludes(['client','tasks','project','invoice']);
|
||||||
'user_id',
|
$manager = new Manager();
|
||||||
'assigned_user_id',
|
$resource = new \League\Fractal\Resource\Collection($tasks, $it, Task::class);
|
||||||
'client_id',
|
$i = $manager->createData($resource)->toArray();
|
||||||
'company_id',
|
return $i['data'];
|
||||||
'project_id',
|
|
||||||
'invoice_id'
|
|
||||||
]);
|
|
||||||
// return $tasks->map(function ($task){
|
|
||||||
// })->toArray();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private function processProjects($projects): Collection
|
private function processProjects($projects): Collection
|
||||||
{
|
{
|
||||||
return $projects->makeHidden([
|
|
||||||
'id',
|
|
||||||
'client_id',
|
|
||||||
'company_id',
|
|
||||||
'user_id',
|
|
||||||
'assigned_user_id',
|
|
||||||
]);
|
|
||||||
|
|
||||||
// return $projects->map(function ($project){
|
$it = new ProjectTransformer();
|
||||||
// })->toArray();
|
$it->setDefaultIncludes(['client','tasks']);
|
||||||
|
$manager = new Manager();
|
||||||
|
$resource = new \League\Fractal\Resource\Collection($projects, $it, Project::class);
|
||||||
|
$i = $manager->createData($resource)->toArray();
|
||||||
|
return $i['data'];
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private function processPurchaseOrders($purchase_orders): array
|
private function processPurchaseOrders($purchase_orders): array
|
||||||
{
|
{
|
||||||
return $purchase_orders->makeHidden($this->purchase_excludes);
|
|
||||||
|
$it = new PurchaseOrderTransformer();
|
||||||
|
$it->setDefaultIncludes(['vendor','expense']);
|
||||||
|
$manager = new Manager();
|
||||||
|
$resource = new \League\Fractal\Resource\Collection($purchase_orders, $it, PurchaseOrder::class);
|
||||||
|
$i = $manager->createData($resource)->toArray();
|
||||||
|
return $i['data'];
|
||||||
|
|
||||||
// return $purchase_orders->map(function ($purchase_order){
|
|
||||||
// })->toArray();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -79,6 +79,37 @@ class TemplateTest extends TestCase
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testDoubleEntityTemplateServiceBuild()
|
||||||
|
{
|
||||||
|
$design_model = Design::find(2);
|
||||||
|
|
||||||
|
$replicated_design = $design_model->replicate();
|
||||||
|
$design = $replicated_design->design;
|
||||||
|
$design->body .= $this->body;
|
||||||
|
$replicated_design->design = $design;
|
||||||
|
$replicated_design->is_custom = true;
|
||||||
|
$replicated_design->save();
|
||||||
|
|
||||||
|
$i2 = Invoice::factory()
|
||||||
|
->for($this->client)
|
||||||
|
->create([
|
||||||
|
'company_id' => $this->company->id,
|
||||||
|
'user_id' => $this->user->id,
|
||||||
|
'status_id' => Invoice::STATUS_SENT,
|
||||||
|
'design_id' => $replicated_design->id,
|
||||||
|
'balance' => 100,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$data = [];
|
||||||
|
$data['invoices'] = collect([$this->invoice, $i2]);
|
||||||
|
|
||||||
|
$ts = $replicated_design->service()->build($data);
|
||||||
|
|
||||||
|
// nlog("results = ");
|
||||||
|
// nlog($ts->getHtml());
|
||||||
|
$this->assertNotNull($ts->getHtml());
|
||||||
|
}
|
||||||
|
|
||||||
public function testTemplateServiceBuild()
|
public function testTemplateServiceBuild()
|
||||||
{
|
{
|
||||||
$design_model = Design::find(2);
|
$design_model = Design::find(2);
|
||||||
@ -95,7 +126,8 @@ class TemplateTest extends TestCase
|
|||||||
|
|
||||||
$ts = $replicated_design->service()->build($data);
|
$ts = $replicated_design->service()->build($data);
|
||||||
|
|
||||||
nlog($ts->getHtml());
|
// nlog("results = ");
|
||||||
|
// nlog($ts->getHtml());
|
||||||
$this->assertNotNull($ts->getHtml());
|
$this->assertNotNull($ts->getHtml());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -150,10 +182,8 @@ class TemplateTest extends TestCase
|
|||||||
|
|
||||||
nlog("Twig + PDF Gen Time: " . $end-$start);
|
nlog("Twig + PDF Gen Time: " . $end-$start);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function testStaticPdfGeneration()
|
public function testStaticPdfGeneration()
|
||||||
{
|
{
|
||||||
$start = microtime(true);
|
$start = microtime(true);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user