1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Sprain\SwissQrBill\PaymentPart\Output\PhpWordOutput\Table; |
4
|
|
|
|
5
|
|
|
use PhpOffice\PhpWord\Element\Cell; |
6
|
|
|
use PhpOffice\PhpWord\Element\Section; |
7
|
|
|
use PhpOffice\PhpWord\SimpleType\JcTable; |
8
|
|
|
use PhpOffice\PhpWord\Style\Table; |
9
|
|
|
use PhpOffice\PhpWord\Style\TablePosition; |
10
|
|
|
use Sprain\SwissQrBill\PaymentPart\Output\PhpWordOutput\PhpWordHelper; |
11
|
|
|
|
12
|
|
|
class Bill |
13
|
|
|
{ |
14
|
|
|
private \PhpOffice\PhpWord\Element\Table $table; |
15
|
|
|
private ?Cell $separate = null; |
16
|
|
|
private Receipt $receipt; |
17
|
|
|
private Payment $payment; |
18
|
|
|
|
19
|
|
|
public function __construct(Section $section, bool $isPrintable) |
20
|
|
|
{ |
21
|
|
|
$this->table = $section->addTable([ |
22
|
|
|
'layout' => Table::LAYOUT_FIXED, |
23
|
|
|
'width' => PhpWordHelper::mmToTwip(Style::DIN_A4_WIDTH), |
24
|
|
|
'height' => PhpWordHelper::mmToTwip(Style::DIN_A6_WIDTH), |
25
|
|
|
'position' => [ |
26
|
|
|
'horzAnchor' => TablePosition::HANCHOR_PAGE, |
27
|
|
|
'vertAnchor' => TablePosition::VANCHOR_PAGE, |
28
|
|
|
'tblpXSpec' => TablePosition::XALIGN_CENTER, |
29
|
|
|
'tblpYSpec' => TablePosition::YALIGN_BOTTOM, |
30
|
|
|
'leftFromText' => 0, |
31
|
|
|
'rightFromText' => 0, |
32
|
|
|
'topFromText' => 0, |
33
|
|
|
'bottomFromText' => 0, |
34
|
|
|
], |
35
|
|
|
]); |
36
|
|
|
$verticalLine = []; |
37
|
|
|
if (!$isPrintable) { |
38
|
|
|
$width = PhpWordHelper::mmToTwip(Style::DIN_A4_WIDTH); |
39
|
|
|
$height = PhpWordHelper::mmToTwip(5); |
40
|
|
|
$separatorCellStyle = [ |
41
|
|
|
'borderBottomColor' => Style::NON_PRINTABLE_BORDER_COLOR, |
42
|
|
|
'borderBottomSize' => Style::NON_PRINTABLE_BORDER_SIZE, |
43
|
|
|
'borderBottomStyle' => Style::NON_PRINTABLE_BORDER_TYPE, |
44
|
|
|
'gridSpan' => 2, |
45
|
|
|
'valign' => JcTable::CENTER, |
46
|
|
|
]; |
47
|
|
|
$this->separate = $this->table->addRow($height)->addCell($width, $separatorCellStyle); |
48
|
|
|
$verticalLine = [ |
49
|
|
|
'borderRightColor' => Style::NON_PRINTABLE_BORDER_COLOR, |
50
|
|
|
'borderRightSize' => Style::NON_PRINTABLE_BORDER_SIZE, |
51
|
|
|
'borderRightStyle' => Style::NON_PRINTABLE_BORDER_TYPE, |
52
|
|
|
]; |
53
|
|
|
} |
54
|
|
|
$row = $this->table->addRow(PhpWordHelper::mmToTwip(Style::INNER_HEIGHT)); |
55
|
|
|
$cell = $row->addCell(PhpWordHelper::mmToTwip(Style::RECEIPT_WIDTH), $verticalLine); |
56
|
|
|
$cell = $cell->addTable([ |
57
|
|
|
'layout' => Table::LAYOUT_FIXED, |
58
|
|
|
'width' => PhpWordHelper::percentToPct(100), |
59
|
|
|
'unit' => 'pct', |
60
|
|
|
'cellMargin' => PhpWordHelper::mmToTwip(5), |
61
|
|
|
])->addRow()->addCell(); |
62
|
|
|
$this->receipt = new Receipt($cell); |
63
|
|
|
|
64
|
|
|
$cell = $row->addCell(PhpWordHelper::mmToTwip(Style::PAYMENT_PART_WIDTH)); |
65
|
|
|
$cell = $cell->addTable([ |
66
|
|
|
'layout' => Table::LAYOUT_FIXED, |
67
|
|
|
'width' => PhpWordHelper::percentToPct(100), |
68
|
|
|
'unit' => 'pct', |
69
|
|
|
'cellMargin' => PhpWordHelper::mmToTwip(5), |
70
|
|
|
])->addRow()->addCell(); |
71
|
|
|
$this->payment = new Payment($cell); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
public function getSeparate() : ?Cell |
75
|
|
|
{ |
76
|
|
|
return $this->separate; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
public function getReceipt() : Receipt |
80
|
|
|
{ |
81
|
|
|
return $this->receipt; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
public function getPayment() : Payment |
85
|
|
|
{ |
86
|
|
|
return $this->payment; |
87
|
|
|
} |
88
|
|
|
} |
89
|
|
|
|