Merging version 2.1 RC to main trunk.
[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                 $this->row = $this->pageHeight - $this->topMargin;
14
15                 $upper = $this->row - 2 * $this->lineHeight;
16                 $lower = $this->bottomMargin + 6 * $this->lineHeight;
17                 $iline1 = $upper - 7 * $this->lineHeight;
18                 $iline2 = $iline1 - 8 * $this->lineHeight;
19                 $iline3 = $iline2 - 1.5 * $this->lineHeight;
20                 $iline4 = $iline3 - 1.5 * $this->lineHeight;
21                 $iline5 = $iline4 - 3 * $this->lineHeight;
22                 $iline6 = $iline5 - 1.5 * $this->lineHeight;
23                 $iline7 = $lower;
24                 $right = $this->pageWidth - $this->rightMargin;
25                 $width = ($right - $this->leftMargin) / 6;
26                 $icol = $this->pageWidth / 2;
27                 $ccol = $this->cols[0] + 4;
28                 $c2col = $ccol + 60;
29                 $ccol2 = $icol / 2;
30                 $mcol = $icol + 8;
31                 $mcol2 = $this->pageWidth - $ccol2;
32                 $cols = count($this->cols);
33                 $this->SetDrawColor(205, 205, 205);
34                 $this->Line($iline1, 3);
35                 $this->SetDrawColor(128, 128, 128);
36                 $this->Line($iline1);
37                 $this->rectangle($this->leftMargin, $iline2, $right - $this->leftMargin, $iline2 - $iline3, "F", null, array(222, 231, 236));   
38                 $this->Line($iline2);
39                 $this->Line($iline3);
40                 $this->Line($iline4);
41                 $this->rectangle($this->leftMargin, $iline5, $right - $this->leftMargin, $iline5 - $iline6, "F", null, array(222, 231, 236));   
42                 $this->Line($iline5);
43                 $this->Line($iline6);
44                 $this->Line($iline7);
45                 $this->LineTo($this->leftMargin, $iline2 ,$this->leftMargin, $iline4);
46                 $col = $this->leftMargin;
47                 for ($i = 0; $i < 5; $i++)
48                 {
49                         $this->LineTo($col += $width, $iline2,$col, $iline4);
50                 }       
51                 $this->LineTo($right, $iline2 ,$right, $iline4);
52                 $this->LineTo($this->leftMargin, $iline5 ,$this->leftMargin, $iline7);
53                 $this->LineTo($this->cols[$cols - 2] + 4, $iline5 ,$this->cols[$cols - 2] + 4, $iline7);
54                 $this->LineTo($right, $iline5 ,$right, $iline7);
55
56                 $this->NewLine();
57                 if ($this->company['coy_logo'] != '')
58                 {
59                         $logo = $comp_path .'/'. user_company() . "/images/" . $this->company['coy_logo'];
60                         $this->AddImage($logo, $ccol, $this->row - 10, 0, 40);
61                 }
62                 else
63                 {
64                         $this->fontSize += 4;
65                         $this->Font('bold');
66                         $this->Text($ccol, $this->company['coy_name'], $icol);
67                         $this->Font();
68                         $this->fontSize -= 4;
69                 }
70                 $this->SetTextColor(190, 190, 190);
71                 $this->fontSize += 10;
72                 $this->Font('bold');
73                 $this->TextWrap($mcol, $this->row, $this->pageWidth - $this->rightMargin - $mcol - 20, $this->title, 'right');
74                 $this->Font();
75                 $this->fontSize -= 10;
76                 $this->NewLine();
77                 $this->SetTextColor(0, 0, 0);
78                 $adrline = $this->row;
79                 $this->TextWrapLines($ccol, $icol, $this->company['postal_address']);
80                 $this->Font('italic');
81                 if ($this->company['phone'] != "")
82                 {
83                         $this->Text($ccol, _("Phone"), $c2col);
84                         $this->Text($c2col, $this->company['phone'], $mcol);
85                         $this->NewLine();
86                 }       
87                 if ($this->company['fax'] != "")
88                 {
89                         $this->Text($ccol, _("Fax"), $c2col);
90                         $this->Text($c2col, $this->company['fax'], $mcol);
91                         $this->NewLine();
92                 }       
93                 if ($this->company['email'] != "")
94                 {
95                         $this->Text($ccol, _("Email"), $c2col);
96
97                         $url = "mailto:" . $this->company['email'];
98                         $this->SetTextColor(0, 0, 255);
99                         $this->Text($c2col, $this->company['email'], $mcol);
100                         $this->SetTextColor(0, 0, 0);
101                         $this->addLink($url, $c2col, $this->row, $mcol, $this->row + $this->lineHeight);
102
103                         $this->NewLine();
104                 }       
105                 if ($this->company['gst_no'] != "")
106                 {
107                         $this->Text($ccol, $doc_Our_VAT_no, $c2col);
108                         $this->Text($c2col, $this->company['gst_no'], $mcol);
109                         $this->NewLine();
110                 }       
111                 $this->Font();
112                 $this->row = $adrline;
113                 $this->NewLine(3);
114                 $this->Text($mcol + 100, $doc_Date.":");
115                 if ($doctype == 8 || $doctype == 9)
116                         $this->Text($mcol + 180, sql2date($myrow['ord_date']));
117                 else
118                         $this->Text($mcol + 180, sql2date($myrow['tran_date']));
119                 $this->NewLine();
120                 $this->Text($mcol + 100, $doc_Invoice_no);
121                 if ($doctype == 8 || $doctype == 9) // PO or SO
122                         $this->Text($mcol + 180, $myrow['order_no']);
123                 else if (isset($myrow['trans_no']) && isset($myrow['reference'])) // INV/CRE/STA
124                 {
125                         if ($print_invoice_no == 1)
126                                 $this->Text($mcol + 180, $myrow['trans_no']);
127                         else
128                                 $this->Text($mcol + 180, $myrow['reference']);
129                 }
130
131                 if ($this->pageNumber > 1 && !strstr($this->filename, "Bulk"))
132                         $this->Text($this->endLine - 35, _("Page") . ' ' . $this->pageNumber);
133                 $this->row = $iline1 - $this->lineHeight;
134                 $this->fontSize -= 4;
135                 $this->Text($ccol, $doc_Charge_To, $icol);
136                 $this->Text($mcol, $doc_Delivered_To);
137                 $this->fontSize += 4;
138
139                 $this->row = $this->row - $this->lineHeight - 5;
140
141                 $temp = $this->row;
142                 if ($doctype == 9)
143                 {
144                         $this->Text($ccol, $myrow['name'], $icol);
145                 }
146                 else
147                 {
148                         if ($doctype == 8) {
149                                 $name = $myrow['supp_name'];
150                                 $addr = $myrow['address'];
151                         } else {
152                                 if (trim($branch['br_address']) != '') {
153                                         $name = $branch['br_name'];
154                                         $addr = $branch['br_address'];
155                                 } else {
156                                         $name = $myrow['DebtorName'];
157                                         $addr = $myrow['address'];
158                                 }
159                         }
160                         $this->Text($ccol, $name, $icol);
161                         $this->NewLine();
162                         $this->TextWrapLines($ccol, $icol - $ccol, $addr);
163                 }
164                 if ($sales_order != NULL)
165                 {
166                         $this->row = $temp;
167                         if ($doctype == 8)
168                                 $this->Text($mcol, $this->company['coy_name']);
169                         else
170                                 $this->Text($mcol, $sales_order['deliver_to']);
171                         $this->NewLine();
172                         $this->TextWrapLines($mcol, $this->rightMargin - $mcol, $sales_order['delivery_address']);
173                 }
174                 $this->row = $iline2 - $this->lineHeight - 1;
175                 $col = $this->leftMargin;
176                 $this->TextWrap($col, $this->row, $width, $doc_Customers_Ref, 'C');
177                 $col += $width;
178                 $this->TextWrap($col, $this->row, $width, $doc_Our_Ref, 'C');
179                 $col += $width;
180                 $this->TextWrap($col, $this->row, $width, $doc_Your_VAT_no, 'C');
181                 $col += $width;
182                 if ($doctype == 10)
183                         $this->TextWrap($col, $this->row, $width, $doc_Delivery_no, 'C');
184                 else
185                         $this->TextWrap($col, $this->row, $width, $doc_Our_Order_No, 'C');
186                 $col += $width;
187                 $this->TextWrap($col, $this->row, $width, $doc_Payment_Terms, 'C');
188                 $col += $width;
189                 $this->TextWrap($col, $this->row, $width, $doc_Due_Date, 'C');
190                 $this->row = $iline3 - $this->lineHeight - 1;
191                 $col = $this->leftMargin;
192                 if ($doctype == 8)
193                         $this->TextWrap($col, $this->row, $width, $myrow['supp_account_no'], 'C');
194                 elseif (isset($sales_order["customer_ref"]))
195                         $this->TextWrap($col, $this->row, $width, $sales_order["customer_ref"], 'C');
196                 $col += $width; 
197                 if ($branch != null)
198                 {
199                         $id = $branch['salesman'];
200                         $sql = "SELECT salesman_name  FROM ".TB_PREF."salesman WHERE salesman_code='$id'";
201                         $result = db_query($sql,"could not get sales person");
202                         $row = db_fetch($result);
203                         $this->TextWrap($col, $this->row, $width, $row['salesman_name'], 'C');
204                 }               
205                 $col += $width; 
206                 if ($doctype != 8 && isset($myrow['tax_id']))
207                         $this->TextWrap($col, $this->row, $width, $myrow['tax_id'], 'C');
208                 $col += $width; 
209                 if ($doctype == 10)
210                 {
211                         $deliveries = get_parent_trans(10,$myrow['trans_no']);
212                         $line = "";
213                         foreach ($deliveries as $delivery)
214                         {
215                                 if ($line == "")
216                                         $line .= "$delivery";
217                                 else
218                                         $line .= ",$delivery";
219                         }               
220                         $this->TextWrap($col, $this->row, $width, $line, 'C');
221                 }
222                 elseif (isset($myrow['order_']))
223                         $this->TextWrap($col, $this->row, $width, $myrow['order_'], 'C');
224                 $col += $width; 
225                 $id = $myrow['payment_terms'];
226                 $sql = "SELECT terms FROM ".TB_PREF."payment_terms WHERE terms_indicator='$id'";
227                 $result = db_query($sql,"could not get paymentterms");
228                 $row = db_fetch($result);
229                 $this->TextWrap($col, $this->row, $width, $row["terms"], 'C');
230                 $col += $width; 
231                 if ($doctype == 9)
232                         $this->TextWrap($col, $this->row, $width, sql2date($myrow['delivery_date']), 'C');
233                 else if ($doctype != 8 && $doctype != 11 && isset($myrow['due_date']))
234                         $this->TextWrap($col, $this->row, $width, sql2date($myrow['due_date']), 'C');
235                 
236                 $this->row = $iline5 - $this->lineHeight - 1;
237                 $this->Font('bold');
238                 $count = count($this->headers);
239                 $this->cols[$count] = $right - 3;
240                 for ($i = 0; $i < $count; $i++)
241                         $this->TextCol($i, $i + 1, $this->headers[$i], -2);
242                 $this->Font();
243                 $this->Font('italic');
244                 $this->row = $iline7 - $this->lineHeight - 6;
245                 $this->TextWrap($ccol, $this->row, $right - $ccol, $doc_Please_Quote . " - " . $myrow['curr_code'], 'C');
246                 $this->NewLine();
247
248                 if (isset($bankaccount['bank_name']))
249                 {
250                         $txt = $doc_Bank . ": ".$bankaccount['bank_name']. ", " . $doc_Bank_Account . ": " . $bankaccount['bank_account_number'];
251                         $this->TextWrap($ccol, $this->row, $right - $ccol, $txt, 'C');
252                         $this->NewLine();
253                 }       
254                 if ($doctype == 10 && $branch['disable_branch'] > 0) // payment links
255                 {
256                         if ($branch['disable_branch'] == 1)
257                         {
258                                 $amt = number_format($myrow["ov_freight"] + $myrow["ov_gst"] +  $myrow["ov_amount"], user_price_dec());
259                                 $txt = $doc_Payment_Link . " PayPal: ";
260                                 $name = urlencode($this->title . " " . $myrow['reference']);
261                                 $url = "https://www.paypal.com/xclick/business=" . $this->company['email'] . "&item_name=" .
262                                         $name . "&amount=" . $amt . "&currency_code=" . $myrow['curr_code'];
263                                 $this->fontSize -= 2;
264                                 $this->TextWrap($ccol, $this->row, $right - $ccol, $txt, 'C');
265                                 $this->NewLine();
266                                 $this->SetTextColor(0, 0, 255);
267                                 $this->TextWrap($ccol, $this->row, $right - $ccol, $url, 'C');
268                                 $this->SetTextColor(0, 0, 0);
269                                 $this->addLink($url, $ccol, $this->row, $this->pageWidth - $this->rightMargin, $this->row + $this->lineHeight);
270                                 $this->fontSize += 2;
271                                 $this->NewLine();
272                         }
273                 }
274                 if ($this->params['comments'] != '')
275                 {
276                         $this->TextWrap($ccol, $this->row, $right - $ccol, $this->params['comments'], 'C');
277                         $this->NewLine();
278                 }
279                 $legal = get_company_pref('legal_text');
280                 if (($doctype == 10 || $doctype == 12) && $legal != "") 
281                 {
282                         $this->TextWrap($ccol, $this->row, $right - $ccol, $legal, 'C');
283                         $this->NewLine();
284                 }
285                 $this->Font();
286                 $temp = $iline6 - $this->lineHeight - 2;
287 ?>