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