Updated documentation
This commit is contained in:
parent
9de00dd511
commit
d49c9703a7
|
|
@ -0,0 +1,89 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Invoice Ninja (https://invoiceninja.com).
|
||||
*
|
||||
* @link https://github.com/invoiceninja/invoiceninja source repository
|
||||
*
|
||||
* @copyright Copyright (c) 2024. Invoice Ninja LLC (https://invoiceninja.com)
|
||||
*
|
||||
* @license https://www.elastic.co/licensing/elastic-license
|
||||
*/
|
||||
|
||||
namespace App\Services\Report;
|
||||
|
||||
use App\Models\User;
|
||||
use App\Utils\Ninja;
|
||||
use App\Utils\Number;
|
||||
use App\Models\Client;
|
||||
use League\Csv\Writer;
|
||||
use App\Models\Company;
|
||||
use App\Models\Invoice;
|
||||
use App\Libraries\MultiDB;
|
||||
use App\Export\CSV\BaseExport;
|
||||
use App\Utils\Traits\MakesDates;
|
||||
use Illuminate\Support\Facades\App;
|
||||
use App\Services\Template\TemplateService;
|
||||
|
||||
class ProjectReport extends BaseExport
|
||||
{
|
||||
use MakesDates;
|
||||
|
||||
private string $template = '/views/templates/reports/project_report.html';
|
||||
|
||||
/**
|
||||
@param array $input
|
||||
[
|
||||
'date_range',
|
||||
'start_date',
|
||||
'end_date',
|
||||
'projects',
|
||||
]
|
||||
*/
|
||||
public function __construct(public Company $company, public array $input)
|
||||
{
|
||||
}
|
||||
|
||||
public function run()
|
||||
{
|
||||
|
||||
MultiDB::setDb($this->company->db);
|
||||
App::forgetInstance('translator');
|
||||
App::setLocale($this->company->locale());
|
||||
$t = app('translator');
|
||||
$t->replace(Ninja::transformTranslations($this->company->settings));
|
||||
|
||||
return $this->getPdf();
|
||||
}
|
||||
|
||||
public function getPdf()
|
||||
{
|
||||
$user = isset($this->input['user_id']) ? User::withTrashed()->find($this->input['user_id']) : $this->company->owner();
|
||||
|
||||
$user_name = $user ? $user->present()->name() : '';
|
||||
|
||||
|
||||
$projects = \App\Models\Project::where('company_id', $this->company->id)
|
||||
->whereIn('id', $this->transformKeys($this->input['projects'])
|
||||
->get();
|
||||
|
||||
$data = [
|
||||
'projects' => $projects,
|
||||
'company_logo' => $this->company->present()->logo(),
|
||||
'company_name' => $this->company->present()->name(),
|
||||
'created_on' => $this->translateDate(now()->format('Y-m-d'), $this->company->date_format(), $this->company->locale()),
|
||||
'created_by' => $user_name,
|
||||
];
|
||||
|
||||
$ts = new TemplateService();
|
||||
|
||||
$ts_instance = $ts->setCompany($this->company)
|
||||
->setData($data)
|
||||
->setRawTemplate(file_get_contents(resource_path($this->template)))
|
||||
->parseNinjaBlocks()
|
||||
->save();
|
||||
|
||||
return $ts_instance->getPdf();
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue