Bug 5194: The company name is not displayed on invoices if the logo is set. Fixed.
[fa-stable.git] / reporting / includes / header2.inc
1 <?php
2 /**********************************************************************
3     Copyright (C) FrontAccounting, LLC.
4         Released under the terms of the GNU General Public License, GPL, 
5         as published by the Free Software Foundation, either version 3 
6         of the License, or (at your option) any later version.
7     This program is distributed in the hope that it will be useful,
8     but WITHOUT ANY WARRANTY; without even the implied warranty of
9     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
10     See the License here <http://www.gnu.org/licenses/gpl-3.0.html>.
11 ***********************************************************************/
12
13 /**
14         Document blueprint use following parameters set in doctext.inc:
15
16         $Addr1, $Addr2 - address info
17         $Payment_Terms - payment terms line
18         $Footer - footer texts
19         $this->company - company info
20         $this->title - report title
21         $this->formData - some other info
22 ***/
23
24                 $this->row = $this->pageHeight - $this->topMargin;
25
26                 $upper = $this->row - 2 * $this->lineHeight;
27                 $lower = $this->bottomMargin + 8 * $this->lineHeight;
28                 $iline1 = $upper - 7.5 * $this->lineHeight;
29                 $iline2 = $iline1 - 8 * $this->lineHeight;
30                 $iline3 = $iline2 - 1.5 * $this->lineHeight;
31                 $iline4 = $iline3 - 1.5 * $this->lineHeight;
32                 $iline5 = $iline4 - 3 * $this->lineHeight;
33                 $iline6 = $iline5 - 1.5 * $this->lineHeight;
34                 $iline7 = $lower;
35                 $right = $this->pageWidth - $this->rightMargin;
36                 $width = ($right - $this->leftMargin) / 5;
37                 $icol = $this->pageWidth / 2;
38                 $ccol = $this->cols[0] + 4;
39                 $c2col = $ccol + 60;
40                 $ccol2 = $icol / 2;
41                 $mcol = $icol + 8;
42                 $mcol2 = $this->pageWidth - $ccol2;
43                 $cols = count($this->cols);
44                 $this->SetDrawColor(205, 205, 205);
45                 $this->Line($iline1, 3);
46                 $this->SetDrawColor(128, 128, 128);
47                 $this->Line($iline1);
48                 $this->rectangle($this->leftMargin, $iline2, $right - $this->leftMargin, $iline2 - $iline3, "F", null, array(222, 231, 236));   
49                 $this->Line($iline2);
50                 $this->Line($iline3);
51                 $this->Line($iline4);
52                 $this->rectangle($this->leftMargin, $iline5, $right - $this->leftMargin, $iline5 - $iline6, "F", null, array(222, 231, 236));   
53                 $this->Line($iline5);
54                 $this->Line($iline6);
55                 $this->Line($iline7);
56                 $this->LineTo($this->leftMargin, $iline2 ,$this->leftMargin, $iline4);
57                 $col = $this->leftMargin;
58                 for ($i = 0; $i < 5; $i++)
59                 {
60                         $this->LineTo($col += $width, $iline2,$col, $iline4);
61                 }
62                 $this->LineTo($this->leftMargin, $iline5 ,$this->leftMargin, $iline7);
63                 if ($this->l['a_meta_dir'] == 'rtl') // avoid line overwrite in rtl language
64                         $this->LineTo($this->cols[$cols - 2], $iline5 ,$this->cols[$cols - 2], $iline7);
65                 else    
66                         $this->LineTo($this->cols[$cols - 2] + 4, $iline5 ,$this->cols[$cols - 2] + 4, $iline7);
67                 $this->LineTo($right, $iline5 ,$right, $iline7);
68
69                 // Company Logo
70                 $logo = company_path() . "/images/" . $this->company['coy_logo'];
71                 if ($this->company['coy_logo'] != '' && file_exists($logo))
72                 {
73                         $this->NewLine();
74                         $this->AddImage($logo, $ccol, $this->row, 0, 40);
75                 }
76                 $this->NewLine();
77                 $this->fontSize += 4;
78                 $this->Font('bold');
79                 $this->Text($ccol, $this->company['coy_name'], $icol);
80                 $this->Font();
81                 $this->fontSize -= 4;
82                 // Document title
83                 $this->SetTextColor(190, 190, 190);
84                 $this->fontSize += 10;
85                 $this->Font('bold');
86                 $this->TextWrap($mcol, $this->row, $this->pageWidth - $this->rightMargin - $mcol - 20, $this->title, 'right');
87                 $this->Font();
88                 $this->fontSize -= 10;
89                 $this->NewLine();
90                 $this->SetTextColor(0, 0, 0);
91                 $adrline = $this->row;
92
93                 // Company data
94                 $this->TextWrapLines($ccol, $icol, $this->company['postal_address']);
95                 $this->Font('italic');
96                 if (@$this->company['phone'])
97                 {
98                         $this->Text($ccol, _("Phone"), $c2col);
99                         $this->Text($c2col, $this->company['phone'], $mcol);
100                         $this->NewLine();
101                 }
102                 if (@$this->company['fax'])
103                 {
104                         $this->Text($ccol, _("Fax"), $c2col);
105                         $this->Text($c2col, $this->company['fax'], $mcol);
106                         $this->NewLine();
107                 }
108                 if (@$this->company['email'])
109                 {
110                         $this->Text($ccol, _("Email"), $c2col);
111
112                         $url = "mailto:" . $this->company['email'];
113                         $this->SetTextColor(0, 0, 255);
114                         $this->Text($c2col, $this->company['email'], $mcol);
115                         $this->SetTextColor(0, 0, 0);
116                         $this->addLink($url, $c2col, $this->row, $mcol, $this->row + $this->lineHeight);
117
118                         $this->NewLine();
119                 }
120                 if (@$this->company['gst_no'])
121                 {
122                         $this->Text($ccol, _("Our VAT No."), $c2col);
123                         $this->Text($c2col, $this->company['gst_no'], $mcol);
124                         $this->NewLine();
125                 }
126                 if (@$this->formData['domicile'])
127                 {
128                         $this->Text($ccol, _("Domicile"), $c2col);
129                         $this->Text($c2col, $this->company['domicile'], $mcol);
130                         $this->NewLine();
131                 }
132                 $this->Font();
133                 $this->row = $adrline;
134                 $this->NewLine(3);
135                 $this->Text($mcol + 100, _("Date"));
136                 $this->Text($mcol + 180, sql2date($this->formData['document_date']));
137
138                 $this->NewLine();
139                 $this->Text($mcol + 100, $this->formData['document_name']);
140                 $this->Text($mcol + 180, $this->formData['document_number']);
141                 $this->NewLine(2);
142         
143                 if ($this->pageNumber > 1)
144                         $this->Text($mcol + 180, _("Page") . ' ' . $this->pageNumber);
145                 $this->row = $iline1 - $this->lineHeight;
146                 $this->fontSize -= 4;
147                 $this->Text($ccol, $Addr1['title'], $icol);
148                 $this->Text($mcol, $Addr2['title']);
149                 $this->fontSize += 4;
150
151 // address1
152                 $temp = $this->row = $this->row - $this->lineHeight - 5;
153                 $this->Text($ccol, $Addr1['name'], $icol);
154                 $this->NewLine();
155                 $this->TextWrapLines($ccol, $icol - $ccol, $Addr1['address']);
156
157 // address2
158                 $this->row = $temp;
159                 $this->Text($mcol, $Addr2['name']);
160                 $this->NewLine();
161                 $this->TextWrapLines($mcol, $this->rightMargin - $mcol, $Addr2['address'], 'left', 0, 0, NULL, 1);
162
163                 // Auxiliary document information
164                 $col = $this->leftMargin;
165                 foreach($aux_info as $info_header => $info_content)
166                 {
167
168                         $this->row = $iline2 - $this->lineHeight - 1;
169                         $this->TextWrap($col, $this->row, $width, $info_header, 'C');
170                         $this->row = $iline3 - $this->lineHeight - 1;
171                         $this->TextWrap($col, $this->row, $width, $info_content, 'C');
172                         $col += $width;
173                 }
174                 // Payment terms
175                 $this->row -= (2 * $this->lineHeight);
176                 $this->Font('italic');
177                 $this->TextWrap($ccol, $this->row, $right-$ccol, $Payment_Terms);
178                 $this->Font();
179
180                 // Line headers
181                 $this->row = $iline5 - $this->lineHeight - 1;
182                 $this->Font('bold');
183                 $count = count($this->headers);
184                 $this->cols[$count] = $right - 3;
185                 for ($i = 0; $i < $count; $i++)
186                         $this->TextCol($i, $i + 1, $this->headers[$i], -2);
187                 $this->Font();
188
189                 // Footer
190                 $this->Font('italic');
191                 $this->row = $iline7 - $this->lineHeight - 6;
192
193                 foreach ($Footer as $line => $txt)
194                 {
195                         if (!is_numeric($line)) // title => link
196                         {
197                                 $this->fontSize -= 2;
198                                 $this->TextWrap($ccol, $this->row, $right - $ccol, $line, 'C');
199                                 $this->row -= $this->lineHeight;
200                                 $this->SetTextColor(0, 0, 255);
201                                 $this->TextWrap($ccol, $this->row, $right - $ccol, $txt, 'C');
202                                 $this->SetTextColor(0, 0, 0);
203                                 $this->addLink($txt, $ccol, $this->row, $this->pageWidth - $this->rightMargin, $this->row + $this->lineHeight);
204                                 $this->fontSize += 2;
205                         }
206                         else
207                                 $this->TextWrap($ccol, $this->row, $right - $ccol, $txt, 'C');
208                         $this->row -= $this->lineHeight;
209
210                 }
211
212                 $this->Font();
213                 $temp = $iline6 - $this->lineHeight - 2;