/[drupal]/contributions/modules/invoice/invoice_form.inc
ViewVC logotype

Contents of /contributions/modules/invoice/invoice_form.inc

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.4 - (show annotations) (download) (as text)
Sat Dec 13 14:03:32 2008 UTC (11 months, 2 weeks ago) by pvogelaar
Branch: MAIN
CVS Tags: HEAD
Changes since 1.3: +2 -2 lines
File MIME type: text/x-php
* Fixed bug: "Invoice items : Unit Cost incl VAT is wrong whent you use a VAT less of 10%" => http://drupal.org/node/345800
* Added a TODO: Possibility to link an invoice to a site user + page for that user to view his invoices => http://drupal.org/node/346516
  - With a extra option to also send the invoice by email (if no site user is selected the customer email field that is not implemented yet
    will be choosen, if both are empty an error will be thrown if this checkbox is still checked. => http://drupal.org/node/346005
1 <?php
2 // $Id$
3
4 /**
5 * @file
6 * Invoice module
7 *
8 * This module was developed by Platina Designs, http://www.platinadesigns.nl
9 *
10 * @author Pieter Vogelaar <ps.vogelaar@platinadesigns.nl>
11 */
12
13 /**
14 * Implementatin of node_form()
15 */
16 function invoice_form(&$form_state, $node) {
17 _invoice_add_css_js();
18
19 // If an invoice number is available we are in editing mode
20 if (!empty($form_state->invoice['invoice_number'])) {
21 $mode = 'edit';
22 }
23 else {
24 $mode = 'create';
25 }
26
27 $form = array();
28 $form['invoice_template'] = array(
29 '#type' => 'fieldset',
30 '#title' => t('Invoice template'),
31 '#collapsible' => TRUE,
32 '#collapsed' => FALSE,
33 '#weight' => 1,
34 );
35
36 // Get template names
37 $a_templates = _invoice_get_templates();
38
39 // Build array for selecting the default template
40 $a_template_options = array();
41 foreach ($a_templates as $s_template) {
42 $a_template_options[$s_template] = ucfirst($s_template);
43 }
44
45 $active_template = empty($form_state->invoice['template']) ? _invoice_get_chosen_template() : $form_state->invoice['template'];
46
47 $form['invoice_template']['template'] = array(
48 '#type' => 'select',
49 '#title' => '',
50 '#options' => $a_template_options,
51 '#default_value' => $active_template,
52 '#attributes' => empty($form_state->invoice['template']) ? array('onchange' => 'invoice_set_template(this.value)') : array(),
53 '#description' => t("When editing this invoice, you'll have to save first before you can see template changes."),
54 );
55
56 if (empty($form_state->invoice['template'])) {
57 $_SESSION['invoice_template'] = _invoice_get_chosen_template();
58 }
59
60 $form['customer'] = array(
61 '#type' => 'fieldset',
62 '#title' => t('Customer details'),
63 '#collapsible' => TRUE,
64 '#collapsed' => FALSE,
65 '#description' => t('You either have to fill in Company name or Lastname. Firstname is optional and is only saved if a Lastname is filled in.'),
66 '#weight' => 2,
67 );
68 $form['customer']['search'] = array(
69 '#type' => 'textfield',
70 '#title' => t('Search customer'),
71 '#maxlength' => 60,
72 '#autocomplete_path' => 'invoice/search/customer',
73 '#default_value' => !empty($form_state->customer['company_name']) ? $form_state->customer['company_name'] : $form_state->customer['lastname'] . (!empty($form_state->customer['firstname']) ? ', '. $form_state->customer['firstname'] : ''),
74 );
75 $form['customer']['company_name'] = array(
76 '#type' => 'textfield',
77 '#title' => t('Company name'),
78 '#required' => FALSE,
79 '#default_value' => $form_state->customer['company_name'],
80 );
81 $form['customer']['firstname'] = array(
82 '#type' => 'textfield',
83 '#title' => t('Firstname'),
84 '#required' => FALSE,
85 '#default_value' => $form_state->customer['firstname'],
86 );
87 $form['customer']['lastname'] = array(
88 '#type' => 'textfield',
89 '#title' => t('Lastname'),
90 '#required' => FALSE,
91 '#default_value' => $form_state->customer['lastname'],
92 );
93
94 $invoice_items_table_header = array(
95 t('Description'),
96 t('VAT'),
97 t('Count'),
98 t('Unitcost (ex. VAT)'),
99 t('Unitcost (inc. VAT)'),
100 t('Subtotal (ex. VAT)'),
101 t('Subtotal (inc. VAT)'),
102 '',
103 );
104
105 $form['invoice_items'] = array(
106 '#type' => 'fieldset',
107 '#title' => t('Invoice items'),
108 '#collapsible' => TRUE,
109 '#collapsed' => FALSE,
110 '#weight' => 4,
111 );
112
113 // Set locale so money has the right format for the preferred culture
114 if (intval($form_state->invoice['invoice_number']) == 0) {
115 if ($locale = _invoice_get_variable(_invoice_get_chosen_template(), 'locale')) {
116 setlocale(LC_MONETARY, $locale);
117 }
118 }
119 elseif ($locale = _invoice_get_variable($active_template, 'locale')) {
120 setlocale(LC_MONETARY, $locale);
121 }
122
123 // Get invoice items
124 $a_items = _invoice_get_invoice_items($form_state->invoice['invoice_number']);
125 $count = $a_items['count'];
126 $invoice_items_table_rows = $a_items['rows'];
127
128 // If now rows are found add an empty row
129 if ($count == 0) {
130 $invoice_items_table_rows = array(
131 array('data' => array(array('data' => t('Empty') .'...', 'colspan' => '7')), 'class' => 'invoice-items-empty'),
132 );
133 }
134 else {
135 // Count the added items
136 $a_totals = _invoice_get_invoice_totals($form_state->invoice['invoice_number'], $GLOBALS['user']->uid);
137 $total->extotal = $a_totals['extotal'];
138 $total->inctotal = $a_totals['inctotal'];
139 }
140
141 $invoice_items_table = theme('invoice_table', $invoice_items_table_header, $invoice_items_table_rows, array('disable_sticky_header' => TRUE));
142 $invoice_items_table_footer = '<tfoot><tr><td colspan="5"></td><td class="extotal">'. money_format('%.2n', _invoice_round($total->extotal, 2)) .'</td><td class="inctotal">'. money_format('%.2n', _invoice_round($total->inctotal, 2)) .'</td><td></td></tr></tfoot>';
143 $invoice_items_table = str_replace('</table>', $invoice_items_table_footer .'</table>', $invoice_items_table);
144
145 $form['invoice_items']['items'] = array(
146 '#value' => '<div class="invoice-items">'. $invoice_items_table .'</div>',
147 );
148 $form['invoice_items']['iid'] = array(
149 '#type' => 'hidden',
150 '#title' => t('Invoice item id'),
151 '#required' => FALSE,
152 );
153 $form['invoice_items']['description'] = array(
154 '#type' => 'textarea',
155 '#title' => t('Description'),
156 '#required' => FALSE,
157 '#rows' => 1,
158 );
159 $form['invoice_items']['quantity'] = array(
160 '#type' => 'textfield',
161 '#title' => t('Quantity'),
162 '#required' => FALSE,
163 '#size' => 5,
164 );
165 $form['invoice_items']['price_without_vat'] = array(
166 '#type' => 'textfield',
167 '#title' => t('Price without VAT'),
168 '#required' => FALSE,
169 '#description' => t("If you don't fill in this field, you'll have to fill in \"Price with VAT\""),
170 );
171 $form['invoice_items']['price_with_vat'] = array(
172 '#type' => 'textfield',
173 '#title' => t('Price with VAT'),
174 '#required' => FALSE,
175 '#description' => t("If you don't fill in this field, you'll have to fill in \"Price without VAT\""),
176 );
177 $form['invoice_items']['vat'] = array(
178 '#type' => 'textfield',
179 '#title' => t('VAT percentage'),
180 '#required' => TRUE,
181 '#attributes' => array('style' => 'width:40px;'), // size attribute didn't work here for some strange reason
182 '#default_value' => _invoice_get_variable($active_template, 'vat'),
183 );
184 $form['invoice_items']['save_item'] = array(
185 '#value' => '<input type="button" id="button-save-item" name="button_save_item" value="'. t('Add item') .'" onclick="invoice_save_item()" />',
186 );
187
188 $form['customer_optional'] = array(
189 '#type' => 'fieldset',
190 '#title' => t('Customer details') .' ('. t('optional') .')',
191 '#collapsible' => TRUE,
192 '#collapsed' => TRUE,
193 '#weight' => 3,
194 );
195 $form['customer_optional']['street'] = array(
196 '#type' => 'textfield',
197 '#title' => t('Street'),
198 '#required' => FALSE,
199 '#default_value' => $form_state->customer['street'],
200 );
201 $form['customer_optional']['building_number'] = array(
202 '#type' => 'textfield',
203 '#title' => t('Building number'),
204 '#required' => FALSE,
205 '#default_value' => $form_state->customer['building_number'],
206 );
207 $form['customer_optional']['zipcode'] = array(
208 '#type' => 'textfield',
209 '#title' => t('Zipcode'),
210 '#required' => FALSE,
211 '#default_value' => $form_state->customer['zipcode'],
212 );
213 $form['customer_optional']['city'] = array(
214 '#type' => 'textfield',
215 '#title' => t('City'),
216 '#required' => FALSE,
217 '#default_value' => $form_state->customer['city'],
218 );
219 $form['customer_optional']['country'] = array(
220 '#type' => 'textfield',
221 '#title' => t('Country'),
222 '#required' => FALSE,
223 '#default_value' => $form_state->customer['country'],
224 );
225 $form['customer_optional']['coc_number'] = array(
226 '#type' => 'textfield',
227 '#title' => t('Chamber of Commerce number'),
228 '#required' => FALSE,
229 '#default_value' => $form_state->customer['coc_number'],
230 );
231 $form['customer_optional']['vat_number'] = array(
232 '#type' => 'textfield',
233 '#title' => t('VAT number'),
234 '#required' => FALSE,
235 '#default_value' => $form_state->customer['vat_number'],
236 );
237 $form['customer_optional']['customer_description'] = array(
238 '#type' => 'textarea',
239 '#title' => t('Description'),
240 '#required' => FALSE,
241 '#default_value' => $form_state->customer['description'],
242 );
243
244 $form['invoice_details'] = array(
245 '#type' => 'fieldset',
246 '#title' => t('Invoice details') .' ('. t('optional') .')',
247 '#collapsible' => TRUE,
248 '#collapsed' => TRUE,
249 '#weight' => 5,
250 );
251
252 // Only display this form field when creating a node
253 if (empty($form_state->invoice['invoice_number'])) {
254 $form['invoice_details']['user_defined_invoice_number'] = array(
255 '#type' => 'textfield',
256 '#title' => t('User defined invoice number'),
257 '#required' => FALSE,
258 '#default_value' => '',
259 '#attributes' => array('style' => 'width:200px;'), // size attribute didn't work here for some strange reason
260 '#description' => t('You can define an invoice number here. The number has to be higher than the latest invoice number though. It also has to be numeric.'),
261 );
262 }
263 $form['invoice_details']['invoice_number'] = array(
264 '#type' => 'hidden',
265 '#title' => t('Invoice number'),
266 '#required' => FALSE,
267 '#default_value' => $form_state->invoice['invoice_number'],
268 );
269 $form['invoice_details']['pay_limit'] = array(
270 '#type' => 'textfield',
271 '#title' => t('Pay limit'),
272 '#required' => FALSE,
273 '#default_value' => empty($form_state->invoice['pay_limit']) ? _invoice_get_variable($active_template, 'pay_limit') : $form_state->invoice['pay_limit'],
274 '#description' => t('Pay limit in days'),
275 '#attributes' => array('style' => 'width:40px;'), // size attribute didn't work here for some strange reason
276 );
277 $form['invoice_details']['invoice_description'] = array(
278 '#type' => 'textarea',
279 '#title' => t('Description'),
280 '#required' => FALSE,
281 '#default_value' => $form_state->invoice['description'],
282 );
283 $form['invoice_details']['invoice_invoice_number_zerofill'] = array(
284 '#type' => 'textfield',
285 '#title' => t('Invoice number zerofill'),
286 '#required' => FALSE,
287 '#default_value' => empty($form_state->invoice['invoice_number_zerofill']) && $mode == 'create' ? variable_get('invoice_invoice_number_zerofill', 0) : $form_state->invoice['invoice_number_zerofill'],
288 '#attributes' => array('style' => 'width:40px;'), // size attribute didn't work here for some strange reason
289 '#description' => t('If you want an invoice number to be displayed as "0001" fill in 4. If you just want to display invoice number "1" leave/set empty.'),
290 );
291 $form['invoice_details']['invoice_invoice_number_prefix'] = array(
292 '#type' => 'textfield',
293 '#title' => t('Invoice number prefix'),
294 '#required' => FALSE,
295 '#default_value' => empty($form_state->invoice['invoice_number_prefix']) && $mode == 'create' ? variable_get('invoice_invoice_number_prefix', '') : $form_state->invoice['invoice_number_prefix'],
296 '#attributes' => array('style' => 'width:150px;'), // size attribute didn't work here for some strange reason
297 '#description' => t('If you want an invoice number to be displayed as "@year0001" fill in "%Y". Fillin 4 in the zerofill field above for extra zero values.', array('@year' => date('Y')))
298 .' '. t('If a new year is reached the numbering will still continue sequentially, so if the year ended with "@year0578", the next year will start with "@next_year0579"', array('@year' => date('Y'), '@next_year' => date('Y') + 1))
299 .' '. t('All !date values may be entered here with a "%" sign before it or every other text you like.', array('!date' => l('date', 'http://www.php.net/date', array('absolute' => TRUE)))),
300 );
301
302 return $form;
303 }
304
305 /**
306 * Invoice settings form
307 */
308 function invoice_settings_form() {
309
310 // Get template names
311 $a_templates = _invoice_get_templates();
312
313 $form['general'] = array(
314 '#type' => 'fieldset',
315 '#title' => t('General settings'),
316 '#collapsible' => TRUE,
317 '#collapsed' => FALSE,
318 );
319 $form['general']['locale'] = array(
320 '#type' => 'textfield',
321 '#title' => t('Locale'),
322 '#required' => TRUE,
323 '#default_value' => variable_get('invoice_locale', ''),
324 '#description' => t('Category/locale names can be found in !rfc1766 and !iso639. Systems can have different naming schemes for locales.',
325 array(
326 '!rfc1766' => l('» RFC 1766', 'http://www.faqs.org/rfcs/rfc1766', array('absolute' => TRUE)),
327 '!iso639' => l('» ISO 639', 'http://www.w3.org/WAI/ER/IG/ert/iso639.htm', array('absolute' => TRUE)),
328 )
329 ) .' '. t('On linux you can check the available locales on the server with the command "locale -a" or click below to see the same list.')
330 .' '. t('If your system/server is ubuntu (debian like) you can install more languages with the aptitude or synaptic package manager. Search for -language-pack-*-base.')
331 .' '. t('If you install for example -language-pack-en-base you get over 10+ locales extra, like en_US, en_GB, en_AU, en_CA etc.')
332 .' '. l('Click here to see an overview of installed locales on your system.', 'invoice/installed_locales'),
333 '#size' => 8,
334 );
335 $form['general']['date_format'] = array(
336 '#type' => 'textfield',
337 '#title' => t('Date format'),
338 '#required' => TRUE,
339 '#default_value' => variable_get('invoice_date_format', ''),
340 '#description' => t('The date on the invoice will look like: @date_format', array('@date_format' => date(variable_get('invoice_date_format', '')))),
341 '#size' => 20,
342 );
343 $form['general']['vat'] = array(
344 '#type' => 'textfield',
345 '#title' => t('Default VAT precentage'),
346 '#required' => TRUE,
347 '#default_value' => variable_get('invoice_vat', ''),
348 '#size' => 3,
349 );
350 $form['general']['pay_limit'] = array(
351 '#type' => 'textfield',
352 '#title' => t('Pay limit'),
353 '#required' => TRUE,
354 '#default_value' => variable_get('invoice_pay_limit', ''),
355 '#description' => t('Pay limit in days'),
356 '#size' => 3,
357 );
358 $form['general']['invoice_number_zerofill'] = array(
359 '#type' => 'textfield',
360 '#title' => t('Invoice number zerofill'),
361 '#required' => FALSE,
362 '#default_value' => variable_get('invoice_invoice_number_zerofill', ''),
363 '#description' => t('If you want an invoice number to be displayed as "0001" fill in 4. If you just want to display invoice number "1" leave/set empty.'),
364 '#size' => 3,
365 );
366 $form['general']['invoice_number_prefix'] = array(
367 '#type' => 'textfield',
368 '#title' => t('Invoice number prefix'),
369 '#required' => FALSE,
370 '#default_value' => variable_get('invoice_invoice_number_prefix', ''),
371 '#description' => t('If you want an invoice number to be displayed as "@year0001" fill in "%Y". Fillin 4 in the zerofill field above for extra zero values.', array('@year' => date('Y')))
372 .' '. t('If a new year is reached the numbering will still continue sequentially, so if the year ended with "@year0578", the next year will start with "@next_year0579"', array('@year' => date('Y'), '@next_year' => date('Y') + 1))
373 .' '. t('All !date values may be entered here with a "%" sign before it or every other text you like.', array('!date' => l('date', 'http://www.php.net/date', array('absolute' => TRUE)))),
374 '#size' => 20,
375 );
376
377 /*------------------------------------------------------*/
378
379 $form['general']['display_column'] = array(
380 '#type' => 'fieldset',
381 '#title' => t('Display invoice columns'),
382 '#collapsible' => TRUE,
383 '#collapsed' => TRUE,
384 );
385 $form['general']['display_column']['display_column_vat'] = array(
386 '#type' => 'checkbox',
387 '#title' => t('VAT'),
388 '#required' => FALSE,
389 '#default_value' => variable_get('invoice_display_column_vat', ''),
390 );
391 $form['general']['display_column']['display_column_exunitcost'] = array(
392 '#type' => 'checkbox',
393 '#title' => t('Unitcost (ex)'),
394 '#required' => FALSE,
395 '#default_value' => variable_get('invoice_display_column_exunitcost', ''),
396 );
397 $form['general']['display_column']['display_column_incunitcost'] = array(
398 '#type' => 'checkbox',
399 '#title' => t('Unitcost (inc)'),
400 '#required' => FALSE,
401 '#default_value' => variable_get('invoice_display_column_incunitcost', ''),
402 );
403 $form['general']['display_column']['display_column_extotal'] = array(
404 '#type' => 'checkbox',
405 '#title' => t('Total (ex)'),
406 '#required' => FALSE,
407 '#default_value' => variable_get('invoice_display_column_extotal', ''),
408 );
409 $form['general']['display_column']['display_column_inctotal'] = array(
410 '#type' => 'checkbox',
411 '#title' => t('Total (inc)'),
412 '#required' => FALSE,
413 '#default_value' => variable_get('invoice_display_column_inctotal', ''),
414 );
415
416 /*------------------------------------------------------*/
417
418 $form['general']['supplier'] = array(
419 '#type' => 'fieldset',
420 '#title' => t('Supplier details'),
421 '#collapsible' => TRUE,
422 '#collapsed' => TRUE,
423 );
424 $form['general']['supplier']['supplier_company_name'] = array(
425 '#type' => 'textfield',
426 '#title' => t('Company name'),
427 '#required' => FALSE,
428 '#default_value' => variable_get('invoice_supplier_company_name', ''),
429 );
430 $form['general']['supplier']['supplier_street'] = array(
431 '#type' => 'textfield',
432 '#title' => t('Street'),
433 '#required' => FALSE,
434 '#default_value' => variable_get('invoice_supplier_street', ''),
435 );
436 $form['general']['supplier']['supplier_building_number'] = array(
437 '#type' => 'textfield',
438 '#title' => t('Building number'),
439 '#required' => FALSE,
440 '#default_value' => variable_get('invoice_supplier_building_number', ''),
441 );
442 $form['general']['supplier']['supplier_zipcode'] = array(
443 '#type' => 'textfield',
444 '#title' => t('Zipcode'),
445 '#required' => FALSE,
446 '#default_value' => variable_get('invoice_supplier_zipcode', ''),
447 );
448 $form['general']['supplier']['supplier_city'] = array(
449 '#type' => 'textfield',
450 '#title' => t('City'),
451 '#required' => FALSE,
452 '#default_value' => variable_get('invoice_supplier_city', ''),
453 );
454 $form['general']['supplier']['supplier_country'] = array(
455 '#type' => 'textfield',
456 '#title' => t('Country'),
457 '#required' => FALSE,
458 '#default_value' => variable_get('invoice_supplier_country', ''),
459 );
460 $form['general']['supplier']['supplier_phone'] = array(
461 '#type' => 'textfield',
462 '#title' => t('Phone'),
463 '#required' => FALSE,
464 '#default_value' => variable_get('invoice_supplier_phone', ''),
465 );
466 $form['general']['supplier']['supplier_fax'] = array(
467 '#type' => 'textfield',
468 '#title' => t('Fax'),
469 '#required' => FALSE,
470 '#default_value' => variable_get('invoice_supplier_fax', ''),
471 );
472 $form['general']['supplier']['supplier_email'] = array(
473 '#type' => 'textfield',
474 '#title' => t('Email'),
475 '#required' => FALSE,
476 '#default_value' => variable_get('invoice_supplier_email', ''),
477 );
478 $form['general']['supplier']['supplier_web'] = array(
479 '#type' => 'textfield',
480 '#title' => t('Web address'),
481 '#required' => FALSE,
482 '#default_value' => variable_get('invoice_supplier_web', ''),
483 );
484 $form['general']['supplier']['supplier_coc_number'] = array(
485 '#type' => 'textfield',
486 '#title' => t('CoC Number'),
487 '#required' => FALSE,
488 '#default_value' => variable_get('invoice_supplier_coc_number', ''),
489 );
490 $form['general']['supplier']['supplier_vat_number'] = array(
491 '#type' => 'textfield',
492 '#title' => t('VAT Number'),
493 '#required' => FALSE,
494 '#default_value' => variable_get('invoice_supplier_vat_number', ''),
495 );
496
497 // Build array for selecting the default template
498 $a_default_template = array();
499 foreach ($a_templates as $s_template) {
500 $a_default_template[$s_template] = ucfirst($s_template);
501 }
502
503 $form['general']['default_template'] = array(
504 '#type' => 'select',
505 '#title' => t('Default template'),
506 '#options' => $a_default_template,
507 '#default_value' => variable_get('invoice_default_template', 'default'),
508 '#required' => TRUE,
509 '#size' => 1,
510 );
511
512 /*------------------------------------------------------*/
513 // Build form for template values
514
515 foreach ($a_templates as $s_template) {
516 $form[$s_template] = array(
517 '#type' => 'fieldset',
518 '#title' => t('Template') .' ('. $s_template .')',
519 '#collapsible' => TRUE,
520 '#collapsed' => $s_template == 'default' ? FALSE : TRUE,
521 '#description' => t('If fields are also set in invoice general settings and the template field is empty, the general setting of the field will be used.'),
522 );
523 $form[$s_template][$s_template .'_locale'] = array(
524 '#type' => 'textfield',
525 '#title' => t('Locale'),
526 '#required' => FALSE,
527 '#default_value' => _invoice_get_variable($s_template, 'locale', ''),
528 '#description' => t('Category/locale names can be found in !rfc1766 and !iso639. Systems can have different naming schemes for locales.',
529 array(
530 '!rfc1766' => l('» RFC 1766', 'http://www.faqs.org/rfcs/rfc1766', array('absolute' => TRUE)),
531 '!iso639' => l('» ISO 639', 'http://www.w3.org/WAI/ER/IG/ert/iso639.htm', array('absolute' => TRUE)),
532 )
533 ) .' '. t('On linux you can check the available locales on the server with the command "locale -a" or click below to see the same list.')
534 .' '. t('If your system/server is ubuntu (debian like) you can install more languages with the aptitude or synaptic package manager. Search for -language-pack-*-base.')
535 .' '. t('If you install for example -language-pack-en-base you get over 10+ locales extra, like en_US, en_GB, en_AU, en_CA etc.')
536 .' '. l('Click here to see an overview of installed locales on your system.', 'invoice/installed_locales'),
537 '#size' => 20,
538 );
539 $form[$s_template][$s_template .'_date_format'] = array(
540 '#type' => 'textfield',
541 '#title' => t('Date format'),
542 '#required' => FALSE,
543 '#default_value' => _invoice_get_variable($s_template, 'date_format', ''),
544 '#description' => t('The date on the invoice will look like: @date_format', array('@date_format' => date(_invoice_get_variable($s_template, 'date_format')))),
545 '#size' => 20,
546 );
547 $form[$s_template][$s_template .'_vat'] = array(
548 '#type' => 'textfield',
549 '#title' => t('Default vat percentage'),
550 '#required' => FALSE,
551 '#default_value' => _invoice_get_variable($s_template, 'vat', ''),
552 '#size' => 3,
553 );
554 $form[$s_template][$s_template .'_pay_limit'] = array(
555 '#type' => 'textfield',
556 '#title' => t('Pay limit'),
557 '#required' => FALSE,
558 '#default_value' => _invoice_get_variable($s_template, 'pay_limit', ''),
559 '#description' => t('Pay limit in days'),
560 '#size' => 3,
561 );
562
563 /*------------------------------------------------------*/
564
565 $s_fieldset_name = '_display_column';
566
567 $form[$s_template][$s_template .'_display_column'] = array(
568 '#type' => 'fieldset',
569 '#title' => t('Display invoice columns'),
570 '#collapsible' => TRUE,
571 '#collapsed' => TRUE,
572 );
573 $form[$s_template][$s_template .'_display_column'][$s_template . $s_fieldset_name .'_vat'] = array(
574 '#type' => 'checkbox',
575 '#title' => t('VAT'),
576 '#required' => FALSE,
577 '#default_value' => _invoice_get_variable($s_template, 'display_column_vat', ''),
578 );
579 $form[$s_template][$s_template .'_display_column'][$s_template . $s_fieldset_name .'_exunitcost'] = array(
580 '#type' => 'checkbox',
581 '#title' => t('Unitcost (ex)'),
582 '#required' => FALSE,
583 '#default_value' => _invoice_get_variable($s_template, 'display_column_exunitcost', ''),
584 );
585 $form[$s_template][$s_template .'_display_column'][$s_template . $s_fieldset_name .'_incunitcost'] = array(
586 '#type' => 'checkbox',
587 '#title' => t('Unitcost (inc)'),
588 '#required' => FALSE,
589 '#default_value' => _invoice_get_variable($s_template, 'display_column_incunitcost', ''),
590 );
591 $form[$s_template][$s_template .'_display_column'][$s_template . $s_fieldset_name .'_extotal'] = array(
592 '#type' => 'checkbox',
593 '#title' => t('Total (ex)'),
594 '#required' => FALSE,
595 '#default_value' => _invoice_get_variable($s_template, 'display_column_extotal', ''),
596 );
597 $form[$s_template][$s_template .'_display_column'][$s_template . $s_fieldset_name .'_inctotal'] = array(
598 '#type' => 'checkbox',
599 '#title' => t('Total (inc)'),
600 '#required' => FALSE,
601 '#default_value' => _invoice_get_variable($s_template, 'display_column_inctotal', ''),
602 );
603
604 /*------------------------------------------------------*/
605
606 $form[$s_template][$s_template .'_supplier'] = array(
607 '#type' => 'fieldset',
608 '#title' => t('Supplier details'),
609 '#collapsible' => TRUE,
610 '#collapsed' => TRUE,
611 );
612 $form[$s_template][$s_template .'_supplier'][$s_template .'_supplier_company_name'] = array(
613 '#type' => 'textfield',
614 '#title' => t('Company name'),
615 '#required' => FALSE,
616 '#default_value' => _invoice_get_variable($s_template, 'supplier_company_name', ''),
617 );
618 $form[$s_template][$s_template .'_supplier'][$s_template .'_supplier_street'] = array(
619 '#type' => 'textfield',
620 '#title' => t('Street'),
621 '#required' => FALSE,
622 '#default_value' => _invoice_get_variable($s_template, 'supplier_street', ''),
623 );
624 $form[$s_template][$s_template .'_supplier'][$s_template .'_supplier_building_number'] = array(
625 '#type' => 'textfield',
626 '#title' => t('Building number'),
627 '#required' => FALSE,
628 '#default_value' => _invoice_get_variable($s_template, 'supplier_building_number', ''),
629 );
630 $form[$s_template][$s_template .'_supplier'][$s_template .'_supplier_zipcode'] = array(
631 '#type' => 'textfield',
632 '#title' => t('Zipcode'),
633 '#required' => FALSE,
634 '#default_value' => _invoice_get_variable($s_template, 'supplier_zipcode', ''),
635 );
636 $form[$s_template][$s_template .'_supplier'][$s_template .'_supplier_city'] = array(
637 '#type' => 'textfield',
638 '#title' => t('City'),
639 '#required' => FALSE,
640 '#default_value' => _invoice_get_variable($s_template, 'supplier_city', ''),
641 );
642 $form[$s_template][$s_template .'_supplier'][$s_template .'_supplier_country'] = array(
643 '#type' => 'textfield',
644 '#title' => t('Country'),
645 '#required' => FALSE,
646 '#default_value' => _invoice_get_variable($s_template, 'supplier_country', ''),
647 );
648 $form[$s_template][$s_template .'_supplier'][$s_template .'_supplier_phone'] = array(
649 '#type' => 'textfield',
650 '#title' => t('Phone'),
651 '#required' => FALSE,
652 '#default_value' => _invoice_get_variable($s_template, 'supplier_phone', ''),
653 );
654 $form[$s_template][$s_template .'_supplier'][$s_template .'_supplier_fax'] = array(
655 '#type' => 'textfield',
656 '#title' => t('Fax'),
657 '#required' => FALSE,
658 '#default_value' => _invoice_get_variable($s_template, 'supplier_fax', ''),
659 );
660 $form[$s_template][$s_template .'_supplier'][$s_template .'_supplier_email'] = array(
661 '#type' => 'textfield',
662 '#title' => t('Email'),
663 '#required' => FALSE,
664 '#default_value' => _invoice_get_variable($s_template, 'supplier_email', ''),
665 );
666 $form[$s_template][$s_template .'_supplier'][$s_template .'_supplier_web'] = array(
667 '#type' => 'textfield',
668 '#title' => t('Web address'),
669 '#required' => FALSE,
670 '#default_value' => _invoice_get_variable($s_template, 'supplier_web', ''),
671 );
672 $form[$s_template][$s_template .'_supplier'][$s_template .'_supplier_coc_number'] = array(
673 '#type' => 'textfield',
674 '#title' => t('CoC number'),
675 '#required' => FALSE,
676 '#default_value' => _invoice_get_variable($s_template, 'supplier_coc_number', ''),
677 );
678 $form[$s_template][$s_template .'_supplier'][$s_template .'_supplier_vat_number'] = array(
679 '#type' => 'textfield',
680 '#title' => t('VAT number'),
681 '#required' => FALSE,
682 '#default_value' => _invoice_get_variable($s_template, 'supplier_vat_number', ''),
683 );
684 }
685
686 $form['submit'] = array(
687 '#type' => 'submit',
688 '#value' => t('Submit'),
689 );
690
691 return $form;
692 }
693
694 /**
695 * Form helper function to get all invoice items
696 *
697 * @param string $type
698 * @param integer $invoice_id
699 *
700 * @return array
701 */
702 function _invoice_get_invoice_items($invoice_id=0, $type=NULL) {
703 $i = 0;
704 $invoice_id = intval($invoice_id);
705
706 $invoice_items_table_rows = array();
707 $sql_addition = $invoice_id > 0 ? ' '. intval($invoice_id) : '';
708
709 $result = db_query("SELECT * FROM {invoice_items}
710 WHERE uid=%d AND invoice_id=%d ORDER BY created ASC",
711 $GLOBALS['user']->uid,
712 $invoice_id
713 );
714
715 while ($row = db_fetch_object($result)) {
716 $i++;
717 $invoice_items_table_rows[] = array('data' => array(
718 nl2br($row->description),
719 $row->vat .'%',
720 $row->quantity,
721 money_format('%.3n', _invoice_round($row->unitcost, 3)),
722 money_format('%.2n', _invoice_round($row->unitcost * _invoice_vat_percent_to_decimal($row->vat), 2)),
723 money_format('%.2n', _invoice_round($row->quantity * $row->unitcost, 2)),
724 money_format('%.2n', _invoice_round($row->quantity * $row->unitcost * _invoice_vat_percent_to_decimal($row->vat), 2)),
725 array('data' =>
726 _invoice_get_icon('edit', NULL, array(
727 'onclick' => sprintf("invoice_edit_item('%d')", $row->iid),
728 'class' => 'mouse-pointer',
729 'title' => t('Edit'),
730 ))
731 .
732 _invoice_get_icon('delete', NULL, array(
733 'onclick' => sprintf("invoice_delete_item('%d')", $row->iid),
734 'class' => 'mouse-pointer',
735 'title' => t('Delete'),
736 )),
737 'class' => 'actions'
738 ),
739 ),
740 'class' => $type .'item-'. $row->iid,
741 );
742 }
743
744 return array('rows' => $invoice_items_table_rows, 'count' => $i);
745 }
746
747 /**
748 * Implementation of hook_form_alter()
749 *
750 * @param array $form
751 * @param array $form_state
752 * @param string $form_id
753 */
754 function invoice_form_alter(&$form, $form_state, $form_id) {
755 if ($form_id == 'invoice_node_form') {
756 unset($form['buttons']['preview']);
757 }
758 }

  ViewVC Help
Powered by ViewVC 1.1.2