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