Merged changes form main trunk (2.2.8, 2.2.9)
[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                 // New version (without vertical lines)
13
14         global $wo_types_array, $systypes_array;
15         
16                 $this->row = $this->pageHeight - $this->topMargin;
17
18                 $upper = $this->row - 2 * $this->lineHeight;
19                 $lower = $this->bottomMargin + 8 * $this->lineHeight;
20                 $iline1 = $upper - 7.5 * $this->lineHeight;
21                 $iline2 = $iline1 - 8 * $this->lineHeight;
22                 $iline3 = $iline2 - 1.5 * $this->lineHeight;
23                 $iline4 = $iline3 - 1.5 * $this->lineHeight;
24                 $iline5 = $iline4 - 3 * $this->lineHeight;
25                 $iline6 = $iline5 - 1.5 * $this->lineHeight;
26                 $iline7 = $lower;
27                 $right = $this->pageWidth - $this->rightMargin;
28                 $width = ($right - $this->leftMargin) / 5;
29                 $icol = $this->pageWidth / 2;
30                 $ccol = $this->cols[0] + 4;
31                 $c2col = $ccol + 60;
32                 $ccol2 = $icol / 2;
33                 $mcol = $icol + 8;
34                 $mcol2 = $this->pageWidth - $ccol2;
35                 $cols = count($this->cols);
36                 $this->SetDrawColor(205, 205, 205);
37                 $this->Line($iline1, 3);
38                 $this->SetDrawColor(128, 128, 128);
39                 $this->Line($iline1);
40                 $this->rectangle($this->leftMargin, $iline2, $right - $this->leftMargin, $iline2 - $iline3, "F", null, array(222, 231, 236));   
41                 $this->Line($iline2);
42                 $this->Line($iline3);
43                 $this->Line($iline4);
44                 $this->rectangle($this->leftMargin, $iline5, $right - $this->leftMargin, $iline5 - $iline6, "F", null, array(222, 231, 236));   
45                 $this->Line($iline5);
46                 $this->Line($iline6);
47                 $this->Line($iline7);
48                 $this->LineTo($this->leftMargin, $iline2 ,$this->leftMargin, $iline4);
49                 $col = $this->leftMargin;
50                 for ($i = 0; $i < 5; $i++)
51                 {
52                         $this->LineTo($col += $width, $iline2,$col, $iline4);
53                 }       
54                 $this->LineTo($right, $iline2 ,$right, $iline4);
55                 $this->LineTo($this->leftMargin, $iline5 ,$this->leftMargin, $iline7);
56                 $this->LineTo($this->cols[$cols - 2] + 4, $iline5 ,$this->cols[$cols - 2] + 4, $iline7);
57                 $this->LineTo($right, $iline5 ,$right, $iline7);
58
59                 $this->NewLine();
60                 if ($this->company['coy_logo'] != '')
61                 {
62                         $logo = company_path() . "/images/" . $this->company['coy_logo'];
63                         $this->AddImage($logo, $ccol, $this->row, 0, 40);
64                 }
65                 else
66                 {
67                         $this->fontSize += 4;
68                         $this->Font('bold');
69                         $this->Text($ccol, $this->company['coy_name'], $icol);
70                         $this->Font();
71                         $this->fontSize -= 4;
72                 }
73                 $this->SetTextColor(190, 190, 190);
74                 $this->fontSize += 10;
75                 $this->Font('bold');
76                 $this->TextWrap($mcol, $this->row, $this->pageWidth - $this->rightMargin - $mcol - 20, $this->title, 'right');
77                 $this->Font();
78                 $this->fontSize -= 10;
79                 $this->NewLine();
80                 $this->SetTextColor(0, 0, 0);
81                 $adrline = $this->row;
82                 $this->TextWrapLines($ccol, $icol, $this->company['postal_address']);
83                 $this->Font('italic');
84                 if ($this->company['phone'] != "")
85                 {
86                         $this->Text($ccol, _("Phone"), $c2col);
87                         $this->Text($c2col, $this->company['phone'], $mcol);
88                         $this->NewLine();
89                 }       
90                 if ($this->company['fax'] != "")
91                 {
92                         $this->Text($ccol, _("Fax"), $c2col);
93                         $this->Text($c2col, $this->company['fax'], $mcol);
94                         $this->NewLine();
95                 }       
96                 if ($this->company['email'] != "")
97                 {
98                         $this->Text($ccol, _("Email"), $c2col);
99
100                         $url = "mailto:" . $this->company['email'];
101                         $this->SetTextColor(0, 0, 255);
102                         $this->Text($c2col, $this->company['email'], $mcol);
103                         $this->SetTextColor(0, 0, 0);
104                         $this->addLink($url, $c2col, $this->row, $mcol, $this->row + $this->lineHeight);
105
106                         $this->NewLine();
107                 }       
108                 if ($this->company['gst_no'] != "")
109                 {
110                         $this->Text($ccol, $doc_Our_VAT_no, $c2col);
111                         $this->Text($c2col, $this->company['gst_no'], $mcol);
112                         $this->NewLine();
113                 }
114                 if (($doctype == ST_SALESINVOICE || $doctype == ST_STATEMENT) && $this->company['domicile'] != "")
115                 {
116                         $this->Text($ccol, $doc_Domicile, $c2col);
117                         $this->Text($c2col, $this->company['domicile'], $mcol);
118                         $this->NewLine();
119                 }
120                 $this->Font();
121                 $this->row = $adrline;
122                 $this->NewLine(3);
123                 $this->Text($mcol + 100, $doc_Date);
124                 if ($doctype == ST_SALESQUOTE || $doctype == ST_PURCHORDER || $doctype == ST_SALESORDER)
125                         $this->Text($mcol + 180, sql2date($this->formData['ord_date']));
126                 elseif ($doctype == ST_WORKORDER)       
127                         $this->Text($mcol + 180, sql2date($this->formData['date_']));
128                 else
129                         $this->Text($mcol + 180, sql2date($this->formData['tran_date']));
130                 $this->NewLine();
131                 $this->Text($mcol + 100, $doc_Invoice_no);
132                 if ($doctype == ST_SALESQUOTE || $doctype == ST_PURCHORDER || $doctype == ST_SALESORDER) // QUOTE, PO or SO
133                 {
134                         if ($print_invoice_no == 1)
135                                 $this->Text($mcol + 180, $this->formData['order_no']);
136                         else    
137                                 $this->Text($mcol + 180, $this->formData['reference']);
138                 }               
139                 elseif ($doctype == ST_WORKORDER)       
140                         $this->Text($mcol + 180, $this->formData['id']);
141                 else if (isset($this->formData['trans_no']) && isset($this->formData['reference'])) // INV/CRE/STA
142                 {
143                         if ($print_invoice_no == 1)
144                                 $this->Text($mcol + 180, $this->formData['trans_no']);
145                         else
146                                 $this->Text($mcol + 180, $this->formData['reference']);
147                 }
148
149                 if ($this->pageNumber > 1 && !strstr($this->filename, "Bulk"))
150                         $this->Text($this->endLine - 35, _("Page") . ' ' . $this->pageNumber);
151                 $this->row = $iline1 - $this->lineHeight;
152                 $this->fontSize -= 4;
153                 $this->Text($ccol, $doc_Charge_To, $icol);
154                 $this->Text($mcol, $doc_Delivered_To);
155                 $this->fontSize += 4;
156
157                 $this->row = $this->row - $this->lineHeight - 5;
158
159                 $temp = $this->row;
160                 if ($doctype == ST_SALESQUOTE || $doctype == ST_SALESORDER)
161                 {
162                         $this->Text($ccol, $this->formData['name'], $icol);
163                 }
164                 elseif ($doctype == ST_WORKORDER)
165                 {
166                         $this->Text($ccol, $this->formData['location_name'], $icol);
167                         $this->NewLine();
168                         $this->TextWrapLines($ccol, $icol - $ccol, $this->formData['delivery_address']);
169                 }
170                 else
171                 {
172                         if ($doctype == ST_PURCHORDER || $doctype == ST_SUPPAYMENT) {
173                                 $name = $this->formData['supp_name'];
174                                 $addr = $this->formData['address'];
175                         } else {
176                                 if (isset($this->formData['br_address']) && 
177                                                 trim($this->formData['br_address']) != '') {
178                                         $name = $this->formData['br_name'];
179                                         $addr = $this->formData['br_address'];
180                                 } else {
181                                         $name = $this->formData['DebtorName'];
182                                         $addr = $this->formData['address'];
183                                 }
184                         }
185                         $this->Text($ccol, $name, $icol);
186                         $this->NewLine();
187                         $this->TextWrapLines($ccol, $icol - $ccol, $addr);
188                 }
189                 if (isset($this->formData['deliver_to']))
190                 {
191                         $this->row = $temp;
192                         if ($doctype == ST_PURCHORDER)
193                                 $this->Text($mcol, $this->company['coy_name']);
194                         elseif ($doctype != ST_SUPPAYMENT && isset($sales_order['deliver_to']))
195                         {
196                                 $this->Text($mcol, $sales_order['deliver_to']);
197                                 $this->NewLine();
198                         }       
199                         // if you need the company name in purchase order then write it as first line in location addresss.     
200                         if ($doctype != ST_SUPPAYMENT && isset($sales_order['delivery_address']))
201                                 $this->TextWrapLines($mcol, $this->rightMargin - $mcol, $sales_order['delivery_address']);
202                 }
203                 $this->row = $iline2 - $this->lineHeight - 1;
204                 $col = $this->leftMargin;
205                 $this->TextWrap($col, $this->row, $width, $doc_Customers_Ref, 'C');
206                 $col += $width;
207                 $this->TextWrap($col, $this->row, $width, $doc_Our_Ref, 'C');
208                 $col += $width;
209                 $this->TextWrap($col, $this->row, $width, $doc_Your_VAT_no, 'C');
210                 $col += $width;
211                 if ($doctype == ST_SALESINVOICE)
212                         $this->TextWrap($col, $this->row, $width, $doc_Delivery_no, 'C');
213                 else
214                         $this->TextWrap($col, $this->row, $width, $doc_Our_Order_No, 'C');
215                 $col += $width;
216                 $this->TextWrap($col, $this->row, $width, $doc_Due_Date, 'C');
217                 $this->row = $iline3 - $this->lineHeight - 1;
218                 $col = $this->leftMargin;
219                 if ($doctype == ST_PURCHORDER || $doctype == ST_SUPPAYMENT)
220                         $this->TextWrap($col, $this->row, $width, $this->formData['supp_account_no'], 'C');
221                 elseif ($doctype == ST_WORKORDER)
222                         $this->TextWrap($col, $this->row, $width, $this->formData['wo_ref'], 'C');
223                 elseif (isset($this->formData["customer_ref"]))
224                         $this->TextWrap($col, $this->row, $width, $this->formData["customer_ref"], 'C');
225                 elseif (isset($this->formData["debtor_ref"]))
226                         $this->TextWrap($col, $this->row, $width, $this->formData["debtor_ref"], 'C');
227                 $col += $width; 
228                 if (isset($this->formData['salesman']))
229                 {
230                         $id = $this->formData['salesman'];
231                         //$sql = "SELECT salesman_name  FROM ".TB_PREF."salesman WHERE salesman_code='$id'";
232                         //$result = db_query($sql,"could not get sales person");
233                         //$row = db_fetch($result);
234                         //$this->TextWrap($col, $this->row, $width, $row['salesman_name'], 'C');
235                         $this->TextWrap($col, $this->row, $width, get_salesman_name($id), 'C');
236                 }               
237                 elseif ($doctype == ST_SUPPAYMENT || $doctype == ST_CUSTPAYMENT)
238                         $this->TextWrap($col, $this->row, $width, $systypes_array[$this->formData["type"]], 'C');
239                 elseif ($doctype == ST_WORKORDER)
240                         $this->TextWrap($col, $this->row, $width, $wo_types_array[$this->formData["type"]], 'C');
241                 $col += $width; 
242                 if ($doctype == ST_WORKORDER)
243                         $this->TextWrap($col, $this->row, $width, $this->formData["StockItemName"], 'C');
244                 elseif ($doctype != ST_PURCHORDER && isset($this->formData['tax_id']))
245                         $this->TextWrap($col, $this->row, $width, $this->formData['tax_id'], 'C');
246                 $col += $width; 
247                 if ($doctype == ST_SALESINVOICE)
248                 {
249                         $deliveries = get_parent_trans(ST_SALESINVOICE, $this->formData['trans_no']);
250                         $line = "";
251                         foreach ($deliveries as $delivery)
252                         {
253                                 if ($print_invoice_no == 0)
254                                 {
255                                         $ref = get_reference(ST_CUSTDELIVERY, $delivery);
256                                         if ($ref)
257                                                 $delivery = $ref;
258                                 }               
259                                 if ($line == "")
260                                         $line .= "$delivery";
261                                 else
262                                         $line .= ",$delivery";
263                         }               
264                         $this->TextWrap($col, $this->row, $width, $line, 'C');
265                 }
266                 elseif ($doctype == ST_CUSTDELIVERY)
267                 {
268                         $ref = $this->formData['order_'];
269                         if ($print_invoice_no == 0)
270                         {
271                                 $ref = get_reference(ST_SALESORDER, $this->formData['order_']);
272                                 if (!$ref)
273                                         $ref = $this->formData['order_'];
274                         }               
275                         $this->TextWrap($col, $this->row, $width, $ref, 'C');
276                 }
277                 elseif ($doctype == ST_WORKORDER)
278                         $this->TextWrap($col, $this->row, $width, $this->formData["location_name"], 'C');
279                 elseif (isset($this->formData['order_']) && $this->formData['order_'] != 0)
280                         $this->TextWrap($col, $this->row, $width, $this->formData['order_'], 'C');
281                 $col += $width; 
282                 if ($doctype == ST_SALESORDER || $doctype == ST_SALESQUOTE)
283                         $this->TextWrap($col, $this->row, $width, sql2date($this->formData['delivery_date']), 'C');
284                 elseif ($doctype == ST_WORKORDER)       
285                         $this->TextWrap($col, $this->row, $width, $this->formData["units_issued"], 'C');
286                 elseif ($doctype != ST_PURCHORDER && $doctype != ST_CUSTCREDIT && $doctype != ST_CUSTPAYMENT &&
287                         $doctype != ST_SUPPAYMENT && isset($this->formData['due_date']))
288                         $this->TextWrap($col, $this->row, $width, sql2date($this->formData['due_date']), 'C');
289                 if ((!isset($packing_slip) || $packing_slip == 0) && ($doctype != ST_STATEMENT)) //!
290                 {
291                         $this->row -= (2 * $this->lineHeight);
292                         if ($doctype == ST_WORKORDER)
293                                 $str = sql2date($this->formData["required_by"]);
294                         else
295                         {
296                                 $id = $this->formData['payment_terms'];
297                                 $sql = "SELECT terms FROM ".TB_PREF."payment_terms WHERE terms_indicator='$id'";
298                                 $result = db_query($sql,"could not get paymentterms");
299                                 $row = db_fetch($result);
300                                 $str = $row["terms"];
301                         }       
302                         $this->Font('italic');
303                         $this->TextWrap($ccol, $this->row, $right-$ccol, $doc_Payment_Terms . ":  " . $str);
304                         $this->Font();
305                 }
306                 $this->row = $iline5 - $this->lineHeight - 1;
307                 $this->Font('bold');
308                 $count = count($this->headers);
309                 $this->cols[$count] = $right - 3;
310                 for ($i = 0; $i < $count; $i++)
311                         $this->TextCol($i, $i + 1, $this->headers[$i], -2);
312                 $this->Font();
313                 $this->Font('italic');
314                 $this->row = $iline7 - $this->lineHeight - 6;
315                 if ($doctype != ST_WORKORDER)
316                         $this->TextWrap($ccol, $this->row, $right - $ccol, $doc_Please_Quote . " - " . $this->formData['curr_code'], 'C');
317                 $this->row -= $this->lineHeight;
318
319                 if (isset($this->formData['bank_name']))
320                 {
321                         $txt = $doc_Bank . ": ".$this->formData['bank_name']. ", " . $doc_Bank_Account . ": " . $this->formData['bank_account_number'];
322                         $this->TextWrap($ccol, $this->row, $right - $ccol, $txt, 'C');
323                         $this->row -= $this->lineHeight;
324                 }       
325                 if ($doctype == ST_SALESINVOICE && $this->formData['disable_branch'] > 0) // payment links
326                 {
327                         if ($this->formData['disable_branch'] == 1)
328                         {
329                                 $amt = number_format($this->formData["ov_freight"] + $this->formData["ov_gst"] +        $this->formData["ov_amount"], user_price_dec());
330                                 $txt = $doc_Payment_Link . " PayPal: ";
331                                 $name = urlencode($this->title . " " . $this->formData['reference']);
332                                 $url = "https://www.paypal.com/xclick/business=" . $this->company['email'] . "&item_name=" .
333                                         $name . "&amount=" . $amt . "&currency_code=" . $this->formData['curr_code'];
334                                 $this->fontSize -= 2;
335                                 $this->TextWrap($ccol, $this->row, $right - $ccol, $txt, 'C');
336                                 $this->row -= $this->lineHeight;
337                                 $this->SetTextColor(0, 0, 255);
338                                 $this->TextWrap($ccol, $this->row, $right - $ccol, $url, 'C');
339                                 $this->SetTextColor(0, 0, 0);
340                                 $this->addLink($url, $ccol, $this->row, $this->pageWidth - $this->rightMargin, $this->row + $this->lineHeight);
341                                 $this->fontSize += 2;
342                                 $this->row -= $this->lineHeight;
343                         }
344                 }
345                 if ($doc_Extra != "")
346                 {
347                         $this->TextWrap($ccol, $this->row, $right - $ccol, $doc_Extra, 'C');
348                         $this->row -= $this->lineHeight;
349                 }
350                 if ($this->params['comments'] != '')
351                 {
352                         $this->TextWrap($ccol, $this->row, $right - $ccol, $this->params['comments'], 'C');
353                         $this->row -= $this->lineHeight;
354                 }
355                 if (($doctype == ST_SALESINVOICE || $doctype == ST_STATEMENT) && $this->company['legal_text'] != "") 
356                 {
357                         $this->TextWrapLines($ccol, $right - $ccol, $this->company['legal_text'], 'C');
358                 }
359                 $this->Font();
360                 $temp = $iline6 - $this->lineHeight - 2;
361 ?>