Cleanup: various random sql queries found in UI files moved to database interface...
[fa-stable.git] / reporting / includes / doctext.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 *       Set document type dependent elements of common page layout.
15 *
16 */
17         $Addr1 = array(
18                         'title' => _("Charge To"),
19                         'name' => @$this->formData['br_name'] ? $this->formData['br_name'] : @$this->formData['DebtorName'],
20                         'address' => @$this->formData['br_address'] ? $this->formData['br_address'] : @$this->formData['address']
21         );
22         $Addr2 = array(
23                         'title' => _("Delivered To"),
24                         'name' => @$this->formData['deliver_to'],
25                         'address' => @$this->formData['delivery_address']
26         );
27
28         // default item column headers
29         $this->headers = array(_("Item Code"), _("Item Description"), _("Quantity"),
30                 _("Unit"), _("Price"), _("Discount %"), _("Total"));
31
32         // for links use 'text' => 'url'
33         $Footer[0] = _("All amounts stated in") . " - " . @$this->formData['curr_code'];
34
35         if (!in_array($this->formData['doctype'], array(ST_STATEMENT, ST_WORKORDER)))
36         {
37                 $row = get_payment_terms($this->formData['payment_terms']);
38                 $Payment_Terms = _("Payment Terms") . ': ' . $row["terms"];
39                 if ($this->formData['doctype'] == ST_SALESINVOICE && $this->formData['prepaid'])
40                         $this->formData['prepaid'] = ($row['days_before_due'] >= 0) ? 'final' : 'partial';
41         }
42
43
44         switch ($this->formData['doctype'])
45         {
46                 case ST_SALESQUOTE:
47                         $this->title = _("SALES QUOTATION");
48                         $this->formData['document_name'] =_("Quotation No.");
49                         $this->formData['document_date'] = $this->formData['ord_date'];
50                         $this->formData['document_number'] = $SysPrefs->print_invoice_no() == 0 && isset($this->formData['reference'])
51                                 ? $this->formData['reference'] : $this->formData['order_no'];
52                         $aux_info = array(
53                                 _("Customer's Reference") => $this->formData["customer_ref"],
54                                 _("Sales Person") => get_salesman_name($this->formData['salesman']),
55                                 _("Your VAT no.") => $this->formData['tax_id'],
56                                 _("Our Quotation No") => $this->formData['order_no'],
57                                 _("Valid until") => sql2date($this->formData['delivery_date']),
58                         );
59                         break;
60
61                 case ST_SALESORDER:
62                         $this->title = ($print_as_quote==1 ? _("QUOTE") : ($this->formData['prepaid'] ? _("PREPAYMENT ORDER") : _("SALES ORDER")));
63                         $this->formData['document_name'] =_("Order No.");
64                         $this->formData['document_date'] = $this->formData['ord_date'];
65                         $this->formData['document_number'] = $SysPrefs->print_invoice_no() == 0 && isset($this->formData['reference'])
66                                 ? $this->formData['reference'] : $this->formData['order_no'];
67                         $this->formData['document_amount'] = $this->formData['order_no'];
68
69                         $aux_info = array(
70                                 _("Customer's Reference") => $this->formData["customer_ref"],
71                                 _("Sales Person") => get_salesman_name($this->formData['salesman']),
72                                 _("Your VAT no.") => $this->formData['tax_id'],
73                                 _("Our Order No") => $this->formData['order_no'],
74                                 _("Delivery Date") => sql2date($this->formData['delivery_date']),
75                         );
76                         break;
77
78                 case ST_CUSTDELIVERY:
79                         $this->title = ($packing_slip==1 ? _("PACKING SLIP") : _("DELIVERY NOTE"));
80                         $this->formData['document_name'] = _("Delivery Note No.");
81                         if (@$packing_slip)
82                                 $Payment_Terms = '';
83                         $ref = $this->formData['order_'];
84                         if ($SysPrefs->print_invoice_no() == 0)
85                         {
86                                 $ref = get_reference(ST_SALESORDER, $this->formData['order_']);
87                                 if (!$ref)
88                                         $ref = $this->formData['order_'];
89                         }
90                         $aux_info = array(
91                                 _("Customer's Reference") => $this->formData["customer_ref"],
92                                 _("Sales Person") => get_salesman_name($this->formData['salesman']),
93                                 _("Your VAT no.") => $this->formData['tax_id'],
94                                 _("Our Order No") => $ref,
95                                 _("To Be Invoiced Before") => sql2date($this->formData['due_date']),
96                         );
97                         break;
98
99                 case ST_CUSTCREDIT:
100                         $this->title = _("CREDIT NOTE");
101                         $this->formData['document_name'] =_("Credit No.");
102                         $Footer[0] = _("Please quote Credit no. when paying. All amounts stated in") . " - " . $this->formData['curr_code'];
103
104                         $aux_info = array(
105                                 _("Customer's Reference") => @$this->formData["customer_ref"],
106                                 _("Sales Person") => get_salesman_name($this->formData['salesman']),
107                                 _("Your VAT no.") => $this->formData['tax_id'],
108                                 _("Our Order No") => $this->formData['order_'],
109                                 _("Due Date") => '',
110                         );
111                         break;
112
113                 case ST_SALESINVOICE:
114                         $this->title = $this->formData['prepaid']=='partial' ? _("PREPAYMENT INVOICE")
115                                 : ($this->formData['prepaid']=='final' ? _("FINAL INVOICE")  : _("INVOICE"));
116                         $this->formData['document_name'] =_("Invoice No.");
117                         $this->formData['domicile'] = $this->company['domicile'];
118                         $Footer[0] = _("Please quote Invoice no. when paying. All amounts stated in"). " - " . $this->formData['curr_code'];
119
120                         $deliveries = get_sales_parent_numbers(ST_SALESINVOICE, $this->formData['trans_no']);
121                         if ($SysPrefs->print_invoice_no() == 0)
122                         {
123                                 foreach($deliveries as $n => $delivery) {
124                                         $deliveries[$n] = get_reference(ST_CUSTDELIVERY, $delivery);
125                                 }
126                         }
127                         $aux_info = array(
128                                 _("Customer's Reference") => $this->formData["customer_ref"],
129                                 _("Sales Person") => get_salesman_name($this->formData['salesman']),
130                                 _("Your VAT no.") => $this->formData['tax_id'],
131                         );
132                         if ($this->formData['prepaid']=='partial')
133                         {
134                                 $aux_info[_("Date of Payment")] = sql2date(get_oldest_payment_date($this->formData['trans_no']));
135                                 $aux_info[_("Our Order No")]  = $this->formData['order_'];
136                         } else {
137                                 if ($this->formData['prepaid'] =='final')
138                                         $aux_info[_("Invoice Date")] = sql2date($this->formData['tran_date']);
139                                 else
140                                         $aux_info[_("Date of Sale")] = sql2date(get_oldest_delivery_date($this->formData['trans_no']));
141                                 $aux_info[_("Due Date")]  = sql2date($this->formData['due_date']);
142                         }
143                         break;
144
145                 case ST_SUPPAYMENT:
146                         global $systypes_array;
147
148                         $this->title = _("REMITTANCE");
149                         $this->formData['document_name'] =_("Remittance No.");
150                         $Addr1['title'] = _("Order To");
151                         $Addr1['name'] = $this->formData['supp_name'];
152                         $Addr1['address'] = $this->formData['address'];
153                         $Addr2['title'] = _("Charge To");
154                         $Addr2['name'] = '';
155                         $Addr2['address'] = '';
156
157                         $aux_info = array(
158                                 _("Customer's Reference") => $this->formData['supp_account_no'],
159                                 _("Type") =>$systypes_array[$this->formData["type"]],
160                                 _("Your VAT no.") => $this->formData['tax_id'],
161                                 _("Supplier's Reference") => '',
162                                 _("Due Date") => sql2date($this->formData['tran_date']),
163                         );
164                         $this->headers = array(_("Trans Type"), _("#"), _("Date"), _("Due Date"), _("Total Amount"), _("Left to Allocate"), _("This Allocation"));
165                         break;
166
167                 case ST_PURCHORDER:
168                         $this->title = _("PURCHASE ORDER");
169                         $this->formData['document_name'] =_("Purchase Order No.");
170                         $Addr1['title'] = _("Order To");
171                         $Addr1['name'] = $this->formData['supp_name'];
172                         $Addr1['address'] = $this->formData['address'];
173                         $Addr2['title'] = _("Deliver To");
174                         $Addr2['name'] = $this->company['coy_name'];
175                         //$Addr2['address'] = $this->company['postal_address']; No, don't destroy delivery address!
176                         $this->formData['document_date'] = $this->formData['ord_date'];
177                         $this->formData['document_number'] = $SysPrefs->print_invoice_no() == 0 && isset($this->formData['reference'])
178                                 ? $this->formData['reference'] : $this->formData['order_no'];
179
180                         $aux_info = array(
181                                 _("Customer's Reference") => $this->formData['supp_account_no'],
182                                 _("Sales Person") => $this->formData['contact'],
183                                 _("Your VAT no.") => $this->formData['tax_id'],
184                                 _("Supplier's Reference") => $this->formData['requisition_no'],
185                                 _("Order Date") => sql2date($this->formData['document_date']),
186                         );
187
188                         $this->headers = array(_("Item Code"), _("Item Description"),
189                                 _("Delivery Date"), _("Quantity"),      _("Unit"), _("Price"), _("Total"));
190                         break;
191
192                 case ST_CUSTPAYMENT:
193                         global $systypes_array;
194
195                         $this->title = _("RECEIPT");
196                         $this->formData['document_name'] =_("Receipt No.");
197                         $Addr1['title'] = _("With thanks from");
198                         $aux_info = array(
199                                 _("Customer's Reference") => $this->formData["debtor_ref"],
200                                 _("Type") =>$systypes_array[$this->formData["type"]],
201                                 _("Your VAT no.") => $this->formData['tax_id'],
202                                 _("Our Order No") => $this->formData['order_'],
203                                 _("Due Date") => sql2date($this->formData['tran_date']),
204                         );
205                         $this->headers = array(_("Trans Type"), _("#"), _("Date"), _("Due Date"), _("Total Amount"), _("Left to Allocate"), _("This Allocation"));
206                         break;
207
208                 case ST_WORKORDER:
209                         global $wo_types_array;
210
211                         $this->title = _("WORK ORDER");
212                         $this->formData['document_name'] =_("Work Order No.");
213                         $this->formData['document_date'] = $this->formData['date_'];
214                         $this->formData['document_number'] = $this->formData['id'];
215                         $Addr1['name'] = $this->formData['location_name'];
216                         $Addr1['address'] = $this->formData['delivery_address'];
217                         $aux_info = array(
218                                 _("Reference") => $this->formData['wo_ref'],
219                                 _("Type") => $wo_types_array[$this->formData["type"]],
220                                 _("Manufactured Item") => $this->formData["StockItemName"],
221                                 _("Into Location") => $this->formData["location_name"],
222                                 _("Quantity") => $this->formData["units_issued"],
223                         );
224                         $Payment_Terms = _("Required By").": ".sql2date($this->formData["required_by"]);
225                         $this->headers = array(_("Item Code"), _("Item Description"),
226                                 _("From Location"), _("Work Centre"),   _("Unit Quantity"), _("Total Quantity"), _("Units Issued"));
227                         unset($Footer[0]);
228                         break;
229
230
231                 case ST_STATEMENT:
232                         $this->formData['document_name'] = '';
233                         $this->formData['domicile'] = $this->company['domicile'];
234                         $Payment_Terms = '';
235                         $this->title = _("STATEMENT");
236                         $aux_info = array(
237                                 _("Customer's Reference") => '',
238                                 _("Sales Person") => '',
239                                 _("Your VAT no.") => $this->formData['tax_id'],
240                                 _("Our Order No") => '',
241                                 _("Delivery Date") => '',
242                         );
243                         $this->headers = array(_("Trans Type"), _("#"), _("Date"), _("DueDate"), _("Charges"),
244                                 _("Credits"), _("Allocated"), _("Outstanding"));
245         }
246
247         // default values
248         if (!isset($this->formData['document_date']))
249                 $this->formData['document_date'] = $this->formData['tran_date'];
250
251         if (!isset($this->formData['document_number']))
252                 $this->formData['document_number'] = $SysPrefs->print_invoice_no() == 0 && isset($this->formData['reference'])
253                         ? $this->formData['reference'] : @$this->formData['trans_no'];
254
255         // footer generic content
256         if (@$this->formData['bank_name'])
257                 $Footer[] = _("Bank"). ": ".$this->formData['bank_name']. ", " . _("Bank Account") . ": " . $this->formData['bank_account_number'];
258
259         if (@$this->formData['payment_service'])        //payment link
260         {
261                 $amt = number_format($this->formData["ov_freight"] + $this->formData["ov_gst"] + $this->formData["ov_amount"], user_price_dec());
262                 $service = $this->formData['payment_service'];
263                 $url = payment_link($service, array(
264                         'company_email' => $this->company['email'],
265                         'amount' => $amt,
266                         'currency' => $this->formData['curr_code'],
267                         'comment' => $this->title . " " . $this->formData['reference']
268                         ));
269                 $Footer[_("You can pay through"). " $service: "] = "$url";
270         }
271
272         if ($this->formData['doctype'] == ST_CUSTPAYMENT)
273                 $Footer[] = _("* Subject to Realisation of the Cheque.");
274
275         if ($this->params['comments'] != '')
276                 $Footer[] = $this->params['comments'];
277
278         if (($this->formData['doctype'] == ST_SALESINVOICE || $this->formData['doctype'] == ST_STATEMENT) && $this->company['legal_text'] != "") 
279         {
280                 foreach(explode("\n", $this->company['legal_text']) as $line)
281                         $Footer[] = $line;
282         }
283
284         $this->formData['recipient_name'] = $Addr1['name'];