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