<?php
/*
  $Id: invoice.php,v 1.25 2003/02/19 02:14:00 harley_vb Exp $

  osCommerce, Open Source E-Commerce Solutions
  http://www.oscommerce.com

  Copyright (c) 2002 - 2003 osCommerce

  Released under the GNU General Public License
*/

  class invoice {
    var $code, $title, $description, $enabled;

// class constructor
    function invoice() {
      global $order, $bt_array;

      $this->code = 'invoice';
      $this->title = MODULE_PAYMENT_INVOICE_TEXT_TITLE;
      $this->description = MODULE_PAYMENT_INVOICE_TEXT_DESCRIPTION;
      $this->sort_order = MODULE_PAYMENT_INVOICE_SORT_ORDER;
      $this->enabled = ((MODULE_PAYMENT_INVOICE_STATUS == 'True') ? true : false);

      if ((int)MODULE_PAYMENT_INVOICE_ORDER_STATUS_ID > 0) {
        $this->order_status = MODULE_PAYMENT_INVOICE_ORDER_STATUS_ID;
      }

      if (is_object($order)) $this->update_status();
    }

// class methods
    function update_status() {
      global $order, $attendee_id;

      if ( ($this->enabled == true) && ((int)MODULE_PAYMENT_INVOICE_ZONE > 0) ) {
        $check_flag = false;
        $check_query = go_db_query("select zone_id from " . DB_TBL_ZONES_TO_GEO_ZONES . " where geo_zone_id = '" . MODULE_PAYMENT_INVOICE_ZONE . "' and zone_land_id = '" . $order->billing['land']['id'] . "' order by zone_id");
        while ($check = go_db_fetch_array($check_query)) {
          if ($check['zone_id'] < 1) {
            $check_flag = true;
            break;
          } elseif ($check['zone_id'] == $order->billing['zone_id']) {
            $check_flag = true;
            break;
          }
        }

        if ($check_flag == false) {
          $this->enabled = false;
        }
      }

	  // start änderung
	  $test_query = go_db_query("select count(*) as total from " . DB_TBL_ORDERS . " where attendees_id='".$attendee_id."' AND orders_status>'" . MODULE_PAYMENT_INVOICE_ORDER_STATUS_ID . "'");
	  $result = go_db_fetch_array($test_query);

	  $inv_query = go_db_query("select attendees_invoice from " . DB_TBL_ATTENDEES . " where attendees_id='".$attendee_id."'");
	  $inv_info = go_db_fetch_array($inv_query);

  $inv_check = $inv_info['attendees_invoice'];
  switch ($inv_check) {
      case 0:

	  $total = $result['total'];
	  if (($total+1) < MODULE_PAYMENT_INVOICE_FROM_ORDER) {
		$this->enabled = false;
		}
      break;
      case 1:
      if (($inv_info['attendees_invoice']) < 1) { 
      $this->enabled = false; 
     }
      break;
	 }
	  // ende änderung

// disable the module if the order only contains virtual products
	  // start änderung
      /*if ($this->enabled == true) {
        if ($order->content_type == 'virtual') {
          $this->enabled = false;
        }
      }*/
	  // ende änderung
    }
	

// class methods
    function javascript_validation() {
      return false;
    }

    function selection() {
      return array('id' => $this->code,
                   'module' => $this->title);
    }

    function pre_confirmation_check(){
      return false;
    }

    function confirmation() {
      return false;
    }

    function process_button() {
      return false;
    }

    function before_process() {
      return false;
    }

    function after_process() {
      return false;
    }

    function get_error() {
      return false;
    }

    function check() {
      if (!isset($this->_check)) {
        $check_query = go_db_query("select set_it_up_value from " . DB_TBL_SET_IT_UP . " where set_it_up_key = 'MODULE_PAYMENT_INVOICE_STATUS'");
        $this->_check = go_db_num_rows($check_query);
      }
      return $this->_check;
    }

    function install() {

			go_db_query("insert into " . DB_TBL_SET_IT_UP . " (set_it_up_title, set_it_up_key, set_it_up_value, set_it_up_description, set_it_up_group_id, sort_order, use_function, set_function, date_added) values ('MODULE_PAYMENT_INVOICE_STATUS_TITEL', 'MODULE_PAYMENT_INVOICE_STATUS', 'True', 'MODULE_PAYMENT_INVOICE_STATUS_DESCRIPTION', '6', '0', '', 'go_cfg_select_option(array(\'True\', \'False\'),', now())");
			go_db_query("insert into " . DB_TBL_SET_IT_UP . " (set_it_up_title, set_it_up_key, set_it_up_value, set_it_up_description, set_it_up_group_id, sort_order, use_function, set_function, date_added) values ('MODULE_PAYMENT_INVOICE_ZONE_TITEL', 'MODULE_PAYMENT_INVOICE_ZONE', '0', 'MODULE_PAYMENT_INVOICE_ZONE_DESCRIPTION', '6', '2', 'go_get_zone_class_title', 'go_cfg_pull_down_zone_classes(', now())");
			go_db_query("insert into " . DB_TBL_SET_IT_UP . " (set_it_up_title, set_it_up_key, set_it_up_value, set_it_up_description, set_it_up_group_id, sort_order, use_function, set_function, date_added) values ('MODULE_PAYMENT_INVOICE_SORT_ORDER_TITEL', 'MODULE_PAYMENT_INVOICE_SORT_ORDER', '0', 'MODULE_PAYMENT_INVOICE_SORT_ORDER_DESCRIPTION', '6', '0', '', '', now())");
			go_db_query("insert into " . DB_TBL_SET_IT_UP . " (set_it_up_title, set_it_up_key, set_it_up_value, set_it_up_description, set_it_up_group_id, sort_order, use_function, set_function, date_added) values ('MODULE_PAYMENT_INVOICE_ORDER_STATUS_ID_TITEL', 'MODULE_PAYMENT_INVOICE_ORDER_STATUS_ID', '0', 'MODULE_PAYMENT_INVOICE_ORDER_STATUS_ID_DESCRIPTION', '6', '0', 'go_get_order_status_name', 'go_cfg_pull_down_order_statuses(', now())");
			go_db_query("insert into " . DB_TBL_SET_IT_UP . " (set_it_up_title, set_it_up_key, set_it_up_value, set_it_up_description, set_it_up_group_id, sort_order, use_function, set_function, date_added) values ('MODULE_PAYMENT_INVOICE_FROM_ORDER_TITEL', 'MODULE_PAYMENT_INVOICE_FROM_ORDER', '3', 'MODULE_PAYMENT_INVOICE_FROM_ORDER_DESCRIPTION', '6', '0', '', '', now())");

    }

    function remove() {
      go_db_query("delete from " . DB_TBL_SET_IT_UP . " where set_it_up_key in ('" . implode("', '", $this->keys()) . "')");
    }

    function keys() {
	  // start änderung
      /*return array('MODULE_PAYMENT_INVOICE_STATUS', 'MODULE_PAYMENT_INVOICE_ZONE', 'MODULE_PAYMENT_INVOICE_ORDER_STATUS_ID', 'MODULE_PAYMENT_INVOICE_SORT_ORDER');*/
	  return array('MODULE_PAYMENT_INVOICE_STATUS', 'MODULE_PAYMENT_INVOICE_ZONE', 'MODULE_PAYMENT_INVOICE_ORDER_STATUS_ID', 'MODULE_PAYMENT_INVOICE_SORT_ORDER',
	  'MODULE_PAYMENT_INVOICE_FROM_ORDER');
	  // ende änderung
    }
  }
?>