Pdf builder for invoices
This commit is contained in:
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
namespace Classes\Pdf;
|
namespace Classes\Pdf;
|
||||||
|
|
||||||
use Forms\Common\EmployeeFormPDFBuilder;
|
use Invoices\InvoicePDFBuilder;
|
||||||
|
|
||||||
class PDFRegister
|
class PDFRegister
|
||||||
{
|
{
|
||||||
@@ -10,8 +10,8 @@ class PDFRegister
|
|||||||
|
|
||||||
public static function init()
|
public static function init()
|
||||||
{
|
{
|
||||||
self::put('empf', function ($data) {
|
self::put('invoice', function ($data) {
|
||||||
return new EmployeeFormPDFBuilder($data);
|
return new InvoicePDFBuilder($data);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
2
extensions/invoices/dist/invoices.js
vendored
2
extensions/invoices/dist/invoices.js
vendored
@@ -3099,7 +3099,7 @@ var ModuleBase = /*#__PURE__*/function () {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}catch(e){
|
}catch(e){
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|||||||
2
extensions/invoices/dist/invoices.js.map
vendored
2
extensions/invoices/dist/invoices.js.map
vendored
File diff suppressed because one or more lines are too long
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"label": "Invoices",
|
"label": "Invoices",
|
||||||
"menu": ["Invoices", "fa-file"],
|
"menu": ["Invoices", "fa-file"],
|
||||||
"icon": "fa-file",
|
"icon": "fa-file-invoice",
|
||||||
"user_levels": [
|
"user_levels": [
|
||||||
"Admin",
|
"Admin",
|
||||||
"Manager",
|
"Manager",
|
||||||
|
|||||||
56
extensions/invoices/src/Invoices/InvoicePDFBuilder.php
Normal file
56
extensions/invoices/src/Invoices/InvoicePDFBuilder.php
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
42
extensions/invoices/src/Invoices/Pdf/InvoicePdf.php
Normal file
42
extensions/invoices/src/Invoices/Pdf/InvoicePdf.php
Normal 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);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user