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