Pdf builder for invoices

This commit is contained in:
ddave
2021-07-09 11:24:04 +02:00
parent 5416bdb840
commit 7228bb2922
6 changed files with 104 additions and 6 deletions

View File

@@ -2,7 +2,7 @@
namespace Classes\Pdf;
use Forms\Common\EmployeeFormPDFBuilder;
use Invoices\InvoicePDFBuilder;
class PDFRegister
{
@@ -10,8 +10,8 @@ class PDFRegister
public static function init()
{
self::put('empf', function ($data) {
return new EmployeeFormPDFBuilder($data);
self::put('invoice', function ($data) {
return new InvoicePDFBuilder($data);
});
}

View File

@@ -3099,7 +3099,7 @@ var ModuleBase = /*#__PURE__*/function () {
}
}
}catch(e){
}
}
return null;
}
*/

File diff suppressed because one or more lines are too long

View File

@@ -1,7 +1,7 @@
{
"label": "Invoices",
"menu": ["Invoices", "fa-file"],
"icon": "fa-file",
"icon": "fa-file-invoice",
"user_levels": [
"Admin",
"Manager",

View File

@@ -0,0 +1,56 @@
<?php
namespace Invoices;
use Classes\Authorizable;
use Classes\BaseService;
use Classes\FileService;
use Classes\IceResponse;
use Classes\Pdf\PdfBuilder;
use Employees\Common\Model\Employee;
use Invoices\Pdf\InvoicePdf;
class InvoicePDFBuilder implements Authorizable, PdfBuilder
{
protected $formId;
public function __construct($formId)
{
$this->formId = $formId;
}
public function granted(): bool
{
$empForm = new EmployeeForm();
$empForm->Load("id = ?", array($this->formId));
$currentEmployeeId = BaseService::getInstance()->getCurrentProfileId();
$user = BaseService::getInstance()->getCurrentUser();
return ($currentEmployeeId == $empForm->employee
|| $user->user_level === 'Admin'
|| BaseService::getInstance()->isSubordinateEmployee($currentEmployeeId, $empForm->employee)
);
}
public function createPdf()
{
$response = FormsActionManager::getFormDataById($this->formId);
if ($response->getStatus() === IceResponse::ERROR) {
return null;
}
$form = $response->getData()['form'];
$employeeForm = $response->getData()['data'];
$employee = new Employee();
$employee->Load('id = ?', [$employeeForm->employee]);
$employee = FileService::getInstance()->updateSmallProfileImage($employee);
$pdf = new InvoicePdf($invoice);
$pdf->initialize($form->name);
$pdf->process();
return $pdf;
}
}

View File

@@ -0,0 +1,42 @@
<?php
namespace Invoices\Pdf;
use Classes\Pdf\BasePdfTemplate;
use Invoices\Model\Invoice;
class InvoicePdf extends BasePdfTemplate
{
protected $invoice;
public function __construct(Invoice $invoice)
{
parent::__construct();
$this->invoice = $invoice;
}
public function process()
{
$this->addH3($this->form->name, 'B', 'L');
$this->addBorderedText($this->invoice->description);
}
// protected function addFormItems()
// {
// $signatures = [];
// $fields = json_decode($this->form->items);
// foreach ($fields as $field) {
// if ($field->field_type === 'signature') {
// $signatures[$field->field_label] = $this->employeeForm->{$field->name};
// } elseif ($field->field_type === 'fileupload') {
// // ignore
// } else {
// $this->addKeyValue($field->field_label, $this->employeeForm->{$field->name}, $field->field_type);
// }
// }
//
// foreach ($signatures as $name => $data) {
// $this->addSignature($name, $data);
// }
// }
}